Skip to content

Commit 3c89536

Browse files
authored
Merge pull request #2860 from cesanta/l2r
fix ARP resolution when remote host is the gw
2 parents d763fce + 045b196 commit 3c89536

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

mongoose.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,7 +5117,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) {
51175117
MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
51185118
MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
51195119
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
5120-
arp_ask(ifp, ifp->gw);
5120+
arp_ask(ifp, ifp->gw); // unsolicited GW ARP request
51215121
} else if (ifp->state == MG_TCPIP_STATE_UP) {
51225122
MG_ERROR(("Link up"));
51235123
srand((unsigned int) mg_millis());
@@ -5966,7 +5966,8 @@ void mg_connect_resolved(struct mg_connection *c) {
59665966
if (c->is_udp && (rem_ip == 0xffffffff || rem_ip == (ifp->ip | ~ifp->mask))) {
59675967
struct connstate *s = (struct connstate *) (c + 1);
59685968
memset(s->mac, 0xFF, sizeof(s->mac)); // global or local broadcast
5969-
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask))) {
5969+
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask)) &&
5970+
rem_ip != ifp->gw) { // skip if gw (onstatechange -> READY -> ARP)
59705971
// If we're in the same LAN, fire an ARP lookup.
59715972
MG_DEBUG(("%lu ARP lookup...", c->id));
59725973
arp_ask(ifp, rem_ip);

src/net_builtin.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) {
204204
MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
205205
MG_INFO((" GW: %M", mg_print_ip4, &ifp->gw));
206206
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
207-
arp_ask(ifp, ifp->gw);
207+
arp_ask(ifp, ifp->gw); // unsolicited GW ARP request
208208
} else if (ifp->state == MG_TCPIP_STATE_UP) {
209209
MG_ERROR(("Link up"));
210210
srand((unsigned int) mg_millis());
@@ -1053,7 +1053,8 @@ void mg_connect_resolved(struct mg_connection *c) {
10531053
if (c->is_udp && (rem_ip == 0xffffffff || rem_ip == (ifp->ip | ~ifp->mask))) {
10541054
struct connstate *s = (struct connstate *) (c + 1);
10551055
memset(s->mac, 0xFF, sizeof(s->mac)); // global or local broadcast
1056-
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask))) {
1056+
} else if (ifp->ip && ((rem_ip & ifp->mask) == (ifp->ip & ifp->mask)) &&
1057+
rem_ip != ifp->gw) { // skip if gw (onstatechange -> READY -> ARP)
10571058
// If we're in the same LAN, fire an ARP lookup.
10581059
MG_DEBUG(("%lu ARP lookup...", c->id));
10591060
arp_ask(ifp, rem_ip);

0 commit comments

Comments
 (0)