ipv6.c 31 KB

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