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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * Changes: |
| 17 | * |
| 18 | * Janos Farkas : delete timer on ifdown |
| 19 | * <chexum@bankinf.banki.hu> |
| 20 | * Andi Kleen : kill double kfree on module |
| 21 | * unload. |
| 22 | * Maciej W. Rozycki : FDDI support |
| 23 | * sekiya@USAGI : Don't send too many RS |
| 24 | * packets. |
| 25 | * yoshfuji@USAGI : Fixed interval between DAD |
| 26 | * packets. |
| 27 | * YOSHIFUJI Hideaki @USAGI : improved accuracy of |
| 28 | * address validation timer. |
| 29 | * YOSHIFUJI Hideaki @USAGI : Privacy Extensions (RFC3041) |
| 30 | * support. |
| 31 | * Yuji SEKIYA @USAGI : Don't assign a same IPv6 |
| 32 | * address on a same interface. |
| 33 | * YOSHIFUJI Hideaki @USAGI : ARCnet support |
| 34 | * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to |
| 35 | * seq_file. |
YOSHIFUJI Hideaki | b1cacb6 | 2005-11-08 09:38:12 -0800 | [diff] [blame] | 36 | * YOSHIFUJI Hideaki @USAGI : improved source address |
| 37 | * selection; consider scope, |
| 38 | * status etc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 41 | #define pr_fmt(fmt) "IPv6: " fmt |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/errno.h> |
| 44 | #include <linux/types.h> |
Ilpo Järvinen | a0bffff | 2009-03-21 13:36:17 -0700 | [diff] [blame] | 45 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/socket.h> |
| 47 | #include <linux/sockios.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/net.h> |
| 49 | #include <linux/in6.h> |
| 50 | #include <linux/netdevice.h> |
Thomas Graf | 1823730 | 2006-08-04 23:04:54 -0700 | [diff] [blame] | 51 | #include <linux/if_addr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/if_arp.h> |
| 53 | #include <linux/if_arcnet.h> |
| 54 | #include <linux/if_infiniband.h> |
| 55 | #include <linux/route.h> |
| 56 | #include <linux/inetdevice.h> |
| 57 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 58 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #ifdef CONFIG_SYSCTL |
| 60 | #include <linux/sysctl.h> |
| 61 | #endif |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 62 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include <linux/delay.h> |
| 64 | #include <linux/notifier.h> |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 65 | #include <linux/string.h> |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 66 | #include <linux/hash.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 68 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include <net/sock.h> |
| 70 | #include <net/snmp.h> |
| 71 | |
alex.bluesman.smirnov@gmail.com | 06a4c1c | 2012-05-10 03:25:52 +0000 | [diff] [blame] | 72 | #include <net/af_ieee802154.h> |
YOSHIFUJI Hideaki / 吉藤英明 | cb6bf35 | 2013-03-25 08:26:24 +0000 | [diff] [blame] | 73 | #include <net/firewire.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #include <net/ipv6.h> |
| 75 | #include <net/protocol.h> |
| 76 | #include <net/ndisc.h> |
| 77 | #include <net/ip6_route.h> |
| 78 | #include <net/addrconf.h> |
| 79 | #include <net/tcp.h> |
| 80 | #include <net/ip.h> |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 81 | #include <net/netlink.h> |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 82 | #include <net/pkt_sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #include <linux/if_tunnel.h> |
| 84 | #include <linux/rtnetlink.h> |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 85 | #include <linux/netconf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #include <linux/random.h> |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 87 | #include <linux/uaccess.h> |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 88 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | #include <linux/proc_fs.h> |
| 91 | #include <linux/seq_file.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 92 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* Set to 3 to get tracing... */ |
| 95 | #define ACONF_DEBUG 2 |
| 96 | |
| 97 | #if ACONF_DEBUG >= 3 |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 98 | #define ADBG(fmt, ...) printk(fmt, ##__VA_ARGS__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #else |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 100 | #define ADBG(fmt, ...) do { if (0) printk(fmt, ##__VA_ARGS__); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #endif |
| 102 | |
| 103 | #define INFINITY_LIFE_TIME 0xFFFFFFFF |
Thomas Graf | 18a31e1 | 2010-11-17 04:12:02 +0000 | [diff] [blame] | 104 | |
| 105 | static inline u32 cstamp_delta(unsigned long cstamp) |
| 106 | { |
| 107 | return (cstamp - INITIAL_JIFFIES) * 100UL / HZ; |
| 108 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | f52295a | 2007-12-02 00:58:37 +1100 | [diff] [blame] | 111 | static void addrconf_sysctl_register(struct inet6_dev *idev); |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 112 | static void addrconf_sysctl_unregister(struct inet6_dev *idev); |
| 113 | #else |
| 114 | static inline void addrconf_sysctl_register(struct inet6_dev *idev) |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | static inline void addrconf_sysctl_unregister(struct inet6_dev *idev) |
| 119 | { |
| 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #endif |
| 122 | |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 123 | static void __ipv6_regen_rndid(struct inet6_dev *idev); |
| 124 | static void __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | static void ipv6_regen_rndid(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 127 | static int ipv6_generate_eui64(u8 *eui, struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int ipv6_count_addresses(struct inet6_dev *idev); |
| 129 | |
| 130 | /* |
| 131 | * Configured unicast address hash table |
| 132 | */ |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 133 | static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE]; |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 134 | static DEFINE_SPINLOCK(addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static void addrconf_verify(unsigned long); |
| 137 | |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 138 | static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | static DEFINE_SPINLOCK(addrconf_verify_lock); |
| 140 | |
| 141 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp); |
| 142 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); |
| 143 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 144 | static void addrconf_type_change(struct net_device *dev, |
| 145 | unsigned long event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static int addrconf_ifdown(struct net_device *dev, int how); |
| 147 | |
Romain Kuntz | 21caa66 | 2013-01-09 21:06:03 +0000 | [diff] [blame] | 148 | static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, |
| 149 | int plen, |
| 150 | const struct net_device *dev, |
| 151 | u32 flags, u32 noflags); |
| 152 | |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 153 | static void addrconf_dad_start(struct inet6_ifaddr *ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static void addrconf_dad_timer(unsigned long data); |
| 155 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp); |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 156 | static void addrconf_dad_run(struct inet6_dev *idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | static void addrconf_rs_timer(unsigned long data); |
| 158 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa); |
| 159 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa); |
| 160 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 161 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | struct prefix_info *pinfo); |
David S. Miller | 3e81c6d | 2010-03-20 16:18:00 -0700 | [diff] [blame] | 163 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
| 164 | struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Adrian Bunk | 888c848 | 2008-07-22 14:21:58 -0700 | [diff] [blame] | 166 | static struct ipv6_devconf ipv6_devconf __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | .forwarding = 0, |
| 168 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 169 | .mtu6 = IPV6_MIN_MTU, |
| 170 | .accept_ra = 1, |
| 171 | .accept_redirects = 1, |
| 172 | .autoconf = 1, |
| 173 | .force_mld_version = 0, |
Hannes Frederic Sowa | fc4eba5 | 2013-08-14 01:03:46 +0200 | [diff] [blame] | 174 | .mldv1_unsolicited_report_interval = 10 * HZ, |
| 175 | .mldv2_unsolicited_report_interval = HZ, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | .dad_transmits = 1, |
| 177 | .rtr_solicits = MAX_RTR_SOLICITATIONS, |
| 178 | .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL, |
| 179 | .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | .use_tempaddr = 0, |
| 181 | .temp_valid_lft = TEMP_VALID_LIFETIME, |
| 182 | .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, |
| 183 | .regen_max_retry = REGEN_MAX_RETRY, |
| 184 | .max_desync_factor = MAX_DESYNC_FACTOR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | .max_addresses = IPV6_MAX_ADDRESSES, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 186 | .accept_ra_defrtr = 1, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 187 | .accept_ra_pinfo = 1, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 188 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 189 | .accept_ra_rtr_pref = 1, |
YOSHIFUJI Hideaki | 52e16356 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 190 | .rtr_probe_interval = 60 * HZ, |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 191 | #ifdef CONFIG_IPV6_ROUTE_INFO |
| 192 | .accept_ra_rt_info_max_plen = 0, |
| 193 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 194 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 195 | .proxy_ndp = 0, |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 196 | .accept_source_route = 0, /* we do not accept RH0 by default. */ |
YOSHIFUJI Hideaki | 778d80b | 2008-06-28 14:17:11 +0900 | [diff] [blame] | 197 | .disable_ipv6 = 0, |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 198 | .accept_dad = 1, |
Hannes Frederic Sowa | b800c3b | 2013-08-27 01:36:51 +0200 | [diff] [blame] | 199 | .suppress_frag_ndisc = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 202 | static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | .forwarding = 0, |
| 204 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 205 | .mtu6 = IPV6_MIN_MTU, |
| 206 | .accept_ra = 1, |
| 207 | .accept_redirects = 1, |
| 208 | .autoconf = 1, |
Hannes Frederic Sowa | fc4eba5 | 2013-08-14 01:03:46 +0200 | [diff] [blame] | 209 | .force_mld_version = 0, |
| 210 | .mldv1_unsolicited_report_interval = 10 * HZ, |
| 211 | .mldv2_unsolicited_report_interval = HZ, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | .dad_transmits = 1, |
| 213 | .rtr_solicits = MAX_RTR_SOLICITATIONS, |
| 214 | .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL, |
| 215 | .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | .use_tempaddr = 0, |
| 217 | .temp_valid_lft = TEMP_VALID_LIFETIME, |
| 218 | .temp_prefered_lft = TEMP_PREFERRED_LIFETIME, |
| 219 | .regen_max_retry = REGEN_MAX_RETRY, |
| 220 | .max_desync_factor = MAX_DESYNC_FACTOR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | .max_addresses = IPV6_MAX_ADDRESSES, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 222 | .accept_ra_defrtr = 1, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 223 | .accept_ra_pinfo = 1, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 224 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 225 | .accept_ra_rtr_pref = 1, |
YOSHIFUJI Hideaki | 52e16356 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 226 | .rtr_probe_interval = 60 * HZ, |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 227 | #ifdef CONFIG_IPV6_ROUTE_INFO |
| 228 | .accept_ra_rt_info_max_plen = 0, |
| 229 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 230 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 231 | .proxy_ndp = 0, |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 232 | .accept_source_route = 0, /* we do not accept RH0 by default. */ |
YOSHIFUJI Hideaki | 778d80b | 2008-06-28 14:17:11 +0900 | [diff] [blame] | 233 | .disable_ipv6 = 0, |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 234 | .accept_dad = 1, |
Hannes Frederic Sowa | b800c3b | 2013-08-27 01:36:51 +0200 | [diff] [blame] | 235 | .suppress_frag_ndisc = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 238 | /* Check if a valid qdisc is available */ |
David S. Miller | 0529794 | 2008-07-08 23:01:27 -0700 | [diff] [blame] | 239 | static inline bool addrconf_qdisc_ok(const struct net_device *dev) |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 240 | { |
David S. Miller | 0529794 | 2008-07-08 23:01:27 -0700 | [diff] [blame] | 241 | return !qdisc_tx_is_noop(dev); |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 244 | static void addrconf_del_rs_timer(struct inet6_dev *idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 246 | if (del_timer(&idev->rs_timer)) |
| 247 | __in6_dev_put(idev); |
| 248 | } |
| 249 | |
| 250 | static void addrconf_del_dad_timer(struct inet6_ifaddr *ifp) |
| 251 | { |
| 252 | if (del_timer(&ifp->dad_timer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | __in6_ifa_put(ifp); |
| 254 | } |
| 255 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 256 | static void addrconf_mod_rs_timer(struct inet6_dev *idev, |
| 257 | unsigned long when) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 259 | if (!timer_pending(&idev->rs_timer)) |
| 260 | in6_dev_hold(idev); |
| 261 | mod_timer(&idev->rs_timer, jiffies + when); |
| 262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 264 | static void addrconf_mod_dad_timer(struct inet6_ifaddr *ifp, |
| 265 | unsigned long when) |
| 266 | { |
| 267 | if (!timer_pending(&ifp->dad_timer)) |
| 268 | in6_ifa_hold(ifp); |
| 269 | mod_timer(&ifp->dad_timer, jiffies + when); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 272 | static int snmp6_alloc_dev(struct inet6_dev *idev) |
| 273 | { |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 274 | int i; |
| 275 | |
Tejun Heo | 7d720c3 | 2010-02-16 15:20:26 +0000 | [diff] [blame] | 276 | if (snmp_mib_init((void __percpu **)idev->stats.ipv6, |
Eric Dumazet | 1823e4c8 | 2010-06-22 20:58:41 +0000 | [diff] [blame] | 277 | sizeof(struct ipstats_mib), |
| 278 | __alignof__(struct ipstats_mib)) < 0) |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 279 | goto err_ip; |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 280 | |
| 281 | for_each_possible_cpu(i) { |
| 282 | struct ipstats_mib *addrconf_stats; |
| 283 | addrconf_stats = per_cpu_ptr(idev->stats.ipv6[0], i); |
| 284 | u64_stats_init(&addrconf_stats->syncp); |
| 285 | #if SNMP_ARRAY_SZ == 2 |
| 286 | addrconf_stats = per_cpu_ptr(idev->stats.ipv6[1], i); |
| 287 | u64_stats_init(&addrconf_stats->syncp); |
| 288 | #endif |
| 289 | } |
| 290 | |
| 291 | |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 292 | idev->stats.icmpv6dev = kzalloc(sizeof(struct icmpv6_mib_device), |
| 293 | GFP_KERNEL); |
| 294 | if (!idev->stats.icmpv6dev) |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 295 | goto err_icmp; |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 296 | idev->stats.icmpv6msgdev = kzalloc(sizeof(struct icmpv6msg_mib_device), |
| 297 | GFP_KERNEL); |
| 298 | if (!idev->stats.icmpv6msgdev) |
David L Stevens | 14878f7 | 2007-09-16 16:52:35 -0700 | [diff] [blame] | 299 | goto err_icmpmsg; |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 300 | |
| 301 | return 0; |
| 302 | |
David L Stevens | 14878f7 | 2007-09-16 16:52:35 -0700 | [diff] [blame] | 303 | err_icmpmsg: |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 304 | kfree(idev->stats.icmpv6dev); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 305 | err_icmp: |
Tejun Heo | 7d720c3 | 2010-02-16 15:20:26 +0000 | [diff] [blame] | 306 | snmp_mib_free((void __percpu **)idev->stats.ipv6); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 307 | err_ip: |
Pavel Emelyanov | aaf70ec | 2007-10-17 21:25:32 -0700 | [diff] [blame] | 308 | return -ENOMEM; |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 311 | static struct inet6_dev *ipv6_add_dev(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
| 313 | struct inet6_dev *ndev; |
| 314 | |
| 315 | ASSERT_RTNL(); |
| 316 | |
| 317 | if (dev->mtu < IPV6_MIN_MTU) |
| 318 | return NULL; |
| 319 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 320 | ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 322 | if (ndev == NULL) |
| 323 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 325 | rwlock_init(&ndev->lock); |
| 326 | ndev->dev = dev; |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 327 | INIT_LIST_HEAD(&ndev->addr_list); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 328 | setup_timer(&ndev->rs_timer, addrconf_rs_timer, |
| 329 | (unsigned long)ndev); |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 330 | memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 331 | ndev->cnf.mtu6 = dev->mtu; |
| 332 | ndev->cnf.sysctl = NULL; |
| 333 | ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); |
| 334 | if (ndev->nd_parms == NULL) { |
| 335 | kfree(ndev); |
| 336 | return NULL; |
| 337 | } |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 338 | if (ndev->cnf.forwarding) |
| 339 | dev_disable_lro(dev); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 340 | /* We refer to the device */ |
| 341 | dev_hold(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 343 | if (snmp6_alloc_dev(ndev) < 0) { |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 344 | ADBG(KERN_WARNING |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 345 | "%s: cannot allocate memory for statistics; dev=%s.\n", |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 346 | __func__, dev->name); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 347 | neigh_parms_release(&nd_tbl, ndev->nd_parms); |
Roy Li | 8603e33 | 2011-09-20 15:10:16 -0400 | [diff] [blame] | 348 | dev_put(dev); |
| 349 | kfree(ndev); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 350 | return NULL; |
| 351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 353 | if (snmp6_register_dev(ndev) < 0) { |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 354 | ADBG(KERN_WARNING |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 355 | "%s: cannot create /proc/net/dev_snmp6/%s\n", |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 356 | __func__, dev->name); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 357 | neigh_parms_release(&nd_tbl, ndev->nd_parms); |
| 358 | ndev->dead = 1; |
| 359 | in6_dev_finish_destroy(ndev); |
| 360 | return NULL; |
| 361 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 363 | /* One reference from device. We must do this before |
| 364 | * we invoke __ipv6_regen_rndid(). |
| 365 | */ |
| 366 | in6_dev_hold(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 368 | if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) |
| 369 | ndev->cnf.accept_dad = -1; |
| 370 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 371 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
YOSHIFUJI Hideaki | b077d7a | 2008-04-13 23:42:18 -0700 | [diff] [blame] | 372 | if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) { |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 373 | pr_info("%s: Disabled Multicast RS\n", dev->name); |
YOSHIFUJI Hideaki | b077d7a | 2008-04-13 23:42:18 -0700 | [diff] [blame] | 374 | ndev->cnf.rtr_solicits = 0; |
| 375 | } |
| 376 | #endif |
| 377 | |
stephen hemminger | 372e6c8 | 2010-03-17 20:31:09 +0000 | [diff] [blame] | 378 | INIT_LIST_HEAD(&ndev->tempaddr_list); |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 379 | setup_timer(&ndev->regen_timer, ipv6_regen_rndid, (unsigned long)ndev); |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 380 | if ((dev->flags&IFF_LOOPBACK) || |
| 381 | dev->type == ARPHRD_TUNNEL || |
YOSHIFUJI Hideaki | 9625ed7 | 2008-04-13 23:47:11 -0700 | [diff] [blame] | 382 | dev->type == ARPHRD_TUNNEL6 || |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 383 | dev->type == ARPHRD_SIT || |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 384 | dev->type == ARPHRD_NONE) { |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 385 | ndev->cnf.use_tempaddr = -1; |
| 386 | } else { |
| 387 | in6_dev_hold(ndev); |
| 388 | ipv6_regen_rndid((unsigned long) ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
David S. Miller | 5d9efa7 | 2013-10-28 20:07:50 -0400 | [diff] [blame] | 390 | |
Daniel Borkmann | 914faa1 | 2013-04-09 03:47:14 +0000 | [diff] [blame] | 391 | ndev->token = in6addr_any; |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 392 | |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 393 | if (netif_running(dev) && addrconf_qdisc_ok(dev)) |
Herbert Xu | 53aadcc | 2007-03-27 14:31:52 -0700 | [diff] [blame] | 394 | ndev->if_flags |= IF_READY; |
| 395 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 396 | ipv6_mc_init_dev(ndev); |
| 397 | ndev->tstamp = jiffies; |
Pavel Emelyanov | f52295a | 2007-12-02 00:58:37 +1100 | [diff] [blame] | 398 | addrconf_sysctl_register(ndev); |
David L Stevens | 30c4cf5 | 2007-01-04 12:31:14 -0800 | [diff] [blame] | 399 | /* protected by rtnl_lock */ |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 400 | rcu_assign_pointer(dev->ip6_ptr, ndev); |
YOSHIFUJI Hideaki | d88ae4c | 2007-01-14 21:48:40 -0800 | [diff] [blame] | 401 | |
Hannes Frederic Sowa | 2c5e893 | 2013-02-10 03:50:18 +0000 | [diff] [blame] | 402 | /* Join interface-local all-node multicast group */ |
| 403 | ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allnodes); |
| 404 | |
YOSHIFUJI Hideaki | d88ae4c | 2007-01-14 21:48:40 -0800 | [diff] [blame] | 405 | /* Join all-node multicast group */ |
YOSHIFUJI Hideaki | f3ee401 | 2008-04-10 15:42:11 +0900 | [diff] [blame] | 406 | ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes); |
YOSHIFUJI Hideaki | d88ae4c | 2007-01-14 21:48:40 -0800 | [diff] [blame] | 407 | |
Li Wei | d6ddef9 | 2012-03-05 14:45:17 +0000 | [diff] [blame] | 408 | /* Join all-router multicast group if forwarding is set */ |
Li Wei | 8b2aaed | 2012-03-07 14:58:07 +0000 | [diff] [blame] | 409 | if (ndev->cnf.forwarding && (dev->flags & IFF_MULTICAST)) |
Li Wei | d6ddef9 | 2012-03-05 14:45:17 +0000 | [diff] [blame] | 410 | ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters); |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return ndev; |
| 413 | } |
| 414 | |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 415 | static struct inet6_dev *ipv6_find_idev(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | struct inet6_dev *idev; |
| 418 | |
| 419 | ASSERT_RTNL(); |
| 420 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 421 | idev = __in6_dev_get(dev); |
| 422 | if (!idev) { |
| 423 | idev = ipv6_add_dev(dev); |
| 424 | if (!idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return NULL; |
| 426 | } |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (dev->flags&IFF_UP) |
| 429 | ipv6_mc_up(idev); |
| 430 | return idev; |
| 431 | } |
| 432 | |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 433 | static int inet6_netconf_msgsize_devconf(int type) |
| 434 | { |
| 435 | int size = NLMSG_ALIGN(sizeof(struct netconfmsg)) |
| 436 | + nla_total_size(4); /* NETCONFA_IFINDEX */ |
| 437 | |
Nicolas Dichtel | 76f8f6c | 2012-10-25 22:28:51 +0000 | [diff] [blame] | 438 | /* type -1 is used for ALL */ |
| 439 | if (type == -1 || type == NETCONFA_FORWARDING) |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 440 | size += nla_total_size(4); |
David S. Miller | b1afce9 | 2012-12-04 14:46:34 -0500 | [diff] [blame] | 441 | #ifdef CONFIG_IPV6_MROUTE |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 442 | if (type == -1 || type == NETCONFA_MC_FORWARDING) |
| 443 | size += nla_total_size(4); |
David S. Miller | b1afce9 | 2012-12-04 14:46:34 -0500 | [diff] [blame] | 444 | #endif |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 445 | |
| 446 | return size; |
| 447 | } |
| 448 | |
| 449 | static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex, |
| 450 | struct ipv6_devconf *devconf, u32 portid, |
| 451 | u32 seq, int event, unsigned int flags, |
| 452 | int type) |
| 453 | { |
| 454 | struct nlmsghdr *nlh; |
| 455 | struct netconfmsg *ncm; |
| 456 | |
| 457 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg), |
| 458 | flags); |
| 459 | if (nlh == NULL) |
| 460 | return -EMSGSIZE; |
| 461 | |
| 462 | ncm = nlmsg_data(nlh); |
| 463 | ncm->ncm_family = AF_INET6; |
| 464 | |
| 465 | if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0) |
| 466 | goto nla_put_failure; |
| 467 | |
Nicolas Dichtel | 76f8f6c | 2012-10-25 22:28:51 +0000 | [diff] [blame] | 468 | /* type -1 is used for ALL */ |
| 469 | if ((type == -1 || type == NETCONFA_FORWARDING) && |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 470 | nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0) |
| 471 | goto nla_put_failure; |
David S. Miller | b1afce9 | 2012-12-04 14:46:34 -0500 | [diff] [blame] | 472 | #ifdef CONFIG_IPV6_MROUTE |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 473 | if ((type == -1 || type == NETCONFA_MC_FORWARDING) && |
| 474 | nla_put_s32(skb, NETCONFA_MC_FORWARDING, |
| 475 | devconf->mc_forwarding) < 0) |
| 476 | goto nla_put_failure; |
David S. Miller | b1afce9 | 2012-12-04 14:46:34 -0500 | [diff] [blame] | 477 | #endif |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 478 | return nlmsg_end(skb, nlh); |
| 479 | |
| 480 | nla_put_failure: |
| 481 | nlmsg_cancel(skb, nlh); |
| 482 | return -EMSGSIZE; |
| 483 | } |
| 484 | |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 485 | void inet6_netconf_notify_devconf(struct net *net, int type, int ifindex, |
| 486 | struct ipv6_devconf *devconf) |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 487 | { |
| 488 | struct sk_buff *skb; |
| 489 | int err = -ENOBUFS; |
| 490 | |
| 491 | skb = nlmsg_new(inet6_netconf_msgsize_devconf(type), GFP_ATOMIC); |
| 492 | if (skb == NULL) |
| 493 | goto errout; |
| 494 | |
| 495 | err = inet6_netconf_fill_devconf(skb, ifindex, devconf, 0, 0, |
| 496 | RTM_NEWNETCONF, 0, type); |
| 497 | if (err < 0) { |
| 498 | /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ |
| 499 | WARN_ON(err == -EMSGSIZE); |
| 500 | kfree_skb(skb); |
| 501 | goto errout; |
| 502 | } |
| 503 | rtnl_notify(skb, net, 0, RTNLGRP_IPV6_NETCONF, NULL, GFP_ATOMIC); |
| 504 | return; |
| 505 | errout: |
Cong Ding | bd77902 | 2012-12-18 12:08:56 +0000 | [diff] [blame] | 506 | rtnl_set_sk_err(net, RTNLGRP_IPV6_NETCONF, err); |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Nicolas Dichtel | 76f8f6c | 2012-10-25 22:28:51 +0000 | [diff] [blame] | 509 | static const struct nla_policy devconf_ipv6_policy[NETCONFA_MAX+1] = { |
| 510 | [NETCONFA_IFINDEX] = { .len = sizeof(int) }, |
| 511 | [NETCONFA_FORWARDING] = { .len = sizeof(int) }, |
| 512 | }; |
| 513 | |
| 514 | static int inet6_netconf_get_devconf(struct sk_buff *in_skb, |
Thomas Graf | 661d296 | 2013-03-21 07:45:29 +0000 | [diff] [blame] | 515 | struct nlmsghdr *nlh) |
Nicolas Dichtel | 76f8f6c | 2012-10-25 22:28:51 +0000 | [diff] [blame] | 516 | { |
| 517 | struct net *net = sock_net(in_skb->sk); |
| 518 | struct nlattr *tb[NETCONFA_MAX+1]; |
| 519 | struct netconfmsg *ncm; |
| 520 | struct sk_buff *skb; |
| 521 | struct ipv6_devconf *devconf; |
| 522 | struct inet6_dev *in6_dev; |
| 523 | struct net_device *dev; |
| 524 | int ifindex; |
| 525 | int err; |
| 526 | |
| 527 | err = nlmsg_parse(nlh, sizeof(*ncm), tb, NETCONFA_MAX, |
| 528 | devconf_ipv6_policy); |
| 529 | if (err < 0) |
| 530 | goto errout; |
| 531 | |
| 532 | err = EINVAL; |
| 533 | if (!tb[NETCONFA_IFINDEX]) |
| 534 | goto errout; |
| 535 | |
| 536 | ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]); |
| 537 | switch (ifindex) { |
| 538 | case NETCONFA_IFINDEX_ALL: |
| 539 | devconf = net->ipv6.devconf_all; |
| 540 | break; |
| 541 | case NETCONFA_IFINDEX_DEFAULT: |
| 542 | devconf = net->ipv6.devconf_dflt; |
| 543 | break; |
| 544 | default: |
| 545 | dev = __dev_get_by_index(net, ifindex); |
| 546 | if (dev == NULL) |
| 547 | goto errout; |
| 548 | in6_dev = __in6_dev_get(dev); |
| 549 | if (in6_dev == NULL) |
| 550 | goto errout; |
| 551 | devconf = &in6_dev->cnf; |
| 552 | break; |
| 553 | } |
| 554 | |
| 555 | err = -ENOBUFS; |
| 556 | skb = nlmsg_new(inet6_netconf_msgsize_devconf(-1), GFP_ATOMIC); |
| 557 | if (skb == NULL) |
| 558 | goto errout; |
| 559 | |
| 560 | err = inet6_netconf_fill_devconf(skb, ifindex, devconf, |
| 561 | NETLINK_CB(in_skb).portid, |
| 562 | nlh->nlmsg_seq, RTM_NEWNETCONF, 0, |
| 563 | -1); |
| 564 | if (err < 0) { |
| 565 | /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ |
| 566 | WARN_ON(err == -EMSGSIZE); |
| 567 | kfree_skb(skb); |
| 568 | goto errout; |
| 569 | } |
| 570 | err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); |
| 571 | errout: |
| 572 | return err; |
| 573 | } |
| 574 | |
Nicolas Dichtel | 7a67420 | 2013-03-05 23:42:06 +0000 | [diff] [blame] | 575 | static int inet6_netconf_dump_devconf(struct sk_buff *skb, |
| 576 | struct netlink_callback *cb) |
| 577 | { |
| 578 | struct net *net = sock_net(skb->sk); |
| 579 | int h, s_h; |
| 580 | int idx, s_idx; |
| 581 | struct net_device *dev; |
| 582 | struct inet6_dev *idev; |
| 583 | struct hlist_head *head; |
| 584 | |
| 585 | s_h = cb->args[0]; |
| 586 | s_idx = idx = cb->args[1]; |
| 587 | |
| 588 | for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { |
| 589 | idx = 0; |
| 590 | head = &net->dev_index_head[h]; |
| 591 | rcu_read_lock(); |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 592 | cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ |
| 593 | net->dev_base_seq; |
Nicolas Dichtel | 7a67420 | 2013-03-05 23:42:06 +0000 | [diff] [blame] | 594 | hlist_for_each_entry_rcu(dev, head, index_hlist) { |
| 595 | if (idx < s_idx) |
| 596 | goto cont; |
| 597 | idev = __in6_dev_get(dev); |
| 598 | if (!idev) |
| 599 | goto cont; |
| 600 | |
| 601 | if (inet6_netconf_fill_devconf(skb, dev->ifindex, |
| 602 | &idev->cnf, |
| 603 | NETLINK_CB(cb->skb).portid, |
| 604 | cb->nlh->nlmsg_seq, |
| 605 | RTM_NEWNETCONF, |
| 606 | NLM_F_MULTI, |
| 607 | -1) <= 0) { |
| 608 | rcu_read_unlock(); |
| 609 | goto done; |
| 610 | } |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 611 | nl_dump_check_consistent(cb, nlmsg_hdr(skb)); |
Nicolas Dichtel | 7a67420 | 2013-03-05 23:42:06 +0000 | [diff] [blame] | 612 | cont: |
| 613 | idx++; |
| 614 | } |
| 615 | rcu_read_unlock(); |
| 616 | } |
| 617 | if (h == NETDEV_HASHENTRIES) { |
| 618 | if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_ALL, |
| 619 | net->ipv6.devconf_all, |
| 620 | NETLINK_CB(cb->skb).portid, |
| 621 | cb->nlh->nlmsg_seq, |
| 622 | RTM_NEWNETCONF, NLM_F_MULTI, |
| 623 | -1) <= 0) |
| 624 | goto done; |
| 625 | else |
| 626 | h++; |
| 627 | } |
| 628 | if (h == NETDEV_HASHENTRIES + 1) { |
| 629 | if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_DEFAULT, |
| 630 | net->ipv6.devconf_dflt, |
| 631 | NETLINK_CB(cb->skb).portid, |
| 632 | cb->nlh->nlmsg_seq, |
| 633 | RTM_NEWNETCONF, NLM_F_MULTI, |
| 634 | -1) <= 0) |
| 635 | goto done; |
| 636 | else |
| 637 | h++; |
| 638 | } |
| 639 | done: |
| 640 | cb->args[0] = h; |
| 641 | cb->args[1] = idx; |
| 642 | |
| 643 | return skb->len; |
| 644 | } |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | #ifdef CONFIG_SYSCTL |
| 647 | static void dev_forward_change(struct inet6_dev *idev) |
| 648 | { |
| 649 | struct net_device *dev; |
| 650 | struct inet6_ifaddr *ifa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | if (!idev) |
| 653 | return; |
| 654 | dev = idev->dev; |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 655 | if (idev->cnf.forwarding) |
| 656 | dev_disable_lro(dev); |
Amerigo Wang | 1a94083 | 2012-10-28 17:43:53 +0000 | [diff] [blame] | 657 | if (dev->flags & IFF_MULTICAST) { |
Hannes Frederic Sowa | 2c5e893 | 2013-02-10 03:50:18 +0000 | [diff] [blame] | 658 | if (idev->cnf.forwarding) { |
YOSHIFUJI Hideaki | f3ee401 | 2008-04-10 15:42:11 +0900 | [diff] [blame] | 659 | ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters); |
Hannes Frederic Sowa | 2c5e893 | 2013-02-10 03:50:18 +0000 | [diff] [blame] | 660 | ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allrouters); |
| 661 | ipv6_dev_mc_inc(dev, &in6addr_sitelocal_allrouters); |
| 662 | } else { |
YOSHIFUJI Hideaki | f3ee401 | 2008-04-10 15:42:11 +0900 | [diff] [blame] | 663 | ipv6_dev_mc_dec(dev, &in6addr_linklocal_allrouters); |
Hannes Frederic Sowa | 2c5e893 | 2013-02-10 03:50:18 +0000 | [diff] [blame] | 664 | ipv6_dev_mc_dec(dev, &in6addr_interfacelocal_allrouters); |
| 665 | ipv6_dev_mc_dec(dev, &in6addr_sitelocal_allrouters); |
| 666 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 668 | |
| 669 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
Michal Wrobel | 2c12a74 | 2007-02-26 15:36:10 -0800 | [diff] [blame] | 670 | if (ifa->flags&IFA_F_TENTATIVE) |
| 671 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | if (idev->cnf.forwarding) |
| 673 | addrconf_join_anycast(ifa); |
| 674 | else |
| 675 | addrconf_leave_anycast(ifa); |
| 676 | } |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 677 | inet6_netconf_notify_devconf(dev_net(dev), NETCONFA_FORWARDING, |
| 678 | dev->ifindex, &idev->cnf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | |
Pavel Emelyanov | e186932 | 2008-01-10 17:43:50 -0800 | [diff] [blame] | 682 | static void addrconf_forward_change(struct net *net, __s32 newf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
| 684 | struct net_device *dev; |
| 685 | struct inet6_dev *idev; |
| 686 | |
Ben Hutchings | 4acd494 | 2012-08-14 08:54:51 +0000 | [diff] [blame] | 687 | for_each_netdev(net, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | idev = __in6_dev_get(dev); |
| 689 | if (idev) { |
Pavel Emelyanov | e186932 | 2008-01-10 17:43:50 -0800 | [diff] [blame] | 690 | int changed = (!idev->cnf.forwarding) ^ (!newf); |
| 691 | idev->cnf.forwarding = newf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | if (changed) |
| 693 | dev_forward_change(idev); |
| 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 697 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 698 | static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf) |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 699 | { |
Pavel Emelyanov | bff16c2 | 2008-01-10 17:42:13 -0800 | [diff] [blame] | 700 | struct net *net; |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 701 | int old; |
| 702 | |
| 703 | if (!rtnl_trylock()) |
| 704 | return restart_syscall(); |
Pavel Emelyanov | bff16c2 | 2008-01-10 17:42:13 -0800 | [diff] [blame] | 705 | |
| 706 | net = (struct net *)table->extra2; |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 707 | old = *p; |
| 708 | *p = newf; |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 709 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 710 | if (p == &net->ipv6.devconf_dflt->forwarding) { |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 711 | if ((!newf) ^ (!old)) |
| 712 | inet6_netconf_notify_devconf(net, NETCONFA_FORWARDING, |
| 713 | NETCONFA_IFINDEX_DEFAULT, |
| 714 | net->ipv6.devconf_dflt); |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 715 | rtnl_unlock(); |
| 716 | return 0; |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 717 | } |
Stephen Hemminger | b325fdd | 2009-02-26 06:55:31 +0000 | [diff] [blame] | 718 | |
Pavel Emelyanov | e186932 | 2008-01-10 17:43:50 -0800 | [diff] [blame] | 719 | if (p == &net->ipv6.devconf_all->forwarding) { |
Pavel Emelyanov | e186932 | 2008-01-10 17:43:50 -0800 | [diff] [blame] | 720 | net->ipv6.devconf_dflt->forwarding = newf; |
| 721 | addrconf_forward_change(net, newf); |
Nicolas Dichtel | f3a1bfb | 2012-10-25 22:28:50 +0000 | [diff] [blame] | 722 | if ((!newf) ^ (!old)) |
| 723 | inet6_netconf_notify_devconf(net, NETCONFA_FORWARDING, |
| 724 | NETCONFA_IFINDEX_ALL, |
| 725 | net->ipv6.devconf_all); |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 726 | } else if ((!newf) ^ (!old)) |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 727 | dev_forward_change((struct inet6_dev *)table->extra1); |
Ben Hutchings | 0187bdf | 2008-06-19 16:15:47 -0700 | [diff] [blame] | 728 | rtnl_unlock(); |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 729 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 730 | if (newf) |
Daniel Lezcano | 7b4da53 | 2008-03-04 13:47:14 -0800 | [diff] [blame] | 731 | rt6_purge_dflt_routers(net); |
Stephen Hemminger | b325fdd | 2009-02-26 06:55:31 +0000 | [diff] [blame] | 732 | return 1; |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 733 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | #endif |
| 735 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 736 | /* Nobody refers to this ifaddr, destroy it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) |
| 738 | { |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 739 | WARN_ON(!hlist_unhashed(&ifp->addr_lst)); |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | #ifdef NET_REFCNT_DEBUG |
Joe Perches | 91df42b | 2012-05-15 14:11:54 +0000 | [diff] [blame] | 742 | pr_debug("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | #endif |
| 744 | |
| 745 | in6_dev_put(ifp->idev); |
| 746 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 747 | if (del_timer(&ifp->dad_timer)) |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 748 | pr_notice("Timer is still running, when freeing ifa=%p\n", ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Herbert Xu | e9d3e08 | 2010-05-18 15:36:06 -0700 | [diff] [blame] | 750 | if (ifp->state != INET6_IFADDR_STATE_DEAD) { |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 751 | pr_warn("Freeing alive inet6 address %p\n", ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | return; |
| 753 | } |
Amerigo Wang | 94e187c | 2012-10-29 00:13:19 +0000 | [diff] [blame] | 754 | ip6_rt_put(ifp->rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Lai Jiangshan | e578598 | 2011-03-15 18:00:14 +0800 | [diff] [blame] | 756 | kfree_rcu(ifp, rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 759 | static void |
| 760 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) |
| 761 | { |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 762 | struct list_head *p; |
YOSHIFUJI Hideaki | 8a6ce0c | 2006-07-11 13:05:30 -0700 | [diff] [blame] | 763 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 764 | |
| 765 | /* |
| 766 | * Each device address list is sorted in order of scope - |
| 767 | * global before linklocal. |
| 768 | */ |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 769 | list_for_each(p, &idev->addr_list) { |
| 770 | struct inet6_ifaddr *ifa |
| 771 | = list_entry(p, struct inet6_ifaddr, if_list); |
YOSHIFUJI Hideaki | 8a6ce0c | 2006-07-11 13:05:30 -0700 | [diff] [blame] | 772 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 773 | break; |
| 774 | } |
| 775 | |
David S. Miller | b54c9b9 | 2010-03-25 21:25:30 -0700 | [diff] [blame] | 776 | list_add_tail(&ifp->if_list, p); |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 779 | static u32 inet6_addr_hash(const struct in6_addr *addr) |
YOSHIFUJI Hideaki | 3eb84f4 | 2008-04-10 15:42:08 +0900 | [diff] [blame] | 780 | { |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 781 | return hash_32(ipv6_addr_hash(addr), IN6_ADDR_HSIZE_SHIFT); |
YOSHIFUJI Hideaki | 3eb84f4 | 2008-04-10 15:42:08 +0900 | [diff] [blame] | 782 | } |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | /* On success it returns ifp with increased reference count */ |
| 785 | |
| 786 | static struct inet6_ifaddr * |
Jiri Pirko | 3f8f529 | 2013-08-01 10:41:27 +0200 | [diff] [blame] | 787 | ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, |
| 788 | const struct in6_addr *peer_addr, int pfxlen, |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 789 | int scope, u32 flags, u32 valid_lft, u32 prefered_lft) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { |
| 791 | struct inet6_ifaddr *ifa = NULL; |
| 792 | struct rt6_info *rt; |
stephen hemminger | 3a88a81 | 2010-03-17 20:31:12 +0000 | [diff] [blame] | 793 | unsigned int hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | int err = 0; |
YOSHIFUJI Hideaki | d68b827 | 2008-06-25 16:26:47 +0900 | [diff] [blame] | 795 | int addr_type = ipv6_addr_type(addr); |
| 796 | |
| 797 | if (addr_type == IPV6_ADDR_ANY || |
| 798 | addr_type & IPV6_ADDR_MULTICAST || |
| 799 | (!(idev->dev->flags & IFF_LOOPBACK) && |
| 800 | addr_type & IPV6_ADDR_LOOPBACK)) |
| 801 | return ERR_PTR(-EADDRNOTAVAIL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 803 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | if (idev->dead) { |
| 805 | err = -ENODEV; /*XXX*/ |
| 806 | goto out2; |
| 807 | } |
| 808 | |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 809 | if (idev->cnf.disable_ipv6) { |
Brian Haley | 9bdd8d4 | 2009-03-18 18:22:48 -0700 | [diff] [blame] | 810 | err = -EACCES; |
| 811 | goto out2; |
| 812 | } |
| 813 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 814 | spin_lock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | /* Ignore adding duplicate addresses on an interface */ |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 817 | if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 818 | ADBG("ipv6_add_addr: already assigned\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | err = -EEXIST; |
| 820 | goto out; |
| 821 | } |
| 822 | |
Ingo Oeser | 322f74a | 2006-03-20 23:01:47 -0800 | [diff] [blame] | 823 | ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | if (ifa == NULL) { |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 826 | ADBG("ipv6_add_addr: malloc failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | err = -ENOBUFS; |
| 828 | goto out; |
| 829 | } |
| 830 | |
David S. Miller | 8f03151 | 2011-12-06 16:48:14 -0500 | [diff] [blame] | 831 | rt = addrconf_dst_alloc(idev, addr, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (IS_ERR(rt)) { |
| 833 | err = PTR_ERR(rt); |
| 834 | goto out; |
| 835 | } |
| 836 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 837 | ifa->addr = *addr; |
Jiri Pirko | 3f8f529 | 2013-08-01 10:41:27 +0200 | [diff] [blame] | 838 | if (peer_addr) |
| 839 | ifa->peer_addr = *peer_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | spin_lock_init(&ifa->lock); |
Herbert Xu | e9d3e08 | 2010-05-18 15:36:06 -0700 | [diff] [blame] | 842 | spin_lock_init(&ifa->state_lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 843 | setup_timer(&ifa->dad_timer, addrconf_dad_timer, |
| 844 | (unsigned long)ifa); |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 845 | INIT_HLIST_NODE(&ifa->addr_lst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | ifa->scope = scope; |
| 847 | ifa->prefix_len = pfxlen; |
| 848 | ifa->flags = flags | IFA_F_TENTATIVE; |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 849 | ifa->valid_lft = valid_lft; |
| 850 | ifa->prefered_lft = prefered_lft; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | ifa->cstamp = ifa->tstamp = jiffies; |
Daniel Borkmann | 617fe29 | 2013-04-09 03:47:16 +0000 | [diff] [blame] | 852 | ifa->tokenized = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Keir Fraser | 57f5f54 | 2006-08-29 02:43:49 -0700 | [diff] [blame] | 854 | ifa->rt = rt; |
| 855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | ifa->idev = idev; |
| 857 | in6_dev_hold(idev); |
| 858 | /* For caller */ |
| 859 | in6_ifa_hold(ifa); |
| 860 | |
| 861 | /* Add to big hash table */ |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 862 | hash = inet6_addr_hash(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 864 | hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 865 | spin_unlock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
| 867 | write_lock(&idev->lock); |
| 868 | /* Add to inet6_dev unicast addr list. */ |
Brian Haley | e55ffac | 2006-07-10 15:25:51 -0700 | [diff] [blame] | 869 | ipv6_link_dev_addr(idev, ifa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | if (ifa->flags&IFA_F_TEMPORARY) { |
stephen hemminger | 372e6c8 | 2010-03-17 20:31:09 +0000 | [diff] [blame] | 872 | list_add(&ifa->tmp_list, &idev->tempaddr_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | in6_ifa_hold(ifa); |
| 874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | in6_ifa_hold(ifa); |
| 877 | write_unlock(&idev->lock); |
| 878 | out2: |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 879 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
YOSHIFUJI Hideaki | fd92833 | 2005-04-19 22:27:09 -0700 | [diff] [blame] | 881 | if (likely(err == 0)) |
Cong Wang | f88c91d | 2013-04-14 23:18:43 +0800 | [diff] [blame] | 882 | inet6addr_notifier_call_chain(NETDEV_UP, ifa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | else { |
| 884 | kfree(ifa); |
| 885 | ifa = ERR_PTR(err); |
| 886 | } |
| 887 | |
| 888 | return ifa; |
| 889 | out: |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 890 | spin_unlock(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | goto out2; |
| 892 | } |
| 893 | |
| 894 | /* This function wants to get referenced ifp and releases it before return */ |
| 895 | |
| 896 | static void ipv6_del_addr(struct inet6_ifaddr *ifp) |
| 897 | { |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 898 | struct inet6_ifaddr *ifa, *ifn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | struct inet6_dev *idev = ifp->idev; |
Herbert Xu | 4c5ff6a | 2010-05-18 15:54:18 -0700 | [diff] [blame] | 900 | int state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | int deleted = 0, onlink = 0; |
| 902 | unsigned long expires = jiffies; |
| 903 | |
Herbert Xu | 4c5ff6a | 2010-05-18 15:54:18 -0700 | [diff] [blame] | 904 | spin_lock_bh(&ifp->state_lock); |
| 905 | state = ifp->state; |
Herbert Xu | e9d3e08 | 2010-05-18 15:36:06 -0700 | [diff] [blame] | 906 | ifp->state = INET6_IFADDR_STATE_DEAD; |
Herbert Xu | 4c5ff6a | 2010-05-18 15:54:18 -0700 | [diff] [blame] | 907 | spin_unlock_bh(&ifp->state_lock); |
| 908 | |
| 909 | if (state == INET6_IFADDR_STATE_DEAD) |
| 910 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 912 | spin_lock_bh(&addrconf_hash_lock); |
| 913 | hlist_del_init_rcu(&ifp->addr_lst); |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 914 | spin_unlock_bh(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | write_lock_bh(&idev->lock); |
David S. Miller | 5d9efa7 | 2013-10-28 20:07:50 -0400 | [diff] [blame] | 917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | if (ifp->flags&IFA_F_TEMPORARY) { |
stephen hemminger | 372e6c8 | 2010-03-17 20:31:09 +0000 | [diff] [blame] | 919 | list_del(&ifp->tmp_list); |
| 920 | if (ifp->ifpub) { |
| 921 | in6_ifa_put(ifp->ifpub); |
| 922 | ifp->ifpub = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | } |
stephen hemminger | 372e6c8 | 2010-03-17 20:31:09 +0000 | [diff] [blame] | 924 | __in6_ifa_put(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 927 | list_for_each_entry_safe(ifa, ifn, &idev->addr_list, if_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if (ifa == ifp) { |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 929 | list_del_init(&ifp->if_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | __in6_ifa_put(ifp); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0) |
| 933 | break; |
| 934 | deleted = 1; |
Kristian Slavov | 1d14280 | 2005-12-21 18:47:24 -0800 | [diff] [blame] | 935 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } else if (ifp->flags & IFA_F_PERMANENT) { |
| 937 | if (ipv6_prefix_equal(&ifa->addr, &ifp->addr, |
| 938 | ifp->prefix_len)) { |
| 939 | if (ifa->flags & IFA_F_PERMANENT) { |
| 940 | onlink = 1; |
| 941 | if (deleted) |
| 942 | break; |
| 943 | } else { |
| 944 | unsigned long lifetime; |
| 945 | |
| 946 | if (!onlink) |
| 947 | onlink = -1; |
| 948 | |
| 949 | spin_lock(&ifa->lock); |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 950 | |
| 951 | lifetime = addrconf_timeout_fixup(ifa->valid_lft, HZ); |
| 952 | /* |
| 953 | * Note: Because this address is |
| 954 | * not permanent, lifetime < |
| 955 | * LONG_MAX / HZ here. |
| 956 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (time_before(expires, |
| 958 | ifa->tstamp + lifetime * HZ)) |
| 959 | expires = ifa->tstamp + lifetime * HZ; |
| 960 | spin_unlock(&ifa->lock); |
| 961 | } |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | write_unlock_bh(&idev->lock); |
| 966 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 967 | addrconf_del_dad_timer(ifp); |
Andrey Vagin | b223856 | 2008-07-08 15:13:31 -0700 | [diff] [blame] | 968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | ipv6_ifa_notify(RTM_DELADDR, ifp); |
| 970 | |
Cong Wang | f88c91d | 2013-04-14 23:18:43 +0800 | [diff] [blame] | 971 | inet6addr_notifier_call_chain(NETDEV_DOWN, ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | /* |
| 974 | * Purge or update corresponding prefix |
| 975 | * |
| 976 | * 1) we don't purge prefix here if address was not permanent. |
| 977 | * prefix is managed by its own lifetime. |
| 978 | * 2) if there're no addresses, delete prefix. |
| 979 | * 3) if there're still other permanent address(es), |
| 980 | * corresponding prefix is still permanent. |
| 981 | * 4) otherwise, update prefix lifetime to the |
| 982 | * longest valid lifetime among the corresponding |
| 983 | * addresses on the device. |
| 984 | * Note: subsequent RA will update lifetime. |
| 985 | * |
| 986 | * --yoshfuji |
| 987 | */ |
| 988 | if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) { |
| 989 | struct in6_addr prefix; |
| 990 | struct rt6_info *rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Nicolas Dichtel | 64c6d08 | 2012-09-26 00:04:55 +0000 | [diff] [blame] | 992 | ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len); |
Nicolas Dichtel | 64c6d08 | 2012-09-26 00:04:55 +0000 | [diff] [blame] | 993 | |
Romain Kuntz | 21caa66 | 2013-01-09 21:06:03 +0000 | [diff] [blame] | 994 | rt = addrconf_get_prefix_route(&prefix, |
| 995 | ifp->prefix_len, |
| 996 | ifp->idev->dev, |
| 997 | 0, RTF_GATEWAY | RTF_DEFAULT); |
| 998 | |
| 999 | if (rt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | if (onlink == 0) { |
Thomas Graf | e0a1ad73 | 2006-08-22 00:00:21 -0700 | [diff] [blame] | 1001 | ip6_del_rt(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | rt = NULL; |
| 1003 | } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { |
Gao feng | 1716a96 | 2012-04-06 00:13:10 +0000 | [diff] [blame] | 1004 | rt6_set_expires(rt, expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | } |
Amerigo Wang | 94e187c | 2012-10-29 00:13:19 +0000 | [diff] [blame] | 1007 | ip6_rt_put(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Daniel Walter | c3968a8 | 2011-04-13 21:10:57 +0000 | [diff] [blame] | 1010 | /* clean up prefsrc entries */ |
| 1011 | rt6_remove_prefsrc(ifp); |
Herbert Xu | 4c5ff6a | 2010-05-18 15:54:18 -0700 | [diff] [blame] | 1012 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | in6_ifa_put(ifp); |
| 1014 | } |
| 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *ift) |
| 1017 | { |
| 1018 | struct inet6_dev *idev = ifp->idev; |
| 1019 | struct in6_addr addr, *tmpaddr; |
Lorenzo Colitti | 76f793e | 2011-07-26 13:50:49 +0000 | [diff] [blame] | 1020 | unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_tstamp, age; |
Benoit Boissinot | eac55bf | 2008-04-02 00:01:35 -0700 | [diff] [blame] | 1021 | unsigned long regen_advance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | int tmp_plen; |
| 1023 | int ret = 0; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1024 | u32 addr_flags; |
Lorenzo Colitti | 76f793e | 2011-07-26 13:50:49 +0000 | [diff] [blame] | 1025 | unsigned long now = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 1027 | write_lock_bh(&idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | if (ift) { |
| 1029 | spin_lock_bh(&ift->lock); |
| 1030 | memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8); |
| 1031 | spin_unlock_bh(&ift->lock); |
| 1032 | tmpaddr = &addr; |
| 1033 | } else { |
| 1034 | tmpaddr = NULL; |
| 1035 | } |
| 1036 | retry: |
| 1037 | in6_dev_hold(idev); |
| 1038 | if (idev->cnf.use_tempaddr <= 0) { |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 1039 | write_unlock_bh(&idev->lock); |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 1040 | pr_info("%s: use_tempaddr is disabled\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | in6_dev_put(idev); |
| 1042 | ret = -1; |
| 1043 | goto out; |
| 1044 | } |
| 1045 | spin_lock_bh(&ifp->lock); |
| 1046 | if (ifp->regen_count++ >= idev->cnf.regen_max_retry) { |
| 1047 | idev->cnf.use_tempaddr = -1; /*XXX*/ |
| 1048 | spin_unlock_bh(&ifp->lock); |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 1049 | write_unlock_bh(&idev->lock); |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 1050 | pr_warn("%s: regeneration time exceeded - disabled temporary address support\n", |
| 1051 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | in6_dev_put(idev); |
| 1053 | ret = -1; |
| 1054 | goto out; |
| 1055 | } |
| 1056 | in6_ifa_hold(ifp); |
| 1057 | memcpy(addr.s6_addr, ifp->addr.s6_addr, 8); |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 1058 | __ipv6_try_regen_rndid(idev, tmpaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | memcpy(&addr.s6_addr[8], idev->rndid, 8); |
Lorenzo Colitti | 76f793e | 2011-07-26 13:50:49 +0000 | [diff] [blame] | 1060 | age = (now - ifp->tstamp) / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | tmp_valid_lft = min_t(__u32, |
| 1062 | ifp->valid_lft, |
Glenn Wurster | 7a876b0 | 2010-09-27 07:10:10 +0000 | [diff] [blame] | 1063 | idev->cnf.temp_valid_lft + age); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1064 | tmp_prefered_lft = min_t(__u32, |
| 1065 | ifp->prefered_lft, |
Glenn Wurster | 7a876b0 | 2010-09-27 07:10:10 +0000 | [diff] [blame] | 1066 | idev->cnf.temp_prefered_lft + age - |
Ben Hutchings | 784e271 | 2010-06-26 11:42:55 +0000 | [diff] [blame] | 1067 | idev->cnf.max_desync_factor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | tmp_plen = ifp->prefix_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | tmp_tstamp = ifp->tstamp; |
| 1070 | spin_unlock_bh(&ifp->lock); |
| 1071 | |
Benoit Boissinot | eac55bf | 2008-04-02 00:01:35 -0700 | [diff] [blame] | 1072 | regen_advance = idev->cnf.regen_max_retry * |
David S. Miller | 7eaa48a | 2013-08-20 23:44:39 -0700 | [diff] [blame] | 1073 | idev->cnf.dad_transmits * |
| 1074 | idev->nd_parms->retrans_time / HZ; |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 1075 | write_unlock_bh(&idev->lock); |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1076 | |
Benoit Boissinot | eac55bf | 2008-04-02 00:01:35 -0700 | [diff] [blame] | 1077 | /* A temporary address is created only if this calculated Preferred |
| 1078 | * Lifetime is greater than REGEN_ADVANCE time units. In particular, |
| 1079 | * an implementation must not create a temporary address with a zero |
| 1080 | * Preferred Lifetime. |
| 1081 | */ |
| 1082 | if (tmp_prefered_lft <= regen_advance) { |
| 1083 | in6_ifa_put(ifp); |
| 1084 | in6_dev_put(idev); |
| 1085 | ret = -1; |
| 1086 | goto out; |
| 1087 | } |
| 1088 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1089 | addr_flags = IFA_F_TEMPORARY; |
| 1090 | /* set in addrconf_prefix_rcv() */ |
| 1091 | if (ifp->flags & IFA_F_OPTIMISTIC) |
| 1092 | addr_flags |= IFA_F_OPTIMISTIC; |
| 1093 | |
Hannes Frederic Sowa | 4b08a8f | 2013-08-16 13:02:27 +0200 | [diff] [blame] | 1094 | ift = ipv6_add_addr(idev, &addr, NULL, tmp_plen, |
| 1095 | ipv6_addr_scope(&addr), addr_flags, |
| 1096 | tmp_valid_lft, tmp_prefered_lft); |
| 1097 | if (IS_ERR(ift)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | in6_ifa_put(ifp); |
| 1099 | in6_dev_put(idev); |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 1100 | pr_info("%s: retry temporary address regeneration\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | tmpaddr = &addr; |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 1102 | write_lock_bh(&idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | goto retry; |
| 1104 | } |
| 1105 | |
| 1106 | spin_lock_bh(&ift->lock); |
| 1107 | ift->ifpub = ifp; |
Lorenzo Colitti | 76f793e | 2011-07-26 13:50:49 +0000 | [diff] [blame] | 1108 | ift->cstamp = now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | ift->tstamp = tmp_tstamp; |
| 1110 | spin_unlock_bh(&ift->lock); |
| 1111 | |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 1112 | addrconf_dad_start(ift); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | in6_ifa_put(ift); |
| 1114 | in6_dev_put(idev); |
| 1115 | out: |
| 1116 | return ret; |
| 1117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
| 1119 | /* |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1120 | * Choose an appropriate source address (RFC3484) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | */ |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1122 | enum { |
| 1123 | IPV6_SADDR_RULE_INIT = 0, |
| 1124 | IPV6_SADDR_RULE_LOCAL, |
| 1125 | IPV6_SADDR_RULE_SCOPE, |
| 1126 | IPV6_SADDR_RULE_PREFERRED, |
| 1127 | #ifdef CONFIG_IPV6_MIP6 |
| 1128 | IPV6_SADDR_RULE_HOA, |
| 1129 | #endif |
| 1130 | IPV6_SADDR_RULE_OIF, |
| 1131 | IPV6_SADDR_RULE_LABEL, |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1132 | IPV6_SADDR_RULE_PRIVACY, |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1133 | IPV6_SADDR_RULE_ORCHID, |
| 1134 | IPV6_SADDR_RULE_PREFIX, |
| 1135 | IPV6_SADDR_RULE_MAX |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1136 | }; |
| 1137 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1138 | struct ipv6_saddr_score { |
| 1139 | int rule; |
| 1140 | int addr_type; |
| 1141 | struct inet6_ifaddr *ifa; |
| 1142 | DECLARE_BITMAP(scorebits, IPV6_SADDR_RULE_MAX); |
| 1143 | int scopedist; |
| 1144 | int matchlen; |
| 1145 | }; |
| 1146 | |
| 1147 | struct ipv6_saddr_dst { |
YOSHIFUJI Hideaki | 9acd9f3 | 2008-04-10 15:42:10 +0900 | [diff] [blame] | 1148 | const struct in6_addr *addr; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1149 | int ifindex; |
| 1150 | int scope; |
| 1151 | int label; |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1152 | unsigned int prefs; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1153 | }; |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1154 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 1155 | static inline int ipv6_saddr_preferred(int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
Ulrich Weber | 45bb006 | 2010-02-25 23:28:58 +0000 | [diff] [blame] | 1157 | if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|IPV6_ADDR_LOOPBACK)) |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1158 | return 1; |
| 1159 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Benjamin Thery | 3de2325 | 2008-05-28 14:51:24 +0200 | [diff] [blame] | 1162 | static int ipv6_get_saddr_eval(struct net *net, |
| 1163 | struct ipv6_saddr_score *score, |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1164 | struct ipv6_saddr_dst *dst, |
| 1165 | int i) |
| 1166 | { |
| 1167 | int ret; |
| 1168 | |
| 1169 | if (i <= score->rule) { |
| 1170 | switch (i) { |
| 1171 | case IPV6_SADDR_RULE_SCOPE: |
| 1172 | ret = score->scopedist; |
| 1173 | break; |
| 1174 | case IPV6_SADDR_RULE_PREFIX: |
| 1175 | ret = score->matchlen; |
| 1176 | break; |
| 1177 | default: |
| 1178 | ret = !!test_bit(i, score->scorebits); |
| 1179 | } |
| 1180 | goto out; |
| 1181 | } |
| 1182 | |
| 1183 | switch (i) { |
| 1184 | case IPV6_SADDR_RULE_INIT: |
| 1185 | /* Rule 0: remember if hiscore is not ready yet */ |
| 1186 | ret = !!score->ifa; |
| 1187 | break; |
| 1188 | case IPV6_SADDR_RULE_LOCAL: |
| 1189 | /* Rule 1: Prefer same address */ |
| 1190 | ret = ipv6_addr_equal(&score->ifa->addr, dst->addr); |
| 1191 | break; |
| 1192 | case IPV6_SADDR_RULE_SCOPE: |
| 1193 | /* Rule 2: Prefer appropriate scope |
| 1194 | * |
| 1195 | * ret |
| 1196 | * ^ |
| 1197 | * -1 | d 15 |
| 1198 | * ---+--+-+---> scope |
| 1199 | * | |
| 1200 | * | d is scope of the destination. |
| 1201 | * B-d | \ |
| 1202 | * | \ <- smaller scope is better if |
| 1203 | * B-15 | \ if scope is enough for destinaion. |
| 1204 | * | ret = B - scope (-1 <= scope >= d <= 15). |
| 1205 | * d-C-1 | / |
| 1206 | * |/ <- greater is better |
| 1207 | * -C / if scope is not enough for destination. |
| 1208 | * /| ret = scope - C (-1 <= d < scope <= 15). |
| 1209 | * |
| 1210 | * d - C - 1 < B -15 (for all -1 <= d <= 15). |
| 1211 | * C > d + 14 - B >= 15 + 14 - B = 29 - B. |
| 1212 | * Assume B = 0 and we get C > 29. |
| 1213 | */ |
| 1214 | ret = __ipv6_addr_src_scope(score->addr_type); |
| 1215 | if (ret >= dst->scope) |
| 1216 | ret = -ret; |
| 1217 | else |
| 1218 | ret -= 128; /* 30 is enough */ |
| 1219 | score->scopedist = ret; |
| 1220 | break; |
| 1221 | case IPV6_SADDR_RULE_PREFERRED: |
| 1222 | /* Rule 3: Avoid deprecated and optimistic addresses */ |
| 1223 | ret = ipv6_saddr_preferred(score->addr_type) || |
| 1224 | !(score->ifa->flags & (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)); |
| 1225 | break; |
| 1226 | #ifdef CONFIG_IPV6_MIP6 |
| 1227 | case IPV6_SADDR_RULE_HOA: |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1228 | { |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1229 | /* Rule 4: Prefer home address */ |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1230 | int prefhome = !(dst->prefs & IPV6_PREFER_SRC_COA); |
| 1231 | ret = !(score->ifa->flags & IFA_F_HOMEADDRESS) ^ prefhome; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1232 | break; |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1233 | } |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1234 | #endif |
| 1235 | case IPV6_SADDR_RULE_OIF: |
| 1236 | /* Rule 5: Prefer outgoing interface */ |
| 1237 | ret = (!dst->ifindex || |
| 1238 | dst->ifindex == score->ifa->idev->dev->ifindex); |
| 1239 | break; |
| 1240 | case IPV6_SADDR_RULE_LABEL: |
| 1241 | /* Rule 6: Prefer matching label */ |
Benjamin Thery | 3de2325 | 2008-05-28 14:51:24 +0200 | [diff] [blame] | 1242 | ret = ipv6_addr_label(net, |
| 1243 | &score->ifa->addr, score->addr_type, |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1244 | score->ifa->idev->dev->ifindex) == dst->label; |
| 1245 | break; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1246 | case IPV6_SADDR_RULE_PRIVACY: |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1247 | { |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1248 | /* Rule 7: Prefer public address |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1249 | * Note: prefer temporary address if use_tempaddr >= 2 |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1250 | */ |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1251 | int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ? |
| 1252 | !!(dst->prefs & IPV6_PREFER_SRC_TMP) : |
| 1253 | score->ifa->idev->cnf.use_tempaddr >= 2; |
| 1254 | ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1255 | break; |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1256 | } |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1257 | case IPV6_SADDR_RULE_ORCHID: |
| 1258 | /* Rule 8-: Prefer ORCHID vs ORCHID or |
| 1259 | * non-ORCHID vs non-ORCHID |
| 1260 | */ |
| 1261 | ret = !(ipv6_addr_orchid(&score->ifa->addr) ^ |
| 1262 | ipv6_addr_orchid(dst->addr)); |
| 1263 | break; |
| 1264 | case IPV6_SADDR_RULE_PREFIX: |
| 1265 | /* Rule 8: Use longest matching prefix */ |
YOSHIFUJI Hideaki / 吉藤英明 | 91b4b04 | 2012-09-10 18:41:07 +0000 | [diff] [blame] | 1266 | ret = ipv6_addr_diff(&score->ifa->addr, dst->addr); |
| 1267 | if (ret > score->ifa->prefix_len) |
| 1268 | ret = score->ifa->prefix_len; |
| 1269 | score->matchlen = ret; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1270 | break; |
| 1271 | default: |
| 1272 | ret = 0; |
| 1273 | } |
| 1274 | |
| 1275 | if (ret) |
| 1276 | __set_bit(i, score->scorebits); |
| 1277 | score->rule = i; |
| 1278 | out: |
| 1279 | return ret; |
| 1280 | } |
| 1281 | |
Patrick McHardy | b3f644f | 2012-08-26 19:14:14 +0200 | [diff] [blame] | 1282 | int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev, |
YOSHIFUJI Hideaki | 9acd9f3 | 2008-04-10 15:42:10 +0900 | [diff] [blame] | 1283 | const struct in6_addr *daddr, unsigned int prefs, |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1284 | struct in6_addr *saddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1286 | struct ipv6_saddr_score scores[2], |
| 1287 | *score = &scores[0], *hiscore = &scores[1]; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1288 | struct ipv6_saddr_dst dst; |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1289 | struct net_device *dev; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1290 | int dst_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1292 | dst_type = __ipv6_addr_type(daddr); |
| 1293 | dst.addr = daddr; |
| 1294 | dst.ifindex = dst_dev ? dst_dev->ifindex : 0; |
| 1295 | dst.scope = __ipv6_addr_src_scope(dst_type); |
Benjamin Thery | 3de2325 | 2008-05-28 14:51:24 +0200 | [diff] [blame] | 1296 | dst.label = ipv6_addr_label(net, daddr, dst_type, dst.ifindex); |
YOSHIFUJI Hideaki | 7cbca67 | 2008-03-25 09:37:42 +0900 | [diff] [blame] | 1297 | dst.prefs = prefs; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1298 | |
| 1299 | hiscore->rule = -1; |
| 1300 | hiscore->ifa = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1302 | rcu_read_lock(); |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1303 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 1304 | for_each_netdev_rcu(net, dev) { |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1305 | struct inet6_dev *idev; |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1306 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1307 | /* Candidate Source Address (section 4) |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1308 | * - multicast and link-local destination address, |
| 1309 | * the set of candidate source address MUST only |
| 1310 | * include addresses assigned to interfaces |
| 1311 | * belonging to the same link as the outgoing |
| 1312 | * interface. |
| 1313 | * (- For site-local destination addresses, the |
| 1314 | * set of candidate source addresses MUST only |
| 1315 | * include addresses assigned to interfaces |
| 1316 | * belonging to the same site as the outgoing |
| 1317 | * interface.) |
| 1318 | */ |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1319 | if (((dst_type & IPV6_ADDR_MULTICAST) || |
| 1320 | dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL) && |
| 1321 | dst.ifindex && dev->ifindex != dst.ifindex) |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1322 | continue; |
| 1323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | idev = __in6_dev_get(dev); |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1325 | if (!idev) |
| 1326 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1328 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 1329 | list_for_each_entry(score->ifa, &idev->addr_list, if_list) { |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1330 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1332 | /* |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 1333 | * - Tentative Address (RFC2462 section 5.4) |
| 1334 | * - A tentative address is not considered |
| 1335 | * "assigned to an interface" in the traditional |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1336 | * sense, unless it is also flagged as optimistic. |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 1337 | * - Candidate Source Address (section 4) |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1338 | * - In any case, anycast addresses, multicast |
| 1339 | * addresses, and the unspecified address MUST |
| 1340 | * NOT be included in a candidate set. |
| 1341 | */ |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1342 | if ((score->ifa->flags & IFA_F_TENTATIVE) && |
| 1343 | (!(score->ifa->flags & IFA_F_OPTIMISTIC))) |
YOSHIFUJI Hideaki | 6b3ae80 | 2005-12-21 22:58:01 +0900 | [diff] [blame] | 1344 | continue; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1345 | |
| 1346 | score->addr_type = __ipv6_addr_type(&score->ifa->addr); |
| 1347 | |
| 1348 | if (unlikely(score->addr_type == IPV6_ADDR_ANY || |
| 1349 | score->addr_type & IPV6_ADDR_MULTICAST)) { |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1350 | LIMIT_NETDEBUG(KERN_DEBUG |
Joe Perches | 3b6d821c | 2007-11-19 23:47:25 -0800 | [diff] [blame] | 1351 | "ADDRCONF: unspecified / multicast address " |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1352 | "assigned as unicast address on %s", |
| 1353 | dev->name); |
| 1354 | continue; |
| 1355 | } |
| 1356 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1357 | score->rule = -1; |
| 1358 | bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX); |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1359 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1360 | for (i = 0; i < IPV6_SADDR_RULE_MAX; i++) { |
| 1361 | int minihiscore, miniscore; |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1362 | |
Benjamin Thery | 3de2325 | 2008-05-28 14:51:24 +0200 | [diff] [blame] | 1363 | minihiscore = ipv6_get_saddr_eval(net, hiscore, &dst, i); |
| 1364 | miniscore = ipv6_get_saddr_eval(net, score, &dst, i); |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1365 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1366 | if (minihiscore > miniscore) { |
| 1367 | if (i == IPV6_SADDR_RULE_SCOPE && |
| 1368 | score->scopedist > 0) { |
| 1369 | /* |
| 1370 | * special case: |
| 1371 | * each remaining entry |
| 1372 | * has too small (not enough) |
| 1373 | * scope, because ifa entries |
| 1374 | * are sorted by their scope |
| 1375 | * values. |
| 1376 | */ |
| 1377 | goto try_nextdev; |
| 1378 | } |
| 1379 | break; |
| 1380 | } else if (minihiscore < miniscore) { |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1381 | if (hiscore->ifa) |
| 1382 | in6_ifa_put(hiscore->ifa); |
| 1383 | |
| 1384 | in6_ifa_hold(score->ifa); |
| 1385 | |
Ilpo Järvinen | a0bffff | 2009-03-21 13:36:17 -0700 | [diff] [blame] | 1386 | swap(hiscore, score); |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1387 | |
| 1388 | /* restore our iterator */ |
| 1389 | score->ifa = hiscore->ifa; |
| 1390 | |
| 1391 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
| 1393 | } |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1394 | } |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1395 | try_nextdev: |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1396 | read_unlock_bh(&idev->lock); |
| 1397 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1398 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1400 | if (!hiscore->ifa) |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1401 | return -EADDRNOTAVAIL; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1402 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 1403 | *saddr = hiscore->ifa->addr; |
YOSHIFUJI Hideaki | a9b0572 | 2008-03-02 10:48:21 +0900 | [diff] [blame] | 1404 | in6_ifa_put(hiscore->ifa); |
YOSHIFUJI Hideaki | 072047e4 | 2005-11-08 09:38:30 -0800 | [diff] [blame] | 1405 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | } |
YOSHIFUJI Hideaki | 5e5f3f0 | 2008-03-03 21:44:34 +0900 | [diff] [blame] | 1407 | EXPORT_SYMBOL(ipv6_dev_get_saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Amerigo Wang | 8965779 | 2013-06-29 21:30:49 +0800 | [diff] [blame] | 1409 | int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr, |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 1410 | u32 banned_flags) |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 1411 | { |
| 1412 | struct inet6_ifaddr *ifp; |
| 1413 | int err = -EADDRNOTAVAIL; |
| 1414 | |
| 1415 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
| 1416 | if (ifp->scope == IFA_LINK && |
| 1417 | !(ifp->flags & banned_flags)) { |
| 1418 | *addr = ifp->addr; |
| 1419 | err = 0; |
| 1420 | break; |
| 1421 | } |
| 1422 | } |
| 1423 | return err; |
| 1424 | } |
| 1425 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 1426 | int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 1427 | u32 banned_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | { |
| 1429 | struct inet6_dev *idev; |
| 1430 | int err = -EADDRNOTAVAIL; |
| 1431 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1432 | rcu_read_lock(); |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 1433 | idev = __in6_dev_get(dev); |
| 1434 | if (idev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | read_lock_bh(&idev->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 1436 | err = __ipv6_get_lladdr(idev, addr, banned_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | read_unlock_bh(&idev->lock); |
| 1438 | } |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1439 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | return err; |
| 1441 | } |
| 1442 | |
| 1443 | static int ipv6_count_addresses(struct inet6_dev *idev) |
| 1444 | { |
| 1445 | int cnt = 0; |
| 1446 | struct inet6_ifaddr *ifp; |
| 1447 | |
| 1448 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 1449 | list_for_each_entry(ifp, &idev->addr_list, if_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | cnt++; |
| 1451 | read_unlock_bh(&idev->lock); |
| 1452 | return cnt; |
| 1453 | } |
| 1454 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1455 | int ipv6_chk_addr(struct net *net, const struct in6_addr *addr, |
Florian Westphal | 2a7851b | 2013-05-17 03:56:10 +0000 | [diff] [blame] | 1456 | const struct net_device *dev, int strict) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | { |
Stephen Hemminger | eedf042 | 2010-05-17 22:27:12 -0700 | [diff] [blame] | 1458 | struct inet6_ifaddr *ifp; |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 1459 | unsigned int hash = inet6_addr_hash(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 1461 | rcu_read_lock_bh(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1462 | hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { |
YOSHIFUJI Hideaki | 878628f | 2008-03-26 03:57:35 +0900 | [diff] [blame] | 1463 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
Daniel Lezcano | bfeade0 | 2008-01-10 22:43:18 -0800 | [diff] [blame] | 1464 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | if (ipv6_addr_equal(&ifp->addr, addr) && |
Stephen Hemminger | eedf042 | 2010-05-17 22:27:12 -0700 | [diff] [blame] | 1466 | !(ifp->flags&IFA_F_TENTATIVE) && |
| 1467 | (dev == NULL || ifp->idev->dev == dev || |
| 1468 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) { |
| 1469 | rcu_read_unlock_bh(); |
| 1470 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | } |
| 1472 | } |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 1473 | |
Stephen Hemminger | eedf042 | 2010-05-17 22:27:12 -0700 | [diff] [blame] | 1474 | rcu_read_unlock_bh(); |
| 1475 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | } |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 1477 | EXPORT_SYMBOL(ipv6_chk_addr); |
| 1478 | |
David S. Miller | 3e81c6d | 2010-03-20 16:18:00 -0700 | [diff] [blame] | 1479 | static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, |
| 1480 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 1482 | unsigned int hash = inet6_addr_hash(addr); |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 1483 | struct inet6_ifaddr *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1485 | hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) { |
YOSHIFUJI Hideaki | 878628f | 2008-03-26 03:57:35 +0900 | [diff] [blame] | 1486 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
Daniel Lezcano | 06bfe65 | 2008-01-10 22:43:42 -0800 | [diff] [blame] | 1487 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
| 1489 | if (dev == NULL || ifp->idev->dev == dev) |
David S. Miller | 3e81c6d | 2010-03-20 16:18:00 -0700 | [diff] [blame] | 1490 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | } |
| 1492 | } |
David S. Miller | 3e81c6d | 2010-03-20 16:18:00 -0700 | [diff] [blame] | 1493 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Catalin\(ux\) M. BOIE | 7df37ff | 2013-09-23 23:04:19 +0300 | [diff] [blame] | 1496 | /* Compares an address/prefix_len with addresses on device @dev. |
| 1497 | * If one is found it returns true. |
| 1498 | */ |
| 1499 | bool ipv6_chk_custom_prefix(const struct in6_addr *addr, |
| 1500 | const unsigned int prefix_len, struct net_device *dev) |
| 1501 | { |
| 1502 | struct inet6_dev *idev; |
| 1503 | struct inet6_ifaddr *ifa; |
| 1504 | bool ret = false; |
| 1505 | |
| 1506 | rcu_read_lock(); |
| 1507 | idev = __in6_dev_get(dev); |
| 1508 | if (idev) { |
| 1509 | read_lock_bh(&idev->lock); |
| 1510 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 1511 | ret = ipv6_prefix_equal(addr, &ifa->addr, prefix_len); |
| 1512 | if (ret) |
| 1513 | break; |
| 1514 | } |
| 1515 | read_unlock_bh(&idev->lock); |
| 1516 | } |
| 1517 | rcu_read_unlock(); |
| 1518 | |
| 1519 | return ret; |
| 1520 | } |
| 1521 | EXPORT_SYMBOL(ipv6_chk_custom_prefix); |
| 1522 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1523 | int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev) |
YOSHIFUJI Hideaki | 52eeeb8 | 2008-03-15 22:54:23 -0400 | [diff] [blame] | 1524 | { |
| 1525 | struct inet6_dev *idev; |
| 1526 | struct inet6_ifaddr *ifa; |
| 1527 | int onlink; |
| 1528 | |
| 1529 | onlink = 0; |
| 1530 | rcu_read_lock(); |
| 1531 | idev = __in6_dev_get(dev); |
| 1532 | if (idev) { |
| 1533 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 1534 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
YOSHIFUJI Hideaki | 52eeeb8 | 2008-03-15 22:54:23 -0400 | [diff] [blame] | 1535 | onlink = ipv6_prefix_equal(addr, &ifa->addr, |
| 1536 | ifa->prefix_len); |
| 1537 | if (onlink) |
| 1538 | break; |
| 1539 | } |
| 1540 | read_unlock_bh(&idev->lock); |
| 1541 | } |
| 1542 | rcu_read_unlock(); |
| 1543 | return onlink; |
| 1544 | } |
YOSHIFUJI Hideaki | 52eeeb8 | 2008-03-15 22:54:23 -0400 | [diff] [blame] | 1545 | EXPORT_SYMBOL(ipv6_chk_prefix); |
| 1546 | |
YOSHIFUJI Hideaki | 9acd9f3 | 2008-04-10 15:42:10 +0900 | [diff] [blame] | 1547 | struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, |
Daniel Lezcano | 1cab3da | 2008-01-10 22:44:09 -0800 | [diff] [blame] | 1548 | struct net_device *dev, int strict) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | { |
David S. Miller | b79d1d5 | 2010-03-25 21:39:21 -0700 | [diff] [blame] | 1550 | struct inet6_ifaddr *ifp, *result = NULL; |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 1551 | unsigned int hash = inet6_addr_hash(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 1553 | rcu_read_lock_bh(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1554 | hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) { |
YOSHIFUJI Hideaki | 878628f | 2008-03-26 03:57:35 +0900 | [diff] [blame] | 1555 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
Daniel Lezcano | 1cab3da | 2008-01-10 22:44:09 -0800 | [diff] [blame] | 1556 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | if (ipv6_addr_equal(&ifp->addr, addr)) { |
| 1558 | if (dev == NULL || ifp->idev->dev == dev || |
| 1559 | !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { |
David S. Miller | b79d1d5 | 2010-03-25 21:39:21 -0700 | [diff] [blame] | 1560 | result = ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | in6_ifa_hold(ifp); |
| 1562 | break; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 1566 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
David S. Miller | b79d1d5 | 2010-03-25 21:39:21 -0700 | [diff] [blame] | 1568 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | /* Gets referenced address, destroys ifaddr */ |
| 1572 | |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 1573 | static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | if (ifp->flags&IFA_F_PERMANENT) { |
| 1576 | spin_lock_bh(&ifp->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 1577 | addrconf_del_dad_timer(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | ifp->flags |= IFA_F_TENTATIVE; |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 1579 | if (dad_failed) |
| 1580 | ifp->flags |= IFA_F_DADFAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | spin_unlock_bh(&ifp->lock); |
Herbert Xu | e2577a0 | 2010-03-13 12:23:29 -0800 | [diff] [blame] | 1582 | if (dad_failed) |
| 1583 | ipv6_ifa_notify(0, ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | in6_ifa_put(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } else if (ifp->flags&IFA_F_TEMPORARY) { |
| 1586 | struct inet6_ifaddr *ifpub; |
| 1587 | spin_lock_bh(&ifp->lock); |
| 1588 | ifpub = ifp->ifpub; |
| 1589 | if (ifpub) { |
| 1590 | in6_ifa_hold(ifpub); |
| 1591 | spin_unlock_bh(&ifp->lock); |
| 1592 | ipv6_create_tempaddr(ifpub, ifp); |
| 1593 | in6_ifa_put(ifpub); |
| 1594 | } else { |
| 1595 | spin_unlock_bh(&ifp->lock); |
| 1596 | } |
| 1597 | ipv6_del_addr(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | } else |
| 1599 | ipv6_del_addr(ifp); |
| 1600 | } |
| 1601 | |
Herbert Xu | f2344a1 | 2010-05-18 15:55:27 -0700 | [diff] [blame] | 1602 | static int addrconf_dad_end(struct inet6_ifaddr *ifp) |
| 1603 | { |
| 1604 | int err = -ENOENT; |
| 1605 | |
| 1606 | spin_lock(&ifp->state_lock); |
| 1607 | if (ifp->state == INET6_IFADDR_STATE_DAD) { |
| 1608 | ifp->state = INET6_IFADDR_STATE_POSTDAD; |
| 1609 | err = 0; |
| 1610 | } |
| 1611 | spin_unlock(&ifp->state_lock); |
| 1612 | |
| 1613 | return err; |
| 1614 | } |
| 1615 | |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 1616 | void addrconf_dad_failure(struct inet6_ifaddr *ifp) |
| 1617 | { |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 1618 | struct inet6_dev *idev = ifp->idev; |
Brian Haley | 9bdd8d4 | 2009-03-18 18:22:48 -0700 | [diff] [blame] | 1619 | |
Ursula Braun | 853dc2e | 2010-10-24 23:06:43 +0000 | [diff] [blame] | 1620 | if (addrconf_dad_end(ifp)) { |
| 1621 | in6_ifa_put(ifp); |
Herbert Xu | f2344a1 | 2010-05-18 15:55:27 -0700 | [diff] [blame] | 1622 | return; |
Ursula Braun | 853dc2e | 2010-10-24 23:06:43 +0000 | [diff] [blame] | 1623 | } |
Herbert Xu | f2344a1 | 2010-05-18 15:55:27 -0700 | [diff] [blame] | 1624 | |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1625 | net_info_ratelimited("%s: IPv6 duplicate address %pI6c detected!\n", |
| 1626 | ifp->idev->dev->name, &ifp->addr); |
Brian Haley | 9bdd8d4 | 2009-03-18 18:22:48 -0700 | [diff] [blame] | 1627 | |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 1628 | if (idev->cnf.accept_dad > 1 && !idev->cnf.disable_ipv6) { |
| 1629 | struct in6_addr addr; |
| 1630 | |
| 1631 | addr.s6_addr32[0] = htonl(0xfe800000); |
| 1632 | addr.s6_addr32[1] = 0; |
| 1633 | |
| 1634 | if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && |
| 1635 | ipv6_addr_equal(&ifp->addr, &addr)) { |
| 1636 | /* DAD failed for link-local based on MAC address */ |
| 1637 | idev->cnf.disable_ipv6 = 1; |
Brian Haley | 9bdd8d4 | 2009-03-18 18:22:48 -0700 | [diff] [blame] | 1638 | |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 1639 | pr_info("%s: IPv6 being disabled!\n", |
Brian Haley | 9bdd8d4 | 2009-03-18 18:22:48 -0700 | [diff] [blame] | 1640 | ifp->idev->dev->name); |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 1644 | addrconf_dad_stop(ifp, 1); |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 1645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
| 1647 | /* Join to solicited addr multicast group. */ |
| 1648 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1649 | void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | { |
| 1651 | struct in6_addr maddr; |
| 1652 | |
| 1653 | if (dev->flags&(IFF_LOOPBACK|IFF_NOARP)) |
| 1654 | return; |
| 1655 | |
| 1656 | addrconf_addr_solict_mult(addr, &maddr); |
| 1657 | ipv6_dev_mc_inc(dev, &maddr); |
| 1658 | } |
| 1659 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1660 | void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | { |
| 1662 | struct in6_addr maddr; |
| 1663 | |
| 1664 | if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP)) |
| 1665 | return; |
| 1666 | |
| 1667 | addrconf_addr_solict_mult(addr, &maddr); |
| 1668 | __ipv6_dev_mc_dec(idev, &maddr); |
| 1669 | } |
| 1670 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1671 | static void addrconf_join_anycast(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | { |
| 1673 | struct in6_addr addr; |
Bjørn Mork | 2bda8a0 | 2011-07-05 23:04:13 +0000 | [diff] [blame] | 1674 | if (ifp->prefix_len == 127) /* RFC 6164 */ |
| 1675 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); |
| 1677 | if (ipv6_addr_any(&addr)) |
| 1678 | return; |
| 1679 | ipv6_dev_ac_inc(ifp->idev->dev, &addr); |
| 1680 | } |
| 1681 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1682 | static void addrconf_leave_anycast(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | { |
| 1684 | struct in6_addr addr; |
YOSHIFUJI Hideaki | 32019e6 | 2011-07-24 11:44:34 +0000 | [diff] [blame] | 1685 | if (ifp->prefix_len == 127) /* RFC 6164 */ |
| 1686 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); |
| 1688 | if (ipv6_addr_any(&addr)) |
| 1689 | return; |
| 1690 | __ipv6_dev_ac_dec(ifp->idev, &addr); |
| 1691 | } |
| 1692 | |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1693 | static int addrconf_ifid_eui48(u8 *eui, struct net_device *dev) |
| 1694 | { |
| 1695 | if (dev->addr_len != ETH_ALEN) |
| 1696 | return -1; |
| 1697 | memcpy(eui, dev->dev_addr, 3); |
| 1698 | memcpy(eui + 5, dev->dev_addr + 3, 3); |
| 1699 | |
| 1700 | /* |
| 1701 | * The zSeries OSA network cards can be shared among various |
| 1702 | * OS instances, but the OSA cards have only one MAC address. |
| 1703 | * This leads to duplicate address conflicts in conjunction |
| 1704 | * with IPv6 if more than one instance uses the same card. |
| 1705 | * |
| 1706 | * The driver for these cards can deliver a unique 16-bit |
| 1707 | * identifier for each instance sharing the same card. It is |
| 1708 | * placed instead of 0xFFFE in the interface identifier. The |
| 1709 | * "u" bit of the interface identifier is not inverted in this |
| 1710 | * case. Hence the resulting interface identifier has local |
| 1711 | * scope according to RFC2373. |
| 1712 | */ |
| 1713 | if (dev->dev_id) { |
| 1714 | eui[3] = (dev->dev_id >> 8) & 0xFF; |
| 1715 | eui[4] = dev->dev_id & 0xFF; |
| 1716 | } else { |
| 1717 | eui[3] = 0xFF; |
| 1718 | eui[4] = 0xFE; |
| 1719 | eui[0] ^= 2; |
| 1720 | } |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
alex.bluesman.smirnov@gmail.com | 06a4c1c | 2012-05-10 03:25:52 +0000 | [diff] [blame] | 1724 | static int addrconf_ifid_eui64(u8 *eui, struct net_device *dev) |
| 1725 | { |
| 1726 | if (dev->addr_len != IEEE802154_ADDR_LEN) |
| 1727 | return -1; |
| 1728 | memcpy(eui, dev->dev_addr, 8); |
YOSHIFUJI Hideaki / 吉藤英明 | 5e98a36 | 2013-01-28 10:44:29 +0000 | [diff] [blame] | 1729 | eui[0] ^= 2; |
alex.bluesman.smirnov@gmail.com | 06a4c1c | 2012-05-10 03:25:52 +0000 | [diff] [blame] | 1730 | return 0; |
| 1731 | } |
| 1732 | |
YOSHIFUJI Hideaki / 吉藤英明 | cb6bf35 | 2013-03-25 08:26:24 +0000 | [diff] [blame] | 1733 | static int addrconf_ifid_ieee1394(u8 *eui, struct net_device *dev) |
| 1734 | { |
| 1735 | union fwnet_hwaddr *ha; |
| 1736 | |
| 1737 | if (dev->addr_len != FWNET_ALEN) |
| 1738 | return -1; |
| 1739 | |
| 1740 | ha = (union fwnet_hwaddr *)dev->dev_addr; |
| 1741 | |
| 1742 | memcpy(eui, &ha->uc.uniq_id, sizeof(ha->uc.uniq_id)); |
| 1743 | eui[0] ^= 2; |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1747 | static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev) |
| 1748 | { |
| 1749 | /* XXX: inherit EUI-64 from other interface -- yoshfuji */ |
| 1750 | if (dev->addr_len != ARCNET_ALEN) |
| 1751 | return -1; |
| 1752 | memset(eui, 0, 7); |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 1753 | eui[7] = *(u8 *)dev->dev_addr; |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev) |
| 1758 | { |
| 1759 | if (dev->addr_len != INFINIBAND_ALEN) |
| 1760 | return -1; |
| 1761 | memcpy(eui, dev->dev_addr + 12, 8); |
| 1762 | eui[0] |= 2; |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
stephen hemminger | c61393e | 2010-10-04 20:17:53 +0000 | [diff] [blame] | 1766 | static int __ipv6_isatap_ifid(u8 *eui, __be32 addr) |
YOSHIFUJI Hideaki | dfd982b | 2008-04-10 15:42:09 +0900 | [diff] [blame] | 1767 | { |
Sascha Hlusiak | 9af2851 | 2009-05-19 12:56:51 +0000 | [diff] [blame] | 1768 | if (addr == 0) |
| 1769 | return -1; |
YOSHIFUJI Hideaki | dfd982b | 2008-04-10 15:42:09 +0900 | [diff] [blame] | 1770 | eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) || |
| 1771 | ipv4_is_loopback(addr) || ipv4_is_linklocal_169(addr) || |
| 1772 | ipv4_is_private_172(addr) || ipv4_is_test_192(addr) || |
| 1773 | ipv4_is_anycast_6to4(addr) || ipv4_is_private_192(addr) || |
| 1774 | ipv4_is_test_198(addr) || ipv4_is_multicast(addr) || |
| 1775 | ipv4_is_lbcast(addr)) ? 0x00 : 0x02; |
| 1776 | eui[1] = 0; |
| 1777 | eui[2] = 0x5E; |
| 1778 | eui[3] = 0xFE; |
| 1779 | memcpy(eui + 4, &addr, 4); |
| 1780 | return 0; |
| 1781 | } |
YOSHIFUJI Hideaki | dfd982b | 2008-04-10 15:42:09 +0900 | [diff] [blame] | 1782 | |
| 1783 | static int addrconf_ifid_sit(u8 *eui, struct net_device *dev) |
| 1784 | { |
| 1785 | if (dev->priv_flags & IFF_ISATAP) |
| 1786 | return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); |
| 1787 | return -1; |
| 1788 | } |
| 1789 | |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 1790 | static int addrconf_ifid_gre(u8 *eui, struct net_device *dev) |
| 1791 | { |
| 1792 | return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); |
| 1793 | } |
| 1794 | |
Nicolas Dichtel | e837735 | 2013-08-20 12:16:06 +0200 | [diff] [blame] | 1795 | static int addrconf_ifid_ip6tnl(u8 *eui, struct net_device *dev) |
| 1796 | { |
| 1797 | memcpy(eui, dev->perm_addr, 3); |
| 1798 | memcpy(eui + 5, dev->perm_addr + 3, 3); |
| 1799 | eui[3] = 0xFF; |
| 1800 | eui[4] = 0xFE; |
| 1801 | eui[0] ^= 2; |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | static int ipv6_generate_eui64(u8 *eui, struct net_device *dev) |
| 1806 | { |
| 1807 | switch (dev->type) { |
| 1808 | case ARPHRD_ETHER: |
| 1809 | case ARPHRD_FDDI: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1810 | return addrconf_ifid_eui48(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | case ARPHRD_ARCNET: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1812 | return addrconf_ifid_arcnet(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | case ARPHRD_INFINIBAND: |
YOSHIFUJI Hideaki | 073a8e0 | 2006-03-20 16:54:49 -0800 | [diff] [blame] | 1814 | return addrconf_ifid_infiniband(eui, dev); |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 1815 | case ARPHRD_SIT: |
YOSHIFUJI Hideaki | dfd982b | 2008-04-10 15:42:09 +0900 | [diff] [blame] | 1816 | return addrconf_ifid_sit(eui, dev); |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 1817 | case ARPHRD_IPGRE: |
| 1818 | return addrconf_ifid_gre(eui, dev); |
alex.bluesman.smirnov@gmail.com | 06a4c1c | 2012-05-10 03:25:52 +0000 | [diff] [blame] | 1819 | case ARPHRD_IEEE802154: |
| 1820 | return addrconf_ifid_eui64(eui, dev); |
YOSHIFUJI Hideaki / 吉藤英明 | cb6bf35 | 2013-03-25 08:26:24 +0000 | [diff] [blame] | 1821 | case ARPHRD_IEEE1394: |
| 1822 | return addrconf_ifid_ieee1394(eui, dev); |
Nicolas Dichtel | e837735 | 2013-08-20 12:16:06 +0200 | [diff] [blame] | 1823 | case ARPHRD_TUNNEL6: |
| 1824 | return addrconf_ifid_ip6tnl(eui, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | } |
| 1826 | return -1; |
| 1827 | } |
| 1828 | |
| 1829 | static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev) |
| 1830 | { |
| 1831 | int err = -1; |
| 1832 | struct inet6_ifaddr *ifp; |
| 1833 | |
| 1834 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 1835 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { |
| 1837 | memcpy(eui, ifp->addr.s6_addr+8, 8); |
| 1838 | err = 0; |
| 1839 | break; |
| 1840 | } |
| 1841 | } |
| 1842 | read_unlock_bh(&idev->lock); |
| 1843 | return err; |
| 1844 | } |
| 1845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */ |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 1847 | static void __ipv6_regen_rndid(struct inet6_dev *idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | regen: |
YOSHIFUJI Hideaki | 955189e | 2006-03-20 16:54:09 -0800 | [diff] [blame] | 1850 | get_random_bytes(idev->rndid, sizeof(idev->rndid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | idev->rndid[0] &= ~0x02; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* |
| 1854 | * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>: |
| 1855 | * check if generated address is not inappropriate |
| 1856 | * |
| 1857 | * - Reserved subnet anycast (RFC 2526) |
| 1858 | * 11111101 11....11 1xxxxxxx |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 1859 | * - ISATAP (RFC4214) 6.1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | * 00-00-5E-FE-xx-xx-xx-xx |
| 1861 | * - value 0 |
| 1862 | * - XXX: already assigned to an address on the device |
| 1863 | */ |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1864 | if (idev->rndid[0] == 0xfd && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | (idev->rndid[1]&idev->rndid[2]&idev->rndid[3]&idev->rndid[4]&idev->rndid[5]&idev->rndid[6]) == 0xff && |
| 1866 | (idev->rndid[7]&0x80)) |
| 1867 | goto regen; |
| 1868 | if ((idev->rndid[0]|idev->rndid[1]) == 0) { |
| 1869 | if (idev->rndid[2] == 0x5e && idev->rndid[3] == 0xfe) |
| 1870 | goto regen; |
| 1871 | if ((idev->rndid[2]|idev->rndid[3]|idev->rndid[4]|idev->rndid[5]|idev->rndid[6]|idev->rndid[7]) == 0x00) |
| 1872 | goto regen; |
| 1873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | static void ipv6_regen_rndid(unsigned long data) |
| 1877 | { |
| 1878 | struct inet6_dev *idev = (struct inet6_dev *) data; |
| 1879 | unsigned long expires; |
| 1880 | |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1881 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | write_lock_bh(&idev->lock); |
| 1883 | |
| 1884 | if (idev->dead) |
| 1885 | goto out; |
| 1886 | |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 1887 | __ipv6_regen_rndid(idev); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | expires = jiffies + |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 1890 | idev->cnf.temp_prefered_lft * HZ - |
Ben Hutchings | 784e271 | 2010-06-26 11:42:55 +0000 | [diff] [blame] | 1891 | idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - |
| 1892 | idev->cnf.max_desync_factor * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | if (time_before(expires, jiffies)) { |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 1894 | pr_warn("%s: too short regeneration interval; timer disabled for %s\n", |
| 1895 | __func__, idev->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | goto out; |
| 1897 | } |
| 1898 | |
| 1899 | if (!mod_timer(&idev->regen_timer, expires)) |
| 1900 | in6_dev_hold(idev); |
| 1901 | |
| 1902 | out: |
| 1903 | write_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 1904 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | in6_dev_put(idev); |
| 1906 | } |
| 1907 | |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 1908 | static void __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr) |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 1909 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | if (tmpaddr && memcmp(idev->rndid, &tmpaddr->s6_addr[8], 8) == 0) |
Sorin Dumitru | eb7e057 | 2012-08-30 02:01:45 +0000 | [diff] [blame] | 1911 | __ipv6_regen_rndid(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
| 1914 | /* |
| 1915 | * Add prefix route. |
| 1916 | */ |
| 1917 | |
| 1918 | static void |
| 1919 | 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] | 1920 | unsigned long expires, u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1922 | struct fib6_config cfg = { |
| 1923 | .fc_table = RT6_TABLE_PREFIX, |
| 1924 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1925 | .fc_ifindex = dev->ifindex, |
| 1926 | .fc_expires = expires, |
| 1927 | .fc_dst_len = plen, |
| 1928 | .fc_flags = RTF_UP | flags, |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 1929 | .fc_nlinfo.nl_net = dev_net(dev), |
Stephen Hemminger | f410a1f | 2008-08-23 05:16:46 -0700 | [diff] [blame] | 1930 | .fc_protocol = RTPROT_KERNEL, |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1931 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | |
Alexey Dobriyan | 4e3fd7a | 2011-11-21 03:39:03 +0000 | [diff] [blame] | 1933 | cfg.fc_dst = *pfx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | |
| 1935 | /* Prevent useless cloning on PtP SIT. |
| 1936 | This thing is done here expecting that the whole |
| 1937 | class of non-broadcast devices need not cloning. |
| 1938 | */ |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 1939 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1940 | if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) |
| 1941 | cfg.fc_flags |= RTF_NONEXTHOP; |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 1942 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1944 | ip6_route_add(&cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 1947 | |
| 1948 | static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, |
| 1949 | int plen, |
| 1950 | const struct net_device *dev, |
| 1951 | u32 flags, u32 noflags) |
| 1952 | { |
| 1953 | struct fib6_node *fn; |
| 1954 | struct rt6_info *rt = NULL; |
| 1955 | struct fib6_table *table; |
| 1956 | |
| 1957 | table = fib6_get_table(dev_net(dev), RT6_TABLE_PREFIX); |
| 1958 | if (table == NULL) |
| 1959 | return NULL; |
| 1960 | |
Li RongQing | 5744dd9 | 2012-09-11 21:59:01 +0000 | [diff] [blame] | 1961 | read_lock_bh(&table->tb6_lock); |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 1962 | fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0); |
| 1963 | if (!fn) |
| 1964 | goto out; |
| 1965 | for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) { |
David S. Miller | d191854 | 2011-12-28 20:19:20 -0500 | [diff] [blame] | 1966 | if (rt->dst.dev->ifindex != dev->ifindex) |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 1967 | continue; |
| 1968 | if ((rt->rt6i_flags & flags) != flags) |
| 1969 | continue; |
Romain Kuntz | 85da53b | 2013-01-09 15:02:26 +0100 | [diff] [blame] | 1970 | if ((rt->rt6i_flags & noflags) != 0) |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 1971 | continue; |
| 1972 | dst_hold(&rt->dst); |
| 1973 | break; |
| 1974 | } |
| 1975 | out: |
Li RongQing | 5744dd9 | 2012-09-11 21:59:01 +0000 | [diff] [blame] | 1976 | read_unlock_bh(&table->tb6_lock); |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 1977 | return rt; |
| 1978 | } |
| 1979 | |
| 1980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | /* Create "default" multicast route to the interface */ |
| 1982 | |
| 1983 | static void addrconf_add_mroute(struct net_device *dev) |
| 1984 | { |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1985 | struct fib6_config cfg = { |
| 1986 | .fc_table = RT6_TABLE_LOCAL, |
| 1987 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1988 | .fc_ifindex = dev->ifindex, |
| 1989 | .fc_dst_len = 8, |
| 1990 | .fc_flags = RTF_UP, |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 1991 | .fc_nlinfo.nl_net = dev_net(dev), |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1992 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
Thomas Graf | 86872cb | 2006-08-22 00:01:08 -0700 | [diff] [blame] | 1994 | ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); |
| 1995 | |
| 1996 | ip6_route_add(&cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | static struct inet6_dev *addrconf_add_dev(struct net_device *dev) |
| 2000 | { |
| 2001 | struct inet6_dev *idev; |
| 2002 | |
| 2003 | ASSERT_RTNL(); |
| 2004 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 2005 | idev = ipv6_find_idev(dev); |
| 2006 | if (!idev) |
Brian Haley | 64e724f | 2010-07-20 10:34:30 +0000 | [diff] [blame] | 2007 | return ERR_PTR(-ENOBUFS); |
| 2008 | |
| 2009 | if (idev->cnf.disable_ipv6) |
| 2010 | return ERR_PTR(-EACCES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | |
| 2012 | /* Add default multicast route */ |
Li Wei | 4af04ab | 2011-12-06 21:23:45 +0000 | [diff] [blame] | 2013 | if (!(dev->flags & IFF_LOOPBACK)) |
| 2014 | addrconf_add_mroute(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | return idev; |
| 2017 | } |
| 2018 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 2019 | static void manage_tempaddrs(struct inet6_dev *idev, |
| 2020 | struct inet6_ifaddr *ifp, |
| 2021 | __u32 valid_lft, __u32 prefered_lft, |
| 2022 | bool create, unsigned long now) |
| 2023 | { |
| 2024 | u32 flags; |
| 2025 | struct inet6_ifaddr *ift; |
| 2026 | |
| 2027 | read_lock_bh(&idev->lock); |
| 2028 | /* update all temporary addresses in the list */ |
| 2029 | list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) { |
| 2030 | int age, max_valid, max_prefered; |
| 2031 | |
| 2032 | if (ifp != ift->ifpub) |
| 2033 | continue; |
| 2034 | |
| 2035 | /* RFC 4941 section 3.3: |
| 2036 | * If a received option will extend the lifetime of a public |
| 2037 | * address, the lifetimes of temporary addresses should |
| 2038 | * be extended, subject to the overall constraint that no |
| 2039 | * temporary addresses should ever remain "valid" or "preferred" |
| 2040 | * for a time longer than (TEMP_VALID_LIFETIME) or |
| 2041 | * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively. |
| 2042 | */ |
| 2043 | age = (now - ift->cstamp) / HZ; |
| 2044 | max_valid = idev->cnf.temp_valid_lft - age; |
| 2045 | if (max_valid < 0) |
| 2046 | max_valid = 0; |
| 2047 | |
| 2048 | max_prefered = idev->cnf.temp_prefered_lft - |
| 2049 | idev->cnf.max_desync_factor - age; |
| 2050 | if (max_prefered < 0) |
| 2051 | max_prefered = 0; |
| 2052 | |
| 2053 | if (valid_lft > max_valid) |
| 2054 | valid_lft = max_valid; |
| 2055 | |
| 2056 | if (prefered_lft > max_prefered) |
| 2057 | prefered_lft = max_prefered; |
| 2058 | |
| 2059 | spin_lock(&ift->lock); |
| 2060 | flags = ift->flags; |
| 2061 | ift->valid_lft = valid_lft; |
| 2062 | ift->prefered_lft = prefered_lft; |
| 2063 | ift->tstamp = now; |
| 2064 | if (prefered_lft > 0) |
| 2065 | ift->flags &= ~IFA_F_DEPRECATED; |
| 2066 | |
| 2067 | spin_unlock(&ift->lock); |
| 2068 | if (!(flags&IFA_F_TENTATIVE)) |
| 2069 | ipv6_ifa_notify(0, ift); |
| 2070 | } |
| 2071 | |
| 2072 | if ((create || list_empty(&idev->tempaddr_list)) && |
| 2073 | idev->cnf.use_tempaddr > 0) { |
| 2074 | /* When a new public address is created as described |
| 2075 | * in [ADDRCONF], also create a new temporary address. |
| 2076 | * Also create a temporary address if it's enabled but |
| 2077 | * no temporary address currently exists. |
| 2078 | */ |
| 2079 | read_unlock_bh(&idev->lock); |
| 2080 | ipv6_create_tempaddr(ifp, NULL); |
| 2081 | } else { |
| 2082 | read_unlock_bh(&idev->lock); |
| 2083 | } |
| 2084 | } |
| 2085 | |
Neil Horman | e6bff99 | 2012-01-04 10:49:15 +0000 | [diff] [blame] | 2086 | void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | { |
| 2088 | struct prefix_info *pinfo; |
| 2089 | __u32 valid_lft; |
| 2090 | __u32 prefered_lft; |
| 2091 | int addr_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | struct inet6_dev *in6_dev; |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 2093 | struct net *net = dev_net(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
| 2095 | pinfo = (struct prefix_info *) opt; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | if (len < sizeof(struct prefix_info)) { |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 2098 | ADBG("addrconf: prefix option too short\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | return; |
| 2100 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | /* |
| 2103 | * Validation checks ([ADDRCONF], page 19) |
| 2104 | */ |
| 2105 | |
| 2106 | addr_type = ipv6_addr_type(&pinfo->prefix); |
| 2107 | |
| 2108 | if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL)) |
| 2109 | return; |
| 2110 | |
| 2111 | valid_lft = ntohl(pinfo->valid); |
| 2112 | prefered_lft = ntohl(pinfo->prefered); |
| 2113 | |
| 2114 | if (prefered_lft > valid_lft) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2115 | net_warn_ratelimited("addrconf: prefix option has invalid lifetime\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | return; |
| 2117 | } |
| 2118 | |
| 2119 | in6_dev = in6_dev_get(dev); |
| 2120 | |
| 2121 | if (in6_dev == NULL) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2122 | net_dbg_ratelimited("addrconf: device %s not configured\n", |
| 2123 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | return; |
| 2125 | } |
| 2126 | |
| 2127 | /* |
| 2128 | * Two things going on here: |
| 2129 | * 1) Add routes for on-link prefixes |
| 2130 | * 2) Configure prefixes with the auto flag set |
| 2131 | */ |
| 2132 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2133 | if (pinfo->onlink) { |
| 2134 | struct rt6_info *rt; |
| 2135 | unsigned long rt_expires; |
| 2136 | |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2137 | /* Avoid arithmetic overflow. Really, we could |
| 2138 | * save rt_expires in seconds, likely valid_lft, |
| 2139 | * but it would require division in fib gc, that it |
| 2140 | * not good. |
| 2141 | */ |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2142 | if (HZ > USER_HZ) |
| 2143 | rt_expires = addrconf_timeout_fixup(valid_lft, HZ); |
| 2144 | else |
| 2145 | rt_expires = addrconf_timeout_fixup(valid_lft, USER_HZ); |
YOSHIFUJI Hideaki | 3dd4bc6 | 2005-12-19 14:02:45 -0800 | [diff] [blame] | 2146 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2147 | if (addrconf_finite_timeout(rt_expires)) |
| 2148 | rt_expires *= HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 2150 | rt = addrconf_get_prefix_route(&pinfo->prefix, |
| 2151 | pinfo->prefix_len, |
| 2152 | dev, |
| 2153 | RTF_ADDRCONF | RTF_PREFIX_RT, |
| 2154 | RTF_GATEWAY | RTF_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | |
Andreas Hofmeister | 14ef37b | 2011-10-26 03:24:29 +0000 | [diff] [blame] | 2156 | if (rt) { |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2157 | /* Autoconf prefix route */ |
| 2158 | if (valid_lft == 0) { |
| 2159 | ip6_del_rt(rt); |
| 2160 | rt = NULL; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2161 | } else if (addrconf_finite_timeout(rt_expires)) { |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2162 | /* not infinity */ |
Gao feng | 1716a96 | 2012-04-06 00:13:10 +0000 | [diff] [blame] | 2163 | rt6_set_expires(rt, jiffies + rt_expires); |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2164 | } else { |
Gao feng | 1716a96 | 2012-04-06 00:13:10 +0000 | [diff] [blame] | 2165 | rt6_clean_expires(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | } |
| 2167 | } else if (valid_lft) { |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2168 | clock_t expires = 0; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2169 | int flags = RTF_ADDRCONF | RTF_PREFIX_RT; |
| 2170 | if (addrconf_finite_timeout(rt_expires)) { |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2171 | /* not infinity */ |
| 2172 | flags |= RTF_EXPIRES; |
| 2173 | expires = jiffies_to_clock_t(rt_expires); |
| 2174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2176 | dev, expires, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
Amerigo Wang | 94e187c | 2012-10-29 00:13:19 +0000 | [diff] [blame] | 2178 | ip6_rt_put(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | /* Try to figure out our local address for this prefix */ |
| 2182 | |
| 2183 | if (pinfo->autoconf && in6_dev->cnf.autoconf) { |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 2184 | struct inet6_ifaddr *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | struct in6_addr addr; |
| 2186 | int create = 0, update_lft = 0; |
Daniel Borkmann | 617fe29 | 2013-04-09 03:47:16 +0000 | [diff] [blame] | 2187 | bool tokenized = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | |
| 2189 | if (pinfo->prefix_len == 64) { |
| 2190 | memcpy(&addr, &pinfo->prefix, 8); |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 2191 | |
| 2192 | if (!ipv6_addr_any(&in6_dev->token)) { |
| 2193 | read_lock_bh(&in6_dev->lock); |
| 2194 | memcpy(addr.s6_addr + 8, |
| 2195 | in6_dev->token.s6_addr + 8, 8); |
| 2196 | read_unlock_bh(&in6_dev->lock); |
Daniel Borkmann | 617fe29 | 2013-04-09 03:47:16 +0000 | [diff] [blame] | 2197 | tokenized = true; |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 2198 | } else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) && |
| 2199 | ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | in6_dev_put(in6_dev); |
| 2201 | return; |
| 2202 | } |
| 2203 | goto ok; |
| 2204 | } |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2205 | net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n", |
| 2206 | pinfo->prefix_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | in6_dev_put(in6_dev); |
| 2208 | return; |
| 2209 | |
| 2210 | ok: |
| 2211 | |
YOSHIFUJI Hideaki | 53b7997 | 2008-07-19 22:35:03 -0700 | [diff] [blame] | 2212 | ifp = ipv6_get_ifaddr(net, &addr, dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
| 2214 | if (ifp == NULL && valid_lft) { |
| 2215 | int max_addresses = in6_dev->cnf.max_addresses; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2216 | u32 addr_flags = 0; |
| 2217 | |
| 2218 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 2219 | if (in6_dev->cnf.optimistic_dad && |
Neil Horman | e6bff99 | 2012-01-04 10:49:15 +0000 | [diff] [blame] | 2220 | !net->ipv6.devconf_all->forwarding && sllao) |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2221 | addr_flags = IFA_F_OPTIMISTIC; |
| 2222 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
| 2224 | /* Do not allow to create too much of autoconfigured |
| 2225 | * addresses; this would be too easy way to crash kernel. |
| 2226 | */ |
| 2227 | if (!max_addresses || |
| 2228 | ipv6_count_addresses(in6_dev) < max_addresses) |
Jiri Pirko | 3f8f529 | 2013-08-01 10:41:27 +0200 | [diff] [blame] | 2229 | ifp = ipv6_add_addr(in6_dev, &addr, NULL, |
| 2230 | pinfo->prefix_len, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2231 | addr_type&IPV6_ADDR_SCOPE_MASK, |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2232 | addr_flags, valid_lft, |
| 2233 | prefered_lft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
YOSHIFUJI Hideaki / 吉藤英明 | 3f0d2ba | 2013-01-22 06:32:54 +0000 | [diff] [blame] | 2235 | if (IS_ERR_OR_NULL(ifp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | in6_dev_put(in6_dev); |
| 2237 | return; |
| 2238 | } |
| 2239 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 2240 | ifp->flags |= IFA_F_MANAGETEMPADDR; |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2241 | update_lft = 0; |
| 2242 | create = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | ifp->cstamp = jiffies; |
Daniel Borkmann | 617fe29 | 2013-04-09 03:47:16 +0000 | [diff] [blame] | 2244 | ifp->tokenized = tokenized; |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 2245 | addrconf_dad_start(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | if (ifp) { |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 2249 | u32 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | unsigned long now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | u32 stored_lft; |
| 2252 | |
| 2253 | /* update lifetime (RFC2462 5.5.3 e) */ |
| 2254 | spin_lock(&ifp->lock); |
| 2255 | now = jiffies; |
| 2256 | if (ifp->valid_lft > (now - ifp->tstamp) / HZ) |
| 2257 | stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; |
| 2258 | else |
| 2259 | stored_lft = 0; |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2260 | if (!update_lft && !create && stored_lft) { |
Paul Marks | c9d55d5 | 2013-09-25 15:12:55 -0700 | [diff] [blame] | 2261 | const u32 minimum_lft = min( |
| 2262 | stored_lft, (u32)MIN_VALID_LIFETIME); |
| 2263 | valid_lft = max(valid_lft, minimum_lft); |
| 2264 | |
| 2265 | /* RFC4862 Section 5.5.3e: |
| 2266 | * "Note that the preferred lifetime of the |
| 2267 | * corresponding address is always reset to |
| 2268 | * the Preferred Lifetime in the received |
| 2269 | * Prefix Information option, regardless of |
| 2270 | * whether the valid lifetime is also reset or |
| 2271 | * ignored." |
| 2272 | * |
| 2273 | * So we should always update prefered_lft here. |
| 2274 | */ |
| 2275 | update_lft = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | if (update_lft) { |
| 2279 | ifp->valid_lft = valid_lft; |
| 2280 | ifp->prefered_lft = prefered_lft; |
| 2281 | ifp->tstamp = now; |
| 2282 | flags = ifp->flags; |
| 2283 | ifp->flags &= ~IFA_F_DEPRECATED; |
| 2284 | spin_unlock(&ifp->lock); |
| 2285 | |
| 2286 | if (!(flags&IFA_F_TENTATIVE)) |
| 2287 | ipv6_ifa_notify(0, ifp); |
| 2288 | } else |
| 2289 | spin_unlock(&ifp->lock); |
| 2290 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 2291 | manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft, |
| 2292 | create, now); |
David S. Miller | 5d9efa7 | 2013-10-28 20:07:50 -0400 | [diff] [blame] | 2293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | in6_ifa_put(ifp); |
| 2295 | addrconf_verify(0); |
| 2296 | } |
| 2297 | } |
| 2298 | inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo); |
| 2299 | in6_dev_put(in6_dev); |
| 2300 | } |
| 2301 | |
| 2302 | /* |
| 2303 | * Set destination address. |
| 2304 | * Special case for SIT interfaces where we create a new "virtual" |
| 2305 | * device. |
| 2306 | */ |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2307 | int addrconf_set_dstaddr(struct net *net, void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | { |
| 2309 | struct in6_ifreq ireq; |
| 2310 | struct net_device *dev; |
| 2311 | int err = -EINVAL; |
| 2312 | |
| 2313 | rtnl_lock(); |
| 2314 | |
| 2315 | err = -EFAULT; |
| 2316 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 2317 | goto err_exit; |
| 2318 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2319 | dev = __dev_get_by_index(net, ireq.ifr6_ifindex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
| 2321 | err = -ENODEV; |
| 2322 | if (dev == NULL) |
| 2323 | goto err_exit; |
| 2324 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2325 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | if (dev->type == ARPHRD_SIT) { |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 2327 | const struct net_device_ops *ops = dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | struct ifreq ifr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | struct ip_tunnel_parm p; |
| 2330 | |
| 2331 | err = -EADDRNOTAVAIL; |
| 2332 | if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4)) |
| 2333 | goto err_exit; |
| 2334 | |
| 2335 | memset(&p, 0, sizeof(p)); |
| 2336 | p.iph.daddr = ireq.ifr6_addr.s6_addr32[3]; |
| 2337 | p.iph.saddr = 0; |
| 2338 | p.iph.version = 4; |
| 2339 | p.iph.ihl = 5; |
| 2340 | p.iph.protocol = IPPROTO_IPV6; |
| 2341 | p.iph.ttl = 64; |
Stephen Hemminger | d20b310 | 2008-01-21 00:48:43 -0800 | [diff] [blame] | 2342 | ifr.ifr_ifru.ifru_data = (__force void __user *)&p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 2344 | if (ops->ndo_do_ioctl) { |
| 2345 | mm_segment_t oldfs = get_fs(); |
| 2346 | |
| 2347 | set_fs(KERNEL_DS); |
| 2348 | err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); |
| 2349 | set_fs(oldfs); |
| 2350 | } else |
| 2351 | err = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
| 2353 | if (err == 0) { |
| 2354 | err = -ENOBUFS; |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2355 | dev = __dev_get_by_name(net, p.name); |
| 2356 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | goto err_exit; |
| 2358 | err = dev_open(dev); |
| 2359 | } |
| 2360 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2361 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | |
| 2363 | err_exit: |
| 2364 | rtnl_unlock(); |
| 2365 | return err; |
| 2366 | } |
| 2367 | |
| 2368 | /* |
| 2369 | * Manual configuration of address on an interface |
| 2370 | */ |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 2371 | static int inet6_addr_add(struct net *net, int ifindex, |
| 2372 | const struct in6_addr *pfx, |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 2373 | const struct in6_addr *peer_pfx, |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 2374 | unsigned int plen, __u32 ifa_flags, |
| 2375 | __u32 prefered_lft, __u32 valid_lft) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | { |
| 2377 | struct inet6_ifaddr *ifp; |
| 2378 | struct inet6_dev *idev; |
| 2379 | struct net_device *dev; |
| 2380 | int scope; |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2381 | u32 flags; |
| 2382 | clock_t expires; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2383 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | |
| 2385 | ASSERT_RTNL(); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2386 | |
Thomas Graf | 24ef0da | 2008-05-28 16:54:22 +0200 | [diff] [blame] | 2387 | if (plen > 128) |
| 2388 | return -EINVAL; |
| 2389 | |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 2390 | /* check the lifetime */ |
| 2391 | if (!valid_lft || prefered_lft > valid_lft) |
| 2392 | return -EINVAL; |
| 2393 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 2394 | if (ifa_flags & IFA_F_MANAGETEMPADDR && plen != 64) |
| 2395 | return -EINVAL; |
| 2396 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2397 | dev = __dev_get_by_index(net, ifindex); |
| 2398 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | return -ENODEV; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2400 | |
Brian Haley | 64e724f | 2010-07-20 10:34:30 +0000 | [diff] [blame] | 2401 | idev = addrconf_add_dev(dev); |
| 2402 | if (IS_ERR(idev)) |
| 2403 | return PTR_ERR(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | |
| 2405 | scope = ipv6_addr_scope(pfx); |
| 2406 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2407 | timeout = addrconf_timeout_fixup(valid_lft, HZ); |
| 2408 | if (addrconf_finite_timeout(timeout)) { |
| 2409 | expires = jiffies_to_clock_t(timeout * HZ); |
| 2410 | valid_lft = timeout; |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2411 | flags = RTF_EXPIRES; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2412 | } else { |
| 2413 | expires = 0; |
| 2414 | flags = 0; |
| 2415 | ifa_flags |= IFA_F_PERMANENT; |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2416 | } |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 2417 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 2418 | timeout = addrconf_timeout_fixup(prefered_lft, HZ); |
| 2419 | if (addrconf_finite_timeout(timeout)) { |
| 2420 | if (timeout == 0) |
| 2421 | ifa_flags |= IFA_F_DEPRECATED; |
| 2422 | prefered_lft = timeout; |
| 2423 | } |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 2424 | |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2425 | ifp = ipv6_add_addr(idev, pfx, peer_pfx, plen, scope, ifa_flags, |
| 2426 | valid_lft, prefered_lft); |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 2427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | if (!IS_ERR(ifp)) { |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2429 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 2430 | expires, flags); |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2431 | /* |
| 2432 | * Note that section 3.1 of RFC 4429 indicates |
| 2433 | * that the Optimistic flag should not be set for |
| 2434 | * manually configured addresses |
| 2435 | */ |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 2436 | addrconf_dad_start(ifp); |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 2437 | if (ifa_flags & IFA_F_MANAGETEMPADDR) |
| 2438 | manage_tempaddrs(idev, ifp, valid_lft, prefered_lft, |
| 2439 | true, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | in6_ifa_put(ifp); |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 2441 | addrconf_verify(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | return 0; |
| 2443 | } |
| 2444 | |
| 2445 | return PTR_ERR(ifp); |
| 2446 | } |
| 2447 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 2448 | static int inet6_addr_del(struct net *net, int ifindex, const struct in6_addr *pfx, |
Thomas Graf | 24ef0da | 2008-05-28 16:54:22 +0200 | [diff] [blame] | 2449 | unsigned int plen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | { |
| 2451 | struct inet6_ifaddr *ifp; |
| 2452 | struct inet6_dev *idev; |
| 2453 | struct net_device *dev; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2454 | |
Thomas Graf | 24ef0da | 2008-05-28 16:54:22 +0200 | [diff] [blame] | 2455 | if (plen > 128) |
| 2456 | return -EINVAL; |
| 2457 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2458 | dev = __dev_get_by_index(net, ifindex); |
| 2459 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | return -ENODEV; |
| 2461 | |
David S. Miller | 7eaa48a | 2013-08-20 23:44:39 -0700 | [diff] [blame] | 2462 | if ((idev = __in6_dev_get(dev)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | return -ENXIO; |
| 2464 | |
| 2465 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 2466 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | if (ifp->prefix_len == plen && |
| 2468 | ipv6_addr_equal(pfx, &ifp->addr)) { |
| 2469 | in6_ifa_hold(ifp); |
| 2470 | read_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | ipv6_del_addr(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | return 0; |
| 2474 | } |
| 2475 | } |
| 2476 | read_unlock_bh(&idev->lock); |
| 2477 | return -EADDRNOTAVAIL; |
| 2478 | } |
| 2479 | |
| 2480 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2481 | int addrconf_add_ifaddr(struct net *net, void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | { |
| 2483 | struct in6_ifreq ireq; |
| 2484 | int err; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2485 | |
Eric W. Biederman | af31f41 | 2012-11-16 03:03:06 +0000 | [diff] [blame] | 2486 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | return -EPERM; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 2490 | return -EFAULT; |
| 2491 | |
| 2492 | rtnl_lock(); |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 2493 | err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr, NULL, |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2494 | ireq.ifr6_prefixlen, IFA_F_PERMANENT, |
| 2495 | INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | rtnl_unlock(); |
| 2497 | return err; |
| 2498 | } |
| 2499 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2500 | int addrconf_del_ifaddr(struct net *net, void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | { |
| 2502 | struct in6_ifreq ireq; |
| 2503 | int err; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2504 | |
Eric W. Biederman | af31f41 | 2012-11-16 03:03:06 +0000 | [diff] [blame] | 2505 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | return -EPERM; |
| 2507 | |
| 2508 | if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) |
| 2509 | return -EFAULT; |
| 2510 | |
| 2511 | rtnl_lock(); |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 2512 | err = inet6_addr_del(net, ireq.ifr6_ifindex, &ireq.ifr6_addr, |
| 2513 | ireq.ifr6_prefixlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | rtnl_unlock(); |
| 2515 | return err; |
| 2516 | } |
| 2517 | |
Ilpo Järvinen | b5f348e | 2009-02-06 23:48:01 -0800 | [diff] [blame] | 2518 | static void add_addr(struct inet6_dev *idev, const struct in6_addr *addr, |
| 2519 | int plen, int scope) |
| 2520 | { |
| 2521 | struct inet6_ifaddr *ifp; |
| 2522 | |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2523 | ifp = ipv6_add_addr(idev, addr, NULL, plen, |
| 2524 | scope, IFA_F_PERMANENT, 0, 0); |
Ilpo Järvinen | b5f348e | 2009-02-06 23:48:01 -0800 | [diff] [blame] | 2525 | if (!IS_ERR(ifp)) { |
| 2526 | spin_lock_bh(&ifp->lock); |
| 2527 | ifp->flags &= ~IFA_F_TENTATIVE; |
| 2528 | spin_unlock_bh(&ifp->lock); |
| 2529 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 2530 | in6_ifa_put(ifp); |
| 2531 | } |
| 2532 | } |
| 2533 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2534 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | static void sit_add_v4_addrs(struct inet6_dev *idev) |
| 2536 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | struct in6_addr addr; |
| 2538 | struct net_device *dev; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 2539 | struct net *net = dev_net(idev->dev); |
Nicolas Dichtel | 929c9cf | 2013-11-14 13:51:05 +0100 | [diff] [blame] | 2540 | int scope, plen; |
Nicolas Dichtel | f0e2acf | 2013-11-14 13:51:06 +0100 | [diff] [blame] | 2541 | u32 pflags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | |
| 2543 | ASSERT_RTNL(); |
| 2544 | |
| 2545 | memset(&addr, 0, sizeof(struct in6_addr)); |
| 2546 | memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4); |
| 2547 | |
| 2548 | if (idev->dev->flags&IFF_POINTOPOINT) { |
| 2549 | addr.s6_addr32[0] = htonl(0xfe800000); |
| 2550 | scope = IFA_LINK; |
Nicolas Dichtel | 929c9cf | 2013-11-14 13:51:05 +0100 | [diff] [blame] | 2551 | plen = 64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | } else { |
| 2553 | scope = IPV6_ADDR_COMPATv4; |
Nicolas Dichtel | 929c9cf | 2013-11-14 13:51:05 +0100 | [diff] [blame] | 2554 | plen = 96; |
Nicolas Dichtel | f0e2acf | 2013-11-14 13:51:06 +0100 | [diff] [blame] | 2555 | pflags |= RTF_NONEXTHOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | if (addr.s6_addr32[3]) { |
Nicolas Dichtel | 929c9cf | 2013-11-14 13:51:05 +0100 | [diff] [blame] | 2559 | add_addr(idev, &addr, plen, scope); |
Nicolas Dichtel | f0e2acf | 2013-11-14 13:51:06 +0100 | [diff] [blame] | 2560 | addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | return; |
| 2562 | } |
| 2563 | |
Benjamin Thery | 6fda735 | 2008-03-05 10:47:47 -0800 | [diff] [blame] | 2564 | for_each_netdev(net, dev) { |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 2565 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | if (in_dev && (dev->flags & IFF_UP)) { |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 2567 | struct in_ifaddr *ifa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | |
| 2569 | int flag = scope; |
| 2570 | |
| 2571 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
| 2573 | addr.s6_addr32[3] = ifa->ifa_local; |
| 2574 | |
| 2575 | if (ifa->ifa_scope == RT_SCOPE_LINK) |
| 2576 | continue; |
| 2577 | if (ifa->ifa_scope >= RT_SCOPE_HOST) { |
| 2578 | if (idev->dev->flags&IFF_POINTOPOINT) |
| 2579 | continue; |
| 2580 | flag |= IFA_HOST; |
| 2581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | |
Ilpo Järvinen | b5f348e | 2009-02-06 23:48:01 -0800 | [diff] [blame] | 2583 | add_addr(idev, &addr, plen, flag); |
Nicolas Dichtel | f0e2acf | 2013-11-14 13:51:06 +0100 | [diff] [blame] | 2584 | addrconf_prefix_route(&addr, plen, idev->dev, 0, |
| 2585 | pflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } |
| 2587 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2590 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
| 2592 | static void init_loopback(struct net_device *dev) |
| 2593 | { |
| 2594 | struct inet6_dev *idev; |
Balakumaran Kannan | 25fb6ca4 | 2013-04-02 16:15:05 +0530 | [diff] [blame] | 2595 | struct net_device *sp_dev; |
| 2596 | struct inet6_ifaddr *sp_ifa; |
| 2597 | struct rt6_info *sp_rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | |
| 2599 | /* ::1 */ |
| 2600 | |
| 2601 | ASSERT_RTNL(); |
| 2602 | |
David S. Miller | 7eaa48a | 2013-08-20 23:44:39 -0700 | [diff] [blame] | 2603 | if ((idev = ipv6_find_idev(dev)) == NULL) { |
Joe Perches | 91df42b | 2012-05-15 14:11:54 +0000 | [diff] [blame] | 2604 | pr_debug("%s: add_dev failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | return; |
| 2606 | } |
| 2607 | |
Ilpo Järvinen | b5f348e | 2009-02-06 23:48:01 -0800 | [diff] [blame] | 2608 | add_addr(idev, &in6addr_loopback, 128, IFA_HOST); |
Balakumaran Kannan | 25fb6ca4 | 2013-04-02 16:15:05 +0530 | [diff] [blame] | 2609 | |
| 2610 | /* Add routes to other interface's IPv6 addresses */ |
| 2611 | for_each_netdev(dev_net(dev), sp_dev) { |
| 2612 | if (!strcmp(sp_dev->name, dev->name)) |
| 2613 | continue; |
| 2614 | |
| 2615 | idev = __in6_dev_get(sp_dev); |
| 2616 | if (!idev) |
| 2617 | continue; |
| 2618 | |
| 2619 | read_lock_bh(&idev->lock); |
| 2620 | list_for_each_entry(sp_ifa, &idev->addr_list, if_list) { |
| 2621 | |
| 2622 | if (sp_ifa->flags & (IFA_F_DADFAILED | IFA_F_TENTATIVE)) |
| 2623 | continue; |
| 2624 | |
Gao feng | a881ae1 | 2013-06-16 11:14:30 +0800 | [diff] [blame] | 2625 | if (sp_ifa->rt) |
| 2626 | continue; |
| 2627 | |
François-Xavier Le Bail | 57ec0af | 2013-12-02 11:28:49 +0100 | [diff] [blame] | 2628 | sp_rt = addrconf_dst_alloc(idev, &sp_ifa->addr, false); |
Balakumaran Kannan | 25fb6ca4 | 2013-04-02 16:15:05 +0530 | [diff] [blame] | 2629 | |
| 2630 | /* Failure cases are ignored */ |
Gao feng | 534c877 | 2013-06-02 22:16:21 +0000 | [diff] [blame] | 2631 | if (!IS_ERR(sp_rt)) { |
| 2632 | sp_ifa->rt = sp_rt; |
Balakumaran Kannan | 25fb6ca4 | 2013-04-02 16:15:05 +0530 | [diff] [blame] | 2633 | ip6_ins_rt(sp_rt); |
Gao feng | 534c877 | 2013-06-02 22:16:21 +0000 | [diff] [blame] | 2634 | } |
Balakumaran Kannan | 25fb6ca4 | 2013-04-02 16:15:05 +0530 | [diff] [blame] | 2635 | } |
| 2636 | read_unlock_bh(&idev->lock); |
| 2637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 2640 | static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | { |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 2642 | struct inet6_ifaddr *ifp; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2643 | u32 addr_flags = IFA_F_PERMANENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2645 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 2646 | if (idev->cnf.optimistic_dad && |
David Miller | 702beb8 | 2008-07-20 18:17:02 -0700 | [diff] [blame] | 2647 | !dev_net(idev->dev)->ipv6.devconf_all->forwarding) |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2648 | addr_flags |= IFA_F_OPTIMISTIC; |
| 2649 | #endif |
| 2650 | |
| 2651 | |
Jiri Benc | 8a226b2 | 2013-08-01 10:41:28 +0200 | [diff] [blame] | 2652 | ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | if (!IS_ERR(ifp)) { |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 2654 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0); |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 2655 | addrconf_dad_start(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | in6_ifa_put(ifp); |
| 2657 | } |
| 2658 | } |
| 2659 | |
| 2660 | static void addrconf_dev_config(struct net_device *dev) |
| 2661 | { |
| 2662 | struct in6_addr addr; |
Eldad Zack | 8e5e8f3 | 2012-04-01 07:49:08 +0000 | [diff] [blame] | 2663 | struct inet6_dev *idev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
| 2665 | ASSERT_RTNL(); |
| 2666 | |
Herbert Xu | 74235a2 | 2007-06-14 13:02:55 -0700 | [diff] [blame] | 2667 | if ((dev->type != ARPHRD_ETHER) && |
| 2668 | (dev->type != ARPHRD_FDDI) && |
Herbert Xu | 74235a2 | 2007-06-14 13:02:55 -0700 | [diff] [blame] | 2669 | (dev->type != ARPHRD_ARCNET) && |
alex.bluesman.smirnov@gmail.com | 06a4c1c | 2012-05-10 03:25:52 +0000 | [diff] [blame] | 2670 | (dev->type != ARPHRD_INFINIBAND) && |
YOSHIFUJI Hideaki / 吉藤英明 | cb6bf35 | 2013-03-25 08:26:24 +0000 | [diff] [blame] | 2671 | (dev->type != ARPHRD_IEEE802154) && |
Nicolas Dichtel | e837735 | 2013-08-20 12:16:06 +0200 | [diff] [blame] | 2672 | (dev->type != ARPHRD_IEEE1394) && |
| 2673 | (dev->type != ARPHRD_TUNNEL6)) { |
Herbert Xu | 74235a2 | 2007-06-14 13:02:55 -0700 | [diff] [blame] | 2674 | /* Alas, we support only Ethernet autoconfiguration. */ |
| 2675 | return; |
| 2676 | } |
| 2677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | idev = addrconf_add_dev(dev); |
Brian Haley | 64e724f | 2010-07-20 10:34:30 +0000 | [diff] [blame] | 2679 | if (IS_ERR(idev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | return; |
| 2681 | |
| 2682 | memset(&addr, 0, sizeof(struct in6_addr)); |
| 2683 | addr.s6_addr32[0] = htonl(0xFE800000); |
| 2684 | |
| 2685 | if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0) |
| 2686 | addrconf_add_linklocal(idev, &addr); |
| 2687 | } |
| 2688 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2689 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | static void addrconf_sit_config(struct net_device *dev) |
| 2691 | { |
| 2692 | struct inet6_dev *idev; |
| 2693 | |
| 2694 | ASSERT_RTNL(); |
| 2695 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2696 | /* |
| 2697 | * Configure the tunnel with one of our IPv4 |
| 2698 | * addresses... we should configure all of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | * our v4 addrs in the tunnel |
| 2700 | */ |
| 2701 | |
David S. Miller | 7eaa48a | 2013-08-20 23:44:39 -0700 | [diff] [blame] | 2702 | if ((idev = ipv6_find_idev(dev)) == NULL) { |
Joe Perches | 91df42b | 2012-05-15 14:11:54 +0000 | [diff] [blame] | 2703 | pr_debug("%s: add_dev failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | return; |
| 2705 | } |
| 2706 | |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 2707 | if (dev->priv_flags & IFF_ISATAP) { |
| 2708 | struct in6_addr addr; |
| 2709 | |
| 2710 | ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); |
Fred L. Templin | c7dc89c | 2007-11-29 22:11:40 +1100 | [diff] [blame] | 2711 | if (!ipv6_generate_eui64(addr.s6_addr + 8, dev)) |
| 2712 | addrconf_add_linklocal(idev, &addr); |
| 2713 | return; |
| 2714 | } |
| 2715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | sit_add_v4_addrs(idev); |
| 2717 | |
Nicolas Dichtel | 62b54dd | 2012-10-01 23:19:14 +0000 | [diff] [blame] | 2718 | if (dev->flags&IFF_POINTOPOINT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | addrconf_add_mroute(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | } |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2721 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2723 | #if IS_ENABLED(CONFIG_NET_IPGRE) |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 2724 | static void addrconf_gre_config(struct net_device *dev) |
| 2725 | { |
| 2726 | struct inet6_dev *idev; |
| 2727 | struct in6_addr addr; |
| 2728 | |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 2729 | ASSERT_RTNL(); |
| 2730 | |
David S. Miller | 7eaa48a | 2013-08-20 23:44:39 -0700 | [diff] [blame] | 2731 | if ((idev = ipv6_find_idev(dev)) == NULL) { |
Joe Perches | 91df42b | 2012-05-15 14:11:54 +0000 | [diff] [blame] | 2732 | pr_debug("%s: add_dev failed\n", __func__); |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 2733 | return; |
| 2734 | } |
| 2735 | |
| 2736 | ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 2737 | if (!ipv6_generate_eui64(addr.s6_addr + 8, dev)) |
| 2738 | addrconf_add_linklocal(idev, &addr); |
| 2739 | } |
| 2740 | #endif |
| 2741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | static inline int |
| 2743 | ipv6_inherit_linklocal(struct inet6_dev *idev, struct net_device *link_dev) |
| 2744 | { |
| 2745 | struct in6_addr lladdr; |
| 2746 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 2747 | if (!ipv6_get_lladdr(link_dev, &lladdr, IFA_F_TENTATIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | addrconf_add_linklocal(idev, &lladdr); |
| 2749 | return 0; |
| 2750 | } |
| 2751 | return -1; |
| 2752 | } |
| 2753 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 2754 | static int addrconf_notify(struct notifier_block *this, unsigned long event, |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 2755 | void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 2757 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Eric Dumazet | 748e2d9 | 2012-08-22 21:50:59 +0000 | [diff] [blame] | 2758 | struct inet6_dev *idev = __in6_dev_get(dev); |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2759 | int run_pending = 0; |
Herbert Xu | b217d61 | 2007-07-30 17:04:52 -0700 | [diff] [blame] | 2760 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 2762 | switch (event) { |
YOSHIFUJI Hideaki | 45ba9dd | 2007-02-15 02:07:27 +0900 | [diff] [blame] | 2763 | case NETDEV_REGISTER: |
Herbert Xu | 74235a2 | 2007-06-14 13:02:55 -0700 | [diff] [blame] | 2764 | if (!idev && dev->mtu >= IPV6_MIN_MTU) { |
YOSHIFUJI Hideaki | 45ba9dd | 2007-02-15 02:07:27 +0900 | [diff] [blame] | 2765 | idev = ipv6_add_dev(dev); |
| 2766 | if (!idev) |
Herbert Xu | b217d61 | 2007-07-30 17:04:52 -0700 | [diff] [blame] | 2767 | return notifier_from_errno(-ENOMEM); |
YOSHIFUJI Hideaki | 45ba9dd | 2007-02-15 02:07:27 +0900 | [diff] [blame] | 2768 | } |
| 2769 | break; |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | case NETDEV_UP: |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2772 | case NETDEV_CHANGE: |
Jay Vosburgh | c2edacf | 2007-07-09 10:42:47 -0700 | [diff] [blame] | 2773 | if (dev->flags & IFF_SLAVE) |
| 2774 | break; |
| 2775 | |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2776 | if (event == NETDEV_UP) { |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 2777 | if (!addrconf_qdisc_ok(dev)) { |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2778 | /* device is not ready yet. */ |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 2779 | pr_info("ADDRCONF(NETDEV_UP): %s: link is not ready\n", |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2780 | dev->name); |
| 2781 | break; |
| 2782 | } |
Kristian Slavov | 9908104 | 2006-02-08 16:10:53 -0800 | [diff] [blame] | 2783 | |
Evgeniy Polyakov | d31c7b8 | 2007-11-30 23:36:08 +1100 | [diff] [blame] | 2784 | if (!idev && dev->mtu >= IPV6_MIN_MTU) |
| 2785 | idev = ipv6_add_dev(dev); |
| 2786 | |
Benjamin Thery | e3ec6cf | 2008-11-05 01:43:57 -0800 | [diff] [blame] | 2787 | if (idev) { |
Kristian Slavov | 9908104 | 2006-02-08 16:10:53 -0800 | [diff] [blame] | 2788 | idev->if_flags |= IF_READY; |
Benjamin Thery | e3ec6cf | 2008-11-05 01:43:57 -0800 | [diff] [blame] | 2789 | run_pending = 1; |
| 2790 | } |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2791 | } else { |
Mitsuru Chinen | f24e3d6 | 2007-10-10 02:53:43 -0700 | [diff] [blame] | 2792 | if (!addrconf_qdisc_ok(dev)) { |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2793 | /* device is still not ready. */ |
| 2794 | break; |
| 2795 | } |
| 2796 | |
| 2797 | if (idev) { |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2798 | if (idev->if_flags & IF_READY) |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2799 | /* device is already configured. */ |
| 2800 | break; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2801 | idev->if_flags |= IF_READY; |
| 2802 | } |
| 2803 | |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 2804 | pr_info("ADDRCONF(NETDEV_CHANGE): %s: link becomes ready\n", |
| 2805 | dev->name); |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2806 | |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2807 | run_pending = 1; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2808 | } |
| 2809 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 2810 | switch (dev->type) { |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2811 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | case ARPHRD_SIT: |
| 2813 | addrconf_sit_config(dev); |
| 2814 | break; |
Joerg Roedel | 0be669b | 2006-10-10 14:49:53 -0700 | [diff] [blame] | 2815 | #endif |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 2816 | #if IS_ENABLED(CONFIG_NET_IPGRE) |
stephen hemminger | aee80b5 | 2011-06-08 10:44:30 +0000 | [diff] [blame] | 2817 | case ARPHRD_IPGRE: |
| 2818 | addrconf_gre_config(dev); |
| 2819 | break; |
| 2820 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | case ARPHRD_LOOPBACK: |
| 2822 | init_loopback(dev); |
| 2823 | break; |
| 2824 | |
| 2825 | default: |
| 2826 | addrconf_dev_config(dev); |
| 2827 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2828 | } |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | if (idev) { |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 2831 | if (run_pending) |
| 2832 | addrconf_dad_run(idev); |
| 2833 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2834 | /* |
| 2835 | * If the MTU changed during the interface down, |
| 2836 | * when the interface up, the changed MTU must be |
| 2837 | * reflected in the idev as well as routers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | */ |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2839 | if (idev->cnf.mtu6 != dev->mtu && |
| 2840 | dev->mtu >= IPV6_MIN_MTU) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | rt6_mtu_change(dev, dev->mtu); |
| 2842 | idev->cnf.mtu6 = dev->mtu; |
| 2843 | } |
| 2844 | idev->tstamp = jiffies; |
| 2845 | inet6_ifinfo_notify(RTM_NEWLINK, idev); |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2846 | |
| 2847 | /* |
| 2848 | * If the changed mtu during down is lower than |
| 2849 | * IPV6_MIN_MTU stop IPv6 on this interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | */ |
| 2851 | if (dev->mtu < IPV6_MIN_MTU) |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2852 | addrconf_ifdown(dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | } |
| 2854 | break; |
| 2855 | |
| 2856 | case NETDEV_CHANGEMTU: |
Evgeniy Polyakov | d31c7b8 | 2007-11-30 23:36:08 +1100 | [diff] [blame] | 2857 | if (idev && dev->mtu >= IPV6_MIN_MTU) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | rt6_mtu_change(dev, dev->mtu); |
| 2859 | idev->cnf.mtu6 = dev->mtu; |
| 2860 | break; |
| 2861 | } |
| 2862 | |
Evgeniy Polyakov | d31c7b8 | 2007-11-30 23:36:08 +1100 | [diff] [blame] | 2863 | if (!idev && dev->mtu >= IPV6_MIN_MTU) { |
| 2864 | idev = ipv6_add_dev(dev); |
| 2865 | if (idev) |
| 2866 | break; |
| 2867 | } |
| 2868 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2869 | /* |
| 2870 | * MTU falled under IPV6_MIN_MTU. |
| 2871 | * Stop IPv6 on this interface. |
| 2872 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | |
| 2874 | case NETDEV_DOWN: |
| 2875 | case NETDEV_UNREGISTER: |
| 2876 | /* |
| 2877 | * Remove all addresses from this interface. |
| 2878 | */ |
| 2879 | addrconf_ifdown(dev, event != NETDEV_DOWN); |
| 2880 | break; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | case NETDEV_CHANGENAME: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | if (idev) { |
Stephen Hemminger | 5632c51 | 2007-04-28 21:16:39 -0700 | [diff] [blame] | 2884 | snmp6_unregister_dev(idev); |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 2885 | addrconf_sysctl_unregister(idev); |
Pavel Emelyanov | f52295a | 2007-12-02 00:58:37 +1100 | [diff] [blame] | 2886 | addrconf_sysctl_register(idev); |
Herbert Xu | b217d61 | 2007-07-30 17:04:52 -0700 | [diff] [blame] | 2887 | err = snmp6_register_dev(idev); |
| 2888 | if (err) |
| 2889 | return notifier_from_errno(err); |
Stephen Hemminger | 5632c51 | 2007-04-28 21:16:39 -0700 | [diff] [blame] | 2890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | break; |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2892 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 2893 | case NETDEV_PRE_TYPE_CHANGE: |
| 2894 | case NETDEV_POST_TYPE_CHANGE: |
| 2895 | addrconf_type_change(dev, event); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 2896 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
| 2899 | return NOTIFY_OK; |
| 2900 | } |
| 2901 | |
| 2902 | /* |
| 2903 | * addrconf module should be notified of a device going up |
| 2904 | */ |
| 2905 | static struct notifier_block ipv6_dev_notf = { |
| 2906 | .notifier_call = addrconf_notify, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | }; |
| 2908 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 2909 | static void addrconf_type_change(struct net_device *dev, unsigned long event) |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 2910 | { |
| 2911 | struct inet6_dev *idev; |
| 2912 | ASSERT_RTNL(); |
| 2913 | |
| 2914 | idev = __in6_dev_get(dev); |
| 2915 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 2916 | if (event == NETDEV_POST_TYPE_CHANGE) |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 2917 | ipv6_mc_remap(idev); |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 2918 | else if (event == NETDEV_PRE_TYPE_CHANGE) |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 2919 | ipv6_mc_unmap(idev); |
| 2920 | } |
| 2921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | static int addrconf_ifdown(struct net_device *dev, int how) |
| 2923 | { |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 2924 | struct net *net = dev_net(dev); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 2925 | struct inet6_dev *idev; |
| 2926 | struct inet6_ifaddr *ifa; |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2927 | int state, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
| 2929 | ASSERT_RTNL(); |
| 2930 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2931 | rt6_ifdown(net, dev); |
| 2932 | neigh_ifdown(&nd_tbl, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
| 2934 | idev = __in6_dev_get(dev); |
| 2935 | if (idev == NULL) |
| 2936 | return -ENODEV; |
| 2937 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2938 | /* |
| 2939 | * Step 1: remove reference to ipv6 device from parent device. |
| 2940 | * Do not dev_put! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | */ |
Denis V. Lunev | 439e238 | 2008-04-03 13:30:17 -0700 | [diff] [blame] | 2942 | if (how) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | idev->dead = 1; |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 2944 | |
| 2945 | /* protected by rtnl_lock */ |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 2946 | RCU_INIT_POINTER(dev->ip6_ptr, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
| 2948 | /* Step 1.5: remove snmp6 entry */ |
| 2949 | snmp6_unregister_dev(idev); |
| 2950 | |
| 2951 | } |
| 2952 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2953 | /* Step 2: clear hash table */ |
| 2954 | for (i = 0; i < IN6_ADDR_HSIZE; i++) { |
| 2955 | struct hlist_head *h = &inet6_addr_lst[i]; |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2956 | |
| 2957 | spin_lock_bh(&addrconf_hash_lock); |
| 2958 | restart: |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2959 | hlist_for_each_entry_rcu(ifa, h, addr_lst) { |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2960 | if (ifa->idev == idev) { |
| 2961 | hlist_del_init_rcu(&ifa->addr_lst); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 2962 | addrconf_del_dad_timer(ifa); |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 2963 | goto restart; |
| 2964 | } |
| 2965 | } |
| 2966 | spin_unlock_bh(&addrconf_hash_lock); |
| 2967 | } |
| 2968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | write_lock_bh(&idev->lock); |
| 2970 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 2971 | addrconf_del_rs_timer(idev); |
| 2972 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2973 | /* Step 2: clear flags for stateless addrconf */ |
Denis V. Lunev | 439e238 | 2008-04-03 13:30:17 -0700 | [diff] [blame] | 2974 | if (!how) |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 2975 | idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | |
Denis V. Lunev | 439e238 | 2008-04-03 13:30:17 -0700 | [diff] [blame] | 2977 | if (how && del_timer(&idev->regen_timer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | in6_dev_put(idev); |
| 2979 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 2980 | /* Step 3: clear tempaddr list */ |
stephen hemminger | 372e6c8 | 2010-03-17 20:31:09 +0000 | [diff] [blame] | 2981 | while (!list_empty(&idev->tempaddr_list)) { |
| 2982 | ifa = list_first_entry(&idev->tempaddr_list, |
| 2983 | struct inet6_ifaddr, tmp_list); |
| 2984 | list_del(&ifa->tmp_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | write_unlock_bh(&idev->lock); |
| 2986 | spin_lock_bh(&ifa->lock); |
| 2987 | |
| 2988 | if (ifa->ifpub) { |
| 2989 | in6_ifa_put(ifa->ifpub); |
| 2990 | ifa->ifpub = NULL; |
| 2991 | } |
| 2992 | spin_unlock_bh(&ifa->lock); |
| 2993 | in6_ifa_put(ifa); |
| 2994 | write_lock_bh(&idev->lock); |
| 2995 | } |
stephen hemminger | 8f37ada | 2010-03-03 08:19:59 +0000 | [diff] [blame] | 2996 | |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 2997 | while (!list_empty(&idev->addr_list)) { |
| 2998 | ifa = list_first_entry(&idev->addr_list, |
| 2999 | struct inet6_ifaddr, if_list); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3000 | addrconf_del_dad_timer(ifa); |
stephen hemminger | 84e8b80 | 2010-03-02 13:32:46 +0000 | [diff] [blame] | 3001 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3002 | list_del(&ifa->if_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3004 | write_unlock_bh(&idev->lock); |
stephen hemminger | 84e8b80 | 2010-03-02 13:32:46 +0000 | [diff] [blame] | 3005 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3006 | spin_lock_bh(&ifa->state_lock); |
| 3007 | state = ifa->state; |
| 3008 | ifa->state = INET6_IFADDR_STATE_DEAD; |
| 3009 | spin_unlock_bh(&ifa->state_lock); |
stephen hemminger | 84e8b80 | 2010-03-02 13:32:46 +0000 | [diff] [blame] | 3010 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3011 | if (state != INET6_IFADDR_STATE_DEAD) { |
| 3012 | __ipv6_ifa_notify(RTM_DELADDR, ifa); |
Cong Wang | f88c91d | 2013-04-14 23:18:43 +0800 | [diff] [blame] | 3013 | inet6addr_notifier_call_chain(NETDEV_DOWN, ifa); |
stephen hemminger | 27bdb2a | 2010-04-12 05:41:32 +0000 | [diff] [blame] | 3014 | } |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3015 | in6_ifa_put(ifa); |
stephen hemminger | 8f37ada | 2010-03-03 08:19:59 +0000 | [diff] [blame] | 3016 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 3017 | write_lock_bh(&idev->lock); |
| 3018 | } |
stephen hemminger | 8f37ada | 2010-03-03 08:19:59 +0000 | [diff] [blame] | 3019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | write_unlock_bh(&idev->lock); |
| 3021 | |
| 3022 | /* Step 5: Discard multicast list */ |
Denis V. Lunev | 439e238 | 2008-04-03 13:30:17 -0700 | [diff] [blame] | 3023 | if (how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | ipv6_mc_destroy_dev(idev); |
| 3025 | else |
| 3026 | ipv6_mc_down(idev); |
| 3027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | idev->tstamp = jiffies; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3029 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 3030 | /* Last: Shot the device (if unregistered) */ |
Denis V. Lunev | 439e238 | 2008-04-03 13:30:17 -0700 | [diff] [blame] | 3031 | if (how) { |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 3032 | addrconf_sysctl_unregister(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | neigh_parms_release(&nd_tbl, idev->nd_parms); |
| 3034 | neigh_ifdown(&nd_tbl, dev); |
| 3035 | in6_dev_put(idev); |
| 3036 | } |
| 3037 | return 0; |
| 3038 | } |
| 3039 | |
| 3040 | static void addrconf_rs_timer(unsigned long data) |
| 3041 | { |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3042 | struct inet6_dev *idev = (struct inet6_dev *)data; |
Cong Wang | caf92bc | 2013-08-31 13:44:32 +0800 | [diff] [blame] | 3043 | struct net_device *dev = idev->dev; |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3044 | struct in6_addr lladdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3046 | write_lock(&idev->lock); |
stephen hemminger | 5b2a195 | 2010-03-02 13:32:45 +0000 | [diff] [blame] | 3047 | if (idev->dead || !(idev->if_flags & IF_READY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | goto out; |
| 3049 | |
Shmulik Ladkani | 9ba2add | 2012-12-02 01:44:53 +0000 | [diff] [blame] | 3050 | if (!ipv6_accept_ra(idev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | goto out; |
stephen hemminger | 5b2a195 | 2010-03-02 13:32:45 +0000 | [diff] [blame] | 3052 | |
| 3053 | /* Announcement received after solicitation was sent */ |
| 3054 | if (idev->if_flags & IF_RA_RCVD) |
| 3055 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3057 | if (idev->rs_probes++ < idev->cnf.rtr_solicits) { |
Cong Wang | caf92bc | 2013-08-31 13:44:32 +0800 | [diff] [blame] | 3058 | write_unlock(&idev->lock); |
| 3059 | if (!ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE)) |
| 3060 | ndisc_send_rs(dev, &lladdr, |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3061 | &in6addr_linklocal_allrouters); |
| 3062 | else |
Cong Wang | caf92bc | 2013-08-31 13:44:32 +0800 | [diff] [blame] | 3063 | goto put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
Cong Wang | caf92bc | 2013-08-31 13:44:32 +0800 | [diff] [blame] | 3065 | write_lock(&idev->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3066 | /* The wait after the last probe can be shorter */ |
| 3067 | addrconf_mod_rs_timer(idev, (idev->rs_probes == |
| 3068 | idev->cnf.rtr_solicits) ? |
| 3069 | idev->cnf.rtr_solicit_delay : |
| 3070 | idev->cnf.rtr_solicit_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | /* |
| 3073 | * Note: we do not support deprecated "all on-link" |
| 3074 | * assumption any longer. |
| 3075 | */ |
Joe Perches | 91df42b | 2012-05-15 14:11:54 +0000 | [diff] [blame] | 3076 | pr_debug("%s: no IPv6 routers present\n", idev->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | out: |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3080 | write_unlock(&idev->lock); |
Cong Wang | caf92bc | 2013-08-31 13:44:32 +0800 | [diff] [blame] | 3081 | put: |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3082 | in6_dev_put(idev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | /* |
| 3086 | * Duplicate Address Detection |
| 3087 | */ |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 3088 | static void addrconf_dad_kick(struct inet6_ifaddr *ifp) |
| 3089 | { |
| 3090 | unsigned long rand_num; |
| 3091 | struct inet6_dev *idev = ifp->idev; |
| 3092 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3093 | if (ifp->flags & IFA_F_OPTIMISTIC) |
| 3094 | rand_num = 0; |
| 3095 | else |
| 3096 | rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1); |
| 3097 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3098 | ifp->dad_probes = idev->cnf.dad_transmits; |
| 3099 | addrconf_mod_dad_timer(ifp, rand_num); |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 3100 | } |
| 3101 | |
David S. Miller | cf22f9a | 2012-04-14 21:37:40 -0400 | [diff] [blame] | 3102 | static void addrconf_dad_start(struct inet6_ifaddr *ifp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | { |
| 3104 | struct inet6_dev *idev = ifp->idev; |
| 3105 | struct net_device *dev = idev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | |
| 3107 | addrconf_join_solict(dev, &ifp->addr); |
| 3108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | net_srandom(ifp->addr.s6_addr32[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | |
| 3111 | read_lock_bh(&idev->lock); |
Herbert Xu | 622ccdf | 2010-05-18 15:56:06 -0700 | [diff] [blame] | 3112 | spin_lock(&ifp->lock); |
Herbert Xu | e9d3e08 | 2010-05-18 15:36:06 -0700 | [diff] [blame] | 3113 | if (ifp->state == INET6_IFADDR_STATE_DEAD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | |
| 3116 | if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 3117 | idev->cnf.accept_dad < 1 || |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3118 | !(ifp->flags&IFA_F_TENTATIVE) || |
| 3119 | ifp->flags & IFA_F_NODAD) { |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 3120 | ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3121 | spin_unlock(&ifp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | read_unlock_bh(&idev->lock); |
| 3123 | |
| 3124 | addrconf_dad_completed(ifp); |
| 3125 | return; |
| 3126 | } |
| 3127 | |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 3128 | if (!(idev->if_flags & IF_READY)) { |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3129 | spin_unlock(&ifp->lock); |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 3130 | read_unlock_bh(&idev->lock); |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 3131 | /* |
Masatake YAMATO | 590a988 | 2009-06-09 10:41:12 +0900 | [diff] [blame] | 3132 | * If the device is not ready: |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 3133 | * - keep it tentative if it is a permanent address. |
| 3134 | * - otherwise, kill it. |
| 3135 | */ |
| 3136 | in6_ifa_hold(ifp); |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 3137 | addrconf_dad_stop(ifp, 0); |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 3138 | return; |
YOSHIFUJI Hideaki | 3c21edb | 2005-12-21 22:57:24 +0900 | [diff] [blame] | 3139 | } |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3140 | |
| 3141 | /* |
| 3142 | * Optimistic nodes can start receiving |
| 3143 | * Frames right away |
| 3144 | */ |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 3145 | if (ifp->flags & IFA_F_OPTIMISTIC) |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 3146 | ip6_ins_rt(ifp->rt); |
| 3147 | |
YOSHIFUJI Hideaki | 6732bad | 2005-12-27 13:35:15 -0800 | [diff] [blame] | 3148 | addrconf_dad_kick(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | out: |
Herbert Xu | 622ccdf | 2010-05-18 15:56:06 -0700 | [diff] [blame] | 3150 | spin_unlock(&ifp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | read_unlock_bh(&idev->lock); |
| 3152 | } |
| 3153 | |
| 3154 | static void addrconf_dad_timer(unsigned long data) |
| 3155 | { |
| 3156 | struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; |
| 3157 | struct inet6_dev *idev = ifp->idev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | struct in6_addr mcaddr; |
| 3159 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3160 | if (!ifp->dad_probes && addrconf_dad_end(ifp)) |
Herbert Xu | f2344a1 | 2010-05-18 15:55:27 -0700 | [diff] [blame] | 3161 | goto out; |
| 3162 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3163 | write_lock(&idev->lock); |
stephen hemminger | 122e451 | 2010-03-02 13:32:44 +0000 | [diff] [blame] | 3164 | if (idev->dead || !(idev->if_flags & IF_READY)) { |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3165 | write_unlock(&idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | goto out; |
| 3167 | } |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3168 | |
| 3169 | spin_lock(&ifp->lock); |
Herbert Xu | 622ccdf | 2010-05-18 15:56:06 -0700 | [diff] [blame] | 3170 | if (ifp->state == INET6_IFADDR_STATE_DEAD) { |
| 3171 | spin_unlock(&ifp->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3172 | write_unlock(&idev->lock); |
Herbert Xu | 622ccdf | 2010-05-18 15:56:06 -0700 | [diff] [blame] | 3173 | goto out; |
| 3174 | } |
| 3175 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3176 | if (ifp->dad_probes == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | /* |
| 3178 | * DAD was successful |
| 3179 | */ |
| 3180 | |
Brian Haley | cc411d0 | 2009-09-09 14:41:32 +0000 | [diff] [blame] | 3181 | ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3182 | spin_unlock(&ifp->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3183 | write_unlock(&idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | |
| 3185 | addrconf_dad_completed(ifp); |
| 3186 | |
| 3187 | goto out; |
| 3188 | } |
| 3189 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3190 | ifp->dad_probes--; |
| 3191 | addrconf_mod_dad_timer(ifp, ifp->idev->nd_parms->retrans_time); |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3192 | spin_unlock(&ifp->lock); |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3193 | write_unlock(&idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | |
| 3195 | /* send a neighbour solicitation for our addr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | addrconf_addr_solict_mult(&ifp->addr, &mcaddr); |
YOSHIFUJI Hideaki | d7aabf2 | 2008-04-10 15:42:11 +0900 | [diff] [blame] | 3197 | ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | out: |
| 3199 | in6_ifa_put(ifp); |
| 3200 | } |
| 3201 | |
| 3202 | static void addrconf_dad_completed(struct inet6_ifaddr *ifp) |
| 3203 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 3204 | struct net_device *dev = ifp->idev->dev; |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3205 | struct in6_addr lladdr; |
Hannes Frederic Sowa | b173ee4 | 2013-06-27 00:07:01 +0200 | [diff] [blame] | 3206 | bool send_rs, send_mld; |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3207 | |
| 3208 | addrconf_del_dad_timer(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | |
| 3210 | /* |
| 3211 | * Configure the address for reception. Now it is valid. |
| 3212 | */ |
| 3213 | |
| 3214 | ipv6_ifa_notify(RTM_NEWADDR, ifp); |
| 3215 | |
Tore Anderson | 026359b | 2011-08-28 23:47:33 +0000 | [diff] [blame] | 3216 | /* If added prefix is link local and we are prepared to process |
| 3217 | router advertisements, start sending router solicitations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | */ |
| 3219 | |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3220 | read_lock_bh(&ifp->idev->lock); |
| 3221 | spin_lock(&ifp->lock); |
Hannes Frederic Sowa | b173ee4 | 2013-06-27 00:07:01 +0200 | [diff] [blame] | 3222 | send_mld = ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL && |
| 3223 | ifp->idev->valid_ll_addr_cnt == 1; |
| 3224 | send_rs = send_mld && |
| 3225 | ipv6_accept_ra(ifp->idev) && |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3226 | ifp->idev->cnf.rtr_solicits > 0 && |
Hannes Frederic Sowa | b173ee4 | 2013-06-27 00:07:01 +0200 | [diff] [blame] | 3227 | (dev->flags&IFF_LOOPBACK) == 0; |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3228 | spin_unlock(&ifp->lock); |
| 3229 | read_unlock_bh(&ifp->idev->lock); |
| 3230 | |
Hannes Frederic Sowa | b173ee4 | 2013-06-27 00:07:01 +0200 | [diff] [blame] | 3231 | /* While dad is in progress mld report's source address is in6_addrany. |
| 3232 | * Resend with proper ll now. |
| 3233 | */ |
| 3234 | if (send_mld) |
| 3235 | ipv6_mc_dad_complete(ifp->idev); |
| 3236 | |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3237 | if (send_rs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | /* |
| 3239 | * If a host as already performed a random delay |
| 3240 | * [...] as part of DAD [...] there is no need |
| 3241 | * to delay again before sending the first RS |
| 3242 | */ |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3243 | if (ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE)) |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3244 | return; |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 3245 | ndisc_send_rs(dev, &lladdr, &in6addr_linklocal_allrouters); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3247 | write_lock_bh(&ifp->idev->lock); |
| 3248 | spin_lock(&ifp->lock); |
| 3249 | ifp->idev->rs_probes = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | ifp->idev->if_flags |= IF_RS_SENT; |
Hannes Frederic Sowa | b7b1bfc | 2013-06-23 18:39:01 +0200 | [diff] [blame] | 3251 | addrconf_mod_rs_timer(ifp->idev, |
| 3252 | ifp->idev->cnf.rtr_solicit_interval); |
| 3253 | spin_unlock(&ifp->lock); |
| 3254 | write_unlock_bh(&ifp->idev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | } |
| 3256 | } |
| 3257 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 3258 | static void addrconf_dad_run(struct inet6_dev *idev) |
| 3259 | { |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 3260 | struct inet6_ifaddr *ifp; |
| 3261 | |
| 3262 | read_lock_bh(&idev->lock); |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 3263 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3264 | spin_lock(&ifp->lock); |
Herbert Xu | f2344a1 | 2010-05-18 15:55:27 -0700 | [diff] [blame] | 3265 | if (ifp->flags & IFA_F_TENTATIVE && |
| 3266 | ifp->state == INET6_IFADDR_STATE_DAD) |
| 3267 | addrconf_dad_kick(ifp); |
stephen hemminger | 21809fa | 2010-02-08 19:48:52 +0000 | [diff] [blame] | 3268 | spin_unlock(&ifp->lock); |
YOSHIFUJI Hideaki | c5e33bd | 2005-12-21 22:57:44 +0900 | [diff] [blame] | 3269 | } |
| 3270 | read_unlock_bh(&idev->lock); |
| 3271 | } |
| 3272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | #ifdef CONFIG_PROC_FS |
| 3274 | struct if6_iter_state { |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3275 | struct seq_net_private p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | int bucket; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3277 | int offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | }; |
| 3279 | |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3280 | static struct inet6_ifaddr *if6_get_first(struct seq_file *seq, loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | { |
| 3282 | struct inet6_ifaddr *ifa = NULL; |
| 3283 | struct if6_iter_state *state = seq->private; |
YOSHIFUJI Hideaki | 1218854 | 2008-03-26 02:36:06 +0900 | [diff] [blame] | 3284 | struct net *net = seq_file_net(seq); |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3285 | int p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3287 | /* initial bucket if pos is 0 */ |
| 3288 | if (pos == 0) { |
| 3289 | state->bucket = 0; |
| 3290 | state->offset = 0; |
| 3291 | } |
| 3292 | |
| 3293 | for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3294 | hlist_for_each_entry_rcu_bh(ifa, &inet6_addr_lst[state->bucket], |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3295 | addr_lst) { |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3296 | if (!net_eq(dev_net(ifa->idev->dev), net)) |
| 3297 | continue; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3298 | /* sync with offset */ |
| 3299 | if (p < state->offset) { |
| 3300 | p++; |
| 3301 | continue; |
| 3302 | } |
| 3303 | state->offset++; |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3304 | return ifa; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | /* prepare for next bucket */ |
| 3308 | state->offset = 0; |
| 3309 | p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3311 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3314 | static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, |
| 3315 | struct inet6_ifaddr *ifa) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | { |
| 3317 | struct if6_iter_state *state = seq->private; |
YOSHIFUJI Hideaki | 1218854 | 2008-03-26 02:36:06 +0900 | [diff] [blame] | 3318 | struct net *net = seq_file_net(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3320 | hlist_for_each_entry_continue_rcu_bh(ifa, addr_lst) { |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3321 | if (!net_eq(dev_net(ifa->idev->dev), net)) |
| 3322 | continue; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3323 | state->offset++; |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3324 | return ifa; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3325 | } |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3326 | |
| 3327 | while (++state->bucket < IN6_ADDR_HSIZE) { |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3328 | state->offset = 0; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3329 | hlist_for_each_entry_rcu_bh(ifa, |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3330 | &inet6_addr_lst[state->bucket], addr_lst) { |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3331 | if (!net_eq(dev_net(ifa->idev->dev), net)) |
| 3332 | continue; |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3333 | state->offset++; |
Eric Dumazet | 9f0d3c2 | 2012-10-16 07:37:27 +0000 | [diff] [blame] | 3334 | return ifa; |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3338 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | static void *if6_seq_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 4f70ecc | 2010-05-03 10:50:14 +0000 | [diff] [blame] | 3342 | __acquires(rcu_bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | { |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3344 | rcu_read_lock_bh(); |
Mihai Maruseac | 1d57830 | 2012-01-03 23:31:35 +0000 | [diff] [blame] | 3345 | return if6_get_first(seq, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 3349 | { |
| 3350 | struct inet6_ifaddr *ifa; |
| 3351 | |
| 3352 | ifa = if6_get_next(seq, v); |
| 3353 | ++*pos; |
| 3354 | return ifa; |
| 3355 | } |
| 3356 | |
| 3357 | static void if6_seq_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 4f70ecc | 2010-05-03 10:50:14 +0000 | [diff] [blame] | 3358 | __releases(rcu_bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | { |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3360 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | static int if6_seq_show(struct seq_file *seq, void *v) |
| 3364 | { |
| 3365 | struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v; |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3366 | seq_printf(seq, "%pi6 %02x %02x %02x %03x %8s\n", |
Harvey Harrison | b071195 | 2008-10-28 16:05:40 -0700 | [diff] [blame] | 3367 | &ifp->addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | ifp->idev->dev->ifindex, |
| 3369 | ifp->prefix_len, |
| 3370 | ifp->scope, |
| 3371 | ifp->flags, |
| 3372 | ifp->idev->dev->name); |
| 3373 | return 0; |
| 3374 | } |
| 3375 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 3376 | static const struct seq_operations if6_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | .start = if6_seq_start, |
| 3378 | .next = if6_seq_next, |
| 3379 | .show = if6_seq_show, |
| 3380 | .stop = if6_seq_stop, |
| 3381 | }; |
| 3382 | |
| 3383 | static int if6_seq_open(struct inode *inode, struct file *file) |
| 3384 | { |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3385 | return seq_open_net(inode, file, &if6_seq_ops, |
| 3386 | sizeof(struct if6_iter_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 3389 | static const struct file_operations if6_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | .owner = THIS_MODULE, |
| 3391 | .open = if6_seq_open, |
| 3392 | .read = seq_read, |
| 3393 | .llseek = seq_lseek, |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3394 | .release = seq_release_net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | }; |
| 3396 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3397 | static int __net_init if6_proc_net_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | { |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 3399 | if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | return -ENOMEM; |
| 3401 | return 0; |
| 3402 | } |
| 3403 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3404 | static void __net_exit if6_proc_net_exit(struct net *net) |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3405 | { |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 3406 | remove_proc_entry("if_inet6", net->proc_net); |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | static struct pernet_operations if6_proc_net_ops = { |
| 3410 | .init = if6_proc_net_init, |
| 3411 | .exit = if6_proc_net_exit, |
| 3412 | }; |
| 3413 | |
| 3414 | int __init if6_proc_init(void) |
| 3415 | { |
| 3416 | return register_pernet_subsys(&if6_proc_net_ops); |
| 3417 | } |
| 3418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | void if6_proc_exit(void) |
| 3420 | { |
Daniel Lezcano | 3c40090 | 2008-01-10 22:42:49 -0800 | [diff] [blame] | 3421 | unregister_pernet_subsys(&if6_proc_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | } |
| 3423 | #endif /* CONFIG_PROC_FS */ |
| 3424 | |
Amerigo Wang | 07a9362 | 2012-10-29 16:23:10 +0000 | [diff] [blame] | 3425 | #if IS_ENABLED(CONFIG_IPV6_MIP6) |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 3426 | /* Check if address is a home address configured on any interface. */ |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 3427 | int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr) |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 3428 | { |
| 3429 | int ret = 0; |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3430 | struct inet6_ifaddr *ifp = NULL; |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 3431 | unsigned int hash = inet6_addr_hash(addr); |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 3432 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3433 | rcu_read_lock_bh(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3434 | hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) { |
YOSHIFUJI Hideaki | 878628f | 2008-03-26 03:57:35 +0900 | [diff] [blame] | 3435 | if (!net_eq(dev_net(ifp->idev->dev), net)) |
Daniel Lezcano | 389f661 | 2008-01-10 22:44:40 -0800 | [diff] [blame] | 3436 | continue; |
YOSHIFUJI Hideaki | caad295 | 2008-04-10 15:42:07 +0900 | [diff] [blame] | 3437 | if (ipv6_addr_equal(&ifp->addr, addr) && |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 3438 | (ifp->flags & IFA_F_HOMEADDRESS)) { |
| 3439 | ret = 1; |
| 3440 | break; |
| 3441 | } |
| 3442 | } |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3443 | rcu_read_unlock_bh(); |
Noriaki TAKAMIYA | 3b9f9a1 | 2006-09-22 14:45:56 -0700 | [diff] [blame] | 3444 | return ret; |
| 3445 | } |
| 3446 | #endif |
| 3447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | /* |
| 3449 | * Periodic address status verification |
| 3450 | */ |
| 3451 | |
| 3452 | static void addrconf_verify(unsigned long foo) |
| 3453 | { |
YOSHIFUJI Hideaki | b2db756 | 2010-03-20 16:11:12 -0700 | [diff] [blame] | 3454 | unsigned long now, next, next_sec, next_sched; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | struct inet6_ifaddr *ifp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | int i; |
| 3457 | |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3458 | rcu_read_lock_bh(); |
| 3459 | spin_lock(&addrconf_verify_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | now = jiffies; |
YOSHIFUJI Hideaki | b2db756 | 2010-03-20 16:11:12 -0700 | [diff] [blame] | 3461 | next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | |
| 3463 | del_timer(&addr_chk_timer); |
| 3464 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 3465 | for (i = 0; i < IN6_ADDR_HSIZE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | restart: |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3467 | hlist_for_each_entry_rcu_bh(ifp, |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3468 | &inet6_addr_lst[i], addr_lst) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | unsigned long age; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | |
| 3471 | if (ifp->flags & IFA_F_PERMANENT) |
| 3472 | continue; |
| 3473 | |
| 3474 | spin_lock(&ifp->lock); |
YOSHIFUJI Hideaki | b2db756 | 2010-03-20 16:11:12 -0700 | [diff] [blame] | 3475 | /* We try to batch several events at once. */ |
| 3476 | age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | |
YOSHIFUJI Hideaki | 8f27ebb | 2006-07-28 18:12:11 +0900 | [diff] [blame] | 3478 | if (ifp->valid_lft != INFINITY_LIFE_TIME && |
| 3479 | age >= ifp->valid_lft) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | spin_unlock(&ifp->lock); |
| 3481 | in6_ifa_hold(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | ipv6_del_addr(ifp); |
| 3483 | goto restart; |
YOSHIFUJI Hideaki | 8f27ebb | 2006-07-28 18:12:11 +0900 | [diff] [blame] | 3484 | } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { |
| 3485 | spin_unlock(&ifp->lock); |
| 3486 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | } else if (age >= ifp->prefered_lft) { |
Brian Haley | a1ed052 | 2009-07-02 07:10:52 +0000 | [diff] [blame] | 3488 | /* jiffies - ifp->tstamp > age >= ifp->prefered_lft */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | int deprecate = 0; |
| 3490 | |
| 3491 | if (!(ifp->flags&IFA_F_DEPRECATED)) { |
| 3492 | deprecate = 1; |
| 3493 | ifp->flags |= IFA_F_DEPRECATED; |
| 3494 | } |
| 3495 | |
| 3496 | if (time_before(ifp->tstamp + ifp->valid_lft * HZ, next)) |
| 3497 | next = ifp->tstamp + ifp->valid_lft * HZ; |
| 3498 | |
| 3499 | spin_unlock(&ifp->lock); |
| 3500 | |
| 3501 | if (deprecate) { |
| 3502 | in6_ifa_hold(ifp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | |
| 3504 | ipv6_ifa_notify(0, ifp); |
| 3505 | in6_ifa_put(ifp); |
| 3506 | goto restart; |
| 3507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | } else if ((ifp->flags&IFA_F_TEMPORARY) && |
| 3509 | !(ifp->flags&IFA_F_TENTATIVE)) { |
stephen hemminger | 88949cf | 2010-03-17 20:31:17 +0000 | [diff] [blame] | 3510 | unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * |
| 3511 | ifp->idev->cnf.dad_transmits * |
| 3512 | ifp->idev->nd_parms->retrans_time / HZ; |
| 3513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | if (age >= ifp->prefered_lft - regen_advance) { |
| 3515 | struct inet6_ifaddr *ifpub = ifp->ifpub; |
| 3516 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) |
| 3517 | next = ifp->tstamp + ifp->prefered_lft * HZ; |
| 3518 | if (!ifp->regen_count && ifpub) { |
| 3519 | ifp->regen_count++; |
| 3520 | in6_ifa_hold(ifp); |
| 3521 | in6_ifa_hold(ifpub); |
| 3522 | spin_unlock(&ifp->lock); |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3523 | |
Hiroyuki YAMAMORI | 291d809 | 2005-12-23 11:24:05 -0800 | [diff] [blame] | 3524 | spin_lock(&ifpub->lock); |
| 3525 | ifpub->regen_count = 0; |
| 3526 | spin_unlock(&ifpub->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | ipv6_create_tempaddr(ifpub, ifp); |
| 3528 | in6_ifa_put(ifpub); |
| 3529 | in6_ifa_put(ifp); |
| 3530 | goto restart; |
| 3531 | } |
| 3532 | } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next)) |
| 3533 | next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ; |
| 3534 | spin_unlock(&ifp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | } else { |
| 3536 | /* ifp->prefered_lft <= ifp->valid_lft */ |
| 3537 | if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) |
| 3538 | next = ifp->tstamp + ifp->prefered_lft * HZ; |
| 3539 | spin_unlock(&ifp->lock); |
| 3540 | } |
| 3541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
YOSHIFUJI Hideaki | b2db756 | 2010-03-20 16:11:12 -0700 | [diff] [blame] | 3544 | next_sec = round_jiffies_up(next); |
| 3545 | next_sched = next; |
| 3546 | |
| 3547 | /* If rounded timeout is accurate enough, accept it. */ |
| 3548 | if (time_before(next_sec, next + ADDRCONF_TIMER_FUZZ)) |
| 3549 | next_sched = next_sec; |
| 3550 | |
| 3551 | /* And minimum interval is ADDRCONF_TIMER_FUZZ_MAX. */ |
| 3552 | if (time_before(next_sched, jiffies + ADDRCONF_TIMER_FUZZ_MAX)) |
| 3553 | next_sched = jiffies + ADDRCONF_TIMER_FUZZ_MAX; |
| 3554 | |
dingtianhong | ba3542e | 2013-08-17 10:27:04 +0800 | [diff] [blame] | 3555 | ADBG(KERN_DEBUG "now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n", |
| 3556 | now, next, next_sec, next_sched); |
YOSHIFUJI Hideaki | b2db756 | 2010-03-20 16:11:12 -0700 | [diff] [blame] | 3557 | |
| 3558 | addr_chk_timer.expires = next_sched; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | add_timer(&addr_chk_timer); |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 3560 | spin_unlock(&addrconf_verify_lock); |
| 3561 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3564 | static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local, |
| 3565 | struct in6_addr **peer_pfx) |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3566 | { |
| 3567 | struct in6_addr *pfx = NULL; |
| 3568 | |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3569 | *peer_pfx = NULL; |
| 3570 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3571 | if (addr) |
| 3572 | pfx = nla_data(addr); |
| 3573 | |
| 3574 | if (local) { |
| 3575 | if (pfx && nla_memcmp(local, pfx, sizeof(*pfx))) |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3576 | *peer_pfx = pfx; |
| 3577 | pfx = nla_data(local); |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | return pfx; |
| 3581 | } |
| 3582 | |
Patrick McHardy | ef7c79e | 2007-06-05 12:38:30 -0700 | [diff] [blame] | 3583 | static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = { |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3584 | [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) }, |
| 3585 | [IFA_LOCAL] = { .len = sizeof(struct in6_addr) }, |
| 3586 | [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3587 | [IFA_FLAGS] = { .len = sizeof(u32) }, |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3588 | }; |
| 3589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | static int |
Thomas Graf | 661d296 | 2013-03-21 07:45:29 +0000 | [diff] [blame] | 3591 | inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 3593 | struct net *net = sock_net(skb->sk); |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 3594 | struct ifaddrmsg *ifm; |
| 3595 | struct nlattr *tb[IFA_MAX+1]; |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3596 | struct in6_addr *pfx, *peer_pfx; |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 3597 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | |
Thomas Graf | b933f71 | 2006-09-18 00:10:19 -0700 | [diff] [blame] | 3599 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 3600 | if (err < 0) |
| 3601 | return err; |
| 3602 | |
| 3603 | ifm = nlmsg_data(nlh); |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3604 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | if (pfx == NULL) |
| 3606 | return -EINVAL; |
| 3607 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 3608 | return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3611 | static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags, |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3612 | u32 prefered_lft, u32 valid_lft) |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3613 | { |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 3614 | u32 flags; |
| 3615 | clock_t expires; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 3616 | unsigned long timeout; |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 3617 | bool was_managetempaddr; |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 3618 | |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3619 | if (!valid_lft || (prefered_lft > valid_lft)) |
| 3620 | return -EINVAL; |
| 3621 | |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 3622 | if (ifa_flags & IFA_F_MANAGETEMPADDR && |
| 3623 | (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64)) |
| 3624 | return -EINVAL; |
| 3625 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 3626 | timeout = addrconf_timeout_fixup(valid_lft, HZ); |
| 3627 | if (addrconf_finite_timeout(timeout)) { |
| 3628 | expires = jiffies_to_clock_t(timeout * HZ); |
| 3629 | valid_lft = timeout; |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 3630 | flags = RTF_EXPIRES; |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 3631 | } else { |
| 3632 | expires = 0; |
| 3633 | flags = 0; |
| 3634 | ifa_flags |= IFA_F_PERMANENT; |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 3635 | } |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3636 | |
YOSHIFUJI Hideaki | 4bed72e | 2008-05-27 17:37:49 +0900 | [diff] [blame] | 3637 | timeout = addrconf_timeout_fixup(prefered_lft, HZ); |
| 3638 | if (addrconf_finite_timeout(timeout)) { |
| 3639 | if (timeout == 0) |
| 3640 | ifa_flags |= IFA_F_DEPRECATED; |
| 3641 | prefered_lft = timeout; |
| 3642 | } |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3643 | |
| 3644 | spin_lock_bh(&ifp->lock); |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 3645 | was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR; |
| 3646 | ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | |
| 3647 | IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR); |
| 3648 | ifp->flags |= ifa_flags; |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3649 | ifp->tstamp = jiffies; |
| 3650 | ifp->valid_lft = valid_lft; |
| 3651 | ifp->prefered_lft = prefered_lft; |
| 3652 | |
| 3653 | spin_unlock_bh(&ifp->lock); |
| 3654 | if (!(ifp->flags&IFA_F_TENTATIVE)) |
| 3655 | ipv6_ifa_notify(0, ifp); |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3656 | |
YOSHIFUJI Hideaki | 46d4804 | 2007-02-07 20:36:26 +0900 | [diff] [blame] | 3657 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev, |
YOSHIFUJI Hideaki | 6f70499 | 2008-05-19 16:56:11 -0700 | [diff] [blame] | 3658 | expires, flags); |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 3659 | |
| 3660 | if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) { |
| 3661 | if (was_managetempaddr && !(ifp->flags & IFA_F_MANAGETEMPADDR)) |
| 3662 | valid_lft = prefered_lft = 0; |
| 3663 | manage_tempaddrs(ifp->idev, ifp, valid_lft, prefered_lft, |
| 3664 | !was_managetempaddr, jiffies); |
| 3665 | } |
| 3666 | |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3667 | addrconf_verify(0); |
| 3668 | |
| 3669 | return 0; |
| 3670 | } |
| 3671 | |
| 3672 | static int |
Thomas Graf | 661d296 | 2013-03-21 07:45:29 +0000 | [diff] [blame] | 3673 | inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 3675 | struct net *net = sock_net(skb->sk); |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3676 | struct ifaddrmsg *ifm; |
| 3677 | struct nlattr *tb[IFA_MAX+1]; |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3678 | struct in6_addr *pfx, *peer_pfx; |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3679 | struct inet6_ifaddr *ifa; |
| 3680 | struct net_device *dev; |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3681 | u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME; |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3682 | u32 ifa_flags; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3683 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3685 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 3686 | if (err < 0) |
| 3687 | return err; |
| 3688 | |
| 3689 | ifm = nlmsg_data(nlh); |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3690 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | if (pfx == NULL) |
| 3692 | return -EINVAL; |
| 3693 | |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3694 | if (tb[IFA_CACHEINFO]) { |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3695 | struct ifa_cacheinfo *ci; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3696 | |
| 3697 | ci = nla_data(tb[IFA_CACHEINFO]); |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3698 | valid_lft = ci->ifa_valid; |
Thomas Graf | 461d883 | 2006-09-18 00:09:49 -0700 | [diff] [blame] | 3699 | preferred_lft = ci->ifa_prefered; |
| 3700 | } else { |
| 3701 | preferred_lft = INFINITY_LIFE_TIME; |
| 3702 | valid_lft = INFINITY_LIFE_TIME; |
Noriaki TAKAMIYA | 0778769d | 2006-07-28 18:12:10 +0900 | [diff] [blame] | 3703 | } |
| 3704 | |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 3705 | dev = __dev_get_by_index(net, ifm->ifa_index); |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3706 | if (dev == NULL) |
| 3707 | return -ENODEV; |
| 3708 | |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3709 | ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags; |
| 3710 | |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3711 | /* We ignore other flags so far. */ |
Jiri Pirko | 53bd674 | 2013-12-06 09:45:22 +0100 | [diff] [blame^] | 3712 | ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR; |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3713 | |
Daniel Lezcano | 1cab3da | 2008-01-10 22:44:09 -0800 | [diff] [blame] | 3714 | ifa = ipv6_get_ifaddr(net, pfx, dev, 1); |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3715 | if (ifa == NULL) { |
| 3716 | /* |
| 3717 | * It would be best to check for !NLM_F_CREATE here but |
| 3718 | * userspace alreay relies on not having to provide this. |
| 3719 | */ |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3720 | return inet6_addr_add(net, ifm->ifa_index, pfx, peer_pfx, |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 3721 | ifm->ifa_prefixlen, ifa_flags, |
| 3722 | preferred_lft, valid_lft); |
Noriaki TAKAMIYA | 081bba5 | 2006-07-28 18:12:13 +0900 | [diff] [blame] | 3723 | } |
| 3724 | |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3725 | if (nlh->nlmsg_flags & NLM_F_EXCL || |
| 3726 | !(nlh->nlmsg_flags & NLM_F_REPLACE)) |
| 3727 | err = -EEXIST; |
| 3728 | else |
Noriaki TAKAMIYA | 55ebaef | 2006-09-22 14:45:27 -0700 | [diff] [blame] | 3729 | err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft); |
Thomas Graf | 7198f8c | 2006-09-18 00:13:46 -0700 | [diff] [blame] | 3730 | |
| 3731 | in6_ifa_put(ifa); |
| 3732 | |
| 3733 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3736 | static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u32 flags, |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3737 | u8 scope, int ifindex) |
| 3738 | { |
| 3739 | struct ifaddrmsg *ifm; |
| 3740 | |
| 3741 | ifm = nlmsg_data(nlh); |
| 3742 | ifm->ifa_family = AF_INET6; |
| 3743 | ifm->ifa_prefixlen = prefixlen; |
| 3744 | ifm->ifa_flags = flags; |
| 3745 | ifm->ifa_scope = scope; |
| 3746 | ifm->ifa_index = ifindex; |
| 3747 | } |
| 3748 | |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3749 | static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp, |
| 3750 | unsigned long tstamp, u32 preferred, u32 valid) |
| 3751 | { |
| 3752 | struct ifa_cacheinfo ci; |
| 3753 | |
Thomas Graf | 18a31e1 | 2010-11-17 04:12:02 +0000 | [diff] [blame] | 3754 | ci.cstamp = cstamp_delta(cstamp); |
| 3755 | ci.tstamp = cstamp_delta(tstamp); |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3756 | ci.ifa_prefered = preferred; |
| 3757 | ci.ifa_valid = valid; |
| 3758 | |
| 3759 | return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci); |
| 3760 | } |
| 3761 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3762 | static inline int rt_scope(int ifa_scope) |
| 3763 | { |
| 3764 | if (ifa_scope & IFA_HOST) |
| 3765 | return RT_SCOPE_HOST; |
| 3766 | else if (ifa_scope & IFA_LINK) |
| 3767 | return RT_SCOPE_LINK; |
| 3768 | else if (ifa_scope & IFA_SITE) |
| 3769 | return RT_SCOPE_SITE; |
| 3770 | else |
| 3771 | return RT_SCOPE_UNIVERSE; |
| 3772 | } |
| 3773 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3774 | static inline int inet6_ifaddr_msgsize(void) |
| 3775 | { |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3776 | return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3777 | + nla_total_size(16) /* IFA_LOCAL */ |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 3778 | + nla_total_size(16) /* IFA_ADDRESS */ |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3779 | + nla_total_size(sizeof(struct ifa_cacheinfo)) |
| 3780 | + nla_total_size(4) /* IFA_FLAGS */; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3781 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 3782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3784 | u32 portid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | struct nlmsghdr *nlh; |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3787 | u32 preferred, valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3789 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3790 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3791 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3792 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3793 | put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope), |
| 3794 | ifa->idev->dev->ifindex); |
| 3795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | if (!(ifa->flags&IFA_F_PERMANENT)) { |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3797 | preferred = ifa->prefered_lft; |
| 3798 | valid = ifa->valid_lft; |
| 3799 | if (preferred != INFINITY_LIFE_TIME) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | long tval = (jiffies - ifa->tstamp)/HZ; |
Jens Rosenboom | a1faa69 | 2009-06-25 04:55:50 +0000 | [diff] [blame] | 3801 | if (preferred > tval) |
| 3802 | preferred -= tval; |
| 3803 | else |
| 3804 | preferred = 0; |
Ben Hutchings | f56619f | 2010-06-26 11:37:47 +0000 | [diff] [blame] | 3805 | if (valid != INFINITY_LIFE_TIME) { |
| 3806 | if (valid > tval) |
| 3807 | valid -= tval; |
| 3808 | else |
| 3809 | valid = 0; |
| 3810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } |
| 3812 | } else { |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3813 | preferred = INFINITY_LIFE_TIME; |
| 3814 | valid = INFINITY_LIFE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3816 | |
Cong Wang | 7996c79 | 2013-05-22 05:41:06 +0000 | [diff] [blame] | 3817 | if (!ipv6_addr_any(&ifa->peer_addr)) { |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3818 | if (nla_put(skb, IFA_LOCAL, 16, &ifa->addr) < 0 || |
| 3819 | nla_put(skb, IFA_ADDRESS, 16, &ifa->peer_addr) < 0) |
| 3820 | goto error; |
| 3821 | } else |
| 3822 | if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0) |
| 3823 | goto error; |
| 3824 | |
| 3825 | if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) |
| 3826 | goto error; |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3827 | |
Jiri Pirko | 479840f | 2013-12-06 09:45:21 +0100 | [diff] [blame] | 3828 | if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0) |
| 3829 | goto error; |
| 3830 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3831 | return nlmsg_end(skb, nlh); |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 3832 | |
| 3833 | error: |
| 3834 | nlmsg_cancel(skb, nlh); |
| 3835 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3839 | u32 portid, u32 seq, int event, u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | struct nlmsghdr *nlh; |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3842 | u8 scope = RT_SCOPE_UNIVERSE; |
| 3843 | int ifindex = ifmca->idev->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3845 | if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) |
| 3846 | scope = RT_SCOPE_SITE; |
| 3847 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3848 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3849 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3850 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3851 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3852 | put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3853 | if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 || |
| 3854 | put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3855 | INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { |
| 3856 | nlmsg_cancel(skb, nlh); |
| 3857 | return -EMSGSIZE; |
| 3858 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3859 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3860 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3864 | u32 portid, u32 seq, int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | struct nlmsghdr *nlh; |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3867 | u8 scope = RT_SCOPE_UNIVERSE; |
| 3868 | int ifindex = ifaca->aca_idev->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3870 | if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) |
| 3871 | scope = RT_SCOPE_SITE; |
| 3872 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3873 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3874 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3875 | return -EMSGSIZE; |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3876 | |
Thomas Graf | 101bb22 | 2006-09-18 00:11:52 -0700 | [diff] [blame] | 3877 | put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex); |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3878 | if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 || |
| 3879 | put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 3880 | INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) { |
| 3881 | nlmsg_cancel(skb, nlh); |
| 3882 | return -EMSGSIZE; |
| 3883 | } |
Thomas Graf | 85486af | 2006-09-18 00:11:24 -0700 | [diff] [blame] | 3884 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 3885 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 3888 | enum addr_type_t { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | UNICAST_ADDR, |
| 3890 | MULTICAST_ADDR, |
| 3891 | ANYCAST_ADDR, |
| 3892 | }; |
| 3893 | |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3894 | /* called with rcu_read_lock() */ |
| 3895 | static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb, |
| 3896 | struct netlink_callback *cb, enum addr_type_t type, |
| 3897 | int s_ip_idx, int *p_ip_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | struct ifmcaddr6 *ifmca; |
| 3900 | struct ifacaddr6 *ifaca; |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3901 | int err = 1; |
| 3902 | int ip_idx = *p_ip_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3904 | read_lock_bh(&idev->lock); |
| 3905 | switch (type) { |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 3906 | case UNICAST_ADDR: { |
| 3907 | struct inet6_ifaddr *ifa; |
| 3908 | |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3909 | /* unicast address incl. temp addr */ |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 3910 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 3911 | if (++ip_idx < s_ip_idx) |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3912 | continue; |
| 3913 | err = inet6_fill_ifaddr(skb, ifa, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3914 | NETLINK_CB(cb->skb).portid, |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3915 | cb->nlh->nlmsg_seq, |
| 3916 | RTM_NEWADDR, |
| 3917 | NLM_F_MULTI); |
| 3918 | if (err <= 0) |
| 3919 | break; |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 3920 | nl_dump_check_consistent(cb, nlmsg_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | } |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3922 | break; |
stephen hemminger | 502a2ff | 2010-03-17 20:31:13 +0000 | [diff] [blame] | 3923 | } |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3924 | case MULTICAST_ADDR: |
| 3925 | /* multicast address */ |
| 3926 | for (ifmca = idev->mc_list; ifmca; |
| 3927 | ifmca = ifmca->next, ip_idx++) { |
| 3928 | if (ip_idx < s_ip_idx) |
| 3929 | continue; |
| 3930 | err = inet6_fill_ifmcaddr(skb, ifmca, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3931 | NETLINK_CB(cb->skb).portid, |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3932 | cb->nlh->nlmsg_seq, |
| 3933 | RTM_GETMULTICAST, |
| 3934 | NLM_F_MULTI); |
| 3935 | if (err <= 0) |
| 3936 | break; |
| 3937 | } |
| 3938 | break; |
| 3939 | case ANYCAST_ADDR: |
| 3940 | /* anycast address */ |
| 3941 | for (ifaca = idev->ac_list; ifaca; |
| 3942 | ifaca = ifaca->aca_next, ip_idx++) { |
| 3943 | if (ip_idx < s_ip_idx) |
| 3944 | continue; |
| 3945 | err = inet6_fill_ifacaddr(skb, ifaca, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3946 | NETLINK_CB(cb->skb).portid, |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3947 | cb->nlh->nlmsg_seq, |
| 3948 | RTM_GETANYCAST, |
| 3949 | NLM_F_MULTI); |
| 3950 | if (err <= 0) |
| 3951 | break; |
| 3952 | } |
| 3953 | break; |
| 3954 | default: |
| 3955 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | } |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3957 | read_unlock_bh(&idev->lock); |
| 3958 | *p_ip_idx = ip_idx; |
| 3959 | return err; |
| 3960 | } |
| 3961 | |
| 3962 | static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb, |
| 3963 | enum addr_type_t type) |
| 3964 | { |
| 3965 | struct net *net = sock_net(skb->sk); |
| 3966 | int h, s_h; |
| 3967 | int idx, ip_idx; |
| 3968 | int s_idx, s_ip_idx; |
| 3969 | struct net_device *dev; |
| 3970 | struct inet6_dev *idev; |
| 3971 | struct hlist_head *head; |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3972 | |
| 3973 | s_h = cb->args[0]; |
| 3974 | s_idx = idx = cb->args[1]; |
| 3975 | s_ip_idx = ip_idx = cb->args[2]; |
| 3976 | |
| 3977 | rcu_read_lock(); |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 3978 | cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq; |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3979 | for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { |
| 3980 | idx = 0; |
| 3981 | head = &net->dev_index_head[h]; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 3982 | hlist_for_each_entry_rcu(dev, head, index_hlist) { |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3983 | if (idx < s_idx) |
| 3984 | goto cont; |
Patrick McHardy | 4b97efd | 2010-03-26 20:27:49 -0700 | [diff] [blame] | 3985 | if (h > s_h || idx > s_idx) |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3986 | s_ip_idx = 0; |
| 3987 | ip_idx = 0; |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 3988 | idev = __in6_dev_get(dev); |
| 3989 | if (!idev) |
Eric Dumazet | 234b27c | 2009-11-12 04:11:50 +0000 | [diff] [blame] | 3990 | goto cont; |
| 3991 | |
| 3992 | if (in6_dump_addrs(idev, skb, cb, type, |
| 3993 | s_ip_idx, &ip_idx) <= 0) |
| 3994 | goto done; |
| 3995 | cont: |
| 3996 | idx++; |
| 3997 | } |
| 3998 | } |
| 3999 | done: |
| 4000 | rcu_read_unlock(); |
| 4001 | cb->args[0] = h; |
| 4002 | cb->args[1] = idx; |
| 4003 | cb->args[2] = ip_idx; |
| 4004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | return skb->len; |
| 4006 | } |
| 4007 | |
| 4008 | static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 4009 | { |
| 4010 | enum addr_type_t type = UNICAST_ADDR; |
Denis V. Lunev | b854272 | 2007-12-01 00:21:31 +1100 | [diff] [blame] | 4011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | return inet6_dump_addr(skb, cb, type); |
| 4013 | } |
| 4014 | |
| 4015 | static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 4016 | { |
| 4017 | enum addr_type_t type = MULTICAST_ADDR; |
Denis V. Lunev | b854272 | 2007-12-01 00:21:31 +1100 | [diff] [blame] | 4018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | return inet6_dump_addr(skb, cb, type); |
| 4020 | } |
| 4021 | |
| 4022 | |
| 4023 | static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb) |
| 4024 | { |
| 4025 | enum addr_type_t type = ANYCAST_ADDR; |
Denis V. Lunev | b854272 | 2007-12-01 00:21:31 +1100 | [diff] [blame] | 4026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | return inet6_dump_addr(skb, cb, type); |
| 4028 | } |
| 4029 | |
Thomas Graf | 661d296 | 2013-03-21 07:45:29 +0000 | [diff] [blame] | 4030 | static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr *nlh) |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4031 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 4032 | struct net *net = sock_net(in_skb->sk); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4033 | struct ifaddrmsg *ifm; |
| 4034 | struct nlattr *tb[IFA_MAX+1]; |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 4035 | struct in6_addr *addr = NULL, *peer; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4036 | struct net_device *dev = NULL; |
| 4037 | struct inet6_ifaddr *ifa; |
| 4038 | struct sk_buff *skb; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4039 | int err; |
| 4040 | |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4041 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 4042 | if (err < 0) |
| 4043 | goto errout; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4044 | |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 4045 | addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4046 | if (addr == NULL) { |
| 4047 | err = -EINVAL; |
| 4048 | goto errout; |
| 4049 | } |
| 4050 | |
| 4051 | ifm = nlmsg_data(nlh); |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4052 | if (ifm->ifa_index) |
Benjamin Thery | 6fda735 | 2008-03-05 10:47:47 -0800 | [diff] [blame] | 4053 | dev = __dev_get_by_index(net, ifm->ifa_index); |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4054 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4055 | ifa = ipv6_get_ifaddr(net, addr, dev, 1); |
| 4056 | if (!ifa) { |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4057 | err = -EADDRNOTAVAIL; |
| 4058 | goto errout; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4059 | } |
| 4060 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4061 | skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL); |
| 4062 | if (!skb) { |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4063 | err = -ENOBUFS; |
| 4064 | goto errout_ifa; |
| 4065 | } |
| 4066 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4067 | err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).portid, |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4068 | nlh->nlmsg_seq, RTM_NEWADDR, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4069 | if (err < 0) { |
| 4070 | /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ |
| 4071 | WARN_ON(err == -EMSGSIZE); |
| 4072 | kfree_skb(skb); |
| 4073 | goto errout_ifa; |
| 4074 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4075 | err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4076 | errout_ifa: |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4077 | in6_ifa_put(ifa); |
Thomas Graf | 1b29fc2 | 2006-09-18 00:10:50 -0700 | [diff] [blame] | 4078 | errout: |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4079 | return err; |
Noriaki TAKAMIYA | 6c22382 | 2006-07-28 18:12:12 +0900 | [diff] [blame] | 4080 | } |
| 4081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) |
| 4083 | { |
| 4084 | struct sk_buff *skb; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 4085 | struct net *net = dev_net(ifa->idev->dev); |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 4086 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | |
Thomas Graf | 0ab6803 | 2006-09-18 00:12:35 -0700 | [diff] [blame] | 4088 | skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC); |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 4089 | if (skb == NULL) |
| 4090 | goto errout; |
| 4091 | |
| 4092 | err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4093 | if (err < 0) { |
| 4094 | /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ |
| 4095 | WARN_ON(err == -EMSGSIZE); |
| 4096 | kfree_skb(skb); |
| 4097 | goto errout; |
| 4098 | } |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 4099 | rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); |
| 4100 | return; |
Thomas Graf | 5d62026 | 2006-08-15 00:35:02 -0700 | [diff] [blame] | 4101 | errout: |
| 4102 | if (err < 0) |
Benjamin Thery | 6fda735 | 2008-03-05 10:47:47 -0800 | [diff] [blame] | 4103 | rtnl_set_sk_err(net, RTNLGRP_IPV6_IFADDR, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | } |
| 4105 | |
Dave Jones | b6f99a2 | 2007-03-22 12:27:49 -0700 | [diff] [blame] | 4106 | static inline void ipv6_store_devconf(struct ipv6_devconf *cnf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | __s32 *array, int bytes) |
| 4108 | { |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 4109 | BUG_ON(bytes < (DEVCONF_MAX * 4)); |
| 4110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | memset(array, 0, bytes); |
| 4112 | array[DEVCONF_FORWARDING] = cnf->forwarding; |
| 4113 | array[DEVCONF_HOPLIMIT] = cnf->hop_limit; |
| 4114 | array[DEVCONF_MTU6] = cnf->mtu6; |
| 4115 | array[DEVCONF_ACCEPT_RA] = cnf->accept_ra; |
| 4116 | array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects; |
| 4117 | array[DEVCONF_AUTOCONF] = cnf->autoconf; |
| 4118 | array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits; |
| 4119 | array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits; |
Thomas Graf | 93908d1 | 2010-11-17 01:44:24 +0000 | [diff] [blame] | 4120 | array[DEVCONF_RTR_SOLICIT_INTERVAL] = |
| 4121 | jiffies_to_msecs(cnf->rtr_solicit_interval); |
| 4122 | array[DEVCONF_RTR_SOLICIT_DELAY] = |
| 4123 | jiffies_to_msecs(cnf->rtr_solicit_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version; |
Hannes Frederic Sowa | fc4eba5 | 2013-08-14 01:03:46 +0200 | [diff] [blame] | 4125 | array[DEVCONF_MLDV1_UNSOLICITED_REPORT_INTERVAL] = |
| 4126 | jiffies_to_msecs(cnf->mldv1_unsolicited_report_interval); |
| 4127 | array[DEVCONF_MLDV2_UNSOLICITED_REPORT_INTERVAL] = |
| 4128 | jiffies_to_msecs(cnf->mldv2_unsolicited_report_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr; |
| 4130 | array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft; |
| 4131 | array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft; |
| 4132 | array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry; |
| 4133 | array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 4135 | array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 4136 | array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 4137 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 4138 | array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref; |
Thomas Graf | 93908d1 | 2010-11-17 01:44:24 +0000 | [diff] [blame] | 4139 | array[DEVCONF_RTR_PROBE_INTERVAL] = |
| 4140 | jiffies_to_msecs(cnf->rtr_probe_interval); |
Neil Horman | fa03ef3 | 2007-01-30 14:30:10 -0800 | [diff] [blame] | 4141 | #ifdef CONFIG_IPV6_ROUTE_INFO |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 4142 | array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; |
| 4143 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 4144 | #endif |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 4145 | array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp; |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 4146 | array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route; |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 4147 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 4148 | array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad; |
| 4149 | #endif |
YOSHIFUJI Hideaki | 7bc570c | 2008-04-03 09:22:53 +0900 | [diff] [blame] | 4150 | #ifdef CONFIG_IPV6_MROUTE |
| 4151 | array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding; |
| 4152 | #endif |
YOSHIFUJI Hideaki | 778d80b | 2008-06-28 14:17:11 +0900 | [diff] [blame] | 4153 | array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6; |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 4154 | array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad; |
Cosmin Ratiu | c3faca0 | 2009-10-09 03:11:14 +0000 | [diff] [blame] | 4155 | array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao; |
Hannes Frederic Sowa | 5cb0443 | 2012-11-06 16:46:20 +0000 | [diff] [blame] | 4156 | array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify; |
Hannes Frederic Sowa | b800c3b | 2013-08-27 01:36:51 +0200 | [diff] [blame] | 4157 | array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4160 | static inline size_t inet6_ifla6_size(void) |
| 4161 | { |
| 4162 | return nla_total_size(4) /* IFLA_INET6_FLAGS */ |
| 4163 | + nla_total_size(sizeof(struct ifla_cacheinfo)) |
| 4164 | + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */ |
| 4165 | + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */ |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4166 | + nla_total_size(ICMP6_MIB_MAX * 8) /* IFLA_INET6_ICMP6STATS */ |
| 4167 | + nla_total_size(sizeof(struct in6_addr)); /* IFLA_INET6_TOKEN */ |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 4170 | static inline size_t inet6_if_nlmsg_size(void) |
| 4171 | { |
| 4172 | return NLMSG_ALIGN(sizeof(struct ifinfomsg)) |
| 4173 | + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */ |
| 4174 | + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */ |
| 4175 | + nla_total_size(4) /* IFLA_MTU */ |
| 4176 | + nla_total_size(4) /* IFLA_LINK */ |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4177 | + nla_total_size(inet6_ifla6_size()); /* IFLA_PROTINFO */ |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 4178 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 4179 | |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 4180 | static inline void __snmp6_fill_statsdev(u64 *stats, atomic_long_t *mib, |
Tejun Heo | 7d720c3 | 2010-02-16 15:20:26 +0000 | [diff] [blame] | 4181 | int items, int bytes) |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4182 | { |
| 4183 | int i; |
| 4184 | int pad = bytes - sizeof(u64) * items; |
| 4185 | BUG_ON(pad < 0); |
| 4186 | |
| 4187 | /* Use put_unaligned() because stats may not be aligned for u64. */ |
| 4188 | put_unaligned(items, &stats[0]); |
| 4189 | for (i = 1; i < items; i++) |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 4190 | put_unaligned(atomic_long_read(&mib[i]), &stats[i]); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4191 | |
| 4192 | memset(&stats[items], 0, pad); |
| 4193 | } |
| 4194 | |
Eric Dumazet | 4ce3c18 | 2010-06-30 13:31:19 -0700 | [diff] [blame] | 4195 | static inline void __snmp6_fill_stats64(u64 *stats, void __percpu **mib, |
| 4196 | int items, int bytes, size_t syncpoff) |
| 4197 | { |
| 4198 | int i; |
| 4199 | int pad = bytes - sizeof(u64) * items; |
| 4200 | BUG_ON(pad < 0); |
| 4201 | |
| 4202 | /* Use put_unaligned() because stats may not be aligned for u64. */ |
| 4203 | put_unaligned(items, &stats[0]); |
| 4204 | for (i = 1; i < items; i++) |
| 4205 | put_unaligned(snmp_fold_field64(mib, i, syncpoff), &stats[i]); |
| 4206 | |
| 4207 | memset(&stats[items], 0, pad); |
| 4208 | } |
| 4209 | |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4210 | static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype, |
| 4211 | int bytes) |
| 4212 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4213 | switch (attrtype) { |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4214 | case IFLA_INET6_STATS: |
Eric Dumazet | 4ce3c18 | 2010-06-30 13:31:19 -0700 | [diff] [blame] | 4215 | __snmp6_fill_stats64(stats, (void __percpu **)idev->stats.ipv6, |
| 4216 | IPSTATS_MIB_MAX, bytes, offsetof(struct ipstats_mib, syncp)); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4217 | break; |
| 4218 | case IFLA_INET6_ICMP6STATS: |
Eric Dumazet | be281e5 | 2011-05-19 01:14:23 +0000 | [diff] [blame] | 4219 | __snmp6_fill_statsdev(stats, idev->stats.icmpv6dev->mibs, ICMP6_MIB_MAX, bytes); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 4220 | break; |
| 4221 | } |
| 4222 | } |
| 4223 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4224 | static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | { |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame] | 4226 | struct nlattr *nla; |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 4227 | struct ifla_cacheinfo ci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | |
David S. Miller | c78679e | 2012-04-01 20:27:33 -0400 | [diff] [blame] | 4229 | if (nla_put_u32(skb, IFLA_INET6_FLAGS, idev->if_flags)) |
| 4230 | goto nla_put_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | ci.max_reasm_len = IPV6_MAXPLEN; |
David S. Miller | 2491242 | 2010-11-19 13:13:47 -0800 | [diff] [blame] | 4232 | ci.tstamp = cstamp_delta(idev->tstamp); |
| 4233 | ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time); |
| 4234 | ci.retrans_time = jiffies_to_msecs(idev->nd_parms->retrans_time); |
David S. Miller | c78679e | 2012-04-01 20:27:33 -0400 | [diff] [blame] | 4235 | if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci)) |
| 4236 | goto nla_put_failure; |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame] | 4237 | nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32)); |
| 4238 | if (nla == NULL) |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 4239 | goto nla_put_failure; |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame] | 4240 | ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | |
YOSHIFUJI Hideaki | bf99f1b | 2007-04-20 15:56:20 -0700 | [diff] [blame] | 4242 | /* XXX - MC not implemented */ |
| 4243 | |
| 4244 | nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64)); |
| 4245 | if (nla == NULL) |
| 4246 | goto nla_put_failure; |
| 4247 | snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla)); |
| 4248 | |
| 4249 | nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64)); |
| 4250 | if (nla == NULL) |
| 4251 | goto nla_put_failure; |
| 4252 | 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] | 4253 | |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4254 | nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr)); |
| 4255 | if (nla == NULL) |
| 4256 | goto nla_put_failure; |
| 4257 | read_lock_bh(&idev->lock); |
| 4258 | memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla)); |
| 4259 | read_unlock_bh(&idev->lock); |
| 4260 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4261 | return 0; |
| 4262 | |
| 4263 | nla_put_failure: |
| 4264 | return -EMSGSIZE; |
| 4265 | } |
| 4266 | |
| 4267 | static size_t inet6_get_link_af_size(const struct net_device *dev) |
| 4268 | { |
| 4269 | if (!__in6_dev_get(dev)) |
| 4270 | return 0; |
| 4271 | |
| 4272 | return inet6_ifla6_size(); |
| 4273 | } |
| 4274 | |
| 4275 | static int inet6_fill_link_af(struct sk_buff *skb, const struct net_device *dev) |
| 4276 | { |
| 4277 | struct inet6_dev *idev = __in6_dev_get(dev); |
| 4278 | |
| 4279 | if (!idev) |
| 4280 | return -ENODATA; |
| 4281 | |
| 4282 | if (inet6_fill_ifla6_attrs(skb, idev) < 0) |
| 4283 | return -EMSGSIZE; |
| 4284 | |
| 4285 | return 0; |
| 4286 | } |
| 4287 | |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4288 | static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token) |
| 4289 | { |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4290 | struct inet6_ifaddr *ifp; |
| 4291 | struct net_device *dev = idev->dev; |
Daniel Borkmann | fc40383 | 2013-04-09 03:47:15 +0000 | [diff] [blame] | 4292 | bool update_rs = false; |
Hannes Frederic Sowa | dc84829 | 2013-06-24 21:42:40 +0200 | [diff] [blame] | 4293 | struct in6_addr ll_addr; |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4294 | |
| 4295 | if (token == NULL) |
| 4296 | return -EINVAL; |
| 4297 | if (ipv6_addr_any(token)) |
| 4298 | return -EINVAL; |
| 4299 | if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) |
| 4300 | return -EINVAL; |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4301 | if (!ipv6_accept_ra(idev)) |
| 4302 | return -EINVAL; |
| 4303 | if (idev->cnf.rtr_solicits <= 0) |
| 4304 | return -EINVAL; |
| 4305 | |
| 4306 | write_lock_bh(&idev->lock); |
| 4307 | |
| 4308 | BUILD_BUG_ON(sizeof(token->s6_addr) != 16); |
| 4309 | memcpy(idev->token.s6_addr + 8, token->s6_addr + 8, 8); |
| 4310 | |
| 4311 | write_unlock_bh(&idev->lock); |
| 4312 | |
Hannes Frederic Sowa | dc84829 | 2013-06-24 21:42:40 +0200 | [diff] [blame] | 4313 | if (!idev->dead && (idev->if_flags & IF_READY) && |
| 4314 | !ipv6_get_lladdr(dev, &ll_addr, IFA_F_TENTATIVE | |
| 4315 | IFA_F_OPTIMISTIC)) { |
Daniel Borkmann | fc40383 | 2013-04-09 03:47:15 +0000 | [diff] [blame] | 4316 | |
| 4317 | /* If we're not ready, then normal ifup will take care |
| 4318 | * of this. Otherwise, we need to request our rs here. |
| 4319 | */ |
| 4320 | ndisc_send_rs(dev, &ll_addr, &in6addr_linklocal_allrouters); |
| 4321 | update_rs = true; |
| 4322 | } |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4323 | |
| 4324 | write_lock_bh(&idev->lock); |
Daniel Borkmann | fc40383 | 2013-04-09 03:47:15 +0000 | [diff] [blame] | 4325 | |
Hannes Frederic Sowa | 77ecaac | 2013-06-26 03:41:49 +0200 | [diff] [blame] | 4326 | if (update_rs) { |
Daniel Borkmann | fc40383 | 2013-04-09 03:47:15 +0000 | [diff] [blame] | 4327 | idev->if_flags |= IF_RS_SENT; |
Hannes Frederic Sowa | 77ecaac | 2013-06-26 03:41:49 +0200 | [diff] [blame] | 4328 | idev->rs_probes = 1; |
| 4329 | addrconf_mod_rs_timer(idev, idev->cnf.rtr_solicit_interval); |
| 4330 | } |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4331 | |
| 4332 | /* Well, that's kinda nasty ... */ |
| 4333 | list_for_each_entry(ifp, &idev->addr_list, if_list) { |
| 4334 | spin_lock(&ifp->lock); |
Daniel Borkmann | 617fe29 | 2013-04-09 03:47:16 +0000 | [diff] [blame] | 4335 | if (ifp->tokenized) { |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4336 | ifp->valid_lft = 0; |
| 4337 | ifp->prefered_lft = 0; |
| 4338 | } |
| 4339 | spin_unlock(&ifp->lock); |
| 4340 | } |
| 4341 | |
| 4342 | write_unlock_bh(&idev->lock); |
Hannes Frederic Sowa | 2b9651d | 2013-06-24 22:03:28 +0200 | [diff] [blame] | 4343 | addrconf_verify(0); |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 4344 | return 0; |
| 4345 | } |
| 4346 | |
| 4347 | static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla) |
| 4348 | { |
| 4349 | int err = -EINVAL; |
| 4350 | struct inet6_dev *idev = __in6_dev_get(dev); |
| 4351 | struct nlattr *tb[IFLA_INET6_MAX + 1]; |
| 4352 | |
| 4353 | if (!idev) |
| 4354 | return -EAFNOSUPPORT; |
| 4355 | |
| 4356 | if (nla_parse_nested(tb, IFLA_INET6_MAX, nla, NULL) < 0) |
| 4357 | BUG(); |
| 4358 | |
| 4359 | if (tb[IFLA_INET6_TOKEN]) |
| 4360 | err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN])); |
| 4361 | |
| 4362 | return err; |
| 4363 | } |
| 4364 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4365 | static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4366 | u32 portid, u32 seq, int event, unsigned int flags) |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4367 | { |
| 4368 | struct net_device *dev = idev->dev; |
| 4369 | struct ifinfomsg *hdr; |
| 4370 | struct nlmsghdr *nlh; |
| 4371 | void *protoinfo; |
| 4372 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4373 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(*hdr), flags); |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4374 | if (nlh == NULL) |
| 4375 | return -EMSGSIZE; |
| 4376 | |
| 4377 | hdr = nlmsg_data(nlh); |
| 4378 | hdr->ifi_family = AF_INET6; |
| 4379 | hdr->__ifi_pad = 0; |
| 4380 | hdr->ifi_type = dev->type; |
| 4381 | hdr->ifi_index = dev->ifindex; |
| 4382 | hdr->ifi_flags = dev_get_flags(dev); |
| 4383 | hdr->ifi_change = 0; |
| 4384 | |
David S. Miller | c78679e | 2012-04-01 20:27:33 -0400 | [diff] [blame] | 4385 | if (nla_put_string(skb, IFLA_IFNAME, dev->name) || |
| 4386 | (dev->addr_len && |
| 4387 | nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || |
| 4388 | nla_put_u32(skb, IFLA_MTU, dev->mtu) || |
| 4389 | (dev->ifindex != dev->iflink && |
| 4390 | nla_put_u32(skb, IFLA_LINK, dev->iflink))) |
| 4391 | goto nla_put_failure; |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 4392 | protoinfo = nla_nest_start(skb, IFLA_PROTINFO); |
| 4393 | if (protoinfo == NULL) |
| 4394 | goto nla_put_failure; |
| 4395 | |
| 4396 | if (inet6_fill_ifla6_attrs(skb, idev) < 0) |
| 4397 | goto nla_put_failure; |
| 4398 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 4399 | nla_nest_end(skb, protoinfo); |
| 4400 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | |
Thomas Graf | 04561c1 | 2006-11-14 19:53:58 -0800 | [diff] [blame] | 4402 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4403 | nlmsg_cancel(skb, nlh); |
| 4404 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) |
| 4408 | { |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 4409 | struct net *net = sock_net(skb->sk); |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4410 | int h, s_h; |
David S. Miller | 434a8a5 | 2009-11-11 18:53:00 -0800 | [diff] [blame] | 4411 | int idx = 0, s_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | struct net_device *dev; |
| 4413 | struct inet6_dev *idev; |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4414 | struct hlist_head *head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4416 | s_h = cb->args[0]; |
| 4417 | s_idx = cb->args[1]; |
| 4418 | |
| 4419 | rcu_read_lock(); |
| 4420 | for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { |
| 4421 | idx = 0; |
| 4422 | head = &net->dev_index_head[h]; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4423 | hlist_for_each_entry_rcu(dev, head, index_hlist) { |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4424 | if (idx < s_idx) |
| 4425 | goto cont; |
| 4426 | idev = __in6_dev_get(dev); |
| 4427 | if (!idev) |
| 4428 | goto cont; |
| 4429 | if (inet6_fill_ifinfo(skb, idev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4430 | NETLINK_CB(cb->skb).portid, |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4431 | cb->nlh->nlmsg_seq, |
| 4432 | RTM_NEWLINK, NLM_F_MULTI) <= 0) |
| 4433 | goto out; |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 4434 | cont: |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4435 | idx++; |
| 4436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | } |
Eric Dumazet | 84d2697 | 2009-11-09 12:11:28 +0000 | [diff] [blame] | 4438 | out: |
| 4439 | rcu_read_unlock(); |
| 4440 | cb->args[1] = idx; |
| 4441 | cb->args[0] = h; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | |
| 4443 | return skb->len; |
| 4444 | } |
| 4445 | |
| 4446 | void inet6_ifinfo_notify(int event, struct inet6_dev *idev) |
| 4447 | { |
| 4448 | struct sk_buff *skb; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 4449 | struct net *net = dev_net(idev->dev); |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 4450 | int err = -ENOBUFS; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4451 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 4452 | skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC); |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 4453 | if (skb == NULL) |
| 4454 | goto errout; |
| 4455 | |
| 4456 | err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4457 | if (err < 0) { |
| 4458 | /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */ |
| 4459 | WARN_ON(err == -EMSGSIZE); |
| 4460 | kfree_skb(skb); |
| 4461 | goto errout; |
| 4462 | } |
Nicolas Dichtel | 5f75a10 | 2010-12-07 23:38:31 +0000 | [diff] [blame] | 4463 | rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFINFO, NULL, GFP_ATOMIC); |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 4464 | return; |
Thomas Graf | 8d7a76c | 2006-08-15 00:35:47 -0700 | [diff] [blame] | 4465 | errout: |
| 4466 | if (err < 0) |
Nicolas Dichtel | 5f75a10 | 2010-12-07 23:38:31 +0000 | [diff] [blame] | 4467 | rtnl_set_sk_err(net, RTNLGRP_IPV6_IFINFO, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 4470 | static inline size_t inet6_prefix_nlmsg_size(void) |
| 4471 | { |
| 4472 | return NLMSG_ALIGN(sizeof(struct prefixmsg)) |
| 4473 | + nla_total_size(sizeof(struct in6_addr)) |
| 4474 | + nla_total_size(sizeof(struct prefix_cacheinfo)); |
| 4475 | } |
YOSHIFUJI Hideaki | c5396a3 | 2006-06-17 22:48:48 -0700 | [diff] [blame] | 4476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4478 | struct prefix_info *pinfo, u32 portid, u32 seq, |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4479 | int event, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4481 | struct prefixmsg *pmsg; |
| 4482 | struct nlmsghdr *nlh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | struct prefix_cacheinfo ci; |
| 4484 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4485 | nlh = nlmsg_put(skb, portid, seq, event, sizeof(*pmsg), flags); |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4486 | if (nlh == NULL) |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4487 | return -EMSGSIZE; |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4488 | |
| 4489 | pmsg = nlmsg_data(nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | pmsg->prefix_family = AF_INET6; |
Patrick McHardy | 8a47077 | 2005-06-28 12:56:45 -0700 | [diff] [blame] | 4491 | pmsg->prefix_pad1 = 0; |
| 4492 | pmsg->prefix_pad2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | pmsg->prefix_ifindex = idev->dev->ifindex; |
| 4494 | pmsg->prefix_len = pinfo->prefix_len; |
| 4495 | pmsg->prefix_type = pinfo->type; |
Patrick McHardy | 8a47077 | 2005-06-28 12:56:45 -0700 | [diff] [blame] | 4496 | pmsg->prefix_pad3 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | pmsg->prefix_flags = 0; |
| 4498 | if (pinfo->onlink) |
| 4499 | pmsg->prefix_flags |= IF_PREFIX_ONLINK; |
| 4500 | if (pinfo->autoconf) |
| 4501 | pmsg->prefix_flags |= IF_PREFIX_AUTOCONF; |
| 4502 | |
David S. Miller | c78679e | 2012-04-01 20:27:33 -0400 | [diff] [blame] | 4503 | if (nla_put(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix)) |
| 4504 | goto nla_put_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | ci.preferred_time = ntohl(pinfo->prefered); |
| 4506 | ci.valid_time = ntohl(pinfo->valid); |
David S. Miller | c78679e | 2012-04-01 20:27:33 -0400 | [diff] [blame] | 4507 | if (nla_put(skb, PREFIX_CACHEINFO, sizeof(ci), &ci)) |
| 4508 | goto nla_put_failure; |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4509 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | |
Thomas Graf | 6051e2f | 2006-11-14 19:54:19 -0800 | [diff] [blame] | 4511 | nla_put_failure: |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4512 | nlmsg_cancel(skb, nlh); |
| 4513 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4516 | static void inet6_prefix_notify(int event, struct inet6_dev *idev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | struct prefix_info *pinfo) |
| 4518 | { |
| 4519 | struct sk_buff *skb; |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 4520 | struct net *net = dev_net(idev->dev); |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 4521 | int err = -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
Thomas Graf | 339bf98 | 2006-11-10 14:10:15 -0800 | [diff] [blame] | 4523 | skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC); |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 4524 | if (skb == NULL) |
| 4525 | goto errout; |
| 4526 | |
| 4527 | err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0); |
Patrick McHardy | 2693256 | 2007-01-31 23:16:40 -0800 | [diff] [blame] | 4528 | if (err < 0) { |
| 4529 | /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */ |
| 4530 | WARN_ON(err == -EMSGSIZE); |
| 4531 | kfree_skb(skb); |
| 4532 | goto errout; |
| 4533 | } |
Pablo Neira Ayuso | 1ce85fe | 2009-02-24 23:18:28 -0800 | [diff] [blame] | 4534 | rtnl_notify(skb, net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC); |
| 4535 | return; |
Thomas Graf | 8c384bfa | 2006-08-15 00:36:07 -0700 | [diff] [blame] | 4536 | errout: |
| 4537 | if (err < 0) |
Benjamin Thery | 6fda735 | 2008-03-05 10:47:47 -0800 | [diff] [blame] | 4538 | rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 4541 | static void update_valid_ll_addr_cnt(struct inet6_ifaddr *ifp, int count) |
| 4542 | { |
| 4543 | write_lock_bh(&ifp->idev->lock); |
| 4544 | spin_lock(&ifp->lock); |
| 4545 | if (((ifp->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE|IFA_F_OPTIMISTIC| |
| 4546 | IFA_F_DADFAILED)) == IFA_F_PERMANENT) && |
| 4547 | (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) |
| 4548 | ifp->idev->valid_ll_addr_cnt += count; |
| 4549 | WARN_ON(ifp->idev->valid_ll_addr_cnt < 0); |
| 4550 | spin_unlock(&ifp->lock); |
| 4551 | write_unlock_bh(&ifp->idev->lock); |
| 4552 | } |
| 4553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| 4555 | { |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 4556 | struct net *net = dev_net(ifp->idev->dev); |
| 4557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | inet6_ifa_notify(event ? : RTM_NEWADDR, ifp); |
| 4559 | |
| 4560 | switch (event) { |
| 4561 | case RTM_NEWADDR: |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 4562 | update_valid_ll_addr_cnt(ifp, 1); |
| 4563 | |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 4564 | /* |
| 4565 | * If the address was optimistic |
| 4566 | * we inserted the route at the start of |
| 4567 | * our DAD process, so we don't need |
| 4568 | * to do it again |
| 4569 | */ |
| 4570 | if (!(ifp->rt->rt6i_node)) |
| 4571 | ip6_ins_rt(ifp->rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | if (ifp->idev->cnf.forwarding) |
| 4573 | addrconf_join_anycast(ifp); |
Cong Wang | 7996c79 | 2013-05-22 05:41:06 +0000 | [diff] [blame] | 4574 | if (!ipv6_addr_any(&ifp->peer_addr)) |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 4575 | addrconf_prefix_route(&ifp->peer_addr, 128, |
| 4576 | ifp->idev->dev, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | break; |
| 4578 | case RTM_DELADDR: |
Hannes Frederic Sowa | 1ec047e | 2013-06-27 00:06:56 +0200 | [diff] [blame] | 4579 | update_valid_ll_addr_cnt(ifp, -1); |
| 4580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | if (ifp->idev->cnf.forwarding) |
| 4582 | addrconf_leave_anycast(ifp); |
| 4583 | addrconf_leave_solict(ifp->idev, &ifp->addr); |
Cong Wang | 7996c79 | 2013-05-22 05:41:06 +0000 | [diff] [blame] | 4584 | if (!ipv6_addr_any(&ifp->peer_addr)) { |
Nicolas Dichtel | caeaba7 | 2013-05-16 22:32:00 +0000 | [diff] [blame] | 4585 | struct rt6_info *rt; |
| 4586 | struct net_device *dev = ifp->idev->dev; |
| 4587 | |
| 4588 | rt = rt6_lookup(dev_net(dev), &ifp->peer_addr, NULL, |
| 4589 | dev->ifindex, 1); |
| 4590 | if (rt) { |
| 4591 | dst_hold(&rt->dst); |
| 4592 | if (ip6_del_rt(rt)) |
| 4593 | dst_free(&rt->dst); |
| 4594 | } |
| 4595 | } |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 4596 | dst_hold(&ifp->rt->dst); |
stephen hemminger | 93fa159 | 2010-04-12 05:41:31 +0000 | [diff] [blame] | 4597 | |
David S. Miller | 73a8bd7 | 2011-01-23 23:27:15 -0800 | [diff] [blame] | 4598 | if (ip6_del_rt(ifp->rt)) |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 4599 | dst_free(&ifp->rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | break; |
| 4601 | } |
Nicolas Dichtel | 63998ac | 2013-03-22 06:28:43 +0000 | [diff] [blame] | 4602 | atomic_inc(&net->ipv6.dev_addr_genid); |
fan.du | 439677d | 2013-08-01 17:44:44 +0800 | [diff] [blame] | 4603 | rt_genid_bump_ipv6(net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| 4607 | { |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 4608 | rcu_read_lock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | if (likely(ifp->idev->dead == 0)) |
| 4610 | __ipv6_ifa_notify(event, ifp); |
YOSHIFUJI Hideaki | 8814c4b | 2006-09-22 14:44:24 -0700 | [diff] [blame] | 4611 | rcu_read_unlock_bh(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | #ifdef CONFIG_SYSCTL |
| 4615 | |
| 4616 | static |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 4617 | int addrconf_sysctl_forward(struct ctl_table *ctl, int write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 4619 | { |
| 4620 | int *valp = ctl->data; |
| 4621 | int val = *valp; |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 4622 | loff_t pos = *ppos; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 4623 | struct ctl_table lctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | int ret; |
| 4625 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4626 | /* |
| 4627 | * ctl->data points to idev->cnf.forwarding, we should |
| 4628 | * not modify it until we get the rtnl lock. |
| 4629 | */ |
| 4630 | lctl = *ctl; |
| 4631 | lctl.data = &val; |
| 4632 | |
| 4633 | ret = proc_dointvec(&lctl, write, buffer, lenp, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | |
Pavel Emelyanov | c8fecf2 | 2007-12-05 01:50:24 -0800 | [diff] [blame] | 4635 | if (write) |
Stephen Hemminger | b325fdd | 2009-02-26 06:55:31 +0000 | [diff] [blame] | 4636 | ret = addrconf_fixup_forwarding(ctl, valp, val); |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 4637 | if (ret) |
| 4638 | *ppos = pos; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4639 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4642 | static void dev_disable_change(struct inet6_dev *idev) |
| 4643 | { |
Cong Wang | 75538c2 | 2013-05-29 11:30:50 +0800 | [diff] [blame] | 4644 | struct netdev_notifier_info info; |
| 4645 | |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4646 | if (!idev || !idev->dev) |
| 4647 | return; |
| 4648 | |
Cong Wang | 75538c2 | 2013-05-29 11:30:50 +0800 | [diff] [blame] | 4649 | netdev_notifier_info_init(&info, idev->dev); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4650 | if (idev->cnf.disable_ipv6) |
Cong Wang | 75538c2 | 2013-05-29 11:30:50 +0800 | [diff] [blame] | 4651 | addrconf_notify(NULL, NETDEV_DOWN, &info); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4652 | else |
Cong Wang | 75538c2 | 2013-05-29 11:30:50 +0800 | [diff] [blame] | 4653 | addrconf_notify(NULL, NETDEV_UP, &info); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | static void addrconf_disable_change(struct net *net, __s32 newf) |
| 4657 | { |
| 4658 | struct net_device *dev; |
| 4659 | struct inet6_dev *idev; |
| 4660 | |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 4661 | rcu_read_lock(); |
| 4662 | for_each_netdev_rcu(net, dev) { |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4663 | idev = __in6_dev_get(dev); |
| 4664 | if (idev) { |
| 4665 | int changed = (!idev->cnf.disable_ipv6) ^ (!newf); |
| 4666 | idev->cnf.disable_ipv6 = newf; |
| 4667 | if (changed) |
| 4668 | dev_disable_change(idev); |
| 4669 | } |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4670 | } |
Eric Dumazet | c6d14c8 | 2009-11-04 05:43:23 -0800 | [diff] [blame] | 4671 | rcu_read_unlock(); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4674 | static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf) |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4675 | { |
| 4676 | struct net *net; |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4677 | int old; |
| 4678 | |
| 4679 | if (!rtnl_trylock()) |
| 4680 | return restart_syscall(); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4681 | |
| 4682 | net = (struct net *)table->extra2; |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4683 | old = *p; |
| 4684 | *p = newf; |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4685 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4686 | if (p == &net->ipv6.devconf_dflt->disable_ipv6) { |
| 4687 | rtnl_unlock(); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4688 | return 0; |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 4689 | } |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4690 | |
| 4691 | if (p == &net->ipv6.devconf_all->disable_ipv6) { |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4692 | net->ipv6.devconf_dflt->disable_ipv6 = newf; |
| 4693 | addrconf_disable_change(net, newf); |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4694 | } else if ((!newf) ^ (!old)) |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4695 | dev_disable_change((struct inet6_dev *)table->extra1); |
| 4696 | |
| 4697 | rtnl_unlock(); |
| 4698 | return 0; |
| 4699 | } |
| 4700 | |
| 4701 | static |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 4702 | int addrconf_sysctl_disable(struct ctl_table *ctl, int write, |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4703 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 4704 | { |
| 4705 | int *valp = ctl->data; |
| 4706 | int val = *valp; |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 4707 | loff_t pos = *ppos; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 4708 | struct ctl_table lctl; |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4709 | int ret; |
| 4710 | |
Francesco Ruggeri | 013d97e | 2012-01-16 10:40:10 +0000 | [diff] [blame] | 4711 | /* |
| 4712 | * ctl->data points to idev->cnf.disable_ipv6, we should |
| 4713 | * not modify it until we get the rtnl lock. |
| 4714 | */ |
| 4715 | lctl = *ctl; |
| 4716 | lctl.data = &val; |
| 4717 | |
| 4718 | ret = proc_dointvec(&lctl, write, buffer, lenp, ppos); |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4719 | |
| 4720 | if (write) |
| 4721 | ret = addrconf_disable_ipv6(ctl, valp, val); |
Eric W. Biederman | 88af182 | 2010-02-19 13:22:59 +0000 | [diff] [blame] | 4722 | if (ret) |
| 4723 | *ppos = pos; |
Brian Haley | 56d417b | 2009-06-01 03:07:33 -0700 | [diff] [blame] | 4724 | return ret; |
| 4725 | } |
| 4726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | static struct addrconf_sysctl_table |
| 4728 | { |
| 4729 | struct ctl_table_header *sysctl_header; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 4730 | struct ctl_table addrconf_vars[DEVCONF_MAX+1]; |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 4731 | } addrconf_sysctl __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | .sysctl_header = NULL, |
| 4733 | .addrconf_vars = { |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 4734 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4735 | .procname = "forwarding", |
| 4736 | .data = &ipv6_devconf.forwarding, |
| 4737 | .maxlen = sizeof(int), |
| 4738 | .mode = 0644, |
| 4739 | .proc_handler = addrconf_sysctl_forward, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | }, |
| 4741 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4742 | .procname = "hop_limit", |
| 4743 | .data = &ipv6_devconf.hop_limit, |
| 4744 | .maxlen = sizeof(int), |
| 4745 | .mode = 0644, |
| 4746 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | }, |
| 4748 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4749 | .procname = "mtu", |
| 4750 | .data = &ipv6_devconf.mtu6, |
| 4751 | .maxlen = sizeof(int), |
| 4752 | .mode = 0644, |
| 4753 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | }, |
| 4755 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4756 | .procname = "accept_ra", |
| 4757 | .data = &ipv6_devconf.accept_ra, |
| 4758 | .maxlen = sizeof(int), |
| 4759 | .mode = 0644, |
| 4760 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | }, |
| 4762 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4763 | .procname = "accept_redirects", |
| 4764 | .data = &ipv6_devconf.accept_redirects, |
| 4765 | .maxlen = sizeof(int), |
| 4766 | .mode = 0644, |
| 4767 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | }, |
| 4769 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4770 | .procname = "autoconf", |
| 4771 | .data = &ipv6_devconf.autoconf, |
| 4772 | .maxlen = sizeof(int), |
| 4773 | .mode = 0644, |
| 4774 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | }, |
| 4776 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4777 | .procname = "dad_transmits", |
| 4778 | .data = &ipv6_devconf.dad_transmits, |
| 4779 | .maxlen = sizeof(int), |
| 4780 | .mode = 0644, |
| 4781 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | }, |
| 4783 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4784 | .procname = "router_solicitations", |
| 4785 | .data = &ipv6_devconf.rtr_solicits, |
| 4786 | .maxlen = sizeof(int), |
| 4787 | .mode = 0644, |
| 4788 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | }, |
| 4790 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4791 | .procname = "router_solicitation_interval", |
| 4792 | .data = &ipv6_devconf.rtr_solicit_interval, |
| 4793 | .maxlen = sizeof(int), |
| 4794 | .mode = 0644, |
| 4795 | .proc_handler = proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | }, |
| 4797 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4798 | .procname = "router_solicitation_delay", |
| 4799 | .data = &ipv6_devconf.rtr_solicit_delay, |
| 4800 | .maxlen = sizeof(int), |
| 4801 | .mode = 0644, |
| 4802 | .proc_handler = proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | }, |
| 4804 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4805 | .procname = "force_mld_version", |
| 4806 | .data = &ipv6_devconf.force_mld_version, |
| 4807 | .maxlen = sizeof(int), |
| 4808 | .mode = 0644, |
| 4809 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | }, |
Hannes Frederic Sowa | fc4eba5 | 2013-08-14 01:03:46 +0200 | [diff] [blame] | 4811 | { |
| 4812 | .procname = "mldv1_unsolicited_report_interval", |
| 4813 | .data = |
| 4814 | &ipv6_devconf.mldv1_unsolicited_report_interval, |
| 4815 | .maxlen = sizeof(int), |
| 4816 | .mode = 0644, |
| 4817 | .proc_handler = proc_dointvec_ms_jiffies, |
| 4818 | }, |
| 4819 | { |
| 4820 | .procname = "mldv2_unsolicited_report_interval", |
| 4821 | .data = |
| 4822 | &ipv6_devconf.mldv2_unsolicited_report_interval, |
| 4823 | .maxlen = sizeof(int), |
| 4824 | .mode = 0644, |
| 4825 | .proc_handler = proc_dointvec_ms_jiffies, |
| 4826 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4828 | .procname = "use_tempaddr", |
| 4829 | .data = &ipv6_devconf.use_tempaddr, |
| 4830 | .maxlen = sizeof(int), |
| 4831 | .mode = 0644, |
| 4832 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | }, |
| 4834 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4835 | .procname = "temp_valid_lft", |
| 4836 | .data = &ipv6_devconf.temp_valid_lft, |
| 4837 | .maxlen = sizeof(int), |
| 4838 | .mode = 0644, |
| 4839 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | }, |
| 4841 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4842 | .procname = "temp_prefered_lft", |
| 4843 | .data = &ipv6_devconf.temp_prefered_lft, |
| 4844 | .maxlen = sizeof(int), |
| 4845 | .mode = 0644, |
| 4846 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | }, |
| 4848 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4849 | .procname = "regen_max_retry", |
| 4850 | .data = &ipv6_devconf.regen_max_retry, |
| 4851 | .maxlen = sizeof(int), |
| 4852 | .mode = 0644, |
| 4853 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | }, |
| 4855 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4856 | .procname = "max_desync_factor", |
| 4857 | .data = &ipv6_devconf.max_desync_factor, |
| 4858 | .maxlen = sizeof(int), |
| 4859 | .mode = 0644, |
| 4860 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4863 | .procname = "max_addresses", |
| 4864 | .data = &ipv6_devconf.max_addresses, |
| 4865 | .maxlen = sizeof(int), |
| 4866 | .mode = 0644, |
| 4867 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | }, |
| 4869 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4870 | .procname = "accept_ra_defrtr", |
| 4871 | .data = &ipv6_devconf.accept_ra_defrtr, |
| 4872 | .maxlen = sizeof(int), |
| 4873 | .mode = 0644, |
| 4874 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 65f5c7c | 2006-03-20 16:55:08 -0800 | [diff] [blame] | 4875 | }, |
| 4876 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4877 | .procname = "accept_ra_pinfo", |
| 4878 | .data = &ipv6_devconf.accept_ra_pinfo, |
| 4879 | .maxlen = sizeof(int), |
| 4880 | .mode = 0644, |
| 4881 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 4882 | }, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 4883 | #ifdef CONFIG_IPV6_ROUTER_PREF |
| 4884 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4885 | .procname = "accept_ra_rtr_pref", |
| 4886 | .data = &ipv6_devconf.accept_ra_rtr_pref, |
| 4887 | .maxlen = sizeof(int), |
| 4888 | .mode = 0644, |
| 4889 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 4890 | }, |
YOSHIFUJI Hideaki | 52e16356 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 4891 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4892 | .procname = "router_probe_interval", |
| 4893 | .data = &ipv6_devconf.rtr_probe_interval, |
| 4894 | .maxlen = sizeof(int), |
| 4895 | .mode = 0644, |
| 4896 | .proc_handler = proc_dointvec_jiffies, |
YOSHIFUJI Hideaki | 52e16356 | 2006-03-20 17:05:47 -0800 | [diff] [blame] | 4897 | }, |
Neil Horman | fa03ef3 | 2007-01-30 14:30:10 -0800 | [diff] [blame] | 4898 | #ifdef CONFIG_IPV6_ROUTE_INFO |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 4899 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4900 | .procname = "accept_ra_rt_info_max_plen", |
| 4901 | .data = &ipv6_devconf.accept_ra_rt_info_max_plen, |
| 4902 | .maxlen = sizeof(int), |
| 4903 | .mode = 0644, |
| 4904 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 09c884d | 2006-03-20 17:07:03 -0800 | [diff] [blame] | 4905 | }, |
| 4906 | #endif |
YOSHIFUJI Hideaki | 930d6ff | 2006-03-20 17:05:30 -0800 | [diff] [blame] | 4907 | #endif |
YOSHIFUJI Hideaki | c4fd30e | 2006-03-20 16:55:26 -0800 | [diff] [blame] | 4908 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4909 | .procname = "proxy_ndp", |
| 4910 | .data = &ipv6_devconf.proxy_ndp, |
| 4911 | .maxlen = sizeof(int), |
| 4912 | .mode = 0644, |
| 4913 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | fbea49e | 2006-09-22 14:43:49 -0700 | [diff] [blame] | 4914 | }, |
| 4915 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4916 | .procname = "accept_source_route", |
| 4917 | .data = &ipv6_devconf.accept_source_route, |
| 4918 | .maxlen = sizeof(int), |
| 4919 | .mode = 0644, |
| 4920 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 4921 | }, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 4922 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
| 4923 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4924 | .procname = "optimistic_dad", |
| 4925 | .data = &ipv6_devconf.optimistic_dad, |
| 4926 | .maxlen = sizeof(int), |
| 4927 | .mode = 0644, |
| 4928 | .proc_handler = proc_dointvec, |
Neil Horman | 95c385b | 2007-04-25 17:08:10 -0700 | [diff] [blame] | 4929 | |
| 4930 | }, |
| 4931 | #endif |
YOSHIFUJI Hideaki | 7bc570c | 2008-04-03 09:22:53 +0900 | [diff] [blame] | 4932 | #ifdef CONFIG_IPV6_MROUTE |
| 4933 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4934 | .procname = "mc_forwarding", |
| 4935 | .data = &ipv6_devconf.mc_forwarding, |
| 4936 | .maxlen = sizeof(int), |
| 4937 | .mode = 0444, |
| 4938 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 7bc570c | 2008-04-03 09:22:53 +0900 | [diff] [blame] | 4939 | }, |
| 4940 | #endif |
YOSHIFUJI Hideaki | 0bcbc92 | 2007-04-24 14:58:30 -0700 | [diff] [blame] | 4941 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4942 | .procname = "disable_ipv6", |
| 4943 | .data = &ipv6_devconf.disable_ipv6, |
| 4944 | .maxlen = sizeof(int), |
| 4945 | .mode = 0644, |
| 4946 | .proc_handler = addrconf_sysctl_disable, |
YOSHIFUJI Hideaki | 778d80b | 2008-06-28 14:17:11 +0900 | [diff] [blame] | 4947 | }, |
| 4948 | { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4949 | .procname = "accept_dad", |
| 4950 | .data = &ipv6_devconf.accept_dad, |
| 4951 | .maxlen = sizeof(int), |
| 4952 | .mode = 0644, |
| 4953 | .proc_handler = proc_dointvec, |
YOSHIFUJI Hideaki | 1b34be7 | 2008-06-28 14:18:38 +0900 | [diff] [blame] | 4954 | }, |
| 4955 | { |
Octavian Purdila | f7734fd | 2009-10-02 11:39:15 +0000 | [diff] [blame] | 4956 | .procname = "force_tllao", |
| 4957 | .data = &ipv6_devconf.force_tllao, |
| 4958 | .maxlen = sizeof(int), |
| 4959 | .mode = 0644, |
| 4960 | .proc_handler = proc_dointvec |
| 4961 | }, |
| 4962 | { |
Hannes Frederic Sowa | 5cb0443 | 2012-11-06 16:46:20 +0000 | [diff] [blame] | 4963 | .procname = "ndisc_notify", |
| 4964 | .data = &ipv6_devconf.ndisc_notify, |
| 4965 | .maxlen = sizeof(int), |
| 4966 | .mode = 0644, |
| 4967 | .proc_handler = proc_dointvec |
| 4968 | }, |
| 4969 | { |
Hannes Frederic Sowa | b800c3b | 2013-08-27 01:36:51 +0200 | [diff] [blame] | 4970 | .procname = "suppress_frag_ndisc", |
| 4971 | .data = &ipv6_devconf.suppress_frag_ndisc, |
| 4972 | .maxlen = sizeof(int), |
| 4973 | .mode = 0644, |
| 4974 | .proc_handler = proc_dointvec |
| 4975 | }, |
| 4976 | { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 4977 | /* sentinel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | } |
| 4979 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | }; |
| 4981 | |
Pavel Emelyanov | bff16c2 | 2008-01-10 17:42:13 -0800 | [diff] [blame] | 4982 | static int __addrconf_sysctl_register(struct net *net, char *dev_name, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 4983 | struct inet6_dev *idev, struct ipv6_devconf *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | { |
| 4985 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | struct addrconf_sysctl_table *t; |
Eric W. Biederman | 6105e29 | 2012-04-19 13:41:24 +0000 | [diff] [blame] | 4987 | char path[sizeof("net/ipv6/conf/") + IFNAMSIZ]; |
Pavel Emelyanov | 1dab622 | 2007-12-02 00:59:38 +1100 | [diff] [blame] | 4988 | |
Arnaldo Carvalho de Melo | af879cc | 2006-11-17 12:14:37 -0200 | [diff] [blame] | 4989 | t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | if (t == NULL) |
Pavel Emelyanov | f68635e | 2007-12-02 00:21:52 +1100 | [diff] [blame] | 4991 | goto out; |
| 4992 | |
Stephen Hemminger | bcdd553 | 2010-03-20 16:08:18 -0700 | [diff] [blame] | 4993 | for (i = 0; t->addrconf_vars[i].data; i++) { |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 4994 | t->addrconf_vars[i].data += (char *)p - (char *)&ipv6_devconf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */ |
Pavel Emelyanov | bff16c2 | 2008-01-10 17:42:13 -0800 | [diff] [blame] | 4996 | t->addrconf_vars[i].extra2 = net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | |
Eric W. Biederman | 6105e29 | 2012-04-19 13:41:24 +0000 | [diff] [blame] | 4999 | snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | |
Eric W. Biederman | 6105e29 | 2012-04-19 13:41:24 +0000 | [diff] [blame] | 5001 | t->sysctl_header = register_net_sysctl(net, path, t->addrconf_vars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | if (t->sysctl_header == NULL) |
Eric W. Biederman | 6105e29 | 2012-04-19 13:41:24 +0000 | [diff] [blame] | 5003 | goto free; |
Pavel Emelyanov | f68635e | 2007-12-02 00:21:52 +1100 | [diff] [blame] | 5004 | |
| 5005 | p->sysctl = t; |
Pavel Emelyanov | 9589731 | 2008-01-10 17:41:45 -0800 | [diff] [blame] | 5006 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | |
Pavel Emelyanov | f68635e | 2007-12-02 00:21:52 +1100 | [diff] [blame] | 5008 | free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | kfree(t); |
Pavel Emelyanov | f68635e | 2007-12-02 00:21:52 +1100 | [diff] [blame] | 5010 | out: |
Pavel Emelyanov | 9589731 | 2008-01-10 17:41:45 -0800 | [diff] [blame] | 5011 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 5014 | static void __addrconf_sysctl_unregister(struct ipv6_devconf *p) |
| 5015 | { |
| 5016 | struct addrconf_sysctl_table *t; |
| 5017 | |
| 5018 | if (p->sysctl == NULL) |
| 5019 | return; |
| 5020 | |
| 5021 | t = p->sysctl; |
| 5022 | p->sysctl = NULL; |
Lucian Adrian Grijincu | ff53881 | 2011-05-01 01:44:01 +0000 | [diff] [blame] | 5023 | unregister_net_sysctl_table(t->sysctl_header); |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 5024 | kfree(t); |
| 5025 | } |
| 5026 | |
Pavel Emelyanov | f52295a | 2007-12-02 00:58:37 +1100 | [diff] [blame] | 5027 | static void addrconf_sysctl_register(struct inet6_dev *idev) |
| 5028 | { |
Eric W. Biederman | 54716e3 | 2010-02-14 03:27:03 +0000 | [diff] [blame] | 5029 | neigh_sysctl_register(idev->dev, idev->nd_parms, "ipv6", |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 5030 | &ndisc_ifinfo_sysctl_change); |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 5031 | __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 5032 | idev, &idev->cnf); |
Pavel Emelyanov | f52295a | 2007-12-02 00:58:37 +1100 | [diff] [blame] | 5033 | } |
| 5034 | |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 5035 | static void addrconf_sysctl_unregister(struct inet6_dev *idev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | { |
Pavel Emelyanov | 408c476 | 2008-01-10 17:41:21 -0800 | [diff] [blame] | 5037 | __addrconf_sysctl_unregister(&idev->cnf); |
| 5038 | neigh_sysctl_unregister(idev->nd_parms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | |
| 5042 | #endif |
| 5043 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 5044 | static int __net_init addrconf_init_net(struct net *net) |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5045 | { |
Hong Zhiguo | a79ca22 | 2013-03-26 01:52:45 +0800 | [diff] [blame] | 5046 | int err = -ENOMEM; |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5047 | struct ipv6_devconf *all, *dflt; |
| 5048 | |
Hong Zhiguo | a79ca22 | 2013-03-26 01:52:45 +0800 | [diff] [blame] | 5049 | all = kmemdup(&ipv6_devconf, sizeof(ipv6_devconf), GFP_KERNEL); |
| 5050 | if (all == NULL) |
| 5051 | goto err_alloc_all; |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5052 | |
Hong Zhiguo | a79ca22 | 2013-03-26 01:52:45 +0800 | [diff] [blame] | 5053 | dflt = kmemdup(&ipv6_devconf_dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL); |
| 5054 | if (dflt == NULL) |
| 5055 | goto err_alloc_dflt; |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5056 | |
Hong Zhiguo | a79ca22 | 2013-03-26 01:52:45 +0800 | [diff] [blame] | 5057 | /* these will be inherited by all namespaces */ |
| 5058 | dflt->autoconf = ipv6_defaults.autoconf; |
| 5059 | dflt->disable_ipv6 = ipv6_defaults.disable_ipv6; |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5060 | |
| 5061 | net->ipv6.devconf_all = all; |
| 5062 | net->ipv6.devconf_dflt = dflt; |
| 5063 | |
| 5064 | #ifdef CONFIG_SYSCTL |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 5065 | err = __addrconf_sysctl_register(net, "all", NULL, all); |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5066 | if (err < 0) |
| 5067 | goto err_reg_all; |
| 5068 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 5069 | err = __addrconf_sysctl_register(net, "default", NULL, dflt); |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5070 | if (err < 0) |
| 5071 | goto err_reg_dflt; |
| 5072 | #endif |
| 5073 | return 0; |
| 5074 | |
| 5075 | #ifdef CONFIG_SYSCTL |
| 5076 | err_reg_dflt: |
| 5077 | __addrconf_sysctl_unregister(all); |
| 5078 | err_reg_all: |
| 5079 | kfree(dflt); |
| 5080 | #endif |
| 5081 | err_alloc_dflt: |
| 5082 | kfree(all); |
| 5083 | err_alloc_all: |
| 5084 | return err; |
| 5085 | } |
| 5086 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 5087 | static void __net_exit addrconf_exit_net(struct net *net) |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5088 | { |
| 5089 | #ifdef CONFIG_SYSCTL |
| 5090 | __addrconf_sysctl_unregister(net->ipv6.devconf_dflt); |
| 5091 | __addrconf_sysctl_unregister(net->ipv6.devconf_all); |
| 5092 | #endif |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 5093 | if (!net_eq(net, &init_net)) { |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5094 | kfree(net->ipv6.devconf_dflt); |
| 5095 | kfree(net->ipv6.devconf_all); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | static struct pernet_operations addrconf_ops = { |
| 5100 | .init = addrconf_init_net, |
| 5101 | .exit = addrconf_exit_net, |
| 5102 | }; |
| 5103 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 5104 | static struct rtnl_af_ops inet6_ops = { |
| 5105 | .family = AF_INET6, |
| 5106 | .fill_link_af = inet6_fill_link_af, |
| 5107 | .get_link_af_size = inet6_get_link_af_size, |
Daniel Borkmann | f53adae | 2013-04-08 04:01:30 +0000 | [diff] [blame] | 5108 | .set_link_af = inet6_set_link_af, |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 5109 | }; |
| 5110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | /* |
| 5112 | * Init / cleanup code |
| 5113 | */ |
| 5114 | |
| 5115 | int __init addrconf_init(void) |
| 5116 | { |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 5117 | int i, err; |
YOSHIFUJI Hideaki | 2a8cc6c | 2007-11-14 15:56:23 +0900 | [diff] [blame] | 5118 | |
Stephen Hemminger | e21e846 | 2010-03-20 16:09:01 -0700 | [diff] [blame] | 5119 | err = ipv6_addr_label_init(); |
| 5120 | if (err < 0) { |
Joe Perches | f321383 | 2012-05-15 14:11:53 +0000 | [diff] [blame] | 5121 | pr_crit("%s: cannot initialize default policy table: %d\n", |
| 5122 | __func__, err); |
Neil Horman | 2cc6d2b | 2010-09-24 09:55:52 +0000 | [diff] [blame] | 5123 | goto out; |
YOSHIFUJI Hideaki | 2a8cc6c | 2007-11-14 15:56:23 +0900 | [diff] [blame] | 5124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | |
Neil Horman | 2cc6d2b | 2010-09-24 09:55:52 +0000 | [diff] [blame] | 5126 | err = register_pernet_subsys(&addrconf_ops); |
| 5127 | if (err < 0) |
| 5128 | goto out_addrlabel; |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | /* The addrconf netdev notifier requires that loopback_dev |
| 5131 | * has it's ipv6 private information allocated and setup |
| 5132 | * before it can bring up and give link-local addresses |
| 5133 | * to other devices which are up. |
| 5134 | * |
| 5135 | * Unfortunately, loopback_dev is not necessarily the first |
| 5136 | * entry in the global dev_base list of net devices. In fact, |
| 5137 | * it is likely to be the very last entry on that list. |
| 5138 | * So this causes the notifier registry below to try and |
| 5139 | * give link-local addresses to all devices besides loopback_dev |
| 5140 | * first, then loopback_dev, which cases all the non-loopback_dev |
| 5141 | * devices to fail to get a link-local address. |
| 5142 | * |
| 5143 | * So, as a temporary fix, allocate the ipv6 structure for |
| 5144 | * loopback_dev first by hand. |
| 5145 | * Longer term, all of the dependencies ipv6 has upon the loopback |
| 5146 | * device and it being up should be removed. |
| 5147 | */ |
| 5148 | rtnl_lock(); |
Eric W. Biederman | 2774c7a | 2007-09-26 22:10:56 -0700 | [diff] [blame] | 5149 | if (!ipv6_add_dev(init_net.loopback_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5150 | err = -ENOMEM; |
| 5151 | rtnl_unlock(); |
| 5152 | if (err) |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5153 | goto errlo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 5155 | for (i = 0; i < IN6_ADDR_HSIZE; i++) |
| 5156 | INIT_HLIST_HEAD(&inet6_addr_lst[i]); |
| 5157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | register_netdevice_notifier(&ipv6_dev_notf); |
| 5159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | addrconf_verify(0); |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5161 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 5162 | err = rtnl_af_register(&inet6_ops); |
| 5163 | if (err < 0) |
| 5164 | goto errout_af; |
| 5165 | |
Greg Rose | c7ac867 | 2011-06-10 01:27:09 +0000 | [diff] [blame] | 5166 | err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo, |
| 5167 | NULL); |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5168 | if (err < 0) |
| 5169 | goto errout; |
| 5170 | |
| 5171 | /* Only the first call to __rtnl_register can fail */ |
Greg Rose | c7ac867 | 2011-06-10 01:27:09 +0000 | [diff] [blame] | 5172 | __rtnl_register(PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL, NULL); |
| 5173 | __rtnl_register(PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL, NULL); |
| 5174 | __rtnl_register(PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, |
| 5175 | inet6_dump_ifaddr, NULL); |
| 5176 | __rtnl_register(PF_INET6, RTM_GETMULTICAST, NULL, |
| 5177 | inet6_dump_ifmcaddr, NULL); |
| 5178 | __rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, |
| 5179 | inet6_dump_ifacaddr, NULL); |
Nicolas Dichtel | 76f8f6c | 2012-10-25 22:28:51 +0000 | [diff] [blame] | 5180 | __rtnl_register(PF_INET6, RTM_GETNETCONF, inet6_netconf_get_devconf, |
Nicolas Dichtel | 7a67420 | 2013-03-05 23:42:06 +0000 | [diff] [blame] | 5181 | inet6_netconf_dump_devconf, NULL); |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5182 | |
YOSHIFUJI Hideaki | 2a8cc6c | 2007-11-14 15:56:23 +0900 | [diff] [blame] | 5183 | ipv6_addr_label_rtnl_register(); |
| 5184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | return 0; |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5186 | errout: |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 5187 | rtnl_af_unregister(&inet6_ops); |
| 5188 | errout_af: |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5189 | unregister_netdevice_notifier(&ipv6_dev_notf); |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5190 | errlo: |
| 5191 | unregister_pernet_subsys(&addrconf_ops); |
Neil Horman | 2cc6d2b | 2010-09-24 09:55:52 +0000 | [diff] [blame] | 5192 | out_addrlabel: |
| 5193 | ipv6_addr_label_cleanup(); |
| 5194 | out: |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 5195 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | } |
| 5197 | |
Daniel Lezcano | 09f7709 | 2007-12-13 05:34:58 -0800 | [diff] [blame] | 5198 | void addrconf_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | { |
Daniel Lezcano | 176c39a | 2009-03-03 01:06:45 -0800 | [diff] [blame] | 5200 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | int i; |
| 5202 | |
| 5203 | unregister_netdevice_notifier(&ipv6_dev_notf); |
Pavel Emelyanov | e0da5a4 | 2008-01-10 17:42:55 -0800 | [diff] [blame] | 5204 | unregister_pernet_subsys(&addrconf_ops); |
Neil Horman | 2cc6d2b | 2010-09-24 09:55:52 +0000 | [diff] [blame] | 5205 | ipv6_addr_label_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | |
| 5207 | rtnl_lock(); |
| 5208 | |
Thomas Graf | b382b19 | 2010-11-16 04:33:57 +0000 | [diff] [blame] | 5209 | __rtnl_af_unregister(&inet6_ops); |
| 5210 | |
Daniel Lezcano | 176c39a | 2009-03-03 01:06:45 -0800 | [diff] [blame] | 5211 | /* clean dev list */ |
| 5212 | for_each_netdev(&init_net, dev) { |
| 5213 | if (__in6_dev_get(dev) == NULL) |
| 5214 | continue; |
| 5215 | addrconf_ifdown(dev, 1); |
| 5216 | } |
| 5217 | addrconf_ifdown(init_net.loopback_dev, 2); |
| 5218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | * Check hash table. |
| 5221 | */ |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 5222 | spin_lock_bh(&addrconf_hash_lock); |
stephen hemminger | c2e2129 | 2010-03-17 20:31:10 +0000 | [diff] [blame] | 5223 | for (i = 0; i < IN6_ADDR_HSIZE; i++) |
| 5224 | WARN_ON(!hlist_empty(&inet6_addr_lst[i])); |
stephen hemminger | 5c578aed | 2010-03-17 20:31:11 +0000 | [diff] [blame] | 5225 | spin_unlock_bh(&addrconf_hash_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | |
| 5227 | del_timer(&addr_chk_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | } |