aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/survey0
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-04-14 15:43:59 -0700
committerGarrett D'Amore <garrett@damore.org>2024-04-14 18:52:56 -0700
commit82b322a37bcf890275f91b56a9a0347be056be9d (patch)
tree42a5f763f963c178b854e9326ef89f0d21582424 /src/sp/protocol/survey0
parent2b967f48a669f7199c40bc730f800e53d6d4fb72 (diff)
downloadnng-82b322a37bcf890275f91b56a9a0347be056be9d.tar.gz
nng-82b322a37bcf890275f91b56a9a0347be056be9d.tar.bz2
nng-82b322a37bcf890275f91b56a9a0347be056be9d.zip
Log protocol connections rejected by protocol.
Diffstat (limited to 'src/sp/protocol/survey0')
-rw-r--r--src/sp/protocol/survey0/respond.c51
-rw-r--r--src/sp/protocol/survey0/survey.c45
-rw-r--r--src/sp/protocol/survey0/xrespond.c19
-rw-r--r--src/sp/protocol/survey0/xsurvey.c19
4 files changed, 73 insertions, 61 deletions
diff --git a/src/sp/protocol/survey0/respond.c b/src/sp/protocol/survey0/respond.c
index d29eab97..8a8c134b 100644
--- a/src/sp/protocol/survey0/respond.c
+++ b/src/sp/protocol/survey0/respond.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -35,11 +35,11 @@ static void resp0_pipe_recv_cb(void *);
static void resp0_pipe_fini(void *);
struct resp0_ctx {
- resp0_sock * sock;
+ resp0_sock *sock;
uint32_t pipe_id;
- resp0_pipe * spipe; // send pipe
- nni_aio * saio; // send aio
- nni_aio * raio; // recv aio
+ resp0_pipe *spipe; // send pipe
+ nni_aio *saio; // send aio
+ nni_aio *raio; // recv aio
nni_list_node sqnode;
nni_list_node rqnode;
size_t btrace_len;
@@ -60,8 +60,8 @@ struct resp0_sock {
// resp0_pipe is our per-pipe protocol private structure.
struct resp0_pipe {
- nni_pipe * npipe;
- resp0_sock * psock;
+ nni_pipe *npipe;
+ resp0_sock *psock;
bool busy;
bool closed;
uint32_t id;
@@ -74,9 +74,9 @@ struct resp0_pipe {
static void
resp0_ctx_close(void *arg)
{
- resp0_ctx * ctx = arg;
+ resp0_ctx *ctx = arg;
resp0_sock *s = ctx->sock;
- nni_aio * aio;
+ nni_aio *aio;
// complete any outstanding operations here, cancellation, etc.
@@ -108,7 +108,7 @@ static void
resp0_ctx_init(void *carg, void *sarg)
{
resp0_sock *s = sarg;
- resp0_ctx * ctx = carg;
+ resp0_ctx *ctx = carg;
NNI_LIST_NODE_INIT(&ctx->sqnode);
NNI_LIST_NODE_INIT(&ctx->rqnode);
@@ -120,7 +120,7 @@ resp0_ctx_init(void *carg, void *sarg)
static void
resp0_ctx_cancel_send(nni_aio *aio, void *arg, int rv)
{
- resp0_ctx * ctx = arg;
+ resp0_ctx *ctx = arg;
resp0_sock *s = ctx->sock;
nni_mtx_lock(&s->mtx);
@@ -138,10 +138,10 @@ resp0_ctx_cancel_send(nni_aio *aio, void *arg, int rv)
static void
resp0_ctx_send(void *arg, nni_aio *aio)
{
- resp0_ctx * ctx = arg;
+ resp0_ctx *ctx = arg;
resp0_sock *s = ctx->sock;
resp0_pipe *p;
- nni_msg * msg;
+ nni_msg *msg;
size_t len;
uint32_t pid;
int rv;
@@ -269,7 +269,7 @@ static void
resp0_pipe_fini(void *arg)
{
resp0_pipe *p = arg;
- nng_msg * msg;
+ nng_msg *msg;
if ((msg = nni_aio_get_msg(&p->aio_recv)) != NULL) {
nni_aio_set_msg(&p->aio_recv, NULL);
@@ -305,6 +305,9 @@ resp0_pipe_start(void *arg)
int rv;
if (nni_pipe_peer(p->npipe) != NNI_PROTO_SURVEYOR_V0) {
+ nng_log_warn("NNG-PEER-MISMATCH",
+ "Peer protocol mismatch: %d != %d, rejected.",
+ nni_pipe_peer(p->npipe), NNI_PROTO_SURVEYOR_V0);
return (NNG_EPROTO);
}
@@ -324,7 +327,7 @@ resp0_pipe_close(void *arg)
{
resp0_pipe *p = arg;
resp0_sock *s = p->psock;
- resp0_ctx * ctx;
+ resp0_ctx *ctx;
nni_aio_close(&p->aio_send);
nni_aio_close(&p->aio_recv);
@@ -356,9 +359,9 @@ resp0_pipe_send_cb(void *arg)
{
resp0_pipe *p = arg;
resp0_sock *s = p->psock;
- resp0_ctx * ctx;
- nni_aio * aio;
- nni_msg * msg;
+ resp0_ctx *ctx;
+ nni_aio *aio;
+ nni_msg *msg;
size_t len;
if (nni_aio_result(&p->aio_send) != 0) {
@@ -398,7 +401,7 @@ resp0_pipe_send_cb(void *arg)
static void
resp0_cancel_recv(nni_aio *aio, void *arg, int rv)
{
- resp0_ctx * ctx = arg;
+ resp0_ctx *ctx = arg;
resp0_sock *s = ctx->sock;
nni_mtx_lock(&s->mtx);
@@ -413,11 +416,11 @@ resp0_cancel_recv(nni_aio *aio, void *arg, int rv)
static void
resp0_ctx_recv(void *arg, nni_aio *aio)
{
- resp0_ctx * ctx = arg;
+ resp0_ctx *ctx = arg;
resp0_sock *s = ctx->sock;
resp0_pipe *p;
size_t len;
- nni_msg * msg;
+ nni_msg *msg;
if (nni_aio_begin(aio) != 0) {
return;
@@ -470,9 +473,9 @@ resp0_pipe_recv_cb(void *arg)
{
resp0_pipe *p = arg;
resp0_sock *s = p->psock;
- resp0_ctx * ctx;
- nni_msg * msg;
- nni_aio * aio;
+ resp0_ctx *ctx;
+ nni_msg *msg;
+ nni_aio *aio;
int hops;
size_t len;
int ttl;
diff --git a/src/sp/protocol/survey0/survey.c b/src/sp/protocol/survey0/survey.c
index dc7346c7..3197f743 100644
--- a/src/sp/protocol/survey0/survey.c
+++ b/src/sp/protocol/survey0/survey.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -27,7 +27,7 @@ static void surv0_pipe_send_cb(void *);
static void surv0_pipe_recv_cb(void *);
struct surv0_ctx {
- surv0_sock * sock;
+ surv0_sock *sock;
uint32_t survey_id; // survey id
nni_lmq recv_lmq;
nni_list recv_queue;
@@ -51,8 +51,8 @@ struct surv0_sock {
// surv0_pipe is our per-pipe protocol private structure.
struct surv0_pipe {
- nni_pipe * pipe;
- surv0_sock * sock;
+ nni_pipe *pipe;
+ surv0_sock *sock;
nni_lmq send_queue;
nni_list_node node;
nni_aio aio_send;
@@ -64,7 +64,7 @@ struct surv0_pipe {
static void
surv0_ctx_abort(surv0_ctx *ctx, int err)
{
- nni_aio * aio;
+ nni_aio *aio;
surv0_sock *sock = ctx->sock;
while ((aio = nni_list_first(&ctx->recv_queue)) != NULL) {
@@ -103,8 +103,8 @@ surv0_ctx_fini(void *arg)
static void
surv0_ctx_init(void *c, void *s)
{
- surv0_ctx * ctx = c;
- surv0_sock * sock = s;
+ surv0_ctx *ctx = c;
+ surv0_sock *sock = s;
int len;
nng_duration tmo;
@@ -131,7 +131,7 @@ surv0_ctx_init(void *c, void *s)
static void
surv0_ctx_cancel(nni_aio *aio, void *arg, int rv)
{
- surv0_ctx * ctx = arg;
+ surv0_ctx *ctx = arg;
surv0_sock *sock = ctx->sock;
nni_mtx_lock(&sock->mtx);
if (nni_list_active(&ctx->recv_queue, aio)) {
@@ -148,10 +148,10 @@ surv0_ctx_cancel(nni_aio *aio, void *arg, int rv)
static void
surv0_ctx_recv(void *arg, nni_aio *aio)
{
- surv0_ctx * ctx = arg;
- surv0_sock *sock = ctx->sock;
- nni_msg * msg;
- nni_time now;
+ surv0_ctx *ctx = arg;
+ surv0_sock *sock = ctx->sock;
+ nni_msg *msg;
+ nni_time now;
nni_duration timeout;
if (nni_aio_begin(aio) != 0) {
@@ -200,10 +200,10 @@ again:
static void
surv0_ctx_send(void *arg, nni_aio *aio)
{
- surv0_ctx * ctx = arg;
- surv0_sock * sock = ctx->sock;
- surv0_pipe * pipe;
- nni_msg * msg = nni_aio_get_msg(aio);
+ surv0_ctx *ctx = arg;
+ surv0_sock *sock = ctx->sock;
+ surv0_pipe *pipe;
+ nni_msg *msg = nni_aio_get_msg(aio);
size_t len = nni_msg_len(msg);
nng_duration survey_time;
int rv;
@@ -360,6 +360,9 @@ surv0_pipe_start(void *arg)
surv0_sock *s = p->sock;
if (nni_pipe_peer(p->pipe) != NNG_SURVEYOR0_PEER) {
+ nng_log_warn("NNG-PEER-MISMATCH",
+ "Peer protocol mismatch: %d != %d, rejected.",
+ nni_pipe_peer(p->pipe), NNG_SURVEYOR0_PEER);
return (NNG_EPROTO);
}
@@ -394,7 +397,7 @@ surv0_pipe_send_cb(void *arg)
{
surv0_pipe *p = arg;
surv0_sock *sock = p->sock;
- nni_msg * msg;
+ nni_msg *msg;
if (nni_aio_result(&p->aio_send) != 0) {
nni_msg_free(nni_aio_get_msg(&p->aio_send));
@@ -422,10 +425,10 @@ surv0_pipe_recv_cb(void *arg)
{
surv0_pipe *p = arg;
surv0_sock *sock = p->sock;
- surv0_ctx * ctx;
- nni_msg * msg;
+ surv0_ctx *ctx;
+ nni_msg *msg;
uint32_t id;
- nni_aio * aio;
+ nni_aio *aio;
if (nni_aio_result(&p->aio_recv) != 0) {
nni_pipe_close(p->pipe);
@@ -470,7 +473,7 @@ static int
surv0_ctx_set_survey_time(
void *arg, const void *buf, size_t sz, nni_opt_type t)
{
- surv0_ctx * ctx = arg;
+ surv0_ctx *ctx = arg;
nng_duration expire;
int rv;
if ((rv = nni_copyin_ms(&expire, buf, sz, t)) == 0) {
diff --git a/src/sp/protocol/survey0/xrespond.c b/src/sp/protocol/survey0/xrespond.c
index 81a40486..c4d54594 100644
--- a/src/sp/protocol/survey0/xrespond.c
+++ b/src/sp/protocol/survey0/xrespond.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -37,8 +37,8 @@ static void xresp0_pipe_fini(void *);
// resp0_sock is our per-socket protocol private structure.
struct xresp0_sock {
- nni_msgq * urq;
- nni_msgq * uwq;
+ nni_msgq *urq;
+ nni_msgq *uwq;
nni_atomic_int ttl;
nni_id_map pipes;
nni_aio aio_getq;
@@ -47,10 +47,10 @@ struct xresp0_sock {
// resp0_pipe is our per-pipe protocol private structure.
struct xresp0_pipe {
- nni_pipe * npipe;
+ nni_pipe *npipe;
xresp0_sock *psock;
uint32_t id;
- nni_msgq * sendq;
+ nni_msgq *sendq;
nni_aio aio_getq;
nni_aio aio_putq;
nni_aio aio_send;
@@ -150,6 +150,9 @@ xresp0_pipe_start(void *arg)
int rv;
if (nni_pipe_peer(p->npipe) != NNI_PROTO_SURVEYOR_V0) {
+ nng_log_warn("NNG-PEER-MISMATCH",
+ "Peer protocol mismatch: %d != %d, rejected.",
+ nni_pipe_peer(p->npipe), NNI_PROTO_SURVEYOR_V0);
return (NNG_EPROTO);
}
@@ -195,7 +198,7 @@ void
xresp0_sock_getq_cb(void *arg)
{
xresp0_sock *s = arg;
- nni_msg * msg;
+ nni_msg *msg;
uint32_t id;
xresp0_pipe *p;
@@ -262,8 +265,8 @@ xresp0_recv_cb(void *arg)
{
xresp0_pipe *p = arg;
xresp0_sock *s = p->psock;
- nni_msgq * urq = s->urq;
- nni_msg * msg;
+ nni_msgq *urq = s->urq;
+ nni_msg *msg;
int hops;
int ttl;
diff --git a/src/sp/protocol/survey0/xsurvey.c b/src/sp/protocol/survey0/xsurvey.c
index 3cb3b6bd..208db051 100644
--- a/src/sp/protocol/survey0/xsurvey.c
+++ b/src/sp/protocol/survey0/xsurvey.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -27,17 +27,17 @@ static void xsurv0_recv_cb(void *);
struct xsurv0_sock {
nni_list pipes;
nni_aio aio_getq;
- nni_msgq * uwq;
- nni_msgq * urq;
+ nni_msgq *uwq;
+ nni_msgq *urq;
nni_mtx mtx;
nni_atomic_int ttl;
};
// surv0_pipe is our per-pipe protocol private structure.
struct xsurv0_pipe {
- nni_pipe * npipe;
- xsurv0_sock * psock;
- nni_msgq * sendq;
+ nni_pipe *npipe;
+ xsurv0_sock *psock;
+ nni_msgq *sendq;
nni_list_node node;
nni_aio aio_getq;
nni_aio aio_putq;
@@ -142,6 +142,9 @@ xsurv0_pipe_start(void *arg)
xsurv0_sock *s = p->psock;
if (nni_pipe_peer(p->npipe) != NNG_SURVEYOR0_PEER) {
+ nng_log_warn("NNG-PEER-MISMATCH",
+ "Peer protocol mismatch: %d != %d, rejected.",
+ nni_pipe_peer(p->npipe), NNG_SURVEYOR0_PEER);
return (NNG_EPROTO);
}
@@ -224,7 +227,7 @@ static void
xsurv0_recv_cb(void *arg)
{
xsurv0_pipe *p = arg;
- nni_msg * msg;
+ nni_msg *msg;
bool end;
if (nni_aio_result(&p->aio_recv) != 0) {
@@ -289,7 +292,7 @@ xsurv0_sock_getq_cb(void *arg)
{
xsurv0_sock *s = arg;
xsurv0_pipe *p;
- nni_msg * msg;
+ nni_msg *msg;
if (nni_aio_result(&s->aio_getq) != 0) {
// Should be NNG_ECLOSED.