Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e985ada authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller
Browse files

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: default avatarThomas Graf <tgraf@infradead.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e77aeb71
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ struct net {
	struct list_head 	dev_base_head;
	struct list_head 	dev_base_head;
	struct hlist_head 	*dev_name_head;
	struct hlist_head 	*dev_name_head;
	struct hlist_head	*dev_index_head;
	struct hlist_head	*dev_index_head;
	unsigned int		dev_base_seq;	/* protected by rtnl_mutex */


	/* core fib_rules */
	/* core fib_rules */
	struct list_head	rules_ops;
	struct list_head	rules_ops;
+10 −0
Original line number Original line Diff line number Diff line
@@ -199,6 +199,11 @@ static struct list_head ptype_all __read_mostly; /* Taps */
DEFINE_RWLOCK(dev_base_lock);
DEFINE_RWLOCK(dev_base_lock);
EXPORT_SYMBOL(dev_base_lock);
EXPORT_SYMBOL(dev_base_lock);


static inline void dev_base_seq_inc(struct net *net)
{
	while (++net->dev_base_seq == 0);
}

static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
{
{
	unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
	unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ));
@@ -237,6 +242,9 @@ static int list_netdevice(struct net_device *dev)
	hlist_add_head_rcu(&dev->index_hlist,
	hlist_add_head_rcu(&dev->index_hlist,
			   dev_index_hash(net, dev->ifindex));
			   dev_index_hash(net, dev->ifindex));
	write_unlock_bh(&dev_base_lock);
	write_unlock_bh(&dev_base_lock);

	dev_base_seq_inc(net);

	return 0;
	return 0;
}
}


@@ -253,6 +261,8 @@ static void unlist_netdevice(struct net_device *dev)
	hlist_del_rcu(&dev->name_hlist);
	hlist_del_rcu(&dev->name_hlist);
	hlist_del_rcu(&dev->index_hlist);
	hlist_del_rcu(&dev->index_hlist);
	write_unlock_bh(&dev_base_lock);
	write_unlock_bh(&dev_base_lock);

	dev_base_seq_inc(dev_net(dev));
}
}


/*
/*
+1 −0
Original line number Original line Diff line number Diff line
@@ -129,6 +129,7 @@ static __net_init int setup_net(struct net *net)


	atomic_set(&net->count, 1);
	atomic_set(&net->count, 1);
	atomic_set(&net->passive, 1);
	atomic_set(&net->passive, 1);
	net->dev_base_seq = 1;


#ifdef NETNS_REFCNT_DEBUG
#ifdef NETNS_REFCNT_DEBUG
	atomic_set(&net->use_count, 0);
	atomic_set(&net->use_count, 0);
+4 −0
Original line number Original line Diff line number Diff line
@@ -1032,6 +1032,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
	s_idx = cb->args[1];
	s_idx = cb->args[1];


	rcu_read_lock();
	rcu_read_lock();
	cb->seq = net->dev_base_seq;

	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
		idx = 0;
		idx = 0;
		head = &net->dev_index_head[h];
		head = &net->dev_index_head[h];
@@ -1043,6 +1045,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
					     cb->nlh->nlmsg_seq, 0,
					     cb->nlh->nlmsg_seq, 0,
					     NLM_F_MULTI) <= 0)
					     NLM_F_MULTI) <= 0)
				goto out;
				goto out;

			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
cont:
cont:
			idx++;
			idx++;
		}
		}