1 .\" $NetBSD: ifwatchd.8,v 1.24 2008/04/30 13:11:02 martin Exp $
3 .\" Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Martin Husemann <martin@NetBSD.org>.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
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.
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.
35 .Nd "watch for addresses added to or deleted from interfaces and call up/down-scripts for them"
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
44 .Op Fl n Ar no-carrier-script
48 is used to monitor dynamic interfaces (for example PPP interfaces)
49 for address changes, and to monitor static interfaces for carrier
51 Sometimes these interfaces are accompanied by a daemon program,
52 which can take care of running any necessary scripts (like
56 but sometimes the interfaces run completely autonomously (like
60 provides a generic way to watch these types of changes.
61 It works by monitoring the routing socket and interpreting
68 .Pq carrier detect or loss of carrier
70 It does not need special privileges to do this.
71 The scripts called for up or down events are run with the same user
76 The following options are available:
77 .Bl -tag -width indent
78 .It Fl A Ar arrival-script
79 Specify the command to invoke on arrival of new interfaces (like
81 .It Fl c Ar carrier-script
82 Specify the command to invoke when the carrier status transitions from
83 no carrier to carrier.
84 .It Fl D Ar departure-script
85 Specify the command to invoke when an interface departs (for example
86 a PCMCIA card is removed.)
87 .It Fl d Ar down-script
88 Specify the command to invoke on
90 events (or: deletion of an address from an interface).
94 Inhibit a call to the up-script on startup for all watched interfaces
96 If this option is not given,
98 will check all watched interfaces on startup whether they are
99 already marked up and, if they are, call the up-script with
100 appropriate parameters.
101 Additionally, if the interface is up and has a link,
103 will run the carrier script.
105 Since ifwatchd typically is started late in the system boot sequence,
106 some of the monitored interfaces may already have come up when it
107 finally starts, but their up-scripts have not been called.
110 calls them on startup to account for this (and make the scripts
112 .It Fl n Ar no-carrier-script
113 Specify the command to invoke when the carrier status transitions from
114 carrier to no carrier.
116 Be quiet and don't log non-error messages to syslog.
117 .It Fl u Ar up-script
118 Specify the command to invoke on
120 events (or: addition of an address to an interface).
122 Run in verbose debug mode and do not detach from the controlling
124 Output verbose progress messages and flag errors ignored during
126 .Em You do not want to use this option in
129 The name of the interface to watch.
130 Multiple interfaces may be specified.
131 Events for other interfaces are ignored.
134 .Bd -literal -offset indent
135 # ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0
138 If your pppoe0 interface is your main connection to the internet,
139 the typical use of the up/down scripts is to add and remove a
141 This is an example for an up script doing this:
142 .Bd -literal -offset indent
144 /sbin/route add default $5
147 As described below the fifth command line parameter will contain
148 the peer address of the pppoe link.
149 The corresponding ip-down script is:
150 .Bd -literal -offset indent
152 /sbin/route delete default $5
155 Note that this is not a good idea if you have pppoe0 configured to
156 connect only on demand (via the link1 flag), but works well for
157 all permanent connected cases.
159 .Bd -literal -offset indent
160 ! /sbin/route add default -iface 0.0.0.1
164 .Pa /etc/ifconfig.pppoe0
165 file in the on-demand case.
167 The next example is for dhclient users.
168 .Bd -literal -offset indent
169 # ifwatchd -i -c /etc/dhcp/carrier-detect tlp0
172 With the above command, the carrier-detect script will be invoked when
173 a carrier is detected on the interface
177 flag prevents any action based on the initial state.
178 A script like the following should work for most users, although it
179 will not work for machines with multiple interfaces running
181 .Bd -literal -offset indent
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,
187 if [ -f /var/run/dhclient.pid ]; then
188 /bin/kill `/bin/cat /var/run/dhclient.pid`
190 # Start dhclient again on this interface
193 .Sh PARAMETERS PASSED TO SCRIPTS
194 The invoked scripts get passed these parameters:
195 .Bl -tag -width destination
197 The name of the interface this change is for (this allows to share
198 the same script for multiple interfaces watched and dispatching on
199 the interface name in the script).
201 Dummy parameter for compatibility with
206 Dummy parameter for compatibility with
211 The new address if this is an up event, or the no longer valid old
212 address if this is a down event.
214 The format of the address depends on the address family, for IPv4
215 it is the usual dotted quad notation, for IPv6 the colon separated
218 For point to point interfaces, this is the remote address of the
220 For other interfaces it is the broadcast address.
223 The program logs to the syslog daemon as facility
225 For detailed debugging use the
240 The program was written by
242 .Aq martin@NetBSD.org .
244 Due to the nature of the program a lot of stupid errors can not
245 easily be caught in advance without removing the provided facility
247 For example typing errors in the interface name can not be detected
248 by checking against the list of installed interfaces, because it
249 is possible for a pcmcia card with the name given to be inserted