From a43cea70cb08e89cd671f75c1882c59c4380c449 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 28 Jun 2018 13:22:50 +0200 Subject: filter: Allocate each ctr group with a different idx Fixes following runtime warning: libosmocore/src/rate_ctr.c:219 counter group 'nat:filter' already exists for index 0, instead using index 1. This is a software bug that needs fixing. Forward-port from openbsc.git c08d58802e03a45f95b8f7d28b29dc7026f664ba. Change-Id: I7c5054c374281bb1d4bd1ecd76ddcca7a010d50a --- src/libfilter/bsc_msg_acc.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/libfilter') diff --git a/src/libfilter/bsc_msg_acc.c b/src/libfilter/bsc_msg_acc.c index f0232eed7..46077b321 100644 --- a/src/libfilter/bsc_msg_acc.c +++ b/src/libfilter/bsc_msg_acc.c @@ -41,6 +41,21 @@ static const struct rate_ctr_group_desc bsc_cfg_acc_list_desc = { .class_id = OSMO_STATS_CLASS_GLOBAL, }; +/*! Find an unused index for this rate counter group. + * \param[in] head List of allocated ctr groups of the same type + * \returns the largest used index number + 1, or 0 if none exist yet. */ +static unsigned int rate_ctr_get_unused_idx(struct llist_head *head) +{ + unsigned int idx = 0; + struct bsc_msg_acc_lst *lst; + + llist_for_each_entry(lst, head, list) { + if (idx <= lst->stats->idx) + idx = lst->stats->idx + 1; + } + return idx; +} + int bsc_msg_acc_lst_check_allow(struct bsc_msg_acc_lst *lst, const char *mi_string) { @@ -73,6 +88,7 @@ struct bsc_msg_acc_lst *bsc_msg_acc_lst_find(struct llist_head *head, const char struct bsc_msg_acc_lst *bsc_msg_acc_lst_get(void *ctx, struct llist_head *head, const char *name) { struct bsc_msg_acc_lst *lst; + unsigned int new_idx; lst = bsc_msg_acc_lst_find(head, name); if (lst) @@ -84,8 +100,8 @@ struct bsc_msg_acc_lst *bsc_msg_acc_lst_get(void *ctx, struct llist_head *head, return NULL; } - /* TODO: get the index right */ - lst->stats = rate_ctr_group_alloc(lst, &bsc_cfg_acc_list_desc, 0); + new_idx = rate_ctr_get_unused_idx(head); + lst->stats = rate_ctr_group_alloc(lst, &bsc_cfg_acc_list_desc, new_idx); if (!lst->stats) { talloc_free(lst); return NULL; -- cgit v1.2.3