Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

ifwatchd

Watch for addresses added to or deleted from interfaces and call up/down-scripts for them

Syntax:

ifwatchd [-hiqv] [-A arrival-script] [-c carrier-script]
         [-D departure-script] [-d down-script]
         [-n no-carrier-script] [-u up-script] ifname(s)

Runs on:

Neutrino

Options:

-A arrival-script
Specify the command to invoke when new interfaces (such as PCMCIA cards) arrive.
-c carrier-script
Specify the command to invoke when the carrier status changes from no carrier to carrier.
-D departure-script
Specify the command to invoke when an interface departs (for example a PCMCIA card is removed.)
-d down-script
Specify the command to invoke on “interface down” events (or on the deletion of an address from an interface).
-h
Show the synopsis.
-i
Inhibit a call to the up-script on startup for all watched interfaces already marked up. If you don't specify this option, ifwatchd checks all watched interfaces on startup whether they're already marked up and, if they are, calls the up-script with appropriate parameters.

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 haven't been called. By default, ifwatchd calls them on startup to account for this (and make the scripts easier.)

-n no-carrier-script
Specify the command to invoke when the carrier status transitions from carrier to no carrier.
-q
Be quiet and don't log non-error messages to slogger.
-u up-script
Specify the command to invoke on “interface up” events (or on the addition of an address to an interface).
-v
Run in verbose debug mode and don't detach from the controlling terminal. Output verbose progress messages, and flag those errors that are ignored during normal operation. Don't use this option in /etc/rc.conf.
ifname(s)
The name of the interface to watch. You can specify multiple interfaces. Events for other interfaces are ignored.

Description:

The ifwatchd utility is used to monitor dynamic interfaces (for example PPP interfaces) for address changes, and to monitor static interfaces for carrier changes. Sometimes these interfaces are accompanied by a daemon program, which can take care of running any necessary scripts (such as pppd or isdnd), but sometimes the interfaces run completely autonomously (such as pppoe).

The ifwatchd utility provides a generic way to watch these types of changes. It works by monitoring the routing socket and interpreting RTM_NEWADDR (address added), RTM_DELADDR (address deleted) and RTM_IFINFO (carrier detect or loss of carrier) messages. It doesn't need special privileges to do this. The scripts called for up or down events are run with the same user ID as for ifwatchd.

Examples:

# ifwatchd -u /etc/ppp/ip-up -d /etc/ppp/ip-down pppoe0

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 of an up script that does this:

#! /bin/sh
/sbin/route add default $5

As described below, the fifth command line parameter contains the peer address of the pppoe link. The corresponding ip-down script is:

#! /bin/sh
/sbin/route delete default $5

Note: This isn't 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:
! /sbin/route add default -iface 0.0.0.1

in your /etc/ifconfig.pppoe0 file in the on-demand case.