Skip to content

Commit

Permalink
pppd: implement net-init, net-pre-up and net-down scripts.
Browse files Browse the repository at this point in the history
net-init: executes from set_ifunit which gets called once we have a ppp
interface to work with.  I suspect this may be called multiple times,
which I think is OK.  Will wait.

net-pre-up:  executes from set_ifup, *prior* to bringing the interface
up.  Will wait.

net-down:  executes just prior to actually tearing down the interface.
Will NOT wait.

Arguments passed:

interface-name
tty-device
speed
ipparam

Documentation pending.

Signed-off-by: Jaco Kroon <[email protected]>
  • Loading branch information
jkroonza committed Aug 24, 2022
1 parent bf9329e commit b810041
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
31 changes: 29 additions & 2 deletions pppd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ static void holdoff_end(void *);
static void forget_child(int pid, int status);
static int reap_kids(void);
static void childwait_end(void *);
static void main_script(char* script, int wait);

#ifdef PPP_WITH_TDB
static void update_db_entry(void);
Expand Down Expand Up @@ -739,6 +740,7 @@ set_ifunit(int iskey)
else
slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
info("Using interface %s", ifname);
main_script(PPP_PATH_NET_INIT, 1);
script_setenv("IFNAME", ifname, iskey);
slprintf(ifkey, sizeof(ifkey), "%d", ifunit);
script_setenv("UNIT", ifkey, iskey);
Expand All @@ -748,6 +750,26 @@ set_ifunit(int iskey)
}
}

/*
* net-* scripts to be run come through here.
*/
static void main_script(char* script, int wait)
{
char strspeed[32];
char *argv[6];

slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);

argv[0] = script;
argv[1] = ifname;
argv[2] = devnam;
argv[3] = strspeed;
argv[4] = ipparam;
argv[5] = NULL;

run_program(script, argv, 0, NULL, NULL, wait);
}

/*
* set_ifup - called in order to set the ppp interface to up, if not already
* brought up.
Expand All @@ -761,8 +783,11 @@ set_ifup(const char* name)
int i;
const char** t;

if (!up_protos && !netif_set_up())
return 0;
if (!up_protos) {
main_script(PPP_PATH_NET_PREUP, 1);
if (!netif_set_up())
return 0;
}

i = 0;
while (up_protos && up_protos[i]) {
Expand Down Expand Up @@ -822,6 +847,8 @@ set_ifdown(const char* name)
free(up_protos);
up_protos = NULL;

main_script(PPP_PATH_NET_DOWN, 0);

return netif_set_down();
}

Expand Down
3 changes: 3 additions & 0 deletions pppd/pathnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
#define PPP_PATH_TTYOPT PPP_PATH_CONFDIR "/options."
#define PPP_PATH_PEERFILES PPP_PATH_CONFDIR "/peers/"
#define PPP_PATH_RESOLV PPP_PATH_CONFDIR "/resolv.conf"
#define PPP_PATH_NET_INIT PPP_PATH_CONFDIR "/net-init"
#define PPP_PATH_NET_PREUP PPP_PATH_CONFDIR "/net-pre-up"
#define PPP_PATH_NET_DOWN PPP_PATH_CONFDIR "/net-down"

#define PPP_PATH_CONNERRS PPP_PATH_VARLOG "/connect-errors"

Expand Down

0 comments on commit b810041

Please sign in to comment.