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
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index be35513..6be16a2 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -160,18 +160,18 @@
};
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 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 0574cb2..68f28db 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -85,6 +85,20 @@
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 c525dd7..67ee254 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) ||