richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
da2bf9
From 9f59dca3868b1e934a2aac2d811c55ab33cca0eb Mon Sep 17 00:00:00 2001
da2bf9
From: Yu Watanabe <watanabe.yu+github@gmail.com>
da2bf9
Date: Tue, 17 Dec 2019 11:01:35 +0900
da2bf9
Subject: [PATCH] udev: extend the length of ID_NET_NAME_XXX= to ALTIFNAMSIZ
da2bf9
da2bf9
(cherry picked from commit 78f8849f84ca0939796edb840e878a9d2e124a4d)
da2bf9
da2bf9
Related: #2005008
da2bf9
---
da2bf9
 src/udev/net/link-config.c     |  5 ++++-
da2bf9
 src/udev/udev-builtin-net_id.c | 33 +++++++++++++++++----------------
da2bf9
 src/udev/udev-event.c          |  4 ++--
da2bf9
 3 files changed, 23 insertions(+), 19 deletions(-)
da2bf9
da2bf9
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
da2bf9
index e5052f8f29..4de8ee7d7e 100644
da2bf9
--- a/src/udev/net/link-config.c
da2bf9
+++ b/src/udev/net/link-config.c
da2bf9
@@ -19,6 +19,7 @@
da2bf9
 #include "path-util.h"
da2bf9
 #include "proc-cmdline.h"
da2bf9
 #include "random-util.h"
da2bf9
+#include "socket-util.h"
da2bf9
 #include "stat-util.h"
da2bf9
 #include "string-table.h"
da2bf9
 #include "string-util.h"
da2bf9
@@ -405,7 +406,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
da2bf9
                 NamePolicy *policy;
da2bf9
 
da2bf9
                 for (policy = config->name_policy;
da2bf9
-                     !new_name && *policy != _NAMEPOLICY_INVALID; policy++) {
da2bf9
+                     *policy != _NAMEPOLICY_INVALID; policy++) {
da2bf9
                         switch (*policy) {
da2bf9
                                 case NAMEPOLICY_KERNEL:
da2bf9
                                         respect_predictable = true;
da2bf9
@@ -428,6 +429,8 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
da2bf9
                                 default:
da2bf9
                                         break;
da2bf9
                         }
da2bf9
+                        if (ifname_valid(new_name))
da2bf9
+                                break;
da2bf9
                 }
da2bf9
         }
da2bf9
 
da2bf9
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
da2bf9
index eafcbb64c5..386d74ca5e 100644
da2bf9
--- a/src/udev/udev-builtin-net_id.c
da2bf9
+++ b/src/udev/udev-builtin-net_id.c
da2bf9
@@ -90,6 +90,7 @@
da2bf9
 #include <stdlib.h>
da2bf9
 #include <string.h>
da2bf9
 #include <unistd.h>
da2bf9
+#include <linux/if.h>
da2bf9
 #include <linux/pci_regs.h>
da2bf9
 
da2bf9
 #include "dirent-util.h"
da2bf9
@@ -176,21 +177,21 @@ struct netnames {
da2bf9
         bool mac_valid;
da2bf9
 
da2bf9
         struct udev_device *pcidev;
da2bf9
-        char pci_slot[IFNAMSIZ];
da2bf9
-        char pci_path[IFNAMSIZ];
da2bf9
-        char pci_onboard[IFNAMSIZ];
da2bf9
+        char pci_slot[ALTIFNAMSIZ];
da2bf9
+        char pci_path[ALTIFNAMSIZ];
da2bf9
+        char pci_onboard[ALTIFNAMSIZ];
da2bf9
         const char *pci_onboard_label;
da2bf9
 
da2bf9
-        char usb_ports[IFNAMSIZ];
da2bf9
-        char bcma_core[IFNAMSIZ];
da2bf9
-        char ccw_busid[IFNAMSIZ];
da2bf9
-        char vio_slot[IFNAMSIZ];
da2bf9
-        char platform_path[IFNAMSIZ];
da2bf9
+        char usb_ports[ALTIFNAMSIZ];
da2bf9
+        char bcma_core[ALTIFNAMSIZ];
da2bf9
+        char ccw_busid[ALTIFNAMSIZ];
da2bf9
+        char vio_slot[ALTIFNAMSIZ];
da2bf9
+        char platform_path[ALTIFNAMSIZ];
da2bf9
 };
da2bf9
 
da2bf9
 struct virtfn_info {
da2bf9
         struct udev_device *physfn_pcidev;
da2bf9
-        char suffix[IFNAMSIZ];
da2bf9
+        char suffix[ALTIFNAMSIZ];
da2bf9
 };
da2bf9
 
da2bf9
 static const NamingScheme* naming_scheme_from_name(const char *name) {
da2bf9
@@ -887,7 +888,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
 
da2bf9
         err = names_mac(dev, &names);
da2bf9
         if (err >= 0 && names.mac_valid) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 xsprintf(str, "%sx%02x%02x%02x%02x%02x%02x", prefix,
da2bf9
                          names.mac[0], names.mac[1], names.mac[2],
da2bf9
@@ -900,7 +901,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
         /* get path names for Linux on System z network devices */
da2bf9
         err = names_ccw(dev, &names);
da2bf9
         if (err >= 0 && names.type == NET_CCW) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.ccw_busid))
da2bf9
                         udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
da2bf9
@@ -910,7 +911,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
         /* get ibmveth/ibmvnic slot-based names. */
da2bf9
         err = names_vio(dev, &names);
da2bf9
         if (err >= 0 && names.type == NET_VIO) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
da2bf9
                         udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
da2bf9
@@ -920,7 +921,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
         /* get ACPI path names for ARM64 platform devices */
da2bf9
         err = names_platform(dev, &names, test);
da2bf9
         if (err >= 0 && names.type == NET_PLATFORM) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.platform_path))
da2bf9
                         udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
da2bf9
@@ -934,7 +935,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
 
da2bf9
         /* plain PCI device */
da2bf9
         if (names.type == NET_PCI) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (names.pci_onboard[0] &&
da2bf9
                     snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard))
da2bf9
@@ -957,7 +958,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
         /* USB device */
da2bf9
         err = names_usb(dev, &names);
da2bf9
         if (err >= 0 && names.type == NET_USB) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (names.pci_path[0] &&
da2bf9
                     snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.usb_ports))
da2bf9
@@ -972,7 +973,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
da2bf9
         /* Broadcom bus */
da2bf9
         err = names_bcma(dev, &names);
da2bf9
         if (err >= 0 && names.type == NET_BCMA) {
da2bf9
-                char str[IFNAMSIZ];
da2bf9
+                char str[ALTIFNAMSIZ];
da2bf9
 
da2bf9
                 if (names.pci_path[0] &&
da2bf9
                     snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.bcma_core))
da2bf9
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
da2bf9
index fd8406d959..19b100d4f8 100644
da2bf9
--- a/src/udev/udev-event.c
da2bf9
+++ b/src/udev/udev-event.c
da2bf9
@@ -816,13 +816,13 @@ out:
da2bf9
 
da2bf9
 static int rename_netif(struct udev_event *event) {
da2bf9
         struct udev_device *dev = event->dev;
da2bf9
-        char name[IFNAMSIZ];
da2bf9
+        char name[ALTIFNAMSIZ];
da2bf9
         const char *oldname;
da2bf9
         int r;
da2bf9
 
da2bf9
         oldname = udev_device_get_sysname(dev);
da2bf9
 
da2bf9
-        strscpy(name, IFNAMSIZ, event->name);
da2bf9
+        strscpy(name, ALTIFNAMSIZ, event->name);
da2bf9
 
da2bf9
         r = rtnl_set_link_name(&event->rtnl, udev_device_get_ifindex(dev), name);
da2bf9
         if (r < 0)