summaryrefslogtreecommitdiffstats
path: root/rc.inet1
diff options
context:
space:
mode:
Diffstat (limited to 'rc.inet1')
-rw-r--r--rc.inet160
1 files changed, 53 insertions, 7 deletions
diff --git a/rc.inet1 b/rc.inet1
index d8cbdfd..c19571f 100644
--- a/rc.inet1
+++ b/rc.inet1
@@ -175,6 +175,50 @@ br_close() {
/sbin/ip link del ${IFNAME[$1]}
}
+# Function to create a bond.
+bond_create() {
+ # Argument is 'i' - the position of this interface in the IFNAME array.
+ info_log "${IFNAME[$1]}: creating bond"
+ debug_log "/sbin/ip link add name ${IFNAME[$1]} type bond"
+ /sbin/ip link add name ${IFNAME[$1]} type bond
+ debug_log "/sbin/ip link set dev ${IFNAME[$1]} type bond mode ${BONDMODE[$1]}"
+ /sbin/ip link set dev ${IFNAME[$1]} type bond mode ${BONDMODE[$1]}
+ for BONDIF in ${BONDNICS[$1]}; do
+ debug_log "/sbin/ip link set dev $BONDIF down"
+ /sbin/ip link set dev $BONDIF down
+ debug_log "/sbin/ip address flush dev $BONDIF"
+ /sbin/ip address flush dev $BONDIF
+ debug_log "/sbin/ip link set $BONDIF master ${IFNAME[$1]}"
+ /sbin/ip link set $BONDIF master ${IFNAME[$1]}
+ debug_log "/sbin/ip link set dev $BONDIF up"
+ /sbin/ip link set dev $BONDIF up
+ done
+ while read -r -d \| BONDOPT; do
+ if [ -n "$BONDOPT" ]; then
+ debug_log "/sbin/ip link set dev ${IFNAME[$1]} type bond $BONDOPT"
+ /sbin/ip link set dev ${IFNAME[$1]} type bond $BONDOPT
+ fi
+ done <<<"${BONDOPTS[$1]}|" # The | on the end is required.
+}
+
+# Function to destroy a bond.
+bond_destroy() {
+ # Argument is 'i' - the position of this interface in the IFNAME array.
+ info_log "${IFNAME[$1]}: destroying bond"
+ debug_log "/sbin/ip link set dev ${IFNAME[$1]} down"
+ /sbin/ip link set dev ${IFNAME[$1]} down
+ debug_log "/sbin/ip address flush dev ${IFNAME[$1]}"
+ /sbin/ip address flush dev ${IFNAME[$1]}
+ for BONDIF in ${BONDNICS[$1]}; do
+ debug_log "/sbin/ip link set $BONDIF nomaster"
+ /sbin/ip link set $BONDIF nomaster
+ debug_log "/sbin/ip link set dev $BONDIF down"
+ /sbin/ip link set dev $BONDIF down
+ done
+ debug_log "/sbin/ip link del name ${IFNAME[$1]} type bond"
+ /sbin/ip link del name ${IFNAME[$1]} type bond
+}
+
# Function to bring up a network interface. If the interface is
# already up or does not yet exist (perhaps because the kernel driver
# is not loaded yet), do nothing.
@@ -194,10 +238,12 @@ if_up() {
return
fi
info_log "${1}: configuring interface"
- # If the interface is a bridge, then create it first.
- # If you need to set hardware addresses for the underlying interfaces,
- # configure the interfaces with IPs of 0.0.0.0 and set the MAC address
- # in the usual way. Then, finally, define the bridge.
+ # If you need to set hardware addresses for the underlying interfaces in a
+ # bond or bridge, configure the interfaces with IPs of 0.0.0.0 and set the
+ # MAC address with HWADDR. Then, finally, define the bond or bridge.
+ # If the interface is a bond, create it.
+ [ -n "${BONDNICS[$i]}" ] && bond_create $i
+ # If the interface is a bridge, create it.
[ -n "${BRNICS[$i]}" ] && br_open $i
if [ -e /sys/class/net/${1%%[:.]*} ]; then # interface exists
if ! /sbin/ip address show scope global dev ${1} 2>/dev/null | grep -Ewq '(inet|inet6)' || \
@@ -460,9 +506,9 @@ if_down() {
cat /proc/sys/net/ipv6/conf/default/accept_ra >/proc/sys/net/ipv6/conf/$1/accept_ra
fi
# If the interface is a bridge, then destroy it now:
- if [ -n "${BRNICS[$i]}" ]; then
- br_close $i
- fi
+ [ -n "${BRNICS[$i]}" ] && br_close $i
+ # If the interface is a bond, then destroy it now.
+ [ -n "${BONDNICS[$i]}" ] && bond_destroy $i
# Take down VLAN interface, if configured.
if echo "${1}" | grep -Fq .; then
info_log "${1}: destroying VLAN interface"