From patchwork Sat Aug 26 15:27:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC,3/3] Add fff-hoods Packages From: Christian Dresel X-Patchwork-Id: 454 Message-Id: <1503761266-10028-1-git-send-email-fff@chrisi01.de> To: franken-dev@freifunk.net Cc: Jan Kraus Date: Sat, 26 Aug 2017 17:27:46 +0200 and edit small things in vpn-select and to other small things we need This is only a RFC and not a working Code! I hope i get many feedback here for this idea Signed-off-by: Christian Dresel Signed-off-by: Jan Kraus --- bsp/default/root_file_system/etc/rc.local | 1 + src/packages/fff/fff-hoods/Makefile | 39 ++++ .../fff/fff-hoods/files/usr/lib/micrond/fff-hoods | 1 + .../fff/fff-hoods/files/usr/sbin/configurehood | 198 +++++++++++++++++++++ src/packages/fff/fff-network/Makefile | 2 +- .../fff-network/files/usr/sbin/configurenetwork | 8 +- .../fff/fff-vpn-select/files/usr/sbin/vpn-select | 13 +- src/packages/fff/fff-wireless/Makefile | 4 +- .../fff-wireless/files/lib/functions/fff/wireless | 30 ++++ src/packages/fff/fff/Makefile | 3 +- 10 files changed, 286 insertions(+), 13 deletions(-) create mode 100644 src/packages/fff/fff-hoods/Makefile create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micrond/fff-hoods create mode 100644 src/packages/fff/fff-hoods/files/usr/sbin/configurehood diff --git a/bsp/default/root_file_system/etc/rc.local b/bsp/default/root_file_system/etc/rc.local index bd972fb..c980d8e 100755 --- a/bsp/default/root_file_system/etc/rc.local +++ b/bsp/default/root_file_system/etc/rc.local @@ -2,6 +2,7 @@ # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. +/usr/sbin/configurehood /usr/sbin/configurenetwork touch /tmp/started diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile new file mode 100644 index 0000000..ac48760 --- /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 +fff-network +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/usr/lib/micrond/fff-hoods b/src/packages/fff/fff-hoods/files/usr/lib/micrond/fff-hoods new file mode 100644 index 0000000..a3da358 --- /dev/null +++ b/src/packages/fff/fff-hoods/files/usr/lib/micrond/fff-hoods @@ -0,0 +1 @@ +/5 * * * * /usr/sbin/configurehood 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 100644 index 0000000..7aa0197 --- /dev/null +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -0,0 +1,198 @@ +#!/bin/sh + +. /usr/share/libubox/jshn.sh +. /lib/functions/fff/wireless +. /etc/community.cfg + +project="$VPN_PROJECT" +myLat=$(uci get 'system.@system[0].latitude') +myLon=$(uci get 'system.@system[0].longitude') +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) +hostname=$(cat /proc/sys/kernel/hostname) +[ "$hostname" = "OpenWrt" ] && hostname="" +[ "$hostname" = "" ] && hostname="$mac" + + + +# if Internet, we download the Hoodfile from the keyxchangev2 +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null || + ping -w5 -c3 "$test_ipv4_host2" &>/dev/null || + ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then + + pubkey=$(echo "secret \"$(uci get fastd.fff.secret)\";" | fastd -c - --show-key --machine-readable) + wget -T15 "http://keyserver.freifunk-franken.de/${project}/json.php?mac=$mac&name=$hostname&port=$port&key=$pubkey&lat=$lat&long=$long" -O /tmp/keyxchangev2data +#if no Internet, we connect to the hidden AP and download the file from another Node in range +else + # connect to wireless hidden ap here and download from the next router the json File -O /tmp/keyxchangev2data + # only to that, when we have no gateway in range. If the Uplinkrouter change the hood, we lost the GW and to this automatically again i think! Nice idea? + if [ "$(batctl gwl | grep 'no gateway')" ]; then + #now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file! + #first we delete all wifi settings + if ! wifiDelAll; then + echo "Can't delete current wifi setup" + exit 1 + fi + #now we look for phy and add this + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + if iw phy "$phy" info | grep -q -m1 "2... MHz"; then + echo "$phy is 2.4 GHz" + radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL") + if [ -z "$radio" ]; then + echo "Can't create radio for $phy" + exit 1 + fi + fi + if iw phy "$phy" info | grep -q -m1 "5... MHz"; then + echo "$phy is 5 GHz" + radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL_5GHZ") + if [ -z "$radio" ]; then + echo "Can't create radio for $phy" + exit 1 + fi + fi + #and here we add the station + if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then + echo "Can't add Sta interface on $radio." + exit 1 + else + # here we must set a fix ip adress on the new wifi interface! NO TESTET! + set network.configSta=interface + set network.configSta.proto='static' + # we need a random adress because it can more than 1 Router connect! + # Set $prefix::link-local as IP + suffix=$(awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }' /sys/class/net/br-mesh/address) + addr=$(echo "fded:c8f0:4b9a::" | sed -e 's/\//'$suffix'\//') # need one : or two : after prefix? + set network.configSta.ip6addr=$addr # need /64 or so? + fi + + done + #and here we can check to reach the keyxchangev2 + wget -T15 "http://[fded:c8f0:4b9a::1]/keyxchangev2data" -O /tmp/keyxchangev2data + else + echo "we have a gateway in range and do nothing because we have contact to a hood!" + fi + + +fi + +# we get a json file in this format: +# https://pw.freifunk-franken.de/patch/205/ +# but without signature, every hood file we get is valid! + +# copy the file to webroot that other Meshrouter can download them +cp /tmp/keyxchangev2data /www/public/ + +json_load "$(cat /tmp/keyxchangev2data)" +json_select hood + +json_get_var hood name +json_get_var mesh_bssid mesh_bssid +json_get_var mesh_essid mesh_essid +json_get_var essid essid +# i think the next things we don't active this in the first version! +#json_get_var channel2 channel2 +#json_get_var mode2 mode2 +#json_get_var type2 type2 +#json_get_var channel5 channel5 +#json_get_var mode5 mode5 +#json_get_var type5 type5 +#json_get_var protocol protocol + +echo "Setting hood name: $hood" +uci set system.@system[0].hood=$hood + +if ! wifiDelAll; then + echo "Can't delete current wifi setup" + exit 1 +else + #now we can delete them, because we haven't any Sta here + rm /tmp/novpn +fi + +for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + if iw phy "$phy" info | grep -q -m1 "2... MHz"; then + echo "$phy is 2.4 GHz" + radio=$(wifiAddPhy "$phy" "1") + if [ -z "$radio" ]; then + echo "Can't create radio for $phy" + exit 1 + fi + fi + if iw phy "$phy" info | grep -q -m1 "5... MHz"; then + echo "$phy is 5 GHz" + radio=$(wifiAddPhy "$phy" "13") + if [ -z "$radio" ]; then + echo "Can't create radio for $phy" + exit 1 + fi + fi + # + if ! wifiAddAP "$radio" "$essid" "mesh" "0"; then + echo "Can't add AP interface on $radio." + exit 1 + fi + + if ! wifiAddAP "$radio" "$essid" "configap" "1"; then + echo "Can't add AP interface on $radio." + exit 1 + else + # we must set here a fix ip adress + # this settings are not testet yet! + set network.configap=interface + set network.configap.proto='static' + set network.configap.ip6addr='fded:c8f0:4b9a::1/64' + fi + + if ! wifiAddAdHocMesh "$radio" "$mesh_essid" "$mesh_bssid"; then + echo "Can't add AP interface on $radio." + exit 1 + fi +done + +echo "Loading wifi" +wifi + +json_select .. +json_select network + +json_get_var prefix ula_prefix +echo "Setting prefix: $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 + set network.globals=globals + set network.globals.ula_prefix="$prefix" + set network.mesh.ip6addr="$addr" + commit network +EOF + +# and now we read the VPN Data and give this data to fff-vpn + +json_load "$(cat /tmp/keyxchangev2data)" +json_select vpn +local Index="1" +rm /tmp/fastd_${project}_output +touch /tmp/fastd_${project}_output +while json_select $Index > /dev/null +do + json_get_var protocol protocol + if [ "$protocol" == "fastd" ] + then + json_get_var servername name + echo "####\"$servername\".conf #name \"$servername\";" >> /tmp/fastd_${project}_output + json_get_var key key + echo "key \"$key\";" >> /tmp/fastd_${project}_output + json_get_var address address + json_get_var port port + echo "remote ipv4 \"$address\" port $port;" >> /tmp/fastd_${project}_output + echo "remote ipv6 \"$address\" port $port;" >> /tmp/fastd_${project}_output + echo "float;" >> /tmp/fastd_${project}_output + fi + echo "###" >> /tmp/fastd_${project}_output +done + +# do we need a reboot or set any thinks back here? Don't know! + + diff --git a/src/packages/fff/fff-network/Makefile b/src/packages/fff/fff-network/Makefile index fee3f98..d34016c 100644 --- a/src/packages/fff/fff-network/Makefile +++ b/src/packages/fff/fff-network/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-network -PKG_VERSION:=0.0.6 +PKG_VERSION:=0.0.7 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-network diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork index 7ecfa3b..bcfa7ad 100755 --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork @@ -150,18 +150,16 @@ if [[ -n "$ETH0MAC" ]]; then /etc/init.d/network restart fi -if uci get network.mesh.ip6addr +if uci get network.globals.ula_prefix then - echo "IPv6 for mesh is set already" -else # Some time needed :( sleep 5 + prefix=$(uci get network.globals.ula_prefix) for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do ip -6 addr del $ip dev br-mesh done - prefix="fdff:0::/64" # Set $prefix::MAC as IP suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address) addr=$(echo $prefix | sed -e 's/\//'$suffix'\//') @@ -188,4 +186,6 @@ else uci -q commit network /etc/init.d/fff-uradvd restart +else + echo "IPv6 Prefix is not set" fi diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select index c3d003f..efe79a9 100755 --- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select +++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select @@ -9,7 +9,6 @@ rm /tmp/fastd_${project}_peers/* count=0 # get fastd peers pubkey=$(echo "secret \"$(uci get fastd.fff.secret)\";" | fastd -c - --show-key --machine-readable) -wget -T15 "http://keyserver.freifunk-franken.de/${project}/geo.php?mac=$mac&name=$hostname&port=$port&key=$pubkey&lat=$lat&long=$long" -O /tmp/fastd_${project}_output filecounts=$(awk '/^####/ { gsub(/^####/, "", $0); gsub(/.conf/, "", $0); print $0; }' /tmp/fastd_${project}_output) for file in $filecounts; do awk "{ if(a) print }; /^####$file.conf$/{a=1}; /^$/{a=0};" /tmp/fastd_${project}_output | sed 's/ float;/;/g' > /etc/fastd/$project/peers/$file @@ -42,14 +41,18 @@ test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken keyserver test_ipv4_host2="8.8.8.8" # Google DNS test_ipv6_host1="heise.de" # heise Zeitschriftenverlag +#need this here because the next if need this variable +. /etc/community.cfg +project="$VPN_PROJECT" + # Only do something when the router has internet connection -if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null || +if (ping -w5 -c3 "$test_ipv4_host1" &>/dev/null || ping -w5 -c3 "$test_ipv4_host2" &>/dev/null || - ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then + ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null) && + [ -n /tmp/fastd_${project}_output ]; then + # does we need && [ -n /tmp/fastd_${project}_output ] ?? don't know! # set some vars - . /etc/community.cfg - project="$VPN_PROJECT" mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null) lat=$(uci get system.@system[0].latitude) long=$(uci get system.@system[0].longitude) diff --git a/src/packages/fff/fff-wireless/Makefile b/src/packages/fff/fff-wireless/Makefile index 12456e5..046d932 100644 --- a/src/packages/fff/fff-wireless/Makefile +++ b/src/packages/fff/fff-wireless/Makefile @@ -1,8 +1,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-wireless -PKG_VERSION:=0.0.1 -PKG_RELEASE:=1 +PKG_VERSION:=0.0.2 +PKG_RELEASE:=2 PKG_BUILD_DIR:=$(BUILD_DIR)/fff-wireless diff --git a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless index 8c990ce..cf97700 100644 --- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless +++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless @@ -117,4 +117,34 @@ wifiAddAP() { echo "${iface}" } +wifiAddSta() { + if [ $# -ne "3" ] + then + echo "Usage: wifiAddSta " + return 1 + fi + + local radio=$1 + local essid=$2 + local network=$3 + + local channel=$(uci get "wireless.${radio}.channel") + local iface="w2Sta" + if [ "$channel" -gt "14" ]; then + iface="w5Sta" + fi + uci batch <<-__EOF__ + set wireless.${iface}='wifi-iface' + set wireless.${iface}.device='${radio}' + set wireless.${iface}.network='${network}' + set wireless.${iface}.ifname='${iface}' + set wireless.${iface}.mode='sta' + set wireless.${iface}.ssid='${essid}' + + commit wireless + __EOF__ + + echo "${iface}" +} + # vim: set noexpandtab:tabstop=4 diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile index 1889818..1579070 100644 --- a/src/packages/fff/fff/Makefile +++ b/src/packages/fff/fff/Makefile @@ -28,7 +28,8 @@ define Package/fff-base +fff-sysupgrade \ +fff-wireless \ +fff-timeserver \ - +fff-vpn-select + +fff-vpn-select \ + +fff-hoods endef define Package/fff-base/description