Skip to content

Commit

Permalink
fixup! gnrc_sock_udp: accept response from any address if remote is m…
Browse files Browse the repository at this point in the history
…ulticast
  • Loading branch information
benpicco committed Nov 15, 2022
1 parent e29a6ff commit 2e7b891
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sys/net/gnrc/sock/udp/gnrc_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@ ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
return (nobufs) ? -ENOBUFS : ((res < 0) ? res : ret);
}

static bool _remote_mismatch(const sock_udp_t *sock, const udp_hdr_t *hdr,
static bool _remote_match(const sock_udp_t *sock, const udp_hdr_t *hdr,
const sock_ip_ep_t *remote)
{
if ((sock->flags & SOCK_FLAGS_CONNECT_REMOTE) == 0) {
/* socket is not bound to a remote */
return false;
return true;
}

if (sock->remote.family == AF_UNSPEC) {
/* socket accepts any remote */
return false;
return true;
}

if (sock->remote.port != byteorder_ntohs(hdr->src_port)) {
DEBUG("gnrc_sock_udp: port mismatch (%u != %u)\n",
sock->remote.port, byteorder_ntohs(hdr->src_port));
return true;
return false;
}

if (memcmp(&sock->remote.addr, &remote->addr, sizeof(ipv6_addr_t)) != 0) {
Expand All @@ -231,10 +231,10 @@ static bool _remote_mismatch(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 true;
return false;
}

return false;
return true;
}

ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
Expand Down Expand Up @@ -286,7 +286,7 @@ ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
memcpy(remote, &tmp, sizeof(tmp));
remote->port = byteorder_ntohs(hdr->src_port);
}
if (_remote_mismatch(sock, hdr, &tmp)) {
if (!_remote_match(sock, hdr, &tmp)) {
gnrc_pktbuf_release(pkt);
return -EPROTO;
}
Expand Down

0 comments on commit 2e7b891

Please sign in to comment.