Skip to content

Commit

Permalink
Log messages when peer sends too large message.
Browse files Browse the repository at this point in the history
Also while here, remove unused sockaddr members from some structs.
This should save a bit of memory for servers with a lot of conns.
  • Loading branch information
gdamore committed Apr 16, 2024
1 parent d230d9b commit 62f7055
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
62 changes: 31 additions & 31 deletions src/sp/transport/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ typedef struct ipc_ep ipc_ep;

// ipc_pipe is one end of an IPC connection.
struct ipc_pipe {
nng_stream * conn;
nng_stream *conn;
uint16_t peer;
uint16_t proto;
size_t rcv_max;
bool closed;
nni_sockaddr sa;
ipc_ep * ep;
nni_pipe * pipe;
ipc_ep *ep;
nni_pipe *pipe;
nni_list_node node;
nni_atomic_flag reaped;
nni_reap_node reap;
Expand All @@ -47,24 +46,23 @@ struct ipc_pipe {
nni_aio tx_aio;
nni_aio rx_aio;
nni_aio neg_aio;
nni_msg * rx_msg;
nni_msg *rx_msg;
nni_mtx mtx;
};

struct ipc_ep {
nni_mtx mtx;
nni_sockaddr sa;
size_t rcv_max;
uint16_t proto;
bool started;
bool closed;
bool fini;
int ref_cnt;
nng_stream_dialer * dialer;
nng_stream_dialer *dialer;
nng_stream_listener *listener;
nni_aio * user_aio;
nni_aio * conn_aio;
nni_aio * time_aio;
nni_aio *user_aio;
nni_aio *conn_aio;
nni_aio *time_aio;
nni_list busy_pipes; // busy pipes -- ones passed to socket
nni_list wait_pipes; // pipes waiting to match to socket
nni_list neg_pipes; // pipes busy negotiating
Expand Down Expand Up @@ -140,7 +138,7 @@ static void
ipc_pipe_fini(void *arg)
{
ipc_pipe *p = arg;
ipc_ep * ep;
ipc_ep *ep;

ipc_pipe_stop(p);
if ((ep = p->ep) != NULL) {
Expand Down Expand Up @@ -196,7 +194,7 @@ ipc_pipe_alloc(ipc_pipe **pipe_p)
static void
ipc_ep_match(ipc_ep *ep)
{
nni_aio * aio;
nni_aio *aio;
ipc_pipe *p;

if (((aio = ep->user_aio) == NULL) ||
Expand All @@ -215,9 +213,9 @@ static void
ipc_pipe_neg_cb(void *arg)
{
ipc_pipe *p = arg;
ipc_ep * ep = p->ep;
nni_aio * aio = &p->neg_aio;
nni_aio * user_aio;
ipc_ep *ep = p->ep;
nni_aio *aio = &p->neg_aio;
nni_aio *user_aio;
int rv;

nni_mtx_lock(&ep->mtx);
Expand Down Expand Up @@ -294,10 +292,10 @@ ipc_pipe_send_cb(void *arg)
{
ipc_pipe *p = arg;
int rv;
nni_aio * aio;
nni_aio *aio;
size_t n;
nni_msg * msg;
nni_aio * tx_aio = &p->tx_aio;
nni_msg *msg;
nni_aio *tx_aio = &p->tx_aio;

nni_mtx_lock(&p->mtx);
if ((rv = nni_aio_result(tx_aio)) != 0) {
Expand Down Expand Up @@ -342,11 +340,11 @@ static void
ipc_pipe_recv_cb(void *arg)
{
ipc_pipe *p = arg;
nni_aio * aio;
nni_aio *aio;
int rv;
size_t n;
nni_msg * msg;
nni_aio * rx_aio = &p->rx_aio;
nni_msg *msg;
nni_aio *rx_aio = &p->rx_aio;

nni_mtx_lock(&p->mtx);

Expand Down Expand Up @@ -384,6 +382,9 @@ ipc_pipe_recv_cb(void *arg)
// Make sure the message payload is not too big. If it is
// the caller will shut down the pipe.
if ((len > p->rcv_max) && (p->rcv_max > 0)) {
nng_log_warn("NNG-RCVMAX",
"Rejected oversize message of %d bytes on IPC",
len);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This argument should be of type 'int' but is of type 'unsigned long'.
rv = NNG_EMSGSIZE;
goto error;
}
Expand Down Expand Up @@ -656,7 +657,7 @@ ipc_pipe_start(ipc_pipe *p, nng_stream *conn, ipc_ep *ep)
static void
ipc_ep_close(void *arg)
{
ipc_ep * ep = arg;
ipc_ep *ep = arg;
ipc_pipe *p;

nni_mtx_lock(&ep->mtx);
Expand Down Expand Up @@ -720,9 +721,9 @@ ipc_ep_timer_cb(void *arg)
static void
ipc_ep_accept_cb(void *arg)
{
ipc_ep * ep = arg;
nni_aio * aio = ep->conn_aio;
ipc_pipe * p;
ipc_ep *ep = arg;
nni_aio *aio = ep->conn_aio;
ipc_pipe *p;
int rv;
nng_stream *conn;

Expand Down Expand Up @@ -774,9 +775,9 @@ ipc_ep_accept_cb(void *arg)
static void
ipc_ep_dial_cb(void *arg)
{
ipc_ep * ep = arg;
nni_aio * aio = ep->conn_aio;
ipc_pipe * p;
ipc_ep *ep = arg;
nni_aio *aio = ep->conn_aio;
ipc_pipe *p;
int rv;
nng_stream *conn;

Expand Down Expand Up @@ -846,7 +847,7 @@ ipc_ep_init(ipc_ep **epp, nni_sock *sock)
static int
ipc_ep_init_dialer(void **dp, nni_url *url, nni_dialer *dialer)
{
ipc_ep * ep;
ipc_ep *ep;
int rv;
nni_sock *sock = nni_dialer_sock(dialer);

Expand All @@ -869,7 +870,7 @@ ipc_ep_init_dialer(void **dp, nni_url *url, nni_dialer *dialer)
static int
ipc_ep_init_listener(void **dp, nni_url *url, nni_listener *listener)
{
ipc_ep * ep;
ipc_ep *ep;
int rv;
nni_sock *sock = nni_listener_sock(listener);

Expand Down Expand Up @@ -1147,7 +1148,6 @@ static nni_sp_tran ipc_tran_abstract = {
};
#endif


#ifndef NNG_ELIDE_DEPRECATED
int
nng_ipc_register(void)
Expand Down
6 changes: 4 additions & 2 deletions src/sp/transport/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ struct tcptran_ep {
bool started;
bool closed;
nng_url *url;
const char *host; // for dialers
nng_sockaddr src;
const char *host; // for dialers
int refcnt; // active pipes
nni_aio *useraio;
nni_aio *connaio;
Expand Down Expand Up @@ -385,6 +384,9 @@ tcptran_pipe_recv_cb(void *arg)
// Make sure the message payload is not too big. If it is
// the caller will shut down the pipe.
if ((len > p->rcvmax) && (p->rcvmax > 0)) {
nng_log_warn("NNG-RCVMAX",
"Rejected oversize message of %d bytes on TCP",
len);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This argument should be of type 'int' but is of type 'unsigned long'.
rv = NNG_EMSGSIZE;
goto recv_error;
}
Expand Down
5 changes: 3 additions & 2 deletions src/sp/transport/tls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct tlstran_pipe {
nni_list sendq;
nni_list recvq;
tlstran_ep *ep;
nni_sockaddr sa;
nni_atomic_flag reaped;
nni_reap_node reap;
uint8_t txlen[sizeof(uint64_t)];
Expand Down Expand Up @@ -76,7 +75,6 @@ struct tlstran_ep {
nni_list waitpipes; // pipes waiting to match to socket
nni_list negopipes; // pipes busy negotiating
const char *host;
nng_sockaddr src;
nng_sockaddr sa;
nni_stat_item st_rcv_max;
};
Expand Down Expand Up @@ -379,6 +377,9 @@ tlstran_pipe_recv_cb(void *arg)
// Make sure the message payload is not too big. If it is
// the caller will shut down the pipe.
if ((len > p->rcvmax) && (p->rcvmax > 0)) {
nng_log_warn("NNG-RCVMAX",

Check warning on line 380 in src/sp/transport/tls/tls.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/tls/tls.c#L380

Added line #L380 was not covered by tests
"Rejected oversize message of %d bytes on TLS",
len);

Check failure

Code scanning / CodeQL

Wrong type of arguments to formatting function High

This argument should be of type 'int' but is of type 'unsigned long'.

Check warning on line 382 in src/sp/transport/tls/tls.c

View check run for this annotation

Codecov / codecov/patch

src/sp/transport/tls/tls.c#L382

Added line #L382 was not covered by tests
rv = NNG_EMSGSIZE;
goto recv_error;
}
Expand Down

0 comments on commit 62f7055

Please sign in to comment.