summaryrefslogtreecommitdiffstats
path: root/src/udev/udev-builtin-net_id.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-03-28 08:24:59 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-03-29 01:33:07 +0100
commit089bef66316e5bdc91b9984148e5a6455449c1da (patch)
treef2bc54ab62d00d6d775a76dc94d47825b72da574 /src/udev/udev-builtin-net_id.c
parentudev-event: split out update_clone() (diff)
downloadsystemd-089bef66316e5bdc91b9984148e5a6455449c1da.tar.xz
systemd-089bef66316e5bdc91b9984148e5a6455449c1da.zip
udev: make udevadm test and test-builtin not destructive
Previously, 'udevadm test' performs not only processing udev rules, but made several destructive change on the system; updating udev database, device node permission, devlinks, network interface properties, and so on. Similary, 'udevadm test-builtin' may perform something destructive, especially by 'keyboard', 'kmod', and 'net_setup_link' builtins. Let's make these commands and test executables not change device configurations.
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r--src/udev/udev-builtin-net_id.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 8ef3abada9..0d87a35288 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -298,7 +298,7 @@ static int pci_get_onboard_index(sd_device *dev, unsigned *ret) {
return 0;
}
-static int names_pci_onboard(sd_device *dev, sd_device *pci_dev, const char *prefix, const char *suffix, bool test) {
+static int names_pci_onboard(sd_device *dev, sd_device *pci_dev, const char *prefix, const char *suffix, EventMode mode) {
_cleanup_free_ char *port = NULL;
unsigned idx = 0; /* avoid false maybe-uninitialized warning */
int r;
@@ -318,7 +318,7 @@ static int names_pci_onboard(sd_device *dev, sd_device *pci_dev, const char *pre
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%so%u%s%s", prefix, idx, strempty(port), strempty(suffix)))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_ONBOARD", str);
log_device_debug(dev, "Onboard index identifier: index=%u port=%s %s %s",
idx, strna(port),
@@ -327,7 +327,7 @@ static int names_pci_onboard(sd_device *dev, sd_device *pci_dev, const char *pre
return 0;
}
-static int names_pci_onboard_label(sd_device *dev, sd_device *pci_dev, const char *prefix, bool test) {
+static int names_pci_onboard_label(sd_device *dev, sd_device *pci_dev, const char *prefix, EventMode mode) {
const char *label;
int r;
@@ -343,7 +343,7 @@ static int names_pci_onboard_label(sd_device *dev, sd_device *pci_dev, const cha
if (snprintf_ok(str, sizeof str, "%s%s",
naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix,
label))
- udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_LABEL_ONBOARD", str);
log_device_debug(dev, "Onboard label from PCI device: %s", label);
return 0;
@@ -613,7 +613,7 @@ static int get_pci_slot_specifiers(
return 0;
}
-static int names_pci_slot(sd_device *dev, sd_device *pci_dev, const char *prefix, const char *suffix, bool test) {
+static int names_pci_slot(sd_device *dev, sd_device *pci_dev, const char *prefix, const char *suffix, EventMode mode) {
_cleanup_free_ char *domain = NULL, *bus_and_slot = NULL, *func = NULL, *port = NULL;
uint32_t hotplug_slot = 0; /* avoid false maybe-uninitialized warning */
char str[ALTIFNAMSIZ];
@@ -634,7 +634,7 @@ static int names_pci_slot(sd_device *dev, sd_device *pci_dev, const char *prefix
/* compose a name based on the raw kernel's PCI bus, slot numbers */
if (snprintf_ok(str, sizeof str, "%s%s%s%s%s%s",
prefix, strempty(domain), bus_and_slot, strempty(func), strempty(port), strempty(suffix)))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_PATH", str);
log_device_debug(dev, "PCI path identifier: domain=%s bus_and_slot=%s func=%s port=%s %s %s",
strna(domain), bus_and_slot, strna(func), strna(port),
@@ -650,7 +650,7 @@ static int names_pci_slot(sd_device *dev, sd_device *pci_dev, const char *prefix
if (snprintf_ok(str, sizeof str, "%s%ss%"PRIu32"%s%s%s",
prefix, strempty(domain), hotplug_slot, strempty(func), strempty(port), strempty(suffix)))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_SLOT", str);
log_device_debug(dev, "Slot identifier: domain=%s slot=%"PRIu32" func=%s port=%s %s %s",
strna(domain), hotplug_slot, strna(func), strna(port),
@@ -659,7 +659,7 @@ static int names_pci_slot(sd_device *dev, sd_device *pci_dev, const char *prefix
return 0;
}
-static int names_vio(sd_device *dev, const char *prefix, bool test) {
+static int names_vio(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_free_ char *s = NULL;
unsigned slotid;
int r;
@@ -698,13 +698,13 @@ static int names_vio(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sv%u", prefix, slotid))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_SLOT", str);
log_device_debug(dev, "Vio slot identifier: slotid=%u %s %s",
slotid, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
}
-static int names_platform(sd_device *dev, const char *prefix, bool test) {
+static int names_platform(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_free_ char *p = NULL;
const char *validchars;
char *vendor, *model_str, *instance_str;
@@ -760,13 +760,13 @@ static int names_platform(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sa%s%xi%u", prefix, vendor, model, instance))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_PATH", str);
log_device_debug(dev, "Platform identifier: vendor=%s model=%x instance=%u %s %s",
vendor, model, instance, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
}
-static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
+static int names_devicetree(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_(sd_device_unrefp) sd_device *aliases_dev = NULL, *ofnode_dev = NULL, *devicetree_dev = NULL;
const char *ofnode_path, *ofnode_syspath, *devicetree_syspath;
sd_device *parent;
@@ -858,7 +858,7 @@ static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sd%u", prefix, i))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_ONBOARD", str);
log_device_debug(dev, "devicetree identifier: alias_index=%u %s \"%s\"",
i, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
@@ -867,7 +867,7 @@ static int names_devicetree(sd_device *dev, const char *prefix, bool test) {
return -ENOENT;
}
-static int names_pci(sd_device *dev, const char *prefix, bool test) {
+static int names_pci(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
_cleanup_free_ char *virtfn_suffix = NULL;
sd_device *parent;
@@ -884,10 +884,10 @@ static int names_pci(sd_device *dev, const char *prefix, bool test) {
get_virtfn_info(parent, &physfn_pcidev, &virtfn_suffix) >= 0)
parent = physfn_pcidev;
else
- (void) names_pci_onboard_label(dev, parent, prefix, test);
+ (void) names_pci_onboard_label(dev, parent, prefix, mode);
- (void) names_pci_onboard(dev, parent, prefix, virtfn_suffix, test);
- (void) names_pci_slot(dev, parent, prefix, virtfn_suffix, test);
+ (void) names_pci_onboard(dev, parent, prefix, virtfn_suffix, mode);
+ (void) names_pci_slot(dev, parent, prefix, virtfn_suffix, mode);
return 0;
}
@@ -950,7 +950,7 @@ static int get_usb_specifier(sd_device *dev, char **ret) {
return 0;
}
-static int names_usb(sd_device *dev, const char *prefix, bool test) {
+static int names_usb(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_free_ char *suffix = NULL;
sd_device *usbdev, *pcidev;
int r;
@@ -971,7 +971,7 @@ static int names_usb(sd_device *dev, const char *prefix, bool test) {
/* If the USB bus is on PCI bus, then suffix the USB specifier to the name based on the PCI bus. */
r = sd_device_get_parent_with_subsystem_devtype(usbdev, "pci", NULL, &pcidev);
if (r >= 0)
- return names_pci_slot(dev, pcidev, prefix, suffix, test);
+ return names_pci_slot(dev, pcidev, prefix, suffix, mode);
if (r != -ENOENT || !naming_scheme_has(NAMING_USB_HOST))
return log_device_debug_errno(usbdev, r, "Failed to get parent PCI bus: %m");
@@ -979,7 +979,7 @@ static int names_usb(sd_device *dev, const char *prefix, bool test) {
/* Otherwise, e.g. on-chip asics that have USB ports, use the USB specifier as is. */
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, suffix))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_PATH", str);
return 0;
}
@@ -1014,7 +1014,7 @@ static int get_bcma_specifier(sd_device *dev, char **ret) {
return 0;
}
-static int names_bcma(sd_device *dev, const char *prefix, bool test) {
+static int names_bcma(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_free_ char *suffix = NULL;
sd_device *bcmadev, *pcidev;
int r;
@@ -1034,10 +1034,10 @@ static int names_bcma(sd_device *dev, const char *prefix, bool test) {
if (r < 0)
return r;
- return names_pci_slot(dev, pcidev, prefix, suffix, test);
+ return names_pci_slot(dev, pcidev, prefix, suffix, mode);
}
-static int names_ccw(sd_device *dev, const char *prefix, bool test) {
+static int names_ccw(sd_device *dev, const char *prefix, EventMode mode) {
sd_device *cdev;
const char *bus_id;
size_t bus_id_start, bus_id_len;
@@ -1079,14 +1079,14 @@ static int names_ccw(sd_device *dev, const char *prefix, bool test) {
/* Use the CCW bus-ID as network device name */
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sc%s", prefix, bus_id))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_PATH", str);
log_device_debug(dev, "CCW identifier: ccw_busid=%s %s \"%s\"",
bus_id, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
}
/* IEEE Organizationally Unique Identifier vendor string */
-static int ieee_oui(sd_device *dev, const struct hw_addr_data *hw_addr, bool test) {
+static int ieee_oui(sd_device *dev, const struct hw_addr_data *hw_addr, EventMode mode) {
char str[32];
assert(dev);
@@ -1109,10 +1109,10 @@ static int ieee_oui(sd_device *dev, const struct hw_addr_data *hw_addr, bool tes
hw_addr->bytes[4],
hw_addr->bytes[5]);
- return udev_builtin_hwdb_lookup(dev, NULL, str, NULL, test);
+ return udev_builtin_hwdb_lookup(dev, NULL, str, NULL, mode);
}
-static int names_mac(sd_device *dev, const char *prefix, bool test) {
+static int names_mac(sd_device *dev, const char *prefix, EventMode mode) {
unsigned iftype, assign_type;
struct hw_addr_data hw_addr;
const char *s;
@@ -1156,16 +1156,16 @@ static int names_mac(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
xsprintf(str, "%sx%s", prefix, HW_ADDR_TO_STR_FULL(&hw_addr, HW_ADDR_TO_STRING_NO_COLON));
- udev_builtin_add_property(dev, test, "ID_NET_NAME_MAC", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_MAC", str);
log_device_debug(dev, "MAC address identifier: hw_addr=%s %s %s",
HW_ADDR_TO_STR(&hw_addr),
special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
- (void) ieee_oui(dev, &hw_addr, test);
+ (void) ieee_oui(dev, &hw_addr, mode);
return 0;
}
-static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
+static int names_netdevsim(sd_device *dev, const char *prefix, EventMode mode) {
sd_device *netdevsimdev;
const char *sysnum, *phys_port_name;
unsigned addr;
@@ -1200,13 +1200,13 @@ static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%si%un%s", prefix, addr, phys_port_name))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_PATH", str);
log_device_debug(dev, "Netdevsim identifier: address=%u, port_name=%s %s %s",
addr, phys_port_name, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
}
-static int names_xen(sd_device *dev, const char *prefix, bool test) {
+static int names_xen(sd_device *dev, const char *prefix, EventMode mode) {
_cleanup_free_ char *vif = NULL;
const char *p;
unsigned id;
@@ -1240,7 +1240,7 @@ static int names_xen(sd_device *dev, const char *prefix, bool test) {
char str[ALTIFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%sX%u", prefix, id))
- udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
+ udev_builtin_add_property(dev, mode, "ID_NET_NAME_SLOT", str);
log_device_debug(dev, "Xen identifier: id=%u %s %s",
id, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
return 0;
@@ -1300,7 +1300,7 @@ static int device_is_stacked(sd_device *dev) {
return ifindex != iflink;
}
-static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
+static int builtin_net_id(UdevEvent *event, int argc, char *argv[]) {
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
const char *prefix;
int r;
@@ -1318,18 +1318,18 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
return 0;
}
- udev_builtin_add_property(dev, test, "ID_NET_NAMING_SCHEME", naming_scheme()->name);
-
- (void) names_mac(dev, prefix, test);
- (void) names_devicetree(dev, prefix, test);
- (void) names_ccw(dev, prefix, test);
- (void) names_vio(dev, prefix, test);
- (void) names_platform(dev, prefix, test);
- (void) names_netdevsim(dev, prefix, test);
- (void) names_xen(dev, prefix, test);
- (void) names_pci(dev, prefix, test);
- (void) names_usb(dev, prefix, test);
- (void) names_bcma(dev, prefix, test);
+ udev_builtin_add_property(dev, event->event_mode, "ID_NET_NAMING_SCHEME", naming_scheme()->name);
+
+ (void) names_mac(dev, prefix, event->event_mode);
+ (void) names_devicetree(dev, prefix, event->event_mode);
+ (void) names_ccw(dev, prefix, event->event_mode);
+ (void) names_vio(dev, prefix, event->event_mode);
+ (void) names_platform(dev, prefix, event->event_mode);
+ (void) names_netdevsim(dev, prefix, event->event_mode);
+ (void) names_xen(dev, prefix, event->event_mode);
+ (void) names_pci(dev, prefix, event->event_mode);
+ (void) names_usb(dev, prefix, event->event_mode);
+ (void) names_bcma(dev, prefix, event->event_mode);
return 0;
}