gbproxy: Add config option to name an SGSN
This is useful for logging and configuration to identify an SGSN by name Change-Id: I2a3410dd9bebb242957e13a63ed70e447204203c Related: SYS#5115, OS#4472
This commit is contained in:
parent
51730f7a8c
commit
dee0bcc8e9
|
@ -9,6 +9,7 @@ gbproxy
|
||||||
nri bitlen 4
|
nri bitlen 4
|
||||||
nri null add 0 4
|
nri null add 0 4
|
||||||
sgsn nsei 101
|
sgsn nsei 101
|
||||||
|
name main
|
||||||
nri add 1
|
nri add 1
|
||||||
nri add 11
|
nri add 11
|
||||||
sgsn nsei 102
|
sgsn nsei 102
|
||||||
|
|
|
@ -7,6 +7,7 @@ line vty
|
||||||
!
|
!
|
||||||
gbproxy
|
gbproxy
|
||||||
sgsn nsei 101
|
sgsn nsei 101
|
||||||
|
name main
|
||||||
ns
|
ns
|
||||||
bind udp local
|
bind udp local
|
||||||
listen 127.0.0.100 23000
|
listen 127.0.0.100 23000
|
||||||
|
|
|
@ -149,6 +149,9 @@ struct gbproxy_sgsn {
|
||||||
/* The NSE belonging to this SGSN */
|
/* The NSE belonging to this SGSN */
|
||||||
struct gbproxy_nse *nse;
|
struct gbproxy_nse *nse;
|
||||||
|
|
||||||
|
/* Name of the SGSN */
|
||||||
|
char *name;
|
||||||
|
|
||||||
/* Pool configuration for the sgsn (only valid if sgsn_facing == true) */
|
/* Pool configuration for the sgsn (only valid if sgsn_facing == true) */
|
||||||
struct {
|
struct {
|
||||||
bool allow_attach;
|
bool allow_attach;
|
||||||
|
@ -176,7 +179,7 @@ struct gbproxy_sgsn {
|
||||||
LOGPCELL_CAT(CELL, DGPRS, LEVEL, FMT, ## ARGS)
|
LOGPCELL_CAT(CELL, DGPRS, LEVEL, FMT, ## ARGS)
|
||||||
|
|
||||||
#define LOGPSGSN_CAT(SGSN, SUBSYS, LEVEL, FMT, ARGS...) \
|
#define LOGPSGSN_CAT(SGSN, SUBSYS, LEVEL, FMT, ARGS...) \
|
||||||
LOGP(SUBSYS, LEVEL, "NSE(%05u)-SGSN " FMT, (SGSN)->nse->nsei, ## ARGS)
|
LOGP(SUBSYS, LEVEL, "NSE(%05u)-SGSN(%s) " FMT, (SGSN)->nse->nsei, (SGSN)->name, ## ARGS)
|
||||||
#define LOGPSGSN(SGSN, LEVEL, FMT, ARGS...) \
|
#define LOGPSGSN(SGSN, LEVEL, FMT, ARGS...) \
|
||||||
LOGPSGSN_CAT(SGSN, DGPRS, LEVEL, FMT, ## ARGS)
|
LOGPSGSN_CAT(SGSN, DGPRS, LEVEL, FMT, ## ARGS)
|
||||||
|
|
||||||
|
@ -224,8 +227,9 @@ struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nse
|
||||||
struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei, bool sgsn_facing);
|
struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei, bool sgsn_facing);
|
||||||
|
|
||||||
/* SGSN handling */
|
/* SGSN handling */
|
||||||
struct gbproxy_sgsn *gbproxy_sgsn_alloc(struct gbproxy_config *cfg, uint16_t nsei);
|
struct gbproxy_sgsn *gbproxy_sgsn_alloc(struct gbproxy_config *cfg, uint16_t nsei, const char *name);
|
||||||
void gbproxy_sgsn_free(struct gbproxy_sgsn *sgsn);
|
void gbproxy_sgsn_free(struct gbproxy_sgsn *sgsn);
|
||||||
|
struct gbproxy_sgsn *gbproxy_sgsn_by_name(struct gbproxy_config *cfg, const char *name);
|
||||||
struct gbproxy_sgsn *gbproxy_sgsn_by_nsei(struct gbproxy_config *cfg, uint16_t nsei);
|
struct gbproxy_sgsn *gbproxy_sgsn_by_nsei(struct gbproxy_config *cfg, uint16_t nsei);
|
||||||
struct gbproxy_sgsn *gbproxy_sgsn_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei);
|
struct gbproxy_sgsn *gbproxy_sgsn_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei);
|
||||||
struct gbproxy_sgsn *gbproxy_sgsn_by_nri(struct gbproxy_config *cfg, uint16_t nri, bool *null_nri);
|
struct gbproxy_sgsn *gbproxy_sgsn_by_nri(struct gbproxy_config *cfg, uint16_t nri, bool *null_nri);
|
||||||
|
|
|
@ -302,7 +302,7 @@ static struct gbproxy_bvc *gbproxy_select_sgsn_bvc(struct gbproxy_config *cfg, s
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This shouldn't happen */
|
/* This shouldn't happen */
|
||||||
LOGPCELL(cell, LOGL_ERROR, "Could not find matching BVC for SGSN, dropping message!\n");
|
LOGPCELL(cell, LOGL_ERROR, "Could not find matching BVC for SGSN %s, dropping message!\n", sgsn->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -350,9 +350,10 @@ struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint1
|
||||||
/*! Allocate a new SGSN. This ensures the corresponding gbproxy_nse is allocated as well
|
/*! Allocate a new SGSN. This ensures the corresponding gbproxy_nse is allocated as well
|
||||||
* \param[in] cfg The gbproxy configuration
|
* \param[in] cfg The gbproxy configuration
|
||||||
* \param[in] nsei The nsei where the SGSN can be reached
|
* \param[in] nsei The nsei where the SGSN can be reached
|
||||||
|
* \param[in] name A name to give the SGSN
|
||||||
* \return The SGSN, NULL if it couldn't be allocated
|
* \return The SGSN, NULL if it couldn't be allocated
|
||||||
*/
|
*/
|
||||||
struct gbproxy_sgsn *gbproxy_sgsn_alloc(struct gbproxy_config *cfg, uint16_t nsei)
|
struct gbproxy_sgsn *gbproxy_sgsn_alloc(struct gbproxy_config *cfg, uint16_t nsei, const char *name)
|
||||||
{
|
{
|
||||||
struct gbproxy_sgsn *sgsn;
|
struct gbproxy_sgsn *sgsn;
|
||||||
OSMO_ASSERT(cfg);
|
OSMO_ASSERT(cfg);
|
||||||
|
@ -364,16 +365,26 @@ struct gbproxy_sgsn *gbproxy_sgsn_alloc(struct gbproxy_config *cfg, uint16_t nse
|
||||||
sgsn->nse = gbproxy_nse_alloc(cfg, nsei, true);
|
sgsn->nse = gbproxy_nse_alloc(cfg, nsei, true);
|
||||||
if (!sgsn->nse) {
|
if (!sgsn->nse) {
|
||||||
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "Could not allocate NSE(%05u) for SGSN\n", nsei);
|
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "Could not allocate NSE(%05u) for SGSN\n", nsei);
|
||||||
talloc_free(sgsn);
|
goto free_sgsn;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
sgsn->name = talloc_strdup(sgsn, name);
|
||||||
|
else
|
||||||
|
sgsn->name = talloc_asprintf(sgsn, "NSE(%05u)", sgsn->nse->nsei);
|
||||||
|
if (!sgsn->name)
|
||||||
|
goto free_sgsn;
|
||||||
|
|
||||||
sgsn->pool.allow_attach = true;
|
sgsn->pool.allow_attach = true;
|
||||||
sgsn->pool.nri_ranges = osmo_nri_ranges_alloc(sgsn);
|
sgsn->pool.nri_ranges = osmo_nri_ranges_alloc(sgsn);
|
||||||
|
|
||||||
llist_add_tail(&sgsn->list, &cfg->sgsns);
|
llist_add_tail(&sgsn->list, &cfg->sgsns);
|
||||||
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "SGSN Created\n");
|
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "SGSN Created\n");
|
||||||
return sgsn;
|
return sgsn;
|
||||||
|
|
||||||
|
free_sgsn:
|
||||||
|
talloc_free(sgsn);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only free gbproxy_sgsn, sgsn can't be NULL */
|
/* Only free gbproxy_sgsn, sgsn can't be NULL */
|
||||||
|
@ -386,6 +397,7 @@ static void _sgsn_free(struct gbproxy_sgsn *sgsn) {
|
||||||
|
|
||||||
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "SGSN Destroying\n");
|
LOGPSGSN_CAT(sgsn, DOBJ, LOGL_INFO, "SGSN Destroying\n");
|
||||||
llist_del(&sgsn->list);
|
llist_del(&sgsn->list);
|
||||||
|
// talloc will free ->name and ->pool.nri_ranges
|
||||||
talloc_free(sgsn);
|
talloc_free(sgsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,6 +415,24 @@ void gbproxy_sgsn_free(struct gbproxy_sgsn *sgsn)
|
||||||
_sgsn_free(sgsn);
|
_sgsn_free(sgsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Return the SGSN for a given NSEI
|
||||||
|
* \param[in] cfg The gbproxy configuration
|
||||||
|
* \param[in] nsei The nsei where the SGSN can be reached
|
||||||
|
* \return Returns the matching SGSN or NULL if it couldn't be found
|
||||||
|
*/
|
||||||
|
struct gbproxy_sgsn *gbproxy_sgsn_by_name(struct gbproxy_config *cfg, const char *name)
|
||||||
|
{
|
||||||
|
struct gbproxy_sgsn *sgsn;
|
||||||
|
OSMO_ASSERT(cfg);
|
||||||
|
|
||||||
|
llist_for_each_entry(sgsn, &cfg->sgsns, list) {
|
||||||
|
if (!strcmp(sgsn->name, name))
|
||||||
|
return sgsn;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Return the SGSN for a given NSEI
|
/*! Return the SGSN for a given NSEI
|
||||||
* \param[in] cfg The gbproxy configuration
|
* \param[in] cfg The gbproxy configuration
|
||||||
* \param[in] nsei The nsei where the SGSN can be reached
|
* \param[in] nsei The nsei where the SGSN can be reached
|
||||||
|
@ -433,7 +463,7 @@ struct gbproxy_sgsn *gbproxy_sgsn_by_nsei_or_new(struct gbproxy_config *cfg, uin
|
||||||
|
|
||||||
sgsn = gbproxy_sgsn_by_nsei(cfg, nsei);
|
sgsn = gbproxy_sgsn_by_nsei(cfg, nsei);
|
||||||
if (!sgsn)
|
if (!sgsn)
|
||||||
sgsn = gbproxy_sgsn_alloc(cfg, nsei);
|
sgsn = gbproxy_sgsn_alloc(cfg, nsei, NULL);
|
||||||
|
|
||||||
return sgsn;
|
return sgsn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <osmocom/core/talloc.h>
|
#include <osmocom/core/talloc.h>
|
||||||
#include <osmocom/core/timer.h>
|
#include <osmocom/core/timer.h>
|
||||||
#include <osmocom/core/rate_ctr.h>
|
#include <osmocom/core/rate_ctr.h>
|
||||||
|
#include <osmocom/core/utils.h>
|
||||||
|
|
||||||
#include <osmocom/gprs/gprs_ns2.h>
|
#include <osmocom/gprs/gprs_ns2.h>
|
||||||
#include <osmocom/gprs/bssgp_bvc_fsm.h>
|
#include <osmocom/gprs/bssgp_bvc_fsm.h>
|
||||||
|
@ -188,6 +189,7 @@ static void sgsn_write_nri(struct vty *vty, struct gbproxy_sgsn *sgsn, bool verb
|
||||||
static void write_sgsn(struct vty *vty, struct gbproxy_sgsn *sgsn)
|
static void write_sgsn(struct vty *vty, struct gbproxy_sgsn *sgsn)
|
||||||
{
|
{
|
||||||
vty_out(vty, "sgsn nsei %u%s", sgsn->nse->nsei, VTY_NEWLINE);
|
vty_out(vty, "sgsn nsei %u%s", sgsn->nse->nsei, VTY_NEWLINE);
|
||||||
|
vty_out(vty, " name %s%s", sgsn->name, VTY_NEWLINE);
|
||||||
vty_out(vty, " %sallow-attach%s", sgsn->pool.allow_attach ? "" : "no ", VTY_NEWLINE);
|
vty_out(vty, " %sallow-attach%s", sgsn->pool.allow_attach ? "" : "no ", VTY_NEWLINE);
|
||||||
sgsn_write_nri(vty, sgsn, false);
|
sgsn_write_nri(vty, sgsn, false);
|
||||||
}
|
}
|
||||||
|
@ -256,6 +258,26 @@ free_nothing:
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFUN(cfg_sgsn_name,
|
||||||
|
cfg_sgsn_name_cmd,
|
||||||
|
"name NAME",
|
||||||
|
"Configure the SGSN\n"
|
||||||
|
"Name the SGSN\n"
|
||||||
|
"The name\n")
|
||||||
|
{
|
||||||
|
struct gbproxy_sgsn *sgsn = vty->index;
|
||||||
|
const char *name = argv[0];
|
||||||
|
|
||||||
|
|
||||||
|
osmo_talloc_replace_string(sgsn, &sgsn->name, name);
|
||||||
|
if (!sgsn->name) {
|
||||||
|
vty_out(vty, "%% Unable to set name for SGSN with nsei %05u%s", sgsn->nse->nsei, VTY_NEWLINE);
|
||||||
|
return CMD_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
DEFUN_ATTR(cfg_sgsn_nri_add, cfg_sgsn_nri_add_cmd,
|
DEFUN_ATTR(cfg_sgsn_nri_add, cfg_sgsn_nri_add_cmd,
|
||||||
"nri add <0-32767> [<0-32767>]",
|
"nri add <0-32767> [<0-32767>]",
|
||||||
NRI_STR "Add NRI value or range to the NRI mapping for this MSC\n"
|
NRI_STR "Add NRI value or range to the NRI mapping for this MSC\n"
|
||||||
|
@ -647,6 +669,7 @@ int gbproxy_vty_init(void)
|
||||||
|
|
||||||
install_element(CONFIG_NODE, &cfg_sgsn_nsei_cmd);
|
install_element(CONFIG_NODE, &cfg_sgsn_nsei_cmd);
|
||||||
install_node(&sgsn_node, config_write_sgsn);
|
install_node(&sgsn_node, config_write_sgsn);
|
||||||
|
install_element(SGSN_NODE, &cfg_sgsn_name_cmd);
|
||||||
install_element(SGSN_NODE, &cfg_sgsn_allow_attach_cmd);
|
install_element(SGSN_NODE, &cfg_sgsn_allow_attach_cmd);
|
||||||
install_element(SGSN_NODE, &cfg_sgsn_no_allow_attach_cmd);
|
install_element(SGSN_NODE, &cfg_sgsn_no_allow_attach_cmd);
|
||||||
install_element(SGSN_NODE, &cfg_sgsn_nri_add_cmd);
|
install_element(SGSN_NODE, &cfg_sgsn_nri_add_cmd);
|
||||||
|
|
Loading…
Reference in New Issue