diff options
Diffstat (limited to 'net/core/dev.c')
-rw-r--r-- | net/core/dev.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index fc1e289397f5..faebb398fb46 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -792,6 +792,40 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex) | |||
792 | EXPORT_SYMBOL(dev_get_by_index); | 792 | EXPORT_SYMBOL(dev_get_by_index); |
793 | 793 | ||
794 | /** | 794 | /** |
795 | * netdev_get_name - get a netdevice name, knowing its ifindex. | ||
796 | * @net: network namespace | ||
797 | * @name: a pointer to the buffer where the name will be stored. | ||
798 | * @ifindex: the ifindex of the interface to get the name from. | ||
799 | * | ||
800 | * The use of raw_seqcount_begin() and cond_resched() before | ||
801 | * retrying is required as we want to give the writers a chance | ||
802 | * to complete when CONFIG_PREEMPT is not set. | ||
803 | */ | ||
804 | int netdev_get_name(struct net *net, char *name, int ifindex) | ||
805 | { | ||
806 | struct net_device *dev; | ||
807 | unsigned int seq; | ||
808 | |||
809 | retry: | ||
810 | seq = raw_seqcount_begin(&devnet_rename_seq); | ||
811 | rcu_read_lock(); | ||
812 | dev = dev_get_by_index_rcu(net, ifindex); | ||
813 | if (!dev) { | ||
814 | rcu_read_unlock(); | ||
815 | return -ENODEV; | ||
816 | } | ||
817 | |||
818 | strcpy(name, dev->name); | ||
819 | rcu_read_unlock(); | ||
820 | if (read_seqcount_retry(&devnet_rename_seq, seq)) { | ||
821 | cond_resched(); | ||
822 | goto retry; | ||
823 | } | ||
824 | |||
825 | return 0; | ||
826 | } | ||
827 | |||
828 | /** | ||
795 | * dev_getbyhwaddr_rcu - find a device by its hardware address | 829 | * dev_getbyhwaddr_rcu - find a device by its hardware address |
796 | * @net: the applicable net namespace | 830 | * @net: the applicable net namespace |
797 | * @type: media type of device | 831 | * @type: media type of device |