[RFC] script for binding ARP <-> IP pairs

Xin LI delphij at delphij.net
Thu Aug 6 18:58:49 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Here is a new rc.d startup script, which helps to bind static ARP
entries like this:

	static_arp_pairs="gw"
	arp_gw="172.16.1.254 00:1c:58:6a:7a:4c"

At the beginning I was inclined to add an "options" part for this script
which helps to set e.g. logging options for ARP but it looks that these
would be redundant, i.e., can be done with easy /etc/sysctl.conf.

Comments?

Cheers,
- --
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (FreeBSD)

iEYEARECAAYFAkp7J5IACgkQi+vbBBjt66Du7QCePX+p8F8u6i/4mCGW+I//eFBu
O7oAn2TdLvcH9TFHR1bY3zKlJ8NTAJx4
=OAHW
-----END PGP SIGNATURE-----
-------------- next part --------------
#!/bin/sh
#
# Copyright (c) 2009  Xin LI <delphij at FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Configure static ARP table
#
# $FreeBSD$
#

# PROVIDE: arp
# REQUIRE: netif
# KEYWORD: nojail

. /etc/rc.subr

name="arp"
start_cmd="arp_start"
stop_cmd="arp_stop"

arp_start()
{
	if [ -n "${static_arp_pairs}" ]; then
		echo -n 'Binding static ARP pair:'
		for e in ${static_arp_pairs}; do
			echo -n " ${e}"
			eval arp_args=\$arp_${e}
			arp -S ${arp_args} >/dev/null 2>&1
		done
		echo '.'
	fi
}

arp_stop()
{
	if [ -n "${static_arp_pairs}" ]; then
		echo -n 'Unbinding static ARP pair:'
		for e in ${static_arp_pairs}; do
			echo -n " ${e}"
			eval arp_args=\$arp_${e}
			arp_args=`echo ${arp_args} | sed -e s,..:..:..:..:..:..,,g`
			arp -d ${arp_args} >/dev/null 2>&1
		done
		echo '.'
	fi
}

load_rc_config $name
run_rc_command "$1"


More information about the freebsd-rc mailing list