#!/bin/sh

##
# VERY simple access control script for leeenux
##

# Note: your PATH is inherited from the gateway process
#

action=$1
mac=$2
ip=$3
class=$4

if [ -z "$action" -o -z "$mac" -o -z "$ip" -o -z "$class" ]; then 
    echo Usage: $0 [permit\|deny] [MAC] [IP] [Class]
    echo Example: $0 permit 00:02:2d:aa:bb:cc 10.0.0.105 member
    exit 1
fi

if [ "$action" = "permit" ]; then
    cmd=-A
elif [ "$action" = "deny" ]; then
    cmd=-D
else
    echo "FATAL: Bad action: $action!"
    exit 1
fi

if [ "$class" = "Owner" ]; then
    mark=1
elif [ "$class" = "Member" ]; then
    mark=2
elif [ "$class" = "Public" ]; then
    mark=3
else
    echo "FATAL: Bad class: $class!"
    exit 1
fi

if [ "$IgnoreMAC" ]; then
    match_mac=""
else
    match_mac="-m mac --mac-source $mac"
fi

# Mark outbound traffic from this node.
iptables -t mangle $cmd NoCat $match_mac -s $ip -j MARK --set-mark $mark

# Mark inbound traffic to this node.
iptables -t filter $cmd NoCat_Inbound -d $ip -j ACCEPT

#
# Ende
#
