From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, schoen@loyalty.org,
David Ahern <dsahern@gmail.com>
Subject: [PATCH net-next v2 01/11] selftests: Move device validation in nettest
Date: Sat, 9 Jan 2021 17:18:42 -0700 [thread overview]
Message-ID: <20210110001852.35653-2-dsahern@kernel.org> (raw)
In-Reply-To: <20210110001852.35653-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Later patch adds support for switching network namespaces before
running client, server or both. Device validations need to be
done after the network namespace switch, so add a helper to do it
and invoke in server and client code versus inline with argument
parsing. Move related argument checks as well.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
tools/testing/selftests/net/nettest.c | 64 ++++++++++++++++++---------
1 file changed, 42 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/net/nettest.c b/tools/testing/selftests/net/nettest.c
index f75c53ce0a2d..2bb06a3e6880 100644
--- a/tools/testing/selftests/net/nettest.c
+++ b/tools/testing/selftests/net/nettest.c
@@ -84,6 +84,7 @@ struct sock_args {
unsigned int prefix_len;
/* expected addresses and device index for connection */
+ const char *expected_dev;
int expected_ifindex;
/* local address */
@@ -522,6 +523,33 @@ static int str_to_uint(const char *str, int min, int max, unsigned int *value)
return -1;
}
+static int resolve_devices(struct sock_args *args)
+{
+ if (args->dev) {
+ args->ifindex = get_ifidx(args->dev);
+ if (args->ifindex < 0) {
+ log_error("Invalid device name\n");
+ return 1;
+ }
+ }
+
+ if (args->expected_dev) {
+ unsigned int tmp;
+
+ if (str_to_uint(args->expected_dev, 0, INT_MAX, &tmp) == 0) {
+ args->expected_ifindex = (int)tmp;
+ } else {
+ args->expected_ifindex = get_ifidx(args->expected_dev);
+ if (args->expected_ifindex < 0) {
+ fprintf(stderr, "Invalid expected device\n");
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
static int expected_addr_match(struct sockaddr *sa, void *expected,
const char *desc)
{
@@ -1190,6 +1218,9 @@ static int do_server(struct sock_args *args)
fd_set rfds;
int rc;
+ if (resolve_devices(args))
+ return 1;
+
if (prog_timeout)
ptval = &timeout;
@@ -1375,6 +1406,16 @@ static int do_client(struct sock_args *args)
return 1;
}
+ if (resolve_devices(args))
+ return 1;
+
+ if ((args->use_setsockopt || args->use_cmsg) && !args->ifindex) {
+ fprintf(stderr, "Device binding not specified\n");
+ return 1;
+ }
+ if (args->use_setsockopt || args->use_cmsg)
+ args->dev = NULL;
+
switch (args->version) {
case AF_INET:
sin.sin_port = htons(args->port);
@@ -1703,11 +1744,6 @@ int main(int argc, char *argv[])
break;
case 'd':
args.dev = optarg;
- args.ifindex = get_ifidx(optarg);
- if (args.ifindex < 0) {
- fprintf(stderr, "Invalid device name\n");
- return 1;
- }
break;
case 'i':
interactive = 1;
@@ -1738,16 +1774,7 @@ int main(int argc, char *argv[])
break;
case '2':
- if (str_to_uint(optarg, 0, INT_MAX, &tmp) == 0) {
- args.expected_ifindex = (int)tmp;
- } else {
- args.expected_ifindex = get_ifidx(optarg);
- if (args.expected_ifindex < 0) {
- fprintf(stderr,
- "Invalid expected device\n");
- return 1;
- }
- }
+ args.expected_dev = optarg;
break;
case 'q':
quiet = 1;
@@ -1769,13 +1796,6 @@ int main(int argc, char *argv[])
return 1;
}
- if ((args.use_setsockopt || args.use_cmsg) && !args.ifindex) {
- fprintf(stderr, "Device binding not specified\n");
- return 1;
- }
- if (args.use_setsockopt || args.use_cmsg)
- args.dev = NULL;
-
if (iter == 0) {
fprintf(stderr, "Invalid number of messages to send\n");
return 1;
--
2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-01-10 0:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-10 0:18 [PATCH net-next v2 00/11] selftests: Updates to allow single instance of nettest for client and server David Ahern
2021-01-10 0:18 ` David Ahern [this message]
2021-01-10 0:18 ` [PATCH net-next v2 02/11] selftests: Move convert_addr up in nettest David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 03/11] selftests: Move address validation " David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 04/11] selftests: Add options to set network namespace to nettest David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 05/11] selftests: Add support to nettest to run both client and server David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 06/11] selftests: Use separate stdout and stderr buffers in nettest David Ahern
2021-01-12 0:15 ` Jakub Kicinski
2021-01-12 0:20 ` David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 07/11] selftests: Add missing newline in nettest error messages David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 08/11] selftests: Make address validation apply only to client mode David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 09/11] selftests: Consistently specify address for MD5 protection David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 10/11] selftests: Add new option for client-side passwords David Ahern
2021-01-10 0:18 ` [PATCH net-next v2 11/11] selftests: Add separate options for server device bindings David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210110001852.35653-2-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=schoen@loyalty.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.