[2/2] configurehood: Check for timestamp of hood file over LAN

Submitted by Adrian Schmutzler on March 8, 2018, 8:24 p.m.

Details

Message ID 1520540695-4303-2-git-send-email-freifunk@adrianschmutzler.de
State Rejected
Headers show

Commit Message

Adrian Schmutzler March 8, 2018, 8:24 p.m.
This patch does no more take the first hood file it finds, but
compares the timestamps provided.

Additionally, we again started to check for the gateway at the
end, but only take the file if its newer and FROM THE SAME HOOD.

Thus, we enable updates, but prohobit switching from a cable
hood to a WiFi peer. (Bug # 68)

Fixes #95.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

---

NOT TESTED!
---
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 26 ++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index 127ce5b..3a6fb9b 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -145,6 +145,7 @@  else
 
 			# check eth first
 			oldhood=""
+			oldtime="0"
 			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
@@ -154,6 +155,7 @@  else
 						json_load "$(cat "$ethfile")"
 						json_select hood
 						json_get_var newhood name
+						json_get_var newtime timestamp
 						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."
@@ -161,18 +163,28 @@  else
 							touch "$resetnetworkfile"
 							continue 2 # go to the next interface
 						fi
-						mv "$ethfile" "$hoodfile" # Only use hoodfile if sane
+						if [ "$oldtime" -lt "$newtime" ] ; then
+							mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
+							oldtime="$newtime"
+						fi
 						[ -n "$oldhood" ] || oldhood="$newhood" # only set oldhood once
 					fi
 				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"
+
+			# check gateway
+			wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$ethfile"
+			if [ -s "$ethfile" ]; then
+				json_load "$(cat "$ethfile")"
+				json_select hood
+				json_get_var newhood name
+				json_get_var newtime timestamp
+				if [ -z "$oldhood" ] || [ "$newhood" = "$oldhood" ] ; then
+					# Gateway on same hood, check for newer hood file
+					[ "$oldtime" -lt "$newtime" ] && mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
+				fi
 			fi
-			#UPLINK: Do nothing
+			#SECTORFILE: Do nothing
 		fi
 	fi
 fi

Comments

Adrian Schmutzler March 11, 2018, 3:01 p.m.
Hallo,

gerade getestet mit folgendem Setup:

dez. GW <--- WiFi --> FF-Router 1 <--- Ethernet ---> FF-Router 2

Sowohl für Trennung des Ethernet-Clusters vom Uplink/GW (z.B. bei Änderung
der mesh-SSID) als auch für Wechsel der Datei ohne Mesh-Unterbrechung (z.B.
bei Änderung der AP-SSID) scheint jetzt alles zu klappen.

Tested-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

Grüße

Adrian

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Donnerstag, 8. März 2018 21:25
> To: franken-dev@freifunk.net
> Subject: [PATCH 2/2] configurehood: Check for timestamp of hood file over
> LAN
> 
> This patch does no more take the first hood file it finds, but compares
the
> timestamps provided.
> 
> Additionally, we again started to check for the gateway at the end, but
only
> take the file if its newer and FROM THE SAME HOOD.
> 
> Thus, we enable updates, but prohobit switching from a cable hood to a
WiFi
> peer. (Bug # 68)
> 
> Fixes #95.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> 
> ---
> 
> NOT TESTED!
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 26
++++++++++++++++---
> ---
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 127ce5b..3a6fb9b 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -145,6 +145,7 @@ else
> 
>  			# check eth first
>  			oldhood=""
> +			oldtime="0"
>  			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 @@ -154,6 +155,7 @@ else
>  						json_load "$(cat
"$ethfile")"
>  						json_select hood
>  						json_get_var newhood name
> +						json_get_var newtime
> timestamp
>  						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."
> @@ -161,18 +163,28 @@ else
>  							touch
> "$resetnetworkfile"
>  							continue 2 # go to
the
> next interface
>  						fi
> -						mv "$ethfile" "$hoodfile" #
> Only use hoodfile if sane
> +						if [ "$oldtime" -lt
"$newtime" ]
> ; then
> +							mv "$ethfile"
> "$hoodfile" # Only use hoodfile if sane and newer
> +							oldtime="$newtime"
> +						fi
>  						[ -n "$oldhood" ] ||
> oldhood="$newhood" # only set oldhood once
>  					fi
>  				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"
> +
> +			# check gateway
> +			wget -T15 -t5 "http://[fe80::1%br-
> mesh]:2342/keyxchangev2data" -O "$ethfile"
> +			if [ -s "$ethfile" ]; then
> +				json_load "$(cat "$ethfile")"
> +				json_select hood
> +				json_get_var newhood name
> +				json_get_var newtime timestamp
> +				if [ -z "$oldhood" ] || [ "$newhood" =
> "$oldhood" ] ; then
> +					# Gateway on same hood, check for
> newer hood file
> +					[ "$oldtime" -lt "$newtime" ] && mv
> "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> +				fi
>  			fi
> -			#UPLINK: Do nothing
> +			#SECTORFILE: Do nothing
>  		fi
>  	fi
>  fi
> --
> 2.7.4
> 
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Tim Niemeyer April 1, 2018, 10:47 a.m.
Moin Adrian

Unten Kommentare.

Im allgemeinen gefällt mir die Architektur aber nicht:

Du vergleichst den Timestamp, aber nur, wenn kein hoodlocal (die config
in /etc) da ist und wenn der Knoten kein Internet Zugang hat und wenn
ein Gateway in der Nähe ist.

Dabei vergleichst du den Timestamp aber jeweils nur unter den Hoodfiles
der Nachbarn, vergisst dabei dein eigenes.

Dann lädst du das Hoodfile vom Gateway, nimmst es aber nur wenn die
Hood gleich heißt und der Timestamp neuer ist. Moment? Wenn das Gateway
nun nen neuen Namen hat, aktualisiert sich diese Wolke nicht mehr?

Ok, jetzt bin ich auch final verwirrt. 

Am Donnerstag, den 08.03.2018, 21:24 +0100 schrieb Adrian Schmutzler:
> This patch does no more take the first hood file it finds, but
> compares the timestamps provided.
> 
> Additionally, we again started to check for the gateway at the
> end, but only take the file if its newer and FROM THE SAME HOOD.
> 
> Thus, we enable updates, but prohobit switching from a cable
> hood to a WiFi peer. (Bug # 68)
> 
> Fixes #95.
> 
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> 
> ---
> 
> NOT TESTED!
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 26 ++++++++++++++++------
>  1 file changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 127ce5b..3a6fb9b 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -145,6 +145,7 @@ else
>  
> >  			# check eth first
> >  			oldhood=""
> +			oldtime="0"
Die Variable sollte doch mit dem (sofern es da ist) aktuell verwendeten
Hood-File initialisiert werden?

>  			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
> @@ -154,6 +155,7 @@ else
> >  						json_load "$(cat "$ethfile")"
> >  						json_select hood
> >  						json_get_var newhood name
> > +						json_get_var newtime timestamp
> >  						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."
> @@ -161,18 +163,28 @@ else
> >  							touch "$resetnetworkfile"
> >  							continue 2 # go to the next interface
> >  						fi
> > -						mv "$ethfile" "$hoodfile" # Only use hoodfile if sane
> > +						if [ "$oldtime" -lt "$newtime" ] ; then
> > +							mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> > +							oldtime="$newtime"
> > +						fi
> >  						[ -n "$oldhood" ] || oldhood="$newhood" # only set oldhood once
> >  					fi
> >  				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"
> +
> > +			# check gateway
> > +			wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$ethfile"
> > +			if [ -s "$ethfile" ]; then
> > +				json_load "$(cat "$ethfile")"
> > +				json_select hood
> > +				json_get_var newhood name
> > +				json_get_var newtime timestamp
> +				if [ -z "$oldhood" ] || [ "$newhood" = "$oldhood" ] ; then
s.o.

> +					# Gateway on same hood, check for newer hood file
> > +					[ "$oldtime" -lt "$newtime" ] && mv "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> > +				fi
> >  			fi
> > -			#UPLINK: Do nothing
> +			#SECTORFILE: Do nothing
Verstehe den Kommentar nicht.

Tim
>  		fi
> >  	fi
>  fi
> -- 
> 2.7.4
>
Adrian Schmutzler April 1, 2018, 11:44 a.m.
Hallo Tim,

siehe Inline.

> -----Original Message-----
> From: Tim Niemeyer [mailto:tim@tn-x.org]
> Sent: Sonntag, 1. April 2018 12:48
> To: Adrian Schmutzler <freifunk@adrianschmutzler.de>; franken-
> dev@freifunk.net
> Subject: Re: [PATCH 2/2] configurehood: Check for timestamp of hood file
> over LAN
> 
> Moin Adrian
> 
> Unten Kommentare.
> 
> Im allgemeinen gefällt mir die Architektur aber nicht:
> 
> Du vergleichst den Timestamp, aber nur, wenn kein hoodlocal (die config in
> /etc) da ist und wenn der Knoten kein Internet Zugang hat und wenn ein
> Gateway in der Nähe ist.

Internet gewinnt immer.

> 
> Dabei vergleichst du den Timestamp aber jeweils nur unter den Hoodfiles
> der Nachbarn, vergisst dabei dein eigenes.
> 
> Dann lädst du das Hoodfile vom Gateway, nimmst es aber nur wenn die
> Hood gleich heißt und der Timestamp neuer ist. Moment? Wenn das
> Gateway nun nen neuen Namen hat, aktualisiert sich diese Wolke nicht
> mehr?

Dieser ganze Block mit dem Durchgehen des Netzwerks ist damals entstanden, um Loops zu vermeiden.

Christian hatte glaube ich da ein Problem, dass er gelegentlich aus seiner Hood in die vom Nachbarn reingekommen ist. Deshalb habe ich damals das so gebaut, dass das Netzwerk präferiert wird (!). In der Konsequenz sollte bei einem Hoodwechsel eines per WiFi verbunden Gateways dieser verworfen werden, und die Hood aus dem lokalen Netzwerk gewinnen. Daher prüfe ich hier erst die Hood. Man kann das natürlich auch so bauen, dass der Timestamp des WLANs gewinnt oder das Gateway zuerst abgefragt wird, dann verliert bei einem Konflikt aber (möglicherweise) das Netzwerk gegen das WiFi.

Zum Timestamp:
Von allen angebotenen Files nehme ich immer den neuesten, außer wir verbinden mehrere Hoods. Dann nehme ich den neuesten der ersten gefundenen Hood. Danach wird weiter unten in configurehood ja der neue mit dem vorhandenen File verglichen (Zeile 195-202). Hier haben wir damals schon den Timestamp rausgeworfen und nur den content verglichen. In der Logik von configurehood müsste man wenn dann den Timestamp dort wieder berücksichtigen.
Ändert jetzt z.B. jemand das Hoodfile am KeyXchange, ohne den Timestamp zu ändern, würde das aktuelle Skript trotzdem funktionieren. Würde man auf den timestamp prüfen, würde das neue File zugunsten des bestehenden verworfen.
Wir haben aber ja extra einen zweiten Schritt, der dann nochmal feststellt, ob es Änderungen im File gab. Dies war auch die ursprüngliche Architektur von configurehood: Im ersten Schritt das neueste File holen, und dann weiter unten prüfen, ob es verändert ist. Ich habe mich in dieser Logik bewegt.

> 
> Ok, jetzt bin ich auch final verwirrt.
> 
> Am Donnerstag, den 08.03.2018, 21:24 +0100 schrieb Adrian Schmutzler:
> > This patch does no more take the first hood file it finds, but
> > compares the timestamps provided.
> >
> > Additionally, we again started to check for the gateway at the end,
> > but only take the file if its newer and FROM THE SAME HOOD.
> >
> > Thus, we enable updates, but prohobit switching from a cable hood to a
> > WiFi peer. (Bug # 68)
> >
> > Fixes #95.
> >
> > > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> >
> > ---
> >
> > NOT TESTED!
> > ---
> >  .../fff/fff-hoods/files/usr/sbin/configurehood     | 26
> > ++++++++++++++++------
> >  1 file changed, 19 insertions(+), 7 deletions(-)
> >
> > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > index 127ce5b..3a6fb9b 100755
> > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > @@ -145,6 +145,7 @@ else
> >
> > >  			# check eth first
> > >  			oldhood=""
> > +			oldtime="0"
> Die Variable sollte doch mit dem (sofern es da ist) aktuell verwendeten
> Hood-File initialisiert werden?

siehe oben. Hier holen wir nur das neue Hood-File, aber vergleichen nicht mit dem ist-Zustand.

> 
> >  			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
> > @@ -154,6 +155,7 @@ else
> > >  						json_load "$(cat "$ethfile")"
> > >  						json_select hood
> > >  						json_get_var newhood name
> > > +						json_get_var newtime
> timestamp
> > >  						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."
> > @@ -161,18 +163,28 @@ else
> > >  							touch
> "$resetnetworkfile"
> > >  							continue 2 # go to the
> next interface
> > >  						fi
> > > -						mv "$ethfile" "$hoodfile" #
> Only use hoodfile if sane
> > > +						if [ "$oldtime" -lt "$newtime" ]
> ; then
> > > +							mv "$ethfile"
> "$hoodfile" # Only use hoodfile if sane and newer
> > > +							oldtime="$newtime"
> > > +						fi
> > >  						[ -n "$oldhood" ] ||
> oldhood="$newhood" # only set oldhood once
> > >  					fi
> > >  				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"
> > +
> > > +			# check gateway
> > > +			wget -T15 -t5 "http://[fe80::1%br-
> mesh]:2342/keyxchangev2data" -O "$ethfile"
> > > +			if [ -s "$ethfile" ]; then
> > > +				json_load "$(cat "$ethfile")"
> > > +				json_select hood
> > > +				json_get_var newhood name
> > > +				json_get_var newtime timestamp
> > +				if [ -z "$oldhood" ] || [ "$newhood" =
> "$oldhood" ] ; then
> s.o.

Wir werten das hood-File nur aus, wenn es die gleiche Hood wie das Netzwerk hat, damit ein Hoodwechsel des Wifi-Gateways uns nicht aus der LAN-Hood zieht.

> 
> > +					# Gateway on same hood, check for
> newer hood file
> > > +					[ "$oldtime" -lt "$newtime" ] && mv
> "$ethfile" "$hoodfile" # Only use hoodfile if sane and newer
> > > +				fi
> > >  			fi
> > > -			#UPLINK: Do nothing
> > +			#SECTORFILE: Do nothing
> Verstehe den Kommentar nicht.

Hier geht es um das Sectorfile (ganz anderes Thema). Wir haben das damals so gebaut, dass es NICHT in diesem Block geupdatet wird, sondern nur wenn man sich über w2sta konfiguriert. Dementsprechend soll der Kommentar daran erinnern. Dummerweise haben wir hier zunächst von Uplink gesprochen (weil der Uplink den Sector definiert), was aber verwirrend ist. Daher habe ich das bei der Gelegenheit in Sectorfile geändert, sodass man weiß, was gemeint ist.

Ich hatte nicht so viel Zeit, daher die Kommentare etwas unstrukturiert.

Ich habe den Patch getestet und er funktioniert im Einsatz gut, was dir aber natürlich nichts nützt, wenn dir das Design nicht gefällt.

Grüße

Adrian

> 
> Tim
> >  		fi
> > >  	fi
> >  fi
> > --
> > 2.7.4
> >