ryantimwilson / rpms / systemd

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