]> git.ozlabs.org Git - ppp.git/commitdiff
Added an /etc/ppp/ip-pre-up script, run before the interface
authorPaul Mackerras <paulus@samba.org>
Thu, 25 Aug 2005 23:59:34 +0000 (23:59 +0000)
committerPaul Mackerras <paulus@samba.org>
Thu, 25 Aug 2005 23:59:34 +0000 (23:59 +0000)
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
pppd/ipcp.c
pppd/ipv6cp.c
pppd/ipxcp.c
pppd/main.c
pppd/pathnames.h
pppd/pppd.h

index 9f677c2f37330743a216e0f72e91cd19042bdbd7..41ef5463c5928d84f2ea7bc225d103aa61a15873 100644 (file)
@@ -68,7 +68,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * 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 <stdio.h>
 #include <stddef.h>
 
 #include <stdio.h>
 #include <stddef.h>
@@ -2558,5 +2558,5 @@ auth_script(script)
     argv[5] = strspeed;
     argv[6] = NULL;
 
     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);
 }
 }
index da5fd739560f22d50f0191651da97cddc4b70ebb..5962c4720a39ea6924b383463eaecaf513c73a7f 100644 (file)
@@ -40,7 +40,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * 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:
 
 /*
  * 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_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 *));
 
 /*
 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;
     }
     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))
     if (!sifup(u))
        return 0;
     if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
@@ -1793,6 +1794,9 @@ ipcp_up(f)
        }
 #endif
 
        }
 #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)
        /* 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;
      */
     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;
     /* 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;
     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;
        }
        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;
     }
        }
        break;
     }
@@ -1968,8 +1972,9 @@ ipcp_script_done(arg)
  * interface-name tty-name speed local-IP remote-IP.
  */
 static void
  * interface-name tty-name speed local-IP remote-IP.
  */
 static void
-ipcp_script(script)
+ipcp_script(script, wait)
     char *script;
     char *script;
+    int wait;
 {
     char strspeed[32], strlocal[32], strremote[32];
     char *argv[8];
 {
     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;
     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);
 }
 
 /*
 }
 
 /*
index ce9b1385a444a90f7e2b5ba61edf547d83a31f04..4a09c9aa3aeddbe6587c214a34d8cb34c6286611 100644 (file)
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * 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: 
 
 /*
  * TODO: 
@@ -1419,7 +1419,8 @@ ipv6cp_script(script)
     argv[6] = ipparam;
     argv[7] = NULL;
 
     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);
 }
 
 /*
 }
 
 /*
index a78456d8cdedfe553c6094e989414d5c72d2278c..f0ee696854f9c63626a757af18059daf73306de6 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifdef IPX_CHANGE
 
 
 #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:
 
 /*
  * TODO:
@@ -1458,7 +1458,7 @@ ipxcp_script(f, script)
     argv[11] = ipparam;
     argv[12] = strpid;
     argv[13] = NULL;
     argv[11] = ipparam;
     argv[12] = strpid;
     argv[13] = NULL;
-    run_program(script, argv, 0, NULL, NULL);
+    run_program(script, argv, 0, NULL, NULL, 0);
 }
 
 /*
 }
 
 /*
index be212daa171f36cfa3c0922fc5f92b430b014a62..fe34cff76bf1da04cfab96850d17082c69dfd8de 100644 (file)
@@ -66,7 +66,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * 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 <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -1662,7 +1662,7 @@ device_script(program, in, out, dont_wait)
 
 /*
  * run-program - execute a program with given arguments,
 
 /*
  * 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
  * 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
  * 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;
     char *prog;
     char **args;
     int must_exist;
     void (*done) __P((void *));
     void *arg;
+    int wait;
 {
 {
-    int pid;
+    int pid, status;
     struct stat sbuf;
 
     /*
     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 (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;
     }
 
        return pid;
     }
 
index f070b43617087f0f1a3ee272c8f9ec2d8917b262..a33f0466c9d6d7e86e17316e0672477fd31228aa 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * define path names
  *
 /*
  * 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
  */
 
 #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_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."
 #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."
index 3a95d35349ff42e988b69f4f45105d8b710aa05b..f43a0390ab13479eb5cded5a93a7140f52b13fec 100644 (file)
@@ -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.
  *
  * 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,
 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 */
                                /* 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 */