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