From 88cd67309cc94af545a96dac921d5ef21b3aa56e Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Wed, 18 Jan 2023 11:26:25 +0000 Subject: [PATCH] 3rd-party/lwip/dhserver: interface for dhcp reply If more than one interface is used, chances are that the last one added will have changed the default interface used for sending data (see netif_set_default). This causes problems for the DHCP server in the PAN example as the DHCP reply is sent on the wrong network. On Windows this can cause it to use the wrong address. Send replies to the interface that received the dhcp request. --- 3rd-party/lwip/dhcp-server/dhserver.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/3rd-party/lwip/dhcp-server/dhserver.c b/3rd-party/lwip/dhcp-server/dhserver.c index 1ced6025f..899742ae0 100644 --- a/3rd-party/lwip/dhcp-server/dhserver.c +++ b/3rd-party/lwip/dhcp-server/dhserver.c @@ -231,6 +231,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const uint8_t *ptr; dhcp_entry_t *entry; struct pbuf *pp; + struct netif *nif; unsigned int n = p->len; if (n > sizeof(dhcp_data)) n = sizeof(dhcp_data); @@ -262,7 +263,12 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const pp = pbuf_alloc(PBUF_TRANSPORT, sizeof(dhcp_data), PBUF_POOL); if (pp == NULL) break; memcpy(pp->payload, &dhcp_data, sizeof(dhcp_data)); - udp_sendto(upcb, pp, IP_ADDR_BROADCAST, port); + nif = ip_current_input_netif(); + if (nif) { + udp_sendto_if(upcb, pp, IP_ADDR_BROADCAST, port, nif); + } else { + udp_sendto(upcb, pp, IP_ADDR_BROADCAST, port); + } pbuf_free(pp); break; @@ -306,7 +312,12 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const if (pp == NULL) break; memcpy(entry->mac, dhcp_data.dp_chaddr, 6); memcpy(pp->payload, &dhcp_data, sizeof(dhcp_data)); - udp_sendto(upcb, pp, IP_ADDR_BROADCAST, port); + nif = ip_current_input_netif(); + if (nif) { + udp_sendto_if(upcb, pp, IP_ADDR_BROADCAST, port, nif); + } else { + udp_sendto(upcb, pp, IP_ADDR_BROADCAST, port); + } pbuf_free(pp); break;