Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * NET3 IP device support routines. |
| 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Derived from the IP parts of dev.c 1.0.19 |
Jesper Juhl | 02c30a8 | 2005-05-05 16:16:16 -0700 | [diff] [blame] | 10 | * Authors: Ross Biro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
| 12 | * Mark Evans, <evansmp@uhura.aston.ac.uk> |
| 13 | * |
| 14 | * Additional Authors: |
| 15 | * Alan Cox, <gw4pts@gw4pts.ampr.org> |
| 16 | * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 17 | * |
| 18 | * Changes: |
| 19 | * Alexey Kuznetsov: pa_* fields are replaced with ifaddr |
| 20 | * lists. |
| 21 | * Cyrus Durgin: updated for kmod |
| 22 | * Matthias Andree: in devinet_ioctl, compare label and |
| 23 | * address (4.4BSD alias style support), |
| 24 | * fall back to comparing just the label |
| 25 | * if no match found. |
| 26 | */ |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | #include <asm/uaccess.h> |
| 30 | #include <asm/system.h> |
| 31 | #include <linux/bitops.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 32 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/types.h> |
| 35 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/string.h> |
| 37 | #include <linux/mm.h> |
| 38 | #include <linux/socket.h> |
| 39 | #include <linux/sockios.h> |
| 40 | #include <linux/in.h> |
| 41 | #include <linux/errno.h> |
| 42 | #include <linux/interrupt.h> |
Thomas Graf | 1823730 | 2006-08-04 23:04:54 -0700 | [diff] [blame] | 43 | #include <linux/if_addr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/if_ether.h> |
| 45 | #include <linux/inet.h> |
| 46 | #include <linux/netdevice.h> |
| 47 | #include <linux/etherdevice.h> |
| 48 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/init.h> |
| 50 | #include <linux/notifier.h> |
| 51 | #include <linux/inetdevice.h> |
| 52 | #include <linux/igmp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 53 | #include <linux/slab.h> |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 54 | #include <linux/hash.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_SYSCTL |
| 56 | #include <linux/sysctl.h> |
| 57 | #endif |
| 58 | #include <linux/kmod.h> |
| 59 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 60 | #include <net/arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <net/ip.h> |
| 62 | #include <net/route.h> |
| 63 | #include <net/ip_fib.h> |
Thomas Graf | 63f3444 | 2007-03-22 11:55:17 -0700 | [diff] [blame] | 64 | #include <net/rtnetlink.h> |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 65 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Adrian Bunk | 0027ba8 | 2008-01-31 17:17:31 -0800 | [diff] [blame] | 67 | static struct ipv4_devconf ipv4_devconf = { |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 68 | .data = { |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 69 | [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1, |
| 70 | [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1, |
| 71 | [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1, |
| 72 | [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1, |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 73 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static struct ipv4_devconf ipv4_devconf_dflt = { |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 77 | .data = { |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 78 | [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1, |
| 79 | [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1, |
| 80 | [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1, |
| 81 | [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1, |
| 82 | [IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE - 1] = 1, |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 83 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Pavel Emelyanov | 9355bbd | 2007-12-16 13:32:16 -0800 | [diff] [blame] | 86 | #define IPV4_DEVCONF_DFLT(net, attr) \ |
| 87 | IPV4_DEVCONF((*net->ipv4.devconf_dflt), attr) |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 88 | |
Patrick McHardy | ef7c79e | 2007-06-05 12:38:30 -0700 | [diff] [blame] | 89 | static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = { |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 90 | [IFA_LOCAL] = { .type = NLA_U32 }, |
| 91 | [IFA_ADDRESS] = { .type = NLA_U32 }, |
| 92 | [IFA_BROADCAST] = { .type = NLA_U32 }, |
Thomas Graf | 5176f91 | 2006-08-26 20:13:18 -0700 | [diff] [blame] | 93 | [IFA_LABEL] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 96 | /* inet_addr_hash's shifting is dependent upon this IN4_ADDR_HSIZE |
| 97 | * value. So if you change this define, make appropriate changes to |
| 98 | * inet_addr_hash as well. |
| 99 | */ |
| 100 | #define IN4_ADDR_HSIZE 256 |
| 101 | static struct hlist_head inet_addr_lst[IN4_ADDR_HSIZE]; |
| 102 | static DEFINE_SPINLOCK(inet_addr_hash_lock); |
| 103 | |
| 104 | static inline unsigned int inet_addr_hash(struct net *net, __be32 addr) |
| 105 | { |
| 106 | u32 val = (__force u32) addr ^ hash_ptr(net, 8); |
| 107 | |
| 108 | return ((val ^ (val >> 8) ^ (val >> 16) ^ (val >> 24)) & |
| 109 | (IN4_ADDR_HSIZE - 1)); |
| 110 | } |
| 111 | |
| 112 | static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) |
| 113 | { |
| 114 | unsigned int hash = inet_addr_hash(net, ifa->ifa_address); |
| 115 | |
| 116 | spin_lock(&inet_addr_hash_lock); |
| 117 | hlist_add_head_rcu(&ifa->hash, &inet_addr_lst[hash]); |
| 118 | spin_unlock(&inet_addr_hash_lock); |
| 119 | } |
| 120 | |
| 121 | static void inet_hash_remove(struct in_ifaddr *ifa) |
| 122 | { |
| 123 | spin_lock(&inet_addr_hash_lock); |
| 124 | hlist_del_init_rcu(&ifa->hash); |
| 125 | spin_unlock(&inet_addr_hash_lock); |
| 126 | } |
| 127 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 128 | static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 130 | static BLOCKING_NOTIFIER_HEAD(inetaddr_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, |
| 132 | int destroy); |
| 133 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | 66f27a5 | 2007-12-02 00:55:54 +1100 | [diff] [blame] | 134 | static void devinet_sysctl_register(struct in_device *idev); |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 135 | static void devinet_sysctl_unregister(struct in_device *idev); |
| 136 | #else |
| 137 | static inline void devinet_sysctl_register(struct in_device *idev) |
| 138 | { |
| 139 | } |
| 140 | static inline void devinet_sysctl_unregister(struct in_device *idev) |
| 141 | { |
| 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | /* Locks all the inet devices. */ |
| 146 | |
| 147 | static struct in_ifaddr *inet_alloc_ifa(void) |
| 148 | { |
Alexey Dobriyan | 93adcc8 | 2008-10-28 13:25:09 -0700 | [diff] [blame] | 149 | return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static void inet_rcu_free_ifa(struct rcu_head *head) |
| 153 | { |
| 154 | struct in_ifaddr *ifa = container_of(head, struct in_ifaddr, rcu_head); |
| 155 | if (ifa->ifa_dev) |
| 156 | in_dev_put(ifa->ifa_dev); |
| 157 | kfree(ifa); |
| 158 | } |
| 159 | |
| 160 | static inline void inet_free_ifa(struct in_ifaddr *ifa) |
| 161 | { |
| 162 | call_rcu(&ifa->rcu_head, inet_rcu_free_ifa); |
| 163 | } |
| 164 | |
| 165 | void in_dev_finish_destroy(struct in_device *idev) |
| 166 | { |
| 167 | struct net_device *dev = idev->dev; |
| 168 | |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 169 | WARN_ON(idev->ifa_list); |
| 170 | WARN_ON(idev->mc_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | #ifdef NET_REFCNT_DEBUG |
| 172 | printk(KERN_DEBUG "in_dev_finish_destroy: %p=%s\n", |
| 173 | idev, dev ? dev->name : "NIL"); |
| 174 | #endif |
| 175 | dev_put(dev); |
| 176 | if (!idev->dead) |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 177 | pr_err("Freeing alive in_device %p\n", idev); |
| 178 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | kfree(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 181 | EXPORT_SYMBOL(in_dev_finish_destroy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Herbert Xu | 71e27da | 2007-06-04 23:36:06 -0700 | [diff] [blame] | 183 | static struct in_device *inetdev_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | struct in_device *in_dev; |
| 186 | |
| 187 | ASSERT_RTNL(); |
| 188 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 189 | in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | if (!in_dev) |
| 191 | goto out; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 192 | memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt, |
Pavel Emelyanov | 9355bbd | 2007-12-16 13:32:16 -0800 | [diff] [blame] | 193 | sizeof(in_dev->cnf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | in_dev->cnf.sysctl = NULL; |
| 195 | in_dev->dev = dev; |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 196 | in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl); |
| 197 | if (!in_dev->arp_parms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | goto out_kfree; |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 199 | if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) |
| 200 | dev_disable_lro(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | /* Reference in_dev->dev */ |
| 202 | dev_hold(dev); |
David L Stevens | 30c4cf5 | 2007-01-04 12:31:14 -0800 | [diff] [blame] | 203 | /* Account for reference dev->ip_ptr (below) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | in_dev_hold(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Pavel Emelyanov | 66f27a5 | 2007-12-02 00:55:54 +1100 | [diff] [blame] | 206 | devinet_sysctl_register(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | ip_mc_init_dev(in_dev); |
| 208 | if (dev->flags & IFF_UP) |
| 209 | ip_mc_up(in_dev); |
Jarek Poplawski | 483479e | 2007-01-09 14:38:31 -0800 | [diff] [blame] | 210 | |
David L Stevens | 30c4cf5 | 2007-01-04 12:31:14 -0800 | [diff] [blame] | 211 | /* we can receive as soon as ip_ptr is set -- do this last */ |
| 212 | rcu_assign_pointer(dev->ip_ptr, in_dev); |
Jarek Poplawski | 483479e | 2007-01-09 14:38:31 -0800 | [diff] [blame] | 213 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return in_dev; |
| 215 | out_kfree: |
| 216 | kfree(in_dev); |
| 217 | in_dev = NULL; |
| 218 | goto out; |
| 219 | } |
| 220 | |
| 221 | static void in_dev_rcu_put(struct rcu_head *head) |
| 222 | { |
| 223 | struct in_device *idev = container_of(head, struct in_device, rcu_head); |
| 224 | in_dev_put(idev); |
| 225 | } |
| 226 | |
| 227 | static void inetdev_destroy(struct in_device *in_dev) |
| 228 | { |
| 229 | struct in_ifaddr *ifa; |
| 230 | struct net_device *dev; |
| 231 | |
| 232 | ASSERT_RTNL(); |
| 233 | |
| 234 | dev = in_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | in_dev->dead = 1; |
| 237 | |
| 238 | ip_mc_destroy_dev(in_dev); |
| 239 | |
| 240 | while ((ifa = in_dev->ifa_list) != NULL) { |
| 241 | inet_del_ifa(in_dev, &in_dev->ifa_list, 0); |
| 242 | inet_free_ifa(ifa); |
| 243 | } |
| 244 | |
Eric Dumazet | 95ae6b2 | 2010-09-15 04:04:31 +0000 | [diff] [blame] | 245 | rcu_assign_pointer(dev->ip_ptr, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 247 | devinet_sysctl_unregister(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | neigh_parms_release(&arp_tbl, in_dev->arp_parms); |
| 249 | arp_ifdown(dev); |
| 250 | |
| 251 | call_rcu(&in_dev->rcu_head, in_dev_rcu_put); |
| 252 | } |
| 253 | |
Al Viro | ff428d7 | 2006-09-26 22:13:35 -0700 | [diff] [blame] | 254 | int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
| 256 | rcu_read_lock(); |
| 257 | for_primary_ifa(in_dev) { |
| 258 | if (inet_ifa_match(a, ifa)) { |
| 259 | if (!b || inet_ifa_match(b, ifa)) { |
| 260 | rcu_read_unlock(); |
| 261 | return 1; |
| 262 | } |
| 263 | } |
| 264 | } endfor_ifa(in_dev); |
| 265 | rcu_read_unlock(); |
| 266 | return 0; |
| 267 | } |
| 268 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 269 | static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, |
| 270 | int destroy, struct nlmsghdr *nlh, u32 pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Harald Welte | 8f937c6 | 2005-05-29 20:23:46 -0700 | [diff] [blame] | 272 | struct in_ifaddr *promote = NULL; |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 273 | struct in_ifaddr *ifa, *ifa1 = *ifap; |
| 274 | struct in_ifaddr *last_prim = in_dev->ifa_list; |
| 275 | struct in_ifaddr *prev_prom = NULL; |
| 276 | int do_promote = IN_DEV_PROMOTE_SECONDARIES(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | ASSERT_RTNL(); |
| 279 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 280 | /* 1. Deleting primary ifaddr forces deletion all secondaries |
Harald Welte | 8f937c6 | 2005-05-29 20:23:46 -0700 | [diff] [blame] | 281 | * unless alias promotion is set |
| 282 | **/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | struct in_ifaddr **ifap1 = &ifa1->ifa_next; |
| 286 | |
| 287 | while ((ifa = *ifap1) != NULL) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 288 | if (!(ifa->ifa_flags & IFA_F_SECONDARY) && |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 289 | ifa1->ifa_scope <= ifa->ifa_scope) |
| 290 | last_prim = ifa; |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (!(ifa->ifa_flags & IFA_F_SECONDARY) || |
| 293 | ifa1->ifa_mask != ifa->ifa_mask || |
| 294 | !inet_ifa_match(ifa1->ifa_address, ifa)) { |
| 295 | ifap1 = &ifa->ifa_next; |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 296 | prev_prom = ifa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | continue; |
| 298 | } |
| 299 | |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 300 | if (!do_promote) { |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 301 | inet_hash_remove(ifa); |
Harald Welte | 8f937c6 | 2005-05-29 20:23:46 -0700 | [diff] [blame] | 302 | *ifap1 = ifa->ifa_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 304 | rtmsg_ifa(RTM_DELADDR, ifa, nlh, pid); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 305 | blocking_notifier_call_chain(&inetaddr_chain, |
| 306 | NETDEV_DOWN, ifa); |
Harald Welte | 8f937c6 | 2005-05-29 20:23:46 -0700 | [diff] [blame] | 307 | inet_free_ifa(ifa); |
| 308 | } else { |
| 309 | promote = ifa; |
| 310 | break; |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | /* 2. Unlink it */ |
| 316 | |
| 317 | *ifap = ifa1->ifa_next; |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 318 | inet_hash_remove(ifa1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | /* 3. Announce address deletion */ |
| 321 | |
| 322 | /* Send message first, then call notifier. |
| 323 | At first sight, FIB update triggered by notifier |
| 324 | will refer to already deleted ifaddr, that could confuse |
| 325 | netlink listeners. It is not true: look, gated sees |
| 326 | that route deleted and if it still thinks that ifaddr |
| 327 | is valid, it will try to restore deleted routes... Grr. |
| 328 | So that, this order is correct. |
| 329 | */ |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 330 | rtmsg_ifa(RTM_DELADDR, ifa1, nlh, pid); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 331 | blocking_notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1); |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 332 | |
| 333 | if (promote) { |
| 334 | |
| 335 | if (prev_prom) { |
| 336 | prev_prom->ifa_next = promote->ifa_next; |
| 337 | promote->ifa_next = last_prim->ifa_next; |
| 338 | last_prim->ifa_next = promote; |
| 339 | } |
| 340 | |
| 341 | promote->ifa_flags &= ~IFA_F_SECONDARY; |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 342 | rtmsg_ifa(RTM_NEWADDR, promote, nlh, pid); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 343 | blocking_notifier_call_chain(&inetaddr_chain, |
| 344 | NETDEV_UP, promote); |
Jamal Hadi Salim | 0ff60a4 | 2005-11-22 14:47:37 -0800 | [diff] [blame] | 345 | for (ifa = promote->ifa_next; ifa; ifa = ifa->ifa_next) { |
| 346 | if (ifa1->ifa_mask != ifa->ifa_mask || |
| 347 | !inet_ifa_match(ifa1->ifa_address, ifa)) |
| 348 | continue; |
| 349 | fib_add_ifaddr(ifa); |
| 350 | } |
| 351 | |
| 352 | } |
Herbert Xu | 6363097 | 2007-06-07 18:35:38 -0700 | [diff] [blame] | 353 | if (destroy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | inet_free_ifa(ifa1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 357 | static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, |
| 358 | int destroy) |
| 359 | { |
| 360 | __inet_del_ifa(in_dev, ifap, destroy, NULL, 0); |
| 361 | } |
| 362 | |
| 363 | static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, |
| 364 | u32 pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
| 366 | struct in_device *in_dev = ifa->ifa_dev; |
| 367 | struct in_ifaddr *ifa1, **ifap, **last_primary; |
| 368 | |
| 369 | ASSERT_RTNL(); |
| 370 | |
| 371 | if (!ifa->ifa_local) { |
| 372 | inet_free_ifa(ifa); |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | ifa->ifa_flags &= ~IFA_F_SECONDARY; |
| 377 | last_primary = &in_dev->ifa_list; |
| 378 | |
| 379 | for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL; |
| 380 | ifap = &ifa1->ifa_next) { |
| 381 | if (!(ifa1->ifa_flags & IFA_F_SECONDARY) && |
| 382 | ifa->ifa_scope <= ifa1->ifa_scope) |
| 383 | last_primary = &ifa1->ifa_next; |
| 384 | if (ifa1->ifa_mask == ifa->ifa_mask && |
| 385 | inet_ifa_match(ifa1->ifa_address, ifa)) { |
| 386 | if (ifa1->ifa_local == ifa->ifa_local) { |
| 387 | inet_free_ifa(ifa); |
| 388 | return -EEXIST; |
| 389 | } |
| 390 | if (ifa1->ifa_scope != ifa->ifa_scope) { |
| 391 | inet_free_ifa(ifa); |
| 392 | return -EINVAL; |
| 393 | } |
| 394 | ifa->ifa_flags |= IFA_F_SECONDARY; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (!(ifa->ifa_flags & IFA_F_SECONDARY)) { |
| 399 | net_srandom(ifa->ifa_local); |
| 400 | ifap = last_primary; |
| 401 | } |
| 402 | |
| 403 | ifa->ifa_next = *ifap; |
| 404 | *ifap = ifa; |
| 405 | |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 406 | inet_hash_insert(dev_net(in_dev->dev), ifa); |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* Send message first, then call notifier. |
| 409 | Notifier will trigger FIB update, so that |
| 410 | listeners of netlink will know about new ifaddr */ |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 411 | rtmsg_ifa(RTM_NEWADDR, ifa, nlh, pid); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 412 | blocking_notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 417 | static int inet_insert_ifa(struct in_ifaddr *ifa) |
| 418 | { |
| 419 | return __inet_insert_ifa(ifa, NULL, 0); |
| 420 | } |
| 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa) |
| 423 | { |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 424 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | ASSERT_RTNL(); |
| 427 | |
| 428 | if (!in_dev) { |
Herbert Xu | 71e27da | 2007-06-04 23:36:06 -0700 | [diff] [blame] | 429 | inet_free_ifa(ifa); |
| 430 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
Herbert Xu | 71e27da | 2007-06-04 23:36:06 -0700 | [diff] [blame] | 432 | ipv4_devconf_setall(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (ifa->ifa_dev != in_dev) { |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 434 | WARN_ON(ifa->ifa_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | in_dev_hold(in_dev); |
| 436 | ifa->ifa_dev = in_dev; |
| 437 | } |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 438 | if (ipv4_is_loopback(ifa->ifa_local)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | ifa->ifa_scope = RT_SCOPE_HOST; |
| 440 | return inet_insert_ifa(ifa); |
| 441 | } |
| 442 | |
Eric Dumazet | 8723e1b | 2010-10-19 00:39:26 +0000 | [diff] [blame] | 443 | /* Caller must hold RCU or RTNL : |
| 444 | * We dont take a reference on found in_device |
| 445 | */ |
Denis V. Lunev | 7fee0ca | 2008-01-21 17:32:38 -0800 | [diff] [blame] | 446 | struct in_device *inetdev_by_index(struct net *net, int ifindex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
| 448 | struct net_device *dev; |
| 449 | struct in_device *in_dev = NULL; |
Eric Dumazet | c148fc2 | 2009-11-01 19:23:04 +0000 | [diff] [blame] | 450 | |
| 451 | rcu_read_lock(); |
| 452 | dev = dev_get_by_index_rcu(net, ifindex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (dev) |
Eric Dumazet | 8723e1b | 2010-10-19 00:39:26 +0000 | [diff] [blame] | 454 | in_dev = rcu_dereference_rtnl(dev->ip_ptr); |
Eric Dumazet | c148fc2 | 2009-11-01 19:23:04 +0000 | [diff] [blame] | 455 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return in_dev; |
| 457 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 458 | EXPORT_SYMBOL(inetdev_by_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | /* Called only from RTNL semaphored context. No locks. */ |
| 461 | |
Al Viro | 60cad5d | 2006-09-26 22:17:09 -0700 | [diff] [blame] | 462 | struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, |
| 463 | __be32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
| 465 | ASSERT_RTNL(); |
| 466 | |
| 467 | for_primary_ifa(in_dev) { |
| 468 | if (ifa->ifa_mask == mask && inet_ifa_match(prefix, ifa)) |
| 469 | return ifa; |
| 470 | } endfor_ifa(in_dev); |
| 471 | return NULL; |
| 472 | } |
| 473 | |
| 474 | static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 475 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 476 | struct net *net = sock_net(skb->sk); |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 477 | struct nlattr *tb[IFA_MAX+1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | struct in_device *in_dev; |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 479 | struct ifaddrmsg *ifm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | struct in_ifaddr *ifa, **ifap; |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 481 | int err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | ASSERT_RTNL(); |
| 484 | |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 485 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy); |
| 486 | if (err < 0) |
| 487 | goto errout; |
| 488 | |
| 489 | ifm = nlmsg_data(nlh); |
Denis V. Lunev | 7fee0ca | 2008-01-21 17:32:38 -0800 | [diff] [blame] | 490 | in_dev = inetdev_by_index(net, ifm->ifa_index); |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 491 | if (in_dev == NULL) { |
| 492 | err = -ENODEV; |
| 493 | goto errout; |
| 494 | } |
| 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; |
| 497 | ifap = &ifa->ifa_next) { |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 498 | if (tb[IFA_LOCAL] && |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 499 | ifa->ifa_local != nla_get_be32(tb[IFA_LOCAL])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | continue; |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 501 | |
| 502 | if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label)) |
| 503 | continue; |
| 504 | |
| 505 | if (tb[IFA_ADDRESS] && |
| 506 | (ifm->ifa_prefixlen != ifa->ifa_prefixlen || |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 507 | !inet_ifa_match(nla_get_be32(tb[IFA_ADDRESS]), ifa))) |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 508 | continue; |
| 509 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 510 | __inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return 0; |
| 512 | } |
Thomas Graf | dfdd5fd | 2006-08-04 23:04:17 -0700 | [diff] [blame] | 513 | |
| 514 | err = -EADDRNOTAVAIL; |
| 515 | errout: |
| 516 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Denis V. Lunev | 4b8aa9a | 2008-01-31 18:47:40 -0800 | [diff] [blame] | 519 | static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 521 | struct nlattr *tb[IFA_MAX+1]; |
| 522 | struct in_ifaddr *ifa; |
| 523 | struct ifaddrmsg *ifm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | struct net_device *dev; |
| 525 | struct in_device *in_dev; |
Denis V. Lunev | 7b21857 | 2008-01-31 18:47:00 -0800 | [diff] [blame] | 526 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 528 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy); |
| 529 | if (err < 0) |
| 530 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 532 | ifm = nlmsg_data(nlh); |
Denis V. Lunev | 7b21857 | 2008-01-31 18:47:00 -0800 | [diff] [blame] | 533 | err = -EINVAL; |
| 534 | if (ifm->ifa_prefixlen > 32 || tb[IFA_LOCAL] == NULL) |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 535 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Denis V. Lunev | 4b8aa9a | 2008-01-31 18:47:40 -0800 | [diff] [blame] | 537 | dev = __dev_get_by_index(net, ifm->ifa_index); |
Denis V. Lunev | 7b21857 | 2008-01-31 18:47:00 -0800 | [diff] [blame] | 538 | err = -ENODEV; |
| 539 | if (dev == NULL) |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 540 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 542 | in_dev = __in_dev_get_rtnl(dev); |
Denis V. Lunev | 7b21857 | 2008-01-31 18:47:00 -0800 | [diff] [blame] | 543 | err = -ENOBUFS; |
| 544 | if (in_dev == NULL) |
Herbert Xu | 71e27da | 2007-06-04 23:36:06 -0700 | [diff] [blame] | 545 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 547 | ifa = inet_alloc_ifa(); |
Denis V. Lunev | 7b21857 | 2008-01-31 18:47:00 -0800 | [diff] [blame] | 548 | if (ifa == NULL) |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 549 | /* |
| 550 | * A potential indev allocation can be left alive, it stays |
| 551 | * assigned to its device and is destroy with it. |
| 552 | */ |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 553 | goto errout; |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 554 | |
Pavel Emelyanov | a4e65d3 | 2007-12-07 23:55:43 -0800 | [diff] [blame] | 555 | ipv4_devconf_setall(in_dev); |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 556 | in_dev_hold(in_dev); |
| 557 | |
| 558 | if (tb[IFA_ADDRESS] == NULL) |
| 559 | tb[IFA_ADDRESS] = tb[IFA_LOCAL]; |
| 560 | |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 561 | INIT_HLIST_NODE(&ifa->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | ifa->ifa_prefixlen = ifm->ifa_prefixlen; |
| 563 | ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | ifa->ifa_flags = ifm->ifa_flags; |
| 565 | ifa->ifa_scope = ifm->ifa_scope; |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 566 | ifa->ifa_dev = in_dev; |
| 567 | |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 568 | ifa->ifa_local = nla_get_be32(tb[IFA_LOCAL]); |
| 569 | ifa->ifa_address = nla_get_be32(tb[IFA_ADDRESS]); |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 570 | |
| 571 | if (tb[IFA_BROADCAST]) |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 572 | ifa->ifa_broadcast = nla_get_be32(tb[IFA_BROADCAST]); |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 573 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 574 | if (tb[IFA_LABEL]) |
| 575 | nla_strlcpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | else |
| 577 | memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); |
| 578 | |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 579 | return ifa; |
| 580 | |
| 581 | errout: |
| 582 | return ERR_PTR(err); |
| 583 | } |
| 584 | |
| 585 | static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 586 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 587 | struct net *net = sock_net(skb->sk); |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 588 | struct in_ifaddr *ifa; |
| 589 | |
| 590 | ASSERT_RTNL(); |
| 591 | |
Denis V. Lunev | 4b8aa9a | 2008-01-31 18:47:40 -0800 | [diff] [blame] | 592 | ifa = rtm_to_ifaddr(net, nlh); |
Thomas Graf | 5c75397 | 2006-08-04 23:03:53 -0700 | [diff] [blame] | 593 | if (IS_ERR(ifa)) |
| 594 | return PTR_ERR(ifa); |
| 595 | |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 596 | return __inet_insert_ifa(ifa, nlh, NETLINK_CB(skb).pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* |
| 600 | * Determine a default network mask, based on the IP address. |
| 601 | */ |
| 602 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 603 | static inline int inet_abc_len(__be32 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | { |
| 605 | int rc = -1; /* Something else, probably a multicast. */ |
| 606 | |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 607 | if (ipv4_is_zeronet(addr)) |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 608 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | else { |
Al Viro | 714e85b | 2006-11-14 20:51:49 -0800 | [diff] [blame] | 610 | __u32 haddr = ntohl(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Al Viro | 714e85b | 2006-11-14 20:51:49 -0800 | [diff] [blame] | 612 | if (IN_CLASSA(haddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | rc = 8; |
Al Viro | 714e85b | 2006-11-14 20:51:49 -0800 | [diff] [blame] | 614 | else if (IN_CLASSB(haddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | rc = 16; |
Al Viro | 714e85b | 2006-11-14 20:51:49 -0800 | [diff] [blame] | 616 | else if (IN_CLASSC(haddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | rc = 24; |
| 618 | } |
| 619 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 620 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
Denis V. Lunev | e5b13cb | 2008-02-28 20:51:43 -0800 | [diff] [blame] | 624 | int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
| 626 | struct ifreq ifr; |
| 627 | struct sockaddr_in sin_orig; |
| 628 | struct sockaddr_in *sin = (struct sockaddr_in *)&ifr.ifr_addr; |
| 629 | struct in_device *in_dev; |
| 630 | struct in_ifaddr **ifap = NULL; |
| 631 | struct in_ifaddr *ifa = NULL; |
| 632 | struct net_device *dev; |
| 633 | char *colon; |
| 634 | int ret = -EFAULT; |
| 635 | int tryaddrmatch = 0; |
| 636 | |
| 637 | /* |
| 638 | * Fetch the caller's info block into kernel space |
| 639 | */ |
| 640 | |
| 641 | if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) |
| 642 | goto out; |
| 643 | ifr.ifr_name[IFNAMSIZ - 1] = 0; |
| 644 | |
| 645 | /* save original address for comparison */ |
| 646 | memcpy(&sin_orig, sin, sizeof(*sin)); |
| 647 | |
| 648 | colon = strchr(ifr.ifr_name, ':'); |
| 649 | if (colon) |
| 650 | *colon = 0; |
| 651 | |
Denis V. Lunev | e5b13cb | 2008-02-28 20:51:43 -0800 | [diff] [blame] | 652 | dev_load(net, ifr.ifr_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 654 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | case SIOCGIFADDR: /* Get interface address */ |
| 656 | case SIOCGIFBRDADDR: /* Get the broadcast address */ |
| 657 | case SIOCGIFDSTADDR: /* Get the destination address */ |
| 658 | case SIOCGIFNETMASK: /* Get the netmask for the interface */ |
| 659 | /* Note that these ioctls will not sleep, |
| 660 | so that we do not impose a lock. |
| 661 | One day we will be forced to put shlock here (I mean SMP) |
| 662 | */ |
| 663 | tryaddrmatch = (sin_orig.sin_family == AF_INET); |
| 664 | memset(sin, 0, sizeof(*sin)); |
| 665 | sin->sin_family = AF_INET; |
| 666 | break; |
| 667 | |
| 668 | case SIOCSIFFLAGS: |
| 669 | ret = -EACCES; |
| 670 | if (!capable(CAP_NET_ADMIN)) |
| 671 | goto out; |
| 672 | break; |
| 673 | case SIOCSIFADDR: /* Set interface address (and family) */ |
| 674 | case SIOCSIFBRDADDR: /* Set the broadcast address */ |
| 675 | case SIOCSIFDSTADDR: /* Set the destination address */ |
| 676 | case SIOCSIFNETMASK: /* Set the netmask for the interface */ |
| 677 | ret = -EACCES; |
| 678 | if (!capable(CAP_NET_ADMIN)) |
| 679 | goto out; |
| 680 | ret = -EINVAL; |
| 681 | if (sin->sin_family != AF_INET) |
| 682 | goto out; |
| 683 | break; |
| 684 | default: |
| 685 | ret = -EINVAL; |
| 686 | goto out; |
| 687 | } |
| 688 | |
| 689 | rtnl_lock(); |
| 690 | |
| 691 | ret = -ENODEV; |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 692 | dev = __dev_get_by_name(net, ifr.ifr_name); |
| 693 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | goto done; |
| 695 | |
| 696 | if (colon) |
| 697 | *colon = ':'; |
| 698 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 699 | in_dev = __in_dev_get_rtnl(dev); |
| 700 | if (in_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (tryaddrmatch) { |
| 702 | /* Matthias Andree */ |
| 703 | /* compare label and address (4.4BSD style) */ |
| 704 | /* note: we only do this for a limited set of ioctls |
| 705 | and only if the original address family was AF_INET. |
| 706 | This is checked above. */ |
| 707 | for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; |
| 708 | ifap = &ifa->ifa_next) { |
| 709 | if (!strcmp(ifr.ifr_name, ifa->ifa_label) && |
| 710 | sin_orig.sin_addr.s_addr == |
| 711 | ifa->ifa_address) { |
| 712 | break; /* found */ |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | /* we didn't get a match, maybe the application is |
| 717 | 4.3BSD-style and passed in junk so we fall back to |
| 718 | comparing just the label */ |
| 719 | if (!ifa) { |
| 720 | for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; |
| 721 | ifap = &ifa->ifa_next) |
| 722 | if (!strcmp(ifr.ifr_name, ifa->ifa_label)) |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | ret = -EADDRNOTAVAIL; |
| 728 | if (!ifa && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS) |
| 729 | goto done; |
| 730 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 731 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | case SIOCGIFADDR: /* Get interface address */ |
| 733 | sin->sin_addr.s_addr = ifa->ifa_local; |
| 734 | goto rarok; |
| 735 | |
| 736 | case SIOCGIFBRDADDR: /* Get the broadcast address */ |
| 737 | sin->sin_addr.s_addr = ifa->ifa_broadcast; |
| 738 | goto rarok; |
| 739 | |
| 740 | case SIOCGIFDSTADDR: /* Get the destination address */ |
| 741 | sin->sin_addr.s_addr = ifa->ifa_address; |
| 742 | goto rarok; |
| 743 | |
| 744 | case SIOCGIFNETMASK: /* Get the netmask for the interface */ |
| 745 | sin->sin_addr.s_addr = ifa->ifa_mask; |
| 746 | goto rarok; |
| 747 | |
| 748 | case SIOCSIFFLAGS: |
| 749 | if (colon) { |
| 750 | ret = -EADDRNOTAVAIL; |
| 751 | if (!ifa) |
| 752 | break; |
| 753 | ret = 0; |
| 754 | if (!(ifr.ifr_flags & IFF_UP)) |
| 755 | inet_del_ifa(in_dev, ifap, 1); |
| 756 | break; |
| 757 | } |
| 758 | ret = dev_change_flags(dev, ifr.ifr_flags); |
| 759 | break; |
| 760 | |
| 761 | case SIOCSIFADDR: /* Set interface address (and family) */ |
| 762 | ret = -EINVAL; |
| 763 | if (inet_abc_len(sin->sin_addr.s_addr) < 0) |
| 764 | break; |
| 765 | |
| 766 | if (!ifa) { |
| 767 | ret = -ENOBUFS; |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 768 | ifa = inet_alloc_ifa(); |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 769 | INIT_HLIST_NODE(&ifa->hash); |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 770 | if (!ifa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | break; |
| 772 | if (colon) |
| 773 | memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ); |
| 774 | else |
| 775 | memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); |
| 776 | } else { |
| 777 | ret = 0; |
| 778 | if (ifa->ifa_local == sin->sin_addr.s_addr) |
| 779 | break; |
| 780 | inet_del_ifa(in_dev, ifap, 0); |
| 781 | ifa->ifa_broadcast = 0; |
Bjorn Mork | 148f972 | 2008-02-26 18:17:53 -0800 | [diff] [blame] | 782 | ifa->ifa_scope = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | ifa->ifa_address = ifa->ifa_local = sin->sin_addr.s_addr; |
| 786 | |
| 787 | if (!(dev->flags & IFF_POINTOPOINT)) { |
| 788 | ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); |
| 789 | ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); |
| 790 | if ((dev->flags & IFF_BROADCAST) && |
| 791 | ifa->ifa_prefixlen < 31) |
| 792 | ifa->ifa_broadcast = ifa->ifa_address | |
| 793 | ~ifa->ifa_mask; |
| 794 | } else { |
| 795 | ifa->ifa_prefixlen = 32; |
| 796 | ifa->ifa_mask = inet_make_mask(32); |
| 797 | } |
| 798 | ret = inet_set_ifa(dev, ifa); |
| 799 | break; |
| 800 | |
| 801 | case SIOCSIFBRDADDR: /* Set the broadcast address */ |
| 802 | ret = 0; |
| 803 | if (ifa->ifa_broadcast != sin->sin_addr.s_addr) { |
| 804 | inet_del_ifa(in_dev, ifap, 0); |
| 805 | ifa->ifa_broadcast = sin->sin_addr.s_addr; |
| 806 | inet_insert_ifa(ifa); |
| 807 | } |
| 808 | break; |
| 809 | |
| 810 | case SIOCSIFDSTADDR: /* Set the destination address */ |
| 811 | ret = 0; |
| 812 | if (ifa->ifa_address == sin->sin_addr.s_addr) |
| 813 | break; |
| 814 | ret = -EINVAL; |
| 815 | if (inet_abc_len(sin->sin_addr.s_addr) < 0) |
| 816 | break; |
| 817 | ret = 0; |
| 818 | inet_del_ifa(in_dev, ifap, 0); |
| 819 | ifa->ifa_address = sin->sin_addr.s_addr; |
| 820 | inet_insert_ifa(ifa); |
| 821 | break; |
| 822 | |
| 823 | case SIOCSIFNETMASK: /* Set the netmask for the interface */ |
| 824 | |
| 825 | /* |
| 826 | * The mask we set must be legal. |
| 827 | */ |
| 828 | ret = -EINVAL; |
| 829 | if (bad_mask(sin->sin_addr.s_addr, 0)) |
| 830 | break; |
| 831 | ret = 0; |
| 832 | if (ifa->ifa_mask != sin->sin_addr.s_addr) { |
Al Viro | a144ea4 | 2006-09-28 18:00:55 -0700 | [diff] [blame] | 833 | __be32 old_mask = ifa->ifa_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | inet_del_ifa(in_dev, ifap, 0); |
| 835 | ifa->ifa_mask = sin->sin_addr.s_addr; |
| 836 | ifa->ifa_prefixlen = inet_mask_len(ifa->ifa_mask); |
| 837 | |
| 838 | /* See if current broadcast address matches |
| 839 | * with current netmask, then recalculate |
| 840 | * the broadcast address. Otherwise it's a |
| 841 | * funny address, so don't touch it since |
| 842 | * the user seems to know what (s)he's doing... |
| 843 | */ |
| 844 | if ((dev->flags & IFF_BROADCAST) && |
| 845 | (ifa->ifa_prefixlen < 31) && |
| 846 | (ifa->ifa_broadcast == |
David Engel | dcab5e1 | 2005-10-21 22:09:16 -0500 | [diff] [blame] | 847 | (ifa->ifa_local|~old_mask))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | ifa->ifa_broadcast = (ifa->ifa_local | |
| 849 | ~sin->sin_addr.s_addr); |
| 850 | } |
| 851 | inet_insert_ifa(ifa); |
| 852 | } |
| 853 | break; |
| 854 | } |
| 855 | done: |
| 856 | rtnl_unlock(); |
| 857 | out: |
| 858 | return ret; |
| 859 | rarok: |
| 860 | rtnl_unlock(); |
| 861 | ret = copy_to_user(arg, &ifr, sizeof(struct ifreq)) ? -EFAULT : 0; |
| 862 | goto out; |
| 863 | } |
| 864 | |
| 865 | static int inet_gifconf(struct net_device *dev, char __user *buf, int len) |
| 866 | { |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 867 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | struct in_ifaddr *ifa; |
| 869 | struct ifreq ifr; |
| 870 | int done = 0; |
| 871 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 872 | if (!in_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | goto out; |
| 874 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 875 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | if (!buf) { |
| 877 | done += sizeof(ifr); |
| 878 | continue; |
| 879 | } |
| 880 | if (len < (int) sizeof(ifr)) |
| 881 | break; |
| 882 | memset(&ifr, 0, sizeof(struct ifreq)); |
| 883 | if (ifa->ifa_label) |
| 884 | strcpy(ifr.ifr_name, ifa->ifa_label); |
| 885 | else |
| 886 | strcpy(ifr.ifr_name, dev->name); |
| 887 | |
| 888 | (*(struct sockaddr_in *)&ifr.ifr_addr).sin_family = AF_INET; |
| 889 | (*(struct sockaddr_in *)&ifr.ifr_addr).sin_addr.s_addr = |
| 890 | ifa->ifa_local; |
| 891 | |
| 892 | if (copy_to_user(buf, &ifr, sizeof(struct ifreq))) { |
| 893 | done = -EFAULT; |
| 894 | break; |
| 895 | } |
| 896 | buf += sizeof(struct ifreq); |
| 897 | len -= sizeof(struct ifreq); |
| 898 | done += sizeof(struct ifreq); |
| 899 | } |
| 900 | out: |
| 901 | return done; |
| 902 | } |
| 903 | |
Al Viro | a61ced5 | 2006-09-26 21:27:54 -0700 | [diff] [blame] | 904 | __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | { |
Al Viro | a61ced5 | 2006-09-26 21:27:54 -0700 | [diff] [blame] | 906 | __be32 addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | struct in_device *in_dev; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 908 | struct net *net = dev_net(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 911 | in_dev = __in_dev_get_rcu(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | if (!in_dev) |
| 913 | goto no_in_dev; |
| 914 | |
| 915 | for_primary_ifa(in_dev) { |
| 916 | if (ifa->ifa_scope > scope) |
| 917 | continue; |
| 918 | if (!dst || inet_ifa_match(dst, ifa)) { |
| 919 | addr = ifa->ifa_local; |
| 920 | break; |
| 921 | } |
| 922 | if (!addr) |
| 923 | addr = ifa->ifa_local; |
| 924 | } endfor_ifa(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | if (addr) |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 927 | goto out_unlock; |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 928 | no_in_dev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
| 930 | /* Not loopback addresses on loopback should be preferred |
| 931 | in this case. It is importnat that lo is the first interface |
| 932 | in dev_base list. |
| 933 | */ |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 934 | for_each_netdev_rcu(net, dev) { |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 935 | in_dev = __in_dev_get_rcu(dev); |
| 936 | if (!in_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | continue; |
| 938 | |
| 939 | for_primary_ifa(in_dev) { |
| 940 | if (ifa->ifa_scope != RT_SCOPE_LINK && |
| 941 | ifa->ifa_scope <= scope) { |
| 942 | addr = ifa->ifa_local; |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 943 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | } endfor_ifa(in_dev); |
| 946 | } |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 947 | out_unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return addr; |
| 950 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 951 | EXPORT_SYMBOL(inet_select_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Al Viro | 60cad5d | 2006-09-26 22:17:09 -0700 | [diff] [blame] | 953 | static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst, |
| 954 | __be32 local, int scope) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
| 956 | int same = 0; |
Al Viro | a144ea4 | 2006-09-28 18:00:55 -0700 | [diff] [blame] | 957 | __be32 addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | for_ifa(in_dev) { |
| 960 | if (!addr && |
| 961 | (local == ifa->ifa_local || !local) && |
| 962 | ifa->ifa_scope <= scope) { |
| 963 | addr = ifa->ifa_local; |
| 964 | if (same) |
| 965 | break; |
| 966 | } |
| 967 | if (!same) { |
| 968 | same = (!local || inet_ifa_match(local, ifa)) && |
| 969 | (!dst || inet_ifa_match(dst, ifa)); |
| 970 | if (same && addr) { |
| 971 | if (local || !dst) |
| 972 | break; |
| 973 | /* Is the selected addr into dst subnet? */ |
| 974 | if (inet_ifa_match(addr, ifa)) |
| 975 | break; |
| 976 | /* No, then can we use new local src? */ |
| 977 | if (ifa->ifa_scope <= scope) { |
| 978 | addr = ifa->ifa_local; |
| 979 | break; |
| 980 | } |
| 981 | /* search for large dst subnet for addr */ |
| 982 | same = 0; |
| 983 | } |
| 984 | } |
| 985 | } endfor_ifa(in_dev); |
| 986 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 987 | return same ? addr : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* |
| 991 | * Confirm that local IP address exists using wildcards: |
Denis V. Lunev | 9bd85e3 | 2008-01-14 23:05:55 -0800 | [diff] [blame] | 992 | * - in_dev: only on this interface, 0=any interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | * - dst: only in the same subnet as dst, 0=any dst |
| 994 | * - local: address, 0=autoselect the local address |
| 995 | * - scope: maximum allowed scope value for the local address |
| 996 | */ |
Denis V. Lunev | 9bd85e3 | 2008-01-14 23:05:55 -0800 | [diff] [blame] | 997 | __be32 inet_confirm_addr(struct in_device *in_dev, |
| 998 | __be32 dst, __be32 local, int scope) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | { |
Al Viro | 60cad5d | 2006-09-26 22:17:09 -0700 | [diff] [blame] | 1000 | __be32 addr = 0; |
Denis V. Lunev | 9bd85e3 | 2008-01-14 23:05:55 -0800 | [diff] [blame] | 1001 | struct net_device *dev; |
Denis V. Lunev | 39a6d06 | 2008-01-14 23:06:19 -0800 | [diff] [blame] | 1002 | struct net *net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
Denis V. Lunev | 39a6d06 | 2008-01-14 23:06:19 -0800 | [diff] [blame] | 1004 | if (scope != RT_SCOPE_LINK) |
Denis V. Lunev | 9bd85e3 | 2008-01-14 23:05:55 -0800 | [diff] [blame] | 1005 | return confirm_addr_indev(in_dev, dst, local, scope); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 1007 | net = dev_net(in_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | rcu_read_lock(); |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1009 | for_each_netdev_rcu(net, dev) { |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1010 | in_dev = __in_dev_get_rcu(dev); |
| 1011 | if (in_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | addr = confirm_addr_indev(in_dev, dst, local, scope); |
| 1013 | if (addr) |
| 1014 | break; |
| 1015 | } |
| 1016 | } |
| 1017 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | return addr; |
| 1020 | } |
| 1021 | |
| 1022 | /* |
| 1023 | * Device notifier |
| 1024 | */ |
| 1025 | |
| 1026 | int register_inetaddr_notifier(struct notifier_block *nb) |
| 1027 | { |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1028 | return blocking_notifier_chain_register(&inetaddr_chain, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1030 | EXPORT_SYMBOL(register_inetaddr_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
| 1032 | int unregister_inetaddr_notifier(struct notifier_block *nb) |
| 1033 | { |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1034 | return blocking_notifier_chain_unregister(&inetaddr_chain, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1036 | EXPORT_SYMBOL(unregister_inetaddr_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1038 | /* Rename ifa_labels for a device name change. Make some effort to preserve |
| 1039 | * existing alias numbering and to create unique labels if possible. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | */ |
| 1041 | static void inetdev_changename(struct net_device *dev, struct in_device *in_dev) |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1042 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | struct in_ifaddr *ifa; |
| 1044 | int named = 0; |
| 1045 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1046 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 1047 | char old[IFNAMSIZ], *dot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | memcpy(old, ifa->ifa_label, IFNAMSIZ); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1050 | memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | if (named++ == 0) |
Thomas Graf | 573bf47 | 2008-06-10 15:40:04 -0700 | [diff] [blame] | 1052 | goto skip; |
Mark McLoughlin | 44344b2 | 2008-01-04 00:56:25 -0800 | [diff] [blame] | 1053 | dot = strchr(old, ':'); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1054 | if (dot == NULL) { |
| 1055 | sprintf(old, ":%d", named); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | dot = old; |
| 1057 | } |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1058 | if (strlen(dot) + strlen(dev->name) < IFNAMSIZ) |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1059 | strcat(ifa->ifa_label, dot); |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1060 | else |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1061 | strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot); |
Thomas Graf | 573bf47 | 2008-06-10 15:40:04 -0700 | [diff] [blame] | 1062 | skip: |
| 1063 | rtmsg_ifa(RTM_NEWADDR, ifa, NULL, 0); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1064 | } |
| 1065 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Breno Leitao | 0677084 | 2008-09-02 17:28:58 -0700 | [diff] [blame] | 1067 | static inline bool inetdev_valid_mtu(unsigned mtu) |
| 1068 | { |
| 1069 | return mtu >= 68; |
| 1070 | } |
| 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | /* Called only under RTNL semaphore */ |
| 1073 | |
| 1074 | static int inetdev_event(struct notifier_block *this, unsigned long event, |
| 1075 | void *ptr) |
| 1076 | { |
| 1077 | struct net_device *dev = ptr; |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 1078 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
| 1080 | ASSERT_RTNL(); |
| 1081 | |
| 1082 | if (!in_dev) { |
Herbert Xu | 8030f54 | 2007-02-22 01:53:47 +0900 | [diff] [blame] | 1083 | if (event == NETDEV_REGISTER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | in_dev = inetdev_init(dev); |
Herbert Xu | b217d61 | 2007-07-30 17:04:52 -0700 | [diff] [blame] | 1085 | if (!in_dev) |
| 1086 | return notifier_from_errno(-ENOMEM); |
Eric W. Biederman | 0cc217e | 2007-09-26 22:10:06 -0700 | [diff] [blame] | 1087 | if (dev->flags & IFF_LOOPBACK) { |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1088 | IN_DEV_CONF_SET(in_dev, NOXFRM, 1); |
| 1089 | IN_DEV_CONF_SET(in_dev, NOPOLICY, 1); |
Herbert Xu | 8030f54 | 2007-02-22 01:53:47 +0900 | [diff] [blame] | 1090 | } |
Breno Leitao | 0677084 | 2008-09-02 17:28:58 -0700 | [diff] [blame] | 1091 | } else if (event == NETDEV_CHANGEMTU) { |
| 1092 | /* Re-enabling IP */ |
| 1093 | if (inetdev_valid_mtu(dev->mtu)) |
| 1094 | in_dev = inetdev_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
| 1096 | goto out; |
| 1097 | } |
| 1098 | |
| 1099 | switch (event) { |
| 1100 | case NETDEV_REGISTER: |
| 1101 | printk(KERN_DEBUG "inetdev_event: bug\n"); |
Eric Dumazet | 95ae6b2 | 2010-09-15 04:04:31 +0000 | [diff] [blame] | 1102 | rcu_assign_pointer(dev->ip_ptr, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | break; |
| 1104 | case NETDEV_UP: |
Breno Leitao | 0677084 | 2008-09-02 17:28:58 -0700 | [diff] [blame] | 1105 | if (!inetdev_valid_mtu(dev->mtu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | break; |
Eric W. Biederman | 0cc217e | 2007-09-26 22:10:06 -0700 | [diff] [blame] | 1107 | if (dev->flags & IFF_LOOPBACK) { |
Eric Dumazet | 9f9354b | 2009-11-04 22:05:10 -0800 | [diff] [blame] | 1108 | struct in_ifaddr *ifa = inet_alloc_ifa(); |
| 1109 | |
| 1110 | if (ifa) { |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 1111 | INIT_HLIST_NODE(&ifa->hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | ifa->ifa_local = |
| 1113 | ifa->ifa_address = htonl(INADDR_LOOPBACK); |
| 1114 | ifa->ifa_prefixlen = 8; |
| 1115 | ifa->ifa_mask = inet_make_mask(8); |
| 1116 | in_dev_hold(in_dev); |
| 1117 | ifa->ifa_dev = in_dev; |
| 1118 | ifa->ifa_scope = RT_SCOPE_HOST; |
| 1119 | memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); |
| 1120 | inet_insert_ifa(ifa); |
| 1121 | } |
| 1122 | } |
| 1123 | ip_mc_up(in_dev); |
Stephen Hemminger | eefef1c | 2009-02-01 01:04:33 -0800 | [diff] [blame] | 1124 | /* fall through */ |
Ian Campbell | 06c4648 | 2010-05-26 00:09:42 +0000 | [diff] [blame] | 1125 | case NETDEV_NOTIFY_PEERS: |
Stephen Hemminger | eefef1c | 2009-02-01 01:04:33 -0800 | [diff] [blame] | 1126 | case NETDEV_CHANGEADDR: |
Stephen Hemminger | a21090c | 2009-10-07 03:18:17 -0700 | [diff] [blame] | 1127 | /* Send gratuitous ARP to notify of link change */ |
| 1128 | if (IN_DEV_ARP_NOTIFY(in_dev)) { |
| 1129 | struct in_ifaddr *ifa = in_dev->ifa_list; |
| 1130 | |
| 1131 | if (ifa) |
| 1132 | arp_send(ARPOP_REQUEST, ETH_P_ARP, |
| 1133 | ifa->ifa_address, dev, |
| 1134 | ifa->ifa_address, NULL, |
| 1135 | dev->dev_addr, NULL); |
| 1136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | break; |
| 1138 | case NETDEV_DOWN: |
| 1139 | ip_mc_down(in_dev); |
| 1140 | break; |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 1141 | case NETDEV_PRE_TYPE_CHANGE: |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1142 | ip_mc_unmap(in_dev); |
| 1143 | break; |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 1144 | case NETDEV_POST_TYPE_CHANGE: |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1145 | ip_mc_remap(in_dev); |
| 1146 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | case NETDEV_CHANGEMTU: |
Breno Leitao | 0677084 | 2008-09-02 17:28:58 -0700 | [diff] [blame] | 1148 | if (inetdev_valid_mtu(dev->mtu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | break; |
Breno Leitao | 0677084 | 2008-09-02 17:28:58 -0700 | [diff] [blame] | 1150 | /* disable IP when MTU is not enough */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | case NETDEV_UNREGISTER: |
| 1152 | inetdev_destroy(in_dev); |
| 1153 | break; |
| 1154 | case NETDEV_CHANGENAME: |
| 1155 | /* Do not notify about label change, this event is |
| 1156 | * not interesting to applications using netlink. |
| 1157 | */ |
| 1158 | inetdev_changename(dev, in_dev); |
| 1159 | |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 1160 | devinet_sysctl_unregister(in_dev); |
Pavel Emelyanov | 66f27a5 | 2007-12-02 00:55:54 +1100 | [diff] [blame] | 1161 | devinet_sysctl_register(in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | out: |
| 1165 | return NOTIFY_DONE; |
| 1166 | } |
| 1167 | |
| 1168 | static struct notifier_block ip_netdev_notifier = { |
Jianjun Kong | 539afed | 2008-11-03 02:48:48 -0800 | [diff] [blame] | 1169 | .notifier_call = inetdev_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | }; |
| 1171 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 1172 | static inline size_t inet_nlmsg_size(void) |
| 1173 | { |
| 1174 | return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) |
| 1175 | + nla_total_size(4) /* IFA_ADDRESS */ |
| 1176 | + nla_total_size(4) /* IFA_LOCAL */ |
| 1177 | + nla_total_size(4) /* IFA_BROADCAST */ |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 1178 | + nla_total_size(IFNAMSIZ); /* IFA_LABEL */ |
| 1179 | } |
| 1180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 1182 | u32 pid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | { |
| 1184 | struct ifaddrmsg *ifm; |
| 1185 | struct nlmsghdr *nlh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1187 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*ifm), flags); |
| 1188 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 1189 | return -EMSGSIZE; |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1190 | |
| 1191 | ifm = nlmsg_data(nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | ifm->ifa_family = AF_INET; |
| 1193 | ifm->ifa_prefixlen = ifa->ifa_prefixlen; |
| 1194 | ifm->ifa_flags = ifa->ifa_flags|IFA_F_PERMANENT; |
| 1195 | ifm->ifa_scope = ifa->ifa_scope; |
| 1196 | ifm->ifa_index = ifa->ifa_dev->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1198 | if (ifa->ifa_address) |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 1199 | NLA_PUT_BE32(skb, IFA_ADDRESS, ifa->ifa_address); |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (ifa->ifa_local) |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 1202 | NLA_PUT_BE32(skb, IFA_LOCAL, ifa->ifa_local); |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | if (ifa->ifa_broadcast) |
Al Viro | a7a628c | 2006-09-26 22:16:43 -0700 | [diff] [blame] | 1205 | NLA_PUT_BE32(skb, IFA_BROADCAST, ifa->ifa_broadcast); |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1206 | |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1207 | if (ifa->ifa_label[0]) |
| 1208 | NLA_PUT_STRING(skb, IFA_LABEL, ifa->ifa_label); |
| 1209 | |
| 1210 | return nlmsg_end(skb, nlh); |
| 1211 | |
| 1212 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 1213 | nlmsg_cancel(skb, nlh); |
| 1214 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 1218 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 1219 | struct net *net = sock_net(skb->sk); |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1220 | int h, s_h; |
| 1221 | int idx, s_idx; |
| 1222 | int ip_idx, s_ip_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | struct net_device *dev; |
| 1224 | struct in_device *in_dev; |
| 1225 | struct in_ifaddr *ifa; |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1226 | struct hlist_head *head; |
| 1227 | struct hlist_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1229 | s_h = cb->args[0]; |
| 1230 | s_idx = idx = cb->args[1]; |
| 1231 | s_ip_idx = ip_idx = cb->args[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1233 | for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { |
| 1234 | idx = 0; |
| 1235 | head = &net->dev_index_head[h]; |
| 1236 | rcu_read_lock(); |
| 1237 | hlist_for_each_entry_rcu(dev, node, head, index_hlist) { |
| 1238 | if (idx < s_idx) |
| 1239 | goto cont; |
Patrick McHardy | 4b97efd | 2010-03-26 20:27:49 -0700 | [diff] [blame] | 1240 | if (h > s_h || idx > s_idx) |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1241 | s_ip_idx = 0; |
| 1242 | in_dev = __in_dev_get_rcu(dev); |
| 1243 | if (!in_dev) |
| 1244 | goto cont; |
| 1245 | |
| 1246 | for (ifa = in_dev->ifa_list, ip_idx = 0; ifa; |
| 1247 | ifa = ifa->ifa_next, ip_idx++) { |
| 1248 | if (ip_idx < s_ip_idx) |
| 1249 | continue; |
| 1250 | if (inet_fill_ifaddr(skb, ifa, |
| 1251 | NETLINK_CB(cb->skb).pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | cb->nlh->nlmsg_seq, |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1253 | RTM_NEWADDR, NLM_F_MULTI) <= 0) { |
| 1254 | rcu_read_unlock(); |
| 1255 | goto done; |
| 1256 | } |
| 1257 | } |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 1258 | cont: |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1259 | idx++; |
| 1260 | } |
| 1261 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | done: |
Eric Dumazet | eec4df9 | 2009-11-12 07:44:25 +0000 | [diff] [blame] | 1265 | cb->args[0] = h; |
| 1266 | cb->args[1] = idx; |
| 1267 | cb->args[2] = ip_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | return skb->len; |
| 1270 | } |
| 1271 | |
Jianjun Kong | 539afed | 2008-11-03 02:48:48 -0800 | [diff] [blame] | 1272 | static void rtmsg_ifa(int event, struct in_ifaddr *ifa, struct nlmsghdr *nlh, |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 1273 | u32 pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | { |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1275 | struct sk_buff *skb; |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 1276 | u32 seq = nlh ? nlh->nlmsg_seq : 0; |
| 1277 | int err = -ENOBUFS; |
Denis V. Lunev | 4b8aa9a | 2008-01-31 18:47:40 -0800 | [diff] [blame] | 1278 | struct net *net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 1280 | net = dev_net(ifa->ifa_dev->dev); |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 1281 | skb = nlmsg_new(inet_nlmsg_size(), GFP_KERNEL); |
Thomas Graf | 47f6851 | 2006-08-04 23:04:36 -0700 | [diff] [blame] | 1282 | if (skb == NULL) |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 1283 | goto errout; |
| 1284 | |
| 1285 | err = inet_fill_ifaddr(skb, ifa, pid, seq, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 1286 | if (err < 0) { |
| 1287 | /* -EMSGSIZE implies BUG in inet_nlmsg_size() */ |
| 1288 | WARN_ON(err == -EMSGSIZE); |
| 1289 | kfree_skb(skb); |
| 1290 | goto errout; |
| 1291 | } |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 1292 | rtnl_notify(skb, net, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL); |
| 1293 | return; |
Thomas Graf | d6062cb | 2006-08-15 00:33:59 -0700 | [diff] [blame] | 1294 | errout: |
| 1295 | if (err < 0) |
Denis V. Lunev | 4b8aa9a | 2008-01-31 18:47:40 -0800 | [diff] [blame] | 1296 | rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1299 | static size_t inet_get_link_af_size(const struct net_device *dev) |
| 1300 | { |
Eric Dumazet | f7fce74 | 2010-12-01 06:03:06 +0000 | [diff] [blame] | 1301 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1302 | |
| 1303 | if (!in_dev) |
| 1304 | return 0; |
| 1305 | |
| 1306 | return nla_total_size(IPV4_DEVCONF_MAX * 4); /* IFLA_INET_CONF */ |
| 1307 | } |
| 1308 | |
| 1309 | static int inet_fill_link_af(struct sk_buff *skb, const struct net_device *dev) |
| 1310 | { |
Eric Dumazet | f7fce74 | 2010-12-01 06:03:06 +0000 | [diff] [blame] | 1311 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1312 | struct nlattr *nla; |
| 1313 | int i; |
| 1314 | |
| 1315 | if (!in_dev) |
| 1316 | return -ENODATA; |
| 1317 | |
| 1318 | nla = nla_reserve(skb, IFLA_INET_CONF, IPV4_DEVCONF_MAX * 4); |
| 1319 | if (nla == NULL) |
| 1320 | return -EMSGSIZE; |
| 1321 | |
| 1322 | for (i = 0; i < IPV4_DEVCONF_MAX; i++) |
| 1323 | ((u32 *) nla_data(nla))[i] = in_dev->cnf.data[i]; |
| 1324 | |
| 1325 | return 0; |
| 1326 | } |
| 1327 | |
| 1328 | static const struct nla_policy inet_af_policy[IFLA_INET_MAX+1] = { |
| 1329 | [IFLA_INET_CONF] = { .type = NLA_NESTED }, |
| 1330 | }; |
| 1331 | |
Thomas Graf | cf7afbf | 2010-11-22 01:31:54 +0000 | [diff] [blame] | 1332 | static int inet_validate_link_af(const struct net_device *dev, |
| 1333 | const struct nlattr *nla) |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1334 | { |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1335 | struct nlattr *a, *tb[IFLA_INET_MAX+1]; |
| 1336 | int err, rem; |
| 1337 | |
Eric Dumazet | f7fce74 | 2010-12-01 06:03:06 +0000 | [diff] [blame] | 1338 | if (dev && !__in_dev_get_rtnl(dev)) |
Thomas Graf | cf7afbf | 2010-11-22 01:31:54 +0000 | [diff] [blame] | 1339 | return -EAFNOSUPPORT; |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1340 | |
| 1341 | err = nla_parse_nested(tb, IFLA_INET_MAX, nla, inet_af_policy); |
| 1342 | if (err < 0) |
| 1343 | return err; |
| 1344 | |
| 1345 | if (tb[IFLA_INET_CONF]) { |
| 1346 | nla_for_each_nested(a, tb[IFLA_INET_CONF], rem) { |
| 1347 | int cfgid = nla_type(a); |
| 1348 | |
| 1349 | if (nla_len(a) < 4) |
| 1350 | return -EINVAL; |
| 1351 | |
| 1352 | if (cfgid <= 0 || cfgid > IPV4_DEVCONF_MAX) |
| 1353 | return -EINVAL; |
| 1354 | } |
| 1355 | } |
| 1356 | |
Thomas Graf | cf7afbf | 2010-11-22 01:31:54 +0000 | [diff] [blame] | 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla) |
| 1361 | { |
Eric Dumazet | f7fce74 | 2010-12-01 06:03:06 +0000 | [diff] [blame] | 1362 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Thomas Graf | cf7afbf | 2010-11-22 01:31:54 +0000 | [diff] [blame] | 1363 | struct nlattr *a, *tb[IFLA_INET_MAX+1]; |
| 1364 | int rem; |
| 1365 | |
| 1366 | if (!in_dev) |
| 1367 | return -EAFNOSUPPORT; |
| 1368 | |
| 1369 | if (nla_parse_nested(tb, IFLA_INET_MAX, nla, NULL) < 0) |
| 1370 | BUG(); |
| 1371 | |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1372 | if (tb[IFLA_INET_CONF]) { |
| 1373 | nla_for_each_nested(a, tb[IFLA_INET_CONF], rem) |
| 1374 | ipv4_devconf_set(in_dev, nla_type(a), nla_get_u32(a)); |
| 1375 | } |
| 1376 | |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | #ifdef CONFIG_SYSCTL |
| 1381 | |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1382 | static void devinet_copy_dflt_conf(struct net *net, int i) |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1383 | { |
| 1384 | struct net_device *dev; |
| 1385 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1386 | rcu_read_lock(); |
| 1387 | for_each_netdev_rcu(net, dev) { |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1388 | struct in_device *in_dev; |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1389 | |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1390 | in_dev = __in_dev_get_rcu(dev); |
| 1391 | if (in_dev && !test_bit(i, in_dev->cnf.state)) |
Pavel Emelyanov | 9355bbd | 2007-12-16 13:32:16 -0800 | [diff] [blame] | 1392 | in_dev->cnf.data[i] = net->ipv4.devconf_dflt->data[i]; |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1393 | } |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1394 | rcu_read_unlock(); |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1397 | /* called with RTNL locked */ |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1398 | static void inet_forward_change(struct net *net) |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1399 | { |
| 1400 | struct net_device *dev; |
Pavel Emelyanov | 586f121 | 2007-12-16 13:32:48 -0800 | [diff] [blame] | 1401 | int on = IPV4_DEVCONF_ALL(net, FORWARDING); |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1402 | |
Pavel Emelyanov | 586f121 | 2007-12-16 13:32:48 -0800 | [diff] [blame] | 1403 | IPV4_DEVCONF_ALL(net, ACCEPT_REDIRECTS) = !on; |
Pavel Emelyanov | 9355bbd | 2007-12-16 13:32:16 -0800 | [diff] [blame] | 1404 | IPV4_DEVCONF_DFLT(net, FORWARDING) = on; |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1405 | |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1406 | for_each_netdev(net, dev) { |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1407 | struct in_device *in_dev; |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 1408 | if (on) |
| 1409 | dev_disable_lro(dev); |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1410 | rcu_read_lock(); |
| 1411 | in_dev = __in_dev_get_rcu(dev); |
| 1412 | if (in_dev) |
| 1413 | IN_DEV_CONF_SET(in_dev, FORWARDING, on); |
| 1414 | rcu_read_unlock(); |
| 1415 | } |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1418 | static int devinet_conf_proc(ctl_table *ctl, int write, |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 1419 | void __user *buffer, |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1420 | size_t *lenp, loff_t *ppos) |
| 1421 | { |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 1422 | int ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1423 | |
| 1424 | if (write) { |
| 1425 | struct ipv4_devconf *cnf = ctl->extra1; |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1426 | struct net *net = ctl->extra2; |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1427 | int i = (int *)ctl->data - cnf->data; |
| 1428 | |
| 1429 | set_bit(i, cnf->state); |
| 1430 | |
Pavel Emelyanov | 9355bbd | 2007-12-16 13:32:16 -0800 | [diff] [blame] | 1431 | if (cnf == net->ipv4.devconf_dflt) |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1432 | devinet_copy_dflt_conf(net, i); |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | return ret; |
| 1436 | } |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | static int devinet_sysctl_forward(ctl_table *ctl, int write, |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 1439 | void __user *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | size_t *lenp, loff_t *ppos) |
| 1441 | { |
| 1442 | int *valp = ctl->data; |
| 1443 | int val = *valp; |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 1444 | loff_t pos = *ppos; |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 1445 | int ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | if (write && *valp != val) { |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1448 | struct net *net = ctl->extra2; |
| 1449 | |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 1450 | if (valp != &IPV4_DEVCONF_DFLT(net, FORWARDING)) { |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 1451 | if (!rtnl_trylock()) { |
| 1452 | /* Restore the original values before restarting */ |
| 1453 | *valp = val; |
| 1454 | *ppos = pos; |
Eric W. Biederman | 9b8adb5 | 2009-05-13 16:59:21 +0000 | [diff] [blame] | 1455 | return restart_syscall(); |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 1456 | } |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 1457 | if (valp == &IPV4_DEVCONF_ALL(net, FORWARDING)) { |
| 1458 | inet_forward_change(net); |
| 1459 | } else if (*valp) { |
| 1460 | struct ipv4_devconf *cnf = ctl->extra1; |
| 1461 | struct in_device *idev = |
| 1462 | container_of(cnf, struct in_device, cnf); |
| 1463 | dev_disable_lro(idev->dev); |
| 1464 | } |
| 1465 | rtnl_unlock(); |
Denis V. Lunev | 76e6ebf | 2008-07-05 19:00:44 -0700 | [diff] [blame] | 1466 | rt_cache_flush(net, 0); |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 1467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | return ret; |
| 1471 | } |
| 1472 | |
David S. Miller | 323e126 | 2010-12-12 21:55:08 -0800 | [diff] [blame] | 1473 | static int ipv4_doint_and_flush(ctl_table *ctl, int write, |
| 1474 | void __user *buffer, |
| 1475 | size_t *lenp, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | { |
| 1477 | int *valp = ctl->data; |
| 1478 | int val = *valp; |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 1479 | int ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
Denis V. Lunev | 76e6ebf | 2008-07-05 19:00:44 -0700 | [diff] [blame] | 1480 | struct net *net = ctl->extra2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | |
| 1482 | if (write && *valp != val) |
Denis V. Lunev | 76e6ebf | 2008-07-05 19:00:44 -0700 | [diff] [blame] | 1483 | rt_cache_flush(net, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
| 1485 | return ret; |
| 1486 | } |
| 1487 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1488 | #define DEVINET_SYSCTL_ENTRY(attr, name, mval, proc) \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1489 | { \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1490 | .procname = name, \ |
| 1491 | .data = ipv4_devconf.data + \ |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 1492 | IPV4_DEVCONF_ ## attr - 1, \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1493 | .maxlen = sizeof(int), \ |
| 1494 | .mode = mval, \ |
| 1495 | .proc_handler = proc, \ |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1496 | .extra1 = &ipv4_devconf, \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | #define DEVINET_SYSCTL_RW_ENTRY(attr, name) \ |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1500 | DEVINET_SYSCTL_ENTRY(attr, name, 0644, devinet_conf_proc) |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1501 | |
| 1502 | #define DEVINET_SYSCTL_RO_ENTRY(attr, name) \ |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1503 | DEVINET_SYSCTL_ENTRY(attr, name, 0444, devinet_conf_proc) |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1504 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1505 | #define DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, proc) \ |
| 1506 | DEVINET_SYSCTL_ENTRY(attr, name, 0644, proc) |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1507 | |
| 1508 | #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \ |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1509 | DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush) |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | static struct devinet_sysctl_table { |
| 1512 | struct ctl_table_header *sysctl_header; |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 1513 | struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX]; |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1514 | char *dev_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | } devinet_sysctl = { |
| 1516 | .devinet_vars = { |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1517 | DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding", |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1518 | devinet_sysctl_forward), |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1519 | DEVINET_SYSCTL_RO_ENTRY(MC_FORWARDING, "mc_forwarding"), |
| 1520 | |
| 1521 | DEVINET_SYSCTL_RW_ENTRY(ACCEPT_REDIRECTS, "accept_redirects"), |
| 1522 | DEVINET_SYSCTL_RW_ENTRY(SECURE_REDIRECTS, "secure_redirects"), |
| 1523 | DEVINET_SYSCTL_RW_ENTRY(SHARED_MEDIA, "shared_media"), |
| 1524 | DEVINET_SYSCTL_RW_ENTRY(RP_FILTER, "rp_filter"), |
| 1525 | DEVINET_SYSCTL_RW_ENTRY(SEND_REDIRECTS, "send_redirects"), |
| 1526 | DEVINET_SYSCTL_RW_ENTRY(ACCEPT_SOURCE_ROUTE, |
| 1527 | "accept_source_route"), |
Patrick McHardy | 8153a10 | 2009-12-03 01:25:58 +0000 | [diff] [blame] | 1528 | DEVINET_SYSCTL_RW_ENTRY(ACCEPT_LOCAL, "accept_local"), |
Jamal Hadi Salim | 28f6aee | 2009-12-25 17:30:22 -0800 | [diff] [blame] | 1529 | DEVINET_SYSCTL_RW_ENTRY(SRC_VMARK, "src_valid_mark"), |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1530 | DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP, "proxy_arp"), |
| 1531 | DEVINET_SYSCTL_RW_ENTRY(MEDIUM_ID, "medium_id"), |
| 1532 | DEVINET_SYSCTL_RW_ENTRY(BOOTP_RELAY, "bootp_relay"), |
| 1533 | DEVINET_SYSCTL_RW_ENTRY(LOG_MARTIANS, "log_martians"), |
| 1534 | DEVINET_SYSCTL_RW_ENTRY(TAG, "tag"), |
| 1535 | DEVINET_SYSCTL_RW_ENTRY(ARPFILTER, "arp_filter"), |
| 1536 | DEVINET_SYSCTL_RW_ENTRY(ARP_ANNOUNCE, "arp_announce"), |
| 1537 | DEVINET_SYSCTL_RW_ENTRY(ARP_IGNORE, "arp_ignore"), |
| 1538 | DEVINET_SYSCTL_RW_ENTRY(ARP_ACCEPT, "arp_accept"), |
Stephen Hemminger | eefef1c | 2009-02-01 01:04:33 -0800 | [diff] [blame] | 1539 | DEVINET_SYSCTL_RW_ENTRY(ARP_NOTIFY, "arp_notify"), |
Jesper Dangaard Brouer | 6532414 | 2010-01-05 05:50:47 +0000 | [diff] [blame] | 1540 | DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP_PVLAN, "proxy_arp_pvlan"), |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 1541 | |
| 1542 | DEVINET_SYSCTL_FLUSHING_ENTRY(NOXFRM, "disable_xfrm"), |
| 1543 | DEVINET_SYSCTL_FLUSHING_ENTRY(NOPOLICY, "disable_policy"), |
| 1544 | DEVINET_SYSCTL_FLUSHING_ENTRY(FORCE_IGMP_VERSION, |
| 1545 | "force_igmp_version"), |
| 1546 | DEVINET_SYSCTL_FLUSHING_ENTRY(PROMOTE_SECONDARIES, |
| 1547 | "promote_secondaries"), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | }; |
| 1550 | |
Pavel Emelyanov | ea40b32 | 2007-12-16 13:30:07 -0800 | [diff] [blame] | 1551 | static int __devinet_sysctl_register(struct net *net, char *dev_name, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1552 | struct ipv4_devconf *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | { |
| 1554 | int i; |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1555 | struct devinet_sysctl_table *t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1557 | #define DEVINET_CTL_PATH_DEV 3 |
| 1558 | |
| 1559 | struct ctl_path devinet_ctl_path[] = { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1560 | { .procname = "net", }, |
| 1561 | { .procname = "ipv4", }, |
| 1562 | { .procname = "conf", }, |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1563 | { /* to be set */ }, |
| 1564 | { }, |
| 1565 | }; |
| 1566 | |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1567 | t = kmemdup(&devinet_sysctl, sizeof(*t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | if (!t) |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1569 | goto out; |
| 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) { |
| 1572 | t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf; |
Herbert Xu | 31be308 | 2007-06-04 23:35:37 -0700 | [diff] [blame] | 1573 | t->devinet_vars[i].extra1 = p; |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1574 | t->devinet_vars[i].extra2 = net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1577 | /* |
| 1578 | * Make a copy of dev_name, because '.procname' is regarded as const |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | * by sysctl and we wouldn't want anyone to change it under our feet |
| 1580 | * (see SIOCSIFNAME). |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1581 | */ |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1582 | t->dev_name = kstrdup(dev_name, GFP_KERNEL); |
| 1583 | if (!t->dev_name) |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1584 | goto free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1586 | devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1588 | t->sysctl_header = register_net_sysctl_table(net, devinet_ctl_path, |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1589 | t->devinet_vars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | if (!t->sysctl_header) |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1591 | goto free_procname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
| 1593 | p->sysctl = t; |
Pavel Emelyanov | ea40b32 | 2007-12-16 13:30:07 -0800 | [diff] [blame] | 1594 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1596 | free_procname: |
Pavel Emelyanov | bfada69 | 2007-12-02 00:57:08 +1100 | [diff] [blame] | 1597 | kfree(t->dev_name); |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1598 | free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | kfree(t); |
Pavel Emelyanov | 9fa8964 | 2007-12-02 00:17:46 +1100 | [diff] [blame] | 1600 | out: |
Pavel Emelyanov | ea40b32 | 2007-12-16 13:30:07 -0800 | [diff] [blame] | 1601 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 1604 | static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf) |
| 1605 | { |
| 1606 | struct devinet_sysctl_table *t = cnf->sysctl; |
| 1607 | |
| 1608 | if (t == NULL) |
| 1609 | return; |
| 1610 | |
| 1611 | cnf->sysctl = NULL; |
| 1612 | unregister_sysctl_table(t->sysctl_header); |
| 1613 | kfree(t->dev_name); |
| 1614 | kfree(t); |
| 1615 | } |
| 1616 | |
Pavel Emelyanov | 66f27a5 | 2007-12-02 00:55:54 +1100 | [diff] [blame] | 1617 | static void devinet_sysctl_register(struct in_device *idev) |
| 1618 | { |
Eric W. Biederman | 54716e3 | 2010-02-14 03:27:03 +0000 | [diff] [blame] | 1619 | neigh_sysctl_register(idev->dev, idev->arp_parms, "ipv4", NULL); |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 1620 | __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1621 | &idev->cnf); |
Pavel Emelyanov | 66f27a5 | 2007-12-02 00:55:54 +1100 | [diff] [blame] | 1622 | } |
| 1623 | |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 1624 | static void devinet_sysctl_unregister(struct in_device *idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | { |
Pavel Emelyanov | 51602b2 | 2007-12-11 02:17:40 -0800 | [diff] [blame] | 1626 | __devinet_sysctl_unregister(&idev->cnf); |
| 1627 | neigh_sysctl_unregister(idev->arp_parms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1630 | static struct ctl_table ctl_forward_entry[] = { |
| 1631 | { |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1632 | .procname = "ip_forward", |
| 1633 | .data = &ipv4_devconf.data[ |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 1634 | IPV4_DEVCONF_FORWARDING - 1], |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1635 | .maxlen = sizeof(int), |
| 1636 | .mode = 0644, |
| 1637 | .proc_handler = devinet_sysctl_forward, |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1638 | .extra1 = &ipv4_devconf, |
Pavel Emelyanov | c0ce9fb | 2007-12-16 13:31:14 -0800 | [diff] [blame] | 1639 | .extra2 = &init_net, |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1640 | }, |
| 1641 | { }, |
| 1642 | }; |
| 1643 | |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1644 | static __net_initdata struct ctl_path net_ipv4_path[] = { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1645 | { .procname = "net", }, |
| 1646 | { .procname = "ipv4", }, |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1647 | { }, |
| 1648 | }; |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1649 | #endif |
Pavel Emelyanov | 68dd299 | 2007-12-05 01:44:58 -0800 | [diff] [blame] | 1650 | |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1651 | static __net_init int devinet_init_net(struct net *net) |
| 1652 | { |
| 1653 | int err; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1654 | struct ipv4_devconf *all, *dflt; |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1655 | #ifdef CONFIG_SYSCTL |
| 1656 | struct ctl_table *tbl = ctl_forward_entry; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1657 | struct ctl_table_header *forw_hdr; |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1658 | #endif |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1659 | |
| 1660 | err = -ENOMEM; |
| 1661 | all = &ipv4_devconf; |
| 1662 | dflt = &ipv4_devconf_dflt; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1663 | |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 1664 | if (!net_eq(net, &init_net)) { |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1665 | all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL); |
| 1666 | if (all == NULL) |
| 1667 | goto err_alloc_all; |
| 1668 | |
| 1669 | dflt = kmemdup(dflt, sizeof(ipv4_devconf_dflt), GFP_KERNEL); |
| 1670 | if (dflt == NULL) |
| 1671 | goto err_alloc_dflt; |
| 1672 | |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1673 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1674 | tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL); |
| 1675 | if (tbl == NULL) |
| 1676 | goto err_alloc_ctl; |
| 1677 | |
Eric W. Biederman | 0229168 | 2010-02-14 03:25:51 +0000 | [diff] [blame] | 1678 | tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1]; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1679 | tbl[0].extra1 = all; |
| 1680 | tbl[0].extra2 = net; |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1681 | #endif |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | #ifdef CONFIG_SYSCTL |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1685 | err = __devinet_sysctl_register(net, "all", all); |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1686 | if (err < 0) |
| 1687 | goto err_reg_all; |
| 1688 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 1689 | err = __devinet_sysctl_register(net, "default", dflt); |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1690 | if (err < 0) |
| 1691 | goto err_reg_dflt; |
| 1692 | |
| 1693 | err = -ENOMEM; |
| 1694 | forw_hdr = register_net_sysctl_table(net, net_ipv4_path, tbl); |
| 1695 | if (forw_hdr == NULL) |
| 1696 | goto err_reg_ctl; |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1697 | net->ipv4.forw_hdr = forw_hdr; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1698 | #endif |
| 1699 | |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1700 | net->ipv4.devconf_all = all; |
| 1701 | net->ipv4.devconf_dflt = dflt; |
| 1702 | return 0; |
| 1703 | |
| 1704 | #ifdef CONFIG_SYSCTL |
| 1705 | err_reg_ctl: |
| 1706 | __devinet_sysctl_unregister(dflt); |
| 1707 | err_reg_dflt: |
| 1708 | __devinet_sysctl_unregister(all); |
| 1709 | err_reg_all: |
| 1710 | if (tbl != ctl_forward_entry) |
| 1711 | kfree(tbl); |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1712 | err_alloc_ctl: |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1713 | #endif |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1714 | if (dflt != &ipv4_devconf_dflt) |
| 1715 | kfree(dflt); |
| 1716 | err_alloc_dflt: |
| 1717 | if (all != &ipv4_devconf) |
| 1718 | kfree(all); |
| 1719 | err_alloc_all: |
| 1720 | return err; |
| 1721 | } |
| 1722 | |
| 1723 | static __net_exit void devinet_exit_net(struct net *net) |
| 1724 | { |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1725 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1726 | struct ctl_table *tbl; |
| 1727 | |
| 1728 | tbl = net->ipv4.forw_hdr->ctl_table_arg; |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1729 | unregister_net_sysctl_table(net->ipv4.forw_hdr); |
| 1730 | __devinet_sysctl_unregister(net->ipv4.devconf_dflt); |
| 1731 | __devinet_sysctl_unregister(net->ipv4.devconf_all); |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1732 | kfree(tbl); |
Eric Dumazet | 2a75de0 | 2008-01-05 23:08:49 -0800 | [diff] [blame] | 1733 | #endif |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1734 | kfree(net->ipv4.devconf_dflt); |
| 1735 | kfree(net->ipv4.devconf_all); |
| 1736 | } |
| 1737 | |
| 1738 | static __net_initdata struct pernet_operations devinet_ops = { |
| 1739 | .init = devinet_init_net, |
| 1740 | .exit = devinet_exit_net, |
| 1741 | }; |
| 1742 | |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1743 | static struct rtnl_af_ops inet_af_ops = { |
| 1744 | .family = AF_INET, |
| 1745 | .fill_link_af = inet_fill_link_af, |
| 1746 | .get_link_af_size = inet_get_link_af_size, |
Thomas Graf | cf7afbf | 2010-11-22 01:31:54 +0000 | [diff] [blame] | 1747 | .validate_link_af = inet_validate_link_af, |
| 1748 | .set_link_af = inet_set_link_af, |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1749 | }; |
| 1750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | void __init devinet_init(void) |
| 1752 | { |
David S. Miller | fd23c3b | 2011-02-18 12:42:28 -0800 | [diff] [blame^] | 1753 | int i; |
| 1754 | |
| 1755 | for (i = 0; i < IN4_ADDR_HSIZE; i++) |
| 1756 | INIT_HLIST_HEAD(&inet_addr_lst[i]); |
| 1757 | |
Pavel Emelyanov | 752d14d | 2007-12-16 13:31:47 -0800 | [diff] [blame] | 1758 | register_pernet_subsys(&devinet_ops); |
| 1759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | register_gifconf(PF_INET, inet_gifconf); |
| 1761 | register_netdevice_notifier(&ip_netdev_notifier); |
Thomas Graf | 63f3444 | 2007-03-22 11:55:17 -0700 | [diff] [blame] | 1762 | |
Thomas Graf | 9f0f727 | 2010-11-16 04:32:48 +0000 | [diff] [blame] | 1763 | rtnl_af_register(&inet_af_ops); |
| 1764 | |
Thomas Graf | 63f3444 | 2007-03-22 11:55:17 -0700 | [diff] [blame] | 1765 | rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL); |
| 1766 | rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL); |
| 1767 | rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |