summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modprobe.d/bonding.conf2
-rw-r--r--rc.inet160
-rw-r--r--rc.inet1.conf17
3 files changed, 72 insertions, 7 deletions
diff --git a/modprobe.d/bonding.conf b/modprobe.d/bonding.conf
new file mode 100644
index 0000000..20652c2
--- /dev/null
+++ b/modprobe.d/bonding.conf
@@ -0,0 +1,2 @@
+options bonding max_bonds=0
+options rtnl-link-bond max_bonds=0
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"
diff --git a/rc.inet1.conf b/rc.inet1.conf
index ce22cd3..e48f5c1 100644
--- a/rc.inet1.conf
+++ b/rc.inet1.conf
@@ -78,6 +78,23 @@ DEBUG_ETH_UP="no"
# =============================================================================
+# Example of how to configure a bond (link aggrigation) interface.
+
+# IFNAME[0]="bond0"
+# BONDNICS[0]="eth0 eth1"
+# BONDMODE[0]="balance-rr"
+# BONDOPTS[0]="xmit_hash_policy layer2+3 | miimon 100"
+# IPADDR[0]="192.168.0.1"
+# NETMASK[0]="24"
+# IPALIASES[0]=""
+# USE_DHCP[0]=""
+# DHCP_HOSTNAME[0]=""
+# IP6ADDRS[0]=""
+# USE_SLAAC[0]=""
+# USE_DHCP6[0]=""
+
+# =============================================================================
+
# Example of how to configure a VLAN interface.
# The VLAN ID is taken from the full interface name, which is comprised of the
# underlying interface name, a period (.) and then the VLAN ID.