]>
git.ipfire.org Git - people/stevee/network.git/blob - hooks/bonding
2 ########################################################################
3 # Begin $NETWORK_DEVICES/services/bonding
5 # Description : Bonding Script
7 # Authors : Michael Tremer - michael.tremer@ipfire.org
11 # Notes : This script adds bonding support.
13 ########################################################################
15 .
/lib
/network
/hook-header
23 function port_name
() {
32 echo "HOOK_NAME=${HOOK_NAME}"
33 echo "HOOK_TYPE=${HOOK_TYPE}"
37 if ! grep -q ^bonding
/proc
/modules
; then
39 echo "-bond0" > /sys
/class
/net
/bonding_masters
42 if device_exists
${MAC}; then
43 device
=$
(devicify
${MAC})
44 if ! device_is_bonding
${device}; then
45 log_failure_msg
"Device \"${device}\" is up, but not a bonding device."
51 device
=$
(device_get_free $
(port_name
))
52 echo "+${device}" > /sys
/class
/net
/bonding_masters
53 ip link
set ${device} address
${MAC}
56 echo "${MODE}" > /sys
/class
/net
/${device}/bonding
/mode
58 echo "${MIIMON-100}" > /sys
/class
/net
/${device}/bonding
/miimon
60 for slave
in ${SLAVES}; do
61 if device_exists
${slave}; then
62 if device_is_up
${slave}; then
63 log_warning_msg
"Cannot enslave device \"${slave}\"."
66 device_rename
"$(devicify ${slave})" "${device}s+"
67 echo "+$(devicify ${slave})" > /sys
/class
/net
/${device}/bonding
/slaves
69 log_warning_msg
"Device ${slave} does not exist."
73 ip link
set ${device} up
75 log_success_msg
"Setting up trunk ${MAC}..."
79 device
=$
(devicify
${MAC})
80 if ! zone_has_device_attached
${zone} ${device}; then
81 zone_add_port
${zone} ${device}
86 device
=$
(devicify
${MAC})
87 if zone_has_device_attached
${zone} ${device}; then
88 zone_del_port
${zone} ${device}
93 device
=$
(devicify
${MAC})
94 if port_is_up
${device}; then
95 MESSAGE
="Pulling down trunk ${MAC}..."
96 ip link
set ${device} down
98 echo "-${device}" > /sys
/class
/net
/bonding_masters
106 while [ $# -gt 0 ]; do
115 SLAVES
="${SLAVES} $(macify ${1})"
122 cat <<EOF > ${CONFIG_UUIDS}/${UUID}
126 SLAVES="$(echo ${SLAVES})"
128 ln -sf ${CONFIG_UUIDS}/${UUID} \
129 ${CONFIG_ZONES}/${zone}/${HOOK_NAME}-${UUID}
131 log_success_msg
"Configuration successfully saved!"
132 echo " MAC address : ${MAC}"
133 echo " Mode : ${MODE}"
134 echo " Slaves : $(echo ${SLAVES})"
141 DEVICE
=$
(devicify
${MAC})
142 echo -e "# ${CLR_BOLD_CYN}Trunk ${DEVICE} (${MAC})${NORMAL}"
143 if device_is_up
${MAC}; then
144 echo -e "# State: ${CLR_BOLD_GRN}up${NORMAL}"
146 for slave
in $
(</sys
/class
/net
/${DEVICE}/bonding
/slaves
); do
147 echo -e "# ${CLR_BOLD_CYN}Slave port ${slave}${NORMAL}"
150 if device_is_up
${slave}; then
151 echo -e "${CLR_BOLD_GRN}up${NORMAL}"
153 echo -e "${CLR_BOLD_RED}down${NORMAL}"
157 if device_has_carrier
${slave}; then
158 echo -e "${CLR_BOLD_GRN}yes${NORMAL}"
160 echo -e "${CLR_BOLD_RED}no${NORMAL}"
164 echo -e "# State: ${CLR_BOLD_RED}down${NORMAL}"
172 echo "Usage: ${0} [interface] {up|down|add|remove|attach|detach|status}"
177 # End $NETWORK_DEVICES/services/bonding