Skip to content

Commit 4e985ad

Browse files
Thomas Grafdavem330
authored andcommitted
rtnl: provide link dump consistency info
This patch adds a change sequence counter to each net namespace which is bumped whenever a netdevice is added or removed from the list. If such a change occurred while a link dump took place, the dump will have the NLM_F_DUMP_INTR flag set in the first message which has been interrupted and in all subsequent messages of the same dump. Note that links may still be modified or renamed while a dump is taking place but we can guarantee for userspace to receive a complete list of links and not miss any. Testing: I have added 500 VLAN netdevices to make sure the dump is split over multiple messages. Then while continuously dumping links in one process I also continuously deleted and re-added a dummy netdevice in another process. Multiple dumps per seconds have had the NLM_F_DUMP_INTR flag set. I guess we can wait for Johannes patch to hit net-next via the wireless tree. I just wanted to give this some testing right away. Signed-off-by: Thomas Graf <tgraf@infradead.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e77aeb7 commit 4e985ad

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct net {
6565
struct list_head dev_base_head;
6666
struct hlist_head *dev_name_head;
6767
struct hlist_head *dev_index_head;
68+
unsigned int dev_base_seq; /* protected by rtnl_mutex */
6869

6970
/* core fib_rules */
7071
struct list_head rules_ops;

‎net/core/dev.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ static struct list_head ptype_all __read_mostly; /* Taps */
199199
DEFINE_RWLOCK(dev_base_lock);
200200
EXPORT_SYMBOL(dev_base_lock);
201201

202+
static inline void dev_base_seq_inc(struct net *net)
203+
{
204+
while (++net->dev_base_seq == 0);
205+
}
206+
202207
static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
203208
{
204209
unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
@@ -237,6 +242,9 @@ static int list_netdevice(struct net_device *dev)
237242
hlist_add_head_rcu(&dev->index_hlist,
238243
dev_index_hash(net, dev->ifindex));
239244
write_unlock_bh(&dev_base_lock);
245+
246+
dev_base_seq_inc(net);
247+
240248
return 0;
241249
}
242250

@@ -253,6 +261,8 @@ static void unlist_netdevice(struct net_device *dev)
253261
hlist_del_rcu(&dev->name_hlist);
254262
hlist_del_rcu(&dev->index_hlist);
255263
write_unlock_bh(&dev_base_lock);
264+
265+
dev_base_seq_inc(dev_net(dev));
256266
}
257267

258268
/*

‎net/core/net_namespace.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ static __net_init int setup_net(struct net *net)
129129

130130
atomic_set(&net->count, 1);
131131
atomic_set(&net->passive, 1);
132+
net->dev_base_seq = 1;
132133

133134
#ifdef NETNS_REFCNT_DEBUG
134135
atomic_set(&net->use_count, 0);

‎net/core/rtnetlink.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
10321032
s_idx = cb->args[1];
10331033

10341034
rcu_read_lock();
1035+
cb->seq = net->dev_base_seq;
1036+
10351037
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
10361038
idx = 0;
10371039
head = &net->dev_index_head[h];
@@ -1043,6 +1045,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
10431045
cb->nlh->nlmsg_seq, 0,
10441046
NLM_F_MULTI) <= 0)
10451047
goto out;
1048+
1049+
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
10461050
cont:
10471051
idx++;
10481052
}

0 commit comments

Comments
 (0)