Set router packet length in firewall integration fixture

This commit is contained in:
evgeny committed 2026-10-21 19:59:34 +02:00
1 parent 4f627bddff
commit 41c32cf063
1 file changed
+7 -2
+7 -2
View File
@@ -149,6 +149,7 @@ static void test_parser(void) {
}
static void test_packets(void) {
debug_set_category_level(DEBUG_CATEGORY_ROUTING, DEBUG_LEVEL_INFO);
struct CFG_FIREWALL_RULE rule = {0x0a000001, 443};
struct global_config cfg = {.firewall_rules = &rule, .firewall_rule_count = 1};
struct firewall_ctx fw = {0};
@@ -158,10 +159,10 @@ static void test_packets(void) {
for (size_t ihl = 20; ihl <= 60; ihl += 4) {
size_t len = packet(data, rule.ip, 443, proto, ihl);
assert(fw_check_packet(&fw, data, len) == 1);
data[ihl + 3] = 80;
data[ihl + 2] = 0; data[ihl + 3] = 80;
assert(fw_check_packet(&fw, data, len) == 0);
data[ihl] = 1; data[ihl + 1] = 187;
assert(fw_check_packet(&fw, data, len) == 0); // source port 443 не разрешает destination 336.
assert(fw_check_packet(&fw, data, len) == 0); // source port 443 не разрешает destination 80.
}
}
size_t len = packet(data, rule.ip, 443, 1, 20);
@@ -196,6 +197,7 @@ static void test_packets(void) {
data[6] = 0x80; assert(fw_check_packet(&fw, data, len) == -1);
data[6] = 0x20; data[3]--; assert(fw_check_packet(&fw, data, len - 1) == -1);
fw_free(&fw);
debug_set_category_level(DEBUG_CATEGORY_ROUTING, DEBUG_LEVEL_DEBUG);
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "[PASS] firewall IPv4 options, TCP/UDP destination, ICMP, fragments and malformed lengths");
}
@@ -203,6 +205,7 @@ static void test_packets(void) {
static void incoming(struct UTUN_INSTANCE *inst, const uint8_t *data, size_t len) {
struct ll_entry *entry = ll_alloc_lldgram(ROUTER_SVC_PAYLOAD_OFF + len);
assert(entry);
entry->len = ROUTER_SVC_PAYLOAD_OFF + len;
uint64_t src = 2;
entry->dgram[0] = ETCP_RT_ID_DATA;
memcpy(entry->dgram + ROUTER_SVC_SRC_OFF, &src, sizeof(src));
@@ -270,8 +273,10 @@ static void test_tun(void) {
assert(!tun_inject_packet(inst.tun, data, len) && sent_packets == 3 && inst.dropped_packets == 6);
send_result = 0;
struct ll_entry *invalid = ll_alloc_lldgram(1); assert(invalid);
invalid->len = 1;
assert(!queue_data_put(inst.tun->output_queue, invalid));
struct ll_entry *short_entry = ll_alloc_lldgram(1); assert(short_entry);
short_entry->len = 1;
route_pkt(&inst, short_entry, 2);
struct ll_entry *no_instance = ll_alloc_lldgram(1); assert(no_instance);
route_pkt(NULL, no_instance, 2);