Commit ef11db33 authored by Florian Westphal's avatar Florian Westphal Committed by David S. Miller

net: inetdevice: provide replacement iterators for in_ifaddr walk

The ifa_list is protected either by rcu or rtnl lock, but the
current iterators do not account for this.

This adds two iterators as replacement, a later patch in
the series will update them with the needed rcu/rtnl_dereference calls.

Its not done in this patch yet to avoid sparse warnings -- the fields
lack the proper __rcu annotation.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 35ebfc22
...@@ -186,7 +186,7 @@ __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst, ...@@ -186,7 +186,7 @@ __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst,
struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
__be32 mask); __be32 mask);
struct in_ifaddr *inet_lookup_ifaddr_rcu(struct net *net, __be32 addr); struct in_ifaddr *inet_lookup_ifaddr_rcu(struct net *net, __be32 addr);
static __inline__ bool inet_ifa_match(__be32 addr, struct in_ifaddr *ifa) static inline bool inet_ifa_match(__be32 addr, const struct in_ifaddr *ifa)
{ {
return !((addr^ifa->ifa_address)&ifa->ifa_mask); return !((addr^ifa->ifa_address)&ifa->ifa_mask);
} }
...@@ -215,6 +215,14 @@ static __inline__ bool bad_mask(__be32 mask, __be32 addr) ...@@ -215,6 +215,14 @@ static __inline__ bool bad_mask(__be32 mask, __be32 addr)
#define endfor_ifa(in_dev) } #define endfor_ifa(in_dev) }
#define in_dev_for_each_ifa_rtnl(ifa, in_dev) \
for (ifa = (in_dev)->ifa_list; ifa; \
ifa = ifa->ifa_next)
#define in_dev_for_each_ifa_rcu(ifa, in_dev) \
for (ifa = (in_dev)->ifa_list; ifa; \
ifa = ifa->ifa_next)
static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev) static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev)
{ {
return rcu_dereference(dev->ip_ptr); return rcu_dereference(dev->ip_ptr);
......
...@@ -873,13 +873,12 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh, ...@@ -873,13 +873,12 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
static struct in_ifaddr *find_matching_ifa(struct in_ifaddr *ifa) static struct in_ifaddr *find_matching_ifa(struct in_ifaddr *ifa)
{ {
struct in_device *in_dev = ifa->ifa_dev; struct in_device *in_dev = ifa->ifa_dev;
struct in_ifaddr *ifa1, **ifap; struct in_ifaddr *ifa1;
if (!ifa->ifa_local) if (!ifa->ifa_local)
return NULL; return NULL;
for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL; in_dev_for_each_ifa_rtnl(ifa1, in_dev) {
ifap = &ifa1->ifa_next) {
if (ifa1->ifa_mask == ifa->ifa_mask && if (ifa1->ifa_mask == ifa->ifa_mask &&
inet_ifa_match(ifa1->ifa_address, ifa) && inet_ifa_match(ifa1->ifa_address, ifa) &&
ifa1->ifa_local == ifa->ifa_local) ifa1->ifa_local == ifa->ifa_local)
...@@ -1208,7 +1207,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr) ...@@ -1208,7 +1207,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
static int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size) static int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
{ {
struct in_device *in_dev = __in_dev_get_rtnl(dev); struct in_device *in_dev = __in_dev_get_rtnl(dev);
struct in_ifaddr *ifa; const struct in_ifaddr *ifa;
struct ifreq ifr; struct ifreq ifr;
int done = 0; int done = 0;
...@@ -1218,7 +1217,7 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len, int s ...@@ -1218,7 +1217,7 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len, int s
if (!in_dev) if (!in_dev)
goto out; goto out;
for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { in_dev_for_each_ifa_rtnl(ifa, in_dev) {
if (!buf) { if (!buf) {
done += size; done += size;
continue; continue;
...@@ -1321,10 +1320,11 @@ EXPORT_SYMBOL(inet_select_addr); ...@@ -1321,10 +1320,11 @@ EXPORT_SYMBOL(inet_select_addr);
static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst, static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
__be32 local, int scope) __be32 local, int scope)
{ {
int same = 0; const struct in_ifaddr *ifa;
__be32 addr = 0; __be32 addr = 0;
int same = 0;
for_ifa(in_dev) { in_dev_for_each_ifa_rcu(ifa, in_dev) {
if (!addr && if (!addr &&
(local == ifa->ifa_local || !local) && (local == ifa->ifa_local || !local) &&
ifa->ifa_scope <= scope) { ifa->ifa_scope <= scope) {
...@@ -1350,7 +1350,7 @@ static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst, ...@@ -1350,7 +1350,7 @@ static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
same = 0; same = 0;
} }
} }
} endfor_ifa(in_dev); }
return same ? addr : 0; return same ? addr : 0;
} }
...@@ -1424,7 +1424,7 @@ static void inetdev_changename(struct net_device *dev, struct in_device *in_dev) ...@@ -1424,7 +1424,7 @@ static void inetdev_changename(struct net_device *dev, struct in_device *in_dev)
struct in_ifaddr *ifa; struct in_ifaddr *ifa;
int named = 0; int named = 0;
for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { in_dev_for_each_ifa_rtnl(ifa, in_dev) {
char old[IFNAMSIZ], *dot; char old[IFNAMSIZ], *dot;
memcpy(old, ifa->ifa_label, IFNAMSIZ); memcpy(old, ifa->ifa_label, IFNAMSIZ);
...@@ -1454,10 +1454,9 @@ static void inetdev_send_gratuitous_arp(struct net_device *dev, ...@@ -1454,10 +1454,9 @@ static void inetdev_send_gratuitous_arp(struct net_device *dev,
struct in_device *in_dev) struct in_device *in_dev)
{ {
struct in_ifaddr *ifa; const struct in_ifaddr *ifa;
for (ifa = in_dev->ifa_list; ifa; in_dev_for_each_ifa_rtnl(ifa, in_dev) {
ifa = ifa->ifa_next) {
arp_send(ARPOP_REQUEST, ETH_P_ARP, arp_send(ARPOP_REQUEST, ETH_P_ARP,
ifa->ifa_local, dev, ifa->ifa_local, dev,
ifa->ifa_local, NULL, ifa->ifa_local, NULL,
...@@ -1727,15 +1726,17 @@ static int in_dev_dump_addr(struct in_device *in_dev, struct sk_buff *skb, ...@@ -1727,15 +1726,17 @@ static int in_dev_dump_addr(struct in_device *in_dev, struct sk_buff *skb,
int ip_idx = 0; int ip_idx = 0;
int err; int err;
for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next, ip_idx++) { in_dev_for_each_ifa_rcu(ifa, in_dev) {
if (ip_idx < s_ip_idx) if (ip_idx < s_ip_idx) {
ip_idx++;
continue; continue;
}
err = inet_fill_ifaddr(skb, ifa, fillargs); err = inet_fill_ifaddr(skb, ifa, fillargs);
if (err < 0) if (err < 0)
goto done; goto done;
nl_dump_check_consistent(cb, nlmsg_hdr(skb)); nl_dump_check_consistent(cb, nlmsg_hdr(skb));
ip_idx++;
} }
err = 0; err = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment