@@ -1012,6 +1012,12 @@ int netdev_get_name(struct net *net, char *name, int ifindex)
1012
1012
return ret ;
1013
1013
}
1014
1014
1015
+ static bool dev_addr_cmp (struct net_device * dev , unsigned short type ,
1016
+ const char * ha )
1017
+ {
1018
+ return dev -> type == type && !memcmp (dev -> dev_addr , ha , dev -> addr_len );
1019
+ }
1020
+
1015
1021
/**
1016
1022
* dev_getbyhwaddr_rcu - find a device by its hardware address
1017
1023
* @net: the applicable net namespace
@@ -1020,7 +1026,7 @@ int netdev_get_name(struct net *net, char *name, int ifindex)
1020
1026
*
1021
1027
* Search for an interface by MAC address. Returns NULL if the device
1022
1028
* is not found or a pointer to the device.
1023
- * The caller must hold RCU or RTNL .
1029
+ * The caller must hold RCU.
1024
1030
* The returned device has not had its ref count increased
1025
1031
* and the caller must therefore be careful about locking
1026
1032
*
@@ -1032,14 +1038,39 @@ struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
1032
1038
struct net_device * dev ;
1033
1039
1034
1040
for_each_netdev_rcu (net , dev )
1035
- if (dev -> type == type &&
1036
- !memcmp (dev -> dev_addr , ha , dev -> addr_len ))
1041
+ if (dev_addr_cmp (dev , type , ha ))
1037
1042
return dev ;
1038
1043
1039
1044
return NULL ;
1040
1045
}
1041
1046
EXPORT_SYMBOL (dev_getbyhwaddr_rcu );
1042
1047
1048
+ /**
1049
+ * dev_getbyhwaddr() - find a device by its hardware address
1050
+ * @net: the applicable net namespace
1051
+ * @type: media type of device
1052
+ * @ha: hardware address
1053
+ *
1054
+ * Similar to dev_getbyhwaddr_rcu(), but the owner needs to hold
1055
+ * rtnl_lock.
1056
+ *
1057
+ * Context: rtnl_lock() must be held.
1058
+ * Return: pointer to the net_device, or NULL if not found
1059
+ */
1060
+ struct net_device * dev_getbyhwaddr (struct net * net , unsigned short type ,
1061
+ const char * ha )
1062
+ {
1063
+ struct net_device * dev ;
1064
+
1065
+ ASSERT_RTNL ();
1066
+ for_each_netdev (net , dev )
1067
+ if (dev_addr_cmp (dev , type , ha ))
1068
+ return dev ;
1069
+
1070
+ return NULL ;
1071
+ }
1072
+ EXPORT_SYMBOL (dev_getbyhwaddr );
1073
+
1043
1074
struct net_device * dev_getfirstbyhwtype (struct net * net , unsigned short type )
1044
1075
{
1045
1076
struct net_device * dev , * ret = NULL ;
0 commit comments