#!/bin/bash
# $Header:$

# IFACE      = Logical interface name
# MODE       = { start | stop }
# METHOD     = manual, otherwise exit
# IF_DEVICE  = physical interface name

. /etc/network/if.d/common-functions

# only do something for ATM interfaces

[ "$IF_TYPE" == "atm" ] || exit 0

# remove state if interface is being stopped

if [ "$MODE" == "stop" ]; then
  exec_down "dev" ""
  exit 0
fi

case "$MODE" in
  start)

    # ATM interfaces can't be deleted (2003-09, atm-tools 2.4.1).

    if ! /sbin/ip link show dev $IF_DEVICE >/dev/null 2>&1; then
      # ATM interface $IF_DEVICE does not exist yet. Create.
      verbose "atmarp -c $IF_DEVICE"
      atmarp -c $IF_DEVICE
    fi

    add_down "dev" "$IF_DEVICE"

    # set physical interface name to what we want to have
    # atmarpd currently (atm-tools 2.4.1) doesn't work with that.

    #if [ "$iface" != "$IF_DEVICE" ]; then
      # we need to rename the iface
    #  ip link set dev $iface down
    #  ip link set dev $iface name $IF_DEVICE
    #else
      # iface already has the correct name, we're done
    #fi
    
    # don't take link up here because atmarpd barfs if link is taken
    # up before IP address is assigned (atm-tools 2.4.1)
    #cmd "ip link set dev $IF_DEVICE up"
    
    ;;
  stop)
    ;;
esac

# end of file

