You are not logged in.

#1 2004-03-11 17:11:26

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

ArchLinux VLAN support

Hi,

I've hacked vlan support into the arch init, at least, I haven't been able to test this really, I have no vlan capable switch... This might be of use to some people, or may not... (it also includes my bonding support)

/etc/rc.d/network:

#!/bin/bash

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

ifup()
{
  varname="$${1}"
  eval new_ifline=$varname
  vlanname="$${1}_vlan"
  eval new_vlline=$vlanname

  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
    if [ "$new_vlline" != "" ]; then
      vconfig add $1 $new_vlline
    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

Please do backup your own /etc/rc.d/network script, just in case!

Good luck,
Pascal de Bruijn


Look I'm Doctor Zoidberg, home owner!

Offline

Board footer

Powered by FluxBB