From 29254ce84ba3af67e42ad6ad0a911e37528f955c Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Mon, 12 Jan 2026 09:45:36 -0300 Subject: [PATCH] allow creative usage of TCP reserved space in 'flags' --- mongoose.c | 6 ++++-- src/net_builtin.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 6aaf7d4e..632ea5c7 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4939,8 +4939,9 @@ struct tcp { #define TH_PUSH 0x08 #define TH_ACK 0x10 #define TH_URG 0x20 -#define TH_ECE 0x40 -#define TH_CWR 0x80 +#define TH_STDFLAGS 0x3f +//#define TH_ECE 0x40 // not part of TCP but RFC-3168 (ECN) +//#define TH_CWR 0x80 uint16_t win; // Window uint16_t csum; // Checksum uint16_t urp; // Urgent pointer @@ -6269,6 +6270,7 @@ static void handle_opt(struct connstate *s, struct tcp *tcp, bool ip6) { static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) { struct mg_connection *c = getpeer(ifp->mgr, pkt, false); struct connstate *s = c == NULL ? NULL : (struct connstate *) (c + 1); + pkt->tcp->flags &= TH_STDFLAGS; // tolerate creative usage (ECN, ?) // Order is VERY important; RFC-9293 3.5.2 // - check clients (Group 1) and established connections (Group 3) if (c != NULL && c->is_connecting && pkt->tcp->flags == (TH_SYN | TH_ACK)) { diff --git a/src/net_builtin.c b/src/net_builtin.c index 7727a87f..1d6a49fe 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -118,8 +118,9 @@ struct tcp { #define TH_PUSH 0x08 #define TH_ACK 0x10 #define TH_URG 0x20 -#define TH_ECE 0x40 -#define TH_CWR 0x80 +#define TH_STDFLAGS 0x3f +//#define TH_ECE 0x40 // not part of TCP but RFC-3168 (ECN) +//#define TH_CWR 0x80 uint16_t win; // Window uint16_t csum; // Checksum uint16_t urp; // Urgent pointer @@ -1448,6 +1449,7 @@ static void handle_opt(struct connstate *s, struct tcp *tcp, bool ip6) { static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) { struct mg_connection *c = getpeer(ifp->mgr, pkt, false); struct connstate *s = c == NULL ? NULL : (struct connstate *) (c + 1); + pkt->tcp->flags &= TH_STDFLAGS; // tolerate creative usage (ECN, ?) // Order is VERY important; RFC-9293 3.5.2 // - check clients (Group 1) and established connections (Group 3) if (c != NULL && c->is_connecting && pkt->tcp->flags == (TH_SYN | TH_ACK)) {