[gprs] fully integrate VTY configuration into Gb proxy
The Gb-proxy is now fully configured by config file / VTY
diff --git a/openbsc/src/gb_proxy_main.c b/openbsc/src/gb_proxy_main.c
index 1793757..8f03060 100644
--- a/openbsc/src/gb_proxy_main.c
+++ b/openbsc/src/gb_proxy_main.c
@@ -41,6 +41,7 @@
#include <openbsc/gprs_ns.h>
#include <openbsc/telnet_interface.h>
#include <openbsc/vty.h>
+#include <openbsc/gb_proxy.h>
#include "../bscconfig.h"
@@ -53,7 +54,6 @@
void *tall_bsc_ctx;
struct gprs_ns_inst *gbprox_nsi;
-static u_int16_t nsip_listen_port = 23000;
const char *openbsc_version = "Osmocom NSIP Proxy " PACKAGE_VERSION;
const char *openbsc_copyright =
@@ -64,7 +64,8 @@
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n";
-static char *config_file = "nsip_proxy.cfg";
+static char *config_file = "gb_proxy.cfg";
+static struct gbproxy_config gbcfg;
/* Pointer to the SGSN peer */
extern struct gbprox_peer *gbprox_peer_sgsn;
@@ -105,19 +106,27 @@
log_set_all_filter(stderr_target, 1);
telnet_init(&dummy_network, 4244);
+ rc = gbproxy_parse_config(config_file, &gbcfg);
+ if (rc < 0) {
+ LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n");
+ exit(2);
+ }
gbprox_nsi = gprs_ns_instantiate(&proxy_ns_cb);
if (!gbprox_nsi) {
LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
exit(1);
}
- nsip_listen(gbprox_nsi, nsip_listen_port);
+ gbcfg.nsi = gbprox_nsi;
+ nsip_listen(gbprox_nsi, gbcfg.nsip_listen_port);
/* 'establish' the outgoing connection to the SGSN */
sin.sin_family = AF_INET;
- sin.sin_port = ntohs(23000);
- inet_aton("192.168.100.239", &sin.sin_addr);
- gbprox_peer_sgsn = nsip_connect(gbprox_nsi, &sin, 2342);
+ sin.sin_port = htons(gbcfg.nsip_sgsn_port);
+ sin.sin_addr.s_addr = htonl(gbcfg.nsip_sgsn_ip);
+ gbprox_peer_sgsn = nsip_connect(gbprox_nsi, &sin,
+ gbcfg.nsip_sgsn_nsei,
+ gbcfg.nsip_sgsn_nsvci);
while (1) {
rc = bsc_select_main(0);
diff --git a/openbsc/src/gb_proxy_vty.c b/openbsc/src/gb_proxy_vty.c
index ae6be5e..16f6a1e 100644
--- a/openbsc/src/gb_proxy_vty.c
+++ b/openbsc/src/gb_proxy_vty.c
@@ -27,27 +27,18 @@
#include <osmocore/talloc.h>
#include <openbsc/debug.h>
+#include <openbsc/gb_proxy.h>
+#include <openbsc/gprs_ns.h>
#include <vty/command.h>
#include <vty/vty.h>
-struct gbproxy_config {
- u_int32_t nsip_listen_ip;
- u_int16_t nsip_listen_port;
-
- u_int32_t nsip_sgsn_ip;
- u_int16_t nsip_sgsn_port;
-
- u_int16_t nsip_sgsn_nsei;
- u_int16_t nsip_sgsn_nsvci;
-};
-
static struct gbproxy_config *g_cfg = NULL;
/*
* vty code for mgcp below
*/
-struct cmd_node gbproxy_node = {
+static struct cmd_node gbproxy_node = {
GBPROXY_NODE,
"%s(gbproxy)#",
1,
@@ -83,6 +74,21 @@
SHOW_STR "Display information about the Gb proxy")
{
/* FIXME: iterate over list of NS-VC's and display their state */
+ struct gprs_ns_inst *nsi = g_cfg->nsi;
+ struct gprs_nsvc *nsvc;
+
+ llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
+ vty_out(vty, "NSEI %5u, NS-VC %5u, %s-mode, %s %s%s",
+ nsvc->nsei, nsvc->nsvci,
+ nsvc->remote_end_is_sgsn ? "BSS" : "SGSN",
+ nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
+ nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
+ VTY_NEWLINE);
+ if (nsvc->nsi->ll == GPRS_NS_LL_UDP)
+ vty_out(vty, " remote peer %s:%u%s",
+ inet_ntoa(nsvc->ip.bts_addr.sin_addr),
+ ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE);
+ }
return CMD_SUCCESS;
}
diff --git a/openbsc/src/gprs_ns.c b/openbsc/src/gprs_ns.c
index 3bb0bf9..18d189f 100644
--- a/openbsc/src/gprs_ns.c
+++ b/openbsc/src/gprs_ns.c
@@ -72,30 +72,6 @@
},
};
-enum gprs_ns_ll {
- GPRS_NS_LL_UDP,
- GPRS_NS_LL_E1,
-};
-
-/* An instance of the NS protocol stack */
-struct gprs_ns_inst {
- /* callback to the user for incoming UNIT DATA IND */
- gprs_ns_cb_t *cb;
-
- /* linked lists of all NSVC in this instance */
- struct llist_head gprs_nsvcs;
-
- /* which link-layer are we based on? */
- enum gprs_ns_ll ll;
-
- union {
- /* NS-over-IP specific bits */
- struct {
- struct bsc_fd fd;
- } nsip;
- };
-};
-
/* Lookup struct gprs_nsvc based on NSVCI */
static struct gprs_nsvc *nsvc_by_nsvci(struct gprs_ns_inst *nsi,
u_int16_t nsvci)
@@ -565,7 +541,8 @@
/* Establish a connection (from the BSS) to the SGSN */
struct gprs_nsvc *nsip_connect(struct gprs_ns_inst *nsi,
- struct sockaddr_in *dest, uint16_t nsvci)
+ struct sockaddr_in *dest, uint16_t nsei,
+ uint16_t nsvci)
{
struct gprs_nsvc *nsvc;
@@ -574,6 +551,8 @@
nsvc = nsvc_create(nsi, nsvci);
nsvc->ip.bts_addr = *dest;
}
+ nsvc->nsei = nsei;
+ nsvc->nsvci = nsvci;
nsvc->remote_end_is_sgsn = 1;
/* Initiate a RESET procedure */