commit
0e5a5d31f5
@ -37,7 +37,7 @@ static struct json_object * get_autoupdater(void) {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
uci_free_context(ctx);
|
uci_free_context(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -10,104 +10,104 @@
|
|||||||
|
|
||||||
|
|
||||||
static struct json_object * gluon_site_udata(lua_State *L, int narg) {
|
static struct json_object * gluon_site_udata(lua_State *L, int narg) {
|
||||||
return *(struct json_object **)luaL_checkudata(L, narg, UDATA);
|
return *(struct json_object **)luaL_checkudata(L, narg, UDATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gluon_site_push_none(lua_State *L) {
|
static void gluon_site_push_none(lua_State *L) {
|
||||||
lua_pushlightuserdata(L, gluon_site_push_none);
|
lua_pushlightuserdata(L, gluon_site_push_none);
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gluon_site_do_wrap(lua_State *L, struct json_object *obj) {
|
static void gluon_site_do_wrap(lua_State *L, struct json_object *obj) {
|
||||||
struct json_object **objp = lua_newuserdata(L, sizeof(struct json_object *));
|
struct json_object **objp = lua_newuserdata(L, sizeof(struct json_object *));
|
||||||
*objp = json_object_get(obj);
|
*objp = json_object_get(obj);
|
||||||
luaL_getmetatable(L, UDATA);
|
luaL_getmetatable(L, UDATA);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gluon_site_wrap(lua_State *L, struct json_object *obj) {
|
static void gluon_site_wrap(lua_State *L, struct json_object *obj) {
|
||||||
if (obj)
|
if (obj)
|
||||||
gluon_site_do_wrap(L, obj);
|
gluon_site_do_wrap(L, obj);
|
||||||
else
|
else
|
||||||
gluon_site_push_none(L);
|
gluon_site_push_none(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int gluon_site_index(lua_State *L) {
|
static int gluon_site_index(lua_State *L) {
|
||||||
struct json_object *obj = gluon_site_udata(L, 1);
|
struct json_object *obj = gluon_site_udata(L, 1);
|
||||||
const char *key;
|
const char *key;
|
||||||
lua_Number lua_index;
|
lua_Number lua_index;
|
||||||
size_t index;
|
size_t index;
|
||||||
struct json_object *v = NULL;
|
struct json_object *v = NULL;
|
||||||
|
|
||||||
switch (json_object_get_type(obj)) {
|
switch (json_object_get_type(obj)) {
|
||||||
case json_type_object:
|
case json_type_object:
|
||||||
key = lua_tostring(L, 2);
|
key = lua_tostring(L, 2);
|
||||||
if (key)
|
if (key)
|
||||||
json_object_object_get_ex(obj, key, &v);
|
json_object_object_get_ex(obj, key, &v);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case json_type_array:
|
case json_type_array:
|
||||||
index = lua_index = lua_tonumber(L, 2);
|
index = lua_index = lua_tonumber(L, 2);
|
||||||
if (lua_index == (lua_Number)index && index >= 1)
|
if (lua_index == (lua_Number)index && index >= 1)
|
||||||
v = json_object_array_get_idx(obj, index-1);
|
v = json_object_array_get_idx(obj, index-1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case json_type_string:
|
case json_type_string:
|
||||||
case json_type_null:
|
case json_type_null:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case json_type_boolean:
|
case json_type_boolean:
|
||||||
case json_type_int:
|
case json_type_int:
|
||||||
case json_type_double:
|
case json_type_double:
|
||||||
luaL_error(L, "attempt to index a number or boolean value");
|
luaL_error(L, "attempt to index a number or boolean value");
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
gluon_site_wrap(L, v);
|
gluon_site_wrap(L, v);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gluon_site_call(lua_State *L) {
|
static int gluon_site_call(lua_State *L) {
|
||||||
struct json_object *obj = gluon_site_udata(L, 1);
|
struct json_object *obj = gluon_site_udata(L, 1);
|
||||||
|
|
||||||
if (obj) {
|
if (obj) {
|
||||||
lua_jsonc_push_json(L, obj);
|
lua_jsonc_push_json(L, obj);
|
||||||
} else {
|
} else {
|
||||||
if (lua_isnone(L, 2))
|
if (lua_isnone(L, 2))
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
else
|
else
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gluon_site_gc(lua_State *L) {
|
static int gluon_site_gc(lua_State *L) {
|
||||||
json_object_put(gluon_site_udata(L, 1));
|
json_object_put(gluon_site_udata(L, 1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_reg R[] = {
|
static const luaL_reg R[] = {
|
||||||
{ "__index", gluon_site_index },
|
{ "__index", gluon_site_index },
|
||||||
{ "__call", gluon_site_call },
|
{ "__call", gluon_site_call },
|
||||||
{ "__gc", gluon_site_gc },
|
{ "__gc", gluon_site_gc },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
int luaopen_gluon_site(lua_State *L) {
|
int luaopen_gluon_site(lua_State *L) {
|
||||||
luaL_newmetatable(L, UDATA);
|
luaL_newmetatable(L, UDATA);
|
||||||
luaL_register(L, NULL, R);
|
luaL_register(L, NULL, R);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Create "none" object */
|
/* Create "none" object */
|
||||||
lua_pushlightuserdata(L, gluon_site_push_none);
|
lua_pushlightuserdata(L, gluon_site_push_none);
|
||||||
gluon_site_do_wrap(L, NULL);
|
gluon_site_do_wrap(L, NULL);
|
||||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
struct json_object *site = gluonutil_load_site_config();
|
struct json_object *site = gluonutil_load_site_config();
|
||||||
gluon_site_wrap(L, site);
|
gluon_site_wrap(L, site);
|
||||||
json_object_put(site);
|
json_object_put(site);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "lookup3.h"
|
#include "lookup3.h"
|
||||||
|
|
||||||
static struct addr_list *addr_node_alloc(void *addr,
|
static struct addr_list *addr_node_alloc(void *addr,
|
||||||
struct addr_store *store)
|
struct addr_store *store)
|
||||||
{
|
{
|
||||||
struct addr_list *node;
|
struct addr_list *node;
|
||||||
size_t addr_len = store->addr_len;
|
size_t addr_len = store->addr_len;
|
||||||
@ -27,8 +27,8 @@ static struct addr_list *addr_node_alloc(void *addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct addr_list *addr_list_search(void *addr,
|
static struct addr_list *addr_list_search(void *addr,
|
||||||
size_t addr_len,
|
size_t addr_len,
|
||||||
struct addr_list *list)
|
struct addr_list *list)
|
||||||
{
|
{
|
||||||
struct addr_list *node = list;
|
struct addr_list *node = list;
|
||||||
struct addr_list *ret = NULL;
|
struct addr_list *ret = NULL;
|
||||||
@ -73,7 +73,7 @@ int addr_store_add(void *addr, struct addr_store *store)
|
|||||||
{
|
{
|
||||||
struct addr_list **bucket = addr_store_get_bucket(addr, store);
|
struct addr_list **bucket = addr_store_get_bucket(addr, store);
|
||||||
struct addr_list *node = addr_list_search(addr, store->addr_len,
|
struct addr_list *node = addr_list_search(addr, store->addr_len,
|
||||||
*bucket);
|
*bucket);
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
node->tic = clock;
|
node->tic = clock;
|
||||||
@ -91,9 +91,9 @@ int addr_store_add(void *addr, struct addr_store *store)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int addr_store_init(size_t addr_len,
|
int addr_store_init(size_t addr_len,
|
||||||
void (*destructor)(struct addr_list *),
|
void (*destructor)(struct addr_list *),
|
||||||
char *(*ntoa)(void *),
|
char *(*ntoa)(void *),
|
||||||
struct addr_store *store)
|
struct addr_store *store)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ struct addr_store {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int addr_store_init(size_t addr_len,
|
int addr_store_init(size_t addr_len,
|
||||||
void (*destructor)(struct addr_list *),
|
void (*destructor)(struct addr_list *),
|
||||||
char *(*ntoa)(void *),
|
char *(*ntoa)(void *),
|
||||||
struct addr_store *store);
|
struct addr_store *store);
|
||||||
int addr_store_add(void *addr, struct addr_store *store);
|
int addr_store_add(void *addr, struct addr_store *store);
|
||||||
void addr_store_cleanup(struct addr_store *store);
|
void addr_store_cleanup(struct addr_store *store);
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ static void ebt_ip_call(char *mod, struct in_addr ip)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
snprintf(str, sizeof(str),
|
snprintf(str, sizeof(str),
|
||||||
EBTABLES " %s ARP_LIMIT_DATCHECK -p ARP --arp-ip-dst %s -j mark --mark-or 0x2 --mark-target RETURN",
|
EBTABLES " %s ARP_LIMIT_DATCHECK -p ARP --arp-ip-dst %s -j mark --mark-or 0x2 --mark-target RETURN",
|
||||||
mod, inet_ntoa(ip));
|
mod, inet_ntoa(ip));
|
||||||
|
|
||||||
ret = system(str);
|
ret = system(str);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -62,8 +62,8 @@ static void ebt_mac_limit_call(char *mod, struct mac_addr *mac)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
snprintf(str, sizeof(str),
|
snprintf(str, sizeof(str),
|
||||||
EBTABLES " %s ARP_LIMIT_TLCHECK --source %s --limit 6/min --limit-burst 50 -j RETURN",
|
EBTABLES " %s ARP_LIMIT_TLCHECK --source %s --limit 6/min --limit-burst 50 -j RETURN",
|
||||||
mod, mac_ntoa(mac));
|
mod, mac_ntoa(mac));
|
||||||
|
|
||||||
ret = system(str);
|
ret = system(str);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -78,8 +78,8 @@ static void ebt_mac_ret_call(char *mod, struct mac_addr *mac, int add)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
snprintf(str, sizeof(str),
|
snprintf(str, sizeof(str),
|
||||||
EBTABLES " %s ARP_LIMIT_TLCHECK %s --source %s -j DROP",
|
EBTABLES " %s ARP_LIMIT_TLCHECK %s --source %s -j DROP",
|
||||||
mod, add ? "2" : "", mac_ntoa(mac));
|
mod, add ? "2" : "", mac_ntoa(mac));
|
||||||
|
|
||||||
ret = system(str);
|
ret = system(str);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,8 +21,8 @@ int mac_aton(const char *cp, struct mac_addr *mac)
|
|||||||
memset(&m, 0, sizeof(m));
|
memset(&m, 0, sizeof(m));
|
||||||
|
|
||||||
ret = sscanf(cp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
|
ret = sscanf(cp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
|
||||||
&m.storage[0], &m.storage[1], &m.storage[2],
|
&m.storage[0], &m.storage[1], &m.storage[2],
|
||||||
&m.storage[3], &m.storage[4], &m.storage[5]);
|
&m.storage[3], &m.storage[4], &m.storage[5]);
|
||||||
|
|
||||||
if (ret != ETH_ALEN)
|
if (ret != ETH_ALEN)
|
||||||
return 0;
|
return 0;
|
||||||
@ -36,8 +36,8 @@ char *mac_ntoa(struct mac_addr *mac)
|
|||||||
unsigned char *m = mac->storage;
|
unsigned char *m = mac->storage;
|
||||||
|
|
||||||
snprintf(mntoa_buf, sizeof(mntoa_buf),
|
snprintf(mntoa_buf, sizeof(mntoa_buf),
|
||||||
"%02x:%02x:%02x:%02x:%02x:%02x",
|
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
m[0], m[1], m[2], m[3], m[4], m[5]);
|
m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||||
|
|
||||||
return mntoa_buf;
|
return mntoa_buf;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
char mac1[18];
|
char mac1[18];
|
||||||
|
|
||||||
opts = batadv_container_of(query_opts, struct neigh_netlink_opts,
|
opts = batadv_container_of(query_opts, struct neigh_netlink_opts,
|
||||||
query_opts);
|
query_opts);
|
||||||
|
|
||||||
if (!genlmsg_valid_hdr(nlh, 0))
|
if (!genlmsg_valid_hdr(nlh, 0))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
@ -79,11 +79,11 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy))
|
genlmsg_len(ghdr), batadv_genl_policy))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory,
|
if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory,
|
||||||
BATADV_ARRAY_SIZE(parse_orig_list_mandatory)))
|
BATADV_ARRAY_SIZE(parse_orig_list_mandatory)))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
|
orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
|
||||||
|
@ -106,7 +106,7 @@ static bool interface_file_exists(const char *ifname, const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mesh_add_subif(const char *ifname, struct json_object *wireless,
|
static void mesh_add_subif(const char *ifname, struct json_object *wireless,
|
||||||
struct json_object *tunnel, struct json_object *other) {
|
struct json_object *tunnel, struct json_object *other) {
|
||||||
struct json_object *address = gluonutil_wrap_and_free_string(gluonutil_get_interface_address(ifname));
|
struct json_object *address = gluonutil_wrap_and_free_string(gluonutil_get_interface_address(ifname));
|
||||||
|
|
||||||
/* In case of VLAN and bridge interfaces, we want the lower interface
|
/* In case of VLAN and bridge interfaces, we want the lower interface
|
||||||
@ -144,7 +144,7 @@ static struct json_object * get_mesh_subifs(const char *ifname) {
|
|||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < lower.gl_pathc; i++) {
|
for (i = 0; i < lower.gl_pathc; i++) {
|
||||||
mesh_add_subif(lower.gl_pathv[i] + pattern_len - 1,
|
mesh_add_subif(lower.gl_pathv[i] + pattern_len - 1,
|
||||||
wireless, tunnel, other);
|
wireless, tunnel, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
globfree(&lower);
|
globfree(&lower);
|
||||||
|
@ -57,7 +57,7 @@ static int parse_gw_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
char addr[18];
|
char addr[18];
|
||||||
|
|
||||||
opts = batadv_container_of(query_opts, struct gw_netlink_opts,
|
opts = batadv_container_of(query_opts, struct gw_netlink_opts,
|
||||||
query_opts);
|
query_opts);
|
||||||
|
|
||||||
if (!genlmsg_valid_hdr(nlh, 0))
|
if (!genlmsg_valid_hdr(nlh, 0))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
@ -68,11 +68,11 @@ static int parse_gw_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy))
|
genlmsg_len(ghdr), batadv_genl_policy))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (batadv_genl_missing_attrs(attrs, gateways_mandatory,
|
if (batadv_genl_missing_attrs(attrs, gateways_mandatory,
|
||||||
BATADV_ARRAY_SIZE(gateways_mandatory)))
|
BATADV_ARRAY_SIZE(gateways_mandatory)))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (!attrs[BATADV_ATTR_FLAG_BEST])
|
if (!attrs[BATADV_ATTR_FLAG_BEST])
|
||||||
@ -105,8 +105,8 @@ static void add_gateway(struct json_object *obj) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
batadv_genl_query("bat0", BATADV_CMD_GET_GATEWAYS,
|
batadv_genl_query("bat0", BATADV_CMD_GET_GATEWAYS,
|
||||||
parse_gw_list_netlink_cb, NLM_F_DUMP,
|
parse_gw_list_netlink_cb, NLM_F_DUMP,
|
||||||
&opts.query_opts);
|
&opts.query_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool ethtool_ioctl(int fd, struct ifreq *ifr, void *data) {
|
static inline bool ethtool_ioctl(int fd, struct ifreq *ifr, void *data) {
|
||||||
@ -214,7 +214,7 @@ static struct json_object * get_traffic(void) {
|
|||||||
json_object_object_add(ret, "mgmt_rx", mgmt_rx);
|
json_object_object_add(ret, "mgmt_rx", mgmt_rx);
|
||||||
json_object_object_add(ret, "mgmt_tx", mgmt_tx);
|
json_object_object_add(ret, "mgmt_tx", mgmt_tx);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(stats);
|
free(stats);
|
||||||
free(strings);
|
free(strings);
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -241,7 +241,7 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
uint32_t flags, lastseen;
|
uint32_t flags, lastseen;
|
||||||
|
|
||||||
opts = batadv_container_of(query_opts, struct clients_netlink_opts,
|
opts = batadv_container_of(query_opts, struct clients_netlink_opts,
|
||||||
query_opts);
|
query_opts);
|
||||||
|
|
||||||
if (!genlmsg_valid_hdr(nlh, 0))
|
if (!genlmsg_valid_hdr(nlh, 0))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
@ -252,11 +252,11 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy))
|
genlmsg_len(ghdr), batadv_genl_policy))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (batadv_genl_missing_attrs(attrs, clients_mandatory,
|
if (batadv_genl_missing_attrs(attrs, clients_mandatory,
|
||||||
BATADV_ARRAY_SIZE(clients_mandatory)))
|
BATADV_ARRAY_SIZE(clients_mandatory)))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
flags = nla_get_u32(attrs[BATADV_ATTR_TT_FLAGS]);
|
flags = nla_get_u32(attrs[BATADV_ATTR_TT_FLAGS]);
|
||||||
@ -282,8 +282,8 @@ static struct json_object * get_clients(void) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
batadv_genl_query("bat0", BATADV_CMD_GET_TRANSTABLE_LOCAL,
|
batadv_genl_query("bat0", BATADV_CMD_GET_TRANSTABLE_LOCAL,
|
||||||
parse_clients_list_netlink_cb, NLM_F_DUMP,
|
parse_clients_list_netlink_cb, NLM_F_DUMP,
|
||||||
&opts.query_opts);
|
&opts.query_opts);
|
||||||
|
|
||||||
struct json_object *ret = json_object_new_object();
|
struct json_object *ret = json_object_new_object();
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ static bool get_peer_connection(struct json_object **ret, struct json_object *co
|
|||||||
|
|
||||||
struct json_object *peer, *connection, *established;
|
struct json_object *peer, *connection, *established;
|
||||||
if (!json_object_object_get_ex(peers, key, &peer) ||
|
if (!json_object_object_get_ex(peers, key, &peer) ||
|
||||||
!json_object_object_get_ex(peer, "connection", &connection))
|
!json_object_object_get_ex(peer, "connection", &connection))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (json_object_object_get_ex(connection, "established", &established)) {
|
if (json_object_object_get_ex(connection, "established", &established)) {
|
||||||
@ -242,7 +242,7 @@ static struct json_object * get_peer_group(struct json_object *config, struct js
|
|||||||
|
|
||||||
struct json_object *config_peers;
|
struct json_object *config_peers;
|
||||||
if (json_object_object_get_ex(config, "peers", &config_peers) &&
|
if (json_object_object_get_ex(config, "peers", &config_peers) &&
|
||||||
json_object_is_type(config_peers, json_type_object)) {
|
json_object_is_type(config_peers, json_type_object)) {
|
||||||
struct json_object *ret_peers = json_object_new_object();
|
struct json_object *ret_peers = json_object_new_object();
|
||||||
|
|
||||||
json_object_object_foreach(config_peers, peername, peerconfig) {
|
json_object_object_foreach(config_peers, peername, peerconfig) {
|
||||||
@ -320,7 +320,7 @@ static struct json_object * get_mesh_vpn(void) {
|
|||||||
|
|
||||||
ret = get_peer_group(mesh_vpn_fastd, peers);
|
ret = get_peer_group(mesh_vpn_fastd, peers);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
json_object_put(site);
|
json_object_put(site);
|
||||||
json_object_put(status);
|
json_object_put(status);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ static struct json_object * stdout_read(const char *cmd, const char *skip, bool
|
|||||||
if (oneword) {
|
if (oneword) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (isspace(line[i])) {
|
if (isspace(line[i])) {
|
||||||
line[i] = 0;
|
line[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ void resize_recvbuffer(char **recvbuffer, size_t *recvbuffer_len, size_t recvlen
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len,
|
ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len,
|
||||||
const struct timeval *timeout) {
|
const struct timeval *timeout) {
|
||||||
struct timeval now, timeout_left;
|
struct timeval now, timeout_left;
|
||||||
ssize_t recvlen;
|
ssize_t recvlen;
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int request(const int sock, char **recvbuffer, size_t *recvbuffer_len,
|
int request(const int sock, char **recvbuffer, size_t *recvbuffer_len,
|
||||||
const struct sockaddr_in6 *client_addr, const char *request,
|
const struct sockaddr_in6 *client_addr, const char *request,
|
||||||
const char *sse, double timeout, unsigned int max_count) {
|
const char *sse, double timeout, unsigned int max_count) {
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr,
|
ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr,
|
||||||
request_string, sse, timeout, max_count);
|
request_string, sse, timeout, max_count);
|
||||||
} while(loop);
|
} while(loop);
|
||||||
|
|
||||||
if (sse)
|
if (sse)
|
||||||
|
@ -59,10 +59,10 @@
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define CHECK(stmt) \
|
#define CHECK(stmt) \
|
||||||
if(!(stmt)) { \
|
if(!(stmt)) { \
|
||||||
fprintf(stderr, "check failed: " #stmt "\n"); \
|
fprintf(stderr, "check failed: " #stmt "\n"); \
|
||||||
goto check_failed; \
|
goto check_failed; \
|
||||||
}
|
}
|
||||||
#define DEBUG_MSG(msg, ...) fprintf(stderr, msg "\n", ##__VA_ARGS__)
|
#define DEBUG_MSG(msg, ...) fprintf(stderr, msg "\n", ##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define CHECK(stmt) if(!(stmt)) goto check_failed;
|
#define CHECK(stmt) if(!(stmt)) goto check_failed;
|
||||||
@ -78,8 +78,8 @@
|
|||||||
|
|
||||||
#define foreach_safe(item, safe, list) \
|
#define foreach_safe(item, safe, list) \
|
||||||
for ((item) = (list); \
|
for ((item) = (list); \
|
||||||
(item) && (((safe) = item->next) || 1); \
|
(item) && (((safe) = item->next) || 1); \
|
||||||
(item) = (safe))
|
(item) = (safe))
|
||||||
|
|
||||||
struct router {
|
struct router {
|
||||||
struct router *next;
|
struct router *next;
|
||||||
@ -103,7 +103,7 @@ static struct global {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int fork_execvp_timeout(struct timespec *timeout, const char *file,
|
static int fork_execvp_timeout(struct timespec *timeout, const char *file,
|
||||||
const char *const argv[]);
|
const char *const argv[]);
|
||||||
|
|
||||||
static void error_message(int status, int errnum, char *message, ...) {
|
static void error_message(int status, int errnum, char *message, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -120,7 +120,7 @@ static void error_message(int status, int errnum, char *message, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int timespec_diff(struct timespec *tv1, struct timespec *tv2,
|
static int timespec_diff(struct timespec *tv1, struct timespec *tv2,
|
||||||
struct timespec *tvdiff)
|
struct timespec *tvdiff)
|
||||||
{
|
{
|
||||||
tvdiff->tv_sec = tv1->tv_sec - tv2->tv_sec;
|
tvdiff->tv_sec = tv1->tv_sec - tv2->tv_sec;
|
||||||
if (tv1->tv_nsec < tv2->tv_nsec) {
|
if (tv1->tv_nsec < tv2->tv_nsec) {
|
||||||
@ -219,8 +219,8 @@ static int init_packet_socket(unsigned int ifindex) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sock_fprog radv_filter = {
|
struct sock_fprog radv_filter = {
|
||||||
.len = ARRAY_SIZE(radv_filter_code),
|
.len = ARRAY_SIZE(radv_filter_code),
|
||||||
.filter = radv_filter_code,
|
.filter = radv_filter_code,
|
||||||
};
|
};
|
||||||
|
|
||||||
int sock = socket(AF_PACKET, SOCK_DGRAM|SOCK_CLOEXEC, htons(ETH_P_IPV6));
|
int sock = socket(AF_PACKET, SOCK_DGRAM|SOCK_CLOEXEC, htons(ETH_P_IPV6));
|
||||||
@ -382,7 +382,7 @@ static void expire_routers(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int parse_tt_global(struct nl_msg *msg,
|
static int parse_tt_global(struct nl_msg *msg,
|
||||||
void *arg __attribute__((unused)))
|
void *arg __attribute__((unused)))
|
||||||
{
|
{
|
||||||
static const enum batadv_nl_attrs mandatory[] = {
|
static const enum batadv_nl_attrs mandatory[] = {
|
||||||
BATADV_ATTR_TT_ADDRESS,
|
BATADV_ATTR_TT_ADDRESS,
|
||||||
@ -406,7 +406,7 @@ static int parse_tt_global(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy)) {
|
genlmsg_len(ghdr), batadv_genl_policy)) {
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,14 +428,14 @@ static int parse_tt_global(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
DEBUG_MSG("Found originator for " F_MAC ", it's " F_MAC,
|
DEBUG_MSG("Found originator for " F_MAC ", it's " F_MAC,
|
||||||
F_MAC_VAR(router->src), F_MAC_VAR(mac_b));
|
F_MAC_VAR(router->src), F_MAC_VAR(mac_b));
|
||||||
router->originator = mac_b;
|
router->originator = mac_b;
|
||||||
|
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_originator(struct nl_msg *msg,
|
static int parse_originator(struct nl_msg *msg,
|
||||||
void *arg __attribute__((unused)))
|
void *arg __attribute__((unused)))
|
||||||
{
|
{
|
||||||
|
|
||||||
static const enum batadv_nl_attrs mandatory[] = {
|
static const enum batadv_nl_attrs mandatory[] = {
|
||||||
@ -460,7 +460,7 @@ static int parse_originator(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy)) {
|
genlmsg_len(ghdr), batadv_genl_policy)) {
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ static int parse_originator(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
DEBUG_MSG("Found TQ for router " F_MAC " (originator " F_MAC "), it's %d",
|
DEBUG_MSG("Found TQ for router " F_MAC " (originator " F_MAC "), it's %d",
|
||||||
F_MAC_VAR(router->src), F_MAC_VAR(router->originator), tq);
|
F_MAC_VAR(router->src), F_MAC_VAR(router->originator), tq);
|
||||||
router->tq = tq;
|
router->tq = tq;
|
||||||
if (router->tq > G.max_tq)
|
if (router->tq > G.max_tq)
|
||||||
G.max_tq = router->tq;
|
G.max_tq = router->tq;
|
||||||
@ -490,7 +490,7 @@ static int parse_originator(struct nl_msg *msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int parse_tt_local(struct nl_msg *msg,
|
static int parse_tt_local(struct nl_msg *msg,
|
||||||
void *arg __attribute__((unused)))
|
void *arg __attribute__((unused)))
|
||||||
{
|
{
|
||||||
static const enum batadv_nl_attrs mandatory[] = {
|
static const enum batadv_nl_attrs mandatory[] = {
|
||||||
BATADV_ATTR_TT_ADDRESS,
|
BATADV_ATTR_TT_ADDRESS,
|
||||||
@ -512,7 +512,7 @@ static int parse_tt_local(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy)) {
|
genlmsg_len(ghdr), batadv_genl_policy)) {
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +528,7 @@ static int parse_tt_local(struct nl_msg *msg,
|
|||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
DEBUG_MSG("Found router " F_MAC " in transtable_local, assigning TQ %d",
|
DEBUG_MSG("Found router " F_MAC " in transtable_local, assigning TQ %d",
|
||||||
F_MAC_VAR(router->src), LOCAL_TQ);
|
F_MAC_VAR(router->src), LOCAL_TQ);
|
||||||
router->tq = LOCAL_TQ;
|
router->tq = LOCAL_TQ;
|
||||||
if (router->tq > G.max_tq)
|
if (router->tq > G.max_tq)
|
||||||
G.max_tq = router->tq;
|
G.max_tq = router->tq;
|
||||||
@ -770,7 +770,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
if (G.routers != NULL &&
|
if (G.routers != NULL &&
|
||||||
timespec_diff(&now, &next_update, &diff)) {
|
timespec_diff(&now, &next_update, &diff)) {
|
||||||
expire_routers();
|
expire_routers();
|
||||||
|
|
||||||
// all routers could have expired, check again
|
// all routers could have expired, check again
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
&(var).ether_addr_octet[2], &(var).ether_addr_octet[3], \
|
&(var).ether_addr_octet[2], &(var).ether_addr_octet[3], \
|
||||||
&(var).ether_addr_octet[4], &(var).ether_addr_octet[5]
|
&(var).ether_addr_octet[4], &(var).ether_addr_octet[5]
|
||||||
#define MAC2ETHER(_ether, _mac) memcpy((_ether).ether_addr_octet, \
|
#define MAC2ETHER(_ether, _mac) memcpy((_ether).ether_addr_octet, \
|
||||||
(_mac), ETH_ALEN)
|
(_mac), ETH_ALEN)
|
||||||
|
|
||||||
#define ether_addr_equal(_a, _b) (memcmp((_a).ether_addr_octet, \
|
#define ether_addr_equal(_a, _b) (memcmp((_a).ether_addr_octet, \
|
||||||
(_b).ether_addr_octet, ETH_ALEN) == 0)
|
(_b).ether_addr_octet, ETH_ALEN) == 0)
|
||||||
|
@ -34,8 +34,8 @@ static struct json_object * get_wifi_neighbours(const char *ifname) {
|
|||||||
|
|
||||||
char mac[18];
|
char mac[18];
|
||||||
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
|
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
entry->mac[0], entry->mac[1], entry->mac[2],
|
entry->mac[0], entry->mac[1], entry->mac[2],
|
||||||
entry->mac[3], entry->mac[4], entry->mac[5]);
|
entry->mac[3], entry->mac[4], entry->mac[5]);
|
||||||
|
|
||||||
json_object_object_add(neighbours, mac, obj);
|
json_object_object_add(neighbours, mac, obj);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ static struct json_object * get_stat(void) {
|
|||||||
if (!strcmp(label, "cpu")) {
|
if (!strcmp(label, "cpu")) {
|
||||||
int64_t user, nice, system, idle, iowait, irq, softirq;
|
int64_t user, nice, system, idle, iowait, irq, softirq;
|
||||||
if (sscanf(line, "%*s %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64,
|
if (sscanf(line, "%*s %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64,
|
||||||
&user, &nice, &system, &idle, &iowait, &irq, &softirq) != 7)
|
&user, &nice, &system, &idle, &iowait, &irq, &softirq) != 7)
|
||||||
goto invalid_stat_format;
|
goto invalid_stat_format;
|
||||||
|
|
||||||
struct json_object *cpu = json_object_new_object();
|
struct json_object *cpu = json_object_new_object();
|
||||||
@ -253,7 +253,7 @@ static void count_stations(size_t *wifi24, size_t *wifi5, size_t *owe24, size_t
|
|||||||
count_iface_stations(wifi24, wifi5, ifname);
|
count_iface_stations(wifi24, wifi5, ifname);
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
uci_free_context(ctx);
|
uci_free_context(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,116 +10,116 @@
|
|||||||
#define XSTR(x) STR(x)
|
#define XSTR(x) STR(x)
|
||||||
|
|
||||||
struct neigh_netlink_opts {
|
struct neigh_netlink_opts {
|
||||||
struct json_object *obj;
|
struct json_object *obj;
|
||||||
struct batadv_nlquery_opts query_opts;
|
struct batadv_nlquery_opts query_opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const enum batadv_nl_attrs parse_orig_list_mandatory[] = {
|
static const enum batadv_nl_attrs parse_orig_list_mandatory[] = {
|
||||||
BATADV_ATTR_ORIG_ADDRESS,
|
BATADV_ATTR_ORIG_ADDRESS,
|
||||||
BATADV_ATTR_NEIGH_ADDRESS,
|
BATADV_ATTR_NEIGH_ADDRESS,
|
||||||
BATADV_ATTR_TQ,
|
BATADV_ATTR_TQ,
|
||||||
BATADV_ATTR_HARD_IFINDEX,
|
BATADV_ATTR_HARD_IFINDEX,
|
||||||
BATADV_ATTR_LAST_SEEN_MSECS,
|
BATADV_ATTR_LAST_SEEN_MSECS,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
||||||
{
|
{
|
||||||
struct nlattr *attrs[BATADV_ATTR_MAX+1];
|
struct nlattr *attrs[BATADV_ATTR_MAX+1];
|
||||||
struct nlmsghdr *nlh = nlmsg_hdr(msg);
|
struct nlmsghdr *nlh = nlmsg_hdr(msg);
|
||||||
struct batadv_nlquery_opts *query_opts = arg;
|
struct batadv_nlquery_opts *query_opts = arg;
|
||||||
struct genlmsghdr *ghdr;
|
struct genlmsghdr *ghdr;
|
||||||
uint8_t *orig;
|
uint8_t *orig;
|
||||||
uint8_t *dest;
|
uint8_t *dest;
|
||||||
uint8_t tq;
|
uint8_t tq;
|
||||||
uint32_t hardif;
|
uint32_t hardif;
|
||||||
char ifname_buf[IF_NAMESIZE], *ifname;
|
char ifname_buf[IF_NAMESIZE], *ifname;
|
||||||
struct neigh_netlink_opts *opts;
|
struct neigh_netlink_opts *opts;
|
||||||
char mac1[18];
|
char mac1[18];
|
||||||
|
|
||||||
opts = batadv_container_of(query_opts, struct neigh_netlink_opts, query_opts);
|
opts = batadv_container_of(query_opts, struct neigh_netlink_opts, query_opts);
|
||||||
|
|
||||||
if (!genlmsg_valid_hdr(nlh, 0))
|
if (!genlmsg_valid_hdr(nlh, 0))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
ghdr = nlmsg_data(nlh);
|
ghdr = nlmsg_data(nlh);
|
||||||
|
|
||||||
if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS)
|
if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS)
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
|
||||||
genlmsg_len(ghdr), batadv_genl_policy))
|
genlmsg_len(ghdr), batadv_genl_policy))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory,
|
if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory,
|
||||||
BATADV_ARRAY_SIZE(parse_orig_list_mandatory)))
|
BATADV_ARRAY_SIZE(parse_orig_list_mandatory)))
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
|
orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
|
||||||
dest = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]);
|
dest = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]);
|
||||||
tq = nla_get_u8(attrs[BATADV_ATTR_TQ]);
|
tq = nla_get_u8(attrs[BATADV_ATTR_TQ]);
|
||||||
hardif = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]);
|
hardif = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]);
|
||||||
|
|
||||||
if (memcmp(orig, dest, 6) != 0)
|
if (memcmp(orig, dest, 6) != 0)
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
ifname = if_indextoname(hardif, ifname_buf);
|
ifname = if_indextoname(hardif, ifname_buf);
|
||||||
if (!ifname)
|
if (!ifname)
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
sprintf(mac1, "%02x:%02x:%02x:%02x:%02x:%02x",
|
sprintf(mac1, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
orig[0], orig[1], orig[2], orig[3], orig[4], orig[5]);
|
orig[0], orig[1], orig[2], orig[3], orig[4], orig[5]);
|
||||||
|
|
||||||
struct json_object *neigh = json_object_new_object();
|
struct json_object *neigh = json_object_new_object();
|
||||||
if (!neigh)
|
if (!neigh)
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255));
|
json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255));
|
||||||
json_object_object_add(neigh, "ifname", json_object_new_string(ifname));
|
json_object_object_add(neigh, "ifname", json_object_new_string(ifname));
|
||||||
json_object_object_add(neigh, "best", json_object_new_boolean(attrs[BATADV_ATTR_FLAG_BEST]));
|
json_object_object_add(neigh, "best", json_object_new_boolean(attrs[BATADV_ATTR_FLAG_BEST]));
|
||||||
|
|
||||||
json_object_object_add(opts->obj, mac1, neigh);
|
json_object_object_add(opts->obj, mac1, neigh);
|
||||||
|
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static json_object *neighbours(void) {
|
static json_object *neighbours(void) {
|
||||||
struct neigh_netlink_opts opts = {
|
struct neigh_netlink_opts opts = {
|
||||||
.query_opts = {
|
.query_opts = {
|
||||||
.err = 0,
|
.err = 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
opts.obj = json_object_new_object();
|
opts.obj = json_object_new_object();
|
||||||
if (!opts.obj)
|
if (!opts.obj)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = batadv_genl_query("bat0", BATADV_CMD_GET_ORIGINATORS,
|
ret = batadv_genl_query("bat0", BATADV_CMD_GET_ORIGINATORS,
|
||||||
parse_orig_list_netlink_cb, NLM_F_DUMP,
|
parse_orig_list_netlink_cb, NLM_F_DUMP,
|
||||||
&opts.query_opts);
|
&opts.query_opts);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
json_object_put(opts.obj);
|
json_object_put(opts.obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return opts.obj;
|
return opts.obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
struct json_object *obj;
|
struct json_object *obj;
|
||||||
|
|
||||||
printf("Content-type: text/event-stream\n\n");
|
printf("Content-type: text/event-stream\n\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
obj = neighbours();
|
obj = neighbours();
|
||||||
if (obj) {
|
if (obj) {
|
||||||
printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN));
|
printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
json_object_put(obj);
|
json_object_put(obj);
|
||||||
}
|
}
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,115 +12,115 @@
|
|||||||
#define LOWERGLOB_SUFFIX "/lower_*"
|
#define LOWERGLOB_SUFFIX "/lower_*"
|
||||||
|
|
||||||
static struct json_object *get_stations(const struct iwinfo_ops *iw, const char *ifname) {
|
static struct json_object *get_stations(const struct iwinfo_ops *iw, const char *ifname) {
|
||||||
int len;
|
int len;
|
||||||
char buf[IWINFO_BUFSIZE];
|
char buf[IWINFO_BUFSIZE];
|
||||||
struct json_object *stations = json_object_new_object();
|
struct json_object *stations = json_object_new_object();
|
||||||
|
|
||||||
if (iw->assoclist(ifname, buf, &len) == -1)
|
if (iw->assoclist(ifname, buf, &len) == -1)
|
||||||
return stations;
|
return stations;
|
||||||
|
|
||||||
// This is just: for entry in assoclist(ifname)
|
// This is just: for entry in assoclist(ifname)
|
||||||
for (struct iwinfo_assoclist_entry *entry = (struct iwinfo_assoclist_entry *)buf;
|
for (struct iwinfo_assoclist_entry *entry = (struct iwinfo_assoclist_entry *)buf;
|
||||||
(char*)(entry+1) <= buf + len; entry++) {
|
(char*)(entry+1) <= buf + len; entry++) {
|
||||||
struct json_object *station = json_object_new_object();
|
struct json_object *station = json_object_new_object();
|
||||||
|
|
||||||
json_object_object_add(station, "signal", json_object_new_int(entry->signal));
|
json_object_object_add(station, "signal", json_object_new_int(entry->signal));
|
||||||
json_object_object_add(station, "noise", json_object_new_int(entry->noise));
|
json_object_object_add(station, "noise", json_object_new_int(entry->noise));
|
||||||
json_object_object_add(station, "inactive", json_object_new_int(entry->inactive));
|
json_object_object_add(station, "inactive", json_object_new_int(entry->inactive));
|
||||||
|
|
||||||
char macstr[18];
|
char macstr[18];
|
||||||
|
|
||||||
snprintf(macstr, sizeof(macstr), "%02x:%02x:%02x:%02x:%02x:%02x",
|
snprintf(macstr, sizeof(macstr), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
entry->mac[0], entry->mac[1], entry->mac[2],
|
entry->mac[0], entry->mac[1], entry->mac[2],
|
||||||
entry->mac[3], entry->mac[4], entry->mac[5]);
|
entry->mac[3], entry->mac[4], entry->mac[5]);
|
||||||
|
|
||||||
json_object_object_add(stations, macstr, station);
|
json_object_object_add(stations, macstr, station);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stations;
|
return stations;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void badrequest() {
|
static void badrequest() {
|
||||||
printf("Status: 400 Bad Request\n\n");
|
printf("Status: 400 Bad Request\n\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recurse down to the lowest layer-2 interface
|
// recurse down to the lowest layer-2 interface
|
||||||
static int interface_get_lowest(const char *ifname, char *hwifname);
|
static int interface_get_lowest(const char *ifname, char *hwifname);
|
||||||
static int interface_get_lowest(const char *ifname, char *hwifname) {
|
static int interface_get_lowest(const char *ifname, char *hwifname) {
|
||||||
glob_t globbuf;
|
glob_t globbuf;
|
||||||
char *fnamebuf = alloca(1 + strlen(VIRTIF_PREFIX) + IF_NAMESIZE +
|
char *fnamebuf = alloca(1 + strlen(VIRTIF_PREFIX) + IF_NAMESIZE +
|
||||||
strlen(LOWERGLOB_SUFFIX));
|
strlen(LOWERGLOB_SUFFIX));
|
||||||
char *lowentry = NULL;
|
char *lowentry = NULL;
|
||||||
|
|
||||||
|
|
||||||
sprintf(fnamebuf, "%s%s%s", VIRTIF_PREFIX, ifname, LOWERGLOB_SUFFIX);
|
sprintf(fnamebuf, "%s%s%s", VIRTIF_PREFIX, ifname, LOWERGLOB_SUFFIX);
|
||||||
glob(fnamebuf, GLOB_NOSORT | GLOB_NOESCAPE, NULL, &globbuf);
|
glob(fnamebuf, GLOB_NOSORT | GLOB_NOESCAPE, NULL, &globbuf);
|
||||||
|
|
||||||
if (globbuf.gl_pathc == 1) {
|
if (globbuf.gl_pathc == 1) {
|
||||||
lowentry = alloca(1 + strlen(globbuf.gl_pathv[0]));
|
lowentry = alloca(1 + strlen(globbuf.gl_pathv[0]));
|
||||||
strncpy(lowentry, globbuf.gl_pathv[0], 1 + strlen(globbuf.gl_pathv[0]));
|
strncpy(lowentry, globbuf.gl_pathv[0], 1 + strlen(globbuf.gl_pathv[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
globfree(&globbuf);
|
globfree(&globbuf);
|
||||||
|
|
||||||
if (!lowentry) {
|
if (!lowentry) {
|
||||||
char *path = alloca(1 + strlen(NETIF_PREFIX) + strlen(ifname));
|
char *path = alloca(1 + strlen(NETIF_PREFIX) + strlen(ifname));
|
||||||
sprintf(path, "%s%s", NETIF_PREFIX, ifname);
|
sprintf(path, "%s%s", NETIF_PREFIX, ifname);
|
||||||
|
|
||||||
if(access(path, F_OK) != 0)
|
if(access(path, F_OK) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
strncpy(hwifname, ifname, IF_NAMESIZE - 1);
|
strncpy(hwifname, ifname, IF_NAMESIZE - 1);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if ((len = readlink(lowentry, buf, sizeof(buf)-1)) != -1)
|
if ((len = readlink(lowentry, buf, sizeof(buf)-1)) != -1)
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (strncmp(buf, "../", 3) == 0) {
|
if (strncmp(buf, "../", 3) == 0) {
|
||||||
return interface_get_lowest(strrchr(buf, '/') + 1, hwifname);
|
return interface_get_lowest(strrchr(buf, '/') + 1, hwifname);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
const char *ifname = argv[1];
|
const char *ifname = argv[1];
|
||||||
char hwifname[IF_NAMESIZE] = "";
|
char hwifname[IF_NAMESIZE] = "";
|
||||||
|
|
||||||
if (strlen(ifname) >= IF_NAMESIZE)
|
if (strlen(ifname) >= IF_NAMESIZE)
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
if (strcspn(ifname, "/\\[]{}*?") != strlen(ifname))
|
if (strcspn(ifname, "/\\[]{}*?") != strlen(ifname))
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
if (!interface_get_lowest(ifname, hwifname))
|
if (!interface_get_lowest(ifname, hwifname))
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
const struct iwinfo_ops *iw = iwinfo_backend(hwifname);
|
const struct iwinfo_ops *iw = iwinfo_backend(hwifname);
|
||||||
|
|
||||||
if (iw == NULL)
|
if (iw == NULL)
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
printf("Content-type: text/event-stream\n\n");
|
printf("Content-type: text/event-stream\n\n");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
struct json_object *obj;
|
struct json_object *obj;
|
||||||
obj = get_stations(iw, hwifname);
|
obj = get_stations(iw, hwifname);
|
||||||
printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN));
|
printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
json_object_put(obj);
|
json_object_put(obj);
|
||||||
usleep(150000);
|
usleep(150000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ static inline uint16_t get_le16(const void *data) {
|
|||||||
static inline uint32_t get_be32(const void *data) {
|
static inline uint32_t get_be32(const void *data) {
|
||||||
const uint8_t *d = data;
|
const uint8_t *d = data;
|
||||||
return (((uint32_t)d[0]) << 24)
|
return (((uint32_t)d[0]) << 24)
|
||||||
| (((uint32_t)d[1]) << 16)
|
| (((uint32_t)d[1]) << 16)
|
||||||
| (((uint32_t)d[2]) << 8)
|
| (((uint32_t)d[2]) << 8)
|
||||||
| d[3];
|
| d[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -97,8 +97,8 @@ static int template_L_load_catalog(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
luaL_getmetatable(L, TEMPLATE_CATALOG);
|
luaL_getmetatable(L, TEMPLATE_CATALOG);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ static int template_L_load_catalog(lua_State *L)
|
|||||||
static int template_catalog_call(lua_State *L)
|
static int template_catalog_call(lua_State *L)
|
||||||
{
|
{
|
||||||
size_t inlen, outlen;
|
size_t inlen, outlen;
|
||||||
lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG);
|
lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG);
|
||||||
const char *in = luaL_checklstring(L, 2, &inlen), *out;
|
const char *in = luaL_checklstring(L, 2, &inlen), *out;
|
||||||
if (!lmo_translate(cat, in, inlen, &out, &outlen))
|
if (!lmo_translate(cat, in, inlen, &out, &outlen))
|
||||||
return 0;
|
return 0;
|
||||||
@ -118,7 +118,7 @@ static int template_catalog_call(lua_State *L)
|
|||||||
|
|
||||||
static int template_catalog_gc(lua_State *L)
|
static int template_catalog_gc(lua_State *L)
|
||||||
{
|
{
|
||||||
lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG);
|
lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG);
|
||||||
lmo_unload(cat);
|
lmo_unload(cat);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -133,8 +133,8 @@ static const luaL_reg R[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const luaL_reg template_catalog_methods[] = {
|
static const luaL_reg template_catalog_methods[] = {
|
||||||
{ "__call", template_catalog_call },
|
{ "__call", template_catalog_call },
|
||||||
{ "__gc", template_catalog_gc },
|
{ "__gc", template_catalog_gc },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ int template_error(lua_State *L, struct template_parser *parser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
snprintf(msg, sizeof(msg), "Syntax error in %s:%d: %s",
|
snprintf(msg, sizeof(msg), "Syntax error in %s:%d: %s",
|
||||||
parser->file ?: "[string]", line + chunkline, err ?: "(unknown error)");
|
parser->file ?: "[string]", line + chunkline, err ?: "(unknown error)");
|
||||||
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushinteger(L, line + chunkline);
|
lua_pushinteger(L, line + chunkline);
|
||||||
|
@ -130,37 +130,37 @@ static inline bool mb_is_shortest(const unsigned char *s, size_t n)
|
|||||||
case 2:
|
case 2:
|
||||||
/* 1100000x (10xxxxxx) */
|
/* 1100000x (10xxxxxx) */
|
||||||
return !(((*s >> 1) == 0x60) &&
|
return !(((*s >> 1) == 0x60) &&
|
||||||
((*(s+1) >> 6) == 0x02));
|
((*(s+1) >> 6) == 0x02));
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
/* 11100000 100xxxxx (10xxxxxx) */
|
/* 11100000 100xxxxx (10xxxxxx) */
|
||||||
return !((*s == 0xE0) &&
|
return !((*s == 0xE0) &&
|
||||||
((*(s+1) >> 5) == 0x04) &&
|
((*(s+1) >> 5) == 0x04) &&
|
||||||
((*(s+2) >> 6) == 0x02));
|
((*(s+2) >> 6) == 0x02));
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
/* 11110000 1000xxxx (10xxxxxx 10xxxxxx) */
|
/* 11110000 1000xxxx (10xxxxxx 10xxxxxx) */
|
||||||
return !((*s == 0xF0) &&
|
return !((*s == 0xF0) &&
|
||||||
((*(s+1) >> 4) == 0x08) &&
|
((*(s+1) >> 4) == 0x08) &&
|
||||||
((*(s+2) >> 6) == 0x02) &&
|
((*(s+2) >> 6) == 0x02) &&
|
||||||
((*(s+3) >> 6) == 0x02));
|
((*(s+3) >> 6) == 0x02));
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
/* 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) */
|
/* 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) */
|
||||||
return !((*s == 0xF8) &&
|
return !((*s == 0xF8) &&
|
||||||
((*(s+1) >> 3) == 0x10) &&
|
((*(s+1) >> 3) == 0x10) &&
|
||||||
((*(s+2) >> 6) == 0x02) &&
|
((*(s+2) >> 6) == 0x02) &&
|
||||||
((*(s+3) >> 6) == 0x02) &&
|
((*(s+3) >> 6) == 0x02) &&
|
||||||
((*(s+4) >> 6) == 0x02));
|
((*(s+4) >> 6) == 0x02));
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
/* 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) */
|
/* 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) */
|
||||||
return !((*s == 0xF8) &&
|
return !((*s == 0xF8) &&
|
||||||
((*(s+1) >> 2) == 0x20) &&
|
((*(s+1) >> 2) == 0x20) &&
|
||||||
((*(s+2) >> 6) == 0x02) &&
|
((*(s+2) >> 6) == 0x02) &&
|
||||||
((*(s+3) >> 6) == 0x02) &&
|
((*(s+3) >> 6) == 0x02) &&
|
||||||
((*(s+4) >> 6) == 0x02) &&
|
((*(s+4) >> 6) == 0x02) &&
|
||||||
((*(s+5) >> 6) == 0x02));
|
((*(s+5) >> 6) == 0x02));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -270,18 +270,18 @@ bool pcdata(const char *s, size_t l, char **out, size_t *outl)
|
|||||||
for (o = 0; o < l; o++) {
|
for (o = 0; o < l; o++) {
|
||||||
/* Invalid XML bytes */
|
/* Invalid XML bytes */
|
||||||
if ((*ptr <= 0x08) ||
|
if ((*ptr <= 0x08) ||
|
||||||
((*ptr >= 0x0B) && (*ptr <= 0x0C)) ||
|
((*ptr >= 0x0B) && (*ptr <= 0x0C)) ||
|
||||||
((*ptr >= 0x0E) && (*ptr <= 0x1F)) ||
|
((*ptr >= 0x0E) && (*ptr <= 0x1F)) ||
|
||||||
(*ptr == 0x7F)) {
|
(*ptr == 0x7F)) {
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Escapes */
|
/* Escapes */
|
||||||
else if ((*ptr == '\'') ||
|
else if ((*ptr == '\'') ||
|
||||||
(*ptr == '"') ||
|
(*ptr == '"') ||
|
||||||
(*ptr == '&') ||
|
(*ptr == '&') ||
|
||||||
(*ptr == '<') ||
|
(*ptr == '<') ||
|
||||||
(*ptr == '>')) {
|
(*ptr == '>')) {
|
||||||
esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
|
esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr);
|
||||||
|
|
||||||
if (!buf_append(buf, esq, esl))
|
if (!buf_append(buf, esq, esl))
|
||||||
|
@ -45,19 +45,19 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = {
|
|||||||
[BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
|
[BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
|
||||||
[BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
|
[BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING,
|
[BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING,
|
||||||
.maxlen = IFNAMSIZ },
|
.maxlen = IFNAMSIZ },
|
||||||
[BATADV_ATTR_MESH_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_MESH_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
|
[BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING,
|
[BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING,
|
||||||
.maxlen = IFNAMSIZ },
|
.maxlen = IFNAMSIZ },
|
||||||
[BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
|
[BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
|
||||||
[BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
|
[BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
|
[BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
|
||||||
@ -65,8 +65,8 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = {
|
|||||||
[BATADV_ATTR_PAD] = { .type = NLA_UNSPEC },
|
[BATADV_ATTR_PAD] = { .type = NLA_UNSPEC },
|
||||||
[BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
|
[BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
|
||||||
[BATADV_ATTR_TT_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_TT_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
|
[BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
|
||||||
[BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
|
[BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
|
||||||
[BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
|
[BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
|
||||||
@ -75,23 +75,23 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = {
|
|||||||
[BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
|
[BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
|
||||||
[BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
|
[BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_NEIGH_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_NEIGH_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_TQ] = { .type = NLA_U8 },
|
[BATADV_ATTR_TQ] = { .type = NLA_U8 },
|
||||||
[BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
|
[BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
|
[BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
|
[BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
|
||||||
[BATADV_ATTR_ROUTER] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_ROUTER] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
|
[BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
|
||||||
[BATADV_ATTR_BLA_ADDRESS] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_BLA_ADDRESS] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
|
[BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
|
||||||
[BATADV_ATTR_BLA_BACKBONE] = { .type = NLA_UNSPEC,
|
[BATADV_ATTR_BLA_BACKBONE] = { .type = NLA_UNSPEC,
|
||||||
.minlen = ETH_ALEN,
|
.minlen = ETH_ALEN,
|
||||||
.maxlen = ETH_ALEN },
|
.maxlen = ETH_ALEN },
|
||||||
[BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
|
[BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = {
|
|||||||
* Return: Always NL_STOP
|
* Return: Always NL_STOP
|
||||||
*/
|
*/
|
||||||
static int nlquery_error_cb(struct sockaddr_nl *nla __attribute__((unused)),
|
static int nlquery_error_cb(struct sockaddr_nl *nla __attribute__((unused)),
|
||||||
struct nlmsgerr *nlerr, void *arg)
|
struct nlmsgerr *nlerr, void *arg)
|
||||||
{
|
{
|
||||||
struct batadv_nlquery_opts *query_opts = arg;
|
struct batadv_nlquery_opts *query_opts = arg;
|
||||||
|
|
||||||
@ -147,8 +147,8 @@ static int nlquery_stop_cb(struct nl_msg *msg, void *arg)
|
|||||||
*/
|
*/
|
||||||
__attribute__ ((visibility ("default")))
|
__attribute__ ((visibility ("default")))
|
||||||
int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd,
|
int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd,
|
||||||
nl_recvmsg_msg_cb_t callback, int flags,
|
nl_recvmsg_msg_cb_t callback, int flags,
|
||||||
struct batadv_nlquery_opts *query_opts)
|
struct batadv_nlquery_opts *query_opts)
|
||||||
{
|
{
|
||||||
struct nl_sock *sock;
|
struct nl_sock *sock;
|
||||||
struct nl_msg *msg;
|
struct nl_msg *msg;
|
||||||
@ -198,7 +198,7 @@ int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, flags,
|
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, flags,
|
||||||
nl_cmd, 1);
|
nl_cmd, 1);
|
||||||
|
|
||||||
nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex);
|
nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex);
|
||||||
nl_send_auto_complete(sock, msg);
|
nl_send_auto_complete(sock, msg);
|
||||||
|
@ -79,10 +79,8 @@ struct batadv_nlquery_opts {
|
|||||||
*
|
*
|
||||||
* Return: Return true when a attribute is missing, false otherwise
|
* Return: Return true when a attribute is missing, false otherwise
|
||||||
*/
|
*/
|
||||||
static inline bool
|
static inline bool batadv_genl_missing_attrs(struct nlattr *attrs[],
|
||||||
batadv_genl_missing_attrs(struct nlattr *attrs[],
|
const enum batadv_nl_attrs mandatory[], size_t num) {
|
||||||
const enum batadv_nl_attrs mandatory[], size_t num)
|
|
||||||
{
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
@ -96,7 +94,7 @@ batadv_genl_missing_attrs(struct nlattr *attrs[],
|
|||||||
extern struct nla_policy batadv_genl_policy[];
|
extern struct nla_policy batadv_genl_policy[];
|
||||||
|
|
||||||
int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd,
|
int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd,
|
||||||
nl_recvmsg_msg_cb_t callback, int flags,
|
nl_recvmsg_msg_cb_t callback, int flags,
|
||||||
struct batadv_nlquery_opts *query_opts);
|
struct batadv_nlquery_opts *query_opts);
|
||||||
|
|
||||||
#endif /* _BATADV_GENL_H_ */
|
#endif /* _BATADV_GENL_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user