xref: /netbsd-src/usr.sbin/ifwatchd/ifwatchd.8 (revision 50728e7823a76d5bd1a7bfa3a4eac400269b1339)
1.\" $NetBSD: ifwatchd.8,v 1.24 2008/04/30 13:11:02 martin Exp $
2.\"
3.\" Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Martin Husemann <martin@NetBSD.org>.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd November 4, 2004
31.Os
32.Dt IFWATCHD 8
33.Sh NAME
34.Nm ifwatchd
35.Nd "watch for addresses added to or deleted from interfaces and call up/down-scripts for them"
36.Sh SYNOPSIS
37.Nm
38.Op Fl hiqv
39.Op Fl A Ar arrival-script
40.Op Fl c Ar carrier-script
41.Op Fl D Ar departure-script
42.Op Fl d Ar down-script
43.Op Fl u Ar up-script
44.Op Fl n Ar no-carrier-script
45.Ar ifname(s)
46.Sh DESCRIPTION
47.Nm
48is used to monitor dynamic interfaces (for example PPP interfaces)
49for address changes, and to monitor static interfaces for carrier
50changes.
51Sometimes these interfaces are accompanied by a daemon program,
52which can take care of running any necessary scripts (like
53.Xr pppd 8
54or
55.Xr isdnd 8 ) ,
56but sometimes the interfaces run completely autonomously (like
57.Xr pppoe 4 ) .
58.Pp
59.Nm
60provides a generic way to watch these types of changes.
61It works by monitoring the routing socket and interpreting
62.Ql RTM_NEWADDR
63.Pq address added ,
64.Ql RTM_DELADDR
65.Pq address deleted
66and
67.Ql RTM_IFINFO
68.Pq carrier detect or loss of carrier
69messages.
70It does not need special privileges to do this.
71The scripts called for up or down events are run with the same user
72id as
73.Nm
74is run.
75.Pp
76The following options are available:
77.Bl -tag -width indent
78.It Fl A Ar arrival-script
79Specify the command to invoke on arrival of new interfaces (like
80PCMCIA cards).
81.It Fl c Ar carrier-script
82Specify the command to invoke when the carrier status transitions from
83no carrier to carrier.
84.It Fl D Ar departure-script
85Specify the command to invoke when an interface departs (for example
86a PCMCIA card is removed.)
87.It Fl d Ar down-script
88Specify the command to invoke on
89.Dq interface down
90events (or: deletion of an address from an interface).
91.It Fl h
92Show the synopsis.
93.It Fl i
94Inhibit a call to the up-script on startup for all watched interfaces
95already marked up.
96If this option is not given,
97.Nm
98will check all watched interfaces on startup whether they are
99already marked up and, if they are, call the up-script with
100appropriate parameters.
101Additionally, if the interface is up and has a link,
102.Nm
103will run the carrier script.
104.Pp
105Since ifwatchd typically is started late in the system boot sequence,
106some of the monitored interfaces may already have come up when it
107finally starts, but their up-scripts have not been called.
108By default
109.Nm
110calls them on startup to account for this (and make the scripts
111easier.)
112.It Fl n Ar no-carrier-script
113Specify the command to invoke when the carrier status transitions from
114carrier to no carrier.
115.It Fl q
116Be quiet and don't log non-error messages to syslog.
117.It Fl u Ar up-script
118Specify the command to invoke on
119.Dq interface up
120events (or: addition of an address to an interface).
121.It Fl v
122Run in verbose debug mode and do not detach from the controlling
123terminal.
124Output verbose progress messages and flag errors ignored during
125normal operation.
126.Em You do not want to use this option in
127.Pa /etc/rc.conf !
128.It Ar ifname(s)
129The name of the interface to watch.
130Multiple interfaces may be specified.
131Events for other interfaces are ignored.
132.El
133.Sh EXAMPLES
134.Bd -literal -offset indent
135# ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0
136.Ed
137.Pp
138If your pppoe0 interface is your main connection to the internet,
139the typical use of the up/down scripts is to add and remove a
140default route.
141This is an example for an up script doing this:
142.Bd -literal -offset indent
143#! /bin/sh
144/sbin/route add default $5
145.Ed
146.Pp
147As described below the fifth command line parameter will contain
148the peer address of the pppoe link.
149The corresponding ip-down script is:
150.Bd -literal -offset indent
151#! /bin/sh
152/sbin/route delete default $5
153.Ed
154.Pp
155Note that this is not a good idea if you have pppoe0 configured to
156connect only on demand (via the link1 flag), but works well for
157all permanent connected cases.
158Use
159.Bd -literal -offset indent
160! /sbin/route add default -iface 0.0.0.1
161.Ed
162.Pp
163in your
164.Pa /etc/ifconfig.pppoe0
165file in the on-demand case.
166.Pp
167The next example is for dhclient users.
168.Bd -literal -offset indent
169# ifwatchd -i -c /etc/dhcp/carrier-detect tlp0
170.Ed
171.Pp
172With the above command, the carrier-detect script will be invoked when
173a carrier is detected on the interface
174.Ar tlp0 .
175Note that the
176.Ar -i
177flag prevents any action based on the initial state.
178A script like the following should work for most users, although it
179will not work for machines with multiple interfaces running
180.Cm dhclient .
181.Bd -literal -offset indent
182#! /bin/sh
183# Arguments:  ifname tty speed address destination
184# If there is a dhclient already running, kill it.
185# (This step could be put in a distinct no-carrier script,
186# if desired.)
187if [ -f /var/run/dhclient.pid ]; then
188       /bin/kill `/bin/cat /var/run/dhclient.pid`
189fi
190# Start dhclient again on this interface
191/sbin/dhclient $1
192.Ed
193.Sh PARAMETERS PASSED TO SCRIPTS
194The invoked scripts get passed these parameters:
195.Bl -tag -width destination
196.It Ar ifname
197The name of the interface this change is for (this allows to share
198the same script for multiple interfaces watched and dispatching on
199the interface name in the script).
200.It Ar tty
201Dummy parameter for compatibility with
202.Xr pppd 8
203which will always be
204.Em /dev/null .
205.It Ar speed
206Dummy parameter for compatibility with
207.Xr pppd 8
208which will always be
209.Em 9600 .
210.It Ar address
211The new address if this is an up event, or the no longer valid old
212address if this is a down event.
213.Pp
214The format of the address depends on the address family, for IPv4
215it is the usual dotted quad notation, for IPv6 the colon separated
216standard notation.
217.It Ar destination
218For point to point interfaces, this is the remote address of the
219interface.
220For other interfaces it is the broadcast address.
221.El
222.Sh ERRORS
223The program logs to the syslog daemon as facility
224.Dq daemon .
225For detailed debugging use the
226.Fl v
227(verbose) option.
228.Sh SEE ALSO
229.Xr pppoe 4 ,
230.Xr route 4 ,
231.Xr ifconfig.if 5 ,
232.Xr rc.d 8 ,
233.Xr route 8
234.Sh HISTORY
235The
236.Nm
237utility appeared in
238.Nx 1.6 .
239.Sh AUTHORS
240The program was written by
241.An Martin Husemann
242.Aq martin@NetBSD.org .
243.Sh CAVEATS
244Due to the nature of the program a lot of stupid errors can not
245easily be caught in advance without removing the provided facility
246for advanced uses.
247For example typing errors in the interface name can not be detected
248by checking against the list of installed interfaces, because it
249is possible for a pcmcia card with the name given to be inserted
250later.
251