ipv6.c 32 KB

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