Skip to content

Commit

Permalink
selftests: Add separate option to nettest for address binding
Browse files Browse the repository at this point in the history
Add separate option to nettest to specify local address
binding in client mode.

Signed-off-by: David Ahern <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
dsahern authored and kuba-moo committed Jan 15, 2021
1 parent f26a008 commit 5265a01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tools/testing/selftests/net/fcnal-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ ipv4_tcp_md5_novrf()
show_hint "Should timeout due to MD5 mismatch"
run_cmd nettest -s -M ${MD5_PW} -m ${NS_NET} &
sleep 1
run_cmd_nsb nettest -l ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
run_cmd_nsb nettest -c ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
}

Expand Down Expand Up @@ -922,7 +922,7 @@ ipv4_tcp_md5()
show_hint "Should timeout since client address is outside of prefix"
run_cmd nettest -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET} &
sleep 1
run_cmd_nsb nettest -l ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
run_cmd_nsb nettest -c ${NSB_LO_IP} -r ${NSA_IP} -X ${MD5_PW}
log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"

#
Expand Down Expand Up @@ -1706,11 +1706,11 @@ ipv4_addr_bind_novrf()
#
a=${NSA_IP}
log_start
run_cmd nettest -l ${a} -r ${NSB_IP} -t1 -b
run_cmd nettest -c ${a} -r ${NSB_IP} -t1 -b
log_test_addr ${a} $? 0 "TCP socket bind to local address"

log_start
run_cmd nettest -l ${a} -r ${NSB_IP} -d ${NSA_DEV} -t1 -b
run_cmd nettest -c ${a} -r ${NSB_IP} -d ${NSA_DEV} -t1 -b
log_test_addr ${a} $? 0 "TCP socket bind to local address after device bind"

# Sadly, the kernel allows binding a socket to a device and then
Expand Down Expand Up @@ -2318,7 +2318,7 @@ ipv6_tcp_md5_novrf()
show_hint "Should timeout due to MD5 mismatch"
run_cmd nettest -6 -s -M ${MD5_PW} -m ${NS_NET6} &
sleep 1
run_cmd_nsb nettest -6 -l ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
run_cmd_nsb nettest -6 -c ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
log_test $? 2 "MD5: Prefix config, client address not in configured prefix"
}

Expand Down Expand Up @@ -2386,7 +2386,7 @@ ipv6_tcp_md5()
show_hint "Should timeout since client address is outside of prefix"
run_cmd nettest -6 -s -I ${VRF} -M ${MD5_PW} -m ${NS_NET6} &
sleep 1
run_cmd_nsb nettest -6 -l ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
run_cmd_nsb nettest -6 -c ${NSB_LO_IP6} -r ${NSA_IP6} -X ${MD5_PW}
log_test $? 2 "MD5: VRF: Prefix config, client address not in configured prefix"

#
Expand Down
11 changes: 9 additions & 2 deletions tools/testing/selftests/net/nettest.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
struct sock_args {
/* local address */
const char *local_addr_str;
const char *client_local_addr_str;
union {
struct in_addr in;
struct in6_addr in6;
Expand Down Expand Up @@ -1630,6 +1631,7 @@ static int do_client(struct sock_args *args)
log_msg("Switched client netns\n");
}

args->local_addr_str = args->client_local_addr_str;
if (resolve_devices(args) || validate_addresses(args))
return 1;

Expand Down Expand Up @@ -1770,7 +1772,7 @@ static int ipc_parent(int cpid, int fd, struct sock_args *args)
return client_status;
}

#define GETOPT_STR "sr:l:p:t:g:P:DRn:M:X:m:d:I:BN:O:SCi6L:0:1:2:3:Fbq"
#define GETOPT_STR "sr:l:c:p:t:g:P:DRn:M:X:m:d:I:BN:O:SCi6L:0:1:2:3:Fbq"

static void print_usage(char *prog)
{
Expand All @@ -1791,7 +1793,8 @@ static void print_usage(char *prog)
" -6 IPv6 (default is IPv4)\n"
" -P proto protocol for socket: icmp, ospf (default: none)\n"
" -D|R datagram (D) / raw (R) socket (default stream)\n"
" -l addr local address to bind to\n"
" -l addr local address to bind to in server mode\n"
" -c addr local address to bind to in client mode\n"
"\n"
" -d dev bind socket to given device name\n"
" -I dev bind socket to given device name - server mode\n"
Expand Down Expand Up @@ -1859,6 +1862,10 @@ int main(int argc, char *argv[])
args.has_remote_ip = 1;
args.remote_addr_str = optarg;
break;
case 'c':
args.has_local_ip = 1;
args.client_local_addr_str = optarg;
break;
case 'p':
if (str_to_uint(optarg, 1, 65535, &tmp) != 0) {
fprintf(stderr, "Invalid port\n");
Expand Down

0 comments on commit 5265a01

Please sign in to comment.