ipv6.c 31 KB

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