Commit aeefbb57 authored by Guillaume Nault's avatar Guillaume Nault Committed by David S. Miller

selftests: Add SO_DONTROUTE option to nettest.

Add --client-dontroute and --server-dontroute options to nettest. They
allow to set the SO_DONTROUTE option to the client and server sockets
respectively. This will be used by the following patches to test
the SO_DONTROUTE kernel behaviour with TCP and UDP.
Signed-off-by: default avatarGuillaume Nault <gnault@redhat.com>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c1bc7d73
...@@ -76,7 +76,9 @@ struct sock_args { ...@@ -76,7 +76,9 @@ struct sock_args {
has_grp:1, has_grp:1,
has_expected_laddr:1, has_expected_laddr:1,
has_expected_raddr:1, has_expected_raddr:1,
bind_test_only:1; bind_test_only:1,
client_dontroute:1,
server_dontroute:1;
unsigned short port; unsigned short port;
...@@ -611,6 +613,18 @@ static int set_dsfield(int sd, int version, int dsfield) ...@@ -611,6 +613,18 @@ static int set_dsfield(int sd, int version, int dsfield)
return 0; return 0;
} }
static int set_dontroute(int sd)
{
unsigned int one = 1;
if (setsockopt(sd, SOL_SOCKET, SO_DONTROUTE, &one, sizeof(one)) < 0) {
log_err_errno("setsockopt(SO_DONTROUTE)");
return -1;
}
return 0;
}
static int str_to_uint(const char *str, int min, int max, unsigned int *value) static int str_to_uint(const char *str, int min, int max, unsigned int *value)
{ {
int number; int number;
...@@ -1351,6 +1365,14 @@ static int msock_init(struct sock_args *args, int server) ...@@ -1351,6 +1365,14 @@ static int msock_init(struct sock_args *args, int server)
if (set_dsfield(sd, AF_INET, args->dsfield) != 0) if (set_dsfield(sd, AF_INET, args->dsfield) != 0)
goto out_err; goto out_err;
if (server) {
if (args->server_dontroute && set_dontroute(sd) != 0)
goto out_err;
} else {
if (args->client_dontroute && set_dontroute(sd) != 0)
goto out_err;
}
if (args->dev && bind_to_device(sd, args->dev) != 0) if (args->dev && bind_to_device(sd, args->dev) != 0)
goto out_err; goto out_err;
else if (args->use_setsockopt && else if (args->use_setsockopt &&
...@@ -1482,6 +1504,9 @@ static int lsock_init(struct sock_args *args) ...@@ -1482,6 +1504,9 @@ static int lsock_init(struct sock_args *args)
if (set_dsfield(sd, args->version, args->dsfield) != 0) if (set_dsfield(sd, args->version, args->dsfield) != 0)
goto err; goto err;
if (args->server_dontroute && set_dontroute(sd) != 0)
goto err;
if (args->dev && bind_to_device(sd, args->dev) != 0) if (args->dev && bind_to_device(sd, args->dev) != 0)
goto err; goto err;
else if (args->use_setsockopt && else if (args->use_setsockopt &&
...@@ -1698,6 +1723,9 @@ static int connectsock(void *addr, socklen_t alen, struct sock_args *args) ...@@ -1698,6 +1723,9 @@ static int connectsock(void *addr, socklen_t alen, struct sock_args *args)
if (set_dsfield(sd, args->version, args->dsfield) != 0) if (set_dsfield(sd, args->version, args->dsfield) != 0)
goto err; goto err;
if (args->client_dontroute && set_dontroute(sd) != 0)
goto err;
if (args->dev && bind_to_device(sd, args->dev) != 0) if (args->dev && bind_to_device(sd, args->dev) != 0)
goto err; goto err;
else if (args->use_setsockopt && else if (args->use_setsockopt &&
...@@ -1905,10 +1933,14 @@ static int ipc_parent(int cpid, int fd, struct sock_args *args) ...@@ -1905,10 +1933,14 @@ static int ipc_parent(int cpid, int fd, struct sock_args *args)
#define GETOPT_STR "sr:l:c:Q:p:t:g:P:DRn:M:X:m:d:I:BN:O:SUCi6xL:0:1:2:3:Fbqf" #define GETOPT_STR "sr:l:c:Q:p:t:g:P:DRn:M:X:m:d:I:BN:O:SUCi6xL:0:1:2:3:Fbqf"
#define OPT_FORCE_BIND_KEY_IFINDEX 1001 #define OPT_FORCE_BIND_KEY_IFINDEX 1001
#define OPT_NO_BIND_KEY_IFINDEX 1002 #define OPT_NO_BIND_KEY_IFINDEX 1002
#define OPT_CLIENT_DONTROUTE 1003
#define OPT_SERVER_DONTROUTE 1004
static struct option long_opts[] = { static struct option long_opts[] = {
{"force-bind-key-ifindex", 0, 0, OPT_FORCE_BIND_KEY_IFINDEX}, {"force-bind-key-ifindex", 0, 0, OPT_FORCE_BIND_KEY_IFINDEX},
{"no-bind-key-ifindex", 0, 0, OPT_NO_BIND_KEY_IFINDEX}, {"no-bind-key-ifindex", 0, 0, OPT_NO_BIND_KEY_IFINDEX},
{"client-dontroute", 0, 0, OPT_CLIENT_DONTROUTE},
{"server-dontroute", 0, 0, OPT_SERVER_DONTROUTE},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -1954,6 +1986,12 @@ static void print_usage(char *prog) ...@@ -1954,6 +1986,12 @@ static void print_usage(char *prog)
" --no-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX off\n" " --no-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX off\n"
" --force-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX on\n" " --force-bind-key-ifindex: Force TCP_MD5SIG_FLAG_IFINDEX on\n"
" (default: only if -I is passed)\n" " (default: only if -I is passed)\n"
" --client-dontroute: don't use gateways for client socket: send\n"
" packets only if destination is on link (see\n"
" SO_DONTROUTE in socket(7))\n"
" --server-dontroute: don't use gateways for server socket: send\n"
" packets only if destination is on link (see\n"
" SO_DONTROUTE in socket(7))\n"
"\n" "\n"
" -g grp multicast group (e.g., 239.1.1.1)\n" " -g grp multicast group (e.g., 239.1.1.1)\n"
" -i interactive mode (default is echo and terminate)\n" " -i interactive mode (default is echo and terminate)\n"
...@@ -2076,6 +2114,12 @@ int main(int argc, char *argv[]) ...@@ -2076,6 +2114,12 @@ int main(int argc, char *argv[])
case OPT_NO_BIND_KEY_IFINDEX: case OPT_NO_BIND_KEY_IFINDEX:
args.bind_key_ifindex = -1; args.bind_key_ifindex = -1;
break; break;
case OPT_CLIENT_DONTROUTE:
args.client_dontroute = 1;
break;
case OPT_SERVER_DONTROUTE:
args.server_dontroute = 1;
break;
case 'X': case 'X':
args.client_pw = optarg; args.client_pw = optarg;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment