Skip to content

Commit

Permalink
gnrc_sock/udp: add option to disable remote address check
Browse files Browse the repository at this point in the history
If a server has e.g. multiple global IPv6 addresses, it might
respond with a different address that the one it received the request on.

This is against the CoAP spec, but that doesn't stop existing implementations
from doing it.
  • Loading branch information
benpicco committed Apr 10, 2024
1 parent 43f010c commit 0fb153d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions sys/net/gnrc/sock/include/gnrc_sock_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ extern "C" {
*/
#define GNRC_SOCK_DYN_PORTRANGE_ERR (0)

/**
* @brief Check if remote address of a UDP packet matches the address the socket
* is bound to.
*/
#ifndef CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR
#define CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR (1)
#endif

/**
* @brief Structure to retrieve auxiliary data from @ref gnrc_sock_recv
*
Expand Down
4 changes: 3 additions & 1 deletion sys/net/gnrc/sock/udp/gnrc_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ static bool _accept_remote(const sock_udp_t *sock, const udp_hdr_t *hdr,
ipv6_addr_to_str(addr_str, (ipv6_addr_t *)&sock->remote.addr, sizeof(addr_str)));
DEBUG(", source (%s) does not match\n",
ipv6_addr_to_str(addr_str, (ipv6_addr_t *)&remote->addr, sizeof(addr_str)));
return false;
if (CONFIG_GNRC_SOCK_UDP_CHECK_REMOTE_ADDR) {
return false;
}
}

return true;
Expand Down

0 comments on commit 0fb153d

Please sign in to comment.