#!/usr/bin/env bats -*- bats -*- # # macvlan driver test # load helpers function setup() { basic_setup # create a extra interface which we can use to connect the ipvlan to run_in_host_netns ip link add dummy0 type dummy } @test "simple ipvlan setup" { run_netavark --file ${TESTSDIR}/testfiles/ipvlan.json setup $(get_container_netns_path) result="$output" mac=$(jq -r '.podman.interfaces.eth0.mac_address' <<< "$result" ) # check that interface exists run_in_container_netns ip -j --details link show eth0 link_info="$output" assert_json "$link_info" ".[].address" "==" "$mac" "MAC matches container mac" assert_json "$link_info" '.[].flags[] | select(.=="UP")' "==" "UP" "Container interface is up" assert_json "$link_info" ".[].linkinfo.info_kind" "==" "ipvlan" "Container interface is a ipvlan device" ipaddr="10.88.0.2/16" run_in_container_netns ip addr show eth0 assert "$output" "=~" "$ipaddr" "IP address matches container address" assert_json "$result" ".podman.interfaces.eth0.subnets[0].ipnet" "==" "$ipaddr" "Result contains correct IP address" # check gateway assignment run_in_container_netns ip r assert "$output" "=~" "default via 10.88.0.1" "gateway must be there in default route" assert_json "$result" ".podman.interfaces.eth0.subnets[0].gateway" == "10.88.0.1" "Result contains gateway address" run_in_container_netns cat /proc/sys/net/ipv6/conf/eth0/autoconf assert "0" "autoconf is disabled" run_netavark --file ${TESTSDIR}/testfiles/ipvlan.json teardown $(get_container_netns_path) assert "" "no errors" } @test "ipvlan setup with static routes" { # add second interface and routes through that interface to test proper teardown run_in_container_netns ip link add type dummy run_in_container_netns ip a add 10.91.0.10/24 dev dummy0 run_in_container_netns ip link set dummy0 up run_netavark --file ${TESTSDIR}/testfiles/ipvlan-staticroutes.json setup $(get_container_netns_path) # check static routes run_in_container_netns ip r assert "$output" "=~" "10.89.0.0/24 via 10.88.0.2" "static route not set" assert "$output" "=~" "10.90.0.0/24 via 10.88.0.3" "static route not set" assert "$output" "=~" "10.92.0.0/24 via 10.91.0.1" "static route not set" run_in_container_netns ip -6 r assert "$output" "=~" "fd:2f2f::/64 via fd:1f1f::20" "static route not set" run_netavark --file ${TESTSDIR}/testfiles/ipvlan-staticroutes.json teardown $(get_container_netns_path) assert "" "no errors" # check static routes get removed run_in_container_netns ip r assert "$output" "!~" "10.89.0.0/24 via 10.88.0.2" "static route not removed" assert "$output" "!~" "10.90.0.0/24 via 10.88.0.3" "static route not removed" assert "$output" "!~" "10.92.0.0/24 via 10.91.0.1" "static route not removed" run_in_container_netns ip -6 r assert "$output" "!~" "fd:2f2f::/64 via fd:1f1f::20" "static route not removed" run_in_container_netns ip link delete dummy0 } @test "ipvlan setup no default route" { run_netavark --file ${TESTSDIR}/testfiles/ipvlan-nodefaultroute.json setup $(get_container_netns_path) run_in_container_netns ip r assert "$output" "!~" "default" "default route exists" run_in_container_netns ip -6 r assert "$output" "!~" "default" "default route exists" run_netavark --file ${TESTSDIR}/testfiles/ipvlan-nodefaultroute.json teardown $(get_container_netns_path) assert "" "no errors" } @test "ipvlan setup internal" { run_netavark --file ${TESTSDIR}/testfiles/ipvlan-internal.json setup $(get_container_netns_path) result="$output" mac=$(jq -r '.podman.interfaces.eth0.mac_address' <<< "$result" ) # check that interface exists run_in_container_netns ip -j --details link show eth0 link_info="$output" assert_json "$link_info" ".[].address" "==" "$mac" "MAC matches container mac" assert_json "$link_info" '.[].flags[] | select(.=="UP")' "==" "UP" "Container interface is up" assert_json "$link_info" ".[].linkinfo.info_kind" "==" "ipvlan" "Container interface is a ipvlan device" ipaddr="10.88.0.2/16" run_in_container_netns ip addr show eth0 assert "$output" "=~" "$ipaddr" "IP address matches container address" assert_json "$result" ".podman.interfaces.eth0.subnets[0].ipnet" "==" "$ipaddr" "Result contains correct IP address" # internal ipvlan must not contain run_in_container_netns ip r assert "$output" !~ 'default' "ipvlan must not contain default gateway in route at all" } @test "ipvlan setup with mtu" { run_netavark --file ${TESTSDIR}/testfiles/ipvlan-mtu.json setup $(get_container_netns_path) result="$output" mac=$(jq -r '.podman.interfaces.eth0.mac_address' <<< "$result" ) # check that interface exists run_in_container_netns ip -j --details link show eth0 link_info="$output" assert_json "$link_info" ".[].mtu" "==" "1400" "MTU matches configured MTU" assert_json "$link_info" ".[].address" "==" "$mac" "MAC matches container mac" assert_json "$link_info" '.[].flags[] | select(.=="UP")' "==" "UP" "Container interface is up" assert_json "$link_info" ".[].linkinfo.info_kind" "==" "ipvlan" "Container interface is a ipvlan device" ipaddr="10.88.0.2" run_in_container_netns ip -j addr show eth0 link_info="$output" assert_json "$link_info" ".[].addr_info[0].local" "==" "$ipaddr" "IP address matches container address" assert_json "$link_info" ".[].addr_info[0].prefixlen" "==" "16" "IP prefix matches container subnet" assert_json "$result" ".podman.interfaces.eth0.subnets[0].ipnet" "==" "$ipaddr/16" "Result contains correct IP address" } @test "ipvlan modes" { for mode in l2 l3 l3s; do # echo here so we know which test failed echo "mode $mode" read -r -d '\0' config <