raw.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. /*
  2. * RAW sockets for IPv6
  3. * Linux INET6 implementation
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. * Adapted from linux/net/ipv4/raw.c
  9. *
  10. * Fixes:
  11. * Hideaki YOSHIFUJI : sin6_scope_id support
  12. * YOSHIFUJI,H.@USAGI : raw checksum (RFC2292(bis) compliance)
  13. * Kazunori MIYAZAWA @USAGI: change process style to use ip6_append_data
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/types.h>
  22. #include <linux/socket.h>
  23. #include <linux/slab.h>
  24. #include <linux/sockios.h>
  25. #include <linux/net.h>
  26. #include <linux/in6.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/if_arp.h>
  29. #include <linux/icmpv6.h>
  30. #include <linux/netfilter.h>
  31. #include <linux/netfilter_ipv6.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/compat.h>
  34. #include <linux/uaccess.h>
  35. #include <asm/ioctls.h>
  36. #include <net/net_namespace.h>
  37. #include <net/ip.h>
  38. #include <net/sock.h>
  39. #include <net/snmp.h>
  40. #include <net/ipv6.h>
  41. #include <net/ndisc.h>
  42. #include <net/protocol.h>
  43. #include <net/ip6_route.h>
  44. #include <net/ip6_checksum.h>
  45. #include <net/addrconf.h>
  46. #include <net/transp_v6.h>
  47. #include <net/udp.h>
  48. #include <net/inet_common.h>
  49. #include <net/tcp_states.h>
  50. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  51. #include <net/mip6.h>
  52. #endif
  53. #include <linux/mroute6.h>
  54. #include <net/raw.h>
  55. #include <net/rawv6.h>
  56. #include <net/xfrm.h>
  57. #include <linux/proc_fs.h>
  58. #include <linux/seq_file.h>
  59. #include <linux/export.h>
  60. #define ICMPV6_HDRLEN 4 /* ICMPv6 header, RFC 4443 Section 2.1 */
  61. static struct raw_hashinfo raw_v6_hashinfo = {
  62. .lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock),
  63. };
  64. static struct sock *__raw_v6_lookup(struct net *net, struct sock *sk,
  65. unsigned short num, const struct in6_addr *loc_addr,
  66. const struct in6_addr *rmt_addr, int dif)
  67. {
  68. bool is_multicast = ipv6_addr_is_multicast(loc_addr);
  69. sk_for_each_from(sk)
  70. if (inet_sk(sk)->inet_num == num) {
  71. if (!net_eq(sock_net(sk), net))
  72. continue;
  73. if (!ipv6_addr_any(&sk->sk_v6_daddr) &&
  74. !ipv6_addr_equal(&sk->sk_v6_daddr, rmt_addr))
  75. continue;
  76. if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)
  77. continue;
  78. if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
  79. if (ipv6_addr_equal(&sk->sk_v6_rcv_saddr, loc_addr))
  80. goto found;
  81. if (is_multicast &&
  82. inet6_mc_check(sk, loc_addr, rmt_addr))
  83. goto found;
  84. continue;
  85. }
  86. goto found;
  87. }
  88. sk = NULL;
  89. found:
  90. return sk;
  91. }
  92. /*
  93. * 0 - deliver
  94. * 1 - block
  95. */
  96. static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
  97. {
  98. struct icmp6hdr _hdr;
  99. const struct icmp6hdr *hdr;
  100. /* We require only the four bytes of the ICMPv6 header, not any
  101. * additional bytes of message body in "struct icmp6hdr".
  102. */
  103. hdr = skb_header_pointer(skb, skb_transport_offset(skb),
  104. ICMPV6_HDRLEN, &_hdr);
  105. if (hdr) {
  106. const __u32 *data = &raw6_sk(sk)->filter.data[0];
  107. unsigned int type = hdr->icmp6_type;
  108. return (data[type >> 5] & (1U << (type & 31))) != 0;
  109. }
  110. return 1;
  111. }
  112. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  113. typedef int mh_filter_t(struct sock *sock, struct sk_buff *skb);
  114. static mh_filter_t __rcu *mh_filter __read_mostly;
  115. int rawv6_mh_filter_register(mh_filter_t filter)
  116. {
  117. rcu_assign_pointer(mh_filter, filter);
  118. return 0;
  119. }
  120. EXPORT_SYMBOL(rawv6_mh_filter_register);
  121. int rawv6_mh_filter_unregister(mh_filter_t filter)
  122. {
  123. RCU_INIT_POINTER(mh_filter, NULL);
  124. synchronize_rcu();
  125. return 0;
  126. }
  127. EXPORT_SYMBOL(rawv6_mh_filter_unregister);
  128. #endif
  129. /*
  130. * demultiplex raw sockets.
  131. * (should consider queueing the skb in the sock receive_queue
  132. * without calling rawv6.c)
  133. *
  134. * Caller owns SKB so we must make clones.
  135. */
  136. static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
  137. {
  138. const struct in6_addr *saddr;
  139. const struct in6_addr *daddr;
  140. struct sock *sk;
  141. bool delivered = false;
  142. __u8 hash;
  143. struct net *net;
  144. saddr = &ipv6_hdr(skb)->saddr;
  145. daddr = saddr + 1;
  146. hash = nexthdr & (RAW_HTABLE_SIZE - 1);
  147. read_lock(&raw_v6_hashinfo.lock);
  148. sk = sk_head(&raw_v6_hashinfo.ht[hash]);
  149. if (!sk)
  150. goto out;
  151. net = dev_net(skb->dev);
  152. sk = __raw_v6_lookup(net, sk, nexthdr, daddr, saddr, inet6_iif(skb));
  153. while (sk) {
  154. int filtered;
  155. delivered = true;
  156. switch (nexthdr) {
  157. case IPPROTO_ICMPV6:
  158. filtered = icmpv6_filter(sk, skb);
  159. break;
  160. #if IS_ENABLED(CONFIG_IPV6_MIP6)
  161. case IPPROTO_MH:
  162. {
  163. /* XXX: To validate MH only once for each packet,
  164. * this is placed here. It should be after checking
  165. * xfrm policy, however it doesn't. The checking xfrm
  166. * policy is placed in rawv6_rcv() because it is
  167. * required for each socket.
  168. */
  169. mh_filter_t *filter;
  170. filter = rcu_dereference(mh_filter);
  171. filtered = filter ? (*filter)(sk, skb) : 0;
  172. break;
  173. }
  174. #endif
  175. default:
  176. filtered = 0;
  177. break;
  178. }
  179. if (filtered < 0)
  180. break;
  181. if (filtered == 0) {
  182. struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
  183. /* Not releasing hash table! */
  184. if (clone) {
  185. nf_reset(clone);
  186. rawv6_rcv(sk, clone);
  187. }
  188. }
  189. sk = __raw_v6_lookup(net, sk_next(sk), nexthdr, daddr, saddr,
  190. inet6_iif(skb));
  191. }
  192. out:
  193. read_unlock(&raw_v6_hashinfo.lock);
  194. return delivered;
  195. }
  196. bool raw6_local_deliver(struct sk_buff *skb, int nexthdr)
  197. {
  198. struct sock *raw_sk;
  199. raw_sk = sk_head(&raw_v6_hashinfo.ht[nexthdr & (RAW_HTABLE_SIZE - 1)]);
  200. if (raw_sk && !ipv6_raw_deliver(skb, nexthdr))
  201. raw_sk = NULL;
  202. return raw_sk != NULL;
  203. }
  204. /* This cleans up af_inet6 a bit. -DaveM */
  205. static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
  206. {
  207. struct inet_sock *inet = inet_sk(sk);
  208. struct ipv6_pinfo *np = inet6_sk(sk);
  209. struct sockaddr_in6 *addr = (struct sockaddr_in6 *) uaddr;
  210. __be32 v4addr = 0;
  211. int addr_type;
  212. int err;
  213. if (addr_len < SIN6_LEN_RFC2133)
  214. return -EINVAL;
  215. if (addr->sin6_family != AF_INET6)
  216. return -EINVAL;
  217. addr_type = ipv6_addr_type(&addr->sin6_addr);
  218. /* Raw sockets are IPv6 only */
  219. if (addr_type == IPV6_ADDR_MAPPED)
  220. return -EADDRNOTAVAIL;
  221. lock_sock(sk);
  222. err = -EINVAL;
  223. if (sk->sk_state != TCP_CLOSE)
  224. goto out;
  225. rcu_read_lock();
  226. /* Check if the address belongs to the host. */
  227. if (addr_type != IPV6_ADDR_ANY) {
  228. struct net_device *dev = NULL;
  229. if (__ipv6_addr_needs_scope_id(addr_type)) {
  230. if (addr_len >= sizeof(struct sockaddr_in6) &&
  231. addr->sin6_scope_id) {
  232. /* Override any existing binding, if another
  233. * one is supplied by user.
  234. */
  235. sk->sk_bound_dev_if = addr->sin6_scope_id;
  236. }
  237. /* Binding to link-local address requires an interface */
  238. if (!sk->sk_bound_dev_if)
  239. goto out_unlock;
  240. err = -ENODEV;
  241. dev = dev_get_by_index_rcu(sock_net(sk),
  242. sk->sk_bound_dev_if);
  243. if (!dev)
  244. goto out_unlock;
  245. }
  246. /* ipv4 addr of the socket is invalid. Only the
  247. * unspecified and mapped address have a v4 equivalent.
  248. */
  249. v4addr = LOOPBACK4_IPV6;
  250. if (!(addr_type & IPV6_ADDR_MULTICAST)) {
  251. err = -EADDRNOTAVAIL;
  252. if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
  253. dev, 0)) {
  254. goto out_unlock;
  255. }
  256. }
  257. }
  258. inet->inet_rcv_saddr = inet->inet_saddr = v4addr;
  259. sk->sk_v6_rcv_saddr = addr->sin6_addr;
  260. if (!(addr_type & IPV6_ADDR_MULTICAST))
  261. np->saddr = addr->sin6_addr;
  262. err = 0;
  263. out_unlock:
  264. rcu_read_unlock();
  265. out:
  266. release_sock(sk);
  267. return err;
  268. }
  269. static void rawv6_err(struct sock *sk, struct sk_buff *skb,
  270. struct inet6_skb_parm *opt,
  271. u8 type, u8 code, int offset, __be32 info)
  272. {
  273. struct inet_sock *inet = inet_sk(sk);
  274. struct ipv6_pinfo *np = inet6_sk(sk);
  275. int err;
  276. int harderr;
  277. /* Report error on raw socket, if:
  278. 1. User requested recverr.
  279. 2. Socket is connected (otherwise the error indication
  280. is useless without recverr and error is hard.
  281. */
  282. if (!np->recverr && sk->sk_state != TCP_ESTABLISHED)
  283. return;
  284. harderr = icmpv6_err_convert(type, code, &err);
  285. if (type == ICMPV6_PKT_TOOBIG) {
  286. ip6_sk_update_pmtu(skb, sk, info);
  287. harderr = (np->pmtudisc == IPV6_PMTUDISC_DO);
  288. }
  289. if (type == NDISC_REDIRECT) {
  290. ip6_sk_redirect(skb, sk);
  291. return;
  292. }
  293. if (np->recverr) {
  294. u8 *payload = skb->data;
  295. if (!inet->hdrincl)
  296. payload += offset;
  297. ipv6_icmp_error(sk, skb, err, 0, ntohl(info), payload);
  298. }
  299. if (np->recverr || harderr) {
  300. sk->sk_err = err;
  301. sk->sk_error_report(sk);
  302. }
  303. }
  304. void raw6_icmp_error(struct sk_buff *skb, int nexthdr,
  305. u8 type, u8 code, int inner_offset, __be32 info)
  306. {
  307. struct sock *sk;
  308. int hash;
  309. const struct in6_addr *saddr, *daddr;
  310. struct net *net;
  311. hash = nexthdr & (RAW_HTABLE_SIZE - 1);
  312. read_lock(&raw_v6_hashinfo.lock);
  313. sk = sk_head(&raw_v6_hashinfo.ht[hash]);
  314. if (sk) {
  315. /* Note: ipv6_hdr(skb) != skb->data */
  316. const struct ipv6hdr *ip6h = (const struct ipv6hdr *)skb->data;
  317. saddr = &ip6h->saddr;
  318. daddr = &ip6h->daddr;
  319. net = dev_net(skb->dev);
  320. while ((sk = __raw_v6_lookup(net, sk, nexthdr, saddr, daddr,
  321. inet6_iif(skb)))) {
  322. rawv6_err(sk, skb, NULL, type, code,
  323. inner_offset, info);
  324. sk = sk_next(sk);
  325. }
  326. }
  327. read_unlock(&raw_v6_hashinfo.lock);
  328. }
  329. static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
  330. {
  331. if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
  332. skb_checksum_complete(skb)) {
  333. atomic_inc(&sk->sk_drops);
  334. kfree_skb(skb);
  335. return NET_RX_DROP;
  336. }
  337. /* Charge it to the socket. */
  338. skb_dst_drop(skb);
  339. if (sock_queue_rcv_skb(sk, skb) < 0) {
  340. kfree_skb(skb);
  341. return NET_RX_DROP;
  342. }
  343. return 0;
  344. }
  345. /*
  346. * This is next to useless...
  347. * if we demultiplex in network layer we don't need the extra call
  348. * just to queue the skb...
  349. * maybe we could have the network decide upon a hint if it
  350. * should call raw_rcv for demultiplexing
  351. */
  352. int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
  353. {
  354. struct inet_sock *inet = inet_sk(sk);
  355. struct raw6_sock *rp = raw6_sk(sk);
  356. if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
  357. atomic_inc(&sk->sk_drops);
  358. kfree_skb(skb);
  359. return NET_RX_DROP;
  360. }
  361. if (!rp->checksum)
  362. skb->ip_summed = CHECKSUM_UNNECESSARY;
  363. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  364. skb_postpull_rcsum(skb, skb_network_header(skb),
  365. skb_network_header_len(skb));
  366. if (!csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  367. &ipv6_hdr(skb)->daddr,
  368. skb->len, inet->inet_num, skb->csum))
  369. skb->ip_summed = CHECKSUM_UNNECESSARY;
  370. }
  371. if (!skb_csum_unnecessary(skb))
  372. skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  373. &ipv6_hdr(skb)->daddr,
  374. skb->len,
  375. inet->inet_num, 0));
  376. if (inet->hdrincl) {
  377. if (skb_checksum_complete(skb)) {
  378. atomic_inc(&sk->sk_drops);
  379. kfree_skb(skb);
  380. return NET_RX_DROP;
  381. }
  382. }
  383. rawv6_rcv_skb(sk, skb);
  384. return 0;
  385. }
  386. /*
  387. * This should be easy, if there is something there
  388. * we return it, otherwise we block.
  389. */
  390. static int rawv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
  391. int noblock, int flags, int *addr_len)
  392. {
  393. struct ipv6_pinfo *np = inet6_sk(sk);
  394. DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
  395. struct sk_buff *skb;
  396. size_t copied;
  397. int err;
  398. if (flags & MSG_OOB)
  399. return -EOPNOTSUPP;
  400. if (flags & MSG_ERRQUEUE)
  401. return ipv6_recv_error(sk, msg, len, addr_len);
  402. if (np->rxpmtu && np->rxopt.bits.rxpmtu)
  403. return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
  404. skb = skb_recv_datagram(sk, flags, noblock, &err);
  405. if (!skb)
  406. goto out;
  407. copied = skb->len;
  408. if (copied > len) {
  409. copied = len;
  410. msg->msg_flags |= MSG_TRUNC;
  411. }
  412. if (skb_csum_unnecessary(skb)) {
  413. err = skb_copy_datagram_msg(skb, 0, msg, copied);
  414. } else if (msg->msg_flags&MSG_TRUNC) {
  415. if (__skb_checksum_complete(skb))
  416. goto csum_copy_err;
  417. err = skb_copy_datagram_msg(skb, 0, msg, copied);
  418. } else {
  419. err = skb_copy_and_csum_datagram_msg(skb, 0, msg);
  420. if (err == -EINVAL)
  421. goto csum_copy_err;
  422. }
  423. if (err)
  424. goto out_free;
  425. /* Copy the address. */
  426. if (sin6) {
  427. sin6->sin6_family = AF_INET6;
  428. sin6->sin6_port = 0;
  429. sin6->sin6_addr = ipv6_hdr(skb)->saddr;
  430. sin6->sin6_flowinfo = 0;
  431. sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
  432. inet6_iif(skb));
  433. *addr_len = sizeof(*sin6);
  434. }
  435. sock_recv_ts_and_drops(msg, sk, skb);
  436. if (np->rxopt.all)
  437. ip6_datagram_recv_ctl(sk, msg, skb);
  438. err = copied;
  439. if (flags & MSG_TRUNC)
  440. err = skb->len;
  441. out_free:
  442. skb_free_datagram(sk, skb);
  443. out:
  444. return err;
  445. csum_copy_err:
  446. skb_kill_datagram(sk, skb, flags);
  447. /* Error for blocking case is chosen to masquerade
  448. as some normal condition.
  449. */
  450. err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
  451. goto out;
  452. }
  453. static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
  454. struct raw6_sock *rp)
  455. {
  456. struct sk_buff *skb;
  457. int err = 0;
  458. int offset;
  459. int len;
  460. int total_len;
  461. __wsum tmp_csum;
  462. __sum16 csum;
  463. if (!rp->checksum)
  464. goto send;
  465. skb = skb_peek(&sk->sk_write_queue);
  466. if (!skb)
  467. goto out;
  468. offset = rp->offset;
  469. total_len = inet_sk(sk)->cork.base.length;
  470. if (offset >= total_len - 1) {
  471. err = -EINVAL;
  472. ip6_flush_pending_frames(sk);
  473. goto out;
  474. }
  475. /* should be check HW csum miyazawa */
  476. if (skb_queue_len(&sk->sk_write_queue) == 1) {
  477. /*
  478. * Only one fragment on the socket.
  479. */
  480. tmp_csum = skb->csum;
  481. } else {
  482. struct sk_buff *csum_skb = NULL;
  483. tmp_csum = 0;
  484. skb_queue_walk(&sk->sk_write_queue, skb) {
  485. tmp_csum = csum_add(tmp_csum, skb->csum);
  486. if (csum_skb)
  487. continue;
  488. len = skb->len - skb_transport_offset(skb);
  489. if (offset >= len) {
  490. offset -= len;
  491. continue;
  492. }
  493. csum_skb = skb;
  494. }
  495. skb = csum_skb;
  496. }
  497. offset += skb_transport_offset(skb);
  498. BUG_ON(skb_copy_bits(skb, offset, &csum, 2));
  499. /* in case cksum was not initialized */
  500. if (unlikely(csum))
  501. tmp_csum = csum_sub(tmp_csum, csum_unfold(csum));
  502. csum = csum_ipv6_magic(&fl6->saddr, &fl6->daddr,
  503. total_len, fl6->flowi6_proto, tmp_csum);
  504. if (csum == 0 && fl6->flowi6_proto == IPPROTO_UDP)
  505. csum = CSUM_MANGLED_0;
  506. BUG_ON(skb_store_bits(skb, offset, &csum, 2));
  507. send:
  508. err = ip6_push_pending_frames(sk);
  509. out:
  510. return err;
  511. }
  512. static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
  513. struct flowi6 *fl6, struct dst_entry **dstp,
  514. unsigned int flags)
  515. {
  516. struct ipv6_pinfo *np = inet6_sk(sk);
  517. struct ipv6hdr *iph;
  518. struct sk_buff *skb;
  519. int err;
  520. struct rt6_info *rt = (struct rt6_info *)*dstp;
  521. int hlen = LL_RESERVED_SPACE(rt->dst.dev);
  522. int tlen = rt->dst.dev->needed_tailroom;
  523. if (length > rt->dst.dev->mtu) {
  524. ipv6_local_error(sk, EMSGSIZE, fl6, rt->dst.dev->mtu);
  525. return -EMSGSIZE;
  526. }
  527. if (flags&MSG_PROBE)
  528. goto out;
  529. skb = sock_alloc_send_skb(sk,
  530. length + hlen + tlen + 15,
  531. flags & MSG_DONTWAIT, &err);
  532. if (!skb)
  533. goto error;
  534. skb_reserve(skb, hlen);
  535. skb->protocol = htons(ETH_P_IPV6);
  536. skb->priority = sk->sk_priority;
  537. skb->mark = sk->sk_mark;
  538. skb_dst_set(skb, &rt->dst);
  539. *dstp = NULL;
  540. skb_put(skb, length);
  541. skb_reset_network_header(skb);
  542. iph = ipv6_hdr(skb);
  543. skb->ip_summed = CHECKSUM_NONE;
  544. skb->transport_header = skb->network_header;
  545. err = memcpy_from_msg(iph, msg, length);
  546. if (err)
  547. goto error_fault;
  548. IP6_UPD_PO_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
  549. err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, sk, skb,
  550. NULL, rt->dst.dev, dst_output_sk);
  551. if (err > 0)
  552. err = net_xmit_errno(err);
  553. if (err)
  554. goto error;
  555. out:
  556. return 0;
  557. error_fault:
  558. err = -EFAULT;
  559. kfree_skb(skb);
  560. error:
  561. IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
  562. if (err == -ENOBUFS && !np->recverr)
  563. err = 0;
  564. return err;
  565. }
  566. struct raw6_frag_vec {
  567. struct msghdr *msg;
  568. int hlen;
  569. char c[4];
  570. };
  571. static int rawv6_probe_proto_opt(struct raw6_frag_vec *rfv, struct flowi6 *fl6)
  572. {
  573. int err = 0;
  574. switch (fl6->flowi6_proto) {
  575. case IPPROTO_ICMPV6:
  576. rfv->hlen = 2;
  577. err = memcpy_from_msg(rfv->c, rfv->msg, rfv->hlen);
  578. if (!err) {
  579. fl6->fl6_icmp_type = rfv->c[0];
  580. fl6->fl6_icmp_code = rfv->c[1];
  581. }
  582. break;
  583. case IPPROTO_MH:
  584. rfv->hlen = 4;
  585. err = memcpy_from_msg(rfv->c, rfv->msg, rfv->hlen);
  586. if (!err)
  587. fl6->fl6_mh_type = rfv->c[2];
  588. }
  589. return err;
  590. }
  591. static int raw6_getfrag(void *from, char *to, int offset, int len, int odd,
  592. struct sk_buff *skb)
  593. {
  594. struct raw6_frag_vec *rfv = from;
  595. if (offset < rfv->hlen) {
  596. int copy = min(rfv->hlen - offset, len);
  597. if (skb->ip_summed == CHECKSUM_PARTIAL)
  598. memcpy(to, rfv->c + offset, copy);
  599. else
  600. skb->csum = csum_block_add(
  601. skb->csum,
  602. csum_partial_copy_nocheck(rfv->c + offset,
  603. to, copy, 0),
  604. odd);
  605. odd = 0;
  606. offset += copy;
  607. to += copy;
  608. len -= copy;
  609. if (!len)
  610. return 0;
  611. }
  612. offset -= rfv->hlen;
  613. return ip_generic_getfrag(rfv->msg, to, offset, len, odd, skb);
  614. }
  615. static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
  616. {
  617. struct ipv6_txoptions opt_space;
  618. DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
  619. struct in6_addr *daddr, *final_p, final;
  620. struct inet_sock *inet = inet_sk(sk);
  621. struct ipv6_pinfo *np = inet6_sk(sk);
  622. struct raw6_sock *rp = raw6_sk(sk);
  623. struct ipv6_txoptions *opt = NULL;
  624. struct ip6_flowlabel *flowlabel = NULL;
  625. struct dst_entry *dst = NULL;
  626. struct raw6_frag_vec rfv;
  627. struct flowi6 fl6;
  628. int addr_len = msg->msg_namelen;
  629. int hlimit = -1;
  630. int tclass = -1;
  631. int dontfrag = -1;
  632. u16 proto;
  633. int err;
  634. /* Rough check on arithmetic overflow,
  635. better check is made in ip6_append_data().
  636. */
  637. if (len > INT_MAX)
  638. return -EMSGSIZE;
  639. /* Mirror BSD error message compatibility */
  640. if (msg->msg_flags & MSG_OOB)
  641. return -EOPNOTSUPP;
  642. /*
  643. * Get and verify the address.
  644. */
  645. memset(&fl6, 0, sizeof(fl6));
  646. fl6.flowi6_mark = sk->sk_mark;
  647. if (sin6) {
  648. if (addr_len < SIN6_LEN_RFC2133)
  649. return -EINVAL;
  650. if (sin6->sin6_family && sin6->sin6_family != AF_INET6)
  651. return -EAFNOSUPPORT;
  652. /* port is the proto value [0..255] carried in nexthdr */
  653. proto = ntohs(sin6->sin6_port);
  654. if (!proto)
  655. proto = inet->inet_num;
  656. else if (proto != inet->inet_num)
  657. return -EINVAL;
  658. if (proto > 255)
  659. return -EINVAL;
  660. daddr = &sin6->sin6_addr;
  661. if (np->sndflow) {
  662. fl6.flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
  663. if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) {
  664. flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
  665. if (!flowlabel)
  666. return -EINVAL;
  667. }
  668. }
  669. /*
  670. * Otherwise it will be difficult to maintain
  671. * sk->sk_dst_cache.
  672. */
  673. if (sk->sk_state == TCP_ESTABLISHED &&
  674. ipv6_addr_equal(daddr, &sk->sk_v6_daddr))
  675. daddr = &sk->sk_v6_daddr;
  676. if (addr_len >= sizeof(struct sockaddr_in6) &&
  677. sin6->sin6_scope_id &&
  678. __ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr)))
  679. fl6.flowi6_oif = sin6->sin6_scope_id;
  680. } else {
  681. if (sk->sk_state != TCP_ESTABLISHED)
  682. return -EDESTADDRREQ;
  683. proto = inet->inet_num;
  684. daddr = &sk->sk_v6_daddr;
  685. fl6.flowlabel = np->flow_label;
  686. }
  687. if (fl6.flowi6_oif == 0)
  688. fl6.flowi6_oif = sk->sk_bound_dev_if;
  689. if (msg->msg_controllen) {
  690. opt = &opt_space;
  691. memset(opt, 0, sizeof(struct ipv6_txoptions));
  692. opt->tot_len = sizeof(struct ipv6_txoptions);
  693. err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, opt,
  694. &hlimit, &tclass, &dontfrag);
  695. if (err < 0) {
  696. fl6_sock_release(flowlabel);
  697. return err;
  698. }
  699. if ((fl6.flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
  700. flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
  701. if (!flowlabel)
  702. return -EINVAL;
  703. }
  704. if (!(opt->opt_nflen|opt->opt_flen))
  705. opt = NULL;
  706. }
  707. if (!opt)
  708. opt = np->opt;
  709. if (flowlabel)
  710. opt = fl6_merge_options(&opt_space, flowlabel, opt);
  711. opt = ipv6_fixup_options(&opt_space, opt);
  712. fl6.flowi6_proto = proto;
  713. rfv.msg = msg;
  714. rfv.hlen = 0;
  715. err = rawv6_probe_proto_opt(&rfv, &fl6);
  716. if (err)
  717. goto out;
  718. if (!ipv6_addr_any(daddr))
  719. fl6.daddr = *daddr;
  720. else
  721. fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
  722. if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr))
  723. fl6.saddr = np->saddr;
  724. final_p = fl6_update_dst(&fl6, opt, &final);
  725. if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
  726. fl6.flowi6_oif = np->mcast_oif;
  727. else if (!fl6.flowi6_oif)
  728. fl6.flowi6_oif = np->ucast_oif;
  729. security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
  730. if (inet->hdrincl)
  731. fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;
  732. dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
  733. if (IS_ERR(dst)) {
  734. err = PTR_ERR(dst);
  735. goto out;
  736. }
  737. if (hlimit < 0)
  738. hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
  739. if (tclass < 0)
  740. tclass = np->tclass;
  741. if (dontfrag < 0)
  742. dontfrag = np->dontfrag;
  743. if (msg->msg_flags&MSG_CONFIRM)
  744. goto do_confirm;
  745. back_from_confirm:
  746. if (inet->hdrincl)
  747. err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags);
  748. else {
  749. lock_sock(sk);
  750. err = ip6_append_data(sk, raw6_getfrag, &rfv,
  751. len, 0, hlimit, tclass, opt, &fl6, (struct rt6_info *)dst,
  752. msg->msg_flags, dontfrag);
  753. if (err)
  754. ip6_flush_pending_frames(sk);
  755. else if (!(msg->msg_flags & MSG_MORE))
  756. err = rawv6_push_pending_frames(sk, &fl6, rp);
  757. release_sock(sk);
  758. }
  759. done:
  760. dst_release(dst);
  761. out:
  762. fl6_sock_release(flowlabel);
  763. return err < 0 ? err : len;
  764. do_confirm:
  765. dst_confirm(dst);
  766. if (!(msg->msg_flags & MSG_PROBE) || len)
  767. goto back_from_confirm;
  768. err = 0;
  769. goto done;
  770. }
  771. static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
  772. char __user *optval, int optlen)
  773. {
  774. switch (optname) {
  775. case ICMPV6_FILTER:
  776. if (optlen > sizeof(struct icmp6_filter))
  777. optlen = sizeof(struct icmp6_filter);
  778. if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
  779. return -EFAULT;
  780. return 0;
  781. default:
  782. return -ENOPROTOOPT;
  783. }
  784. return 0;
  785. }
  786. static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
  787. char __user *optval, int __user *optlen)
  788. {
  789. int len;
  790. switch (optname) {
  791. case ICMPV6_FILTER:
  792. if (get_user(len, optlen))
  793. return -EFAULT;
  794. if (len < 0)
  795. return -EINVAL;
  796. if (len > sizeof(struct icmp6_filter))
  797. len = sizeof(struct icmp6_filter);
  798. if (put_user(len, optlen))
  799. return -EFAULT;
  800. if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
  801. return -EFAULT;
  802. return 0;
  803. default:
  804. return -ENOPROTOOPT;
  805. }
  806. return 0;
  807. }
  808. static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
  809. char __user *optval, unsigned int optlen)
  810. {
  811. struct raw6_sock *rp = raw6_sk(sk);
  812. int val;
  813. if (get_user(val, (int __user *)optval))
  814. return -EFAULT;
  815. switch (optname) {
  816. case IPV6_CHECKSUM:
  817. if (inet_sk(sk)->inet_num == IPPROTO_ICMPV6 &&
  818. level == IPPROTO_IPV6) {
  819. /*
  820. * RFC3542 tells that IPV6_CHECKSUM socket
  821. * option in the IPPROTO_IPV6 level is not
  822. * allowed on ICMPv6 sockets.
  823. * If you want to set it, use IPPROTO_RAW
  824. * level IPV6_CHECKSUM socket option
  825. * (Linux extension).
  826. */
  827. return -EINVAL;
  828. }
  829. /* You may get strange result with a positive odd offset;
  830. RFC2292bis agrees with me. */
  831. if (val > 0 && (val&1))
  832. return -EINVAL;
  833. if (val < 0) {
  834. rp->checksum = 0;
  835. } else {
  836. rp->checksum = 1;
  837. rp->offset = val;
  838. }
  839. return 0;
  840. default:
  841. return -ENOPROTOOPT;
  842. }
  843. }
  844. static int rawv6_setsockopt(struct sock *sk, int level, int optname,
  845. char __user *optval, unsigned int optlen)
  846. {
  847. switch (level) {
  848. case SOL_RAW:
  849. break;
  850. case SOL_ICMPV6:
  851. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  852. return -EOPNOTSUPP;
  853. return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
  854. case SOL_IPV6:
  855. if (optname == IPV6_CHECKSUM)
  856. break;
  857. default:
  858. return ipv6_setsockopt(sk, level, optname, optval, optlen);
  859. }
  860. return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
  861. }
  862. #ifdef CONFIG_COMPAT
  863. static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
  864. char __user *optval, unsigned int optlen)
  865. {
  866. switch (level) {
  867. case SOL_RAW:
  868. break;
  869. case SOL_ICMPV6:
  870. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  871. return -EOPNOTSUPP;
  872. return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
  873. case SOL_IPV6:
  874. if (optname == IPV6_CHECKSUM)
  875. break;
  876. default:
  877. return compat_ipv6_setsockopt(sk, level, optname,
  878. optval, optlen);
  879. }
  880. return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
  881. }
  882. #endif
  883. static int do_rawv6_getsockopt(struct sock *sk, int level, int optname,
  884. char __user *optval, int __user *optlen)
  885. {
  886. struct raw6_sock *rp = raw6_sk(sk);
  887. int val, len;
  888. if (get_user(len, optlen))
  889. return -EFAULT;
  890. switch (optname) {
  891. case IPV6_CHECKSUM:
  892. /*
  893. * We allow getsockopt() for IPPROTO_IPV6-level
  894. * IPV6_CHECKSUM socket option on ICMPv6 sockets
  895. * since RFC3542 is silent about it.
  896. */
  897. if (rp->checksum == 0)
  898. val = -1;
  899. else
  900. val = rp->offset;
  901. break;
  902. default:
  903. return -ENOPROTOOPT;
  904. }
  905. len = min_t(unsigned int, sizeof(int), len);
  906. if (put_user(len, optlen))
  907. return -EFAULT;
  908. if (copy_to_user(optval, &val, len))
  909. return -EFAULT;
  910. return 0;
  911. }
  912. static int rawv6_getsockopt(struct sock *sk, int level, int optname,
  913. char __user *optval, int __user *optlen)
  914. {
  915. switch (level) {
  916. case SOL_RAW:
  917. break;
  918. case SOL_ICMPV6:
  919. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  920. return -EOPNOTSUPP;
  921. return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
  922. case SOL_IPV6:
  923. if (optname == IPV6_CHECKSUM)
  924. break;
  925. default:
  926. return ipv6_getsockopt(sk, level, optname, optval, optlen);
  927. }
  928. return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
  929. }
  930. #ifdef CONFIG_COMPAT
  931. static int compat_rawv6_getsockopt(struct sock *sk, int level, int optname,
  932. char __user *optval, int __user *optlen)
  933. {
  934. switch (level) {
  935. case SOL_RAW:
  936. break;
  937. case SOL_ICMPV6:
  938. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  939. return -EOPNOTSUPP;
  940. return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
  941. case SOL_IPV6:
  942. if (optname == IPV6_CHECKSUM)
  943. break;
  944. default:
  945. return compat_ipv6_getsockopt(sk, level, optname,
  946. optval, optlen);
  947. }
  948. return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
  949. }
  950. #endif
  951. static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
  952. {
  953. switch (cmd) {
  954. case SIOCOUTQ: {
  955. int amount = sk_wmem_alloc_get(sk);
  956. return put_user(amount, (int __user *)arg);
  957. }
  958. case SIOCINQ: {
  959. struct sk_buff *skb;
  960. int amount = 0;
  961. spin_lock_bh(&sk->sk_receive_queue.lock);
  962. skb = skb_peek(&sk->sk_receive_queue);
  963. if (skb)
  964. amount = skb_tail_pointer(skb) -
  965. skb_transport_header(skb);
  966. spin_unlock_bh(&sk->sk_receive_queue.lock);
  967. return put_user(amount, (int __user *)arg);
  968. }
  969. default:
  970. #ifdef CONFIG_IPV6_MROUTE
  971. return ip6mr_ioctl(sk, cmd, (void __user *)arg);
  972. #else
  973. return -ENOIOCTLCMD;
  974. #endif
  975. }
  976. }
  977. #ifdef CONFIG_COMPAT
  978. static int compat_rawv6_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg)
  979. {
  980. switch (cmd) {
  981. case SIOCOUTQ:
  982. case SIOCINQ:
  983. return -ENOIOCTLCMD;
  984. default:
  985. #ifdef CONFIG_IPV6_MROUTE
  986. return ip6mr_compat_ioctl(sk, cmd, compat_ptr(arg));
  987. #else
  988. return -ENOIOCTLCMD;
  989. #endif
  990. }
  991. }
  992. #endif
  993. static void rawv6_close(struct sock *sk, long timeout)
  994. {
  995. if (inet_sk(sk)->inet_num == IPPROTO_RAW)
  996. ip6_ra_control(sk, -1);
  997. ip6mr_sk_done(sk);
  998. sk_common_release(sk);
  999. }
  1000. static void raw6_destroy(struct sock *sk)
  1001. {
  1002. lock_sock(sk);
  1003. ip6_flush_pending_frames(sk);
  1004. release_sock(sk);
  1005. inet6_destroy_sock(sk);
  1006. }
  1007. static int rawv6_init_sk(struct sock *sk)
  1008. {
  1009. struct raw6_sock *rp = raw6_sk(sk);
  1010. switch (inet_sk(sk)->inet_num) {
  1011. case IPPROTO_ICMPV6:
  1012. rp->checksum = 1;
  1013. rp->offset = 2;
  1014. break;
  1015. case IPPROTO_MH:
  1016. rp->checksum = 1;
  1017. rp->offset = 4;
  1018. break;
  1019. default:
  1020. break;
  1021. }
  1022. return 0;
  1023. }
  1024. struct proto rawv6_prot = {
  1025. .name = "RAWv6",
  1026. .owner = THIS_MODULE,
  1027. .close = rawv6_close,
  1028. .destroy = raw6_destroy,
  1029. .connect = ip6_datagram_connect_v6_only,
  1030. .disconnect = udp_disconnect,
  1031. .ioctl = rawv6_ioctl,
  1032. .init = rawv6_init_sk,
  1033. .setsockopt = rawv6_setsockopt,
  1034. .getsockopt = rawv6_getsockopt,
  1035. .sendmsg = rawv6_sendmsg,
  1036. .recvmsg = rawv6_recvmsg,
  1037. .bind = rawv6_bind,
  1038. .backlog_rcv = rawv6_rcv_skb,
  1039. .hash = raw_hash_sk,
  1040. .unhash = raw_unhash_sk,
  1041. .obj_size = sizeof(struct raw6_sock),
  1042. .h.raw_hash = &raw_v6_hashinfo,
  1043. #ifdef CONFIG_COMPAT
  1044. .compat_setsockopt = compat_rawv6_setsockopt,
  1045. .compat_getsockopt = compat_rawv6_getsockopt,
  1046. .compat_ioctl = compat_rawv6_ioctl,
  1047. #endif
  1048. };
  1049. #ifdef CONFIG_PROC_FS
  1050. static int raw6_seq_show(struct seq_file *seq, void *v)
  1051. {
  1052. if (v == SEQ_START_TOKEN) {
  1053. seq_puts(seq, IPV6_SEQ_DGRAM_HEADER);
  1054. } else {
  1055. struct sock *sp = v;
  1056. __u16 srcp = inet_sk(sp)->inet_num;
  1057. ip6_dgram_sock_seq_show(seq, v, srcp, 0,
  1058. raw_seq_private(seq)->bucket);
  1059. }
  1060. return 0;
  1061. }
  1062. static const struct seq_operations raw6_seq_ops = {
  1063. .start = raw_seq_start,
  1064. .next = raw_seq_next,
  1065. .stop = raw_seq_stop,
  1066. .show = raw6_seq_show,
  1067. };
  1068. static int raw6_seq_open(struct inode *inode, struct file *file)
  1069. {
  1070. return raw_seq_open(inode, file, &raw_v6_hashinfo, &raw6_seq_ops);
  1071. }
  1072. static const struct file_operations raw6_seq_fops = {
  1073. .owner = THIS_MODULE,
  1074. .open = raw6_seq_open,
  1075. .read = seq_read,
  1076. .llseek = seq_lseek,
  1077. .release = seq_release_net,
  1078. };
  1079. static int __net_init raw6_init_net(struct net *net)
  1080. {
  1081. if (!proc_create("raw6", S_IRUGO, net->proc_net, &raw6_seq_fops))
  1082. return -ENOMEM;
  1083. return 0;
  1084. }
  1085. static void __net_exit raw6_exit_net(struct net *net)
  1086. {
  1087. remove_proc_entry("raw6", net->proc_net);
  1088. }
  1089. static struct pernet_operations raw6_net_ops = {
  1090. .init = raw6_init_net,
  1091. .exit = raw6_exit_net,
  1092. };
  1093. int __init raw6_proc_init(void)
  1094. {
  1095. return register_pernet_subsys(&raw6_net_ops);
  1096. }
  1097. void raw6_proc_exit(void)
  1098. {
  1099. unregister_pernet_subsys(&raw6_net_ops);
  1100. }
  1101. #endif /* CONFIG_PROC_FS */
  1102. /* Same as inet6_dgram_ops, sans udp_poll. */
  1103. static const struct proto_ops inet6_sockraw_ops = {
  1104. .family = PF_INET6,
  1105. .owner = THIS_MODULE,
  1106. .release = inet6_release,
  1107. .bind = inet6_bind,
  1108. .connect = inet_dgram_connect, /* ok */
  1109. .socketpair = sock_no_socketpair, /* a do nothing */
  1110. .accept = sock_no_accept, /* a do nothing */
  1111. .getname = inet6_getname,
  1112. .poll = datagram_poll, /* ok */
  1113. .ioctl = inet6_ioctl, /* must change */
  1114. .listen = sock_no_listen, /* ok */
  1115. .shutdown = inet_shutdown, /* ok */
  1116. .setsockopt = sock_common_setsockopt, /* ok */
  1117. .getsockopt = sock_common_getsockopt, /* ok */
  1118. .sendmsg = inet_sendmsg, /* ok */
  1119. .recvmsg = sock_common_recvmsg, /* ok */
  1120. .mmap = sock_no_mmap,
  1121. .sendpage = sock_no_sendpage,
  1122. #ifdef CONFIG_COMPAT
  1123. .compat_setsockopt = compat_sock_common_setsockopt,
  1124. .compat_getsockopt = compat_sock_common_getsockopt,
  1125. #endif
  1126. };
  1127. static struct inet_protosw rawv6_protosw = {
  1128. .type = SOCK_RAW,
  1129. .protocol = IPPROTO_IP, /* wild card */
  1130. .prot = &rawv6_prot,
  1131. .ops = &inet6_sockraw_ops,
  1132. .flags = INET_PROTOSW_REUSE,
  1133. };
  1134. int __init rawv6_init(void)
  1135. {
  1136. return inet6_register_protosw(&rawv6_protosw);
  1137. }
  1138. void rawv6_exit(void)
  1139. {
  1140. inet6_unregister_protosw(&rawv6_protosw);
  1141. }