ipv6.c 31 KB

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