]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
AWS: Rename all interfaces when booting up
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Jun 2018 18:40:31 +0000 (19:40 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Jun 2018 18:40:31 +0000 (19:40 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/initscripts/helper/aws-setup

index d86ab7d3978d9d6506bff11f62201b342fd92cf7..334f3e4be1ef6ef5f6f514df46f7cbb1a6c73484 100644 (file)
@@ -47,6 +47,22 @@ prefix2netmask() {
        to_address "$(( netmask ^ 0xffffffff ))"
 }
 
+find_interface() {
+       local mac="${1}"
+
+       local path
+       for path in /sys/class/net/*; do
+               local address="$(<${path}/address)"
+
+               if [ "${mac}" = "${address}" ]; then
+                       basename "${path}"
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
 import_aws_configuration() {
        local instance_id="$(get instance-id)"
 
@@ -104,6 +120,8 @@ import_aws_configuration() {
                case "${device_number}" in
                        # RED
                        0)
+                               local interface_name="red0"
+
                                # The gateway is always the first IP address in the subnet
                                local gateway="$(to_address $(( netaddress_num + 1 )))"
 
@@ -113,7 +131,7 @@ import_aws_configuration() {
 
                                (
                                        echo "RED_TYPE=STATIC"
-                                       echo "RED_DEV=red0"
+                                       echo "RED_DEV=${interface_name}"
                                        echo "RED_MACADDR=${mac}"
                                        echo "RED_DESCRIPTION='${interface_id}'"
                                        echo "RED_ADDRESS=${ipv4_address}"
@@ -133,8 +151,10 @@ import_aws_configuration() {
 
                        # GREEN
                        1)
+                               local interface_name="green0"
+
                                (
-                                       echo "GREEN_DEV=green0"
+                                       echo "GREEN_DEV=${interface_name}"
                                        echo "GREEN_MACADDR=${mac}"
                                        echo "GREEN_DESCRIPTION='${interface_id}'"
                                        echo "GREEN_ADDRESS=${ipv4_address}"
@@ -146,10 +166,11 @@ import_aws_configuration() {
 
                        # ORANGE
                        2)
+                               local interface_name="orange0"
                                config_type=2
 
                                (
-                                       echo "ORANGE_DEV=orange0"
+                                       echo "ORANGE_DEV=${interface_name}"
                                        echo "ORANGE_MACADDR=${mac}"
                                        echo "ORANGE_DESCRIPTION='${interface_id}'"
                                        echo "ORANGE_ADDRESS=${ipv4_address}"
@@ -159,6 +180,14 @@ import_aws_configuration() {
                                ) >> /var/ipfire/ethernet/settings
                                ;;
                esac
+
+               # Rename interface
+               local interface="$(find_interface "${mac}")"
+
+               if [ -n "${interface}" ] && [ -n "${interface_name}" ]; then
+                       ip link set "${interface}" down
+                       ip link set "${interface}" name "${interface_name}"
+               fi
        done
 
        # Save CONFIG_TYPE