static_arp revision 196550
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: head/etc/rc.d/static_arp 196550 2009-08-25 19:07:26Z delphij $
30196550Sdelphij#
31196550Sdelphij
32196550Sdelphij# PROVIDE: static_arp
33196550Sdelphij# REQUIRE: netif
34196550Sdelphij# KEYWORD: nojail
35196550Sdelphij
36196550Sdelphij. /etc/rc.subr
37196550Sdelphij
38196550Sdelphijname="static_arp"
39196550Sdelphijstart_cmd="static_arp_start"
40196550Sdelphijstop_cmd="static_arp_stop"
41196550Sdelphij
42196550Sdelphijstatic_arp_start()
43196550Sdelphij{
44196550Sdelphij	if [ -n "${static_arp_pairs}" ]; then
45196550Sdelphij		echo -n 'Binding static ARP pair(s):'
46196550Sdelphij		for e in ${static_arp_pairs}; do
47196550Sdelphij			local arp_args
48196550Sdelphij			echo -n " ${e}"
49196550Sdelphij			eval arp_args=\$static_arp_${e}
50196550Sdelphij			arp -S ${arp_args} >/dev/null 2>&1
51196550Sdelphij		done
52196550Sdelphij		echo '.'
53196550Sdelphij	fi
54196550Sdelphij}
55196550Sdelphij
56196550Sdelphijstatic_arp_stop()
57196550Sdelphij{
58196550Sdelphij	if [ -n "${static_arp_pairs}" ]; then
59196550Sdelphij		echo -n 'Unbinding static ARP pair(s):'
60196550Sdelphij		for e in ${static_arp_pairs}; do
61196550Sdelphij			local arp_args
62196550Sdelphij			echo -n " ${e}"
63196550Sdelphij			eval arp_args=\$static_arp_${e}
64196550Sdelphij			arp -d ${arp_args%%[ 	]*} > /dev/null 2>&1
65196550Sdelphij		done
66196550Sdelphij		echo '.'
67196550Sdelphij	fi
68196550Sdelphij}
69196550Sdelphij
70196550Sdelphijload_rc_config $name
71196550Sdelphijrun_rc_command "$1"
72