filter: Cease out "struct bsc_nat" from the API
This means we need to require a talloc context and simply operate on the list. I had considered creating a structure to hold the list head but I didn't find any other members so omitted it for now.
This commit is contained in:
parent
d04d009f47
commit
d7e04b9956
|
@ -10,7 +10,6 @@
|
||||||
struct vty;
|
struct vty;
|
||||||
|
|
||||||
/* TODO: remove */
|
/* TODO: remove */
|
||||||
struct bsc_nat;
|
|
||||||
struct bsc_nat_parsed;
|
struct bsc_nat_parsed;
|
||||||
struct bsc_connection;
|
struct bsc_connection;
|
||||||
struct nat_sccp_connection;
|
struct nat_sccp_connection;
|
||||||
|
@ -73,12 +72,12 @@ int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
|
||||||
struct bsc_nat_reject_cause *cause);
|
struct bsc_nat_reject_cause *cause);
|
||||||
|
|
||||||
/* IMSI allow/deny handling */
|
/* IMSI allow/deny handling */
|
||||||
struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name);
|
struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct llist_head *lst, const char *name);
|
||||||
struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name);
|
struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(void *ctx, struct llist_head *lst, const char *name);
|
||||||
void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst);
|
void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst);
|
||||||
|
|
||||||
struct bsc_nat_acc_lst_entry *bsc_nat_acc_lst_entry_create(struct bsc_nat_acc_lst *);
|
struct bsc_nat_acc_lst_entry *bsc_nat_acc_lst_entry_create(struct bsc_nat_acc_lst *);
|
||||||
int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *imsi);
|
int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *imsi);
|
||||||
|
|
||||||
void bsc_nat_lst_vty_init(struct bsc_nat *nat, int node);
|
void bsc_nat_lst_vty_init(void *ctx, struct llist_head *lst, int node);
|
||||||
void bsc_nat_acc_lst_write(struct vty *vty, struct bsc_nat_acc_lst *lst);
|
void bsc_nat_acc_lst_write(struct vty *vty, struct bsc_nat_acc_lst *lst);
|
||||||
|
|
|
@ -52,29 +52,29 @@ int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *mi_string)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name)
|
struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct llist_head *head, const char *name)
|
||||||
{
|
{
|
||||||
struct bsc_nat_acc_lst *lst;
|
struct bsc_nat_acc_lst *lst;
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
llist_for_each_entry(lst, &nat->access_lists, list)
|
llist_for_each_entry(lst, head, list)
|
||||||
if (strcmp(lst->name, name) == 0)
|
if (strcmp(lst->name, name) == 0)
|
||||||
return lst;
|
return lst;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name)
|
struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(void *ctx, struct llist_head *head, const char *name)
|
||||||
{
|
{
|
||||||
struct bsc_nat_acc_lst *lst;
|
struct bsc_nat_acc_lst *lst;
|
||||||
|
|
||||||
lst = bsc_nat_acc_lst_find(nat, name);
|
lst = bsc_nat_acc_lst_find(head, name);
|
||||||
if (lst)
|
if (lst)
|
||||||
return lst;
|
return lst;
|
||||||
|
|
||||||
lst = talloc_zero(nat, struct bsc_nat_acc_lst);
|
lst = talloc_zero(ctx, struct bsc_nat_acc_lst);
|
||||||
if (!lst) {
|
if (!lst) {
|
||||||
LOGP(DNAT, LOGL_ERROR, "Failed to allocate access list");
|
LOGP(DNAT, LOGL_ERROR, "Failed to allocate access list");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -89,7 +89,7 @@ struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *nam
|
||||||
|
|
||||||
INIT_LLIST_HEAD(&lst->fltr_list);
|
INIT_LLIST_HEAD(&lst->fltr_list);
|
||||||
lst->name = talloc_strdup(lst, name);
|
lst->name = talloc_strdup(lst, name);
|
||||||
llist_add_tail(&lst->list, &nat->access_lists);
|
llist_add_tail(&lst->list, head);
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,8 +168,8 @@ static int auth_imsi(struct bsc_connection *bsc, const char *imsi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bsc_lst = bsc_nat_acc_lst_find(bsc->nat, bsc->cfg->acc_lst_name);
|
bsc_lst = bsc_nat_acc_lst_find(&bsc->nat->access_lists, bsc->cfg->acc_lst_name);
|
||||||
nat_lst = bsc_nat_acc_lst_find(bsc->nat, bsc->nat->acc_lst_name);
|
nat_lst = bsc_nat_acc_lst_find(&bsc->nat->access_lists, bsc->nat->acc_lst_name);
|
||||||
|
|
||||||
|
|
||||||
if (bsc_lst) {
|
if (bsc_lst) {
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <openbsc/bsc_msg_filter.h>
|
#include <openbsc/bsc_msg_filter.h>
|
||||||
#include <openbsc/bsc_nat.h>
|
|
||||||
#include <openbsc/gsm_data.h>
|
#include <openbsc/gsm_data.h>
|
||||||
#include <openbsc/vty.h>
|
#include <openbsc/vty.h>
|
||||||
|
|
||||||
#include <osmocom/vty/misc.h>
|
#include <osmocom/vty/misc.h>
|
||||||
|
|
||||||
static struct bsc_nat *_nat;
|
static struct llist_head *_acc_lst;
|
||||||
|
static void *_ctx;
|
||||||
|
|
||||||
DEFUN(cfg_lst_no,
|
DEFUN(cfg_lst_no,
|
||||||
cfg_lst_no_cmd,
|
cfg_lst_no_cmd,
|
||||||
|
@ -33,7 +33,7 @@ DEFUN(cfg_lst_no,
|
||||||
"The access-list to remove\n")
|
"The access-list to remove\n")
|
||||||
{
|
{
|
||||||
struct bsc_nat_acc_lst *acc;
|
struct bsc_nat_acc_lst *acc;
|
||||||
acc = bsc_nat_acc_lst_find(_nat, argv[0]);
|
acc = bsc_nat_acc_lst_find(_acc_lst, argv[0]);
|
||||||
if (!acc)
|
if (!acc)
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ DEFUN(show_acc_lst,
|
||||||
SHOW_STR "IMSI access list\n" "Name of the access list\n")
|
SHOW_STR "IMSI access list\n" "Name of the access list\n")
|
||||||
{
|
{
|
||||||
struct bsc_nat_acc_lst *acc;
|
struct bsc_nat_acc_lst *acc;
|
||||||
acc = bsc_nat_acc_lst_find(_nat, argv[0]);
|
acc = bsc_nat_acc_lst_find(_acc_lst, argv[0]);
|
||||||
if (!acc)
|
if (!acc)
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ DEFUN(cfg_lst_imsi_allow,
|
||||||
struct bsc_nat_acc_lst *acc;
|
struct bsc_nat_acc_lst *acc;
|
||||||
struct bsc_nat_acc_lst_entry *entry;
|
struct bsc_nat_acc_lst_entry *entry;
|
||||||
|
|
||||||
acc = bsc_nat_acc_lst_get(_nat, argv[0]);
|
acc = bsc_nat_acc_lst_get(_ctx, _acc_lst, argv[0]);
|
||||||
if (!acc)
|
if (!acc)
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ DEFUN(cfg_lst_imsi_deny,
|
||||||
struct bsc_nat_acc_lst *acc;
|
struct bsc_nat_acc_lst *acc;
|
||||||
struct bsc_nat_acc_lst_entry *entry;
|
struct bsc_nat_acc_lst_entry *entry;
|
||||||
|
|
||||||
acc = bsc_nat_acc_lst_get(_nat, argv[0]);
|
acc = bsc_nat_acc_lst_get(_ctx, _acc_lst, argv[0]);
|
||||||
if (!acc)
|
if (!acc)
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
|
|
||||||
|
@ -127,11 +127,10 @@ void bsc_nat_acc_lst_write(struct vty *vty, struct bsc_nat_acc_lst *lst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bsc_nat_lst_vty_init(void *ctx, struct llist_head *lst, int node)
|
||||||
void bsc_nat_lst_vty_init(struct bsc_nat *nat, int node)
|
|
||||||
{
|
{
|
||||||
_nat = nat;
|
_ctx = ctx;
|
||||||
|
_acc_lst = lst;
|
||||||
install_element_ve(&show_acc_lst_cmd);
|
install_element_ve(&show_acc_lst_cmd);
|
||||||
|
|
||||||
/* access-list */
|
/* access-list */
|
||||||
|
|
|
@ -1171,7 +1171,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
|
||||||
install_element(NAT_NODE, &cfg_nat_ussd_local_cmd);
|
install_element(NAT_NODE, &cfg_nat_ussd_local_cmd);
|
||||||
install_element(NAT_NODE, &cfg_nat_use_ipa_for_mgcp_cmd);
|
install_element(NAT_NODE, &cfg_nat_use_ipa_for_mgcp_cmd);
|
||||||
|
|
||||||
bsc_nat_lst_vty_init(nat, NAT_NODE);
|
bsc_nat_lst_vty_init(nat, &nat->access_lists, NAT_NODE);
|
||||||
|
|
||||||
/* number rewriting */
|
/* number rewriting */
|
||||||
install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd);
|
install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd);
|
||||||
|
|
|
@ -416,7 +416,7 @@ int bsc_ussd_check(struct nat_sccp_connection *con, struct bsc_nat_parsed *parse
|
||||||
if (msg_type == GSM0480_MTYPE_REGISTER) {
|
if (msg_type == GSM0480_MTYPE_REGISTER) {
|
||||||
|
|
||||||
/* now check if it is a IMSI we care about */
|
/* now check if it is a IMSI we care about */
|
||||||
lst = bsc_nat_acc_lst_find(con->bsc->nat,
|
lst = bsc_nat_acc_lst_find(&con->bsc->nat->access_lists,
|
||||||
con->bsc->nat->ussd_lst_name);
|
con->bsc->nat->ussd_lst_name);
|
||||||
if (!lst)
|
if (!lst)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -879,8 +879,8 @@ static void test_cr_filter()
|
||||||
bsc->cfg->acc_lst_name = "bsc";
|
bsc->cfg->acc_lst_name = "bsc";
|
||||||
nat->acc_lst_name = "nat";
|
nat->acc_lst_name = "nat";
|
||||||
|
|
||||||
nat_lst = bsc_nat_acc_lst_get(nat, "nat");
|
nat_lst = bsc_nat_acc_lst_get(nat, &nat->access_lists, "nat");
|
||||||
bsc_lst = bsc_nat_acc_lst_get(nat, "bsc");
|
bsc_lst = bsc_nat_acc_lst_get(nat, &nat->access_lists, "bsc");
|
||||||
|
|
||||||
bsc_entry = bsc_nat_acc_lst_entry_create(bsc_lst);
|
bsc_entry = bsc_nat_acc_lst_entry_create(bsc_lst);
|
||||||
nat_entry = bsc_nat_acc_lst_entry_create(nat_lst);
|
nat_entry = bsc_nat_acc_lst_entry_create(nat_lst);
|
||||||
|
|
Loading…
Reference in New Issue