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