hnbgw: Introduce LOGHNB() macro for log context information

So far we don't really have any way of matching a given log message
to a specific hNB.  Let's introduce a new log macro, together with
a configuration directive to select whether the hNB-ID or the
UMTS CellID shall be used.

Change-Id: I6113925216c6f88add2c6d27bdf47ccbb017f293
This commit is contained in:
Harald Welte 2020-12-30 13:36:20 +01:00
parent dc529f3d78
commit c6d93452b2
3 changed files with 42 additions and 0 deletions

View File

@ -18,6 +18,9 @@ enum {
DRANAP,
};
#define LOGHNB(x, ss, lvl, fmt, args ...) \
LOGP(ss, lvl, "%s " fmt, hnb_context_name(x), ## args)
enum hnb_ctrl_node {
CTRL_NODE_HNB = _LAST_CTRL_NODE,
_LAST_CTRL_NODE_HNB
@ -128,6 +131,8 @@ struct hnb_gw {
const char *iups_remote_addr_name;
uint16_t rnc_id;
bool hnbap_allow_tmsi;
/*! print hnb-id (true) or MCC-MNC-LAC-RAC-SAC (false) in logs */
bool log_prefix_hnb_id;
} config;
/*! SCTP listen socket for incoming connections */
struct osmo_stream_srv_link *iuh;
@ -152,6 +157,7 @@ extern void *talloc_asn1_ctx;
struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid);
struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info);
const char *hnb_context_name(struct hnb_context *ctx);
unsigned hnb_contexts(const struct hnb_gw *gw);
struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id);

View File

@ -83,6 +83,7 @@ static struct hnb_gw *hnb_gw_create(void *ctx)
/* strdup so we can easily talloc_free in the VTY code */
gw->config.iuh_local_ip = talloc_strdup(gw, HNBGW_LOCAL_IP_DEFAULT);
gw->config.iuh_local_port = IUH_DEFAULT_SCTP_PORT;
gw->config.log_prefix_hnb_id = true;
gw->next_ue_ctx_id = 23;
INIT_LLIST_HEAD(&gw->hnb_list);
@ -296,6 +297,25 @@ struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_
return ctx;
}
static const char *umts_cell_id_name(const struct umts_cell_id *ucid)
{
static __thread char buf[40];
snprintf(buf, sizeof(buf), "%u-%u-L%u-R%u-S%u", ucid->mcc, ucid->mnc, ucid->lac, ucid->rac, ucid->sac);
return buf;
}
const char *hnb_context_name(struct hnb_context *ctx)
{
if (!ctx)
return "NULL";
if (ctx->gw->config.log_prefix_hnb_id)
return ctx->identity_info;
else
return umts_cell_id_name(&ctx->id);
}
void hnb_context_release(struct hnb_context *ctx)
{
struct hnbgw_context_map *map, *map2;

View File

@ -296,6 +296,19 @@ DEFUN(cfg_hnbgw_iuh_hnbap_allow_tmsi, cfg_hnbgw_iuh_hnbap_allow_tmsi_cmd,
return CMD_SUCCESS;
}
DEFUN(cfg_hnbgw_log_prefix, cfg_hnbgw_log_prefix_cmd,
"log-prefix (hnb-id|umts-cell-id)",
"Configure the log message prefix\n"
"Use the hNB-ID as log message prefix\n"
"Use the UMTS Cell ID as log message prefix\n")
{
if (!strcmp(argv[0], "hnb-id"))
g_hnb_gw->config.log_prefix_hnb_id = true;
else
g_hnb_gw->config.log_prefix_hnb_id = false;
return CMD_SUCCESS;
}
DEFUN(cfg_hnbgw_iucs_remote_addr,
cfg_hnbgw_iucs_remote_addr_cmd,
"remote-addr NAME",
@ -319,6 +332,8 @@ DEFUN(cfg_hnbgw_iups_remote_addr,
static int config_write_hnbgw(struct vty *vty)
{
vty_out(vty, "hnbgw%s", VTY_NEWLINE);
vty_out(vty, " log-prefix %s%s", g_hnb_gw->config.log_prefix_hnb_id ? "hnb-id" : "umts-cell-id",
VTY_NEWLINE);
return CMD_SUCCESS;
}
@ -376,6 +391,7 @@ void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx)
install_node(&hnbgw_node, config_write_hnbgw);
install_element(HNBGW_NODE, &cfg_hnbgw_rnc_id_cmd);
install_element(HNBGW_NODE, &cfg_hnbgw_log_prefix_cmd);
install_element(HNBGW_NODE, &cfg_hnbgw_iuh_cmd);
install_node(&iuh_node, config_write_hnbgw_iuh);