mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
Merge pull request #2518 from cesanta/tls
Move TLS API to tls.h, fix builtin handshake codepath
This commit is contained in:
5 files changed
+18
-18
No files matched your search
+4
-4
@@ -5000,8 +5000,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
|
|||||||
}
|
}
|
||||||
// Ensure the MTU isn't lower than the minimum allowed value
|
// Ensure the MTU isn't lower than the minimum allowed value
|
||||||
if (ifp->mtu < min_mtu) {
|
if (ifp->mtu < min_mtu) {
|
||||||
MG_ERROR(("MTU is lower than minimum possible value. Setting it to %d.",
|
MG_ERROR(("MTU is lower than minimum, capping to %lu", min_mtu));
|
||||||
min_mtu));
|
|
||||||
ifp->mtu = (uint16_t) min_mtu;
|
ifp->mtu = (uint16_t) min_mtu;
|
||||||
}
|
}
|
||||||
// If the total packet size exceeds the MTU, trim the length
|
// If the total packet size exceeds the MTU, trim the length
|
||||||
@@ -5112,7 +5111,9 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
|||||||
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (c->is_tls) {
|
if (c->is_tls && c->is_tls_hs) {
|
||||||
|
mg_tls_handshake(c);
|
||||||
|
} else if (c->is_tls) {
|
||||||
// TLS connection. Make room for decrypted data in c->recv
|
// TLS connection. Make room for decrypted data in c->recv
|
||||||
io = &c->recv;
|
io = &c->recv;
|
||||||
if (io->size - io->len < pkt->pay.len &&
|
if (io->size - io->len < pkt->pay.len &&
|
||||||
@@ -5526,7 +5527,6 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
|||||||
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
||||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
||||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
|
||||||
if (can_write(c)) write_conn(c);
|
if (can_write(c)) write_conn(c);
|
||||||
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
||||||
init_closure(c);
|
init_closure(c);
|
||||||
|
|||||||
+5
-5
@@ -1293,11 +1293,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
|||||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||||
unsigned flags, void (*fn)(void *), void *arg);
|
unsigned flags, void (*fn)(void *), void *arg);
|
||||||
|
|
||||||
// Low-level IO primives used by TLS layer
|
|
||||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
|
||||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
|
||||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1402,6 +1397,11 @@ void mg_tls_handshake(struct mg_connection *);
|
|||||||
void mg_tls_ctx_init(struct mg_mgr *);
|
void mg_tls_ctx_init(struct mg_mgr *);
|
||||||
void mg_tls_ctx_free(struct mg_mgr *);
|
void mg_tls_ctx_free(struct mg_mgr *);
|
||||||
|
|
||||||
|
// Low-level IO primives used by TLS layer
|
||||||
|
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||||
|
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||||
|
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -99,8 +99,3 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||||
unsigned flags, void (*fn)(void *), void *arg);
|
unsigned flags, void (*fn)(void *), void *arg);
|
||||||
|
|
||||||
// Low-level IO primives used by TLS layer
|
|
||||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
|
||||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
|
||||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
|
||||||
+4
-4
@@ -557,8 +557,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
|
|||||||
}
|
}
|
||||||
// Ensure the MTU isn't lower than the minimum allowed value
|
// Ensure the MTU isn't lower than the minimum allowed value
|
||||||
if (ifp->mtu < min_mtu) {
|
if (ifp->mtu < min_mtu) {
|
||||||
MG_ERROR(("MTU is lower than minimum possible value. Setting it to %d.",
|
MG_ERROR(("MTU is lower than minimum, capping to %lu", min_mtu));
|
||||||
min_mtu));
|
|
||||||
ifp->mtu = (uint16_t) min_mtu;
|
ifp->mtu = (uint16_t) min_mtu;
|
||||||
}
|
}
|
||||||
// If the total packet size exceeds the MTU, trim the length
|
// If the total packet size exceeds the MTU, trim the length
|
||||||
@@ -669,7 +668,9 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
|||||||
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (c->is_tls) {
|
if (c->is_tls && c->is_tls_hs) {
|
||||||
|
mg_tls_handshake(c);
|
||||||
|
} else if (c->is_tls) {
|
||||||
// TLS connection. Make room for decrypted data in c->recv
|
// TLS connection. Make room for decrypted data in c->recv
|
||||||
io = &c->recv;
|
io = &c->recv;
|
||||||
if (io->size - io->len < pkt->pay.len &&
|
if (io->size - io->len < pkt->pay.len &&
|
||||||
@@ -1083,7 +1084,6 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
|||||||
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
||||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
||||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
|
||||||
if (can_write(c)) write_conn(c);
|
if (can_write(c)) write_conn(c);
|
||||||
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
||||||
init_closure(c);
|
init_closure(c);
|
||||||
|
|||||||
@@ -31,3 +31,8 @@ void mg_tls_handshake(struct mg_connection *);
|
|||||||
// Private
|
// Private
|
||||||
void mg_tls_ctx_init(struct mg_mgr *);
|
void mg_tls_ctx_init(struct mg_mgr *);
|
||||||
void mg_tls_ctx_free(struct mg_mgr *);
|
void mg_tls_ctx_free(struct mg_mgr *);
|
||||||
|
|
||||||
|
// Low-level IO primives used by TLS layer
|
||||||
|
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||||
|
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||||
|
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||||
Reference in new issue
Block a user