[RFC PATCH] fff-hoods: add initial hood configuration package

Tim Niemeyer tim.niemeyer at mastersword.de
Mo Jan 4 17:04:33 CET 2016


Signed-off-by: Tim Niemeyer <tim.niemeyer at mastersword.de>
---

 bsp/default/root_file_system/etc/firewall.user     |   9 ++
 src/packages/fff/fff-hoods/Makefile                |  39 ++++++
 .../fff/fff-hoods/files/etc/hoods/fuerth.hood      |  18 +++
 .../fff/fff-hoods/files/etc/hoods/nuernberg.hood   |  18 +++
 .../fff/fff-hoods/files/etc/hoods/test.hood        |  18 +++
 .../fff-hoods/files/etc/hoods/trainstation.hood    |  17 +++
 .../fff/fff-hoods/files/etc/uci-defaults/hood-dhcp |  18 +++
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 144 +++++++++++++++++++++
 src/packages/fff/fff/Makefile                      |   4 +-
 9 files changed, 283 insertions(+), 2 deletions(-)
 create mode 100644 src/packages/fff/fff-hoods/Makefile
 create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
 create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
 create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/test.hood
 create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
 create mode 100644 src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
 create mode 100755 src/packages/fff/fff-hoods/files/usr/sbin/configurehood

diff --git a/bsp/default/root_file_system/etc/firewall.user b/bsp/default/root_file_system/etc/firewall.user
index 1af101c..d776d20 100755
--- a/bsp/default/root_file_system/etc/firewall.user
+++ b/bsp/default/root_file_system/etc/firewall.user
@@ -59,6 +59,11 @@ ebtables -A MULTICAST_OUT -p IPv4 --ip-proto igmp -j RETURN
 ######## INPUT ############
 ebtables -P INPUT ACCEPT
 
+# Erlaube dhcpv6 request / router solicitation von client zu knoten
+ebtables -A INPUT -p IPv6 -i ! bat0 --ip6-proto udp --ip6-dport 547 -j ACCEPT
+ebtables -A INPUT -p IPv6 -i ! bat0 --ip6-proto ipv6-icmp --ip6-icmp-type router-solicitation -j ACCEPT
+ebtables -A INPUT -d Multicast --logical-in br-mesh -i ! bat0 -j ACCEPT
+
 # Erlaube nur DHCP Antworten von BATMAN -> KNOTEN
 ebtables -A INPUT -p IPv4 --ip-proto udp --ip-dport 68 -j IN_ONLY
 # Erlaube nur DHCPv6 Antworten von BATMAN -> KNOTEN
@@ -89,6 +94,10 @@ ebtables -A FORWARD -d Multicast --logical-out br-mesh -o bat0 -j MULTICAST_OUT
 ######## OUTPUT ############
 ebtables -P OUTPUT ACCEPT
 
+# Erlaube dhcpv6 reply / router advertisment von knoten zu client
+ebtables -A OUTPUT -p IPv6 -o ! bat0 --ip6-proto udp --ip6-dport 546 -j ACCEPT
+ebtables -A OUTPUT -p IPv6 -o ! bat0 --ip6-proto ipv6-icmp --ip6-icmp-type router-advertisement -j ACCEPT
+
 # Erlaube nur DHCP Request von KNOTEN -> BATMAN
 ebtables -A OUTPUT -p IPv4 --ip-proto udp --ip-dport 67 -j OUT_ONLY
 # Erlaube nur DHCPv6 Request von KNOTEN -> BATMAN
diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
new file mode 100644
index 0000000..bf92689
--- /dev/null
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -0,0 +1,39 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=fff-hoods
+PKG_VERSION:=0.0.1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/fff-hoods
+    SECTION:=base
+    CATEGORY:=Freifunk
+    TITLE:= Freifunk-Franken hoods
+    URL:=http://www.freifunk-franken.de
+    DEPENDS:=+mdns +odhcpd
+endef
+
+define Package/fff-hoods/description
+    This package load and configures the current hood
+endef
+
+define Build/Prepare
+	echo "all: " > $(PKG_BUILD_DIR)/Makefile
+endef
+
+define Build/Configure
+	# nothing
+endef
+
+define Build/Compile
+	# nothing
+endef
+
+define Package/fff-hoods/install
+	$(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,fff-hoods))
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood b/src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
new file mode 100644
index 0000000..fd5c9ea
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
@@ -0,0 +1,18 @@
+{
+ "version": 1,
+ "hood": {
+  "name": "fuerth",
+  "bssid": "ca:ff:ee:ba:be:02",
+  "protocol": "batman-adv-v14",
+  "channel2": 1,
+  "mode2": "ht20",
+  "type2": "adhoc",
+  "channel5": 40,
+  "mode5": "ht40+",
+  "type5": "adhoc",
+  "location": { "lat": 49.478330, "lon": 10.990270 },
+ },
+ "network": {
+  "ula_prefix": "fdff:2::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood b/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
new file mode 100644
index 0000000..6c26ab3
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
@@ -0,0 +1,18 @@
+{
+ "version": 1,
+ "hood": {
+  "name": "nuernberg",
+  "bssid": "ca:ff:ee:ba:be:03",
+  "protocol": "batman-adv-v14",
+  "channel2": 1,
+  "mode2": "HT20",
+  "type": "adhoc",
+  "channel5": 40,
+  "mode5": "HT40+",
+  "type": "adhoc",
+  "location": { "lat": 49.448856, "lon": 11.082108 },
+ },
+ "network": {
+  "ula_prefix": "fdff:3::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/test.hood b/src/packages/fff/fff-hoods/files/etc/hoods/test.hood
new file mode 100644
index 0000000..18a93f1
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/test.hood
@@ -0,0 +1,18 @@
+{
+ "version": 0,
+ "hood": {
+  "name": "test",
+  "bssid": "ca:ff:ee:ba:be:ff",
+  "protocol": "batman-adv-v14",
+  "channel2": 13,
+  "mode2": "ht20",
+  "type2": "adhoc",
+  "channel5": 40,
+  "mode5": "ht40+",
+  "type5": "adhoc",
+  "location": { "lat": 49.46654, "lon": 10.992 },
+ },
+ "network": {
+  "ula_prefix": "fdff:ff::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood b/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
new file mode 100644
index 0000000..41ac75e
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
@@ -0,0 +1,17 @@
+{
+ "version": 1,
+ "hood": {
+  "name": "trainstation",
+  "bssid": "ca:ff:ee:ba:be:00",
+  "protocol": "batman-adv-v14",
+  "channel2": 1,
+  "mode2": "ht20",
+  "type2": "adhoc",
+  "channel5": 40,
+  "mode5": "ht40+",
+  "type5": "adhoc",
+ },
+ "network": {
+  "ula_prefix": "fdff:0::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp b/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
new file mode 100644
index 0000000..d9fdb6d
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
@@ -0,0 +1,18 @@
+#!/bin/sh
+>/etc/config/dhcp
+
+uci batch <<EOF
+set dhcp.odhcpd=odhcpd
+set dhcp.odhcpd.maindhcp=0
+set dhcp.odhcpd.leasefile=/tmp/hosts/odhcpd
+set dhcp.odhcpd.leasetrigger=/usr/sbin/odhcpd-update
+set dhcp.local=dhcp
+set dhcp.local.interface=mesh
+set dhcp.local.ra=server
+set dhcp.local.dhcpv6=server
+set dhcp.local.dhcpv4=disabled
+set dhcp.local.ndp=disabled
+set dhcp.local.ra_default=0
+set dhcp.local.ra_preference=low
+commit dhcp
+EOF
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
new file mode 100755
index 0000000..480b35c
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -0,0 +1,144 @@
+#!/bin/sh
+
+HOODDIR=/etc/hoods
+
+. /usr/share/libubox/jshn.sh
+
+myGeo=$(uci get 'system. at system[0].geo')
+
+if [ -z "$myGeo" ]; then
+  nearestHood=trainstation
+else
+  for hood in $HOODDIR/*.hood; do
+    echo "Parsing $hood"
+    filename=$(basename "$hood" .hood)
+    json_load "$(cat $hood)"
+    json_get_var ret version
+    if [ "$ret" -ne "1" ]; then
+      echo "Wrong version for $hood"
+      continue
+    fi
+
+    json_select hood
+    json_get_var protocol protocol
+    if [ "$protocol" != "batman-adv-v14" ]; then
+      echo "Unknown protocol in $hood"
+      continue
+    fi
+    json_get_var type2 type2
+    json_get_var type5 type5
+    if [ "$type2" != "adhoc" -o "$type5" != "adhoc" ]; then
+      echo "Unknown mesh type in $hood"
+      continue
+    fi
+    json_get_var hoodname name
+    if ! json_select location; then
+        echo "No location for $hood"
+        continue
+    fi
+    json_get_var lat lat
+    json_get_var lon lon
+
+    d=$(echo "$lat $lon $myGeo" | awk '
+    function rad(deg) { # degrees to radians
+        return deg * (3.1415926 / 180.)
+    }
+    function distance(lat1,lon1,lat2,lon2) {
+        dlat = rad(lat2-lat1)
+        dlon = rad(lon2-lon1)
+        lat1 = rad(lat1)
+        lat2 = rad(lat2)
+        a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
+        return 6371 * 2 * atan2(sqrt(a),sqrt(1-a)) * 1000
+    }
+    {
+        printf("%d", distance($1, $2, $3, $4))
+    }')
+    if [ -z "$nearestDistance" ]; then
+      nearestDistance=$d
+      nearestHood=$filename
+    else
+      if [ "$d" -lt "$nearestDistance" ]; then
+        nearestDistance=$d
+        nearestHood=$filename
+      fi
+    fi
+  done
+fi
+
+echo "Found Hood: $nearestHood in $nearestDistance m"
+
+json_load "$(cat $HOODDIR/$nearestHood.hood)"
+json_select hood
+
+json_get_var hood name
+json_get_var bssid bssid
+json_get_var channel2 channel2
+json_get_var mode2 mode2
+json_get_var protocol protocol
+json_get_var type2 type2
+
+echo "Setting hood name: $hood"
+echo "Setting channel 2.4 Ghz: $channel2"
+echo "Setting mode 2.4 GHz: $mode2"
+echo "Setting mesh 2.4 GHz type: $type2"
+
+echo "Shutting down wifi"
+wifi down
+
+uci set wireless.radio0=wifi-device
+uci set wireless.radio0.type=mac80211
+uci set wireless.radio0.channel=$channel2
+uci set wireless.radio0.phy=phy0
+uci set wireless.radio0.hwmode=11g
+uci set wireless.radio0.htmode=$mode2
+uci set wireless.radio0.country=DE
+uci set wireless. at wifi-iface[0]=wifi-iface
+uci set wireless. at wifi-iface[0].device=radio0
+uci set wireless. at wifi-iface[0].network=w2mesh
+uci set wireless. at wifi-iface[0].ifname=w2mesh
+uci set wireless. at wifi-iface[0].mode=$type2
+uci set wireless. at wifi-iface[0].bssid=$bssid
+uci set wireless. at wifi-iface[0].ssid=${protocol}.${hood}.freifunk.net
+uci set wireless. at wifi-iface[0].mcast_rate=6000
+uci set wireless. at wifi-iface[0].encryption=none
+uci set wireless. at wifi-iface[1]=wifi-iface
+uci set wireless. at wifi-iface[1].device=radio0
+uci set wireless. at wifi-iface[1].network=mesh
+uci set wireless. at wifi-iface[1].ifname=w2ap
+uci set wireless. at wifi-iface[1].mode=ap
+uci set wireless. at wifi-iface[1].ssid=${hood}.freifunk.net
+uci set wireless. at wifi-iface[1].encryption=none
+uci commit
+
+echo "Loading wifi"
+wifi
+
+json_select ..
+json_select network
+
+echo "Setting prefix: $prefix"
+json_get_var prefix ula_prefix
+suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)
+addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
+
+uci -q batch <<-EOF >/dev/null
+    del network.globals
+    add network.globals
+    set network.globals.ula_prefix=$prefix
+    set network.mesh.ip6addr=$addr
+    commit network
+EOF
+
+echo "Restarting network"
+for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
+    ip -6 addr del $ip dev br-mesh
+done
+ip -6 addr add $addr dev br-mesh
+#/etc/init.d/odhcpd stop
+#/etc/init.d/network restart
+#/etc/init.d/odhcpd start
+
+echo "Finding fastd Gateways, if online. Configure fastd."
+
+echo "Done"
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
index e29713f..df41fe7 100644
--- a/src/packages/fff/fff/Makefile
+++ b/src/packages/fff/fff/Makefile
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff
 PKG_VERSION:=0.0.1
-PKG_RELEASE:=4
+PKG_RELEASE:=5
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/fff
 
@@ -14,7 +14,7 @@ define Package/fff-base
     DEFAULT:=y
     TITLE:= Freifunk-Franken Base
     URL:=http://www.freifunk-franken.de
-    DEPENDS:=+micrond +fff-nodewatcher +fff-web
+    DEPENDS:=+micrond +fff-nodewatcher +fff-web +fff-hoods
 endef
 
 define Package/fff-base/description
-- 
2.1.4




Mehr Informationen über die Mailingliste franken-dev