gprs: Add counters related to LLC layer patching

This commit adds the following counters:

  - attach-reqs:   Number of Attach Request messages
  - attach-rejs:   Number of Attach Reject messages
  - tlli-cache:    Size of the TLLI cache

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c
index 89ed84e..88f727e 100644
--- a/openbsc/src/gprs/gb_proxy.c
+++ b/openbsc/src/gprs/gb_proxy.c
@@ -109,6 +109,9 @@
 	GBPROX_PEER_CTR_APN_PATCHED,
 	GBPROX_PEER_CTR_PATCH_CRYPT_ERR,
 	GBPROX_PEER_CTR_PATCH_ERR,
+	GBPROX_PEER_CTR_ATTACH_REQS,
+	GBPROX_PEER_CTR_ATTACH_REJS,
+	GBPROX_PEER_CTR_TLLI_CACHE_SIZE,
 };
 
 static const struct rate_ctr_desc peer_ctr_description[] = {
@@ -122,6 +125,9 @@
 	{ "apn-mod.sgsn",  "APN patched                     " },
 	{ "mod-crypt-err", "Patch error: encrypted          " },
 	{ "mod-err",	   "Patch error: other              " },
+	{ "attach-reqs",   "Attach Request count            " },
+	{ "attach-rejs",   "Attach Reject count             " },
+	{ "tlli-cache",    "TLLI cache size                 " },
 };
 
 static const struct rate_ctr_group_desc peer_ctrg_desc = {
@@ -639,6 +645,10 @@
 		OSMO_ASSERT(tlli_info->mi_data != NULL);
 		memcpy(tlli_info->mi_data, imsi, imsi_len);
 	}
+
+	/* TODO: Hack??? */
+	peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
+		state->enabled_tllis_count;
 }
 
 static void gbprox_unregister_tlli(struct gbprox_peer *peer, uint32_t tlli)
@@ -1023,6 +1033,7 @@
 
 	switch (g48h->msg_type) {
 	case GSM48_MT_GMM_ATTACH_REQ:
+		rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_ATTACH_REQS]);
 		return gbprox_patch_gmm_attach_req(msg, data, data_len,
 						   peer, to_bss, len_change);
 
@@ -1032,6 +1043,10 @@
 		return gbprox_patch_gmm_attach_ack(msg, data, data_len,
 						   peer, to_bss, len_change);
 
+	case GSM48_MT_GMM_ATTACH_REJ:
+		rate_ctr_inc(&peer->ctrg->ctr[GBPROX_PEER_CTR_ATTACH_REJS]);
+		break;
+
 	case GSM48_MT_GMM_RA_UPD_REQ:
 		if (!patching_is_enabled(GBPROX_PATCH_LLC_GMM))
 			break;
diff --git a/openbsc/tests/gbproxy/gbproxy_test.ok b/openbsc/tests/gbproxy/gbproxy_test.ok
index fb8991c..58f4951 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.ok
+++ b/openbsc/tests/gbproxy/gbproxy_test.ok
@@ -1678,6 +1678,8 @@
     RAID patched              (BSS ): 9
     RAID patched              (SGSN): 3
     APN patched                     : 2
+    Attach Request count            : 1
+    TLLI cache size                 : 2
 --- Bad cases ---
 
 TLLI is already detached, shouldn't patch
@@ -1714,5 +1716,7 @@
     RAID patched              (BSS ): 10
     RAID patched              (SGSN): 3
     APN patched                     : 2
+    Attach Request count            : 1
+    TLLI cache size                 : 2
 ===== GbProxy test END