From a1fea711da37c6ef24d271ab64620eed15b202e4 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Thu, 9 Feb 2017 19:29:24 +0100 Subject: [PATCH] gluon-radv-filterd: Add respondd module reporting the chosen gateway --- package/gluon-radv-filterd/Makefile | 9 ++-- package/gluon-radv-filterd/src/Makefile | 5 ++- .../src/gluon-radv-filterd.c | 9 +--- package/gluon-radv-filterd/src/mac.h | 8 ++++ package/gluon-radv-filterd/src/respondd.c | 45 +++++++++++++++++++ 5 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 package/gluon-radv-filterd/src/mac.h create mode 100644 package/gluon-radv-filterd/src/respondd.c diff --git a/package/gluon-radv-filterd/Makefile b/package/gluon-radv-filterd/Makefile index 88f79736..fcf5c552 100644 --- a/package/gluon-radv-filterd/Makefile +++ b/package/gluon-radv-filterd/Makefile @@ -12,11 +12,7 @@ define Package/gluon-radv-filterd SECTION:=gluon CATEGORY:=Gluon TITLE:=Filter IPv6 router advertisements - DEPENDS:=+gluon-ebtables -endef - -define Package/gluon-radv-filterd/description - Gluon community wifi mesh firmware framework: filter IPv6 router advertisements + DEPENDS:=+gluon-ebtables +libgluonutil endef define Build/Prepare @@ -38,6 +34,9 @@ define Package/gluon-radv-filterd/install $(INSTALL_DIR) $(1)/usr/sbin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/gluon-radv-filterd $(1)/usr/sbin/ + + $(INSTALL_DIR) $(1)/lib/gluon/respondd + $(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/radv-filterd.so endef define Package/gluon-radv-filterd/postinst diff --git a/package/gluon-radv-filterd/src/Makefile b/package/gluon-radv-filterd/src/Makefile index 652c6703..82a2bace 100644 --- a/package/gluon-radv-filterd/src/Makefile +++ b/package/gluon-radv-filterd/src/Makefile @@ -1,4 +1,7 @@ -all: gluon-radv-filterd +all: gluon-radv-filterd respondd.so gluon-radv-filterd: gluon-radv-filterd.c $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wall -o $@ $^ $(LDLIBS) + +respondd.so: respondd.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil diff --git a/package/gluon-radv-filterd/src/gluon-radv-filterd.c b/package/gluon-radv-filterd/src/gluon-radv-filterd.c index b85a2084..eeef8328 100644 --- a/package/gluon-radv-filterd/src/gluon-radv-filterd.c +++ b/package/gluon-radv-filterd/src/gluon-radv-filterd.c @@ -45,12 +45,13 @@ #include #include -#include #include #include #include +#include "mac.h" + // Recheck TQs after this time even if no RA was received #define MAX_INTERVAL 60 @@ -72,10 +73,6 @@ #define TRANSTABLE_GLOBAL DEBUGFS "transtable_global" #define TRANSTABLE_LOCAL DEBUGFS "transtable_local" -#define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" -#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] - #ifdef DEBUG #define CHECK(stmt) \ if(!(stmt)) { \ @@ -92,8 +89,6 @@ #define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0])) #endif -typedef uint8_t macaddr_t[ETH_ALEN]; - struct list_item { struct list *next; }; diff --git a/package/gluon-radv-filterd/src/mac.h b/package/gluon-radv-filterd/src/mac.h new file mode 100644 index 00000000..4635a7b7 --- /dev/null +++ b/package/gluon-radv-filterd/src/mac.h @@ -0,0 +1,8 @@ +#include +#include + +#define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" +#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] + +typedef uint8_t macaddr_t[ETH_ALEN]; diff --git a/package/gluon-radv-filterd/src/respondd.c b/package/gluon-radv-filterd/src/respondd.c new file mode 100644 index 00000000..fe5ddbfe --- /dev/null +++ b/package/gluon-radv-filterd/src/respondd.c @@ -0,0 +1,45 @@ +#include + +#include +#include +#include + +#include "mac.h" + +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 }; + struct json_object *ret = NULL; + + if (!f) + return NULL; + + while (getline(&line, &len, f) > 0) { + if (sscanf(line, "-s " F_MAC " -j ACCEPT\n", F_MAC_VAR(&mac)) == ETH_ALEN) + break; + } + + pclose(f); + + sprintf(line, F_MAC, F_MAC_VAR(mac)); + ret = gluonutil_wrap_string(line); + free(line); + return ret; +} + +static struct json_object * respondd_provider_statistics() { + struct json_object *ret = json_object_new_object(); + + struct json_object *radv_filter = get_radv_filter(); + if (radv_filter) + json_object_object_add(ret, "gateway6", radv_filter); + + return ret; +} + +const struct respondd_provider_info respondd_providers[] = { + {"statistics", respondd_provider_statistics}, + {} +};