ipv6.c 32 KB

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