2017-08-19 23:32:10 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
prereqs)
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Extract kernel parameters
|
|
|
|
set -- $(cat /proc/cmdline)
|
|
|
|
items=""
|
|
|
|
for x in "$@"; do
|
|
|
|
case "$x" in
|
|
|
|
Aboot=*)
|
|
|
|
aboot_flag="${x#Aboot=}"
|
|
|
|
;;
|
|
|
|
net_*)
|
|
|
|
item="${x#net_}"
|
|
|
|
items="$items $item"
|
|
|
|
;;
|
|
|
|
platform=*)
|
|
|
|
platform_flag="${x#platform=}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-04-06 12:48:13 -05:00
|
|
|
random() {
|
|
|
|
echo $(od -vAn -N1 -tu1 < /dev/urandom)
|
|
|
|
}
|
|
|
|
|
|
|
|
arista_net_devname() {
|
|
|
|
local pciaddr="$1"
|
|
|
|
local devname_prefix="$2"
|
|
|
|
for path in $(ls -d /sys/class/net/${devname_prefix}* 2>/dev/null); do
|
|
|
|
local devid="$(realpath "$path/device")"
|
|
|
|
if echo "$devid" | grep -q "$pciaddr"; then
|
|
|
|
echo "${path##*/}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-08-19 23:32:10 -05:00
|
|
|
arista_net_rename() {
|
|
|
|
local device_path="$1"
|
|
|
|
local new_name="$2"
|
|
|
|
local from_name="$3"
|
2018-04-06 12:48:13 -05:00
|
|
|
devname=$(arista_net_devname "$device_path" "$from_name")
|
2022-04-20 12:03:37 -05:00
|
|
|
if [ -n "$devname" ]; then
|
|
|
|
ip link set "$devname" name "$new_name"
|
|
|
|
fi
|
2018-04-06 12:48:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Sets the MAC address to the value passed by Aboot through /proc/cmdline
|
|
|
|
tg3fixhwaddr()
|
|
|
|
{
|
|
|
|
local default_tg3_hwaddr="00:10:18:00:00:00"
|
|
|
|
local pciaddr="$1"
|
|
|
|
local hwaddr="$2"
|
|
|
|
|
|
|
|
devname=$(arista_net_devname "$pciaddr")
|
|
|
|
if [ -z "$devname" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
driver=$(basename $(readlink "/sys/class/net/$devname/device/driver"))
|
|
|
|
if [ "$driver" != "tg3" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$hwaddr" = "$default_tg3_hwaddr" ]; then
|
|
|
|
hwaddr=$(cat /sys/class/net/$devname/address)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$hwaddr" = "$default_tg3_hwaddr" ]; then
|
|
|
|
hwaddr=$(printf "%02x" "$(($(random) & 0xfe | 0x02))")
|
|
|
|
for i in 1 2 3 4 5; do
|
|
|
|
hwaddr=$(printf "$hwaddr:%02x" "$(($(random) & 0xfe | 0x02))")
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
ip link set dev "$devname" addr "$hwaddr"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$aboot_flag" ]; then
|
|
|
|
for item in $items; do
|
|
|
|
key="${item%=*}"
|
|
|
|
value="${item#*=}"
|
|
|
|
hwaddr=$(eval echo \${hwaddr_${key}})
|
|
|
|
if [ -n "$hwaddr" ]; then
|
|
|
|
tg3fixhwaddr "$value" "$hwaddr"
|
2017-08-19 23:32:10 -05:00
|
|
|
fi
|
|
|
|
done
|
2018-04-06 12:48:13 -05:00
|
|
|
fi
|
2017-08-19 23:32:10 -05:00
|
|
|
|
|
|
|
# Iterate over all the net_maX items found in the cmdline two times.
|
|
|
|
# First time renaming the interfaces to maX.
|
|
|
|
# The second time renaming them to their final name ethX.
|
|
|
|
if [ -n "$aboot_flag" -a "$platform_flag" == 'rook' ]; then
|
|
|
|
for item in $items; do
|
|
|
|
key="${item%=*}"
|
|
|
|
value="${item#*=}"
|
|
|
|
arista_net_rename "$value" "$key" eth
|
|
|
|
done
|
|
|
|
for item in $items; do
|
|
|
|
key="${item%=*}"
|
|
|
|
value="${item#*=}"
|
|
|
|
index="${key#ma}"
|
|
|
|
index="$(( $index - 1 ))"
|
|
|
|
newKey="eth$index"
|
|
|
|
arista_net_rename "$value" "$newKey" ma
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|