[PATCH] Make possible to use fixed hoodfile

Tim Niemeyer tim at tn-x.org
Sa Jan 20 13:09:46 CET 2018


Hi

Reviewed und Applied, sowie die hier angesprochenen Änderungen
übernommen.

Tim

Am Donnerstag, den 04.01.2018, 15:53 +0100 schrieb
mail at adrianschmutzler.de:
> Hallo,
> 
> mir fällt immer noch kein Problem ein, was dem entgegensteht.
> 
> Drei Kleinigkeiten:
> In den Commit-Titel würde ich an den Anfang noch "fff-hoods: " oder
> "configurehood: " schreiben, damit man es zuordnen kann.
> Die anderen Kleinigkeiten inline.
> Beides kann ggf. beim Applien korrigiert werden!
> 
> Reviewed-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
> 
> > -----Original Message-----
> > From: franken-dev [mailto:franken-dev-bounces at freifunk.net] On
> > Behalf
> > Of Christian Dresel
> > Sent: Dienstag, 2. Januar 2018 15:47
> > To: franken-dev at freifunk.net
> > Subject: [PATCH] Make possible to use fixed hoodfile
> > 
> > Add a complete hoodfile to /etc/hoodfile to use only this file
> > 
> > Signed-off-by: Christian Dresel <fff at chrisi01.de>
> > ---
> >  .../fff/fff-hoods/files/usr/sbin/configurehood     | 158
> 
> +++++++++++----------
> >  .../files/etc/uci-defaults/99-fff-sysupgrade       |   1 +
> >  2 files changed, 83 insertions(+), 76 deletions(-)
> > 
> > diff --git a/src/packages/fff/fff-
> > hoods/files/usr/sbin/configurehood
> > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > index 2b9c47e..f140eaa 100755
> > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > @@ -11,6 +11,7 @@ sectortmp=/tmp/sectorfile
> > sectorcopy=/www/hood/sectorfile  hiddenapfile=/tmp/hiddenapflag
> > resetnetworkfile=/tmp/resetnetwork
> > +hoodlocal=/etc/hoodfile
> > 
> >  rm -f "$hoodfile"
> > 
> > @@ -72,92 +73,97 @@ if [ -f "$resetnetworkfile" ]; then
> >  	rm "$resetnetworkfile"
> >  fi
> > 
> > -# if we have Internet, we download the Hoodfile from the
> > keyxchangev2 -if
> > hasInternet ; then
> > -	wget -T15 -t5 "http://keyserver.freifunk-
> > franken.de/v2/?lat=$lat&long=$long" -O "$hoodfile"
> > -	rm -f "$sectortmp"
> > -	[ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If internet
> > present,
> 
> no
> > custom config should be distributed, except when local file is
> > present
> > -	#UPLINK: No uplink download if internet present
> > -	#if no Internet, we connect to the hidden AP and download
> > the file
> > from another Node in range
> > +if [ -s $hoodlocal ]; then
> 
> Hier $hoodlocal in Anführungszeichen:
> 
> if [ -s "$hoodlocal" ]; then
> 
> 
> > +	hoodfile="$hoodlocal"
> > +	echo "Use local Hoodfile"
> 
> Richtig wäre "Use local hood file"; wenn man kleinlich ist ...
> 
> Grüße
> 
> Adrian
> 
> >  else
> > -	# connect to wireless hidden ap here and download the json
> > File
> > from the nearest router
> > -	# Only do that, when we have no gateway in range. If the
> > Uplinkrouter changed the hood, we lost the GW and do this
> > automatically
> > again, I think! Nice idea?
> > -	if ! isGatewayAvailable ; 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
> > -		rm -f "$hoodfilecopy" # delete this, so interfaces
> > are
> > recreated if reconnect with unchanged hood file takes place
> > -		rm -f "$sectorcopy" # always delete: no broadcast
> > for
> 
> isolated
> > device
> > +	# if we have Internet, we download the Hoodfile from the
> > keyxchangev2
> > +	if hasInternet ; then
> > +		wget -T15 -t5 "http://keyserver.freifunk-
> > franken.de/v2/?lat=$lat&long=$long" -O "$hoodfile"
> >  		rm -f "$sectortmp"
> > +		[ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If
> > internet
> > present, no custom config should be distributed, except when local
> > file is
> > present
> > +		#UPLINK: No uplink download if internet present
> > +		#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
> > the json
> > File from the nearest router
> > +		# Only do that, when we have no gateway in range.
> > If the
> > Uplinkrouter changed the hood, we lost the GW and do this
> > automatically
> > again, I think! Nice idea?
> > +		if ! isGatewayAvailable ; 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
> > +			rm -f "$hoodfilecopy" # delete this, so
> > interfaces
> 
> are
> > recreated if reconnect with unchanged hood file takes place
> > +			rm -f "$sectorcopy" # always delete: no
> > broadcast
> 
> for
> > isolated device
> > +			rm -f "$sectortmp"
> > 
> > -		sleep 30 # Wait for the config AP, which may be
> > created at
> > the same time as this script has started
> > -
> > -		if ! wifiDelIface; 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
> > -			radio="$(wifiAddPhyCond "$phy" "2"
> > "auto")"
> > -			radio5="$(wifiAddPhyCond "$phy" "5"
> > "auto5")"
> > -			if [ -n "$radio5" ] ; then
> > -				radio="$radio5"
> > -				staiface="w5sta"
> > -			else
> > -				staiface="w2sta"
> > -			fi
> > +			sleep 30 # Wait for the config AP, which
> > may be
> > created at the same
> > +time as this script has started
> > 
> > -			#and here we add the station
> > -			if ! wifiAddSta "$radio"
> 
> "config.franken.freifunk.net"
> > "configSta" "$staiface" ; then
> > -				echo "Can't add Sta interface on
> > $radio."
> > +			if ! wifiDelIface; then
> > +				echo "Can't delete current wifi
> > setup"
> >  				exit 1
> > -			else
> > -				uci -q set
> > network.configSta=interface
> > -				uci -q set
> > network.configSta.proto='static'
> > -				uci -q commit network
> >  			fi
> > -		done
> > +			#now we look for phy and add this
> > +			for phy in $(iw phy | awk '/^Wiphy/{ print
> > $2 }');
> 
> do
> > +				radio="$(wifiAddPhyCond "$phy" "2"
> > "auto")"
> > +				radio5="$(wifiAddPhyCond "$phy"
> > "5"
> > "auto5")"
> > +				if [ -n "$radio5" ] ; then
> > +					radio="$radio5"
> > +					staiface="w5sta"
> > +				else
> > +					staiface="w2sta"
> > +				fi
> > +
> > +				#and here we add the station
> > +				if ! wifiAddSta "$radio"
> > "config.franken.freifunk.net" "configSta" "$staiface" ; then
> > +					echo "Can't add Sta
> > interface on
> > $radio."
> > +					exit 1
> > +				else
> > +					uci -q set
> 
> network.configSta=interface
> > +					uci -q set
> > network.configSta.proto='static'
> > +					uci -q commit network
> > +				fi
> > +			done
> > 
> > -		wifi
> > -		# wait a moment to start the interface
> > -		sleep 10;
> > -		# and here we can download the Hoodfile from the
> > other
> > node
> > -		wget -T15 -t5
> > "http://[fe80::1%w2sta]:2342/keyxchangev2data" -O "$hoodfile" ||
> > wget -
> > T15 -t5 "http://[fe80::1%w5sta]:2342/keyxchangev2data" -O
> > "$hoodfile"
> > -		#UPLINK: Set up uplink data on first contact:
> > -		if [ -s /tmp/keyxchangev2data ]; then
> > -			wget -T15 -t5
> > "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectortmp" || wget
> > -T15 -t5
> > "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp"
> > -		fi
> > -	else
> > -		echo "We have a Gateway in Range, we load the
> > keyxchangev2data from fe80::1"
> > -		# check eth first
> > -		oldhood=""
> > -		ethfile="${hoodfile}eth"
> > -		for eth in $(batctl if | grep "eth" | sed -nE
> > 's/.*(eth[^:]+):.*/\1/p'); do
> > -			for mac in $(batctl n | grep "$eth" | sed
> > -nE
> > 's/.*eth[0-9.]+\s+([^\s]+)\s.*/\1/p'); do
> > -				EUI="$(echo "$mac" | awk -F: '{
> > printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5,
> > $6)
> 
> }')"
> > -				wget -T2 -t3
> > "http://[fe80::${EUI}%${eth}]:2342/keyxchangev2data" -O "$ethfile"
> > -				if [ -s "$ethfile" ]; then
> > -					json_load "$(cat
> > "$ethfile")"
> > -					json_select hood
> > -					json_get_var newhood name
> > -					if [ -n "$oldhood" ] && [
> > -n
> > "$newhood" ] && ( ! [ "$newhood" = "$oldhood" ] ) ; then
> > -						# 2nd hood found,
> > kill
> > interface and go on (next try in 5 min.)
> > -						echo "Two hoods
> > detected.
> > Remove cables to stay in just one."
> > -						ifconfig "$eth"
> > down
> > -						touch
> > "$resetnetworkfile"
> > -						continue 2 # go to
> > the next
> > interface
> > +			wifi
> > +			# wait a moment to start the interface
> > +			sleep 10;
> > +			# and here we can download the Hoodfile
> > from the
> > other node
> > +			wget -T15 -t5
> > "http://[fe80::1%w2sta]:2342/keyxchangev2data" -O "$hoodfile" ||
> > wget -
> > T15 -t5 "http://[fe80::1%w5sta]:2342/keyxchangev2data" -O
> > "$hoodfile"
> > +			#UPLINK: Set up uplink data on first
> > contact:
> > +			if [ -s /tmp/keyxchangev2data ]; then
> > +				wget -T15 -t5
> > "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectortmp" || wget
> > -T15 -t5
> > "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp"
> > +			fi
> > +		else
> > +			echo "We have a Gateway in Range, we load
> > the
> > keyxchangev2data from fe80::1"
> > +			# check eth first
> > +			oldhood=""
> > +			ethfile="${hoodfile}eth"
> > +			for eth in $(batctl if | grep "eth" | sed
> > -nE
> > 's/.*(eth[^:]+):.*/\1/p'); do
> > +				for mac in $(batctl n | grep
> > "$eth" | sed
> 
> -nE
> > 's/.*eth[0-9.]+\s+([^\s]+)\s.*/\1/p'); do
> > +					EUI="$(echo "$mac" | awk
> > -F: '{
> > printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5,
> > $6)
> 
> }')"
> > +					wget -T2 -t3
> > "http://[fe80::${EUI}%${eth}]:2342/keyxchangev2data" -O "$ethfile"
> > +					if [ -s "$ethfile" ]; then
> > +						json_load "$(cat
> 
> "$ethfile")"
> > +						json_select hood
> > +						json_get_var
> > newhood name
> > +						if [ -n "$oldhood"
> > ] && [ -n
> > "$newhood" ] && ( ! [ "$newhood" = "$oldhood" ] ) ; then
> > +							# 2nd hood
> > found,
> 
> kill
> > interface and go on (next try in 5 min.)
> > +							echo "Two
> > hoods
> > detected. Remove cables to stay in just one."
> > +							ifconfig
> > "$eth" down
> > +							touch
> > "$resetnetworkfile"
> > +							continue 2
> > # go to
> 
> the
> > next interface
> > +						fi
> > +						mv "$ethfile"
> > "$hoodfile" #
> > Only use hoodfile if sane
> > +						[ -n "$oldhood" ]
> > ||
> > oldhood="$newhood" # only set oldhood once
> >  					fi
> > -					mv "$ethfile" "$hoodfile"
> > # Only use
> > hoodfile if sane
> > -					[ -n "$oldhood" ] ||
> > oldhood="$newhood" # only set oldhood once
> > -				fi
> > +				done
> >  			done
> > -		done
> > -		if [ ! -s "$hoodfile" ]; then
> > -			# Only load hoodfile from gateway if not
> > already
> > present from local network
> > -			# - This gives local network a precedence
> > (take the
> > hood from local network)
> > -			# - This prevents file insertion from a
> > third
> 
> person, as I
> > will only connect via LAN to who I trust
> > -			wget -T15 -t5 "http://[fe80::1%br-
> > mesh]:2342/keyxchangev2data" -O "$hoodfile"
> > +			if [ ! -s "$hoodfile" ]; then
> > +				# Only load hoodfile from gateway
> > if not
> > already present from local network
> > +				# - This gives local network a
> > precedence
> > (take the hood from local network)
> > +				# - This prevents file insertion
> > from a
> 
> third
> > person, as I will only connect via LAN to who I trust
> > +				wget -T15 -t5 "http://[fe80::1%br-
> > mesh]:2342/keyxchangev2data" -O "$hoodfile"
> > +			fi
> > +			#UPLINK: Do nothing
> >  		fi
> > -		#UPLINK: Do nothing
> >  	fi
> >  fi
> > 
> > diff --git
> 
> a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
> > sysupgrade
> 
> b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-
> > sysupgrade
> > index 847ce1e..7ff83f5 100644
> > --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-
> > fff-
> > sysupgrade
> > +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-
> > fff-sysu
> > +++ pgrade
> > @@ -9,4 +9,5 @@ cat > /etc/sysupgrade.conf <<-__EOF__
> > /etc/dropbear/authorized_keys  /etc/network.config  /etc/config/fff
> > +/etc/hoodfile
> >  __EOF__
> > --
> > 2.11.0
> > 
> > --
> > franken-dev mailing list
> > franken-dev at freifunk.net
> > http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
> 
> 
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigröße  : 488 bytes
Beschreibung: This is a digitally signed message part
URL         : <http://lists.freifunk.net/pipermail/franken-dev-freifunk.net/attachments/20180120/7a3e2f7e/attachment.sig>


Mehr Informationen über die Mailingliste franken-dev