naccyde / rpms / systemd

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