#!/bin/sh
# stop dhcp6c and radvd, and delete all non-128bit dynamic prefix on LAN

# $0 (/etc_ro/ppp/ipv6-down)
# $1 ifname  (ppp0)
# $2 devname (eth2.2)
# $4 local  LL addr
# $5 remote LL addr

LAN=br0
DHCP6C="/sbin/dhcp6.sh client"

get_lan_prefix()
{
  EXCLUDE_PAT="fe80::|/128"
  LAN_STATIC_IP=`nvram_get v6_lan_ip`
  [ $LAN_STATIC_IP ] && EXCLUDE_PAT="${EXCLUDE_PAT}|${LAN_STATIC_IP}/64"
  
  ifconfig $LAN | grep "inet6 addr" | grep -vE $EXCLUDE_PAT | sed -e "s/^.*inet6 addr: //" -e "s/ Scope.*\$//"
}

# program entry

$DHCP6C stop

PREFIX=`get_lan_prefix`
if [ ! -z "$PREFIX" ]; then
  ifconfig $LAN del $PREFIX
fi
