Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: forwarding: Fix failing tests with old libnet

The custom multipath hash tests use mausezahn in order to test how
changes in various packet fields affect the packet distribution across
the available nexthops.

The tool uses the libnet library for various low-level packet
construction and injection. The library started using the
"SO_BINDTODEVICE" socket option for IPv6 sockets in version 1.1.6 and
for IPv4 sockets in version 1.2.

When the option is not set, packets are not routed according to the
table associated with the VRF master device and tests fail.

Fix this by prefixing the command with "ip vrf exec", which will cause
the route lookup to occur in the VRF routing table. This makes the tests
pass regardless of the libnet library version.

Fixes: 511e8db54036 ("selftests: forwarding: Add test for custom multipath hash")
Fixes: 185b0c190bb6 ("selftests: forwarding: Add test for custom multipath hash with IPv4 GRE")
Fixes: b7715acba4d3 ("selftests: forwarding: Add test for custom multipath hash with IPv6 GRE")
Reported-by: Ivan Vecera <ivecera@redhat.com>
Tested-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Link: https://lore.kernel.org/r/20220809113320.751413-1-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ido Schimmel and committed by
Jakub Kicinski
8bcfb4ae fbe8870f

+48 -24
+16 -8
tools/testing/selftests/net/forwarding/custom_multipath_hash.sh
··· 181 181 182 182 send_src_ipv4() 183 183 { 184 - $MZ $h1 -q -p 64 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 184 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 185 + -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 185 186 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 186 187 } 187 188 188 189 send_dst_ipv4() 189 190 { 190 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 191 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 192 + -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 191 193 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 192 194 } 193 195 194 196 send_src_udp4() 195 197 { 196 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 198 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 199 + -A 198.51.100.2 -B 203.0.113.2 \ 197 200 -d 1msec -t udp "sp=0-32768,dp=30000" 198 201 } 199 202 200 203 send_dst_udp4() 201 204 { 202 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 205 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 206 + -A 198.51.100.2 -B 203.0.113.2 \ 203 207 -d 1msec -t udp "sp=20000,dp=0-32768" 204 208 } 205 209 206 210 send_src_ipv6() 207 211 { 208 - $MZ -6 $h1 -q -p 64 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:4::2 \ 212 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 213 + -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:4::2 \ 209 214 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 210 215 } 211 216 212 217 send_dst_ipv6() 213 218 { 214 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B "2001:db8:4::2-2001:db8:4::fd" \ 219 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 220 + -A 2001:db8:1::2 -B "2001:db8:4::2-2001:db8:4::fd" \ 215 221 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 216 222 } 217 223 ··· 232 226 233 227 send_src_udp6() 234 228 { 235 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:4::2 \ 229 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 230 + -A 2001:db8:1::2 -B 2001:db8:4::2 \ 236 231 -d 1msec -t udp "sp=0-32768,dp=30000" 237 232 } 238 233 239 234 send_dst_udp6() 240 235 { 241 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:4::2 \ 236 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 237 + -A 2001:db8:1::2 -B 2001:db8:4::2 \ 242 238 -d 1msec -t udp "sp=20000,dp=0-32768" 243 239 } 244 240
+16 -8
tools/testing/selftests/net/forwarding/gre_custom_multipath_hash.sh
··· 276 276 277 277 send_src_ipv4() 278 278 { 279 - $MZ $h1 -q -p 64 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 279 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 280 + -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 280 281 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 281 282 } 282 283 283 284 send_dst_ipv4() 284 285 { 285 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 286 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 287 + -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 286 288 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 287 289 } 288 290 289 291 send_src_udp4() 290 292 { 291 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 293 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 294 + -A 198.51.100.2 -B 203.0.113.2 \ 292 295 -d 1msec -t udp "sp=0-32768,dp=30000" 293 296 } 294 297 295 298 send_dst_udp4() 296 299 { 297 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 300 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 301 + -A 198.51.100.2 -B 203.0.113.2 \ 298 302 -d 1msec -t udp "sp=20000,dp=0-32768" 299 303 } 300 304 301 305 send_src_ipv6() 302 306 { 303 - $MZ -6 $h1 -q -p 64 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:2::2 \ 307 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 308 + -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:2::2 \ 304 309 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 305 310 } 306 311 307 312 send_dst_ipv6() 308 313 { 309 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \ 314 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 315 + -A 2001:db8:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \ 310 316 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 311 317 } 312 318 ··· 327 321 328 322 send_src_udp6() 329 323 { 330 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:2::2 \ 324 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 325 + -A 2001:db8:1::2 -B 2001:db8:2::2 \ 331 326 -d 1msec -t udp "sp=0-32768,dp=30000" 332 327 } 333 328 334 329 send_dst_udp6() 335 330 { 336 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:2::2 \ 331 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 332 + -A 2001:db8:1::2 -B 2001:db8:2::2 \ 337 333 -d 1msec -t udp "sp=20000,dp=0-32768" 338 334 } 339 335
+16 -8
tools/testing/selftests/net/forwarding/ip6gre_custom_multipath_hash.sh
··· 278 278 279 279 send_src_ipv4() 280 280 { 281 - $MZ $h1 -q -p 64 -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 281 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 282 + -A "198.51.100.2-198.51.100.253" -B 203.0.113.2 \ 282 283 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 283 284 } 284 285 285 286 send_dst_ipv4() 286 287 { 287 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 288 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 289 + -A 198.51.100.2 -B "203.0.113.2-203.0.113.253" \ 288 290 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 289 291 } 290 292 291 293 send_src_udp4() 292 294 { 293 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 295 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 296 + -A 198.51.100.2 -B 203.0.113.2 \ 294 297 -d 1msec -t udp "sp=0-32768,dp=30000" 295 298 } 296 299 297 300 send_dst_udp4() 298 301 { 299 - $MZ $h1 -q -p 64 -A 198.51.100.2 -B 203.0.113.2 \ 302 + ip vrf exec v$h1 $MZ $h1 -q -p 64 \ 303 + -A 198.51.100.2 -B 203.0.113.2 \ 300 304 -d 1msec -t udp "sp=20000,dp=0-32768" 301 305 } 302 306 303 307 send_src_ipv6() 304 308 { 305 - $MZ -6 $h1 -q -p 64 -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:2::2 \ 309 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 310 + -A "2001:db8:1::2-2001:db8:1::fd" -B 2001:db8:2::2 \ 306 311 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 307 312 } 308 313 309 314 send_dst_ipv6() 310 315 { 311 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \ 316 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 317 + -A 2001:db8:1::2 -B "2001:db8:2::2-2001:db8:2::fd" \ 312 318 -d 1msec -c 50 -t udp "sp=20000,dp=30000" 313 319 } 314 320 ··· 329 323 330 324 send_src_udp6() 331 325 { 332 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:2::2 \ 326 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 327 + -A 2001:db8:1::2 -B 2001:db8:2::2 \ 333 328 -d 1msec -t udp "sp=0-32768,dp=30000" 334 329 } 335 330 336 331 send_dst_udp6() 337 332 { 338 - $MZ -6 $h1 -q -p 64 -A 2001:db8:1::2 -B 2001:db8:2::2 \ 333 + ip vrf exec v$h1 $MZ -6 $h1 -q -p 64 \ 334 + -A 2001:db8:1::2 -B 2001:db8:2::2 \ 339 335 -d 1msec -t udp "sp=20000,dp=0-32768" 340 336 } 341 337