diff --git a/.github/labeler.yml b/.github/labeler.yml index 707df790bfa29da60ce3ead04f9ecd45695b7153..f5629ac3a1fd1e75e45f832c4f0212d59823c5bf 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,8 +1,4 @@ --- -"3. topic: babel": - - package/gluon-l3roamd/** - - package/gluon-mesh-babel/** - - package/gluon-mmfd/** "3. topic: batman-adv": - docs/package/gluon-mesh-batman-adv* - package/gluon-alfred/** @@ -38,6 +34,10 @@ - docs/multidomain-site-example/** - package/gluon-config-mode-domain-select/** - package/gluon-scheduled-domain-switch/** +"3. topic: olsr": + - package/gluon-l3roamd/** + - package/gluon-mesh-olsrd/** + - package/gluon-mmfd/** "3. topic: package": - package/** "3. topic: respondd": diff --git a/docs/user/site.rst b/docs/user/site.rst index 7f8f544be609e97807e65322fa5d23d9a4f24cd1..7e13ad40a726c7cc478be31ff34cbdf0bb909948 100644 --- a/docs/user/site.rst +++ b/docs/user/site.rst @@ -45,7 +45,7 @@ prefix6 node_prefix6 The ipv6 prefix from which the unique IP-addresses for nodes are selected - in babel-based networks. This may overlap with prefix6. e.g. :: + in olsr-based networks. This may overlap with prefix6. e.g. :: node_prefix6 = 'fdca::ffee:babe:2::/64' @@ -56,7 +56,7 @@ node_client_prefix6 \: optional, deprecated An IPv6 prefix internally used by the l3roamd protocol, used to allow an efficient handover via unicast when a client roamed. This is exclusively useful when running a routing mesh protocol - like babel. e.g. :: + like olsr. e.g. :: node_client_prefix6 = 'fdca::ffee:babe:3::/64' @@ -321,7 +321,7 @@ mesh_vpn setting the *preserve* option of a peer to ``1`` in UCI. **Note:** It may be interesting to include the package *gluon-iptables-clamp-mss-to-pmtu* - in the build when using *gluon-mesh-babel* to work around ICMP black holes on the internet. + in the build when using *gluon-mesh-olsrd* to work around ICMP black holes on the internet. :: diff --git a/package/features b/package/features index 380775c61a841f951b4dd510835f7c1827aa2777..2893c18726b251f429a35872bf506b40613e0e09 100644 --- a/package/features +++ b/package/features @@ -46,7 +46,7 @@ when(_'status-page' and _'mesh-batman-adv-15', { }) -when(_'mesh-babel' or _'mesh-olsrd', { +when(_'mesh-olsrd', { 'gluon-radvd', }) diff --git a/package/gluon-l3roamd/Makefile b/package/gluon-l3roamd/Makefile index 25cb830ffbc922df093bdf9c5bb2ea3524b00460..67ed083a033d9f38dd226b7a6588f61235040bbf 100644 --- a/package/gluon-l3roamd/Makefile +++ b/package/gluon-l3roamd/Makefile @@ -5,7 +5,7 @@ PKG_NAME:=gluon-l3roamd include ../gluon.mk define Package/gluon-l3roamd - TITLE:=Configure l3roamd for babel + TITLE:=Configure l3roamd for l3-mesh DEPENDS:=+gluon-core +gluon-mesh-layer3-common +l3roamd +uc endef diff --git a/package/gluon-mesh-babel/Makefile b/package/gluon-mesh-babel/Makefile deleted file mode 100644 index 61eaff38f954fbc567503df7e703bd895625dc85..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include $(TOPDIR)/rules.mk - -PKG_NAME:=gluon-mesh-babel - -PKG_BUILD_DEPENDS := libbabelhelper -PKG_BUILD_DEPENDS += libjson-c - -include ../gluon.mk - -define Package/gluon-mesh-babel - TITLE:=Babel mesh - DEPENDS:=+gluon-core +babeld +gluon-mesh-layer3-common +libiwinfo +libgluonutil +firewall +libjson-c +libnl-tiny +libubus +libubox +libblobmsg-json +libbabelhelper - PROVIDES:=gluon-mesh-provider -endef - -define Package/gluon-mesh-babel/install - $(Gluon/Build/Install) - - $(INSTALL_DIR) $(1)/lib/gluon/status-page/providers - $(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-babel $(1)/lib/gluon/status-page/providers/ -endef - -$(eval $(call BuildPackageGluon,gluon-mesh-babel)) diff --git a/package/gluon-mesh-babel/check_site.lua b/package/gluon-mesh-babel/check_site.lua deleted file mode 100644 index 2182e833786d6eccc23c228f960cd4ccfe2a193a..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/check_site.lua +++ /dev/null @@ -1,8 +0,0 @@ -need_string_match(in_domain({'node_prefix6'}), '^[%x:]+/64$') - -need_string_match(in_domain({'next_node', 'ip6'}), '^[%x:]+$', false) -need_string_match(in_domain({'next_node', 'ip4'}), '^%d+.%d+.%d+.%d+$', false) - -need_string_match(in_domain({'next_node', 'mac'}), '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$', false) - -need_value(in_domain({'mesh', 'vxlan'}), true, false) diff --git a/package/gluon-mesh-babel/files/etc/hotplug.d/iface/90-gluon-babel-brclient-configure-snooping b/package/gluon-mesh-babel/files/etc/hotplug.d/iface/90-gluon-babel-brclient-configure-snooping deleted file mode 100644 index 9970a875508bfaf043da38f58ede4e2a30b07190..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/files/etc/hotplug.d/iface/90-gluon-babel-brclient-configure-snooping +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -case "$ACTION" -in - ifup) - echo 1 > /sys/devices/virtual/net/br-client/bridge/multicast_snooping - echo 2 > /sys/devices/virtual/net/br-client/bridge/multicast_router - ;; -esac diff --git a/package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babel b/package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babel deleted file mode 100755 index 2d04ff5386b053b45d4ca56ecfd4c98016711825..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/files/etc/init.d/gluon-mesh-babel +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/sh /etc/rc.common -USE_PROCD=1 -START=45 -PORT=33123 - -DAEMON=/usr/sbin/babeld -pidfile=/var/run/gluon-babeld.pid -CONFIGFILE=/etc/gluon-babeld.conf -BABELOPTSFILE=/tmp/addn-babelopts -touch $BABELOPTSFILE - -start_service() { - procd_open_instance - procd_set_param command $DAEMON - procd_append_param command -D -I "$pidfile" -G "$PORT" -c "$CONFIGFILE" $(cat $BABELOPTSFILE) babeldummydoesnotexist - procd_set_param respawn ${respawn_threshold:-60} ${respawn_timeout:-5} ${respawn_retry:-0} - procd_set_param stderr 1 - procd_set_param stdout 1 - procd_close_instance -} - -echotobabel() { - local count=0 - local line="$1" - local maxretries=10 - while ! (echo -e "$line" | busybox nc ::1 "$PORT" >/dev/null 2>&1) - do - sleep 1 - echo retrying to connect to babeld in PID $$, waited ${count}s >&2 - count=$((count+1)) - if [ $count -gt $maxretries ]; then - return 1 - fi - done - return 0 -} - -waitforsocket() { - echotobabel "dump" - [ $? -gt 0 ] && { echo "Failed to connect to babeld socket on port $PORT, assuming the service was not started properly"; exit 43; } -} - -reload_service() { - waitforsocket - - for i in $(ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device") - do - if ! echotobabel dump|grep "add interface"|grep -q $i - then - echotobabel "interface $i update-interval 300" - fi - done - - for i in $(echotobabel "dump"|grep "add interface"|cut -d" " -f3) - do - if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"|grep -q $i - then - echotobabel "flush interface $i" - fi - done -} - -service_triggers() { - local script=$(readlink "$initscript") - local name=$(basename "${script:-$initscript}") - - procd_open_trigger - procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload - procd_close_trigger -} - -service_started() { -# make sure the init script does not finish until babeld is actually up. -# unfortunately procd will still start multiple instances of the same script which is why waitforsocket is also run on reload - waitforsocket -} -stop_service(){ - kill $(pgrep -P 1 babeld) -} -status() { - kill -USR1 $(pgrep -P 1 babeld) -} diff --git a/package/gluon-mesh-babel/files/lib/gluon/respondd/client.dev b/package/gluon-mesh-babel/files/lib/gluon/respondd/client.dev deleted file mode 100644 index 202a2374ae5a6d18c57d5f0ed33e89bc87abb6bc..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/files/lib/gluon/respondd/client.dev +++ /dev/null @@ -1 +0,0 @@ -mmfd diff --git a/package/gluon-mesh-babel/files/lib/gluon/state/check.d/has_neighbours b/package/gluon-mesh-babel/files/lib/gluon/state/check.d/has_neighbours deleted file mode 100644 index b0f5aa34fde5f3f5568fb3cf208cec41929b2a02..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/files/lib/gluon/state/check.d/has_neighbours +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo dump | nc ::1 33123 | grep -qF "add neighbour" diff --git a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig b/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig deleted file mode 100755 index 7465494b55f0eae5f8a2c82afcfe7629823be7e1..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/lua - -local site = require 'gluon.site' -local l3 = require 'gluon.l3' -local uci = require('simple-uci').cursor() -local nodeip = uci:get('network', 'loopback', 'ip6addr'):match('^[^/]+') -local babelconf='/etc/gluon-babeld.conf' - -local file = io.open(babelconf, "w") -file:write("ipv6-subtrees true\n") -file:write("reflect-kernel-metric true\n") -file:write("export-table 254\n") -file:write("import-table 254\n") - -file:write("out ip " .. site.next_node.ip6() .. "/128 deny\n") -file:write("redistribute ip " .. site.next_node.ip6() .. "/128 deny\n") -file:write("redistribute ip " .. site.prefix6() .. " eq 128 allow\n") -file:write("redistribute ip " .. l3.node_client_prefix6() .. " eq 128 allow\n") -file:write("redistribute ip " .. site.node_prefix6() .. " eq 128 allow\n") -file:write("redistribute ip 2000::/3 allow\n") -file:write("redistribute local if br-wan deny\n") -file:write("redistribute local ip 0.0.0.0/0 deny\n") -file:write("install pref-src " .. nodeip .."\n") -file:close() diff --git a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/310-gluon-mesh-babel-firewall b/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/310-gluon-mesh-babel-firewall deleted file mode 100755 index 09daeba77addde5a64d6fc036b736f51fe1145b6..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/310-gluon-mesh-babel-firewall +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/lua - -local uci = require('simple-uci').cursor() - -uci:section('firewall', 'rule', 'mesh_babel', { - src = 'mesh', - src_ip = 'fe80::/64', - dest_port = '6696', - proto = 'udp', - target = 'ACCEPT', -}) - -uci:save('firewall') diff --git a/package/gluon-mesh-babel/src/Makefile b/package/gluon-mesh-babel/src/Makefile deleted file mode 100644 index 80d29fa942dd3b0ae8eadaa134ebbd985631c180..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/src/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -all: respondd.so neighbours-babel - -CFLAGS += -Wall -g -fPIC -D_GNU_SOURCE - -ifeq ($(origin PKG_CONFIG), undefined) - PKG_CONFIG = pkg-config - ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),) - $(error $(PKG_CONFIG) not found) - endif -endif - -ifeq ($(origin LIBBABEL_CFLAGS) $(origin LIBBABEL_LDLIBS), undefined undefined) - LIBBABEL_NAME ?= libbabelhelper - ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBBABEL_NAME) 2>/dev/null),) - $(error No $(LIBBABEL_NAME) development libraries found!) - endif - LIBBABEL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBBABEL_NAME)) - LIBBABEL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBABEL_NAME)) -endif -CFLAGS += $(LIBBABEL_CFLAGS) -LDLIBS += $(LIBBABEL_LDLIBS) - -CFLAGS_JSONC = $(shell pkg-config --cflags json-c) -LDFLAGS_JSONC = $(shell pkg-config --libs json-c) - - -respondd.so: respondd.c handle_neighbour.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -shared $(LDFLAGS_JSONC) -o $@ $^ -lgluonutil -lblobmsg_json -lubox -lubus -luci - -neighbours-babel: neighbours-babel.c handle_neighbour.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDLIBS) $(LDFLAGS_JSONC) -o $@ $^ diff --git a/package/gluon-mesh-babel/src/handle_neighbour.c b/package/gluon-mesh-babel/src/handle_neighbour.c deleted file mode 100644 index 950bfe45810af9a28215be016e9942523b6f62bf..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/src/handle_neighbour.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include "handle_neighbour.h" -#include <libbabelhelper/babelhelper.h> - -bool handle_neighbour(char **data, void *arg) { - struct json_object *obj = (struct json_object*)arg; - - if (data[NEIGHBOUR]) { - struct json_object *neigh = json_object_new_object(); - - if (data[RXCOST]) - json_object_object_add(neigh, "rxcost", json_object_new_int(atoi(data[RXCOST]))); - if (data[TXCOST]) - json_object_object_add(neigh, "txcost", json_object_new_int(atoi(data[TXCOST]))); - if (data[COST]) - json_object_object_add(neigh, "cost", json_object_new_int(atoi(data[COST]))); - if (data[REACH]) - json_object_object_add(neigh, "reachability", json_object_new_double(strtod(data[REACH], NULL))); - if (data[IF]) - json_object_object_add(neigh, "ifname", json_object_new_string(data[IF])); - if (data[ADDRESS]) - json_object_object_add(obj, data[ADDRESS] , neigh); - } - return true; -} diff --git a/package/gluon-mesh-babel/src/handle_neighbour.h b/package/gluon-mesh-babel/src/handle_neighbour.h deleted file mode 100644 index 85e0dcfc0c4b3146904f19d745d508f3bed4f525..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/src/handle_neighbour.h +++ /dev/null @@ -1,4 +0,0 @@ -#include <json-c/json.h> -#include <stdbool.h> - -bool handle_neighbour(char **line, void *arg); diff --git a/package/gluon-mesh-babel/src/neighbours-babel.c b/package/gluon-mesh-babel/src/neighbours-babel.c deleted file mode 100644 index 31f9c606f99f70bd356aa1415499ab40d9e351be..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/src/neighbours-babel.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <json-c/json.h> -#include <libbabelhelper/babelhelper.h> -#include "handle_neighbour.h" - -int main(void) { - struct json_object *neighbours; - - printf("Content-type: text/event-stream\n\n"); - fflush(stdout); - - struct babelhelper_ctx bhelper_ctx = {}; - while (1) { - neighbours = json_object_new_object(); - if (!neighbours) - continue; - - bhelper_ctx.debug = false; - babelhelper_readbabeldata(&bhelper_ctx, "dump", (void*)neighbours, handle_neighbour); - - printf("data: %s\n\n", json_object_to_json_string(neighbours)); - fflush(stdout); - json_object_put(neighbours); - neighbours = NULL; - sleep(10); - } - - return 0; -} diff --git a/package/gluon-mesh-babel/src/respondd.c b/package/gluon-mesh-babel/src/respondd.c deleted file mode 100644 index 9584a4331d8c91b8a014e8d758d16b4afb8c5091..0000000000000000000000000000000000000000 --- a/package/gluon-mesh-babel/src/respondd.c +++ /dev/null @@ -1,524 +0,0 @@ -/* SPDX-FileCopyrightText: 2016, Matthias Schiffer <mschiffer@universe-factory.net> */ -/* SPDX-License-Identifier: BSD-2-Clause */ - - -#include <respondd.h> - -#include <json-c/json.h> -#include <libgluonutil.h> -#include <uci.h> - -#include <inttypes.h> -#include <stdbool.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -#include <arpa/inet.h> -#include <net/if.h> -#include <netinet/in.h> - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <ifaddrs.h> - -#include <netdb.h> -#include <errno.h> -#include <libbabelhelper/babelhelper.h> - -#include <libubox/blobmsg_json.h> -#include <libubus.h> - -#define SOCKET_INPUT_BUFFER_SIZE 255 - -#define PROTOLEN 32 - -#define UBUS_TIMEOUT 30000 - -static struct babelhelper_ctx bhelper_ctx = {}; - -static bool get_linklocal_address(const char *ifname, char lladdr[INET6_ADDRSTRLEN]) { - struct ifaddrs *ifaddr, *ifa; - bool ret = false; - - if (getifaddrs(&ifaddr) == -1) { - perror("getifaddrs"); - return false; - } - - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) - continue; - - if (ifa->ifa_addr->sa_family != AF_INET6) - continue; - - if (strcmp(ifname, ifa->ifa_name) != 0) - continue; - - const struct in6_addr *address = &((const struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; - if (!IN6_IS_ADDR_LINKLOCAL(address)) - continue; - - if (!inet_ntop(AF_INET6, address, lladdr, INET6_ADDRSTRLEN)) { - perror("inet_ntop"); - continue; - } - - ret = true; - break; - } - - freeifaddrs(ifaddr); - return ret; -} - - -static char* get_line_from_run(const char* command) { - FILE *fp; - char *line = NULL; - size_t len = 0; - - fp = popen(command, "r"); - - if (fp != NULL) { - ssize_t r = getline(&line, &len, fp); - if (r >= 0) { - len = strlen(line); - - if (len && line[len-1] == '\n') - line[len-1] = 0; - } - else { - free(line); - line = NULL; - } - - pclose(fp); - } - return line; -} - -static struct json_object * get_addresses(void) { - char *primarymac = gluonutil_get_sysconfig("primary_mac"); - char *address = malloc(INET6_ADDRSTRLEN+1); - char node_prefix_str[INET6_ADDRSTRLEN+1]; - struct in6_addr node_prefix = {}; - struct json_object *retval = json_object_new_array(); - - if (!gluonutil_get_node_prefix6(&node_prefix)) { - fprintf(stderr, "get_addresses: could not obtain mesh-prefix from site.conf. Not adding addresses to json data\n"); - goto free; - } - - if (inet_ntop(AF_INET6, &(node_prefix.s6_addr), node_prefix_str, INET6_ADDRSTRLEN) == NULL) { - fprintf(stderr, "get_addresses: could not convert mesh-prefix from site.conf to string\n"); - goto free; - } - - char *prefix_addresspart = strndup(node_prefix_str, INET6_ADDRSTRLEN); - if (! babelhelper_generateip_str(address, primarymac, prefix_addresspart) ) { - fprintf(stderr, "IP-address could not be generated by babelhelper"); - } - free(prefix_addresspart); - - json_object_array_add(retval, json_object_new_string(address)); - -free: - free(address); - free(primarymac); - - return retval; -} - -static void mesh_add_if(const char *ifname, struct json_object *wireless, - struct json_object *tunnel, struct json_object *other) { - char str_ip[INET6_ADDRSTRLEN]; - - if (!get_linklocal_address(ifname, str_ip)) - return; - - struct json_object *address = json_object_new_string(str_ip); - - /* In case of VLAN and bridge interfaces, we want the lower interface - * to determine the interface type (but not for the interface address) */ - char lowername[IF_NAMESIZE]; - gluonutil_get_interface_lower(lowername, ifname); - - switch(gluonutil_get_interface_type(lowername)) { - case GLUONUTIL_INTERFACE_TYPE_WIRELESS: - json_object_array_add(wireless, address); - break; - - case GLUONUTIL_INTERFACE_TYPE_TUNNEL: - json_object_array_add(tunnel, address); - break; - - default: - json_object_array_add(other, address); - } -} - - -static bool handle_neighbour(char **data, void *obj) { - if (data[NEIGHBOUR]) { - struct json_object *neigh = json_object_new_object(); - - if (data[RXCOST]) - json_object_object_add(neigh, "rxcost", json_object_new_int(atoi(data[RXCOST]))); - if (data[TXCOST]) - json_object_object_add(neigh, "txcost", json_object_new_int(atoi(data[TXCOST]))); - if (data[COST]) - json_object_object_add(neigh, "cost", json_object_new_int(atoi(data[COST]))); - if (data[REACH]) - json_object_object_add(neigh, "reachability", json_object_new_double(strtod(data[REACH], NULL))); - - if (!data[IF]) - return true; - - struct json_object *nif; - if (!json_object_object_get_ex(obj, data[IF], &nif)) { - char str_ip[INET6_ADDRSTRLEN]; - - nif = json_object_new_object(); - - if (get_linklocal_address(data[IF], str_ip)) - json_object_object_add(nif, "ll-addr", json_object_new_string(str_ip)); - - json_object_object_add(nif, "protocol", json_object_new_string("babel")); - json_object_object_add(obj, data[IF], nif); - - json_object_object_add(nif, "neighbours", json_object_new_object()); - } - - struct json_object *neighborcollector; - json_object_object_get_ex(nif, "neighbours", &neighborcollector); - json_object_object_add(neighborcollector, data[ADDRESS], neigh); - - } - return true; -} - -static struct json_object * get_babel_neighbours(void) { - - struct json_object *neighbours; - neighbours = json_object_new_object(); - if (!neighbours) - return NULL; - - babelhelper_readbabeldata(&bhelper_ctx, "dump", (void*)neighbours, handle_neighbour); - - return(neighbours); -} - -static void blobmsg_handle_list(struct blob_attr *attr, int len, bool array, struct json_object *wireless, struct json_object *tunnel, struct json_object *other); - -static void blobmsg_handle_element(struct blob_attr *attr, bool head, char **ifname, char **proto, struct json_object *wireless, struct json_object *tunnel, struct json_object *other) { - void *data; - - if (!blobmsg_check_attr(attr, false)) - return; - - data = blobmsg_data(attr); - - switch (blob_id(attr)) { - case BLOBMSG_TYPE_STRING: - if (!strncmp(blobmsg_name(attr), "device", 6)) { - free(*ifname); - *ifname = strndup(data, IF_NAMESIZE); - } else if (!strncmp(blobmsg_name(attr), "proto", 5)) { - free(*proto); - *proto = strndup(data, PROTOLEN); - } - return; - case BLOBMSG_TYPE_ARRAY: - blobmsg_handle_list(data, blobmsg_data_len(attr), true, wireless, tunnel, other); - return; - case BLOBMSG_TYPE_TABLE: - blobmsg_handle_list(data, blobmsg_data_len(attr), false, wireless, tunnel, other); - } -} - -static void blobmsg_handle_list(struct blob_attr *attr, int len, bool array, struct json_object *wireless, struct json_object *tunnel, struct json_object *other) { - struct blob_attr *pos; - int rem = len; - - char *ifname = NULL; - char *proto = NULL; - - __blob_for_each_attr(pos, attr, rem) { - blobmsg_handle_element(pos, array, &ifname, &proto, wireless, tunnel, other); - } - - if (ifname && proto) { - if (!strncmp(proto, "gluon_mesh", 10)) { - mesh_add_if(ifname, wireless, tunnel, other); - } - } - free(ifname); - free(proto); -} - -static void add_if_not_empty(struct json_object *obj, const char *key, struct json_object *val) { - if (json_object_array_length(val)) - json_object_object_add(obj, key, val); - else - json_object_put(val); -} - -static void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg) { - struct json_object *ret = json_object_new_object(); - struct json_object *wireless = json_object_new_array(); - struct json_object *tunnel = json_object_new_array(); - struct json_object *other = json_object_new_array(); - - if (!ret || !wireless || !tunnel || !other) { - json_object_put(wireless); - json_object_put(tunnel); - json_object_put(other); - json_object_put(ret); - return; - } - - if (!msg) { - printf("empty message\n"); - return; - } - - blobmsg_handle_list(blobmsg_data(msg), blobmsg_data_len(msg), false, wireless, tunnel, other); - - add_if_not_empty(ret, "wireless", wireless); - add_if_not_empty(ret, "tunnel", tunnel); - add_if_not_empty(ret, "other", other); - - *((struct json_object**)(req->priv)) = ret; -} - - -static struct json_object * get_mesh_ifs() { - struct ubus_context *ubus_ctx; - struct json_object *ret = NULL; - struct blob_buf b = {}; - - unsigned int id=8; - - ubus_ctx = ubus_connect(NULL); - if (!ubus_ctx) { - fprintf(stderr,"could not connect to ubus, not providing mesh-data\n"); - goto end; - } - - blob_buf_init(&b, 0); - ubus_lookup_id(ubus_ctx, "network.interface", &id); - int uret = ubus_invoke(ubus_ctx, id, "dump", b.head, receive_call_result_data, &ret, UBUS_TIMEOUT); - - if (uret > 0) - fprintf(stderr, "ubus command failed: %s\n", ubus_strerror(uret)); - else if (uret == -2) - fprintf(stderr, "invalid call, exiting\n"); - - blob_buf_free(&b); - -end: - ubus_free(ubus_ctx); - return ret; -} - -static struct json_object * get_mesh(void) { - struct json_object *ret = json_object_new_object(); - struct json_object *interfaces = NULL; - interfaces = json_object_new_object(); - json_object_object_add(interfaces, "interfaces", get_mesh_ifs()); - json_object_object_add(ret, "babel", interfaces); - return ret; -} - -static struct json_object * get_babeld_version(void) { - char *version = get_line_from_run("exec babeld -V 2>&1"); - struct json_object *ret = gluonutil_wrap_string(version); - free(version); - return ret; -} - -static struct json_object * respondd_provider_nodeinfo(void) { - bhelper_ctx.debug=false; - struct json_object *ret = json_object_new_object(); - - struct json_object *network = json_object_new_object(); - json_object_object_add(network, "addresses", get_addresses()); - json_object_object_add(network, "mesh", get_mesh()); - json_object_object_add(ret, "network", network); - - struct json_object *software = json_object_new_object(); - struct json_object *software_babeld = json_object_new_object(); - json_object_object_add(software_babeld, "version", get_babeld_version()); - json_object_object_add(software, "babeld", software_babeld); - json_object_object_add(ret, "software", software); - - return ret; -} - -static struct json_object * read_number(const char *ifname, const char *stat) { - const char *format = "/sys/class/net/%s/statistics/%s"; - - struct json_object *ret = NULL; - int64_t i; - - char path[strlen(format) + strlen(ifname) + strlen(stat) + 1]; - snprintf(path, sizeof(path), format, ifname, stat); - - FILE *f = fopen(path, "r"); - if (!f) - return NULL; - - if (fscanf(f, "%"SCNd64, &i) == 1) - ret = json_object_new_int64(i); - - fclose(f); - - return ret; -} - -static struct json_object * get_traffic(void) { - const char *ifname = "br-client"; - - struct json_object *ret = NULL; - struct json_object *rx = json_object_new_object(); - struct json_object *tx = json_object_new_object(); - - json_object_object_add(rx, "packets", read_number(ifname, "rx_packets")); - json_object_object_add(rx, "bytes", read_number(ifname, "rx_bytes")); - json_object_object_add(rx, "dropped", read_number(ifname, "rx_dropped")); - json_object_object_add(tx, "packets", read_number(ifname, "tx_packets")); - json_object_object_add(tx, "dropped", read_number(ifname, "tx_dropped")); - json_object_object_add(tx, "bytes", read_number(ifname, "tx_bytes")); - - ret = json_object_new_object(); - json_object_object_add(ret, "rx", rx); - json_object_object_add(ret, "tx", tx); - - return ret; -} - -static bool handle_route_addgw_nexthop(char **data, void *arg) { - struct json_object *obj = (struct json_object*) arg; - if (data[PREFIX] && data[FROM] && data[VIA] && data[IF]) { - if ( (! strncmp(data[PREFIX], "::/0", 4) ) && ( ! strncmp(data[FROM], "::/0", 4) ) ) { - int gw_nexthoplen=strlen(data[VIA]) + strlen(data[IF])+2; - char gw_nexthop[gw_nexthoplen]; - snprintf(gw_nexthop, gw_nexthoplen , "%s%%%s", data[VIA], data[IF]); - json_object_object_add(obj, "gateway_nexthop", json_object_new_string(gw_nexthop)); - } - } - return true; -} - -static int json_parse_get_clients(json_object * object) { - if (object) { - json_object_object_foreach(object, key, val) { - if (! strncmp("clients", key, 7)) { - return(json_object_get_int(val)); - } - } - } - return(-1); -} - -static int ask_l3roamd_for_client_count() { - struct sockaddr_un addr; - const char *socket_path = "/var/run/l3roamd.sock"; - int fd; - int clients = -1; - char *buf = NULL; - int already_read = 0; - - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - fprintf(stderr, "could not setup l3roamd-control-socket\n"); - return(-1); - } - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)-1); - - if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { - fprintf(stderr, "connect error\n"); - return(-1); - } - - if (write(fd,"get_clients\n",12) != 12) { - perror("could not send command to l3roamd socket: get_clients"); - goto end; - } - - int rc = 0; - do { - char *buf_tmp = realloc(buf, already_read + SOCKET_INPUT_BUFFER_SIZE + 1); - if (buf_tmp == NULL) { - fprintf(stderr, "could not allocate memory for buffer\n"); - goto end; - } - buf = buf_tmp; - - rc = read(fd, &buf[already_read], SOCKET_INPUT_BUFFER_SIZE); - already_read+=rc; - if (rc < 0) { - perror("error on read in ask_l3roamd_for_client_count():"); - goto end; - } - buf[already_read]='\0'; - } while (rc == SOCKET_INPUT_BUFFER_SIZE); - - json_object * jobj = json_tokener_parse(buf); - clients = json_parse_get_clients(jobj); - json_object_put(jobj); - -end: - free(buf); - close(fd); - - return clients; -} - -static struct json_object * get_clients(void) { - struct json_object *ret = json_object_new_object(); - - int total = ask_l3roamd_for_client_count(); - if (total >= 0) - json_object_object_add(ret, "total", json_object_new_int(total)); - - return ret; -} - -static struct json_object * respondd_provider_statistics(void) { - struct json_object *ret = json_object_new_object(); - - json_object_object_add(ret, "clients", get_clients()); - json_object_object_add(ret, "traffic", get_traffic()); - - babelhelper_readbabeldata(&bhelper_ctx, "dump", (void*)ret, handle_route_addgw_nexthop ); - - return ret; -} - -static struct json_object * respondd_provider_neighbours(void) { - struct json_object *ret = json_object_new_object(); - - struct json_object *babel = get_babel_neighbours(); - if (babel) - json_object_object_add(ret, "babel", babel); - - - return ret; -} - - -const struct respondd_provider_info respondd_providers[] = { - {"nodeinfo", respondd_provider_nodeinfo}, - {"statistics", respondd_provider_statistics}, - {"neighbours", respondd_provider_neighbours}, - {} -}; diff --git a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html index fddb4f1f00e9cf5719d39a50b0d65dc5d59aa35d..806145ecdecc46019feec4cb66c0edc9118ae4bc 100644 --- a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html +++ b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html @@ -196,11 +196,8 @@ string.format(' (%s)', nodeinfo.software.autoupdater.branch) %></dd> <%- end %> - <% if nodeinfo.software.babeld or nodeinfo.software['batman-adv'] then -%> + <% if nodeinfo.software['batman-adv'] then -%> <dt><%:Mesh protocol%></dt> - <% if nodeinfo.software.babeld then -%> - <dd>babeld <%| nodeinfo.software.babeld.version %></dd> - <%- end %> <% if nodeinfo.software['batman-adv'] then -%> <dd>batman-adv <%| nodeinfo.software['batman-adv'].version %> (compat<%| nodeinfo.software['batman-adv'].compat %>)</dd> <%- end %>