ipv6.c 33 KB

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