ipv6.c 32 KB

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