Skip to content

Commit

Permalink
Merge pull request #2860 from cesanta/l2r
Browse files Browse the repository at this point in the history
fix ARP resolution when remote host is the gw
  • Loading branch information
scaprile authored Aug 12, 2024
2 parents d763fce + 045b196 commit 3c89536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -5117,7 +5117,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) {
MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
arp_ask(ifp, ifp->gw);
arp_ask(ifp, ifp->gw); // unsolicited GW ARP request
} else if (ifp->state == MG_TCPIP_STATE_UP) {
MG_ERROR(("Link up"));
srand((unsigned int) mg_millis());
Expand Down Expand Up @@ -5966,7 +5966,8 @@ void mg_connect_resolved(struct mg_connection *c) {
if (c->is_udp && (rem_ip == 0xffffffff || rem_ip == (ifp->ip | ~ifp->mask))) {
struct connstate *s = (struct connstate *) (c + 1);
memset(s->mac, 0xFF, sizeof(s->mac)); // global or local broadcast
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask))) {
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask)) &&
rem_ip != ifp->gw) { // skip if gw (onstatechange -> READY -> ARP)
// If we're in the same LAN, fire an ARP lookup.
MG_DEBUG(("%lu ARP lookup...", c->id));
arp_ask(ifp, rem_ip);
Expand Down
5 changes: 3 additions & 2 deletions src/net_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) {
MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
arp_ask(ifp, ifp->gw);
arp_ask(ifp, ifp->gw); // unsolicited GW ARP request
} else if (ifp->state == MG_TCPIP_STATE_UP) {
MG_ERROR(("Link up"));
srand((unsigned int) mg_millis());
Expand Down Expand Up @@ -1053,7 +1053,8 @@ void mg_connect_resolved(struct mg_connection *c) {
if (c->is_udp && (rem_ip == 0xffffffff || rem_ip == (ifp->ip | ~ifp->mask))) {
struct connstate *s = (struct connstate *) (c + 1);
memset(s->mac, 0xFF, sizeof(s->mac)); // global or local broadcast
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask))) {
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask)) &&
rem_ip != ifp->gw) { // skip if gw (onstatechange -> READY -> ARP)
// If we're in the same LAN, fire an ARP lookup.
MG_DEBUG(("%lu ARP lookup...", c->id));
arp_ask(ifp, rem_ip);
Expand Down

0 comments on commit 3c89536

Please sign in to comment.