Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IPv6 Address [auto]configuration |
| 3 | * Linux INET6 implementation |
| 4 | * |
| 5 | * Authors: |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 6 | * Pedro Roque <roque@di.fc.ul.pt> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
| 8 | * |
| 9 | * $Id: addrconf.c,v 1.69 2001/10/31 21:55:54 davem Exp $ |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version |
| 14 | * 2 of the License, or (at your option) any later version. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Changes: |
| 19 | * |
| 20 | * Janos Farkas : delete timer on ifdown |
| 21 | * <chexum@bankinf.banki.hu> |
| 22 | * Andi Kleen : kill double kfree on module |
| 23 | * unload. |
| 24 | * Maciej W. Rozycki : FDDI support |
| 25 | * sekiya@USAGI : Don't send too many RS |
| 26 | * packets. |
| 27 | * yoshfuji@USAGI : Fixed interval between DAD |
| 28 | * packets. |
| 29 | * YOSHIFUJI Hideaki @USAGI : improved accuracy of |
| 30 | * address validation timer. |
| 31 | * YOSHIFUJI Hideaki @USAGI : Privacy Extensions (RFC3041) |
| 32 | * support. |
| 33 | * Yuji SEKIYA @USAGI : Don't assign a same IPv6 |
| 34 | * address on a same interface. |
| 35 | * YOSHIFUJI Hideaki @USAGI : ARCnet support |
| 36 | * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to |
| 37 | * seq_file. |
YOSHIFUJI Hideaki | b1cacb6 | 2005-11-08 09:38:12 -0800 | [diff] [blame] | 38 | * YOSHIFUJI Hideaki @USAGI : improved source address |
| 39 | * selection; consider scope, |
| 40 | * status etc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | */ |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/errno.h> |
| 44 | #include <linux/types.h> |
| 45 | #include <linux/socket.h> |
| 46 | #include <linux/sockios.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/net.h> |
| 48 | #include <linux/in6.h> |
| 49 | #include <linux/netdevice.h> |
Thomas Graf | 1823730 | 2006-08-04 23:04:54 -0700 | [diff] [blame] | 50 | #include <linux/if_addr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/if_arp.h> |
| 52 | #include <linux/if_arcnet.h> |
| 53 | #include <linux/if_infiniband.h> |
| 54 | #include <linux/route.h> |
| 55 | #include <linux/inetdevice.h> |
| 56 | #include <linux/init.h> |
| 57 | #ifdef CONFIG_SYSCTL |
| 58 | #include <linux/sysctl.h> |
| 59 | #endif |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 60 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <linux/delay.h> |
| 62 | #include <linux/notifier.h> |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 63 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | #include <net/sock.h> |
| 66 | #include <net/snmp.h> |
| 67 | |
| 68 | #include <net/ipv6.h> |
| 69 | #include <net/protocol.h> |
| 70 | #include <net/ndisc.h> |
| 71 | #include <net/ip6_route.h> |
| 72 | #include <net/addrconf.h> |
| 73 | #include <net/tcp.h> |
| 74 | #include <net/ip.h> |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 75 | #include <net/netlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include <linux/if_tunnel.h> |
| 77 | #include <linux/rtnetlink.h> |
| 78 | |
| 79 | #ifdef CONFIG_IPV6_PRIVACY |
| 80 | #include <linux/random.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #endif |
| 82 | |
| 83 | #include <asm/uaccess.h> |
| 84 | |
| 85 | #include <linux/proc_fs.h> |
| 86 | #include <linux/seq_file.h> |
| 87 | |
| 88 | /* Set to 3 to get tracing... */ |
| 89 | #define ACONF_DEBUG 2 |
| 90 | |
| 91 | #if ACONF_DEBUG >= 3 |
| 92 | #define ADBG(x) printk x |
| 93 | #else |
| 94 | #define ADBG(x) |
| 95 | #endif |
| 96 | |
| 97 | #define INFINITY_LIFE_TIME 0xFFFFFFFF |
| 98 | #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b))) |
| 99 | |
| 100 | #ifdef CONFIG_SYSCTL |
| 101 | static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p); |
| 102 | static void addrconf_sysctl_unregister(struct ipv6_devconf *p); |
| 103 | #endif |
| 104 | |
| 105 | #ifdef CONFIG_IPV6_PRIVACY |
| 106 | static int __ipv6_regen_rndid(struct inet6_dev *idev); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 107 | static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static void ipv6_regen_rndid(unsigned long data); |
| 109 | |
| 110 | static int desync_factor = MAX_DESYNC_FACTOR * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #endif |
| 112 | |
| 113 | static int ipv6_count_addresses(struct inet6_dev *idev); |
| 114 | |
| 115 | /* |
| 116 | * Configured unicast address hash table |
| 117 | */ |
| 118 | static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE]; |
| 119 | static DEFINE_RWLOCK(addrconf_hash_lock); |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | static void addrconf_verify(unsigned long); |
| 122 | |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 123 | static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static DEFINE_SPINLOCK(addrconf_verify_lock); |
| 125 | |
| 126 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp); |
| 127 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); |
| 128 | |
| 129 | static int addrconf_ifdown(struct net_device *dev, int how); |
| 130 | |
Jamal Hadi Salim | e431b8c | 2005-06-18 22:55:31 -0700 | [diff] [blame] | 131 | static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static void addrconf_dad_timer(unsigned long data); |
| 133 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp); |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 134 | static void addrconf_dad_run(struct inet6_dev *idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static void addrconf_rs_timer(unsigned long data); |
| 136 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa); |
| 137 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa); |
| 138 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 139 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | struct prefix_info *pinfo); |
| 141 | static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev); |
| 142 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 143 | static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 145 | struct ipv6_devconf ipv6_devconf __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | .forwarding = 0, |
| 147 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 148 | .mtu6 = IPV6_MIN_MTU, |
| 149 | .accept_ra = 1, |
| 150 | .accept_redirects = 1, |
| 151 | .autoconf = 1, |
| 152 | .force_mld_version = 0, |
| 153 | .dad_transmits = 1, |
| 154 | .rtr_solicits = MAX_RTR_SOLICITATIONS, |
| 155 | .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL, |
| 156 | .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY, |
| 157 | #ifdef CONFIG_IPV6_PRIVACY |
| 158 | .use_tempaddr = 0, |
| 159 | .temp_valid_lft = TEMP_VALID_LIFETIME, |
| 160 | .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, |
| 161 | .regen_max_retry = REGEN_MAX_RETRY, |
| 162 | .max_desync_factor = MAX_DESYNC_FACTOR, |
| 163 | #endif |
| 164 | .max_addresses = IPV6_MAX_ADDRESSES, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 165 | .accept_ra_defrtr = 1, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 166 | .accept_ra_pinfo = 1, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 167 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 168 | .accept_ra_rtr_pref = 1, |
YOSHIFUJI Hideaki | 52e1635 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 169 | .rtr_probe_interval = 60 * HZ, |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 170 | #ifdef CONFIG_IPV6_ROUTE_INFO |
| 171 | .accept_ra_rt_info_max_plen = 0, |
| 172 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 173 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 174 | .proxy_ndp = 0, |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 175 | .accept_source_route = 0, /* we do not accept RH0 by default. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 178 | static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | .forwarding = 0, |
| 180 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 181 | .mtu6 = IPV6_MIN_MTU, |
| 182 | .accept_ra = 1, |
| 183 | .accept_redirects = 1, |
| 184 | .autoconf = 1, |
| 185 | .dad_transmits = 1, |
| 186 | .rtr_solicits = MAX_RTR_SOLICITATIONS, |
| 187 | .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL, |
| 188 | .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY, |
| 189 | #ifdef CONFIG_IPV6_PRIVACY |
| 190 | .use_tempaddr = 0, |
| 191 | .temp_valid_lft = TEMP_VALID_LIFETIME, |
| 192 | .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, |
| 193 | .regen_max_retry = REGEN_MAX_RETRY, |
| 194 | .max_desync_factor = MAX_DESYNC_FACTOR, |
| 195 | #endif |
| 196 | .max_addresses = IPV6_MAX_ADDRESSES, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 197 | .accept_ra_defrtr = 1, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 198 | .accept_ra_pinfo = 1, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 199 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 200 | .accept_ra_rtr_pref = 1, |
YOSHIFUJI Hideaki | 52e1635 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 201 | .rtr_probe_interval = 60 * HZ, |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 202 | #ifdef CONFIG_IPV6_ROUTE_INFO |
| 203 | .accept_ra_rt_info_max_plen = 0, |
| 204 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 205 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 206 | .proxy_ndp = 0, |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 207 | .accept_source_route = 0, /* we do not accept RH0 by default. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */ |
| 211 | #if 0 |
| 212 | const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; |
| 213 | #endif |
| 214 | const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | static void addrconf_del_timer(struct inet6_ifaddr *ifp) |
| 217 | { |
| 218 | if (del_timer(&ifp->timer)) |
| 219 | __in6_ifa_put(ifp); |
| 220 | } |
| 221 | |
| 222 | enum addrconf_timer_t |
| 223 | { |
| 224 | AC_NONE, |
| 225 | AC_DAD, |
| 226 | AC_RS, |
| 227 | }; |
| 228 | |
| 229 | static void addrconf_mod_timer(struct inet6_ifaddr *ifp, |
| 230 | enum addrconf_timer_t what, |
| 231 | unsigned long when) |
| 232 | { |
| 233 | if (!del_timer(&ifp->timer)) |
| 234 | in6_ifa_hold(ifp); |
| 235 | |
| 236 | switch (what) { |
| 237 | case AC_DAD: |
| 238 | ifp->timer.function = addrconf_dad_timer; |
| 239 | break; |
| 240 | case AC_RS: |
| 241 | ifp->timer.function = addrconf_rs_timer; |
| 242 | break; |
| 243 | default:; |
| 244 | } |
| 245 | ifp->timer.expires = jiffies + when; |
| 246 | add_timer(&ifp->timer); |
| 247 | } |
| 248 | |
| 249 | /* Nobody refers to this device, we may destroy it. */ |
| 250 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 251 | static void in6_dev_finish_destroy_rcu(struct rcu_head *head) |
| 252 | { |
| 253 | struct inet6_dev *idev = container_of(head, struct inet6_dev, rcu); |
| 254 | kfree(idev); |
| 255 | } |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | void in6_dev_finish_destroy(struct inet6_dev *idev) |
| 258 | { |
| 259 | struct net_device *dev = idev->dev; |
| 260 | BUG_TRAP(idev->addr_list==NULL); |
| 261 | BUG_TRAP(idev->mc_list==NULL); |
| 262 | #ifdef NET_REFCNT_DEBUG |
| 263 | printk(KERN_DEBUG "in6_dev_finish_destroy: %s\n", dev ? dev->name : "NIL"); |
| 264 | #endif |
| 265 | dev_put(dev); |
| 266 | if (!idev->dead) { |
| 267 | printk("Freeing alive inet6 device %p\n", idev); |
| 268 | return; |
| 269 | } |
| 270 | snmp6_free_dev(idev); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 271 | call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 274 | EXPORT_SYMBOL(in6_dev_finish_destroy); |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | static struct inet6_dev * ipv6_add_dev(struct net_device *dev) |
| 277 | { |
| 278 | struct inet6_dev *ndev; |
YOSHIFUJI Hideaki | d88ae4c | 2007-01-14 21:48:40 -0800 | [diff] [blame] | 279 | struct in6_addr maddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | ASSERT_RTNL(); |
| 282 | |
| 283 | if (dev->mtu < IPV6_MIN_MTU) |
| 284 | return NULL; |
| 285 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 286 | ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 288 | if (ndev == NULL) |
| 289 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 291 | rwlock_init(&ndev->lock); |
| 292 | ndev->dev = dev; |
| 293 | memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf)); |
| 294 | ndev->cnf.mtu6 = dev->mtu; |
| 295 | ndev->cnf.sysctl = NULL; |
| 296 | ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); |
| 297 | if (ndev->nd_parms == NULL) { |
| 298 | kfree(ndev); |
| 299 | return NULL; |
| 300 | } |
| 301 | /* We refer to the device */ |
| 302 | dev_hold(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 304 | if (snmp6_alloc_dev(ndev) < 0) { |
| 305 | ADBG((KERN_WARNING |
| 306 | "%s(): cannot allocate memory for statistics; dev=%s.\n", |
| 307 | __FUNCTION__, dev->name)); |
| 308 | neigh_parms_release(&nd_tbl, ndev->nd_parms); |
| 309 | ndev->dead = 1; |
| 310 | in6_dev_finish_destroy(ndev); |
| 311 | return NULL; |
| 312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 314 | if (snmp6_register_dev(ndev) < 0) { |
| 315 | ADBG((KERN_WARNING |
| 316 | "%s(): cannot create /proc/net/dev_snmp6/%s\n", |
| 317 | __FUNCTION__, dev->name)); |
| 318 | neigh_parms_release(&nd_tbl, ndev->nd_parms); |
| 319 | ndev->dead = 1; |
| 320 | in6_dev_finish_destroy(ndev); |
| 321 | return NULL; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 324 | /* One reference from device. We must do this before |
| 325 | * we invoke __ipv6_regen_rndid(). |
| 326 | */ |
| 327 | in6_dev_hold(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | #ifdef CONFIG_IPV6_PRIVACY |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 330 | init_timer(&ndev->regen_timer); |
| 331 | ndev->regen_timer.function = ipv6_regen_rndid; |
| 332 | ndev->regen_timer.data = (unsigned long) ndev; |
| 333 | if ((dev->flags&IFF_LOOPBACK) || |
| 334 | dev->type == ARPHRD_TUNNEL || |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 335 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
| 336 | dev->type == ARPHRD_SIT || |
| 337 | #endif |
| 338 | dev->type == ARPHRD_NONE) { |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 339 | printk(KERN_INFO |
| 340 | "%s: Disabled Privacy Extensions\n", |
| 341 | dev->name); |
| 342 | ndev->cnf.use_tempaddr = -1; |
| 343 | } else { |
| 344 | in6_dev_hold(ndev); |
| 345 | ipv6_regen_rndid((unsigned long) ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 347 | #endif |
| 348 | |
Herbert Xu | 53aadcc | 2007-03-27 14:31:52 -0700 | [diff] [blame] | 349 | if (netif_running(dev) && netif_carrier_ok(dev)) |
| 350 | ndev->if_flags |= IF_READY; |
| 351 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 352 | ipv6_mc_init_dev(ndev); |
| 353 | ndev->tstamp = jiffies; |
| 354 | #ifdef CONFIG_SYSCTL |
| 355 | neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6, |
| 356 | NET_IPV6_NEIGH, "ipv6", |
| 357 | &ndisc_ifinfo_sysctl_change, |
| 358 | NULL); |
| 359 | addrconf_sysctl_register(ndev, &ndev->cnf); |
| 360 | #endif |
David L Stevens | 30c4cf5 | 2007-01-04 12:31:14 -0800 | [diff] [blame] | 361 | /* protected by rtnl_lock */ |
| 362 | rcu_assign_pointer(dev->ip6_ptr, ndev); |
YOSHIFUJI Hideaki | d88ae4c | 2007-01-14 21:48:40 -0800 | [diff] [blame] | 363 | |
| 364 | /* Join all-node multicast group */ |
| 365 | ipv6_addr_all_nodes(&maddr); |
| 366 | ipv6_dev_mc_inc(dev, &maddr); |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return ndev; |
| 369 | } |
| 370 | |
| 371 | static struct inet6_dev * ipv6_find_idev(struct net_device *dev) |
| 372 | { |
| 373 | struct inet6_dev *idev; |
| 374 | |
| 375 | ASSERT_RTNL(); |
| 376 | |
| 377 | if ((idev = __in6_dev_get(dev)) == NULL) { |
| 378 | if ((idev = ipv6_add_dev(dev)) == NULL) |
| 379 | return NULL; |
| 380 | } |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if (dev->flags&IFF_UP) |
| 383 | ipv6_mc_up(idev); |
| 384 | return idev; |
| 385 | } |
| 386 | |
| 387 | #ifdef CONFIG_SYSCTL |
| 388 | static void dev_forward_change(struct inet6_dev *idev) |
| 389 | { |
| 390 | struct net_device *dev; |
| 391 | struct inet6_ifaddr *ifa; |
| 392 | struct in6_addr addr; |
| 393 | |
| 394 | if (!idev) |
| 395 | return; |
| 396 | dev = idev->dev; |
| 397 | if (dev && (dev->flags & IFF_MULTICAST)) { |
| 398 | ipv6_addr_all_routers(&addr); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | if (idev->cnf.forwarding) |
| 401 | ipv6_dev_mc_inc(dev, &addr); |
| 402 | else |
| 403 | ipv6_dev_mc_dec(dev, &addr); |
| 404 | } |
| 405 | for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) { |
Michal Wrobel | 2c12a74 | 2007-02-26 15:36:10 -0800 | [diff] [blame] | 406 | if (ifa->flags&IFA_F_TENTATIVE) |
| 407 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | if (idev->cnf.forwarding) |
| 409 | addrconf_join_anycast(ifa); |
| 410 | else |
| 411 | addrconf_leave_anycast(ifa); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| 416 | static void addrconf_forward_change(void) |
| 417 | { |
| 418 | struct net_device *dev; |
| 419 | struct inet6_dev *idev; |
| 420 | |
| 421 | read_lock(&dev_base_lock); |
| 422 | for (dev=dev_base; dev; dev=dev->next) { |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 423 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | idev = __in6_dev_get(dev); |
| 425 | if (idev) { |
| 426 | int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding); |
| 427 | idev->cnf.forwarding = ipv6_devconf.forwarding; |
| 428 | if (changed) |
| 429 | dev_forward_change(idev); |
| 430 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 431 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | read_unlock(&dev_base_lock); |
| 434 | } |
| 435 | #endif |
| 436 | |
| 437 | /* Nobody refers to this ifaddr, destroy it */ |
| 438 | |
| 439 | void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) |
| 440 | { |
| 441 | BUG_TRAP(ifp->if_next==NULL); |
| 442 | BUG_TRAP(ifp->lst_next==NULL); |
| 443 | #ifdef NET_REFCNT_DEBUG |
| 444 | printk(KERN_DEBUG "inet6_ifa_finish_destroy\n"); |
| 445 | #endif |
| 446 | |
| 447 | in6_dev_put(ifp->idev); |
| 448 | |
| 449 | if (del_timer(&ifp->timer)) |
| 450 | printk("Timer is still running, when freeing ifa=%p\n", ifp); |
| 451 | |
| 452 | if (!ifp->dead) { |
| 453 | printk("Freeing alive inet6 address %p\n", ifp); |
| 454 | return; |
| 455 | } |
| 456 | dst_release(&ifp->rt->u.dst); |
| 457 | |
| 458 | kfree(ifp); |
| 459 | } |
| 460 | |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 461 | static void |
| 462 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) |
| 463 | { |
| 464 | struct inet6_ifaddr *ifa, **ifap; |
YOSHIFUJI Hideaki | 8a6ce0c | 2006-07-11 13:05:30 -0700 | [diff] [blame] | 465 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * Each device address list is sorted in order of scope - |
| 469 | * global before linklocal. |
| 470 | */ |
| 471 | for (ifap = &idev->addr_list; (ifa = *ifap) != NULL; |
| 472 | ifap = &ifa->if_next) { |
YOSHIFUJI Hideaki | 8a6ce0c | 2006-07-11 13:05:30 -0700 | [diff] [blame] | 473 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 474 | break; |
| 475 | } |
| 476 | |
| 477 | ifp->if_next = *ifap; |
| 478 | *ifap = ifp; |
| 479 | } |
| 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | /* On success it returns ifp with increased reference count */ |
| 482 | |
| 483 | static struct inet6_ifaddr * |
| 484 | ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, |
Jamal Hadi Salim | e431b8c | 2005-06-18 22:55:31 -0700 | [diff] [blame] | 485 | int scope, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | struct inet6_ifaddr *ifa = NULL; |
| 488 | struct rt6_info *rt; |
| 489 | int hash; |
| 490 | int err = 0; |
| 491 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 492 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (idev->dead) { |
| 494 | err = -ENODEV; /*XXX*/ |
| 495 | goto out2; |
| 496 | } |
| 497 | |
| 498 | write_lock(&addrconf_hash_lock); |
| 499 | |
| 500 | /* Ignore adding duplicate addresses on an interface */ |
| 501 | if (ipv6_chk_same_addr(addr, idev->dev)) { |
| 502 | ADBG(("ipv6_add_addr: already assigned\n")); |
| 503 | err = -EEXIST; |
| 504 | goto out; |
| 505 | } |
| 506 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 507 | ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | if (ifa == NULL) { |
| 510 | ADBG(("ipv6_add_addr: malloc failed\n")); |
| 511 | err = -ENOBUFS; |
| 512 | goto out; |
| 513 | } |
| 514 | |
| 515 | rt = addrconf_dst_alloc(idev, addr, 0); |
| 516 | if (IS_ERR(rt)) { |
| 517 | err = PTR_ERR(rt); |
| 518 | goto out; |
| 519 | } |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | ipv6_addr_copy(&ifa->addr, addr); |
| 522 | |
| 523 | spin_lock_init(&ifa->lock); |
| 524 | init_timer(&ifa->timer); |
| 525 | ifa->timer.data = (unsigned long) ifa; |
| 526 | ifa->scope = scope; |
| 527 | ifa->prefix_len = pfxlen; |
| 528 | ifa->flags = flags | IFA_F_TENTATIVE; |
| 529 | ifa->cstamp = ifa->tstamp = jiffies; |
| 530 | |
Keir Fraser | 57f5f54 | 2006-08-29 02:43:49 -0700 | [diff] [blame] | 531 | ifa->rt = rt; |
| 532 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 533 | /* |
| 534 | * part one of RFC 4429, section 3.3 |
| 535 | * We should not configure an address as |
| 536 | * optimistic if we do not yet know the link |
| 537 | * layer address of our nexhop router |
| 538 | */ |
| 539 | |
| 540 | if (rt->rt6i_nexthop == NULL) |
| 541 | ifa->flags &= ~IFA_F_OPTIMISTIC; |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | ifa->idev = idev; |
| 544 | in6_dev_hold(idev); |
| 545 | /* For caller */ |
| 546 | in6_ifa_hold(ifa); |
| 547 | |
| 548 | /* Add to big hash table */ |
| 549 | hash = ipv6_addr_hash(addr); |
| 550 | |
| 551 | ifa->lst_next = inet6_addr_lst[hash]; |
| 552 | inet6_addr_lst[hash] = ifa; |
| 553 | in6_ifa_hold(ifa); |
| 554 | write_unlock(&addrconf_hash_lock); |
| 555 | |
| 556 | write_lock(&idev->lock); |
| 557 | /* Add to inet6_dev unicast addr list. */ |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 558 | ipv6_link_dev_addr(idev, ifa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | #ifdef CONFIG_IPV6_PRIVACY |
| 561 | if (ifa->flags&IFA_F_TEMPORARY) { |
| 562 | ifa->tmp_next = idev->tempaddr_list; |
| 563 | idev->tempaddr_list = ifa; |
| 564 | in6_ifa_hold(ifa); |
| 565 | } |
| 566 | #endif |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | in6_ifa_hold(ifa); |
| 569 | write_unlock(&idev->lock); |
| 570 | out2: |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 571 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
YOSHIFUJI Hideaki | fd92833 | 2005-04-19 22:27:09 -0700 | [diff] [blame] | 573 | if (likely(err == 0)) |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 574 | atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | else { |
| 576 | kfree(ifa); |
| 577 | ifa = ERR_PTR(err); |
| 578 | } |
| 579 | |
| 580 | return ifa; |
| 581 | out: |
| 582 | write_unlock(&addrconf_hash_lock); |
| 583 | goto out2; |
| 584 | } |
| 585 | |
| 586 | /* This function wants to get referenced ifp and releases it before return */ |
| 587 | |
| 588 | static void ipv6_del_addr(struct inet6_ifaddr *ifp) |
| 589 | { |
| 590 | struct inet6_ifaddr *ifa, **ifap; |
| 591 | struct inet6_dev *idev = ifp->idev; |
| 592 | int hash; |
| 593 | int deleted = 0, onlink = 0; |
| 594 | unsigned long expires = jiffies; |
| 595 | |
| 596 | hash = ipv6_addr_hash(&ifp->addr); |
| 597 | |
| 598 | ifp->dead = 1; |
| 599 | |
| 600 | write_lock_bh(&addrconf_hash_lock); |
| 601 | for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL; |
| 602 | ifap = &ifa->lst_next) { |
| 603 | if (ifa == ifp) { |
| 604 | *ifap = ifa->lst_next; |
| 605 | __in6_ifa_put(ifp); |
| 606 | ifa->lst_next = NULL; |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | write_unlock_bh(&addrconf_hash_lock); |
| 611 | |
| 612 | write_lock_bh(&idev->lock); |
| 613 | #ifdef CONFIG_IPV6_PRIVACY |
| 614 | if (ifp->flags&IFA_F_TEMPORARY) { |
| 615 | for (ifap = &idev->tempaddr_list; (ifa=*ifap) != NULL; |
| 616 | ifap = &ifa->tmp_next) { |
| 617 | if (ifa == ifp) { |
| 618 | *ifap = ifa->tmp_next; |
| 619 | if (ifp->ifpub) { |
| 620 | in6_ifa_put(ifp->ifpub); |
| 621 | ifp->ifpub = NULL; |
| 622 | } |
| 623 | __in6_ifa_put(ifp); |
| 624 | ifa->tmp_next = NULL; |
| 625 | break; |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | #endif |
| 630 | |
Kristian Slavov | 1d14280 | 2005-12-21 18:47:24 -0800 | [diff] [blame] | 631 | for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | if (ifa == ifp) { |
| 633 | *ifap = ifa->if_next; |
| 634 | __in6_ifa_put(ifp); |
| 635 | ifa->if_next = NULL; |
| 636 | if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0) |
| 637 | break; |
| 638 | deleted = 1; |
Kristian Slavov | 1d14280 | 2005-12-21 18:47:24 -0800 | [diff] [blame] | 639 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } else if (ifp->flags & IFA_F_PERMANENT) { |
| 641 | if (ipv6_prefix_equal(&ifa->addr, &ifp->addr, |
| 642 | ifp->prefix_len)) { |
| 643 | if (ifa->flags & IFA_F_PERMANENT) { |
| 644 | onlink = 1; |
| 645 | if (deleted) |
| 646 | break; |
| 647 | } else { |
| 648 | unsigned long lifetime; |
| 649 | |
| 650 | if (!onlink) |
| 651 | onlink = -1; |
| 652 | |
| 653 | spin_lock(&ifa->lock); |
| 654 | lifetime = min_t(unsigned long, |
| 655 | ifa->valid_lft, 0x7fffffffUL/HZ); |
| 656 | if (time_before(expires, |
| 657 | ifa->tstamp + lifetime * HZ)) |
| 658 | expires = ifa->tstamp + lifetime * HZ; |
| 659 | spin_unlock(&ifa->lock); |
| 660 | } |
| 661 | } |
| 662 | } |
Kristian Slavov | 1d14280 | 2005-12-21 18:47:24 -0800 | [diff] [blame] | 663 | ifap = &ifa->if_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | write_unlock_bh(&idev->lock); |
| 666 | |
| 667 | ipv6_ifa_notify(RTM_DELADDR, ifp); |
| 668 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 669 | atomic_notifier_call_chain(&inet6addr_chain, NETDEV_DOWN, ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | addrconf_del_timer(ifp); |
| 672 | |
| 673 | /* |
| 674 | * Purge or update corresponding prefix |
| 675 | * |
| 676 | * 1) we don't purge prefix here if address was not permanent. |
| 677 | * prefix is managed by its own lifetime. |
| 678 | * 2) if there're no addresses, delete prefix. |
| 679 | * 3) if there're still other permanent address(es), |
| 680 | * corresponding prefix is still permanent. |
| 681 | * 4) otherwise, update prefix lifetime to the |
| 682 | * longest valid lifetime among the corresponding |
| 683 | * addresses on the device. |
| 684 | * Note: subsequent RA will update lifetime. |
| 685 | * |
| 686 | * --yoshfuji |
| 687 | */ |
| 688 | if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) { |
| 689 | struct in6_addr prefix; |
| 690 | struct rt6_info *rt; |
| 691 | |
| 692 | ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len); |
| 693 | rt = rt6_lookup(&prefix, NULL, ifp->idev->dev->ifindex, 1); |
| 694 | |
| 695 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { |
| 696 | if (onlink == 0) { |
Thomas Graf | e0a1ad73 | 2006-08-22 00:00:21 -0700 | [diff] [blame] | 697 | ip6_del_rt(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | rt = NULL; |
| 699 | } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { |
| 700 | rt->rt6i_expires = expires; |
| 701 | rt->rt6i_flags |= RTF_EXPIRES; |
| 702 | } |
| 703 | } |
| 704 | dst_release(&rt->u.dst); |
| 705 | } |
| 706 | |
| 707 | in6_ifa_put(ifp); |
| 708 | } |
| 709 | |
| 710 | #ifdef CONFIG_IPV6_PRIVACY |
| 711 | static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *ift) |
| 712 | { |
| 713 | struct inet6_dev *idev = ifp->idev; |
| 714 | struct in6_addr addr, *tmpaddr; |
| 715 | unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp; |
| 716 | int tmp_plen; |
| 717 | int ret = 0; |
| 718 | int max_addresses; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 719 | u32 addr_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | write_lock(&idev->lock); |
| 722 | if (ift) { |
| 723 | spin_lock_bh(&ift->lock); |
| 724 | memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8); |
| 725 | spin_unlock_bh(&ift->lock); |
| 726 | tmpaddr = &addr; |
| 727 | } else { |
| 728 | tmpaddr = NULL; |
| 729 | } |
| 730 | retry: |
| 731 | in6_dev_hold(idev); |
| 732 | if (idev->cnf.use_tempaddr <= 0) { |
| 733 | write_unlock(&idev->lock); |
| 734 | printk(KERN_INFO |
| 735 | "ipv6_create_tempaddr(): use_tempaddr is disabled.\n"); |
| 736 | in6_dev_put(idev); |
| 737 | ret = -1; |
| 738 | goto out; |
| 739 | } |
| 740 | spin_lock_bh(&ifp->lock); |
| 741 | if (ifp->regen_count++ >= idev->cnf.regen_max_retry) { |
| 742 | idev->cnf.use_tempaddr = -1; /*XXX*/ |
| 743 | spin_unlock_bh(&ifp->lock); |
| 744 | write_unlock(&idev->lock); |
| 745 | printk(KERN_WARNING |
| 746 | "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n"); |
| 747 | in6_dev_put(idev); |
| 748 | ret = -1; |
| 749 | goto out; |
| 750 | } |
| 751 | in6_ifa_hold(ifp); |
| 752 | memcpy(addr.s6_addr, ifp->addr.s6_addr, 8); |
| 753 | if (__ipv6_try_regen_rndid(idev, tmpaddr) < 0) { |
| 754 | spin_unlock_bh(&ifp->lock); |
| 755 | write_unlock(&idev->lock); |
| 756 | printk(KERN_WARNING |
| 757 | "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n"); |
| 758 | in6_ifa_put(ifp); |
| 759 | in6_dev_put(idev); |
| 760 | ret = -1; |
| 761 | goto out; |
| 762 | } |
| 763 | memcpy(&addr.s6_addr[8], idev->rndid, 8); |
| 764 | tmp_valid_lft = min_t(__u32, |
| 765 | ifp->valid_lft, |
| 766 | idev->cnf.temp_valid_lft); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 767 | tmp_prefered_lft = min_t(__u32, |
| 768 | ifp->prefered_lft, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | idev->cnf.temp_prefered_lft - desync_factor / HZ); |
| 770 | tmp_plen = ifp->prefix_len; |
| 771 | max_addresses = idev->cnf.max_addresses; |
| 772 | tmp_cstamp = ifp->cstamp; |
| 773 | tmp_tstamp = ifp->tstamp; |
| 774 | spin_unlock_bh(&ifp->lock); |
| 775 | |
| 776 | write_unlock(&idev->lock); |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 777 | |
| 778 | addr_flags = IFA_F_TEMPORARY; |
| 779 | /* set in addrconf_prefix_rcv() */ |
| 780 | if (ifp->flags & IFA_F_OPTIMISTIC) |
| 781 | addr_flags |= IFA_F_OPTIMISTIC; |
| 782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | ift = !max_addresses || |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 784 | ipv6_count_addresses(idev) < max_addresses ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | ipv6_add_addr(idev, &addr, tmp_plen, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 786 | ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK, |
| 787 | addr_flags) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (!ift || IS_ERR(ift)) { |
| 789 | in6_ifa_put(ifp); |
| 790 | in6_dev_put(idev); |
| 791 | printk(KERN_INFO |
| 792 | "ipv6_create_tempaddr(): retry temporary address regeneration.\n"); |
| 793 | tmpaddr = &addr; |
| 794 | write_lock(&idev->lock); |
| 795 | goto retry; |
| 796 | } |
| 797 | |
| 798 | spin_lock_bh(&ift->lock); |
| 799 | ift->ifpub = ifp; |
| 800 | ift->valid_lft = tmp_valid_lft; |
| 801 | ift->prefered_lft = tmp_prefered_lft; |
| 802 | ift->cstamp = tmp_cstamp; |
| 803 | ift->tstamp = tmp_tstamp; |
| 804 | spin_unlock_bh(&ift->lock); |
| 805 | |
| 806 | addrconf_dad_start(ift, 0); |
| 807 | in6_ifa_put(ift); |
| 808 | in6_dev_put(idev); |
| 809 | out: |
| 810 | return ret; |
| 811 | } |
| 812 | #endif |
| 813 | |
| 814 | /* |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 815 | * Choose an appropriate source address (RFC3484) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | */ |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 817 | struct ipv6_saddr_score { |
| 818 | int addr_type; |
| 819 | unsigned int attrs; |
| 820 | int matchlen; |
Brian Haley | 0d27b42 | 2006-03-11 18:50:14 -0800 | [diff] [blame] | 821 | int scope; |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 822 | unsigned int rule; |
| 823 | }; |
| 824 | |
| 825 | #define IPV6_SADDR_SCORE_LOCAL 0x0001 |
| 826 | #define IPV6_SADDR_SCORE_PREFERRED 0x0004 |
| 827 | #define IPV6_SADDR_SCORE_HOA 0x0008 |
| 828 | #define IPV6_SADDR_SCORE_OIF 0x0010 |
| 829 | #define IPV6_SADDR_SCORE_LABEL 0x0020 |
| 830 | #define IPV6_SADDR_SCORE_PRIVACY 0x0040 |
| 831 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 832 | static inline int ipv6_saddr_preferred(int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 834 | if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4| |
| 835 | IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED)) |
| 836 | return 1; |
| 837 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 840 | /* static matching label */ |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 841 | static inline int ipv6_saddr_label(const struct in6_addr *addr, int type) |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 842 | { |
| 843 | /* |
| 844 | * prefix (longest match) label |
| 845 | * ----------------------------- |
| 846 | * ::1/128 0 |
| 847 | * ::/0 1 |
| 848 | * 2002::/16 2 |
| 849 | * ::/96 3 |
| 850 | * ::ffff:0:0/96 4 |
Łukasz Stelmach | 102128e | 2006-06-22 01:37:19 -0700 | [diff] [blame] | 851 | * fc00::/7 5 |
| 852 | * 2001::/32 6 |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 853 | */ |
| 854 | if (type & IPV6_ADDR_LOOPBACK) |
| 855 | return 0; |
| 856 | else if (type & IPV6_ADDR_COMPATv4) |
| 857 | return 3; |
| 858 | else if (type & IPV6_ADDR_MAPPED) |
| 859 | return 4; |
Łukasz Stelmach | 102128e | 2006-06-22 01:37:19 -0700 | [diff] [blame] | 860 | else if (addr->s6_addr32[0] == htonl(0x20010000)) |
| 861 | return 6; |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 862 | else if (addr->s6_addr16[0] == htons(0x2002)) |
| 863 | return 2; |
Łukasz Stelmach | 102128e | 2006-06-22 01:37:19 -0700 | [diff] [blame] | 864 | else if ((addr->s6_addr[0] & 0xfe) == 0xfc) |
| 865 | return 5; |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 866 | return 1; |
| 867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 869 | int ipv6_dev_get_saddr(struct net_device *daddr_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | struct in6_addr *daddr, struct in6_addr *saddr) |
| 871 | { |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 872 | struct ipv6_saddr_score hiscore; |
| 873 | struct inet6_ifaddr *ifa_result = NULL; |
| 874 | int daddr_type = __ipv6_addr_type(daddr); |
| 875 | int daddr_scope = __ipv6_addr_src_scope(daddr_type); |
| 876 | u32 daddr_label = ipv6_saddr_label(daddr, daddr_type); |
| 877 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 879 | memset(&hiscore, 0, sizeof(hiscore)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | read_lock(&dev_base_lock); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 882 | rcu_read_lock(); |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | for (dev = dev_base; dev; dev=dev->next) { |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 885 | struct inet6_dev *idev; |
| 886 | struct inet6_ifaddr *ifa; |
| 887 | |
| 888 | /* Rule 0: Candidate Source Address (section 4) |
| 889 | * - multicast and link-local destination address, |
| 890 | * the set of candidate source address MUST only |
| 891 | * include addresses assigned to interfaces |
| 892 | * belonging to the same link as the outgoing |
| 893 | * interface. |
| 894 | * (- For site-local destination addresses, the |
| 895 | * set of candidate source addresses MUST only |
| 896 | * include addresses assigned to interfaces |
| 897 | * belonging to the same site as the outgoing |
| 898 | * interface.) |
| 899 | */ |
| 900 | if ((daddr_type & IPV6_ADDR_MULTICAST || |
| 901 | daddr_scope <= IPV6_ADDR_SCOPE_LINKLOCAL) && |
| 902 | daddr_dev && dev != daddr_dev) |
| 903 | continue; |
| 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | idev = __in6_dev_get(dev); |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 906 | if (!idev) |
| 907 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 909 | read_lock_bh(&idev->lock); |
| 910 | for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) { |
| 911 | struct ipv6_saddr_score score; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 913 | score.addr_type = __ipv6_addr_type(&ifa->addr); |
| 914 | |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 915 | /* Rule 0: |
| 916 | * - Tentative Address (RFC2462 section 5.4) |
| 917 | * - A tentative address is not considered |
| 918 | * "assigned to an interface" in the traditional |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 919 | * sense, unless it is also flagged as optimistic. |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 920 | * - Candidate Source Address (section 4) |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 921 | * - In any case, anycast addresses, multicast |
| 922 | * addresses, and the unspecified address MUST |
| 923 | * NOT be included in a candidate set. |
| 924 | */ |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 925 | if ((ifa->flags & IFA_F_TENTATIVE) && |
| 926 | (!(ifa->flags & IFA_F_OPTIMISTIC))) |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 927 | continue; |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 928 | if (unlikely(score.addr_type == IPV6_ADDR_ANY || |
| 929 | score.addr_type & IPV6_ADDR_MULTICAST)) { |
| 930 | LIMIT_NETDEBUG(KERN_DEBUG |
| 931 | "ADDRCONF: unspecified / multicast address" |
| 932 | "assigned as unicast address on %s", |
| 933 | dev->name); |
| 934 | continue; |
| 935 | } |
| 936 | |
| 937 | score.attrs = 0; |
| 938 | score.matchlen = 0; |
| 939 | score.scope = 0; |
| 940 | score.rule = 0; |
| 941 | |
| 942 | if (ifa_result == NULL) { |
| 943 | /* record it if the first available entry */ |
| 944 | goto record_it; |
| 945 | } |
| 946 | |
| 947 | /* Rule 1: Prefer same address */ |
| 948 | if (hiscore.rule < 1) { |
| 949 | if (ipv6_addr_equal(&ifa_result->addr, daddr)) |
| 950 | hiscore.attrs |= IPV6_SADDR_SCORE_LOCAL; |
| 951 | hiscore.rule++; |
| 952 | } |
| 953 | if (ipv6_addr_equal(&ifa->addr, daddr)) { |
| 954 | score.attrs |= IPV6_SADDR_SCORE_LOCAL; |
| 955 | if (!(hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)) { |
| 956 | score.rule = 1; |
| 957 | goto record_it; |
| 958 | } |
| 959 | } else { |
| 960 | if (hiscore.attrs & IPV6_SADDR_SCORE_LOCAL) |
| 961 | continue; |
| 962 | } |
| 963 | |
| 964 | /* Rule 2: Prefer appropriate scope */ |
| 965 | if (hiscore.rule < 2) { |
| 966 | hiscore.scope = __ipv6_addr_src_scope(hiscore.addr_type); |
| 967 | hiscore.rule++; |
| 968 | } |
| 969 | score.scope = __ipv6_addr_src_scope(score.addr_type); |
| 970 | if (hiscore.scope < score.scope) { |
| 971 | if (hiscore.scope < daddr_scope) { |
| 972 | score.rule = 2; |
| 973 | goto record_it; |
| 974 | } else |
| 975 | continue; |
| 976 | } else if (score.scope < hiscore.scope) { |
| 977 | if (score.scope < daddr_scope) |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 978 | break; /* addresses sorted by scope */ |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 979 | else { |
| 980 | score.rule = 2; |
| 981 | goto record_it; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 985 | /* Rule 3: Avoid deprecated and optimistic addresses */ |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 986 | if (hiscore.rule < 3) { |
| 987 | if (ipv6_saddr_preferred(hiscore.addr_type) || |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 988 | (((ifa_result->flags & |
| 989 | (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0))) |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 990 | hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED; |
| 991 | hiscore.rule++; |
| 992 | } |
| 993 | if (ipv6_saddr_preferred(score.addr_type) || |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 994 | (((ifa_result->flags & |
| 995 | (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0))) { |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 996 | score.attrs |= IPV6_SADDR_SCORE_PREFERRED; |
| 997 | if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) { |
| 998 | score.rule = 3; |
| 999 | goto record_it; |
| 1000 | } |
| 1001 | } else { |
| 1002 | if (hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED) |
| 1003 | continue; |
| 1004 | } |
| 1005 | |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 1006 | /* Rule 4: Prefer home address */ |
| 1007 | #ifdef CONFIG_IPV6_MIP6 |
| 1008 | if (hiscore.rule < 4) { |
| 1009 | if (ifa_result->flags & IFA_F_HOMEADDRESS) |
| 1010 | hiscore.attrs |= IPV6_SADDR_SCORE_HOA; |
| 1011 | hiscore.rule++; |
| 1012 | } |
| 1013 | if (ifa->flags & IFA_F_HOMEADDRESS) { |
| 1014 | score.attrs |= IPV6_SADDR_SCORE_HOA; |
| 1015 | if (!(ifa_result->flags & IFA_F_HOMEADDRESS)) { |
| 1016 | score.rule = 4; |
| 1017 | goto record_it; |
| 1018 | } |
| 1019 | } else { |
| 1020 | if (hiscore.attrs & IPV6_SADDR_SCORE_HOA) |
| 1021 | continue; |
| 1022 | } |
| 1023 | #else |
YOSHIFUJI Hideaki | 220bbd7 | 2005-11-28 22:27:11 -0800 | [diff] [blame] | 1024 | if (hiscore.rule < 4) |
| 1025 | hiscore.rule++; |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 1026 | #endif |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1027 | |
| 1028 | /* Rule 5: Prefer outgoing interface */ |
| 1029 | if (hiscore.rule < 5) { |
| 1030 | if (daddr_dev == NULL || |
| 1031 | daddr_dev == ifa_result->idev->dev) |
| 1032 | hiscore.attrs |= IPV6_SADDR_SCORE_OIF; |
| 1033 | hiscore.rule++; |
| 1034 | } |
| 1035 | if (daddr_dev == NULL || |
| 1036 | daddr_dev == ifa->idev->dev) { |
| 1037 | score.attrs |= IPV6_SADDR_SCORE_OIF; |
| 1038 | if (!(hiscore.attrs & IPV6_SADDR_SCORE_OIF)) { |
| 1039 | score.rule = 5; |
| 1040 | goto record_it; |
| 1041 | } |
| 1042 | } else { |
| 1043 | if (hiscore.attrs & IPV6_SADDR_SCORE_OIF) |
| 1044 | continue; |
| 1045 | } |
| 1046 | |
| 1047 | /* Rule 6: Prefer matching label */ |
| 1048 | if (hiscore.rule < 6) { |
| 1049 | if (ipv6_saddr_label(&ifa_result->addr, hiscore.addr_type) == daddr_label) |
| 1050 | hiscore.attrs |= IPV6_SADDR_SCORE_LABEL; |
| 1051 | hiscore.rule++; |
| 1052 | } |
| 1053 | if (ipv6_saddr_label(&ifa->addr, score.addr_type) == daddr_label) { |
| 1054 | score.attrs |= IPV6_SADDR_SCORE_LABEL; |
| 1055 | if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) { |
| 1056 | score.rule = 6; |
| 1057 | goto record_it; |
| 1058 | } |
| 1059 | } else { |
| 1060 | if (hiscore.attrs & IPV6_SADDR_SCORE_LABEL) |
| 1061 | continue; |
| 1062 | } |
| 1063 | |
Peter Chubb | 44fd026 | 2005-11-09 13:05:47 -0800 | [diff] [blame] | 1064 | #ifdef CONFIG_IPV6_PRIVACY |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1065 | /* Rule 7: Prefer public address |
| 1066 | * Note: prefer temprary address if use_tempaddr >= 2 |
| 1067 | */ |
| 1068 | if (hiscore.rule < 7) { |
| 1069 | if ((!(ifa_result->flags & IFA_F_TEMPORARY)) ^ |
| 1070 | (ifa_result->idev->cnf.use_tempaddr >= 2)) |
| 1071 | hiscore.attrs |= IPV6_SADDR_SCORE_PRIVACY; |
| 1072 | hiscore.rule++; |
| 1073 | } |
| 1074 | if ((!(ifa->flags & IFA_F_TEMPORARY)) ^ |
| 1075 | (ifa->idev->cnf.use_tempaddr >= 2)) { |
| 1076 | score.attrs |= IPV6_SADDR_SCORE_PRIVACY; |
| 1077 | if (!(hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)) { |
| 1078 | score.rule = 7; |
| 1079 | goto record_it; |
| 1080 | } |
| 1081 | } else { |
| 1082 | if (hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY) |
| 1083 | continue; |
| 1084 | } |
YOSHIFUJI Hideaki | 5e2707f | 2006-06-22 01:41:18 -0700 | [diff] [blame] | 1085 | #else |
| 1086 | if (hiscore.rule < 7) |
| 1087 | hiscore.rule++; |
Peter Chubb | 44fd026 | 2005-11-09 13:05:47 -0800 | [diff] [blame] | 1088 | #endif |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1089 | /* Rule 8: Use longest matching prefix */ |
Yan Zheng | 12da2a4 | 2005-11-14 21:42:46 -0800 | [diff] [blame] | 1090 | if (hiscore.rule < 8) { |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1091 | hiscore.matchlen = ipv6_addr_diff(&ifa_result->addr, daddr); |
Yan Zheng | 12da2a4 | 2005-11-14 21:42:46 -0800 | [diff] [blame] | 1092 | hiscore.rule++; |
| 1093 | } |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1094 | score.matchlen = ipv6_addr_diff(&ifa->addr, daddr); |
| 1095 | if (score.matchlen > hiscore.matchlen) { |
| 1096 | score.rule = 8; |
| 1097 | goto record_it; |
| 1098 | } |
| 1099 | #if 0 |
| 1100 | else if (score.matchlen < hiscore.matchlen) |
| 1101 | continue; |
| 1102 | #endif |
| 1103 | |
| 1104 | /* Final Rule: choose first available one */ |
| 1105 | continue; |
| 1106 | record_it: |
| 1107 | if (ifa_result) |
| 1108 | in6_ifa_put(ifa_result); |
| 1109 | in6_ifa_hold(ifa); |
| 1110 | ifa_result = ifa; |
| 1111 | hiscore = score; |
| 1112 | } |
| 1113 | read_unlock_bh(&idev->lock); |
| 1114 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1115 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | read_unlock(&dev_base_lock); |
| 1117 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1118 | if (!ifa_result) |
| 1119 | return -EADDRNOTAVAIL; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1120 | |
YOSHIFUJI Hideaki | 072047e | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1121 | ipv6_addr_copy(saddr, &ifa_result->addr); |
| 1122 | in6_ifa_put(ifa_result); |
| 1123 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | |
| 1127 | int ipv6_get_saddr(struct dst_entry *dst, |
| 1128 | struct in6_addr *daddr, struct in6_addr *saddr) |
| 1129 | { |
YOSHIFUJI Hideaki | 7a3025b | 2006-10-13 16:17:25 +0900 | [diff] [blame] | 1130 | return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 1133 | EXPORT_SYMBOL(ipv6_get_saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1135 | int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, |
| 1136 | unsigned char banned_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | { |
| 1138 | struct inet6_dev *idev; |
| 1139 | int err = -EADDRNOTAVAIL; |
| 1140 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1141 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | if ((idev = __in6_dev_get(dev)) != NULL) { |
| 1143 | struct inet6_ifaddr *ifp; |
| 1144 | |
| 1145 | read_lock_bh(&idev->lock); |
| 1146 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1147 | if (ifp->scope == IFA_LINK && !(ifp->flags & banned_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | ipv6_addr_copy(addr, &ifp->addr); |
| 1149 | err = 0; |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
| 1153 | read_unlock_bh(&idev->lock); |
| 1154 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1155 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return err; |
| 1157 | } |
| 1158 | |
| 1159 | static int ipv6_count_addresses(struct inet6_dev *idev) |
| 1160 | { |
| 1161 | int cnt = 0; |
| 1162 | struct inet6_ifaddr *ifp; |
| 1163 | |
| 1164 | read_lock_bh(&idev->lock); |
| 1165 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) |
| 1166 | cnt++; |
| 1167 | read_unlock_bh(&idev->lock); |
| 1168 | return cnt; |
| 1169 | } |
| 1170 | |
| 1171 | int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev, int strict) |
| 1172 | { |
| 1173 | struct inet6_ifaddr * ifp; |
| 1174 | u8 hash = ipv6_addr_hash(addr); |
| 1175 | |
| 1176 | read_lock_bh(&addrconf_hash_lock); |
| 1177 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { |
| 1178 | if (ipv6_addr_equal(&ifp->addr, addr) && |
| 1179 | !(ifp->flags&IFA_F_TENTATIVE)) { |
| 1180 | if (dev == NULL || ifp->idev->dev == dev || |
| 1181 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) |
| 1182 | break; |
| 1183 | } |
| 1184 | } |
| 1185 | read_unlock_bh(&addrconf_hash_lock); |
| 1186 | return ifp != NULL; |
| 1187 | } |
| 1188 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 1189 | EXPORT_SYMBOL(ipv6_chk_addr); |
| 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | static |
| 1192 | int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev) |
| 1193 | { |
| 1194 | struct inet6_ifaddr * ifp; |
| 1195 | u8 hash = ipv6_addr_hash(addr); |
| 1196 | |
| 1197 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { |
| 1198 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
| 1199 | if (dev == NULL || ifp->idev->dev == dev) |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
| 1203 | return ifp != NULL; |
| 1204 | } |
| 1205 | |
| 1206 | struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr, struct net_device *dev, int strict) |
| 1207 | { |
| 1208 | struct inet6_ifaddr * ifp; |
| 1209 | u8 hash = ipv6_addr_hash(addr); |
| 1210 | |
| 1211 | read_lock_bh(&addrconf_hash_lock); |
| 1212 | for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) { |
| 1213 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
| 1214 | if (dev == NULL || ifp->idev->dev == dev || |
| 1215 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { |
| 1216 | in6_ifa_hold(ifp); |
| 1217 | break; |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | read_unlock_bh(&addrconf_hash_lock); |
| 1222 | |
| 1223 | return ifp; |
| 1224 | } |
| 1225 | |
| 1226 | int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2) |
| 1227 | { |
| 1228 | const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; |
Arnaldo Carvalho de Melo | 0fa1a53 | 2005-12-13 23:23:09 -0800 | [diff] [blame] | 1229 | const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); |
Al Viro | 8210323 | 2006-09-27 18:44:10 -0700 | [diff] [blame] | 1230 | __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr; |
| 1231 | __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | int sk_ipv6only = ipv6_only_sock(sk); |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 1233 | int sk2_ipv6only = inet_v6_ipv6only(sk2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | int addr_type = ipv6_addr_type(sk_rcv_saddr6); |
| 1235 | int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED; |
| 1236 | |
| 1237 | if (!sk2_rcv_saddr && !sk_ipv6only) |
| 1238 | return 1; |
| 1239 | |
| 1240 | if (addr_type2 == IPV6_ADDR_ANY && |
| 1241 | !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED)) |
| 1242 | return 1; |
| 1243 | |
| 1244 | if (addr_type == IPV6_ADDR_ANY && |
| 1245 | !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED)) |
| 1246 | return 1; |
| 1247 | |
| 1248 | if (sk2_rcv_saddr6 && |
| 1249 | ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6)) |
| 1250 | return 1; |
| 1251 | |
| 1252 | if (addr_type == IPV6_ADDR_MAPPED && |
| 1253 | !sk2_ipv6only && |
| 1254 | (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr)) |
| 1255 | return 1; |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | /* Gets referenced address, destroys ifaddr */ |
| 1261 | |
Adrian Bunk | 9f5336e | 2006-01-07 13:24:25 -0800 | [diff] [blame] | 1262 | static void addrconf_dad_stop(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | if (ifp->flags&IFA_F_PERMANENT) { |
| 1265 | spin_lock_bh(&ifp->lock); |
| 1266 | addrconf_del_timer(ifp); |
| 1267 | ifp->flags |= IFA_F_TENTATIVE; |
| 1268 | spin_unlock_bh(&ifp->lock); |
| 1269 | in6_ifa_put(ifp); |
| 1270 | #ifdef CONFIG_IPV6_PRIVACY |
| 1271 | } else if (ifp->flags&IFA_F_TEMPORARY) { |
| 1272 | struct inet6_ifaddr *ifpub; |
| 1273 | spin_lock_bh(&ifp->lock); |
| 1274 | ifpub = ifp->ifpub; |
| 1275 | if (ifpub) { |
| 1276 | in6_ifa_hold(ifpub); |
| 1277 | spin_unlock_bh(&ifp->lock); |
| 1278 | ipv6_create_tempaddr(ifpub, ifp); |
| 1279 | in6_ifa_put(ifpub); |
| 1280 | } else { |
| 1281 | spin_unlock_bh(&ifp->lock); |
| 1282 | } |
| 1283 | ipv6_del_addr(ifp); |
| 1284 | #endif |
| 1285 | } else |
| 1286 | ipv6_del_addr(ifp); |
| 1287 | } |
| 1288 | |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 1289 | void addrconf_dad_failure(struct inet6_ifaddr *ifp) |
| 1290 | { |
| 1291 | if (net_ratelimit()) |
| 1292 | printk(KERN_INFO "%s: duplicate address detected!\n", ifp->idev->dev->name); |
| 1293 | addrconf_dad_stop(ifp); |
| 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | /* Join to solicited addr multicast group. */ |
| 1297 | |
| 1298 | void addrconf_join_solict(struct net_device *dev, struct in6_addr *addr) |
| 1299 | { |
| 1300 | struct in6_addr maddr; |
| 1301 | |
| 1302 | if (dev->flags&(IFF_LOOPBACK|IFF_NOARP)) |
| 1303 | return; |
| 1304 | |
| 1305 | addrconf_addr_solict_mult(addr, &maddr); |
| 1306 | ipv6_dev_mc_inc(dev, &maddr); |
| 1307 | } |
| 1308 | |
| 1309 | void addrconf_leave_solict(struct inet6_dev *idev, struct in6_addr *addr) |
| 1310 | { |
| 1311 | struct in6_addr maddr; |
| 1312 | |
| 1313 | if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP)) |
| 1314 | return; |
| 1315 | |
| 1316 | addrconf_addr_solict_mult(addr, &maddr); |
| 1317 | __ipv6_dev_mc_dec(idev, &maddr); |
| 1318 | } |
| 1319 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1320 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | { |
| 1322 | struct in6_addr addr; |
| 1323 | ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); |
| 1324 | if (ipv6_addr_any(&addr)) |
| 1325 | return; |
| 1326 | ipv6_dev_ac_inc(ifp->idev->dev, &addr); |
| 1327 | } |
| 1328 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1329 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | { |
| 1331 | struct in6_addr addr; |
| 1332 | ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); |
| 1333 | if (ipv6_addr_any(&addr)) |
| 1334 | return; |
| 1335 | __ipv6_dev_ac_dec(ifp->idev, &addr); |
| 1336 | } |
| 1337 | |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1338 | static int addrconf_ifid_eui48(u8 *eui, struct net_device *dev) |
| 1339 | { |
| 1340 | if (dev->addr_len != ETH_ALEN) |
| 1341 | return -1; |
| 1342 | memcpy(eui, dev->dev_addr, 3); |
| 1343 | memcpy(eui + 5, dev->dev_addr + 3, 3); |
| 1344 | |
| 1345 | /* |
| 1346 | * The zSeries OSA network cards can be shared among various |
| 1347 | * OS instances, but the OSA cards have only one MAC address. |
| 1348 | * This leads to duplicate address conflicts in conjunction |
| 1349 | * with IPv6 if more than one instance uses the same card. |
| 1350 | * |
| 1351 | * The driver for these cards can deliver a unique 16-bit |
| 1352 | * identifier for each instance sharing the same card. It is |
| 1353 | * placed instead of 0xFFFE in the interface identifier. The |
| 1354 | * "u" bit of the interface identifier is not inverted in this |
| 1355 | * case. Hence the resulting interface identifier has local |
| 1356 | * scope according to RFC2373. |
| 1357 | */ |
| 1358 | if (dev->dev_id) { |
| 1359 | eui[3] = (dev->dev_id >> 8) & 0xFF; |
| 1360 | eui[4] = dev->dev_id & 0xFF; |
| 1361 | } else { |
| 1362 | eui[3] = 0xFF; |
| 1363 | eui[4] = 0xFE; |
| 1364 | eui[0] ^= 2; |
| 1365 | } |
| 1366 | return 0; |
| 1367 | } |
| 1368 | |
| 1369 | static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev) |
| 1370 | { |
| 1371 | /* XXX: inherit EUI-64 from other interface -- yoshfuji */ |
| 1372 | if (dev->addr_len != ARCNET_ALEN) |
| 1373 | return -1; |
| 1374 | memset(eui, 0, 7); |
| 1375 | eui[7] = *(u8*)dev->dev_addr; |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
| 1379 | static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev) |
| 1380 | { |
| 1381 | if (dev->addr_len != INFINIBAND_ALEN) |
| 1382 | return -1; |
| 1383 | memcpy(eui, dev->dev_addr + 12, 8); |
| 1384 | eui[0] |= 2; |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | static int ipv6_generate_eui64(u8 *eui, struct net_device *dev) |
| 1389 | { |
| 1390 | switch (dev->type) { |
| 1391 | case ARPHRD_ETHER: |
| 1392 | case ARPHRD_FDDI: |
| 1393 | case ARPHRD_IEEE802_TR: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1394 | return addrconf_ifid_eui48(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | case ARPHRD_ARCNET: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1396 | return addrconf_ifid_arcnet(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | case ARPHRD_INFINIBAND: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1398 | return addrconf_ifid_infiniband(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | } |
| 1400 | return -1; |
| 1401 | } |
| 1402 | |
| 1403 | static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev) |
| 1404 | { |
| 1405 | int err = -1; |
| 1406 | struct inet6_ifaddr *ifp; |
| 1407 | |
| 1408 | read_lock_bh(&idev->lock); |
| 1409 | for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) { |
| 1410 | if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { |
| 1411 | memcpy(eui, ifp->addr.s6_addr+8, 8); |
| 1412 | err = 0; |
| 1413 | break; |
| 1414 | } |
| 1415 | } |
| 1416 | read_unlock_bh(&idev->lock); |
| 1417 | return err; |
| 1418 | } |
| 1419 | |
| 1420 | #ifdef CONFIG_IPV6_PRIVACY |
| 1421 | /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */ |
| 1422 | static int __ipv6_regen_rndid(struct inet6_dev *idev) |
| 1423 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | regen: |
YOSHIFUJI Hideaki | 955189e | 2006-03-20 16:54:09 -0800 | [diff] [blame] | 1425 | get_random_bytes(idev->rndid, sizeof(idev->rndid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | idev->rndid[0] &= ~0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
| 1428 | /* |
| 1429 | * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>: |
| 1430 | * check if generated address is not inappropriate |
| 1431 | * |
| 1432 | * - Reserved subnet anycast (RFC 2526) |
| 1433 | * 11111101 11....11 1xxxxxxx |
| 1434 | * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1 |
| 1435 | * 00-00-5E-FE-xx-xx-xx-xx |
| 1436 | * - value 0 |
| 1437 | * - XXX: already assigned to an address on the device |
| 1438 | */ |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1439 | if (idev->rndid[0] == 0xfd && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | (idev->rndid[1]&idev->rndid[2]&idev->rndid[3]&idev->rndid[4]&idev->rndid[5]&idev->rndid[6]) == 0xff && |
| 1441 | (idev->rndid[7]&0x80)) |
| 1442 | goto regen; |
| 1443 | if ((idev->rndid[0]|idev->rndid[1]) == 0) { |
| 1444 | if (idev->rndid[2] == 0x5e && idev->rndid[3] == 0xfe) |
| 1445 | goto regen; |
| 1446 | if ((idev->rndid[2]|idev->rndid[3]|idev->rndid[4]|idev->rndid[5]|idev->rndid[6]|idev->rndid[7]) == 0x00) |
| 1447 | goto regen; |
| 1448 | } |
| 1449 | |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | static void ipv6_regen_rndid(unsigned long data) |
| 1454 | { |
| 1455 | struct inet6_dev *idev = (struct inet6_dev *) data; |
| 1456 | unsigned long expires; |
| 1457 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1458 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | write_lock_bh(&idev->lock); |
| 1460 | |
| 1461 | if (idev->dead) |
| 1462 | goto out; |
| 1463 | |
| 1464 | if (__ipv6_regen_rndid(idev) < 0) |
| 1465 | goto out; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | expires = jiffies + |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1468 | idev->cnf.temp_prefered_lft * HZ - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - desync_factor; |
| 1470 | if (time_before(expires, jiffies)) { |
| 1471 | printk(KERN_WARNING |
| 1472 | "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n", |
| 1473 | idev->dev->name); |
| 1474 | goto out; |
| 1475 | } |
| 1476 | |
| 1477 | if (!mod_timer(&idev->regen_timer, expires)) |
| 1478 | in6_dev_hold(idev); |
| 1479 | |
| 1480 | out: |
| 1481 | write_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1482 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | in6_dev_put(idev); |
| 1484 | } |
| 1485 | |
| 1486 | static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr) { |
| 1487 | int ret = 0; |
| 1488 | |
| 1489 | if (tmpaddr && memcmp(idev->rndid, &tmpaddr->s6_addr[8], 8) == 0) |
| 1490 | ret = __ipv6_regen_rndid(idev); |
| 1491 | return ret; |
| 1492 | } |
| 1493 | #endif |
| 1494 | |
| 1495 | /* |
| 1496 | * Add prefix route. |
| 1497 | */ |
| 1498 | |
| 1499 | static void |
| 1500 | addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, |
Jamal Hadi Salim | e431b8c | 2005-06-18 22:55:31 -0700 | [diff] [blame] | 1501 | unsigned long expires, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | { |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1503 | struct fib6_config cfg = { |
| 1504 | .fc_table = RT6_TABLE_PREFIX, |
| 1505 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1506 | .fc_ifindex = dev->ifindex, |
| 1507 | .fc_expires = expires, |
| 1508 | .fc_dst_len = plen, |
| 1509 | .fc_flags = RTF_UP | flags, |
| 1510 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1512 | ipv6_addr_copy(&cfg.fc_dst, pfx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* Prevent useless cloning on PtP SIT. |
| 1515 | This thing is done here expecting that the whole |
| 1516 | class of non-broadcast devices need not cloning. |
| 1517 | */ |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1518 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1519 | if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) |
| 1520 | cfg.fc_flags |= RTF_NONEXTHOP; |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1521 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1523 | ip6_route_add(&cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | /* Create "default" multicast route to the interface */ |
| 1527 | |
| 1528 | static void addrconf_add_mroute(struct net_device *dev) |
| 1529 | { |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1530 | struct fib6_config cfg = { |
| 1531 | .fc_table = RT6_TABLE_LOCAL, |
| 1532 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1533 | .fc_ifindex = dev->ifindex, |
| 1534 | .fc_dst_len = 8, |
| 1535 | .fc_flags = RTF_UP, |
| 1536 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1538 | ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); |
| 1539 | |
| 1540 | ip6_route_add(&cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1543 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | static void sit_route_add(struct net_device *dev) |
| 1545 | { |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1546 | struct fib6_config cfg = { |
| 1547 | .fc_table = RT6_TABLE_MAIN, |
| 1548 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1549 | .fc_ifindex = dev->ifindex, |
| 1550 | .fc_dst_len = 96, |
| 1551 | .fc_flags = RTF_UP | RTF_NONEXTHOP, |
| 1552 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
| 1554 | /* prefix length - 96 bits "::d.d.d.d" */ |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1555 | ip6_route_add(&cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1557 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
| 1559 | static void addrconf_add_lroute(struct net_device *dev) |
| 1560 | { |
| 1561 | struct in6_addr addr; |
| 1562 | |
| 1563 | ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); |
| 1564 | addrconf_prefix_route(&addr, 64, dev, 0, 0); |
| 1565 | } |
| 1566 | |
| 1567 | static struct inet6_dev *addrconf_add_dev(struct net_device *dev) |
| 1568 | { |
| 1569 | struct inet6_dev *idev; |
| 1570 | |
| 1571 | ASSERT_RTNL(); |
| 1572 | |
| 1573 | if ((idev = ipv6_find_idev(dev)) == NULL) |
| 1574 | return NULL; |
| 1575 | |
| 1576 | /* Add default multicast route */ |
| 1577 | addrconf_add_mroute(dev); |
| 1578 | |
| 1579 | /* Add link local route */ |
| 1580 | addrconf_add_lroute(dev); |
| 1581 | return idev; |
| 1582 | } |
| 1583 | |
| 1584 | void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len) |
| 1585 | { |
| 1586 | struct prefix_info *pinfo; |
| 1587 | __u32 valid_lft; |
| 1588 | __u32 prefered_lft; |
| 1589 | int addr_type; |
| 1590 | unsigned long rt_expires; |
| 1591 | struct inet6_dev *in6_dev; |
| 1592 | |
| 1593 | pinfo = (struct prefix_info *) opt; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | if (len < sizeof(struct prefix_info)) { |
| 1596 | ADBG(("addrconf: prefix option too short\n")); |
| 1597 | return; |
| 1598 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | /* |
| 1601 | * Validation checks ([ADDRCONF], page 19) |
| 1602 | */ |
| 1603 | |
| 1604 | addr_type = ipv6_addr_type(&pinfo->prefix); |
| 1605 | |
| 1606 | if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL)) |
| 1607 | return; |
| 1608 | |
| 1609 | valid_lft = ntohl(pinfo->valid); |
| 1610 | prefered_lft = ntohl(pinfo->prefered); |
| 1611 | |
| 1612 | if (prefered_lft > valid_lft) { |
| 1613 | if (net_ratelimit()) |
| 1614 | printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n"); |
| 1615 | return; |
| 1616 | } |
| 1617 | |
| 1618 | in6_dev = in6_dev_get(dev); |
| 1619 | |
| 1620 | if (in6_dev == NULL) { |
| 1621 | if (net_ratelimit()) |
| 1622 | printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name); |
| 1623 | return; |
| 1624 | } |
| 1625 | |
| 1626 | /* |
| 1627 | * Two things going on here: |
| 1628 | * 1) Add routes for on-link prefixes |
| 1629 | * 2) Configure prefixes with the auto flag set |
| 1630 | */ |
| 1631 | |
| 1632 | /* Avoid arithmetic overflow. Really, we could |
| 1633 | save rt_expires in seconds, likely valid_lft, |
| 1634 | but it would require division in fib gc, that it |
| 1635 | not good. |
| 1636 | */ |
| 1637 | if (valid_lft >= 0x7FFFFFFF/HZ) |
YOSHIFUJI Hideaki | 3dd4bc6 | 2005-12-19 14:02:45 -0800 | [diff] [blame] | 1638 | rt_expires = 0x7FFFFFFF - (0x7FFFFFFF % HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | else |
YOSHIFUJI Hideaki | 3dd4bc6 | 2005-12-19 14:02:45 -0800 | [diff] [blame] | 1640 | rt_expires = valid_lft * HZ; |
| 1641 | |
| 1642 | /* |
| 1643 | * We convert this (in jiffies) to clock_t later. |
| 1644 | * Avoid arithmetic overflow there as well. |
| 1645 | * Overflow can happen only if HZ < USER_HZ. |
| 1646 | */ |
| 1647 | if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ) |
| 1648 | rt_expires = 0x7FFFFFFF / USER_HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
| 1650 | if (pinfo->onlink) { |
| 1651 | struct rt6_info *rt; |
| 1652 | rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1); |
| 1653 | |
| 1654 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { |
| 1655 | if (rt->rt6i_flags&RTF_EXPIRES) { |
| 1656 | if (valid_lft == 0) { |
Thomas Graf | e0a1ad73 | 2006-08-22 00:00:21 -0700 | [diff] [blame] | 1657 | ip6_del_rt(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | rt = NULL; |
| 1659 | } else { |
YOSHIFUJI Hideaki | 3dd4bc6 | 2005-12-19 14:02:45 -0800 | [diff] [blame] | 1660 | rt->rt6i_expires = jiffies + rt_expires; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | } else if (valid_lft) { |
| 1664 | addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, |
YOSHIFUJI Hideaki | 3dd4bc6 | 2005-12-19 14:02:45 -0800 | [diff] [blame] | 1665 | dev, jiffies_to_clock_t(rt_expires), RTF_ADDRCONF|RTF_EXPIRES|RTF_PREFIX_RT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | } |
| 1667 | if (rt) |
| 1668 | dst_release(&rt->u.dst); |
| 1669 | } |
| 1670 | |
| 1671 | /* Try to figure out our local address for this prefix */ |
| 1672 | |
| 1673 | if (pinfo->autoconf && in6_dev->cnf.autoconf) { |
| 1674 | struct inet6_ifaddr * ifp; |
| 1675 | struct in6_addr addr; |
| 1676 | int create = 0, update_lft = 0; |
| 1677 | |
| 1678 | if (pinfo->prefix_len == 64) { |
| 1679 | memcpy(&addr, &pinfo->prefix, 8); |
| 1680 | if (ipv6_generate_eui64(addr.s6_addr + 8, dev) && |
| 1681 | ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) { |
| 1682 | in6_dev_put(in6_dev); |
| 1683 | return; |
| 1684 | } |
| 1685 | goto ok; |
| 1686 | } |
| 1687 | if (net_ratelimit()) |
| 1688 | printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n", |
| 1689 | pinfo->prefix_len); |
| 1690 | in6_dev_put(in6_dev); |
| 1691 | return; |
| 1692 | |
| 1693 | ok: |
| 1694 | |
| 1695 | ifp = ipv6_get_ifaddr(&addr, dev, 1); |
| 1696 | |
| 1697 | if (ifp == NULL && valid_lft) { |
| 1698 | int max_addresses = in6_dev->cnf.max_addresses; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1699 | u32 addr_flags = 0; |
| 1700 | |
| 1701 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 1702 | if (in6_dev->cnf.optimistic_dad && |
| 1703 | !ipv6_devconf.forwarding) |
| 1704 | addr_flags = IFA_F_OPTIMISTIC; |
| 1705 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
| 1707 | /* Do not allow to create too much of autoconfigured |
| 1708 | * addresses; this would be too easy way to crash kernel. |
| 1709 | */ |
| 1710 | if (!max_addresses || |
| 1711 | ipv6_count_addresses(in6_dev) < max_addresses) |
| 1712 | ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1713 | addr_type&IPV6_ADDR_SCOPE_MASK, |
| 1714 | addr_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
| 1716 | if (!ifp || IS_ERR(ifp)) { |
| 1717 | in6_dev_put(in6_dev); |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | update_lft = create = 1; |
| 1722 | ifp->cstamp = jiffies; |
| 1723 | addrconf_dad_start(ifp, RTF_ADDRCONF|RTF_PREFIX_RT); |
| 1724 | } |
| 1725 | |
| 1726 | if (ifp) { |
| 1727 | int flags; |
| 1728 | unsigned long now; |
| 1729 | #ifdef CONFIG_IPV6_PRIVACY |
| 1730 | struct inet6_ifaddr *ift; |
| 1731 | #endif |
| 1732 | u32 stored_lft; |
| 1733 | |
| 1734 | /* update lifetime (RFC2462 5.5.3 e) */ |
| 1735 | spin_lock(&ifp->lock); |
| 1736 | now = jiffies; |
| 1737 | if (ifp->valid_lft > (now - ifp->tstamp) / HZ) |
| 1738 | stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; |
| 1739 | else |
| 1740 | stored_lft = 0; |
| 1741 | if (!update_lft && stored_lft) { |
| 1742 | if (valid_lft > MIN_VALID_LIFETIME || |
| 1743 | valid_lft > stored_lft) |
| 1744 | update_lft = 1; |
| 1745 | else if (stored_lft <= MIN_VALID_LIFETIME) { |
| 1746 | /* valid_lft <= stored_lft is always true */ |
| 1747 | /* XXX: IPsec */ |
| 1748 | update_lft = 0; |
| 1749 | } else { |
| 1750 | valid_lft = MIN_VALID_LIFETIME; |
| 1751 | if (valid_lft < prefered_lft) |
| 1752 | prefered_lft = valid_lft; |
| 1753 | update_lft = 1; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | if (update_lft) { |
| 1758 | ifp->valid_lft = valid_lft; |
| 1759 | ifp->prefered_lft = prefered_lft; |
| 1760 | ifp->tstamp = now; |
| 1761 | flags = ifp->flags; |
| 1762 | ifp->flags &= ~IFA_F_DEPRECATED; |
| 1763 | spin_unlock(&ifp->lock); |
| 1764 | |
| 1765 | if (!(flags&IFA_F_TENTATIVE)) |
| 1766 | ipv6_ifa_notify(0, ifp); |
| 1767 | } else |
| 1768 | spin_unlock(&ifp->lock); |
| 1769 | |
| 1770 | #ifdef CONFIG_IPV6_PRIVACY |
| 1771 | read_lock_bh(&in6_dev->lock); |
| 1772 | /* update all temporary addresses in the list */ |
| 1773 | for (ift=in6_dev->tempaddr_list; ift; ift=ift->tmp_next) { |
| 1774 | /* |
| 1775 | * When adjusting the lifetimes of an existing |
| 1776 | * temporary address, only lower the lifetimes. |
| 1777 | * Implementations must not increase the |
| 1778 | * lifetimes of an existing temporary address |
| 1779 | * when processing a Prefix Information Option. |
| 1780 | */ |
| 1781 | spin_lock(&ift->lock); |
| 1782 | flags = ift->flags; |
| 1783 | if (ift->valid_lft > valid_lft && |
| 1784 | ift->valid_lft - valid_lft > (jiffies - ift->tstamp) / HZ) |
| 1785 | ift->valid_lft = valid_lft + (jiffies - ift->tstamp) / HZ; |
| 1786 | if (ift->prefered_lft > prefered_lft && |
| 1787 | ift->prefered_lft - prefered_lft > (jiffies - ift->tstamp) / HZ) |
| 1788 | ift->prefered_lft = prefered_lft + (jiffies - ift->tstamp) / HZ; |
| 1789 | spin_unlock(&ift->lock); |
| 1790 | if (!(flags&IFA_F_TENTATIVE)) |
| 1791 | ipv6_ifa_notify(0, ift); |
| 1792 | } |
| 1793 | |
| 1794 | if (create && in6_dev->cnf.use_tempaddr > 0) { |
| 1795 | /* |
| 1796 | * When a new public address is created as described in [ADDRCONF], |
| 1797 | * also create a new temporary address. |
| 1798 | */ |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1799 | read_unlock_bh(&in6_dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | ipv6_create_tempaddr(ifp, NULL); |
| 1801 | } else { |
| 1802 | read_unlock_bh(&in6_dev->lock); |
| 1803 | } |
| 1804 | #endif |
| 1805 | in6_ifa_put(ifp); |
| 1806 | addrconf_verify(0); |
| 1807 | } |
| 1808 | } |
| 1809 | inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo); |
| 1810 | in6_dev_put(in6_dev); |
| 1811 | } |
| 1812 | |
| 1813 | /* |
| 1814 | * Set destination address. |
| 1815 | * Special case for SIT interfaces where we create a new "virtual" |
| 1816 | * device. |
| 1817 | */ |
| 1818 | int addrconf_set_dstaddr(void __user *arg) |
| 1819 | { |
| 1820 | struct in6_ifreq ireq; |
| 1821 | struct net_device *dev; |
| 1822 | int err = -EINVAL; |
| 1823 | |
| 1824 | rtnl_lock(); |
| 1825 | |
| 1826 | err = -EFAULT; |
| 1827 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 1828 | goto err_exit; |
| 1829 | |
| 1830 | dev = __dev_get_by_index(ireq.ifr6_ifindex); |
| 1831 | |
| 1832 | err = -ENODEV; |
| 1833 | if (dev == NULL) |
| 1834 | goto err_exit; |
| 1835 | |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1836 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | if (dev->type == ARPHRD_SIT) { |
| 1838 | struct ifreq ifr; |
| 1839 | mm_segment_t oldfs; |
| 1840 | struct ip_tunnel_parm p; |
| 1841 | |
| 1842 | err = -EADDRNOTAVAIL; |
| 1843 | if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4)) |
| 1844 | goto err_exit; |
| 1845 | |
| 1846 | memset(&p, 0, sizeof(p)); |
| 1847 | p.iph.daddr = ireq.ifr6_addr.s6_addr32[3]; |
| 1848 | p.iph.saddr = 0; |
| 1849 | p.iph.version = 4; |
| 1850 | p.iph.ihl = 5; |
| 1851 | p.iph.protocol = IPPROTO_IPV6; |
| 1852 | p.iph.ttl = 64; |
| 1853 | ifr.ifr_ifru.ifru_data = (void __user *)&p; |
| 1854 | |
| 1855 | oldfs = get_fs(); set_fs(KERNEL_DS); |
| 1856 | err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL); |
| 1857 | set_fs(oldfs); |
| 1858 | |
| 1859 | if (err == 0) { |
| 1860 | err = -ENOBUFS; |
| 1861 | if ((dev = __dev_get_by_name(p.name)) == NULL) |
| 1862 | goto err_exit; |
| 1863 | err = dev_open(dev); |
| 1864 | } |
| 1865 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1866 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
| 1868 | err_exit: |
| 1869 | rtnl_unlock(); |
| 1870 | return err; |
| 1871 | } |
| 1872 | |
| 1873 | /* |
| 1874 | * Manual configuration of address on an interface |
| 1875 | */ |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1876 | static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen, |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 1877 | __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | { |
| 1879 | struct inet6_ifaddr *ifp; |
| 1880 | struct inet6_dev *idev; |
| 1881 | struct net_device *dev; |
| 1882 | int scope; |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 1883 | u32 flags = RTF_EXPIRES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
| 1885 | ASSERT_RTNL(); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1886 | |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1887 | /* check the lifetime */ |
| 1888 | if (!valid_lft || prefered_lft > valid_lft) |
| 1889 | return -EINVAL; |
| 1890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | if ((dev = __dev_get_by_index(ifindex)) == NULL) |
| 1892 | return -ENODEV; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if ((idev = addrconf_add_dev(dev)) == NULL) |
| 1895 | return -ENOBUFS; |
| 1896 | |
| 1897 | scope = ipv6_addr_scope(pfx); |
| 1898 | |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 1899 | if (valid_lft == INFINITY_LIFE_TIME) { |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1900 | ifa_flags |= IFA_F_PERMANENT; |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 1901 | flags = 0; |
| 1902 | } else if (valid_lft >= 0x7FFFFFFF/HZ) |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1903 | valid_lft = 0x7FFFFFFF/HZ; |
| 1904 | |
| 1905 | if (prefered_lft == 0) |
| 1906 | ifa_flags |= IFA_F_DEPRECATED; |
| 1907 | else if ((prefered_lft >= 0x7FFFFFFF/HZ) && |
| 1908 | (prefered_lft != INFINITY_LIFE_TIME)) |
| 1909 | prefered_lft = 0x7FFFFFFF/HZ; |
| 1910 | |
| 1911 | ifp = ipv6_add_addr(idev, pfx, plen, scope, ifa_flags); |
| 1912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | if (!IS_ERR(ifp)) { |
Herbert Xu | 06aebfb | 2006-08-09 16:52:04 -0700 | [diff] [blame] | 1914 | spin_lock_bh(&ifp->lock); |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1915 | ifp->valid_lft = valid_lft; |
| 1916 | ifp->prefered_lft = prefered_lft; |
| 1917 | ifp->tstamp = jiffies; |
Herbert Xu | 06aebfb | 2006-08-09 16:52:04 -0700 | [diff] [blame] | 1918 | spin_unlock_bh(&ifp->lock); |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1919 | |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 1920 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, |
| 1921 | jiffies_to_clock_t(valid_lft * HZ), flags); |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1922 | /* |
| 1923 | * Note that section 3.1 of RFC 4429 indicates |
| 1924 | * that the Optimistic flag should not be set for |
| 1925 | * manually configured addresses |
| 1926 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | addrconf_dad_start(ifp, 0); |
| 1928 | in6_ifa_put(ifp); |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1929 | addrconf_verify(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | return PTR_ERR(ifp); |
| 1934 | } |
| 1935 | |
| 1936 | static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen) |
| 1937 | { |
| 1938 | struct inet6_ifaddr *ifp; |
| 1939 | struct inet6_dev *idev; |
| 1940 | struct net_device *dev; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | if ((dev = __dev_get_by_index(ifindex)) == NULL) |
| 1943 | return -ENODEV; |
| 1944 | |
| 1945 | if ((idev = __in6_dev_get(dev)) == NULL) |
| 1946 | return -ENXIO; |
| 1947 | |
| 1948 | read_lock_bh(&idev->lock); |
| 1949 | for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) { |
| 1950 | if (ifp->prefix_len == plen && |
| 1951 | ipv6_addr_equal(pfx, &ifp->addr)) { |
| 1952 | in6_ifa_hold(ifp); |
| 1953 | read_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | ipv6_del_addr(ifp); |
| 1956 | |
| 1957 | /* If the last address is deleted administratively, |
| 1958 | disable IPv6 on this interface. |
| 1959 | */ |
| 1960 | if (idev->addr_list == NULL) |
| 1961 | addrconf_ifdown(idev->dev, 1); |
| 1962 | return 0; |
| 1963 | } |
| 1964 | } |
| 1965 | read_unlock_bh(&idev->lock); |
| 1966 | return -EADDRNOTAVAIL; |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | int addrconf_add_ifaddr(void __user *arg) |
| 1971 | { |
| 1972 | struct in6_ifreq ireq; |
| 1973 | int err; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | if (!capable(CAP_NET_ADMIN)) |
| 1976 | return -EPERM; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 1979 | return -EFAULT; |
| 1980 | |
| 1981 | rtnl_lock(); |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 1982 | err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen, |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 1983 | IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | rtnl_unlock(); |
| 1985 | return err; |
| 1986 | } |
| 1987 | |
| 1988 | int addrconf_del_ifaddr(void __user *arg) |
| 1989 | { |
| 1990 | struct in6_ifreq ireq; |
| 1991 | int err; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | if (!capable(CAP_NET_ADMIN)) |
| 1994 | return -EPERM; |
| 1995 | |
| 1996 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 1997 | return -EFAULT; |
| 1998 | |
| 1999 | rtnl_lock(); |
| 2000 | err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen); |
| 2001 | rtnl_unlock(); |
| 2002 | return err; |
| 2003 | } |
| 2004 | |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2005 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | static void sit_add_v4_addrs(struct inet6_dev *idev) |
| 2007 | { |
| 2008 | struct inet6_ifaddr * ifp; |
| 2009 | struct in6_addr addr; |
| 2010 | struct net_device *dev; |
| 2011 | int scope; |
| 2012 | |
| 2013 | ASSERT_RTNL(); |
| 2014 | |
| 2015 | memset(&addr, 0, sizeof(struct in6_addr)); |
| 2016 | memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4); |
| 2017 | |
| 2018 | if (idev->dev->flags&IFF_POINTOPOINT) { |
| 2019 | addr.s6_addr32[0] = htonl(0xfe800000); |
| 2020 | scope = IFA_LINK; |
| 2021 | } else { |
| 2022 | scope = IPV6_ADDR_COMPATv4; |
| 2023 | } |
| 2024 | |
| 2025 | if (addr.s6_addr32[3]) { |
| 2026 | ifp = ipv6_add_addr(idev, &addr, 128, scope, IFA_F_PERMANENT); |
| 2027 | if (!IS_ERR(ifp)) { |
| 2028 | spin_lock_bh(&ifp->lock); |
| 2029 | ifp->flags &= ~IFA_F_TENTATIVE; |
| 2030 | spin_unlock_bh(&ifp->lock); |
| 2031 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 2032 | in6_ifa_put(ifp); |
| 2033 | } |
| 2034 | return; |
| 2035 | } |
| 2036 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2037 | for (dev = dev_base; dev != NULL; dev = dev->next) { |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 2038 | struct in_device * in_dev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | if (in_dev && (dev->flags & IFF_UP)) { |
| 2040 | struct in_ifaddr * ifa; |
| 2041 | |
| 2042 | int flag = scope; |
| 2043 | |
| 2044 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 2045 | int plen; |
| 2046 | |
| 2047 | addr.s6_addr32[3] = ifa->ifa_local; |
| 2048 | |
| 2049 | if (ifa->ifa_scope == RT_SCOPE_LINK) |
| 2050 | continue; |
| 2051 | if (ifa->ifa_scope >= RT_SCOPE_HOST) { |
| 2052 | if (idev->dev->flags&IFF_POINTOPOINT) |
| 2053 | continue; |
| 2054 | flag |= IFA_HOST; |
| 2055 | } |
| 2056 | if (idev->dev->flags&IFF_POINTOPOINT) |
| 2057 | plen = 64; |
| 2058 | else |
| 2059 | plen = 96; |
| 2060 | |
| 2061 | ifp = ipv6_add_addr(idev, &addr, plen, flag, |
| 2062 | IFA_F_PERMANENT); |
| 2063 | if (!IS_ERR(ifp)) { |
| 2064 | spin_lock_bh(&ifp->lock); |
| 2065 | ifp->flags &= ~IFA_F_TENTATIVE; |
| 2066 | spin_unlock_bh(&ifp->lock); |
| 2067 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 2068 | in6_ifa_put(ifp); |
| 2069 | } |
| 2070 | } |
| 2071 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2074 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | |
| 2076 | static void init_loopback(struct net_device *dev) |
| 2077 | { |
| 2078 | struct inet6_dev *idev; |
| 2079 | struct inet6_ifaddr * ifp; |
| 2080 | |
| 2081 | /* ::1 */ |
| 2082 | |
| 2083 | ASSERT_RTNL(); |
| 2084 | |
| 2085 | if ((idev = ipv6_find_idev(dev)) == NULL) { |
| 2086 | printk(KERN_DEBUG "init loopback: add_dev failed\n"); |
| 2087 | return; |
| 2088 | } |
| 2089 | |
| 2090 | ifp = ipv6_add_addr(idev, &in6addr_loopback, 128, IFA_HOST, IFA_F_PERMANENT); |
| 2091 | if (!IS_ERR(ifp)) { |
| 2092 | spin_lock_bh(&ifp->lock); |
| 2093 | ifp->flags &= ~IFA_F_TENTATIVE; |
| 2094 | spin_unlock_bh(&ifp->lock); |
| 2095 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 2096 | in6_ifa_put(ifp); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr) |
| 2101 | { |
| 2102 | struct inet6_ifaddr * ifp; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2103 | u32 addr_flags = IFA_F_PERMANENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2105 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 2106 | if (idev->cnf.optimistic_dad && |
| 2107 | !ipv6_devconf.forwarding) |
| 2108 | addr_flags |= IFA_F_OPTIMISTIC; |
| 2109 | #endif |
| 2110 | |
| 2111 | |
| 2112 | ifp = ipv6_add_addr(idev, addr, 64, IFA_LINK, addr_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | if (!IS_ERR(ifp)) { |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2114 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | addrconf_dad_start(ifp, 0); |
| 2116 | in6_ifa_put(ifp); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | static void addrconf_dev_config(struct net_device *dev) |
| 2121 | { |
| 2122 | struct in6_addr addr; |
| 2123 | struct inet6_dev * idev; |
| 2124 | |
| 2125 | ASSERT_RTNL(); |
| 2126 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2127 | if ((dev->type != ARPHRD_ETHER) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | (dev->type != ARPHRD_FDDI) && |
| 2129 | (dev->type != ARPHRD_IEEE802_TR) && |
| 2130 | (dev->type != ARPHRD_ARCNET) && |
| 2131 | (dev->type != ARPHRD_INFINIBAND)) { |
| 2132 | /* Alas, we support only Ethernet autoconfiguration. */ |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | idev = addrconf_add_dev(dev); |
| 2137 | if (idev == NULL) |
| 2138 | return; |
| 2139 | |
| 2140 | memset(&addr, 0, sizeof(struct in6_addr)); |
| 2141 | addr.s6_addr32[0] = htonl(0xFE800000); |
| 2142 | |
| 2143 | if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0) |
| 2144 | addrconf_add_linklocal(idev, &addr); |
| 2145 | } |
| 2146 | |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2147 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | static void addrconf_sit_config(struct net_device *dev) |
| 2149 | { |
| 2150 | struct inet6_dev *idev; |
| 2151 | |
| 2152 | ASSERT_RTNL(); |
| 2153 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2154 | /* |
| 2155 | * Configure the tunnel with one of our IPv4 |
| 2156 | * addresses... we should configure all of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | * our v4 addrs in the tunnel |
| 2158 | */ |
| 2159 | |
| 2160 | if ((idev = ipv6_find_idev(dev)) == NULL) { |
| 2161 | printk(KERN_DEBUG "init sit: add_dev failed\n"); |
| 2162 | return; |
| 2163 | } |
| 2164 | |
| 2165 | sit_add_v4_addrs(idev); |
| 2166 | |
| 2167 | if (dev->flags&IFF_POINTOPOINT) { |
| 2168 | addrconf_add_mroute(dev); |
| 2169 | addrconf_add_lroute(dev); |
| 2170 | } else |
| 2171 | sit_route_add(dev); |
| 2172 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2173 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
| 2175 | static inline int |
| 2176 | ipv6_inherit_linklocal(struct inet6_dev *idev, struct net_device *link_dev) |
| 2177 | { |
| 2178 | struct in6_addr lladdr; |
| 2179 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2180 | if (!ipv6_get_lladdr(link_dev, &lladdr, IFA_F_TENTATIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | addrconf_add_linklocal(idev, &lladdr); |
| 2182 | return 0; |
| 2183 | } |
| 2184 | return -1; |
| 2185 | } |
| 2186 | |
| 2187 | static void ip6_tnl_add_linklocal(struct inet6_dev *idev) |
| 2188 | { |
| 2189 | struct net_device *link_dev; |
| 2190 | |
| 2191 | /* first try to inherit the link-local address from the link device */ |
| 2192 | if (idev->dev->iflink && |
| 2193 | (link_dev = __dev_get_by_index(idev->dev->iflink))) { |
| 2194 | if (!ipv6_inherit_linklocal(idev, link_dev)) |
| 2195 | return; |
| 2196 | } |
| 2197 | /* then try to inherit it from any device */ |
| 2198 | for (link_dev = dev_base; link_dev; link_dev = link_dev->next) { |
| 2199 | if (!ipv6_inherit_linklocal(idev, link_dev)) |
| 2200 | return; |
| 2201 | } |
| 2202 | printk(KERN_DEBUG "init ip6-ip6: add_linklocal failed\n"); |
| 2203 | } |
| 2204 | |
| 2205 | /* |
| 2206 | * Autoconfigure tunnel with a link-local address so routing protocols, |
| 2207 | * DHCPv6, MLD etc. can be run over the virtual link |
| 2208 | */ |
| 2209 | |
| 2210 | static void addrconf_ip6_tnl_config(struct net_device *dev) |
| 2211 | { |
| 2212 | struct inet6_dev *idev; |
| 2213 | |
| 2214 | ASSERT_RTNL(); |
| 2215 | |
| 2216 | if ((idev = addrconf_add_dev(dev)) == NULL) { |
| 2217 | printk(KERN_DEBUG "init ip6-ip6: add_dev failed\n"); |
| 2218 | return; |
| 2219 | } |
| 2220 | ip6_tnl_add_linklocal(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2223 | static int addrconf_notify(struct notifier_block *this, unsigned long event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | void * data) |
| 2225 | { |
| 2226 | struct net_device *dev = (struct net_device *) data; |
| 2227 | struct inet6_dev *idev = __in6_dev_get(dev); |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2228 | int run_pending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | |
| 2230 | switch(event) { |
YOSHIFUJI Hideaki | 45ba9dd | 2007-02-15 02:07:27 +0900 | [diff] [blame] | 2231 | case NETDEV_REGISTER: |
| 2232 | if (!idev) { |
| 2233 | idev = ipv6_add_dev(dev); |
| 2234 | if (!idev) |
| 2235 | printk(KERN_WARNING "IPv6: add_dev failed for %s\n", |
| 2236 | dev->name); |
| 2237 | } |
| 2238 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | case NETDEV_UP: |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2240 | case NETDEV_CHANGE: |
| 2241 | if (event == NETDEV_UP) { |
| 2242 | if (!netif_carrier_ok(dev)) { |
| 2243 | /* device is not ready yet. */ |
| 2244 | printk(KERN_INFO |
| 2245 | "ADDRCONF(NETDEV_UP): %s: " |
| 2246 | "link is not ready\n", |
| 2247 | dev->name); |
| 2248 | break; |
| 2249 | } |
Kristian Slavov | 9908104 | 2006-02-08 16:10:53 -0800 | [diff] [blame] | 2250 | |
| 2251 | if (idev) |
| 2252 | idev->if_flags |= IF_READY; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2253 | } else { |
| 2254 | if (!netif_carrier_ok(dev)) { |
| 2255 | /* device is still not ready. */ |
| 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | if (idev) { |
| 2260 | if (idev->if_flags & IF_READY) { |
| 2261 | /* device is already configured. */ |
| 2262 | break; |
| 2263 | } |
| 2264 | idev->if_flags |= IF_READY; |
| 2265 | } |
| 2266 | |
| 2267 | printk(KERN_INFO |
| 2268 | "ADDRCONF(NETDEV_CHANGE): %s: " |
| 2269 | "link becomes ready\n", |
| 2270 | dev->name); |
| 2271 | |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2272 | run_pending = 1; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2273 | } |
| 2274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | switch(dev->type) { |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2276 | #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | case ARPHRD_SIT: |
| 2278 | addrconf_sit_config(dev); |
| 2279 | break; |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2280 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | case ARPHRD_TUNNEL6: |
| 2282 | addrconf_ip6_tnl_config(dev); |
| 2283 | break; |
| 2284 | case ARPHRD_LOOPBACK: |
| 2285 | init_loopback(dev); |
| 2286 | break; |
| 2287 | |
| 2288 | default: |
| 2289 | addrconf_dev_config(dev); |
| 2290 | break; |
| 2291 | }; |
| 2292 | if (idev) { |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2293 | if (run_pending) |
| 2294 | addrconf_dad_run(idev); |
| 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | /* If the MTU changed during the interface down, when the |
| 2297 | interface up, the changed MTU must be reflected in the |
| 2298 | idev as well as routers. |
| 2299 | */ |
| 2300 | if (idev->cnf.mtu6 != dev->mtu && dev->mtu >= IPV6_MIN_MTU) { |
| 2301 | rt6_mtu_change(dev, dev->mtu); |
| 2302 | idev->cnf.mtu6 = dev->mtu; |
| 2303 | } |
| 2304 | idev->tstamp = jiffies; |
| 2305 | inet6_ifinfo_notify(RTM_NEWLINK, idev); |
| 2306 | /* If the changed mtu during down is lower than IPV6_MIN_MTU |
| 2307 | stop IPv6 on this interface. |
| 2308 | */ |
| 2309 | if (dev->mtu < IPV6_MIN_MTU) |
| 2310 | addrconf_ifdown(dev, event != NETDEV_DOWN); |
| 2311 | } |
| 2312 | break; |
| 2313 | |
| 2314 | case NETDEV_CHANGEMTU: |
| 2315 | if ( idev && dev->mtu >= IPV6_MIN_MTU) { |
| 2316 | rt6_mtu_change(dev, dev->mtu); |
| 2317 | idev->cnf.mtu6 = dev->mtu; |
| 2318 | break; |
| 2319 | } |
| 2320 | |
| 2321 | /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */ |
| 2322 | |
| 2323 | case NETDEV_DOWN: |
| 2324 | case NETDEV_UNREGISTER: |
| 2325 | /* |
| 2326 | * Remove all addresses from this interface. |
| 2327 | */ |
| 2328 | addrconf_ifdown(dev, event != NETDEV_DOWN); |
| 2329 | break; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | case NETDEV_CHANGENAME: |
| 2332 | #ifdef CONFIG_SYSCTL |
| 2333 | if (idev) { |
| 2334 | addrconf_sysctl_unregister(&idev->cnf); |
| 2335 | neigh_sysctl_unregister(idev->nd_parms); |
| 2336 | neigh_sysctl_register(dev, idev->nd_parms, |
| 2337 | NET_IPV6, NET_IPV6_NEIGH, "ipv6", |
| 2338 | &ndisc_ifinfo_sysctl_change, |
| 2339 | NULL); |
| 2340 | addrconf_sysctl_register(idev, &idev->cnf); |
| 2341 | } |
| 2342 | #endif |
| 2343 | break; |
| 2344 | }; |
| 2345 | |
| 2346 | return NOTIFY_OK; |
| 2347 | } |
| 2348 | |
| 2349 | /* |
| 2350 | * addrconf module should be notified of a device going up |
| 2351 | */ |
| 2352 | static struct notifier_block ipv6_dev_notf = { |
| 2353 | .notifier_call = addrconf_notify, |
| 2354 | .priority = 0 |
| 2355 | }; |
| 2356 | |
| 2357 | static int addrconf_ifdown(struct net_device *dev, int how) |
| 2358 | { |
| 2359 | struct inet6_dev *idev; |
| 2360 | struct inet6_ifaddr *ifa, **bifa; |
| 2361 | int i; |
| 2362 | |
| 2363 | ASSERT_RTNL(); |
| 2364 | |
| 2365 | if (dev == &loopback_dev && how == 1) |
| 2366 | how = 0; |
| 2367 | |
| 2368 | rt6_ifdown(dev); |
| 2369 | neigh_ifdown(&nd_tbl, dev); |
| 2370 | |
| 2371 | idev = __in6_dev_get(dev); |
| 2372 | if (idev == NULL) |
| 2373 | return -ENODEV; |
| 2374 | |
| 2375 | /* Step 1: remove reference to ipv6 device from parent device. |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2376 | Do not dev_put! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | */ |
| 2378 | if (how == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | idev->dead = 1; |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 2380 | |
| 2381 | /* protected by rtnl_lock */ |
| 2382 | rcu_assign_pointer(dev->ip6_ptr, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
| 2384 | /* Step 1.5: remove snmp6 entry */ |
| 2385 | snmp6_unregister_dev(idev); |
| 2386 | |
| 2387 | } |
| 2388 | |
| 2389 | /* Step 2: clear hash table */ |
| 2390 | for (i=0; i<IN6_ADDR_HSIZE; i++) { |
| 2391 | bifa = &inet6_addr_lst[i]; |
| 2392 | |
| 2393 | write_lock_bh(&addrconf_hash_lock); |
| 2394 | while ((ifa = *bifa) != NULL) { |
| 2395 | if (ifa->idev == idev) { |
| 2396 | *bifa = ifa->lst_next; |
| 2397 | ifa->lst_next = NULL; |
| 2398 | addrconf_del_timer(ifa); |
| 2399 | in6_ifa_put(ifa); |
| 2400 | continue; |
| 2401 | } |
| 2402 | bifa = &ifa->lst_next; |
| 2403 | } |
| 2404 | write_unlock_bh(&addrconf_hash_lock); |
| 2405 | } |
| 2406 | |
| 2407 | write_lock_bh(&idev->lock); |
| 2408 | |
| 2409 | /* Step 3: clear flags for stateless addrconf */ |
| 2410 | if (how != 1) |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2411 | idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | |
| 2413 | /* Step 4: clear address list */ |
| 2414 | #ifdef CONFIG_IPV6_PRIVACY |
| 2415 | if (how == 1 && del_timer(&idev->regen_timer)) |
| 2416 | in6_dev_put(idev); |
| 2417 | |
| 2418 | /* clear tempaddr list */ |
| 2419 | while ((ifa = idev->tempaddr_list) != NULL) { |
| 2420 | idev->tempaddr_list = ifa->tmp_next; |
| 2421 | ifa->tmp_next = NULL; |
| 2422 | ifa->dead = 1; |
| 2423 | write_unlock_bh(&idev->lock); |
| 2424 | spin_lock_bh(&ifa->lock); |
| 2425 | |
| 2426 | if (ifa->ifpub) { |
| 2427 | in6_ifa_put(ifa->ifpub); |
| 2428 | ifa->ifpub = NULL; |
| 2429 | } |
| 2430 | spin_unlock_bh(&ifa->lock); |
| 2431 | in6_ifa_put(ifa); |
| 2432 | write_lock_bh(&idev->lock); |
| 2433 | } |
| 2434 | #endif |
| 2435 | while ((ifa = idev->addr_list) != NULL) { |
| 2436 | idev->addr_list = ifa->if_next; |
| 2437 | ifa->if_next = NULL; |
| 2438 | ifa->dead = 1; |
| 2439 | addrconf_del_timer(ifa); |
| 2440 | write_unlock_bh(&idev->lock); |
| 2441 | |
| 2442 | __ipv6_ifa_notify(RTM_DELADDR, ifa); |
| 2443 | in6_ifa_put(ifa); |
| 2444 | |
| 2445 | write_lock_bh(&idev->lock); |
| 2446 | } |
| 2447 | write_unlock_bh(&idev->lock); |
| 2448 | |
| 2449 | /* Step 5: Discard multicast list */ |
| 2450 | |
| 2451 | if (how == 1) |
| 2452 | ipv6_mc_destroy_dev(idev); |
| 2453 | else |
| 2454 | ipv6_mc_down(idev); |
| 2455 | |
| 2456 | /* Step 5: netlink notification of this interface */ |
| 2457 | idev->tstamp = jiffies; |
Yan Zheng | 979ad66 | 2005-10-14 18:31:15 +0800 | [diff] [blame] | 2458 | inet6_ifinfo_notify(RTM_DELLINK, idev); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | /* Shot the device (if unregistered) */ |
| 2461 | |
| 2462 | if (how == 1) { |
| 2463 | #ifdef CONFIG_SYSCTL |
| 2464 | addrconf_sysctl_unregister(&idev->cnf); |
| 2465 | neigh_sysctl_unregister(idev->nd_parms); |
| 2466 | #endif |
| 2467 | neigh_parms_release(&nd_tbl, idev->nd_parms); |
| 2468 | neigh_ifdown(&nd_tbl, dev); |
| 2469 | in6_dev_put(idev); |
| 2470 | } |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
| 2474 | static void addrconf_rs_timer(unsigned long data) |
| 2475 | { |
| 2476 | struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; |
| 2477 | |
| 2478 | if (ifp->idev->cnf.forwarding) |
| 2479 | goto out; |
| 2480 | |
| 2481 | if (ifp->idev->if_flags & IF_RA_RCVD) { |
| 2482 | /* |
| 2483 | * Announcement received after solicitation |
| 2484 | * was sent |
| 2485 | */ |
| 2486 | goto out; |
| 2487 | } |
| 2488 | |
| 2489 | spin_lock(&ifp->lock); |
| 2490 | if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) { |
| 2491 | struct in6_addr all_routers; |
| 2492 | |
| 2493 | /* The wait after the last probe can be shorter */ |
| 2494 | addrconf_mod_timer(ifp, AC_RS, |
| 2495 | (ifp->probes == ifp->idev->cnf.rtr_solicits) ? |
| 2496 | ifp->idev->cnf.rtr_solicit_delay : |
| 2497 | ifp->idev->cnf.rtr_solicit_interval); |
| 2498 | spin_unlock(&ifp->lock); |
| 2499 | |
| 2500 | ipv6_addr_all_routers(&all_routers); |
| 2501 | |
| 2502 | ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers); |
| 2503 | } else { |
| 2504 | spin_unlock(&ifp->lock); |
| 2505 | /* |
| 2506 | * Note: we do not support deprecated "all on-link" |
| 2507 | * assumption any longer. |
| 2508 | */ |
| 2509 | printk(KERN_DEBUG "%s: no IPv6 routers present\n", |
| 2510 | ifp->idev->dev->name); |
| 2511 | } |
| 2512 | |
| 2513 | out: |
| 2514 | in6_ifa_put(ifp); |
| 2515 | } |
| 2516 | |
| 2517 | /* |
| 2518 | * Duplicate Address Detection |
| 2519 | */ |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2520 | static void addrconf_dad_kick(struct inet6_ifaddr *ifp) |
| 2521 | { |
| 2522 | unsigned long rand_num; |
| 2523 | struct inet6_dev *idev = ifp->idev; |
| 2524 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2525 | if (ifp->flags & IFA_F_OPTIMISTIC) |
| 2526 | rand_num = 0; |
| 2527 | else |
| 2528 | rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1); |
| 2529 | |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2530 | ifp->probes = idev->cnf.dad_transmits; |
| 2531 | addrconf_mod_timer(ifp, AC_DAD, rand_num); |
| 2532 | } |
| 2533 | |
Jamal Hadi Salim | e431b8c | 2005-06-18 22:55:31 -0700 | [diff] [blame] | 2534 | static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | { |
| 2536 | struct inet6_dev *idev = ifp->idev; |
| 2537 | struct net_device *dev = idev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | |
| 2539 | addrconf_join_solict(dev, &ifp->addr); |
| 2540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | net_srandom(ifp->addr.s6_addr32[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
| 2543 | read_lock_bh(&idev->lock); |
| 2544 | if (ifp->dead) |
| 2545 | goto out; |
| 2546 | spin_lock_bh(&ifp->lock); |
| 2547 | |
| 2548 | if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 2549 | !(ifp->flags&IFA_F_TENTATIVE) || |
| 2550 | ifp->flags & IFA_F_NODAD) { |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2551 | ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | spin_unlock_bh(&ifp->lock); |
| 2553 | read_unlock_bh(&idev->lock); |
| 2554 | |
| 2555 | addrconf_dad_completed(ifp); |
| 2556 | return; |
| 2557 | } |
| 2558 | |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 2559 | if (!(idev->if_flags & IF_READY)) { |
YOSHIFUJI Hideaki | 3dd3bf8 | 2005-12-23 11:23:21 -0800 | [diff] [blame] | 2560 | spin_unlock_bh(&ifp->lock); |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 2561 | read_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2562 | /* |
| 2563 | * If the defice is not ready: |
| 2564 | * - keep it tentative if it is a permanent address. |
| 2565 | * - otherwise, kill it. |
| 2566 | */ |
| 2567 | in6_ifa_hold(ifp); |
| 2568 | addrconf_dad_stop(ifp); |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 2569 | return; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2570 | } |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2571 | |
| 2572 | /* |
| 2573 | * Optimistic nodes can start receiving |
| 2574 | * Frames right away |
| 2575 | */ |
| 2576 | if(ifp->flags & IFA_F_OPTIMISTIC) |
| 2577 | ip6_ins_rt(ifp->rt); |
| 2578 | |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 2579 | addrconf_dad_kick(ifp); |
| 2580 | spin_unlock_bh(&ifp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | out: |
| 2582 | read_unlock_bh(&idev->lock); |
| 2583 | } |
| 2584 | |
| 2585 | static void addrconf_dad_timer(unsigned long data) |
| 2586 | { |
| 2587 | struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; |
| 2588 | struct inet6_dev *idev = ifp->idev; |
| 2589 | struct in6_addr unspec; |
| 2590 | struct in6_addr mcaddr; |
| 2591 | |
| 2592 | read_lock_bh(&idev->lock); |
| 2593 | if (idev->dead) { |
| 2594 | read_unlock_bh(&idev->lock); |
| 2595 | goto out; |
| 2596 | } |
| 2597 | spin_lock_bh(&ifp->lock); |
| 2598 | if (ifp->probes == 0) { |
| 2599 | /* |
| 2600 | * DAD was successful |
| 2601 | */ |
| 2602 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2603 | ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | spin_unlock_bh(&ifp->lock); |
| 2605 | read_unlock_bh(&idev->lock); |
| 2606 | |
| 2607 | addrconf_dad_completed(ifp); |
| 2608 | |
| 2609 | goto out; |
| 2610 | } |
| 2611 | |
| 2612 | ifp->probes--; |
| 2613 | addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time); |
| 2614 | spin_unlock_bh(&ifp->lock); |
| 2615 | read_unlock_bh(&idev->lock); |
| 2616 | |
| 2617 | /* send a neighbour solicitation for our addr */ |
| 2618 | memset(&unspec, 0, sizeof(unspec)); |
| 2619 | addrconf_addr_solict_mult(&ifp->addr, &mcaddr); |
| 2620 | ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &unspec); |
| 2621 | out: |
| 2622 | in6_ifa_put(ifp); |
| 2623 | } |
| 2624 | |
| 2625 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp) |
| 2626 | { |
| 2627 | struct net_device * dev = ifp->idev->dev; |
| 2628 | |
| 2629 | /* |
| 2630 | * Configure the address for reception. Now it is valid. |
| 2631 | */ |
| 2632 | |
| 2633 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 2634 | |
| 2635 | /* If added prefix is link local and forwarding is off, |
| 2636 | start sending router solicitations. |
| 2637 | */ |
| 2638 | |
| 2639 | if (ifp->idev->cnf.forwarding == 0 && |
| 2640 | ifp->idev->cnf.rtr_solicits > 0 && |
| 2641 | (dev->flags&IFF_LOOPBACK) == 0 && |
| 2642 | (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) { |
| 2643 | struct in6_addr all_routers; |
| 2644 | |
| 2645 | ipv6_addr_all_routers(&all_routers); |
| 2646 | |
| 2647 | /* |
| 2648 | * If a host as already performed a random delay |
| 2649 | * [...] as part of DAD [...] there is no need |
| 2650 | * to delay again before sending the first RS |
| 2651 | */ |
| 2652 | ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers); |
| 2653 | |
| 2654 | spin_lock_bh(&ifp->lock); |
| 2655 | ifp->probes = 1; |
| 2656 | ifp->idev->if_flags |= IF_RS_SENT; |
| 2657 | addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval); |
| 2658 | spin_unlock_bh(&ifp->lock); |
| 2659 | } |
| 2660 | } |
| 2661 | |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2662 | static void addrconf_dad_run(struct inet6_dev *idev) { |
| 2663 | struct inet6_ifaddr *ifp; |
| 2664 | |
| 2665 | read_lock_bh(&idev->lock); |
| 2666 | for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) { |
| 2667 | spin_lock_bh(&ifp->lock); |
| 2668 | if (!(ifp->flags & IFA_F_TENTATIVE)) { |
| 2669 | spin_unlock_bh(&ifp->lock); |
| 2670 | continue; |
| 2671 | } |
| 2672 | spin_unlock_bh(&ifp->lock); |
| 2673 | addrconf_dad_kick(ifp); |
| 2674 | } |
| 2675 | read_unlock_bh(&idev->lock); |
| 2676 | } |
| 2677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | #ifdef CONFIG_PROC_FS |
| 2679 | struct if6_iter_state { |
| 2680 | int bucket; |
| 2681 | }; |
| 2682 | |
| 2683 | static struct inet6_ifaddr *if6_get_first(struct seq_file *seq) |
| 2684 | { |
| 2685 | struct inet6_ifaddr *ifa = NULL; |
| 2686 | struct if6_iter_state *state = seq->private; |
| 2687 | |
| 2688 | for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { |
| 2689 | ifa = inet6_addr_lst[state->bucket]; |
| 2690 | if (ifa) |
| 2691 | break; |
| 2692 | } |
| 2693 | return ifa; |
| 2694 | } |
| 2695 | |
| 2696 | static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa) |
| 2697 | { |
| 2698 | struct if6_iter_state *state = seq->private; |
| 2699 | |
| 2700 | ifa = ifa->lst_next; |
| 2701 | try_again: |
| 2702 | if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) { |
| 2703 | ifa = inet6_addr_lst[state->bucket]; |
| 2704 | goto try_again; |
| 2705 | } |
| 2706 | return ifa; |
| 2707 | } |
| 2708 | |
| 2709 | static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos) |
| 2710 | { |
| 2711 | struct inet6_ifaddr *ifa = if6_get_first(seq); |
| 2712 | |
| 2713 | if (ifa) |
| 2714 | while(pos && (ifa = if6_get_next(seq, ifa)) != NULL) |
| 2715 | --pos; |
| 2716 | return pos ? NULL : ifa; |
| 2717 | } |
| 2718 | |
| 2719 | static void *if6_seq_start(struct seq_file *seq, loff_t *pos) |
| 2720 | { |
| 2721 | read_lock_bh(&addrconf_hash_lock); |
| 2722 | return if6_get_idx(seq, *pos); |
| 2723 | } |
| 2724 | |
| 2725 | static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 2726 | { |
| 2727 | struct inet6_ifaddr *ifa; |
| 2728 | |
| 2729 | ifa = if6_get_next(seq, v); |
| 2730 | ++*pos; |
| 2731 | return ifa; |
| 2732 | } |
| 2733 | |
| 2734 | static void if6_seq_stop(struct seq_file *seq, void *v) |
| 2735 | { |
| 2736 | read_unlock_bh(&addrconf_hash_lock); |
| 2737 | } |
| 2738 | |
| 2739 | static int if6_seq_show(struct seq_file *seq, void *v) |
| 2740 | { |
| 2741 | struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v; |
| 2742 | seq_printf(seq, |
YOSHIFUJI Hideaki | 9343e79 | 2006-01-17 02:10:53 -0800 | [diff] [blame] | 2743 | NIP6_SEQFMT " %02x %02x %02x %02x %8s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | NIP6(ifp->addr), |
| 2745 | ifp->idev->dev->ifindex, |
| 2746 | ifp->prefix_len, |
| 2747 | ifp->scope, |
| 2748 | ifp->flags, |
| 2749 | ifp->idev->dev->name); |
| 2750 | return 0; |
| 2751 | } |
| 2752 | |
| 2753 | static struct seq_operations if6_seq_ops = { |
| 2754 | .start = if6_seq_start, |
| 2755 | .next = if6_seq_next, |
| 2756 | .show = if6_seq_show, |
| 2757 | .stop = if6_seq_stop, |
| 2758 | }; |
| 2759 | |
| 2760 | static int if6_seq_open(struct inode *inode, struct file *file) |
| 2761 | { |
| 2762 | struct seq_file *seq; |
| 2763 | int rc = -ENOMEM; |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 2764 | struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
| 2766 | if (!s) |
| 2767 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
| 2769 | rc = seq_open(file, &if6_seq_ops); |
| 2770 | if (rc) |
| 2771 | goto out_kfree; |
| 2772 | |
| 2773 | seq = file->private_data; |
| 2774 | seq->private = s; |
| 2775 | out: |
| 2776 | return rc; |
| 2777 | out_kfree: |
| 2778 | kfree(s); |
| 2779 | goto out; |
| 2780 | } |
| 2781 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 2782 | static const struct file_operations if6_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | .owner = THIS_MODULE, |
| 2784 | .open = if6_seq_open, |
| 2785 | .read = seq_read, |
| 2786 | .llseek = seq_lseek, |
| 2787 | .release = seq_release_private, |
| 2788 | }; |
| 2789 | |
| 2790 | int __init if6_proc_init(void) |
| 2791 | { |
| 2792 | if (!proc_net_fops_create("if_inet6", S_IRUGO, &if6_fops)) |
| 2793 | return -ENOMEM; |
| 2794 | return 0; |
| 2795 | } |
| 2796 | |
| 2797 | void if6_proc_exit(void) |
| 2798 | { |
| 2799 | proc_net_remove("if_inet6"); |
| 2800 | } |
| 2801 | #endif /* CONFIG_PROC_FS */ |
| 2802 | |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 2803 | #ifdef CONFIG_IPV6_MIP6 |
| 2804 | /* Check if address is a home address configured on any interface. */ |
| 2805 | int ipv6_chk_home_addr(struct in6_addr *addr) |
| 2806 | { |
| 2807 | int ret = 0; |
| 2808 | struct inet6_ifaddr * ifp; |
| 2809 | u8 hash = ipv6_addr_hash(addr); |
| 2810 | read_lock_bh(&addrconf_hash_lock); |
| 2811 | for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) { |
| 2812 | if (ipv6_addr_cmp(&ifp->addr, addr) == 0 && |
| 2813 | (ifp->flags & IFA_F_HOMEADDRESS)) { |
| 2814 | ret = 1; |
| 2815 | break; |
| 2816 | } |
| 2817 | } |
| 2818 | read_unlock_bh(&addrconf_hash_lock); |
| 2819 | return ret; |
| 2820 | } |
| 2821 | #endif |
| 2822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | /* |
| 2824 | * Periodic address status verification |
| 2825 | */ |
| 2826 | |
| 2827 | static void addrconf_verify(unsigned long foo) |
| 2828 | { |
| 2829 | struct inet6_ifaddr *ifp; |
| 2830 | unsigned long now, next; |
| 2831 | int i; |
| 2832 | |
| 2833 | spin_lock_bh(&addrconf_verify_lock); |
| 2834 | now = jiffies; |
| 2835 | next = now + ADDR_CHECK_FREQUENCY; |
| 2836 | |
| 2837 | del_timer(&addr_chk_timer); |
| 2838 | |
| 2839 | for (i=0; i < IN6_ADDR_HSIZE; i++) { |
| 2840 | |
| 2841 | restart: |
Yan Zheng | 5d5780d | 2005-11-20 13:42:20 -0800 | [diff] [blame] | 2842 | read_lock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) { |
| 2844 | unsigned long age; |
| 2845 | #ifdef CONFIG_IPV6_PRIVACY |
| 2846 | unsigned long regen_advance; |
| 2847 | #endif |
| 2848 | |
| 2849 | if (ifp->flags & IFA_F_PERMANENT) |
| 2850 | continue; |
| 2851 | |
| 2852 | spin_lock(&ifp->lock); |
| 2853 | age = (now - ifp->tstamp) / HZ; |
| 2854 | |
| 2855 | #ifdef CONFIG_IPV6_PRIVACY |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2856 | regen_advance = ifp->idev->cnf.regen_max_retry * |
| 2857 | ifp->idev->cnf.dad_transmits * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | ifp->idev->nd_parms->retrans_time / HZ; |
| 2859 | #endif |
| 2860 | |
YOSHIFUJI Hideaki | 8f27ebb | 2006-07-28 18:12:11 +0900 | [diff] [blame] | 2861 | if (ifp->valid_lft != INFINITY_LIFE_TIME && |
| 2862 | age >= ifp->valid_lft) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | spin_unlock(&ifp->lock); |
| 2864 | in6_ifa_hold(ifp); |
Yan Zheng | 5d5780d | 2005-11-20 13:42:20 -0800 | [diff] [blame] | 2865 | read_unlock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | ipv6_del_addr(ifp); |
| 2867 | goto restart; |
YOSHIFUJI Hideaki | 8f27ebb | 2006-07-28 18:12:11 +0900 | [diff] [blame] | 2868 | } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { |
| 2869 | spin_unlock(&ifp->lock); |
| 2870 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } else if (age >= ifp->prefered_lft) { |
| 2872 | /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */ |
| 2873 | int deprecate = 0; |
| 2874 | |
| 2875 | if (!(ifp->flags&IFA_F_DEPRECATED)) { |
| 2876 | deprecate = 1; |
| 2877 | ifp->flags |= IFA_F_DEPRECATED; |
| 2878 | } |
| 2879 | |
| 2880 | if (time_before(ifp->tstamp + ifp->valid_lft * HZ, next)) |
| 2881 | next = ifp->tstamp + ifp->valid_lft * HZ; |
| 2882 | |
| 2883 | spin_unlock(&ifp->lock); |
| 2884 | |
| 2885 | if (deprecate) { |
| 2886 | in6_ifa_hold(ifp); |
Yan Zheng | 5d5780d | 2005-11-20 13:42:20 -0800 | [diff] [blame] | 2887 | read_unlock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | |
| 2889 | ipv6_ifa_notify(0, ifp); |
| 2890 | in6_ifa_put(ifp); |
| 2891 | goto restart; |
| 2892 | } |
| 2893 | #ifdef CONFIG_IPV6_PRIVACY |
| 2894 | } else if ((ifp->flags&IFA_F_TEMPORARY) && |
| 2895 | !(ifp->flags&IFA_F_TENTATIVE)) { |
| 2896 | if (age >= ifp->prefered_lft - regen_advance) { |
| 2897 | struct inet6_ifaddr *ifpub = ifp->ifpub; |
| 2898 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) |
| 2899 | next = ifp->tstamp + ifp->prefered_lft * HZ; |
| 2900 | if (!ifp->regen_count && ifpub) { |
| 2901 | ifp->regen_count++; |
| 2902 | in6_ifa_hold(ifp); |
| 2903 | in6_ifa_hold(ifpub); |
| 2904 | spin_unlock(&ifp->lock); |
Yan Zheng | 5d5780d | 2005-11-20 13:42:20 -0800 | [diff] [blame] | 2905 | read_unlock(&addrconf_hash_lock); |
Hiroyuki YAMAMORI | 291d809 | 2005-12-23 11:24:05 -0800 | [diff] [blame] | 2906 | spin_lock(&ifpub->lock); |
| 2907 | ifpub->regen_count = 0; |
| 2908 | spin_unlock(&ifpub->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | ipv6_create_tempaddr(ifpub, ifp); |
| 2910 | in6_ifa_put(ifpub); |
| 2911 | in6_ifa_put(ifp); |
| 2912 | goto restart; |
| 2913 | } |
| 2914 | } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next)) |
| 2915 | next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ; |
| 2916 | spin_unlock(&ifp->lock); |
| 2917 | #endif |
| 2918 | } else { |
| 2919 | /* ifp->prefered_lft <= ifp->valid_lft */ |
| 2920 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) |
| 2921 | next = ifp->tstamp + ifp->prefered_lft * HZ; |
| 2922 | spin_unlock(&ifp->lock); |
| 2923 | } |
| 2924 | } |
Yan Zheng | 5d5780d | 2005-11-20 13:42:20 -0800 | [diff] [blame] | 2925 | read_unlock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | addr_chk_timer.expires = time_before(next, jiffies + HZ) ? jiffies + HZ : next; |
| 2929 | add_timer(&addr_chk_timer); |
| 2930 | spin_unlock_bh(&addrconf_verify_lock); |
| 2931 | } |
| 2932 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 2933 | static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local) |
| 2934 | { |
| 2935 | struct in6_addr *pfx = NULL; |
| 2936 | |
| 2937 | if (addr) |
| 2938 | pfx = nla_data(addr); |
| 2939 | |
| 2940 | if (local) { |
| 2941 | if (pfx && nla_memcmp(local, pfx, sizeof(*pfx))) |
| 2942 | pfx = NULL; |
| 2943 | else |
| 2944 | pfx = nla_data(local); |
| 2945 | } |
| 2946 | |
| 2947 | return pfx; |
| 2948 | } |
| 2949 | |
| 2950 | static struct nla_policy ifa_ipv6_policy[IFA_MAX+1] __read_mostly = { |
| 2951 | [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) }, |
| 2952 | [IFA_LOCAL] = { .len = sizeof(struct in6_addr) }, |
| 2953 | [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, |
| 2954 | }; |
| 2955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | static int |
| 2957 | inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 2958 | { |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 2959 | struct ifaddrmsg *ifm; |
| 2960 | struct nlattr *tb[IFA_MAX+1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | struct in6_addr *pfx; |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 2962 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 2964 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 2965 | if (err < 0) |
| 2966 | return err; |
| 2967 | |
| 2968 | ifm = nlmsg_data(nlh); |
| 2969 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | if (pfx == NULL) |
| 2971 | return -EINVAL; |
| 2972 | |
| 2973 | return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen); |
| 2974 | } |
| 2975 | |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 2976 | static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, |
| 2977 | u32 prefered_lft, u32 valid_lft) |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 2978 | { |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2979 | u32 flags = RTF_EXPIRES; |
| 2980 | |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 2981 | if (!valid_lft || (prefered_lft > valid_lft)) |
| 2982 | return -EINVAL; |
| 2983 | |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2984 | if (valid_lft == INFINITY_LIFE_TIME) { |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 2985 | ifa_flags |= IFA_F_PERMANENT; |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2986 | flags = 0; |
| 2987 | } else if (valid_lft >= 0x7FFFFFFF/HZ) |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 2988 | valid_lft = 0x7FFFFFFF/HZ; |
| 2989 | |
| 2990 | if (prefered_lft == 0) |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 2991 | ifa_flags |= IFA_F_DEPRECATED; |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 2992 | else if ((prefered_lft >= 0x7FFFFFFF/HZ) && |
| 2993 | (prefered_lft != INFINITY_LIFE_TIME)) |
| 2994 | prefered_lft = 0x7FFFFFFF/HZ; |
| 2995 | |
| 2996 | spin_lock_bh(&ifp->lock); |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 2997 | ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags; |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 2998 | ifp->tstamp = jiffies; |
| 2999 | ifp->valid_lft = valid_lft; |
| 3000 | ifp->prefered_lft = prefered_lft; |
| 3001 | |
| 3002 | spin_unlock_bh(&ifp->lock); |
| 3003 | if (!(ifp->flags&IFA_F_TENTATIVE)) |
| 3004 | ipv6_ifa_notify(0, ifp); |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3005 | |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 3006 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev, |
| 3007 | jiffies_to_clock_t(valid_lft * HZ), flags); |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3008 | addrconf_verify(0); |
| 3009 | |
| 3010 | return 0; |
| 3011 | } |
| 3012 | |
| 3013 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 3015 | { |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3016 | struct ifaddrmsg *ifm; |
| 3017 | struct nlattr *tb[IFA_MAX+1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | struct in6_addr *pfx; |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3019 | struct inet6_ifaddr *ifa; |
| 3020 | struct net_device *dev; |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3021 | u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME; |
| 3022 | u8 ifa_flags; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3023 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3025 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 3026 | if (err < 0) |
| 3027 | return err; |
| 3028 | |
| 3029 | ifm = nlmsg_data(nlh); |
| 3030 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | if (pfx == NULL) |
| 3032 | return -EINVAL; |
| 3033 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3034 | if (tb[IFA_CACHEINFO]) { |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3035 | struct ifa_cacheinfo *ci; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3036 | |
| 3037 | ci = nla_data(tb[IFA_CACHEINFO]); |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3038 | valid_lft = ci->ifa_valid; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3039 | preferred_lft = ci->ifa_prefered; |
| 3040 | } else { |
| 3041 | preferred_lft = INFINITY_LIFE_TIME; |
| 3042 | valid_lft = INFINITY_LIFE_TIME; |
Noriaki TAKAMIYA | 0778769 | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3043 | } |
| 3044 | |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3045 | dev = __dev_get_by_index(ifm->ifa_index); |
| 3046 | if (dev == NULL) |
| 3047 | return -ENODEV; |
| 3048 | |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3049 | /* We ignore other flags so far. */ |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 3050 | ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS); |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3051 | |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3052 | ifa = ipv6_get_ifaddr(pfx, dev, 1); |
| 3053 | if (ifa == NULL) { |
| 3054 | /* |
| 3055 | * It would be best to check for !NLM_F_CREATE here but |
| 3056 | * userspace alreay relies on not having to provide this. |
| 3057 | */ |
| 3058 | return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen, |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3059 | ifa_flags, preferred_lft, valid_lft); |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3060 | } |
| 3061 | |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3062 | if (nlh->nlmsg_flags & NLM_F_EXCL || |
| 3063 | !(nlh->nlmsg_flags & NLM_F_REPLACE)) |
| 3064 | err = -EEXIST; |
| 3065 | else |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3066 | err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft); |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3067 | |
| 3068 | in6_ifa_put(ifa); |
| 3069 | |
| 3070 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3073 | static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags, |
| 3074 | u8 scope, int ifindex) |
| 3075 | { |
| 3076 | struct ifaddrmsg *ifm; |
| 3077 | |
| 3078 | ifm = nlmsg_data(nlh); |
| 3079 | ifm->ifa_family = AF_INET6; |
| 3080 | ifm->ifa_prefixlen = prefixlen; |
| 3081 | ifm->ifa_flags = flags; |
| 3082 | ifm->ifa_scope = scope; |
| 3083 | ifm->ifa_index = ifindex; |
| 3084 | } |
| 3085 | |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3086 | static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp, |
| 3087 | unsigned long tstamp, u32 preferred, u32 valid) |
| 3088 | { |
| 3089 | struct ifa_cacheinfo ci; |
| 3090 | |
| 3091 | ci.cstamp = (u32)(TIME_DELTA(cstamp, INITIAL_JIFFIES) / HZ * 100 |
| 3092 | + TIME_DELTA(cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); |
| 3093 | ci.tstamp = (u32)(TIME_DELTA(tstamp, INITIAL_JIFFIES) / HZ * 100 |
| 3094 | + TIME_DELTA(tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); |
| 3095 | ci.ifa_prefered = preferred; |
| 3096 | ci.ifa_valid = valid; |
| 3097 | |
| 3098 | return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci); |
| 3099 | } |
| 3100 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3101 | static inline int rt_scope(int ifa_scope) |
| 3102 | { |
| 3103 | if (ifa_scope & IFA_HOST) |
| 3104 | return RT_SCOPE_HOST; |
| 3105 | else if (ifa_scope & IFA_LINK) |
| 3106 | return RT_SCOPE_LINK; |
| 3107 | else if (ifa_scope & IFA_SITE) |
| 3108 | return RT_SCOPE_SITE; |
| 3109 | else |
| 3110 | return RT_SCOPE_UNIVERSE; |
| 3111 | } |
| 3112 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3113 | static inline int inet6_ifaddr_msgsize(void) |
| 3114 | { |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3115 | return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) |
| 3116 | + nla_total_size(16) /* IFA_ADDRESS */ |
| 3117 | + nla_total_size(sizeof(struct ifa_cacheinfo)); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3118 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 3119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3121 | u32 pid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | struct nlmsghdr *nlh; |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3124 | u32 preferred, valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3126 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags); |
| 3127 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3128 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3129 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3130 | put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope), |
| 3131 | ifa->idev->dev->ifindex); |
| 3132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | if (!(ifa->flags&IFA_F_PERMANENT)) { |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3134 | preferred = ifa->prefered_lft; |
| 3135 | valid = ifa->valid_lft; |
| 3136 | if (preferred != INFINITY_LIFE_TIME) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | long tval = (jiffies - ifa->tstamp)/HZ; |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3138 | preferred -= tval; |
| 3139 | if (valid != INFINITY_LIFE_TIME) |
| 3140 | valid -= tval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } else { |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3143 | preferred = INFINITY_LIFE_TIME; |
| 3144 | valid = INFINITY_LIFE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3146 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3147 | if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 || |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3148 | put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) { |
| 3149 | nlmsg_cancel(skb, nlh); |
| 3150 | return -EMSGSIZE; |
| 3151 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3152 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3153 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, |
Jamal Hadi Salim | e431b8c | 2005-06-18 22:55:31 -0700 | [diff] [blame] | 3157 | u32 pid, u32 seq, int event, u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | struct nlmsghdr *nlh; |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3160 | u8 scope = RT_SCOPE_UNIVERSE; |
| 3161 | int ifindex = ifmca->idev->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3163 | if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) |
| 3164 | scope = RT_SCOPE_SITE; |
| 3165 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3166 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags); |
| 3167 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3168 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3169 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3170 | put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3171 | if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 || |
| 3172 | put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3173 | INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { |
| 3174 | nlmsg_cancel(skb, nlh); |
| 3175 | return -EMSGSIZE; |
| 3176 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3177 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3178 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3182 | u32 pid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | struct nlmsghdr *nlh; |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3185 | u8 scope = RT_SCOPE_UNIVERSE; |
| 3186 | int ifindex = ifaca->aca_idev->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3188 | if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) |
| 3189 | scope = RT_SCOPE_SITE; |
| 3190 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3191 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags); |
| 3192 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3193 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3194 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3195 | put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3196 | if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 || |
| 3197 | put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3198 | INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { |
| 3199 | nlmsg_cancel(skb, nlh); |
| 3200 | return -EMSGSIZE; |
| 3201 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3202 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3203 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | enum addr_type_t |
| 3207 | { |
| 3208 | UNICAST_ADDR, |
| 3209 | MULTICAST_ADDR, |
| 3210 | ANYCAST_ADDR, |
| 3211 | }; |
| 3212 | |
| 3213 | static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb, |
| 3214 | enum addr_type_t type) |
| 3215 | { |
| 3216 | int idx, ip_idx; |
| 3217 | int s_idx, s_ip_idx; |
| 3218 | int err = 1; |
| 3219 | struct net_device *dev; |
| 3220 | struct inet6_dev *idev = NULL; |
| 3221 | struct inet6_ifaddr *ifa; |
| 3222 | struct ifmcaddr6 *ifmca; |
| 3223 | struct ifacaddr6 *ifaca; |
| 3224 | |
| 3225 | s_idx = cb->args[0]; |
| 3226 | s_ip_idx = ip_idx = cb->args[1]; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) { |
| 3229 | if (idx < s_idx) |
| 3230 | continue; |
| 3231 | if (idx > s_idx) |
| 3232 | s_ip_idx = 0; |
| 3233 | ip_idx = 0; |
| 3234 | if ((idev = in6_dev_get(dev)) == NULL) |
| 3235 | continue; |
| 3236 | read_lock_bh(&idev->lock); |
| 3237 | switch (type) { |
| 3238 | case UNICAST_ADDR: |
YOSHIFUJI Hideaki | ae9cda5 | 2005-06-28 13:00:30 -0700 | [diff] [blame] | 3239 | /* unicast address incl. temp addr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | for (ifa = idev->addr_list; ifa; |
| 3241 | ifa = ifa->if_next, ip_idx++) { |
| 3242 | if (ip_idx < s_ip_idx) |
| 3243 | continue; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3244 | if ((err = inet6_fill_ifaddr(skb, ifa, |
| 3245 | NETLINK_CB(cb->skb).pid, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3246 | cb->nlh->nlmsg_seq, RTM_NEWADDR, |
| 3247 | NLM_F_MULTI)) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | goto done; |
| 3249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | break; |
| 3251 | case MULTICAST_ADDR: |
| 3252 | /* multicast address */ |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3253 | for (ifmca = idev->mc_list; ifmca; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | ifmca = ifmca->next, ip_idx++) { |
| 3255 | if (ip_idx < s_ip_idx) |
| 3256 | continue; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3257 | if ((err = inet6_fill_ifmcaddr(skb, ifmca, |
| 3258 | NETLINK_CB(cb->skb).pid, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3259 | cb->nlh->nlmsg_seq, RTM_GETMULTICAST, |
| 3260 | NLM_F_MULTI)) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | goto done; |
| 3262 | } |
| 3263 | break; |
| 3264 | case ANYCAST_ADDR: |
| 3265 | /* anycast address */ |
| 3266 | for (ifaca = idev->ac_list; ifaca; |
| 3267 | ifaca = ifaca->aca_next, ip_idx++) { |
| 3268 | if (ip_idx < s_ip_idx) |
| 3269 | continue; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3270 | if ((err = inet6_fill_ifacaddr(skb, ifaca, |
| 3271 | NETLINK_CB(cb->skb).pid, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3272 | cb->nlh->nlmsg_seq, RTM_GETANYCAST, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3273 | NLM_F_MULTI)) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | goto done; |
| 3275 | } |
| 3276 | break; |
| 3277 | default: |
| 3278 | break; |
| 3279 | } |
| 3280 | read_unlock_bh(&idev->lock); |
| 3281 | in6_dev_put(idev); |
| 3282 | } |
| 3283 | done: |
| 3284 | if (err <= 0) { |
| 3285 | read_unlock_bh(&idev->lock); |
| 3286 | in6_dev_put(idev); |
| 3287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | cb->args[0] = idx; |
| 3289 | cb->args[1] = ip_idx; |
| 3290 | return skb->len; |
| 3291 | } |
| 3292 | |
| 3293 | static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 3294 | { |
| 3295 | enum addr_type_t type = UNICAST_ADDR; |
| 3296 | return inet6_dump_addr(skb, cb, type); |
| 3297 | } |
| 3298 | |
| 3299 | static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 3300 | { |
| 3301 | enum addr_type_t type = MULTICAST_ADDR; |
| 3302 | return inet6_dump_addr(skb, cb, type); |
| 3303 | } |
| 3304 | |
| 3305 | |
| 3306 | static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 3307 | { |
| 3308 | enum addr_type_t type = ANYCAST_ADDR; |
| 3309 | return inet6_dump_addr(skb, cb, type); |
| 3310 | } |
| 3311 | |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3312 | static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh, |
| 3313 | void *arg) |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3314 | { |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3315 | struct ifaddrmsg *ifm; |
| 3316 | struct nlattr *tb[IFA_MAX+1]; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3317 | struct in6_addr *addr = NULL; |
| 3318 | struct net_device *dev = NULL; |
| 3319 | struct inet6_ifaddr *ifa; |
| 3320 | struct sk_buff *skb; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3321 | int err; |
| 3322 | |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3323 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 3324 | if (err < 0) |
| 3325 | goto errout; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3326 | |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3327 | addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); |
| 3328 | if (addr == NULL) { |
| 3329 | err = -EINVAL; |
| 3330 | goto errout; |
| 3331 | } |
| 3332 | |
| 3333 | ifm = nlmsg_data(nlh); |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3334 | if (ifm->ifa_index) |
| 3335 | dev = __dev_get_by_index(ifm->ifa_index); |
| 3336 | |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3337 | if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) { |
| 3338 | err = -EADDRNOTAVAIL; |
| 3339 | goto errout; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3340 | } |
| 3341 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3342 | if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) { |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3343 | err = -ENOBUFS; |
| 3344 | goto errout_ifa; |
| 3345 | } |
| 3346 | |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3347 | err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid, |
| 3348 | nlh->nlmsg_seq, RTM_NEWADDR, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3349 | if (err < 0) { |
| 3350 | /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ |
| 3351 | WARN_ON(err == -EMSGSIZE); |
| 3352 | kfree_skb(skb); |
| 3353 | goto errout_ifa; |
| 3354 | } |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 3355 | err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3356 | errout_ifa: |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3357 | in6_ifa_put(ifa); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 3358 | errout: |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3359 | return err; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 3360 | } |
| 3361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) |
| 3363 | { |
| 3364 | struct sk_buff *skb; |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 3365 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3367 | skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC); |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 3368 | if (skb == NULL) |
| 3369 | goto errout; |
| 3370 | |
| 3371 | err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3372 | if (err < 0) { |
| 3373 | /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ |
| 3374 | WARN_ON(err == -EMSGSIZE); |
| 3375 | kfree_skb(skb); |
| 3376 | goto errout; |
| 3377 | } |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 3378 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); |
| 3379 | errout: |
| 3380 | if (err < 0) |
| 3381 | rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 3384 | static inline void ipv6_store_devconf(struct ipv6_devconf *cnf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | __s32 *array, int bytes) |
| 3386 | { |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3387 | BUG_ON(bytes < (DEVCONF_MAX * 4)); |
| 3388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | memset(array, 0, bytes); |
| 3390 | array[DEVCONF_FORWARDING] = cnf->forwarding; |
| 3391 | array[DEVCONF_HOPLIMIT] = cnf->hop_limit; |
| 3392 | array[DEVCONF_MTU6] = cnf->mtu6; |
| 3393 | array[DEVCONF_ACCEPT_RA] = cnf->accept_ra; |
| 3394 | array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects; |
| 3395 | array[DEVCONF_AUTOCONF] = cnf->autoconf; |
| 3396 | array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits; |
| 3397 | array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits; |
| 3398 | array[DEVCONF_RTR_SOLICIT_INTERVAL] = cnf->rtr_solicit_interval; |
| 3399 | array[DEVCONF_RTR_SOLICIT_DELAY] = cnf->rtr_solicit_delay; |
| 3400 | array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version; |
| 3401 | #ifdef CONFIG_IPV6_PRIVACY |
| 3402 | array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr; |
| 3403 | array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft; |
| 3404 | array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft; |
| 3405 | array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry; |
| 3406 | array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; |
| 3407 | #endif |
| 3408 | array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 3409 | array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 3410 | array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 3411 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 3412 | array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref; |
YOSHIFUJI Hideaki | 52e1635 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 3413 | array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval; |
Neil Horman | fa03ef3 | 2007-01-30 14:30:10 -0800 | [diff] [blame] | 3414 | #ifdef CONFIG_IPV6_ROUTE_INFO |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 3415 | array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; |
| 3416 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 3417 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 3418 | array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp; |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 3419 | array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3420 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 3421 | array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad; |
| 3422 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3425 | static inline size_t inet6_if_nlmsg_size(void) |
| 3426 | { |
| 3427 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
| 3428 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 3429 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 3430 | + nla_total_size(4) /* IFLA_MTU */ |
| 3431 | + nla_total_size(4) /* IFLA_LINK */ |
| 3432 | + nla_total_size( /* IFLA_PROTINFO */ |
| 3433 | nla_total_size(4) /* IFLA_INET6_FLAGS */ |
| 3434 | + nla_total_size(sizeof(struct ifla_cacheinfo)) |
| 3435 | + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */ |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame^] | 3436 | + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */ |
| 3437 | + nla_total_size(ICMP6_MIB_MAX * 8) /* IFLA_INET6_ICMP6STATS */ |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3438 | ); |
| 3439 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 3440 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3441 | static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3442 | u32 pid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | { |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3444 | struct net_device *dev = idev->dev; |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame^] | 3445 | struct nlattr *nla; |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3446 | struct ifinfomsg *hdr; |
| 3447 | struct nlmsghdr *nlh; |
| 3448 | void *protoinfo; |
| 3449 | struct ifla_cacheinfo ci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3451 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags); |
| 3452 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3453 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3455 | hdr = nlmsg_data(nlh); |
| 3456 | hdr->ifi_family = AF_INET6; |
| 3457 | hdr->__ifi_pad = 0; |
| 3458 | hdr->ifi_type = dev->type; |
| 3459 | hdr->ifi_index = dev->ifindex; |
| 3460 | hdr->ifi_flags = dev_get_flags(dev); |
| 3461 | hdr->ifi_change = 0; |
| 3462 | |
| 3463 | NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | |
| 3465 | if (dev->addr_len) |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3466 | NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3468 | NLA_PUT_U32(skb, IFLA_MTU, dev->mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | if (dev->ifindex != dev->iflink) |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3470 | NLA_PUT_U32(skb, IFLA_LINK, dev->iflink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3472 | protoinfo = nla_nest_start(skb, IFLA_PROTINFO); |
| 3473 | if (protoinfo == NULL) |
| 3474 | goto nla_put_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3476 | NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | ci.max_reasm_len = IPV6_MAXPLEN; |
| 3479 | ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100 |
| 3480 | + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); |
| 3481 | ci.reachable_time = idev->nd_parms->reachable_time; |
| 3482 | ci.retrans_time = idev->nd_parms->retrans_time; |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3483 | NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci); |
| 3484 | |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame^] | 3485 | nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32)); |
| 3486 | if (nla == NULL) |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3487 | goto nla_put_failure; |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame^] | 3488 | ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame^] | 3490 | /* XXX - MC not implemented */ |
| 3491 | |
| 3492 | nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64)); |
| 3493 | if (nla == NULL) |
| 3494 | goto nla_put_failure; |
| 3495 | snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla)); |
| 3496 | |
| 3497 | nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64)); |
| 3498 | if (nla == NULL) |
| 3499 | goto nla_put_failure; |
| 3500 | snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_ICMP6STATS, nla_len(nla)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3502 | nla_nest_end(skb, protoinfo); |
| 3503 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 3505 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3506 | nlmsg_cancel(skb, nlh); |
| 3507 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) |
| 3511 | { |
| 3512 | int idx, err; |
| 3513 | int s_idx = cb->args[0]; |
| 3514 | struct net_device *dev; |
| 3515 | struct inet6_dev *idev; |
| 3516 | |
| 3517 | read_lock(&dev_base_lock); |
| 3518 | for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) { |
| 3519 | if (idx < s_idx) |
| 3520 | continue; |
| 3521 | if ((idev = in6_dev_get(dev)) == NULL) |
| 3522 | continue; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3523 | err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid, |
Jamal Hadi Salim | b6544c0 | 2005-06-18 22:54:12 -0700 | [diff] [blame] | 3524 | cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | in6_dev_put(idev); |
| 3526 | if (err <= 0) |
| 3527 | break; |
| 3528 | } |
| 3529 | read_unlock(&dev_base_lock); |
| 3530 | cb->args[0] = idx; |
| 3531 | |
| 3532 | return skb->len; |
| 3533 | } |
| 3534 | |
| 3535 | void inet6_ifinfo_notify(int event, struct inet6_dev *idev) |
| 3536 | { |
| 3537 | struct sk_buff *skb; |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 3538 | int err = -ENOBUFS; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3539 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3540 | skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC); |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 3541 | if (skb == NULL) |
| 3542 | goto errout; |
| 3543 | |
| 3544 | err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3545 | if (err < 0) { |
| 3546 | /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */ |
| 3547 | WARN_ON(err == -EMSGSIZE); |
| 3548 | kfree_skb(skb); |
| 3549 | goto errout; |
| 3550 | } |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 3551 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); |
| 3552 | errout: |
| 3553 | if (err < 0) |
| 3554 | rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3557 | static inline size_t inet6_prefix_nlmsg_size(void) |
| 3558 | { |
| 3559 | return NLMSG_ALIGN(sizeof(struct prefixmsg)) |
| 3560 | + nla_total_size(sizeof(struct in6_addr)) |
| 3561 | + nla_total_size(sizeof(struct prefix_cacheinfo)); |
| 3562 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 3563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev, |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3565 | struct prefix_info *pinfo, u32 pid, u32 seq, |
| 3566 | int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | { |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3568 | struct prefixmsg *pmsg; |
| 3569 | struct nlmsghdr *nlh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | struct prefix_cacheinfo ci; |
| 3571 | |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3572 | nlh = nlmsg_put(skb, pid, seq, event, sizeof(*pmsg), flags); |
| 3573 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3574 | return -EMSGSIZE; |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3575 | |
| 3576 | pmsg = nlmsg_data(nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | pmsg->prefix_family = AF_INET6; |
Patrick McHardy | 8a47077 | 2005-06-28 12:56:45 -0700 | [diff] [blame] | 3578 | pmsg->prefix_pad1 = 0; |
| 3579 | pmsg->prefix_pad2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | pmsg->prefix_ifindex = idev->dev->ifindex; |
| 3581 | pmsg->prefix_len = pinfo->prefix_len; |
| 3582 | pmsg->prefix_type = pinfo->type; |
Patrick McHardy | 8a47077 | 2005-06-28 12:56:45 -0700 | [diff] [blame] | 3583 | pmsg->prefix_pad3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | pmsg->prefix_flags = 0; |
| 3585 | if (pinfo->onlink) |
| 3586 | pmsg->prefix_flags |= IF_PREFIX_ONLINK; |
| 3587 | if (pinfo->autoconf) |
| 3588 | pmsg->prefix_flags |= IF_PREFIX_AUTOCONF; |
| 3589 | |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3590 | NLA_PUT(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | |
| 3592 | ci.preferred_time = ntohl(pinfo->prefered); |
| 3593 | ci.valid_time = ntohl(pinfo->valid); |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3594 | NLA_PUT(skb, PREFIX_CACHEINFO, sizeof(ci), &ci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3596 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 3598 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3599 | nlmsg_cancel(skb, nlh); |
| 3600 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3603 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | struct prefix_info *pinfo) |
| 3605 | { |
| 3606 | struct sk_buff *skb; |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 3607 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3609 | skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC); |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 3610 | if (skb == NULL) |
| 3611 | goto errout; |
| 3612 | |
| 3613 | err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3614 | if (err < 0) { |
| 3615 | /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */ |
| 3616 | WARN_ON(err == -EMSGSIZE); |
| 3617 | kfree_skb(skb); |
| 3618 | goto errout; |
| 3619 | } |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 3620 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC); |
| 3621 | errout: |
| 3622 | if (err < 0) |
| 3623 | rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| 3627 | { |
| 3628 | inet6_ifa_notify(event ? : RTM_NEWADDR, ifp); |
| 3629 | |
| 3630 | switch (event) { |
| 3631 | case RTM_NEWADDR: |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3632 | /* |
| 3633 | * If the address was optimistic |
| 3634 | * we inserted the route at the start of |
| 3635 | * our DAD process, so we don't need |
| 3636 | * to do it again |
| 3637 | */ |
| 3638 | if (!(ifp->rt->rt6i_node)) |
| 3639 | ip6_ins_rt(ifp->rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | if (ifp->idev->cnf.forwarding) |
| 3641 | addrconf_join_anycast(ifp); |
| 3642 | break; |
| 3643 | case RTM_DELADDR: |
| 3644 | if (ifp->idev->cnf.forwarding) |
| 3645 | addrconf_leave_anycast(ifp); |
| 3646 | addrconf_leave_solict(ifp->idev, &ifp->addr); |
| 3647 | dst_hold(&ifp->rt->u.dst); |
Thomas Graf | e0a1ad73 | 2006-08-22 00:00:21 -0700 | [diff] [blame] | 3648 | if (ip6_del_rt(ifp->rt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | dst_free(&ifp->rt->u.dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | break; |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| 3655 | { |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 3656 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | if (likely(ifp->idev->dead == 0)) |
| 3658 | __ipv6_ifa_notify(event, ifp); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 3659 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | #ifdef CONFIG_SYSCTL |
| 3663 | |
| 3664 | static |
| 3665 | int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp, |
| 3666 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 3667 | { |
| 3668 | int *valp = ctl->data; |
| 3669 | int val = *valp; |
| 3670 | int ret; |
| 3671 | |
| 3672 | ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos); |
| 3673 | |
| 3674 | if (write && valp != &ipv6_devconf_dflt.forwarding) { |
| 3675 | if (valp != &ipv6_devconf.forwarding) { |
| 3676 | if ((!*valp) ^ (!val)) { |
| 3677 | struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1; |
| 3678 | if (idev == NULL) |
| 3679 | return ret; |
| 3680 | dev_forward_change(idev); |
| 3681 | } |
| 3682 | } else { |
| 3683 | ipv6_devconf_dflt.forwarding = ipv6_devconf.forwarding; |
| 3684 | addrconf_forward_change(); |
| 3685 | } |
| 3686 | if (*valp) |
| 3687 | rt6_purge_dflt_routers(); |
| 3688 | } |
| 3689 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3690 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3693 | static int addrconf_sysctl_forward_strategy(ctl_table *table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | int __user *name, int nlen, |
| 3695 | void __user *oldval, |
| 3696 | size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 3697 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | { |
| 3699 | int *valp = table->data; |
| 3700 | int new; |
| 3701 | |
| 3702 | if (!newval || !newlen) |
| 3703 | return 0; |
| 3704 | if (newlen != sizeof(int)) |
| 3705 | return -EINVAL; |
| 3706 | if (get_user(new, (int __user *)newval)) |
| 3707 | return -EFAULT; |
| 3708 | if (new == *valp) |
| 3709 | return 0; |
| 3710 | if (oldval && oldlenp) { |
| 3711 | size_t len; |
| 3712 | if (get_user(len, oldlenp)) |
| 3713 | return -EFAULT; |
| 3714 | if (len) { |
| 3715 | if (len > table->maxlen) |
| 3716 | len = table->maxlen; |
| 3717 | if (copy_to_user(oldval, valp, len)) |
| 3718 | return -EFAULT; |
| 3719 | if (put_user(len, oldlenp)) |
| 3720 | return -EFAULT; |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | if (valp != &ipv6_devconf_dflt.forwarding) { |
| 3725 | if (valp != &ipv6_devconf.forwarding) { |
| 3726 | struct inet6_dev *idev = (struct inet6_dev *)table->extra1; |
| 3727 | int changed; |
| 3728 | if (unlikely(idev == NULL)) |
| 3729 | return -ENODEV; |
| 3730 | changed = (!*valp) ^ (!new); |
| 3731 | *valp = new; |
| 3732 | if (changed) |
| 3733 | dev_forward_change(idev); |
| 3734 | } else { |
| 3735 | *valp = new; |
| 3736 | addrconf_forward_change(); |
| 3737 | } |
| 3738 | |
| 3739 | if (*valp) |
| 3740 | rt6_purge_dflt_routers(); |
| 3741 | } else |
| 3742 | *valp = new; |
| 3743 | |
| 3744 | return 1; |
| 3745 | } |
| 3746 | |
| 3747 | static struct addrconf_sysctl_table |
| 3748 | { |
| 3749 | struct ctl_table_header *sysctl_header; |
| 3750 | ctl_table addrconf_vars[__NET_IPV6_MAX]; |
| 3751 | ctl_table addrconf_dev[2]; |
| 3752 | ctl_table addrconf_conf_dir[2]; |
| 3753 | ctl_table addrconf_proto_dir[2]; |
| 3754 | ctl_table addrconf_root_dir[2]; |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 3755 | } addrconf_sysctl __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | .sysctl_header = NULL, |
| 3757 | .addrconf_vars = { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3758 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | .ctl_name = NET_IPV6_FORWARDING, |
| 3760 | .procname = "forwarding", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3761 | .data = &ipv6_devconf.forwarding, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | .maxlen = sizeof(int), |
| 3763 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3764 | .proc_handler = &addrconf_sysctl_forward, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | .strategy = &addrconf_sysctl_forward_strategy, |
| 3766 | }, |
| 3767 | { |
| 3768 | .ctl_name = NET_IPV6_HOP_LIMIT, |
| 3769 | .procname = "hop_limit", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3770 | .data = &ipv6_devconf.hop_limit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | .maxlen = sizeof(int), |
| 3772 | .mode = 0644, |
| 3773 | .proc_handler = proc_dointvec, |
| 3774 | }, |
| 3775 | { |
| 3776 | .ctl_name = NET_IPV6_MTU, |
| 3777 | .procname = "mtu", |
| 3778 | .data = &ipv6_devconf.mtu6, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3779 | .maxlen = sizeof(int), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3781 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | }, |
| 3783 | { |
| 3784 | .ctl_name = NET_IPV6_ACCEPT_RA, |
| 3785 | .procname = "accept_ra", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3786 | .data = &ipv6_devconf.accept_ra, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | .maxlen = sizeof(int), |
| 3788 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3789 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | }, |
| 3791 | { |
| 3792 | .ctl_name = NET_IPV6_ACCEPT_REDIRECTS, |
| 3793 | .procname = "accept_redirects", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3794 | .data = &ipv6_devconf.accept_redirects, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | .maxlen = sizeof(int), |
| 3796 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3797 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | }, |
| 3799 | { |
| 3800 | .ctl_name = NET_IPV6_AUTOCONF, |
| 3801 | .procname = "autoconf", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3802 | .data = &ipv6_devconf.autoconf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | .maxlen = sizeof(int), |
| 3804 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3805 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | }, |
| 3807 | { |
| 3808 | .ctl_name = NET_IPV6_DAD_TRANSMITS, |
| 3809 | .procname = "dad_transmits", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3810 | .data = &ipv6_devconf.dad_transmits, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | .maxlen = sizeof(int), |
| 3812 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3813 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | }, |
| 3815 | { |
| 3816 | .ctl_name = NET_IPV6_RTR_SOLICITS, |
| 3817 | .procname = "router_solicitations", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3818 | .data = &ipv6_devconf.rtr_solicits, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | .maxlen = sizeof(int), |
| 3820 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3821 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | }, |
| 3823 | { |
| 3824 | .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL, |
| 3825 | .procname = "router_solicitation_interval", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3826 | .data = &ipv6_devconf.rtr_solicit_interval, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | .maxlen = sizeof(int), |
| 3828 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3829 | .proc_handler = &proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | .strategy = &sysctl_jiffies, |
| 3831 | }, |
| 3832 | { |
| 3833 | .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY, |
| 3834 | .procname = "router_solicitation_delay", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3835 | .data = &ipv6_devconf.rtr_solicit_delay, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | .maxlen = sizeof(int), |
| 3837 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3838 | .proc_handler = &proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | .strategy = &sysctl_jiffies, |
| 3840 | }, |
| 3841 | { |
| 3842 | .ctl_name = NET_IPV6_FORCE_MLD_VERSION, |
| 3843 | .procname = "force_mld_version", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3844 | .data = &ipv6_devconf.force_mld_version, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | .maxlen = sizeof(int), |
| 3846 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3847 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | }, |
| 3849 | #ifdef CONFIG_IPV6_PRIVACY |
| 3850 | { |
| 3851 | .ctl_name = NET_IPV6_USE_TEMPADDR, |
| 3852 | .procname = "use_tempaddr", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3853 | .data = &ipv6_devconf.use_tempaddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 | .maxlen = sizeof(int), |
| 3855 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3856 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | }, |
| 3858 | { |
| 3859 | .ctl_name = NET_IPV6_TEMP_VALID_LFT, |
| 3860 | .procname = "temp_valid_lft", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3861 | .data = &ipv6_devconf.temp_valid_lft, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | .maxlen = sizeof(int), |
| 3863 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3864 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | }, |
| 3866 | { |
| 3867 | .ctl_name = NET_IPV6_TEMP_PREFERED_LFT, |
| 3868 | .procname = "temp_prefered_lft", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3869 | .data = &ipv6_devconf.temp_prefered_lft, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | .maxlen = sizeof(int), |
| 3871 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3872 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | }, |
| 3874 | { |
| 3875 | .ctl_name = NET_IPV6_REGEN_MAX_RETRY, |
| 3876 | .procname = "regen_max_retry", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3877 | .data = &ipv6_devconf.regen_max_retry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | .maxlen = sizeof(int), |
| 3879 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3880 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | }, |
| 3882 | { |
| 3883 | .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR, |
| 3884 | .procname = "max_desync_factor", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3885 | .data = &ipv6_devconf.max_desync_factor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | .maxlen = sizeof(int), |
| 3887 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3888 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | }, |
| 3890 | #endif |
| 3891 | { |
| 3892 | .ctl_name = NET_IPV6_MAX_ADDRESSES, |
| 3893 | .procname = "max_addresses", |
| 3894 | .data = &ipv6_devconf.max_addresses, |
| 3895 | .maxlen = sizeof(int), |
| 3896 | .mode = 0644, |
| 3897 | .proc_handler = &proc_dointvec, |
| 3898 | }, |
| 3899 | { |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 3900 | .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR, |
| 3901 | .procname = "accept_ra_defrtr", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3902 | .data = &ipv6_devconf.accept_ra_defrtr, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 3903 | .maxlen = sizeof(int), |
| 3904 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3905 | .proc_handler = &proc_dointvec, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 3906 | }, |
| 3907 | { |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 3908 | .ctl_name = NET_IPV6_ACCEPT_RA_PINFO, |
| 3909 | .procname = "accept_ra_pinfo", |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3910 | .data = &ipv6_devconf.accept_ra_pinfo, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 3911 | .maxlen = sizeof(int), |
| 3912 | .mode = 0644, |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3913 | .proc_handler = &proc_dointvec, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 3914 | }, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 3915 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 3916 | { |
| 3917 | .ctl_name = NET_IPV6_ACCEPT_RA_RTR_PREF, |
| 3918 | .procname = "accept_ra_rtr_pref", |
| 3919 | .data = &ipv6_devconf.accept_ra_rtr_pref, |
| 3920 | .maxlen = sizeof(int), |
| 3921 | .mode = 0644, |
| 3922 | .proc_handler = &proc_dointvec, |
| 3923 | }, |
YOSHIFUJI Hideaki | 52e1635 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 3924 | { |
| 3925 | .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL, |
| 3926 | .procname = "router_probe_interval", |
| 3927 | .data = &ipv6_devconf.rtr_probe_interval, |
| 3928 | .maxlen = sizeof(int), |
| 3929 | .mode = 0644, |
| 3930 | .proc_handler = &proc_dointvec_jiffies, |
| 3931 | .strategy = &sysctl_jiffies, |
| 3932 | }, |
Neil Horman | fa03ef3 | 2007-01-30 14:30:10 -0800 | [diff] [blame] | 3933 | #ifdef CONFIG_IPV6_ROUTE_INFO |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 3934 | { |
| 3935 | .ctl_name = NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN, |
| 3936 | .procname = "accept_ra_rt_info_max_plen", |
| 3937 | .data = &ipv6_devconf.accept_ra_rt_info_max_plen, |
| 3938 | .maxlen = sizeof(int), |
| 3939 | .mode = 0644, |
| 3940 | .proc_handler = &proc_dointvec, |
| 3941 | }, |
| 3942 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 3943 | #endif |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 3944 | { |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 3945 | .ctl_name = NET_IPV6_PROXY_NDP, |
| 3946 | .procname = "proxy_ndp", |
| 3947 | .data = &ipv6_devconf.proxy_ndp, |
| 3948 | .maxlen = sizeof(int), |
| 3949 | .mode = 0644, |
| 3950 | .proc_handler = &proc_dointvec, |
| 3951 | }, |
| 3952 | { |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 3953 | .ctl_name = NET_IPV6_ACCEPT_SOURCE_ROUTE, |
| 3954 | .procname = "accept_source_route", |
| 3955 | .data = &ipv6_devconf.accept_source_route, |
| 3956 | .maxlen = sizeof(int), |
| 3957 | .mode = 0644, |
| 3958 | .proc_handler = &proc_dointvec, |
| 3959 | }, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3960 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 3961 | { |
| 3962 | .ctl_name = CTL_UNNUMBERED, |
| 3963 | .procname = "optimistic_dad", |
| 3964 | .data = &ipv6_devconf.optimistic_dad, |
| 3965 | .maxlen = sizeof(int), |
| 3966 | .mode = 0644, |
| 3967 | .proc_handler = &proc_dointvec, |
| 3968 | |
| 3969 | }, |
| 3970 | #endif |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 3971 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | .ctl_name = 0, /* sentinel */ |
| 3973 | } |
| 3974 | }, |
| 3975 | .addrconf_dev = { |
| 3976 | { |
| 3977 | .ctl_name = NET_PROTO_CONF_ALL, |
| 3978 | .procname = "all", |
| 3979 | .mode = 0555, |
| 3980 | .child = addrconf_sysctl.addrconf_vars, |
| 3981 | }, |
| 3982 | { |
| 3983 | .ctl_name = 0, /* sentinel */ |
| 3984 | } |
| 3985 | }, |
| 3986 | .addrconf_conf_dir = { |
| 3987 | { |
| 3988 | .ctl_name = NET_IPV6_CONF, |
| 3989 | .procname = "conf", |
| 3990 | .mode = 0555, |
| 3991 | .child = addrconf_sysctl.addrconf_dev, |
| 3992 | }, |
| 3993 | { |
| 3994 | .ctl_name = 0, /* sentinel */ |
| 3995 | } |
| 3996 | }, |
| 3997 | .addrconf_proto_dir = { |
| 3998 | { |
| 3999 | .ctl_name = NET_IPV6, |
| 4000 | .procname = "ipv6", |
| 4001 | .mode = 0555, |
| 4002 | .child = addrconf_sysctl.addrconf_conf_dir, |
| 4003 | }, |
| 4004 | { |
| 4005 | .ctl_name = 0, /* sentinel */ |
| 4006 | } |
| 4007 | }, |
| 4008 | .addrconf_root_dir = { |
| 4009 | { |
| 4010 | .ctl_name = CTL_NET, |
| 4011 | .procname = "net", |
| 4012 | .mode = 0555, |
| 4013 | .child = addrconf_sysctl.addrconf_proto_dir, |
| 4014 | }, |
| 4015 | { |
| 4016 | .ctl_name = 0, /* sentinel */ |
| 4017 | } |
| 4018 | }, |
| 4019 | }; |
| 4020 | |
| 4021 | static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p) |
| 4022 | { |
| 4023 | int i; |
| 4024 | struct net_device *dev = idev ? idev->dev : NULL; |
| 4025 | struct addrconf_sysctl_table *t; |
| 4026 | char *dev_name = NULL; |
| 4027 | |
Arnaldo Carvalho de Melo | af879cc | 2006-11-17 12:14:37 -0200 | [diff] [blame] | 4028 | t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | if (t == NULL) |
| 4030 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | for (i=0; t->addrconf_vars[i].data; i++) { |
| 4032 | t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */ |
| 4034 | } |
| 4035 | if (dev) { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4036 | dev_name = dev->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | t->addrconf_dev[0].ctl_name = dev->ifindex; |
| 4038 | } else { |
| 4039 | dev_name = "default"; |
| 4040 | t->addrconf_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT; |
| 4041 | } |
| 4042 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4043 | /* |
| 4044 | * Make a copy of dev_name, because '.procname' is regarded as const |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | * by sysctl and we wouldn't want anyone to change it under our feet |
| 4046 | * (see SIOCSIFNAME). |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4047 | */ |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 4048 | dev_name = kstrdup(dev_name, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | if (!dev_name) |
| 4050 | goto free; |
| 4051 | |
| 4052 | t->addrconf_dev[0].procname = dev_name; |
| 4053 | |
| 4054 | t->addrconf_dev[0].child = t->addrconf_vars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | t->addrconf_conf_dir[0].child = t->addrconf_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | t->addrconf_proto_dir[0].child = t->addrconf_conf_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | t->addrconf_root_dir[0].child = t->addrconf_proto_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 4059 | t->sysctl_header = register_sysctl_table(t->addrconf_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | if (t->sysctl_header == NULL) |
| 4061 | goto free_procname; |
| 4062 | else |
| 4063 | p->sysctl = t; |
| 4064 | return; |
| 4065 | |
| 4066 | /* error path */ |
| 4067 | free_procname: |
| 4068 | kfree(dev_name); |
| 4069 | free: |
| 4070 | kfree(t); |
| 4071 | |
| 4072 | return; |
| 4073 | } |
| 4074 | |
| 4075 | static void addrconf_sysctl_unregister(struct ipv6_devconf *p) |
| 4076 | { |
| 4077 | if (p->sysctl) { |
| 4078 | struct addrconf_sysctl_table *t = p->sysctl; |
| 4079 | p->sysctl = NULL; |
| 4080 | unregister_sysctl_table(t->sysctl_header); |
| 4081 | kfree(t->addrconf_dev[0].procname); |
| 4082 | kfree(t); |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | |
| 4087 | #endif |
| 4088 | |
| 4089 | /* |
| 4090 | * Device notifier |
| 4091 | */ |
| 4092 | |
| 4093 | int register_inet6addr_notifier(struct notifier_block *nb) |
| 4094 | { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4095 | return atomic_notifier_chain_register(&inet6addr_chain, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 4098 | EXPORT_SYMBOL(register_inet6addr_notifier); |
| 4099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | int unregister_inet6addr_notifier(struct notifier_block *nb) |
| 4101 | { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4102 | return atomic_notifier_chain_unregister(&inet6addr_chain,nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 4105 | EXPORT_SYMBOL(unregister_inet6addr_notifier); |
| 4106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | /* |
| 4108 | * Init / cleanup code |
| 4109 | */ |
| 4110 | |
| 4111 | int __init addrconf_init(void) |
| 4112 | { |
| 4113 | int err = 0; |
| 4114 | |
| 4115 | /* The addrconf netdev notifier requires that loopback_dev |
| 4116 | * has it's ipv6 private information allocated and setup |
| 4117 | * before it can bring up and give link-local addresses |
| 4118 | * to other devices which are up. |
| 4119 | * |
| 4120 | * Unfortunately, loopback_dev is not necessarily the first |
| 4121 | * entry in the global dev_base list of net devices. In fact, |
| 4122 | * it is likely to be the very last entry on that list. |
| 4123 | * So this causes the notifier registry below to try and |
| 4124 | * give link-local addresses to all devices besides loopback_dev |
| 4125 | * first, then loopback_dev, which cases all the non-loopback_dev |
| 4126 | * devices to fail to get a link-local address. |
| 4127 | * |
| 4128 | * So, as a temporary fix, allocate the ipv6 structure for |
| 4129 | * loopback_dev first by hand. |
| 4130 | * Longer term, all of the dependencies ipv6 has upon the loopback |
| 4131 | * device and it being up should be removed. |
| 4132 | */ |
| 4133 | rtnl_lock(); |
| 4134 | if (!ipv6_add_dev(&loopback_dev)) |
| 4135 | err = -ENOMEM; |
| 4136 | rtnl_unlock(); |
| 4137 | if (err) |
| 4138 | return err; |
| 4139 | |
Herbert Xu | c62dba9 | 2005-09-26 15:10:16 -0700 | [diff] [blame] | 4140 | ip6_null_entry.rt6i_idev = in6_dev_get(&loopback_dev); |
| 4141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | register_netdevice_notifier(&ipv6_dev_notf); |
| 4143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | addrconf_verify(0); |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 4145 | |
| 4146 | err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo); |
| 4147 | if (err < 0) |
| 4148 | goto errout; |
| 4149 | |
| 4150 | /* Only the first call to __rtnl_register can fail */ |
| 4151 | __rtnl_register(PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL); |
| 4152 | __rtnl_register(PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL); |
| 4153 | __rtnl_register(PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, inet6_dump_ifaddr); |
| 4154 | __rtnl_register(PF_INET6, RTM_GETMULTICAST, NULL, inet6_dump_ifmcaddr); |
| 4155 | __rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, inet6_dump_ifacaddr); |
| 4156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | #ifdef CONFIG_SYSCTL |
| 4158 | addrconf_sysctl.sysctl_header = |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 4159 | register_sysctl_table(addrconf_sysctl.addrconf_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | addrconf_sysctl_register(NULL, &ipv6_devconf_dflt); |
| 4161 | #endif |
| 4162 | |
| 4163 | return 0; |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 4164 | errout: |
| 4165 | unregister_netdevice_notifier(&ipv6_dev_notf); |
| 4166 | |
| 4167 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | void __exit addrconf_cleanup(void) |
| 4171 | { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4172 | struct net_device *dev; |
| 4173 | struct inet6_dev *idev; |
| 4174 | struct inet6_ifaddr *ifa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | int i; |
| 4176 | |
| 4177 | unregister_netdevice_notifier(&ipv6_dev_notf); |
| 4178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | #ifdef CONFIG_SYSCTL |
| 4180 | addrconf_sysctl_unregister(&ipv6_devconf_dflt); |
| 4181 | addrconf_sysctl_unregister(&ipv6_devconf); |
| 4182 | #endif |
| 4183 | |
| 4184 | rtnl_lock(); |
| 4185 | |
| 4186 | /* |
| 4187 | * clean dev list. |
| 4188 | */ |
| 4189 | |
| 4190 | for (dev=dev_base; dev; dev=dev->next) { |
| 4191 | if ((idev = __in6_dev_get(dev)) == NULL) |
| 4192 | continue; |
| 4193 | addrconf_ifdown(dev, 1); |
| 4194 | } |
| 4195 | addrconf_ifdown(&loopback_dev, 2); |
| 4196 | |
| 4197 | /* |
| 4198 | * Check hash table. |
| 4199 | */ |
| 4200 | |
| 4201 | write_lock_bh(&addrconf_hash_lock); |
| 4202 | for (i=0; i < IN6_ADDR_HSIZE; i++) { |
| 4203 | for (ifa=inet6_addr_lst[i]; ifa; ) { |
| 4204 | struct inet6_ifaddr *bifa; |
| 4205 | |
| 4206 | bifa = ifa; |
| 4207 | ifa = ifa->lst_next; |
| 4208 | printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa); |
| 4209 | /* Do not free it; something is wrong. |
| 4210 | Now we can investigate it with debugger. |
| 4211 | */ |
| 4212 | } |
| 4213 | } |
| 4214 | write_unlock_bh(&addrconf_hash_lock); |
| 4215 | |
| 4216 | del_timer(&addr_chk_timer); |
| 4217 | |
| 4218 | rtnl_unlock(); |
| 4219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | #ifdef CONFIG_PROC_FS |
| 4221 | proc_net_remove("if_inet6"); |
| 4222 | #endif |
| 4223 | } |