ipv6.c 32 KB

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