ipv6.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  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. static void dccp_v6_ctl_send_reset(struct sk_buff *skb);
  33. static void dccp_v6_reqsk_send_ack(struct sk_buff *skb,
  34. struct request_sock *req);
  35. static void dccp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb);
  36. static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb);
  37. static struct inet_connection_sock_af_ops dccp_ipv6_mapped;
  38. static struct inet_connection_sock_af_ops dccp_ipv6_af_ops;
  39. static int dccp_v6_get_port(struct sock *sk, unsigned short snum)
  40. {
  41. return inet_csk_get_port(&dccp_hashinfo, sk, snum,
  42. inet6_csk_bind_conflict);
  43. }
  44. static void dccp_v6_hash(struct sock *sk)
  45. {
  46. if (sk->sk_state != DCCP_CLOSED) {
  47. if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) {
  48. dccp_prot.hash(sk);
  49. return;
  50. }
  51. local_bh_disable();
  52. __inet6_hash(&dccp_hashinfo, sk);
  53. local_bh_enable();
  54. }
  55. }
  56. static inline u16 dccp_v6_check(struct dccp_hdr *dh, int len,
  57. struct in6_addr *saddr,
  58. struct in6_addr *daddr,
  59. unsigned long base)
  60. {
  61. return csum_ipv6_magic(saddr, daddr, len, IPPROTO_DCCP, base);
  62. }
  63. static __u32 dccp_v6_init_sequence(struct sock *sk, struct sk_buff *skb)
  64. {
  65. const struct dccp_hdr *dh = dccp_hdr(skb);
  66. if (skb->protocol == htons(ETH_P_IPV6))
  67. return secure_tcpv6_sequence_number(skb->nh.ipv6h->daddr.s6_addr32,
  68. skb->nh.ipv6h->saddr.s6_addr32,
  69. dh->dccph_dport,
  70. dh->dccph_sport);
  71. else
  72. return secure_dccp_sequence_number(skb->nh.iph->daddr,
  73. skb->nh.iph->saddr,
  74. dh->dccph_dport,
  75. dh->dccph_sport);
  76. }
  77. static int dccp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
  78. int addr_len)
  79. {
  80. struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr;
  81. struct inet_connection_sock *icsk = inet_csk(sk);
  82. struct inet_sock *inet = inet_sk(sk);
  83. struct ipv6_pinfo *np = inet6_sk(sk);
  84. struct dccp_sock *dp = dccp_sk(sk);
  85. struct in6_addr *saddr = NULL, *final_p = NULL, final;
  86. struct flowi fl;
  87. struct dst_entry *dst;
  88. int addr_type;
  89. int err;
  90. dp->dccps_role = DCCP_ROLE_CLIENT;
  91. if (addr_len < SIN6_LEN_RFC2133)
  92. return -EINVAL;
  93. if (usin->sin6_family != AF_INET6)
  94. return -EAFNOSUPPORT;
  95. memset(&fl, 0, sizeof(fl));
  96. if (np->sndflow) {
  97. fl.fl6_flowlabel = usin->sin6_flowinfo & IPV6_FLOWINFO_MASK;
  98. IP6_ECN_flow_init(fl.fl6_flowlabel);
  99. if (fl.fl6_flowlabel & IPV6_FLOWLABEL_MASK) {
  100. struct ip6_flowlabel *flowlabel;
  101. flowlabel = fl6_sock_lookup(sk, fl.fl6_flowlabel);
  102. if (flowlabel == NULL)
  103. return -EINVAL;
  104. ipv6_addr_copy(&usin->sin6_addr, &flowlabel->dst);
  105. fl6_sock_release(flowlabel);
  106. }
  107. }
  108. /*
  109. * connect() to INADDR_ANY means loopback (BSD'ism).
  110. */
  111. if (ipv6_addr_any(&usin->sin6_addr))
  112. usin->sin6_addr.s6_addr[15] = 0x1;
  113. addr_type = ipv6_addr_type(&usin->sin6_addr);
  114. if(addr_type & IPV6_ADDR_MULTICAST)
  115. return -ENETUNREACH;
  116. if (addr_type & IPV6_ADDR_LINKLOCAL) {
  117. if (addr_len >= sizeof(struct sockaddr_in6) &&
  118. usin->sin6_scope_id) {
  119. /* If interface is set while binding, indices
  120. * must coincide.
  121. */
  122. if (sk->sk_bound_dev_if &&
  123. sk->sk_bound_dev_if != usin->sin6_scope_id)
  124. return -EINVAL;
  125. sk->sk_bound_dev_if = usin->sin6_scope_id;
  126. }
  127. /* Connect to link-local address requires an interface */
  128. if (!sk->sk_bound_dev_if)
  129. return -EINVAL;
  130. }
  131. ipv6_addr_copy(&np->daddr, &usin->sin6_addr);
  132. np->flow_label = fl.fl6_flowlabel;
  133. /*
  134. * DCCP over IPv4
  135. */
  136. if (addr_type == IPV6_ADDR_MAPPED) {
  137. u32 exthdrlen = icsk->icsk_ext_hdr_len;
  138. struct sockaddr_in sin;
  139. SOCK_DEBUG(sk, "connect: ipv4 mapped\n");
  140. if (__ipv6_only_sock(sk))
  141. return -ENETUNREACH;
  142. sin.sin_family = AF_INET;
  143. sin.sin_port = usin->sin6_port;
  144. sin.sin_addr.s_addr = usin->sin6_addr.s6_addr32[3];
  145. icsk->icsk_af_ops = &dccp_ipv6_mapped;
  146. sk->sk_backlog_rcv = dccp_v4_do_rcv;
  147. err = dccp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin));
  148. if (err) {
  149. icsk->icsk_ext_hdr_len = exthdrlen;
  150. icsk->icsk_af_ops = &dccp_ipv6_af_ops;
  151. sk->sk_backlog_rcv = dccp_v6_do_rcv;
  152. goto failure;
  153. } else {
  154. ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000FFFF),
  155. inet->saddr);
  156. ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000FFFF),
  157. inet->rcv_saddr);
  158. }
  159. return err;
  160. }
  161. if (!ipv6_addr_any(&np->rcv_saddr))
  162. saddr = &np->rcv_saddr;
  163. fl.proto = IPPROTO_DCCP;
  164. ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
  165. ipv6_addr_copy(&fl.fl6_src, saddr ? saddr : &np->saddr);
  166. fl.oif = sk->sk_bound_dev_if;
  167. fl.fl_ip_dport = usin->sin6_port;
  168. fl.fl_ip_sport = inet->sport;
  169. if (np->opt && np->opt->srcrt) {
  170. struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt;
  171. ipv6_addr_copy(&final, &fl.fl6_dst);
  172. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  173. final_p = &final;
  174. }
  175. err = ip6_dst_lookup(sk, &dst, &fl);
  176. if (err)
  177. goto failure;
  178. if (final_p)
  179. ipv6_addr_copy(&fl.fl6_dst, final_p);
  180. if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0)
  181. goto failure;
  182. if (saddr == NULL) {
  183. saddr = &fl.fl6_src;
  184. ipv6_addr_copy(&np->rcv_saddr, saddr);
  185. }
  186. /* set the source address */
  187. ipv6_addr_copy(&np->saddr, saddr);
  188. inet->rcv_saddr = LOOPBACK4_IPV6;
  189. ip6_dst_store(sk, dst, NULL);
  190. icsk->icsk_ext_hdr_len = 0;
  191. if (np->opt)
  192. icsk->icsk_ext_hdr_len = (np->opt->opt_flen +
  193. np->opt->opt_nflen);
  194. inet->dport = usin->sin6_port;
  195. dccp_set_state(sk, DCCP_REQUESTING);
  196. err = inet6_hash_connect(&dccp_death_row, sk);
  197. if (err)
  198. goto late_failure;
  199. /* FIXME */
  200. #if 0
  201. dp->dccps_gar = secure_dccp_v6_sequence_number(np->saddr.s6_addr32,
  202. np->daddr.s6_addr32,
  203. inet->sport,
  204. inet->dport);
  205. #endif
  206. err = dccp_connect(sk);
  207. if (err)
  208. goto late_failure;
  209. return 0;
  210. late_failure:
  211. dccp_set_state(sk, DCCP_CLOSED);
  212. __sk_dst_reset(sk);
  213. failure:
  214. inet->dport = 0;
  215. sk->sk_route_caps = 0;
  216. return err;
  217. }
  218. static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  219. int type, int code, int offset, __u32 info)
  220. {
  221. struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
  222. const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
  223. struct ipv6_pinfo *np;
  224. struct sock *sk;
  225. int err;
  226. __u64 seq;
  227. sk = inet6_lookup(&dccp_hashinfo, &hdr->daddr, dh->dccph_dport,
  228. &hdr->saddr, dh->dccph_sport, skb->dev->ifindex);
  229. if (sk == NULL) {
  230. ICMP6_INC_STATS_BH(__in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
  231. return;
  232. }
  233. if (sk->sk_state == DCCP_TIME_WAIT) {
  234. inet_twsk_put((struct inet_timewait_sock *)sk);
  235. return;
  236. }
  237. bh_lock_sock(sk);
  238. if (sock_owned_by_user(sk))
  239. NET_INC_STATS_BH(LINUX_MIB_LOCKDROPPEDICMPS);
  240. if (sk->sk_state == DCCP_CLOSED)
  241. goto out;
  242. np = inet6_sk(sk);
  243. if (type == ICMPV6_PKT_TOOBIG) {
  244. struct dst_entry *dst = NULL;
  245. if (sock_owned_by_user(sk))
  246. goto out;
  247. if ((1 << sk->sk_state) & (DCCPF_LISTEN | DCCPF_CLOSED))
  248. goto out;
  249. /* icmp should have updated the destination cache entry */
  250. dst = __sk_dst_check(sk, np->dst_cookie);
  251. if (dst == NULL) {
  252. struct inet_sock *inet = inet_sk(sk);
  253. struct flowi fl;
  254. /* BUGGG_FUTURE: Again, it is not clear how
  255. to handle rthdr case. Ignore this complexity
  256. for now.
  257. */
  258. memset(&fl, 0, sizeof(fl));
  259. fl.proto = IPPROTO_DCCP;
  260. ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
  261. ipv6_addr_copy(&fl.fl6_src, &np->saddr);
  262. fl.oif = sk->sk_bound_dev_if;
  263. fl.fl_ip_dport = inet->dport;
  264. fl.fl_ip_sport = inet->sport;
  265. if ((err = ip6_dst_lookup(sk, &dst, &fl))) {
  266. sk->sk_err_soft = -err;
  267. goto out;
  268. }
  269. if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) {
  270. sk->sk_err_soft = -err;
  271. goto out;
  272. }
  273. } else
  274. dst_hold(dst);
  275. if (inet_csk(sk)->icsk_pmtu_cookie > dst_mtu(dst)) {
  276. dccp_sync_mss(sk, dst_mtu(dst));
  277. } /* else let the usual retransmit timer handle it */
  278. dst_release(dst);
  279. goto out;
  280. }
  281. icmpv6_err_convert(type, code, &err);
  282. seq = DCCP_SKB_CB(skb)->dccpd_seq;
  283. /* Might be for an request_sock */
  284. switch (sk->sk_state) {
  285. struct request_sock *req, **prev;
  286. case DCCP_LISTEN:
  287. if (sock_owned_by_user(sk))
  288. goto out;
  289. req = inet6_csk_search_req(sk, &prev, dh->dccph_dport,
  290. &hdr->daddr, &hdr->saddr,
  291. inet6_iif(skb));
  292. if (!req)
  293. goto out;
  294. /* ICMPs are not backlogged, hence we cannot get
  295. * an established socket here.
  296. */
  297. BUG_TRAP(req->sk == NULL);
  298. if (seq != dccp_rsk(req)->dreq_iss) {
  299. NET_INC_STATS_BH(LINUX_MIB_OUTOFWINDOWICMPS);
  300. goto out;
  301. }
  302. inet_csk_reqsk_queue_drop(sk, req, prev);
  303. goto out;
  304. case DCCP_REQUESTING:
  305. case DCCP_RESPOND: /* Cannot happen.
  306. It can, it SYNs are crossed. --ANK */
  307. if (!sock_owned_by_user(sk)) {
  308. DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS);
  309. sk->sk_err = err;
  310. /*
  311. * Wake people up to see the error
  312. * (see connect in sock.c)
  313. */
  314. sk->sk_error_report(sk);
  315. dccp_done(sk);
  316. } else
  317. sk->sk_err_soft = err;
  318. goto out;
  319. }
  320. if (!sock_owned_by_user(sk) && np->recverr) {
  321. sk->sk_err = err;
  322. sk->sk_error_report(sk);
  323. } else
  324. sk->sk_err_soft = err;
  325. out:
  326. bh_unlock_sock(sk);
  327. sock_put(sk);
  328. }
  329. static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
  330. struct dst_entry *dst)
  331. {
  332. struct inet6_request_sock *ireq6 = inet6_rsk(req);
  333. struct ipv6_pinfo *np = inet6_sk(sk);
  334. struct sk_buff *skb;
  335. struct ipv6_txoptions *opt = NULL;
  336. struct in6_addr *final_p = NULL, final;
  337. struct flowi fl;
  338. int err = -1;
  339. memset(&fl, 0, sizeof(fl));
  340. fl.proto = IPPROTO_DCCP;
  341. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  342. ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
  343. fl.fl6_flowlabel = 0;
  344. fl.oif = ireq6->iif;
  345. fl.fl_ip_dport = inet_rsk(req)->rmt_port;
  346. fl.fl_ip_sport = inet_sk(sk)->sport;
  347. if (dst == NULL) {
  348. opt = np->opt;
  349. if (opt == NULL &&
  350. np->rxopt.bits.osrcrt == 2 &&
  351. ireq6->pktopts) {
  352. struct sk_buff *pktopts = ireq6->pktopts;
  353. struct inet6_skb_parm *rxopt = IP6CB(pktopts);
  354. if (rxopt->srcrt)
  355. opt = ipv6_invert_rthdr(sk,
  356. (struct ipv6_rt_hdr *)(pktopts->nh.raw +
  357. rxopt->srcrt));
  358. }
  359. if (opt && opt->srcrt) {
  360. struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
  361. ipv6_addr_copy(&final, &fl.fl6_dst);
  362. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  363. final_p = &final;
  364. }
  365. err = ip6_dst_lookup(sk, &dst, &fl);
  366. if (err)
  367. goto done;
  368. if (final_p)
  369. ipv6_addr_copy(&fl.fl6_dst, final_p);
  370. if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0)
  371. goto done;
  372. }
  373. skb = dccp_make_response(sk, dst, req);
  374. if (skb != NULL) {
  375. struct dccp_hdr *dh = dccp_hdr(skb);
  376. dh->dccph_checksum = dccp_v6_check(dh, skb->len,
  377. &ireq6->loc_addr,
  378. &ireq6->rmt_addr,
  379. csum_partial((char *)dh,
  380. skb->len,
  381. skb->csum));
  382. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  383. err = ip6_xmit(sk, skb, &fl, opt, 0);
  384. if (err == NET_XMIT_CN)
  385. err = 0;
  386. }
  387. done:
  388. if (opt && opt != np->opt)
  389. sock_kfree_s(sk, opt, opt->tot_len);
  390. dst_release(dst);
  391. return err;
  392. }
  393. static void dccp_v6_reqsk_destructor(struct request_sock *req)
  394. {
  395. if (inet6_rsk(req)->pktopts != NULL)
  396. kfree_skb(inet6_rsk(req)->pktopts);
  397. }
  398. static struct request_sock_ops dccp6_request_sock_ops = {
  399. .family = AF_INET6,
  400. .obj_size = sizeof(struct dccp6_request_sock),
  401. .rtx_syn_ack = dccp_v6_send_response,
  402. .send_ack = dccp_v6_reqsk_send_ack,
  403. .destructor = dccp_v6_reqsk_destructor,
  404. .send_reset = dccp_v6_ctl_send_reset,
  405. };
  406. static struct timewait_sock_ops dccp6_timewait_sock_ops = {
  407. .twsk_obj_size = sizeof(struct dccp6_timewait_sock),
  408. };
  409. static void dccp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb)
  410. {
  411. struct ipv6_pinfo *np = inet6_sk(sk);
  412. struct dccp_hdr *dh = dccp_hdr(skb);
  413. dh->dccph_checksum = csum_ipv6_magic(&np->saddr, &np->daddr,
  414. len, IPPROTO_DCCP,
  415. csum_partial((char *)dh,
  416. dh->dccph_doff << 2,
  417. skb->csum));
  418. }
  419. static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
  420. {
  421. struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh;
  422. const int dccp_hdr_reset_len = sizeof(struct dccp_hdr) +
  423. sizeof(struct dccp_hdr_ext) +
  424. sizeof(struct dccp_hdr_reset);
  425. struct sk_buff *skb;
  426. struct flowi fl;
  427. u64 seqno;
  428. if (rxdh->dccph_type == DCCP_PKT_RESET)
  429. return;
  430. if (!ipv6_unicast_destination(rxskb))
  431. return;
  432. /*
  433. * We need to grab some memory, and put together an RST,
  434. * and then put it into the queue to be sent.
  435. */
  436. skb = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) +
  437. dccp_hdr_reset_len, GFP_ATOMIC);
  438. if (skb == NULL)
  439. return;
  440. skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr) +
  441. dccp_hdr_reset_len);
  442. skb->h.raw = skb_push(skb, dccp_hdr_reset_len);
  443. dh = dccp_hdr(skb);
  444. memset(dh, 0, dccp_hdr_reset_len);
  445. /* Swap the send and the receive. */
  446. dh->dccph_type = DCCP_PKT_RESET;
  447. dh->dccph_sport = rxdh->dccph_dport;
  448. dh->dccph_dport = rxdh->dccph_sport;
  449. dh->dccph_doff = dccp_hdr_reset_len / 4;
  450. dh->dccph_x = 1;
  451. dccp_hdr_reset(skb)->dccph_reset_code =
  452. DCCP_SKB_CB(rxskb)->dccpd_reset_code;
  453. /* See "8.3.1. Abnormal Termination" in draft-ietf-dccp-spec-11 */
  454. seqno = 0;
  455. if (DCCP_SKB_CB(rxskb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
  456. dccp_set_seqno(&seqno, DCCP_SKB_CB(rxskb)->dccpd_ack_seq + 1);
  457. dccp_hdr_set_seq(dh, seqno);
  458. dccp_hdr_set_ack(dccp_hdr_ack_bits(skb),
  459. DCCP_SKB_CB(rxskb)->dccpd_seq);
  460. memset(&fl, 0, sizeof(fl));
  461. ipv6_addr_copy(&fl.fl6_dst, &rxskb->nh.ipv6h->saddr);
  462. ipv6_addr_copy(&fl.fl6_src, &rxskb->nh.ipv6h->daddr);
  463. dh->dccph_checksum = csum_ipv6_magic(&fl.fl6_src, &fl.fl6_dst,
  464. sizeof(*dh), IPPROTO_DCCP,
  465. skb->csum);
  466. fl.proto = IPPROTO_DCCP;
  467. fl.oif = inet6_iif(rxskb);
  468. fl.fl_ip_dport = dh->dccph_dport;
  469. fl.fl_ip_sport = dh->dccph_sport;
  470. /* sk = NULL, but it is safe for now. RST socket required. */
  471. if (!ip6_dst_lookup(NULL, &skb->dst, &fl)) {
  472. if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
  473. ip6_xmit(NULL, skb, &fl, NULL, 0);
  474. DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
  475. DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
  476. return;
  477. }
  478. }
  479. kfree_skb(skb);
  480. }
  481. static void dccp_v6_ctl_send_ack(struct sk_buff *rxskb)
  482. {
  483. struct flowi fl;
  484. struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh;
  485. const int dccp_hdr_ack_len = sizeof(struct dccp_hdr) +
  486. sizeof(struct dccp_hdr_ext) +
  487. sizeof(struct dccp_hdr_ack_bits);
  488. struct sk_buff *skb;
  489. skb = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) +
  490. dccp_hdr_ack_len, GFP_ATOMIC);
  491. if (skb == NULL)
  492. return;
  493. skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr) +
  494. dccp_hdr_ack_len);
  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(NULL, 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 __u32 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 &&
  681. opt == NULL && ireq6->pktopts) {
  682. struct inet6_skb_parm *rxopt = IP6CB(ireq6->pktopts);
  683. if (rxopt->srcrt)
  684. opt = ipv6_invert_rthdr(sk,
  685. (struct ipv6_rt_hdr *)(ireq6->pktopts->nh.raw +
  686. rxopt->srcrt));
  687. }
  688. if (dst == NULL) {
  689. struct in6_addr *final_p = NULL, final;
  690. struct flowi fl;
  691. memset(&fl, 0, sizeof(fl));
  692. fl.proto = IPPROTO_DCCP;
  693. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  694. if (opt && opt->srcrt) {
  695. struct rt0_hdr *rt0 = (struct rt0_hdr *) opt->srcrt;
  696. ipv6_addr_copy(&final, &fl.fl6_dst);
  697. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  698. final_p = &final;
  699. }
  700. ipv6_addr_copy(&fl.fl6_src, &ireq6->loc_addr);
  701. fl.oif = sk->sk_bound_dev_if;
  702. fl.fl_ip_dport = inet_rsk(req)->rmt_port;
  703. fl.fl_ip_sport = inet_sk(sk)->sport;
  704. if (ip6_dst_lookup(sk, &dst, &fl))
  705. goto out;
  706. if (final_p)
  707. ipv6_addr_copy(&fl.fl6_dst, final_p);
  708. if ((xfrm_lookup(&dst, &fl, sk, 0)) < 0)
  709. goto out;
  710. }
  711. newsk = dccp_create_openreq_child(sk, req, skb);
  712. if (newsk == NULL)
  713. goto out;
  714. /*
  715. * No need to charge this sock to the relevant IPv6 refcnt debug socks
  716. * count here, dccp_create_openreq_child now does this for us, see the
  717. * comment in that function for the gory details. -acme
  718. */
  719. ip6_dst_store(newsk, dst, NULL);
  720. newsk->sk_route_caps = dst->dev->features &
  721. ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
  722. newdp6 = (struct dccp6_sock *)newsk;
  723. newinet = inet_sk(newsk);
  724. newinet->pinet6 = &newdp6->inet6;
  725. newdp = dccp_sk(newsk);
  726. newnp = inet6_sk(newsk);
  727. memcpy(newnp, np, sizeof(struct ipv6_pinfo));
  728. ipv6_addr_copy(&newnp->daddr, &ireq6->rmt_addr);
  729. ipv6_addr_copy(&newnp->saddr, &ireq6->loc_addr);
  730. ipv6_addr_copy(&newnp->rcv_saddr, &ireq6->loc_addr);
  731. newsk->sk_bound_dev_if = ireq6->iif;
  732. /* Now IPv6 options...
  733. First: no IPv4 options.
  734. */
  735. newinet->opt = NULL;
  736. /* Clone RX bits */
  737. newnp->rxopt.all = np->rxopt.all;
  738. /* Clone pktoptions received with SYN */
  739. newnp->pktoptions = NULL;
  740. if (ireq6->pktopts != NULL) {
  741. newnp->pktoptions = skb_clone(ireq6->pktopts, GFP_ATOMIC);
  742. kfree_skb(ireq6->pktopts);
  743. ireq6->pktopts = NULL;
  744. if (newnp->pktoptions)
  745. skb_set_owner_r(newnp->pktoptions, newsk);
  746. }
  747. newnp->opt = NULL;
  748. newnp->mcast_oif = inet6_iif(skb);
  749. newnp->mcast_hops = skb->nh.ipv6h->hop_limit;
  750. /* Clone native IPv6 options from listening socket (if any)
  751. Yes, keeping reference count would be much more clever,
  752. but we make one more one thing there: reattach optmem
  753. to newsk.
  754. */
  755. if (opt) {
  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)
  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 && 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
  803. * is currently 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)
  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)
  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)
  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. int err = dccp_v4_init_sock(sk);
  950. if (err == 0)
  951. inet_csk(sk)->icsk_af_ops = &dccp_ipv6_af_ops;
  952. return err;
  953. }
  954. static int dccp_v6_destroy_sock(struct sock *sk)
  955. {
  956. dccp_v4_destroy_sock(sk);
  957. return inet6_destroy_sock(sk);
  958. }
  959. static struct proto dccp_v6_prot = {
  960. .name = "DCCPv6",
  961. .owner = THIS_MODULE,
  962. .close = dccp_close,
  963. .connect = dccp_v6_connect,
  964. .disconnect = dccp_disconnect,
  965. .ioctl = dccp_ioctl,
  966. .init = dccp_v6_init_sock,
  967. .setsockopt = dccp_setsockopt,
  968. .getsockopt = dccp_getsockopt,
  969. .sendmsg = dccp_sendmsg,
  970. .recvmsg = dccp_recvmsg,
  971. .backlog_rcv = dccp_v6_do_rcv,
  972. .hash = dccp_v6_hash,
  973. .unhash = dccp_unhash,
  974. .accept = inet_csk_accept,
  975. .get_port = dccp_v6_get_port,
  976. .shutdown = dccp_shutdown,
  977. .destroy = dccp_v6_destroy_sock,
  978. .orphan_count = &dccp_orphan_count,
  979. .max_header = MAX_DCCP_HEADER,
  980. .obj_size = sizeof(struct dccp6_sock),
  981. .rsk_prot = &dccp6_request_sock_ops,
  982. .twsk_prot = &dccp6_timewait_sock_ops,
  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. };
  1009. static struct inet_protosw dccp_v6_protosw = {
  1010. .type = SOCK_DCCP,
  1011. .protocol = IPPROTO_DCCP,
  1012. .prot = &dccp_v6_prot,
  1013. .ops = &inet6_dccp_ops,
  1014. .capability = -1,
  1015. .flags = INET_PROTOSW_ICSK,
  1016. };
  1017. static int __init dccp_v6_init(void)
  1018. {
  1019. int err = proto_register(&dccp_v6_prot, 1);
  1020. if (err != 0)
  1021. goto out;
  1022. err = inet6_add_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1023. if (err != 0)
  1024. goto out_unregister_proto;
  1025. inet6_register_protosw(&dccp_v6_protosw);
  1026. out:
  1027. return err;
  1028. out_unregister_proto:
  1029. proto_unregister(&dccp_v6_prot);
  1030. goto out;
  1031. }
  1032. static void __exit dccp_v6_exit(void)
  1033. {
  1034. inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1035. inet6_unregister_protosw(&dccp_v6_protosw);
  1036. proto_unregister(&dccp_v6_prot);
  1037. }
  1038. module_init(dccp_v6_init);
  1039. module_exit(dccp_v6_exit);
  1040. /*
  1041. * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
  1042. * values directly, Also cover the case where the protocol is not specified,
  1043. * i.e. net-pf-PF_INET6-proto-0-type-SOCK_DCCP
  1044. */
  1045. MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-33-type-6");
  1046. MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-0-type-6");
  1047. MODULE_LICENSE("GPL");
  1048. MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
  1049. MODULE_DESCRIPTION("DCCPv6 - Datagram Congestion Controlled Protocol");