mirror of
https://github.com/apache/nuttx.git
synced 2026-10-03 04:07:55 +00:00
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 <wenquan1@xiaomi.com>
This commit is contained in:
parent
238cfa4a31
commit
7c87b4586c
4 changed files with 8 additions and 70 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue