2010-04-16 17:47:50 +04:00
|
|
|
.\" $NetBSD: ifwatchd.8,v 1.26 2010/04/16 13:47:50 jmcneill Exp $
|
2001-11-19 13:10:45 +03:00
|
|
|
.\"
|
2003-03-05 12:03:49 +03:00
|
|
|
.\" Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
|
2001-11-19 12:43:03 +03:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
2002-04-14 15:41:42 +04:00
|
|
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
2003-02-14 19:11:34 +03:00
|
|
|
.\" by Martin Husemann <martin@NetBSD.org>.
|
2002-04-14 15:41:42 +04:00
|
|
|
.\"
|
2001-11-19 12:43:03 +03:00
|
|
|
.\" 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.
|
|
|
|
.\"
|
2002-04-14 15:41:42 +04:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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
|
2001-11-19 12:43:03 +03:00
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
2010-04-16 17:47:50 +04:00
|
|
|
.Dd April 16, 2010
|
2001-11-19 12:43:03 +03:00
|
|
|
.Dt IFWATCHD 8
|
2009-03-09 22:24:26 +03:00
|
|
|
.Os
|
2001-11-19 12:43:03 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm ifwatchd
|
2001-12-10 18:04:51 +03:00
|
|
|
.Nd "watch for addresses added to or deleted from interfaces and call up/down-scripts for them"
|
2001-11-19 12:43:03 +03:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm
|
2003-07-04 16:44:12 +04:00
|
|
|
.Op Fl hiqv
|
2003-03-05 12:03:49 +03:00
|
|
|
.Op Fl A Ar arrival-script
|
2004-11-25 19:05:11 +03:00
|
|
|
.Op Fl c Ar carrier-script
|
2003-03-05 12:03:49 +03:00
|
|
|
.Op Fl D Ar departure-script
|
2001-12-10 18:04:51 +03:00
|
|
|
.Op Fl d Ar down-script
|
2001-11-19 12:43:03 +03:00
|
|
|
.Op Fl u Ar up-script
|
2004-01-05 01:19:51 +03:00
|
|
|
.Op Fl n Ar no-carrier-script
|
2001-11-19 12:43:03 +03:00
|
|
|
.Ar ifname(s)
|
|
|
|
.Sh DESCRIPTION
|
2001-12-10 18:04:51 +03:00
|
|
|
.Nm
|
2003-07-04 16:48:30 +04:00
|
|
|
is used to monitor dynamic interfaces (for example PPP interfaces)
|
2004-01-05 01:19:51 +03:00
|
|
|
for address changes, and to monitor static interfaces for carrier
|
|
|
|
changes.
|
2003-07-04 16:48:30 +04:00
|
|
|
Sometimes these interfaces are accompanied by a daemon program,
|
|
|
|
which can take care of running any necessary scripts (like
|
2001-11-19 13:10:45 +03:00
|
|
|
.Xr pppd 8
|
|
|
|
or
|
|
|
|
.Xr isdnd 8 ) ,
|
|
|
|
but sometimes the interfaces run completely autonomously (like
|
2003-04-16 13:06:55 +04:00
|
|
|
.Xr pppoe 4 ) .
|
2001-11-19 12:43:03 +03:00
|
|
|
.Pp
|
2001-12-10 18:04:51 +03:00
|
|
|
.Nm
|
2004-01-05 01:19:51 +03:00
|
|
|
provides a generic way to watch these types of changes.
|
2003-07-04 16:48:30 +04:00
|
|
|
It works by monitoring the routing socket and interpreting
|
2001-11-19 12:43:03 +03:00
|
|
|
.Ql RTM_NEWADDR
|
2004-01-05 01:19:51 +03:00
|
|
|
.Pq address added ,
|
2001-11-19 12:43:03 +03:00
|
|
|
.Ql RTM_DELADDR
|
|
|
|
.Pq address deleted
|
2004-01-05 01:19:51 +03:00
|
|
|
and
|
|
|
|
.Ql RTM_IFINFO
|
|
|
|
.Pq carrier detect or loss of carrier
|
2003-07-04 16:48:30 +04:00
|
|
|
messages.
|
|
|
|
It does not need special privileges to do this.
|
|
|
|
The scripts called for up or down events are run with the same user
|
|
|
|
id as
|
2001-11-19 12:43:03 +03:00
|
|
|
.Nm
|
|
|
|
is run.
|
|
|
|
.Pp
|
|
|
|
The following options are available:
|
|
|
|
.Bl -tag -width indent
|
2003-03-05 12:03:49 +03:00
|
|
|
.It Fl A Ar arrival-script
|
2003-07-04 16:48:30 +04:00
|
|
|
Specify the command to invoke on arrival of new interfaces (like
|
|
|
|
PCMCIA cards).
|
2004-01-05 01:19:51 +03:00
|
|
|
.It Fl c Ar carrier-script
|
|
|
|
Specify the command to invoke when the carrier status transitions from
|
|
|
|
no carrier to carrier.
|
2003-07-04 16:44:12 +04:00
|
|
|
.It Fl D Ar departure-script
|
|
|
|
Specify the command to invoke when an interface departs (for example
|
|
|
|
a PCMCIA card is removed.)
|
2001-11-19 13:10:45 +03:00
|
|
|
.It Fl d Ar down-script
|
|
|
|
Specify the command to invoke on
|
|
|
|
.Dq interface down
|
|
|
|
events (or: deletion of an address from an interface).
|
2001-11-19 12:43:03 +03:00
|
|
|
.It Fl h
|
|
|
|
Show the synopsis.
|
2001-12-10 18:04:51 +03:00
|
|
|
.It Fl i
|
|
|
|
Inhibit a call to the up-script on startup for all watched interfaces
|
2003-07-04 16:48:30 +04:00
|
|
|
already marked up.
|
|
|
|
If this option is not given,
|
2001-12-10 18:04:51 +03:00
|
|
|
.Nm
|
2003-07-04 16:48:30 +04:00
|
|
|
will check all watched interfaces on startup whether they are
|
|
|
|
already marked up and, if they are, call the up-script with
|
2004-11-25 19:04:30 +03:00
|
|
|
appropriate parameters.
|
|
|
|
Additionally, if the interface is up and has a link,
|
2004-11-25 18:55:29 +03:00
|
|
|
.Nm
|
|
|
|
will run the carrier script.
|
2001-12-10 18:04:51 +03:00
|
|
|
.Pp
|
2003-07-04 16:48:30 +04:00
|
|
|
Since ifwatchd typically is started late in the system boot sequence,
|
|
|
|
some of the monitored interfaces may already have come up when it
|
|
|
|
finally starts, but their up-scripts have not been called.
|
|
|
|
By default
|
2001-12-10 18:04:51 +03:00
|
|
|
.Nm
|
2003-07-04 16:48:30 +04:00
|
|
|
calls them on startup to account for this (and make the scripts
|
|
|
|
easier.)
|
2004-01-05 01:19:51 +03:00
|
|
|
.It Fl n Ar no-carrier-script
|
|
|
|
Specify the command to invoke when the carrier status transitions from
|
|
|
|
carrier to no carrier.
|
2003-07-04 16:44:12 +04:00
|
|
|
.It Fl q
|
|
|
|
Be quiet and don't log non-error messages to syslog.
|
2001-11-19 12:43:03 +03:00
|
|
|
.It Fl u Ar up-script
|
|
|
|
Specify the command to invoke on
|
|
|
|
.Dq interface up
|
|
|
|
events (or: addition of an address to an interface).
|
2001-11-19 13:10:45 +03:00
|
|
|
.It Fl v
|
2003-07-04 16:48:30 +04:00
|
|
|
Run in verbose debug mode and do not detach from the controlling
|
|
|
|
terminal.
|
|
|
|
Output verbose progress messages and flag errors ignored during
|
|
|
|
normal operation.
|
2003-06-24 13:31:17 +04:00
|
|
|
.Em You do not want to use this option in
|
|
|
|
.Pa /etc/rc.conf !
|
2004-01-05 01:19:51 +03:00
|
|
|
.It Ar ifname(s)
|
|
|
|
The name of the interface to watch.
|
|
|
|
Multiple interfaces may be specified.
|
|
|
|
Events for other interfaces are ignored.
|
2001-11-19 12:43:03 +03:00
|
|
|
.El
|
|
|
|
.Sh EXAMPLES
|
2001-11-19 13:10:45 +03:00
|
|
|
.Bd -literal -offset indent
|
2001-11-19 12:43:03 +03:00
|
|
|
# ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0
|
|
|
|
.Ed
|
2003-07-04 16:48:30 +04:00
|
|
|
.Pp
|
|
|
|
If your pppoe0 interface is your main connection to the internet,
|
|
|
|
the typical use of the up/down scripts is to add and remove a
|
|
|
|
default route.
|
|
|
|
This is an example for an up script doing this:
|
2002-02-23 11:11:22 +03:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
#! /bin/sh
|
2002-04-15 21:32:18 +04:00
|
|
|
/sbin/route add default $5
|
2010-04-16 17:47:50 +04:00
|
|
|
/sbin/route add -inet6 default fe80::2 -iface ifp $1
|
2002-02-23 11:11:22 +03:00
|
|
|
.Ed
|
2003-07-04 16:48:30 +04:00
|
|
|
.Pp
|
|
|
|
As described below the fifth command line parameter will contain
|
|
|
|
the peer address of the pppoe link.
|
|
|
|
The corresponding ip-down script is:
|
2002-02-23 11:11:22 +03:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
#! /bin/sh
|
2002-04-15 21:32:18 +04:00
|
|
|
/sbin/route delete default $5
|
2010-04-16 17:47:50 +04:00
|
|
|
/sbin/route delete -inet6 default fe80::2
|
2002-02-23 11:11:22 +03:00
|
|
|
.Ed
|
2003-07-04 16:48:30 +04:00
|
|
|
.Pp
|
|
|
|
Note that this is not a good idea if you have pppoe0 configured to
|
|
|
|
connect only on demand (via the link1 flag), but works well for
|
|
|
|
all permanent connected cases.
|
|
|
|
Use
|
2002-02-23 11:11:22 +03:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
! /sbin/route add default -iface 0.0.0.1
|
|
|
|
.Ed
|
2003-07-04 16:48:30 +04:00
|
|
|
.Pp
|
2002-02-23 11:11:22 +03:00
|
|
|
in your
|
|
|
|
.Pa /etc/ifconfig.pppoe0
|
|
|
|
file in the on-demand case.
|
2004-01-05 01:19:51 +03:00
|
|
|
.Pp
|
|
|
|
The next example is for dhclient users.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
# ifwatchd -i -c /etc/dhcp/carrier-detect tlp0
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
With the above command, the carrier-detect script will be invoked when
|
|
|
|
a carrier is detected on the interface
|
|
|
|
.Ar tlp0 .
|
|
|
|
Note that the
|
|
|
|
.Ar -i
|
|
|
|
flag prevents any action based on the initial state.
|
|
|
|
A script like the following should work for most users, although it
|
|
|
|
will not work for machines with multiple interfaces running
|
|
|
|
.Cm dhclient .
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
#! /bin/sh
|
|
|
|
# Arguments: ifname tty speed address destination
|
|
|
|
# If there is a dhclient already running, kill it.
|
|
|
|
# (This step could be put in a distinct no-carrier script,
|
|
|
|
# if desired.)
|
|
|
|
if [ -f /var/run/dhclient.pid ]; then
|
|
|
|
/bin/kill `/bin/cat /var/run/dhclient.pid`
|
|
|
|
fi
|
|
|
|
# Start dhclient again on this interface
|
|
|
|
/sbin/dhclient $1
|
|
|
|
.Ed
|
2001-11-19 12:43:03 +03:00
|
|
|
.Sh PARAMETERS PASSED TO SCRIPTS
|
2002-04-16 11:28:09 +04:00
|
|
|
The invoked scripts get passed these parameters:
|
2002-01-10 22:38:51 +03:00
|
|
|
.Bl -tag -width destination
|
2001-11-19 12:43:03 +03:00
|
|
|
.It Ar ifname
|
2003-07-04 16:48:30 +04:00
|
|
|
The name of the interface this change is for (this allows to share
|
|
|
|
the same script for multiple interfaces watched and dispatching on
|
|
|
|
the interface name in the script).
|
2002-04-15 21:32:18 +04:00
|
|
|
.It Ar tty
|
|
|
|
Dummy parameter for compatibility with
|
|
|
|
.Xr pppd 8
|
|
|
|
which will always be
|
|
|
|
.Em /dev/null .
|
|
|
|
.It Ar speed
|
|
|
|
Dummy parameter for compatibility with
|
|
|
|
.Xr pppd 8
|
|
|
|
which will always be
|
|
|
|
.Em 9600 .
|
2001-11-19 12:43:03 +03:00
|
|
|
.It Ar address
|
2003-07-04 16:48:30 +04:00
|
|
|
The new address if this is an up event, or the no longer valid old
|
|
|
|
address if this is a down event.
|
2001-11-19 12:43:03 +03:00
|
|
|
.Pp
|
2003-07-04 16:48:30 +04:00
|
|
|
The format of the address depends on the address family, for IPv4
|
|
|
|
it is the usual dotted quad notation, for IPv6 the colon separated
|
|
|
|
standard notation.
|
2002-01-10 22:38:51 +03:00
|
|
|
.It Ar destination
|
2003-07-04 16:48:30 +04:00
|
|
|
For point to point interfaces, this is the remote address of the
|
|
|
|
interface.
|
2002-01-10 22:38:51 +03:00
|
|
|
For other interfaces it is the broadcast address.
|
2001-11-19 12:43:03 +03:00
|
|
|
.El
|
2003-06-24 01:50:12 +04:00
|
|
|
.Sh ERRORS
|
|
|
|
The program logs to the syslog daemon as facility
|
|
|
|
.Dq daemon .
|
|
|
|
For detailed debugging use the
|
|
|
|
.Fl v
|
|
|
|
(verbose) option.
|
2001-11-19 12:43:03 +03:00
|
|
|
.Sh SEE ALSO
|
2003-04-16 13:06:55 +04:00
|
|
|
.Xr pppoe 4 ,
|
2001-11-19 12:43:03 +03:00
|
|
|
.Xr route 4 ,
|
|
|
|
.Xr ifconfig.if 5 ,
|
|
|
|
.Xr rc.d 8 ,
|
|
|
|
.Xr route 8
|
|
|
|
.Sh HISTORY
|
2001-11-19 13:10:45 +03:00
|
|
|
The
|
2001-11-19 12:43:03 +03:00
|
|
|
.Nm
|
|
|
|
utility appeared in
|
|
|
|
.Nx 1.6 .
|
2001-11-19 13:10:45 +03:00
|
|
|
.Sh AUTHORS
|
2001-11-19 12:43:03 +03:00
|
|
|
The program was written by
|
2003-02-14 19:11:34 +03:00
|
|
|
.An Martin Husemann
|
|
|
|
.Aq martin@NetBSD.org .
|
2003-07-04 16:44:12 +04:00
|
|
|
.Sh CAVEATS
|
2003-07-04 16:48:30 +04:00
|
|
|
Due to the nature of the program a lot of stupid errors can not
|
|
|
|
easily be caught in advance without removing the provided facility
|
|
|
|
for advanced uses.
|
|
|
|
For example typing errors in the interface name can not be detected
|
|
|
|
by checking against the list of installed interfaces, because it
|
|
|
|
is possible for a pcmcia card with the name given to be inserted
|
|
|
|
later.
|