diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2019-05-25 05:41:18 +0200 |
---|---|---|
committer | Alexander Couzens <lynxis@fe80.eu> | 2019-06-07 01:17:53 +0200 |
commit | 5c3783b7e83b586d72304d798b195bffa1a53ba2 (patch) | |
tree | 369326edd4143ea94095141e2e90ee56d010407f /src | |
parent | a558ad426951f6f536c4bc7bef302afbd3573ce6 (diff) |
gprs_bssgp_pcu: explicit allocate & initialize bssgp_nsi instance
The instance bssgp_nsi is a global instance to be used by all
NS related functions. Previous the PCU allocated and initialized
the bssgp_nsi instance when (re-)connecting and freeing on disconnect.
The problem of the implicit initialisation is gprs_ns_vty_init(bssgp_nsi).
All vty init functions must be called before the configuration is read,
otherwise a previous vty written configuration is invalid.
Furthermore the vty modifications to the `ns` object were lost when the PCU has to
reconnect to the SGSN.
Fixes: OS#4024
Change-Id: I2aa53ea54e9352577f6280ad7b9d1d9da9f57eaf
Diffstat (limited to 'src')
-rw-r--r-- | src/gprs_bssgp_pcu.cpp | 20 | ||||
-rw-r--r-- | src/pcu_main.cpp | 9 |
2 files changed, 12 insertions, 17 deletions
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp index 50f10db9..22abc6bd 100644 --- a/src/gprs_bssgp_pcu.cpp +++ b/src/gprs_bssgp_pcu.cpp @@ -875,11 +875,6 @@ static int gprs_ns_reconnect(struct gprs_nsvc *nsvc) { struct gprs_nsvc *nsvc2; - if (!bssgp_nsi) { - LOGP(DBSSGP, LOGL_ERROR, "NS instance does not exist\n"); - return -EINVAL; - } - if (nsvc != the_pcu.nsvc) { LOGP(DBSSGP, LOGL_ERROR, "NSVC is invalid\n"); return -EBADF; @@ -913,12 +908,6 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts the_pcu.bts = bts; - bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); - if (!bssgp_nsi) { - LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); - return NULL; - } - gprs_ns_vty_init(bssgp_nsi); /* don't specify remote IP/port if SNS dialect is in use; Doing so would * issue a connect() on the socket, which prevents us to dynamically communicate * with any number of IP-SNS endpoints on the SGSN side */ @@ -930,8 +919,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts rc = gprs_ns_nsip_listen(bssgp_nsi); if (rc < 0) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n"); - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } @@ -945,8 +933,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts the_pcu.nsvc = gprs_ns_nsip_connect(bssgp_nsi, &dest, nsei, nsvci); if (!the_pcu.nsvc) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n"); - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } @@ -954,8 +941,7 @@ struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts if (!the_pcu.bctx) { LOGP(DBSSGP, LOGL_ERROR, "Failed to create BSSGP context\n"); the_pcu.nsvc = NULL; - gprs_ns_destroy(bssgp_nsi); - bssgp_nsi = NULL; + gprs_ns_close(bssgp_nsi); return NULL; } the_pcu.bctx->ra_id.mcc = spoof_mcc ? : mcc; diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp index 1003e3c4..fa075cdf 100644 --- a/src/pcu_main.cpp +++ b/src/pcu_main.cpp @@ -33,6 +33,8 @@ #include <bts.h> #include <gprs_coding_scheme.h> #include <osmocom/pcu/pcuif_proto.h> +#include "gprs_bssgp_pcu.h" + extern "C" { #include "pcu_vty.h" #include <osmocom/gprs/gprs_bssgp.h> @@ -291,6 +293,13 @@ int main(int argc, char *argv[]) else fprintf(stderr, "Failed to initialize GSMTAP for %s\n", gsmtap_addr); + bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); + if (!bssgp_nsi) { + LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); + exit(1); + } + gprs_ns_vty_init(bssgp_nsi); + rc = vty_read_config_file(config_file, NULL); if (rc < 0 && config_given) { fprintf(stderr, "Failed to parse the config file: '%s'\n", |