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