daandemeyer / rpms / systemd

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