From 5ae0f31c314273bf95658bd1238628e9398199bb Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 25 Apr 2022 15:53:04 +0200 Subject: [PATCH] Check RSPRO component type; print error if type doesn't match If one component connects to another component, verify that the remote component type (bank/server/client) matches our expectation. This is important in order to detect a misconfiguration of port numbers, for example. Closes: OS#5548 Change-Id: I89a4fc4331e8a0622f8f146c7fc235d34d990497 --- src/bankd/bankd_main.c | 7 +++++++ src/client/remsim_client.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/bankd/bankd_main.c b/src/bankd/bankd_main.c index fcdbf76..9e2d8f8 100644 --- a/src/bankd/bankd_main.c +++ b/src/bankd/bankd_main.c @@ -174,6 +174,13 @@ static int bankd_srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t switch (pdu->msg.present) { case RsproPDUchoice_PR_connectBankRes: + if (pdu->msg.choice.connectBankRes.identity.type != ComponentType_remsimServer) { + LOGPFSML(srvc->fi, LOGL_ERROR, "Server connection to a ComponentType(%ld) != RemsimServer? " + "Check your IP/Port configuration\n", + pdu->msg.choice.connectBankRes.identity.type); + osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_DISCONNECT, NULL); + return -1; + } /* Store 'identity' of server in srvc->peer_comp_id */ rspro_comp_id_retrieve(&srvc->peer_comp_id, &pdu->msg.choice.connectBankRes.identity); osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_CLIENT_CONN_RES, (void *) pdu); diff --git a/src/client/remsim_client.c b/src/client/remsim_client.c index 8da82ef..247ae42 100644 --- a/src/client/remsim_client.c +++ b/src/client/remsim_client.c @@ -67,6 +67,13 @@ static int bankd_handle_rx(struct rspro_server_conn *bankdc, const RsproPDU_t *p switch (pdu->msg.present) { case RsproPDUchoice_PR_connectClientRes: + if (pdu->msg.choice.connectClientRes.identity.type != ComponentType_remsimBankd) { + LOGPFSML(bankdc->fi, LOGL_ERROR, "Server connection to a ComponentType(%ld) != RemsimBankd? " + "Check your IP/Port configuration\n", + pdu->msg.choice.connectClientRes.identity.type); + osmo_fsm_inst_dispatch(bankdc->fi, SRVC_E_DISCONNECT, NULL); + return -1; + } /* Store 'identity' of bankd to in peer_comp_id */ rspro_comp_id_retrieve(&bankdc->peer_comp_id, &pdu->msg.choice.connectClientRes.identity); osmo_fsm_inst_dispatch(bankdc->fi, SRVC_E_CLIENT_CONN_RES, (void *) pdu); @@ -94,6 +101,13 @@ static int srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t *pdu) switch (pdu->msg.present) { case RsproPDUchoice_PR_connectClientRes: + if (pdu->msg.choice.connectClientRes.identity.type != ComponentType_remsimServer) { + LOGPFSML(srvc->fi, LOGL_ERROR, "Server connection to a ComponentType(%ld) != RemsimServer? " + "Check your IP/Port configuration\n", + pdu->msg.choice.connectClientRes.identity.type); + osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_DISCONNECT, NULL); + return -1; + } /* Store 'identity' of server in srvc->peer_comp_id */ rspro_comp_id_retrieve(&srvc->peer_comp_id, &pdu->msg.choice.connectClientRes.identity); osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_CLIENT_CONN_RES, (void *) pdu);