aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/gprs
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-11-17 14:30:37 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-12-03 11:39:28 +0100
commite2ed8e6cc3eef9f93d8603634072720d20821ebb (patch)
tree568daf406dc0a3396cd00ab2cb64a9bbcc238e58 /openbsc/src/gprs
parent334af5dd9dcee962a25ca9cca9425da5d7f57a2c (diff)
gtphub: nr_map: add min,max and wrap.
Implement min/max bounds for nr_pool, adjust nr_pool_init() and current tests, and create unit tests for nr_map wrapping. Sequence numbers range from 0 to 65535, while TEIs range from 1 to 0xffffffff. Both cause problems when the nr_pool surpasses the range: seq exit their valid range, causing unmappings to fail, and a TEI would be mapped as zero (invalid). Add a comment about TEI wrapping, and lose the comment about random TEIs (not really important). Sponsored-by: On-Waves ehi
Diffstat (limited to 'openbsc/src/gprs')
-rw-r--r--openbsc/src/gprs/gtphub.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index ef622a68f..8af3ff7ec 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -577,18 +577,21 @@ void expiring_item_del(struct expiring_item *item)
/* nr_map, nr_pool */
-void nr_pool_init(struct nr_pool *pool)
+void nr_pool_init(struct nr_pool *pool, nr_t nr_min, nr_t nr_max)
{
- *pool = (struct nr_pool){};
+ *pool = (struct nr_pool){
+ .nr_min = nr_min,
+ .nr_max = nr_max,
+ .last_nr = nr_max
+ };
}
nr_t nr_pool_next(struct nr_pool *pool)
{
- pool->last_nr ++;
-
- OSMO_ASSERT(pool->last_nr > 0);
- /* TODO: gracefully handle running out of TEIs. */
- /* TODO: random TEIs. */
+ if (pool->last_nr >= pool->nr_max)
+ pool->last_nr = pool->nr_min;
+ else
+ pool->last_nr ++;
return pool->last_nr;
}
@@ -1739,7 +1742,7 @@ void gtphub_init(struct gtphub *hub)
int plane_idx;
for (plane_idx = 0; plane_idx < GTPH_PLANE_N; plane_idx++) {
- nr_pool_init(&hub->tei_pool[plane_idx]);
+ nr_pool_init(&hub->tei_pool[plane_idx], 1, 0xffffffff);
nr_map_init(&hub->tei_map[plane_idx],
&hub->tei_pool[plane_idx],
&hub->expire_tei_maps);
@@ -1907,7 +1910,7 @@ static struct gtphub_peer *gtphub_peer_new(struct gtphub *hub,
INIT_LLIST_HEAD(&peer->addresses);
- nr_pool_init(&peer->seq_pool);
+ nr_pool_init(&peer->seq_pool, 0, 0xffff);
nr_map_init(&peer->seq_map, &peer->seq_pool, &hub->expire_seq_maps);
/* TODO use something random to pick the initial sequence nr.