ip6_flowlabel.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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/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. EXPORT_SYMBOL_GPL(fl6_sock_lookup);
  168. void fl6_free_socklist(struct sock *sk)
  169. {
  170. struct ipv6_pinfo *np = inet6_sk(sk);
  171. struct ipv6_fl_socklist *sfl;
  172. while ((sfl = np->ipv6_fl_list) != NULL) {
  173. np->ipv6_fl_list = sfl->next;
  174. fl_release(sfl->fl);
  175. kfree(sfl);
  176. }
  177. }
  178. /* Service routines */
  179. /*
  180. It is the only difficult place. flowlabel enforces equal headers
  181. before and including routing header, however user may supply options
  182. following rthdr.
  183. */
  184. struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space,
  185. struct ip6_flowlabel * fl,
  186. struct ipv6_txoptions * fopt)
  187. {
  188. struct ipv6_txoptions * fl_opt = fl->opt;
  189. if (fopt == NULL || fopt->opt_flen == 0)
  190. return fl_opt;
  191. if (fl_opt != NULL) {
  192. opt_space->hopopt = fl_opt->hopopt;
  193. opt_space->dst0opt = fl_opt->dst0opt;
  194. opt_space->srcrt = fl_opt->srcrt;
  195. opt_space->opt_nflen = fl_opt->opt_nflen;
  196. } else {
  197. if (fopt->opt_nflen == 0)
  198. return fopt;
  199. opt_space->hopopt = NULL;
  200. opt_space->dst0opt = NULL;
  201. opt_space->srcrt = NULL;
  202. opt_space->opt_nflen = 0;
  203. }
  204. opt_space->dst1opt = fopt->dst1opt;
  205. opt_space->opt_flen = fopt->opt_flen;
  206. return opt_space;
  207. }
  208. static unsigned long check_linger(unsigned long ttl)
  209. {
  210. if (ttl < FL_MIN_LINGER)
  211. return FL_MIN_LINGER*HZ;
  212. if (ttl > FL_MAX_LINGER && !capable(CAP_NET_ADMIN))
  213. return 0;
  214. return ttl*HZ;
  215. }
  216. static int fl6_renew(struct ip6_flowlabel *fl, unsigned long linger, unsigned long expires)
  217. {
  218. linger = check_linger(linger);
  219. if (!linger)
  220. return -EPERM;
  221. expires = check_linger(expires);
  222. if (!expires)
  223. return -EPERM;
  224. fl->lastuse = jiffies;
  225. if (time_before(fl->linger, linger))
  226. fl->linger = linger;
  227. if (time_before(expires, fl->linger))
  228. expires = fl->linger;
  229. if (time_before(fl->expires, fl->lastuse + expires))
  230. fl->expires = fl->lastuse + expires;
  231. return 0;
  232. }
  233. static struct ip6_flowlabel *
  234. fl_create(struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *err_p)
  235. {
  236. struct ip6_flowlabel *fl;
  237. int olen;
  238. int addr_type;
  239. int err;
  240. err = -ENOMEM;
  241. fl = kzalloc(sizeof(*fl), GFP_KERNEL);
  242. if (fl == NULL)
  243. goto done;
  244. olen = optlen - CMSG_ALIGN(sizeof(*freq));
  245. if (olen > 0) {
  246. struct msghdr msg;
  247. struct flowi flowi;
  248. int junk;
  249. err = -ENOMEM;
  250. fl->opt = kmalloc(sizeof(*fl->opt) + olen, GFP_KERNEL);
  251. if (fl->opt == NULL)
  252. goto done;
  253. memset(fl->opt, 0, sizeof(*fl->opt));
  254. fl->opt->tot_len = sizeof(*fl->opt) + olen;
  255. err = -EFAULT;
  256. if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen))
  257. goto done;
  258. msg.msg_controllen = olen;
  259. msg.msg_control = (void*)(fl->opt+1);
  260. flowi.oif = 0;
  261. err = datagram_send_ctl(&msg, &flowi, fl->opt, &junk, &junk);
  262. if (err)
  263. goto done;
  264. err = -EINVAL;
  265. if (fl->opt->opt_flen)
  266. goto done;
  267. if (fl->opt->opt_nflen == 0) {
  268. kfree(fl->opt);
  269. fl->opt = NULL;
  270. }
  271. }
  272. fl->expires = jiffies;
  273. err = fl6_renew(fl, freq->flr_linger, freq->flr_expires);
  274. if (err)
  275. goto done;
  276. fl->share = freq->flr_share;
  277. addr_type = ipv6_addr_type(&freq->flr_dst);
  278. if ((addr_type&IPV6_ADDR_MAPPED)
  279. || addr_type == IPV6_ADDR_ANY)
  280. goto done;
  281. ipv6_addr_copy(&fl->dst, &freq->flr_dst);
  282. atomic_set(&fl->users, 1);
  283. switch (fl->share) {
  284. case IPV6_FL_S_EXCL:
  285. case IPV6_FL_S_ANY:
  286. break;
  287. case IPV6_FL_S_PROCESS:
  288. fl->owner = current->pid;
  289. break;
  290. case IPV6_FL_S_USER:
  291. fl->owner = current->euid;
  292. break;
  293. default:
  294. err = -EINVAL;
  295. goto done;
  296. }
  297. return fl;
  298. done:
  299. fl_free(fl);
  300. *err_p = err;
  301. return NULL;
  302. }
  303. static int mem_check(struct sock *sk)
  304. {
  305. struct ipv6_pinfo *np = inet6_sk(sk);
  306. struct ipv6_fl_socklist *sfl;
  307. int room = FL_MAX_SIZE - atomic_read(&fl_size);
  308. int count = 0;
  309. if (room > FL_MAX_SIZE - FL_MAX_PER_SOCK)
  310. return 0;
  311. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next)
  312. count++;
  313. if (room <= 0 ||
  314. ((count >= FL_MAX_PER_SOCK ||
  315. (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4)
  316. && !capable(CAP_NET_ADMIN)))
  317. return -ENOBUFS;
  318. return 0;
  319. }
  320. static int ipv6_hdr_cmp(struct ipv6_opt_hdr *h1, struct ipv6_opt_hdr *h2)
  321. {
  322. if (h1 == h2)
  323. return 0;
  324. if (h1 == NULL || h2 == NULL)
  325. return 1;
  326. if (h1->hdrlen != h2->hdrlen)
  327. return 1;
  328. return memcmp(h1+1, h2+1, ((h1->hdrlen+1)<<3) - sizeof(*h1));
  329. }
  330. static int ipv6_opt_cmp(struct ipv6_txoptions *o1, struct ipv6_txoptions *o2)
  331. {
  332. if (o1 == o2)
  333. return 0;
  334. if (o1 == NULL || o2 == NULL)
  335. return 1;
  336. if (o1->opt_nflen != o2->opt_nflen)
  337. return 1;
  338. if (ipv6_hdr_cmp(o1->hopopt, o2->hopopt))
  339. return 1;
  340. if (ipv6_hdr_cmp(o1->dst0opt, o2->dst0opt))
  341. return 1;
  342. if (ipv6_hdr_cmp((struct ipv6_opt_hdr *)o1->srcrt, (struct ipv6_opt_hdr *)o2->srcrt))
  343. return 1;
  344. return 0;
  345. }
  346. int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
  347. {
  348. int err;
  349. struct ipv6_pinfo *np = inet6_sk(sk);
  350. struct in6_flowlabel_req freq;
  351. struct ipv6_fl_socklist *sfl1=NULL;
  352. struct ipv6_fl_socklist *sfl, **sflp;
  353. struct ip6_flowlabel *fl;
  354. if (optlen < sizeof(freq))
  355. return -EINVAL;
  356. if (copy_from_user(&freq, optval, sizeof(freq)))
  357. return -EFAULT;
  358. switch (freq.flr_action) {
  359. case IPV6_FL_A_PUT:
  360. write_lock_bh(&ip6_sk_fl_lock);
  361. for (sflp = &np->ipv6_fl_list; (sfl=*sflp)!=NULL; sflp = &sfl->next) {
  362. if (sfl->fl->label == freq.flr_label) {
  363. if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK))
  364. np->flow_label &= ~IPV6_FLOWLABEL_MASK;
  365. *sflp = sfl->next;
  366. write_unlock_bh(&ip6_sk_fl_lock);
  367. fl_release(sfl->fl);
  368. kfree(sfl);
  369. return 0;
  370. }
  371. }
  372. write_unlock_bh(&ip6_sk_fl_lock);
  373. return -ESRCH;
  374. case IPV6_FL_A_RENEW:
  375. read_lock_bh(&ip6_sk_fl_lock);
  376. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
  377. if (sfl->fl->label == freq.flr_label) {
  378. err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires);
  379. read_unlock_bh(&ip6_sk_fl_lock);
  380. return err;
  381. }
  382. }
  383. read_unlock_bh(&ip6_sk_fl_lock);
  384. if (freq.flr_share == IPV6_FL_S_NONE && capable(CAP_NET_ADMIN)) {
  385. fl = fl_lookup(freq.flr_label);
  386. if (fl) {
  387. err = fl6_renew(fl, freq.flr_linger, freq.flr_expires);
  388. fl_release(fl);
  389. return err;
  390. }
  391. }
  392. return -ESRCH;
  393. case IPV6_FL_A_GET:
  394. if (freq.flr_label & ~IPV6_FLOWLABEL_MASK)
  395. return -EINVAL;
  396. fl = fl_create(&freq, optval, optlen, &err);
  397. if (fl == NULL)
  398. return err;
  399. sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL);
  400. if (freq.flr_label) {
  401. struct ip6_flowlabel *fl1 = NULL;
  402. err = -EEXIST;
  403. read_lock_bh(&ip6_sk_fl_lock);
  404. for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) {
  405. if (sfl->fl->label == freq.flr_label) {
  406. if (freq.flr_flags&IPV6_FL_F_EXCL) {
  407. read_unlock_bh(&ip6_sk_fl_lock);
  408. goto done;
  409. }
  410. fl1 = sfl->fl;
  411. atomic_inc(&fl1->users);
  412. break;
  413. }
  414. }
  415. read_unlock_bh(&ip6_sk_fl_lock);
  416. if (fl1 == NULL)
  417. fl1 = fl_lookup(freq.flr_label);
  418. if (fl1) {
  419. err = -EEXIST;
  420. if (freq.flr_flags&IPV6_FL_F_EXCL)
  421. goto release;
  422. err = -EPERM;
  423. if (fl1->share == IPV6_FL_S_EXCL ||
  424. fl1->share != fl->share ||
  425. fl1->owner != fl->owner)
  426. goto release;
  427. err = -EINVAL;
  428. if (!ipv6_addr_equal(&fl1->dst, &fl->dst) ||
  429. ipv6_opt_cmp(fl1->opt, fl->opt))
  430. goto release;
  431. err = -ENOMEM;
  432. if (sfl1 == NULL)
  433. goto release;
  434. if (fl->linger > fl1->linger)
  435. fl1->linger = fl->linger;
  436. if ((long)(fl->expires - fl1->expires) > 0)
  437. fl1->expires = fl->expires;
  438. write_lock_bh(&ip6_sk_fl_lock);
  439. sfl1->fl = fl1;
  440. sfl1->next = np->ipv6_fl_list;
  441. np->ipv6_fl_list = sfl1;
  442. write_unlock_bh(&ip6_sk_fl_lock);
  443. fl_free(fl);
  444. return 0;
  445. release:
  446. fl_release(fl1);
  447. goto done;
  448. }
  449. }
  450. err = -ENOENT;
  451. if (!(freq.flr_flags&IPV6_FL_F_CREATE))
  452. goto done;
  453. err = -ENOMEM;
  454. if (sfl1 == NULL || (err = mem_check(sk)) != 0)
  455. goto done;
  456. err = fl_intern(fl, freq.flr_label);
  457. if (err)
  458. goto done;
  459. if (!freq.flr_label) {
  460. if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label,
  461. &fl->label, sizeof(fl->label))) {
  462. /* Intentionally ignore fault. */
  463. }
  464. }
  465. sfl1->fl = fl;
  466. sfl1->next = np->ipv6_fl_list;
  467. np->ipv6_fl_list = sfl1;
  468. return 0;
  469. default:
  470. return -EINVAL;
  471. }
  472. done:
  473. fl_free(fl);
  474. kfree(sfl1);
  475. return err;
  476. }
  477. #ifdef CONFIG_PROC_FS
  478. struct ip6fl_iter_state {
  479. int bucket;
  480. };
  481. #define ip6fl_seq_private(seq) ((struct ip6fl_iter_state *)(seq)->private)
  482. static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq)
  483. {
  484. struct ip6_flowlabel *fl = NULL;
  485. struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
  486. for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) {
  487. if (fl_ht[state->bucket]) {
  488. fl = fl_ht[state->bucket];
  489. break;
  490. }
  491. }
  492. return fl;
  493. }
  494. static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flowlabel *fl)
  495. {
  496. struct ip6fl_iter_state *state = ip6fl_seq_private(seq);
  497. fl = fl->next;
  498. while (!fl) {
  499. if (++state->bucket <= FL_HASH_MASK)
  500. fl = fl_ht[state->bucket];
  501. }
  502. return fl;
  503. }
  504. static struct ip6_flowlabel *ip6fl_get_idx(struct seq_file *seq, loff_t pos)
  505. {
  506. struct ip6_flowlabel *fl = ip6fl_get_first(seq);
  507. if (fl)
  508. while (pos && (fl = ip6fl_get_next(seq, fl)) != NULL)
  509. --pos;
  510. return pos ? NULL : fl;
  511. }
  512. static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos)
  513. {
  514. read_lock_bh(&ip6_fl_lock);
  515. return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
  516. }
  517. static void *ip6fl_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  518. {
  519. struct ip6_flowlabel *fl;
  520. if (v == SEQ_START_TOKEN)
  521. fl = ip6fl_get_first(seq);
  522. else
  523. fl = ip6fl_get_next(seq, v);
  524. ++*pos;
  525. return fl;
  526. }
  527. static void ip6fl_seq_stop(struct seq_file *seq, void *v)
  528. {
  529. read_unlock_bh(&ip6_fl_lock);
  530. }
  531. static void ip6fl_fl_seq_show(struct seq_file *seq, struct ip6_flowlabel *fl)
  532. {
  533. while(fl) {
  534. seq_printf(seq,
  535. "%05X %-1d %-6d %-6d %-6ld %-8ld " NIP6_SEQFMT " %-4d\n",
  536. (unsigned)ntohl(fl->label),
  537. fl->share,
  538. (unsigned)fl->owner,
  539. atomic_read(&fl->users),
  540. fl->linger/HZ,
  541. (long)(fl->expires - jiffies)/HZ,
  542. NIP6(fl->dst),
  543. fl->opt ? fl->opt->opt_nflen : 0);
  544. fl = fl->next;
  545. }
  546. }
  547. static int ip6fl_seq_show(struct seq_file *seq, void *v)
  548. {
  549. if (v == SEQ_START_TOKEN)
  550. seq_printf(seq, "%-5s %-1s %-6s %-6s %-6s %-8s %-32s %s\n",
  551. "Label", "S", "Owner", "Users", "Linger", "Expires", "Dst", "Opt");
  552. else
  553. ip6fl_fl_seq_show(seq, v);
  554. return 0;
  555. }
  556. static struct seq_operations ip6fl_seq_ops = {
  557. .start = ip6fl_seq_start,
  558. .next = ip6fl_seq_next,
  559. .stop = ip6fl_seq_stop,
  560. .show = ip6fl_seq_show,
  561. };
  562. static int ip6fl_seq_open(struct inode *inode, struct file *file)
  563. {
  564. struct seq_file *seq;
  565. int rc = -ENOMEM;
  566. struct ip6fl_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
  567. if (!s)
  568. goto out;
  569. rc = seq_open(file, &ip6fl_seq_ops);
  570. if (rc)
  571. goto out_kfree;
  572. seq = file->private_data;
  573. seq->private = s;
  574. out:
  575. return rc;
  576. out_kfree:
  577. kfree(s);
  578. goto out;
  579. }
  580. static struct file_operations ip6fl_seq_fops = {
  581. .owner = THIS_MODULE,
  582. .open = ip6fl_seq_open,
  583. .read = seq_read,
  584. .llseek = seq_lseek,
  585. .release = seq_release_private,
  586. };
  587. #endif
  588. void ip6_flowlabel_init(void)
  589. {
  590. #ifdef CONFIG_PROC_FS
  591. proc_net_fops_create("ip6_flowlabel", S_IRUGO, &ip6fl_seq_fops);
  592. #endif
  593. }
  594. void ip6_flowlabel_cleanup(void)
  595. {
  596. del_timer(&ip6_fl_gc_timer);
  597. #ifdef CONFIG_PROC_FS
  598. proc_net_remove("ip6_flowlabel");
  599. #endif
  600. }