From: Simon Horman <horms@kernel.org>
To: Leo Stone <leocstone@gmail.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, shuah@kernel.org, 0x7f454c46@gmail.com,
rdunlap@infradead.org, mnassiri@ciena.com,
jiapeng.chong@linux.alibaba.com, colin.i.king@gmail.com,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] selftest/tcp-ao: Add filter tests
Date: Fri, 18 Oct 2024 10:32:04 +0100 [thread overview]
Message-ID: <20241018093204.GC1697@kernel.org> (raw)
In-Reply-To: <20241016055823.21299-1-leocstone@gmail.com>
On Tue, Oct 15, 2024 at 10:51:52PM -0700, Leo Stone wrote:
> Add tests that check if getsockopt(TCP_AO_GET_KEYS) returns the right
> keys when using different filters.
>
> Sample output:
>
> > # ok 114 filter keys: by sndid, rcvid, address
> > # ok 115 filter keys: by is_current
> > # ok 116 filter keys: by is_rnext
> > # ok 117 filter keys: by sndid, rcvid
> > # ok 118 filter keys: correct nkeys when in.nkeys < matched_keys
>
> Signed-off-by: Leo Stone <leocstone@gmail.com>
> ---
> Changes in v2:
> - Changed 2 unnecessary test_error calls to test_fail
> - Added another test to make sure getsockopt returns the right nkeys
> value when the input nkeys is smaller than the number of matching keys
> - Removed the TODO that this patch addresses
>
> Thank you for your feedback.
> ---
> .../selftests/net/tcp_ao/setsockopt-closed.c | 180 +++++++++++++++++-
> 1 file changed, 175 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c b/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
> index 084db4ecdff6..4bfa76c28e4e 100644
> --- a/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
> +++ b/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
> @@ -6,6 +6,8 @@
>
> static union tcp_addr tcp_md5_client;
>
> +#define FILTER_TEST_NKEYS 16
> +
> static int test_port = 7788;
> static void make_listen(int sk)
> {
> @@ -813,23 +815,191 @@ static void duplicate_tests(void)
> setsockopt_checked(sk, TCP_AO_ADD_KEY, &ao, EEXIST, "duplicate: SendID differs");
> }
>
> +
> +static void fetch_all_keys(int sk, struct tcp_ao_getsockopt *keys)
> +{
> + socklen_t optlen = sizeof(struct tcp_ao_getsockopt);
> +
> + memset(keys, 0, sizeof(struct tcp_ao_getsockopt) * FILTER_TEST_NKEYS);
> + keys[0].get_all = 1;
> + keys[0].nkeys = FILTER_TEST_NKEYS;
> + if (getsockopt(sk, IPPROTO_TCP, TCP_AO_GET_KEYS, &keys[0], &optlen))
> + test_error("getsockopt");
> +}
> +
> +static int prepare_test_keys(struct tcp_ao_getsockopt *keys)
> +{
> + struct tcp_ao_add test_ao[FILTER_TEST_NKEYS];
> + u8 rcvid = 100, sndid = 100;
> + const char *test_password = "Test password number ";
> + char test_password_scratch[64] = {};
> + int sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP);
Hi Leo,
In Networking code it is preferred to arrange local variables in
reverse xmas tree order. In this case I think that could be as
follows (completely untested!).
Also, as the sk needs to be checked for errors, I would
separate it's assignment form it's declaration
const char *test_password = "Test password number ";
struct tcp_ao_add test_ao[FILTER_TEST_NKEYS];
char test_password_scratch[64] = {};
u8 rcvid = 100, sndid = 100;
int sk;
sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP);
if (sk < 0)
test_error("socket()");
This tool can be of assistance here:
https://github.com/ecree-solarflare/xmastree
> +
> + if (sk < 0)
> + test_error("socket()");
> +
> + for (int i = 0; i < FILTER_TEST_NKEYS; i++) {
> + snprintf(test_password_scratch, 64, "%s %d", test_password, i);
> + test_prepare_key(&test_ao[i], DEFAULT_TEST_ALGO, this_ip_dest, false, false,
> + DEFAULT_TEST_PREFIX, 0, sndid++, rcvid++, 0, 0,
> + strlen(test_password_scratch), test_password_scratch);
Likewise, in Networking code it is still preferred to keep lines at or
below 80 columns wide, where it can trivially be achieved: don't split
strings across or otherwise make the code less readable because of this
guideline.
test_prepare_key(&test_ao[i], DEFAULT_TEST_ALGO, this_ip_dest,
false, false, DEFAULT_TEST_PREFIX, 0, sndid++,
rcvid++, 0, 0, strlen(test_password_scratch),
test_password_scratch);
You can check for this using:
./scripts/checkpatch.pl --strict --max-line-length=80
I think it would be good if you could do a pass over this patch with the
above in mind.
Lastly, please include the target tree, net or net-next, in the subject
when posting patches for Networking.
Subject: [PATCH net-next] ...
More information on processes for netdev can be found here:
https://docs.kernel.org/process/maintainer-netdev.html
--
pw-bot: changes-requested
prev parent reply other threads:[~2024-10-18 9:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 5:51 [PATCH v2] selftest/tcp-ao: Add filter tests Leo Stone
2024-10-17 1:04 ` Dmitry Safonov
2024-10-18 9:32 ` Simon Horman [this message]
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=20241018093204.GC1697@kernel.org \
--to=horms@kernel.org \
--cc=0x7f454c46@gmail.com \
--cc=colin.i.king@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiapeng.chong@linux.alibaba.com \
--cc=kuba@kernel.org \
--cc=leocstone@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mnassiri@ciena.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=shuah@kernel.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.