netns_netlink: Rewrite into new API
PATCH v3 1/1 netns_netlink: Rewrite into new API
cleanup:
- stop using legacy libclone.h, checks done by requiring CONFIG_NET_NS=y
- remove check for iproute 100519 (v2.6.34 => old enough to drop this check)
- remove check for unshare() CLONE_NEWNET support (since 2.6.24, old enough) This allow us to remove netns_helper.h. If ever needed iproute2 version check, it can be added separately. Current implementation also does work with the new iproute2 version scheme v5.7.0-77-gb687d1067169 (released in iproute2 v5.8.0).
- simplify check for child result
---
changes v2->v3
Implement Cyril's requirements:
- simplify check for child result, use safe macros
- require CONFIG_NET_NS=y
- adding static
- further cleanup
Not sure if while (tries < MAX_TRIES) section can be cleaned more.
Kind regards,
Petr
.../kernel/containers/netns/netns_helper.h | 80 -------- .../kernel/containers/netns/netns_netlink.c | 176 ++++++------------ 2 files changed, 61 insertions(+), 195 deletions(-) delete mode 100644 testcases/kernel/containers/netns/netns_helper.h
testcases/kernel/containers/netns/netns_helper.h deleted +0 -80
@@ -1,80 +0,0 @@ -/* -* Copyright (c) International Business Machines Corp., 2008 -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* Author: Veerendra C <[email protected]> -* -* Net namespaces were introduced around 2.6.25. Kernels before that, -* assume they are not enabled. Kernels after that, check for -EINVAL -* when trying to use CLONE_NEWNET and CLONE_NEWNS. -***************************************************************************/ - -#define _GNU_SOURCE -#include <sched.h> -#include "config.h" -#include "libclone.h" -#include "lapi/syscalls.h" -#include "test.h" -#include "safe_macros.h" - -#ifndef CLONE_NEWNS -#define CLONE_NEWNS -1 -#endif - -static void check_iproute (unsigned int spe_ipver) -{ -FILE *ipf; -int n; -unsigned int ipver =0 ; - - ipf =popen ("ip -V" ,"r" ); -if (ipf ==NULL ) -tst_brkm (TCONF ,NULL , -"Failed while opening pipe for iproute check" ); - - n =fscanf (ipf,"ip utility, iproute2-ss%u" , &ipver); -if (n <1 ) { -tst_brkm (TCONF ,NULL , -"Failed while obtaining version for iproute check" ); - } -if (ipver < spe_ipver) { -tst_brkm (TCONF ,NULL ,"The commands in iproute tools do " -"not support required objects" ); - } - -pclose (ipf); -} - -static int dummy (void *arg) -{ - (void ) arg; -return 0 ; -} - -static void check_netns (void ) -{ -int pid, status; -/* Checking if the kernel supports unshare with netns capabilities. */ -if (CLONE_NEWNS ==-1 ) -tst_brkm (TCONF |TERRNO ,NULL ,"CLONE_NEWNS (%d) not supported" , -CLONE_NEWNS ); - - pid =do_clone_unshare_test (T_UNSHARE ,CLONE_NEWNET |CLONE_NEWNS , - dummy,NULL ); -if (pid ==-1 ) -tst_brkm (TCONF |TERRNO ,NULL , -"unshare syscall smoke test failed" ); - -SAFE_WAIT (NULL , &status); -}
testcases/kernel/containers/netns/netns_netlink.c +61 -115
231 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 1/1 netns_netlink: Rewrite into new API
Hi!
Looks good: Reviewed-by: Cyril Hrubis <[email protected]>
Also this is a bugfix for new iproute, right? If so this should get in before the release.
And we should probably make use of the netlink library from Martin later on, but that can wait after the release.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 netns_netlink: Rewrite into new API
Hi Cyril,
Quoted 2 lines
Hi!
Looks good: Reviewed-by: Cyril Hrubis <[email protected]>
Thanks!
Quoted 2 lines
Also this is a bugfix for new iproute, right? If so this should get in before the release.
Yes, thus pushed.
Quoted 2 lines
And we should probably make use of the netlink library from Martin later on, but that can wait after the release.
+1, put into my TODO list.
Also how about keeping libmnl vs. using Martin's library for route-change-netlink.c? Which one is better to use? (already asked in [1]: it'd be nice to get rid of libmnl dependency, but on the other hand using it means also testing it).
Kind regards,
Petr
[1] https://lists.linux.it/pipermail/ltp/2021-May/022529.html