Change in osmo-bsc[master]: vty: add 'show rejected'

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Mon Oct 29 10:12:41 UTC 2018


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/11493


Change subject: vty: add 'show rejected'
......................................................................

vty: add 'show rejected'

Print IDs and IPs of recently rejected BTS devices. Example output:

OsmoBSC> show rejected
Date                Site ID BTS ID IP
------------------- ------- ------ ---------------
2018-10-25 09:36:28    1234      0    192.168.1.37

Related: OS#2841
Change-Id: Iba3bfe8fc9432b7ae8f819df8bd71b35b3ec507e
---
M include/osmocom/bsc/gsm_data.h
M src/osmo-bsc/bsc_init.c
M src/osmo-bsc/bsc_vty.c
M src/osmo-bsc/bts_ipaccess_nanobts.c
4 files changed, 95 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/93/11493/1

diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 7c91e59..d521708 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -1129,6 +1129,16 @@
 	uint8_t chan_load_avg; /* current channel load average in percent (0 - 100). */
 };
 
+/* One rejected BTS */
+struct gsm_bts_rejected {
+	/* list header in net->bts_rejected */
+	struct llist_head list;
+
+	uint16_t site_id;
+	uint16_t bts_id;
+	char ip[64];
+	time_t time;
+};
 
 struct gsm_network *gsm_network_init(void *ctx);
 
@@ -1404,6 +1414,7 @@
 
 	unsigned int num_bts;
 	struct llist_head bts_list;
+	struct llist_head bts_rejected;
 
 	/* shall reference gsm_network_T[] */
 	struct T_def *T_defs;
diff --git a/src/osmo-bsc/bsc_init.c b/src/osmo-bsc/bsc_init.c
index b1388b8..2f44b20 100644
--- a/src/osmo-bsc/bsc_init.c
+++ b/src/osmo-bsc/bsc_init.c
@@ -257,6 +257,7 @@
 		return NULL;
 	}
 
+	INIT_LLIST_HEAD(&net->bts_rejected);
 	gsm_net_update_ctype(net);
 
 	/*
diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c
index dd540c1..cead6fc 100644
--- a/src/osmo-bsc/bsc_vty.c
+++ b/src/osmo-bsc/bsc_vty.c
@@ -541,6 +541,32 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(show_rejected, show_rejected_cmd, "show rejected",
+	SHOW_STR "Display recently rejected BTS devices\n")
+{
+	/* empty list */
+	struct llist_head *rejected = &gsmnet_from_vty(vty)->bts_rejected;
+	if (llist_empty(rejected)) {
+		vty_out(vty, "No BTS has been rejected.%s", VTY_NEWLINE);
+		return CMD_SUCCESS;
+	}
+
+	/* table head */
+	vty_out(vty, "Date                Site ID BTS ID IP%s", VTY_NEWLINE);
+	vty_out(vty, "------------------- ------- ------ ---------------%s", VTY_NEWLINE);
+
+	/* table body */
+	struct gsm_bts_rejected *pos;
+	llist_for_each_entry(pos, rejected, list) {
+		/* timestamp formatted like: "2018-10-24 15:04:52" */
+		char buf[20];
+		strftime(buf, sizeof(buf), "%F %T", localtime(&pos->time));
+
+		vty_out(vty, "%s %7u %6u %15s%s", buf, pos->site_id, pos->bts_id, pos->ip, VTY_NEWLINE);
+	}
+	return CMD_SUCCESS;
+}
+
 /* utility functions */
 static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
 			  const char *ts, const char *ss)
@@ -4867,6 +4893,7 @@
 
 	install_element_ve(&bsc_show_net_cmd);
 	install_element_ve(&show_bts_cmd);
+	install_element_ve(&show_rejected_cmd);
 	install_element_ve(&show_trx_cmd);
 	install_element_ve(&show_ts_cmd);
 	install_element_ve(&show_lchan_cmd);
diff --git a/src/osmo-bsc/bts_ipaccess_nanobts.c b/src/osmo-bsc/bts_ipaccess_nanobts.c
index fec4147..bbfcb05 100644
--- a/src/osmo-bsc/bts_ipaccess_nanobts.c
+++ b/src/osmo-bsc/bts_ipaccess_nanobts.c
@@ -30,6 +30,7 @@
 #include <osmocom/abis/e1_input.h>
 #include <osmocom/gsm/tlv.h>
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/socket.h>
 #include <osmocom/core/talloc.h>
 #include <osmocom/bsc/gsm_data.h>
 #include <osmocom/bsc/abis_nm.h>
@@ -458,6 +459,60 @@
 	}
 }
 
+/* Reject BTS because of an unknown unit ID */
+static void ipaccess_sign_link_reject(const struct ipaccess_unit *dev, const struct e1inp_ts* ts)
+{
+	uint16_t site_id = dev->site_id;
+	uint16_t bts_id = dev->bts_id;
+	uint16_t trx_id = dev->trx_id;
+
+	/* Write to log and increase counter */
+	LOGP(DLINP, LOGL_ERROR, "Unable to find BTS configuration for %u/%u/%u, disconnecting\n", site_id, bts_id,
+		trx_id);
+	rate_ctr_inc(&bsc_gsmnet->bsc_ctrs->ctr[BSC_CTR_UNKNOWN_UNIT_ID]);
+
+	/* Get remote IP */
+	char ip[64];
+	if (osmo_sock_get_remote_ip(ts->driver.ipaccess.fd.fd, ip, sizeof(ip)))
+		return;
+
+	/* Rejected list: unlink existing entry */
+	struct gsm_bts_rejected *entry = NULL;
+	struct gsm_bts_rejected *pos;
+	llist_for_each_entry(pos, &bsc_gsmnet->bts_rejected, list) {
+		if (pos->site_id == site_id && pos->bts_id == bts_id && !strcmp(pos->ip, ip)) {
+			entry = pos;
+			llist_del(&entry->list);
+			break;
+		}
+	}
+
+	/* Allocate new entry */
+	if (!entry) {
+		entry = talloc_zero(tall_bsc_ctx, struct gsm_bts_rejected);
+		if (!entry)
+			return;
+		entry->site_id = site_id;
+		entry->bts_id = bts_id;
+		strncpy(entry->ip, ip, sizeof(entry->ip));
+	}
+
+	/* Add to beginning with current timestamp */
+	llist_add(&entry->list, &bsc_gsmnet->bts_rejected);
+	entry->time = time(NULL);
+
+	/* Cut off last (oldest) element if we have too many */
+	uint8_t i=0;
+	llist_for_each_entry(pos, &bsc_gsmnet->bts_rejected, list) {
+		if (i >= 25) {
+			llist_del(&pos->list);
+			talloc_free(pos);
+			break;
+		}
+		i++;
+	}
+}
+
 /* This function is called once the OML/RSL link becomes up. */
 static struct e1inp_sign_link *
 ipaccess_sign_link_up(void *unit_data, struct e1inp_line *line,
@@ -471,10 +526,7 @@
 
 	bts = find_bts_by_unitid(bsc_gsmnet, dev->site_id, dev->bts_id);
 	if (!bts) {
-		LOGP(DLINP, LOGL_ERROR, "Unable to find BTS configuration for "
-			" %u/%u/%u, disconnecting\n", dev->site_id,
-			dev->bts_id, dev->trx_id);
-		rate_ctr_inc(&bsc_gsmnet->bsc_ctrs->ctr[BSC_CTR_UNKNOWN_UNIT_ID]);
+		ipaccess_sign_link_reject(dev, &line->ts[E1INP_SIGN_OML - 1]);
 		return NULL;
 	}
 	DEBUGP(DLINP, "Identified BTS %u/%u/%u\n",

-- 
To view, visit https://gerrit.osmocom.org/11493
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba3bfe8fc9432b7ae8f819df8bd71b35b3ec507e
Gerrit-Change-Number: 11493
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181029/b723e71d/attachment.htm>


More information about the gerrit-log mailing list