ipv6.c 32 KB

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