1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4ALL_TESTS="ping_ipv4 ping_ipv6" 5NUM_NETIFS=4 6source lib.sh 7 8h1_create() 9{ 10 vrf_create "vrf-h1" 11 ip link set dev $h1 master vrf-h1 12 13 ip link set dev vrf-h1 up 14 ip link set dev $h1 up 15 16 ip address add 192.0.2.2/24 dev $h1 17 ip address add 2001:db8:1::2/64 dev $h1 18 19 ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1 20 ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1 21} 22 23h1_destroy() 24{ 25 ip route del 2001:db8:2::/64 vrf vrf-h1 26 ip route del 198.51.100.0/24 vrf vrf-h1 27 28 ip address del 2001:db8:1::2/64 dev $h1 29 ip address del 192.0.2.2/24 dev $h1 30 31 ip link set dev $h1 down 32 vrf_destroy "vrf-h1" 33} 34 35h2_create() 36{ 37 vrf_create "vrf-h2" 38 ip link set dev $h2 master vrf-h2 39 40 ip link set dev vrf-h2 up 41 ip link set dev $h2 up 42 43 ip address add 198.51.100.2/24 dev $h2 44 ip address add 2001:db8:2::2/64 dev $h2 45 46 ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1 47 ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1 48} 49 50h2_destroy() 51{ 52 ip route del 2001:db8:1::/64 vrf vrf-h2 53 ip route del 192.0.2.0/24 vrf vrf-h2 54 55 ip address del 2001:db8:2::2/64 dev $h2 56 ip address del 198.51.100.2/24 dev $h2 57 58 ip link set dev $h2 down 59 vrf_destroy "vrf-h2" 60} 61 62router_create() 63{ 64 ip link set dev $rp1 up 65 ip link set dev $rp2 up 66 67 ip address add 192.0.2.1/24 dev $rp1 68 ip address add 2001:db8:1::1/64 dev $rp1 69 70 ip address add 198.51.100.1/24 dev $rp2 71 ip address add 2001:db8:2::1/64 dev $rp2 72} 73 74router_destroy() 75{ 76 ip address del 2001:db8:2::1/64 dev $rp2 77 ip address del 198.51.100.1/24 dev $rp2 78 79 ip address del 2001:db8:1::1/64 dev $rp1 80 ip address del 192.0.2.1/24 dev $rp1 81 82 ip link set dev $rp2 down 83 ip link set dev $rp1 down 84} 85 86setup_prepare() 87{ 88 h1=${NETIFS[p1]} 89 rp1=${NETIFS[p2]} 90 91 rp2=${NETIFS[p3]} 92 h2=${NETIFS[p4]} 93 94 vrf_prepare 95 96 h1_create 97 h2_create 98 99 router_create 100 101 forwarding_enable 102} 103 104cleanup() 105{ 106 pre_cleanup 107 108 forwarding_restore 109 110 router_destroy 111 112 h2_destroy 113 h1_destroy 114 115 vrf_cleanup 116} 117 118ping_ipv4() 119{ 120 ping_test $h1 198.51.100.2 121} 122 123ping_ipv6() 124{ 125 ping6_test $h1 2001:db8:2::2 126} 127 128trap cleanup EXIT 129 130setup_prepare 131setup_wait 132 133tests_run 134 135exit $EXIT_STATUS 136