netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: luoshijie <luoshijie1@huawei.com>
To: <davem@davemloft.net>, <tgraf@suug.ch>, <dsahern@gmail.com>
Cc: <netdev@vger.kernel.org>, <liuzhiqiang26@huawei.com>,
	<wangxiaogang3@huawei.com>, <mingfangsen@huawei.com>,
	<zhoukang7@huawei.com>
Subject: [PATCH v2 3/3] selftests: add route_localnet test script
Date: Tue, 18 Jun 2019 15:14:05 +0000	[thread overview]
Message-ID: <1560870845-172395-4-git-send-email-luoshijie1@huawei.com> (raw)
In-Reply-To: <1560870845-172395-1-git-send-email-luoshijie1@huawei.com>

From: Shijie Luo <luoshijie1@huawei.com>

Add a simple scripts to exercise several situations when enable
route_localnet.

Signed-off-by: Shijie Luo <luoshijie1@huawei.com>
Signed-off-by: Zhiqiang liu <liuzhiqiang26@huawei.com>
---
 tools/testing/selftests/net/route_localnet.sh | 74 +++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100755 tools/testing/selftests/net/route_localnet.sh

diff --git a/tools/testing/selftests/net/route_localnet.sh b/tools/testing/selftests/net/route_localnet.sh
new file mode 100755
index 000000000000..116bfeab72fa
--- /dev/null
+++ b/tools/testing/selftests/net/route_localnet.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Run a couple of tests when route_localnet = 1.
+
+readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
+
+setup() {
+    ip netns add "${PEER_NS}"
+    ip -netns "${PEER_NS}" link set dev lo up
+    ip link add name veth0 type veth peer name veth1
+    ip link set dev veth0 up
+    ip link set dev veth1 netns "${PEER_NS}"
+
+    # Enable route_localnet and delete useless route 127.0.0.0/8.
+    sysctl -w net.ipv4.conf.veth0.route_localnet=1
+    ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.route_localnet=1
+    ip route del 127.0.0.0/8 dev lo table local
+    ip netns exec "${PEER_NS}" ip route del 127.0.0.0/8 dev lo table local
+
+    ifconfig veth0 127.25.3.4/24 up
+    ip netns exec "${PEER_NS}" ifconfig veth1 127.25.3.14/24 up
+
+    ip route flush cache
+    ip netns exec "${PEER_NS}" ip route flush cache
+}
+
+cleanup() {
+    ip link del veth0
+    ip route add local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
+    local -r ns="$(ip netns list|grep $PEER_NS)"
+    [ -n "$ns" ] && ip netns del $ns 2>/dev/null
+}
+
+# Run test when arp_announce = 2.
+run_arp_announce_test() {
+    echo "run arp_announce test"
+    setup
+
+    sysctl -w net.ipv4.conf.veth0.arp_announce=2
+    ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_announce=2
+    ping -c5 -I veth0 127.25.3.14
+    if [ $? -ne 0 ];then
+        echo "failed"
+    else
+        echo "ok"
+    fi
+
+    cleanup
+}
+
+# Run test when arp_ignore = 3.
+run_arp_ignore_test() {
+    echo "run arp_ignore test"
+    setup
+
+    sysctl -w net.ipv4.conf.veth0.arp_ignore=3
+    ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_ignore=3
+    ping -c5 -I veth0 127.25.3.14
+    if [ $? -ne 0 ];then
+        echo "failed"
+    else
+        echo "ok"
+    fi
+
+    cleanup
+}
+
+run_all_tests() {
+    run_arp_announce_test
+    run_arp_ignore_test
+}
+
+run_all_tests
-- 
2.19.1


  parent reply	other threads:[~2019-06-18 13:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 15:14 [PATCH v2 0/3] fix bugs when enable route_localnet luoshijie
2019-06-18 15:14 ` [PATCH v2 1/3] ipv4: fix inet_select_addr() " luoshijie
2019-06-18 15:14 ` [PATCH v2 2/3] ipv4: fix confirm_addr_indev() " luoshijie
2019-06-18 15:14 ` luoshijie [this message]
2019-06-22  8:41 ` [PATCH v2 0/3] fix bugs " Zhiqiang Liu
2019-06-22 12:46   ` David Miller
2019-06-24  1:19     ` Zhiqiang Liu
2019-06-24  3:47     ` David Ahern
2019-06-24 16:03 ` David Miller
2019-06-25  1:25   ` Zhiqiang Liu
2019-06-25  1:50   ` Luoshijie (Poincare Lab)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1560870845-172395-4-git-send-email-luoshijie1@huawei.com \
    --to=luoshijie1@huawei.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=liuzhiqiang26@huawei.com \
    --cc=mingfangsen@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=wangxiaogang3@huawei.com \
    --cc=zhoukang7@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).