ipv6.c 33 KB

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