ipv6.c 32 KB

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