From 09e1de7dde9840e5cd5dbf13fd6294289ef88522 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Fri, 11 Jul 2014 18:25:39 +0200 Subject: [PATCH] gluon-announced: send nodeinformation on request This is a simple daemon that will respond to multicast UDP packets containing the keyword "nodeinfo" with all the information we currently distribute using alfred. The daemon will listen on all mesh interface, that is the hard interfaces batman-adv uses. --- package/gluon-announced/Makefile | 40 +++ .../etc/hotplug.d/iface/10-gluon-announced | 45 ++++ package/gluon-announced/src/Makefile | 6 + package/gluon-announced/src/gluon-announced.c | 229 ++++++++++++++++++ 4 files changed, 320 insertions(+) create mode 100644 package/gluon-announced/Makefile create mode 100644 package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced create mode 100644 package/gluon-announced/src/Makefile create mode 100644 package/gluon-announced/src/gluon-announced.c diff --git a/package/gluon-announced/Makefile b/package/gluon-announced/Makefile new file mode 100644 index 00000000..4fc31f6a --- /dev/null +++ b/package/gluon-announced/Makefile @@ -0,0 +1,40 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-announced +PKG_VERSION:=1 +PKG_RELEASE:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/gluon-announced + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=announced support + DEPENDS:= +endef + +define Package/gluon-announced/description + Gluon community wifi mesh firmware framework: announced support +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Configure +endef + +define Build/Compile + CFLAGS="$(TARGET_CFLAGS)" CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS) +endef + +define Package/gluon-announced/install + $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/gluon-announced $(1)/usr/bin/ +endef + +$(eval $(call BuildPackage,gluon-announced)) diff --git a/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced new file mode 100644 index 00000000..b5546ff0 --- /dev/null +++ b/package/gluon-announced/files/etc/hotplug.d/iface/10-gluon-announced @@ -0,0 +1,45 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh +. /lib/functions/service.sh + +DEVLIST=/var/run/gluon-announce.devs +DAEMON=/usr/bin/gluon-announced + +ifname_to_dev () { + json_load "$(ubus call network.interface.$1 status)" + json_get_var dev device + + echo "$dev" +} + +restart_announced () { + SERVICE_USE_PID=1 + SERVICE_WRITE_PID=1 + SERVICE_DAEMONIZE=1 + + DEVS=$(cat $DEVLIST | while read dev iface;do echo -n " -i $dev";done) + + service_stop $DAEMON + service_start $DAEMON -g ff02:0:0:0:0:0:2:1001 -p 1001 -s /lib/gluon/announce/announce.lua $DEVS +} + +case "$ACTION" in + ifdown) + sed -i "/$INTERFACE/d" $DEVLIST + ;; + ifup) + DEVICE=$(ifname_to_dev $INTERFACE) + MESH=$(cat /sys/class/net/$DEVICE/batman_adv/mesh_iface) + + [ $MESH = "bat0" ] || exit 0 + + DEVS="$(cat $DEVLIST; echo $DEVICE $INTERFACE)" + + echo "$DEVS" | sort | uniq > $DEVLIST + + restart_announced + + ;; +esac + diff --git a/package/gluon-announced/src/Makefile b/package/gluon-announced/src/Makefile new file mode 100644 index 00000000..73e7a9e2 --- /dev/null +++ b/package/gluon-announced/src/Makefile @@ -0,0 +1,6 @@ +all: gluon-announced + +gluon-announced: gluon-announced.c + +clean: + rm gluon-announced diff --git a/package/gluon-announced/src/gluon-announced.c b/package/gluon-announced/src/gluon-announced.c new file mode 100644 index 00000000..8b4ef58a --- /dev/null +++ b/package/gluon-announced/src/gluon-announced.c @@ -0,0 +1,229 @@ +/* + Copyright (c) 2014, Nils Schneider + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage() { + puts("Usage: gluon-announced [-h] -m -p -i [-i ..] -s