zkkkk12 opened a new pull request, #17729: URL: https://github.com/apache/nuttx/pull/17729
Supports no ARP reply for invalid routing addresses in cross-segment communication *Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary Supports no ARP reply for invalid routing addresses in cross-segment communication ## Impact A check for the validity of the router address has been added to the ARP handling code. Cross-segment communication will not be responded to. ## Testing ``` #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <nuttx/net/net.h> #include <nuttx/net/netdev.h> #include <nuttx/net/arp.h> /* Mock network driver structure */ struct net_driver_s { uint8_t d_lltype; char d_ifname[16]; bool d_ifup; in_addr_t d_ipaddr; in_addr_t d_netmask; in_addr_t d_draddr; /* Default router address */ struct ether_addr d_mac; uint8_t *d_buf; uint16_t d_len; }; /* Test buffer */ static uint8_t test_buffer[1024]; /* Create a test network device with invalid router */ struct net_driver_s *create_test_device(void) { struct net_driver_s *dev = malloc(sizeof(struct net_driver_s)); if (!dev) return NULL; memset(dev, 0, sizeof(*dev)); dev->d_lltype = NET_LL_ETHERNET; strcpy(dev->d_ifname, "test_eth0"); dev->d_ifup = true; dev->d_ipaddr = inet_addr("192.168.1.1"); dev->d_netmask = inet_addr("255.255.255.0"); dev->d_draddr = INADDR_ANY; /* Invalid router address */ dev->d_buf = test_buffer; dev->d_len = sizeof(test_buffer); return dev; } int test_arp_send_invalid_router(void) { printf("Testing arp_send with invalid router address...\n"); in_addr_t dest_ip = inet_addr("192.168.2.100"); /* Different subnet */ int result = arp_send(dest_ip); if (result == -EHOSTUNREACH) { printf("✓ PASS: arp_send correctly returned EHOSTUNREACH for invalid router\n"); return 0; } else { printf("✗ FAIL: arp_send returned %d, expected %d (EHOSTUNREACH)\n", result, -EHOSTUNREACH); return -1; } } int test_arp_out_invalid_router(void) { printf("Testing arp_out with invalid router address...\n"); struct net_driver_s *dev = create_test_device(); if (!dev) { printf("✗ FAIL: Could not create test device\n"); return -1; } /* Setup IP header for destination in different subnet */ struct arp_iphdr_s *pip = (struct arp_iphdr_s *)(test_buffer + sizeof(struct eth_hdr_s)); pip->eh_destipaddr[0] = HTONS(0xC0A8); /* 192.168 */ pip->eh_destipaddr[1] = HTONS(0x0264); /* 2.100 */ /* Set initial packet length */ dev->d_len = 100; arp_out(dev); if (dev->d_len == 0) { printf("✓ PASS: arp_out correctly set packet length to 0 for invalid router\n"); free(dev); return 0; } else { printf("✗ FAIL: arp_out set packet length to %d, expected 0\n", dev->d_len); free(dev); return -1; } } int main(int argc, char *argv[]) { printf("=== ARP Router Address Validation Test ===\n\n"); int failures = 0; /* Test 1: arp_send with invalid router */ if (test_arp_send_invalid_router() != 0) { failures++; } printf("\n"); /* Test 2: arp_out with invalid router */ if (test_arp_out_invalid_router() != 0) { failures++; } printf("\n=== Test Results ===\n"); if (failures == 0) { printf("✓ ALL TESTS PASSED: ARP router validation fix is working correctly!\n"); printf("The fix prevents network operations from hanging when router address is invalid.\n"); return 0; } else { printf("✗ %d test(s) FAILED: ARP router validation fix needs attention.\n", failures); return -1; } } ``` Terminal output log: ``` core1> === ARP Router Address Validation Test === core1> === Test Results === core1> ✓ ALL TESTS PASSED: ARP router validation fix is working correctly! core1> The fix prevents network operations from hanging when router address is invalid. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
