From 175ca9464af08839e5f52fe0ed40da7b0e747c2a Mon Sep 17 00:00:00 2001 From: bloqaudio Date: Tue, 22 Sep 2026 09:23:13 -0500 Subject: [PATCH 1/2] uip: build the forwarding module only when configured uip-fw.c forwards packets between several network interfaces. Nothing in this firmware calls it: the only references to uip_fw_output() outside the module are commented out in uip-split.c. It is compiled and linked all the same, and its register pressure lands in direct RAM, which on SWTGW218AS is already reported as having no spare space. Add UIP_CONF_FORWARDING alongside the existing UIP_CONF_BROADCAST and build the module only when it is set. A device that forwards turns it on and gets the module unchanged; a single-interface device stops paying for it. On SWTGW218AS the stack gains 9 bytes, from 151 available to 160, and BANK1 drops 1200 bytes, from 47994 to 46794. --- uip/uip-fw.c | 4 ++++ uip/uipopt.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/uip/uip-fw.c b/uip/uip-fw.c index 4b669798..ddc9de64 100644 --- a/uip/uip-fw.c +++ b/uip/uip-fw.c @@ -64,6 +64,8 @@ #include "../rtl837x_common.h" +#if UIP_FORWARDING + /* * The list of registered network interfaces. */ @@ -535,3 +537,5 @@ uip_fw_periodic(void) } } /*------------------------------------------------------------------------------*/ + +#endif /* UIP_FORWARDING */ diff --git a/uip/uipopt.h b/uip/uipopt.h index 20aec637..620d6054 100644 --- a/uip/uipopt.h +++ b/uip/uipopt.h @@ -464,6 +464,20 @@ extern __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2]; #define UIP_BROADCAST UIP_CONF_BROADCAST #endif /* UIP_CONF_BROADCAST */ +/** + * Build the IP forwarding module. + * + * uip-fw.c forwards packets between several network interfaces. A + * single-interface device does not call it and should not pay for it. + * + * \hideinitializer + */ +#ifndef UIP_CONF_FORWARDING +#define UIP_FORWARDING 0 +#else /* UIP_CONF_FORWARDING */ +#define UIP_FORWARDING UIP_CONF_FORWARDING +#endif /* UIP_CONF_FORWARDING */ + /** * Print out a uIP log message. * From 675faf0471ac3b7d315c36a1a3bba54e8ea7dc40 Mon Sep 17 00:00:00 2001 From: bloqaudio Date: Tue, 22 Sep 2026 09:23:13 -0500 Subject: [PATCH 2/2] uip: build the IPv6 neighbour cache only for IPv6 builds uip-neighbor.c is the IPv6 neighbour cache. Its only caller is the neighbour solicitation handler in uip_process(), which sits inside #if UIP_CONF_IPV6, so on an IPv4 build the module is linked without being reachable. Guard it on the same macro as its caller. Worth recording separately: the module does not currently compile with UIP_CONF_IPV6 set. uip_ipaddr_cmpx() is defined only in the non-IPv6 half of uip.h, and uip_neighbor_add() calls it, so an IPv6 build stops with an implicit declaration. That is true before this change as well, and is left alone here. On SWTGW218AS, on top of the forwarding change, the stack gains a further 12 bytes to 172 available and BANK1 drops another 714 bytes to 46080. --- uip/uip-neighbor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uip/uip-neighbor.c b/uip/uip-neighbor.c index 0795cef8..cc3ab994 100644 --- a/uip/uip-neighbor.c +++ b/uip/uip-neighbor.c @@ -43,6 +43,8 @@ #include "uip-neighbor.h" #include "../rtl837x_common.h" +#if UIP_CONF_IPV6 + #pragma codeseg BANK1 #pragma constseg BANK1 @@ -170,3 +172,5 @@ uip_neighbor_lookup(__xdata uip_ipaddr_t ipaddr) return NULL; } /*---------------------------------------------------------------------------*/ + +#endif /* UIP_CONF_IPV6 */