@@ -31,6 +31,7 @@ IFACES=""
31
31
DRV_MODE=" xdpgeneric xdpdrv xdpegress"
32
32
PASS=0
33
33
FAIL=0
34
+ LOG_DIR=$( mktemp -d)
34
35
35
36
test_pass ()
36
37
{
@@ -100,17 +101,17 @@ do_egress_tests()
100
101
local mode=$1
101
102
102
103
# mac test
103
- ip netns exec ns2 tcpdump -e -i veth0 -nn -l -e & > mac_ns1-2_${mode} .log &
104
- ip netns exec ns3 tcpdump -e -i veth0 -nn -l -e & > mac_ns1-3_${mode} .log &
104
+ ip netns exec ns2 tcpdump -e -i veth0 -nn -l -e & > ${LOG_DIR} / mac_ns1-2_${mode} .log &
105
+ ip netns exec ns3 tcpdump -e -i veth0 -nn -l -e & > ${LOG_DIR} / mac_ns1-3_${mode} .log &
105
106
sleep 0.5
106
107
ip netns exec ns1 ping 192.0.2.254 -i 0.1 -c 4 & > /dev/null
107
108
sleep 0.5
108
109
pkill -9 tcpdump
109
110
110
111
# mac check
111
- grep -q " ${veth_mac[2]} > ff:ff:ff:ff:ff:ff" mac_ns1-2_${mode} .log && \
112
+ grep -q " ${veth_mac[2]} > ff:ff:ff:ff:ff:ff" ${LOG_DIR} / mac_ns1-2_${mode} .log && \
112
113
test_pass " $mode mac ns1-2" || test_fail " $mode mac ns1-2"
113
- grep -q " ${veth_mac[3]} > ff:ff:ff:ff:ff:ff" mac_ns1-3_${mode} .log && \
114
+ grep -q " ${veth_mac[3]} > ff:ff:ff:ff:ff:ff" ${LOG_DIR} / mac_ns1-3_${mode} .log && \
114
115
test_pass " $mode mac ns1-3" || test_fail " $mode mac ns1-3"
115
116
}
116
117
@@ -121,9 +122,9 @@ do_ping_tests()
121
122
# ping6 test: echo request should be redirect back to itself, not others
122
123
ip netns exec ns1 ip neigh add 2001:db8::2 dev veth0 lladdr 00:00:00:00:00:02
123
124
124
- ip netns exec ns1 tcpdump -i veth0 -nn -l -e & > ns1-1_${mode} .log &
125
- ip netns exec ns2 tcpdump -i veth0 -nn -l -e & > ns1-2_${mode} .log &
126
- ip netns exec ns3 tcpdump -i veth0 -nn -l -e & > ns1-3_${mode} .log &
125
+ ip netns exec ns1 tcpdump -i veth0 -nn -l -e & > ${LOG_DIR} / ns1-1_${mode} .log &
126
+ ip netns exec ns2 tcpdump -i veth0 -nn -l -e & > ${LOG_DIR} / ns1-2_${mode} .log &
127
+ ip netns exec ns3 tcpdump -i veth0 -nn -l -e & > ${LOG_DIR} / ns1-3_${mode} .log &
127
128
sleep 0.5
128
129
# ARP test
129
130
ip netns exec ns1 ping 192.0.2.254 -i 0.1 -c 4 & > /dev/null
@@ -135,32 +136,32 @@ do_ping_tests()
135
136
pkill -9 tcpdump
136
137
137
138
# All netns should receive the redirect arp requests
138
- [ $( grep -c " who-has 192.0.2.254" ns1-1_${mode} .log) -gt 4 ] && \
139
+ [ $( grep -c " who-has 192.0.2.254" ${LOG_DIR} / ns1-1_${mode} .log) -gt 4 ] && \
139
140
test_pass " $mode arp(F_BROADCAST) ns1-1" || \
140
141
test_fail " $mode arp(F_BROADCAST) ns1-1"
141
- [ $( grep -c " who-has 192.0.2.254" ns1-2_${mode} .log) -le 4 ] && \
142
+ [ $( grep -c " who-has 192.0.2.254" ${LOG_DIR} / ns1-2_${mode} .log) -le 4 ] && \
142
143
test_pass " $mode arp(F_BROADCAST) ns1-2" || \
143
144
test_fail " $mode arp(F_BROADCAST) ns1-2"
144
- [ $( grep -c " who-has 192.0.2.254" ns1-3_${mode} .log) -le 4 ] && \
145
+ [ $( grep -c " who-has 192.0.2.254" ${LOG_DIR} / ns1-3_${mode} .log) -le 4 ] && \
145
146
test_pass " $mode arp(F_BROADCAST) ns1-3" || \
146
147
test_fail " $mode arp(F_BROADCAST) ns1-3"
147
148
148
149
# ns1 should not receive the redirect echo request, others should
149
- [ $( grep -c " ICMP echo request" ns1-1_${mode} .log) -eq 4 ] && \
150
+ [ $( grep -c " ICMP echo request" ${LOG_DIR} / ns1-1_${mode} .log) -eq 4 ] && \
150
151
test_pass " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-1" || \
151
152
test_fail " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-1"
152
- [ $( grep -c " ICMP echo request" ns1-2_${mode} .log) -eq 4 ] && \
153
+ [ $( grep -c " ICMP echo request" ${LOG_DIR} / ns1-2_${mode} .log) -eq 4 ] && \
153
154
test_pass " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-2" || \
154
155
test_fail " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-2"
155
- [ $( grep -c " ICMP echo request" ns1-3_${mode} .log) -eq 4 ] && \
156
+ [ $( grep -c " ICMP echo request" ${LOG_DIR} / ns1-3_${mode} .log) -eq 4 ] && \
156
157
test_pass " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-3" || \
157
158
test_fail " $mode IPv4 (F_BROADCAST|F_EXCLUDE_INGRESS) ns1-3"
158
159
159
160
# ns1 should receive the echo request, ns2 should not
160
- [ $( grep -c " ICMP6, echo request" ns1-1_${mode} .log) -eq 4 ] && \
161
+ [ $( grep -c " ICMP6, echo request" ${LOG_DIR} / ns1-1_${mode} .log) -eq 4 ] && \
161
162
test_pass " $mode IPv6 (no flags) ns1-1" || \
162
163
test_fail " $mode IPv6 (no flags) ns1-1"
163
- [ $( grep -c " ICMP6, echo request" ns1-2_${mode} .log) -eq 0 ] && \
164
+ [ $( grep -c " ICMP6, echo request" ${LOG_DIR} / ns1-2_${mode} .log) -eq 0 ] && \
164
165
test_pass " $mode IPv6 (no flags) ns1-2" || \
165
166
test_fail " $mode IPv6 (no flags) ns1-2"
166
167
}
@@ -176,7 +177,7 @@ do_tests()
176
177
xdpgeneric) drv_p=" -S" ;;
177
178
esac
178
179
179
- ./xdp_redirect_multi $drv_p $IFACES & > xdp_redirect_${mode} .log &
180
+ ./xdp_redirect_multi $drv_p $IFACES & > ${LOG_DIR} / xdp_redirect_${mode} .log &
180
181
xdp_pid=$!
181
182
sleep 1
182
183
@@ -192,13 +193,13 @@ do_tests()
192
193
trap clean_up 0 2 3 6 9
193
194
194
195
check_env
195
- rm -f xdp_redirect_* .log ns* .log mac_ns* .log
196
196
197
197
for mode in ${DRV_MODE} ; do
198
198
setup_ns $mode
199
199
do_tests $mode
200
200
clean_up
201
201
done
202
+ rm -rf ${LOG_DIR}
202
203
203
204
echo " Summary: PASS $PASS , FAIL $FAIL "
204
205
[ $FAIL -eq 0 ] && exit 0 || exit 1
0 commit comments