p .Nm provides a generic way to watch this type of changes. It works by monitoring the routing socket and interpreting .Ql RTM_NEWADDR
q address added and .Ql RTM_DELADDR
q address deleted 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 .Nm is run.
p The following options are available: l -tag -width indent t Fl d Ar down-script Specify the command to invoke on .Dq interface down events (or: deletion of an address from an interface). t Fl h Show the synopsis. t Fl i Inhibit a call to the up-script on startup for all watched interfaces already marked up. If this option is not given, .Nm will check all watched interfaces on startup whether they are already marked up and, if they are, call the up-script with appropriate parameters.
p 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 .Nm calls them on startup to account for this (and make the scripts easier.) t Fl u Ar up-script Specify the command to invoke on .Dq interface up events (or: addition of an address to an interface). t Fl v Output verbose progress messages and flag errors ignored during normal operation. t Ar ifname(s) The name of the interface to watch. Multiple interfaces may be specified. Events for other interfaces are ignored. .El .Sh EXAMPLES d -literal -offset indent # ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0 .Ed 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: d -literal -offset indent #! /bin/sh /sbin/route add default $5 .Ed As described below the fifth command line parameter will contain the peer address of the pppoe link. The corresponding ip-down script is: d -literal -offset indent #! /bin/sh /sbin/route delete default $5 .Ed 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 d -literal -offset indent ! /sbin/route add default -iface 0.0.0.1 .Ed in your
a /etc/ifconfig.pppoe0 file in the on-demand case. .Sh PARAMETERS PASSED TO SCRIPTS The invoked scripts get passed this parameters: l -tag -width destination t Ar ifname 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). t Ar tty Dummy parameter for compatibility with .Xr pppd 8 which will always be .Em /dev/null . t Ar speed Dummy parameter for compatibility with .Xr pppd 8 which will always be .Em 9600 . t Ar address The new address if this is an up event, or the no longer valid old address if this is a down event.
p 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. t Ar destination For point to point interfaces, this is the remote address of the interface. For other interfaces it is the broadcast address. .El .Sh SEE ALSO .Xr route 4 , .Xr ifconfig.if 5 , .Xr pppoe 8 , .Xr rc.d 8 , .Xr route 8 .Sh HISTORY The .Nm utility appeared in .Nx 1.6 . .Sh AUTHORS The program was written by .An Martin Husemann Aq martin (at] netbsd.org .