Pau Espin Pedrol has uploaded this change for review. ( 
https://gerrit.osmocom.org/9754


Change subject: bsc-nat: Allocate each ctr group with a different idx
......................................................................

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
---
M openbsc/src/libfilter/bsc_msg_acc.c
1 file changed, 18 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/54/9754/1

diff --git a/openbsc/src/libfilter/bsc_msg_acc.c 
b/openbsc/src/libfilter/bsc_msg_acc.c
index 7b658e4..0789fb6 100644
--- a/openbsc/src/libfilter/bsc_msg_acc.c
+++ b/openbsc/src/libfilter/bsc_msg_acc.c
@@ -39,6 +39,21 @@
        .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_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 @@
                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 @@
        llist_add_tail(&entry->list, &lst->fltr_list);
        return entry;
 }
-

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

Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe615379dc44a3a68cf9037630891ebf9b03a06d
Gerrit-Change-Number: 9754
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <[email protected]>

Reply via email to