ip6_flowlabel.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * ip6_flowlabel.c IPv6 flowlabel manager.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  10. */
  11. #include <linux/config.h>
  12. #include <linux/errno.h>
  13. #include <linux/types.h>
  14. #include <linux/socket.h>
  15. #include <linux/net.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/in6.h>
  19. #include <linux/route.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/seq_file.h>
  22. #include <net/sock.h>
  23. #include <net/ipv6.h>
  24. #include <net/ndisc.h>
  25. #include <net/protocol.h>
  26. #include <net/ip6_route.h>
  27. #include <net/addrconf.h>
  28. #include <net/rawv6.h>
  29. #include <net/icmp.h>
  30. #include <net/transp_v6.h>
  31. #include <asm/uaccess.h>
  32. #define FL_MIN_LINGER 6 /* Minimal linger. It is set to 6sec specified
  33. in old IPv6 RFC. Well, it was reasonable value.
  34. */
  35. #define FL_MAX_LINGER 60 /* Maximal linger timeout */
  36. /* FL hash table */
  37. #define FL_MAX_PER_SOCK 32
  38. #define FL_MAX_SIZE 4096
  39. #define FL_HASH_MASK 255
  40. #define FL_HASH(l) (ntohl(l)&FL_HASH_MASK)
  41. static atomic_t fl_size = ATOMIC_INIT(0);
  42. static struct ip6_flowlabel *fl_ht[FL_HASH_MASK+1];
  43. static void ip6_fl_gc(unsigned long dummy);
  44. static DEFINE_TIMER(ip6_fl_gc_timer, ip6_fl_gc, 0, 0);
  45. /* FL hash table lock: it protects only of GC */
  46. static DEFINE_RWLOCK(ip6_fl_lock);
  47. /* Big socket sock */
  48. static DEFINE_RWLOCK(ip6_sk_fl_lock);
  49. static __inline__ struct ip6_flowlabel * __fl_lookup(u32 label)
  50. {
  51. struct ip6_flowlabel *fl;
  52. for (fl=fl_ht[FL_HASH(label)]; fl; fl = fl->next) {
  53. if (fl->label == label)
  54. return fl;
  55. }
  56. return NULL;
  57. }
  58. static struct ip6_flowlabel * fl_lookup(u32 label)
  59. {
  60. struct ip6_flowlabel *fl;
  61. read_lock_bh(&ip6_fl_lock);
  62. fl = __fl_lookup(label);
  63. if (fl)
  64. atomic_inc(&fl->users);
  65. read_unlock_bh(&ip6_fl_lock);
  66. return fl;
  67. }
  68. static void fl_free(struct ip6_flowlabel *fl)
  69. {
  70. if (fl)
  71. kfree(fl->opt);
  72. kfree(fl);
  73. }
  74. static void fl_release(struct ip6_flowlabel *fl)
  75. {
  76. write_lock_bh(&ip6_fl_lock);
  77. fl->lastuse = jiffies;
  78. if (atomic_dec_and_test(&fl->users)) {
  79. unsigned long ttd = fl->lastuse + fl->linger;
  80. if (time_after(ttd, fl->expires))
  81. fl->expires = ttd;
  82. ttd = fl->expires;
  83. if (fl->opt && fl->share == IPV6_FL_S_EXCL) {
  84. struct ipv6_txoptions *opt = fl->opt;
  85. fl->opt = NULL;
  86. kfree(opt);
  87. }
  88. if (!timer_pending(&ip6_fl_gc_timer) ||
  89. time_after(ip6_fl_gc_timer.expires, ttd))
  90. mod_timer(&ip6_fl_gc_timer, ttd);
  91. }
  92. write_unlock_bh(&ip6_fl_lock);
  93. }
  94. static void ip6_fl_gc(unsigned long dummy)
  95. {
  96. int i;
  97. unsigned long now = jiffies;
  98. unsigned long sched = 0;
  99. write_lock(&ip6_fl_lock);
  100. for (i=0; i<=FL_HASH_MASK; i++) {
  101. struct ip6_flowlabel *fl, **flp;
  102. flp = &fl_ht[i];
  103. while ((fl=*flp) != NULL) {
  104. if (atomic_read(&fl->users) == 0) {
  105. unsigned long ttd = fl->lastuse + fl->linger;
  106. if (time_after(ttd, fl->expires))
  107. fl->expires = ttd;
  108. ttd = fl->expires;
  109. if (time_after_eq(now, ttd)) {
  110. *flp = fl->next;
  111. fl_free(fl);
  112. atomic_dec(&fl_size);
  113. continue;
  114. }
  115. if (!sched || time_before(ttd, sched))
  116. sched = ttd;
  117. }
  118. flp = &fl->next;
  119. }
  120. }
  121. if (!sched && atomic_read(&fl_size))
  122. sched = now + FL_MAX_LINGER;
  123. if (sched) {
  124. ip6_fl_gc_timer.expires = sched;
  125. add_timer(&ip6_fl_gc_timer);
  126. }
  127. write_unlock(&ip6_fl_lock);
  128. }
  129. static int fl_intern(struct ip6_flowlabel *fl, __u32 label)
  130. {
  131. fl->label = label & IPV6_FLOWLABEL_MASK;
  132. write_lock_bh(&ip6_fl_lock);
  133. if (label == 0) {
  134. for (;;) {
  135. fl->label = htonl(net_random())&IPV6_FLOWLABEL_MASK;
  136. if (fl->label) {
  137. struct ip6_flowlabel *lfl;
  138. lfl = __fl_lookup(fl->label);
  139. if (lfl == NULL)
  140. break;
  141. }
  142. }
  143. }
  144. fl->lastuse = jiffies;
  145. fl->next = fl_ht[FL_HASH(fl->label)];
  146. fl_ht[FL_HASH(fl->label)] = fl;
  147. atomic_inc(&fl_size);
  148. write_unlock_bh(&ip6_fl_lock);
  149. return 0;
  150. }
  151. /* Socket flowlabel lists */
  152. struct ip6_flowlabel * fl6_sock_lookup(struct sock *sk, u32 label)
  153. {
  154. struct ipv6_fl_socklist *sfl;
  155. struct ipv6_pinfo *np = inet6_sk(sk);
  156. label &= IPV6_FLOWLABEL_MASK;
  157. for (sfl=np->ipv6_fl_list; sfl; sfl = sfl->next) {
  158. struct ip6_flowlabel *fl = sfl->fl;
  159. if (fl->label == label) {
  160. fl->lastuse = jiffies;
  161. atomic_inc(&fl->users);
  162. return fl;
  163. }
  164. }
  165. return NULL;
  166. }
  167. void fl6_free_socklist(struct sock *sk)
  168. {
  169. struct ipv6_pinfo *np = inet6_sk(sk);
  170. struct ipv6_fl_socklist *sfl;
  171. while ((sfl = np->ipv6_fl_list) != NULL) {
  172. np->ipv6_fl_list = sfl->next;
  173. fl_release(sfl->fl);
  174. kfree(sfl);
  175. }
  176. }
  177. /* Service routines */
  178. /*
  179. It is the only difficult place. flowlabel enforces equal headers
  180. before and including routing header, however user may supply options
  181. following rthdr.
  182. */
  183. struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space,
  184. struct ip6_flowlabel * fl,
  185. struct ipv6_txoptions * fopt)
  186. {
  187. struct ipv6_txoptions * fl_opt = fl ? fl->opt : NULL;
  188. if (fopt == NULL || fopt->opt_flen == 0) {
  189. if (!fl_opt || !fl_opt->dst0opt || fl_opt->srcrt)
  190. return fl_opt;
  191. }
  192. if (fl_opt != NULL) {
  193. opt_space->hopopt = fl_opt->hopopt;
  194. opt_space->dst0opt = fl_opt->srcrt ? fl_opt->dst0opt : NULL;
  195. opt_space->srcrt = fl_opt->srcrt;
  196. opt_space->opt_nflen = fl_opt->opt_nflen;
  197. if (fl_opt->dst0opt && !fl_opt->srcrt)
  198. opt_space->opt_nflen -= ipv6_optlen(fl_opt->dst0opt);
  199. } else {
  200. if (fopt->opt_nflen == 0)
  201. return fopt;
  202. opt_space->hopopt = NULL;
  203. opt_space->dst0opt = NULL;
  204. opt_space->srcrt = NULL;
  205. opt_space->opt_nflen = 0;
  206. }
  207. opt_space->dst1opt = fopt->dst1opt;
  208. opt_space->opt_flen = fopt->opt_flen;
  209. return opt_space;
  210. }
  211. static unsigned long check_linger(unsigned long ttl)
  212. {
  213. if (ttl < FL_MIN_LINGER)
  214. return FL_MIN_LINGER*HZ;
  215. if (ttl > FL_MAX_LINGER && !capable(CAP_NET_ADMIN))
  216. return 0;
  217. return ttl*HZ;
  218. }
  219. static int fl6_renew(struct ip6_flowlabel *fl, unsigned long linger, unsigned long expires)
  220. {
  221. linger = check_linger(linger);
  222. if (!linger)
  223. return -EPERM;
  224. expires = check_linger(expires);
  225. if (!expires)
  226. return -EPERM;
  227. fl->lastuse = jiffies;
  228. if (time_before(fl->linger, linger))
  229. fl->linger = linger;
  230. if (time_before(expires, fl->linger))
  231. expires = fl->linger;
  232. if (time_before(fl->expires, fl->lastuse + expires))
  233. fl->expires = fl->lastuse + expires;
  234. return 0;
  235. }
  236. static struct ip6_flowlabel *
  237. fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *err_p)
  238. {
  239. struct ip6_flowlabel *fl;
  240. int olen;
  241. int addr_type;
  242. int err;
  243. err = -ENOMEM;
  244. fl = kmalloc(sizeof(*fl), GFP_KERNEL);
  245. if (fl == NULL)
  246. goto done;
  247. memset(fl, 0, sizeof(*fl));
  248. olen = optlen - CMSG_ALIGN(sizeof(*freq));
  249. if (olen > 0) {
  250. struct msghdr msg;
  251. struct flowi flowi;
  252. int junk;
  253. err = -ENOMEM;
  254. fl->opt = kmalloc(sizeof(*fl->opt) + olen, GFP_KERNEL);
  255. if (fl->opt == NULL)
  256. goto done;
  257. memset(fl->opt, 0, sizeof(*fl->opt));
  258. fl->opt->tot_len = sizeof(*fl->opt) + olen;
  259. err = -EFAULT;
  260. if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen))
  261. goto done;
  262. msg.msg_controllen = olen;
  263. msg.msg_control = (void*)(fl->opt+1);
  264. flowi.oif = 0;
  265. err = datagram_send_ctl(&msg, &flowi, fl->opt, &junk, &junk);
  266. if (err)
  267. goto done;
  268. err = -EINVAL;
  269. if (fl->opt->opt_flen)
  270. goto done;
  271. if (fl->opt->opt_nflen == 0) {
  272. kfree(fl->opt);
  273. fl->opt = NULL;
  274. }
  275. }
  276. fl->expires = jiffies;
  277. err = fl6_renew(fl, freq->flr_linger, freq->flr_expires);
  278. if (err)
  279. goto done;
  280. fl->share = freq->flr_share;
  281. addr_type = ipv6_addr_type(&freq->flr_dst);
  282. if ((addr_type&IPV6_ADDR_MAPPED)
  283. || addr_type == IPV6_ADDR_ANY)
  284. goto done;
  285. ipv6_addr_copy(&fl->dst, &freq->flr_dst);
  286. atomic_set(&fl->users, 1);
  287. switch (fl->share) {
  288. case IPV6_FL_S_EXCL:
  289. case IPV6_FL_S_ANY:
  290. break;
  291. case IPV6_FL_S_PROCESS:
  292. fl->owner = current->pid;
  293. break;
  294. case IPV6_FL_S_USER:
  295. fl->owner = current->euid;
  296. break;
  297. default:
  298. err = -EINVAL;
  299. goto done;
  300. }
  301. return fl;
  302. done:
  303. fl_free(fl);
  304. *err_p = err;
  305. return NULL;
  306. }
  307. static int mem_check(struct sock *sk)
  308. {
  309. struct ipv6_pinfo *np = inet6_sk(sk);
  310. struct ipv6_fl_socklist *sfl;
  311. int room = FL_MAX_SIZE - atomic_read(&fl_size);
  312. int count = 0;
  313. if (room > FL_MAX_SIZE - FL_MAX_PER_SOCK)
  314. return 0;
  315. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next)
  316. count++;
  317. if (room <= 0 ||
  318. ((count >= FL_MAX_PER_SOCK ||
  319. (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4)
  320. && !capable(CAP_NET_ADMIN)))
  321. return -ENOBUFS;
  322. return 0;
  323. }
  324. static int ipv6_hdr_cmp(struct ipv6_opt_hdr *h1, struct ipv6_opt_hdr *h2)
  325. {
  326. if (h1 == h2)
  327. return 0;
  328. if (h1 == NULL || h2 == NULL)
  329. return 1;
  330. if (h1->hdrlen != h2->hdrlen)
  331. return 1;
  332. return memcmp(h1+1, h2+1, ((h1->hdrlen+1)<<3) - sizeof(*h1));
  333. }
  334. static int ipv6_opt_cmp(struct ipv6_txoptions *o1, struct ipv6_txoptions *o2)
  335. {
  336. if (o1 == o2)
  337. return 0;
  338. if (o1 == NULL || o2 == NULL)
  339. return 1;
  340. if (o1->opt_nflen != o2->opt_nflen)
  341. return 1;
  342. if (ipv6_hdr_cmp(o1->hopopt, o2->hopopt))
  343. return 1;
  344. if (ipv6_hdr_cmp(o1->dst0opt, o2->dst0opt))
  345. return 1;
  346. if (ipv6_hdr_cmp((struct ipv6_opt_hdr *)o1->srcrt, (struct ipv6_opt_hdr *)o2->srcrt))
  347. return 1;
  348. return 0;
  349. }
  350. int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
  351. {
  352. int err;
  353. struct ipv6_pinfo *np = inet6_sk(sk);
  354. struct in6_flowlabel_req freq;
  355. struct ipv6_fl_socklist *sfl1=NULL;
  356. struct ipv6_fl_socklist *sfl, **sflp;
  357. struct ip6_flowlabel *fl;
  358. if (optlen < sizeof(freq))
  359. return -EINVAL;
  360. if (copy_from_user(&freq, optval, sizeof(freq)))
  361. return -EFAULT;
  362. switch (freq.flr_action) {
  363. case IPV6_FL_A_PUT:
  364. write_lock_bh(&ip6_sk_fl_lock);
  365. for (sflp = &np->ipv6_fl_list; (sfl=*sflp)!=NULL; sflp = &sfl->next) {
  366. if (sfl->fl->label == freq.flr_label) {
  367. if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK))
  368. np->flow_label &= ~IPV6_FLOWLABEL_MASK;
  369. *sflp = sfl->next;
  370. write_unlock_bh(&ip6_sk_fl_lock);
  371. fl_release(sfl->fl);
  372. kfree(sfl);
  373. return 0;
  374. }
  375. }
  376. write_unlock_bh(&ip6_sk_fl_lock);
  377. return -ESRCH;
  378. case IPV6_FL_A_RENEW:
  379. read_lock_bh(&ip6_sk_fl_lock);
  380. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
  381. if (sfl->fl->label == freq.flr_label) {
  382. err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires);
  383. read_unlock_bh(&ip6_sk_fl_lock);
  384. return err;
  385. }
  386. }
  387. read_unlock_bh(&ip6_sk_fl_lock);
  388. if (freq.flr_share == IPV6_FL_S_NONE && capable(CAP_NET_ADMIN)) {
  389. fl = fl_lookup(freq.flr_label);
  390. if (fl) {
  391. err = fl6_renew(fl, freq.flr_linger, freq.flr_expires);
  392. fl_release(fl);
  393. return err;
  394. }
  395. }
  396. return -ESRCH;
  397. case IPV6_FL_A_GET:
  398. if (freq.flr_label & ~IPV6_FLOWLABEL_MASK)
  399. return -EINVAL;
  400. fl = fl_create(&freq, optval, optlen, &err);
  401. if (fl == NULL)
  402. return err;
  403. sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL);
  404. if (freq.flr_label) {
  405. struct ip6_flowlabel *fl1 = NULL;
  406. err = -EEXIST;
  407. read_lock_bh(&ip6_sk_fl_lock);
  408. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
  409. if (sfl->fl->label == freq.flr_label) {
  410. if (freq.flr_flags&IPV6_FL_F_EXCL) {
  411. read_unlock_bh(&ip6_sk_fl_lock);
  412. goto done;
  413. }
  414. fl1 = sfl->fl;
  415. atomic_inc(&fl->users);
  416. break;
  417. }
  418. }
  419. read_unlock_bh(&ip6_sk_fl_lock);
  420. if (fl1 == NULL)
  421. fl1 = fl_lookup(freq.flr_label);
  422. if (fl1) {
  423. err = -EEXIST;
  424. if (freq.flr_flags&IPV6_FL_F_EXCL)
  425. goto release;
  426. err = -EPERM;
  427. if (fl1->share == IPV6_FL_S_EXCL ||
  428. fl1->share != fl->share ||
  429. fl1->owner != fl->owner)
  430. goto release;
  431. err = -EINVAL;
  432. if (!ipv6_addr_equal(&fl1->dst, &fl->dst) ||
  433. ipv6_opt_cmp(fl1->opt, fl->opt))
  434. goto release;
  435. err = -ENOMEM;
  436. if (sfl1 == NULL)
  437. goto release;
  438. if (fl->linger > fl1->linger)
  439. fl1->linger = fl->linger;
  440. if ((long)(fl->expires - fl1->expires) > 0)
  441. fl1->expires = fl->expires;
  442. write_lock_bh(&ip6_sk_fl_lock);
  443. sfl1->fl = fl1;
  444. sfl1->next = np->ipv6_fl_list;
  445. np->ipv6_fl_list = sfl1;
  446. write_unlock_bh(&ip6_sk_fl_lock);
  447. fl_free(fl);
  448. return 0;
  449. release:
  450. fl_release(fl1);
  451. goto done;
  452. }
  453. }
  454. err = -ENOENT;
  455. if (!(freq.flr_flags&IPV6_FL_F_CREATE))
  456. goto done;
  457. err = -ENOMEM;
  458. if (sfl1 == NULL || (err = mem_check(sk)) != 0)
  459. goto done;
  460. err = fl_intern(fl, freq.flr_label);
  461. if (err)
  462. goto done;
  463. if (!freq.flr_label) {
  464. if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label,
  465. &fl->label, sizeof(fl->label))) {
  466. /* Intentionally ignore fault. */
  467. }
  468. }
  469. sfl1->fl = fl;
  470. sfl1->next = np->ipv6_fl_list;
  471. np->ipv6_fl_list = sfl1;
  472. return 0;
  473. default:
  474. return -EINVAL;
  475. }
  476. done:
  477. fl_free(fl);
  478. kfree(sfl1);
  479. return err;
  480. }
  481. #ifdef CONFIG_PROC_FS
  482. struct ip6fl_iter_state {
  483. int bucket;
  484. };
  485. #define ip6fl_seq_private(seq) ((struct ip6fl_iter_state *)(seq)->private)
  486. static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq)
  487. {
  488. struct ip6_flowlabel *fl = NULL;
  489. struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
  490. for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) {
  491. if (fl_ht[state->bucket]) {
  492. fl = fl_ht[state->bucket];
  493. break;
  494. }
  495. }
  496. return fl;
  497. }
  498. static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flowlabel *fl)
  499. {
  500. struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
  501. fl = fl->next;
  502. while (!fl) {
  503. if (++state->bucket <= FL_HASH_MASK)
  504. fl = fl_ht[state->bucket];
  505. }
  506. return fl;
  507. }
  508. static struct ip6_flowlabel *ip6fl_get_idx(struct seq_file *seq, loff_t pos)
  509. {
  510. struct ip6_flowlabel *fl = ip6fl_get_first(seq);
  511. if (fl)
  512. while (pos && (fl = ip6fl_get_next(seq, fl)) != NULL)
  513. --pos;
  514. return pos ? NULL : fl;
  515. }
  516. static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos)
  517. {
  518. read_lock_bh(&ip6_fl_lock);
  519. return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
  520. }
  521. static void *ip6fl_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  522. {
  523. struct ip6_flowlabel *fl;
  524. if (v == SEQ_START_TOKEN)
  525. fl = ip6fl_get_first(seq);
  526. else
  527. fl = ip6fl_get_next(seq, v);
  528. ++*pos;
  529. return fl;
  530. }
  531. static void ip6fl_seq_stop(struct seq_file *seq, void *v)
  532. {
  533. read_unlock_bh(&ip6_fl_lock);
  534. }
  535. static void ip6fl_fl_seq_show(struct seq_file *seq, struct ip6_flowlabel *fl)
  536. {
  537. while(fl) {
  538. seq_printf(seq,
  539. "%05X %-1d %-6d %-6d %-6ld %-8ld "
  540. "%02x%02x%02x%02x%02x%02x%02x%02x "
  541. "%-4d\n",
  542. (unsigned)ntohl(fl->label),
  543. fl->share,
  544. (unsigned)fl->owner,
  545. atomic_read(&fl->users),
  546. fl->linger/HZ,
  547. (long)(fl->expires - jiffies)/HZ,
  548. NIP6(fl->dst),
  549. fl->opt ? fl->opt->opt_nflen : 0);
  550. fl = fl->next;
  551. }
  552. }
  553. static int ip6fl_seq_show(struct seq_file *seq, void *v)
  554. {
  555. if (v == SEQ_START_TOKEN)
  556. seq_puts(seq, "Label S Owner Users Linger Expires "
  557. "Dst Opt\n");
  558. else
  559. ip6fl_fl_seq_show(seq, v);
  560. return 0;
  561. }
  562. static struct seq_operations ip6fl_seq_ops = {
  563. .start = ip6fl_seq_start,
  564. .next = ip6fl_seq_next,
  565. .stop = ip6fl_seq_stop,
  566. .show = ip6fl_seq_show,
  567. };
  568. static int ip6fl_seq_open(struct inode *inode, struct file *file)
  569. {
  570. struct seq_file *seq;
  571. int rc = -ENOMEM;
  572. struct ip6fl_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
  573. if (!s)
  574. goto out;
  575. rc = seq_open(file, &ip6fl_seq_ops);
  576. if (rc)
  577. goto out_kfree;
  578. seq = file->private_data;
  579. seq->private = s;
  580. memset(s, 0, sizeof(*s));
  581. out:
  582. return rc;
  583. out_kfree:
  584. kfree(s);
  585. goto out;
  586. }
  587. static struct file_operations ip6fl_seq_fops = {
  588. .owner = THIS_MODULE,
  589. .open = ip6fl_seq_open,
  590. .read = seq_read,
  591. .llseek = seq_lseek,
  592. .release = seq_release_private,
  593. };
  594. #endif
  595. void ip6_flowlabel_init(void)
  596. {
  597. #ifdef CONFIG_PROC_FS
  598. proc_net_fops_create("ip6_flowlabel", S_IRUGO, &ip6fl_seq_fops);
  599. #endif
  600. }
  601. void ip6_flowlabel_cleanup(void)
  602. {
  603. del_timer(&ip6_fl_gc_timer);
  604. #ifdef CONFIG_PROC_FS
  605. proc_net_remove("ip6_flowlabel");
  606. #endif
  607. }