ipv6.c 33 KB

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