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_vty.c b/openbsc/src/gprs/gb_proxy_vty.c
index 82d7d95..6dc0e34 100644
--- a/openbsc/src/gprs/gb_proxy_vty.c
+++ b/openbsc/src/gprs/gb_proxy_vty.c
@@ -75,6 +75,8 @@
 
 static int config_write_gbproxy(struct vty *vty)
 {
+	enum gbproxy_match_id match_id;
+
 	vty_out(vty, "gbproxy%s", VTY_NEWLINE);
 
 	vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
@@ -87,9 +89,12 @@
 		vty_out(vty, " core-mobile-network-code %d%s",
 			g_cfg->core_mnc, VTY_NEWLINE);
 
-	if (g_cfg->match_re)
-		vty_out(vty, " match-imsi %s%s",
-			g_cfg->match_re, VTY_NEWLINE);
+	for (match_id = 0; match_id < ARRAY_SIZE(g_cfg->matches); ++match_id) {
+		struct gbproxy_match *match = &g_cfg->matches[match_id];
+		if (match->re_str)
+			vty_out(vty, " match-imsi %s%s",
+				match->re_str, VTY_NEWLINE);
+	}
 
 	if (g_cfg->core_apn != NULL) {
 	       if (g_cfg->core_apn_size > 0) {
@@ -194,15 +199,13 @@
 {
 	const char *filter = argv[0];
 	const char *err_msg = NULL;
+	struct gbproxy_match *match = &g_cfg->matches[GBPROX_MATCH_PATCHING];
 
-	if (gbproxy_set_patch_filter(g_cfg, filter, &err_msg) != 0) {
+	if (gbproxy_set_patch_filter(match, filter, &err_msg) != 0) {
 		vty_out(vty, "Match expression invalid: %s%s",
 			err_msg, VTY_NEWLINE);
 		return CMD_WARNING;
 	}
-	talloc_free(g_cfg->match_re);
-	/* TODO: replace NULL */
-	g_cfg->match_re = talloc_strdup(NULL, filter);
 
 	g_cfg->acquire_imsi = 1;
 
@@ -214,10 +217,9 @@
       "no match-imsi",
       NO_STR GBPROXY_MATCH_IMSI_STR)
 {
-	gbproxy_clear_patch_filter(g_cfg);
+	struct gbproxy_match *match = &g_cfg->matches[GBPROX_MATCH_PATCHING];
 
-	talloc_free(g_cfg->match_re);
-	g_cfg->match_re = NULL;
+	gbproxy_clear_patch_filter(match);
 
 	g_cfg->acquire_imsi = 0;