raw.c 30 KB

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