ipv6.c 31 KB

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