ipv6.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  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. /* The per-net dccp.v6_ctl_sk is used for sending RSTs and ACKs */
  33. static struct inet_connection_sock_af_ops dccp_ipv6_mapped;
  34. static struct inet_connection_sock_af_ops dccp_ipv6_af_ops;
  35. static void dccp_v6_hash(struct sock *sk)
  36. {
  37. if (sk->sk_state != DCCP_CLOSED) {
  38. if (inet_csk(sk)->icsk_af_ops == &dccp_ipv6_mapped) {
  39. inet_hash(sk);
  40. return;
  41. }
  42. local_bh_disable();
  43. __inet6_hash(sk);
  44. local_bh_enable();
  45. }
  46. }
  47. /* add pseudo-header to DCCP checksum stored in skb->csum */
  48. static inline __sum16 dccp_v6_csum_finish(struct sk_buff *skb,
  49. struct in6_addr *saddr,
  50. struct in6_addr *daddr)
  51. {
  52. return csum_ipv6_magic(saddr, daddr, skb->len, IPPROTO_DCCP, skb->csum);
  53. }
  54. static inline void dccp_v6_send_check(struct sock *sk, int unused_value,
  55. struct sk_buff *skb)
  56. {
  57. struct ipv6_pinfo *np = inet6_sk(sk);
  58. struct dccp_hdr *dh = dccp_hdr(skb);
  59. dccp_csum_outgoing(skb);
  60. dh->dccph_checksum = dccp_v6_csum_finish(skb, &np->saddr, &np->daddr);
  61. }
  62. static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
  63. __be16 sport, __be16 dport )
  64. {
  65. return secure_tcpv6_sequence_number(saddr, daddr, sport, dport);
  66. }
  67. static inline __u32 dccp_v6_init_sequence(struct sk_buff *skb)
  68. {
  69. return secure_dccpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32,
  70. ipv6_hdr(skb)->saddr.s6_addr32,
  71. dccp_hdr(skb)->dccph_dport,
  72. dccp_hdr(skb)->dccph_sport );
  73. }
  74. static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
  75. int type, int code, int offset, __be32 info)
  76. {
  77. struct ipv6hdr *hdr = (struct ipv6hdr *)skb->data;
  78. const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
  79. struct ipv6_pinfo *np;
  80. struct sock *sk;
  81. int err;
  82. __u64 seq;
  83. sk = inet6_lookup(dev_net(skb->dev), &dccp_hashinfo,
  84. &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. {
  192. struct inet6_request_sock *ireq6 = inet6_rsk(req);
  193. struct ipv6_pinfo *np = inet6_sk(sk);
  194. struct sk_buff *skb;
  195. struct ipv6_txoptions *opt = NULL;
  196. struct in6_addr *final_p = NULL, final;
  197. struct flowi fl;
  198. int err = -1;
  199. struct dst_entry *dst;
  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. opt = np->opt;
  210. if (opt != NULL && opt->srcrt != NULL) {
  211. const struct rt0_hdr *rt0 = (struct rt0_hdr *)opt->srcrt;
  212. ipv6_addr_copy(&final, &fl.fl6_dst);
  213. ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
  214. final_p = &final;
  215. }
  216. err = ip6_dst_lookup(sk, &dst, &fl);
  217. if (err)
  218. goto done;
  219. if (final_p)
  220. ipv6_addr_copy(&fl.fl6_dst, final_p);
  221. err = xfrm_lookup(&dst, &fl, sk, 0);
  222. if (err < 0)
  223. goto done;
  224. skb = dccp_make_response(sk, dst, req);
  225. if (skb != NULL) {
  226. struct dccp_hdr *dh = dccp_hdr(skb);
  227. dh->dccph_checksum = dccp_v6_csum_finish(skb,
  228. &ireq6->loc_addr,
  229. &ireq6->rmt_addr);
  230. ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
  231. err = ip6_xmit(sk, skb, &fl, opt, 0);
  232. err = net_xmit_eval(err);
  233. }
  234. done:
  235. if (opt != NULL && opt != np->opt)
  236. sock_kfree_s(sk, opt, opt->tot_len);
  237. dst_release(dst);
  238. return err;
  239. }
  240. static void dccp_v6_reqsk_destructor(struct request_sock *req)
  241. {
  242. if (inet6_rsk(req)->pktopts != NULL)
  243. kfree_skb(inet6_rsk(req)->pktopts);
  244. }
  245. static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
  246. {
  247. struct ipv6hdr *rxip6h;
  248. struct sk_buff *skb;
  249. struct flowi fl;
  250. struct net *net = dev_net(rxskb->dst->dev);
  251. struct sock *ctl_sk = net->dccp.v6_ctl_sk;
  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(ctl_sk, 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(ctl_sk, &skb->dst, &fl)) {
  272. if (xfrm_lookup(&skb->dst, &fl, NULL, 0) >= 0) {
  273. ip6_xmit(ctl_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(sock_net(sk), &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))
  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(dev_net(skb->dst->dev), &dccp_hashinfo,
  662. &ipv6_hdr(skb)->saddr, 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. static struct proto dccp_v6_prot = {
  923. .name = "DCCPv6",
  924. .owner = THIS_MODULE,
  925. .close = dccp_close,
  926. .connect = dccp_v6_connect,
  927. .disconnect = dccp_disconnect,
  928. .ioctl = dccp_ioctl,
  929. .init = dccp_v6_init_sock,
  930. .setsockopt = dccp_setsockopt,
  931. .getsockopt = dccp_getsockopt,
  932. .sendmsg = dccp_sendmsg,
  933. .recvmsg = dccp_recvmsg,
  934. .backlog_rcv = dccp_v6_do_rcv,
  935. .hash = dccp_v6_hash,
  936. .unhash = inet_unhash,
  937. .accept = inet_csk_accept,
  938. .get_port = inet_csk_get_port,
  939. .shutdown = dccp_shutdown,
  940. .destroy = dccp_v6_destroy_sock,
  941. .orphan_count = &dccp_orphan_count,
  942. .max_header = MAX_DCCP_HEADER,
  943. .obj_size = sizeof(struct dccp6_sock),
  944. .rsk_prot = &dccp6_request_sock_ops,
  945. .twsk_prot = &dccp6_timewait_sock_ops,
  946. .h.hashinfo = &dccp_hashinfo,
  947. #ifdef CONFIG_COMPAT
  948. .compat_setsockopt = compat_dccp_setsockopt,
  949. .compat_getsockopt = compat_dccp_getsockopt,
  950. #endif
  951. };
  952. static struct inet6_protocol dccp_v6_protocol = {
  953. .handler = dccp_v6_rcv,
  954. .err_handler = dccp_v6_err,
  955. .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
  956. };
  957. static struct proto_ops inet6_dccp_ops = {
  958. .family = PF_INET6,
  959. .owner = THIS_MODULE,
  960. .release = inet6_release,
  961. .bind = inet6_bind,
  962. .connect = inet_stream_connect,
  963. .socketpair = sock_no_socketpair,
  964. .accept = inet_accept,
  965. .getname = inet6_getname,
  966. .poll = dccp_poll,
  967. .ioctl = inet6_ioctl,
  968. .listen = inet_dccp_listen,
  969. .shutdown = inet_shutdown,
  970. .setsockopt = sock_common_setsockopt,
  971. .getsockopt = sock_common_getsockopt,
  972. .sendmsg = inet_sendmsg,
  973. .recvmsg = sock_common_recvmsg,
  974. .mmap = sock_no_mmap,
  975. .sendpage = sock_no_sendpage,
  976. #ifdef CONFIG_COMPAT
  977. .compat_setsockopt = compat_sock_common_setsockopt,
  978. .compat_getsockopt = compat_sock_common_getsockopt,
  979. #endif
  980. };
  981. static struct inet_protosw dccp_v6_protosw = {
  982. .type = SOCK_DCCP,
  983. .protocol = IPPROTO_DCCP,
  984. .prot = &dccp_v6_prot,
  985. .ops = &inet6_dccp_ops,
  986. .capability = -1,
  987. .flags = INET_PROTOSW_ICSK,
  988. };
  989. static int dccp_v6_init_net(struct net *net)
  990. {
  991. int err;
  992. err = inet_ctl_sock_create(&net->dccp.v6_ctl_sk, PF_INET6,
  993. SOCK_DCCP, IPPROTO_DCCP, net);
  994. return err;
  995. }
  996. static void dccp_v6_exit_net(struct net *net)
  997. {
  998. inet_ctl_sock_destroy(net->dccp.v6_ctl_sk);
  999. }
  1000. static struct pernet_operations dccp_v6_ops = {
  1001. .init = dccp_v6_init_net,
  1002. .exit = dccp_v6_exit_net,
  1003. };
  1004. static int __init dccp_v6_init(void)
  1005. {
  1006. int err = proto_register(&dccp_v6_prot, 1);
  1007. if (err != 0)
  1008. goto out;
  1009. err = inet6_add_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1010. if (err != 0)
  1011. goto out_unregister_proto;
  1012. inet6_register_protosw(&dccp_v6_protosw);
  1013. err = register_pernet_subsys(&dccp_v6_ops);
  1014. if (err != 0)
  1015. goto out_destroy_ctl_sock;
  1016. out:
  1017. return err;
  1018. out_destroy_ctl_sock:
  1019. inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1020. inet6_unregister_protosw(&dccp_v6_protosw);
  1021. out_unregister_proto:
  1022. proto_unregister(&dccp_v6_prot);
  1023. goto out;
  1024. }
  1025. static void __exit dccp_v6_exit(void)
  1026. {
  1027. unregister_pernet_subsys(&dccp_v6_ops);
  1028. inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP);
  1029. inet6_unregister_protosw(&dccp_v6_protosw);
  1030. proto_unregister(&dccp_v6_prot);
  1031. }
  1032. module_init(dccp_v6_init);
  1033. module_exit(dccp_v6_exit);
  1034. /*
  1035. * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33)
  1036. * values directly, Also cover the case where the protocol is not specified,
  1037. * i.e. net-pf-PF_INET6-proto-0-type-SOCK_DCCP
  1038. */
  1039. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET6, 33, 6);
  1040. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET6, 0, 6);
  1041. MODULE_LICENSE("GPL");
  1042. MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@mandriva.com>");
  1043. MODULE_DESCRIPTION("DCCPv6 - Datagram Congestion Controlled Protocol");