Commit 68bfd65f authored by Martin KaFai Lau's avatar Martin KaFai Lau

Merge branch 'move SYS() macro to test_progs.h and run mptcp in a dedicated netns'

Hangbin Liu says:

====================

As Martin suggested, let's move the SYS() macro to test_progs.h since
a lot of programs are using it. After that, let's run mptcp in a dedicated
netns to avoid user config influence.

v3: fix fd redirect typo. Move SYS() macro into the test_progs.h
v2: remove unneed close_cgroup_fd goto label.
====================
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parents d0093aae 02d6a057
...@@ -10,14 +10,6 @@ ...@@ -10,14 +10,6 @@
#include "network_helpers.h" #include "network_helpers.h"
#include "decap_sanity.skel.h" #include "decap_sanity.skel.h"
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto fail; \
})
#define NS_TEST "decap_sanity_ns" #define NS_TEST "decap_sanity_ns"
#define IPV6_IFACE_ADDR "face::1" #define IPV6_IFACE_ADDR "face::1"
#define UDP_TEST_PORT 7777 #define UDP_TEST_PORT 7777
...@@ -37,9 +29,9 @@ void test_decap_sanity(void) ...@@ -37,9 +29,9 @@ void test_decap_sanity(void)
if (!ASSERT_OK_PTR(skel, "skel open_and_load")) if (!ASSERT_OK_PTR(skel, "skel open_and_load"))
return; return;
SYS("ip netns add %s", NS_TEST); SYS(fail, "ip netns add %s", NS_TEST);
SYS("ip -net %s -6 addr add %s/128 dev lo nodad", NS_TEST, IPV6_IFACE_ADDR); SYS(fail, "ip -net %s -6 addr add %s/128 dev lo nodad", NS_TEST, IPV6_IFACE_ADDR);
SYS("ip -net %s link set dev lo up", NS_TEST); SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
nstoken = open_netns(NS_TEST); nstoken = open_netns(NS_TEST);
if (!ASSERT_OK_PTR(nstoken, "open_netns")) if (!ASSERT_OK_PTR(nstoken, "open_netns"))
...@@ -80,6 +72,6 @@ void test_decap_sanity(void) ...@@ -80,6 +72,6 @@ void test_decap_sanity(void)
bpf_tc_hook_destroy(&qdisc_hook); bpf_tc_hook_destroy(&qdisc_hook);
close_netns(nstoken); close_netns(nstoken);
} }
system("ip netns del " NS_TEST " &> /dev/null"); SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
decap_sanity__destroy(skel); decap_sanity__destroy(skel);
} }
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
#include <net/if.h> #include <net/if.h>
#include "empty_skb.skel.h" #include "empty_skb.skel.h"
#define SYS(cmd) ({ \
if (!ASSERT_OK(system(cmd), (cmd))) \
goto out; \
})
void test_empty_skb(void) void test_empty_skb(void)
{ {
LIBBPF_OPTS(bpf_test_run_opts, tattr); LIBBPF_OPTS(bpf_test_run_opts, tattr);
...@@ -93,18 +88,18 @@ void test_empty_skb(void) ...@@ -93,18 +88,18 @@ void test_empty_skb(void)
}, },
}; };
SYS("ip netns add empty_skb"); SYS(out, "ip netns add empty_skb");
tok = open_netns("empty_skb"); tok = open_netns("empty_skb");
SYS("ip link add veth0 type veth peer veth1"); SYS(out, "ip link add veth0 type veth peer veth1");
SYS("ip link set dev veth0 up"); SYS(out, "ip link set dev veth0 up");
SYS("ip link set dev veth1 up"); SYS(out, "ip link set dev veth1 up");
SYS("ip addr add 10.0.0.1/8 dev veth0"); SYS(out, "ip addr add 10.0.0.1/8 dev veth0");
SYS("ip addr add 10.0.0.2/8 dev veth1"); SYS(out, "ip addr add 10.0.0.2/8 dev veth1");
veth_ifindex = if_nametoindex("veth0"); veth_ifindex = if_nametoindex("veth0");
SYS("ip link add ipip0 type ipip local 10.0.0.1 remote 10.0.0.2"); SYS(out, "ip link add ipip0 type ipip local 10.0.0.1 remote 10.0.0.2");
SYS("ip link set ipip0 up"); SYS(out, "ip link set ipip0 up");
SYS("ip addr add 192.168.1.1/16 dev ipip0"); SYS(out, "ip addr add 192.168.1.1/16 dev ipip0");
ipip_ifindex = if_nametoindex("ipip0"); ipip_ifindex = if_nametoindex("ipip0");
bpf_obj = empty_skb__open_and_load(); bpf_obj = empty_skb__open_and_load();
...@@ -142,5 +137,5 @@ void test_empty_skb(void) ...@@ -142,5 +137,5 @@ void test_empty_skb(void)
empty_skb__destroy(bpf_obj); empty_skb__destroy(bpf_obj);
if (tok) if (tok)
close_netns(tok); close_netns(tok);
system("ip netns del empty_skb"); SYS_NOFAIL("ip netns del empty_skb");
} }
...@@ -8,14 +8,6 @@ ...@@ -8,14 +8,6 @@
#include "network_helpers.h" #include "network_helpers.h"
#include "fib_lookup.skel.h" #include "fib_lookup.skel.h"
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto fail; \
})
#define NS_TEST "fib_lookup_ns" #define NS_TEST "fib_lookup_ns"
#define IPV6_IFACE_ADDR "face::face" #define IPV6_IFACE_ADDR "face::face"
#define IPV6_NUD_FAILED_ADDR "face::1" #define IPV6_NUD_FAILED_ADDR "face::1"
...@@ -59,16 +51,16 @@ static int setup_netns(void) ...@@ -59,16 +51,16 @@ static int setup_netns(void)
{ {
int err; int err;
SYS("ip link add veth1 type veth peer name veth2"); SYS(fail, "ip link add veth1 type veth peer name veth2");
SYS("ip link set dev veth1 up"); SYS(fail, "ip link set dev veth1 up");
SYS("ip addr add %s/64 dev veth1 nodad", IPV6_IFACE_ADDR); SYS(fail, "ip addr add %s/64 dev veth1 nodad", IPV6_IFACE_ADDR);
SYS("ip neigh add %s dev veth1 nud failed", IPV6_NUD_FAILED_ADDR); SYS(fail, "ip neigh add %s dev veth1 nud failed", IPV6_NUD_FAILED_ADDR);
SYS("ip neigh add %s dev veth1 lladdr %s nud stale", IPV6_NUD_STALE_ADDR, DMAC); SYS(fail, "ip neigh add %s dev veth1 lladdr %s nud stale", IPV6_NUD_STALE_ADDR, DMAC);
SYS("ip addr add %s/24 dev veth1 nodad", IPV4_IFACE_ADDR); SYS(fail, "ip addr add %s/24 dev veth1 nodad", IPV4_IFACE_ADDR);
SYS("ip neigh add %s dev veth1 nud failed", IPV4_NUD_FAILED_ADDR); SYS(fail, "ip neigh add %s dev veth1 nud failed", IPV4_NUD_FAILED_ADDR);
SYS("ip neigh add %s dev veth1 lladdr %s nud stale", IPV4_NUD_STALE_ADDR, DMAC); SYS(fail, "ip neigh add %s dev veth1 lladdr %s nud stale", IPV4_NUD_STALE_ADDR, DMAC);
err = write_sysctl("/proc/sys/net/ipv4/conf/veth1/forwarding", "1"); err = write_sysctl("/proc/sys/net/ipv4/conf/veth1/forwarding", "1");
if (!ASSERT_OK(err, "write_sysctl(net.ipv4.conf.veth1.forwarding)")) if (!ASSERT_OK(err, "write_sysctl(net.ipv4.conf.veth1.forwarding)"))
...@@ -140,7 +132,7 @@ void test_fib_lookup(void) ...@@ -140,7 +132,7 @@ void test_fib_lookup(void)
return; return;
prog_fd = bpf_program__fd(skel->progs.fib_lookup); prog_fd = bpf_program__fd(skel->progs.fib_lookup);
SYS("ip netns add %s", NS_TEST); SYS(fail, "ip netns add %s", NS_TEST);
nstoken = open_netns(NS_TEST); nstoken = open_netns(NS_TEST);
if (!ASSERT_OK_PTR(nstoken, "open_netns")) if (!ASSERT_OK_PTR(nstoken, "open_netns"))
...@@ -182,6 +174,6 @@ void test_fib_lookup(void) ...@@ -182,6 +174,6 @@ void test_fib_lookup(void)
fail: fail:
if (nstoken) if (nstoken)
close_netns(nstoken); close_netns(nstoken);
system("ip netns del " NS_TEST " &> /dev/null"); SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
fib_lookup__destroy(skel); fib_lookup__destroy(skel);
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "network_helpers.h" #include "network_helpers.h"
#include "mptcp_sock.skel.h" #include "mptcp_sock.skel.h"
#define NS_TEST "mptcp_ns"
#ifndef TCP_CA_NAME_MAX #ifndef TCP_CA_NAME_MAX
#define TCP_CA_NAME_MAX 16 #define TCP_CA_NAME_MAX 16
#endif #endif
...@@ -138,12 +140,20 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) ...@@ -138,12 +140,20 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
static void test_base(void) static void test_base(void)
{ {
struct nstoken *nstoken = NULL;
int server_fd, cgroup_fd; int server_fd, cgroup_fd;
cgroup_fd = test__join_cgroup("/mptcp"); cgroup_fd = test__join_cgroup("/mptcp");
if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
return; return;
SYS(fail, "ip netns add %s", NS_TEST);
SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
nstoken = open_netns(NS_TEST);
if (!ASSERT_OK_PTR(nstoken, "open_netns"))
goto fail;
/* without MPTCP */ /* without MPTCP */
server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
if (!ASSERT_GE(server_fd, 0, "start_server")) if (!ASSERT_GE(server_fd, 0, "start_server"))
...@@ -157,13 +167,18 @@ static void test_base(void) ...@@ -157,13 +167,18 @@ static void test_base(void)
/* with MPTCP */ /* with MPTCP */
server_fd = start_mptcp_server(AF_INET, NULL, 0, 0); server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
goto close_cgroup_fd; goto fail;
ASSERT_OK(run_test(cgroup_fd, server_fd, true), "run_test mptcp"); ASSERT_OK(run_test(cgroup_fd, server_fd, true), "run_test mptcp");
close(server_fd); close(server_fd);
close_cgroup_fd: fail:
if (nstoken)
close_netns(nstoken);
SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
close(cgroup_fd); close(cgroup_fd);
} }
......
...@@ -137,24 +137,16 @@ static int get_ifaddr(const char *name, char *ifaddr) ...@@ -137,24 +137,16 @@ static int get_ifaddr(const char *name, char *ifaddr)
return 0; return 0;
} }
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto fail; \
})
static int netns_setup_links_and_routes(struct netns_setup_result *result) static int netns_setup_links_and_routes(struct netns_setup_result *result)
{ {
struct nstoken *nstoken = NULL; struct nstoken *nstoken = NULL;
char veth_src_fwd_addr[IFADDR_STR_LEN+1] = {}; char veth_src_fwd_addr[IFADDR_STR_LEN+1] = {};
SYS("ip link add veth_src type veth peer name veth_src_fwd"); SYS(fail, "ip link add veth_src type veth peer name veth_src_fwd");
SYS("ip link add veth_dst type veth peer name veth_dst_fwd"); SYS(fail, "ip link add veth_dst type veth peer name veth_dst_fwd");
SYS("ip link set veth_dst_fwd address " MAC_DST_FWD); SYS(fail, "ip link set veth_dst_fwd address " MAC_DST_FWD);
SYS("ip link set veth_dst address " MAC_DST); SYS(fail, "ip link set veth_dst address " MAC_DST);
if (get_ifaddr("veth_src_fwd", veth_src_fwd_addr)) if (get_ifaddr("veth_src_fwd", veth_src_fwd_addr))
goto fail; goto fail;
...@@ -175,27 +167,27 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result) ...@@ -175,27 +167,27 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result)
if (!ASSERT_GT(result->ifindex_veth_dst_fwd, 0, "ifindex_veth_dst_fwd")) if (!ASSERT_GT(result->ifindex_veth_dst_fwd, 0, "ifindex_veth_dst_fwd"))
goto fail; goto fail;
SYS("ip link set veth_src netns " NS_SRC); SYS(fail, "ip link set veth_src netns " NS_SRC);
SYS("ip link set veth_src_fwd netns " NS_FWD); SYS(fail, "ip link set veth_src_fwd netns " NS_FWD);
SYS("ip link set veth_dst_fwd netns " NS_FWD); SYS(fail, "ip link set veth_dst_fwd netns " NS_FWD);
SYS("ip link set veth_dst netns " NS_DST); SYS(fail, "ip link set veth_dst netns " NS_DST);
/** setup in 'src' namespace */ /** setup in 'src' namespace */
nstoken = open_netns(NS_SRC); nstoken = open_netns(NS_SRC);
if (!ASSERT_OK_PTR(nstoken, "setns src")) if (!ASSERT_OK_PTR(nstoken, "setns src"))
goto fail; goto fail;
SYS("ip addr add " IP4_SRC "/32 dev veth_src"); SYS(fail, "ip addr add " IP4_SRC "/32 dev veth_src");
SYS("ip addr add " IP6_SRC "/128 dev veth_src nodad"); SYS(fail, "ip addr add " IP6_SRC "/128 dev veth_src nodad");
SYS("ip link set dev veth_src up"); SYS(fail, "ip link set dev veth_src up");
SYS("ip route add " IP4_DST "/32 dev veth_src scope global"); SYS(fail, "ip route add " IP4_DST "/32 dev veth_src scope global");
SYS("ip route add " IP4_NET "/16 dev veth_src scope global"); SYS(fail, "ip route add " IP4_NET "/16 dev veth_src scope global");
SYS("ip route add " IP6_DST "/128 dev veth_src scope global"); SYS(fail, "ip route add " IP6_DST "/128 dev veth_src scope global");
SYS("ip neigh add " IP4_DST " dev veth_src lladdr %s", SYS(fail, "ip neigh add " IP4_DST " dev veth_src lladdr %s",
veth_src_fwd_addr); veth_src_fwd_addr);
SYS("ip neigh add " IP6_DST " dev veth_src lladdr %s", SYS(fail, "ip neigh add " IP6_DST " dev veth_src lladdr %s",
veth_src_fwd_addr); veth_src_fwd_addr);
close_netns(nstoken); close_netns(nstoken);
...@@ -209,15 +201,15 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result) ...@@ -209,15 +201,15 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result)
* needs v4 one in order to start ARP probing. IP4_NET route is added * needs v4 one in order to start ARP probing. IP4_NET route is added
* to the endpoints so that the ARP processing will reply. * to the endpoints so that the ARP processing will reply.
*/ */
SYS("ip addr add " IP4_SLL "/32 dev veth_src_fwd"); SYS(fail, "ip addr add " IP4_SLL "/32 dev veth_src_fwd");
SYS("ip addr add " IP4_DLL "/32 dev veth_dst_fwd"); SYS(fail, "ip addr add " IP4_DLL "/32 dev veth_dst_fwd");
SYS("ip link set dev veth_src_fwd up"); SYS(fail, "ip link set dev veth_src_fwd up");
SYS("ip link set dev veth_dst_fwd up"); SYS(fail, "ip link set dev veth_dst_fwd up");
SYS("ip route add " IP4_SRC "/32 dev veth_src_fwd scope global"); SYS(fail, "ip route add " IP4_SRC "/32 dev veth_src_fwd scope global");
SYS("ip route add " IP6_SRC "/128 dev veth_src_fwd scope global"); SYS(fail, "ip route add " IP6_SRC "/128 dev veth_src_fwd scope global");
SYS("ip route add " IP4_DST "/32 dev veth_dst_fwd scope global"); SYS(fail, "ip route add " IP4_DST "/32 dev veth_dst_fwd scope global");
SYS("ip route add " IP6_DST "/128 dev veth_dst_fwd scope global"); SYS(fail, "ip route add " IP6_DST "/128 dev veth_dst_fwd scope global");
close_netns(nstoken); close_netns(nstoken);
...@@ -226,16 +218,16 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result) ...@@ -226,16 +218,16 @@ static int netns_setup_links_and_routes(struct netns_setup_result *result)
if (!ASSERT_OK_PTR(nstoken, "setns dst")) if (!ASSERT_OK_PTR(nstoken, "setns dst"))
goto fail; goto fail;
SYS("ip addr add " IP4_DST "/32 dev veth_dst"); SYS(fail, "ip addr add " IP4_DST "/32 dev veth_dst");
SYS("ip addr add " IP6_DST "/128 dev veth_dst nodad"); SYS(fail, "ip addr add " IP6_DST "/128 dev veth_dst nodad");
SYS("ip link set dev veth_dst up"); SYS(fail, "ip link set dev veth_dst up");
SYS("ip route add " IP4_SRC "/32 dev veth_dst scope global"); SYS(fail, "ip route add " IP4_SRC "/32 dev veth_dst scope global");
SYS("ip route add " IP4_NET "/16 dev veth_dst scope global"); SYS(fail, "ip route add " IP4_NET "/16 dev veth_dst scope global");
SYS("ip route add " IP6_SRC "/128 dev veth_dst scope global"); SYS(fail, "ip route add " IP6_SRC "/128 dev veth_dst scope global");
SYS("ip neigh add " IP4_SRC " dev veth_dst lladdr " MAC_DST_FWD); SYS(fail, "ip neigh add " IP4_SRC " dev veth_dst lladdr " MAC_DST_FWD);
SYS("ip neigh add " IP6_SRC " dev veth_dst lladdr " MAC_DST_FWD); SYS(fail, "ip neigh add " IP6_SRC " dev veth_dst lladdr " MAC_DST_FWD);
close_netns(nstoken); close_netns(nstoken);
...@@ -375,7 +367,7 @@ static void test_tcp(int family, const char *addr, __u16 port) ...@@ -375,7 +367,7 @@ static void test_tcp(int family, const char *addr, __u16 port)
static int test_ping(int family, const char *addr) static int test_ping(int family, const char *addr)
{ {
SYS("ip netns exec " NS_SRC " %s " PING_ARGS " %s > /dev/null", ping_command(family), addr); SYS(fail, "ip netns exec " NS_SRC " %s " PING_ARGS " %s > /dev/null", ping_command(family), addr);
return 0; return 0;
fail: fail:
return -1; return -1;
...@@ -953,7 +945,7 @@ static int tun_open(char *name) ...@@ -953,7 +945,7 @@ static int tun_open(char *name)
if (!ASSERT_OK(err, "ioctl TUNSETIFF")) if (!ASSERT_OK(err, "ioctl TUNSETIFF"))
goto fail; goto fail;
SYS("ip link set dev %s up", name); SYS(fail, "ip link set dev %s up", name);
return fd; return fd;
fail: fail:
...@@ -1076,23 +1068,23 @@ static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result) ...@@ -1076,23 +1068,23 @@ static void test_tc_redirect_peer_l3(struct netns_setup_result *setup_result)
XGRESS_FILTER_ADD(&qdisc_veth_dst_fwd, BPF_TC_EGRESS, skel->progs.tc_chk, 0); XGRESS_FILTER_ADD(&qdisc_veth_dst_fwd, BPF_TC_EGRESS, skel->progs.tc_chk, 0);
/* Setup route and neigh tables */ /* Setup route and neigh tables */
SYS("ip -netns " NS_SRC " addr add dev tun_src " IP4_TUN_SRC "/24"); SYS(fail, "ip -netns " NS_SRC " addr add dev tun_src " IP4_TUN_SRC "/24");
SYS("ip -netns " NS_FWD " addr add dev tun_fwd " IP4_TUN_FWD "/24"); SYS(fail, "ip -netns " NS_FWD " addr add dev tun_fwd " IP4_TUN_FWD "/24");
SYS("ip -netns " NS_SRC " addr add dev tun_src " IP6_TUN_SRC "/64 nodad"); SYS(fail, "ip -netns " NS_SRC " addr add dev tun_src " IP6_TUN_SRC "/64 nodad");
SYS("ip -netns " NS_FWD " addr add dev tun_fwd " IP6_TUN_FWD "/64 nodad"); SYS(fail, "ip -netns " NS_FWD " addr add dev tun_fwd " IP6_TUN_FWD "/64 nodad");
SYS("ip -netns " NS_SRC " route del " IP4_DST "/32 dev veth_src scope global"); SYS(fail, "ip -netns " NS_SRC " route del " IP4_DST "/32 dev veth_src scope global");
SYS("ip -netns " NS_SRC " route add " IP4_DST "/32 via " IP4_TUN_FWD SYS(fail, "ip -netns " NS_SRC " route add " IP4_DST "/32 via " IP4_TUN_FWD
" dev tun_src scope global"); " dev tun_src scope global");
SYS("ip -netns " NS_DST " route add " IP4_TUN_SRC "/32 dev veth_dst scope global"); SYS(fail, "ip -netns " NS_DST " route add " IP4_TUN_SRC "/32 dev veth_dst scope global");
SYS("ip -netns " NS_SRC " route del " IP6_DST "/128 dev veth_src scope global"); SYS(fail, "ip -netns " NS_SRC " route del " IP6_DST "/128 dev veth_src scope global");
SYS("ip -netns " NS_SRC " route add " IP6_DST "/128 via " IP6_TUN_FWD SYS(fail, "ip -netns " NS_SRC " route add " IP6_DST "/128 via " IP6_TUN_FWD
" dev tun_src scope global"); " dev tun_src scope global");
SYS("ip -netns " NS_DST " route add " IP6_TUN_SRC "/128 dev veth_dst scope global"); SYS(fail, "ip -netns " NS_DST " route add " IP6_TUN_SRC "/128 dev veth_dst scope global");
SYS("ip -netns " NS_DST " neigh add " IP4_TUN_SRC " dev veth_dst lladdr " MAC_DST_FWD); SYS(fail, "ip -netns " NS_DST " neigh add " IP4_TUN_SRC " dev veth_dst lladdr " MAC_DST_FWD);
SYS("ip -netns " NS_DST " neigh add " IP6_TUN_SRC " dev veth_dst lladdr " MAC_DST_FWD); SYS(fail, "ip -netns " NS_DST " neigh add " IP6_TUN_SRC " dev veth_dst lladdr " MAC_DST_FWD);
if (!ASSERT_OK(set_forwarding(false), "disable forwarding")) if (!ASSERT_OK(set_forwarding(false), "disable forwarding"))
goto fail; goto fail;
......
...@@ -91,30 +91,15 @@ ...@@ -91,30 +91,15 @@
#define PING_ARGS "-i 0.01 -c 3 -w 10 -q" #define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto fail; \
})
#define SYS_NOFAIL(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
system(cmd); \
})
static int config_device(void) static int config_device(void)
{ {
SYS("ip netns add at_ns0"); SYS(fail, "ip netns add at_ns0");
SYS("ip link add veth0 address " MAC_VETH1 " type veth peer name veth1"); SYS(fail, "ip link add veth0 address " MAC_VETH1 " type veth peer name veth1");
SYS("ip link set veth0 netns at_ns0"); SYS(fail, "ip link set veth0 netns at_ns0");
SYS("ip addr add " IP4_ADDR1_VETH1 "/24 dev veth1"); SYS(fail, "ip addr add " IP4_ADDR1_VETH1 "/24 dev veth1");
SYS("ip link set dev veth1 up mtu 1500"); SYS(fail, "ip link set dev veth1 up mtu 1500");
SYS("ip netns exec at_ns0 ip addr add " IP4_ADDR_VETH0 "/24 dev veth0"); SYS(fail, "ip netns exec at_ns0 ip addr add " IP4_ADDR_VETH0 "/24 dev veth0");
SYS("ip netns exec at_ns0 ip link set dev veth0 up mtu 1500"); SYS(fail, "ip netns exec at_ns0 ip link set dev veth0 up mtu 1500");
return 0; return 0;
fail: fail:
...@@ -132,23 +117,23 @@ static void cleanup(void) ...@@ -132,23 +117,23 @@ static void cleanup(void)
static int add_vxlan_tunnel(void) static int add_vxlan_tunnel(void)
{ {
/* at_ns0 namespace */ /* at_ns0 namespace */
SYS("ip netns exec at_ns0 ip link add dev %s type vxlan external gbp dstport 4789", SYS(fail, "ip netns exec at_ns0 ip link add dev %s type vxlan external gbp dstport 4789",
VXLAN_TUNL_DEV0); VXLAN_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip link set dev %s address %s up", SYS(fail, "ip netns exec at_ns0 ip link set dev %s address %s up",
VXLAN_TUNL_DEV0, MAC_TUNL_DEV0); VXLAN_TUNL_DEV0, MAC_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip addr add dev %s %s/24", SYS(fail, "ip netns exec at_ns0 ip addr add dev %s %s/24",
VXLAN_TUNL_DEV0, IP4_ADDR_TUNL_DEV0); VXLAN_TUNL_DEV0, IP4_ADDR_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip neigh add %s lladdr %s dev %s", SYS(fail, "ip netns exec at_ns0 ip neigh add %s lladdr %s dev %s",
IP4_ADDR_TUNL_DEV1, MAC_TUNL_DEV1, VXLAN_TUNL_DEV0); IP4_ADDR_TUNL_DEV1, MAC_TUNL_DEV1, VXLAN_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip neigh add %s lladdr %s dev veth0", SYS(fail, "ip netns exec at_ns0 ip neigh add %s lladdr %s dev veth0",
IP4_ADDR2_VETH1, MAC_VETH1); IP4_ADDR2_VETH1, MAC_VETH1);
/* root namespace */ /* root namespace */
SYS("ip link add dev %s type vxlan external gbp dstport 4789", SYS(fail, "ip link add dev %s type vxlan external gbp dstport 4789",
VXLAN_TUNL_DEV1); VXLAN_TUNL_DEV1);
SYS("ip link set dev %s address %s up", VXLAN_TUNL_DEV1, MAC_TUNL_DEV1); SYS(fail, "ip link set dev %s address %s up", VXLAN_TUNL_DEV1, MAC_TUNL_DEV1);
SYS("ip addr add dev %s %s/24", VXLAN_TUNL_DEV1, IP4_ADDR_TUNL_DEV1); SYS(fail, "ip addr add dev %s %s/24", VXLAN_TUNL_DEV1, IP4_ADDR_TUNL_DEV1);
SYS("ip neigh add %s lladdr %s dev %s", SYS(fail, "ip neigh add %s lladdr %s dev %s",
IP4_ADDR_TUNL_DEV0, MAC_TUNL_DEV0, VXLAN_TUNL_DEV1); IP4_ADDR_TUNL_DEV0, MAC_TUNL_DEV0, VXLAN_TUNL_DEV1);
return 0; return 0;
...@@ -165,26 +150,26 @@ static void delete_vxlan_tunnel(void) ...@@ -165,26 +150,26 @@ static void delete_vxlan_tunnel(void)
static int add_ip6vxlan_tunnel(void) static int add_ip6vxlan_tunnel(void)
{ {
SYS("ip netns exec at_ns0 ip -6 addr add %s/96 dev veth0", SYS(fail, "ip netns exec at_ns0 ip -6 addr add %s/96 dev veth0",
IP6_ADDR_VETH0); IP6_ADDR_VETH0);
SYS("ip netns exec at_ns0 ip link set dev veth0 up"); SYS(fail, "ip netns exec at_ns0 ip link set dev veth0 up");
SYS("ip -6 addr add %s/96 dev veth1", IP6_ADDR1_VETH1); SYS(fail, "ip -6 addr add %s/96 dev veth1", IP6_ADDR1_VETH1);
SYS("ip -6 addr add %s/96 dev veth1", IP6_ADDR2_VETH1); SYS(fail, "ip -6 addr add %s/96 dev veth1", IP6_ADDR2_VETH1);
SYS("ip link set dev veth1 up"); SYS(fail, "ip link set dev veth1 up");
/* at_ns0 namespace */ /* at_ns0 namespace */
SYS("ip netns exec at_ns0 ip link add dev %s type vxlan external dstport 4789", SYS(fail, "ip netns exec at_ns0 ip link add dev %s type vxlan external dstport 4789",
IP6VXLAN_TUNL_DEV0); IP6VXLAN_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip addr add dev %s %s/24", SYS(fail, "ip netns exec at_ns0 ip addr add dev %s %s/24",
IP6VXLAN_TUNL_DEV0, IP4_ADDR_TUNL_DEV0); IP6VXLAN_TUNL_DEV0, IP4_ADDR_TUNL_DEV0);
SYS("ip netns exec at_ns0 ip link set dev %s address %s up", SYS(fail, "ip netns exec at_ns0 ip link set dev %s address %s up",
IP6VXLAN_TUNL_DEV0, MAC_TUNL_DEV0); IP6VXLAN_TUNL_DEV0, MAC_TUNL_DEV0);
/* root namespace */ /* root namespace */
SYS("ip link add dev %s type vxlan external dstport 4789", SYS(fail, "ip link add dev %s type vxlan external dstport 4789",
IP6VXLAN_TUNL_DEV1); IP6VXLAN_TUNL_DEV1);
SYS("ip addr add dev %s %s/24", IP6VXLAN_TUNL_DEV1, IP4_ADDR_TUNL_DEV1); SYS(fail, "ip addr add dev %s %s/24", IP6VXLAN_TUNL_DEV1, IP4_ADDR_TUNL_DEV1);
SYS("ip link set dev %s address %s up", SYS(fail, "ip link set dev %s address %s up",
IP6VXLAN_TUNL_DEV1, MAC_TUNL_DEV1); IP6VXLAN_TUNL_DEV1, MAC_TUNL_DEV1);
return 0; return 0;
...@@ -205,7 +190,7 @@ static void delete_ip6vxlan_tunnel(void) ...@@ -205,7 +190,7 @@ static void delete_ip6vxlan_tunnel(void)
static int test_ping(int family, const char *addr) static int test_ping(int family, const char *addr)
{ {
SYS("%s %s %s > /dev/null", ping_command(family), PING_ARGS, addr); SYS(fail, "%s %s %s > /dev/null", ping_command(family), PING_ARGS, addr);
return 0; return 0;
fail: fail:
return -1; return -1;
......
...@@ -141,41 +141,33 @@ static const char * const xmit_policy_names[] = { ...@@ -141,41 +141,33 @@ static const char * const xmit_policy_names[] = {
static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy, static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy,
int bond_both_attach) int bond_both_attach)
{ {
#define SYS(fmt, ...) \ SYS(fail, "ip netns add ns_dst");
({ \ SYS(fail, "ip link add veth1_1 type veth peer name veth2_1 netns ns_dst");
char cmd[1024]; \ SYS(fail, "ip link add veth1_2 type veth peer name veth2_2 netns ns_dst");
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \ SYS(fail, "ip link add bond1 type bond mode %s xmit_hash_policy %s",
return -1; \
})
SYS("ip netns add ns_dst");
SYS("ip link add veth1_1 type veth peer name veth2_1 netns ns_dst");
SYS("ip link add veth1_2 type veth peer name veth2_2 netns ns_dst");
SYS("ip link add bond1 type bond mode %s xmit_hash_policy %s",
mode_names[mode], xmit_policy_names[xmit_policy]); mode_names[mode], xmit_policy_names[xmit_policy]);
SYS("ip link set bond1 up address " BOND1_MAC_STR " addrgenmode none"); SYS(fail, "ip link set bond1 up address " BOND1_MAC_STR " addrgenmode none");
SYS("ip -netns ns_dst link add bond2 type bond mode %s xmit_hash_policy %s", SYS(fail, "ip -netns ns_dst link add bond2 type bond mode %s xmit_hash_policy %s",
mode_names[mode], xmit_policy_names[xmit_policy]); mode_names[mode], xmit_policy_names[xmit_policy]);
SYS("ip -netns ns_dst link set bond2 up address " BOND2_MAC_STR " addrgenmode none"); SYS(fail, "ip -netns ns_dst link set bond2 up address " BOND2_MAC_STR " addrgenmode none");
SYS("ip link set veth1_1 master bond1"); SYS(fail, "ip link set veth1_1 master bond1");
if (bond_both_attach == BOND_BOTH_AND_ATTACH) { if (bond_both_attach == BOND_BOTH_AND_ATTACH) {
SYS("ip link set veth1_2 master bond1"); SYS(fail, "ip link set veth1_2 master bond1");
} else { } else {
SYS("ip link set veth1_2 up addrgenmode none"); SYS(fail, "ip link set veth1_2 up addrgenmode none");
if (xdp_attach(skeletons, skeletons->xdp_dummy->progs.xdp_dummy_prog, "veth1_2")) if (xdp_attach(skeletons, skeletons->xdp_dummy->progs.xdp_dummy_prog, "veth1_2"))
return -1; return -1;
} }
SYS("ip -netns ns_dst link set veth2_1 master bond2"); SYS(fail, "ip -netns ns_dst link set veth2_1 master bond2");
if (bond_both_attach == BOND_BOTH_AND_ATTACH) if (bond_both_attach == BOND_BOTH_AND_ATTACH)
SYS("ip -netns ns_dst link set veth2_2 master bond2"); SYS(fail, "ip -netns ns_dst link set veth2_2 master bond2");
else else
SYS("ip -netns ns_dst link set veth2_2 up addrgenmode none"); SYS(fail, "ip -netns ns_dst link set veth2_2 up addrgenmode none");
/* Load a dummy program on sending side as with veth peer needs to have a /* Load a dummy program on sending side as with veth peer needs to have a
* XDP program loaded as well. * XDP program loaded as well.
...@@ -194,8 +186,8 @@ static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy, ...@@ -194,8 +186,8 @@ static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy,
} }
return 0; return 0;
fail:
#undef SYS return -1;
} }
static void bonding_cleanup(struct skeletons *skeletons) static void bonding_cleanup(struct skeletons *skeletons)
......
...@@ -12,14 +12,6 @@ ...@@ -12,14 +12,6 @@
#include <uapi/linux/netdev.h> #include <uapi/linux/netdev.h>
#include "test_xdp_do_redirect.skel.h" #include "test_xdp_do_redirect.skel.h"
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto out; \
})
struct udp_packet { struct udp_packet {
struct ethhdr eth; struct ethhdr eth;
struct ipv6hdr iph; struct ipv6hdr iph;
...@@ -126,19 +118,19 @@ void test_xdp_do_redirect(void) ...@@ -126,19 +118,19 @@ void test_xdp_do_redirect(void)
* iface and NUM_PKTS-2 in the TC hook. We match the packets on the UDP * iface and NUM_PKTS-2 in the TC hook. We match the packets on the UDP
* payload. * payload.
*/ */
SYS("ip netns add testns"); SYS(out, "ip netns add testns");
nstoken = open_netns("testns"); nstoken = open_netns("testns");
if (!ASSERT_OK_PTR(nstoken, "setns")) if (!ASSERT_OK_PTR(nstoken, "setns"))
goto out; goto out;
SYS("ip link add veth_src type veth peer name veth_dst"); SYS(out, "ip link add veth_src type veth peer name veth_dst");
SYS("ip link set dev veth_src address 00:11:22:33:44:55"); SYS(out, "ip link set dev veth_src address 00:11:22:33:44:55");
SYS("ip link set dev veth_dst address 66:77:88:99:aa:bb"); SYS(out, "ip link set dev veth_dst address 66:77:88:99:aa:bb");
SYS("ip link set dev veth_src up"); SYS(out, "ip link set dev veth_src up");
SYS("ip link set dev veth_dst up"); SYS(out, "ip link set dev veth_dst up");
SYS("ip addr add dev veth_src fc00::1/64"); SYS(out, "ip addr add dev veth_src fc00::1/64");
SYS("ip addr add dev veth_dst fc00::2/64"); SYS(out, "ip addr add dev veth_dst fc00::2/64");
SYS("ip neigh add fc00::2 dev veth_src lladdr 66:77:88:99:aa:bb"); SYS(out, "ip neigh add fc00::2 dev veth_src lladdr 66:77:88:99:aa:bb");
/* We enable forwarding in the test namespace because that will cause /* We enable forwarding in the test namespace because that will cause
* the packets that go through the kernel stack (with XDP_PASS) to be * the packets that go through the kernel stack (with XDP_PASS) to be
...@@ -151,7 +143,7 @@ void test_xdp_do_redirect(void) ...@@ -151,7 +143,7 @@ void test_xdp_do_redirect(void)
* code didn't have this, so we keep the test behaviour to make sure the * code didn't have this, so we keep the test behaviour to make sure the
* bug doesn't resurface. * bug doesn't resurface.
*/ */
SYS("sysctl -qw net.ipv6.conf.all.forwarding=1"); SYS(out, "sysctl -qw net.ipv6.conf.all.forwarding=1");
ifindex_src = if_nametoindex("veth_src"); ifindex_src = if_nametoindex("veth_src");
ifindex_dst = if_nametoindex("veth_dst"); ifindex_dst = if_nametoindex("veth_dst");
...@@ -225,6 +217,6 @@ void test_xdp_do_redirect(void) ...@@ -225,6 +217,6 @@ void test_xdp_do_redirect(void)
out: out:
if (nstoken) if (nstoken)
close_netns(nstoken); close_netns(nstoken);
system("ip netns del testns"); SYS_NOFAIL("ip netns del testns");
test_xdp_do_redirect__destroy(skel); test_xdp_do_redirect__destroy(skel);
} }
...@@ -34,11 +34,6 @@ ...@@ -34,11 +34,6 @@
#define PREFIX_LEN "8" #define PREFIX_LEN "8"
#define FAMILY AF_INET #define FAMILY AF_INET
#define SYS(cmd) ({ \
if (!ASSERT_OK(system(cmd), (cmd))) \
goto out; \
})
struct xsk { struct xsk {
void *umem_area; void *umem_area;
struct xsk_umem *umem; struct xsk_umem *umem;
...@@ -298,16 +293,16 @@ void test_xdp_metadata(void) ...@@ -298,16 +293,16 @@ void test_xdp_metadata(void)
/* Setup new networking namespace, with a veth pair. */ /* Setup new networking namespace, with a veth pair. */
SYS("ip netns add xdp_metadata"); SYS(out, "ip netns add xdp_metadata");
tok = open_netns("xdp_metadata"); tok = open_netns("xdp_metadata");
SYS("ip link add numtxqueues 1 numrxqueues 1 " TX_NAME SYS(out, "ip link add numtxqueues 1 numrxqueues 1 " TX_NAME
" type veth peer " RX_NAME " numtxqueues 1 numrxqueues 1"); " type veth peer " RX_NAME " numtxqueues 1 numrxqueues 1");
SYS("ip link set dev " TX_NAME " address 00:00:00:00:00:01"); SYS(out, "ip link set dev " TX_NAME " address 00:00:00:00:00:01");
SYS("ip link set dev " RX_NAME " address 00:00:00:00:00:02"); SYS(out, "ip link set dev " RX_NAME " address 00:00:00:00:00:02");
SYS("ip link set dev " TX_NAME " up"); SYS(out, "ip link set dev " TX_NAME " up");
SYS("ip link set dev " RX_NAME " up"); SYS(out, "ip link set dev " RX_NAME " up");
SYS("ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME); SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
SYS("ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME); SYS(out, "ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME);
rx_ifindex = if_nametoindex(RX_NAME); rx_ifindex = if_nametoindex(RX_NAME);
tx_ifindex = if_nametoindex(TX_NAME); tx_ifindex = if_nametoindex(TX_NAME);
...@@ -405,5 +400,5 @@ void test_xdp_metadata(void) ...@@ -405,5 +400,5 @@ void test_xdp_metadata(void)
xdp_metadata__destroy(bpf_obj); xdp_metadata__destroy(bpf_obj);
if (tok) if (tok)
close_netns(tok); close_netns(tok);
system("ip netns del xdp_metadata"); SYS_NOFAIL("ip netns del xdp_metadata");
} }
...@@ -8,11 +8,6 @@ ...@@ -8,11 +8,6 @@
#define CMD_OUT_BUF_SIZE 1023 #define CMD_OUT_BUF_SIZE 1023
#define SYS(cmd) ({ \
if (!ASSERT_OK(system(cmd), (cmd))) \
goto out; \
})
#define SYS_OUT(cmd, ...) ({ \ #define SYS_OUT(cmd, ...) ({ \
char buf[1024]; \ char buf[1024]; \
snprintf(buf, sizeof(buf), (cmd), ##__VA_ARGS__); \ snprintf(buf, sizeof(buf), (cmd), ##__VA_ARGS__); \
...@@ -69,37 +64,37 @@ static void test_synproxy(bool xdp) ...@@ -69,37 +64,37 @@ static void test_synproxy(bool xdp)
char buf[CMD_OUT_BUF_SIZE]; char buf[CMD_OUT_BUF_SIZE];
size_t size; size_t size;
SYS("ip netns add synproxy"); SYS(out, "ip netns add synproxy");
SYS("ip link add tmp0 type veth peer name tmp1"); SYS(out, "ip link add tmp0 type veth peer name tmp1");
SYS("ip link set tmp1 netns synproxy"); SYS(out, "ip link set tmp1 netns synproxy");
SYS("ip link set tmp0 up"); SYS(out, "ip link set tmp0 up");
SYS("ip addr replace 198.18.0.1/24 dev tmp0"); SYS(out, "ip addr replace 198.18.0.1/24 dev tmp0");
/* When checksum offload is enabled, the XDP program sees wrong /* When checksum offload is enabled, the XDP program sees wrong
* checksums and drops packets. * checksums and drops packets.
*/ */
SYS("ethtool -K tmp0 tx off"); SYS(out, "ethtool -K tmp0 tx off");
if (xdp) if (xdp)
/* Workaround required for veth. */ /* Workaround required for veth. */
SYS("ip link set tmp0 xdp object xdp_dummy.bpf.o section xdp 2> /dev/null"); SYS(out, "ip link set tmp0 xdp object xdp_dummy.bpf.o section xdp 2> /dev/null");
ns = open_netns("synproxy"); ns = open_netns("synproxy");
if (!ASSERT_OK_PTR(ns, "setns")) if (!ASSERT_OK_PTR(ns, "setns"))
goto out; goto out;
SYS("ip link set lo up"); SYS(out, "ip link set lo up");
SYS("ip link set tmp1 up"); SYS(out, "ip link set tmp1 up");
SYS("ip addr replace 198.18.0.2/24 dev tmp1"); SYS(out, "ip addr replace 198.18.0.2/24 dev tmp1");
SYS("sysctl -w net.ipv4.tcp_syncookies=2"); SYS(out, "sysctl -w net.ipv4.tcp_syncookies=2");
SYS("sysctl -w net.ipv4.tcp_timestamps=1"); SYS(out, "sysctl -w net.ipv4.tcp_timestamps=1");
SYS("sysctl -w net.netfilter.nf_conntrack_tcp_loose=0"); SYS(out, "sysctl -w net.netfilter.nf_conntrack_tcp_loose=0");
SYS("iptables-legacy -t raw -I PREROUTING \ SYS(out, "iptables-legacy -t raw -I PREROUTING \
-i tmp1 -p tcp -m tcp --syn --dport 8080 -j CT --notrack"); -i tmp1 -p tcp -m tcp --syn --dport 8080 -j CT --notrack");
SYS("iptables-legacy -t filter -A INPUT \ SYS(out, "iptables-legacy -t filter -A INPUT \
-i tmp1 -p tcp -m tcp --dport 8080 -m state --state INVALID,UNTRACKED \ -i tmp1 -p tcp -m tcp --dport 8080 -m state --state INVALID,UNTRACKED \
-j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460"); -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460");
SYS("iptables-legacy -t filter -A INPUT \ SYS(out, "iptables-legacy -t filter -A INPUT \
-i tmp1 -m state --state INVALID -j DROP"); -i tmp1 -m state --state INVALID -j DROP");
ctrl_file = SYS_OUT("./xdp_synproxy --iface tmp1 --ports 8080 \ ctrl_file = SYS_OUT("./xdp_synproxy --iface tmp1 --ports 8080 \
...@@ -170,8 +165,8 @@ static void test_synproxy(bool xdp) ...@@ -170,8 +165,8 @@ static void test_synproxy(bool xdp)
if (ns) if (ns)
close_netns(ns); close_netns(ns);
system("ip link del tmp0"); SYS_NOFAIL("ip link del tmp0");
system("ip netns del synproxy"); SYS_NOFAIL("ip netns del synproxy");
} }
void test_xdp_synproxy(void) void test_xdp_synproxy(void)
......
...@@ -69,21 +69,6 @@ ...@@ -69,21 +69,6 @@
"proto esp aead 'rfc4106(gcm(aes))' " \ "proto esp aead 'rfc4106(gcm(aes))' " \
"0xe4d8f4b4da1df18a3510b3781496daa82488b713 128 mode tunnel " "0xe4d8f4b4da1df18a3510b3781496daa82488b713 128 mode tunnel "
#define SYS(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto fail; \
})
#define SYS_NOFAIL(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
system(cmd); \
})
static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd) static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)
{ {
LIBBPF_OPTS(bpf_tc_opts, opts1, .handle = 1, .priority = 1, LIBBPF_OPTS(bpf_tc_opts, opts1, .handle = 1, .priority = 1,
...@@ -126,23 +111,23 @@ static void cleanup(void) ...@@ -126,23 +111,23 @@ static void cleanup(void)
static int config_underlay(void) static int config_underlay(void)
{ {
SYS("ip netns add " NS0); SYS(fail, "ip netns add " NS0);
SYS("ip netns add " NS1); SYS(fail, "ip netns add " NS1);
SYS("ip netns add " NS2); SYS(fail, "ip netns add " NS2);
/* NS0 <-> NS1 [veth01 <-> veth10] */ /* NS0 <-> NS1 [veth01 <-> veth10] */
SYS("ip link add veth01 netns " NS0 " type veth peer name veth10 netns " NS1); SYS(fail, "ip link add veth01 netns " NS0 " type veth peer name veth10 netns " NS1);
SYS("ip -net " NS0 " addr add " IP4_ADDR_VETH01 "/24 dev veth01"); SYS(fail, "ip -net " NS0 " addr add " IP4_ADDR_VETH01 "/24 dev veth01");
SYS("ip -net " NS0 " link set dev veth01 up"); SYS(fail, "ip -net " NS0 " link set dev veth01 up");
SYS("ip -net " NS1 " addr add " IP4_ADDR_VETH10 "/24 dev veth10"); SYS(fail, "ip -net " NS1 " addr add " IP4_ADDR_VETH10 "/24 dev veth10");
SYS("ip -net " NS1 " link set dev veth10 up"); SYS(fail, "ip -net " NS1 " link set dev veth10 up");
/* NS0 <-> NS2 [veth02 <-> veth20] */ /* NS0 <-> NS2 [veth02 <-> veth20] */
SYS("ip link add veth02 netns " NS0 " type veth peer name veth20 netns " NS2); SYS(fail, "ip link add veth02 netns " NS0 " type veth peer name veth20 netns " NS2);
SYS("ip -net " NS0 " addr add " IP4_ADDR_VETH02 "/24 dev veth02"); SYS(fail, "ip -net " NS0 " addr add " IP4_ADDR_VETH02 "/24 dev veth02");
SYS("ip -net " NS0 " link set dev veth02 up"); SYS(fail, "ip -net " NS0 " link set dev veth02 up");
SYS("ip -net " NS2 " addr add " IP4_ADDR_VETH20 "/24 dev veth20"); SYS(fail, "ip -net " NS2 " addr add " IP4_ADDR_VETH20 "/24 dev veth20");
SYS("ip -net " NS2 " link set dev veth20 up"); SYS(fail, "ip -net " NS2 " link set dev veth20 up");
return 0; return 0;
fail: fail:
...@@ -153,20 +138,20 @@ static int setup_xfrm_tunnel_ns(const char *ns, const char *ipv4_local, ...@@ -153,20 +138,20 @@ static int setup_xfrm_tunnel_ns(const char *ns, const char *ipv4_local,
const char *ipv4_remote, int if_id) const char *ipv4_remote, int if_id)
{ {
/* State: local -> remote */ /* State: local -> remote */
SYS("ip -net %s xfrm state add src %s dst %s spi 1 " SYS(fail, "ip -net %s xfrm state add src %s dst %s spi 1 "
ESP_DUMMY_PARAMS "if_id %d", ns, ipv4_local, ipv4_remote, if_id); ESP_DUMMY_PARAMS "if_id %d", ns, ipv4_local, ipv4_remote, if_id);
/* State: local <- remote */ /* State: local <- remote */
SYS("ip -net %s xfrm state add src %s dst %s spi 1 " SYS(fail, "ip -net %s xfrm state add src %s dst %s spi 1 "
ESP_DUMMY_PARAMS "if_id %d", ns, ipv4_remote, ipv4_local, if_id); ESP_DUMMY_PARAMS "if_id %d", ns, ipv4_remote, ipv4_local, if_id);
/* Policy: local -> remote */ /* Policy: local -> remote */
SYS("ip -net %s xfrm policy add dir out src 0.0.0.0/0 dst 0.0.0.0/0 " SYS(fail, "ip -net %s xfrm policy add dir out src 0.0.0.0/0 dst 0.0.0.0/0 "
"if_id %d tmpl src %s dst %s proto esp mode tunnel if_id %d", ns, "if_id %d tmpl src %s dst %s proto esp mode tunnel if_id %d", ns,
if_id, ipv4_local, ipv4_remote, if_id); if_id, ipv4_local, ipv4_remote, if_id);
/* Policy: local <- remote */ /* Policy: local <- remote */
SYS("ip -net %s xfrm policy add dir in src 0.0.0.0/0 dst 0.0.0.0/0 " SYS(fail, "ip -net %s xfrm policy add dir in src 0.0.0.0/0 dst 0.0.0.0/0 "
"if_id %d tmpl src %s dst %s proto esp mode tunnel if_id %d", ns, "if_id %d tmpl src %s dst %s proto esp mode tunnel if_id %d", ns,
if_id, ipv4_remote, ipv4_local, if_id); if_id, ipv4_remote, ipv4_local, if_id);
...@@ -274,16 +259,16 @@ static int config_overlay(void) ...@@ -274,16 +259,16 @@ static int config_overlay(void)
if (!ASSERT_OK(setup_xfrmi_external_dev(NS0), "xfrmi")) if (!ASSERT_OK(setup_xfrmi_external_dev(NS0), "xfrmi"))
goto fail; goto fail;
SYS("ip -net " NS0 " addr add 192.168.1.100/24 dev ipsec0"); SYS(fail, "ip -net " NS0 " addr add 192.168.1.100/24 dev ipsec0");
SYS("ip -net " NS0 " link set dev ipsec0 up"); SYS(fail, "ip -net " NS0 " link set dev ipsec0 up");
SYS("ip -net " NS1 " link add ipsec0 type xfrm if_id %d", IF_ID_1); SYS(fail, "ip -net " NS1 " link add ipsec0 type xfrm if_id %d", IF_ID_1);
SYS("ip -net " NS1 " addr add 192.168.1.200/24 dev ipsec0"); SYS(fail, "ip -net " NS1 " addr add 192.168.1.200/24 dev ipsec0");
SYS("ip -net " NS1 " link set dev ipsec0 up"); SYS(fail, "ip -net " NS1 " link set dev ipsec0 up");
SYS("ip -net " NS2 " link add ipsec0 type xfrm if_id %d", IF_ID_2); SYS(fail, "ip -net " NS2 " link add ipsec0 type xfrm if_id %d", IF_ID_2);
SYS("ip -net " NS2 " addr add 192.168.1.200/24 dev ipsec0"); SYS(fail, "ip -net " NS2 " addr add 192.168.1.200/24 dev ipsec0");
SYS("ip -net " NS2 " link set dev ipsec0 up"); SYS(fail, "ip -net " NS2 " link set dev ipsec0 up");
return 0; return 0;
fail: fail:
...@@ -294,7 +279,7 @@ static int test_xfrm_ping(struct xfrm_info *skel, u32 if_id) ...@@ -294,7 +279,7 @@ static int test_xfrm_ping(struct xfrm_info *skel, u32 if_id)
{ {
skel->bss->req_if_id = if_id; skel->bss->req_if_id = if_id;
SYS("ping -i 0.01 -c 3 -w 10 -q 192.168.1.200 > /dev/null"); SYS(fail, "ping -i 0.01 -c 3 -w 10 -q 192.168.1.200 > /dev/null");
if (!ASSERT_EQ(skel->bss->resp_if_id, if_id, "if_id")) if (!ASSERT_EQ(skel->bss->resp_if_id, if_id, "if_id"))
goto fail; goto fail;
......
...@@ -376,6 +376,21 @@ int test__join_cgroup(const char *path); ...@@ -376,6 +376,21 @@ int test__join_cgroup(const char *path);
___ok; \ ___ok; \
}) })
#define SYS(goto_label, fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
if (!ASSERT_OK(system(cmd), cmd)) \
goto goto_label; \
})
#define SYS_NOFAIL(fmt, ...) \
({ \
char cmd[1024]; \
snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
system(cmd); \
})
static inline __u64 ptr_to_u64(const void *ptr) static inline __u64 ptr_to_u64(const void *ptr)
{ {
return (__u64) (unsigned long) ptr; return (__u64) (unsigned long) ptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment