From c1d6edac4c89eb00e6eae02b8495a5a98b61c6a2 Mon Sep 17 00:00:00 2001 From: jiangheng Date: Thu, 2 Mar 2023 20:06:52 +0800 Subject: [PATCH] fix ip netns attach (cherry picked from commit 7482f7db673f4fb2c1ce385ea0aa76992ff79252) --- ...proc-to-ipnetnsproc-which-is-private.patch | 20 +++++++++---------- iproute.spec | 8 +++++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch b/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch index c640f95..6bb7352 100644 --- a/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch +++ b/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch @@ -116,20 +116,18 @@ index fc58a04..fedc3db 100644 netns = open(net_path, O_RDONLY); if (netns < 0) { fprintf(stderr, "Cannot open network namespace: %s\n", -@@ -917,9 +972,11 @@ static int netns_add(int argc, char **argv, bool create) +@@ -911,9 +965,9 @@ static int netns_add(int argc, char **argv, bool create) + goto out_delete; + } + +- strcpy(proc_path, "/proc/self/ns/net"); ++ snprintf(proc_path, sizeof(proc_path), "/%s/self/ns/net", get_proc_string()); + } else { +- snprintf(proc_path, sizeof(proc_path), "/proc/%d/ns/net", pid); ++ snprintf(proc_path, sizeof(proc_path), "/%s/%d/ns/net", get_proc_string(), pid); } /* Bind the netns last so I can watch for it */ -- if (mount(proc_path, netns_path, "none", MS_BIND, NULL) < 0) { -+ char pid_net_path[MAXPATHLEN]; -+ snprintf(pid_net_path, sizeof(pid_net_path), "%s/self/ns/net", get_proc_string()); -+ if (mount(pid_net_path, netns_path, "none", MS_BIND, NULL) < 0) { - fprintf(stderr, "Bind %s -> %s failed: %s\n", -- proc_path, netns_path, strerror(errno)); -+ pid_net_path, netns_path, strerror(errno)); - goto out_delete; - } - netns_restore(); -- 1.8.3.1 diff --git a/iproute.spec b/iproute.spec index 37d7aa7..c0bbcdc 100644 --- a/iproute.spec +++ b/iproute.spec @@ -2,7 +2,7 @@ Name: iproute Version: 5.15.0 Epoch: 1 -Release: 12 +Release: 13 Summary: Linux network configuration utilities License: GPLv2+ and Public Domain URL: https://kernel.org/pub/linux/utils/net/iproute2/ @@ -107,6 +107,12 @@ install -m 0644 lib/libnetlink.a %{buildroot}%{_libdir}/libnetlink.a %{_mandir}/* %changelog +* Thu Mar 02 2023 jiangheng - 1:5.15.0-13 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix ip netns attach failed + * Fri Feb 17 2023 gaoxingwang - 1:5.15.0-12 - Type:bugfix - ID:NA