Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
| 3 | * operating system. INET is implemented using the BSD Socket |
| 4 | * interface as the means of communication with the user level. |
| 5 | * |
| 6 | * Routing netlink socket interface: protocol independent part. |
| 7 | * |
| 8 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * Fixes: |
| 16 | * Vitaly E. Lavrov RTA_OK arithmetics was wrong. |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/errno.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/socket.h> |
| 23 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/timer.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/sockios.h> |
| 27 | #include <linux/net.h> |
| 28 | #include <linux/fcntl.h> |
| 29 | #include <linux/mm.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/capability.h> |
| 33 | #include <linux/skbuff.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/security.h> |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 36 | #include <linux/mutex.h> |
Thomas Graf | 1823730 | 2006-08-04 23:04:54 -0700 | [diff] [blame] | 37 | #include <linux/if_addr.h> |
Eric W. Biederman | d8a5ec6 | 2007-09-12 13:57:04 +0200 | [diff] [blame] | 38 | #include <linux/nsproxy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include <asm/uaccess.h> |
| 41 | #include <asm/system.h> |
| 42 | #include <asm/string.h> |
| 43 | |
| 44 | #include <linux/inet.h> |
| 45 | #include <linux/netdevice.h> |
| 46 | #include <net/ip.h> |
| 47 | #include <net/protocol.h> |
| 48 | #include <net/arp.h> |
| 49 | #include <net/route.h> |
| 50 | #include <net/udp.h> |
| 51 | #include <net/sock.h> |
| 52 | #include <net/pkt_sched.h> |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 53 | #include <net/fib_rules.h> |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 54 | #include <net/rtnetlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 56 | struct rtnl_link |
| 57 | { |
| 58 | rtnl_doit_func doit; |
| 59 | rtnl_dumpit_func dumpit; |
| 60 | }; |
| 61 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 62 | static DEFINE_MUTEX(rtnl_mutex); |
Thomas Graf | 56fc85a | 2006-08-15 00:37:29 -0700 | [diff] [blame] | 63 | static struct sock *rtnl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | void rtnl_lock(void) |
| 66 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 67 | mutex_lock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 70 | void __rtnl_unlock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 72 | mutex_unlock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | void rtnl_unlock(void) |
| 76 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 77 | mutex_unlock(&rtnl_mutex); |
| 78 | if (rtnl && rtnl->sk_receive_queue.qlen) |
| 79 | rtnl->sk_data_ready(rtnl, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | netdev_run_todo(); |
| 81 | } |
| 82 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 83 | int rtnl_trylock(void) |
| 84 | { |
| 85 | return mutex_trylock(&rtnl_mutex); |
| 86 | } |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len) |
| 89 | { |
| 90 | memset(tb, 0, sizeof(struct rtattr*)*maxattr); |
| 91 | |
| 92 | while (RTA_OK(rta, len)) { |
| 93 | unsigned flavor = rta->rta_type; |
| 94 | if (flavor && flavor <= maxattr) |
| 95 | tb[flavor-1] = rta; |
| 96 | rta = RTA_NEXT(rta, len); |
| 97 | } |
| 98 | return 0; |
| 99 | } |
| 100 | |
Patrick McHardy | 2371baa | 2007-06-26 03:23:44 -0700 | [diff] [blame] | 101 | int __rtattr_parse_nested_compat(struct rtattr *tb[], int maxattr, |
YOSHIFUJI Hideaki | 40b77c9 | 2007-07-19 10:43:23 +0900 | [diff] [blame] | 102 | struct rtattr *rta, int len) |
Patrick McHardy | afdc323 | 2007-06-25 14:30:16 -0700 | [diff] [blame] | 103 | { |
| 104 | if (RTA_PAYLOAD(rta) < len) |
| 105 | return -1; |
Patrick McHardy | afdc323 | 2007-06-25 14:30:16 -0700 | [diff] [blame] | 106 | if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) { |
| 107 | rta = RTA_DATA(rta) + RTA_ALIGN(len); |
| 108 | return rtattr_parse_nested(tb, maxattr, rta); |
| 109 | } |
| 110 | memset(tb, 0, sizeof(struct rtattr *) * maxattr); |
| 111 | return 0; |
| 112 | } |
| 113 | |
Adrian Bunk | 42bad1d | 2007-04-26 00:57:41 -0700 | [diff] [blame] | 114 | static struct rtnl_link *rtnl_msg_handlers[NPROTO]; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 115 | |
| 116 | static inline int rtm_msgindex(int msgtype) |
| 117 | { |
| 118 | int msgindex = msgtype - RTM_BASE; |
| 119 | |
| 120 | /* |
| 121 | * msgindex < 0 implies someone tried to register a netlink |
| 122 | * control code. msgindex >= RTM_NR_MSGTYPES may indicate that |
| 123 | * the message type has not been added to linux/rtnetlink.h |
| 124 | */ |
| 125 | BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES); |
| 126 | |
| 127 | return msgindex; |
| 128 | } |
| 129 | |
| 130 | static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex) |
| 131 | { |
| 132 | struct rtnl_link *tab; |
| 133 | |
| 134 | tab = rtnl_msg_handlers[protocol]; |
Thomas Graf | 51057f2 | 2007-03-22 21:41:06 -0700 | [diff] [blame] | 135 | if (tab == NULL || tab[msgindex].doit == NULL) |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 136 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
| 137 | |
Thomas Graf | 51057f2 | 2007-03-22 21:41:06 -0700 | [diff] [blame] | 138 | return tab ? tab[msgindex].doit : NULL; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex) |
| 142 | { |
| 143 | struct rtnl_link *tab; |
| 144 | |
| 145 | tab = rtnl_msg_handlers[protocol]; |
Thomas Graf | 51057f2 | 2007-03-22 21:41:06 -0700 | [diff] [blame] | 146 | if (tab == NULL || tab[msgindex].dumpit == NULL) |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 147 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
| 148 | |
Thomas Graf | 51057f2 | 2007-03-22 21:41:06 -0700 | [diff] [blame] | 149 | return tab ? tab[msgindex].dumpit : NULL; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * __rtnl_register - Register a rtnetlink message type |
| 154 | * @protocol: Protocol family or PF_UNSPEC |
| 155 | * @msgtype: rtnetlink message type |
| 156 | * @doit: Function pointer called for each request message |
| 157 | * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message |
| 158 | * |
| 159 | * Registers the specified function pointers (at least one of them has |
| 160 | * to be non-NULL) to be called whenever a request message for the |
| 161 | * specified protocol family and message type is received. |
| 162 | * |
| 163 | * The special protocol family PF_UNSPEC may be used to define fallback |
| 164 | * function pointers for the case when no entry for the specific protocol |
| 165 | * family exists. |
| 166 | * |
| 167 | * Returns 0 on success or a negative error code. |
| 168 | */ |
| 169 | int __rtnl_register(int protocol, int msgtype, |
| 170 | rtnl_doit_func doit, rtnl_dumpit_func dumpit) |
| 171 | { |
| 172 | struct rtnl_link *tab; |
| 173 | int msgindex; |
| 174 | |
| 175 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 176 | msgindex = rtm_msgindex(msgtype); |
| 177 | |
| 178 | tab = rtnl_msg_handlers[protocol]; |
| 179 | if (tab == NULL) { |
| 180 | tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL); |
| 181 | if (tab == NULL) |
| 182 | return -ENOBUFS; |
| 183 | |
| 184 | rtnl_msg_handlers[protocol] = tab; |
| 185 | } |
| 186 | |
| 187 | if (doit) |
| 188 | tab[msgindex].doit = doit; |
| 189 | |
| 190 | if (dumpit) |
| 191 | tab[msgindex].dumpit = dumpit; |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | EXPORT_SYMBOL_GPL(__rtnl_register); |
| 197 | |
| 198 | /** |
| 199 | * rtnl_register - Register a rtnetlink message type |
| 200 | * |
| 201 | * Identical to __rtnl_register() but panics on failure. This is useful |
| 202 | * as failure of this function is very unlikely, it can only happen due |
| 203 | * to lack of memory when allocating the chain to store all message |
| 204 | * handlers for a protocol. Meant for use in init functions where lack |
| 205 | * of memory implies no sense in continueing. |
| 206 | */ |
| 207 | void rtnl_register(int protocol, int msgtype, |
| 208 | rtnl_doit_func doit, rtnl_dumpit_func dumpit) |
| 209 | { |
| 210 | if (__rtnl_register(protocol, msgtype, doit, dumpit) < 0) |
| 211 | panic("Unable to register rtnetlink message handler, " |
| 212 | "protocol = %d, message type = %d\n", |
| 213 | protocol, msgtype); |
| 214 | } |
| 215 | |
| 216 | EXPORT_SYMBOL_GPL(rtnl_register); |
| 217 | |
| 218 | /** |
| 219 | * rtnl_unregister - Unregister a rtnetlink message type |
| 220 | * @protocol: Protocol family or PF_UNSPEC |
| 221 | * @msgtype: rtnetlink message type |
| 222 | * |
| 223 | * Returns 0 on success or a negative error code. |
| 224 | */ |
| 225 | int rtnl_unregister(int protocol, int msgtype) |
| 226 | { |
| 227 | int msgindex; |
| 228 | |
| 229 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 230 | msgindex = rtm_msgindex(msgtype); |
| 231 | |
| 232 | if (rtnl_msg_handlers[protocol] == NULL) |
| 233 | return -ENOENT; |
| 234 | |
| 235 | rtnl_msg_handlers[protocol][msgindex].doit = NULL; |
| 236 | rtnl_msg_handlers[protocol][msgindex].dumpit = NULL; |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | EXPORT_SYMBOL_GPL(rtnl_unregister); |
| 242 | |
| 243 | /** |
| 244 | * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol |
| 245 | * @protocol : Protocol family or PF_UNSPEC |
| 246 | * |
| 247 | * Identical to calling rtnl_unregster() for all registered message types |
| 248 | * of a certain protocol family. |
| 249 | */ |
| 250 | void rtnl_unregister_all(int protocol) |
| 251 | { |
| 252 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 253 | |
| 254 | kfree(rtnl_msg_handlers[protocol]); |
| 255 | rtnl_msg_handlers[protocol] = NULL; |
| 256 | } |
| 257 | |
| 258 | EXPORT_SYMBOL_GPL(rtnl_unregister_all); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 260 | static LIST_HEAD(link_ops); |
| 261 | |
| 262 | /** |
| 263 | * __rtnl_link_register - Register rtnl_link_ops with rtnetlink. |
| 264 | * @ops: struct rtnl_link_ops * to register |
| 265 | * |
| 266 | * The caller must hold the rtnl_mutex. This function should be used |
| 267 | * by drivers that create devices during module initialization. It |
| 268 | * must be called before registering the devices. |
| 269 | * |
| 270 | * Returns 0 on success or a negative error code. |
| 271 | */ |
| 272 | int __rtnl_link_register(struct rtnl_link_ops *ops) |
| 273 | { |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 274 | if (!ops->dellink) |
| 275 | ops->dellink = unregister_netdevice; |
| 276 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 277 | list_add_tail(&ops->list, &link_ops); |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | EXPORT_SYMBOL_GPL(__rtnl_link_register); |
| 282 | |
| 283 | /** |
| 284 | * rtnl_link_register - Register rtnl_link_ops with rtnetlink. |
| 285 | * @ops: struct rtnl_link_ops * to register |
| 286 | * |
| 287 | * Returns 0 on success or a negative error code. |
| 288 | */ |
| 289 | int rtnl_link_register(struct rtnl_link_ops *ops) |
| 290 | { |
| 291 | int err; |
| 292 | |
| 293 | rtnl_lock(); |
| 294 | err = __rtnl_link_register(ops); |
| 295 | rtnl_unlock(); |
| 296 | return err; |
| 297 | } |
| 298 | |
| 299 | EXPORT_SYMBOL_GPL(rtnl_link_register); |
| 300 | |
| 301 | /** |
| 302 | * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink. |
| 303 | * @ops: struct rtnl_link_ops * to unregister |
| 304 | * |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 305 | * The caller must hold the rtnl_mutex. |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 306 | */ |
| 307 | void __rtnl_link_unregister(struct rtnl_link_ops *ops) |
| 308 | { |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 309 | struct net_device *dev, *n; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 310 | struct net *net; |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 311 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 312 | for_each_net(net) { |
| 313 | for_each_netdev_safe(net, dev, n) { |
| 314 | if (dev->rtnl_link_ops == ops) |
| 315 | ops->dellink(dev); |
| 316 | } |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 317 | } |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 318 | list_del(&ops->list); |
| 319 | } |
| 320 | |
| 321 | EXPORT_SYMBOL_GPL(__rtnl_link_unregister); |
| 322 | |
| 323 | /** |
| 324 | * rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink. |
| 325 | * @ops: struct rtnl_link_ops * to unregister |
| 326 | */ |
| 327 | void rtnl_link_unregister(struct rtnl_link_ops *ops) |
| 328 | { |
| 329 | rtnl_lock(); |
| 330 | __rtnl_link_unregister(ops); |
| 331 | rtnl_unlock(); |
| 332 | } |
| 333 | |
| 334 | EXPORT_SYMBOL_GPL(rtnl_link_unregister); |
| 335 | |
| 336 | static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind) |
| 337 | { |
| 338 | const struct rtnl_link_ops *ops; |
| 339 | |
| 340 | list_for_each_entry(ops, &link_ops, list) { |
| 341 | if (!strcmp(ops->kind, kind)) |
| 342 | return ops; |
| 343 | } |
| 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | static size_t rtnl_link_get_size(const struct net_device *dev) |
| 348 | { |
| 349 | const struct rtnl_link_ops *ops = dev->rtnl_link_ops; |
| 350 | size_t size; |
| 351 | |
| 352 | if (!ops) |
| 353 | return 0; |
| 354 | |
| 355 | size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */ |
| 356 | nlmsg_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */ |
| 357 | |
| 358 | if (ops->get_size) |
| 359 | /* IFLA_INFO_DATA + nested data */ |
| 360 | size += nlmsg_total_size(sizeof(struct nlattr)) + |
| 361 | ops->get_size(dev); |
| 362 | |
| 363 | if (ops->get_xstats_size) |
| 364 | size += ops->get_xstats_size(dev); /* IFLA_INFO_XSTATS */ |
| 365 | |
| 366 | return size; |
| 367 | } |
| 368 | |
| 369 | static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev) |
| 370 | { |
| 371 | const struct rtnl_link_ops *ops = dev->rtnl_link_ops; |
| 372 | struct nlattr *linkinfo, *data; |
| 373 | int err = -EMSGSIZE; |
| 374 | |
| 375 | linkinfo = nla_nest_start(skb, IFLA_LINKINFO); |
| 376 | if (linkinfo == NULL) |
| 377 | goto out; |
| 378 | |
| 379 | if (nla_put_string(skb, IFLA_INFO_KIND, ops->kind) < 0) |
| 380 | goto err_cancel_link; |
| 381 | if (ops->fill_xstats) { |
| 382 | err = ops->fill_xstats(skb, dev); |
| 383 | if (err < 0) |
| 384 | goto err_cancel_link; |
| 385 | } |
| 386 | if (ops->fill_info) { |
| 387 | data = nla_nest_start(skb, IFLA_INFO_DATA); |
| 388 | if (data == NULL) |
| 389 | goto err_cancel_link; |
| 390 | err = ops->fill_info(skb, dev); |
| 391 | if (err < 0) |
| 392 | goto err_cancel_data; |
| 393 | nla_nest_end(skb, data); |
| 394 | } |
| 395 | |
| 396 | nla_nest_end(skb, linkinfo); |
| 397 | return 0; |
| 398 | |
| 399 | err_cancel_data: |
| 400 | nla_nest_cancel(skb, data); |
| 401 | err_cancel_link: |
| 402 | nla_nest_cancel(skb, linkinfo); |
| 403 | out: |
| 404 | return err; |
| 405 | } |
| 406 | |
Thomas Graf | db46edc | 2005-05-03 14:29:39 -0700 | [diff] [blame] | 407 | static const int rtm_min[RTM_NR_FAMILIES] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 409 | [RTM_FAM(RTM_NEWLINK)] = NLMSG_LENGTH(sizeof(struct ifinfomsg)), |
| 410 | [RTM_FAM(RTM_NEWADDR)] = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), |
| 411 | [RTM_FAM(RTM_NEWROUTE)] = NLMSG_LENGTH(sizeof(struct rtmsg)), |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 412 | [RTM_FAM(RTM_NEWRULE)] = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)), |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 413 | [RTM_FAM(RTM_NEWQDISC)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 414 | [RTM_FAM(RTM_NEWTCLASS)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 415 | [RTM_FAM(RTM_NEWTFILTER)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 416 | [RTM_FAM(RTM_NEWACTION)] = NLMSG_LENGTH(sizeof(struct tcamsg)), |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 417 | [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)), |
| 418 | [RTM_FAM(RTM_GETANYCAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | }; |
| 420 | |
Thomas Graf | db46edc | 2005-05-03 14:29:39 -0700 | [diff] [blame] | 421 | static const int rta_max[RTM_NR_FAMILIES] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 423 | [RTM_FAM(RTM_NEWLINK)] = IFLA_MAX, |
| 424 | [RTM_FAM(RTM_NEWADDR)] = IFA_MAX, |
| 425 | [RTM_FAM(RTM_NEWROUTE)] = RTA_MAX, |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 426 | [RTM_FAM(RTM_NEWRULE)] = FRA_MAX, |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 427 | [RTM_FAM(RTM_NEWQDISC)] = TCA_MAX, |
| 428 | [RTM_FAM(RTM_NEWTCLASS)] = TCA_MAX, |
| 429 | [RTM_FAM(RTM_NEWTFILTER)] = TCA_MAX, |
| 430 | [RTM_FAM(RTM_NEWACTION)] = TCAA_MAX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data) |
| 434 | { |
| 435 | struct rtattr *rta; |
| 436 | int size = RTA_LENGTH(attrlen); |
| 437 | |
| 438 | rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size)); |
| 439 | rta->rta_type = attrtype; |
| 440 | rta->rta_len = size; |
| 441 | memcpy(RTA_DATA(rta), data, attrlen); |
Patrick McHardy | b3563c4 | 2005-06-28 12:54:43 -0700 | [diff] [blame] | 442 | memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size) |
| 446 | { |
| 447 | size_t ret = RTA_PAYLOAD(rta); |
| 448 | char *src = RTA_DATA(rta); |
| 449 | |
| 450 | if (ret > 0 && src[ret - 1] == '\0') |
| 451 | ret--; |
| 452 | if (size > 0) { |
| 453 | size_t len = (ret >= size) ? size - 1 : ret; |
| 454 | memset(dest, 0, size); |
| 455 | memcpy(dest, src, len); |
| 456 | } |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | int rtnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) |
| 461 | { |
| 462 | int err = 0; |
| 463 | |
Patrick McHardy | ac6d439 | 2005-08-14 19:29:52 -0700 | [diff] [blame] | 464 | NETLINK_CB(skb).dst_group = group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (echo) |
| 466 | atomic_inc(&skb->users); |
| 467 | netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL); |
| 468 | if (echo) |
| 469 | err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT); |
| 470 | return err; |
| 471 | } |
| 472 | |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 473 | int rtnl_unicast(struct sk_buff *skb, u32 pid) |
| 474 | { |
| 475 | return nlmsg_unicast(rtnl, skb, pid); |
| 476 | } |
| 477 | |
Thomas Graf | 97676b6 | 2006-08-15 00:31:41 -0700 | [diff] [blame] | 478 | int rtnl_notify(struct sk_buff *skb, u32 pid, u32 group, |
| 479 | struct nlmsghdr *nlh, gfp_t flags) |
| 480 | { |
| 481 | int report = 0; |
| 482 | |
| 483 | if (nlh) |
| 484 | report = nlmsg_report(nlh); |
| 485 | |
| 486 | return nlmsg_notify(rtnl, skb, pid, group, report, flags); |
| 487 | } |
| 488 | |
| 489 | void rtnl_set_sk_err(u32 group, int error) |
| 490 | { |
| 491 | netlink_set_err(rtnl, 0, group, error); |
| 492 | } |
| 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics) |
| 495 | { |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 496 | struct nlattr *mx; |
| 497 | int i, valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 499 | mx = nla_nest_start(skb, RTA_METRICS); |
| 500 | if (mx == NULL) |
| 501 | return -ENOBUFS; |
| 502 | |
| 503 | for (i = 0; i < RTAX_MAX; i++) { |
| 504 | if (metrics[i]) { |
| 505 | valid++; |
| 506 | NLA_PUT_U32(skb, i+1, metrics[i]); |
| 507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
David S. Miller | a57d27f | 2006-08-22 22:20:14 -0700 | [diff] [blame] | 510 | if (!valid) { |
| 511 | nla_nest_cancel(skb, mx); |
| 512 | return 0; |
| 513 | } |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 514 | |
| 515 | return nla_nest_end(skb, mx); |
| 516 | |
| 517 | nla_put_failure: |
| 518 | return nla_nest_cancel(skb, mx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Thomas Graf | e3703b3 | 2006-11-27 09:27:07 -0800 | [diff] [blame] | 521 | int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id, |
| 522 | u32 ts, u32 tsage, long expires, u32 error) |
| 523 | { |
| 524 | struct rta_cacheinfo ci = { |
| 525 | .rta_lastuse = jiffies_to_clock_t(jiffies - dst->lastuse), |
| 526 | .rta_used = dst->__use, |
| 527 | .rta_clntref = atomic_read(&(dst->__refcnt)), |
| 528 | .rta_error = error, |
| 529 | .rta_id = id, |
| 530 | .rta_ts = ts, |
| 531 | .rta_tsage = tsage, |
| 532 | }; |
| 533 | |
| 534 | if (expires) |
| 535 | ci.rta_expires = jiffies_to_clock_t(expires); |
| 536 | |
| 537 | return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci); |
| 538 | } |
| 539 | |
| 540 | EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 542 | static void set_operstate(struct net_device *dev, unsigned char transition) |
| 543 | { |
| 544 | unsigned char operstate = dev->operstate; |
| 545 | |
| 546 | switch(transition) { |
| 547 | case IF_OPER_UP: |
| 548 | if ((operstate == IF_OPER_DORMANT || |
| 549 | operstate == IF_OPER_UNKNOWN) && |
| 550 | !netif_dormant(dev)) |
| 551 | operstate = IF_OPER_UP; |
| 552 | break; |
| 553 | |
| 554 | case IF_OPER_DORMANT: |
| 555 | if (operstate == IF_OPER_UP || |
| 556 | operstate == IF_OPER_UNKNOWN) |
| 557 | operstate = IF_OPER_DORMANT; |
| 558 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 559 | } |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 560 | |
| 561 | if (dev->operstate != operstate) { |
| 562 | write_lock_bh(&dev_base_lock); |
| 563 | dev->operstate = operstate; |
| 564 | write_unlock_bh(&dev_base_lock); |
| 565 | netdev_state_change(dev); |
| 566 | } |
| 567 | } |
| 568 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 569 | static void copy_rtnl_link_stats(struct rtnl_link_stats *a, |
| 570 | struct net_device_stats *b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 572 | a->rx_packets = b->rx_packets; |
| 573 | a->tx_packets = b->tx_packets; |
| 574 | a->rx_bytes = b->rx_bytes; |
| 575 | a->tx_bytes = b->tx_bytes; |
| 576 | a->rx_errors = b->rx_errors; |
| 577 | a->tx_errors = b->tx_errors; |
| 578 | a->rx_dropped = b->rx_dropped; |
| 579 | a->tx_dropped = b->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 581 | a->multicast = b->multicast; |
| 582 | a->collisions = b->collisions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 584 | a->rx_length_errors = b->rx_length_errors; |
| 585 | a->rx_over_errors = b->rx_over_errors; |
| 586 | a->rx_crc_errors = b->rx_crc_errors; |
| 587 | a->rx_frame_errors = b->rx_frame_errors; |
| 588 | a->rx_fifo_errors = b->rx_fifo_errors; |
| 589 | a->rx_missed_errors = b->rx_missed_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 591 | a->tx_aborted_errors = b->tx_aborted_errors; |
| 592 | a->tx_carrier_errors = b->tx_carrier_errors; |
| 593 | a->tx_fifo_errors = b->tx_fifo_errors; |
| 594 | a->tx_heartbeat_errors = b->tx_heartbeat_errors; |
| 595 | a->tx_window_errors = b->tx_window_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 597 | a->rx_compressed = b->rx_compressed; |
| 598 | a->tx_compressed = b->tx_compressed; |
| 599 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 601 | static inline size_t if_nlmsg_size(const struct net_device *dev) |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 602 | { |
| 603 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
| 604 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 605 | + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ |
| 606 | + nla_total_size(sizeof(struct rtnl_link_ifmap)) |
| 607 | + nla_total_size(sizeof(struct rtnl_link_stats)) |
| 608 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 609 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ |
| 610 | + nla_total_size(4) /* IFLA_TXQLEN */ |
| 611 | + nla_total_size(4) /* IFLA_WEIGHT */ |
| 612 | + nla_total_size(4) /* IFLA_MTU */ |
| 613 | + nla_total_size(4) /* IFLA_LINK */ |
| 614 | + nla_total_size(4) /* IFLA_MASTER */ |
| 615 | + nla_total_size(1) /* IFLA_OPERSTATE */ |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 616 | + nla_total_size(1) /* IFLA_LINKMODE */ |
| 617 | + rtnl_link_get_size(dev); /* IFLA_LINKINFO */ |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 620 | static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, |
Patrick McHardy | 575c3e2 | 2007-05-22 17:00:49 -0700 | [diff] [blame] | 621 | int type, u32 pid, u32 seq, u32 change, |
| 622 | unsigned int flags) |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 623 | { |
| 624 | struct ifinfomsg *ifm; |
| 625 | struct nlmsghdr *nlh; |
| 626 | |
| 627 | nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags); |
| 628 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 629 | return -EMSGSIZE; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 630 | |
| 631 | ifm = nlmsg_data(nlh); |
| 632 | ifm->ifi_family = AF_UNSPEC; |
| 633 | ifm->__ifi_pad = 0; |
| 634 | ifm->ifi_type = dev->type; |
| 635 | ifm->ifi_index = dev->ifindex; |
| 636 | ifm->ifi_flags = dev_get_flags(dev); |
| 637 | ifm->ifi_change = change; |
| 638 | |
| 639 | NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); |
| 640 | NLA_PUT_U32(skb, IFLA_TXQLEN, dev->tx_queue_len); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 641 | NLA_PUT_U8(skb, IFLA_OPERSTATE, |
| 642 | netif_running(dev) ? dev->operstate : IF_OPER_DOWN); |
| 643 | NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode); |
| 644 | NLA_PUT_U32(skb, IFLA_MTU, dev->mtu); |
| 645 | |
| 646 | if (dev->ifindex != dev->iflink) |
| 647 | NLA_PUT_U32(skb, IFLA_LINK, dev->iflink); |
| 648 | |
| 649 | if (dev->master) |
| 650 | NLA_PUT_U32(skb, IFLA_MASTER, dev->master->ifindex); |
| 651 | |
| 652 | if (dev->qdisc_sleeping) |
| 653 | NLA_PUT_STRING(skb, IFLA_QDISC, dev->qdisc_sleeping->ops->id); |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 654 | |
| 655 | if (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct rtnl_link_ifmap map = { |
| 657 | .mem_start = dev->mem_start, |
| 658 | .mem_end = dev->mem_end, |
| 659 | .base_addr = dev->base_addr, |
| 660 | .irq = dev->irq, |
| 661 | .dma = dev->dma, |
| 662 | .port = dev->if_port, |
| 663 | }; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 664 | NLA_PUT(skb, IFLA_MAP, sizeof(map), &map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | if (dev->addr_len) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 668 | NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr); |
| 669 | NLA_PUT(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | if (dev->get_stats) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 673 | struct net_device_stats *stats = dev->get_stats(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | if (stats) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 675 | struct nlattr *attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 677 | attr = nla_reserve(skb, IFLA_STATS, |
| 678 | sizeof(struct rtnl_link_stats)); |
| 679 | if (attr == NULL) |
| 680 | goto nla_put_failure; |
| 681 | |
| 682 | copy_rtnl_link_stats(nla_data(attr), stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 686 | if (dev->rtnl_link_ops) { |
| 687 | if (rtnl_link_fill(skb, dev) < 0) |
| 688 | goto nla_put_failure; |
| 689 | } |
| 690 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 691 | return nlmsg_end(skb, nlh); |
| 692 | |
| 693 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 694 | nlmsg_cancel(skb, nlh); |
| 695 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 698 | static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 700 | struct net *net = skb->sk->sk_net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | int idx; |
| 702 | int s_idx = cb->args[0]; |
| 703 | struct net_device *dev; |
| 704 | |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 705 | idx = 0; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 706 | for_each_netdev(net, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (idx < s_idx) |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 708 | goto cont; |
Patrick McHardy | 575c3e2 | 2007-05-22 17:00:49 -0700 | [diff] [blame] | 709 | if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK, |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 710 | NETLINK_CB(cb->skb).pid, |
| 711 | cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | break; |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 713 | cont: |
| 714 | idx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | cb->args[0] = idx; |
| 717 | |
| 718 | return skb->len; |
| 719 | } |
| 720 | |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 721 | const struct nla_policy ifla_policy[IFLA_MAX+1] = { |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 722 | [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 }, |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 723 | [IFLA_ADDRESS] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN }, |
| 724 | [IFLA_BROADCAST] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN }, |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 725 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 726 | [IFLA_MTU] = { .type = NLA_U32 }, |
| 727 | [IFLA_TXQLEN] = { .type = NLA_U32 }, |
| 728 | [IFLA_WEIGHT] = { .type = NLA_U32 }, |
| 729 | [IFLA_OPERSTATE] = { .type = NLA_U8 }, |
| 730 | [IFLA_LINKMODE] = { .type = NLA_U8 }, |
Eric W. Biederman | d8a5ec6 | 2007-09-12 13:57:04 +0200 | [diff] [blame] | 731 | [IFLA_NET_NS_PID] = { .type = NLA_U32 }, |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 732 | }; |
| 733 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 734 | static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { |
| 735 | [IFLA_INFO_KIND] = { .type = NLA_STRING }, |
| 736 | [IFLA_INFO_DATA] = { .type = NLA_NESTED }, |
| 737 | }; |
| 738 | |
Eric W. Biederman | d8a5ec6 | 2007-09-12 13:57:04 +0200 | [diff] [blame] | 739 | static struct net *get_net_ns_by_pid(pid_t pid) |
| 740 | { |
| 741 | struct task_struct *tsk; |
| 742 | struct net *net; |
| 743 | |
| 744 | /* Lookup the network namespace */ |
| 745 | net = ERR_PTR(-ESRCH); |
| 746 | rcu_read_lock(); |
| 747 | tsk = find_task_by_pid(pid); |
| 748 | if (tsk) { |
| 749 | task_lock(tsk); |
| 750 | if (tsk->nsproxy) |
| 751 | net = get_net(tsk->nsproxy->net_ns); |
| 752 | task_unlock(tsk); |
| 753 | } |
| 754 | rcu_read_unlock(); |
| 755 | return net; |
| 756 | } |
| 757 | |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 758 | static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 759 | struct nlattr **tb, char *ifname, int modified) |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 760 | { |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 761 | int send_addr_notify = 0; |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 762 | int err; |
| 763 | |
Eric W. Biederman | d8a5ec6 | 2007-09-12 13:57:04 +0200 | [diff] [blame] | 764 | if (tb[IFLA_NET_NS_PID]) { |
| 765 | struct net *net; |
| 766 | net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID])); |
| 767 | if (IS_ERR(net)) { |
| 768 | err = PTR_ERR(net); |
| 769 | goto errout; |
| 770 | } |
| 771 | err = dev_change_net_namespace(dev, net, ifname); |
| 772 | put_net(net); |
| 773 | if (err) |
| 774 | goto errout; |
| 775 | modified = 1; |
| 776 | } |
| 777 | |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 778 | if (tb[IFLA_MAP]) { |
| 779 | struct rtnl_link_ifmap *u_map; |
| 780 | struct ifmap k_map; |
| 781 | |
| 782 | if (!dev->set_config) { |
| 783 | err = -EOPNOTSUPP; |
| 784 | goto errout; |
| 785 | } |
| 786 | |
| 787 | if (!netif_device_present(dev)) { |
| 788 | err = -ENODEV; |
| 789 | goto errout; |
| 790 | } |
| 791 | |
| 792 | u_map = nla_data(tb[IFLA_MAP]); |
| 793 | k_map.mem_start = (unsigned long) u_map->mem_start; |
| 794 | k_map.mem_end = (unsigned long) u_map->mem_end; |
| 795 | k_map.base_addr = (unsigned short) u_map->base_addr; |
| 796 | k_map.irq = (unsigned char) u_map->irq; |
| 797 | k_map.dma = (unsigned char) u_map->dma; |
| 798 | k_map.port = (unsigned char) u_map->port; |
| 799 | |
| 800 | err = dev->set_config(dev, &k_map); |
| 801 | if (err < 0) |
| 802 | goto errout; |
| 803 | |
| 804 | modified = 1; |
| 805 | } |
| 806 | |
| 807 | if (tb[IFLA_ADDRESS]) { |
| 808 | struct sockaddr *sa; |
| 809 | int len; |
| 810 | |
| 811 | if (!dev->set_mac_address) { |
| 812 | err = -EOPNOTSUPP; |
| 813 | goto errout; |
| 814 | } |
| 815 | |
| 816 | if (!netif_device_present(dev)) { |
| 817 | err = -ENODEV; |
| 818 | goto errout; |
| 819 | } |
| 820 | |
| 821 | len = sizeof(sa_family_t) + dev->addr_len; |
| 822 | sa = kmalloc(len, GFP_KERNEL); |
| 823 | if (!sa) { |
| 824 | err = -ENOMEM; |
| 825 | goto errout; |
| 826 | } |
| 827 | sa->sa_family = dev->type; |
| 828 | memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]), |
| 829 | dev->addr_len); |
| 830 | err = dev->set_mac_address(dev, sa); |
| 831 | kfree(sa); |
| 832 | if (err) |
| 833 | goto errout; |
| 834 | send_addr_notify = 1; |
| 835 | modified = 1; |
| 836 | } |
| 837 | |
| 838 | if (tb[IFLA_MTU]) { |
| 839 | err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU])); |
| 840 | if (err < 0) |
| 841 | goto errout; |
| 842 | modified = 1; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * Interface selected by interface index but interface |
| 847 | * name provided implies that a name change has been |
| 848 | * requested. |
| 849 | */ |
| 850 | if (ifm->ifi_index > 0 && ifname[0]) { |
| 851 | err = dev_change_name(dev, ifname); |
| 852 | if (err < 0) |
| 853 | goto errout; |
| 854 | modified = 1; |
| 855 | } |
| 856 | |
| 857 | if (tb[IFLA_BROADCAST]) { |
| 858 | nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len); |
| 859 | send_addr_notify = 1; |
| 860 | } |
| 861 | |
| 862 | if (ifm->ifi_flags || ifm->ifi_change) { |
| 863 | unsigned int flags = ifm->ifi_flags; |
| 864 | |
| 865 | /* bugwards compatibility: ifi_change == 0 is treated as ~0 */ |
| 866 | if (ifm->ifi_change) |
| 867 | flags = (flags & ifm->ifi_change) | |
| 868 | (dev->flags & ~ifm->ifi_change); |
| 869 | dev_change_flags(dev, flags); |
| 870 | } |
| 871 | |
| 872 | if (tb[IFLA_TXQLEN]) |
| 873 | dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]); |
| 874 | |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 875 | if (tb[IFLA_OPERSTATE]) |
| 876 | set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); |
| 877 | |
| 878 | if (tb[IFLA_LINKMODE]) { |
| 879 | write_lock_bh(&dev_base_lock); |
| 880 | dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); |
| 881 | write_unlock_bh(&dev_base_lock); |
| 882 | } |
| 883 | |
| 884 | err = 0; |
| 885 | |
| 886 | errout: |
| 887 | if (err < 0 && modified && net_ratelimit()) |
| 888 | printk(KERN_WARNING "A link change request failed with " |
| 889 | "some changes comitted already. Interface %s may " |
| 890 | "have been left with an inconsistent configuration, " |
| 891 | "please check.\n", dev->name); |
| 892 | |
| 893 | if (send_addr_notify) |
| 894 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); |
| 895 | return err; |
| 896 | } |
| 897 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 898 | static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 900 | struct net *net = skb->sk->sk_net; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 901 | struct ifinfomsg *ifm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | struct net_device *dev; |
Patrick McHardy | 0157f60 | 2007-06-13 12:03:36 -0700 | [diff] [blame] | 903 | int err; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 904 | struct nlattr *tb[IFLA_MAX+1]; |
| 905 | char ifname[IFNAMSIZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 907 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 908 | if (err < 0) |
| 909 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 911 | if (tb[IFLA_IFNAME]) |
| 912 | nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ); |
Patrick McHardy | 78e5b891 | 2006-09-13 20:35:36 -0700 | [diff] [blame] | 913 | else |
| 914 | ifname[0] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | err = -EINVAL; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 917 | ifm = nlmsg_data(nlh); |
Patrick McHardy | 51055be | 2007-06-05 12:40:01 -0700 | [diff] [blame] | 918 | if (ifm->ifi_index > 0) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 919 | dev = dev_get_by_index(net, ifm->ifi_index); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 920 | else if (tb[IFLA_IFNAME]) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 921 | dev = dev_get_by_name(net, ifname); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 922 | else |
| 923 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 925 | if (dev == NULL) { |
| 926 | err = -ENODEV; |
| 927 | goto errout; |
| 928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 930 | if (tb[IFLA_ADDRESS] && |
| 931 | nla_len(tb[IFLA_ADDRESS]) < dev->addr_len) |
| 932 | goto errout_dev; |
| 933 | |
| 934 | if (tb[IFLA_BROADCAST] && |
| 935 | nla_len(tb[IFLA_BROADCAST]) < dev->addr_len) |
| 936 | goto errout_dev; |
| 937 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 938 | err = do_setlink(dev, ifm, tb, ifname, 0); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 939 | errout_dev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | dev_put(dev); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 941 | errout: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | return err; |
| 943 | } |
| 944 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 945 | static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 946 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 947 | struct net *net = skb->sk->sk_net; |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 948 | const struct rtnl_link_ops *ops; |
| 949 | struct net_device *dev; |
| 950 | struct ifinfomsg *ifm; |
| 951 | char ifname[IFNAMSIZ]; |
| 952 | struct nlattr *tb[IFLA_MAX+1]; |
| 953 | int err; |
| 954 | |
| 955 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 956 | if (err < 0) |
| 957 | return err; |
| 958 | |
| 959 | if (tb[IFLA_IFNAME]) |
| 960 | nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ); |
| 961 | |
| 962 | ifm = nlmsg_data(nlh); |
| 963 | if (ifm->ifi_index > 0) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 964 | dev = __dev_get_by_index(net, ifm->ifi_index); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 965 | else if (tb[IFLA_IFNAME]) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 966 | dev = __dev_get_by_name(net, ifname); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 967 | else |
| 968 | return -EINVAL; |
| 969 | |
| 970 | if (!dev) |
| 971 | return -ENODEV; |
| 972 | |
| 973 | ops = dev->rtnl_link_ops; |
| 974 | if (!ops) |
| 975 | return -EOPNOTSUPP; |
| 976 | |
| 977 | ops->dellink(dev); |
| 978 | return 0; |
| 979 | } |
| 980 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 981 | struct net_device *rtnl_create_link(struct net *net, char *ifname, |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 982 | const struct rtnl_link_ops *ops, struct nlattr *tb[]) |
| 983 | { |
| 984 | int err; |
| 985 | struct net_device *dev; |
| 986 | |
| 987 | err = -ENOMEM; |
| 988 | dev = alloc_netdev(ops->priv_size, ifname, ops->setup); |
| 989 | if (!dev) |
| 990 | goto err; |
| 991 | |
| 992 | if (strchr(dev->name, '%')) { |
| 993 | err = dev_alloc_name(dev, dev->name); |
| 994 | if (err < 0) |
| 995 | goto err_free; |
| 996 | } |
| 997 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 998 | dev->nd_net = net; |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 999 | dev->rtnl_link_ops = ops; |
| 1000 | |
| 1001 | if (tb[IFLA_MTU]) |
| 1002 | dev->mtu = nla_get_u32(tb[IFLA_MTU]); |
| 1003 | if (tb[IFLA_ADDRESS]) |
| 1004 | memcpy(dev->dev_addr, nla_data(tb[IFLA_ADDRESS]), |
| 1005 | nla_len(tb[IFLA_ADDRESS])); |
| 1006 | if (tb[IFLA_BROADCAST]) |
| 1007 | memcpy(dev->broadcast, nla_data(tb[IFLA_BROADCAST]), |
| 1008 | nla_len(tb[IFLA_BROADCAST])); |
| 1009 | if (tb[IFLA_TXQLEN]) |
| 1010 | dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]); |
| 1011 | if (tb[IFLA_OPERSTATE]) |
| 1012 | set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); |
| 1013 | if (tb[IFLA_LINKMODE]) |
| 1014 | dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); |
| 1015 | |
| 1016 | return dev; |
| 1017 | |
| 1018 | err_free: |
| 1019 | free_netdev(dev); |
| 1020 | err: |
| 1021 | return ERR_PTR(err); |
| 1022 | } |
| 1023 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1024 | static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 1025 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1026 | struct net *net = skb->sk->sk_net; |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1027 | const struct rtnl_link_ops *ops; |
| 1028 | struct net_device *dev; |
| 1029 | struct ifinfomsg *ifm; |
| 1030 | char kind[MODULE_NAME_LEN]; |
| 1031 | char ifname[IFNAMSIZ]; |
| 1032 | struct nlattr *tb[IFLA_MAX+1]; |
| 1033 | struct nlattr *linkinfo[IFLA_INFO_MAX+1]; |
| 1034 | int err; |
| 1035 | |
Thomas Graf | 8072f08 | 2007-07-31 14:13:50 -0700 | [diff] [blame] | 1036 | #ifdef CONFIG_KMOD |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1037 | replay: |
Thomas Graf | 8072f08 | 2007-07-31 14:13:50 -0700 | [diff] [blame] | 1038 | #endif |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1039 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 1040 | if (err < 0) |
| 1041 | return err; |
| 1042 | |
| 1043 | if (tb[IFLA_IFNAME]) |
| 1044 | nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ); |
| 1045 | else |
| 1046 | ifname[0] = '\0'; |
| 1047 | |
| 1048 | ifm = nlmsg_data(nlh); |
| 1049 | if (ifm->ifi_index > 0) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1050 | dev = __dev_get_by_index(net, ifm->ifi_index); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1051 | else if (ifname[0]) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1052 | dev = __dev_get_by_name(net, ifname); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1053 | else |
| 1054 | dev = NULL; |
| 1055 | |
| 1056 | if (tb[IFLA_LINKINFO]) { |
| 1057 | err = nla_parse_nested(linkinfo, IFLA_INFO_MAX, |
| 1058 | tb[IFLA_LINKINFO], ifla_info_policy); |
| 1059 | if (err < 0) |
| 1060 | return err; |
| 1061 | } else |
| 1062 | memset(linkinfo, 0, sizeof(linkinfo)); |
| 1063 | |
| 1064 | if (linkinfo[IFLA_INFO_KIND]) { |
| 1065 | nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind)); |
| 1066 | ops = rtnl_link_ops_get(kind); |
| 1067 | } else { |
| 1068 | kind[0] = '\0'; |
| 1069 | ops = NULL; |
| 1070 | } |
| 1071 | |
| 1072 | if (1) { |
| 1073 | struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL; |
| 1074 | |
| 1075 | if (ops) { |
| 1076 | if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { |
| 1077 | err = nla_parse_nested(attr, ops->maxtype, |
| 1078 | linkinfo[IFLA_INFO_DATA], |
| 1079 | ops->policy); |
| 1080 | if (err < 0) |
| 1081 | return err; |
| 1082 | data = attr; |
| 1083 | } |
| 1084 | if (ops->validate) { |
| 1085 | err = ops->validate(tb, data); |
| 1086 | if (err < 0) |
| 1087 | return err; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | if (dev) { |
| 1092 | int modified = 0; |
| 1093 | |
| 1094 | if (nlh->nlmsg_flags & NLM_F_EXCL) |
| 1095 | return -EEXIST; |
| 1096 | if (nlh->nlmsg_flags & NLM_F_REPLACE) |
| 1097 | return -EOPNOTSUPP; |
| 1098 | |
| 1099 | if (linkinfo[IFLA_INFO_DATA]) { |
| 1100 | if (!ops || ops != dev->rtnl_link_ops || |
| 1101 | !ops->changelink) |
| 1102 | return -EOPNOTSUPP; |
| 1103 | |
| 1104 | err = ops->changelink(dev, tb, data); |
| 1105 | if (err < 0) |
| 1106 | return err; |
| 1107 | modified = 1; |
| 1108 | } |
| 1109 | |
| 1110 | return do_setlink(dev, ifm, tb, ifname, modified); |
| 1111 | } |
| 1112 | |
| 1113 | if (!(nlh->nlmsg_flags & NLM_F_CREATE)) |
| 1114 | return -ENODEV; |
| 1115 | |
| 1116 | if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change) |
| 1117 | return -EOPNOTSUPP; |
Patrick McHardy | 0e06877 | 2007-07-11 19:42:31 -0700 | [diff] [blame] | 1118 | if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO]) |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1119 | return -EOPNOTSUPP; |
| 1120 | |
| 1121 | if (!ops) { |
| 1122 | #ifdef CONFIG_KMOD |
| 1123 | if (kind[0]) { |
| 1124 | __rtnl_unlock(); |
| 1125 | request_module("rtnl-link-%s", kind); |
| 1126 | rtnl_lock(); |
| 1127 | ops = rtnl_link_ops_get(kind); |
| 1128 | if (ops) |
| 1129 | goto replay; |
| 1130 | } |
| 1131 | #endif |
| 1132 | return -EOPNOTSUPP; |
| 1133 | } |
| 1134 | |
| 1135 | if (!ifname[0]) |
| 1136 | snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1137 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1138 | dev = rtnl_create_link(net, ifname, ops, tb); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1139 | |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 1140 | if (IS_ERR(dev)) |
| 1141 | err = PTR_ERR(dev); |
| 1142 | else if (ops->newlink) |
Patrick McHardy | 2d85cba | 2007-07-11 19:42:13 -0700 | [diff] [blame] | 1143 | err = ops->newlink(dev, tb, data); |
| 1144 | else |
| 1145 | err = register_netdevice(dev); |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 1146 | |
| 1147 | if (err < 0 && !IS_ERR(dev)) |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1148 | free_netdev(dev); |
| 1149 | return err; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1153 | static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1154 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1155 | struct net *net = skb->sk->sk_net; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1156 | struct ifinfomsg *ifm; |
| 1157 | struct nlattr *tb[IFLA_MAX+1]; |
| 1158 | struct net_device *dev = NULL; |
| 1159 | struct sk_buff *nskb; |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 1160 | int err; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1161 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1162 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 1163 | if (err < 0) |
Eric Sesterhenn | 9918f23 | 2006-09-26 23:26:38 -0700 | [diff] [blame] | 1164 | return err; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1165 | |
| 1166 | ifm = nlmsg_data(nlh); |
Patrick McHardy | 51055be | 2007-06-05 12:40:01 -0700 | [diff] [blame] | 1167 | if (ifm->ifi_index > 0) { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1168 | dev = dev_get_by_index(net, ifm->ifi_index); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1169 | if (dev == NULL) |
| 1170 | return -ENODEV; |
| 1171 | } else |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1172 | return -EINVAL; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1173 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1174 | nskb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1175 | if (nskb == NULL) { |
| 1176 | err = -ENOBUFS; |
| 1177 | goto errout; |
| 1178 | } |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1179 | |
Patrick McHardy | 575c3e2 | 2007-05-22 17:00:49 -0700 | [diff] [blame] | 1180 | err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid, |
| 1181 | nlh->nlmsg_seq, 0, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 1182 | if (err < 0) { |
| 1183 | /* -EMSGSIZE implies BUG in if_nlmsg_size */ |
| 1184 | WARN_ON(err == -EMSGSIZE); |
| 1185 | kfree_skb(nskb); |
| 1186 | goto errout; |
| 1187 | } |
Patrick McHardy | b974179 | 2006-10-12 01:50:30 -0700 | [diff] [blame] | 1188 | err = rtnl_unicast(nskb, NETLINK_CB(skb).pid); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1189 | errout: |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1190 | dev_put(dev); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 1191 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1192 | return err; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1193 | } |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1194 | |
Adrian Bunk | 42bad1d | 2007-04-26 00:57:41 -0700 | [diff] [blame] | 1195 | static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | { |
| 1197 | int idx; |
| 1198 | int s_idx = cb->family; |
| 1199 | |
| 1200 | if (s_idx == 0) |
| 1201 | s_idx = 1; |
| 1202 | for (idx=1; idx<NPROTO; idx++) { |
| 1203 | int type = cb->nlh->nlmsg_type-RTM_BASE; |
| 1204 | if (idx < s_idx || idx == PF_PACKET) |
| 1205 | continue; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1206 | if (rtnl_msg_handlers[idx] == NULL || |
| 1207 | rtnl_msg_handlers[idx][type].dumpit == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | continue; |
| 1209 | if (idx > s_idx) |
| 1210 | memset(&cb->args[0], 0, sizeof(cb->args)); |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1211 | if (rtnl_msg_handlers[idx][type].dumpit(skb, cb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | } |
| 1214 | cb->family = idx; |
| 1215 | |
| 1216 | return skb->len; |
| 1217 | } |
| 1218 | |
| 1219 | void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change) |
| 1220 | { |
| 1221 | struct sk_buff *skb; |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 1222 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1224 | skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL); |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 1225 | if (skb == NULL) |
| 1226 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Patrick McHardy | 575c3e2 | 2007-05-22 17:00:49 -0700 | [diff] [blame] | 1228 | err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 1229 | if (err < 0) { |
| 1230 | /* -EMSGSIZE implies BUG in if_nlmsg_size() */ |
| 1231 | WARN_ON(err == -EMSGSIZE); |
| 1232 | kfree_skb(skb); |
| 1233 | goto errout; |
| 1234 | } |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 1235 | err = rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); |
| 1236 | errout: |
| 1237 | if (err < 0) |
| 1238 | rtnl_set_sk_err(RTNLGRP_LINK, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | /* Protected by RTNL sempahore. */ |
| 1242 | static struct rtattr **rta_buf; |
| 1243 | static int rtattr_max; |
| 1244 | |
| 1245 | /* Process one rtnetlink message. */ |
| 1246 | |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1247 | static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | { |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1249 | rtnl_doit_func doit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | int sz_idx, kind; |
| 1251 | int min_len; |
| 1252 | int family; |
| 1253 | int type; |
Patrick McHardy | 1c2d670 | 2007-04-16 16:59:10 -0700 | [diff] [blame] | 1254 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | type = nlh->nlmsg_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | if (type > RTM_MAX) |
Thomas Graf | 038890f | 2007-04-05 14:35:52 -0700 | [diff] [blame] | 1258 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | type -= RTM_BASE; |
| 1261 | |
| 1262 | /* All the messages must have at least 1 byte length */ |
| 1263 | if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg))) |
| 1264 | return 0; |
| 1265 | |
| 1266 | family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family; |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1267 | if (family >= NPROTO) |
| 1268 | return -EAFNOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | sz_idx = type>>2; |
| 1271 | kind = type&3; |
| 1272 | |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1273 | if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN)) |
| 1274 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
| 1276 | if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1277 | rtnl_dumpit_func dumpit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1279 | dumpit = rtnl_get_dumpit(family, type); |
| 1280 | if (dumpit == NULL) |
Thomas Graf | 038890f | 2007-04-05 14:35:52 -0700 | [diff] [blame] | 1281 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
Patrick McHardy | 1c2d670 | 2007-04-16 16:59:10 -0700 | [diff] [blame] | 1283 | __rtnl_unlock(); |
| 1284 | err = netlink_dump_start(rtnl, skb, nlh, dumpit, NULL); |
| 1285 | rtnl_lock(); |
| 1286 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *))); |
| 1290 | |
| 1291 | min_len = rtm_min[sz_idx]; |
| 1292 | if (nlh->nlmsg_len < min_len) |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1293 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
| 1295 | if (nlh->nlmsg_len > min_len) { |
| 1296 | int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); |
| 1297 | struct rtattr *attr = (void*)nlh + NLMSG_ALIGN(min_len); |
| 1298 | |
| 1299 | while (RTA_OK(attr, attrlen)) { |
| 1300 | unsigned flavor = attr->rta_type; |
| 1301 | if (flavor) { |
| 1302 | if (flavor > rta_max[sz_idx]) |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1303 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | rta_buf[flavor-1] = attr; |
| 1305 | } |
| 1306 | attr = RTA_NEXT(attr, attrlen); |
| 1307 | } |
| 1308 | } |
| 1309 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame] | 1310 | doit = rtnl_get_doit(family, type); |
| 1311 | if (doit == NULL) |
Thomas Graf | 038890f | 2007-04-05 14:35:52 -0700 | [diff] [blame] | 1312 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Thomas Graf | 1d00a4e | 2007-03-22 23:30:12 -0700 | [diff] [blame] | 1314 | return doit(skb, nlh, (void *)&rta_buf[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | static void rtnetlink_rcv(struct sock *sk, int len) |
| 1318 | { |
Thomas Graf | 9ac4a16 | 2005-11-10 02:25:55 +0100 | [diff] [blame] | 1319 | unsigned int qlen = 0; |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 1320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | do { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1322 | mutex_lock(&rtnl_mutex); |
Thomas Graf | 9ac4a16 | 2005-11-10 02:25:55 +0100 | [diff] [blame] | 1323 | netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1324 | mutex_unlock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | netdev_run_todo(); |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 1327 | } while (qlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 1331 | { |
| 1332 | struct net_device *dev = ptr; |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 1333 | |
| 1334 | if (dev->nd_net != &init_net) |
| 1335 | return NOTIFY_DONE; |
| 1336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | switch (event) { |
| 1338 | case NETDEV_UNREGISTER: |
| 1339 | rtmsg_ifinfo(RTM_DELLINK, dev, ~0U); |
| 1340 | break; |
| 1341 | case NETDEV_REGISTER: |
| 1342 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); |
| 1343 | break; |
| 1344 | case NETDEV_UP: |
| 1345 | case NETDEV_DOWN: |
| 1346 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); |
| 1347 | break; |
| 1348 | case NETDEV_CHANGE: |
| 1349 | case NETDEV_GOING_DOWN: |
| 1350 | break; |
| 1351 | default: |
| 1352 | rtmsg_ifinfo(RTM_NEWLINK, dev, 0); |
| 1353 | break; |
| 1354 | } |
| 1355 | return NOTIFY_DONE; |
| 1356 | } |
| 1357 | |
| 1358 | static struct notifier_block rtnetlink_dev_notifier = { |
| 1359 | .notifier_call = rtnetlink_event, |
| 1360 | }; |
| 1361 | |
| 1362 | void __init rtnetlink_init(void) |
| 1363 | { |
| 1364 | int i; |
| 1365 | |
| 1366 | rtattr_max = 0; |
| 1367 | for (i = 0; i < ARRAY_SIZE(rta_max); i++) |
| 1368 | if (rta_max[i] > rtattr_max) |
| 1369 | rtattr_max = rta_max[i]; |
| 1370 | rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL); |
| 1371 | if (!rta_buf) |
| 1372 | panic("rtnetlink_init: cannot allocate rta_buf\n"); |
| 1373 | |
Eric W. Biederman | b4b5102 | 2007-09-12 13:05:38 +0200 | [diff] [blame] | 1374 | rtnl = netlink_kernel_create(&init_net, NETLINK_ROUTE, RTNLGRP_MAX, |
| 1375 | rtnetlink_rcv, &rtnl_mutex, THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | if (rtnl == NULL) |
| 1377 | panic("rtnetlink_init: cannot initialize rtnetlink\n"); |
| 1378 | netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV); |
| 1379 | register_netdevice_notifier(&rtnetlink_dev_notifier); |
Thomas Graf | 340d17f | 2007-03-22 11:49:22 -0700 | [diff] [blame] | 1380 | |
| 1381 | rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink, rtnl_dump_ifinfo); |
| 1382 | rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL); |
Patrick McHardy | 38f7b87 | 2007-06-13 12:03:51 -0700 | [diff] [blame] | 1383 | rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL); |
| 1384 | rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL); |
Thomas Graf | 687ad8c | 2007-03-22 11:59:42 -0700 | [diff] [blame] | 1385 | |
| 1386 | rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all); |
| 1387 | rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | EXPORT_SYMBOL(__rta_fill); |
| 1391 | EXPORT_SYMBOL(rtattr_strlcpy); |
| 1392 | EXPORT_SYMBOL(rtattr_parse); |
Patrick McHardy | 2371baa | 2007-06-26 03:23:44 -0700 | [diff] [blame] | 1393 | EXPORT_SYMBOL(__rtattr_parse_nested_compat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | EXPORT_SYMBOL(rtnetlink_put_metrics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | EXPORT_SYMBOL(rtnl_lock); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1396 | EXPORT_SYMBOL(rtnl_trylock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | EXPORT_SYMBOL(rtnl_unlock); |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 1398 | EXPORT_SYMBOL(rtnl_unicast); |
Thomas Graf | 97676b6 | 2006-08-15 00:31:41 -0700 | [diff] [blame] | 1399 | EXPORT_SYMBOL(rtnl_notify); |
| 1400 | EXPORT_SYMBOL(rtnl_set_sk_err); |
Pavel Emelianov | e719928 | 2007-08-08 22:16:38 -0700 | [diff] [blame] | 1401 | EXPORT_SYMBOL(rtnl_create_link); |
| 1402 | EXPORT_SYMBOL(ifla_policy); |