ipv6.c 32 KB

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