ipv6.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /*
  2. * DCCP over IPv6
  3. * Linux INET6 implementation
  4. *
  5. * Based on net/dccp6/ipv6.c
  6. *
  7. * Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/random.h>
  16. #include <linux/xfrm.h>
  17. #include <net/addrconf.h>
  18. #include <net/inet_common.h>
  19. #include <net/inet_hashtables.h>
  20. #include <net/inet_sock.h>
  21. #include <net/inet6_connection_sock.h>
  22. #include <net/inet6_hashtables.h>
  23. #include <net/ip6_route.h>
  24. #include <net/ipv6.h>
  25. #include <net/protocol.h>
  26. #include <net/transp_v6.h>
  27. #include <net/ip6_checksum.h>
  28. #include <net/xfrm.h>
  29. #include "dccp.h"
  30. #include "ipv6.h"
  31. #include "feat.h"
  32. /* The per-net dccp.v6_ctl_sk is used for sending RSTs and ACKs */
  33. static struct inet_connection_sock_af_ops dccp_ipv6_mapped;
  34. static struct inet_connection_sock_af_ops dccp_ipv6_af_ops;
  35. static void dccp_v6_hash(struct sock *sk)
  36. {
  37. if (sk->sk_state != DCCP_CLOSED) {
  38. if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) {
  39. inet_hash(sk);
  40. return;
  41. }
  42. local_bh_disable();
  43. __inet6_hash(sk);
  44. local_bh_enable();
  45. }
  46. }
  47. /* add pseudo-header to DCCP checksum stored in skb->csum */
  48. static inline __sum16 dccp_v6_csum_finish(struct sk_buff *skb,
  49. struct in6_addr *saddr,
  50. struct in6_addr *daddr)
  51. {
  52. return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum);
  53. }
  54. static inline void dccp_v6_send_check(struct sock *sk, int unused_value,
  55. struct sk_buff *skb)
  56. {
  57. struct ipv6_pinfo *np = inet6_sk(sk);
  58. struct dccp_hdr *dh = dccp_hdr(skb);
  59. dccp_csum_outgoing(skb);
  60. dh->dccph_checksum = dccp_v6_csum_finish(skb, &np->saddr, &np->daddr);
  61. }
  62. static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
  63. __be16 sport, __be16 dport )
  64. {
  65. return secure_tcpv6_sequence_number(saddr, daddr, sport, dport);
  66. }
  67. static inline __u32 dccp_v6_init_sequence(struct sk_buff *skb)
  68. {
  69. return secure_dccpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32,
  70. ipv6_hdr(skb)->saddr.s6_addr32,
  71. dccp_hdr(skb)->dccph_dport,
  72. dccp_hdr(skb)->dccph_sport );
  73. }
  74. static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  75. int type, int code, int offset, __be32 info)
  76. {
  77. struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
  78. const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
  79. struct dccp_sock *dp;
  80. struct ipv6_pinfo *np;
  81. struct sock *sk;
  82. int err;
  83. __u64 seq;
  84. struct net *net = dev_net(skb->dev);
  85. sk = inet6_lookup(net, &dccp_hashinfo,
  86. &hdr->daddr, dh->dccph_dport,
  87. &hdr->saddr, dh->dccph_sport, inet6_iif(skb));
  88. if (sk == NULL) {
  89. ICMP6_INC_STATS_BH(__in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
  90. return;
  91. }
  92. if (sk->sk_state == DCCP_TIME_WAIT) {
  93. inet_twsk_put(inet_twsk(sk));
  94. return;
  95. }
  96. bh_lock_sock(sk);
  97. if (sock_owned_by_user(sk))
  98. NET_INC_STATS_BH(net, LINUX_MIB_LOCKDROPPEDICMPS);
  99. if (sk->sk_state == DCCP_CLOSED)
  100. goto out;
  101. dp = dccp_sk(sk);
  102. seq = dccp_hdr_seq(dh);
  103. if ((1 << sk->sk_state) & ~(DCCPF_REQUESTING | DCCPF_LISTEN) &&
  104. !between48(seq, dp->dccps_awl, dp->dccps_awh)) {
  105. NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
  106. goto out;
  107. }
  108. np = inet6_sk(sk);
  109. if (type == ICMPV6_PKT_TOOBIG) {
  110. struct dst_entry *dst = NULL;
  111. if (sock_owned_by_user(sk))
  112. goto out;
  113. if ((1 << sk->sk_state) & (DCCPF_LISTEN | DCCPF_CLOSED))
  114. goto out;
  115. /* icmp should have updated the destination cache entry */
  116. dst = __sk_dst_check(sk, np->dst_cookie);
  117. if (dst == NULL) {
  118. struct inet_sock *inet = inet_sk(sk);
  119. struct flowi fl;
  120. /* BUGGG_FUTURE: Again, it is not clear how
  121. to handle rthdr case. Ignore this complexity
  122. for now.
  123. */
  124. memset(&fl, 0, sizeof(fl));
  125. fl.proto = IPPROTO_DCCP;
  126. ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
  127. ipv6_addr_copy(&fl.fl6_src, &np->saddr);
  128. fl.oif = sk->sk_bound_dev_if;
  129. fl.fl_ip_dport = inet->dport;
  130. fl.fl_ip_sport = inet->sport;
  131. security_sk_classify_flow(sk, &fl);
  132. err = ip6_dst_lookup(sk, &dst, &fl);
  133. if (err) {
  134. sk->sk_err_soft = -err;
  135. goto out;
  136. }
  137. err = xfrm_lookup(&dst, &fl, sk, 0);
  138. if (err < 0) {
  139. sk->sk_err_soft = -err;
  140. goto out;
  141. }
  142. } else
  143. dst_hold(dst);
  144. if (inet_csk(sk)->icsk_pmtu_cookie > dst_mtu(dst)) {
  145. dccp_sync_mss(sk, dst_mtu(dst));
  146. } /* else let the usual retransmit timer handle it */
  147. dst_release(dst);
  148. goto out;
  149. }
  150. icmpv6_err_convert(type, code, &err);
  151. /* Might be for an request_sock */
  152. switch (sk->sk_state) {
  153. struct request_sock *req, **prev;
  154. case DCCP_LISTEN:
  155. if (sock_owned_by_user(sk))
  156. goto out;
  157. req = inet6_csk_search_req(sk, &prev, dh->dccph_dport,
  158. &hdr->daddr, &hdr->saddr,
  159. inet6_iif(skb));
  160. if (req == NULL)
  161. goto out;
  162. /*
  163. * ICMPs are not backlogged, hence we cannot get an established
  164. * socket here.
  165. */
  166. WARN_ON(req->sk != NULL);
  167. if (seq != dccp_rsk(req)->dreq_iss) {
  168. NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
  169. goto out;
  170. }
  171. inet_csk_reqsk_queue_drop(sk, req, prev);
  172. goto out;
  173. case DCCP_REQUESTING:
  174. case DCCP_RESPOND: /* Cannot happen.
  175. It can, it SYNs are crossed. --ANK */
  176. if (!sock_owned_by_user(sk)) {
  177. DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS);
  178. sk->sk_err = err;
  179. /*
  180. * Wake people up to see the error
  181. * (see connect in sock.c)
  182. */
  183. sk->sk_error_report(sk);
  184. dccp_done(sk);
  185. } else
  186. sk->sk_err_soft = err;
  187. goto out;
  188. }
  189. if (!sock_owned_by_user(sk) && np->recverr) {
  190. sk->sk_err = err;
  191. sk->sk_error_report(sk);
  192. } else
  193. sk->sk_err_soft = err;
  194. out:
  195. bh_unlock_sock(sk);
  196. sock_put(sk);
  197. }
  198. static int dccp_v6_send_response(struct sock *sk, struct request_sock *req)
  199. {
  200. struct inet6_request_sock *ireq6 = inet6_rsk(req);
  201. struct ipv6_pinfo *np = inet6_sk(sk);
  202. struct sk_buff *skb;
  203. struct ipv6_txoptions *opt = NULL;
  204. struct in6_addr *final_p = NULL, final;
  205. struct flowi fl;
  206. int err = -1;
  207. struct dst_entry *dst;
  208. memset(&fl, 0, sizeof(fl));
  209. fl.proto = IPPROTO_DCCP;
  210. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  211. ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
  212. fl.fl6_flowlabel = 0;
  213. fl.oif = ireq6->iif;
  214. fl.fl_ip_dport = inet_rsk(req)->rmt_port;
  215. fl.fl_ip_sport = inet_sk(sk)->sport;
  216. security_req_classify_flow(req, &fl);
  217. opt = np->opt;
  218. if (opt != NULL && opt->srcrt != NULL) {
  219. const struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
  220. ipv6_addr_copy(&final, &fl.fl6_dst);
  221. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  222. final_p = &final;
  223. }
  224. err = ip6_dst_lookup(sk, &dst, &fl);
  225. if (err)
  226. goto done;
  227. if (final_p)
  228. ipv6_addr_copy(&fl.fl6_dst, final_p);
  229. err = xfrm_lookup(&dst, &fl, sk, 0);
  230. if (err < 0)
  231. goto done;
  232. skb = dccp_make_response(sk, dst, req);
  233. if (skb != NULL) {
  234. struct dccp_hdr *dh = dccp_hdr(skb);
  235. dh->dccph_checksum = dccp_v6_csum_finish(skb,
  236. &ireq6->loc_addr,
  237. &ireq6->rmt_addr);
  238. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  239. err = ip6_xmit(sk, skb, &fl, opt, 0);
  240. err = net_xmit_eval(err);
  241. }
  242. done:
  243. if (opt != NULL && opt != np->opt)
  244. sock_kfree_s(sk, opt, opt->tot_len);
  245. dst_release(dst);
  246. return err;
  247. }
  248. static void dccp_v6_reqsk_destructor(struct request_sock *req)
  249. {
  250. if (inet6_rsk(req)->pktopts != NULL)
  251. kfree_skb(inet6_rsk(req)->pktopts);
  252. }
  253. static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
  254. {
  255. struct ipv6hdr *rxip6h;
  256. struct sk_buff *skb;
  257. struct flowi fl;
  258. struct net *net = dev_net(rxskb->dst->dev);
  259. struct sock *ctl_sk = net->dccp.v6_ctl_sk;
  260. if (dccp_hdr(rxskb)->dccph_type == DCCP_PKT_RESET)
  261. return;
  262. if (!ipv6_unicast_destination(rxskb))
  263. return;
  264. skb = dccp_ctl_make_reset(ctl_sk, rxskb);
  265. if (skb == NULL)
  266. return;
  267. rxip6h = ipv6_hdr(rxskb);
  268. dccp_hdr(skb)->dccph_checksum = dccp_v6_csum_finish(skb, &rxip6h->saddr,
  269. &rxip6h->daddr);
  270. memset(&fl, 0, sizeof(fl));
  271. ipv6_addr_copy(&fl.fl6_dst, &rxip6h->saddr);
  272. ipv6_addr_copy(&fl.fl6_src, &rxip6h->daddr);
  273. fl.proto = IPPROTO_DCCP;
  274. fl.oif = inet6_iif(rxskb);
  275. fl.fl_ip_dport = dccp_hdr(skb)->dccph_dport;
  276. fl.fl_ip_sport = dccp_hdr(skb)->dccph_sport;
  277. security_skb_classify_flow(rxskb, &fl);
  278. /* sk = NULL, but it is safe for now. RST socket required. */
  279. if (!ip6_dst_lookup(ctl_sk, &skb->dst, &fl)) {
  280. if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
  281. ip6_xmit(ctl_sk, skb, &fl, NULL, 0);
  282. DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
  283. DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
  284. return;
  285. }
  286. }
  287. kfree_skb(skb);
  288. }
  289. static struct request_sock_ops dccp6_request_sock_ops = {
  290. .family = AF_INET6,
  291. .obj_size = sizeof(struct dccp6_request_sock),
  292. .rtx_syn_ack = dccp_v6_send_response,
  293. .send_ack = dccp_reqsk_send_ack,
  294. .destructor = dccp_v6_reqsk_destructor,
  295. .send_reset = dccp_v6_ctl_send_reset,
  296. };
  297. static struct sock *dccp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
  298. {
  299. const struct dccp_hdr *dh = dccp_hdr(skb);
  300. const struct ipv6hdr *iph = ipv6_hdr(skb);
  301. struct sock *nsk;
  302. struct request_sock **prev;
  303. /* Find possible connection requests. */
  304. struct request_sock *req = inet6_csk_search_req(sk, &prev,
  305. dh->dccph_sport,
  306. &iph->saddr,
  307. &iph->daddr,
  308. inet6_iif(skb));
  309. if (req != NULL)
  310. return dccp_check_req(sk, skb, req, prev);
  311. nsk = __inet6_lookup_established(sock_net(sk), &dccp_hashinfo,
  312. &iph->saddr, dh->dccph_sport,
  313. &iph->daddr, ntohs(dh->dccph_dport),
  314. inet6_iif(skb));
  315. if (nsk != NULL) {
  316. if (nsk->sk_state != DCCP_TIME_WAIT) {
  317. bh_lock_sock(nsk);
  318. return nsk;
  319. }
  320. inet_twsk_put(inet_twsk(nsk));
  321. return NULL;
  322. }
  323. return sk;
  324. }
  325. static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
  326. {
  327. struct request_sock *req;
  328. struct dccp_request_sock *dreq;
  329. struct inet6_request_sock *ireq6;
  330. struct ipv6_pinfo *np = inet6_sk(sk);
  331. const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
  332. struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
  333. if (skb->protocol == htons(ETH_P_IP))
  334. return dccp_v4_conn_request(sk, skb);
  335. if (!ipv6_unicast_destination(skb))
  336. return 0; /* discard, don't send a reset here */
  337. if (dccp_bad_service_code(sk, service)) {
  338. dcb->dccpd_reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE;
  339. goto drop;
  340. }
  341. /*
  342. * There are no SYN attacks on IPv6, yet...
  343. */
  344. dcb->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY;
  345. if (inet_csk_reqsk_queue_is_full(sk))
  346. goto drop;
  347. if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
  348. goto drop;
  349. req = inet6_reqsk_alloc(&dccp6_request_sock_ops);
  350. if (req == NULL)
  351. goto drop;
  352. dccp_reqsk_init(req, skb);
  353. dreq = dccp_rsk(req);
  354. if (dccp_parse_options(sk, dreq, skb))
  355. goto drop_and_free;
  356. if (security_inet_conn_request(sk, skb, req))
  357. goto drop_and_free;
  358. ireq6 = inet6_rsk(req);
  359. ipv6_addr_copy(&ireq6->rmt_addr, &ipv6_hdr(skb)->saddr);
  360. ipv6_addr_copy(&ireq6->loc_addr, &ipv6_hdr(skb)->daddr);
  361. if (ipv6_opt_accepted(sk, skb) ||
  362. np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo ||
  363. np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim) {
  364. atomic_inc(&skb->users);
  365. ireq6->pktopts = skb;
  366. }
  367. ireq6->iif = sk->sk_bound_dev_if;
  368. /* So that link locals have meaning */
  369. if (!sk->sk_bound_dev_if &&
  370. ipv6_addr_type(&ireq6->rmt_addr) & IPV6_ADDR_LINKLOCAL)
  371. ireq6->iif = inet6_iif(skb);
  372. /*
  373. * Step 3: Process LISTEN state
  374. *
  375. * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
  376. *
  377. * In fact we defer setting S.GSR, S.SWL, S.SWH to
  378. * dccp_create_openreq_child.
  379. */
  380. dreq->dreq_isr = dcb->dccpd_seq;
  381. dreq->dreq_iss = dccp_v6_init_sequence(skb);
  382. dreq->dreq_service = service;
  383. if (dccp_v6_send_response(sk, req))
  384. goto drop_and_free;
  385. inet6_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
  386. return 0;
  387. drop_and_free:
  388. reqsk_free(req);
  389. drop:
  390. DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS);
  391. return -1;
  392. }
  393. static struct sock *dccp_v6_request_recv_sock(struct sock *sk,
  394. struct sk_buff *skb,
  395. struct request_sock *req,
  396. struct dst_entry *dst)
  397. {
  398. struct inet6_request_sock *ireq6 = inet6_rsk(req);
  399. struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
  400. struct inet_sock *newinet;
  401. struct dccp_sock *newdp;
  402. struct dccp6_sock *newdp6;
  403. struct sock *newsk;
  404. struct ipv6_txoptions *opt;
  405. if (skb->protocol == htons(ETH_P_IP)) {
  406. /*
  407. * v6 mapped
  408. */
  409. newsk = dccp_v4_request_recv_sock(sk, skb, req, dst);
  410. if (newsk == NULL)
  411. return NULL;
  412. newdp6 = (struct dccp6_sock *)newsk;
  413. newdp = dccp_sk(newsk);
  414. newinet = inet_sk(newsk);
  415. newinet->pinet6 = &newdp6->inet6;
  416. newnp = inet6_sk(newsk);
  417. memcpy(newnp, np, sizeof(struct ipv6_pinfo));
  418. ipv6_addr_set(&newnp->daddr, 0, 0, htonl(0x0000FFFF),
  419. newinet->daddr);
  420. ipv6_addr_set(&newnp->saddr, 0, 0, htonl(0x0000FFFF),
  421. newinet->saddr);
  422. ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr);
  423. inet_csk(newsk)->icsk_af_ops = &dccp_ipv6_mapped;
  424. newsk->sk_backlog_rcv = dccp_v4_do_rcv;
  425. newnp->pktoptions = NULL;
  426. newnp->opt = NULL;
  427. newnp->mcast_oif = inet6_iif(skb);
  428. newnp->mcast_hops = ipv6_hdr(skb)->hop_limit;
  429. /*
  430. * No need to charge this sock to the relevant IPv6 refcnt debug socks count
  431. * here, dccp_create_openreq_child now does this for us, see the comment in
  432. * that function for the gory details. -acme
  433. */
  434. /* It is tricky place. Until this moment IPv4 tcp
  435. worked with IPv6 icsk.icsk_af_ops.
  436. Sync it now.
  437. */
  438. dccp_sync_mss(newsk, inet_csk(newsk)->icsk_pmtu_cookie);
  439. return newsk;
  440. }
  441. opt = np->opt;
  442. if (sk_acceptq_is_full(sk))
  443. goto out_overflow;
  444. if (dst == NULL) {
  445. struct in6_addr *final_p = NULL, final;
  446. struct flowi fl;
  447. memset(&fl, 0, sizeof(fl));
  448. fl.proto = IPPROTO_DCCP;
  449. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  450. if (opt != NULL && opt->srcrt != NULL) {
  451. const struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
  452. ipv6_addr_copy(&final, &fl.fl6_dst);
  453. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  454. final_p = &final;
  455. }
  456. ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
  457. fl.oif = sk->sk_bound_dev_if;
  458. fl.fl_ip_dport = inet_rsk(req)->rmt_port;
  459. fl.fl_ip_sport = inet_sk(sk)->sport;
  460. security_sk_classify_flow(sk, &fl);
  461. if (ip6_dst_lookup(sk, &dst, &fl))
  462. goto out;
  463. if (final_p)
  464. ipv6_addr_copy(&fl.fl6_dst, final_p);
  465. if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0)
  466. goto out;
  467. }
  468. newsk = dccp_create_openreq_child(sk, req, skb);
  469. if (newsk == NULL)
  470. goto out;
  471. /*
  472. * No need to charge this sock to the relevant IPv6 refcnt debug socks
  473. * count here, dccp_create_openreq_child now does this for us, see the
  474. * comment in that function for the gory details. -acme
  475. */
  476. __ip6_dst_store(newsk, dst, NULL, NULL);
  477. newsk->sk_route_caps = dst->dev->features & ~(NETIF_F_IP_CSUM |
  478. NETIF_F_TSO);
  479. newdp6 = (struct dccp6_sock *)newsk;
  480. newinet = inet_sk(newsk);
  481. newinet->pinet6 = &newdp6->inet6;
  482. newdp = dccp_sk(newsk);
  483. newnp = inet6_sk(newsk);
  484. memcpy(newnp, np, sizeof(struct ipv6_pinfo));
  485. ipv6_addr_copy(&newnp->daddr, &ireq6->rmt_addr);
  486. ipv6_addr_copy(&newnp->saddr, &ireq6->loc_addr);
  487. ipv6_addr_copy(&newnp->rcv_saddr, &ireq6->loc_addr);
  488. newsk->sk_bound_dev_if = ireq6->iif;
  489. /* Now IPv6 options...
  490. First: no IPv4 options.
  491. */
  492. newinet->opt = NULL;
  493. /* Clone RX bits */
  494. newnp->rxopt.all = np->rxopt.all;
  495. /* Clone pktoptions received with SYN */
  496. newnp->pktoptions = NULL;
  497. if (ireq6->pktopts != NULL) {
  498. newnp->pktoptions = skb_clone(ireq6->pktopts, GFP_ATOMIC);
  499. kfree_skb(ireq6->pktopts);
  500. ireq6->pktopts = NULL;
  501. if (newnp->pktoptions)
  502. skb_set_owner_r(newnp->pktoptions, newsk);
  503. }
  504. newnp->opt = NULL;
  505. newnp->mcast_oif = inet6_iif(skb);
  506. newnp->mcast_hops = ipv6_hdr(skb)->hop_limit;
  507. /*
  508. * Clone native IPv6 options from listening socket (if any)
  509. *
  510. * Yes, keeping reference count would be much more clever, but we make
  511. * one more one thing there: reattach optmem to newsk.
  512. */
  513. if (opt != NULL) {
  514. newnp->opt = ipv6_dup_options(newsk, opt);
  515. if (opt != np->opt)
  516. sock_kfree_s(sk, opt, opt->tot_len);
  517. }
  518. inet_csk(newsk)->icsk_ext_hdr_len = 0;
  519. if (newnp->opt != NULL)
  520. inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen +
  521. newnp->opt->opt_flen);
  522. dccp_sync_mss(newsk, dst_mtu(dst));
  523. newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6;
  524. __inet6_hash(newsk);
  525. __inet_inherit_port(sk, newsk);
  526. return newsk;
  527. out_overflow:
  528. NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS);
  529. out:
  530. NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENDROPS);
  531. if (opt != NULL && opt != np->opt)
  532. sock_kfree_s(sk, opt, opt->tot_len);
  533. dst_release(dst);
  534. return NULL;
  535. }
  536. /* The socket must have it's spinlock held when we get
  537. * here.
  538. *
  539. * We have a potential double-lock case here, so even when
  540. * doing backlog processing we use the BH locking scheme.
  541. * This is because we cannot sleep with the original spinlock
  542. * held.
  543. */
  544. static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
  545. {
  546. struct ipv6_pinfo *np = inet6_sk(sk);
  547. struct sk_buff *opt_skb = NULL;
  548. /* Imagine: socket is IPv6. IPv4 packet arrives,
  549. goes to IPv4 receive handler and backlogged.
  550. From backlog it always goes here. Kerboom...
  551. Fortunately, dccp_rcv_established and rcv_established
  552. handle them correctly, but it is not case with
  553. dccp_v6_hnd_req and dccp_v6_ctl_send_reset(). --ANK
  554. */
  555. if (skb->protocol == htons(ETH_P_IP))
  556. return dccp_v4_do_rcv(sk, skb);
  557. if (sk_filter(sk, skb))
  558. goto discard;
  559. /*
  560. * socket locking is here for SMP purposes as backlog rcv is currently
  561. * called with bh processing disabled.
  562. */
  563. /* Do Stevens' IPV6_PKTOPTIONS.
  564. Yes, guys, it is the only place in our code, where we
  565. may make it not affecting IPv4.
  566. The rest of code is protocol independent,
  567. and I do not like idea to uglify IPv4.
  568. Actually, all the idea behind IPV6_PKTOPTIONS
  569. looks not very well thought. For now we latch
  570. options, received in the last packet, enqueued
  571. by tcp. Feel free to propose better solution.
  572. --ANK (980728)
  573. */
  574. if (np->rxopt.all)
  575. /*
  576. * FIXME: Add handling of IPV6_PKTOPTIONS skb. See the comments below
  577. * (wrt ipv6_pktopions) and net/ipv6/tcp_ipv6.c for an example.
  578. */
  579. opt_skb = skb_clone(skb, GFP_ATOMIC);
  580. if (sk->sk_state == DCCP_OPEN) { /* Fast path */
  581. if (dccp_rcv_established(sk, skb, dccp_hdr(skb), skb->len))
  582. goto reset;
  583. if (opt_skb) {
  584. /* XXX This is where we would goto ipv6_pktoptions. */
  585. __kfree_skb(opt_skb);
  586. }
  587. return 0;
  588. }
  589. /*
  590. * Step 3: Process LISTEN state
  591. * If S.state == LISTEN,
  592. * If P.type == Request or P contains a valid Init Cookie option,
  593. * (* Must scan the packet's options to check for Init
  594. * Cookies. Only Init Cookies are processed here,
  595. * however; other options are processed in Step 8. This
  596. * scan need only be performed if the endpoint uses Init
  597. * Cookies *)
  598. * (* Generate a new socket and switch to that socket *)
  599. * Set S := new socket for this port pair
  600. * S.state = RESPOND
  601. * Choose S.ISS (initial seqno) or set from Init Cookies
  602. * Initialize S.GAR := S.ISS
  603. * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookies
  604. * Continue with S.state == RESPOND
  605. * (* A Response packet will be generated in Step 11 *)
  606. * Otherwise,
  607. * Generate Reset(No Connection) unless P.type == Reset
  608. * Drop packet and return
  609. *
  610. * NOTE: the check for the packet types is done in
  611. * dccp_rcv_state_process
  612. */
  613. if (sk->sk_state == DCCP_LISTEN) {
  614. struct sock *nsk = dccp_v6_hnd_req(sk, skb);
  615. if (nsk == NULL)
  616. goto discard;
  617. /*
  618. * Queue it on the new socket if the new socket is active,
  619. * otherwise we just shortcircuit this and continue with
  620. * the new socket..
  621. */
  622. if (nsk != sk) {
  623. if (dccp_child_process(sk, nsk, skb))
  624. goto reset;
  625. if (opt_skb != NULL)
  626. __kfree_skb(opt_skb);
  627. return 0;
  628. }
  629. }
  630. if (dccp_rcv_state_process(sk, skb, dccp_hdr(skb), skb->len))
  631. goto reset;
  632. if (opt_skb) {
  633. /* XXX This is where we would goto ipv6_pktoptions. */
  634. __kfree_skb(opt_skb);
  635. }
  636. return 0;
  637. reset:
  638. dccp_v6_ctl_send_reset(sk, skb);
  639. discard:
  640. if (opt_skb != NULL)
  641. __kfree_skb(opt_skb);
  642. kfree_skb(skb);
  643. return 0;
  644. }
  645. static int dccp_v6_rcv(struct sk_buff *skb)
  646. {
  647. const struct dccp_hdr *dh;
  648. struct sock *sk;
  649. int min_cov;
  650. /* Step 1: Check header basics */
  651. if (dccp_invalid_packet(skb))
  652. goto discard_it;
  653. /* Step 1: If header checksum is incorrect, drop packet and return. */
  654. if (dccp_v6_csum_finish(skb, &ipv6_hdr(skb)->saddr,
  655. &ipv6_hdr(skb)->daddr)) {
  656. DCCP_WARN("dropped packet with invalid checksum\n");
  657. goto discard_it;
  658. }
  659. dh = dccp_hdr(skb);
  660. DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(dh);
  661. DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
  662. if (dccp_packet_without_ack(skb))
  663. DCCP_SKB_CB(skb)->dccpd_ack_seq = DCCP_PKT_WITHOUT_ACK_SEQ;
  664. else
  665. DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb);
  666. /* Step 2:
  667. * Look up flow ID in table and get corresponding socket */
  668. sk = __inet6_lookup(dev_net(skb->dst->dev), &dccp_hashinfo,
  669. &ipv6_hdr(skb)->saddr, dh->dccph_sport,
  670. &ipv6_hdr(skb)->daddr, ntohs(dh->dccph_dport),
  671. inet6_iif(skb));
  672. /*
  673. * Step 2:
  674. * If no socket ...
  675. */
  676. if (sk == NULL) {
  677. dccp_pr_debug("failed to look up flow ID in table and "
  678. "get corresponding socket\n");
  679. goto no_dccp_socket;
  680. }
  681. /*
  682. * Step 2:
  683. * ... or S.state == TIMEWAIT,
  684. * Generate Reset(No Connection) unless P.type == Reset
  685. * Drop packet and return
  686. */
  687. if (sk->sk_state == DCCP_TIME_WAIT) {
  688. dccp_pr_debug("sk->sk_state == DCCP_TIME_WAIT: do_time_wait\n");
  689. inet_twsk_put(inet_twsk(sk));
  690. goto no_dccp_socket;
  691. }
  692. /*
  693. * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage
  694. * o if MinCsCov = 0, only packets with CsCov = 0 are accepted
  695. * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov
  696. */
  697. min_cov = dccp_sk(sk)->dccps_pcrlen;
  698. if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) {
  699. dccp_pr_debug("Packet CsCov %d does not satisfy MinCsCov %d\n",
  700. dh->dccph_cscov, min_cov);
  701. /* FIXME: send Data Dropped option (see also dccp_v4_rcv) */
  702. goto discard_and_relse;
  703. }
  704. if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
  705. goto discard_and_relse;
  706. return sk_receive_skb(sk, skb, 1) ? -1 : 0;
  707. no_dccp_socket:
  708. if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
  709. goto discard_it;
  710. /*
  711. * Step 2:
  712. * If no socket ...
  713. * Generate Reset(No Connection) unless P.type == Reset
  714. * Drop packet and return
  715. */
  716. if (dh->dccph_type != DCCP_PKT_RESET) {
  717. DCCP_SKB_CB(skb)->dccpd_reset_code =
  718. DCCP_RESET_CODE_NO_CONNECTION;
  719. dccp_v6_ctl_send_reset(sk, skb);
  720. }
  721. discard_it:
  722. kfree_skb(skb);
  723. return 0;
  724. discard_and_relse:
  725. sock_put(sk);
  726. goto discard_it;
  727. }
  728. static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
  729. int addr_len)
  730. {
  731. struct sockaddr_in6 *usin = (struct sockaddr_in6 *)uaddr;
  732. struct inet_connection_sock *icsk = inet_csk(sk);
  733. struct inet_sock *inet = inet_sk(sk);
  734. struct ipv6_pinfo *np = inet6_sk(sk);
  735. struct dccp_sock *dp = dccp_sk(sk);
  736. struct in6_addr *saddr = NULL, *final_p = NULL, final;
  737. struct flowi fl;
  738. struct dst_entry *dst;
  739. int addr_type;
  740. int err;
  741. dp->dccps_role = DCCP_ROLE_CLIENT;
  742. if (addr_len < SIN6_LEN_RFC2133)
  743. return -EINVAL;
  744. if (usin->sin6_family != AF_INET6)
  745. return -EAFNOSUPPORT;
  746. memset(&fl, 0, sizeof(fl));
  747. if (np->sndflow) {
  748. fl.fl6_flowlabel = usin->sin6_flowinfo & IPV6_FLOWINFO_MASK;
  749. IP6_ECN_flow_init(fl.fl6_flowlabel);
  750. if (fl.fl6_flowlabel & IPV6_FLOWLABEL_MASK) {
  751. struct ip6_flowlabel *flowlabel;
  752. flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
  753. if (flowlabel == NULL)
  754. return -EINVAL;
  755. ipv6_addr_copy(&usin->sin6_addr, &flowlabel->dst);
  756. fl6_sock_release(flowlabel);
  757. }
  758. }
  759. /*
  760. * connect() to INADDR_ANY means loopback (BSD'ism).
  761. */
  762. if (ipv6_addr_any(&usin->sin6_addr))
  763. usin->sin6_addr.s6_addr[15] = 1;
  764. addr_type = ipv6_addr_type(&usin->sin6_addr);
  765. if (addr_type & IPV6_ADDR_MULTICAST)
  766. return -ENETUNREACH;
  767. if (addr_type & IPV6_ADDR_LINKLOCAL) {
  768. if (addr_len >= sizeof(struct sockaddr_in6) &&
  769. usin->sin6_scope_id) {
  770. /* If interface is set while binding, indices
  771. * must coincide.
  772. */
  773. if (sk->sk_bound_dev_if &&
  774. sk->sk_bound_dev_if != usin->sin6_scope_id)
  775. return -EINVAL;
  776. sk->sk_bound_dev_if = usin->sin6_scope_id;
  777. }
  778. /* Connect to link-local address requires an interface */
  779. if (!sk->sk_bound_dev_if)
  780. return -EINVAL;
  781. }
  782. ipv6_addr_copy(&np->daddr, &usin->sin6_addr);
  783. np->flow_label = fl.fl6_flowlabel;
  784. /*
  785. * DCCP over IPv4
  786. */
  787. if (addr_type == IPV6_ADDR_MAPPED) {
  788. u32 exthdrlen = icsk->icsk_ext_hdr_len;
  789. struct sockaddr_in sin;
  790. SOCK_DEBUG(sk, "connect: ipv4 mapped\n");
  791. if (__ipv6_only_sock(sk))
  792. return -ENETUNREACH;
  793. sin.sin_family = AF_INET;
  794. sin.sin_port = usin->sin6_port;
  795. sin.sin_addr.s_addr = usin->sin6_addr.s6_addr32[3];
  796. icsk->icsk_af_ops = &dccp_ipv6_mapped;
  797. sk->sk_backlog_rcv = dccp_v4_do_rcv;
  798. err = dccp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin));
  799. if (err) {
  800. icsk->icsk_ext_hdr_len = exthdrlen;
  801. icsk->icsk_af_ops = &dccp_ipv6_af_ops;
  802. sk->sk_backlog_rcv = dccp_v6_do_rcv;
  803. goto failure;
  804. } else {
  805. ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000FFFF),
  806. inet->saddr);
  807. ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000FFFF),
  808. inet->rcv_saddr);
  809. }
  810. return err;
  811. }
  812. if (!ipv6_addr_any(&np->rcv_saddr))
  813. saddr = &np->rcv_saddr;
  814. fl.proto = IPPROTO_DCCP;
  815. ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
  816. ipv6_addr_copy(&fl.fl6_src, saddr ? saddr : &np->saddr);
  817. fl.oif = sk->sk_bound_dev_if;
  818. fl.fl_ip_dport = usin->sin6_port;
  819. fl.fl_ip_sport = inet->sport;
  820. security_sk_classify_flow(sk, &fl);
  821. if (np->opt != NULL && np->opt->srcrt != NULL) {
  822. const struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt;
  823. ipv6_addr_copy(&final, &fl.fl6_dst);
  824. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  825. final_p = &final;
  826. }
  827. err = ip6_dst_lookup(sk, &dst, &fl);
  828. if (err)
  829. goto failure;
  830. if (final_p)
  831. ipv6_addr_copy(&fl.fl6_dst, final_p);
  832. err = __xfrm_lookup(&dst, &fl, sk, XFRM_LOOKUP_WAIT);
  833. if (err < 0) {
  834. if (err == -EREMOTE)
  835. err = ip6_dst_blackhole(sk, &dst, &fl);
  836. if (err < 0)
  837. goto failure;
  838. }
  839. if (saddr == NULL) {
  840. saddr = &fl.fl6_src;
  841. ipv6_addr_copy(&np->rcv_saddr, saddr);
  842. }
  843. /* set the source address */
  844. ipv6_addr_copy(&np->saddr, saddr);
  845. inet->rcv_saddr = LOOPBACK4_IPV6;
  846. __ip6_dst_store(sk, dst, NULL, NULL);
  847. icsk->icsk_ext_hdr_len = 0;
  848. if (np->opt != NULL)
  849. icsk->icsk_ext_hdr_len = (np->opt->opt_flen +
  850. np->opt->opt_nflen);
  851. inet->dport = usin->sin6_port;
  852. dccp_set_state(sk, DCCP_REQUESTING);
  853. err = inet6_hash_connect(&dccp_death_row, sk);
  854. if (err)
  855. goto late_failure;
  856. dp->dccps_iss = secure_dccpv6_sequence_number(np->saddr.s6_addr32,
  857. np->daddr.s6_addr32,
  858. inet->sport, inet->dport);
  859. err = dccp_connect(sk);
  860. if (err)
  861. goto late_failure;
  862. return 0;
  863. late_failure:
  864. dccp_set_state(sk, DCCP_CLOSED);
  865. __sk_dst_reset(sk);
  866. failure:
  867. inet->dport = 0;
  868. sk->sk_route_caps = 0;
  869. return err;
  870. }
  871. static struct inet_connection_sock_af_ops dccp_ipv6_af_ops = {
  872. .queue_xmit = inet6_csk_xmit,
  873. .send_check = dccp_v6_send_check,
  874. .rebuild_header = inet6_sk_rebuild_header,
  875. .conn_request = dccp_v6_conn_request,
  876. .syn_recv_sock = dccp_v6_request_recv_sock,
  877. .net_header_len = sizeof(struct ipv6hdr),
  878. .setsockopt = ipv6_setsockopt,
  879. .getsockopt = ipv6_getsockopt,
  880. .addr2sockaddr = inet6_csk_addr2sockaddr,
  881. .sockaddr_len = sizeof(struct sockaddr_in6),
  882. .bind_conflict = inet6_csk_bind_conflict,
  883. #ifdef CONFIG_COMPAT
  884. .compat_setsockopt = compat_ipv6_setsockopt,
  885. .compat_getsockopt = compat_ipv6_getsockopt,
  886. #endif
  887. };
  888. /*
  889. * DCCP over IPv4 via INET6 API
  890. */
  891. static struct inet_connection_sock_af_ops dccp_ipv6_mapped = {
  892. .queue_xmit = ip_queue_xmit,
  893. .send_check = dccp_v4_send_check,
  894. .rebuild_header = inet_sk_rebuild_header,
  895. .conn_request = dccp_v6_conn_request,
  896. .syn_recv_sock = dccp_v6_request_recv_sock,
  897. .net_header_len = sizeof(struct iphdr),
  898. .setsockopt = ipv6_setsockopt,
  899. .getsockopt = ipv6_getsockopt,
  900. .addr2sockaddr = inet6_csk_addr2sockaddr,
  901. .sockaddr_len = sizeof(struct sockaddr_in6),
  902. #ifdef CONFIG_COMPAT
  903. .compat_setsockopt = compat_ipv6_setsockopt,
  904. .compat_getsockopt = compat_ipv6_getsockopt,
  905. #endif
  906. };
  907. /* NOTE: A lot of things set to zero explicitly by call to
  908. * sk_alloc() so need not be done here.
  909. */
  910. static int dccp_v6_init_sock(struct sock *sk)
  911. {
  912. static __u8 dccp_v6_ctl_sock_initialized;
  913. int err = dccp_init_sock(sk, dccp_v6_ctl_sock_initialized);
  914. if (err == 0) {
  915. if (unlikely(!dccp_v6_ctl_sock_initialized))
  916. dccp_v6_ctl_sock_initialized = 1;
  917. inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops;
  918. }
  919. return err;
  920. }
  921. static void dccp_v6_destroy_sock(struct sock *sk)
  922. {
  923. dccp_destroy_sock(sk);
  924. inet6_destroy_sock(sk);
  925. }
  926. static struct timewait_sock_ops dccp6_timewait_sock_ops = {
  927. .twsk_obj_size = sizeof(struct dccp6_timewait_sock),
  928. };
  929. static struct proto dccp_v6_prot = {
  930. .name = "DCCPv6",
  931. .owner = THIS_MODULE,
  932. .close = dccp_close,
  933. .connect = dccp_v6_connect,
  934. .disconnect = dccp_disconnect,
  935. .ioctl = dccp_ioctl,
  936. .init = dccp_v6_init_sock,
  937. .setsockopt = dccp_setsockopt,
  938. .getsockopt = dccp_getsockopt,
  939. .sendmsg = dccp_sendmsg,
  940. .recvmsg = dccp_recvmsg,
  941. .backlog_rcv = dccp_v6_do_rcv,
  942. .hash = dccp_v6_hash,
  943. .unhash = inet_unhash,
  944. .accept = inet_csk_accept,
  945. .get_port = inet_csk_get_port,
  946. .shutdown = dccp_shutdown,
  947. .destroy = dccp_v6_destroy_sock,
  948. .orphan_count = &dccp_orphan_count,
  949. .max_header = MAX_DCCP_HEADER,
  950. .obj_size = sizeof(struct dccp6_sock),
  951. .rsk_prot = &dccp6_request_sock_ops,
  952. .twsk_prot = &dccp6_timewait_sock_ops,
  953. .h.hashinfo = &dccp_hashinfo,
  954. #ifdef CONFIG_COMPAT
  955. .compat_setsockopt = compat_dccp_setsockopt,
  956. .compat_getsockopt = compat_dccp_getsockopt,
  957. #endif
  958. };
  959. static struct inet6_protocol dccp_v6_protocol = {
  960. .handler = dccp_v6_rcv,
  961. .err_handler = dccp_v6_err,
  962. .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
  963. };
  964. static struct proto_ops inet6_dccp_ops = {
  965. .family = PF_INET6,
  966. .owner = THIS_MODULE,
  967. .release = inet6_release,
  968. .bind = inet6_bind,
  969. .connect = inet_stream_connect,
  970. .socketpair = sock_no_socketpair,
  971. .accept = inet_accept,
  972. .getname = inet6_getname,
  973. .poll = dccp_poll,
  974. .ioctl = inet6_ioctl,
  975. .listen = inet_dccp_listen,
  976. .shutdown = inet_shutdown,
  977. .setsockopt = sock_common_setsockopt,
  978. .getsockopt = sock_common_getsockopt,
  979. .sendmsg = inet_sendmsg,
  980. .recvmsg = sock_common_recvmsg,
  981. .mmap = sock_no_mmap,
  982. .sendpage = sock_no_sendpage,
  983. #ifdef CONFIG_COMPAT
  984. .compat_setsockopt = compat_sock_common_setsockopt,
  985. .compat_getsockopt = compat_sock_common_getsockopt,
  986. #endif
  987. };
  988. static struct inet_protosw dccp_v6_protosw = {
  989. .type = SOCK_DCCP,
  990. .protocol = IPPROTO_DCCP,
  991. .prot = &dccp_v6_prot,
  992. .ops = &inet6_dccp_ops,
  993. .capability = -1,
  994. .flags = INET_PROTOSW_ICSK,
  995. };
  996. static int dccp_v6_init_net(struct net *net)
  997. {
  998. int err;
  999. err = inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6,
  1000. SOCK_DCCP, IPPROTO_DCCP, net);
  1001. return err;
  1002. }
  1003. static void dccp_v6_exit_net(struct net *net)
  1004. {
  1005. inet_ctl_sock_destroy(net->dccp.v6_ctl_sk);
  1006. }
  1007. static struct pernet_operations dccp_v6_ops = {
  1008. .init = dccp_v6_init_net,
  1009. .exit = dccp_v6_exit_net,
  1010. };
  1011. static int __init dccp_v6_init(void)
  1012. {
  1013. int err = proto_register(&dccp_v6_prot, 1);
  1014. if (err != 0)
  1015. goto out;
  1016. err = inet6_add_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1017. if (err != 0)
  1018. goto out_unregister_proto;
  1019. inet6_register_protosw(&dccp_v6_protosw);
  1020. err = register_pernet_subsys(&dccp_v6_ops);
  1021. if (err != 0)
  1022. goto out_destroy_ctl_sock;
  1023. out:
  1024. return err;
  1025. out_destroy_ctl_sock:
  1026. inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1027. inet6_unregister_protosw(&dccp_v6_protosw);
  1028. out_unregister_proto:
  1029. proto_unregister(&dccp_v6_prot);
  1030. goto out;
  1031. }
  1032. static void __exit dccp_v6_exit(void)
  1033. {
  1034. unregister_pernet_subsys(&dccp_v6_ops);
  1035. inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1036. inet6_unregister_protosw(&dccp_v6_protosw);
  1037. proto_unregister(&dccp_v6_prot);
  1038. }
  1039. module_init(dccp_v6_init);
  1040. module_exit(dccp_v6_exit);
  1041. /*
  1042. * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
  1043. * values directly, Also cover the case where the protocol is not specified,
  1044. * i.e. net-pf-PF_INET6-proto-0-type-SOCK_DCCP
  1045. */
  1046. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET6, 33, 6);
  1047. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET6, 0, 6);
  1048. MODULE_LICENSE("GPL");
  1049. MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
  1050. MODULE_DESCRIPTION("DCCPv6 - Datagram Congestion Controlled Protocol");