ipv6.c 31 KB

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