Commit a22982c3 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

selftests: net: basic test for IPV6_2292*

Add a basic test to make sure ping sockets don't crash
with IPV6_2292* options.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 05ae83d5
...@@ -137,6 +137,15 @@ for ovr in setsock cmsg both diff; do ...@@ -137,6 +137,15 @@ for ovr in setsock cmsg both diff; do
done done
done done
# IPV6 exthdr
for p in u i r; do
# Very basic "does it crash" test
for h in h d r; do
$NSEXE ./cmsg_sender -p $p -6 -H $h $TGT6 1234
check_result $? 0 "ExtHdr $prot $ovr - pass"
done
done
# Summary # Summary
if [ $BAD -ne 0 ]; then if [ $BAD -ne 0 ]; then
echo "FAIL - $BAD/$TOTAL cases failed" echo "FAIL - $BAD/$TOTAL cases failed"
......
...@@ -66,6 +66,7 @@ struct options { ...@@ -66,6 +66,7 @@ struct options {
struct option_cmsg_u32 dontfrag; struct option_cmsg_u32 dontfrag;
struct option_cmsg_u32 tclass; struct option_cmsg_u32 tclass;
struct option_cmsg_u32 hlimit; struct option_cmsg_u32 hlimit;
struct option_cmsg_u32 exthdr;
} v6; } v6;
} opt = { } opt = {
.size = 13, .size = 13,
...@@ -99,6 +100,8 @@ static void __attribute__((noreturn)) cs_usage(const char *bin) ...@@ -99,6 +100,8 @@ static void __attribute__((noreturn)) cs_usage(const char *bin)
"\t\t-C val Set TCLASS via setsockopt\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 cmsg\n"
"\t\t-L val Set HOPLIMIT via setsockopt\n" "\t\t-L val Set HOPLIMIT via setsockopt\n"
"\t\t-H type Add an IPv6 header option\n"
"\t\t (h = HOP; d = DST; r = RTDST)"
""); "");
exit(ERN_HELP); exit(ERN_HELP);
} }
...@@ -107,7 +110,7 @@ static void cs_parse_args(int argc, char *argv[]) ...@@ -107,7 +110,7 @@ static void cs_parse_args(int argc, char *argv[])
{ {
char o; char o;
while ((o = getopt(argc, argv, "46sS:p:m:M:d:tf:F:c:C:l:L:")) != -1) { while ((o = getopt(argc, argv, "46sS:p:m:M:d:tf:F:c:C:l:L:H:")) != -1) {
switch (o) { switch (o) {
case 's': case 's':
opt.silent_send = true; opt.silent_send = true;
...@@ -169,6 +172,23 @@ static void cs_parse_args(int argc, char *argv[]) ...@@ -169,6 +172,23 @@ static void cs_parse_args(int argc, char *argv[])
case 'L': case 'L':
opt.sockopt.hlimit = atoi(optarg); opt.sockopt.hlimit = atoi(optarg);
break; break;
case 'H':
opt.v6.exthdr.ena = true;
switch (optarg[0]) {
case 'h':
opt.v6.exthdr.val = IPV6_HOPOPTS;
break;
case 'd':
opt.v6.exthdr.val = IPV6_DSTOPTS;
break;
case 'r':
opt.v6.exthdr.val = IPV6_RTHDRDSTOPTS;
break;
default:
printf("Error: hdr type: %s\n", optarg);
break;
}
break;
} }
} }
...@@ -272,6 +292,17 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz) ...@@ -272,6 +292,17 @@ cs_write_cmsg(int fd, struct msghdr *msg, char *cbuf, size_t cbuf_sz)
*(__u32 *)CMSG_DATA(cmsg) = SOF_TIMESTAMPING_TX_SCHED | *(__u32 *)CMSG_DATA(cmsg) = SOF_TIMESTAMPING_TX_SCHED |
SOF_TIMESTAMPING_TX_SOFTWARE; SOF_TIMESTAMPING_TX_SOFTWARE;
} }
if (opt.v6.exthdr.ena) {
cmsg = (struct cmsghdr *)(cbuf + cmsg_len);
cmsg_len += CMSG_SPACE(8);
if (cbuf_sz < cmsg_len)
error(ERN_CMSG_WR, EFAULT, "cmsg buffer too small");
cmsg->cmsg_level = SOL_IPV6;
cmsg->cmsg_type = opt.v6.exthdr.val;
cmsg->cmsg_len = CMSG_LEN(8);
*(__u64 *)CMSG_DATA(cmsg) = 0;
}
if (cmsg_len) if (cmsg_len)
msg->msg_controllen = cmsg_len; msg->msg_controllen = cmsg_len;
......
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