ipv6.c 32 KB

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