This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7c87b4586c99dddef4fce650da39923e74445501 Author: wenquan1 <[email protected]> AuthorDate: Wed Mar 11 15:19:15 2026 +0800 net/socket: use s_options for SO_TIMESTAMP instead of per-conn field Remove the redundant `timestamp` field from `udp_conn_s` and use the existing `s_options` bitmask to track SO_TIMESTAMP/SO_TIMESTAMPNS state. The socket-level setsockopt/getsockopt already handles SO_TIMESTAMP via _SO_SETOPT/_SO_GETOPT on s_options. The protocol-level handlers in inet_sockif.c were intercepting the option before the socket layer, causing s_options to never be set. This also meant SO_TIMESTAMPNS was broken since inet_sockif.c only handled SO_TIMESTAMP. Changes: - Remove udp_conn_s.timestamp field from udp.h - Remove SO_TIMESTAMP get/set handlers from inet_sockif.c, letting them fall through to the socket-level handler - Simplify udp_recvfrom.c to call cmsg_store_timestamp() directly, which already checks s_options internally - Align pkt_input.c software timestamp generation with ipv4/can by removing per-socket SO_TIMESTAMP option check, only checking hardware timestamp capability Signed-off-by: wenquan1 <[email protected]> --- net/inet/inet_sockif.c | 55 -------------------------------------------------- net/pkt/pkt_input.c | 4 ++++ net/udp/udp.h | 3 --- net/udp/udp_recvfrom.c | 16 ++++----------- 4 files changed, 8 insertions(+), 70 deletions(-) diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index b8012b4fc6c..61962a9b459 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -713,29 +713,6 @@ static int inet_get_socketlevel_option(FAR struct socket *psock, int option, } #endif -#ifdef CONFIG_NET_TIMESTAMP - case SO_TIMESTAMP: - { - if (*value_len != sizeof(int)) - { - return -EINVAL; - } - -# ifdef NET_UDP_HAVE_STACK - if (psock->s_type == SOCK_DGRAM) - { - FAR struct udp_conn_s *conn = psock->s_conn; - *(FAR int *)value = (conn->timestamp != 0); - } - else -# endif - { - return -ENOPROTOOPT; - } - } - break; -#endif - default: return -ENOPROTOOPT; } @@ -1017,38 +994,6 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option, break; #endif -#ifdef CONFIG_NET_TIMESTAMP - case SO_TIMESTAMP: /* Report receive timestamps as cmsg */ - { - if (value_len < sizeof(int)) - { - return -EINVAL; - } - -# ifdef NET_UDP_HAVE_STACK - if (psock->s_type == SOCK_DGRAM) - { - conn_lock(psock->s_conn); - - /* For now the timestamp enable is just boolean. - * If SO_TIMESTAMPING support is added in future, it can be - * expanded to flags field for rx/tx timestamps. - */ - - FAR struct udp_conn_s *conn = psock->s_conn; - conn->timestamp = (*((FAR int *)value) != 0); - - conn_unlock(psock->s_conn); - } - else -# endif - { - return -ENOPROTOOPT; - } - } - break; - #endif - default: return -ENOPROTOOPT; } diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index 8fc36e0e4d2..60b93b97253 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -184,6 +184,10 @@ static int pkt_in(FAR struct net_driver_s *dev) #endif #ifdef CONFIG_NET_TIMESTAMP + /* Storing reception timestamp provided by realtime + * if timestamp no provided by hardware. + */ + if ((dev->d_features & NETDEV_RX_STAMP) == 0) { /* Storing reception timestamp provided by realtime diff --git a/net/udp/udp.h b/net/udp/udp.h index 68850022f65..b95a2c57eea 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -159,9 +159,6 @@ struct udp_conn_s struct udp_poll_s pollinfo[CONFIG_NET_UDP_NPOLLWAITERS]; -#ifdef CONFIG_NET_TIMESTAMP - int timestamp; /* Nonzero when SO_TIMESTAMP is enabled */ -#endif FAR sem_t *txdrain_sem; }; diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c index a7357d78b87..120eba31548 100644 --- a/net/udp/udp_recvfrom.c +++ b/net/udp/udp_recvfrom.c @@ -207,13 +207,8 @@ static inline void udp_readahead(struct udp_recvfrom_s *pstate) DEBUGASSERT(recvlen == src_addr_size); #ifdef CONFIG_NET_TIMESTAMP - /* Unpack stored timestamp if SO_TIMESTAMP socket option is enabled */ - - if (conn->timestamp) - { - cmsg_store_timestamp(pstate->ir_msg, &iob->io_time, - conn->sconn.s_options); - } + cmsg_store_timestamp(pstate->ir_msg, &iob->io_time, + conn->sconn.s_options); #endif /* Copy to user */ @@ -451,11 +446,8 @@ static uint32_t udp_eventhandler(FAR struct net_driver_s *dev, /* Save packet timestamp, if requested */ #ifdef CONFIG_NET_TIMESTAMP - if (pstate->ir_conn->timestamp) - { - cmsg_store_timestamp(pstate->ir_msg, &dev->d_iob->io_time, - pstate->ir_conn->sconn.s_options); - } + cmsg_store_timestamp(pstate->ir_msg, &dev->d_iob->io_time, + pstate->ir_conn->sconn.s_options); #endif /* Save the sender's address in the caller's 'from' location */
