nat: Add ctrl command to save the configuration

$ bsc_control.py -d localhost -p 4250 -s net.0.save-configuration 0
This commit is contained in:
Holger Hans Peter Freyther 2015-04-05 15:26:33 +02:00
parent ab94ca18f2
commit 8ccf06c58b
1 changed files with 31 additions and 0 deletions

View File

@ -25,6 +25,8 @@
#include <osmocom/ctrl/control_if.h>
#include <osmocom/ctrl/ports.h>
#include <osmocom/vty/misc.h>
#include <openbsc/ctrl.h>
#include <openbsc/bsc_nat.h>
#include <openbsc/vty.h>
@ -436,6 +438,30 @@ static int verify_net_cfg_acc_cmd(struct ctrl_cmd *cmd, const char *value, void
return 0;
}
CTRL_CMD_DEFINE(net_save_cmd, "net 0 save-configuration");
static int verify_net_save_cmd(struct ctrl_cmd *cmd, const char *v, void *d)
{
return 0;
}
static int set_net_save_cmd(struct ctrl_cmd *cmd, void *data)
{
int rc = osmo_vty_save_config_file();
cmd->reply = talloc_asprintf(cmd, "%d", rc);
if (!cmd->reply) {
cmd->reply = "OOM";
return CTRL_CMD_ERROR;
}
return CTRL_CMD_REPLY;
}
static int get_net_save_cmd(struct ctrl_cmd *cmd, void *data)
{
cmd->reply = "Write only attribute";
return CTRL_CMD_ERROR;
}
struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port)
{
struct ctrl_handle *ctrl;
@ -463,6 +489,11 @@ struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat, int port)
fprintf(stderr, "Failed to install the net acc command. Exiting.\n");
goto error;
}
rc = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_save_cmd);
if (rc) {
fprintf(stderr, "Failed to install the net save command. Exiting.\n");
goto error;
}
g_nat = nat;
return ctrl;