gluon-radv-filterd: Various small fixes due to NeoRaider
This commit is contained in:
parent
20d83bca76
commit
66a26d0d23
@ -24,7 +24,7 @@ define Build/Configure
|
|||||||
endef
|
endef
|
||||||
|
|
||||||
define Build/Compile
|
define Build/Compile
|
||||||
CFLAGS="$(TARGET_CFLAGS)" CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS)
|
$(call Build/Compile/Default)
|
||||||
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
|
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
if need_table('radv_filterd', nil, false) then
|
if need_table('radv_filterd', nil, false) then
|
||||||
need_number('radv_filterd.threshold')
|
need_number('radv_filterd.threshold')
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
local site = require 'gluon.site_config'
|
local site = require 'gluon.site_config'
|
||||||
local uci = (require 'luci.model.uci').cursor()
|
local uci = (require 'simple-uci').cursor()
|
||||||
|
|
||||||
if site.radv_filterd and site.radv_filterd.threshold then
|
if site.radv_filterd and site.radv_filterd.threshold then
|
||||||
uci:foreach('gluon-radv-filterd', 'filterd', function(section)
|
uci:foreach('gluon-radv-filterd', 'filterd', function(section)
|
||||||
uci:set('gluon-radv-filterd', section['.name'], 'threshold', site.radv_filterd.threshold)
|
uci:set('gluon-radv-filterd', section['.name'], 'threshold', site.radv_filterd.threshold)
|
||||||
end)
|
end)
|
||||||
uci:save('gluon-radv-filterd')
|
uci:save('gluon-radv-filterd')
|
||||||
end
|
end
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
#define MIN_INTERVAL 15
|
#define MIN_INTERVAL 15
|
||||||
|
|
||||||
// max execution time of a single ebtables call in nanoseconds
|
// max execution time of a single ebtables call in nanoseconds
|
||||||
#define EBTABLES_TIMEOUT 5e8 // 500ms
|
#define EBTABLES_TIMEOUT 500000000 // 500ms
|
||||||
|
|
||||||
// TQ value assigned to local routers
|
// TQ value assigned to local routers
|
||||||
#define LOCAL_TQ 512
|
#define LOCAL_TQ 512
|
||||||
@ -287,7 +287,7 @@ static void handle_ra(int sock) {
|
|||||||
}
|
}
|
||||||
if (!router) {
|
if (!router) {
|
||||||
router = malloc(sizeof(struct router));
|
router = malloc(sizeof(struct router));
|
||||||
memcpy(router->src, src.sll_addr, 8);
|
memcpy(router->src, src.sll_addr, sizeof(router->src));
|
||||||
router->next = G.routers;
|
router->next = G.routers;
|
||||||
G.routers = router;
|
G.routers = router;
|
||||||
}
|
}
|
||||||
@ -325,14 +325,12 @@ static void update_tqs() {
|
|||||||
bool update_originators = false;
|
bool update_originators = false;
|
||||||
int i;
|
int i;
|
||||||
macaddr_t mac_a, mac_b;
|
macaddr_t mac_a, mac_b;
|
||||||
|
macaddr_t unspec = {};
|
||||||
|
|
||||||
// reset TQs
|
// reset TQs
|
||||||
foreach(router, G.routers) {
|
foreach(router, G.routers) {
|
||||||
router->tq = 0;
|
router->tq = 0;
|
||||||
for (i = 0; i < 6; i++)
|
if (!memcmp(router->originator, unspec, sizeof(unspec)))
|
||||||
if (router->originator[i] != 0)
|
|
||||||
break;
|
|
||||||
if (i >= 6)
|
|
||||||
update_originators = true;
|
update_originators = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,8 +345,8 @@ static void update_tqs() {
|
|||||||
snprintf(path, PATH_MAX, TRANSTABLE_GLOBAL, G.mesh_iface);
|
snprintf(path, PATH_MAX, TRANSTABLE_GLOBAL, G.mesh_iface);
|
||||||
f = fopen(path, "r");
|
f = fopen(path, "r");
|
||||||
// skip header
|
// skip header
|
||||||
while (fgetc(f) != '\n');
|
while (fgetc(f) != '\n') {}
|
||||||
while (fgetc(f) != '\n');
|
while (fgetc(f) != '\n') {}
|
||||||
while (fscanf(f, " %*[*+] " F_MAC "%*[0-9 -] (%*3u) via " F_MAC " %*[^]]]\n",
|
while (fscanf(f, " %*[*+] " F_MAC "%*[0-9 -] (%*3u) via " F_MAC " %*[^]]]\n",
|
||||||
F_MAC_VAR(&mac_a), F_MAC_VAR(&mac_b)) == 12) {
|
F_MAC_VAR(&mac_a), F_MAC_VAR(&mac_b)) == 12) {
|
||||||
|
|
||||||
@ -446,21 +444,26 @@ static int fork_execvp_timeout(struct timespec *timeout, const char *file, const
|
|||||||
int ret;
|
int ret;
|
||||||
pid_t child;
|
pid_t child;
|
||||||
siginfo_t info;
|
siginfo_t info;
|
||||||
sigset_t signals;
|
sigset_t signals, oldsignals;
|
||||||
sigemptyset(&signals);
|
sigemptyset(&signals);
|
||||||
sigaddset(&signals, SIGCHLD);
|
sigaddset(&signals, SIGCHLD);
|
||||||
|
|
||||||
child = fork();
|
child = fork();
|
||||||
if (!child) {
|
if (child == 0) {
|
||||||
// casting discards const, but should be safe
|
// casting discards const, but should be safe
|
||||||
// (see http://stackoverflow.com/q/36925388)
|
// (see http://stackoverflow.com/q/36925388)
|
||||||
execvp(file, (char**) argv);
|
execvp(file, (char**) argv);
|
||||||
error(1, errno, "can't execvp(\"%s\", ...)", file);
|
fprintf(stderr, "can't execvp(\"%s\", ...): %s\n", file, strerror(errno));
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
else if (child < 0) {
|
||||||
|
perror("Failed to fork()");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigprocmask(SIG_BLOCK, &signals, NULL);
|
sigprocmask(SIG_BLOCK, &signals, &oldsignals);
|
||||||
ret = sigtimedwait(&signals, &info, timeout);
|
ret = sigtimedwait(&signals, &info, timeout);
|
||||||
sigprocmask(SIG_UNBLOCK, &signals, NULL);
|
sigprocmask(SIG_SETMASK, &oldsignals, NULL);
|
||||||
|
|
||||||
if (ret == SIGCHLD) {
|
if (ret == SIGCHLD) {
|
||||||
if (info.si_pid != child) {
|
if (info.si_pid != child) {
|
||||||
@ -494,7 +497,7 @@ static void update_ebtables() {
|
|||||||
struct timespec timeout = {
|
struct timespec timeout = {
|
||||||
.tv_nsec = EBTABLES_TIMEOUT,
|
.tv_nsec = EBTABLES_TIMEOUT,
|
||||||
};
|
};
|
||||||
char mac[18];
|
char mac[F_MAC_LEN + 1];
|
||||||
struct router *router;
|
struct router *router;
|
||||||
|
|
||||||
if (G.best_router && G.best_router->tq >= G.max_tq - G.hysteresis_thresh) {
|
if (G.best_router && G.best_router->tq >= G.max_tq - G.hysteresis_thresh) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
|
|
||||||
#define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
|
#define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
|
||||||
|
#define F_MAC_LEN 17
|
||||||
#define F_MAC_IGN "%*2x:%*2x:%*2x:%*2x:%*2x:%*2x"
|
#define F_MAC_IGN "%*2x:%*2x:%*2x:%*2x:%*2x:%*2x"
|
||||||
#define F_MAC_VAR(var) var[0], var[1], var[2], var[3], var[4], var[5]
|
#define F_MAC_VAR(var) var[0], var[1], var[2], var[3], var[4], var[5]
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ static struct json_object * get_radv_filter() {
|
|||||||
FILE *f = popen("exec ebtables -L RADV_FILTER", "r");
|
FILE *f = popen("exec ebtables -L RADV_FILTER", "r");
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
macaddr_t mac = { 0 };
|
macaddr_t mac = {};
|
||||||
struct json_object *ret = NULL;
|
struct json_object *ret = NULL;
|
||||||
|
char macstr[F_MAC_LEN + 1] = "";
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -20,12 +21,12 @@ static struct json_object * get_radv_filter() {
|
|||||||
if (sscanf(line, "-s " F_MAC " -j ACCEPT\n", F_MAC_VAR(&mac)) == ETH_ALEN)
|
if (sscanf(line, "-s " F_MAC " -j ACCEPT\n", F_MAC_VAR(&mac)) == ETH_ALEN)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
|
|
||||||
pclose(f);
|
pclose(f);
|
||||||
|
|
||||||
sprintf(line, F_MAC, F_MAC_VAR(mac));
|
snprintf(macstr, sizeof(macstr), F_MAC, F_MAC_VAR(mac));
|
||||||
ret = gluonutil_wrap_string(line);
|
ret = gluonutil_wrap_string(macstr);
|
||||||
free(line);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user