Skip to content

Commit f7e9f00

Browse files
committed
Stop ARP requests falling through to reply handling
F/1162
1 parent 494441f commit f7e9f00

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/test/unit/unit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ Suite *wolf_suite(void)
581581
tcase_add_test(tc_proto, test_arp_recv_request_other_ip_no_reply);
582582
tcase_add_test(tc_proto, test_arp_recv_null_stack);
583583
tcase_add_test(tc_proto, test_arp_recv_request_sends_reply);
584+
tcase_add_test(tc_proto, test_arp_recv_request_does_not_store_self_neighbor);
584585
tcase_add_test(tc_proto, test_arp_recv_request_no_send_fn);
585586
tcase_add_test(tc_proto, test_wolfip_if_for_local_ip_paths);
586587
tcase_add_test(tc_proto, test_wolfip_if_for_local_ip_null_found);

src/test/unit/unit_tests_tcp_ack.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,48 @@ START_TEST(test_arp_recv_request_sends_reply)
20122012
}
20132013
END_TEST
20142014

2015+
START_TEST(test_arp_recv_request_does_not_store_self_neighbor)
2016+
{
2017+
struct wolfIP s;
2018+
struct arp_packet arp_req;
2019+
const ip4 local_ip = 0x0A000001U;
2020+
const ip4 sender_ip = 0x0A000002U;
2021+
const uint8_t sender_mac[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
2022+
int i;
2023+
int sender_count = 0;
2024+
int self_count = 0;
2025+
2026+
wolfIP_init(&s);
2027+
mock_link_init(&s);
2028+
wolfIP_ipconfig_set(&s, local_ip, 0xFFFFFF00U, 0);
2029+
wolfIP_filter_set_callback(NULL, NULL);
2030+
wolfIP_filter_set_mask(0);
2031+
2032+
memset(&arp_req, 0, sizeof(arp_req));
2033+
arp_req.opcode = ee16(ARP_REQUEST);
2034+
arp_req.sip = ee32(sender_ip);
2035+
memcpy(arp_req.sma, sender_mac, sizeof(sender_mac));
2036+
arp_req.tip = ee32(local_ip);
2037+
2038+
arp_recv(&s, TEST_PRIMARY_IF, &arp_req, sizeof(arp_req));
2039+
2040+
for (i = 0; i < MAX_NEIGHBORS; i++) {
2041+
if (s.arp.neighbors[i].if_idx != TEST_PRIMARY_IF)
2042+
continue;
2043+
if (s.arp.neighbors[i].ip == sender_ip) {
2044+
sender_count++;
2045+
ck_assert_mem_eq(s.arp.neighbors[i].mac, sender_mac,
2046+
sizeof(sender_mac));
2047+
}
2048+
if (s.arp.neighbors[i].ip == local_ip)
2049+
self_count++;
2050+
}
2051+
2052+
ck_assert_int_eq(sender_count, 1);
2053+
ck_assert_int_eq(self_count, 0);
2054+
}
2055+
END_TEST
2056+
20152057
START_TEST(test_send_ttl_exceeded_filter_drop)
20162058
{
20172059
struct wolfIP s;

src/wolfip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5811,7 +5811,7 @@ static void arp_recv(struct wolfIP *s, unsigned int if_idx, void *buf, int len)
58115811
ll->send(ll, buf, len);
58125812
}
58135813
}
5814-
if (arp->opcode == ee16(ARP_REPLY)) {
5814+
else if (arp->opcode == ee16(ARP_REPLY)) {
58155815
ip4 sip = ee32(arp->sip);
58165816
int idx = arp_neighbor_index(s, if_idx, sip);
58175817
int pending = arp_pending_match_and_clear(s, if_idx, sip);

0 commit comments

Comments
 (0)