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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/uaccess.h> |
| 40 | #include <asm/system.h> |
| 41 | #include <asm/string.h> |
| 42 | |
| 43 | #include <linux/inet.h> |
| 44 | #include <linux/netdevice.h> |
| 45 | #include <net/ip.h> |
| 46 | #include <net/protocol.h> |
| 47 | #include <net/arp.h> |
| 48 | #include <net/route.h> |
| 49 | #include <net/udp.h> |
| 50 | #include <net/sock.h> |
| 51 | #include <net/pkt_sched.h> |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 52 | #include <net/fib_rules.h> |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 53 | #include <net/rtnetlink.h> |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 54 | #ifdef CONFIG_NET_WIRELESS_RTNETLINK |
| 55 | #include <linux/wireless.h> |
| 56 | #include <net/iw_handler.h> |
| 57 | #endif /* CONFIG_NET_WIRELESS_RTNETLINK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 59 | struct rtnl_link |
| 60 | { |
| 61 | rtnl_doit_func doit; |
| 62 | rtnl_dumpit_func dumpit; |
| 63 | }; |
| 64 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 65 | static DEFINE_MUTEX(rtnl_mutex); |
Thomas Graf | 56fc85a | 2006-08-15 00:37:29 -0700 | [diff] [blame] | 66 | static struct sock *rtnl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | void rtnl_lock(void) |
| 69 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 70 | mutex_lock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 73 | void __rtnl_unlock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 75 | mutex_unlock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | void rtnl_unlock(void) |
| 79 | { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 80 | mutex_unlock(&rtnl_mutex); |
| 81 | if (rtnl && rtnl->sk_receive_queue.qlen) |
| 82 | rtnl->sk_data_ready(rtnl, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | netdev_run_todo(); |
| 84 | } |
| 85 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 86 | int rtnl_trylock(void) |
| 87 | { |
| 88 | return mutex_trylock(&rtnl_mutex); |
| 89 | } |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len) |
| 92 | { |
| 93 | memset(tb, 0, sizeof(struct rtattr*)*maxattr); |
| 94 | |
| 95 | while (RTA_OK(rta, len)) { |
| 96 | unsigned flavor = rta->rta_type; |
| 97 | if (flavor && flavor <= maxattr) |
| 98 | tb[flavor-1] = rta; |
| 99 | rta = RTA_NEXT(rta, len); |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 104 | struct rtnl_link *rtnl_msg_handlers[NPROTO]; |
| 105 | |
| 106 | static inline int rtm_msgindex(int msgtype) |
| 107 | { |
| 108 | int msgindex = msgtype - RTM_BASE; |
| 109 | |
| 110 | /* |
| 111 | * msgindex < 0 implies someone tried to register a netlink |
| 112 | * control code. msgindex >= RTM_NR_MSGTYPES may indicate that |
| 113 | * the message type has not been added to linux/rtnetlink.h |
| 114 | */ |
| 115 | BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES); |
| 116 | |
| 117 | return msgindex; |
| 118 | } |
| 119 | |
| 120 | static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex) |
| 121 | { |
| 122 | struct rtnl_link *tab; |
| 123 | |
| 124 | tab = rtnl_msg_handlers[protocol]; |
| 125 | if (tab == NULL || tab->doit == NULL) |
| 126 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
| 127 | |
| 128 | return tab ? tab->doit : NULL; |
| 129 | } |
| 130 | |
| 131 | static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex) |
| 132 | { |
| 133 | struct rtnl_link *tab; |
| 134 | |
| 135 | tab = rtnl_msg_handlers[protocol]; |
| 136 | if (tab == NULL || tab->dumpit == NULL) |
| 137 | tab = rtnl_msg_handlers[PF_UNSPEC]; |
| 138 | |
| 139 | return tab ? tab->dumpit : NULL; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * __rtnl_register - Register a rtnetlink message type |
| 144 | * @protocol: Protocol family or PF_UNSPEC |
| 145 | * @msgtype: rtnetlink message type |
| 146 | * @doit: Function pointer called for each request message |
| 147 | * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message |
| 148 | * |
| 149 | * Registers the specified function pointers (at least one of them has |
| 150 | * to be non-NULL) to be called whenever a request message for the |
| 151 | * specified protocol family and message type is received. |
| 152 | * |
| 153 | * The special protocol family PF_UNSPEC may be used to define fallback |
| 154 | * function pointers for the case when no entry for the specific protocol |
| 155 | * family exists. |
| 156 | * |
| 157 | * Returns 0 on success or a negative error code. |
| 158 | */ |
| 159 | int __rtnl_register(int protocol, int msgtype, |
| 160 | rtnl_doit_func doit, rtnl_dumpit_func dumpit) |
| 161 | { |
| 162 | struct rtnl_link *tab; |
| 163 | int msgindex; |
| 164 | |
| 165 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 166 | msgindex = rtm_msgindex(msgtype); |
| 167 | |
| 168 | tab = rtnl_msg_handlers[protocol]; |
| 169 | if (tab == NULL) { |
| 170 | tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL); |
| 171 | if (tab == NULL) |
| 172 | return -ENOBUFS; |
| 173 | |
| 174 | rtnl_msg_handlers[protocol] = tab; |
| 175 | } |
| 176 | |
| 177 | if (doit) |
| 178 | tab[msgindex].doit = doit; |
| 179 | |
| 180 | if (dumpit) |
| 181 | tab[msgindex].dumpit = dumpit; |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | EXPORT_SYMBOL_GPL(__rtnl_register); |
| 187 | |
| 188 | /** |
| 189 | * rtnl_register - Register a rtnetlink message type |
| 190 | * |
| 191 | * Identical to __rtnl_register() but panics on failure. This is useful |
| 192 | * as failure of this function is very unlikely, it can only happen due |
| 193 | * to lack of memory when allocating the chain to store all message |
| 194 | * handlers for a protocol. Meant for use in init functions where lack |
| 195 | * of memory implies no sense in continueing. |
| 196 | */ |
| 197 | void rtnl_register(int protocol, int msgtype, |
| 198 | rtnl_doit_func doit, rtnl_dumpit_func dumpit) |
| 199 | { |
| 200 | if (__rtnl_register(protocol, msgtype, doit, dumpit) < 0) |
| 201 | panic("Unable to register rtnetlink message handler, " |
| 202 | "protocol = %d, message type = %d\n", |
| 203 | protocol, msgtype); |
| 204 | } |
| 205 | |
| 206 | EXPORT_SYMBOL_GPL(rtnl_register); |
| 207 | |
| 208 | /** |
| 209 | * rtnl_unregister - Unregister a rtnetlink message type |
| 210 | * @protocol: Protocol family or PF_UNSPEC |
| 211 | * @msgtype: rtnetlink message type |
| 212 | * |
| 213 | * Returns 0 on success or a negative error code. |
| 214 | */ |
| 215 | int rtnl_unregister(int protocol, int msgtype) |
| 216 | { |
| 217 | int msgindex; |
| 218 | |
| 219 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 220 | msgindex = rtm_msgindex(msgtype); |
| 221 | |
| 222 | if (rtnl_msg_handlers[protocol] == NULL) |
| 223 | return -ENOENT; |
| 224 | |
| 225 | rtnl_msg_handlers[protocol][msgindex].doit = NULL; |
| 226 | rtnl_msg_handlers[protocol][msgindex].dumpit = NULL; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | EXPORT_SYMBOL_GPL(rtnl_unregister); |
| 232 | |
| 233 | /** |
| 234 | * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol |
| 235 | * @protocol : Protocol family or PF_UNSPEC |
| 236 | * |
| 237 | * Identical to calling rtnl_unregster() for all registered message types |
| 238 | * of a certain protocol family. |
| 239 | */ |
| 240 | void rtnl_unregister_all(int protocol) |
| 241 | { |
| 242 | BUG_ON(protocol < 0 || protocol >= NPROTO); |
| 243 | |
| 244 | kfree(rtnl_msg_handlers[protocol]); |
| 245 | rtnl_msg_handlers[protocol] = NULL; |
| 246 | } |
| 247 | |
| 248 | EXPORT_SYMBOL_GPL(rtnl_unregister_all); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Thomas Graf | db46edc | 2005-05-03 14:29:39 -0700 | [diff] [blame] | 250 | static const int rtm_min[RTM_NR_FAMILIES] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 252 | [RTM_FAM(RTM_NEWLINK)] = NLMSG_LENGTH(sizeof(struct ifinfomsg)), |
| 253 | [RTM_FAM(RTM_NEWADDR)] = NLMSG_LENGTH(sizeof(struct ifaddrmsg)), |
| 254 | [RTM_FAM(RTM_NEWROUTE)] = NLMSG_LENGTH(sizeof(struct rtmsg)), |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 255 | [RTM_FAM(RTM_NEWRULE)] = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)), |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 256 | [RTM_FAM(RTM_NEWQDISC)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 257 | [RTM_FAM(RTM_NEWTCLASS)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 258 | [RTM_FAM(RTM_NEWTFILTER)] = NLMSG_LENGTH(sizeof(struct tcmsg)), |
| 259 | [RTM_FAM(RTM_NEWACTION)] = NLMSG_LENGTH(sizeof(struct tcamsg)), |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 260 | [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)), |
| 261 | [RTM_FAM(RTM_GETANYCAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
Thomas Graf | db46edc | 2005-05-03 14:29:39 -0700 | [diff] [blame] | 264 | static const int rta_max[RTM_NR_FAMILIES] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 266 | [RTM_FAM(RTM_NEWLINK)] = IFLA_MAX, |
| 267 | [RTM_FAM(RTM_NEWADDR)] = IFA_MAX, |
| 268 | [RTM_FAM(RTM_NEWROUTE)] = RTA_MAX, |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 269 | [RTM_FAM(RTM_NEWRULE)] = FRA_MAX, |
Thomas Graf | f90a0a7 | 2005-05-03 14:29:00 -0700 | [diff] [blame] | 270 | [RTM_FAM(RTM_NEWQDISC)] = TCA_MAX, |
| 271 | [RTM_FAM(RTM_NEWTCLASS)] = TCA_MAX, |
| 272 | [RTM_FAM(RTM_NEWTFILTER)] = TCA_MAX, |
| 273 | [RTM_FAM(RTM_NEWACTION)] = TCAA_MAX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data) |
| 277 | { |
| 278 | struct rtattr *rta; |
| 279 | int size = RTA_LENGTH(attrlen); |
| 280 | |
| 281 | rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size)); |
| 282 | rta->rta_type = attrtype; |
| 283 | rta->rta_len = size; |
| 284 | memcpy(RTA_DATA(rta), data, attrlen); |
Patrick McHardy | b3563c4 | 2005-06-28 12:54:43 -0700 | [diff] [blame] | 285 | memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size) |
| 289 | { |
| 290 | size_t ret = RTA_PAYLOAD(rta); |
| 291 | char *src = RTA_DATA(rta); |
| 292 | |
| 293 | if (ret > 0 && src[ret - 1] == '\0') |
| 294 | ret--; |
| 295 | if (size > 0) { |
| 296 | size_t len = (ret >= size) ? size - 1 : ret; |
| 297 | memset(dest, 0, size); |
| 298 | memcpy(dest, src, len); |
| 299 | } |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | int rtnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo) |
| 304 | { |
| 305 | int err = 0; |
| 306 | |
Patrick McHardy | ac6d439 | 2005-08-14 19:29:52 -0700 | [diff] [blame] | 307 | NETLINK_CB(skb).dst_group = group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (echo) |
| 309 | atomic_inc(&skb->users); |
| 310 | netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL); |
| 311 | if (echo) |
| 312 | err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT); |
| 313 | return err; |
| 314 | } |
| 315 | |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 316 | int rtnl_unicast(struct sk_buff *skb, u32 pid) |
| 317 | { |
| 318 | return nlmsg_unicast(rtnl, skb, pid); |
| 319 | } |
| 320 | |
Thomas Graf | 97676b6 | 2006-08-15 00:31:41 -0700 | [diff] [blame] | 321 | int rtnl_notify(struct sk_buff *skb, u32 pid, u32 group, |
| 322 | struct nlmsghdr *nlh, gfp_t flags) |
| 323 | { |
| 324 | int report = 0; |
| 325 | |
| 326 | if (nlh) |
| 327 | report = nlmsg_report(nlh); |
| 328 | |
| 329 | return nlmsg_notify(rtnl, skb, pid, group, report, flags); |
| 330 | } |
| 331 | |
| 332 | void rtnl_set_sk_err(u32 group, int error) |
| 333 | { |
| 334 | netlink_set_err(rtnl, 0, group, error); |
| 335 | } |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics) |
| 338 | { |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 339 | struct nlattr *mx; |
| 340 | int i, valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 342 | mx = nla_nest_start(skb, RTA_METRICS); |
| 343 | if (mx == NULL) |
| 344 | return -ENOBUFS; |
| 345 | |
| 346 | for (i = 0; i < RTAX_MAX; i++) { |
| 347 | if (metrics[i]) { |
| 348 | valid++; |
| 349 | NLA_PUT_U32(skb, i+1, metrics[i]); |
| 350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
David S. Miller | a57d27f | 2006-08-22 22:20:14 -0700 | [diff] [blame] | 353 | if (!valid) { |
| 354 | nla_nest_cancel(skb, mx); |
| 355 | return 0; |
| 356 | } |
Thomas Graf | 2d7202b | 2006-08-22 00:01:27 -0700 | [diff] [blame] | 357 | |
| 358 | return nla_nest_end(skb, mx); |
| 359 | |
| 360 | nla_put_failure: |
| 361 | return nla_nest_cancel(skb, mx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Thomas Graf | e3703b3 | 2006-11-27 09:27:07 -0800 | [diff] [blame] | 364 | int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id, |
| 365 | u32 ts, u32 tsage, long expires, u32 error) |
| 366 | { |
| 367 | struct rta_cacheinfo ci = { |
| 368 | .rta_lastuse = jiffies_to_clock_t(jiffies - dst->lastuse), |
| 369 | .rta_used = dst->__use, |
| 370 | .rta_clntref = atomic_read(&(dst->__refcnt)), |
| 371 | .rta_error = error, |
| 372 | .rta_id = id, |
| 373 | .rta_ts = ts, |
| 374 | .rta_tsage = tsage, |
| 375 | }; |
| 376 | |
| 377 | if (expires) |
| 378 | ci.rta_expires = jiffies_to_clock_t(expires); |
| 379 | |
| 380 | return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci); |
| 381 | } |
| 382 | |
| 383 | EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 385 | static void set_operstate(struct net_device *dev, unsigned char transition) |
| 386 | { |
| 387 | unsigned char operstate = dev->operstate; |
| 388 | |
| 389 | switch(transition) { |
| 390 | case IF_OPER_UP: |
| 391 | if ((operstate == IF_OPER_DORMANT || |
| 392 | operstate == IF_OPER_UNKNOWN) && |
| 393 | !netif_dormant(dev)) |
| 394 | operstate = IF_OPER_UP; |
| 395 | break; |
| 396 | |
| 397 | case IF_OPER_DORMANT: |
| 398 | if (operstate == IF_OPER_UP || |
| 399 | operstate == IF_OPER_UNKNOWN) |
| 400 | operstate = IF_OPER_DORMANT; |
| 401 | break; |
| 402 | }; |
| 403 | |
| 404 | if (dev->operstate != operstate) { |
| 405 | write_lock_bh(&dev_base_lock); |
| 406 | dev->operstate = operstate; |
| 407 | write_unlock_bh(&dev_base_lock); |
| 408 | netdev_state_change(dev); |
| 409 | } |
| 410 | } |
| 411 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 412 | static void copy_rtnl_link_stats(struct rtnl_link_stats *a, |
| 413 | struct net_device_stats *b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 415 | a->rx_packets = b->rx_packets; |
| 416 | a->tx_packets = b->tx_packets; |
| 417 | a->rx_bytes = b->rx_bytes; |
| 418 | a->tx_bytes = b->tx_bytes; |
| 419 | a->rx_errors = b->rx_errors; |
| 420 | a->tx_errors = b->tx_errors; |
| 421 | a->rx_dropped = b->rx_dropped; |
| 422 | a->tx_dropped = b->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 424 | a->multicast = b->multicast; |
| 425 | a->collisions = b->collisions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 427 | a->rx_length_errors = b->rx_length_errors; |
| 428 | a->rx_over_errors = b->rx_over_errors; |
| 429 | a->rx_crc_errors = b->rx_crc_errors; |
| 430 | a->rx_frame_errors = b->rx_frame_errors; |
| 431 | a->rx_fifo_errors = b->rx_fifo_errors; |
| 432 | a->rx_missed_errors = b->rx_missed_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 434 | a->tx_aborted_errors = b->tx_aborted_errors; |
| 435 | a->tx_carrier_errors = b->tx_carrier_errors; |
| 436 | a->tx_fifo_errors = b->tx_fifo_errors; |
| 437 | a->tx_heartbeat_errors = b->tx_heartbeat_errors; |
| 438 | a->tx_window_errors = b->tx_window_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 440 | a->rx_compressed = b->rx_compressed; |
| 441 | a->tx_compressed = b->tx_compressed; |
| 442 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 444 | static inline size_t if_nlmsg_size(int iwbuflen) |
| 445 | { |
| 446 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
| 447 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 448 | + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */ |
| 449 | + nla_total_size(sizeof(struct rtnl_link_ifmap)) |
| 450 | + nla_total_size(sizeof(struct rtnl_link_stats)) |
| 451 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 452 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */ |
| 453 | + nla_total_size(4) /* IFLA_TXQLEN */ |
| 454 | + nla_total_size(4) /* IFLA_WEIGHT */ |
| 455 | + nla_total_size(4) /* IFLA_MTU */ |
| 456 | + nla_total_size(4) /* IFLA_LINK */ |
| 457 | + nla_total_size(4) /* IFLA_MASTER */ |
| 458 | + nla_total_size(1) /* IFLA_OPERSTATE */ |
| 459 | + nla_total_size(1) /* IFLA_LINKMODE */ |
| 460 | + nla_total_size(iwbuflen); |
| 461 | } |
| 462 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 463 | static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, |
| 464 | void *iwbuf, int iwbuflen, int type, u32 pid, |
| 465 | u32 seq, u32 change, unsigned int flags) |
| 466 | { |
| 467 | struct ifinfomsg *ifm; |
| 468 | struct nlmsghdr *nlh; |
| 469 | |
| 470 | nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags); |
| 471 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 472 | return -EMSGSIZE; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 473 | |
| 474 | ifm = nlmsg_data(nlh); |
| 475 | ifm->ifi_family = AF_UNSPEC; |
| 476 | ifm->__ifi_pad = 0; |
| 477 | ifm->ifi_type = dev->type; |
| 478 | ifm->ifi_index = dev->ifindex; |
| 479 | ifm->ifi_flags = dev_get_flags(dev); |
| 480 | ifm->ifi_change = change; |
| 481 | |
| 482 | NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); |
| 483 | NLA_PUT_U32(skb, IFLA_TXQLEN, dev->tx_queue_len); |
| 484 | NLA_PUT_U32(skb, IFLA_WEIGHT, dev->weight); |
| 485 | NLA_PUT_U8(skb, IFLA_OPERSTATE, |
| 486 | netif_running(dev) ? dev->operstate : IF_OPER_DOWN); |
| 487 | NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode); |
| 488 | NLA_PUT_U32(skb, IFLA_MTU, dev->mtu); |
| 489 | |
| 490 | if (dev->ifindex != dev->iflink) |
| 491 | NLA_PUT_U32(skb, IFLA_LINK, dev->iflink); |
| 492 | |
| 493 | if (dev->master) |
| 494 | NLA_PUT_U32(skb, IFLA_MASTER, dev->master->ifindex); |
| 495 | |
| 496 | if (dev->qdisc_sleeping) |
| 497 | NLA_PUT_STRING(skb, IFLA_QDISC, dev->qdisc_sleeping->ops->id); |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 498 | |
| 499 | if (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | struct rtnl_link_ifmap map = { |
| 501 | .mem_start = dev->mem_start, |
| 502 | .mem_end = dev->mem_end, |
| 503 | .base_addr = dev->base_addr, |
| 504 | .irq = dev->irq, |
| 505 | .dma = dev->dma, |
| 506 | .port = dev->if_port, |
| 507 | }; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 508 | NLA_PUT(skb, IFLA_MAP, sizeof(map), &map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | if (dev->addr_len) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 512 | NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr); |
| 513 | NLA_PUT(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if (dev->get_stats) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 517 | struct net_device_stats *stats = dev->get_stats(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (stats) { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 519 | struct nlattr *attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 521 | attr = nla_reserve(skb, IFLA_STATS, |
| 522 | sizeof(struct rtnl_link_stats)); |
| 523 | if (attr == NULL) |
| 524 | goto nla_put_failure; |
| 525 | |
| 526 | copy_rtnl_link_stats(nla_data(attr), stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 530 | if (iwbuf) |
| 531 | NLA_PUT(skb, IFLA_WIRELESS, iwbuflen, iwbuf); |
| 532 | |
| 533 | return nlmsg_end(skb, nlh); |
| 534 | |
| 535 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 536 | nlmsg_cancel(skb, nlh); |
| 537 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 540 | 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] | 541 | { |
| 542 | int idx; |
| 543 | int s_idx = cb->args[0]; |
| 544 | struct net_device *dev; |
| 545 | |
| 546 | read_lock(&dev_base_lock); |
| 547 | for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) { |
| 548 | if (idx < s_idx) |
| 549 | continue; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 550 | if (rtnl_fill_ifinfo(skb, dev, NULL, 0, RTM_NEWLINK, |
| 551 | NETLINK_CB(cb->skb).pid, |
| 552 | cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | break; |
| 554 | } |
| 555 | read_unlock(&dev_base_lock); |
| 556 | cb->args[0] = idx; |
| 557 | |
| 558 | return skb->len; |
| 559 | } |
| 560 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 561 | static struct nla_policy ifla_policy[IFLA_MAX+1] __read_mostly = { |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 562 | [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 }, |
| 563 | [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) }, |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 564 | [IFLA_MTU] = { .type = NLA_U32 }, |
| 565 | [IFLA_TXQLEN] = { .type = NLA_U32 }, |
| 566 | [IFLA_WEIGHT] = { .type = NLA_U32 }, |
| 567 | [IFLA_OPERSTATE] = { .type = NLA_U8 }, |
| 568 | [IFLA_LINKMODE] = { .type = NLA_U8 }, |
| 569 | }; |
| 570 | |
| 571 | 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] | 572 | { |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 573 | struct ifinfomsg *ifm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | struct net_device *dev; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 575 | int err, send_addr_notify = 0, modified = 0; |
| 576 | struct nlattr *tb[IFLA_MAX+1]; |
| 577 | char ifname[IFNAMSIZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 579 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 580 | if (err < 0) |
| 581 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 583 | if (tb[IFLA_IFNAME]) |
| 584 | nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ); |
Patrick McHardy | 78e5b891 | 2006-09-13 20:35:36 -0700 | [diff] [blame] | 585 | else |
| 586 | ifname[0] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | err = -EINVAL; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 589 | ifm = nlmsg_data(nlh); |
| 590 | if (ifm->ifi_index >= 0) |
| 591 | dev = dev_get_by_index(ifm->ifi_index); |
| 592 | else if (tb[IFLA_IFNAME]) |
| 593 | dev = dev_get_by_name(ifname); |
| 594 | else |
| 595 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 597 | if (dev == NULL) { |
| 598 | err = -ENODEV; |
| 599 | goto errout; |
| 600 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 602 | if (tb[IFLA_ADDRESS] && |
| 603 | nla_len(tb[IFLA_ADDRESS]) < dev->addr_len) |
| 604 | goto errout_dev; |
| 605 | |
| 606 | if (tb[IFLA_BROADCAST] && |
| 607 | nla_len(tb[IFLA_BROADCAST]) < dev->addr_len) |
| 608 | goto errout_dev; |
| 609 | |
| 610 | if (tb[IFLA_MAP]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | struct rtnl_link_ifmap *u_map; |
| 612 | struct ifmap k_map; |
| 613 | |
| 614 | if (!dev->set_config) { |
| 615 | err = -EOPNOTSUPP; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 616 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (!netif_device_present(dev)) { |
| 620 | err = -ENODEV; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 621 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 624 | u_map = nla_data(tb[IFLA_MAP]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | k_map.mem_start = (unsigned long) u_map->mem_start; |
| 626 | k_map.mem_end = (unsigned long) u_map->mem_end; |
| 627 | k_map.base_addr = (unsigned short) u_map->base_addr; |
| 628 | k_map.irq = (unsigned char) u_map->irq; |
| 629 | k_map.dma = (unsigned char) u_map->dma; |
| 630 | k_map.port = (unsigned char) u_map->port; |
| 631 | |
| 632 | err = dev->set_config(dev, &k_map); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 633 | if (err < 0) |
| 634 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 636 | modified = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 639 | if (tb[IFLA_ADDRESS]) { |
David S. Miller | 70f8e78 | 2006-08-08 16:47:37 -0700 | [diff] [blame] | 640 | struct sockaddr *sa; |
| 641 | int len; |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | if (!dev->set_mac_address) { |
| 644 | err = -EOPNOTSUPP; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 645 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (!netif_device_present(dev)) { |
| 649 | err = -ENODEV; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 650 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
David S. Miller | 70f8e78 | 2006-08-08 16:47:37 -0700 | [diff] [blame] | 653 | len = sizeof(sa_family_t) + dev->addr_len; |
| 654 | sa = kmalloc(len, GFP_KERNEL); |
| 655 | if (!sa) { |
| 656 | err = -ENOMEM; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 657 | goto errout_dev; |
David S. Miller | 70f8e78 | 2006-08-08 16:47:37 -0700 | [diff] [blame] | 658 | } |
| 659 | sa->sa_family = dev->type; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 660 | memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]), |
David S. Miller | 70f8e78 | 2006-08-08 16:47:37 -0700 | [diff] [blame] | 661 | dev->addr_len); |
| 662 | err = dev->set_mac_address(dev, sa); |
| 663 | kfree(sa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | if (err) |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 665 | goto errout_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | send_addr_notify = 1; |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 667 | modified = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 670 | if (tb[IFLA_MTU]) { |
| 671 | err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU])); |
| 672 | if (err < 0) |
| 673 | goto errout_dev; |
| 674 | modified = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 677 | /* |
| 678 | * Interface selected by interface index but interface |
| 679 | * name provided implies that a name change has been |
| 680 | * requested. |
| 681 | */ |
| 682 | if (ifm->ifi_index >= 0 && ifname[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | err = dev_change_name(dev, ifname); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 684 | if (err < 0) |
| 685 | goto errout_dev; |
| 686 | modified = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 689 | #ifdef CONFIG_NET_WIRELESS_RTNETLINK |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 690 | if (tb[IFLA_WIRELESS]) { |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 691 | /* Call Wireless Extensions. |
| 692 | * Various stuff checked in there... */ |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 693 | err = wireless_rtnetlink_set(dev, nla_data(tb[IFLA_WIRELESS]), |
| 694 | nla_len(tb[IFLA_WIRELESS])); |
| 695 | if (err < 0) |
| 696 | goto errout_dev; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 697 | } |
| 698 | #endif /* CONFIG_NET_WIRELESS_RTNETLINK */ |
| 699 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 700 | if (tb[IFLA_BROADCAST]) { |
| 701 | nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len); |
| 702 | send_addr_notify = 1; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | if (ifm->ifi_flags) |
| 707 | dev_change_flags(dev, ifm->ifi_flags); |
| 708 | |
| 709 | if (tb[IFLA_TXQLEN]) |
| 710 | dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]); |
| 711 | |
| 712 | if (tb[IFLA_WEIGHT]) |
| 713 | dev->weight = nla_get_u32(tb[IFLA_WEIGHT]); |
| 714 | |
| 715 | if (tb[IFLA_OPERSTATE]) |
| 716 | set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE])); |
| 717 | |
| 718 | if (tb[IFLA_LINKMODE]) { |
| 719 | write_lock_bh(&dev_base_lock); |
| 720 | dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); |
| 721 | write_unlock_bh(&dev_base_lock); |
| 722 | } |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | err = 0; |
| 725 | |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 726 | errout_dev: |
| 727 | if (err < 0 && modified && net_ratelimit()) |
| 728 | printk(KERN_WARNING "A link change request failed with " |
| 729 | "some changes comitted already. Interface %s may " |
| 730 | "have been left with an inconsistent configuration, " |
| 731 | "please check.\n", dev->name); |
| 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | if (send_addr_notify) |
| 734 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); |
| 735 | |
| 736 | dev_put(dev); |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 737 | errout: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return err; |
| 739 | } |
| 740 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 741 | 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] | 742 | { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 743 | struct ifinfomsg *ifm; |
| 744 | struct nlattr *tb[IFLA_MAX+1]; |
| 745 | struct net_device *dev = NULL; |
| 746 | struct sk_buff *nskb; |
| 747 | char *iw_buf = NULL, *iw = NULL; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 748 | int iw_buf_len = 0; |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 749 | int err; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 750 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 751 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy); |
| 752 | if (err < 0) |
Eric Sesterhenn | 9918f23 | 2006-09-26 23:26:38 -0700 | [diff] [blame] | 753 | return err; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 754 | |
| 755 | ifm = nlmsg_data(nlh); |
| 756 | if (ifm->ifi_index >= 0) { |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 757 | dev = dev_get_by_index(ifm->ifi_index); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 758 | if (dev == NULL) |
| 759 | return -ENODEV; |
| 760 | } else |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 761 | return -EINVAL; |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 762 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 763 | |
| 764 | #ifdef CONFIG_NET_WIRELESS_RTNETLINK |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 765 | if (tb[IFLA_WIRELESS]) { |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 766 | /* Call Wireless Extensions. We need to know the size before |
| 767 | * we can alloc. Various stuff checked in there... */ |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 768 | err = wireless_rtnetlink_get(dev, nla_data(tb[IFLA_WIRELESS]), |
| 769 | nla_len(tb[IFLA_WIRELESS]), |
| 770 | &iw_buf, &iw_buf_len); |
| 771 | if (err < 0) |
| 772 | goto errout; |
| 773 | |
Jean Tourrilhes | c2805fb | 2007-03-23 00:31:16 +0000 | [diff] [blame] | 774 | /* Payload is at an offset in buffer */ |
| 775 | iw = iw_buf + IW_EV_POINT_OFF; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 776 | } |
| 777 | #endif /* CONFIG_NET_WIRELESS_RTNETLINK */ |
| 778 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 779 | nskb = nlmsg_new(if_nlmsg_size(iw_buf_len), GFP_KERNEL); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 780 | if (nskb == NULL) { |
| 781 | err = -ENOBUFS; |
| 782 | goto errout; |
| 783 | } |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 784 | |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 785 | err = rtnl_fill_ifinfo(nskb, dev, iw, iw_buf_len, RTM_NEWLINK, |
| 786 | NETLINK_CB(skb).pid, nlh->nlmsg_seq, 0, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 787 | if (err < 0) { |
| 788 | /* -EMSGSIZE implies BUG in if_nlmsg_size */ |
| 789 | WARN_ON(err == -EMSGSIZE); |
| 790 | kfree_skb(nskb); |
| 791 | goto errout; |
| 792 | } |
Patrick McHardy | b974179 | 2006-10-12 01:50:30 -0700 | [diff] [blame] | 793 | err = rtnl_unicast(nskb, NETLINK_CB(skb).pid); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 794 | errout: |
| 795 | kfree(iw_buf); |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 796 | dev_put(dev); |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 797 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 798 | return err; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 799 | } |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 800 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 801 | int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
| 803 | int idx; |
| 804 | int s_idx = cb->family; |
| 805 | |
| 806 | if (s_idx == 0) |
| 807 | s_idx = 1; |
| 808 | for (idx=1; idx<NPROTO; idx++) { |
| 809 | int type = cb->nlh->nlmsg_type-RTM_BASE; |
| 810 | if (idx < s_idx || idx == PF_PACKET) |
| 811 | continue; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 812 | if (rtnl_msg_handlers[idx] == NULL || |
| 813 | rtnl_msg_handlers[idx][type].dumpit == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | continue; |
| 815 | if (idx > s_idx) |
| 816 | memset(&cb->args[0], 0, sizeof(cb->args)); |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 817 | if (rtnl_msg_handlers[idx][type].dumpit(skb, cb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | break; |
| 819 | } |
| 820 | cb->family = idx; |
| 821 | |
| 822 | return skb->len; |
| 823 | } |
| 824 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 825 | EXPORT_SYMBOL_GPL(rtnl_dump_all); |
| 826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change) |
| 828 | { |
| 829 | struct sk_buff *skb; |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 830 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 832 | skb = nlmsg_new(if_nlmsg_size(0), GFP_KERNEL); |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 833 | if (skb == NULL) |
| 834 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 836 | err = rtnl_fill_ifinfo(skb, dev, NULL, 0, type, 0, 0, change, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 837 | if (err < 0) { |
| 838 | /* -EMSGSIZE implies BUG in if_nlmsg_size() */ |
| 839 | WARN_ON(err == -EMSGSIZE); |
| 840 | kfree_skb(skb); |
| 841 | goto errout; |
| 842 | } |
Thomas Graf | 0ec6d3f | 2006-08-15 00:37:09 -0700 | [diff] [blame] | 843 | err = rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_KERNEL); |
| 844 | errout: |
| 845 | if (err < 0) |
| 846 | rtnl_set_sk_err(RTNLGRP_LINK, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | /* Protected by RTNL sempahore. */ |
| 850 | static struct rtattr **rta_buf; |
| 851 | static int rtattr_max; |
| 852 | |
| 853 | /* Process one rtnetlink message. */ |
| 854 | |
| 855 | static __inline__ int |
| 856 | rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) |
| 857 | { |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 858 | rtnl_doit_func doit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | int sz_idx, kind; |
| 860 | int min_len; |
| 861 | int family; |
| 862 | int type; |
| 863 | int err; |
| 864 | |
| 865 | /* Only requests are handled by kernel now */ |
| 866 | if (!(nlh->nlmsg_flags&NLM_F_REQUEST)) |
| 867 | return 0; |
| 868 | |
| 869 | type = nlh->nlmsg_type; |
| 870 | |
| 871 | /* A control message: ignore them */ |
| 872 | if (type < RTM_BASE) |
| 873 | return 0; |
| 874 | |
| 875 | /* Unknown message: reply with EINVAL */ |
| 876 | if (type > RTM_MAX) |
| 877 | goto err_inval; |
| 878 | |
| 879 | type -= RTM_BASE; |
| 880 | |
| 881 | /* All the messages must have at least 1 byte length */ |
| 882 | if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg))) |
| 883 | return 0; |
| 884 | |
| 885 | family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family; |
| 886 | if (family >= NPROTO) { |
| 887 | *errp = -EAFNOSUPPORT; |
| 888 | return -1; |
| 889 | } |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | sz_idx = type>>2; |
| 892 | kind = type&3; |
| 893 | |
Darrel Goeddel | c7bdb54 | 2006-06-27 13:26:11 -0700 | [diff] [blame] | 894 | if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | *errp = -EPERM; |
| 896 | return -1; |
| 897 | } |
| 898 | |
| 899 | if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 900 | rtnl_dumpit_func dumpit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 902 | dumpit = rtnl_get_dumpit(family, type); |
| 903 | if (dumpit == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | goto err_inval; |
| 905 | |
| 906 | if ((*errp = netlink_dump_start(rtnl, skb, nlh, |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 907 | dumpit, NULL)) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return -1; |
| 909 | } |
Thomas Graf | 9ac4a16 | 2005-11-10 02:25:55 +0100 | [diff] [blame] | 910 | |
| 911 | netlink_queue_skip(nlh, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | return -1; |
| 913 | } |
| 914 | |
| 915 | memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *))); |
| 916 | |
| 917 | min_len = rtm_min[sz_idx]; |
| 918 | if (nlh->nlmsg_len < min_len) |
| 919 | goto err_inval; |
| 920 | |
| 921 | if (nlh->nlmsg_len > min_len) { |
| 922 | int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); |
| 923 | struct rtattr *attr = (void*)nlh + NLMSG_ALIGN(min_len); |
| 924 | |
| 925 | while (RTA_OK(attr, attrlen)) { |
| 926 | unsigned flavor = attr->rta_type; |
| 927 | if (flavor) { |
| 928 | if (flavor > rta_max[sz_idx]) |
| 929 | goto err_inval; |
| 930 | rta_buf[flavor-1] = attr; |
| 931 | } |
| 932 | attr = RTA_NEXT(attr, attrlen); |
| 933 | } |
| 934 | } |
| 935 | |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 936 | doit = rtnl_get_doit(family, type); |
| 937 | if (doit == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | goto err_inval; |
Thomas Graf | e284986 | 2007-03-22 11:48:11 -0700 | [diff] [blame^] | 939 | err = doit(skb, nlh, (void *)&rta_buf[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | *errp = err; |
| 942 | return err; |
| 943 | |
| 944 | err_inval: |
| 945 | *errp = -EINVAL; |
| 946 | return -1; |
| 947 | } |
| 948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | static void rtnetlink_rcv(struct sock *sk, int len) |
| 950 | { |
Thomas Graf | 9ac4a16 | 2005-11-10 02:25:55 +0100 | [diff] [blame] | 951 | unsigned int qlen = 0; |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | do { |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 954 | mutex_lock(&rtnl_mutex); |
Thomas Graf | 9ac4a16 | 2005-11-10 02:25:55 +0100 | [diff] [blame] | 955 | netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 956 | mutex_unlock(&rtnl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
| 958 | netdev_run_todo(); |
Herbert Xu | 2a0a6eb | 2005-05-03 14:55:09 -0700 | [diff] [blame] | 959 | } while (qlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Thomas Graf | db46edc | 2005-05-03 14:29:39 -0700 | [diff] [blame] | 962 | static struct rtnetlink_link link_rtnetlink_table[RTM_NR_MSGTYPES] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 964 | [RTM_GETLINK - RTM_BASE] = { .doit = rtnl_getlink, |
| 965 | .dumpit = rtnl_dump_ifinfo }, |
Thomas Graf | da5e049 | 2006-08-10 21:17:37 -0700 | [diff] [blame] | 966 | [RTM_SETLINK - RTM_BASE] = { .doit = rtnl_setlink }, |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 967 | [RTM_GETADDR - RTM_BASE] = { .dumpit = rtnl_dump_all }, |
| 968 | [RTM_GETROUTE - RTM_BASE] = { .dumpit = rtnl_dump_all }, |
Thomas Graf | c7fb64d | 2005-06-18 22:50:55 -0700 | [diff] [blame] | 969 | [RTM_NEWNEIGH - RTM_BASE] = { .doit = neigh_add }, |
| 970 | [RTM_DELNEIGH - RTM_BASE] = { .doit = neigh_delete }, |
| 971 | [RTM_GETNEIGH - RTM_BASE] = { .dumpit = neigh_dump_info }, |
Thomas Graf | 14c0b97 | 2006-08-04 03:38:38 -0700 | [diff] [blame] | 972 | #ifdef CONFIG_FIB_RULES |
| 973 | [RTM_NEWRULE - RTM_BASE] = { .doit = fib_nl_newrule }, |
| 974 | [RTM_DELRULE - RTM_BASE] = { .doit = fib_nl_delrule }, |
| 975 | #endif |
Thomas Graf | b60c511 | 2006-08-04 23:05:34 -0700 | [diff] [blame] | 976 | [RTM_GETRULE - RTM_BASE] = { .dumpit = rtnl_dump_all }, |
Thomas Graf | c7fb64d | 2005-06-18 22:50:55 -0700 | [diff] [blame] | 977 | [RTM_GETNEIGHTBL - RTM_BASE] = { .dumpit = neightbl_dump_info }, |
| 978 | [RTM_SETNEIGHTBL - RTM_BASE] = { .doit = neightbl_set }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | }; |
| 980 | |
| 981 | static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 982 | { |
| 983 | struct net_device *dev = ptr; |
| 984 | switch (event) { |
| 985 | case NETDEV_UNREGISTER: |
| 986 | rtmsg_ifinfo(RTM_DELLINK, dev, ~0U); |
| 987 | break; |
| 988 | case NETDEV_REGISTER: |
| 989 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); |
| 990 | break; |
| 991 | case NETDEV_UP: |
| 992 | case NETDEV_DOWN: |
| 993 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); |
| 994 | break; |
| 995 | case NETDEV_CHANGE: |
| 996 | case NETDEV_GOING_DOWN: |
| 997 | break; |
| 998 | default: |
| 999 | rtmsg_ifinfo(RTM_NEWLINK, dev, 0); |
| 1000 | break; |
| 1001 | } |
| 1002 | return NOTIFY_DONE; |
| 1003 | } |
| 1004 | |
| 1005 | static struct notifier_block rtnetlink_dev_notifier = { |
| 1006 | .notifier_call = rtnetlink_event, |
| 1007 | }; |
| 1008 | |
| 1009 | void __init rtnetlink_init(void) |
| 1010 | { |
| 1011 | int i; |
| 1012 | |
| 1013 | rtattr_max = 0; |
| 1014 | for (i = 0; i < ARRAY_SIZE(rta_max); i++) |
| 1015 | if (rta_max[i] > rtattr_max) |
| 1016 | rtattr_max = rta_max[i]; |
| 1017 | rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL); |
| 1018 | if (!rta_buf) |
| 1019 | panic("rtnetlink_init: cannot allocate rta_buf\n"); |
| 1020 | |
Patrick McHardy | 0662860 | 2005-08-15 12:33:26 -0700 | [diff] [blame] | 1021 | rtnl = netlink_kernel_create(NETLINK_ROUTE, RTNLGRP_MAX, rtnetlink_rcv, |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1022 | THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (rtnl == NULL) |
| 1024 | panic("rtnetlink_init: cannot initialize rtnetlink\n"); |
| 1025 | netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV); |
| 1026 | register_netdevice_notifier(&rtnetlink_dev_notifier); |
| 1027 | rtnetlink_links[PF_UNSPEC] = link_rtnetlink_table; |
| 1028 | rtnetlink_links[PF_PACKET] = link_rtnetlink_table; |
| 1029 | } |
| 1030 | |
| 1031 | EXPORT_SYMBOL(__rta_fill); |
| 1032 | EXPORT_SYMBOL(rtattr_strlcpy); |
| 1033 | EXPORT_SYMBOL(rtattr_parse); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | EXPORT_SYMBOL(rtnetlink_put_metrics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | EXPORT_SYMBOL(rtnl_lock); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1036 | EXPORT_SYMBOL(rtnl_trylock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | EXPORT_SYMBOL(rtnl_unlock); |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 1038 | EXPORT_SYMBOL(rtnl_unicast); |
Thomas Graf | 97676b6 | 2006-08-15 00:31:41 -0700 | [diff] [blame] | 1039 | EXPORT_SYMBOL(rtnl_notify); |
| 1040 | EXPORT_SYMBOL(rtnl_set_sk_err); |