ipv6.c 32 KB

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