gtphub: use a single TEI pool across planes.

There's no need to keep two separate number pools when both can be fed
from the same pool. User and Ctrl plane TEIs can technically overlap without
colliding, but it doesn't hurt if they don't overlap, either.

Sponsored-by: On-Waves ehi
diff --git a/openbsc/include/openbsc/gtphub.h b/openbsc/include/openbsc/gtphub.h
index 2d9d390..a142867 100644
--- a/openbsc/include/openbsc/gtphub.h
+++ b/openbsc/include/openbsc/gtphub.h
@@ -444,7 +444,7 @@
 	 * uint32_t; if a new TEI were mapped every second, this would take
 	 * more than 100 years (in which a single given TEI must not time out)
 	 * to cause a problem. */
-	struct nr_pool tei_pool[GTPH_PLANE_N];
+	struct nr_pool tei_pool;
 
 	struct llist_head tunnels; /* struct gtphub_tunnel */
 
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index 4f81c01..5807f5f 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -1449,7 +1449,7 @@
 
 		if (tei_from_ie) {
 			/* Create TEI mapping and replace in GTP packet IE */
-			uint32_t mapped_tei = nr_pool_next(&hub->tei_pool[plane_idx]);
+			uint32_t mapped_tei = nr_pool_next(&hub->tei_pool);
 
 			tun->endpoint[side_idx][plane_idx].tei_orig = tei_from_ie;
 			tun->endpoint[side_idx][plane_idx].tei_repl = mapped_tei;
@@ -2105,10 +2105,10 @@
 	expiry_init(&hub->expire_quickly, GTPH_EXPIRE_QUICKLY_SECS);
 	expiry_init(&hub->expire_slowly, GTPH_EXPIRE_SLOWLY_MINUTES * 60);
 
+	nr_pool_init(&hub->tei_pool, 1, 0xffffffff);
+
 	int plane_idx;
 	for_each_plane(plane_idx) {
-		nr_pool_init(&hub->tei_pool[plane_idx], 1, 0xffffffff);
-
 		gtphub_bind_init(&hub->to_ggsns[plane_idx]);
 		gtphub_bind_init(&hub->to_sgsns[plane_idx]);
 	}
diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c
index 9ba4643..8347f3b 100644
--- a/openbsc/tests/gtphub/gtphub_test.c
+++ b/openbsc/tests/gtphub/gtphub_test.c
@@ -906,7 +906,7 @@
 				"6d31",	/* mapped seq ("abcd") */
 				"23",
 				"42000121436587f9",
-				"00000001", /* mapped TEI Data I ("123") */
+				"00000002", /* mapped TEI Data I ("123") */
 				"00000001", /* mapped TEI Control ("321") */
 				"0009""08696e7465726e6574",
 				"0004""7f000201", /* replaced with gtphub's ggsn ctrl */
@@ -920,7 +920,7 @@
 	LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
 
 	LVL2_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=1)"
+		"192.168.42.23 (TEI C 321=1 / U 123=2)"
 		" <-> 192.168.43.34 / (uninitialized) (TEI C 0=0 / U 0=0)"
 		" @21945\n"));
 
@@ -939,8 +939,8 @@
 				"00000321", /* unmapped TEI ("001") */
 				"abcd", /* unmapped seq ("6d31") */
 				"23",
-				"00000002", /* mapped TEI from GGSN ("567") */
-				"00000002", /* mapped TEI from GGSN ("765") */
+				"00000004", /* mapped TEI from GGSN ("567") */
+				"00000003", /* mapped TEI from GGSN ("765") */
 				"0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
 				"0004""7f000102" /* gtphub's address towards SGSNs (User) */
 			       );
@@ -979,8 +979,8 @@
 	 * 0x00000567 == 1383 (TEI from GGSN User)
 	 * Mapped TEIs should be 1 and 2. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=1)"
-		" <-> 192.168.43.34 (TEI C 765=2 / U 567=2)"
+		"192.168.42.23 (TEI C 321=1 / U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
 		" @21945\n"));
 	OSMO_ASSERT(clear_test_hub());
 }
@@ -995,8 +995,8 @@
 
 	/* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=1)"
-		" <-> 192.168.43.34 (TEI C 765=2 / U 567=2)"
+		"192.168.42.23 (TEI C 321=1 / U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
 		" @21945\n"));
 
 	LOG("- user data starts");
@@ -1011,7 +1011,7 @@
 		"32" 	/* 0b001'1 0010: version 1, protocol GTP, with seq nr */
 		"ff"	/* type 255: G-PDU */
 		"0058"	/* length: 88 + 8 octets == 96 */
-		"00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */
+		"00000002" /* mapped User TEI for SGSN from create_pdp_ctx() */
 		"0070"	/* seq */
 		"0000"	/* No extensions */
 		/* User data (ICMP packet), 96 - 12 = 84 octets  */
@@ -1041,15 +1041,15 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=1)"
-		" <-> 192.168.43.34 (TEI C 765=2 / U 567=2)"
+		"192.168.42.23 (TEI C 321=1 / U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
 		" @22545\n"));
 
 	const char *u_from_sgsn =
 		"32" 	/* 0b001'1 0010: version 1, protocol GTP, with seq nr */
 		"ff"	/* type 255: G-PDU */
 		"0058"	/* length: 88 + 8 octets == 96 */
-		"00000002" /* mapped User TEI for GGSN from create_pdp_ctx() */
+		"00000004" /* mapped User TEI for GGSN from create_pdp_ctx() */
 		"6d31"	/* mapped seq */
 		"0000"	/* No extensions */
 		/* User data (ICMP packet), 96 - 12 = 84 octets  */
@@ -1077,8 +1077,8 @@
 	/* Make sure the user plane messages have refreshed the TEI mapping
 	 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
 	OSMO_ASSERT(tunnels_are(
-		"192.168.42.23 (TEI C 321=1 / U 123=1)"
-		" <-> 192.168.43.34 (TEI C 765=2 / U 567=2)"
+		"192.168.42.23 (TEI C 321=1 / U 123=2)"
+		" <-> 192.168.43.34 (TEI C 765=3 / U 567=4)"
 		" @22545\n"));
 
 	OSMO_ASSERT(clear_test_hub());