ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
65878a
From 08f8572347ca597147ab761d425e4480885e1995 Mon Sep 17 00:00:00 2001
65878a
From: Hendrik Brueckner <brueckner@redhat.com>
65878a
Date: Thu, 9 Jan 2014 11:28:12 +0100
65878a
Subject: [PATCH] udev/net_id: Introduce predictable network names for Linux on
65878a
 System z
65878a
65878a
Use the bus-ID to create predicatable devices names for network interfaces
65878a
on Linux on System z instances.  The bus-ID identifies a device in the s390
65878a
channel subsystem.
65878a
65878a
Network interfaces of device type Ethernet are named as:
65878a
    enccw0.0.1234    (13 characters)
65878a
up to
65878a
    enccwff.7.ffff   (14 characters)
65878a
65878a
CTC network devices of device type SLIP, use a different prefix as follows:
65878a
    slccw0.0.1234    (13 characters)
65878a
65878a
See also Red Hat Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=870859
65878a
[tomegun: typical problem of netdevs switching names between reboots.]
65878a
65878a
Conflicts:
65878a
	src/udev/udev-builtin-net_id.c
65878a
---
65878a
 src/udev/udev-builtin-net_id.c | 64 ++++++++++++++++++++++++++++++++++++++++--
65878a
 1 file changed, 62 insertions(+), 2 deletions(-)
65878a
65878a
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
65878a
index 9ae8f08..d9de46d 100644
65878a
--- a/src/udev/udev-builtin-net_id.c
65878a
+++ b/src/udev/udev-builtin-net_id.c
65878a
@@ -28,6 +28,7 @@
65878a
  *
65878a
  * Two character prefixes based on the type of interface:
65878a
  *   en -- ethernet
65878a
+ *   sl -- serial line IP (slip)
65878a
  *   wl -- wlan
65878a
  *   ww -- wwan
65878a
  *
65878a
@@ -101,6 +102,7 @@ enum netname_type{
65878a
         NET_PCI,
65878a
         NET_USB,
65878a
         NET_BCMA,
65878a
+        NET_CCWGROUP,
65878a
 };
65878a
 
65878a
 struct netnames {
65878a
@@ -118,6 +120,8 @@ struct netnames {
65878a
         char usb_ports[IFNAMSIZ];
65878a
 
65878a
         char bcma_core[IFNAMSIZ];
65878a
+
65878a
+        char ccw_core[IFNAMSIZ];
65878a
 };
65878a
 
65878a
 /* retrieve on-board index number and label from firmware */
65878a
@@ -351,6 +355,44 @@ static int names_bcma(struct udev_device *dev, struct netnames *names) {
65878a
         return 0;
65878a
 }
65878a
 
65878a
+static int names_ccw(struct  udev_device *dev, struct netnames *names) {
65878a
+        struct udev_device *cdev;
65878a
+        const char *bus_id;
65878a
+        size_t bus_id_len;
65878a
+        int rc;
65878a
+
65878a
+        /* Retrieve the associated CCW device */
65878a
+        cdev = udev_device_get_parent(dev);
65878a
+        if (!cdev)
65878a
+                return -ENOENT;
65878a
+
65878a
+        /* Network devices are always grouped CCW devices */
65878a
+        if (!streq_ptr("ccwgroup", udev_device_get_subsystem(cdev)))
65878a
+                return -ENOENT;
65878a
+
65878a
+        /* Retrieve bus-ID of the grouped CCW device.  The bus-ID uniquely
65878a
+         * identifies the network device on the Linux on System z channel
65878a
+         * subsystem.  Note that the bus-ID contains lowercase characters.
65878a
+         */
65878a
+        bus_id = udev_device_get_sysname(cdev);
65878a
+        if (!bus_id)
65878a
+                return -ENOENT;
65878a
+
65878a
+        /* Check the length of the bus-ID.  Rely on that the kernel provides
65878a
+         * a correct bus-ID; alternatively, improve this check and parse and
65878a
+         * verify each bus-ID part...
65878a
+         */
65878a
+        bus_id_len = strlen(bus_id);
65878a
+        if (!bus_id_len || bus_id_len < 8 || bus_id_len > 9)
65878a
+                return -EINVAL;
65878a
+
65878a
+        /* Store the CCW bus-ID for use as network device name */
65878a
+        rc = snprintf(names->ccw_core, sizeof(names->ccw_core), "ccw%s", bus_id);
65878a
+        if (rc >= 0 && rc < (int)sizeof(names->ccw_core))
65878a
+                names->type = NET_CCWGROUP;
65878a
+        return 0;
65878a
+}
65878a
+
65878a
 static int names_mac(struct udev_device *dev, struct netnames *names) {
65878a
         const char *s;
65878a
         unsigned int i;
65878a
@@ -409,13 +451,21 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
65878a
         struct netnames names = {};
65878a
         int err;
65878a
 
65878a
-        /* handle only ARPHRD_ETHER devices */
65878a
+        /* handle only ARPHRD_ETHER and ARPHRD_SLIP devices */
65878a
         s = udev_device_get_sysattr_value(dev, "type");
65878a
         if (!s)
65878a
                 return EXIT_FAILURE;
65878a
         i = strtoul(s, NULL, 0);
65878a
-        if (i != 1)
65878a
+        switch (i) {
65878a
+        case 1: /* ARPHRD_ETHER */
65878a
+                prefix = "en";
65878a
+                break;
65878a
+        case 256: /* ARPHRD_SLIP */
65878a
+                prefix = "sl";
65878a
+                break;
65878a
+        default:
65878a
                 return 0;
65878a
+        }
65878a
 
65878a
         /* skip stacked devices, like VLANs, ... */
65878a
         s = udev_device_get_sysattr_value(dev, "ifindex");
65878a
@@ -447,6 +497,16 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
65878a
                 ieee_oui(dev, &names, test);
65878a
         }
65878a
 
65878a
+        /* get path names for Linux on System z network devices */
65878a
+        err = names_ccw(dev, &names);
65878a
+        if (err >= 0 && names.type == NET_CCWGROUP) {
65878a
+                char str[IFNAMSIZ];
65878a
+
65878a
+                if (snprintf(str, sizeof(str), "%s%s", prefix, names.ccw_core) < (int)sizeof(str))
65878a
+                        udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
65878a
+                goto out;
65878a
+        }
65878a
+
65878a
         /* get PCI based path names, we compose only PCI based paths */
65878a
         err = names_pci(dev, &names);
65878a
         if (err < 0)