[PATCH] pppd: Add ipv6-pre-up-script option

"Tomas Paukrt" <[email protected]>
Newsgroups gmane.linux.ppp
Message-ID <[email protected]>
This option allow a user to specify the path to a script
that will be run before the interface is brought up,
similarly to the existing ip-pre-up script.

Signed-off-by: Tomas Paukrt <[email protected]>
---
 pppd/ipv6cp.c       | 21 ++++++++++++++-------
 pppd/main.c         |  1 +
 pppd/options.c      |  4 ++++
 pppd/pathnames.h    |  1 +
 pppd/pppd-private.h |  1 +
 5 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/pppd/ipv6cp.c b/pppd/ipv6cp.c
index a36b1d9..9b0ef9d 100644
--- a/pppd/ipv6cp.c
+++ b/pppd/ipv6cp.c
@@ -322,7 +322,7 @@ struct protent ipv6cp_protent = {
 };
 
 static void ipv6cp_clear_addrs (int, eui64_t, eui64_t);
-static void ipv6cp_script (char *);
+static void ipv6cp_script (char *, int);
 static void ipv6cp_script_done (void *);
 
 /*
@@ -1235,6 +1235,7 @@ ipv6_demand_conf(int u)
 	eui64_magic_nz(wo->ourid);
     }
 
+    ipv6cp_script(path_ipv6preup, 1);
     if (!sif6up(u))
 	return 0;
     if (!sif6addr(u, wo->ourid, wo->hisid))
@@ -1342,6 +1343,9 @@ ipv6cp_up(fsm *f)
 	sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
 
     } else {
+	/* run the pre-up script, if any, and wait for it to finish */
+	ipv6cp_script(path_ipv6preup, 1);
+
 	/* bring the interface up for IPv6 */
 	if (!sif6up(f->unit)) {
 	    if (debug)
@@ -1381,7 +1385,7 @@ ipv6cp_up(fsm *f)
      */
     if (ipv6cp_script_state == s_down && ipv6cp_script_pid == 0) {
 	ipv6cp_script_state = s_up;
-	ipv6cp_script(path_ipv6up);
+	ipv6cp_script(path_ipv6up, 0);
     }
 }
 
@@ -1432,7 +1436,7 @@ ipv6cp_down(fsm *f)
     /* Execute the ipv6-down script */
     if (ipv6cp_script_state == s_up && ipv6cp_script_pid == 0) {
 	ipv6cp_script_state = s_down;
-	ipv6cp_script(path_ipv6down);
+	ipv6cp_script(path_ipv6down, 0);
     }
 }
 
@@ -1470,13 +1474,13 @@ ipv6cp_script_done(void *arg)
     case s_up:
 	if (ipv6cp_fsm[0].state != OPENED) {
 	    ipv6cp_script_state = s_down;
-	    ipv6cp_script(path_ipv6down);
+	    ipv6cp_script(path_ipv6down, 0);
 	}
 	break;
     case s_down:
 	if (ipv6cp_fsm[0].state == OPENED) {
 	    ipv6cp_script_state = s_up;
-	    ipv6cp_script(path_ipv6up);
+	    ipv6cp_script(path_ipv6up, 0);
 	}
 	break;
     }
@@ -1488,7 +1492,7 @@ ipv6cp_script_done(void *arg)
  * interface-name tty-name speed local-LL remote-LL.
  */
 static void
-ipv6cp_script(char *script)
+ipv6cp_script(char *script, int wait)
 {
     char strspeed[32], strlocal[64], strremote[64];
     char *argv[8];
@@ -1506,7 +1510,10 @@ ipv6cp_script(char *script)
     argv[6] = ipparam;
     argv[7] = NULL;
 
-    ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done,
+    if (wait)
+      run_program(script, argv, 0, NULL, NULL, 1);
+    else
+      ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done,
 				    NULL, 0);
 }
 
diff --git a/pppd/main.c b/pppd/main.c
index c42b69f..53250e7 100644
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -372,6 +372,7 @@ main(int argc, char *argv[])
 #ifdef PPP_WITH_IPV6CP
     strlcpy(path_ipv6up, PPP_PATH_IPV6UP, MAXPATHLEN);
     strlcpy(path_ipv6down, PPP_PATH_IPV6DOWN, MAXPATHLEN);
+    strlcpy(path_ipv6preup, PPP_PATH_IPV6PREUP, MAXPATHLEN);
 #endif
     link_stats_valid = 0;
     link_stats_print = 1;
diff --git a/pppd/options.c b/pppd/options.c
index 2cdfaf2..8c3e74b 100644
--- a/pppd/options.c
+++ b/pppd/options.c
@@ -138,6 +138,7 @@ int	dfl_route_metric = -1;	/* metric of the default route to set over the PPP li
 #ifdef PPP_WITH_IPV6CP
 char	path_ipv6up[MAXPATHLEN];   /* pathname of ipv6-up script */
 char	path_ipv6down[MAXPATHLEN]; /* pathname of ipv6-down script */
+char	path_ipv6preup[MAXPATHLEN]; /* pathname of ipv6-pre-up script */
 #endif
 
 unsigned int  maxoctets = 0;    /* default - no limit */
@@ -349,6 +350,9 @@ struct option general_options[] = {
     { "ipv6-down-script", o_string, path_ipv6down,
       "Set pathname of ipv6-down script",
       OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
+    { "ipv6-pre-up-script", o_string, path_ipv6preup,
+      "Set pathname of ipv6-pre-up script",
+      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
 #endif
 
 #ifdef PPP_WITH_MULTILINK
diff --git a/pppd/pathnames.h b/pppd/pathnames.h
index d08e8ef..b488236 100644
--- a/pppd/pathnames.h
+++ b/pppd/pathnames.h
@@ -119,6 +119,7 @@
 #ifdef PPP_WITH_IPV6CP
 #define PPP_PATH_IPV6UP         PPP_PATH_CONFDIR "/ipv6-up"
 #define PPP_PATH_IPV6DOWN       PPP_PATH_CONFDIR "/ipv6-down"
+#define PPP_PATH_IPV6PREUP      PPP_PATH_CONFDIR "/ipv6-pre-up"
 #endif
 
 #define PPP_PATH_PPPDB          PPP_PATH_VARRUN  "/pppd2.tdb"
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
index a38f58a..bcee1fd 100644
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -211,6 +211,7 @@ extern int  option_priority;    /* priority of current options */
 #ifdef PPP_WITH_IPV6CP
 extern char	path_ipv6up[]; /* pathname of ipv6-up script */
 extern char	path_ipv6down[]; /* pathname of ipv6-down script */
+extern char	path_ipv6preup[]; /* pathname of ipv6-pre-up script */
 #endif
 
 #if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
-- 
2.7.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.