not force network

This commit is contained in:
Martin/Geno 2018-08-05 15:20:17 +02:00
parent a2dba85251
commit a4961cc6f2
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
7 changed files with 70 additions and 21 deletions

View File

@ -14,3 +14,7 @@ bool config_client_force_probe = false;
bool config_client_probe_steering = true;
// steering contains learning already
bool config_client_probe_learning = false;
#ifndef MINI
#endif

View File

@ -27,4 +27,8 @@ extern bool config_client_probe_steering;
*/
extern bool config_client_probe_learning;
#ifndef MINI
#endif
#endif

View File

@ -8,6 +8,11 @@
#include "socket.h"
#endif
char *ifname = "br-lan";
char *addr = "::";
char *maddr = "ff02::31f1";
char *port = "1000";
struct option longopts[] = {
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
@ -22,6 +27,11 @@ struct option longopts[] = {
{"clean-every", required_argument, 0, 3},
{"clean-older-then", required_argument, 0, 4},
{"clean-authed", optional_argument, 0, 5},
// network options
{"addr", required_argument, 0, 6},
{"maddr", required_argument, 0, 7},
{"port", required_argument, 0, 8},
{"ifname", required_argument, 0, 9},
};
void usage(int c) {
@ -44,7 +54,12 @@ void usage(int c) {
printf(" --clean-every run cleaning every (current: %ds)\n", config_client_clean_every);
printf(" --clean-older-then clean unseen for secound (current: %ds)\n", config_client_clean_older_then);
printf(" --clean-authed clean already authed also (not only learned by probes) (current: %s)\n", BOOL2STR(config_client_clean_authed));
printf("\nConfig could be changed by ubus, see `ubus -v list wifictld`\n");
printf("\nnetwork options:\n");
printf(" --addr listen on ip address (current: %s)\n", addr);
printf(" --maddr listen and request on multcast address (current: %s)\n", maddr);
printf(" --port listen on port (current: %s)\n", port);
printf(" --ifname listen on interface for multicast (current: %s)\n", ifname);
printf("\nSome config could be changed by ubus, see `ubus -v list wifictld`\n");
if(c)
printf("Invalid parameter %c ignored.\n", c);
}
@ -128,6 +143,19 @@ int main(int argc, char *argv[])
else
config_client_clean_authed = !config_client_clean_authed;
break;
// network options
case 6:
addr = optarg;
break;
case 7:
maddr = optarg;
break;
case 8:
port = optarg;
break;
case 9:
ifname = optarg;
break;
default:
usage(c);
return 1;
@ -155,7 +183,7 @@ int main(int argc, char *argv[])
return ret;
}
#ifndef MINI
ret = socket_init("br-lan");
ret = socket_init(ifname, addr, maddr, port);
if (ret)
{
socket_close();

View File

@ -121,19 +121,19 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
log_info("socket: send answer\n");
}
int socket_init(char *ifname) {
int socket_init(char *ifname, char *socket_bind, char *socket_maddr, char *socket_port) {
server.cb = server_cb;
server.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_IPV6ONLY | USOCK_NUMERIC, SOCKET_ADDR, SOCKET_PORT);
server.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_IPV6ONLY | USOCK_NUMERIC, socket_bind, socket_port);
if (server.fd < 0) {
return 1;
}
client_addr.sin6_family = AF_INET6;
client_addr.sin6_port = htons(atoi(SOCKET_PORT));
client_addr.sin6_port = htons(atoi(socket_port));
client_addr.sin6_scope_id = if_nametoindex(ifname);
// listen multicast
if (!inet_pton(AF_INET6, SOCKET_MADDR, &client_addr.sin6_addr)) {
if (!inet_pton(AF_INET6, socket_maddr, &client_addr.sin6_addr)) {
log_error("socket: invalid multicast group\n");
return -1;
}

View File

@ -4,10 +4,6 @@
#include "include.h"
#include "socket_msg.h"
#define SOCKET_ADDR "::"
#define SOCKET_MADDR "ff02::31f1"
#define SOCKET_PORT "1000"
int socket_init();
void socket_close();

View File

@ -87,6 +87,8 @@ static int ubus_get_config(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_bool(&b, "client_force_probe", config_client_force_probe);
blobmsg_add_bool(&b, "client_probe_steering", config_client_probe_steering);
blobmsg_add_bool(&b, "client_probe_learning", config_client_probe_learning);
#ifndef MINI
#endif
blobmsg_close_table(&b, list);
@ -107,6 +109,8 @@ enum {
SET_CONFIG_CLIENT_FORCE_PROBE,
SET_CONFIG_CLIENT_PROBE_STEERING,
SET_CONFIG_CLIENT_PROBE_LEARNING,
#ifndef MINI
#endif
__SET_CONFIG_MAX
};
@ -121,6 +125,8 @@ static const struct blobmsg_policy ubus_set_config_policy[__SET_CONFIG_MAX] = {
[SET_CONFIG_CLIENT_FORCE_PROBE] = { "client_force_probe", BLOBMSG_TYPE_BOOL },
[SET_CONFIG_CLIENT_PROBE_STEERING] = { "client_probe_steering", BLOBMSG_TYPE_BOOL },
[SET_CONFIG_CLIENT_PROBE_LEARNING] = { "client_probe_learning", BLOBMSG_TYPE_BOOL },
#ifndef MINI
#endif
};
static int ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj,
@ -139,7 +145,11 @@ static int ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj,
!tb[SET_CONFIG_CLIENT_FORCE] &&
!tb[SET_CONFIG_CLIENT_FORCE_PROBE] &&
!tb[SET_CONFIG_CLIENT_PROBE_STEERING] &&
!tb[SET_CONFIG_CLIENT_PROBE_LEARNING])
!tb[SET_CONFIG_CLIENT_PROBE_LEARNING]
#ifndef MINI
// &&
#endif
)
return UBUS_STATUS_INVALID_ARGUMENT;
if (tb[SET_CONFIG_VERBOSE])
config_verbose = blobmsg_get_bool(tb[SET_CONFIG_VERBOSE]);
@ -161,6 +171,8 @@ static int ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj,
config_client_probe_steering = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_PROBE_STEERING]);
if (tb[SET_CONFIG_CLIENT_PROBE_LEARNING])
config_client_probe_learning = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_PROBE_LEARNING]);
#ifndef MINI
#endif
return 0;
}

View File

@ -111,10 +111,15 @@ struct wifi_client *__get_client(struct hostapd_client *hclient){
}, resp = {
.client = malloc(sizeof(*client)),
};
if(socket_request(&req, &resp) == 0){
log_debug("wifi_clients.__get_client("MACSTR"): get client from neigbour\n", MAC2STR(hclient->address));
return resp.client;
if (client->freq_highest < resp.client->freq_highest) {
client->freq_highest = resp.client->freq_highest;
}
if(!client->authed) {
client->authed = resp.client->authed;
}
}
#endif
@ -173,19 +178,19 @@ int wifi_clients_try(struct hostapd_client *hclient) {
if (config_client_force || config_client_force_probe && !hclient->auth) {
if(!hclient->auth){
log_verbose("reject - force\n");
returnINFO_CLIENT -1;
return -1;
}
log_info("reject - force\n");
returnINFO_CLIENT -1;
return -1;
}
if (hclient->ssi_signal > config_client_signal_threashold) {
if(!hclient->auth){
log_verbose("reject - learned higher freq + ssi is high enough\n");
returnINFO_CLIENT -1;
return -1;
}
log_info("reject - learned higher freq + ssi is high enough\n");
returnINFO_CLIENT -1;
return -1;
}
}
@ -195,19 +200,19 @@ int wifi_clients_try(struct hostapd_client *hclient) {
if(!hclient->auth){
client->try_probe = 0;
log_verbose("accept - threashold\n");
returnINFO_CLIENT 0;
return 0;
}
log_info("accept - threashold\n");
client->try_auth = 0;
client->connected = 1;
returnINFO_CLIENT 0;
return 0;
}
if(!hclient->auth){
log_verbose("reject\n");
returnINFO_CLIENT client->try_probe;
return client->try_probe;
}
log_info("reject\n");
returnINFO_CLIENT client->try_auth;
return client->try_auth;
}