diff options
| author | Antoine Tenart <atenart@kernel.org> | 2021-10-07 18:16:50 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-10-25 11:59:01 +0200 |
| commit | 30e2db4030328f50cf5b3b5994ca0bc7349b2660 (patch) | |
| tree | 19cf02a50f627f07a4db6682a83d1aa190005986 /include | |
| parent | 38ba5479355b23376557c30cfeca03ad92798c6b (diff) | |
| download | linux-30e2db4030328f50cf5b3b5994ca0bc7349b2660.tar.gz linux-30e2db4030328f50cf5b3b5994ca0bc7349b2660.tar.bz2 linux-30e2db4030328f50cf5b3b5994ca0bc7349b2660.zip | |
net: introduce a function to check if a netdev name is in use
[ Upstream commit 75ea27d0d62281c31ee259c872dfdeb072cf5e39 ]
__dev_get_by_name is currently used to either retrieve a net device
reference using its name or to check if a name is already used by a
registered net device (per ns). In the later case there is no need to
return a reference to a net device.
Introduce a new helper, netdev_name_in_use, to check if a name is
currently used by a registered net device without leaking a reference
the corresponding net device. This helper uses netdev_name_node_lookup
instead of __dev_get_by_name as we don't need the extra logic retrieving
a reference to the corresponding net device.
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: 311cca40661f ("net: fix ifname in netlink ntf during netns move")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/netdevice.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b5df2e59a51d..132f4344fee9 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2978,6 +2978,7 @@ struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags, struct net_device *dev_get_by_name(struct net *net, const char *name); struct net_device *dev_get_by_name_rcu(struct net *net, const char *name); struct net_device *__dev_get_by_name(struct net *net, const char *name); +bool netdev_name_in_use(struct net *net, const char *name); int dev_alloc_name(struct net_device *dev, const char *name); int dev_open(struct net_device *dev, struct netlink_ext_ack *extack); void dev_close(struct net_device *dev); |
