linux-avmb1:PPPD: executing script when pppd comes up

Ralf Friedl Ralf.Friedl at online.de
Fri Jan 14 21:50:02 CET 2005


Hi

Obviously, the are some people who don't (want to) understand what you mean. ip-up is only called after the link is active, and the man page says is clearly:
> /etc/ppp/ip-up
>  A  program or script which is executed when the link is available for sending and receiving IP packets (that is, IPCP has come up).  It is executed with the parameters ...
Some seem to distinguish between 'when the (physical) line gets connected' and 'IP has been negotiated and is up'. While this is technically correct, the two normally happen within some seconds on a successfull connect, and the difference doesn't matter here.

>From your mails it seems you want to start pppd in demand mode and set up some routes so that packets reach the ppp interface and actually trigger the dial on demand. I had the same problem, and I have attached a patch for this.

Some have suggested a wrapper script for pppd. This would probably work, but it would be ugly and not reliable. Basically you start pppd in detach or nodetach mode, arrange for a wait of "sufficient time" and call your script. Whatever wait time you choose, it will be either longer that necessary or to short when the system is loaded.

The elegant and simple solution is to let pppd call your script at the right time, after preparing the interface.
The patch contain two changes:
- Call the script 'if-up' (not 'ip-up') after configuring the interface. The parameters are the same as with ip-up. You can use it to set your routes for the interface.
- detach is called only after the interface is up. You can use this feature to check if the interface is really up after calling pppd, and you could also use this to setup prouting after pppd is started.

Note it may not work in 'demand persist' mode.

The 'init' script is called immediatly before the connect script, and assuming you use the capiplugin, it is not called before dialing, if at all.

Ralf Friedl

Jan Schubert schrieb:

> There are several script option to pppd but there seems to be none for
> exectuting a script when pppd starts up. The init and connect options
> are used when the line/connection is activated (BTW: What is the
> difference betwenn the two of them?). Is there any chance to start a
> script when initializing pppd? This script should initialize some
> routing stuff for instance...
>
> Thx,
> Jan

--- pppd/main.c~        2004-10-02 00:48:43.252896103 +0200
+++ pppd/main.c 2004-10-02 00:51:29.027410849 +0200
@@ -413,11 +413,8 @@
 #endif

     /*
-     * Detach ourselves from the terminal, if required,
-     * and identify who is running us.
+     * identify who is running us.
      */
-    if (!nodetach && !updetach)
-       detach();
     p = getlogin();
     if (p == NULL) {
        pw = getpwuid(uid);
@@ -457,9 +454,33 @@
         * Configure the interface and mark it up, etc.
         */
        demand_conf();
+       {
+         char *script = "/etc/ppp/if-up";
+         char strspeed[32], strlocal[32], strremote[32];
+         char *argv[8];
+
+         slprintf(strspeed, sizeof(strspeed), "%d", baud_rate);
+         slprintf(strlocal, sizeof(strlocal), "%I", ipcp_gotoptions[0].ouraddr);
+         slprintf(strremote, sizeof(strremote), "%I", ipcp_hisoptions[0].hisaddr);
+
+         argv[0] = script;
+         argv[1] = ifname;
+         argv[2] = devnam;
+         argv[3] = strspeed;
+         argv[4] = strlocal;
+         argv[5] = strremote;
+         argv[6] = ipparam;
+         argv[7] = NULL;
+         run_program(script, argv, 0, NULL, NULL);
+       }
        create_linkpidfile(getpid());
     }

+    /*
+     * Detach ourselves from the terminal, if required,
+     */
+    if (!nodetach && !updetach)
+       detach();
     do_callback = 0;
     for (;;) {



More information about the linux-avmb1 mailing list