gbproxy: Kill the global gbprox_global_patch_state struct
Move this patching state into the gbproxy_config as well.
Done by Jacob
diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h
index 7c38274..9c25679 100644
--- a/openbsc/include/openbsc/gb_proxy.h
+++ b/openbsc/include/openbsc/gb_proxy.h
@@ -7,6 +7,9 @@
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/vty/command.h>
+#include <sys/types.h>
+#include <regex.h>
+
struct rate_ctr_group;
enum gbproxy_patch_mode {
@@ -41,6 +44,10 @@
enum gbproxy_patch_mode patch_mode;
int tlli_max_age;
int tlli_max_len;
+
+ /* IMSI checking/matching */
+ int check_imsi;
+ regex_t imsi_re_comp;
};
struct gbproxy_patch_state {
@@ -104,7 +111,8 @@
void gbprox_reset(struct gbproxy_config *cfg);
-int gbprox_set_patch_filter(const char *filter, const char **err_msg);
+int gbprox_set_patch_filter(struct gbproxy_config *cfg, const char *filter,
+ const char **err_msg);
void gbprox_delete_tlli(struct gbproxy_peer *peer,
struct gbproxy_tlli_info *tlli_info);
diff --git a/openbsc/src/gprs/gb_proxy.c b/openbsc/src/gprs/gb_proxy.c
index efd35e0..2770388 100644
--- a/openbsc/src/gprs/gb_proxy.c
+++ b/openbsc/src/gprs/gb_proxy.c
@@ -125,12 +125,6 @@
.ctr_desc = peer_ctr_description,
};
-struct {
- int check_imsi;
- regex_t imsi_re_comp;
-} gbprox_global_patch_state = {0,};
-
-
static void gbprox_delete_tllis(struct gbproxy_peer *peer);
/* Find the gbprox_peer by its BVCI */
@@ -441,29 +435,30 @@
OSMO_ASSERT(llist_empty(&state->enabled_tllis));
}
-int gbprox_set_patch_filter(const char *filter, const char **err_msg)
+int gbprox_set_patch_filter(struct gbproxy_config *cfg, const char *filter,
+ const char **err_msg)
{
static char err_buf[300];
int rc;
- if (gbprox_global_patch_state.check_imsi) {
- regfree(&gbprox_global_patch_state.imsi_re_comp);
- gbprox_global_patch_state.check_imsi = 0;
+ if (cfg->check_imsi) {
+ regfree(&cfg->imsi_re_comp);
+ cfg->check_imsi = 0;
}
if (!filter)
return 0;
- rc = regcomp(&gbprox_global_patch_state.imsi_re_comp, filter,
+ rc = regcomp(&cfg->imsi_re_comp, filter,
REG_EXTENDED | REG_NOSUB | REG_ICASE);
if (rc == 0) {
- gbprox_global_patch_state.check_imsi = 1;
+ cfg->check_imsi = 1;
return 0;
}
if (err_msg) {
- regerror(rc, &gbprox_global_patch_state.imsi_re_comp,
+ regerror(rc, &cfg->imsi_re_comp,
err_buf, sizeof(err_buf));
*err_msg = err_buf;
}
@@ -477,7 +472,7 @@
char mi_buf[200];
int rc;
- if (!gbprox_global_patch_state.check_imsi)
+ if (!peer->cfg->check_imsi)
return 1;
rc = gsm48_mi_to_string(mi_buf, sizeof(mi_buf), imsi, imsi_len);
@@ -489,7 +484,7 @@
LOGP(DGPRS, LOGL_DEBUG, "Checking IMSI '%s' (%d)\n", mi_buf, rc);
- rc = regexec(&gbprox_global_patch_state.imsi_re_comp, mi_buf, 0, NULL, 0);
+ rc = regexec(&peer->cfg->imsi_re_comp, mi_buf, 0, NULL, 0);
if (rc == REG_NOMATCH) {
LOGP(DGPRS, LOGL_INFO,
"IMSI '%s' doesn't match pattern '%s'\n",
@@ -549,7 +544,7 @@
if (!imsi || (imsi[0] & GSM_MI_TYPE_MASK) != GSM_MI_TYPE_IMSI)
return;
- if (!gbprox_global_patch_state.check_imsi)
+ if (!peer->cfg->check_imsi)
return;
tlli_info = gbprox_find_tlli(peer, tlli);
@@ -647,7 +642,7 @@
if (gprs_tlli_type(tlli) != TLLI_LOCAL)
return 0;
- return !gbprox_global_patch_state.check_imsi ||
+ return !peer->cfg->check_imsi ||
gbprox_find_tlli(peer, tlli) != NULL;
}
diff --git a/openbsc/src/gprs/gb_proxy_vty.c b/openbsc/src/gprs/gb_proxy_vty.c
index 2b126f2..68d5e74 100644
--- a/openbsc/src/gprs/gb_proxy_vty.c
+++ b/openbsc/src/gprs/gb_proxy_vty.c
@@ -193,7 +193,7 @@
talloc_free(g_cfg->core_apn);
g_cfg->core_apn = NULL;
g_cfg->core_apn_size = 0;
- gbprox_set_patch_filter(NULL, NULL);
+ gbprox_set_patch_filter(g_cfg, NULL, NULL);
return CMD_SUCCESS;
}
@@ -206,8 +206,8 @@
}
if (!filter) {
- gbprox_set_patch_filter(NULL, NULL);
- } else if (gbprox_set_patch_filter(filter, &err_msg) != 0) {
+ gbprox_set_patch_filter(g_cfg, NULL, NULL);
+ } else if (gbprox_set_patch_filter(g_cfg, filter, &err_msg) != 0) {
vty_out(vty, "Match expression invalid: %s%s",
err_msg, VTY_NEWLINE);
return CMD_WARNING;
diff --git a/openbsc/tests/gbproxy/gbproxy_test.c b/openbsc/tests/gbproxy/gbproxy_test.c
index 63daaff..3abc14e 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.c
+++ b/openbsc/tests/gbproxy/gbproxy_test.c
@@ -951,7 +951,7 @@
configure_bss_peers(bss_peer, ARRAY_SIZE(bss_peer));
gbcfg.match_re = talloc_strdup(NULL, "^9898|^121314");
- if (gbprox_set_patch_filter(gbcfg.match_re, &err_msg) != 0) {
+ if (gbprox_set_patch_filter(&gbcfg, gbcfg.match_re, &err_msg) != 0) {
fprintf(stderr, "Failed to compile RE '%s': %s\n",
gbcfg.match_re, err_msg);
exit(1);