Skip to content

Commit 6fdeee3

Browse files
committed
Update router.cpp
1 parent 8a33504 commit 6fdeee3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎project/apps/he_app/router.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static const uint8_t lan_netmask[4] = {255, 255, 0, 0};
4747
/* Forward declarations */
4848
static int forward_to_wan(struct net_pkt *pkt);
4949
static int forward_to_lan(struct net_pkt *pkt);
50+
static bool get_wan_ip(struct in_addr *addr);
5051

5152
#if NPF_ENABLED
5253
static bool router_npf_test(struct npf_test *test, struct net_pkt *pkt);
@@ -98,6 +99,13 @@ static bool is_our_wan_addr(const struct in_addr *addr)
9899
if (net_if_ipv4_addr_lookup(addr, &found_iface) && found_iface == wan_iface) {
99100
return true;
100101
}
102+
103+
/* Fallback: compare with get_wan_ip result for offload interfaces */
104+
struct in_addr wan_ip;
105+
if (get_wan_ip(&wan_ip) && net_ipv4_addr_cmp(&wan_ip, addr)) {
106+
return true;
107+
}
108+
101109
return false;
102110
}
103111

@@ -412,10 +420,17 @@ static int forward_to_lan(struct net_pkt *pkt)
412420
}
413421

414422
/* Lookup NAT entry by WAN port */
423+
char src_str[NET_IPV4_ADDR_LEN];
424+
LOG_DBG("NAT lookup: proto=%d wan_port=%d src=%s:%d",
425+
protocol, dst_port,
426+
ipv4_to_str(&src_ip, src_str, sizeof(src_str)), src_port);
427+
415428
struct nat_entry *nat = nat_lookup_by_wan(protocol, dst_port,
416429
&src_ip, src_port);
417430
if (!nat) {
418431
/* No NAT entry found - not a reply to our traffic */
432+
LOG_DBG("NAT lookup MISS: no entry for proto=%d wan_port=%d",
433+
protocol, dst_port);
419434
return -ENOENT;
420435
}
421436

@@ -612,6 +627,12 @@ static bool router_npf_test(struct npf_test *test, struct net_pkt *pkt)
612627
if (iface == wan_iface) {
613628
stats.wlan0_rx_total++;
614629

630+
/* Debug: log all WAN packets */
631+
char dst_str[NET_IPV4_ADDR_LEN];
632+
uint8_t proto = ip_hdr->proto;
633+
LOG_DBG("WAN RX: dst=%s proto=%d",
634+
ipv4_to_str(&dst_ip, dst_str, sizeof(dst_str)), proto);
635+
615636
/* Check if destined for our WAN address */
616637
if (is_our_wan_addr(&dst_ip)) {
617638
/* Could be local traffic or NAT reply */
@@ -624,6 +645,8 @@ static bool router_npf_test(struct npf_test *test, struct net_pkt *pkt)
624645
/* Not a NAT reply, let local stack handle it */
625646
stats.wlan0_rx_local++;
626647
return true;
648+
} else {
649+
LOG_DBG("WAN RX: dst not our WAN addr, dropping");
627650
}
628651

629652
/* Not for us - drop */

0 commit comments

Comments
 (0)