#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org

START=45

IPTABLES=iptables
config_load ipbindmacs

fw_ip_bind_mac(){
	local ip
	local mac

	config_get ip $1 ip
	config_get mac $1 mac

	echo $ip $mac >> /etc/ethers

}

start()
{
	config_get ipbindmac_mode ipbindmac_mode ipbindmac_mode
	echo "$ipbindmac_mode" > /proc/sys/net/ipv4/ipbindmac_mode
	cat /dev/null > /etc/ethers
	arp -n|awk '/lan-/ {print "arp -d "$1}' | sh 2>/dev/null
	[ "$ipbindmac_mode" = "0" ] || config_foreach fw_ip_bind_mac ipmac
	arp -f
}
apply()
{
	stop
	start
	uci commit ipbindmacs

	/etc/init.d/dhcpd apply
}
stop()
{
	cat /dev/null > /etc/ethers
	arp -n|awk '/lan-/ {print "arp -d "$1}' | sh 2>/dev/null
}
