From f2af1c05596be799c0c0ec1e451b8b0ae5ddabc6 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 25 Aug 2005 23:59:34 +0000 Subject: [PATCH] Added an /etc/ppp/ip-pre-up script, run before the interface is brought up. This necessitated adding a "wait" parameter to run_program, since we need to wait for this script to finish before proceeding. --- pppd/auth.c | 4 ++-- pppd/ipcp.c | 25 +++++++++++++++++-------- pppd/ipv6cp.c | 7 ++++--- pppd/ipxcp.c | 4 ++-- pppd/main.c | 17 +++++++++++++---- pppd/pathnames.h | 3 ++- pppd/pppd.h | 4 ++-- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/pppd/auth.c b/pppd/auth.c index 9f677c2..41ef546 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -68,7 +68,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: auth.c,v 1.106 2005/07/13 10:41:58 paulus Exp $" +#define RCSID "$Id: auth.c,v 1.107 2005/08/25 23:59:34 paulus Exp $" #include #include @@ -2558,5 +2558,5 @@ auth_script(script) argv[5] = strspeed; argv[6] = NULL; - auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL); + auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0); } diff --git a/pppd/ipcp.c b/pppd/ipcp.c index da5fd73..5962c47 100644 --- a/pppd/ipcp.c +++ b/pppd/ipcp.c @@ -40,7 +40,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: ipcp.c,v 1.69 2004/11/13 12:03:26 paulus Exp $" +#define RCSID "$Id: ipcp.c,v 1.70 2005/08/25 23:59:34 paulus Exp $" /* * TODO: @@ -264,7 +264,7 @@ struct protent ipcp_protent = { }; static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t)); -static void ipcp_script __P((char *)); /* Run an up/down script */ +static void ipcp_script __P((char *, int)); /* Run an up/down script */ static void ipcp_script_done __P((void *)); /* @@ -1654,6 +1654,7 @@ ip_demand_conf(u) } if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr))) return 0; + ipcp_script(_PATH_IPPREUP, 1); if (!sifup(u)) return 0; if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE)) @@ -1793,6 +1794,9 @@ ipcp_up(f) } #endif + /* run the pre-up script, if any, and wait for it to finish */ + ipcp_script(_PATH_IPPREUP, 1); + /* bring the interface up for IP */ if (!sifup(f->unit)) { if (debug) @@ -1846,7 +1850,7 @@ ipcp_up(f) */ if (ipcp_script_state == s_down && ipcp_script_pid == 0) { ipcp_script_state = s_up; - ipcp_script(_PATH_IPUP); + ipcp_script(_PATH_IPUP, 0); } } @@ -1896,7 +1900,7 @@ ipcp_down(f) /* Execute the ip-down script */ if (ipcp_script_state == s_up && ipcp_script_pid == 0) { ipcp_script_state = s_down; - ipcp_script(_PATH_IPDOWN); + ipcp_script(_PATH_IPDOWN, 0); } } @@ -1950,13 +1954,13 @@ ipcp_script_done(arg) case s_up: if (ipcp_fsm[0].state != OPENED) { ipcp_script_state = s_down; - ipcp_script(_PATH_IPDOWN); + ipcp_script(_PATH_IPDOWN, 0); } break; case s_down: if (ipcp_fsm[0].state == OPENED) { ipcp_script_state = s_up; - ipcp_script(_PATH_IPUP); + ipcp_script(_PATH_IPUP, 0); } break; } @@ -1968,8 +1972,9 @@ ipcp_script_done(arg) * interface-name tty-name speed local-IP remote-IP. */ static void -ipcp_script(script) +ipcp_script(script, wait) char *script; + int wait; { char strspeed[32], strlocal[32], strremote[32]; char *argv[8]; @@ -1986,7 +1991,11 @@ ipcp_script(script) argv[5] = strremote; argv[6] = ipparam; argv[7] = NULL; - ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, NULL); + if (wait) + run_program(script, argv, 0, NULL, NULL, 1); + else + ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done, + NULL, 0); } /* diff --git a/pppd/ipv6cp.c b/pppd/ipv6cp.c index ce9b138..4a09c9a 100644 --- a/pppd/ipv6cp.c +++ b/pppd/ipv6cp.c @@ -135,10 +135,10 @@ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: ipv6cp.c,v 1.20 2004/11/13 02:28:15 paulus Exp $ + * $Id: ipv6cp.c,v 1.21 2005/08/25 23:59:34 paulus Exp $ */ -#define RCSID "$Id: ipv6cp.c,v 1.20 2004/11/13 02:28:15 paulus Exp $" +#define RCSID "$Id: ipv6cp.c,v 1.21 2005/08/25 23:59:34 paulus Exp $" /* * TODO: @@ -1419,7 +1419,8 @@ ipv6cp_script(script) argv[6] = ipparam; argv[7] = NULL; - ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done, NULL); + ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done, + NULL, 0); } /* diff --git a/pppd/ipxcp.c b/pppd/ipxcp.c index a78456d..f0ee696 100644 --- a/pppd/ipxcp.c +++ b/pppd/ipxcp.c @@ -42,7 +42,7 @@ #ifdef IPX_CHANGE -#define RCSID "$Id: ipxcp.c,v 1.23 2004/11/13 02:28:15 paulus Exp $" +#define RCSID "$Id: ipxcp.c,v 1.24 2005/08/25 23:59:34 paulus Exp $" /* * TODO: @@ -1458,7 +1458,7 @@ ipxcp_script(f, script) argv[11] = ipparam; argv[12] = strpid; argv[13] = NULL; - run_program(script, argv, 0, NULL, NULL); + run_program(script, argv, 0, NULL, NULL, 0); } /* diff --git a/pppd/main.c b/pppd/main.c index be212da..fe34cff 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -66,7 +66,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: main.c,v 1.151 2005/07/12 01:07:59 paulus Exp $" +#define RCSID "$Id: main.c,v 1.152 2005/08/25 23:59:34 paulus Exp $" #include #include @@ -1662,7 +1662,7 @@ device_script(program, in, out, dont_wait) /* * run-program - execute a program with given arguments, - * but don't wait for it. + * but don't wait for it unless wait is non-zero. * If the program can't be executed, logs an error unless * must_exist is 0 and the program file doesn't exist. * Returns -1 if it couldn't fork, 0 if the file doesn't exist @@ -1671,14 +1671,15 @@ device_script(program, in, out, dont_wait) * reap_kids) iff the return value is > 0. */ pid_t -run_program(prog, args, must_exist, done, arg) +run_program(prog, args, must_exist, done, arg, wait) char *prog; char **args; int must_exist; void (*done) __P((void *)); void *arg; + int wait; { - int pid; + int pid, status; struct stat sbuf; /* @@ -1704,6 +1705,14 @@ run_program(prog, args, must_exist, done, arg) if (debug) dbglog("Script %s started (pid %d)", prog, pid); record_child(pid, prog, done, arg); + if (wait) { + while (waitpid(pid, &status, 0) < 0) { + if (errno == EINTR) + continue; + fatal("error waiting for script %s: %m", prog); + } + reap_kids(); + } return pid; } diff --git a/pppd/pathnames.h b/pppd/pathnames.h index f070b43..a33f046 100644 --- a/pppd/pathnames.h +++ b/pppd/pathnames.h @@ -1,7 +1,7 @@ /* * define path names * - * $Id: pathnames.h,v 1.17 2005/07/10 11:19:10 paulus Exp $ + * $Id: pathnames.h,v 1.18 2005/08/25 23:59:34 paulus Exp $ */ #ifdef HAVE_PATHS_H @@ -24,6 +24,7 @@ #define _PATH_SYSOPTIONS _ROOT_PATH "/etc/ppp/options" #define _PATH_IPUP _ROOT_PATH "/etc/ppp/ip-up" #define _PATH_IPDOWN _ROOT_PATH "/etc/ppp/ip-down" +#define _PATH_IPPREUP _ROOT_PATH "/etc/ppp/ip-pre-up" #define _PATH_AUTHUP _ROOT_PATH "/etc/ppp/auth-up" #define _PATH_AUTHDOWN _ROOT_PATH "/etc/ppp/auth-down" #define _PATH_TTYOPT _ROOT_PATH "/etc/ppp/options." diff --git a/pppd/pppd.h b/pppd/pppd.h index 3a95d35..f43a039 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -39,7 +39,7 @@ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $Id: pppd.h,v 1.90 2005/07/12 01:07:59 paulus Exp $ + * $Id: pppd.h,v 1.91 2005/08/25 23:59:34 paulus Exp $ */ /* @@ -478,7 +478,7 @@ pid_t safe_fork __P((int, int, int)); /* Fork & close stuff in child */ int device_script __P((char *cmd, int in, int out, int dont_wait)); /* Run `cmd' with given stdin and stdout */ pid_t run_program __P((char *prog, char **args, int must_exist, - void (*done)(void *), void *arg)); + void (*done)(void *), void *arg, int wait)); /* Run program prog with args in child */ void reopen_log __P((void)); /* (re)open the connection to syslog */ void print_link_stats __P((void)); /* Print stats, if available */ -- 2.39.2