ipv6.c 31 KB

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