ip6_flowlabel.c 15 KB

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