lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Message-ID: <ZW_g-g1Rd0FA95fU@Laptop-X1> Date: Wed, 6 Dec 2023 10:48:26 +0800 From: Hangbin Liu <liuhangbin@...il.com> To: Paolo Abeni <pabeni@...hat.com> Cc: netdev@...r.kernel.org, "David S. Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, Eric Dumazet <edumazet@...gle.com>, Shuah Khan <shuah@...nel.org>, David Ahern <dsahern@...nel.org>, linux-kselftest@...r.kernel.org, Po-Hsu Lin <po-hsu.lin@...onical.com>, Guillaume Nault <gnault@...hat.com>, Petr Machata <petrm@...dia.com>, James Prestwood <prestwoj@...il.com>, Jaehee Park <jhpark1013@...il.com>, Ido Schimmel <idosch@...dia.com>, Justin Iurman <justin.iurman@...ege.be>, Xin Long <lucien.xin@...il.com>, James Chapman <jchapman@...alix.com> Subject: Re: [PATCHv3 net-next 01/14] selftests/net: add lib.sh On Tue, Dec 05, 2023 at 01:00:29PM +0100, Paolo Abeni wrote: > > +cleanup_ns() > > +{ > > + local ns="" > > + local errexit=0 > > + local ret=0 > > + > > + # disable errexit temporary > > + if [[ $- =~ "e" ]]; then > > + errexit=1 > > + set +e > > + fi > > + > > + for ns in "$@"; do > > + ip netns delete "${ns}" &> /dev/null > > + if ! busywait 2 ip netns list \| grep -vq "^$ns$" &> /dev/null; then > > + echo "Warn: Failed to remove namespace $ns" > > + ret=1 > > + fi > > + done > > + > > + [ $errexit -eq 1 ] && set -e > > + return $ret > > +} > > + > > +# setup netns with given names as prefix. e.g > > +# setup_ns local remote > > +setup_ns() > > +{ > > + local ns="" > > + local ns_name="" > > + local ns_list="" > > + for ns_name in "$@"; do > > + # Some test may setup/remove same netns multi times > > + if unset ${ns_name} 2> /dev/null; then > > + ns="${ns_name,,}-$(mktemp -u XXXXXX)" > > + eval readonly ${ns_name}="$ns" > > + else > > + eval ns='$'${ns_name} > > + cleanup_ns "$ns" > > + > > + fi > > + > > + if ! ip netns add "$ns"; then > > + echo "Failed to create namespace $ns_name" > > + cleanup_ns "$ns_list" > > + return $ksft_skip > > + fi > > + ip -n "$ns" link set lo up > > + ns_list="$ns_list $ns" > > Side note for a possible follow-up: if you maintain $ns_list as global > variable, and remove from such list the ns deleted by cleanup_ns, you > could remove the cleanup trap from the individual test with something > alike: > > final_cleanup_ns() > { > cleanup_ns $ns_list > } > > trap final_cleanup_ns EXIT > > No respin needed for the above, could be a follow-up if agreed upon. Hi Paolo, I did similar in the first version. But Petr said[1] we should let the client do cleanup specifically. I agree that we should let client script keep this in mind. On the other hand, maybe we can add this final cleanup and let client call it directly. What do you think? [1] https://lore.kernel.org/netdev/878r6nf9x5.fsf@nvidia.com/ Thanks Hangbin
Powered by blists - more mailing lists