From mboxrd@z Thu Jan 1 00:00:00 1970 From: Luca Boccassi Subject: [PATCH iproute2 v3 4/4] testsuite: remove gre kmods if the test loads them Date: Sun, 16 Dec 2018 20:55:40 +0000 Message-ID: <20181216205540.16787-4-bluca@debian.org> References: <20181215153051.13166-1-bluca@debian.org> <20181216205540.16787-1-bluca@debian.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: stephen@networkplumber.org, petr.vorel@gmail.com, Luca Boccassi To: netdev@vger.kernel.org Return-path: Received: from mail-wr1-f66.google.com ([209.85.221.66]:35214 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730874AbeLPUzy (ORCPT ); Sun, 16 Dec 2018 15:55:54 -0500 Received: by mail-wr1-f66.google.com with SMTP id 96so10312772wrb.2 for ; Sun, 16 Dec 2018 12:55:53 -0800 (PST) In-Reply-To: <20181216205540.16787-1-bluca@debian.org> Sender: netdev-owner@vger.kernel.org List-ID: The tunnel test leaves behind link devices created by the GRE kernel modules: $ ip -br link ... gre0@NONE DOWN 0.0.0.0 gretap0@NONE DOWN 00:00:00:00:00:00 erspan0@NONE DOWN 00:00:00:00:00:00 ip6tnl0@NONE DOWN :: ip6gre0@NONE DOWN 00:00:00:00: $ lsmod | grep gre ip6_gre 40960 0 ip6_tunnel 40960 1 ip6_gre ip_gre 32768 0 ip_tunnel 24576 1 ip_gre gre 16384 2 ip6_gre,ip_gre Check beforehand if the gre kernel module is loaded, and if not unload them all at the end of the test. This should avoid causing problems if a user is already using GRE for other purposes. Signed-off-by: Luca Boccassi Reviewed-by: Petr Vorel --- v2: applied suggestions from Petr to simplify the modules parsing/unloading v3: ditto, added reviewed-by tag testsuite/tests/ip/tunnel/add_tunnel.t | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t index 3f5a9d3c..65db431c 100755 --- a/testsuite/tests/ip/tunnel/add_tunnel.t +++ b/testsuite/tests/ip/tunnel/add_tunnel.t @@ -3,6 +3,16 @@ . lib/generic.sh TUNNEL_NAME="tunnel_test_ip" +KMODS="ip6_gre ip6_tunnel ip_gre ip_tunnel gre" + +# unload kernel modules to remove dummy interfaces only if they were not in use beforehand +kmods_remove= +# note that checkbashism reports command -v, but dash supports it and it's POSIX 2008 compliant +if command -v lsmod >/dev/null 2>&1 && command -v rmmod >/dev/null 2>&1; then + for i in $KMODS; do + lsmod | grep -q "^$i" || kmods_remove="$kmods_remove $i"; + done +fi ts_log "[Testing add/del tunnels]" @@ -12,3 +22,6 @@ ts_ip "$0" "Del GRE tunnel over IPv4" tunnel del $TUNNEL_NAME ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2 ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME +for mod in $kmods_remove; do + sudo rmmod "$mod" +done -- 2.19.2