Revert "Derive the bridge MAC from concatenated multiple sources"

This reverts commit c2083cbce0.
This commit is contained in:
Martynas Pumputis committed 2016-08-15 09:48:55 +01:00
1 parent c79b6a8bd7
commit c509b6e5bb
2 files changed
+15 -33

No files matched your search

+2 -6
View File
@@ -49,14 +49,10 @@ When the router is launched on a host, it derives its peer name in order of pref
* From the command line, where the user is responsible for uniqueness and * From the command line, where the user is responsible for uniqueness and
stability stability
* From the concatenated result of any of the following: * From the BIOS product UUID, which is generally stable across
* The unique machine ID, which is generated either by [systemd](https://www.freedesktop.org/software/systemd/man/machine-id.html)
or [D-Bus](https://dbus.freedesktop.org/doc/dbus-uuidgen.1.html) and is
practically stable across restarts unless a user re-generates it.
* The BIOS product UUID, which is generally stable across
restarts and unique across different physical hardware and certain restarts and unique across different physical hardware and certain
cloned VMs cloned VMs
* The hypervisor UUID, which is generally stable across restarts * From the hypervisor UUID, which is generally stable across restarts
and unique across VMs which do not provide access to a BIOS product and unique across VMs which do not provide access to a BIOS product
UUID UUID
* From a random value, practically unique across different physical * From a random value, practically unique across different physical
+13 -27
View File
@@ -143,22 +143,12 @@ launch_router_options() {
[ "$1" = "launch" -o "$1" = "launch-router" ] && echo -v /:/host -e HOST_ROOT=/host [ "$1" = "launch" -o "$1" = "launch-router" ] && echo -v /:/host -e HOST_ROOT=/host
} }
exec_options() {
case "$1" in
# Required by create_bridge which might need machine-id
launch|launch-router|create-bridge|attach-router|run|start|attach|restart|expose|hide)
echo -v /etc:/host/etc -v /var/lib/dbus:/host/var/lib/dbus -e HOST_ROOT=/host
;;
esac
}
exec_remote() { exec_remote() {
docker $DOCKER_CLIENT_ARGS run --rm \ docker $DOCKER_CLIENT_ARGS run --rm \
$(docker_run_options) \ $(docker_run_options) \
--pid=host \ --pid=host \
$(cni_volume_options "$@") \ $(cni_volume_options "$@") \
$(launch_router_options "$@") \ $(launch_router_options "$@") \
$(exec_options "$@") \
-e DOCKERHUB_USER="$DOCKERHUB_USER" \ -e DOCKERHUB_USER="$DOCKERHUB_USER" \
-e WEAVE_VERSION \ -e WEAVE_VERSION \
-e WEAVE_DEBUG \ -e WEAVE_DEBUG \
@@ -461,11 +451,12 @@ mac_from_hex() {
read a b c d e f && printf "%02x:$b:$c:$d:$e:$f" $((0x$a & ~1 | 2)) read a b c d e f && printf "%02x:$b:$c:$d:$e:$f" $((0x$a & ~1 | 2))
} }
mac_from_uid() { mac_from_file() {
UUID=$(cat $1 2>/dev/null) || return 1
# We salt the input just as a precaution to avoid clashes with # We salt the input just as a precaution to avoid clashes with
# other applications who might have had the bright idea of # other applications who might have had the bright idea of
# generating MACs in the same way. # generating MACs in the same way.
echo "9oBJ0Jmip-$1" | sha256sum | sed 's/\(..\)/\1 /g' | cut -c1-17 | mac_from_hex echo "9oBJ0Jmip-$UUID" | sha256sum | sed 's/\(..\)/\1 /g' | cut -c1-17 | mac_from_hex
} }
# Generate a random MAC value # Generate a random MAC value
@@ -473,11 +464,6 @@ random_mac() {
od -txC -An -N6 /dev/urandom | mac_from_hex od -txC -An -N6 /dev/urandom | mac_from_hex
} }
machineid() {
cat "$HOST_ROOT/etc/machine-id" 2>/dev/null && return 0 || true
cat "$HOST_ROOT/var/lib/dbus/machine-id" 2>/dev/null && return 0 || true
}
###################################################################### ######################################################################
# weave and docker specific helpers # weave and docker specific helpers
###################################################################### ######################################################################
@@ -710,16 +696,16 @@ init_bridge() {
ip link add name $BRIDGE type bridge ip link add name $BRIDGE type bridge
# Derive the bridge MAC from concatenated machine-id (either systemd or # Derive the bridge MAC from the system (aka bios) UUID, or,
# dbus), the system (aka bios) UUID and the hypervisor UUID. If we cannot # failing that, the hypervisor UUID. Elsewhere we in turn derive
# determine all of them we just generate a random MAC. # the peer name from that, which we want to be stable across
# Elsewhere we in turn derive the peer name from the bridge MAC, which we # reboots but otherwise unique. The system/hypervisor UUID fits
# want to be stable across reboots but otherwise unique. # that bill, unlike, say, /etc/machine-id, which is often
# identical on VMs created from cloned filesystems. If we cannot
uid="$(machineid)" # determine the system/hypervisor UUID we just generate a random MAC.
uid="$uid#$(cat /sys/class/dmi/id/product_uuid 2>/dev/null || echo '')" MAC=$(mac_from_file /sys/class/dmi/id/product_uuid) || \
uid="$uid#$(cat /sys/hypervisor/uuid 2>/dev/null || echo '')" MAC=$(mac_from_file /sys/hypervisor/uuid) || \
[ "$uid" != "##" ] && MAC=$(mac_from_uid "$uid") || MAC=$(random_mac) MAC=$(random_mac)
ip link set dev $BRIDGE address $MAC ip link set dev $BRIDGE address $MAC