Skip to content

Commit

Permalink
First draft ip_mac()
Browse files Browse the repository at this point in the history
  • Loading branch information
schabrolles committed Aug 27, 2017
1 parent 5b2fc64 commit 813e9d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
15 changes: 7 additions & 8 deletions usr/share/rear/rescue/GNU/Linux/310_network_devices.sh
Expand Up @@ -153,23 +153,23 @@ for physical_network_interface in $physical_network_interfaces ; do

if test -s $TMP_DIR/mappings/ip_addresses ; then
while read network_device ip_address junk ; do
Log "New IP-address will be $network_device $ip_address"
( echo "# New IP-address will be $network_device $ip_address:"
echo "ip addr add $ip_address dev $network_device"
echo "ip link set dev $network_device up"
Log "New IP-address will be $network_device($mac) $ip_address"
( echo "# New IP-address will be $network_device($mac) $ip_address:"
echo "ip_mac addr add $ip_address dev $mac"
echo "ip_mac link set dev $mac up"
) >>$network_devices_setup_script
done < $TMP_DIR/mappings/ip_addresses
else
for addr in $( ip a show dev $physical_network_interface scope global | grep "inet.*\ " | tr -s " " | cut -d " " -f 3 ) ; do
echo "ip addr add $addr dev $physical_network_interface" >>$network_devices_setup_script
echo "ip_mac addr add $addr dev $mac" >>$network_devices_setup_script
done
echo "ip link set dev $physical_network_interface up" >>$network_devices_setup_script
echo "ip_mac link set dev $mac up" >>$network_devices_setup_script
fi

# Record interface MTU:
if test -e "$sysfspath/mtu" ; then
mtu="$( cat $sysfspath/mtu )" || LogPrint "Could not read a MTU address from '$sysfspath/mtu'!"
[[ "$mtu" ]] && echo "ip link set dev $physical_network_interface mtu $mtu" >>$network_devices_setup_script
[[ "$mtu" ]] && echo "ip_mac link set dev $mac mtu $mtu" >>$network_devices_setup_script
fi
done

Expand Down Expand Up @@ -352,4 +352,3 @@ else
# Fake already_set_up_bonding_interfaces, so that no recursive call tries to bring one up the not-simplified way:
already_set_up_bonding_interfaces=${bonding_interfaces[@]}
fi

17 changes: 12 additions & 5 deletions usr/share/rear/rescue/GNU/Linux/350_routing.sh
Expand Up @@ -31,7 +31,8 @@ EOT
# route mapping is available
if test -s $TMP_DIR/mappings/routes ; then
while read destination gateway device junk ; do
echo "ip route add $destination via $gateway dev $device" >>$netscript
mac=$( get_hwaddr $device )
echo "ip_mac route add $destination via $gateway dev $mac" >>$netscript
done < $TMP_DIR/mappings/routes
else # use original routes

Expand Down Expand Up @@ -69,10 +70,13 @@ else # use original routes
# by a route to the *first* bonded slave
ifslaves=($(cat /proc/net/bonding/$device | grep "Slave Interface:" | cut -d : -f 2))
Log "X${ifslaves[@]}X"
echo "ip route add $destination $via $gateway $dev ${ifslaves[0]} table $table" >>$netscript
# Get mac-addresses from the first bonded slave
mac=$( get_hwaddr ${ifslaves[0]} )
echo "ip_mac route add $destination $via $gateway $dev $mac table $table" >>$netscript
# be sure that it is not a teaming-interface
elif ! ethtool -i $device | grep -w "driver:" | grep -qw team ; then
echo "ip route add $destination $via $gateway $dev $device table $table" >>$netscript
mac=$( get_hwaddr $device )
echo "ip_mac route add $destination $via $gateway $dev $mac table $table" >>$netscript
fi
done
ip -6 route list table $table |\
Expand All @@ -82,10 +86,13 @@ else # use original routes
if test "$SIMPLIFY_BONDING" -a -r /proc/net/bonding/$device ; then
ifslaves=($(cat /proc/net/bonding/$device | grep "Slave Interface:" | cut -d : -f 2))
Log "X${ifslaves[@]}X"
echo "ip route add $destination $via $gateway $dev ${ifslaves[0]} table $table" >>$netscript
# Get mac-addresses from the first bonded slave
mac=$( get_hwaddr ${ifslaves[0]} )
echo "ip_mac route add $destination $via $gateway $dev ${ifslaves[0]} table $table" >>$netscript
# be sure that it is not a teaming-interface
elif ! ethtool -i $device | grep -w "driver:" | grep -qw team ; then
echo "ip route add $destination $via $gateway $dev $device table $table" >>$netscript
mac=$( get_hwaddr $device )
echo "ip_mac route add $destination $via $gateway $dev $device table $table" >>$netscript
fi
done
done
Expand Down
Expand Up @@ -2,7 +2,7 @@
# call udevtrigger
my_udevtrigger() {
type -p udevadm >/dev/null && udevadm trigger $@ || udevtrigger $@

# If systemd is running, this should help to rename devices
if [[ $(ps --no-headers -C systemd) ]]; then
sleep 1
Expand All @@ -25,6 +25,17 @@ Error() {
echo "ERROR: $*"
}

# source the global functions
. /usr/share/rear/lib/network-functions.sh

# ip wrapper command which use mac adresses instead of device name.
ip_mac(){
ip_args=$*
dev_mac=$(echo $ip_args | awk -F"dev " '{ split($2,TAB," "); print TAB[1] }')
dev_name=$(get_device_by_hwaddr $dev_mac)
ip_args=$( echo $ip_args | sed "s/dev $dev_mac/dev $dev_name/g" )
ip $ip_args
}

# source the global functions
. /usr/share/rear/lib/global-functions.sh

0 comments on commit 813e9d2

Please sign in to comment.