gbproxy: Check tlli_info when patching, fix APN patching

Currently the numeric TLLI or tlli_info's enable_patching flag is
used to decide, whether a APN shall be patched or the secondary SGSN
shall be used. Using the numeric TLLI imposes a problem, when
TLLI/P-TMSI patching is used, since gbproxy_check_tlli uses the BSS
side TLLI namespace when trying to get the tlli_info.

This patch modifies the gbproxy_check_tlli() function to accept a
tlli_info pointer instead of a numeric TLLI. The tlli_info is already
available when the function is called. Since this a similar approach
has been used by accessing the enable_patching flag directly, this
commit unifies checking by always using this function instead of the
flag outside of gb_proxy_tlli.c.

This fixes the APN patching that doesn't work currently when P-TMSI
patching is enabled.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c
index 2026d1a..e77d527 100644
--- a/openbsc/src/gprs/gb_proxy.c
+++ b/openbsc/src/gprs/gb_proxy.c
@@ -330,7 +330,7 @@
 
 	tlli_info = gbproxy_update_tlli_state_ul(peer, now, &parse_ctx);
 
-	if (tlli_info && tlli_info->enable_patching && cfg->route_to_sgsn2) {
+	if (tlli_info && cfg->route_to_sgsn2 && gbproxy_check_tlli(peer, tlli_info)) {
 		sgsn_nsei = cfg->nsip_sgsn2_nsei;
 		send_msg_directly = 1;
 	}
diff --git a/openbsc/src/gprs/gb_proxy_patch.c b/openbsc/src/gprs/gb_proxy_patch.c
index 32e844e..c1b88d9 100644
--- a/openbsc/src/gprs/gb_proxy_patch.c
+++ b/openbsc/src/gprs/gb_proxy_patch.c
@@ -278,7 +278,7 @@
 	if (parse_ctx->apn_ie &&
 	    peer->cfg->core_apn &&
 	    !parse_ctx->to_bss &&
-	    gbproxy_check_tlli(peer, parse_ctx->tlli)) {
+	    gbproxy_check_tlli(peer, tlli_info)) {
 		size_t new_len;
 		gbproxy_patch_apn_ie(msg,
 				     parse_ctx->apn_ie, parse_ctx->apn_ie_len,
diff --git a/openbsc/src/gprs/gb_proxy_tlli.c b/openbsc/src/gprs/gb_proxy_tlli.c
index 22585ab..2074308 100644
--- a/openbsc/src/gprs/gb_proxy_tlli.c
+++ b/openbsc/src/gprs/gb_proxy_tlli.c
@@ -369,18 +369,12 @@
 	}
 }
 
-int gbproxy_check_tlli(struct gbproxy_peer *peer, uint32_t tlli)
+int gbproxy_check_tlli(struct gbproxy_peer *peer,
+		       struct gbproxy_tlli_info *tlli_info)
 {
-	struct gbproxy_tlli_info *tlli_info;
-
-	LOGP(DGPRS, LOGL_INFO, "Checking TLLI %08x, class: %d\n",
-	     tlli, gprs_tlli_type(tlli));
-
 	if (!peer->cfg->check_imsi)
 		return 1;
 
-	tlli_info = gbproxy_find_tlli(peer, tlli);
-
 	return tlli_info != NULL && tlli_info->enable_patching;
 }