From c2b34daa9b494cac5429a28c8b960708bcfe0c7a Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 17 Aug 2024 14:54:26 +0100 Subject: [PATCH] mcast_loop: Drop mcast packet that server sent on different socket Server enabled for mcast receipt. When the server is acting as a proxy sends a mcast packet out over a slave client type socket, it receives the mcast packet on the server socket (which could then be forward out of the client socket....). This change prevents the server socket from passing up the libcoap stack a mcast packet that it knows the client socket is sending. --- src/coap_session.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/coap_session.c b/src/coap_session.c index f0e790cc..7dd7e0b8 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -1074,6 +1074,19 @@ coap_endpoint_get_session(coap_endpoint_t *endpoint, return session; } +#if COAP_CLIENT_SUPPORT + if (coap_is_mcast(&packet->addr_info.local)) { + /* Check if this a proxy client packet we sent on another socket */ + SESSIONS_ITER(endpoint->context->sessions, session, rtmp) { + if (coap_address_equals(&session->addr_info.remote, &packet->addr_info.local) && + coap_address_get_port(&session->addr_info.local) == + coap_address_get_port(&packet->addr_info.remote)) { + /* Drop looped back packet to stop recursion / confusion */ + return NULL; + } + } + } +#endif /* COAP_CLIENT_SUPPORT */ SESSIONS_ITER(endpoint->sessions, session, rtmp) { if (session->ref == 0 && session->delayqueue == NULL) { if (session->type == COAP_SESSION_TYPE_SERVER) {