From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, willemb@google.com, lorenzo@google.com,
maze@google.com, dsahern@kernel.org, yoshfuji@linux-ipv6.org,
shuah@kernel.org, linux-kselftest@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 4/5] selftests: net: test IPV6_HOPLIMIT
Date: Wed, 16 Feb 2022 17:21:19 -0800 [thread overview]
Message-ID: <20220217012120.61250-5-kuba@kernel.org> (raw)
In-Reply-To: <20220217012120.61250-1-kuba@kernel.org>
Test setting IPV6_HOPLIMIT via setsockopt and cmsg
across socket types.
Output without the kernel support (this series):
Case HOPLIMIT ICMP cmsg - packet data returned 1, expected 0
Case HOPLIMIT ICMP diff - packet data returned 1, expected 0
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/testing/selftests/net/cmsg_ipv6.sh | 31 +++++++++++++++++++++++
tools/testing/selftests/net/cmsg_sender.c | 19 +++++++++++++-
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/cmsg_ipv6.sh b/tools/testing/selftests/net/cmsg_ipv6.sh
index f7bb6ce68c88..e42c36e0d741 100755
--- a/tools/testing/selftests/net/cmsg_ipv6.sh
+++ b/tools/testing/selftests/net/cmsg_ipv6.sh
@@ -106,6 +106,37 @@ for ovr in setsock cmsg both diff; do
done
done
+# IPV6_HOPLIMIT
+LIM=4
+
+for ovr in setsock cmsg both diff; do
+ for p in u i r; do
+ [ $p == "u" ] && prot=UDP
+ [ $p == "i" ] && prot=ICMP
+ [ $p == "r" ] && prot=RAW
+
+ [ $ovr == "setsock" ] && m="-L"
+ [ $ovr == "cmsg" ] && m="-l"
+ [ $ovr == "both" ] && m="-L $LIM -l"
+ [ $ovr == "diff" ] && m="-L $((LIM + 1)) -l"
+
+ $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null &
+ BG=$!
+ sleep 0.05
+
+ $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234
+ check_result $? 0 "HOPLIMIT $prot $ovr - pass"
+
+ while [ -d /proc/$BG ]; do
+ $NSEXE ./cmsg_sender -6 -p u $TGT6 1234
+ done
+
+ tcpdump -r $TMPF -v 2>&1 | grep "hlim $LIM[^0-9]" >> /dev/null
+ check_result $? 0 "HOPLIMIT $prot $ovr - packet data"
+ rm $TMPF
+ done
+done
+
# Summary
if [ $BAD -ne 0 ]; then
echo "FAIL - $BAD/$TOTAL cases failed"
diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
index 4033cf93eabf..6136aa7df1c4 100644
--- a/tools/testing/selftests/net/cmsg_sender.c
+++ b/tools/testing/selftests/net/cmsg_sender.c
@@ -47,6 +47,7 @@ struct options {
unsigned int mark;
unsigned int dontfrag;
unsigned int tclass;
+ unsigned int hlimit;
} sockopt;
struct {
unsigned int family;
@@ -64,6 +65,7 @@ struct options {
struct {
struct option_cmsg_u32 dontfrag;
struct option_cmsg_u32 tclass;
+ struct option_cmsg_u32 hlimit;
} v6;
} opt = {
.size = 13,
@@ -95,6 +97,8 @@ static void __attribute__((noreturn)) cs_usage(const char *bin)
"\t\t-F val Set don't fragment via setsockopt\n"
"\t\t-c val Set TCLASS via cmsg\n"
"\t\t-C val Set TCLASS via setsockopt\n"
+ "\t\t-l val Set HOPLIMIT via cmsg\n"
+ "\t\t-L val Set HOPLIMIT via setsockopt\n"
"");
exit(ERN_HELP);
}
@@ -103,7 +107,7 @@ static void cs_parse_args(int argc, char *argv[])
{
char o;
- while ((o = getopt(argc, argv, "46sS:p:m:M:d:tf:F:c:C:")) != -1) {
+ while ((o = getopt(argc, argv, "46sS:p:m:M:d:tf:F:c:C:l:L:")) != -1) {
switch (o) {
case 's':
opt.silent_send = true;
@@ -158,6 +162,13 @@ static void cs_parse_args(int argc, char *argv[])
case 'C':
opt.sockopt.tclass = atoi(optarg);
break;
+ case 'l':
+ opt.v6.hlimit.ena = true;
+ opt.v6.hlimit.val = atoi(optarg);
+ break;
+ case 'L':
+ opt.sockopt.hlimit = atoi(optarg);
+ break;
}
}
@@ -215,6 +226,8 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
SOL_IPV6, IPV6_DONTFRAG, &opt.v6.dontfrag);
ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len,
SOL_IPV6, IPV6_TCLASS, &opt.v6.tclass);
+ ca_write_cmsg_u32(cbuf, cbuf_sz, &cmsg_len,
+ SOL_IPV6, IPV6_HOPLIMIT, &opt.v6.hlimit);
if (opt.txtime.ena) {
struct sock_txtime so_txtime = {
@@ -360,6 +373,10 @@ static void ca_set_sockopts(int fd)
setsockopt(fd, SOL_IPV6, IPV6_TCLASS,
&opt.sockopt.tclass, sizeof(opt.sockopt.tclass)))
error(ERN_SOCKOPT, errno, "setsockopt IPV6_TCLASS");
+ if (opt.sockopt.hlimit &&
+ setsockopt(fd, SOL_IPV6, IPV6_UNICAST_HOPS,
+ &opt.sockopt.hlimit, sizeof(opt.sockopt.hlimit)))
+ error(ERN_SOCKOPT, errno, "setsockopt IPV6_HOPLIMIT");
}
int main(int argc, char *argv[])
--
2.34.1
next prev parent reply other threads:[~2022-02-17 1:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 1:21 [PATCH net-next 0/5] net: ping6: support setting basic SOL_IPV6 options via cmsg Jakub Kicinski
2022-02-17 1:21 ` [PATCH net-next 1/5] " Jakub Kicinski
2022-02-17 1:21 ` [PATCH net-next 2/5] selftests: net: test IPV6_DONTFRAG Jakub Kicinski
2022-02-17 1:21 ` [PATCH net-next 3/5] selftests: net: test IPV6_TCLASS Jakub Kicinski
2022-02-17 1:21 ` Jakub Kicinski [this message]
2022-02-17 1:21 ` [PATCH net-next 5/5] selftests: net: basic test for IPV6_2292* Jakub Kicinski
2022-02-17 14:30 ` [PATCH net-next 0/5] net: ping6: support setting basic SOL_IPV6 options via cmsg patchwork-bot+netdevbpf
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=20220217012120.61250-5-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lorenzo@google.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
--cc=yoshfuji@linux-ipv6.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).