make list of steering-enabled SSIDs configurable
Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
72
local_node.c
72
local_node.c
@@ -42,6 +42,7 @@ usteer_local_node_state_reset(struct usteer_local_node *ln)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ubus_abort_request(ubus_ctx, &ln->req);
|
ubus_abort_request(ubus_ctx, &ln->req);
|
||||||
|
uloop_timeout_cancel(&ln->req_timer);
|
||||||
ln->req_state = REQ_IDLE;
|
ln->req_state = REQ_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +59,6 @@ usteer_free_node(struct ubus_context *ctx, struct usteer_local_node *ln)
|
|||||||
|
|
||||||
usteer_local_node_state_reset(ln);
|
usteer_local_node_state_reset(ln);
|
||||||
usteer_sta_node_cleanup(&ln->node);
|
usteer_sta_node_cleanup(&ln->node);
|
||||||
uloop_timeout_cancel(&ln->req_timer);
|
|
||||||
uloop_timeout_cancel(&ln->update);
|
uloop_timeout_cancel(&ln->update);
|
||||||
avl_delete(&local_nodes, &ln->node.avl);
|
avl_delete(&local_nodes, &ln->node.avl);
|
||||||
ubus_unregister_subscriber(ctx, &ln->ev);
|
ubus_unregister_subscriber(ctx, &ln->ev);
|
||||||
@@ -288,7 +288,7 @@ usteer_local_node_prepare_rrm_set(struct usteer_local_node *ln)
|
|||||||
void *c;
|
void *c;
|
||||||
|
|
||||||
c = blobmsg_open_array(&b, "list");
|
c = blobmsg_open_array(&b, "list");
|
||||||
avl_for_each_element(&local_nodes, node, avl)
|
for_each_local_node(node)
|
||||||
usteer_add_rrm_data(ln, node);
|
usteer_add_rrm_data(ln, node);
|
||||||
avl_for_each_element(&remote_nodes, rn, avl)
|
avl_for_each_element(&remote_nodes, rn, avl)
|
||||||
usteer_add_rrm_data(ln, &rn->node);
|
usteer_add_rrm_data(ln, &rn->node);
|
||||||
@@ -374,7 +374,6 @@ usteer_get_node(struct ubus_context *ctx, const char *name)
|
|||||||
ln->req_timer.cb = usteer_local_node_state_next;
|
ln->req_timer.cb = usteer_local_node_state_next;
|
||||||
ubus_register_subscriber(ctx, &ln->ev);
|
ubus_register_subscriber(ctx, &ln->ev);
|
||||||
avl_insert(&local_nodes, &node->avl);
|
avl_insert(&local_nodes, &node->avl);
|
||||||
uloop_timeout_set(&ln->update, 1);
|
|
||||||
INIT_LIST_HEAD(&node->sta_info);
|
INIT_LIST_HEAD(&node->sta_info);
|
||||||
|
|
||||||
return ln;
|
return ln;
|
||||||
@@ -392,7 +391,42 @@ usteer_node_run_update_script(struct usteer_node *node)
|
|||||||
val = alloca(strlen(node_up_script) + strlen(ln->iface) + 8);
|
val = alloca(strlen(node_up_script) + strlen(ln->iface) + 8);
|
||||||
sprintf(val, "%s '%s'", node_up_script, ln->iface);
|
sprintf(val, "%s '%s'", node_up_script, ln->iface);
|
||||||
if (system(val))
|
if (system(val))
|
||||||
fprintf(stderr, "failed to execute %s\n", val);
|
MSG(INFO, "failed to execute %s\n", val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usteer_check_node_enabled(struct usteer_local_node *ln)
|
||||||
|
{
|
||||||
|
bool ssid_disabled = config.ssid_list;
|
||||||
|
struct blob_attr *cur;
|
||||||
|
int rem;
|
||||||
|
|
||||||
|
blobmsg_for_each_attr(cur, config.ssid_list, rem) {
|
||||||
|
if (strcmp(blobmsg_get_string(cur), ln->node.ssid) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ssid_disabled = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ln->node.disabled == ssid_disabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ln->node.disabled = ssid_disabled;
|
||||||
|
|
||||||
|
if (ssid_disabled) {
|
||||||
|
MSG(INFO, "Disconnecting from local node %s\n", usteer_node_name(&ln->node));
|
||||||
|
usteer_local_node_state_reset(ln);
|
||||||
|
usteer_sta_node_cleanup(&ln->node);
|
||||||
|
uloop_timeout_cancel(&ln->update);
|
||||||
|
ubus_unsubscribe(ubus_ctx, &ln->ev, ln->obj_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MSG(INFO, "Connecting to local node %s\n", usteer_node_name(&ln->node));
|
||||||
|
ubus_subscribe(ubus_ctx, &ln->ev, ln->obj_id);
|
||||||
|
uloop_timeout_set(&ln->update, 1);
|
||||||
|
usteer_node_run_update_script(&ln->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -407,7 +441,7 @@ usteer_register_node(struct ubus_context *ctx, const char *name, uint32_t id)
|
|||||||
if (strncmp(name, "hostapd.", iface - name) != 0)
|
if (strncmp(name, "hostapd.", iface - name) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MSG(INFO, "Connecting to local node %s\n", name);
|
MSG(INFO, "Creating local node %s\n", name);
|
||||||
ln = usteer_get_node(ctx, name);
|
ln = usteer_get_node(ctx, name);
|
||||||
ln->obj_id = id;
|
ln->obj_id = id;
|
||||||
ln->iface = usteer_node_name(&ln->node) + offset;
|
ln->iface = usteer_node_name(&ln->node) + offset;
|
||||||
@@ -423,8 +457,6 @@ usteer_register_node(struct ubus_context *ctx, const char *name, uint32_t id)
|
|||||||
blobmsg_add_u8(&b, "bss_transition", 1);
|
blobmsg_add_u8(&b, "bss_transition", 1);
|
||||||
ubus_invoke(ctx, id, "bss_mgmt_enable", b.head, NULL, NULL, 1000);
|
ubus_invoke(ctx, id, "bss_mgmt_enable", b.head, NULL, NULL, 1000);
|
||||||
|
|
||||||
ubus_subscribe(ctx, &ln->ev, id);
|
|
||||||
|
|
||||||
list_for_each_entry(h, &node_handlers, list) {
|
list_for_each_entry(h, &node_handlers, list) {
|
||||||
if (!h->init_node)
|
if (!h->init_node)
|
||||||
continue;
|
continue;
|
||||||
@@ -432,7 +464,8 @@ usteer_register_node(struct ubus_context *ctx, const char *name, uint32_t id)
|
|||||||
h->init_node(&ln->node);
|
h->init_node(&ln->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
usteer_node_run_update_script(&ln->node);
|
ln->node.disabled = true;
|
||||||
|
usteer_check_node_enabled(ln);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -492,7 +525,7 @@ void config_set_node_up_script(struct blob_attr *data)
|
|||||||
|
|
||||||
node_up_script = strdup(val);
|
node_up_script = strdup(val);
|
||||||
|
|
||||||
avl_for_each_element(&local_nodes, node, avl)
|
for_each_local_node(node)
|
||||||
usteer_node_run_update_script(node);
|
usteer_node_run_update_script(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,6 +537,27 @@ void config_get_node_up_script(struct blob_buf *buf)
|
|||||||
blobmsg_add_string(buf, "node_up_script", node_up_script);
|
blobmsg_add_string(buf, "node_up_script", node_up_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_set_ssid_list(struct blob_attr *data)
|
||||||
|
{
|
||||||
|
struct usteer_local_node *ln;
|
||||||
|
|
||||||
|
free(config.ssid_list);
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
config.ssid_list = blob_memdup(data);
|
||||||
|
else
|
||||||
|
config.ssid_list = NULL;
|
||||||
|
|
||||||
|
avl_for_each_element(&local_nodes, ln, node.avl)
|
||||||
|
usteer_check_node_enabled(ln);
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_get_ssid_list(struct blob_buf *buf)
|
||||||
|
{
|
||||||
|
if (config.ssid_list)
|
||||||
|
blobmsg_add_blob(buf, config.ssid_list);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usteer_local_nodes_init(struct ubus_context *ctx)
|
usteer_local_nodes_init(struct ubus_context *ctx)
|
||||||
{
|
{
|
||||||
|
5
node.h
5
node.h
@@ -76,4 +76,9 @@ struct usteer_remote_node {
|
|||||||
extern struct avl_tree local_nodes;
|
extern struct avl_tree local_nodes;
|
||||||
extern struct avl_tree remote_nodes;
|
extern struct avl_tree remote_nodes;
|
||||||
|
|
||||||
|
#define for_each_local_node(node) \
|
||||||
|
avl_for_each_element(&local_nodes, node, avl) \
|
||||||
|
if (!node->disabled)
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -106,3 +106,6 @@ config usteer
|
|||||||
# - load_kick_client
|
# - load_kick_client
|
||||||
# - signal_kick
|
# - signal_kick
|
||||||
#option event_log_types ''
|
#option event_log_types ''
|
||||||
|
|
||||||
|
# List of SSIDs to enable steering on
|
||||||
|
#list ssid_list ''
|
||||||
|
@@ -21,6 +21,19 @@ load_ifaces() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_add_string() {
|
||||||
|
json_add_string "" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
uci_option_to_json_string_array() {
|
||||||
|
local cfg="$1"
|
||||||
|
local option="$2"
|
||||||
|
|
||||||
|
json_add_array "$option"
|
||||||
|
config_list_foreach "$cfg" "$option" _add_string
|
||||||
|
json_close_array
|
||||||
|
}
|
||||||
|
|
||||||
uci_option_to_json_bool() {
|
uci_option_to_json_bool() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
local option="$2"
|
local option="$2"
|
||||||
@@ -55,6 +68,7 @@ uci_usteer() {
|
|||||||
uci_option_to_json_bool "$cfg" load_kick_enabled
|
uci_option_to_json_bool "$cfg" load_kick_enabled
|
||||||
uci_option_to_json_bool "$cfg" assoc_steering
|
uci_option_to_json_bool "$cfg" assoc_steering
|
||||||
uci_option_to_json_string "$cfg" node_up_script
|
uci_option_to_json_string "$cfg" node_up_script
|
||||||
|
uci_option_to_json_string_array "$cfg" ssid_list
|
||||||
|
|
||||||
for opt in \
|
for opt in \
|
||||||
debug_level \
|
debug_level \
|
||||||
|
2
remote.c
2
remote.c
@@ -492,7 +492,7 @@ usteer_send_update_timer(struct uloop_timeout *t)
|
|||||||
uloop_timeout_set(t, config.remote_update_interval);
|
uloop_timeout_set(t, config.remote_update_interval);
|
||||||
|
|
||||||
c = usteer_update_init();
|
c = usteer_update_init();
|
||||||
avl_for_each_element(&local_nodes, node, avl)
|
for_each_local_node(node)
|
||||||
usteer_send_node(node, NULL);
|
usteer_send_node(node, NULL);
|
||||||
|
|
||||||
usteer_update_send(c);
|
usteer_update_send(c);
|
||||||
|
7
ubus.c
7
ubus.c
@@ -167,7 +167,8 @@ struct cfg_item {
|
|||||||
_cfg(U32, load_kick_reason_code), \
|
_cfg(U32, load_kick_reason_code), \
|
||||||
_cfg(ARRAY_CB, interfaces), \
|
_cfg(ARRAY_CB, interfaces), \
|
||||||
_cfg(STRING_CB, node_up_script), \
|
_cfg(STRING_CB, node_up_script), \
|
||||||
_cfg(ARRAY_CB, event_log_types)
|
_cfg(ARRAY_CB, event_log_types), \
|
||||||
|
_cfg(ARRAY_CB, ssid_list)
|
||||||
|
|
||||||
enum cfg_items {
|
enum cfg_items {
|
||||||
#define _cfg(_type, _name) CFG_##_name
|
#define _cfg(_type, _name) CFG_##_name
|
||||||
@@ -292,7 +293,7 @@ usteer_ubus_local_info(struct ubus_context *ctx, struct ubus_object *obj,
|
|||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
|
||||||
avl_for_each_element(&local_nodes, node, avl)
|
for_each_local_node(node)
|
||||||
usteer_dump_node_info(node);
|
usteer_dump_node_info(node);
|
||||||
|
|
||||||
ubus_send_reply(ctx, req, b.head);
|
ubus_send_reply(ctx, req, b.head);
|
||||||
@@ -375,7 +376,7 @@ int usteer_ubus_notify_client_disassoc(struct sta_info *si)
|
|||||||
blobmsg_printf(&b, "addr", MAC_ADDR_FMT, MAC_ADDR_DATA(si->sta->addr));
|
blobmsg_printf(&b, "addr", MAC_ADDR_FMT, MAC_ADDR_DATA(si->sta->addr));
|
||||||
blobmsg_add_u32(&b, "duration", config.roam_kick_delay);
|
blobmsg_add_u32(&b, "duration", config.roam_kick_delay);
|
||||||
c = blobmsg_open_array(&b, "neighbors");
|
c = blobmsg_open_array(&b, "neighbors");
|
||||||
avl_for_each_element(&local_nodes, node, avl)
|
for_each_local_node(node)
|
||||||
usteer_add_nr_entry(si->node, node);
|
usteer_add_nr_entry(si->node, node);
|
||||||
avl_for_each_element(&remote_nodes, rn, avl)
|
avl_for_each_element(&remote_nodes, rn, avl)
|
||||||
usteer_add_nr_entry(si->node, &rn->node);
|
usteer_add_nr_entry(si->node, &rn->node);
|
||||||
|
6
usteer.h
6
usteer.h
@@ -63,6 +63,7 @@ struct usteer_node {
|
|||||||
struct blob_attr *script_data;
|
struct blob_attr *script_data;
|
||||||
char ssid[33];
|
char ssid[33];
|
||||||
|
|
||||||
|
bool disabled;
|
||||||
int freq;
|
int freq;
|
||||||
int noise;
|
int noise;
|
||||||
int n_assoc;
|
int n_assoc;
|
||||||
@@ -157,6 +158,8 @@ struct usteer_config {
|
|||||||
|
|
||||||
const char *node_up_script;
|
const char *node_up_script;
|
||||||
uint32_t event_log_mask;
|
uint32_t event_log_mask;
|
||||||
|
|
||||||
|
struct blob_attr *ssid_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sta_info_stats {
|
struct sta_info_stats {
|
||||||
@@ -252,6 +255,9 @@ void config_get_interfaces(struct blob_buf *buf);
|
|||||||
void config_set_node_up_script(struct blob_attr *data);
|
void config_set_node_up_script(struct blob_attr *data);
|
||||||
void config_get_node_up_script(struct blob_buf *buf);
|
void config_get_node_up_script(struct blob_buf *buf);
|
||||||
|
|
||||||
|
void config_set_ssid_list(struct blob_attr *data);
|
||||||
|
void config_get_ssid_list(struct blob_buf *buf);
|
||||||
|
|
||||||
int usteer_interface_init(void);
|
int usteer_interface_init(void);
|
||||||
void usteer_interface_add(const char *name);
|
void usteer_interface_add(const char *name);
|
||||||
void usteer_sta_node_cleanup(struct usteer_node *node);
|
void usteer_sta_node_cleanup(struct usteer_node *node);
|
||||||
|
Reference in New Issue
Block a user