@@ -1121,6 +1121,12 @@ int netdev_get_name(struct net *net, char *name, int ifindex)
1121
1121
return ret ;
1122
1122
}
1123
1123
1124
+ static bool dev_addr_cmp (struct net_device * dev , unsigned short type ,
1125
+ const char * ha )
1126
+ {
1127
+ return dev -> type == type && !memcmp (dev -> dev_addr , ha , dev -> addr_len );
1128
+ }
1129
+
1124
1130
/**
1125
1131
* dev_getbyhwaddr_rcu - find a device by its hardware address
1126
1132
* @net: the applicable net namespace
@@ -1129,7 +1135,7 @@ int netdev_get_name(struct net *net, char *name, int ifindex)
1129
1135
*
1130
1136
* Search for an interface by MAC address. Returns NULL if the device
1131
1137
* is not found or a pointer to the device.
1132
- * The caller must hold RCU or RTNL .
1138
+ * The caller must hold RCU.
1133
1139
* The returned device has not had its ref count increased
1134
1140
* and the caller must therefore be careful about locking
1135
1141
*
@@ -1141,14 +1147,39 @@ struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
1141
1147
struct net_device * dev ;
1142
1148
1143
1149
for_each_netdev_rcu (net , dev )
1144
- if (dev -> type == type &&
1145
- !memcmp (dev -> dev_addr , ha , dev -> addr_len ))
1150
+ if (dev_addr_cmp (dev , type , ha ))
1146
1151
return dev ;
1147
1152
1148
1153
return NULL ;
1149
1154
}
1150
1155
EXPORT_SYMBOL (dev_getbyhwaddr_rcu );
1151
1156
1157
+ /**
1158
+ * dev_getbyhwaddr() - find a device by its hardware address
1159
+ * @net: the applicable net namespace
1160
+ * @type: media type of device
1161
+ * @ha: hardware address
1162
+ *
1163
+ * Similar to dev_getbyhwaddr_rcu(), but the owner needs to hold
1164
+ * rtnl_lock.
1165
+ *
1166
+ * Context: rtnl_lock() must be held.
1167
+ * Return: pointer to the net_device, or NULL if not found
1168
+ */
1169
+ struct net_device * dev_getbyhwaddr (struct net * net , unsigned short type ,
1170
+ const char * ha )
1171
+ {
1172
+ struct net_device * dev ;
1173
+
1174
+ ASSERT_RTNL ();
1175
+ for_each_netdev (net , dev )
1176
+ if (dev_addr_cmp (dev , type , ha ))
1177
+ return dev ;
1178
+
1179
+ return NULL ;
1180
+ }
1181
+ EXPORT_SYMBOL (dev_getbyhwaddr );
1182
+
1152
1183
struct net_device * dev_getfirstbyhwtype (struct net * net , unsigned short type )
1153
1184
{
1154
1185
struct net_device * dev , * ret = NULL ;
0 commit comments