From patchwork Tue Jun 12 19:07:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [v4,2/2] Allow initial configuration from Ethernet From: Fabian Blaese X-Patchwork-Id: 857 Message-Id: <20180612190701.30651-2-fabian@blaese.de> To: franken-dev@freifunk.net Cc: Jan Kraus , Adrian Schmutzler Date: Tue, 12 Jun 2018 21:07:01 +0200 Signed-off-by: Fabian Bläse Tested-by: Fabian Bläse Reviewed-by: Adrian Schmutzler Reviewed-by: Tim Niemeyer Reviewed-by: Robert Langhgammer --- Apply after MacKnocker patchset! Changes in v2: - Fix indentation - Improve usage message - Return if no ethmesh_dev exists - Replace . with : in ping6 sed Changes in v3: - Fix messed up v2 Changes in v4: - indentation fix - double quote ethmesh variable in getEthernetHoodfile function - use sort -u instead of additional uniq - grep for DUP in ping6 to avoid downloading own hoodfile if existing --- .../fff-hoods/files/usr/lib/functions/fff/hoodfile | 24 ++++++++++++++++++++++ .../fff/fff-hoods/files/usr/sbin/configurehood | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile index 4efaa66..8c80802 100644 --- a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile +++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile @@ -53,6 +53,30 @@ getWirelessHoodfile() { fi } +getEthernetHoodfile() { + if [ $# != 1 ]; then + echo "Usage: getEthernetHoodfile " + return 1 + fi + file=$1 + + echo "Trying to get hoodfile from ethernet neighbor..." + + if ! ethmesh_dev=$(uci -q get network.ethmesh.ifname); then + # no ethmesh interface + return 1 + fi + + neighbor_addrs=$(ping6 -c2 ff02::1%"${ethmesh_dev}" | grep seq | grep DUP | cut -d " " -f4 | sed s/:$//g | sort -u) + + for addr in $neighbor_addrs; do + wget -T2 -t1 -qO "$file" "http://[${addr}%${ethmesh_dev}]:2342/keyxchangev2data" && return 0 + done + + # got no hoodfile + return 1 +} + getGatewayHoodfile() { if [ $# != 1 ]; then echo "Usage: getGatewayHoodfile " diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index d06a62d..281d38d 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -98,7 +98,7 @@ else sleep 30 # Wait for the config AP, which may be created at the same time as this script has started - getWirelessHoodfile "$hoodfile" + getEthernetHoodfile "$hoodfile" || getWirelessHoodfile "$hoodfile" #UPLINK: Set up uplink data on first contact: if [ -s /tmp/keyxchangev2data ]; then