summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <daniel@totalueberwachung.de>2011-07-16 21:42:53 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-08-22 23:45:56 +0200
commite54db171eeddf100121e18ea62c7ee22df6fbb4d (patch)
tree830531cbb4610d2dedecc571d90250dedd02c9ef
parent7c3298af9ebb5c9f8bcee0cd0b803778478a4336 (diff)
nat: Fix error in get_next_free_bsc_id
The new function now mimcis the behaviour of assign_src_local_reference from bsc_sccp.c
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index c42061b98..6e4282b49 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -1534,34 +1534,39 @@ static struct vty_app_info vty_info = {
.is_config_node = bsc_vty_is_config_node,
};
+static int bsc_id_unused(int id, struct bsc_connection *bsc)
+{
+ struct bsc_cmd_list *pending;
+
+ llist_for_each_entry(pending, &bsc->cmd_pending, list_entry) {
+ if (pending->nat_id == id)
+ return 0;
+ }
+ return 1;
+}
+
+#define NAT_MAX_CTRL_ID 65535
+
static int get_next_free_bsc_id(struct bsc_connection *bsc)
{
int new_id, overflow = 0;
- struct bsc_cmd_list *pending;
new_id = bsc->last_id;
+
do {
new_id++;
- if (new_id <= 0) {
+ if (new_id == NAT_MAX_CTRL_ID) {
new_id = 1;
overflow++;
}
- llist_for_each_entry(pending, &bsc->cmd_pending, list_entry) {
- if (pending->nat_id == new_id)
- continue;
+ if (bsc_id_unused(new_id, bsc)) {
+ bsc->last_id = new_id;
+ return new_id;
}
+ } while (overflow != 2);
- /* ID is not in use */
- break;
- } while ((new_id != bsc->last_id) && (overflow < 2));
-
- if ((new_id == bsc->last_id) || (overflow == 2)) {
- return -1;
- } else {
- bsc->last_id = new_id;
- return new_id;
- }
+ return -1;
}
static void pending_timeout_cb(void *data)