gluon-radv-filterd: Add respondd module reporting the chosen gateway
This commit is contained in:
parent
3bf4d12911
commit
a1fea711da
@ -12,11 +12,7 @@ define Package/gluon-radv-filterd
|
|||||||
SECTION:=gluon
|
SECTION:=gluon
|
||||||
CATEGORY:=Gluon
|
CATEGORY:=Gluon
|
||||||
TITLE:=Filter IPv6 router advertisements
|
TITLE:=Filter IPv6 router advertisements
|
||||||
DEPENDS:=+gluon-ebtables
|
DEPENDS:=+gluon-ebtables +libgluonutil
|
||||||
endef
|
|
||||||
|
|
||||||
define Package/gluon-radv-filterd/description
|
|
||||||
Gluon community wifi mesh firmware framework: filter IPv6 router advertisements
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Build/Prepare
|
define Build/Prepare
|
||||||
@ -38,6 +34,9 @@ define Package/gluon-radv-filterd/install
|
|||||||
|
|
||||||
$(INSTALL_DIR) $(1)/usr/sbin/
|
$(INSTALL_DIR) $(1)/usr/sbin/
|
||||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/gluon-radv-filterd $(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
|
endef
|
||||||
|
|
||||||
define Package/gluon-radv-filterd/postinst
|
define Package/gluon-radv-filterd/postinst
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
all: gluon-radv-filterd
|
all: gluon-radv-filterd respondd.so
|
||||||
|
|
||||||
gluon-radv-filterd: gluon-radv-filterd.c
|
gluon-radv-filterd: gluon-radv-filterd.c
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wall -o $@ $^ $(LDLIBS)
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wall -o $@ $^ $(LDLIBS)
|
||||||
|
|
||||||
|
respondd.so: respondd.c
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil
|
||||||
|
@ -45,12 +45,13 @@
|
|||||||
|
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
#include <linux/if_ether.h>
|
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
|
|
||||||
#include <netinet/icmp6.h>
|
#include <netinet/icmp6.h>
|
||||||
#include <netinet/ip6.h>
|
#include <netinet/ip6.h>
|
||||||
|
|
||||||
|
#include "mac.h"
|
||||||
|
|
||||||
// Recheck TQs after this time even if no RA was received
|
// Recheck TQs after this time even if no RA was received
|
||||||
#define MAX_INTERVAL 60
|
#define MAX_INTERVAL 60
|
||||||
|
|
||||||
@ -72,10 +73,6 @@
|
|||||||
#define TRANSTABLE_GLOBAL DEBUGFS "transtable_global"
|
#define TRANSTABLE_GLOBAL DEBUGFS "transtable_global"
|
||||||
#define TRANSTABLE_LOCAL DEBUGFS "transtable_local"
|
#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
|
#ifdef DEBUG
|
||||||
#define CHECK(stmt) \
|
#define CHECK(stmt) \
|
||||||
if(!(stmt)) { \
|
if(!(stmt)) { \
|
||||||
@ -92,8 +89,6 @@
|
|||||||
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
|
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint8_t macaddr_t[ETH_ALEN];
|
|
||||||
|
|
||||||
struct list_item {
|
struct list_item {
|
||||||
struct list *next;
|
struct list *next;
|
||||||
};
|
};
|
||||||
|
8
package/gluon-radv-filterd/src/mac.h
Normal file
8
package/gluon-radv-filterd/src/mac.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <linux/if_ether.h>
|
||||||
|
|
||||||
|
#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];
|
45
package/gluon-radv-filterd/src/respondd.c
Normal file
45
package/gluon-radv-filterd/src/respondd.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include <respondd.h>
|
||||||
|
|
||||||
|
#include <json-c/json.h>
|
||||||
|
#include <libgluonutil.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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},
|
||||||
|
{}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user