diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-06-27 16:29:07 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2018-06-27 17:04:18 +0200 |
commit | c08d58802e03a45f95b8f7d28b29dc7026f664ba (patch) | |
tree | 19de8289fed85ce90598da42ea8b89f8d69b522b /openbsc/src/libfilter | |
parent | 360284d4d797519faed33559b0ae746b6c17e68a (diff) |
bsc-nat: 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.
Change-Id: Ibe615379dc44a3a68cf9037630891ebf9b03a06d
Diffstat (limited to 'openbsc/src/libfilter')
-rw-r--r-- | openbsc/src/libfilter/bsc_msg_acc.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/openbsc/src/libfilter/bsc_msg_acc.c b/openbsc/src/libfilter/bsc_msg_acc.c index 7b658e440..0789fb6cf 100644 --- a/openbsc/src/libfilter/bsc_msg_acc.c +++ b/openbsc/src/libfilter/bsc_msg_acc.c @@ -39,6 +39,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) { @@ -71,6 +86,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) @@ -82,8 +98,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; @@ -115,4 +131,3 @@ struct bsc_msg_acc_lst_entry *bsc_msg_acc_lst_entry_create(struct bsc_msg_acc_ls llist_add_tail(&entry->list, &lst->fltr_list); return entry; } - |