#!/bin/sh /etc/rc.common

START=99
STOP=90

ipv6_fw_enable() {
    ip6tables -P INPUT ACCEPT
    ip6tables -P FORWARD ACCEPT
    ip6tables -P OUTPUT ACCEPT
}

ipv6_fw_disable() {
    ip6tables -P INPUT DROP
    ip6tables -P FORWARD DROP
    ip6tables -P OUTPUT DROP
}

ipv6_enable() {
    local cfg="$1"
    #global_wanmode="$(uci get network.global.wanmode)"
    #模糊匹配
    [ `echo $cfg | grep -E "wan.*_v6" | wc -l` != 0 ] && {
        ifname=`uci get network.${cfg/v6/eth}.ifname`
    }
    #[ "$cfg" == "lanv6" ] && ifname="br-lan"

    [ -z "$ifname" ] && return

    config_get en "$cfg" enable

    case "$en" in
        on)
            # enable wan ipv6
            echo "0" > /proc/sys/net/ipv6/conf/$ifname/disable_ipv6
            ;;
        off)
            # disable wan ipv6
            echo "1" > /proc/sys/net/ipv6/conf/$ifname/disable_ipv6
            ;;
        *) 
            ;;
    esac
}

boot() {
    ipv6_fw_enable

    config_load protocol
    config_foreach ipv6_enable interface
}

start() {
    return 0
}

stop() {
    return 0
}
