cosmetic: vlr: rename auth_tuple_max_use_count to _reuse_

The name auth_tuple_max_use_count suggests that if I want to use each auth
tuple exactly once, I need to set it to 1. Curiously, so far you need to set
to intended uses - 1.

Reflect this in its name by renaming to auth_tuple_max_reuse_count.

I first considered to not rename but change the if-conditions so that == 1
means each tuple is used once, and upon struct vlr allocation, set the default
to 1. That would also logically entail that setting to 0 means to re-use
vectors infinitely often, like now a value < 0 does. That means, when
allocating a vlr struct zeroed out, we would by default have the most
dangerous/unsafe configuration. It's no problem to set a default to 1 upon
allocation, but by renaming the variable instead, we get safer alloc-zero
behavior and don't need to change any conditionals in the code (even though the
patch ends up considerably larger from all the renaming).

Change-Id: I0b036cae1536d5d6fb2304f837ed1a6c3713be55
This commit is contained in:
Neels Hofmeyr 2017-10-29 02:11:18 +01:00
parent 96748ca790
commit 33f534136c
3 changed files with 21 additions and 21 deletions

View File

@ -222,7 +222,7 @@ struct vlr_instance {
bool retrieve_imeisv_ciphered;
bool assign_tmsi;
bool check_imei_rqd;
int auth_tuple_max_use_count;
int auth_tuple_max_reuse_count;
bool auth_reuse_old_sets_on_error;
bool parq_retrieve_imsi;
bool is_ps;

View File

@ -59,7 +59,7 @@ struct auth_fsm_priv {
bool is_utran;
bool auth_requested;
int auth_tuple_max_use_count; /* see vlr->cfg instead */
int auth_tuple_max_reuse_count; /* see vlr->cfg instead */
};
/***********************************************************************
@ -69,13 +69,13 @@ struct auth_fsm_priv {
/* Always use either vlr_subscr_get_auth_tuple() or vlr_subscr_has_auth_tuple()
* instead, to ensure proper use count.
* Return an auth tuple with the lowest use_count among the auth tuples. If
* max_use_count >= 0, return NULL if all available auth tuples have a use
* count > max_use_count. If max_use_count is negative, return a currently
* max_reuse_count >= 0, return NULL if all available auth tuples have a use
* count > max_reuse_count. If max_reuse_count is negative, return a currently
* least used auth tuple without enforcing a maximum use count. If there are
* no auth tuples, return NULL.
*/
static struct gsm_auth_tuple *
_vlr_subscr_next_auth_tuple(struct vlr_subscr *vsub, int max_use_count)
_vlr_subscr_next_auth_tuple(struct vlr_subscr *vsub, int max_reuse_count)
{
unsigned int count;
unsigned int idx;
@ -104,7 +104,7 @@ _vlr_subscr_next_auth_tuple(struct vlr_subscr *vsub, int max_use_count)
at = &vsub->auth_tuples[idx];
}
if (!at || (max_use_count >= 0 && at->use_count > max_use_count))
if (!at || (max_reuse_count >= 0 && at->use_count > max_reuse_count))
return NULL;
return at;
@ -112,21 +112,21 @@ _vlr_subscr_next_auth_tuple(struct vlr_subscr *vsub, int max_use_count)
/* Return an auth tuple and increment its use count. */
static struct gsm_auth_tuple *
vlr_subscr_get_auth_tuple(struct vlr_subscr *vsub, int max_use_count)
vlr_subscr_get_auth_tuple(struct vlr_subscr *vsub, int max_reuse_count)
{
struct gsm_auth_tuple *at = _vlr_subscr_next_auth_tuple(vsub,
max_use_count);
max_reuse_count);
if (!at)
return NULL;
at->use_count++;
return at;
}
/* Return whether an auth tuple with the given max_use_count is available. */
/* Return whether an auth tuple with a matching use_count is available. */
static bool vlr_subscr_has_auth_tuple(struct vlr_subscr *vsub,
int max_use_count)
int max_reuse_count)
{
return _vlr_subscr_next_auth_tuple(vsub, max_use_count) != NULL;
return _vlr_subscr_next_auth_tuple(vsub, max_reuse_count) != NULL;
}
static bool check_auth_resp(struct vlr_subscr *vsub, bool is_r99,
@ -250,7 +250,7 @@ static int _vlr_subscr_authenticate(struct osmo_fsm_inst *fi)
struct gsm_auth_tuple *at;
/* Caller ensures we have vectors available */
at = vlr_subscr_get_auth_tuple(vsub, afp->auth_tuple_max_use_count);
at = vlr_subscr_get_auth_tuple(vsub, afp->auth_tuple_max_reuse_count);
if (!at) {
LOGPFSML(fi, LOGL_ERROR, "A previous check ensured that an"
" auth tuple was available, but now there is in fact"
@ -284,12 +284,12 @@ static void auth_fsm_needs_auth(struct osmo_fsm_inst *fi, uint32_t event, void *
OSMO_ASSERT(event == VLR_AUTH_E_START);
/* Start off with the default max_use_count, possibly change that if we
/* Start off with the default max_reuse_count, possibly change that if we
* need to re-use an old tuple. */
afp->auth_tuple_max_use_count = vsub->vlr->cfg.auth_tuple_max_use_count;
afp->auth_tuple_max_reuse_count = vsub->vlr->cfg.auth_tuple_max_reuse_count;
/* Check if we have vectors available */
if (!vlr_subscr_has_auth_tuple(vsub, afp->auth_tuple_max_use_count)) {
if (!vlr_subscr_has_auth_tuple(vsub, afp->auth_tuple_max_reuse_count)) {
/* Obtain_Authentication_Sets_VLR */
vlr_subscr_req_sai(vsub, NULL, NULL);
osmo_fsm_inst_state_chg(fi, VLR_SUB_AS_NEEDS_AUTH_WAIT_AI,
@ -323,9 +323,9 @@ static void auth_fsm_wait_ai(struct osmo_fsm_inst *fi, uint32_t event,
|| (event == VLR_AUTH_E_HLR_SAI_ABORT)) {
if (vsub->vlr->cfg.auth_reuse_old_sets_on_error
&& vlr_subscr_has_auth_tuple(vsub, -1)) {
/* To re-use an old tuple, disable the max_use_count
/* To re-use an old tuple, disable the max_reuse_count
* constraint. */
afp->auth_tuple_max_use_count = -1;
afp->auth_tuple_max_reuse_count = -1;
goto pass;
}
/* result = procedure error */

View File

@ -84,7 +84,7 @@ void test_hlr_rej_auth_info_net_fail_no_reuse_tuples()
net->authentication_required = true;
net->vlr->cfg.auth_reuse_old_sets_on_error = false;
net->vlr->cfg.auth_tuple_max_use_count = 0;
net->vlr->cfg.auth_tuple_max_reuse_count = 0;
BTW("Submit a used auth tuple in the VLR");
btw("Location Update request causes a GSUP Send Auth Info request to HLR");
@ -171,7 +171,7 @@ void test_hlr_rej_auth_info_unkown_imsi_no_reuse_tuples()
net->authentication_required = true;
net->vlr->cfg.auth_reuse_old_sets_on_error = true;
net->vlr->cfg.auth_tuple_max_use_count = 0;
net->vlr->cfg.auth_tuple_max_reuse_count = 0;
BTW("Submit a used auth tuple in the VLR");
btw("Location Update request causes a GSUP Send Auth Info request to HLR");
@ -256,7 +256,7 @@ void test_hlr_acc_but_no_auth_tuples()
net->authentication_required = true;
net->vlr->cfg.auth_reuse_old_sets_on_error = true;
net->vlr->cfg.auth_tuple_max_use_count = 0;
net->vlr->cfg.auth_tuple_max_reuse_count = 0;
btw("Location Update request causes a GSUP Send Auth Info request to HLR");
lu_result_sent = RES_NONE;
@ -291,7 +291,7 @@ void test_hlr_rej_auth_info_net_fail_reuse_tuples()
net->authentication_required = true;
net->vlr->cfg.auth_reuse_old_sets_on_error = true;
net->vlr->cfg.auth_tuple_max_use_count = 0;
net->vlr->cfg.auth_tuple_max_reuse_count = 0;
BTW("Submit a used auth tuple in the VLR");
btw("Location Update request causes a GSUP Send Auth Info request to HLR");