ipv6.c 32 KB

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