You are not logged in.

#1 2004-03-08 19:25:57

drz
Member
From: Netherlands
Registered: 2003-08-24
Posts: 13
Website

ArchLinux Ethernet Bonding support

Hi,

I've added ethernet bonding support to the archlinux boot scripts...

Ethernet bonding allows you to bundle forces between multiple network interfaces with failover support, and the combining of bandwidth.

Please refer to /usr/src/linux/Documentation/networking/bonding.txt for more information on the bonding topic.


PKGBUILD:

pkgname=ifenslave
pkgver=2.4.25
pkgrel=1
pkgdesc="Configures network interfaces for parallel routing"
url="http://www.kernel.org"
depends=('glibc')
makedepends=()
conflicts=()
replaces=()
backup=()
install=
source=()
md5sums=()

build() {
  mkdir $startdir/src/$pkgname-$pkgver
  cd $startdir/src/$pkgname-$pkgver
  cp /usr/src/linux-$pkgver/Documentation/networking/ifenslave.c .
  gcc -march=i686 -O2 -Wall -Wstrict-prototypes -I/usr/src/linux/include ifenslave.c -o ifenslave || return 1
  install -D -m755 ifenslave $startdir/pkg/sbin/ifenslave
}


/etc/modules.conf:

#
# /etc/modules.conf (for v2.4 kernels)
#
alias bond0 bonding
options bond0 mode=balance-alb

alias eth0 e100
alias eth1 e100


/etc/rc.d/network:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

ifup()
{
  varname="$${1}"
  eval new_ifline=$varname
  if [[ $1 != bond[0-9]*_slaves ]]; then
    # its a normal interface
    if [ "$new_ifline" = "dhcp" ]; then
      # remove the .pid file if it exists
      rm -f /etc/dhcpc/dhcpcd-${1}.{pid,cache} >/dev/null 2>&1
      /usr/sbin/dhcpcd -t 10 -h $HOSTNAME $1
    else
      /sbin/ifconfig $1 $new_ifline up
    fi
  else
    # its a bonding interface
    for slave_if in ${new_ifline[@]}; do
      if echo $slave_if | grep '^[^!]' >/dev/null 2>&1; then
        /sbin/ifenslave ${1/_slaves} $slave_if
      fi
    done
  fi
  return $?
}

ifdown()
{
  varname="$${1}"
  eval new_ifline=$varname
  if [[ $1 != bond[0-9]*_slaves ]]; then
    if [ "$new_ifline" = "dhcp" ]; then
      [ -f /etc/dhcpc/dhcpcd-${1}.pid ] && 
        /bin/kill `cat /etc/dhcpc/dhcpcd-${1}.pid`
    else
      /sbin/ifconfig $1 $new_ifline down
    fi
  fi
  return $?
}

rtup()
{
  varname="$${1}"
  eval new_rtline=$varname
  /sbin/route add $new_rtline
  return $?
}

rtdown()
{
  varname="$${1}"
  eval new_rtline=$varname
  /sbin/route del $new_rtline
  return $?
}

case "$1" in
  start)
    if ! ck_daemon network; then
      echo "Network is already running.  Try 'network restart'"
      exit
    fi
    stat_busy "Starting Network"
    error=0
    for ifline in ${INTERFACES[@]}; do
      if echo $ifline | grep '^[^!]' >/dev/null 2>&1; then
        ifup $ifline || error=1
      fi
    done
    for rtline in "${ROUTES[@]}"; do
      if echo $rtline | grep '^[^!]' 2>&1 >/dev/null; then
        rtup $rtline || error=1
      fi
    done
    if [ $error -eq 0 ]; then
      add_daemon network
      stat_done
    else
      stat_fail
    fi
    ;;
  stop)
    if ck_daemon network; then
      echo "Network is not running.  Try 'network start'"
      exit
    fi
    stat_busy "Stopping Network"
    rm_daemon network
    error=0
    for rtline in "${ROUTES[@]}"; do
      if echo $rtline | grep '^[^!]' 2>&1 >/dev/null; then
        rtdown $rtline || error=1
      fi
    done
    for ifline in ${INTERFACES[@]}; do
      if echo $ifline | grep '^[^!]' 2>&1 >/dev/null; then
        ifdown $ifline || error=1
      fi
    done
    if [ $error -eq 0 ]; then
      stat_done
    else
      stat_fail
    fi
    ;;
  restart)
    $0 stop
    sleep 2
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac


/etc/rc.conf:

lo="127.0.0.1"
bond0="192.168.0.8 netmask 255.255.255.0"
bond0_slaves="eth0 eth1"
INTERFACES=(lo bond0 bond0_slaves)


Mind, that i've changed some minor things in rc.conf, the interface names no longer need to be repeated.

Also, some coders might argu that i've forgotten to release eth0,eth1 in ifdown, but when bond0 is brought down, the bonding driver automatically brings down any interfaces which are enslaved to it.

Consider this code to be of beta quality!

I've tested it on my SMP machine with two Compaq NC3121 nics (with Intel e100 chipset) in combination with a el'cheapo 5 port switch/router.

Warning do not use bonding in combination with dhcp, the problem lies in the fact that when bond0 is configured manually or through dhcp, it has no actual network link... so dhcpd can't retrieve any DHCP_OFFER. Only after the bond is fully configured, real interfaces are enslaved to it to provide network connectivity.


Have fun!
Pascal de Bruijn


Look I'm Doctor Zoidberg, home owner!

Offline

#2 2004-03-08 20:50:16

drz
Member
From: Netherlands
Registered: 2003-08-24
Posts: 13
Website

Re: ArchLinux Ethernet Bonding support

I'd almost forgot to thank the blokes in irc://irc.freenode.net#bash for their help, as I'm still very much a bash noob.

Also thanks goes out to Intel, who have been doing a lot of cleaning up on the bonding driver!


Look I'm Doctor Zoidberg, home owner!

Offline

#3 2004-06-20 20:02:00

Moo-Crumpus
Member
From: Hessen / Germany
Registered: 2003-12-01
Posts: 1,487

Re: ArchLinux Ethernet Bonding support

Nice to see one more is trying to bond some nics.

Where did you fetch the ifenslave source from? Your PKGBUILD leaves src blank, I guess you fetched it elsewhere.
--- snipplet ---
found it in ORIGINAL www.kernel.org kernels sources
--- snipplet---

Had you tried, in spite of changing any lines inside the rc.conf, to do the jobs inside /etc/sysconfig/network-scripts, like bonding usually is done?


Frumpus addict
[mu'.krum.pus], [frum.pus]

Offline

#4 2004-06-21 04:52:10

Moo-Crumpus
Member
From: Hessen / Germany
Registered: 2003-12-01
Posts: 1,487

Re: ArchLinux Ethernet Bonding support

After doing the bondig, the network does fine, but gnome 2.6 won't start after  each login. :shock:

Wow. X works.

So I switched back to unbonded nics.


Frumpus addict
[mu'.krum.pus], [frum.pus]

Offline

Board footer

Powered by FluxBB