|
22 | 22 | #include "../../../config.h" |
23 | 23 | #undef WOLFIP_MAX_INTERFACES |
24 | 24 | #define WOLFIP_MAX_INTERFACES 3 |
| 25 | +#undef WOLFIP_ENABLE_LOOPBACK |
| 26 | +#define WOLFIP_ENABLE_LOOPBACK 1 |
25 | 27 | #undef WOLFIP_ENABLE_FORWARDING |
26 | 28 | #ifndef WOLFIP_ENABLE_FORWARDING |
27 | 29 | #define WOLFIP_ENABLE_FORWARDING 1 |
@@ -607,6 +609,7 @@ START_TEST(test_arp_lookup_success) { |
607 | 609 |
|
608 | 610 | /* Add a known IP-MAC pair */ |
609 | 611 | s.arp.neighbors[0].ip = ip; |
| 612 | + s.arp.neighbors[0].if_idx = TEST_PRIMARY_IF; |
610 | 613 | memcpy(s.arp.neighbors[0].mac, mock_mac, 6); |
611 | 614 |
|
612 | 615 | /* Test arp_lookup */ |
@@ -850,6 +853,39 @@ START_TEST(test_wolfip_forwarding_ttl_expired) |
850 | 853 | } |
851 | 854 | END_TEST |
852 | 855 |
|
| 856 | +START_TEST(test_loopback_dest_not_forwarded) |
| 857 | +{ |
| 858 | + struct wolfIP s; |
| 859 | + struct wolfIP_ip_packet frame; |
| 860 | + uint8_t src_mac[6] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60}; |
| 861 | + |
| 862 | + wolfIP_init(&s); |
| 863 | + mock_link_init(&s); |
| 864 | + mock_link_init_idx(&s, TEST_SECOND_IF, NULL); |
| 865 | + wolfIP_ipconfig_set(&s, 0xC0A80001, 0xFFFFFF00, 0); |
| 866 | + |
| 867 | + memset(&frame, 0, sizeof(frame)); |
| 868 | + memcpy(frame.eth.dst, s.ll_dev[TEST_PRIMARY_IF].mac, 6); |
| 869 | + memcpy(frame.eth.src, src_mac, 6); |
| 870 | + frame.eth.type = ee16(ETH_TYPE_IP); |
| 871 | + frame.ver_ihl = 0x45; |
| 872 | + frame.ttl = 64; |
| 873 | + frame.proto = WI_IPPROTO_UDP; |
| 874 | + frame.len = ee16(IP_HEADER_LEN); |
| 875 | + frame.src = ee32(0x0A000002U); |
| 876 | + frame.dst = ee32(0x7F000001U); |
| 877 | + frame.csum = 0; |
| 878 | + iphdr_set_checksum(&frame); |
| 879 | + |
| 880 | + memset(last_frame_sent, 0, sizeof(last_frame_sent)); |
| 881 | + last_frame_sent_size = 0; |
| 882 | + |
| 883 | + wolfIP_recv_ex(&s, TEST_PRIMARY_IF, &frame, sizeof(frame)); |
| 884 | + |
| 885 | + ck_assert_uint_eq(last_frame_sent_size, 0); |
| 886 | +} |
| 887 | +END_TEST |
| 888 | + |
853 | 889 |
|
854 | 890 | // Test for `transport_checksum` calculation |
855 | 891 | START_TEST(test_transport_checksum) { |
@@ -906,10 +942,10 @@ START_TEST(test_eth_output_add_header) { |
906 | 942 | memset(ð_frame, 0, sizeof(eth_frame)); |
907 | 943 |
|
908 | 944 | uint8_t test_mac[6] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
909 | | - struct ll *ll = wolfIP_getdev(&S); |
| 945 | + struct ll *ll = wolfIP_getdev_ex(&S, TEST_PRIMARY_IF); |
910 | 946 | memcpy(ll->mac, test_mac, 6); |
911 | 947 |
|
912 | | - eth_output_add_header(&S, 0, NULL, ð_frame, ETH_TYPE_IP); |
| 948 | + eth_output_add_header(&S, TEST_PRIMARY_IF, NULL, ð_frame, ETH_TYPE_IP); |
913 | 949 |
|
914 | 950 | ck_assert_mem_eq(eth_frame.dst, "\xff\xff\xff\xff\xff\xff", 6); // Broadcast |
915 | 951 | ck_assert_mem_eq(eth_frame.src, test_mac, 6); |
@@ -1044,6 +1080,8 @@ Suite *wolf_suite(void) |
1044 | 1080 | suite_add_tcase(s, tc_proto); |
1045 | 1081 | tcase_add_test(tc_proto, test_wolfip_forwarding_ttl_expired); |
1046 | 1082 | suite_add_tcase(s, tc_proto); |
| 1083 | + tcase_add_test(tc_proto, test_loopback_dest_not_forwarded); |
| 1084 | + suite_add_tcase(s, tc_proto); |
1047 | 1085 |
|
1048 | 1086 | tcase_add_test(tc_utils, test_transport_checksum); |
1049 | 1087 | suite_add_tcase(s, tc_proto); |
|
0 commit comments