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


Change subject: filter: Allocate each ctr group with a different idx
......................................................................

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



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/67/9767/1

diff --git a/src/libfilter/bsc_msg_acc.c b/src/libfilter/bsc_msg_acc.c
index f0232ee..46077b3 100644
--- a/src/libfilter/bsc_msg_acc.c
+++ b/src/libfilter/bsc_msg_acc.c
@@ -41,6 +41,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)
 {
@@ -73,6 +88,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)
@@ -84,8 +100,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;

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c5054c374281bb1d4bd1ecd76ddcca7a010d50a
Gerrit-Change-Number: 9767
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <[email protected]>

Reply via email to