From faa582040b37245e806f310a59efbf3b877d2ba9 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Tue, 16 Jan 2024 09:56:05 -0300 Subject: [PATCH] Fallback to IP source address on DHCP servers not filling sid --- mongoose.c | 3 ++- src/net_builtin.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 55c5e17a78..138284faaa 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4873,7 +4873,8 @@ static void rx_dhcp_client(struct mg_tcpip_if *ifp, struct pkt *pkt) { ifp->state = MG_TCPIP_STATE_UP, ifp->ip = 0; } else if (msgtype == 2 && ifp->state == MG_TCPIP_STATE_UP && ip && gw && lease) { // DHCPOFFER - tx_dhcp_request_sel(ifp, ip, pkt->dhcp->siaddr); // select IP, (4.4.1) + // select IP, (4.4.1) (fallback to IP source addr on foul play) + tx_dhcp_request_sel(ifp, ip, pkt->dhcp->siaddr ? pkt->dhcp->siaddr : pkt->ip->src); ifp->state = MG_TCPIP_STATE_REQ; // REQUESTING state } else if (msgtype == 5) { // DHCPACK if (ifp->state == MG_TCPIP_STATE_REQ && ip && gw && lease) { // got an IP diff --git a/src/net_builtin.c b/src/net_builtin.c index 66ba23669a..40b493198c 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -398,7 +398,8 @@ static void rx_dhcp_client(struct mg_tcpip_if *ifp, struct pkt *pkt) { ifp->state = MG_TCPIP_STATE_UP, ifp->ip = 0; } else if (msgtype == 2 && ifp->state == MG_TCPIP_STATE_UP && ip && gw && lease) { // DHCPOFFER - tx_dhcp_request_sel(ifp, ip, pkt->dhcp->siaddr); // select IP, (4.4.1) + // select IP, (4.4.1) (fallback to IP source addr on foul play) + tx_dhcp_request_sel(ifp, ip, pkt->dhcp->siaddr ? pkt->dhcp->siaddr : pkt->ip->src); ifp->state = MG_TCPIP_STATE_REQ; // REQUESTING state } else if (msgtype == 5) { // DHCPACK if (ifp->state == MG_TCPIP_STATE_REQ && ip && gw && lease) { // got an IP