Skip to content

Commit

Permalink
sys/net/sock: add sock_aux_ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jul 18, 2023
1 parent ceaf6bd commit 5a0550e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ PSEUDOMODULES += sock_async
PSEUDOMODULES += sock_aux_local
PSEUDOMODULES += sock_aux_rssi
PSEUDOMODULES += sock_aux_timestamp
PSEUDOMODULES += sock_aux_ttl
PSEUDOMODULES += sock_dtls
PSEUDOMODULES += sock_ip
PSEUDOMODULES += sock_tcp
Expand Down
15 changes: 15 additions & 0 deletions sys/include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ enum {
* @ref sock_dtls_aux_tx_t::local.
*/
SOCK_AUX_SET_LOCAL = (1LU << 3),
/**
* @brief Flag to request the TTL value of received frame
*
* @note Select module `sock_aux_ttl` and a compatible network stack to
* use this
*
* Set this flag in the auxiliary data structure prior to the call of
* @ref sock_udp_recv_aux / @ref sock_ip_recv_aux / etc. to request the
* TTL value of a received frame. This flag will be cleared if the
* time to live was stored, otherwise it remains set.
*
* Depending on the family of the socket, the TTL value will be stored in
* @ref sock_udp_aux_rx_t::ttl or @ref sock_dtls_aux_rx_t::ttl.
*/
SOCK_AUX_GET_TTL = (1LU << 4),
};

/**
Expand Down
8 changes: 8 additions & 0 deletions sys/include/net/sock/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ typedef struct {
*/
int16_t rssi;
#endif /* MODULE_SOCK_AUX_RSSI */
#if defined(MODULE_SOCK_AUX_TTL) || defined(DOXYGEN)
/**
* @brief TTL value of the received frame
*
* @see SOCK_AUX_GET_TTL
*/
uint8_t ttl;
#endif /* MODULE_SOCK_AUX_TTL */
sock_aux_flags_t flags; /**< Flags used request information */
} sock_udp_aux_rx_t;

Expand Down
10 changes: 10 additions & 0 deletions sys/net/gnrc/sock/udp/gnrc_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
if ((aux != NULL) && (_aux.flags & GNRC_SOCK_RECV_AUX_FLAG_RSSI)) {
aux->flags &= ~SOCK_AUX_GET_RSSI;
}
#endif
#if IS_USED(MODULE_SOCK_AUX_TTL)
if ((aux != NULL) && (aux->flags & SOCK_AUX_GET_TTL)) {
gnrc_pktsnip_t *ip = gnrc_pktsnip_search_type(pkt, GNRC_NETTYPE_IPV6);
if (ip) {
ipv6_hdr_t *ip_hdr = ip->data;
aux->ttl = ip_hdr->hl;
aux->flags &= ~SOCK_AUX_GET_TTL;
}
}
#endif
*data = pkt->data;
*buf_ctx = pkt;
Expand Down

0 comments on commit 5a0550e

Please sign in to comment.