ipv6.c 32 KB

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