aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-30 21:33:02 +0100
committerHarald Welte <laforge@osmocom.org>2021-01-31 12:34:36 +0100
commit3d5eaee7262a738001e0c67f9e2a6274293eb2c7 (patch)
treee2f3e38be858530cbfd70bd2831b6b2633f8f91c /src
parentd06128d17d61eb3e9812e10a09d4e97352de6b72 (diff)
ns2: Use named array initializers to avoid mistakes
It's always a bad idea to have an array of descriptions that's indexed by an enum, without using named initializers. It's too easy to get inconsistencies. Change-Id: Id0ebd2a202a465ca0298f4245f1fb5c495235fc8
Diffstat (limited to 'src')
-rw-r--r--src/gb/gprs_ns2.c26
-rw-r--r--src/gb/gprs_ns2_internal.h14
-rw-r--r--src/gb/gprs_ns2_message.c17
3 files changed, 27 insertions, 30 deletions
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index be355134..6be16a22 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -160,18 +160,18 @@ const struct value_string gprs_ns2_cause_strs[] = {
};
static const struct rate_ctr_desc nsvc_ctr_description[] = {
- { "packets:in", "Packets at NS Level ( In)" },
- { "packets:out","Packets at NS Level (Out)" },
- { "bytes:in", "Bytes at NS Level ( In)" },
- { "bytes:out", "Bytes at NS Level (Out)" },
- { "blocked", "NS-VC Block count " },
- { "dead", "NS-VC gone dead count " },
- { "replaced", "NS-VC replaced other count" },
- { "nsei-chg", "NS-VC changed NSEI count " },
- { "inv-nsvci", "NS-VCI was invalid count " },
- { "inv-nsei", "NSEI was invalid count " },
- { "lost:alive", "ALIVE ACK missing count " },
- { "lost:reset", "RESET ACK missing count " },
+ [NS_CTR_PKTS_IN] = { "packets:in", "Packets at NS Level ( In)" },
+ [NS_CTR_PKTS_OUT] = { "packets:out", "Packets at NS Level (Out)" },
+ [NS_CTR_BYTES_IN] = { "bytes:in", "Bytes at NS Level ( In)" },
+ [NS_CTR_BYTES_OUT] = { "bytes:out", "Bytes at NS Level (Out)" },
+ [NS_CTR_BLOCKED] = { "blocked", "NS-VC Block count " },
+ [NS_CTR_DEAD] = { "dead", "NS-VC gone dead count " },
+ [NS_CTR_REPLACED] = { "replaced", "NS-VC replaced other count" },
+ [NS_CTR_NSEI_CHG] = { "nsei-chg", "NS-VC changed NSEI count " },
+ [NS_CTR_INV_VCI] = { "inv-nsvci", "NS-VCI was invalid count " },
+ [NS_CTR_INV_NSEI] = { "inv-nsei", "NSEI was invalid count " },
+ [NS_CTR_LOST_ALIVE] = { "lost:alive", "ALIVE ACK missing count " },
+ [NS_CTR_LOST_RESET] = { "lost:reset", "RESET ACK missing count " },
};
static const struct rate_ctr_group_desc nsvc_ctrg_desc = {
@@ -184,7 +184,7 @@ static const struct rate_ctr_group_desc nsvc_ctrg_desc = {
static const struct osmo_stat_item_desc nsvc_stat_description[] = {
- { "alive.delay", "ALIVE response time ", "ms", 16, 0 },
+ [NS_STAT_ALIVE_DELAY] = { "alive.delay", "ALIVE response time ", "ms", 16, 0 },
};
static const struct osmo_stat_item_group_desc nsvc_statg_desc = {
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index 0574cb2b..68f28dba 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -85,6 +85,20 @@ enum ns2_cs {
NS2_CS_ERROR, /*!< Failed to process message */
};
+enum ns_ctr {
+ NS_CTR_PKTS_IN,
+ NS_CTR_PKTS_OUT,
+ NS_CTR_BYTES_IN,
+ NS_CTR_BYTES_OUT,
+ NS_CTR_BLOCKED,
+ NS_CTR_DEAD,
+ NS_CTR_REPLACED,
+ NS_CTR_NSEI_CHG,
+ NS_CTR_INV_VCI,
+ NS_CTR_INV_NSEI,
+ NS_CTR_LOST_ALIVE,
+ NS_CTR_LOST_RESET,
+};
#define NSE_S_BLOCKED 0x0001
#define NSE_S_ALIVE 0x0002
diff --git a/src/gb/gprs_ns2_message.c b/src/gb/gprs_ns2_message.c
index c525dd7a..67ee254c 100644
--- a/src/gb/gprs_ns2_message.c
+++ b/src/gb/gprs_ns2_message.c
@@ -46,23 +46,6 @@
LOGNSVC(nsvc, LOGL_DEBUG, "invalid packet %s with SNS\n", reason); \
} while (0)
-enum ns_ctr {
- NS_CTR_PKTS_IN,
- NS_CTR_PKTS_OUT,
- NS_CTR_BYTES_IN,
- NS_CTR_BYTES_OUT,
- NS_CTR_BLOCKED,
- NS_CTR_DEAD,
- NS_CTR_REPLACED,
- NS_CTR_NSEI_CHG,
- NS_CTR_INV_VCI,
- NS_CTR_INV_NSEI,
- NS_CTR_LOST_ALIVE,
- NS_CTR_LOST_RESET,
-};
-
-
-
static int ns2_validate_reset(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp, uint8_t *cause)
{
if (!TLVP_PRES_LEN(tp, NS_IE_CAUSE, 1) ||