mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-06 17:52:54 +03:00
coap_io.c: select outbound interface when responding to multicast requests
coap_network_send() uses the address given by local_interface as source address of outgoing IP packets. For responses to requests that have been received via IP multicast, this address is a multicast group and thus must not be set as source in the IP header. As a workaround, this change clears the address and ifindex so that the kernel selects a suitable outbound interface.
This commit is contained in:
1 parent
d989bb174c
commit
91f37ae1a7
1 file changed
+22
-7
+22
-7
@@ -271,9 +271,17 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM,
|
||||
memset(pktinfo, 0, sizeof(struct in6_pktinfo));
|
||||
|
||||
pktinfo->ipi6_ifindex = ep->ifindex;
|
||||
memcpy(&pktinfo->ipi6_addr,
|
||||
&local_interface->addr.addr.sin6.sin6_addr,
|
||||
local_interface->addr.size);
|
||||
if (coap_is_mcast(&local_interface->addr)) {
|
||||
/* We cannot send with multicast address as source address
|
||||
* and hence let the kernel pick the outgoing interface. */
|
||||
pktinfo->ipi6_ifindex = 0;
|
||||
memset(&pktinfo->ipi6_addr, 0, sizeof(pktinfo->ipi6_addr));
|
||||
} else {
|
||||
pktinfo->ipi6_ifindex = ep->ifindex;
|
||||
memcpy(&pktinfo->ipi6_addr,
|
||||
&local_interface->addr.addr.sin6.sin6_addr,
|
||||
local_interface->addr.size);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AF_INET: {
|
||||
@@ -291,10 +299,17 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM,
|
||||
pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
|
||||
memset(pktinfo, 0, sizeof(struct in_pktinfo));
|
||||
|
||||
pktinfo->ipi_ifindex = ep->ifindex;
|
||||
memcpy(&pktinfo->ipi_spec_dst,
|
||||
&local_interface->addr.addr.sin.sin_addr,
|
||||
local_interface->addr.size);
|
||||
if (coap_is_mcast(&local_interface->addr)) {
|
||||
/* We cannot send with multicast address as source address
|
||||
* and hence let the kernel pick the outgoing interface. */
|
||||
pktinfo->ipi_ifindex = 0;
|
||||
memset(&pktinfo->ipi_spec_dst, 0, sizeof(pktinfo->ipi_spec_dst));
|
||||
} else {
|
||||
pktinfo->ipi_ifindex = ep->ifindex;
|
||||
memcpy(&pktinfo->ipi_spec_dst,
|
||||
&local_interface->addr.addr.sin.sin_addr,
|
||||
local_interface->addr.size);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in new issue
Block a user