# Started from theo's sample in /usr/src/etc/ifstated.conf
#
# You will need arping, available in the ports tree.
#
# 
# Replace :
#
# IF	 -> your network interface
# MAC_1	 -> hardware address of a host in network 1
# HOST_1 -> IP address of the host with MAC_1 
# MAC_2	 -> hardware address of a host in network 2
# HOST_2 -> IP address of the host with MAC_2 
# 
# Add MAC_i, HOST_i pairs as required

# Kind of state machine, so it needs a starting state
init-state offline
  
# Conditions to be checked by ifstated and the kernel
#
if_up = "(IF link up)"
if_down = "(IF link down)"

# Conditions to be checked by script 
#
# check where we are every 30 seconds
#
# arping sends an ARP request for the IP address HOST_i
# to the MAC address MAC_i and returns true if there is
# a positive answer. Source address used is 0.0.0.0.
#
net_1 = '( "arping -q -0 -i IF -c 1 -t MAC_1 HOST_1" \
				every 30 )'

net_2 = '( "arping -q -0 -i IF -c 1 -t MAC_2 HOST_2" \
				every 30 )'
# net_i = ...
#

# Now define the states
state offline {
	if $if_up {
		set-state connected
	}
}

state connected {
	# when to leave this state
	if $net_1 {
		set-state in_network_1
	}
	if $net_2 {
		set-state in_network_2
	}
	if $if_down {
		set-state offline
	}
}

state in_network_1 {
	init {
		# The script sets an address/netmask/route/resolver
		# or starts dhcp/rtsol, ...
		run "sh /etc/scripts/network_1_setup"
	}
	if $if_down {
		set-state offline
	}
}

state in_network_2 {
	init {
		# The script sets an address/netmask/route/resolver
		# or starts dhcp/rtsol, ...
		run "sh /etc/scripts/network_2_setup"
	}
	if $if_down {
		set-state offline
	}
}
