Invoke "ip-up" and "ip-down" script with parameters exactly matching

those used by pppd(8).
This commit is contained in:
tron 2002-04-15 17:32:18 +00:00
parent d533e315ee
commit c28d45defe
2 changed files with 22 additions and 13 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ifwatchd.8,v 1.8 2002/04/14 11:41:43 martin Exp $
.\" $NetBSD: ifwatchd.8,v 1.9 2002/04/15 17:32:18 tron Exp $
.\"
.\" Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -106,42 +106,50 @@ Events for other interfaces are ignored.
.Sh EXAMPLES
.Bd -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:
.Bd -literal -offset indent
#! /bin/sh
/sbin/route add default $4
/sbin/route add default $5
.Ed
As described below the fourth command line parameter will contain the peer
address of the pppoe link. The corresponding ip-down script is:
.Bd -literal -offset indent
#! /bin/sh
/sbin/route delete default
/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
.Bd -literal -offset indent
! /sbin/route add default -iface 0.0.0.1
.Ed
in your
.Pa /etc/ifconfig.pppoe0
file in the on-demand case.
.Sh PARAMETERS PASSED TO SCRIPTS
The invoked scripts get four parameters passed:
The invoked scripts get five parameters passed:
.Bl -tag -width destination
.It 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).
.It Ar up/down
Verbatim
.Em up
or
.Em down ,
which allows for the sharing of up and down scripts.
.It Ar tty
Dummy parameter for compatibility with
.Xr pppd 8
which will always be
.Em /dev/null .
.It Ar speed
Dummy parameter for compatibility with
.Xr pppd 8
which will always be
.Em 9600 .
.It Ar address
The new address if this is an up event, or the no longer valid old address
if this is a down event.

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifwatchd.c,v 1.6 2002/04/14 11:41:43 martin Exp $ */
/* $NetBSD: ifwatchd.c,v 1.7 2002/04/15 17:32:18 tron Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -55,6 +55,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -286,8 +287,8 @@ invoke_script(sa, dest, is_up, ifindex)
script = is_up? up_script : down_script;
if (script == NULL) return;
asprintf(&cmd, "%s \"%s\" %s \"%s\" \"%s\"", script, ifname,
is_up?"up":"down", addr, daddr);
asprintf(&cmd, "%s \"%s\" " _PATH_DEVNULL " 9600 \"%s\" \"%s\"",
script, ifname, addr, daddr);
if (cmd == NULL) {
fprintf(stderr, "out of memory\n");
return;