raw.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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. !sock_net(sk)->ipv6.sysctl.ip_nonlocal_bind) {
  252. err = -EADDRNOTAVAIL;
  253. if (!ipv6_chk_addr(sock_net(sk), &addr->sin6_addr,
  254. dev, 0)) {
  255. goto out_unlock;
  256. }
  257. }
  258. }
  259. inet->inet_rcv_saddr = inet->inet_saddr = v4addr;
  260. sk->sk_v6_rcv_saddr = addr->sin6_addr;
  261. if (!(addr_type & IPV6_ADDR_MULTICAST))
  262. np->saddr = addr->sin6_addr;
  263. err = 0;
  264. out_unlock:
  265. rcu_read_unlock();
  266. out:
  267. release_sock(sk);
  268. return err;
  269. }
  270. static void rawv6_err(struct sock *sk, struct sk_buff *skb,
  271. struct inet6_skb_parm *opt,
  272. u8 type, u8 code, int offset, __be32 info)
  273. {
  274. struct inet_sock *inet = inet_sk(sk);
  275. struct ipv6_pinfo *np = inet6_sk(sk);
  276. int err;
  277. int harderr;
  278. /* Report error on raw socket, if:
  279. 1. User requested recverr.
  280. 2. Socket is connected (otherwise the error indication
  281. is useless without recverr and error is hard.
  282. */
  283. if (!np->recverr && sk->sk_state != TCP_ESTABLISHED)
  284. return;
  285. harderr = icmpv6_err_convert(type, code, &err);
  286. if (type == ICMPV6_PKT_TOOBIG) {
  287. ip6_sk_update_pmtu(skb, sk, info);
  288. harderr = (np->pmtudisc == IPV6_PMTUDISC_DO);
  289. }
  290. if (type == NDISC_REDIRECT) {
  291. ip6_sk_redirect(skb, sk);
  292. return;
  293. }
  294. if (np->recverr) {
  295. u8 *payload = skb->data;
  296. if (!inet->hdrincl)
  297. payload += offset;
  298. ipv6_icmp_error(sk, skb, err, 0, ntohl(info), payload);
  299. }
  300. if (np->recverr || harderr) {
  301. sk->sk_err = err;
  302. sk->sk_error_report(sk);
  303. }
  304. }
  305. void raw6_icmp_error(struct sk_buff *skb, int nexthdr,
  306. u8 type, u8 code, int inner_offset, __be32 info)
  307. {
  308. struct sock *sk;
  309. int hash;
  310. const struct in6_addr *saddr, *daddr;
  311. struct net *net;
  312. hash = nexthdr & (RAW_HTABLE_SIZE - 1);
  313. read_lock(&raw_v6_hashinfo.lock);
  314. sk = sk_head(&raw_v6_hashinfo.ht[hash]);
  315. if (sk) {
  316. /* Note: ipv6_hdr(skb) != skb->data */
  317. const struct ipv6hdr *ip6h = (const struct ipv6hdr *)skb->data;
  318. saddr = &ip6h->saddr;
  319. daddr = &ip6h->daddr;
  320. net = dev_net(skb->dev);
  321. while ((sk = __raw_v6_lookup(net, sk, nexthdr, saddr, daddr,
  322. inet6_iif(skb)))) {
  323. rawv6_err(sk, skb, NULL, type, code,
  324. inner_offset, info);
  325. sk = sk_next(sk);
  326. }
  327. }
  328. read_unlock(&raw_v6_hashinfo.lock);
  329. }
  330. static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
  331. {
  332. if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
  333. skb_checksum_complete(skb)) {
  334. atomic_inc(&sk->sk_drops);
  335. kfree_skb(skb);
  336. return NET_RX_DROP;
  337. }
  338. /* Charge it to the socket. */
  339. skb_dst_drop(skb);
  340. if (sock_queue_rcv_skb(sk, skb) < 0) {
  341. kfree_skb(skb);
  342. return NET_RX_DROP;
  343. }
  344. return 0;
  345. }
  346. /*
  347. * This is next to useless...
  348. * if we demultiplex in network layer we don't need the extra call
  349. * just to queue the skb...
  350. * maybe we could have the network decide upon a hint if it
  351. * should call raw_rcv for demultiplexing
  352. */
  353. int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
  354. {
  355. struct inet_sock *inet = inet_sk(sk);
  356. struct raw6_sock *rp = raw6_sk(sk);
  357. if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
  358. atomic_inc(&sk->sk_drops);
  359. kfree_skb(skb);
  360. return NET_RX_DROP;
  361. }
  362. if (!rp->checksum)
  363. skb->ip_summed = CHECKSUM_UNNECESSARY;
  364. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  365. skb_postpull_rcsum(skb, skb_network_header(skb),
  366. skb_network_header_len(skb));
  367. if (!csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  368. &ipv6_hdr(skb)->daddr,
  369. skb->len, inet->inet_num, skb->csum))
  370. skb->ip_summed = CHECKSUM_UNNECESSARY;
  371. }
  372. if (!skb_csum_unnecessary(skb))
  373. skb->csum = ~csum_unfold(csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  374. &ipv6_hdr(skb)->daddr,
  375. skb->len,
  376. inet->inet_num, 0));
  377. if (inet->hdrincl) {
  378. if (skb_checksum_complete(skb)) {
  379. atomic_inc(&sk->sk_drops);
  380. kfree_skb(skb);
  381. return NET_RX_DROP;
  382. }
  383. }
  384. rawv6_rcv_skb(sk, skb);
  385. return 0;
  386. }
  387. /*
  388. * This should be easy, if there is something there
  389. * we return it, otherwise we block.
  390. */
  391. static int rawv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
  392. int noblock, int flags, int *addr_len)
  393. {
  394. struct ipv6_pinfo *np = inet6_sk(sk);
  395. DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
  396. struct sk_buff *skb;
  397. size_t copied;
  398. int err;
  399. if (flags & MSG_OOB)
  400. return -EOPNOTSUPP;
  401. if (flags & MSG_ERRQUEUE)
  402. return ipv6_recv_error(sk, msg, len, addr_len);
  403. if (np->rxpmtu && np->rxopt.bits.rxpmtu)
  404. return ipv6_recv_rxpmtu(sk, msg, len, addr_len);
  405. skb = skb_recv_datagram(sk, flags, noblock, &err);
  406. if (!skb)
  407. goto out;
  408. copied = skb->len;
  409. if (copied > len) {
  410. copied = len;
  411. msg->msg_flags |= MSG_TRUNC;
  412. }
  413. if (skb_csum_unnecessary(skb)) {
  414. err = skb_copy_datagram_msg(skb, 0, msg, copied);
  415. } else if (msg->msg_flags&MSG_TRUNC) {
  416. if (__skb_checksum_complete(skb))
  417. goto csum_copy_err;
  418. err = skb_copy_datagram_msg(skb, 0, msg, copied);
  419. } else {
  420. err = skb_copy_and_csum_datagram_msg(skb, 0, msg);
  421. if (err == -EINVAL)
  422. goto csum_copy_err;
  423. }
  424. if (err)
  425. goto out_free;
  426. /* Copy the address. */
  427. if (sin6) {
  428. sin6->sin6_family = AF_INET6;
  429. sin6->sin6_port = 0;
  430. sin6->sin6_addr = ipv6_hdr(skb)->saddr;
  431. sin6->sin6_flowinfo = 0;
  432. sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
  433. inet6_iif(skb));
  434. *addr_len = sizeof(*sin6);
  435. }
  436. sock_recv_ts_and_drops(msg, sk, skb);
  437. if (np->rxopt.all)
  438. ip6_datagram_recv_ctl(sk, msg, skb);
  439. err = copied;
  440. if (flags & MSG_TRUNC)
  441. err = skb->len;
  442. out_free:
  443. skb_free_datagram(sk, skb);
  444. out:
  445. return err;
  446. csum_copy_err:
  447. skb_kill_datagram(sk, skb, flags);
  448. /* Error for blocking case is chosen to masquerade
  449. as some normal condition.
  450. */
  451. err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
  452. goto out;
  453. }
  454. static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
  455. struct raw6_sock *rp)
  456. {
  457. struct sk_buff *skb;
  458. int err = 0;
  459. int offset;
  460. int len;
  461. int total_len;
  462. __wsum tmp_csum;
  463. __sum16 csum;
  464. if (!rp->checksum)
  465. goto send;
  466. skb = skb_peek(&sk->sk_write_queue);
  467. if (!skb)
  468. goto out;
  469. offset = rp->offset;
  470. total_len = inet_sk(sk)->cork.base.length;
  471. if (offset >= total_len - 1) {
  472. err = -EINVAL;
  473. ip6_flush_pending_frames(sk);
  474. goto out;
  475. }
  476. /* should be check HW csum miyazawa */
  477. if (skb_queue_len(&sk->sk_write_queue) == 1) {
  478. /*
  479. * Only one fragment on the socket.
  480. */
  481. tmp_csum = skb->csum;
  482. } else {
  483. struct sk_buff *csum_skb = NULL;
  484. tmp_csum = 0;
  485. skb_queue_walk(&sk->sk_write_queue, skb) {
  486. tmp_csum = csum_add(tmp_csum, skb->csum);
  487. if (csum_skb)
  488. continue;
  489. len = skb->len - skb_transport_offset(skb);
  490. if (offset >= len) {
  491. offset -= len;
  492. continue;
  493. }
  494. csum_skb = skb;
  495. }
  496. skb = csum_skb;
  497. }
  498. offset += skb_transport_offset(skb);
  499. err = skb_copy_bits(skb, offset, &csum, 2);
  500. if (err < 0) {
  501. ip6_flush_pending_frames(sk);
  502. goto out;
  503. }
  504. /* in case cksum was not initialized */
  505. if (unlikely(csum))
  506. tmp_csum = csum_sub(tmp_csum, csum_unfold(csum));
  507. csum = csum_ipv6_magic(&fl6->saddr, &fl6->daddr,
  508. total_len, fl6->flowi6_proto, tmp_csum);
  509. if (csum == 0 && fl6->flowi6_proto == IPPROTO_UDP)
  510. csum = CSUM_MANGLED_0;
  511. BUG_ON(skb_store_bits(skb, offset, &csum, 2));
  512. send:
  513. err = ip6_push_pending_frames(sk);
  514. out:
  515. return err;
  516. }
  517. static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
  518. struct flowi6 *fl6, struct dst_entry **dstp,
  519. unsigned int flags)
  520. {
  521. struct ipv6_pinfo *np = inet6_sk(sk);
  522. struct net *net = sock_net(sk);
  523. struct ipv6hdr *iph;
  524. struct sk_buff *skb;
  525. int err;
  526. struct rt6_info *rt = (struct rt6_info *)*dstp;
  527. int hlen = LL_RESERVED_SPACE(rt->dst.dev);
  528. int tlen = rt->dst.dev->needed_tailroom;
  529. if (length > rt->dst.dev->mtu) {
  530. ipv6_local_error(sk, EMSGSIZE, fl6, rt->dst.dev->mtu);
  531. return -EMSGSIZE;
  532. }
  533. if (length < sizeof(struct ipv6hdr))
  534. return -EINVAL;
  535. if (flags&MSG_PROBE)
  536. goto out;
  537. skb = sock_alloc_send_skb(sk,
  538. length + hlen + tlen + 15,
  539. flags & MSG_DONTWAIT, &err);
  540. if (!skb)
  541. goto error;
  542. skb_reserve(skb, hlen);
  543. skb->protocol = htons(ETH_P_IPV6);
  544. skb->priority = sk->sk_priority;
  545. skb->mark = sk->sk_mark;
  546. skb_dst_set(skb, &rt->dst);
  547. *dstp = NULL;
  548. skb_put(skb, length);
  549. skb_reset_network_header(skb);
  550. iph = ipv6_hdr(skb);
  551. skb->ip_summed = CHECKSUM_NONE;
  552. skb->transport_header = skb->network_header;
  553. err = memcpy_from_msg(iph, msg, length);
  554. if (err)
  555. goto error_fault;
  556. IP6_UPD_PO_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
  557. err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb,
  558. NULL, rt->dst.dev, dst_output);
  559. if (err > 0)
  560. err = net_xmit_errno(err);
  561. if (err)
  562. goto error;
  563. out:
  564. return 0;
  565. error_fault:
  566. err = -EFAULT;
  567. kfree_skb(skb);
  568. error:
  569. IP6_INC_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
  570. if (err == -ENOBUFS && !np->recverr)
  571. err = 0;
  572. return err;
  573. }
  574. struct raw6_frag_vec {
  575. struct msghdr *msg;
  576. int hlen;
  577. char c[4];
  578. };
  579. static int rawv6_probe_proto_opt(struct raw6_frag_vec *rfv, struct flowi6 *fl6)
  580. {
  581. int err = 0;
  582. switch (fl6->flowi6_proto) {
  583. case IPPROTO_ICMPV6:
  584. rfv->hlen = 2;
  585. err = memcpy_from_msg(rfv->c, rfv->msg, rfv->hlen);
  586. if (!err) {
  587. fl6->fl6_icmp_type = rfv->c[0];
  588. fl6->fl6_icmp_code = rfv->c[1];
  589. }
  590. break;
  591. case IPPROTO_MH:
  592. rfv->hlen = 4;
  593. err = memcpy_from_msg(rfv->c, rfv->msg, rfv->hlen);
  594. if (!err)
  595. fl6->fl6_mh_type = rfv->c[2];
  596. }
  597. return err;
  598. }
  599. static int raw6_getfrag(void *from, char *to, int offset, int len, int odd,
  600. struct sk_buff *skb)
  601. {
  602. struct raw6_frag_vec *rfv = from;
  603. if (offset < rfv->hlen) {
  604. int copy = min(rfv->hlen - offset, len);
  605. if (skb->ip_summed == CHECKSUM_PARTIAL)
  606. memcpy(to, rfv->c + offset, copy);
  607. else
  608. skb->csum = csum_block_add(
  609. skb->csum,
  610. csum_partial_copy_nocheck(rfv->c + offset,
  611. to, copy, 0),
  612. odd);
  613. odd = 0;
  614. offset += copy;
  615. to += copy;
  616. len -= copy;
  617. if (!len)
  618. return 0;
  619. }
  620. offset -= rfv->hlen;
  621. return ip_generic_getfrag(rfv->msg, to, offset, len, odd, skb);
  622. }
  623. static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
  624. {
  625. struct ipv6_txoptions *opt_to_free = NULL;
  626. struct ipv6_txoptions opt_space;
  627. DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
  628. struct in6_addr *daddr, *final_p, final;
  629. struct inet_sock *inet = inet_sk(sk);
  630. struct ipv6_pinfo *np = inet6_sk(sk);
  631. struct raw6_sock *rp = raw6_sk(sk);
  632. struct ipv6_txoptions *opt = NULL;
  633. struct ip6_flowlabel *flowlabel = NULL;
  634. struct dst_entry *dst = NULL;
  635. struct raw6_frag_vec rfv;
  636. struct flowi6 fl6;
  637. int addr_len = msg->msg_namelen;
  638. int hlimit = -1;
  639. int tclass = -1;
  640. int dontfrag = -1;
  641. u16 proto;
  642. int err;
  643. /* Rough check on arithmetic overflow,
  644. better check is made in ip6_append_data().
  645. */
  646. if (len > INT_MAX)
  647. return -EMSGSIZE;
  648. /* Mirror BSD error message compatibility */
  649. if (msg->msg_flags & MSG_OOB)
  650. return -EOPNOTSUPP;
  651. /*
  652. * Get and verify the address.
  653. */
  654. memset(&fl6, 0, sizeof(fl6));
  655. fl6.flowi6_mark = sk->sk_mark;
  656. if (sin6) {
  657. if (addr_len < SIN6_LEN_RFC2133)
  658. return -EINVAL;
  659. if (sin6->sin6_family && sin6->sin6_family != AF_INET6)
  660. return -EAFNOSUPPORT;
  661. /* port is the proto value [0..255] carried in nexthdr */
  662. proto = ntohs(sin6->sin6_port);
  663. if (!proto)
  664. proto = inet->inet_num;
  665. else if (proto != inet->inet_num)
  666. return -EINVAL;
  667. if (proto > 255)
  668. return -EINVAL;
  669. daddr = &sin6->sin6_addr;
  670. if (np->sndflow) {
  671. fl6.flowlabel = sin6->sin6_flowinfo&IPV6_FLOWINFO_MASK;
  672. if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) {
  673. flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
  674. if (!flowlabel)
  675. return -EINVAL;
  676. }
  677. }
  678. /*
  679. * Otherwise it will be difficult to maintain
  680. * sk->sk_dst_cache.
  681. */
  682. if (sk->sk_state == TCP_ESTABLISHED &&
  683. ipv6_addr_equal(daddr, &sk->sk_v6_daddr))
  684. daddr = &sk->sk_v6_daddr;
  685. if (addr_len >= sizeof(struct sockaddr_in6) &&
  686. sin6->sin6_scope_id &&
  687. __ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr)))
  688. fl6.flowi6_oif = sin6->sin6_scope_id;
  689. } else {
  690. if (sk->sk_state != TCP_ESTABLISHED)
  691. return -EDESTADDRREQ;
  692. proto = inet->inet_num;
  693. daddr = &sk->sk_v6_daddr;
  694. fl6.flowlabel = np->flow_label;
  695. }
  696. if (fl6.flowi6_oif == 0)
  697. fl6.flowi6_oif = sk->sk_bound_dev_if;
  698. if (msg->msg_controllen) {
  699. opt = &opt_space;
  700. memset(opt, 0, sizeof(struct ipv6_txoptions));
  701. opt->tot_len = sizeof(struct ipv6_txoptions);
  702. err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, opt,
  703. &hlimit, &tclass, &dontfrag);
  704. if (err < 0) {
  705. fl6_sock_release(flowlabel);
  706. return err;
  707. }
  708. if ((fl6.flowlabel&IPV6_FLOWLABEL_MASK) && !flowlabel) {
  709. flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
  710. if (!flowlabel)
  711. return -EINVAL;
  712. }
  713. if (!(opt->opt_nflen|opt->opt_flen))
  714. opt = NULL;
  715. }
  716. if (!opt) {
  717. opt = txopt_get(np);
  718. opt_to_free = opt;
  719. }
  720. if (flowlabel)
  721. opt = fl6_merge_options(&opt_space, flowlabel, opt);
  722. opt = ipv6_fixup_options(&opt_space, opt);
  723. fl6.flowi6_proto = proto;
  724. rfv.msg = msg;
  725. rfv.hlen = 0;
  726. err = rawv6_probe_proto_opt(&rfv, &fl6);
  727. if (err)
  728. goto out;
  729. if (!ipv6_addr_any(daddr))
  730. fl6.daddr = *daddr;
  731. else
  732. fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
  733. if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr))
  734. fl6.saddr = np->saddr;
  735. final_p = fl6_update_dst(&fl6, opt, &final);
  736. if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr))
  737. fl6.flowi6_oif = np->mcast_oif;
  738. else if (!fl6.flowi6_oif)
  739. fl6.flowi6_oif = np->ucast_oif;
  740. security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
  741. if (inet->hdrincl)
  742. fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;
  743. dst = ip6_dst_lookup_flow(sk, &fl6, final_p);
  744. if (IS_ERR(dst)) {
  745. err = PTR_ERR(dst);
  746. goto out;
  747. }
  748. if (hlimit < 0)
  749. hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
  750. if (tclass < 0)
  751. tclass = np->tclass;
  752. if (dontfrag < 0)
  753. dontfrag = np->dontfrag;
  754. if (msg->msg_flags&MSG_CONFIRM)
  755. goto do_confirm;
  756. back_from_confirm:
  757. if (inet->hdrincl)
  758. err = rawv6_send_hdrinc(sk, msg, len, &fl6, &dst, msg->msg_flags);
  759. else {
  760. lock_sock(sk);
  761. err = ip6_append_data(sk, raw6_getfrag, &rfv,
  762. len, 0, hlimit, tclass, opt, &fl6, (struct rt6_info *)dst,
  763. msg->msg_flags, dontfrag);
  764. if (err)
  765. ip6_flush_pending_frames(sk);
  766. else if (!(msg->msg_flags & MSG_MORE))
  767. err = rawv6_push_pending_frames(sk, &fl6, rp);
  768. release_sock(sk);
  769. }
  770. done:
  771. dst_release(dst);
  772. out:
  773. fl6_sock_release(flowlabel);
  774. txopt_put(opt_to_free);
  775. return err < 0 ? err : len;
  776. do_confirm:
  777. dst_confirm(dst);
  778. if (!(msg->msg_flags & MSG_PROBE) || len)
  779. goto back_from_confirm;
  780. err = 0;
  781. goto done;
  782. }
  783. static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
  784. char __user *optval, int optlen)
  785. {
  786. switch (optname) {
  787. case ICMPV6_FILTER:
  788. if (optlen > sizeof(struct icmp6_filter))
  789. optlen = sizeof(struct icmp6_filter);
  790. if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
  791. return -EFAULT;
  792. return 0;
  793. default:
  794. return -ENOPROTOOPT;
  795. }
  796. return 0;
  797. }
  798. static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
  799. char __user *optval, int __user *optlen)
  800. {
  801. int len;
  802. switch (optname) {
  803. case ICMPV6_FILTER:
  804. if (get_user(len, optlen))
  805. return -EFAULT;
  806. if (len < 0)
  807. return -EINVAL;
  808. if (len > sizeof(struct icmp6_filter))
  809. len = sizeof(struct icmp6_filter);
  810. if (put_user(len, optlen))
  811. return -EFAULT;
  812. if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
  813. return -EFAULT;
  814. return 0;
  815. default:
  816. return -ENOPROTOOPT;
  817. }
  818. return 0;
  819. }
  820. static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
  821. char __user *optval, unsigned int optlen)
  822. {
  823. struct raw6_sock *rp = raw6_sk(sk);
  824. int val;
  825. if (get_user(val, (int __user *)optval))
  826. return -EFAULT;
  827. switch (optname) {
  828. case IPV6_CHECKSUM:
  829. if (inet_sk(sk)->inet_num == IPPROTO_ICMPV6 &&
  830. level == IPPROTO_IPV6) {
  831. /*
  832. * RFC3542 tells that IPV6_CHECKSUM socket
  833. * option in the IPPROTO_IPV6 level is not
  834. * allowed on ICMPv6 sockets.
  835. * If you want to set it, use IPPROTO_RAW
  836. * level IPV6_CHECKSUM socket option
  837. * (Linux extension).
  838. */
  839. return -EINVAL;
  840. }
  841. /* You may get strange result with a positive odd offset;
  842. RFC2292bis agrees with me. */
  843. if (val > 0 && (val&1))
  844. return -EINVAL;
  845. if (val < 0) {
  846. rp->checksum = 0;
  847. } else {
  848. rp->checksum = 1;
  849. rp->offset = val;
  850. }
  851. return 0;
  852. default:
  853. return -ENOPROTOOPT;
  854. }
  855. }
  856. static int rawv6_setsockopt(struct sock *sk, int level, int optname,
  857. char __user *optval, unsigned int optlen)
  858. {
  859. switch (level) {
  860. case SOL_RAW:
  861. break;
  862. case SOL_ICMPV6:
  863. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  864. return -EOPNOTSUPP;
  865. return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
  866. case SOL_IPV6:
  867. if (optname == IPV6_CHECKSUM)
  868. break;
  869. default:
  870. return ipv6_setsockopt(sk, level, optname, optval, optlen);
  871. }
  872. return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
  873. }
  874. #ifdef CONFIG_COMPAT
  875. static int compat_rawv6_setsockopt(struct sock *sk, int level, int optname,
  876. char __user *optval, unsigned int optlen)
  877. {
  878. switch (level) {
  879. case SOL_RAW:
  880. break;
  881. case SOL_ICMPV6:
  882. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  883. return -EOPNOTSUPP;
  884. return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
  885. case SOL_IPV6:
  886. if (optname == IPV6_CHECKSUM)
  887. break;
  888. default:
  889. return compat_ipv6_setsockopt(sk, level, optname,
  890. optval, optlen);
  891. }
  892. return do_rawv6_setsockopt(sk, level, optname, optval, optlen);
  893. }
  894. #endif
  895. static int do_rawv6_getsockopt(struct sock *sk, int level, int optname,
  896. char __user *optval, int __user *optlen)
  897. {
  898. struct raw6_sock *rp = raw6_sk(sk);
  899. int val, len;
  900. if (get_user(len, optlen))
  901. return -EFAULT;
  902. switch (optname) {
  903. case IPV6_CHECKSUM:
  904. /*
  905. * We allow getsockopt() for IPPROTO_IPV6-level
  906. * IPV6_CHECKSUM socket option on ICMPv6 sockets
  907. * since RFC3542 is silent about it.
  908. */
  909. if (rp->checksum == 0)
  910. val = -1;
  911. else
  912. val = rp->offset;
  913. break;
  914. default:
  915. return -ENOPROTOOPT;
  916. }
  917. len = min_t(unsigned int, sizeof(int), len);
  918. if (put_user(len, optlen))
  919. return -EFAULT;
  920. if (copy_to_user(optval, &val, len))
  921. return -EFAULT;
  922. return 0;
  923. }
  924. static int rawv6_getsockopt(struct sock *sk, int level, int optname,
  925. char __user *optval, int __user *optlen)
  926. {
  927. switch (level) {
  928. case SOL_RAW:
  929. break;
  930. case SOL_ICMPV6:
  931. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  932. return -EOPNOTSUPP;
  933. return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
  934. case SOL_IPV6:
  935. if (optname == IPV6_CHECKSUM)
  936. break;
  937. default:
  938. return ipv6_getsockopt(sk, level, optname, optval, optlen);
  939. }
  940. return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
  941. }
  942. #ifdef CONFIG_COMPAT
  943. static int compat_rawv6_getsockopt(struct sock *sk, int level, int optname,
  944. char __user *optval, int __user *optlen)
  945. {
  946. switch (level) {
  947. case SOL_RAW:
  948. break;
  949. case SOL_ICMPV6:
  950. if (inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
  951. return -EOPNOTSUPP;
  952. return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
  953. case SOL_IPV6:
  954. if (optname == IPV6_CHECKSUM)
  955. break;
  956. default:
  957. return compat_ipv6_getsockopt(sk, level, optname,
  958. optval, optlen);
  959. }
  960. return do_rawv6_getsockopt(sk, level, optname, optval, optlen);
  961. }
  962. #endif
  963. static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
  964. {
  965. switch (cmd) {
  966. case SIOCOUTQ: {
  967. int amount = sk_wmem_alloc_get(sk);
  968. return put_user(amount, (int __user *)arg);
  969. }
  970. case SIOCINQ: {
  971. struct sk_buff *skb;
  972. int amount = 0;
  973. spin_lock_bh(&sk->sk_receive_queue.lock);
  974. skb = skb_peek(&sk->sk_receive_queue);
  975. if (skb)
  976. amount = skb->len;
  977. spin_unlock_bh(&sk->sk_receive_queue.lock);
  978. return put_user(amount, (int __user *)arg);
  979. }
  980. default:
  981. #ifdef CONFIG_IPV6_MROUTE
  982. return ip6mr_ioctl(sk, cmd, (void __user *)arg);
  983. #else
  984. return -ENOIOCTLCMD;
  985. #endif
  986. }
  987. }
  988. #ifdef CONFIG_COMPAT
  989. static int compat_rawv6_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg)
  990. {
  991. switch (cmd) {
  992. case SIOCOUTQ:
  993. case SIOCINQ:
  994. return -ENOIOCTLCMD;
  995. default:
  996. #ifdef CONFIG_IPV6_MROUTE
  997. return ip6mr_compat_ioctl(sk, cmd, compat_ptr(arg));
  998. #else
  999. return -ENOIOCTLCMD;
  1000. #endif
  1001. }
  1002. }
  1003. #endif
  1004. static void rawv6_close(struct sock *sk, long timeout)
  1005. {
  1006. if (inet_sk(sk)->inet_num == IPPROTO_RAW)
  1007. ip6_ra_control(sk, -1);
  1008. ip6mr_sk_done(sk);
  1009. sk_common_release(sk);
  1010. }
  1011. static void raw6_destroy(struct sock *sk)
  1012. {
  1013. lock_sock(sk);
  1014. ip6_flush_pending_frames(sk);
  1015. release_sock(sk);
  1016. inet6_destroy_sock(sk);
  1017. }
  1018. static int rawv6_init_sk(struct sock *sk)
  1019. {
  1020. struct raw6_sock *rp = raw6_sk(sk);
  1021. switch (inet_sk(sk)->inet_num) {
  1022. case IPPROTO_ICMPV6:
  1023. rp->checksum = 1;
  1024. rp->offset = 2;
  1025. break;
  1026. case IPPROTO_MH:
  1027. rp->checksum = 1;
  1028. rp->offset = 4;
  1029. break;
  1030. default:
  1031. break;
  1032. }
  1033. return 0;
  1034. }
  1035. struct proto rawv6_prot = {
  1036. .name = "RAWv6",
  1037. .owner = THIS_MODULE,
  1038. .close = rawv6_close,
  1039. .destroy = raw6_destroy,
  1040. .connect = ip6_datagram_connect_v6_only,
  1041. .disconnect = udp_disconnect,
  1042. .ioctl = rawv6_ioctl,
  1043. .init = rawv6_init_sk,
  1044. .setsockopt = rawv6_setsockopt,
  1045. .getsockopt = rawv6_getsockopt,
  1046. .sendmsg = rawv6_sendmsg,
  1047. .recvmsg = rawv6_recvmsg,
  1048. .bind = rawv6_bind,
  1049. .backlog_rcv = rawv6_rcv_skb,
  1050. .hash = raw_hash_sk,
  1051. .unhash = raw_unhash_sk,
  1052. .obj_size = sizeof(struct raw6_sock),
  1053. .h.raw_hash = &raw_v6_hashinfo,
  1054. #ifdef CONFIG_COMPAT
  1055. .compat_setsockopt = compat_rawv6_setsockopt,
  1056. .compat_getsockopt = compat_rawv6_getsockopt,
  1057. .compat_ioctl = compat_rawv6_ioctl,
  1058. #endif
  1059. };
  1060. #ifdef CONFIG_PROC_FS
  1061. static int raw6_seq_show(struct seq_file *seq, void *v)
  1062. {
  1063. if (v == SEQ_START_TOKEN) {
  1064. seq_puts(seq, IPV6_SEQ_DGRAM_HEADER);
  1065. } else {
  1066. struct sock *sp = v;
  1067. __u16 srcp = inet_sk(sp)->inet_num;
  1068. ip6_dgram_sock_seq_show(seq, v, srcp, 0,
  1069. raw_seq_private(seq)->bucket);
  1070. }
  1071. return 0;
  1072. }
  1073. static const struct seq_operations raw6_seq_ops = {
  1074. .start = raw_seq_start,
  1075. .next = raw_seq_next,
  1076. .stop = raw_seq_stop,
  1077. .show = raw6_seq_show,
  1078. };
  1079. static int raw6_seq_open(struct inode *inode, struct file *file)
  1080. {
  1081. return raw_seq_open(inode, file, &raw_v6_hashinfo, &raw6_seq_ops);
  1082. }
  1083. static const struct file_operations raw6_seq_fops = {
  1084. .owner = THIS_MODULE,
  1085. .open = raw6_seq_open,
  1086. .read = seq_read,
  1087. .llseek = seq_lseek,
  1088. .release = seq_release_net,
  1089. };
  1090. static int __net_init raw6_init_net(struct net *net)
  1091. {
  1092. if (!proc_create("raw6", S_IRUGO, net->proc_net, &raw6_seq_fops))
  1093. return -ENOMEM;
  1094. return 0;
  1095. }
  1096. static void __net_exit raw6_exit_net(struct net *net)
  1097. {
  1098. remove_proc_entry("raw6", net->proc_net);
  1099. }
  1100. static struct pernet_operations raw6_net_ops = {
  1101. .init = raw6_init_net,
  1102. .exit = raw6_exit_net,
  1103. };
  1104. int __init raw6_proc_init(void)
  1105. {
  1106. return register_pernet_subsys(&raw6_net_ops);
  1107. }
  1108. void raw6_proc_exit(void)
  1109. {
  1110. unregister_pernet_subsys(&raw6_net_ops);
  1111. }
  1112. #endif /* CONFIG_PROC_FS */
  1113. /* Same as inet6_dgram_ops, sans udp_poll. */
  1114. const struct proto_ops inet6_sockraw_ops = {
  1115. .family = PF_INET6,
  1116. .owner = THIS_MODULE,
  1117. .release = inet6_release,
  1118. .bind = inet6_bind,
  1119. .connect = inet_dgram_connect, /* ok */
  1120. .socketpair = sock_no_socketpair, /* a do nothing */
  1121. .accept = sock_no_accept, /* a do nothing */
  1122. .getname = inet6_getname,
  1123. .poll = datagram_poll, /* ok */
  1124. .ioctl = inet6_ioctl, /* must change */
  1125. .listen = sock_no_listen, /* ok */
  1126. .shutdown = inet_shutdown, /* ok */
  1127. .setsockopt = sock_common_setsockopt, /* ok */
  1128. .getsockopt = sock_common_getsockopt, /* ok */
  1129. .sendmsg = inet_sendmsg, /* ok */
  1130. .recvmsg = sock_common_recvmsg, /* ok */
  1131. .mmap = sock_no_mmap,
  1132. .sendpage = sock_no_sendpage,
  1133. #ifdef CONFIG_COMPAT
  1134. .compat_setsockopt = compat_sock_common_setsockopt,
  1135. .compat_getsockopt = compat_sock_common_getsockopt,
  1136. #endif
  1137. };
  1138. static struct inet_protosw rawv6_protosw = {
  1139. .type = SOCK_RAW,
  1140. .protocol = IPPROTO_IP, /* wild card */
  1141. .prot = &rawv6_prot,
  1142. .ops = &inet6_sockraw_ops,
  1143. .flags = INET_PROTOSW_REUSE,
  1144. };
  1145. int __init rawv6_init(void)
  1146. {
  1147. return inet6_register_protosw(&rawv6_protosw);
  1148. }
  1149. void rawv6_exit(void)
  1150. {
  1151. inet6_unregister_protosw(&rawv6_protosw);
  1152. }