From ff98718ec8baba057c8a12742c8adc7d6389cc90 Mon Sep 17 00:00:00 2001 From: Stefan Nygren Date: Tue, 5 May 2015 18:09:55 +0200 Subject: [PATCH] Update of questd to support igmp --- questd/Makefile | 5 +- questd/files/tmp/igmp_snooping | 5 + questd/src/Makefile | 4 +- questd/src/igmp.c | 184 +++++++++++++++++++++++++++++++++ questd/src/igmp.h | 38 +++++++ questd/src/questd.c | 18 ++++ questd/src/questd.h | 1 + 7 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 questd/files/tmp/igmp_snooping create mode 100644 questd/src/igmp.c create mode 100644 questd/src/igmp.h diff --git a/questd/Makefile b/questd/Makefile index fefb4f938..8e8137b5c 100644 --- a/questd/Makefile +++ b/questd/Makefile @@ -6,8 +6,8 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=questd -PKG_VERSION:=2.0.0 -PKG_RELEASE:=1 +PKG_VERSION:=2.0.3 +PKG_RELEASE:=3 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) include $(INCLUDE_DIR)/package.mk @@ -41,6 +41,7 @@ endef define Package/questd/install $(INSTALL_DIR) $(1)/sbin + $(INSTALL_DIR) $(1)/tmp $(INSTALL_BIN) $(PKG_BUILD_DIR)/questd $(1)/sbin/ $(CP) ./files/* $(1)/ endef diff --git a/questd/files/tmp/igmp_snooping b/questd/files/tmp/igmp_snooping new file mode 100644 index 000000000..795f34e8d --- /dev/null +++ b/questd/files/tmp/igmp_snooping @@ -0,0 +1,5 @@ +igmp snooping 2 proxy 1 lan2lan-snooping 0/0, rate-limit 0pps, priority -1 +bridge device src-dev #tags lan-tci wan-tci group mode RxGroup source reporter timeout Index ExcludPt +br-lan eth5 eth2.1 00 0x0000 0xffffffff 0xe0027ffe EX 0xe0027ffe 0x00000000 0xc0a801f1 258 0x401e0001 -1 +br-lan eth5 eth2.1 00 0x0000 0xffffffff 0xefc3ffff EX 0xefc3ffff 0x00000000 0xc0a801f1 258 0x400e0001 -1 +br-lan eth5 eth2.1 00 0x0000 0xffffffff 0xefffffff EX 0xefffffff 0x00000000 0xc0a801f1 258 0x40070001 -1 diff --git a/questd/src/Makefile b/questd/src/Makefile index 054b4a2b6..6310b9cde 100644 --- a/questd/src/Makefile +++ b/questd/src/Makefile @@ -2,8 +2,8 @@ CC = gcc CFLAGS = -g -Wall LOCLIBS = LIBS = -luci -lubus -lubox -lpthread -OBJS = questd.o dumper.o port.o arping.o usb.o ndisc.o dslstats.o tools.o -SRCS = questd.c dumper.c port.c arping.c usb.c ndisc.c dslstats.c tools.c +OBJS = questd.o dumper.o port.o arping.o usb.o ndisc.o dslstats.o tools.o igmp.o +SRCS = questd.c dumper.c port.c arping.c usb.c ndisc.c dslstats.c tools.c igmp.c LIBSRCS = ISRCS = questd.h diff --git a/questd/src/igmp.c b/questd/src/igmp.c new file mode 100644 index 000000000..adefd528e --- /dev/null +++ b/questd/src/igmp.c @@ -0,0 +1,184 @@ +/* + * igmp.c + * + * Created on: May 5, 2015 + * Author: stefan + */ + +#include "questd.h" +#include "igmp.h" + +static void tokenize_line(char *str, const char **tokens, size_t tokens_size) { + char *ptr = str; + const char **token = tokens; // = line; + while (*ptr) { + if (*ptr == '\t' || *ptr == ' ' || *ptr == '\n') { + *ptr++ = 0; + continue; + } else { + *token++ = ptr; + tokens_size--; + if (tokens_size == 0) { + return; + } + while (*ptr && *ptr != '\t' && *ptr != ' ' && *ptr != '\n') + ptr++; + continue; + } + ptr++; + } +} + +int igmp_rpc(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) { + struct blob_buf bb; + int row = 0, idx = 0; + FILE *in; + char line[256]; + IGMPtable table[128]; + const char *tokens[32] = { 0 }; + void *object, *array,*t; + + blob_buf_init(&bb, 0); + if (!(in = fopen("/tmp/igmp_snooping", "r"))) + return 1; + array = blobmsg_open_array(&bb, "tables"); + + struct element { + char *string; + struct element *next; + }; + while (fgets(line, sizeof(line), in)) { + if (row < 2) { + row++; + continue; + } + //remove_newline(line); + + tokenize_line(line, tokens, sizeof(tokens) / sizeof(char*)); + int tok_pos = 0; + const char **token = tokens; + const char *names[] = { "bridge", "dev", "srcdev", "tags", "lantci", + "wantci", "group", "mode", "rxgroup", "source", "reporter", + "timeout", "index", "excludept" }; + + while (*token) { + printf("<%d>\n",tok_pos); + switch (tok_pos) { + case 0: + + snprintf(table[row-2].bridge,"%s",token); + printf("%s\n%s\n",table[row-2].bridge,token); + break; + case 1: + snprintf(table[row-2].device,"%s",token); + break; + case 2: + snprintf(table[row - 2].tags ,"%s",token); + break; + case 3: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].lantci, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 4: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].wantci, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 5: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].group, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 6: + snprintf(table[row - 2].mode,"%s",token); + break; + case 7: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].RxGroup, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 8: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].source, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 9: { + uint32_t ip; + char str[17]; + + sscanf(token, "%8x", &ip); + sprintf(table[row - 2].reporter, "%d.%d.%d.%d", (ip >> 16), + (ip >> 8) & 0xff, ip & 0xff, (ip >> 24) & 0xff); + } + break; + case 10: + snprintf(table[row - 2].timeout,"%s",token); + + break; + case 11: + snprintf(table[row - 2].Index,"%s",token); + + break; + case 12: + snprintf(table[row - 2].ExcludPt,"%s",token); + + break; + default: + break; + + } + token++; + tok_pos++; + printf("",tok_pos); + } + + row++; + + } + for (idx = 0; idx < (row - 2); idx++) { + object = blobmsg_open_table(&bb, NULL); + blobmsg_add_string(&bb,"bridge", table[idx].bridge); + blobmsg_add_string(&bb,"device", table[idx].device); + blobmsg_add_string(&bb,"srcdev", table[idx].srcdev); + blobmsg_add_string(&bb,"tags", table[idx].tags); + blobmsg_add_string(&bb,"lantci", table[idx].lantci); + blobmsg_add_string(&bb,"wantci", table[idx].wantci); + blobmsg_add_string(&bb,"group", table[idx].group); + blobmsg_add_string(&bb,"mode", table[idx].mode); + blobmsg_add_string(&bb,"rxgroup", table[idx].RxGroup); + blobmsg_add_string(&bb,"source", table[idx].source); + blobmsg_add_string(&bb,"reporter", table[idx].reporter); + blobmsg_add_string(&bb,"timeout", table[idx].timeout); + blobmsg_add_string(&bb,"index", table[idx].Index); + blobmsg_add_string(&bb,"excludpt", table[idx].ExcludPt); + blobmsg_close_table(&bb, object); + } + blobmsg_close_array(&bb, array); + + ubus_send_reply(ctx, req, bb.head); + + return 0; +} diff --git a/questd/src/igmp.h b/questd/src/igmp.h new file mode 100644 index 000000000..da5831090 --- /dev/null +++ b/questd/src/igmp.h @@ -0,0 +1,38 @@ +/* + * igmp.h + * + * Created on: May 5, 2015 + * Author: stefan + */ + +#ifndef IGMP_H_ +#define IGMP_H_ +#ifndef NULL +#define NULL ((void *) 0) +#endif + + + +int igmp_rpc(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg); + + +typedef struct igmp_table { + char bridge[32]; + char device[32]; + char srcdev[32]; + char tags[32]; + char lantci[32]; + char wantci[32]; + char group[32]; + char mode[32]; + char RxGroup[32]; + char source[32]; + char reporter[32]; + char timeout[32]; + char Index[32]; + char ExcludPt[32]; + +}IGMPtable; +#endif /* IGMP_H_ */ diff --git a/questd/src/questd.c b/questd/src/questd.c index 86e93006e..feb70d6f6 100644 --- a/questd/src/questd.c +++ b/questd/src/questd.c @@ -1297,6 +1297,21 @@ quest_router_connected_clients6(struct ubus_context *ctx, struct ubus_object *ob return 0; } +static int +quest_router_igmp_table(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__QUEST_MAX]; + + blobmsg_parse(quest_policy, __QUEST_MAX, tb, blob_data(msg), blob_len(msg)); + + blob_buf_init(&bb, 0); + router_dump_connected_clients6(&bb); + ubus_send_reply(ctx, req, bb.head); + + return 0; +} static int quest_router_clients6(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1492,6 +1507,7 @@ static struct ubus_method router_object_methods[] = { UBUS_METHOD_NOARG("clients6", quest_router_clients6), UBUS_METHOD_NOARG("connected", quest_router_connected_clients), UBUS_METHOD_NOARG("connected6", quest_router_connected_clients6), + UBUS_METHOD_NOARG("igmptable", igmp_rpc), UBUS_METHOD("sta", quest_router_wireless_stas, wl_policy), UBUS_METHOD_NOARG("stas", quest_router_stas), UBUS_METHOD("ports", quest_router_ports, network_policy), @@ -1683,6 +1699,8 @@ quest_ubus_reconnect_timer(struct uloop_timeout *timeout) quest_ubus_add_fd(); } + + static void quest_ubus_connection_lost(struct ubus_context *ctx) { diff --git a/questd/src/questd.h b/questd/src/questd.h index b40a6831c..6f72323d7 100644 --- a/questd/src/questd.h +++ b/questd/src/questd.h @@ -21,6 +21,7 @@ #include #include "dslstats.h" +#include "igmp.h" #define MAX_VIF 8 #define MAX_NETWORK 16