Skip to content

Commit 14ee96a

Browse files
authored
Merge pull request wolfSSL#44 from danielinux/arp-fix-neighbor-cache
ARP bugfix: wrong mac address stored in neighbor cache
2 parents cd0973a + f4dc549 commit 14ee96a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/test/unit/unit.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14337,7 +14337,7 @@ START_TEST(test_arp_request_handling) {
1433714337
uint32_t req_ip = 0xC0A80002; // 192.168.0.2
1433814338
uint32_t device_ip = 0xC0A80001; // 192.168.0.1
1433914339
uint8_t req_mac[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
14340-
//uint8_t mac[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
14340+
uint8_t mac[6] = {0};
1434114341
struct wolfIP s;
1434214342

1434314343
memset(&arp_req, 0, sizeof(arp_req));
@@ -14358,9 +14358,8 @@ START_TEST(test_arp_request_handling) {
1435814358
wolfIP_poll(&s, 1002);
1435914359

1436014360
/* Check if ARP table updated with requester's MAC and IP */
14361-
/* TODO */
14362-
//ck_assert_int_eq(arp_lookup(&s, req_ip, mac), 0);
14363-
//ck_assert_mem_eq(mac, req_mac, 6);
14361+
ck_assert_int_eq(arp_lookup(&s, TEST_PRIMARY_IF, req_ip, mac), 0);
14362+
ck_assert_mem_eq(mac, req_mac, 6);
1436414363

1436514364
/* Check if an ARP reply was generated */
1436614365
arp_reply = (struct arp_packet *)last_frame_sent;

src/wolfip.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5068,12 +5068,15 @@ static void arp_recv(struct wolfIP *s, unsigned int if_idx, void *buf, int len)
50685068
return;
50695069

50705070
if (arp->opcode == ee16(ARP_REQUEST) && arp->tip == ee32(conf->ip)) {
5071+
uint32_t sender_ip = arp->sip;
5072+
uint8_t sender_mac[6];
5073+
memcpy(sender_mac, arp->sma, 6);
50715074
arp->opcode = ee16(ARP_REPLY);
50725075
memcpy(arp->tma, arp->sma, 6);
50735076
memcpy(arp->sma, ll->mac, 6);
50745077
arp->tip = arp->sip;
50755078
arp->sip = ee32(conf->ip);
5076-
arp_store_neighbor(s, if_idx, ee32(arp->sip), arp->sma);
5079+
arp_store_neighbor(s, if_idx, ee32(sender_ip), sender_mac);
50775080
eth_output_add_header(s, if_idx, arp->tma, &arp->eth, ETH_TYPE_ARP);
50785081
if (ll->send) {
50795082
if (wolfIP_filter_notify_eth(WOLFIP_FILT_SENDING, s, if_idx, &arp->eth, len) != 0)

0 commit comments

Comments
 (0)