add socket_info
This commit is contained in:
parent
9aec4435ec
commit
a2dba85251
|
@ -7,6 +7,23 @@ static struct uloop_fd server;
|
||||||
struct in6_addr ownaddr;
|
struct in6_addr ownaddr;
|
||||||
struct sockaddr_in6 client_addr;
|
struct sockaddr_in6 client_addr;
|
||||||
|
|
||||||
|
int socket_info(struct socket_msg *info) {
|
||||||
|
int ret = 0;
|
||||||
|
char msg[REQUEST_MAXLEN];
|
||||||
|
|
||||||
|
ret = socket_msg_marshal(info, msg);
|
||||||
|
if (ret) {
|
||||||
|
log_error("socket_request: could not marshel message: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = sendto(server.fd, msg, REQUEST_MAXLEN, 0, (struct sockaddr *)&client_addr, sizeof(client_addr));
|
||||||
|
if (ret < 0) {
|
||||||
|
log_error("socket_request: could not send message: %d\n", ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout) {
|
int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int sock = 0;
|
int sock = 0;
|
||||||
|
@ -45,7 +62,8 @@ int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer
|
||||||
log_error("socket_request: unable to set timeout: %d\n", errno);
|
log_error("socket_request: unable to set timeout: %d\n", errno);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = recv(sock, msg, REQUEST_MAXLEN, 0);
|
|
||||||
|
ret = recv(sock, msg, REQUEST_MAXLEN, MSG_WAITALL);
|
||||||
close(sock);
|
close(sock);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if(errno == EWOULDBLOCK)
|
if(errno == EWOULDBLOCK)
|
||||||
|
@ -61,10 +79,10 @@ int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer
|
||||||
}
|
}
|
||||||
|
|
||||||
log_verbose("socket_request: end %d\n", ret);
|
log_verbose("socket_request: end %d\n", ret);
|
||||||
if(answer->type & SOCKET_MSG_TYPE_RESPONSE) {
|
if (answer->type & SOCKET_MSG_TYPE_RESPONSE) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
||||||
|
@ -129,6 +147,12 @@ int socket_init(char *ifname) {
|
||||||
log_error("socket: unable to join multicast group: %d\n", errno);
|
log_error("socket: unable to join multicast group: %d\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int loop = 0;
|
||||||
|
if(setsockopt(server.fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop, sizeof(loop)) < 0) {
|
||||||
|
log_error("socket_request: unable to disable listen/loop own multicast package: %d\n", errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// end listen multicast
|
// end listen multicast
|
||||||
uloop_fd_add(&server, ULOOP_READ);
|
uloop_fd_add(&server, ULOOP_READ);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
int socket_init();
|
int socket_init();
|
||||||
void socket_close();
|
void socket_close();
|
||||||
|
|
||||||
|
int socket_info(struct socket_msg *info);
|
||||||
|
|
||||||
|
|
||||||
int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout);
|
int socket_request_timeout(struct socket_msg *request, struct socket_msg *answer, struct timeval timeout);
|
||||||
|
|
||||||
static inline int socket_request(struct socket_msg *request, struct socket_msg *answer)
|
static inline int socket_request(struct socket_msg *request, struct socket_msg *answer)
|
||||||
|
|
|
@ -7,8 +7,6 @@ int socket_msg_marshal(struct socket_msg *src, char dest[REQUEST_MAXLEN]) {
|
||||||
uint16_t ns = 0;
|
uint16_t ns = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
memset(dest, 0, REQUEST_MAXLEN);
|
|
||||||
|
|
||||||
nl = htonl(src->type);
|
nl = htonl(src->type);
|
||||||
memcpy(dest + pos, &nl, sizeof(nl));
|
memcpy(dest + pos, &nl, sizeof(nl));
|
||||||
pos += sizeof(nl);
|
pos += sizeof(nl);
|
||||||
|
|
|
@ -103,16 +103,21 @@ struct wifi_client *__get_client(struct hostapd_client *hclient){
|
||||||
client->authed = false;
|
client->authed = false;
|
||||||
client->freq_highest = 0;
|
client->freq_highest = 0;
|
||||||
__client_setvalues(client, hclient);
|
__client_setvalues(client, hclient);
|
||||||
|
|
||||||
#ifndef MINI
|
#ifndef MINI
|
||||||
struct socket_msg req = {
|
struct socket_msg req = {
|
||||||
.type = SOCKET_MSG_TYPE_CLIENT,
|
.type = SOCKET_MSG_TYPE_CLIENT,
|
||||||
.client = client,
|
.client = client,
|
||||||
}, resp;
|
}, resp = {
|
||||||
|
.client = malloc(sizeof(*client)),
|
||||||
|
};
|
||||||
|
|
||||||
if(socket_request(&req, &resp) == 0){
|
if(socket_request(&req, &resp) == 0){
|
||||||
log_debug("wifi_clients.__get_client("MACSTR"): get client from neigbour\n", MAC2STR(hclient->address));
|
log_debug("wifi_clients.__get_client("MACSTR"): get client from neigbour\n", MAC2STR(hclient->address));
|
||||||
return resp.client;
|
return resp.client;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
client->avl.key = client->addr;
|
client->avl.key = client->addr;
|
||||||
log_debug("wifi_clients.__get_client("MACSTR"): add client to mem\n", MAC2STR(hclient->address));
|
log_debug("wifi_clients.__get_client("MACSTR"): add client to mem\n", MAC2STR(hclient->address));
|
||||||
avl_insert(&clients_by_addr, &client->avl);
|
avl_insert(&clients_by_addr, &client->avl);
|
||||||
|
@ -123,10 +128,23 @@ void wifi_clients_learn(struct hostapd_client *hclient) {
|
||||||
__get_client(hclient);
|
__get_client(hclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MINI
|
||||||
|
#define returnINFO_CLIENT return
|
||||||
|
#else
|
||||||
|
#define returnINFO_CLIENT if(config_client_force_probe && !hclient->auth) socket_info(&msg); return
|
||||||
|
#endif
|
||||||
|
|
||||||
int wifi_clients_try(struct hostapd_client *hclient) {
|
int wifi_clients_try(struct hostapd_client *hclient) {
|
||||||
struct wifi_client *client;
|
struct wifi_client *client;
|
||||||
|
|
||||||
client = __get_client(hclient);
|
client = __get_client(hclient);
|
||||||
|
#ifndef MINI
|
||||||
|
struct socket_msg msg = {
|
||||||
|
.type = SOCKET_MSG_TYPE_CLIENT,
|
||||||
|
.client = client,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
if (hclient->auth) {
|
if (hclient->auth) {
|
||||||
log_info("auth(try=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_auth, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal);
|
log_info("auth(try=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_auth, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal);
|
||||||
|
@ -144,30 +162,30 @@ int wifi_clients_try(struct hostapd_client *hclient) {
|
||||||
if(!hclient->auth){
|
if(!hclient->auth){
|
||||||
client->try_probe = 0;
|
client->try_probe = 0;
|
||||||
log_verbose("accept\n");
|
log_verbose("accept\n");
|
||||||
return 0;
|
returnINFO_CLIENT 0;
|
||||||
}
|
}
|
||||||
log_info("accept\n");
|
log_info("accept\n");
|
||||||
client->try_auth = 0;
|
client->try_auth = 0;
|
||||||
client->connected = 1;
|
client->connected = 1;
|
||||||
return 0;
|
returnINFO_CLIENT 0;
|
||||||
}
|
}
|
||||||
if (client->freq_highest > WIFI_CLIENT_FREQ_THREASHOLD) {
|
if (client->freq_highest > WIFI_CLIENT_FREQ_THREASHOLD) {
|
||||||
if (config_client_force || config_client_force_probe && !hclient->auth) {
|
if (config_client_force || config_client_force_probe && !hclient->auth) {
|
||||||
if(!hclient->auth){
|
if(!hclient->auth){
|
||||||
log_verbose("reject - force\n");
|
log_verbose("reject - force\n");
|
||||||
return -1;
|
returnINFO_CLIENT -1;
|
||||||
}
|
}
|
||||||
log_info("reject - force\n");
|
log_info("reject - force\n");
|
||||||
return -1;
|
returnINFO_CLIENT -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hclient->ssi_signal > config_client_signal_threashold) {
|
if (hclient->ssi_signal > config_client_signal_threashold) {
|
||||||
if(!hclient->auth){
|
if(!hclient->auth){
|
||||||
log_verbose("reject - learned higher freq + ssi is high enough\n");
|
log_verbose("reject - learned higher freq + ssi is high enough\n");
|
||||||
return -1;
|
returnINFO_CLIENT -1;
|
||||||
}
|
}
|
||||||
log_info("reject - learned higher freq + ssi is high enough\n");
|
log_info("reject - learned higher freq + ssi is high enough\n");
|
||||||
return -1;
|
returnINFO_CLIENT -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,25 +195,35 @@ int wifi_clients_try(struct hostapd_client *hclient) {
|
||||||
if(!hclient->auth){
|
if(!hclient->auth){
|
||||||
client->try_probe = 0;
|
client->try_probe = 0;
|
||||||
log_verbose("accept - threashold\n");
|
log_verbose("accept - threashold\n");
|
||||||
return 0;
|
returnINFO_CLIENT 0;
|
||||||
}
|
}
|
||||||
log_info("accept - threashold\n");
|
log_info("accept - threashold\n");
|
||||||
client->try_auth = 0;
|
client->try_auth = 0;
|
||||||
client->connected = 1;
|
client->connected = 1;
|
||||||
return 0;
|
returnINFO_CLIENT 0;
|
||||||
}
|
}
|
||||||
if(!hclient->auth){
|
if(!hclient->auth){
|
||||||
log_verbose("reject\n");
|
log_verbose("reject\n");
|
||||||
return client->try_probe;
|
returnINFO_CLIENT client->try_probe;
|
||||||
}
|
}
|
||||||
log_info("reject\n");
|
log_info("reject\n");
|
||||||
return client->try_auth;
|
returnINFO_CLIENT client->try_auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wifi_clients_disconnect(struct hostapd_client *hclient) {
|
void wifi_clients_disconnect(struct hostapd_client *hclient) {
|
||||||
struct wifi_client *client;
|
struct wifi_client *client;
|
||||||
client = __get_client(hclient);
|
client = __get_client(hclient);
|
||||||
client->connected = 0;
|
client->connected = 0;
|
||||||
|
#ifndef MINI
|
||||||
|
struct socket_msg req = {
|
||||||
|
.type = SOCKET_MSG_TYPE_CLIENT,
|
||||||
|
.client = client,
|
||||||
|
};
|
||||||
|
if(socket_info(&req) == 0){
|
||||||
|
log_error("error on send info about "MACSTR"\n", MAC2STR(hclient->address));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifi_clients_del(const u8 *address) {
|
void wifi_clients_del(const u8 *address) {
|
||||||
|
|
Loading…
Reference in New Issue