#!/bin/sh

# when add phy interface under pass-through
# check & set promisc mode

[ "$ACTION" == "remove" ] && exit

. /lib/zone/zone_api.sh

local zone=$(zone_get_zone_by_device $DEVICENAME)
[ -z "$zone" -o "${zone:0:3}" != "WAN" ] && exit

local CHECKBIT=256

for wan_dev in $(cat /tmp/.wan_passthrough)
do
    if [ "$wan_dev" == "$DEVICENAME" ]; then
        local flags=$(cat /sys/class/net/$DEVICENAME/flags)
        [ -z "$flags" ] && exit

        # flags & 0x100 != 0x100 means this device not in promisc mode 
        if [ $CHECKBIT -ne $(($flags & $CHECKBIT)) ]; then
            ifconfig $DEVICENAME promisc
        fi
    fi
done