gbproxy: Refactor IMSI matching

The current implementation makes it difficult to add further match
expressions.

This patch adds a new struct gbproxy_match that contains the fields
needed for each match expression. The matches (config) and the
results (link_info) are stored in arrays. All related functions are
updated to use them. The old fields in the config structure are
removed.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gb_proxy_tlli.c b/openbsc/src/gprs/gb_proxy_tlli.c
index 093d2b3..d521434 100644
--- a/openbsc/src/gprs/gb_proxy_tlli.c
+++ b/openbsc/src/gprs/gb_proxy_tlli.c
@@ -374,13 +374,18 @@
 	return;
 }
 
-int gbproxy_imsi_matches(struct gbproxy_peer *peer,
-		       struct gbproxy_link_info *link_info)
+int gbproxy_imsi_matches(struct gbproxy_config *cfg,
+			 enum gbproxy_match_id match_id,
+			 struct gbproxy_link_info *link_info)
 {
-	if (!peer->cfg->check_imsi)
+	struct gbproxy_match *match;
+	OSMO_ASSERT(match_id >= 0 && match_id < ARRAY_SIZE(cfg->matches));
+
+	match = &cfg->matches[match_id];
+	if (!match->enable)
 		return 1;
 
-	return link_info != NULL && link_info->imsi_matches;
+	return link_info != NULL && link_info->is_matching[match_id];
 }
 
 void gbproxy_assign_imsi(struct gbproxy_peer *peer,
@@ -389,6 +394,7 @@
 {
 	int imsi_matches;
 	struct gbproxy_link_info *other_link_info;
+	enum gbproxy_match_id match_id;
 
 	/* Make sure that there is a second entry with the same IMSI */
 	other_link_info = gbproxy_link_info_by_imsi(
@@ -410,10 +416,16 @@
 				 parse_ctx->imsi, parse_ctx->imsi_len);
 
 	/* Check, whether the IMSI matches */
-	imsi_matches = gbproxy_check_imsi(peer, parse_ctx->imsi,
-					     parse_ctx->imsi_len);
-	if (imsi_matches >= 0)
-		link_info->imsi_matches = imsi_matches;
+	OSMO_ASSERT(ARRAY_SIZE(link_info->is_matching) ==
+		    ARRAY_SIZE(peer->cfg->matches));
+	for (match_id = 0; match_id < ARRAY_SIZE(link_info->is_matching);
+	     ++match_id) {
+		imsi_matches = gbproxy_check_imsi(
+			&peer->cfg->matches[match_id],
+			parse_ctx->imsi, parse_ctx->imsi_len);
+		if (imsi_matches >= 0)
+			link_info->is_matching[match_id] = imsi_matches;
+	}
 }
 
 static int gbproxy_tlli_match(const struct gbproxy_tlli_state *a,