Merge pull request #1160 from tlaurion/gen_mac_address_for_maximized_boards

Add Heads mac address randomization for maximized boards
This commit is contained in:
tlaurion 2022-05-02 13:08:59 -04:00 committed by GitHub
commit 46d64e9f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#!/bin/ash
. /etc/functions
# bring up the ethernet; maybe should do DHCP?
ifconfig lo 127.0.0.1
@ -11,6 +13,16 @@ for module in `echo $network_modules`; do
done
if [ -e /sys/class/net/eth0 ]; then
#Randomize eth0 MAC address of maximized boards
if echo "$CONFIG_BOARD" | grep -q maximized; then
ifconfig eth0 down
echo "Generating random MAC address (might take a while)..."
mac=$(generate_random_mac_address)
echo "Assigning randomly generated MAC: $mac to eth0..."
ifconfig eth0 hw ether $mac
ifconfig eth0 up
fi
# Set up static IP
if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then
ifconfig eth0 $CONFIG_BOOT_STATIC_IP

View File

@ -374,3 +374,9 @@ print_battery_charge()
echo "$battery_charge"
fi
}
generate_random_mac_address()
{
#Borrowed from https://stackoverflow.com/questions/42660218/bash-generate-random-mac-address-unicast
hexdump -n 6 -ve '1/1 "%.2x "' /dev/urandom | awk -v a="2,6,a,e" -v r="$RANDOM" 'BEGIN{srand(r);}NR==1{split(a,b,",");r=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s\n",substr($1,0,1),b[r],$2,$3,$4,$5,$6}'
}