Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 12 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/socket.h> |
| 16 | #include <linux/net.h> |
| 17 | #include <linux/netdevice.h> |
| 18 | #include <linux/if_arp.h> |
| 19 | #include <linux/in6.h> |
| 20 | #include <linux/route.h> |
| 21 | #include <linux/proc_fs.h> |
| 22 | #include <linux/seq_file.h> |
| 23 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <net/sock.h> |
| 26 | |
| 27 | #include <net/ipv6.h> |
| 28 | #include <net/ndisc.h> |
| 29 | #include <net/protocol.h> |
| 30 | #include <net/ip6_route.h> |
| 31 | #include <net/addrconf.h> |
| 32 | #include <net/rawv6.h> |
| 33 | #include <net/icmp.h> |
| 34 | #include <net/transp_v6.h> |
| 35 | |
| 36 | #include <asm/uaccess.h> |
| 37 | |
| 38 | #define FL_MIN_LINGER 6 /* Minimal linger. It is set to 6sec specified |
| 39 | in old IPv6 RFC. Well, it was reasonable value. |
| 40 | */ |
| 41 | #define FL_MAX_LINGER 60 /* Maximal linger timeout */ |
| 42 | |
| 43 | /* FL hash table */ |
| 44 | |
| 45 | #define FL_MAX_PER_SOCK 32 |
| 46 | #define FL_MAX_SIZE 4096 |
| 47 | #define FL_HASH_MASK 255 |
| 48 | #define FL_HASH(l) (ntohl(l)&FL_HASH_MASK) |
| 49 | |
| 50 | static atomic_t fl_size = ATOMIC_INIT(0); |
| 51 | static struct ip6_flowlabel *fl_ht[FL_HASH_MASK+1]; |
| 52 | |
| 53 | static void ip6_fl_gc(unsigned long dummy); |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 54 | static DEFINE_TIMER(ip6_fl_gc_timer, ip6_fl_gc, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /* FL hash table lock: it protects only of GC */ |
| 57 | |
| 58 | static DEFINE_RWLOCK(ip6_fl_lock); |
| 59 | |
| 60 | /* Big socket sock */ |
| 61 | |
| 62 | static DEFINE_RWLOCK(ip6_sk_fl_lock); |
| 63 | |
| 64 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 65 | static inline struct ip6_flowlabel *__fl_lookup(struct net *net, __be32 label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | struct ip6_flowlabel *fl; |
| 68 | |
| 69 | for (fl=fl_ht[FL_HASH(label)]; fl; fl = fl->next) { |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 70 | if (fl->label == label && net_eq(fl->fl_net, net)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return fl; |
| 72 | } |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 76 | static struct ip6_flowlabel *fl_lookup(struct net *net, __be32 label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | struct ip6_flowlabel *fl; |
| 79 | |
| 80 | read_lock_bh(&ip6_fl_lock); |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 81 | fl = __fl_lookup(net, label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (fl) |
| 83 | atomic_inc(&fl->users); |
| 84 | read_unlock_bh(&ip6_fl_lock); |
| 85 | return fl; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static void fl_free(struct ip6_flowlabel *fl) |
| 90 | { |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 91 | if (fl) { |
| 92 | release_net(fl->fl_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | kfree(fl->opt); |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | kfree(fl); |
| 96 | } |
| 97 | |
| 98 | static void fl_release(struct ip6_flowlabel *fl) |
| 99 | { |
| 100 | write_lock_bh(&ip6_fl_lock); |
| 101 | |
| 102 | fl->lastuse = jiffies; |
| 103 | if (atomic_dec_and_test(&fl->users)) { |
| 104 | unsigned long ttd = fl->lastuse + fl->linger; |
| 105 | if (time_after(ttd, fl->expires)) |
| 106 | fl->expires = ttd; |
| 107 | ttd = fl->expires; |
| 108 | if (fl->opt && fl->share == IPV6_FL_S_EXCL) { |
| 109 | struct ipv6_txoptions *opt = fl->opt; |
| 110 | fl->opt = NULL; |
| 111 | kfree(opt); |
| 112 | } |
| 113 | if (!timer_pending(&ip6_fl_gc_timer) || |
| 114 | time_after(ip6_fl_gc_timer.expires, ttd)) |
| 115 | mod_timer(&ip6_fl_gc_timer, ttd); |
| 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | write_unlock_bh(&ip6_fl_lock); |
| 118 | } |
| 119 | |
| 120 | static void ip6_fl_gc(unsigned long dummy) |
| 121 | { |
| 122 | int i; |
| 123 | unsigned long now = jiffies; |
| 124 | unsigned long sched = 0; |
| 125 | |
| 126 | write_lock(&ip6_fl_lock); |
| 127 | |
| 128 | for (i=0; i<=FL_HASH_MASK; i++) { |
| 129 | struct ip6_flowlabel *fl, **flp; |
| 130 | flp = &fl_ht[i]; |
| 131 | while ((fl=*flp) != NULL) { |
| 132 | if (atomic_read(&fl->users) == 0) { |
| 133 | unsigned long ttd = fl->lastuse + fl->linger; |
| 134 | if (time_after(ttd, fl->expires)) |
| 135 | fl->expires = ttd; |
| 136 | ttd = fl->expires; |
| 137 | if (time_after_eq(now, ttd)) { |
| 138 | *flp = fl->next; |
| 139 | fl_free(fl); |
| 140 | atomic_dec(&fl_size); |
| 141 | continue; |
| 142 | } |
| 143 | if (!sched || time_before(ttd, sched)) |
| 144 | sched = ttd; |
| 145 | } |
| 146 | flp = &fl->next; |
| 147 | } |
| 148 | } |
| 149 | if (!sched && atomic_read(&fl_size)) |
| 150 | sched = now + FL_MAX_LINGER; |
| 151 | if (sched) { |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 152 | mod_timer(&ip6_fl_gc_timer, sched); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | write_unlock(&ip6_fl_lock); |
| 155 | } |
| 156 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 157 | static void ip6_fl_purge(struct net *net) |
| 158 | { |
| 159 | int i; |
| 160 | |
| 161 | write_lock(&ip6_fl_lock); |
| 162 | for (i = 0; i <= FL_HASH_MASK; i++) { |
| 163 | struct ip6_flowlabel *fl, **flp; |
| 164 | flp = &fl_ht[i]; |
| 165 | while ((fl = *flp) != NULL) { |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 166 | if (net_eq(fl->fl_net, net) && |
| 167 | atomic_read(&fl->users) == 0) { |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 168 | *flp = fl->next; |
| 169 | fl_free(fl); |
| 170 | atomic_dec(&fl_size); |
| 171 | continue; |
| 172 | } |
| 173 | flp = &fl->next; |
| 174 | } |
| 175 | } |
| 176 | write_unlock(&ip6_fl_lock); |
| 177 | } |
| 178 | |
| 179 | static struct ip6_flowlabel *fl_intern(struct net *net, |
| 180 | struct ip6_flowlabel *fl, __be32 label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 182 | struct ip6_flowlabel *lfl; |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | fl->label = label & IPV6_FLOWLABEL_MASK; |
| 185 | |
| 186 | write_lock_bh(&ip6_fl_lock); |
| 187 | if (label == 0) { |
| 188 | for (;;) { |
| 189 | fl->label = htonl(net_random())&IPV6_FLOWLABEL_MASK; |
| 190 | if (fl->label) { |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 191 | lfl = __fl_lookup(net, fl->label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (lfl == NULL) |
| 193 | break; |
| 194 | } |
| 195 | } |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 196 | } else { |
| 197 | /* |
| 198 | * we dropper the ip6_fl_lock, so this entry could reappear |
| 199 | * and we need to recheck with it. |
| 200 | * |
| 201 | * OTOH no need to search the active socket first, like it is |
| 202 | * done in ipv6_flowlabel_opt - sock is locked, so new entry |
| 203 | * with the same label can only appear on another sock |
| 204 | */ |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 205 | lfl = __fl_lookup(net, fl->label); |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 206 | if (lfl != NULL) { |
| 207 | atomic_inc(&lfl->users); |
| 208 | write_unlock_bh(&ip6_fl_lock); |
| 209 | return lfl; |
| 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | fl->lastuse = jiffies; |
| 214 | fl->next = fl_ht[FL_HASH(fl->label)]; |
| 215 | fl_ht[FL_HASH(fl->label)] = fl; |
| 216 | atomic_inc(&fl_size); |
| 217 | write_unlock_bh(&ip6_fl_lock); |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 218 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
| 222 | |
| 223 | /* Socket flowlabel lists */ |
| 224 | |
Al Viro | 90bcaf7 | 2006-11-08 00:25:17 -0800 | [diff] [blame] | 225 | struct ip6_flowlabel * fl6_sock_lookup(struct sock *sk, __be32 label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | struct ipv6_fl_socklist *sfl; |
| 228 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 229 | |
| 230 | label &= IPV6_FLOWLABEL_MASK; |
| 231 | |
Pavel Emelyanov | bd0bf57 | 2007-10-18 05:15:57 -0700 | [diff] [blame] | 232 | read_lock_bh(&ip6_sk_fl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | for (sfl=np->ipv6_fl_list; sfl; sfl = sfl->next) { |
| 234 | struct ip6_flowlabel *fl = sfl->fl; |
| 235 | if (fl->label == label) { |
| 236 | fl->lastuse = jiffies; |
| 237 | atomic_inc(&fl->users); |
Pavel Emelyanov | 52f095e | 2007-10-18 05:38:48 -0700 | [diff] [blame] | 238 | read_unlock_bh(&ip6_sk_fl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return fl; |
| 240 | } |
| 241 | } |
Pavel Emelyanov | bd0bf57 | 2007-10-18 05:15:57 -0700 | [diff] [blame] | 242 | read_unlock_bh(&ip6_sk_fl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return NULL; |
| 244 | } |
| 245 | |
Arnaldo Carvalho de Melo | 3cf3dc6 | 2005-12-13 23:23:20 -0800 | [diff] [blame] | 246 | EXPORT_SYMBOL_GPL(fl6_sock_lookup); |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | void fl6_free_socklist(struct sock *sk) |
| 249 | { |
| 250 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 251 | struct ipv6_fl_socklist *sfl; |
| 252 | |
| 253 | while ((sfl = np->ipv6_fl_list) != NULL) { |
| 254 | np->ipv6_fl_list = sfl->next; |
| 255 | fl_release(sfl->fl); |
| 256 | kfree(sfl); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /* Service routines */ |
| 261 | |
| 262 | |
| 263 | /* |
| 264 | It is the only difficult place. flowlabel enforces equal headers |
| 265 | before and including routing header, however user may supply options |
| 266 | following rthdr. |
| 267 | */ |
| 268 | |
| 269 | struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space, |
| 270 | struct ip6_flowlabel * fl, |
| 271 | struct ipv6_txoptions * fopt) |
| 272 | { |
YOSHIFUJI Hideaki | df9890c | 2005-11-20 12:23:18 +0900 | [diff] [blame] | 273 | struct ipv6_txoptions * fl_opt = fl->opt; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 274 | |
YOSHIFUJI Hideaki | df9890c | 2005-11-20 12:23:18 +0900 | [diff] [blame] | 275 | if (fopt == NULL || fopt->opt_flen == 0) |
| 276 | return fl_opt; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (fl_opt != NULL) { |
| 279 | opt_space->hopopt = fl_opt->hopopt; |
YOSHIFUJI Hideaki | df9890c | 2005-11-20 12:23:18 +0900 | [diff] [blame] | 280 | opt_space->dst0opt = fl_opt->dst0opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | opt_space->srcrt = fl_opt->srcrt; |
| 282 | opt_space->opt_nflen = fl_opt->opt_nflen; |
| 283 | } else { |
| 284 | if (fopt->opt_nflen == 0) |
| 285 | return fopt; |
| 286 | opt_space->hopopt = NULL; |
| 287 | opt_space->dst0opt = NULL; |
| 288 | opt_space->srcrt = NULL; |
| 289 | opt_space->opt_nflen = 0; |
| 290 | } |
| 291 | opt_space->dst1opt = fopt->dst1opt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | opt_space->opt_flen = fopt->opt_flen; |
| 293 | return opt_space; |
| 294 | } |
| 295 | |
| 296 | static unsigned long check_linger(unsigned long ttl) |
| 297 | { |
| 298 | if (ttl < FL_MIN_LINGER) |
| 299 | return FL_MIN_LINGER*HZ; |
| 300 | if (ttl > FL_MAX_LINGER && !capable(CAP_NET_ADMIN)) |
| 301 | return 0; |
| 302 | return ttl*HZ; |
| 303 | } |
| 304 | |
| 305 | static int fl6_renew(struct ip6_flowlabel *fl, unsigned long linger, unsigned long expires) |
| 306 | { |
| 307 | linger = check_linger(linger); |
| 308 | if (!linger) |
| 309 | return -EPERM; |
| 310 | expires = check_linger(expires); |
| 311 | if (!expires) |
| 312 | return -EPERM; |
| 313 | fl->lastuse = jiffies; |
| 314 | if (time_before(fl->linger, linger)) |
| 315 | fl->linger = linger; |
| 316 | if (time_before(expires, fl->linger)) |
| 317 | expires = fl->linger; |
| 318 | if (time_before(fl->expires, fl->lastuse + expires)) |
| 319 | fl->expires = fl->lastuse + expires; |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static struct ip6_flowlabel * |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 324 | fl_create(struct net *net, struct in6_flowlabel_req *freq, char __user *optval, |
| 325 | int optlen, int *err_p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
David S. Miller | 684de40 | 2009-02-06 00:49:55 -0800 | [diff] [blame] | 327 | struct ip6_flowlabel *fl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | int olen; |
| 329 | int addr_type; |
| 330 | int err; |
| 331 | |
David S. Miller | 684de40 | 2009-02-06 00:49:55 -0800 | [diff] [blame] | 332 | olen = optlen - CMSG_ALIGN(sizeof(*freq)); |
| 333 | err = -EINVAL; |
| 334 | if (olen > 64 * 1024) |
| 335 | goto done; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | err = -ENOMEM; |
Ingo Oeser | 0c600ed | 2006-03-20 23:01:32 -0800 | [diff] [blame] | 338 | fl = kzalloc(sizeof(*fl), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | if (fl == NULL) |
| 340 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (olen > 0) { |
| 343 | struct msghdr msg; |
| 344 | struct flowi flowi; |
| 345 | int junk; |
| 346 | |
| 347 | err = -ENOMEM; |
| 348 | fl->opt = kmalloc(sizeof(*fl->opt) + olen, GFP_KERNEL); |
| 349 | if (fl->opt == NULL) |
| 350 | goto done; |
| 351 | |
| 352 | memset(fl->opt, 0, sizeof(*fl->opt)); |
| 353 | fl->opt->tot_len = sizeof(*fl->opt) + olen; |
| 354 | err = -EFAULT; |
| 355 | if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen)) |
| 356 | goto done; |
| 357 | |
| 358 | msg.msg_controllen = olen; |
| 359 | msg.msg_control = (void*)(fl->opt+1); |
| 360 | flowi.oif = 0; |
| 361 | |
YOSHIFUJI Hideaki | 91e1908 | 2008-06-04 13:02:49 +0900 | [diff] [blame] | 362 | err = datagram_send_ctl(net, &msg, &flowi, fl->opt, &junk, &junk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (err) |
| 364 | goto done; |
| 365 | err = -EINVAL; |
| 366 | if (fl->opt->opt_flen) |
| 367 | goto done; |
| 368 | if (fl->opt->opt_nflen == 0) { |
| 369 | kfree(fl->opt); |
| 370 | fl->opt = NULL; |
| 371 | } |
| 372 | } |
| 373 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 374 | fl->fl_net = hold_net(net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | fl->expires = jiffies; |
| 376 | err = fl6_renew(fl, freq->flr_linger, freq->flr_expires); |
| 377 | if (err) |
| 378 | goto done; |
| 379 | fl->share = freq->flr_share; |
| 380 | addr_type = ipv6_addr_type(&freq->flr_dst); |
Joe Perches | 3570021 | 2009-11-24 14:52:52 -0800 | [diff] [blame] | 381 | if ((addr_type & IPV6_ADDR_MAPPED) || |
| 382 | addr_type == IPV6_ADDR_ANY) { |
James Morris | c6817e4 | 2006-10-30 18:56:06 -0800 | [diff] [blame] | 383 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | goto done; |
James Morris | c6817e4 | 2006-10-30 18:56:06 -0800 | [diff] [blame] | 385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | ipv6_addr_copy(&fl->dst, &freq->flr_dst); |
| 387 | atomic_set(&fl->users, 1); |
| 388 | switch (fl->share) { |
| 389 | case IPV6_FL_S_EXCL: |
| 390 | case IPV6_FL_S_ANY: |
| 391 | break; |
| 392 | case IPV6_FL_S_PROCESS: |
| 393 | fl->owner = current->pid; |
| 394 | break; |
| 395 | case IPV6_FL_S_USER: |
David Howells | f82b3590 | 2008-11-14 10:39:07 +1100 | [diff] [blame] | 396 | fl->owner = current_euid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | break; |
| 398 | default: |
| 399 | err = -EINVAL; |
| 400 | goto done; |
| 401 | } |
| 402 | return fl; |
| 403 | |
| 404 | done: |
| 405 | fl_free(fl); |
| 406 | *err_p = err; |
| 407 | return NULL; |
| 408 | } |
| 409 | |
| 410 | static int mem_check(struct sock *sk) |
| 411 | { |
| 412 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 413 | struct ipv6_fl_socklist *sfl; |
| 414 | int room = FL_MAX_SIZE - atomic_read(&fl_size); |
| 415 | int count = 0; |
| 416 | |
| 417 | if (room > FL_MAX_SIZE - FL_MAX_PER_SOCK) |
| 418 | return 0; |
| 419 | |
| 420 | for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) |
| 421 | count++; |
| 422 | |
| 423 | if (room <= 0 || |
| 424 | ((count >= FL_MAX_PER_SOCK || |
Joe Perches | 3570021 | 2009-11-24 14:52:52 -0800 | [diff] [blame] | 425 | (count > 0 && room < FL_MAX_SIZE/2) || room < FL_MAX_SIZE/4) && |
| 426 | !capable(CAP_NET_ADMIN))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return -ENOBUFS; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int ipv6_hdr_cmp(struct ipv6_opt_hdr *h1, struct ipv6_opt_hdr *h2) |
| 433 | { |
| 434 | if (h1 == h2) |
| 435 | return 0; |
| 436 | if (h1 == NULL || h2 == NULL) |
| 437 | return 1; |
| 438 | if (h1->hdrlen != h2->hdrlen) |
| 439 | return 1; |
| 440 | return memcmp(h1+1, h2+1, ((h1->hdrlen+1)<<3) - sizeof(*h1)); |
| 441 | } |
| 442 | |
| 443 | static int ipv6_opt_cmp(struct ipv6_txoptions *o1, struct ipv6_txoptions *o2) |
| 444 | { |
| 445 | if (o1 == o2) |
| 446 | return 0; |
| 447 | if (o1 == NULL || o2 == NULL) |
| 448 | return 1; |
| 449 | if (o1->opt_nflen != o2->opt_nflen) |
| 450 | return 1; |
| 451 | if (ipv6_hdr_cmp(o1->hopopt, o2->hopopt)) |
| 452 | return 1; |
| 453 | if (ipv6_hdr_cmp(o1->dst0opt, o2->dst0opt)) |
| 454 | return 1; |
| 455 | if (ipv6_hdr_cmp((struct ipv6_opt_hdr *)o1->srcrt, (struct ipv6_opt_hdr *)o2->srcrt)) |
| 456 | return 1; |
| 457 | return 0; |
| 458 | } |
| 459 | |
Pavel Emelyanov | 0402804 | 2007-10-18 05:14:58 -0700 | [diff] [blame] | 460 | static inline void fl_link(struct ipv6_pinfo *np, struct ipv6_fl_socklist *sfl, |
| 461 | struct ip6_flowlabel *fl) |
| 462 | { |
| 463 | write_lock_bh(&ip6_sk_fl_lock); |
| 464 | sfl->fl = fl; |
| 465 | sfl->next = np->ipv6_fl_list; |
| 466 | np->ipv6_fl_list = sfl; |
| 467 | write_unlock_bh(&ip6_sk_fl_lock); |
| 468 | } |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen) |
| 471 | { |
Ingo Molnar | 55205d4 | 2008-11-25 16:50:30 -0800 | [diff] [blame] | 472 | int uninitialized_var(err); |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 473 | struct net *net = sock_net(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 475 | struct in6_flowlabel_req freq; |
| 476 | struct ipv6_fl_socklist *sfl1=NULL; |
| 477 | struct ipv6_fl_socklist *sfl, **sflp; |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 478 | struct ip6_flowlabel *fl, *fl1 = NULL; |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | if (optlen < sizeof(freq)) |
| 482 | return -EINVAL; |
| 483 | |
| 484 | if (copy_from_user(&freq, optval, sizeof(freq))) |
| 485 | return -EFAULT; |
| 486 | |
| 487 | switch (freq.flr_action) { |
| 488 | case IPV6_FL_A_PUT: |
| 489 | write_lock_bh(&ip6_sk_fl_lock); |
| 490 | for (sflp = &np->ipv6_fl_list; (sfl=*sflp)!=NULL; sflp = &sfl->next) { |
| 491 | if (sfl->fl->label == freq.flr_label) { |
| 492 | if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK)) |
| 493 | np->flow_label &= ~IPV6_FLOWLABEL_MASK; |
| 494 | *sflp = sfl->next; |
| 495 | write_unlock_bh(&ip6_sk_fl_lock); |
| 496 | fl_release(sfl->fl); |
| 497 | kfree(sfl); |
| 498 | return 0; |
| 499 | } |
| 500 | } |
| 501 | write_unlock_bh(&ip6_sk_fl_lock); |
| 502 | return -ESRCH; |
| 503 | |
| 504 | case IPV6_FL_A_RENEW: |
| 505 | read_lock_bh(&ip6_sk_fl_lock); |
| 506 | for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) { |
| 507 | if (sfl->fl->label == freq.flr_label) { |
| 508 | err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires); |
| 509 | read_unlock_bh(&ip6_sk_fl_lock); |
| 510 | return err; |
| 511 | } |
| 512 | } |
| 513 | read_unlock_bh(&ip6_sk_fl_lock); |
| 514 | |
| 515 | if (freq.flr_share == IPV6_FL_S_NONE && capable(CAP_NET_ADMIN)) { |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 516 | fl = fl_lookup(net, freq.flr_label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (fl) { |
| 518 | err = fl6_renew(fl, freq.flr_linger, freq.flr_expires); |
| 519 | fl_release(fl); |
| 520 | return err; |
| 521 | } |
| 522 | } |
| 523 | return -ESRCH; |
| 524 | |
| 525 | case IPV6_FL_A_GET: |
| 526 | if (freq.flr_label & ~IPV6_FLOWLABEL_MASK) |
| 527 | return -EINVAL; |
| 528 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 529 | fl = fl_create(net, &freq, optval, optlen, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | if (fl == NULL) |
| 531 | return err; |
| 532 | sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL); |
| 533 | |
| 534 | if (freq.flr_label) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | err = -EEXIST; |
| 536 | read_lock_bh(&ip6_sk_fl_lock); |
| 537 | for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) { |
| 538 | if (sfl->fl->label == freq.flr_label) { |
| 539 | if (freq.flr_flags&IPV6_FL_F_EXCL) { |
| 540 | read_unlock_bh(&ip6_sk_fl_lock); |
| 541 | goto done; |
| 542 | } |
| 543 | fl1 = sfl->fl; |
Yan Zheng | 4ea6a80 | 2005-10-24 19:55:23 +0800 | [diff] [blame] | 544 | atomic_inc(&fl1->users); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | } |
| 548 | read_unlock_bh(&ip6_sk_fl_lock); |
| 549 | |
| 550 | if (fl1 == NULL) |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 551 | fl1 = fl_lookup(net, freq.flr_label); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (fl1) { |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 553 | recheck: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | err = -EEXIST; |
| 555 | if (freq.flr_flags&IPV6_FL_F_EXCL) |
| 556 | goto release; |
| 557 | err = -EPERM; |
| 558 | if (fl1->share == IPV6_FL_S_EXCL || |
| 559 | fl1->share != fl->share || |
| 560 | fl1->owner != fl->owner) |
| 561 | goto release; |
| 562 | |
| 563 | err = -EINVAL; |
| 564 | if (!ipv6_addr_equal(&fl1->dst, &fl->dst) || |
| 565 | ipv6_opt_cmp(fl1->opt, fl->opt)) |
| 566 | goto release; |
| 567 | |
| 568 | err = -ENOMEM; |
| 569 | if (sfl1 == NULL) |
| 570 | goto release; |
| 571 | if (fl->linger > fl1->linger) |
| 572 | fl1->linger = fl->linger; |
| 573 | if ((long)(fl->expires - fl1->expires) > 0) |
| 574 | fl1->expires = fl->expires; |
Pavel Emelyanov | 0402804 | 2007-10-18 05:14:58 -0700 | [diff] [blame] | 575 | fl_link(np, sfl1, fl1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | fl_free(fl); |
| 577 | return 0; |
| 578 | |
| 579 | release: |
| 580 | fl_release(fl1); |
| 581 | goto done; |
| 582 | } |
| 583 | } |
| 584 | err = -ENOENT; |
| 585 | if (!(freq.flr_flags&IPV6_FL_F_CREATE)) |
| 586 | goto done; |
| 587 | |
| 588 | err = -ENOMEM; |
| 589 | if (sfl1 == NULL || (err = mem_check(sk)) != 0) |
| 590 | goto done; |
| 591 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 592 | fl1 = fl_intern(net, fl, freq.flr_label); |
Pavel Emelyanov | 78c2e50 | 2007-10-18 05:18:56 -0700 | [diff] [blame] | 593 | if (fl1 != NULL) |
| 594 | goto recheck; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
David S. Miller | 6c94d36 | 2005-05-29 20:28:01 -0700 | [diff] [blame] | 596 | if (!freq.flr_label) { |
| 597 | if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label, |
| 598 | &fl->label, sizeof(fl->label))) { |
| 599 | /* Intentionally ignore fault. */ |
| 600 | } |
| 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Pavel Emelyanov | 0402804 | 2007-10-18 05:14:58 -0700 | [diff] [blame] | 603 | fl_link(np, sfl1, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | return 0; |
| 605 | |
| 606 | default: |
| 607 | return -EINVAL; |
| 608 | } |
| 609 | |
| 610 | done: |
| 611 | fl_free(fl); |
| 612 | kfree(sfl1); |
| 613 | return err; |
| 614 | } |
| 615 | |
| 616 | #ifdef CONFIG_PROC_FS |
| 617 | |
| 618 | struct ip6fl_iter_state { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 619 | struct seq_net_private p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | int bucket; |
| 621 | }; |
| 622 | |
| 623 | #define ip6fl_seq_private(seq) ((struct ip6fl_iter_state *)(seq)->private) |
| 624 | |
| 625 | static struct ip6_flowlabel *ip6fl_get_first(struct seq_file *seq) |
| 626 | { |
| 627 | struct ip6_flowlabel *fl = NULL; |
| 628 | struct ip6fl_iter_state *state = ip6fl_seq_private(seq); |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 629 | struct net *net = seq_file_net(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | for (state->bucket = 0; state->bucket <= FL_HASH_MASK; ++state->bucket) { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 632 | fl = fl_ht[state->bucket]; |
| 633 | |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 634 | while (fl && !net_eq(fl->fl_net, net)) |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 635 | fl = fl->next; |
| 636 | if (fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | return fl; |
| 640 | } |
| 641 | |
| 642 | static struct ip6_flowlabel *ip6fl_get_next(struct seq_file *seq, struct ip6_flowlabel *fl) |
| 643 | { |
| 644 | struct ip6fl_iter_state *state = ip6fl_seq_private(seq); |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 645 | struct net *net = seq_file_net(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | fl = fl->next; |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 648 | try_again: |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 649 | while (fl && !net_eq(fl->fl_net, net)) |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 650 | fl = fl->next; |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | while (!fl) { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 653 | if (++state->bucket <= FL_HASH_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | fl = fl_ht[state->bucket]; |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 655 | goto try_again; |
| 656 | } else |
James Morris | bcd6207 | 2006-10-30 15:08:42 -0800 | [diff] [blame] | 657 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | return fl; |
| 660 | } |
| 661 | |
| 662 | static struct ip6_flowlabel *ip6fl_get_idx(struct seq_file *seq, loff_t pos) |
| 663 | { |
| 664 | struct ip6_flowlabel *fl = ip6fl_get_first(seq); |
| 665 | if (fl) |
| 666 | while (pos && (fl = ip6fl_get_next(seq, fl)) != NULL) |
| 667 | --pos; |
| 668 | return pos ? NULL : fl; |
| 669 | } |
| 670 | |
| 671 | static void *ip6fl_seq_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 9a429c4 | 2008-01-01 21:58:02 -0800 | [diff] [blame] | 672 | __acquires(ip6_fl_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | read_lock_bh(&ip6_fl_lock); |
| 675 | return *pos ? ip6fl_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
| 676 | } |
| 677 | |
| 678 | static void *ip6fl_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 679 | { |
| 680 | struct ip6_flowlabel *fl; |
| 681 | |
| 682 | if (v == SEQ_START_TOKEN) |
| 683 | fl = ip6fl_get_first(seq); |
| 684 | else |
| 685 | fl = ip6fl_get_next(seq, v); |
| 686 | ++*pos; |
| 687 | return fl; |
| 688 | } |
| 689 | |
| 690 | static void ip6fl_seq_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 9a429c4 | 2008-01-01 21:58:02 -0800 | [diff] [blame] | 691 | __releases(ip6_fl_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
| 693 | read_unlock_bh(&ip6_fl_lock); |
| 694 | } |
| 695 | |
James Morris | 1b7c2db | 2006-10-31 00:43:44 -0800 | [diff] [blame] | 696 | static int ip6fl_seq_show(struct seq_file *seq, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
James Morris | 1b7c2db | 2006-10-31 00:43:44 -0800 | [diff] [blame] | 698 | if (v == SEQ_START_TOKEN) |
| 699 | seq_printf(seq, "%-5s %-1s %-6s %-6s %-6s %-8s %-32s %s\n", |
| 700 | "Label", "S", "Owner", "Users", "Linger", "Expires", "Dst", "Opt"); |
| 701 | else { |
| 702 | struct ip6_flowlabel *fl = v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | seq_printf(seq, |
Harvey Harrison | 4b7a427 | 2008-10-29 12:50:24 -0700 | [diff] [blame] | 704 | "%05X %-1d %-6d %-6d %-6ld %-8ld %pi6 %-4d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | (unsigned)ntohl(fl->label), |
| 706 | fl->share, |
| 707 | (unsigned)fl->owner, |
| 708 | atomic_read(&fl->users), |
| 709 | fl->linger/HZ, |
| 710 | (long)(fl->expires - jiffies)/HZ, |
Harvey Harrison | b071195 | 2008-10-28 16:05:40 -0700 | [diff] [blame] | 711 | &fl->dst, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | fl->opt ? fl->opt->opt_nflen : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | return 0; |
| 715 | } |
| 716 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 717 | static const struct seq_operations ip6fl_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | .start = ip6fl_seq_start, |
| 719 | .next = ip6fl_seq_next, |
| 720 | .stop = ip6fl_seq_stop, |
| 721 | .show = ip6fl_seq_show, |
| 722 | }; |
| 723 | |
| 724 | static int ip6fl_seq_open(struct inode *inode, struct file *file) |
| 725 | { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 726 | return seq_open_net(inode, file, &ip6fl_seq_ops, |
| 727 | sizeof(struct ip6fl_iter_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 730 | static const struct file_operations ip6fl_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | .owner = THIS_MODULE, |
| 732 | .open = ip6fl_seq_open, |
| 733 | .read = seq_read, |
| 734 | .llseek = seq_lseek, |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 735 | .release = seq_release_net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 738 | static int ip6_flowlabel_proc_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 740 | if (!proc_net_fops_create(net, "ip6_flowlabel", |
| 741 | S_IRUGO, &ip6fl_seq_fops)) |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 742 | return -ENOMEM; |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static void ip6_flowlabel_proc_fini(struct net *net) |
| 747 | { |
| 748 | proc_net_remove(net, "ip6_flowlabel"); |
| 749 | } |
| 750 | #else |
| 751 | static inline int ip6_flowlabel_proc_init(struct net *net) |
| 752 | { |
| 753 | return 0; |
| 754 | } |
| 755 | static inline void ip6_flowlabel_proc_fini(struct net *net) |
| 756 | { |
| 757 | return ; |
| 758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | #endif |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 760 | |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 761 | static inline void ip6_flowlabel_net_exit(struct net *net) |
| 762 | { |
| 763 | ip6_fl_purge(net); |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 764 | ip6_flowlabel_proc_fini(net); |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static struct pernet_operations ip6_flowlabel_net_ops = { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 768 | .init = ip6_flowlabel_proc_init, |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 769 | .exit = ip6_flowlabel_net_exit, |
| 770 | }; |
| 771 | |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 772 | int ip6_flowlabel_init(void) |
| 773 | { |
Benjamin Thery | 5983a3d | 2008-03-26 16:53:30 -0700 | [diff] [blame] | 774 | return register_pernet_subsys(&ip6_flowlabel_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | void ip6_flowlabel_cleanup(void) |
| 778 | { |
| 779 | del_timer(&ip6_fl_gc_timer); |
Benjamin Thery | 60e8fbc | 2008-03-26 16:53:08 -0700 | [diff] [blame] | 780 | unregister_pernet_subsys(&ip6_flowlabel_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |