#!/usr/bin/sh #---------------------------------------------------------------------------- # /usr/libexec/metconfig/nm-get_bonding- create bonding devices # # Creation : 2005-05-22 jv # Last Update: $Id$ # # Copyright (c) 2005-@@YEAR@@ the eisfair team, team(at)eisfair(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- . /etc/config.d/base . /etc/config.d/bonding IP=/usr/sbin/ip #exec 2>/tmp/bonding-nm-get-$$trace.log #set -x # --------------------------------------------------------------------------- # check status of bonding # --------------------------------------------------------------------------- check_bonding_status() { /usr/bin/grep -q '^bonding ' /proc/modules return ${?} } # --------------------------------------------------------------------------- # activate bonding # --------------------------------------------------------------------------- bonding_start() { # write pid file echo "${BONDING_N}" > /run/bonding.pid # load kernelmodul /usr/sbin/modprobe bonding >/dev/null 2>&1 # read config bond_idx=1 while [ ${bond_idx} -le ${BONDING_N:-0} ] do eval bond_arp_targets='$BONDING_'${bond_idx}'_ARP_IP_TARGET_N' # create device name ndev=$((${bond_idx} - 1)) eval bond_dev_name='bond'$ndev eval bond_devn='$BONDING_'${bond_idx}'_BIND_N' eval bond_downdelay='$BONDING_'${bond_idx}'_DOWNDELAY' eval bond_mac='$BONDING_'${bond_idx}'_MAC' eval bond_miimon='$BONDING_'${bond_idx}'_MIIMON' eval bond_mode='$BONDING_'${bond_idx}'_MODE' eval bond_primary='$BONDING_'${bond_idx}'_PRIMARY' eval bond_updelay='$BONDING_'${bond_idx}'_UPDELAY' eval bond_use_carrier='$BONDING_'${bond_idx}'_USE_CARRIER' # clear up ${bond_dev_name} and set it ${IP} addr flush dev ${bond_dev_name} 2>/dev/null # set ${bond_dev_name}.nmconnection { # set interface parameter echo '[connection]' echo "id=${bond_dev_name}" echo 'type=bond' echo "interface-name=${bond_dev_name}" echo echo '[ethernet]' # set individual static mac for bond if [ -n "${bond_mac}" ] then echo "cloned-mac-address=${bond_mac}" fi echo echo '[bond]' # set bond mode case ${bond_mode} in 0) b_mode='balance-rr' ;; 1) b_mode='active-backup' ;; 2) b_mode='balance-xor' ;; 3) b_mode='broadcast' ;; 4) b_mode='802.3ad' ;; 5) b_mode='balance-tlb' ;; 6) b_mode='balance-alb' ;; esac echo "mode=${b_mode:-${bond_mod}}" if [ ${bond_downdelay} -ne 0 ] then bond_downdelay=$((${bond_downdelay} * ${bond_miimon})) echo "downdelay=${bond_downdelay:-0}" fi if [ ${bond_updelay} -ne 0 ] then bond_updelay=$((${bond_updelay} * ${bond_miimon})) echo "updelay=${bond_updelay:-0}" fi if [ "${bond_use_carrier}" = "no" ] then echo "use_carrier=0" fi if [ "${bond_mode}" = "balance-rr" ] || [ ${bond_mode} -eq 0 ] || [ "${bond_mode}" = "balance-xor" ] || [ ${bond_mode} -eq 2 ] then if [ ${bond_arp_targets} -gt 0 ] then eval bond_arp_interval='${BONDING_'${bond_idx}'_ARP_INTERVAL}' echo "arp_interval=${bond_arp_interval:-200}" separator='' bond_ddx=1 while [ ${bond_ddx} -le ${bond_arp_targets:-0} ] do eval bond_ip_target='${BONDING_'${bond_idx}'_ARP_IP_TARGET_'${bond_ddx}'}' b_arp_ip_target="${b_arp_ip_target}${separator}${bond_ip_target}" separator=',' bond_ddx=$((${bond_ddx} + 1)) done echo "arp_ip_target=${b_arp_ip_target}" b_miimon=false fi fi # set miimon only, if arp_ip_target not set if ! "${b_miimon:-false}" then echo "miimon=${bond_miimon:-100}" fi # set primary device only with active backup if [ "${bond_mode}" = "active-backup" ] || [ ${bond_mode} -eq 1 ] && [ -n "${bond_primary}" ] then eval b_primary='${IP_ETH_'${bond_primary}'_NAME}' echo "primary=${b_primary}" fi if [ "${bond_mode}" = "802.3ad" ] || [ ${bond_mode} -eq 4 ] then eval bond_lacp_rate='${BONDING_'${bond_idx}'_LACP_RATE}' if [ "${bond_lacp_rate:-slow}" = "fast" ] || [ ${bond_lacp_rate} -eq 1 ] then echo "lacp_rate=fast" fi fi # ipv4 settings ipv4_gate='' ipv4_dns ipv4_dhcp='' ipv4_dhcp_host='' ipv4_dhcp_peer='' ipv4_method='' ipv4_gateway='' ethx='' eval ipv4_dhcp='${BONDING_'${bond_idx}'_DHCP}' eval ipv4_dhcp_host='${BONDING_'${bond_idx}'_DHCP_HOSTNAME}' eval ipv4_dhcp_peer='${BONDING_'${bond_idx}'_DHCP_PEERDNS}' eval ethx='${BONDING_'${bond_idx}'_BIND_1_ETH}' eval ipv4_method='${IP_ETH_'${ethx}'_METHOD}' eval ipv4_gateway='${IP_ETH_'${ethx}'_GATEWAY}' if [ "${ipv4_dhcp:-no}" = "yes" ] then ipv4_method='auto' fi echo echo '[ipv4]' case "${ipv4_method}" in manual) ipv4_n='' eval ipv4_n='${IP_ETH_'${ethx}'_IP_N}' idxa=1 idy=1 while [ ${idy} -le ${ipv4_n:-0} ] do ipv4_addr='' ipv4_netmask='' eval ipv4_addr='${IP_ETH_'${ethx}'_IP_'${idy}'_IPADDR}' eval ipv4_netmask='${IP_ETH_'${ethx}'_IP_'${idy}'_NETMASK}' netmaskbits=$(/usr/bin/netcalc netmaskbits ${ipv4_netmask}) echo "address${idxa}=${ipv4_addr}/${netmaskbits}" if ! "${ipv4_gate:-false }" && [ -n "${ipv4_gateway}" ] then echo "gateway=${ipv4_gateway}" ipv4_gate=true fi # include to set route . /var/install/include/nm-get-route idxa=$((${idxa} +1)) idy=$((${idy} + 1)) done if ! "${ipv4_dns:-false}" then # include to set dns responder . /var/install/include/nm-get-dns get_dns ipv4 ipv4_dns=true fi ;; auto) echo "dhcp-send-hostname-v2=-1" if [ -n "${ipv4_dhcp_host}" ] then echo "dhcp-hostname=${ipv4_dhcp_host}" fi if [ "${ipv4_dhcp_peer:-no}" != "yes" ] then echo 'ignore-auto-dns=true' # include to set dns responder . /var/install/include/nm-get-dns get_dns ipv4 fi ;; disabled) : # ;; link-local) : # ;; esac echo "method=${ipv4_method}" # ipv6 settings ipv6_gate='' ipv6_dns='' ipv6_dhcp_host='' ipv6_dhcp_peer='' ipv6_method='' ipv6_gateway='' ipv6_addr_mode='' eval ipv6_dhcp_host='${IP_ETH_'${ethx}'_V6_DHCP_HOSTNAME}' eval ipv6_dhcp_peer='${IP_ETH_'${ethx}'_V6_DHCP_PEERDNS}' eval ipv6_method='${IP_ETH_'${ethx}'_V6_METHOD}' eval ipv6_addr_mode='${IP_ETH_'${ethx}'_V6_ADDR_GEN_MODE}' eval ipv6_gateway='${IP_ETH_'${ethx}'_V6_GATEWAY}' if [ "${ipv6_dhcp:-no}" = "yes" ] then ipv6_method='auto' fi echo echo '[ipv6]' case "${ipv6_method}" in manual) ipv6_n='' eval ipv6_n='${IP_ETH_'${ethx}'_V6_IP_N}' idxa=1 id6=1 while [ ${id6} -le ${ipv6_n:-0} ] do ipv6_addr='' ipv6_prefix='' eval ipv6_addr='${IP_ETH_'${ethx}'_V6_IP_'${id6}'_IPADDR}' eval ipv6_prefix='${IP_ETH_'${ethx}'_V6_IP_'${id6}'_PREFIX}' echo "address${idxa}=${ipv6_addr}/${ipv6_prefix}" if ! "${ipv6_gate:-false }" && [ -n "${ipv6_gateway}" ] then echo "gateway=${ipv6_gateway}" ipv6_gate=true fi # include to set route . /var/install/include/nm-get-route idxa=$((${idxa} +1)) id6=$((${id6} +1)) done if ! "${ipv6_dns:-false}" then # include to set dns rsponder . /var/install/include/nm-get-dns get_dns ipv6 ipv6_dns=true fi ;; disabled) : # ;; link-local) echo "addr-gen-mode=${ipv6_addr_mode}" ;; ignore) : # ;; auto) ipv6_privacy='' eval ipv6_privacy='${IP_ETH_'${ethx}'_V6_PRIVACY}' echo "addr-gen-mode=${ipv6_addr_mode}" echo "ip6-privacy=${ipv6_privacy}" echo 'dhcp-send-hostname-v2=-1' if [ -n "${ipv6_dhcp_host}" ] then echo "dhcp-hostname=${ipv6_dhcp_host}" fi if [ "${ipv6_dhcp6_peer:-no}" != "yes" ] then echo 'ignore-auto-dns=true' # include to set dns responder . /var/install/include/nm-get-dns get_dns ipv6 fi ;; esac echo "method=${ipv6_method}" echo echo '[proxy]' echo } > /etc/NetworkManager/system-connections/${bond_dev_name}.nmconnection /usr/bin/chmod 0600 /etc/NetworkManager/system-connections/${bond_dev_name}.nmconnection # set marker for active nmconnection >/run/netconfig/${bond_dev_name}.nmconnection eval bond_devn='${BONDING_'${bond_idx}'_BIND_N}' bond_ddx=1 while [ ${bond_ddx} -le ${bond_devn:-0} ] do # flush the network interface eval idxb='${BONDING_'${bond_idx}'_BIND_'${bond_ddx}'_ETH}' eval bond_iface='${IP_ETH_'${idxb}'_NAME}' ${IP} addr flush dev ${bond_iface} 2>/dev/null # set interface to bonding { echo '[connection]' echo "id=${bond_iface}" echo 'type=ethernet' echo "controller=${bond_dev_name}" echo "interface-name=${bond_iface}" echo 'port-type=bond' echo echo '[ethernet]' echo echo '[bond-port]' echo } > /etc/NetworkManager/system-connections/${bond_iface}.nmconnection /usr/bin/chmod 0600 /etc/NetworkManager/system-connections/${bond_iface}.nmconnection # set marker for active nmconnection >/run/netconfig/${bond_iface}.nmconnection bond_ddx=$((${bond_ddx} + 1)) done bond_idx=$((${bond_idx} + 1)) done } # --------------------------------------------------------------------------- # remove bonding # --------------------------------------------------------------------------- bonding_stop() { if check_bonding_status then # get count of bond interfaces if [ -f /run/bonding.pid ] then n_idx=$(/usr/bin/cat /run/bonding.pid) else n_idx=0 fi bond_idx=1 while [ ${bond_idx} -le ${n_idx:-0} ] do # create device name ndev=$((${bond_idx} - 1)) eval bond_dev_name='bond'${ndev} # stop bond device ${IP} link set ${bond_dev_name} down bond_idx=$((${bond_idx} + 1)) done # remove kernelmodul /usr/sbin/rmmod bonding >/dev/null 2>&1 fi /usr/bin/rm -f /run/bonding.pid } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { while [ "${#}" -gt 0 ] do case "${1}" in --quiet) _quiet=true shift ;; *) _action="${1}" shift ;; esac done case "${_action}" in start) bonding_start ;; stop) bonding_stop ;; esac exit 0 } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------