@@ -63,12 +63,6 @@ typedef struct NetNames {
63
63
char bcma_core [ALTIFNAMSIZ ];
64
64
} NetNames ;
65
65
66
- typedef struct LinkInfo {
67
- int ifindex ;
68
- int iflink ;
69
- int iftype ;
70
- } LinkInfo ;
71
-
72
66
/* skip intermediate virtio devices */
73
67
static sd_device * skip_virtio (sd_device * dev ) {
74
68
/* there can only ever be one virtio bus per parent device, so we can
@@ -266,13 +260,12 @@ static int pci_get_onboard_index(sd_device *dev, unsigned *ret) {
266
260
return 0 ;
267
261
}
268
262
269
- static int dev_pci_onboard (sd_device * dev , const LinkInfo * info , NetNames * names ) {
263
+ static int dev_pci_onboard (sd_device * dev , NetNames * names ) {
270
264
_cleanup_free_ char * port = NULL ;
271
265
unsigned idx = 0 ; /* avoid false maybe-uninitialized warning */
272
266
int r ;
273
267
274
268
assert (dev );
275
- assert (info );
276
269
assert (names );
277
270
278
271
/* retrieve on-board index number and label from firmware */
@@ -306,6 +299,8 @@ static int is_pci_multifunction(sd_device *dev) {
306
299
size_t len ;
307
300
int r ;
308
301
302
+ assert (dev );
303
+
309
304
r = sd_device_get_syspath (dev , & syspath );
310
305
if (r < 0 )
311
306
return r ;
@@ -326,17 +321,16 @@ static int is_pci_multifunction(sd_device *dev) {
326
321
}
327
322
328
323
static bool is_pci_ari_enabled (sd_device * dev ) {
329
- const char * a ;
330
-
331
- if (sd_device_get_sysattr_value (dev , "ari_enabled" , & a ) < 0 )
332
- return false;
324
+ assert (dev );
333
325
334
- return streq ( a , "1" ) ;
326
+ return device_get_sysattr_bool ( dev , "ari_enabled" ) > 0 ;
335
327
}
336
328
337
329
static bool is_pci_bridge (sd_device * dev ) {
338
330
const char * v , * p ;
339
331
332
+ assert (dev );
333
+
340
334
if (sd_device_get_sysattr_value (dev , "modalias" , & v ) < 0 )
341
335
return false;
342
336
@@ -563,13 +557,12 @@ static int get_pci_slot_specifiers(
563
557
return 0 ;
564
558
}
565
559
566
- static int dev_pci_slot (sd_device * dev , const LinkInfo * info , NetNames * names ) {
560
+ static int dev_pci_slot (sd_device * dev , NetNames * names ) {
567
561
_cleanup_free_ char * domain = NULL , * bus_and_slot = NULL , * func = NULL , * port = NULL ;
568
562
uint32_t hotplug_slot = 0 ; /* avoid false maybe-uninitialized warning */
569
563
int r ;
570
564
571
565
assert (dev );
572
- assert (info );
573
566
assert (names );
574
567
575
568
r = get_pci_slot_specifiers (names -> pcidev , & domain , & bus_and_slot , & func );
@@ -847,15 +840,14 @@ static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
847
840
return - ENOENT ;
848
841
}
849
842
850
- static int names_pci (sd_device * dev , const LinkInfo * info , NetNames * names ) {
843
+ static int names_pci (sd_device * dev , NetNames * names ) {
851
844
_cleanup_ (sd_device_unrefp ) sd_device * physfn_pcidev = NULL ;
852
845
_cleanup_free_ char * virtfn_suffix = NULL ;
853
846
sd_device * parent ;
854
847
const char * subsystem ;
855
848
int r ;
856
849
857
850
assert (dev );
858
- assert (info );
859
851
assert (names );
860
852
861
853
r = sd_device_get_parent (dev , & parent );
@@ -884,8 +876,8 @@ static int names_pci(sd_device *dev, const LinkInfo *info, NetNames *names) {
884
876
885
877
/* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
886
878
vf_names .pcidev = physfn_pcidev ;
887
- dev_pci_onboard (dev , info , & vf_names );
888
- dev_pci_slot (dev , info , & vf_names );
879
+ dev_pci_onboard (dev , & vf_names );
880
+ dev_pci_slot (dev , & vf_names );
889
881
890
882
if (vf_names .pci_onboard [0 ])
891
883
if (strlen (vf_names .pci_onboard ) + strlen (virtfn_suffix ) < sizeof (names -> pci_onboard ))
@@ -900,8 +892,8 @@ static int names_pci(sd_device *dev, const LinkInfo *info, NetNames *names) {
900
892
strscpyl (names -> pci_path , sizeof (names -> pci_path ),
901
893
vf_names .pci_path , virtfn_suffix , NULL );
902
894
} else {
903
- dev_pci_onboard (dev , info , names );
904
- dev_pci_slot (dev , info , names );
895
+ dev_pci_onboard (dev , names );
896
+ dev_pci_slot (dev , names );
905
897
}
906
898
907
899
return 0 ;
@@ -956,11 +948,11 @@ static int names_usb(sd_device *dev, NetNames *names) {
956
948
957
949
/* append USB config number, suppress the common config == 1 */
958
950
if (!streq (config , "1" ))
959
- l = strpcpyl (& s , sizeof ( names -> usb_ports ) , "c" , config , NULL );
951
+ l = strpcpyl (& s , l , "c" , config , NULL );
960
952
961
953
/* append USB interface number, suppress the interface == 0 */
962
954
if (!streq (interf , "0" ))
963
- l = strpcpyl (& s , sizeof ( names -> usb_ports ) , "i" , interf , NULL );
955
+ l = strpcpyl (& s , l , "i" , interf , NULL );
964
956
if (l == 0 )
965
957
return log_device_debug_errno (dev , SYNTHETIC_ERRNO (ENAMETOOLONG ),
966
958
"Generated USB name would be too long." );
@@ -1290,41 +1282,32 @@ static int get_ifname_prefix(sd_device *dev, const char **ret) {
1290
1282
}
1291
1283
}
1292
1284
1293
- static int get_link_info (sd_device * dev , LinkInfo * info ) {
1294
- int r ;
1285
+ static int device_is_stacked (sd_device * dev ) {
1286
+ int ifindex , iflink , r ;
1295
1287
1296
1288
assert (dev );
1297
- assert (info );
1298
1289
1299
- r = sd_device_get_ifindex (dev , & info -> ifindex );
1290
+ r = sd_device_get_ifindex (dev , & ifindex );
1300
1291
if (r < 0 )
1301
1292
return r ;
1302
1293
1303
- r = device_get_sysattr_int (dev , "iflink" , & info -> iflink );
1294
+ r = device_get_sysattr_int (dev , "iflink" , & iflink );
1304
1295
if (r < 0 )
1305
1296
return r ;
1306
1297
1307
- r = device_get_sysattr_int (dev , "type" , & info -> iftype );
1308
- if (r < 0 )
1309
- return r ;
1310
-
1311
- return 0 ;
1298
+ return ifindex != iflink ;
1312
1299
}
1313
1300
1314
1301
static int builtin_net_id (UdevEvent * event , int argc , char * argv [], bool test ) {
1315
1302
sd_device * dev = ASSERT_PTR (ASSERT_PTR (event )-> dev );
1316
1303
const char * prefix ;
1317
1304
NetNames names = {};
1318
- LinkInfo info = {};
1319
1305
int r ;
1320
1306
1321
- r = get_link_info (dev , & info );
1322
- if (r < 0 )
1323
- return r ;
1324
-
1325
1307
/* skip stacked devices, like VLANs, ... */
1326
- if (info .ifindex != info .iflink )
1327
- return 0 ;
1308
+ r = device_is_stacked (dev );
1309
+ if (r != 0 )
1310
+ return r ;
1328
1311
1329
1312
r = get_ifname_prefix (dev , & prefix );
1330
1313
if (r < 0 ) {
@@ -1343,7 +1326,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
1343
1326
(void ) names_xen (dev , prefix , test );
1344
1327
1345
1328
/* get PCI based path names */
1346
- r = names_pci (dev , & info , & names );
1329
+ r = names_pci (dev , & names );
1347
1330
if (r < 0 ) {
1348
1331
/*
1349
1332
* check for usb devices that are not off pci interfaces to
0 commit comments