gbproxy: Change creation of tlli_info for SGSN originated messages

Currently tlli_info are created for SGSN originated messages when
the SGSN TLLI cannot be found and P-TMSI patching is active. This
doesn't make much sense, since the BSS side TLLI is not known in this
case. Given that the SGSN is working properly, that can only happen
if either the tlli_info has expired or the gbproxy has been
restarted.

This patch disables the creation of a tlli_info in this case.

Note that these messages are passed unmodified to the MS so far.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gb_proxy_patch.c b/openbsc/src/gprs/gb_proxy_patch.c
index c1b88d9..970f2f6 100644
--- a/openbsc/src/gprs/gb_proxy_patch.c
+++ b/openbsc/src/gprs/gb_proxy_patch.c
@@ -335,6 +335,15 @@
 		goto patch_error;
 	}
 
+	if (!tlli_info && parse_ctx->tlli_enc && parse_ctx->to_bss) {
+		/* Happens with unknown (not cached) TLLI coming from
+		 * the SGSN */
+		/* TODO: What shall be done with the message in this case? */
+		err_ctr = GBPROX_PEER_CTR_TLLI_UNKNOWN;
+		err_info = "TLLI sent by the SGSN is unknown";
+		goto patch_error;
+	}
+
 	if (!tlli_info)
 		return;
 
@@ -346,13 +355,6 @@
 			gbproxy_patch_tlli(parse_ctx->tlli_enc, peer, tlli,
 					   parse_ctx->to_bss, "TLLI");
 			parse_ctx->tlli = tlli;
-		} else if (parse_ctx->to_bss) {
-			/* Happens with unknown (not cached) TLLI coming from
-			 * the SGSN */
-			/* TODO: What shall be done with the message in this case? */
-			err_ctr = GBPROX_PEER_CTR_TLLI_UNKNOWN;
-			err_info = "TLLI sent by the SGSN is unknown";
-			goto patch_error;
 		} else {
 			/* Internal error */
 			err_ctr = GBPROX_PEER_CTR_PATCH_ERR;