summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2019-05-31 12:27:07 -0400
committerDavid S. Miller <davem@davemloft.net>2019-06-02 21:06:26 -0400
commitcd5a411dbaeb9fd70e2a8241a74b6f52a1a572ca (patch)
tree8bf4492b4e338e119927028e1a3a9a2f8959a224
parentb8d19572367bb019f77bbc921ef6bf965f1c8b22 (diff)
net: use new in_dev_ifa iterators
Use in_dev_for_each_ifa_rcu/rtnl instead. This prevents sparse warnings once proper __rcu annotations are added. Signed-off-by: Florian Westphal <fw@strlen.de> t di# Last commands done (6 commands done): Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/fib_frontend.c24
-rw-r--r--net/ipv4/igmp.c5
-rw-r--r--net/ipv6/addrconf.c4
-rw-r--r--net/sctp/protocol.c2
-rw-r--r--net/smc/smc_clc.c11
5 files changed, 29 insertions, 17 deletions
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 76055c66326a..c7cdb8d0d164 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -540,14 +540,22 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
540 cfg->fc_oif = dev->ifindex; 540 cfg->fc_oif = dev->ifindex;
541 cfg->fc_table = l3mdev_fib_table(dev); 541 cfg->fc_table = l3mdev_fib_table(dev);
542 if (colon) { 542 if (colon) {
543 struct in_ifaddr *ifa; 543 const struct in_ifaddr *ifa;
544 struct in_device *in_dev = __in_dev_get_rtnl(dev); 544 struct in_device *in_dev;
545
546 in_dev = __in_dev_get_rtnl(dev);
545 if (!in_dev) 547 if (!in_dev)
546 return -ENODEV; 548 return -ENODEV;
549
547 *colon = ':'; 550 *colon = ':';
548 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) 551
552 rcu_read_lock();
553 in_dev_for_each_ifa_rcu(ifa, in_dev) {
549 if (strcmp(ifa->ifa_label, devname) == 0) 554 if (strcmp(ifa->ifa_label, devname) == 0)
550 break; 555 break;
556 }
557 rcu_read_unlock();
558
551 if (!ifa) 559 if (!ifa)
552 return -ENODEV; 560 return -ENODEV;
553 cfg->fc_prefsrc = ifa->ifa_local; 561 cfg->fc_prefsrc = ifa->ifa_local;
@@ -1177,8 +1185,8 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
1177 * 1185 *
1178 * Scan address list to be sure that addresses are really gone. 1186 * Scan address list to be sure that addresses are really gone.
1179 */ 1187 */
1180 1188 rcu_read_lock();
1181 for (ifa1 = in_dev->ifa_list; ifa1; ifa1 = ifa1->ifa_next) { 1189 in_dev_for_each_ifa_rcu(ifa1, in_dev) {
1182 if (ifa1 == ifa) { 1190 if (ifa1 == ifa) {
1183 /* promotion, keep the IP */ 1191 /* promotion, keep the IP */
1184 gone = 0; 1192 gone = 0;
@@ -1246,6 +1254,7 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
1246 } 1254 }
1247 } 1255 }
1248 } 1256 }
1257 rcu_read_unlock();
1249 1258
1250no_promotions: 1259no_promotions:
1251 if (!(ok & BRD_OK)) 1260 if (!(ok & BRD_OK))
@@ -1415,6 +1424,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1415 struct netdev_notifier_info_ext *info_ext = ptr; 1424 struct netdev_notifier_info_ext *info_ext = ptr;
1416 struct in_device *in_dev; 1425 struct in_device *in_dev;
1417 struct net *net = dev_net(dev); 1426 struct net *net = dev_net(dev);
1427 struct in_ifaddr *ifa;
1418 unsigned int flags; 1428 unsigned int flags;
1419 1429
1420 if (event == NETDEV_UNREGISTER) { 1430 if (event == NETDEV_UNREGISTER) {
@@ -1429,9 +1439,9 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
1429 1439
1430 switch (event) { 1440 switch (event) {
1431 case NETDEV_UP: 1441 case NETDEV_UP:
1432 for_ifa(in_dev) { 1442 in_dev_for_each_ifa_rtnl(ifa, in_dev) {
1433 fib_add_ifaddr(ifa); 1443 fib_add_ifaddr(ifa);
1434 } endfor_ifa(in_dev); 1444 }
1435#ifdef CONFIG_IP_ROUTE_MULTIPATH 1445#ifdef CONFIG_IP_ROUTE_MULTIPATH
1436 fib_sync_up(dev, RTNH_F_DEAD); 1446 fib_sync_up(dev, RTNH_F_DEAD);
1437#endif 1447#endif
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index eb03153dfe12..fa5732bcfc76 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -336,14 +336,15 @@ static __be32 igmpv3_get_srcaddr(struct net_device *dev,
336 const struct flowi4 *fl4) 336 const struct flowi4 *fl4)
337{ 337{
338 struct in_device *in_dev = __in_dev_get_rcu(dev); 338 struct in_device *in_dev = __in_dev_get_rcu(dev);
339 const struct in_ifaddr *ifa;
339 340
340 if (!in_dev) 341 if (!in_dev)
341 return htonl(INADDR_ANY); 342 return htonl(INADDR_ANY);
342 343
343 for_ifa(in_dev) { 344 in_dev_for_each_ifa_rcu(ifa, in_dev) {
344 if (fl4->saddr == ifa->ifa_local) 345 if (fl4->saddr == ifa->ifa_local)
345 return fl4->saddr; 346 return fl4->saddr;
346 } endfor_ifa(in_dev); 347 }
347 348
348 return htonl(INADDR_ANY); 349 return htonl(INADDR_ANY);
349} 350}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 6b673d4f5ca9..4c30726fa7c7 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3127,11 +3127,9 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
3127 struct in_device *in_dev = __in_dev_get_rtnl(dev); 3127 struct in_device *in_dev = __in_dev_get_rtnl(dev);
3128 if (in_dev && (dev->flags & IFF_UP)) { 3128 if (in_dev && (dev->flags & IFF_UP)) {
3129 struct in_ifaddr *ifa; 3129 struct in_ifaddr *ifa;
3130
3131 int flag = scope; 3130 int flag = scope;
3132 3131
3133 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { 3132 in_dev_for_each_ifa_rtnl(ifa, in_dev) {
3134
3135 addr.s6_addr32[3] = ifa->ifa_local; 3133 addr.s6_addr32[3] = ifa->ifa_local;
3136 3134
3137 if (ifa->ifa_scope == RT_SCOPE_LINK) 3135 if (ifa->ifa_scope == RT_SCOPE_LINK)
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 23af232c0a25..2d47adcb4cbe 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -81,7 +81,7 @@ static void sctp_v4_copy_addrlist(struct list_head *addrlist,
81 return; 81 return;
82 } 82 }
83 83
84 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { 84 in_dev_for_each_ifa_rcu(ifa, in_dev) {
85 /* Add the address to the local list. */ 85 /* Add the address to the local list. */
86 addr = kzalloc(sizeof(*addr), GFP_ATOMIC); 86 addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
87 if (addr) { 87 if (addr) {
diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
index 745afd82f281..49bcebff6378 100644
--- a/net/smc/smc_clc.c
+++ b/net/smc/smc_clc.c
@@ -97,17 +97,19 @@ static int smc_clc_prfx_set4_rcu(struct dst_entry *dst, __be32 ipv4,
97 struct smc_clc_msg_proposal_prefix *prop) 97 struct smc_clc_msg_proposal_prefix *prop)
98{ 98{
99 struct in_device *in_dev = __in_dev_get_rcu(dst->dev); 99 struct in_device *in_dev = __in_dev_get_rcu(dst->dev);
100 const struct in_ifaddr *ifa;
100 101
101 if (!in_dev) 102 if (!in_dev)
102 return -ENODEV; 103 return -ENODEV;
103 for_ifa(in_dev) { 104
105 in_dev_for_each_ifa_rcu(ifa, in_dev) {
104 if (!inet_ifa_match(ipv4, ifa)) 106 if (!inet_ifa_match(ipv4, ifa))
105 continue; 107 continue;
106 prop->prefix_len = inet_mask_len(ifa->ifa_mask); 108 prop->prefix_len = inet_mask_len(ifa->ifa_mask);
107 prop->outgoing_subnet = ifa->ifa_address & ifa->ifa_mask; 109 prop->outgoing_subnet = ifa->ifa_address & ifa->ifa_mask;
108 /* prop->ipv6_prefixes_cnt = 0; already done by memset before */ 110 /* prop->ipv6_prefixes_cnt = 0; already done by memset before */
109 return 0; 111 return 0;
110 } endfor_ifa(in_dev); 112 }
111 return -ENOENT; 113 return -ENOENT;
112} 114}
113 115
@@ -190,14 +192,15 @@ static int smc_clc_prfx_match4_rcu(struct net_device *dev,
190 struct smc_clc_msg_proposal_prefix *prop) 192 struct smc_clc_msg_proposal_prefix *prop)
191{ 193{
192 struct in_device *in_dev = __in_dev_get_rcu(dev); 194 struct in_device *in_dev = __in_dev_get_rcu(dev);
195 const struct in_ifaddr *ifa;
193 196
194 if (!in_dev) 197 if (!in_dev)
195 return -ENODEV; 198 return -ENODEV;
196 for_ifa(in_dev) { 199 in_dev_for_each_ifa_rcu(ifa, in_dev) {
197 if (prop->prefix_len == inet_mask_len(ifa->ifa_mask) && 200 if (prop->prefix_len == inet_mask_len(ifa->ifa_mask) &&
198 inet_ifa_match(prop->outgoing_subnet, ifa)) 201 inet_ifa_match(prop->outgoing_subnet, ifa))
199 return 0; 202 return 0;
200 } endfor_ifa(in_dev); 203 }
201 204
202 return -ENOENT; 205 return -ENOENT;
203} 206}