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