gbproxy: Don't remove stale TLLI automatically

This patches removes the call to gbprox_remove_stale_tllis()
from gbprox_register_tlli(), so it must be called explicitly now.
The call is now done from within gbprox_update_state_after().

In addition, the TLLI cache size counter is also kept in sync when
gbprox_remove_stale_tllis is called manually. The call to
gbproxy_peer_free() in gbproxy_peer_free() is moved behind the TLLI
to allow for counter updates in gbprox_delete_tlli().

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck
2014-08-07 17:23:00 +02:00
parent 12828c1b30
commit aad32bccc0
3 changed files with 24 additions and 18 deletions

View File

@@ -217,11 +217,13 @@ struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvc
void gbproxy_peer_free(struct gbproxy_peer *peer)
{
rate_ctr_group_free(peer->ctrg);
llist_del(&peer->list);
gbprox_delete_tllis(peer);
rate_ctr_group_free(peer->ctrg);
peer->ctrg = NULL;
talloc_free(peer);
}
@@ -462,6 +464,9 @@ void gbprox_delete_tlli(struct gbproxy_peer *peer,
llist_del(&tlli_info->list);
talloc_free(tlli_info);
state->enabled_tllis_count -= 1;
peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
state->enabled_tllis_count;
}
static void gbprox_delete_tllis(struct gbproxy_peer *peer)
@@ -546,6 +551,9 @@ static void gbprox_attach_tlli_info(struct gbproxy_peer *peer, time_t now,
tlli_info->timestamp = now;
llist_add(&tlli_info->list, &state->enabled_tllis);
state->enabled_tllis_count += 1;
peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
state->enabled_tllis_count;
}
int gbprox_remove_stale_tllis(struct gbproxy_peer *peer, time_t now)
@@ -597,6 +605,9 @@ static struct gbproxy_tlli_info *gbprox_get_detached_tlli_info(
llist_del(&tlli_info->list);
OSMO_ASSERT(state->enabled_tllis_count > 0);
state->enabled_tllis_count -= 1;
peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
state->enabled_tllis_count;
}
return tlli_info;
@@ -632,7 +643,6 @@ void gbprox_reassign_tlli(struct gbproxy_tlli_info *tlli_info,
void gbprox_register_tlli(struct gbproxy_peer *peer, uint32_t tlli,
const uint8_t *imsi, size_t imsi_len)
{
struct gbproxy_patch_state *state = &peer->patch_state;
struct gbproxy_tlli_info *tlli_info;
int enable_patching = -1;
time_t now = 0;
@@ -673,20 +683,11 @@ void gbprox_register_tlli(struct gbproxy_peer *peer, uint32_t tlli,
gbprox_update_tlli_info(tlli_info, imsi, imsi_len);
if (enable_patching >= 0)
tlli_info->enable_patching = enable_patching;
gbprox_remove_stale_tllis(peer, now);
/* Be on the safe side, currently the new tlli_info won't be
* removed, but this not enforced explicitely */
tlli_info = NULL;
peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
state->enabled_tllis_count;
}
static void gbprox_unregister_tlli(struct gbproxy_peer *peer, uint32_t tlli)
{
struct gbproxy_tlli_info *tlli_info;
struct gbproxy_patch_state *state = &peer->patch_state;
tlli_info = gbprox_find_tlli(peer, tlli);
if (tlli_info) {
@@ -695,9 +696,6 @@ static void gbprox_unregister_tlli(struct gbproxy_peer *peer, uint32_t tlli)
tlli);
gbprox_delete_tlli(peer, tlli_info);
}
peer->ctrg->ctr[GBPROX_PEER_CTR_TLLI_CACHE_SIZE].current =
state->enabled_tllis_count;
}
static int gbprox_check_tlli(struct gbproxy_peer *peer, uint32_t tlli)
@@ -1363,8 +1361,12 @@ static void gbprox_update_state(struct gbproxy_peer *peer,
static void gbprox_update_state_after(struct gbproxy_peer *peer,
struct gbproxy_parse_context *parse_ctx)
{
time_t now = time(NULL);
if (parse_ctx->invalidate_tlli)
gbprox_unregister_tlli(peer, parse_ctx->tlli);
gbprox_remove_stale_tllis(peer, now);
}
static int gbprox_parse_bssgp(uint8_t *bssgp, size_t bssgp_len,

View File

@@ -1412,6 +1412,7 @@ static void test_gbproxy_tlli_expire(void)
{
struct gbproxy_tlli_info *tlli_info;
int num_removed;
printf("Test TLLI expiry, max_len == 1:\n");
@@ -1427,6 +1428,10 @@ static void test_gbproxy_tlli_expire(void)
/* replace the old entry */
printf(" Add TLLI 2, IMSI 2 (should replace IMSI 1)\n");
gbprox_register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2));
OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 2);
num_removed = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
OSMO_ASSERT(num_removed == 1);
OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 1);
dump_peers(stdout, 2, &cfg);
@@ -1444,7 +1449,7 @@ static void test_gbproxy_tlli_expire(void)
}
{
int ret;
int num_removed;
printf("Test TLLI expiry, max_age == 1:\n");
@@ -1462,8 +1467,8 @@ static void test_gbproxy_tlli_expire(void)
gbprox_register_tlli(peer, tlli2, imsi2, ARRAY_SIZE(imsi2));
OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 2);
ret = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
OSMO_ASSERT(ret == 2);
num_removed = gbprox_remove_stale_tllis(peer, time(NULL) + 2);
OSMO_ASSERT(num_removed == 2);
OSMO_ASSERT(peer->patch_state.enabled_tllis_count == 0);
dump_peers(stdout, 2, &cfg);

View File

@@ -1922,7 +1922,6 @@ Test TLLI expiry, max_age == 1:
Add TLLI 2, IMSI 2 (should expire after timeout)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
TLLI cache size : 2
TLLI-Cache: 0
===== GbProxy test END