[PATCH v5 1/2] fff-network: Introduce function to set MAC on device

robert rlanghammer at web.de
Di Nov 6 11:14:56 CET 2018


Hallo Adrian,

nur ein paar Kleinigkeiten.

Am 07.08.18 um 12:25 schrieb Adrian Schmutzler:
> Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
>
> ---
>
> Changes in v2:
> - Suppress output
>
> Changes in v3:
> - Rename iface and dev in explanation. The variables were not
>   renamed, as shorter is better here.
>
> Changes in v4:
> - Rebased
>
> Changes in v5:
> - Rebased
> ---
>  .../fff-network/files/lib/functions/fff/network    | 31 +++++++++++++++++++++
>  .../fff-network/files/usr/sbin/configurenetwork    | 32 ++--------------------
>  2 files changed, 33 insertions(+), 30 deletions(-)
>
> diff --git a/src/packages/fff/fff-network/files/lib/functions/fff/network b/src/packages/fff/fff-network/files/lib/functions/fff/network
> index af9b3434..0e9b466b 100644
> --- a/src/packages/fff/fff-network/files/lib/functions/fff/network
> +++ b/src/packages/fff/fff-network/files/lib/functions/fff/network
> @@ -96,3 +96,34 @@ macFlipLocalBit() {
>  	echo "$mac" | awk -F: '{ printf("%02x:%s:%s:%s:%s:%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }'
>  	return 0
>  }
> +
> +fixMac() {
> +	# Update MAC address on device/interface
> +	#
> +	# fixMac <newmac> <physdev> <interface> <overwrite (optional)>
> +	#
> +	# newmac: MAC address to be set
> +	# physdev: Device name to be updated as in ifconfig (e.g. br-mesh)
> +	# interface: Interface to be updated as in uci (e.g. mesh)
> +	# overwrite: If non-zero, the MAC is always replaced; if not set, the MAC is only written if none is present
> +
> +	local newmac=$1
> +	local dev=$2
> +	local iface=$3
> +	local overwrite=$4
> +
> +	if uci -q get "network.${iface}.macaddr" > /dev/null && [ ! -n "$overwrite" ] ; then
das ist doppelt nein. [ $overwrite ] reicht oder mit -z
> +		echo "MAC for ${iface} is already set"
> +	else
> +		echo "Fixing MAC on ${dev} (${iface})"
> +		sleep 10
> +
> +		uci set "network.${iface}.macaddr=$newmac"
> +		uci -q commit network
> +
> +		ifconfig "$dev" down
> +		ifconfig "$dev" hw ether "$newmac"
> +		ifconfig "$dev" up

# ifconfig is deprecated.

ip link set "$dev" down
ip l s "$dev" address "$newmac"
ip l s "$dev" up

Und die Verwendung der {} ist etwas uneinheitlich. Man braucht das nur,
wenn hinten dran kein white character ist oder man Expansion machen
will. Oder man sagt, es schadet nie und macht die immer hin. Wie ist
denn da der allgemeine Tenor?

Robert

> +		/etc/init.d/network restart
> +	fi
> +}
> diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> index 0e038a49..9dc29da1 100755
> --- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> +++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
> @@ -176,39 +176,11 @@ fi
>  /etc/init.d/network restart
>  
>  if [ -n "$ETHMESHMAC" ]; then
> -    if uci get network.ethmesh.macaddr
> -    then
> -        echo "MAC for ethmesh is set already"
> -    else
> -        echo "Fixing MAC on $SWITCHDEV.3 (ethmesh)"
> -        sleep 10
> -
> -        uci set network.ethmesh.macaddr=$ETHMESHMAC
> -        uci commit network
> -
> -        ifconfig $SWITCHDEV.3 down
> -        ifconfig $SWITCHDEV.3 hw ether $ETHMESHMAC
> -        ifconfig $SWITCHDEV.3 up
> -        /etc/init.d/network restart
> -    fi
> +    fixMac "$ETHMESHMAC" "${SWITCHDEV}.3" "ethmesh"
>  fi
>  
>  if [ -n "$ROUTERMAC" ]; then
> -    if uci get network.mesh.macaddr
> -    then
> -        echo "MAC for mesh is set already"
> -    else
> -        echo "Fixing MAC on br-mesh (mesh)"
> -        sleep 10
> -
> -        uci set network.mesh.macaddr=$ROUTERMAC
> -        uci commit network
> -
> -        ifconfig br-mesh down
> -        ifconfig br-mesh hw ether $ROUTERMAC
> -        ifconfig br-mesh up
> -        /etc/init.d/network restart
> -    fi
> +    fixMac "$ROUTERMAC" "br-mesh" "mesh"
>  fi
>  
>  if [ -n "$ETH0MAC" ]; then



Mehr Informationen über die Mailingliste franken-dev