From d7e04b9956bb7d579697604fff6ba67fc6b9e52d Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 4 Apr 2015 22:28:32 +0200 Subject: 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. --- openbsc/src/libfilter/bsc_msg_acc.c | 12 ++++++------ openbsc/src/libfilter/bsc_msg_filter.c | 4 ++-- openbsc/src/libfilter/bsc_msg_vty.c | 19 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) (limited to 'openbsc/src/libfilter') diff --git a/openbsc/src/libfilter/bsc_msg_acc.c b/openbsc/src/libfilter/bsc_msg_acc.c index 947a7b2ed..cc6c44405 100644 --- a/openbsc/src/libfilter/bsc_msg_acc.c +++ b/openbsc/src/libfilter/bsc_msg_acc.c @@ -52,29 +52,29 @@ int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *mi_string) 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; if (!name) return NULL; - llist_for_each_entry(lst, &nat->access_lists, list) + llist_for_each_entry(lst, head, list) if (strcmp(lst->name, name) == 0) return lst; 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; - lst = bsc_nat_acc_lst_find(nat, name); + lst = bsc_nat_acc_lst_find(head, name); if (lst) return lst; - lst = talloc_zero(nat, struct bsc_nat_acc_lst); + lst = talloc_zero(ctx, struct bsc_nat_acc_lst); if (!lst) { LOGP(DNAT, LOGL_ERROR, "Failed to allocate access list"); 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); lst->name = talloc_strdup(lst, name); - llist_add_tail(&lst->list, &nat->access_lists); + llist_add_tail(&lst->list, head); return lst; } diff --git a/openbsc/src/libfilter/bsc_msg_filter.c b/openbsc/src/libfilter/bsc_msg_filter.c index 8f2e1cabf..1f7a14e63 100644 --- a/openbsc/src/libfilter/bsc_msg_filter.c +++ b/openbsc/src/libfilter/bsc_msg_filter.c @@ -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); - nat_lst = bsc_nat_acc_lst_find(bsc->nat, bsc->nat->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->access_lists, bsc->nat->acc_lst_name); if (bsc_lst) { diff --git a/openbsc/src/libfilter/bsc_msg_vty.c b/openbsc/src/libfilter/bsc_msg_vty.c index 070a03da6..79cf03db1 100644 --- a/openbsc/src/libfilter/bsc_msg_vty.c +++ b/openbsc/src/libfilter/bsc_msg_vty.c @@ -18,13 +18,13 @@ */ #include -#include #include #include #include -static struct bsc_nat *_nat; +static struct llist_head *_acc_lst; +static void *_ctx; DEFUN(cfg_lst_no, cfg_lst_no_cmd, @@ -33,7 +33,7 @@ DEFUN(cfg_lst_no, "The access-list to remove\n") { 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) return CMD_WARNING; @@ -47,7 +47,7 @@ DEFUN(show_acc_lst, SHOW_STR "IMSI access list\n" "Name of the access list\n") { 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) return CMD_WARNING; @@ -68,7 +68,7 @@ DEFUN(cfg_lst_imsi_allow, struct bsc_nat_acc_lst *acc; 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) return CMD_WARNING; @@ -94,7 +94,7 @@ DEFUN(cfg_lst_imsi_deny, struct bsc_nat_acc_lst *acc; 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) 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(struct bsc_nat *nat, int node) +void bsc_nat_lst_vty_init(void *ctx, struct llist_head *lst, int node) { - _nat = nat; - + _ctx = ctx; + _acc_lst = lst; install_element_ve(&show_acc_lst_cmd); /* access-list */ -- cgit v1.2.3