ipv6.c 32 KB

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