1196550Sdelphij#!/bin/sh
2196550Sdelphij#
3196550Sdelphij# Copyright (c) 2009  Xin LI <delphij@FreeBSD.org>
4196550Sdelphij# All rights reserved.
5196550Sdelphij#
6196550Sdelphij# Redistribution and use in source and binary forms, with or without
7196550Sdelphij# modification, are permitted provided that the following conditions
8196550Sdelphij# are met:
9196550Sdelphij# 1. Redistributions of source code must retain the above copyright
10196550Sdelphij#    notice, this list of conditions and the following disclaimer.
11196550Sdelphij# 2. Redistributions in binary form must reproduce the above copyright
12196550Sdelphij#    notice, this list of conditions and the following disclaimer in the
13196550Sdelphij#    documentation and/or other materials provided with the distribution.
14196550Sdelphij#
15196550Sdelphij# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16196550Sdelphij# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17196550Sdelphij# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18196550Sdelphij# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19196550Sdelphij# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20196550Sdelphij# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21196550Sdelphij# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22196550Sdelphij# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23196550Sdelphij# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24196550Sdelphij# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25196550Sdelphij# SUCH DAMAGE.
26196550Sdelphij#
27196550Sdelphij# Configure static ARP table
28196550Sdelphij#
29196550Sdelphij# $FreeBSD$
30196550Sdelphij#
31196550Sdelphij
32196550Sdelphij# PROVIDE: static_arp
33196550Sdelphij# REQUIRE: netif
34196550Sdelphij# KEYWORD: nojail
35196550Sdelphij
36196550Sdelphij. /etc/rc.subr
37197697Shrs. /etc/network.subr
38196550Sdelphij
39196550Sdelphijname="static_arp"
40298514Slmedesc="Static ARP Configuration"
41196550Sdelphijstart_cmd="static_arp_start"
42196550Sdelphijstop_cmd="static_arp_stop"
43196550Sdelphij
44196550Sdelphijstatic_arp_start()
45196550Sdelphij{
46196552Sdelphij	local e arp_args
47196552Sdelphij
48196550Sdelphij	if [ -n "${static_arp_pairs}" ]; then
49196550Sdelphij		echo -n 'Binding static ARP pair(s):'
50196550Sdelphij		for e in ${static_arp_pairs}; do
51196550Sdelphij			echo -n " ${e}"
52196550Sdelphij			eval arp_args=\$static_arp_${e}
53196550Sdelphij			arp -S ${arp_args} >/dev/null 2>&1
54196550Sdelphij		done
55196550Sdelphij		echo '.'
56196550Sdelphij	fi
57196550Sdelphij}
58196550Sdelphij
59196550Sdelphijstatic_arp_stop()
60196550Sdelphij{
61196552Sdelphij	local e arp_args
62196552Sdelphij
63196550Sdelphij	if [ -n "${static_arp_pairs}" ]; then
64196550Sdelphij		echo -n 'Unbinding static ARP pair(s):'
65196550Sdelphij		for e in ${static_arp_pairs}; do
66196550Sdelphij			echo -n " ${e}"
67196550Sdelphij			eval arp_args=\$static_arp_${e}
68196550Sdelphij			arp -d ${arp_args%%[ 	]*} > /dev/null 2>&1
69196550Sdelphij		done
70196550Sdelphij		echo '.'
71196550Sdelphij	fi
72196550Sdelphij}
73196550Sdelphij
74196550Sdelphijload_rc_config $name
75196550Sdelphijrun_rc_command "$1"
76