diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2014-09-25 11:17:31 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-10-09 18:02:33 +0200 |
commit | 9a83d7af55772e4e2e6f187ab11d3f2a2665791c (patch) | |
tree | b57ec27fd26bba90c88252251c5249bafd4d85d1 /openbsc/src/gprs/gb_proxy_tlli.c | |
parent | 55ec2bf97f9b30ea44c05e1ec5310bf93cee7884 (diff) |
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
Diffstat (limited to 'openbsc/src/gprs/gb_proxy_tlli.c')
-rw-r--r-- | openbsc/src/gprs/gb_proxy_tlli.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/openbsc/src/gprs/gb_proxy_tlli.c b/openbsc/src/gprs/gb_proxy_tlli.c index 093d2b328..d521434da 100644 --- a/openbsc/src/gprs/gb_proxy_tlli.c +++ b/openbsc/src/gprs/gb_proxy_tlli.c @@ -374,13 +374,18 @@ static void gbproxy_unregister_link_info(struct gbproxy_peer *peer, 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 @@ void gbproxy_assign_imsi(struct gbproxy_peer *peer, { 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 @@ void gbproxy_assign_imsi(struct gbproxy_peer *peer, 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, |