From 829abf32e529b5fd280066fd18c4af539e419ad3 Mon Sep 17 00:00:00 2001 From: jiangheng Date: Thu, 2 Mar 2023 22:01:58 +0800 Subject: [PATCH] fix ip netns attach failed --- ...proc-to-ipnetnsproc-which-is-private.patch | 29 +++++++++---------- iproute.spec | 8 ++++- 2 files changed, 20 insertions(+), 17 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 bcd9ce7..c3eab86 100644 --- a/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch +++ b/bugfix-iproute2-change-proc-to-ipnetnsproc-which-is-private.patch @@ -16,9 +16,8 @@ Signed-off-by: Minhua Chen --- ip/ipnetns.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 8 deletions(-) - diff --git a/ip/ipnetns.c b/ip/ipnetns.c -index fc58a04..fedc3db 100644 +index 83a9b99..2dde78a 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -24,6 +24,62 @@ @@ -84,7 +83,7 @@ index fc58a04..fedc3db 100644 static int usage(void) { fprintf(stderr, -@@ -589,10 +645,9 @@ static int netns_pids(int argc, char **argv) +@@ -598,10 +654,9 @@ static int netns_pids(int argc, char **argv) strerror(errno)); return -1; } @@ -97,7 +96,7 @@ index fc58a04..fedc3db 100644 return -1; } while ((entry = readdir(dir))) { -@@ -601,8 +656,7 @@ static int netns_pids(int argc, char **argv) +@@ -610,8 +665,7 @@ static int netns_pids(int argc, char **argv) if (!is_pid(entry->d_name)) continue; @@ -107,7 +106,7 @@ index fc58a04..fedc3db 100644 if (stat(pid_net_path, &st) != 0) continue; if ((st.st_dev == netst.st_dev) && -@@ -625,7 +679,7 @@ int netns_identify_pid(const char *pidstr, char *name, int len) +@@ -634,7 +688,7 @@ int netns_identify_pid(const char *pidstr, char *name, int len) name[0] = '\0'; @@ -116,20 +115,18 @@ index fc58a04..fedc3db 100644 netns = open(net_path, O_RDONLY); if (netns < 0) { fprintf(stderr, "Cannot open network namespace: %s\n", -@@ -856,9 +910,11 @@ static int netns_add(int argc, char **argv, bool create) +@@ -910,9 +964,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 948fa76..560e26b 100644 --- a/iproute.spec +++ b/iproute.spec @@ -1,6 +1,6 @@ Name: iproute Version: 5.5.0 -Release: 12 +Release: 13 Summary: Linux network configuration utilities License: GPLv2+ and Public Domain URL: https://kernel.org/pub/linux/utils/net/iproute2/ @@ -101,6 +101,12 @@ install -m 0644 lib/libnetlink.a %{buildroot}%{_libdir}/libnetlink.a %{_mandir}/* %changelog +* Thu Mar 02 2023 jiangheng - 5.5.0-13 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix ip netns attach failed + * Fri Feb 17 2023 gaoxingwang - 5.5.0-12 - Type:bugfix - ID:NA