diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-04-05 15:15:36 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-04-05 15:42:25 +0200 |
commit | ab94ca18f236013f78bd23e3788f003f738396cb (patch) | |
tree | d276e283de6f8c517aa91091c7d0e375b936f491 /openbsc/src/osmo-bsc_nat | |
parent | 7c00983275c1b830b88db124bc0b15078b9cd45d (diff) |
nat: Add a ctrl command to add to an existing ACC list
We want to have a program add entries to the allow list
this can be done using:
$ bsc_control.py -d localhost -p 4250 -s net.0.add.allow.access-list.NAME "^IMSI$"
Diffstat (limited to 'openbsc/src/osmo-bsc_nat')
-rw-r--r-- | openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c index 6aa2ff044..bdb1709e5 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c +++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c @@ -28,6 +28,7 @@ #include <openbsc/ctrl.h> #include <openbsc/bsc_nat.h> #include <openbsc/vty.h> +#include <openbsc/gsm_data.h> #include <unistd.h> #include <string.h> @@ -378,6 +379,62 @@ static int verify_net_cfg_cmd(struct ctrl_cmd *cmd, const char *value, void *dat return 0; } +CTRL_CMD_DEFINE(net_cfg_acc_cmd, "net 0 add allow access-list *"); +static const char *extract_acc_name(const char *var) +{ + char *str; + + str = strstr(var, "net.0.add.allow.access-list."); + if (!str) + return NULL; + str += strlen("net.0.add.allow.access-list."); + if (strlen(str) == 0) + return NULL; + return str; +} + +static int get_net_cfg_acc_cmd(struct ctrl_cmd *cmd, void *data) +{ + cmd->reply = "Append only"; + return CTRL_CMD_ERROR; +} + +static int set_net_cfg_acc_cmd(struct ctrl_cmd *cmd, void *data) +{ + const char *access_name = extract_acc_name(cmd->variable); + struct bsc_nat_acc_lst *acc = bsc_nat_acc_lst_find(g_nat, access_name); + struct bsc_nat_acc_lst_entry *entry; + const char *value = cmd->value; + int rc; + + entry = bsc_nat_acc_lst_entry_create(acc); + if (!entry) { + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; + } + + rc = gsm_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, 1, &value); + if (rc != 0) { + cmd->reply = "Failed to compile expression"; + return CTRL_CMD_ERROR; + } + + cmd->reply = "IMSI allow added to access list"; + return CTRL_CMD_REPLY; +} + +static int verify_net_cfg_acc_cmd(struct ctrl_cmd *cmd, const char *value, void *data) +{ + const char *access_name = extract_acc_name(cmd->variable); + struct bsc_nat_acc_lst *acc = bsc_nat_acc_lst_find(g_nat, access_name); + + if (!acc) { + cmd->reply = "Access list not known"; + return -1; + } + + return 0; +} struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port) { @@ -401,6 +458,11 @@ struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port) fprintf(stderr, "Failed to install the net cfg command. Exiting.\n"); goto error; } + rc = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_cfg_acc_cmd); + if (rc) { + fprintf(stderr, "Failed to install the net acc command. Exiting.\n"); + goto error; + } g_nat = nat; return ctrl; |