Commit 23685923 authored by Willem de Bruijn's avatar Willem de Bruijn Committed by David S. Miller

net-timestamp: no-payload option in txtimestamp test

Demonstrate how SOF_TIMESTAMPING_OPT_TSONLY can be used and
test the implementation.
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b245be1f
...@@ -70,6 +70,7 @@ static int do_ipv6 = 1; ...@@ -70,6 +70,7 @@ static int do_ipv6 = 1;
static int cfg_payload_len = 10; static int cfg_payload_len = 10;
static bool cfg_show_payload; static bool cfg_show_payload;
static bool cfg_do_pktinfo; static bool cfg_do_pktinfo;
static bool cfg_loop_nodata;
static uint16_t dest_port = 9000; static uint16_t dest_port = 9000;
static struct sockaddr_in daddr; static struct sockaddr_in daddr;
...@@ -141,6 +142,9 @@ static void print_payload(char *data, int len) ...@@ -141,6 +142,9 @@ static void print_payload(char *data, int len)
{ {
int i; int i;
if (!len)
return;
if (len > 70) if (len > 70)
len = 70; len = 70;
...@@ -177,6 +181,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len) ...@@ -177,6 +181,7 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)
struct sock_extended_err *serr = NULL; struct sock_extended_err *serr = NULL;
struct scm_timestamping *tss = NULL; struct scm_timestamping *tss = NULL;
struct cmsghdr *cm; struct cmsghdr *cm;
int batch = 0;
for (cm = CMSG_FIRSTHDR(msg); for (cm = CMSG_FIRSTHDR(msg);
cm && cm->cmsg_len; cm && cm->cmsg_len;
...@@ -209,10 +214,18 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len) ...@@ -209,10 +214,18 @@ static void __recv_errmsg_cmsg(struct msghdr *msg, int payload_len)
} else } else
fprintf(stderr, "unknown cmsg %d,%d\n", fprintf(stderr, "unknown cmsg %d,%d\n",
cm->cmsg_level, cm->cmsg_type); cm->cmsg_level, cm->cmsg_type);
if (serr && tss) {
print_timestamp(tss, serr->ee_info, serr->ee_data,
payload_len);
serr = NULL;
tss = NULL;
batch++;
}
} }
if (serr && tss) if (batch > 1)
print_timestamp(tss, serr->ee_info, serr->ee_data, payload_len); fprintf(stderr, "batched %d timestamps\n", batch);
} }
static int recv_errmsg(int fd) static int recv_errmsg(int fd)
...@@ -244,7 +257,7 @@ static int recv_errmsg(int fd) ...@@ -244,7 +257,7 @@ static int recv_errmsg(int fd)
if (ret == -1 && errno != EAGAIN) if (ret == -1 && errno != EAGAIN)
error(1, errno, "recvmsg"); error(1, errno, "recvmsg");
if (ret > 0) { if (ret >= 0) {
__recv_errmsg_cmsg(&msg, ret); __recv_errmsg_cmsg(&msg, ret);
if (cfg_show_payload) if (cfg_show_payload)
print_payload(data, cfg_payload_len); print_payload(data, cfg_payload_len);
...@@ -309,6 +322,9 @@ static void do_test(int family, unsigned int opt) ...@@ -309,6 +322,9 @@ static void do_test(int family, unsigned int opt)
opt |= SOF_TIMESTAMPING_SOFTWARE | opt |= SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_OPT_CMSG | SOF_TIMESTAMPING_OPT_CMSG |
SOF_TIMESTAMPING_OPT_ID; SOF_TIMESTAMPING_OPT_ID;
if (cfg_loop_nodata)
opt |= SOF_TIMESTAMPING_OPT_TSONLY;
if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
(char *) &opt, sizeof(opt))) (char *) &opt, sizeof(opt)))
error(1, 0, "setsockopt timestamping"); error(1, 0, "setsockopt timestamping");
...@@ -378,6 +394,7 @@ static void __attribute__((noreturn)) usage(const char *filepath) ...@@ -378,6 +394,7 @@ static void __attribute__((noreturn)) usage(const char *filepath)
" -h: show this message\n" " -h: show this message\n"
" -I: request PKTINFO\n" " -I: request PKTINFO\n"
" -l N: send N bytes at a time\n" " -l N: send N bytes at a time\n"
" -n: set no-payload option\n"
" -r: use raw\n" " -r: use raw\n"
" -R: use raw (IP_HDRINCL)\n" " -R: use raw (IP_HDRINCL)\n"
" -p N: connect to port N\n" " -p N: connect to port N\n"
...@@ -392,7 +409,7 @@ static void parse_opt(int argc, char **argv) ...@@ -392,7 +409,7 @@ static void parse_opt(int argc, char **argv)
int proto_count = 0; int proto_count = 0;
char c; char c;
while ((c = getopt(argc, argv, "46hIl:p:rRux")) != -1) { while ((c = getopt(argc, argv, "46hIl:np:rRux")) != -1) {
switch (c) { switch (c) {
case '4': case '4':
do_ipv6 = 0; do_ipv6 = 0;
...@@ -403,6 +420,9 @@ static void parse_opt(int argc, char **argv) ...@@ -403,6 +420,9 @@ static void parse_opt(int argc, char **argv)
case 'I': case 'I':
cfg_do_pktinfo = true; cfg_do_pktinfo = true;
break; break;
case 'n':
cfg_loop_nodata = true;
break;
case 'r': case 'r':
proto_count++; proto_count++;
cfg_proto = SOCK_RAW; cfg_proto = SOCK_RAW;
......
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