From eef7625660d6030b81338f00b81994878ff27780 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 30 May 2019 18:33:59 +0800 Subject: [PATCH] net: socket: Add SO_TIMESTAMPING socket option This can be used to activate the network packet statistics collection. Note that we do not have resources to calculate each network packet transit times but we collect average times instead. Signed-off-by: Jukka Rissanen --- include/net/socket.h | 3 +++ subsys/net/lib/sockets/sockets.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/net/socket.h b/include/net/socket.h index b829379094a..5bf5184d618 100644 --- a/include/net/socket.h +++ b/include/net/socket.h @@ -732,6 +732,9 @@ static inline char *inet_ntop(sa_family_t family, const void *src, char *dst, /** sockopt: Async error (ignored, for compatibility) */ #define SO_ERROR 4 +/** sockopt: Timestamp TX packets */ +#define SO_TIMESTAMPING 37 + /* Socket options for IPPROTO_TCP level */ /** sockopt: Disable TCP buffering (ignored, for compatibility) */ #define TCP_NODELAY 1 diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 5f1bc14bc20..8d521cf6ed3 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -1168,6 +1168,24 @@ int zsock_setsockopt_ctx(struct net_context *ctx, int level, int optname, return 0; } + + break; + + case SO_TIMESTAMPING: + /* Calculate TX network packet timings */ + if (IS_ENABLED(CONFIG_NET_CONTEXT_TIMESTAMP)) { + ret = net_context_set_option(ctx, + NET_OPT_TIMESTAMP, + optval, optlen); + if (ret < 0) { + errno = -ret; + return -1; + } + + return 0; + } + + break; } break;