nat: Factor out the config by token search
In the upcoming authentication improvements it is nice to separate the finding of the config from the post-allow handling of it.
This commit is contained in:
parent
2dd18bdd87
commit
aa0cecd9b7
|
@ -319,6 +319,7 @@ struct bsc_nat_ussd_con {
|
||||||
/* create and init the structures */
|
/* create and init the structures */
|
||||||
struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token);
|
struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token);
|
||||||
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
|
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
|
||||||
|
struct bsc_config *bsc_config_by_token(struct bsc_nat *nat, const char *token, int len);
|
||||||
void bsc_config_free(struct bsc_config *);
|
void bsc_config_free(struct bsc_config *);
|
||||||
void bsc_config_add_lac(struct bsc_config *cfg, int lac);
|
void bsc_config_add_lac(struct bsc_config *cfg, int lac);
|
||||||
void bsc_config_del_lac(struct bsc_config *cfg, int lac);
|
void bsc_config_del_lac(struct bsc_config *cfg, int lac);
|
||||||
|
|
|
@ -980,27 +980,21 @@ static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
llist_for_each_entry(conf, &bsc->nat->bsc_configs, entry) {
|
conf = bsc_config_by_token(bsc->nat, token, len);
|
||||||
/*
|
if (!conf) {
|
||||||
* Add the '\0' of the token for the memcmp, the IPA messages
|
LOGP(DNAT, LOGL_ERROR,
|
||||||
* for some reason added null termination.
|
"No bsc found for token '%s' on fd: %d.\n", token,
|
||||||
*/
|
bsc->write_queue.bfd.fd);
|
||||||
const int token_len = strlen(conf->token) + 1;
|
return;
|
||||||
|
|
||||||
if (token_len == len && memcmp(conf->token, token, token_len) == 0) {
|
|
||||||
rate_ctr_inc(&conf->stats.ctrg->ctr[BCFG_CTR_NET_RECONN]);
|
|
||||||
bsc->authenticated = 1;
|
|
||||||
bsc->cfg = conf;
|
|
||||||
osmo_timer_del(&bsc->id_timeout);
|
|
||||||
LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d on fd %d\n",
|
|
||||||
conf->nr, bsc->write_queue.bfd.fd);
|
|
||||||
start_ping_pong(bsc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP(DNAT, LOGL_ERROR, "No bsc found for token '%s' on fd: %d.\n", token,
|
rate_ctr_inc(&conf->stats.ctrg->ctr[BCFG_CTR_NET_RECONN]);
|
||||||
bsc->write_queue.bfd.fd);
|
bsc->authenticated = 1;
|
||||||
|
bsc->cfg = conf;
|
||||||
|
osmo_timer_del(&bsc->id_timeout);
|
||||||
|
LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d on fd %d\n",
|
||||||
|
conf->nr, bsc->write_queue.bfd.fd);
|
||||||
|
start_ping_pong(bsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_con_stats(struct nat_sccp_connection *con)
|
static void handle_con_stats(struct nat_sccp_connection *con)
|
||||||
|
|
|
@ -180,6 +180,24 @@ struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token)
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct bsc_config *bsc_config_by_token(struct bsc_nat *nat, const char *token, int len)
|
||||||
|
{
|
||||||
|
struct bsc_config *conf;
|
||||||
|
|
||||||
|
llist_for_each_entry(conf, &nat->bsc_configs, entry) {
|
||||||
|
/*
|
||||||
|
* Add the '\0' of the token for the memcmp, the IPA messages
|
||||||
|
* for some reason added null termination.
|
||||||
|
*/
|
||||||
|
const int token_len = strlen(conf->token) + 1;
|
||||||
|
|
||||||
|
if (token_len == len && memcmp(conf->token, token, token_len) == 0)
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void bsc_config_free(struct bsc_config *cfg)
|
void bsc_config_free(struct bsc_config *cfg)
|
||||||
{
|
{
|
||||||
llist_del(&cfg->entry);
|
llist_del(&cfg->entry);
|
||||||
|
|
Loading…
Reference in New Issue