]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
pppd.8: Document netmask option
[ppp.git] / pppd / main.c
index 1a2a446cc5ffda2c141f28b5f13eeccc08d02019..8310c9871e4bce3acd5acea6edc2c4bbc6d74ea4 100644 (file)
@@ -55,7 +55,7 @@
  * 3. Redistributions of any form whatsoever must retain the following
  *    acknowledgment:
  *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ *     <paulus@ozlabs.org>".
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -248,6 +248,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 run_net_script(char* script, int wait);
 
 #ifdef PPP_WITH_TDB
 static void update_db_entry(void);
@@ -313,7 +314,7 @@ int ppp_get_ifname(char *buf, size_t bufsz)
 
 void ppp_set_ifname(const char *name)
 {
-    if (ifname) {
+    if (name) {
         strlcpy(ifname, name, sizeof(ifname));
     }
 }
@@ -799,6 +800,26 @@ setup_signals(void)
     signal(SIGPIPE, SIG_IGN);
 }
 
+/*
+ * net-* scripts to be run come through here.
+ */
+void run_net_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_ifunit - do things we need to do once we know which ppp
  * unit we are using.
@@ -820,6 +841,7 @@ set_ifunit(int iskey)
        create_pidfile(getpid());       /* write pid to file */
        create_linkpidfile(getpid());
     }
+    run_net_script(PPP_PATH_NET_INIT, 1);
 }
 
 /*
@@ -888,7 +910,7 @@ create_pidfile(int pid)
 {
     FILE *pidfile;
 
-    slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid",
+    slprintf(pidfilename, sizeof(pidfilename), "%s/%s.pid",
             PPP_PATH_VARRUN, ifname);
     if ((pidfile = fopen(pidfilename, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
@@ -907,7 +929,7 @@ create_linkpidfile(int pid)
     if (linkname[0] == 0)
        return;
     ppp_script_setenv("LINKNAME", linkname, 1);
-    slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid",
+    slprintf(linkpidfile, sizeof(linkpidfile), "%s/ppp-%s.pid",
             PPP_PATH_VARRUN, linkname);
     if ((pidfile = fopen(linkpidfile, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
@@ -1222,6 +1244,23 @@ ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp)
 void
 new_phase(ppp_phase_t p)
 {
+    switch (p) {
+    case PHASE_NETWORK:
+       if (phase <= PHASE_NETWORK) {
+           char iftmpname[IFNAMSIZ];
+           int ifindex = if_nametoindex(ifname);
+           run_net_script(PPP_PATH_NET_PREUP, 1);
+           if (if_indextoname(ifindex, iftmpname) && strcmp(iftmpname, ifname)) {
+               info("Detected interface name change from %s to %s.", ifname, iftmpname);
+               strcpy(ifname, iftmpname);
+           }
+       }
+       break;
+    case PHASE_DISCONNECT:
+       run_net_script(PPP_PATH_NET_DOWN, 0);
+       break;
+    }
+
     phase = p;
     if (new_phase_hook)
        (*new_phase_hook)(p);
@@ -2038,8 +2077,10 @@ struct notifier **get_notifier_by_type(ppp_notify_t type)
         [NF_SIGNALED    ] = &sigreceived,
         [NF_IP_UP       ] = &ip_up_notifier,
         [NF_IP_DOWN     ] = &ip_down_notifier,
+#ifdef PPP_WITH_IPV6CP
         [NF_IPV6_UP     ] = &ipv6_up_notifier,
         [NF_IPV6_DOWN   ] = &ipv6_down_notifier,
+#endif
         [NF_AUTH_UP     ] = &auth_up_notifier,
         [NF_LINK_DOWN   ] = &link_down_notifier,
         [NF_FORK        ] = &fork_notifier,
@@ -2109,7 +2150,7 @@ notify(struct notifier *notif, int val)
  * novm - log an error message saying we ran out of memory, and die.
  */
 void
-novm(char *msg)
+novm(const char *msg)
 {
     fatal("Virtual memory exhausted allocating %s\n", msg);
 }