瀏覽代碼

gluon-radv-filterd: Various small fixes due to NeoRaider

Jan-Philipp Litza 7 年之前
父節點
當前提交
60e6982222

+ 1 - 1
package/gluon-radv-filterd/Makefile

@@ -24,7 +24,7 @@ define Build/Configure
 endef
 
 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/)
 endef
 

+ 1 - 1
package/gluon-radv-filterd/check_site.lua

@@ -1,3 +1,3 @@
 if need_table('radv_filterd', nil, false) then
-    need_number('radv_filterd.threshold')
+	need_number('radv_filterd.threshold')
 end

+ 5 - 5
package/gluon-radv-filterd/luasrc/lib/gluon/upgrade/300-gluon-radv-filterd

@@ -1,11 +1,11 @@
 #!/usr/bin/lua
 
 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
-    uci:foreach('gluon-radv-filterd', 'filterd', function(section)
-        uci:set('gluon-radv-filterd', section['.name'], 'threshold', site.radv_filterd.threshold)
-    end)
-    uci:save('gluon-radv-filterd')
+	uci:foreach('gluon-radv-filterd', 'filterd', function(section)
+		uci:set('gluon-radv-filterd', section['.name'], 'threshold', site.radv_filterd.threshold)
+	end)
+	uci:save('gluon-radv-filterd')
 end

+ 17 - 14
package/gluon-radv-filterd/src/gluon-radv-filterd.c

@@ -62,7 +62,7 @@
 #define MIN_INTERVAL 15
 
 // 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
 #define LOCAL_TQ 512
@@ -287,7 +287,7 @@ static void handle_ra(int sock) {
 	}
 	if (!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;
 		G.routers = router;
 	}
@@ -325,14 +325,12 @@ static void update_tqs() {
 	bool update_originators = false;
 	int i;
 	macaddr_t mac_a, mac_b;
+	macaddr_t unspec = {};
 
 	// reset TQs
 	foreach(router, G.routers) {
 		router->tq = 0;
-		for (i = 0; i < 6; i++)
-			if (router->originator[i] != 0)
-				break;
-		if (i >= 6)
+		if (!memcmp(router->originator, unspec, sizeof(unspec)))
 			update_originators = true;
 	}
 
@@ -347,8 +345,8 @@ static void update_tqs() {
 		snprintf(path, PATH_MAX, TRANSTABLE_GLOBAL, G.mesh_iface);
 		f = fopen(path, "r");
 		// 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",
 				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;
 	pid_t child;
 	siginfo_t info;
-	sigset_t signals;
+	sigset_t signals, oldsignals;
 	sigemptyset(&signals);
 	sigaddset(&signals, SIGCHLD);
 
 	child = fork();
-	if (!child) {
+	if (child == 0) {
 		// casting discards const, but should be safe
 		// (see http://stackoverflow.com/q/36925388)
 		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);
-	sigprocmask(SIG_UNBLOCK, &signals, NULL);
+	sigprocmask(SIG_SETMASK, &oldsignals, NULL);
 
 	if (ret == SIGCHLD) {
 		if (info.si_pid != child) {
@@ -494,7 +497,7 @@ static void update_ebtables() {
 	struct timespec timeout = {
 		.tv_nsec = EBTABLES_TIMEOUT,
 	};
-	char mac[18];
+	char mac[F_MAC_LEN + 1];
 	struct router *router;
 
 	if (G.best_router && G.best_router->tq >= G.max_tq - G.hysteresis_thresh) {

+ 1 - 0
package/gluon-radv-filterd/src/mac.h

@@ -2,6 +2,7 @@
 #include <linux/if_ether.h>
 
 #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_VAR(var) var[0], var[1], var[2], var[3], var[4], var[5]
 

+ 5 - 4
package/gluon-radv-filterd/src/respondd.c

@@ -10,8 +10,9 @@ static struct json_object * get_radv_filter() {
 	FILE *f = popen("exec ebtables -L RADV_FILTER", "r");
 	char *line = NULL;
 	size_t len = 0;
-	macaddr_t mac = { 0 };
+	macaddr_t mac = {};
 	struct json_object *ret = NULL;
+	char macstr[F_MAC_LEN + 1] = "";
 
 	if (!f)
 		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)
 			break;
 	}
+	free(line);
 
 	pclose(f);
 
-	sprintf(line, F_MAC, F_MAC_VAR(mac));
-	ret = gluonutil_wrap_string(line);
-	free(line);
+	snprintf(macstr, sizeof(macstr), F_MAC, F_MAC_VAR(mac));
+	ret = gluonutil_wrap_string(macstr);
 	return ret;
 }