set is_tls at mg_listen and mg_connect level

This commit is contained in:
Sergio R. Caprile committed 2025-05-26 09:42:48 -03:00
1 parent 29594283c1
commit b740c80855
25 files changed
+69 -49

No files matched your search

+9 -4
View File
@@ -177,7 +177,7 @@ static void settmout(struct mg_connection *c, uint8_t type) {
: type == MIP_TTYPE_SYN ? MIP_TCP_SYN_MS
: type == MIP_TTYPE_FIN ? MIP_TCP_FIN_MS
: MIP_TCP_KEEPALIVE_MS;
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
s->timer = ifp->now + n;
s->ttype = type;
MG_VERBOSE(("%lu %d -> %llx", c->id, type, s->timer));
@@ -580,7 +580,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
return NULL;
}
struct connstate *s = (struct connstate *) (c + 1);
s->dmss = 536; // assume default, RFC-9293 3.7.1
s->dmss = 536; // assume default, RFC-9293 3.7.1
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
memcpy(s->mac, pkt->eth->src, sizeof(s->mac));
settmout(c, MIP_TTYPE_KEEPALIVE);
@@ -595,8 +595,10 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
c->pfn_data = lsn->pfn_data;
c->fn = lsn->fn;
c->fn_data = lsn->fn_data;
c->is_tls = lsn->is_tls;
mg_call(c, MG_EV_OPEN, NULL);
mg_call(c, MG_EV_ACCEPT, NULL);
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
return c;
}
@@ -784,6 +786,7 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
settmout(c, MIP_TTYPE_KEEPALIVE);
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
if (c->is_tls_hs) mg_tls_handshake(c);
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
} else if (c != NULL && c->is_connecting && pkt->tcp->flags != TH_ACK) {
// mg_hexdump(pkt->raw.buf, pkt->raw.len);
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
@@ -1209,16 +1212,18 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
for (c = mgr->conns; c != NULL; c = tmp) {
tmp = c->next;
struct connstate *s = (struct connstate *) (c + 1);
bool is_tls = !c->is_resolving && !c->is_arplooking && !c->is_listening &&
!c->is_connecting;
mg_call(c, MG_EV_POLL, &now);
MG_VERBOSE(("%lu .. %c%c%c%c%c %lu %lu", c->id, c->is_tls ? 'T' : 't',
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
mg_tls_pending(c), c->rtls.len));
// order is important, TLS conn close with > 1 record in buffer (below)
if (c->is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
if (is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
handle_tls_recv(c);
if (can_write(c)) write_conn(c);
if (!c->is_listening && c->is_tls && !c->is_tls_hs && c->send.len == 0) mg_tls_flush(c);
if (is_tls && c->send.len == 0) mg_tls_flush(c);
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
init_closure(c);
// For non-TLS, close immediately upon completing the 3-way closure