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