ipv6.c 33 KB

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