Enforce docker bridge address assignment type on launch

This commit is contained in:
Adam Harrison committed 2015-07-28 17:51:48 +01:00
1 parent d5e510f778
commit a14d4d9f8e
1 file changed
+17
+17
View File
@@ -93,6 +93,22 @@ check_docker_version() {
fi
}
enforce_docker_bridge_addr_assign_type() {
if ! ADDR_ASSIGN_TYPE=$(cat /sys/class/net/$DOCKER_BRIDGE/addr_assign_type 2>/dev/null) ; then
echo "Could not determine address assignment type of $DOCKER_BRIDGE" >&2
return
fi
# From include/uapi/linux/netdevice.h
# #define NET_ADDR_PERM 0 /* address is permanent (default) */
# #define NET_ADDR_RANDOM 1 /* address is generated randomly */
# #define NET_ADDR_STOLEN 2 /* address is stolen from other device */
# #define NET_ADDR_SET 3 /* address is set using dev_set_mac_address() */
if [ $ADDR_ASSIGN_TYPE != 3 ] ; then
echo "Setting $DOCKER_BRIDGE MAC (mitigate https://github.com/docker/docker/issues/14908)" >&2
ip link set dev $DOCKER_BRIDGE address $(random_mac) || true
fi
}
is_cidr() {
echo "$1" | grep -E "^$CIDR_REGEXP$" >/dev/null
}
@@ -976,6 +992,7 @@ case "$COMMAND" in
;;
launch)
check_not_running $CONTAINER_NAME $BASE_IMAGE
enforce_docker_bridge_addr_assign_type
create_bridge
# We set the router name to the bridge mac since that is
# stable across re-creations of the containers.