xref: /netbsd-src/usr.sbin/ifwatchd/ifwatchd.8 (revision 7c192b2a5e1093666e67801684f930ef49b3b363)
1.\" $NetBSD: ifwatchd.8,v 1.27 2010/04/16 13:56:45 wiz 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 April 16, 2010
31.Dt IFWATCHD 8
32.Os
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/sbin/route add -inet6 default fe80::2 -iface ifp $1
146.Ed
147.Pp
148As described below the fifth command line parameter will contain
149the peer address of the pppoe link.
150The corresponding ip-down script is:
151.Bd -literal -offset indent
152#! /bin/sh
153/sbin/route delete default $5
154/sbin/route delete -inet6 default fe80::2
155.Ed
156.Pp
157Note that this is not a good idea if you have pppoe0 configured to
158connect only on demand (via the link1 flag), but works well for
159all permanent connected cases.
160Use
161.Bd -literal -offset indent
162! /sbin/route add default -iface 0.0.0.1
163.Ed
164.Pp
165in your
166.Pa /etc/ifconfig.pppoe0
167file in the on-demand case.
168.Pp
169The next example is for dhclient users.
170.Bd -literal -offset indent
171# ifwatchd -i -c /etc/dhcp/carrier-detect tlp0
172.Ed
173.Pp
174With the above command, the carrier-detect script will be invoked when
175a carrier is detected on the interface
176.Ar tlp0 .
177Note that the
178.Fl i
179flag prevents any action based on the initial state.
180A script like the following should work for most users, although it
181will not work for machines with multiple interfaces running
182.Cm dhclient .
183.Bd -literal -offset indent
184#! /bin/sh
185# Arguments:  ifname tty speed address destination
186# If there is a dhclient already running, kill it.
187# (This step could be put in a distinct no-carrier script,
188# if desired.)
189if [ -f /var/run/dhclient.pid ]; then
190       /bin/kill `/bin/cat /var/run/dhclient.pid`
191fi
192# Start dhclient again on this interface
193/sbin/dhclient $1
194.Ed
195.Sh PARAMETERS PASSED TO SCRIPTS
196The invoked scripts get passed these parameters:
197.Bl -tag -width destination
198.It Ar ifname
199The name of the interface this change is for (this allows to share
200the same script for multiple interfaces watched and dispatching on
201the interface name in the script).
202.It Ar tty
203Dummy parameter for compatibility with
204.Xr pppd 8
205which will always be
206.Em /dev/null .
207.It Ar speed
208Dummy parameter for compatibility with
209.Xr pppd 8
210which will always be
211.Em 9600 .
212.It Ar address
213The new address if this is an up event, or the no longer valid old
214address if this is a down event.
215.Pp
216The format of the address depends on the address family, for IPv4
217it is the usual dotted quad notation, for IPv6 the colon separated
218standard notation.
219.It Ar destination
220For point to point interfaces, this is the remote address of the
221interface.
222For other interfaces it is the broadcast address.
223.El
224.Sh ERRORS
225The program logs to the syslog daemon as facility
226.Dq daemon .
227For detailed debugging use the
228.Fl v
229(verbose) option.
230.Sh SEE ALSO
231.Xr pppoe 4 ,
232.Xr route 4 ,
233.Xr ifconfig.if 5 ,
234.Xr rc.d 8 ,
235.Xr route 8
236.Sh HISTORY
237The
238.Nm
239utility appeared in
240.Nx 1.6 .
241.Sh AUTHORS
242The program was written by
243.An Martin Husemann
244.Aq martin@NetBSD.org .
245.Sh CAVEATS
246Due to the nature of the program a lot of stupid errors can not
247easily be caught in advance without removing the provided facility
248for advanced uses.
249For example typing errors in the interface name can not be detected
250by checking against the list of installed interfaces, because it
251is possible for a pcmcia card with the name given to be inserted
252later.
253