From 3fa26448d160bf153ec3f35843dbe3aa728c39fb Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 4 Aug 2014 16:27:11 +0200 Subject: gbproxy: Kill the global gbprox_global_patch_state struct Move this patching state into the gbproxy_config as well. Done by Jacob --- openbsc/include/openbsc/gb_proxy.h | 10 +++++++++- openbsc/src/gprs/gb_proxy.c | 29 ++++++++++++----------------- openbsc/src/gprs/gb_proxy_vty.c | 6 +++--- openbsc/tests/gbproxy/gbproxy_test.c | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) (limited to 'openbsc') diff --git a/openbsc/include/openbsc/gb_proxy.h b/openbsc/include/openbsc/gb_proxy.h index 7c38274dc..9c256793f 100644 --- a/openbsc/include/openbsc/gb_proxy.h +++ b/openbsc/include/openbsc/gb_proxy.h @@ -7,6 +7,9 @@ #include #include +#include +#include + struct rate_ctr_group; enum gbproxy_patch_mode { @@ -41,6 +44,10 @@ struct gbproxy_config { 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 @@ int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi); 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 efd35e0bd..277038809 100644 --- a/openbsc/src/gprs/gb_proxy.c +++ b/openbsc/src/gprs/gb_proxy.c @@ -125,12 +125,6 @@ static const struct rate_ctr_group_desc peer_ctrg_desc = { .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 @@ static void gbprox_delete_tllis(struct gbproxy_peer *peer) 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 @@ static int gbprox_check_imsi(struct gbproxy_peer *peer, 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 @@ static int gbprox_check_imsi(struct gbproxy_peer *peer, 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 @@ static void gbprox_register_tlli(struct gbproxy_peer *peer, uint32_t tlli, 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 @@ static int gbprox_check_tlli(struct gbproxy_peer *peer, uint32_t tlli) 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 2b126f204..68d5e74d0 100644 --- a/openbsc/src/gprs/gb_proxy_vty.c +++ b/openbsc/src/gprs/gb_proxy_vty.c @@ -193,7 +193,7 @@ static int set_core_apn(struct vty *vty, const char *apn, const char *filter) 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 @@ static int set_core_apn(struct vty *vty, const char *apn, const char *filter) } 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 63daaff59..3abc14e16 100644 --- a/openbsc/tests/gbproxy/gbproxy_test.c +++ b/openbsc/tests/gbproxy/gbproxy_test.c @@ -951,7 +951,7 @@ static void test_gbproxy_ra_patching() 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); -- cgit v1.2.3