From f23e2db752ee7213519144202120cac36493b579 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Mon, 27 Jul 2020 22:39:58 +0200 Subject: sgsn: Use the new NS2 api The new NS2 api supports NSE with multiple NS-VC and contains a NS-VC fsm. FR/GRE support is not working. The configuration is compatible except for FR/GRE. Relates: OS#4629 Depends-on: Iaad7b53d44338e5dd81dc2202f23bdcb715af804 (libosmocore) Depends-on: I6cef42749555e577d5573f2ed8b8bce4cf842a98 (libosmocore) Change-Id: I92a3bcaf166b091a22d74c7c1586964d33d7cc9d --- src/sgsn/sgsn_main.c | 70 ++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 54 deletions(-) (limited to 'src/sgsn/sgsn_main.c') diff --git a/src/sgsn/sgsn_main.c b/src/sgsn/sgsn_main.c index 0277f6f04..19039f694 100644 --- a/src/sgsn/sgsn_main.c +++ b/src/sgsn/sgsn_main.c @@ -39,8 +39,9 @@ #include #include #include +#include -#include +#include #include #include @@ -60,6 +61,7 @@ #include #include #include +#include #include #include @@ -80,7 +82,7 @@ void *tall_sgsn_ctx; struct ctrl_handle *g_ctrlh; -struct gprs_ns_inst *sgsn_nsi; +struct gprs_ns2_inst *sgsn_nsi; static int daemonize = 0; const char *openbsc_copyright = "Copyright (C) 2010 Harald Welte and On-Waves\r\n" @@ -94,27 +96,6 @@ const char *openbsc_copyright = struct sgsn_instance *sgsn; -/* call-back function for the NS protocol */ -static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, - struct msgb *msg, uint16_t bvci) -{ - int rc = 0; - - switch (event) { - case GPRS_NS_EVT_UNIT_DATA: - /* hand the message into the BSSGP implementation */ - rc = bssgp_rcvmsg(msg); - break; - default: - LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event); - if (msg) - msgb_free(msg); - rc = -EIO; - break; - } - return rc; -} - /* call-back function for the BSSGP protocol */ int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) { @@ -181,23 +162,6 @@ static void signal_handler(int signum) /* NSI that BSSGP uses when transmitting on NS */ extern struct gprs_ns_inst *bssgp_nsi; -static void bvc_reset_persistent_nsvcs(void) -{ - /* Send BVC-RESET on all persistent NSVCs */ - struct gprs_nsvc *nsvc; - - llist_for_each_entry(nsvc, &sgsn_nsi->gprs_nsvcs, list) { - struct bssgp_bvc_ctx bctx = { - .nsei = nsvc->nsei, - }; - if (!nsvc->persistent) - continue; - /* if it is not marked ALIVE, we cannot send any data over it. */ - nsvc->state |= NSE_S_ALIVE; - bssgp_tx_bvc_reset2(&bctx, BVCI_SIGNALLING, BSSGP_CAUSE_EQUIP_FAIL, false); - } -} - static struct vty_app_info vty_info = { .name = "OsmoSGSN", .version = PACKAGE_VERSION, @@ -364,6 +328,11 @@ static bool file_exists(const char *path) int main(int argc, char **argv) { int rc; + struct osmo_sockaddr_str bind_address = { + .af = AF_INET, + .ip = "0.0.0.0", + .port = 23000, + }; #if BUILD_IU struct osmo_sccp_instance *sccp; #endif @@ -418,27 +387,27 @@ int main(int argc, char **argv) rate_ctr_init(tall_sgsn_ctx); - gprs_ns_set_log_ss(DNS); logging_vty_add_deprecated_subsys(tall_sgsn_ctx, "bssgp"); - sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_sgsn_ctx); + sgsn_nsi = gprs_ns2_instantiate(tall_sgsn_ctx, &gprs_ns_prim_cb, NULL); if (!sgsn_nsi) { LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); exit(1); } - bssgp_nsi = sgsn->cfg.nsi = sgsn_nsi; + sgsn->cfg.nsi = sgsn_nsi; + bssgp_set_bssgp_callback(gprs_gb_send_cb, sgsn_nsi); gprs_llc_init("/usr/local/lib/osmocom/crypt/"); sgsn_rate_ctr_init(); sgsn_inst_init(sgsn); - gprs_ns_vty_init(bssgp_nsi); + + gprs_ns2_vty_init(sgsn_nsi, &bind_address); bssgp_vty_init(); gprs_llc_vty_init(); gprs_sndcp_vty_init(); sgsn_auth_init(sgsn); sgsn_cdr_init(sgsn); - /* FIXME: register signal handler for SS_L_NS */ rc = sgsn_parse_config(sgsn->config_file); if (rc < 0) { @@ -480,18 +449,13 @@ int main(int argc, char **argv) exit(2); } - rc = gprs_ns_nsip_listen(sgsn_nsi); + rc = gprs_ns2_vty_create(); if (rc < 0) { LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); exit(2); } - rc = gprs_ns_frgre_listen(sgsn_nsi); - if (rc < 0) { - LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " - "socket. Do you have CAP_NET_RAW?\n"); - exit(2); - } + gprs_ns2_dynamic_create_nse(sgsn_nsi, true); if (sgsn->cfg.dynamic_lookup) { if (sgsn_ares_init(sgsn) != 0) { @@ -518,8 +482,6 @@ int main(int argc, char **argv) ranap_iu_init(tall_sgsn_ctx, DRANAP, "OsmoSGSN-IuPS", sccp, gsm0408_gprs_rcvmsg_iu, sgsn_ranap_iu_event); #endif - bvc_reset_persistent_nsvcs(); - if (daemonize) { rc = osmo_daemonize(); if (rc < 0) { -- cgit v1.2.3