ipv6.c 32 KB

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