mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
bbf.config: handle wifi configs reload from external script
This commit is contained in:
parent
571a4335a9
commit
25e2d0bab6
3 changed files with 78 additions and 8 deletions
|
|
@ -634,6 +634,7 @@ static int bbf_config_commit_handler(struct ubus_context *ctx, struct ubus_objec
|
||||||
struct blob_attr *tb[__MAX];
|
struct blob_attr *tb[__MAX];
|
||||||
bool monitor = false, reload = true;
|
bool monitor = false, reload = true;
|
||||||
unsigned char idx = 0;
|
unsigned char idx = 0;
|
||||||
|
uint32_t wifi_config_flags = 0;
|
||||||
|
|
||||||
ULOG_INFO("Commit handler called");
|
ULOG_INFO("Commit handler called");
|
||||||
|
|
||||||
|
|
@ -700,10 +701,15 @@ static int bbf_config_commit_handler(struct ubus_context *ctx, struct ubus_objec
|
||||||
}
|
}
|
||||||
|
|
||||||
ULOG_INFO("Committing changes for specified services and reloading");
|
ULOG_INFO("Committing changes for specified services and reloading");
|
||||||
reload_specified_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, async_req->services, true, reload);
|
reload_specified_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, async_req->services, true, reload, &wifi_config_flags);
|
||||||
} else {
|
} else {
|
||||||
ULOG_INFO("Committing changes for all services and reloading");
|
ULOG_INFO("Committing changes for all services and reloading");
|
||||||
reload_all_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, true, reload);
|
reload_all_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, true, reload, &wifi_config_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wifi_config_flags) {
|
||||||
|
ULOG_ERR("Reloading changes for wifi services");
|
||||||
|
wifi_reload_handler_script(wifi_config_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
|
|
@ -757,10 +763,10 @@ static int bbf_config_revert_handler(struct ubus_context *ctx, struct ubus_objec
|
||||||
|
|
||||||
if (arr_len) {
|
if (arr_len) {
|
||||||
ULOG_INFO("Reverting specified services");
|
ULOG_INFO("Reverting specified services");
|
||||||
reload_specified_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, services, false, false);
|
reload_specified_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, services, false, false, NULL);
|
||||||
} else {
|
} else {
|
||||||
ULOG_INFO("Reverting all services");
|
ULOG_INFO("Reverting all services");
|
||||||
reload_all_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, false, false);
|
reload_all_services(ctx, CONFIG_CONFDIR, supported_protocols[idx].config_savedir, false, false, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULOG_INFO("Applying changes to revert all UCI dmmap configurations");
|
ULOG_INFO("Applying changes to revert all UCI dmmap configurations");
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,34 @@ void strncpyt(char *dst, const char *src, size_t n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool file_exists(const char *path)
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return stat(path, &buffer) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_wifi_configs(const char *config_name, uint32_t *wifi_config_flags)
|
||||||
|
{
|
||||||
|
if (!config_name && !wifi_config_flags)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (strcmp(config_name, "wireless") == 0) {
|
||||||
|
*wifi_config_flags |= WIRELESS_CONFIG;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(config_name, "mapcontroller") == 0) {
|
||||||
|
*wifi_config_flags |= MAPCONTROLLER_CONFIG;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int bbf_config_call(struct ubus_context *ctx, const char *object, const char *method, struct blob_buf *data, ubus_data_handler_t callback, void *arg)
|
int bbf_config_call(struct ubus_context *ctx, const char *object, const char *method, struct blob_buf *data, ubus_data_handler_t callback, void *arg)
|
||||||
{
|
{
|
||||||
int fault = 0;
|
int fault = 0;
|
||||||
|
|
@ -77,7 +105,8 @@ static void reload_service(struct ubus_context *ctx, const char *config_name, bo
|
||||||
blob_buf_free(&bb);
|
blob_buf_free(&bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, struct blob_attr *services, bool is_commit, bool reload)
|
void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, struct blob_attr *services,
|
||||||
|
bool is_commit, bool reload, uint32_t *wifi_config_flags)
|
||||||
{
|
{
|
||||||
struct uci_context *uci_ctx = NULL;
|
struct uci_context *uci_ctx = NULL;
|
||||||
struct blob_attr *service = NULL;
|
struct blob_attr *service = NULL;
|
||||||
|
|
@ -127,6 +156,9 @@ void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reload) {
|
if (reload) {
|
||||||
|
if (is_wifi_configs(config_name, wifi_config_flags))
|
||||||
|
continue;
|
||||||
|
|
||||||
ULOG_INFO("Reloading service '%s'", config_name);
|
ULOG_INFO("Reloading service '%s'", config_name);
|
||||||
reload_service(ctx, config_name, is_commit);
|
reload_service(ctx, config_name, is_commit);
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +168,8 @@ void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, c
|
||||||
uci_free_context(uci_ctx);
|
uci_free_context(uci_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reload_all_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, bool is_commit, bool reload)
|
void reload_all_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir,
|
||||||
|
bool is_commit, bool reload, uint32_t *wifi_config_flags)
|
||||||
{
|
{
|
||||||
struct uci_context *uci_ctx = NULL;
|
struct uci_context *uci_ctx = NULL;
|
||||||
char **configs = NULL, **p = NULL;
|
char **configs = NULL, **p = NULL;
|
||||||
|
|
@ -193,6 +226,9 @@ void reload_all_services(struct ubus_context *ctx, const char *conf_dir, const c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reload) {
|
if (reload) {
|
||||||
|
if (is_wifi_configs(*p, wifi_config_flags))
|
||||||
|
continue;
|
||||||
|
|
||||||
ULOG_INFO("Reloading service for config '%s'", *p);
|
ULOG_INFO("Reloading service for config '%s'", *p);
|
||||||
reload_service(ctx, *p, is_commit);
|
reload_service(ctx, *p, is_commit);
|
||||||
}
|
}
|
||||||
|
|
@ -204,6 +240,25 @@ exit:
|
||||||
uci_free_context(uci_ctx);
|
uci_free_context(uci_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wifi_reload_handler_script(uint32_t wifi_config_flags)
|
||||||
|
{
|
||||||
|
#define WIFI_CONFIG_RELOAD_SCRIPT "/etc/wifidmd/bbf_config_reload.sh"
|
||||||
|
char cmd[512] = {0};
|
||||||
|
|
||||||
|
if (!file_exists(WIFI_CONFIG_RELOAD_SCRIPT))
|
||||||
|
return;
|
||||||
|
|
||||||
|
snprintf(cmd, sizeof(cmd), "sh %s '{\"wireless\":\"%d\",\"mapcontroller\":\"%d\"}'",
|
||||||
|
WIFI_CONFIG_RELOAD_SCRIPT,
|
||||||
|
wifi_config_flags & WIRELESS_CONFIG ? 1 : 0,
|
||||||
|
wifi_config_flags & MAPCONTROLLER_CONFIG ? 1 : 0);
|
||||||
|
|
||||||
|
FILE *pp = popen(cmd, "r"); // flawfinder: ignore
|
||||||
|
if (pp) {
|
||||||
|
pclose(pp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void uci_apply_changes(const char *conf_dir, const char *save_dir, bool is_commit)
|
void uci_apply_changes(const char *conf_dir, const char *save_dir, bool is_commit)
|
||||||
{
|
{
|
||||||
struct uci_context *uci_ctx = NULL;
|
struct uci_context *uci_ctx = NULL;
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,22 @@
|
||||||
#define ULOG_DEBUG(fmt, ...) ulog(LOG_DEBUG, fmt, ## __VA_ARGS__)
|
#define ULOG_DEBUG(fmt, ...) ulog(LOG_DEBUG, fmt, ## __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum wifi_config_flags_enum {
|
||||||
|
WIRELESS_CONFIG = 1,
|
||||||
|
MAPCONTROLLER_CONFIG = 1<<1,
|
||||||
|
};
|
||||||
|
|
||||||
void strncpyt(char *dst, const char *src, size_t n);
|
void strncpyt(char *dst, const char *src, size_t n);
|
||||||
|
|
||||||
int bbf_config_call(struct ubus_context *ctx, const char *object, const char *method, struct blob_buf *data, ubus_data_handler_t callback, void *arg);
|
int bbf_config_call(struct ubus_context *ctx, const char *object, const char *method, struct blob_buf *data, ubus_data_handler_t callback, void *arg);
|
||||||
|
|
||||||
void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, struct blob_attr *services, bool is_commit, bool reload);
|
void reload_specified_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, struct blob_attr *services,
|
||||||
|
bool is_commit, bool reload, uint32_t *wifi_config_flags);
|
||||||
|
|
||||||
void reload_all_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir, bool is_commit, bool reload);
|
void reload_all_services(struct ubus_context *ctx, const char *conf_dir, const char *save_dir,
|
||||||
|
bool is_commit, bool reload, uint32_t *wifi_config_flags);
|
||||||
|
|
||||||
|
void wifi_reload_handler_script(uint32_t wifi_config_flags);
|
||||||
|
|
||||||
void uci_apply_changes(const char *conf_dir, const char *save_dir, bool is_commit);
|
void uci_apply_changes(const char *conf_dir, const char *save_dir, bool is_commit);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue