gbproxy: Don't remove stale TLLI automatically

This patches removes the call to gbprox_remove_stale_tllis()
from gbprox_register_tlli(), so it must be called explicitly now.
The call is now done from within gbprox_update_state_after().

In addition, the TLLI cache size counter is also kept in sync when
gbprox_remove_stale_tllis is called manually. The call to
gbproxy_peer_free() in gbproxy_peer_free() is moved behind the TLLI
to allow for counter updates in gbprox_delete_tlli().

Sponsored-by: On-Waves ehf
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index bb2b1aa..beade6e 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -1412,6 +1412,7 @@
 
 	{
 		struct gbproxy_tlli_info *tlli_info;
+		int num_removed;
 
 		printf("Test TLLI expiry, max_len == 1:\n");
 
@@ -1427,6 +1428,10 @@
 		/* replace the old entry */
 		printf("  Add TLLI 2, IMSI 2 (should replace IMSI 1)\n");
 		gbprox_register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2));
+		OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 2);
+
+		num_removed = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
+		OSMO_ASSERT(num_removed == 1);
 		OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 1);
 
 		dump_peers(stdout, 2, &cfg);
@@ -1444,7 +1449,7 @@
 	}
 
 	{
-		int ret;
+		int num_removed;
 
 		printf("Test TLLI expiry, max_age == 1:\n");
 
@@ -1462,8 +1467,8 @@
 		gbprox_register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2));
 		OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 2);
 
-		ret = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
-		OSMO_ASSERT(ret == 2);
+		num_removed = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
+		OSMO_ASSERT(num_removed == 2);
 		OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 0);
 
 		dump_peers(stdout, 2, &cfg);