gbproxy: Keep tlli_info after detach

Currently a tlli_info entry is deleted when the TLLI gets invalidated
by a Detach message.

This patch introduces the possibility to keep tlli_info entries in
the list. Those entries then have cleared TLLI fields, are marked as
de-registered, and can only be retrieved by a message containing an
IMSI or a P-TMSI.

The following VTY configuration commands are added to the gbproxy
node:
  - tlli-list keep-mode never : Don't keep the entries (default)
  - tlli-list keep-mode re-attach : Only keep them, when a Detach
    message with re-attach required has been received
  - tlli-list keep-mode identified : Only keep entries which are
    associated with an IMSI
  - tlli-list keep-mode always : Keep all entries

Note that at least one of max-length or max-age should be set when
this feature is used to limit the number of entries.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gprs_gb_parse.c b/openbsc/src/gprs/gprs_gb_parse.c
index f361951..7ae792a 100644
--- a/openbsc/src/gprs/gprs_gb_parse.c
+++ b/openbsc/src/gprs/gprs_gb_parse.c
@@ -224,6 +224,7 @@
 {
 	uint8_t *value;
 	size_t value_len;
+	int detach_type;
 	int power_off;
 
 	parse_ctx->llc_msg_name = "DETACH_REQ";
@@ -234,9 +235,14 @@
 		/* invalid */
 		return 0;
 
+	detach_type = *value & 0x07;
 	power_off = *value & 0x08 ? 1 : 0;
 
-	if (!parse_ctx->to_bss) {
+	if (parse_ctx->to_bss) {
+		/* Network originated */
+		if (detach_type == GPRS_DET_T_MT_REATT_REQ)
+			parse_ctx->await_reattach = 1;
+	} else {
 		/* Mobile originated */
 
 		if (power_off)
@@ -651,6 +657,10 @@
 		LOGP(DGPRS, LOGL_DEBUG, "%s invalidate", sep);
 		sep = ",";
 	}
+	if (parse_ctx->await_reattach) {
+		LOGP(DGPRS, LOGL_DEBUG, "%s re-attach", sep);
+		sep = ",";
+	}
 
 	LOGP(DGPRS, LOGL_DEBUG, "\n");
 }