X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fudev%2Fudev-builtin-net_id.c;h=c80c30ac77328c0fedfd8d653415e17d3b677148;hb=86e6e5d1b4e78d62d1a45539c1de141bc5e839aa;hp=c3220565ed7232328a0e55aa1c0bd00aac6438f7;hpb=e3d563346c4237af23335cc6904e0662efdf62ad;p=elogind.git diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index c3220565e..c80c30ac7 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -28,10 +28,13 @@ * * Two character prefixes based on the type of interface: * en -- ethernet + * sl -- serial line IP (slip) * wl -- wlan * ww -- wwan * * Type of names: + * b -- BCMA bus core number + * ccw -- CCW bus group name * o -- on-board device index number * s[f][d] -- hotplug slot index number * x -- MAC address @@ -91,6 +94,7 @@ #include #include #include +#include #include #include "udev.h" @@ -102,6 +106,7 @@ enum netname_type{ NET_USB, NET_BCMA, NET_VIRTIO, + NET_CCWGROUP, }; struct netnames { @@ -117,10 +122,8 @@ struct netnames { const char *pci_onboard_label; char usb_ports[IFNAMSIZ]; - char bcma_core[IFNAMSIZ]; - - char virtio_core[IFNAMSIZ]; + char ccw_group[IFNAMSIZ]; }; /* retrieve on-board index number and label from firmware */ @@ -347,22 +350,41 @@ static int names_bcma(struct udev_device *dev, struct netnames *names) { return 0; } -static int names_virtio(struct udev_device *dev, struct netnames *names) { - struct udev_device *virtdev; - unsigned int core; +static int names_ccw(struct udev_device *dev, struct netnames *names) { + struct udev_device *cdev; + const char *bus_id; + size_t bus_id_len; + int rc; + + /* Retrieve the associated CCW device */ + cdev = udev_device_get_parent(dev); + if (!cdev) + return -ENOENT; + + /* Network devices are always grouped CCW devices */ + if (!streq_ptr("ccwgroup", udev_device_get_subsystem(cdev))) + return -ENOENT; - virtdev = udev_device_get_parent_with_subsystem_devtype(dev, "virtio", NULL); - if (!virtdev) + /* Retrieve bus-ID of the grouped CCW device. The bus-ID uniquely + * identifies the network device on the Linux on System z channel + * subsystem. Note that the bus-ID contains lowercase characters. + */ + bus_id = udev_device_get_sysname(cdev); + if (!bus_id) return -ENOENT; - /* core num */ - if (sscanf(udev_device_get_sysname(virtdev), "virtio%u", &core) != 1) + /* Check the length of the bus-ID. Rely on that the kernel provides + * a correct bus-ID; alternatively, improve this check and parse and + * verify each bus-ID part... + */ + bus_id_len = strlen(bus_id); + if (!bus_id_len || bus_id_len < 8 || bus_id_len > 9) return -EINVAL; - /* suppress the common core == 0 */ - if (core > 0) - snprintf(names->virtio_core, sizeof(names->virtio_core), "v%u", core); - names->type = NET_VIRTIO; + /* Store the CCW bus-ID for use as network device name */ + rc = snprintf(names->ccw_group, sizeof(names->ccw_group), "ccw%s", bus_id); + if (rc >= 0 && rc < (int)sizeof(names->ccw_group)) + names->type = NET_CCWGROUP; return 0; } @@ -424,13 +446,21 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool struct netnames names = {}; int err; - /* handle only ARPHRD_ETHER devices */ + /* handle only ARPHRD_ETHER and ARPHRD_SLIP devices */ s = udev_device_get_sysattr_value(dev, "type"); if (!s) return EXIT_FAILURE; i = strtoul(s, NULL, 0); - if (i != 1) + switch (i) { + case ARPHRD_ETHER: + prefix = "en"; + break; + case ARPHRD_SLIP: + prefix = "sl"; + break; + default: return 0; + } /* skip stacked devices, like VLANs, ... */ s = udev_device_get_sysattr_value(dev, "ifindex"); @@ -462,6 +492,16 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool ieee_oui(dev, &names, test); } + /* get path names for Linux on System z network devices */ + err = names_ccw(dev, &names); + if (err >= 0 && names.type == NET_CCWGROUP) { + char str[IFNAMSIZ]; + + if (snprintf(str, sizeof(str), "%s%s", prefix, names.ccw_group) < (int)sizeof(str)) + udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str); + goto out; + } + /* get PCI based path names, we compose only PCI based paths */ err = names_pci(dev, &names); if (err < 0) @@ -518,22 +558,6 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str); goto out; } - - /* virtio bus */ - err = names_virtio(dev, &names); - if (err >= 0 && names.type == NET_VIRTIO) { - char str[IFNAMSIZ]; - - if (names.pci_path[0]) - if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_path, names.virtio_core) < (int)sizeof(str)) - udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str); - - if (names.pci_slot[0]) - if (snprintf(str, sizeof(str), "%s%s%s", prefix, names.pci_slot, names.virtio_core) < (int)sizeof(str)) - udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str); - goto out; - } - out: return EXIT_SUCCESS; }