]> git.ozlabs.org Git - ppp.git/commitdiff
Merge branch 'pppoe-discovery-cleanup' of https://github.com/TDT-AG/ppp
authorPaul Mackerras <paulus@ozlabs.org>
Sat, 23 Jun 2018 10:16:25 +0000 (20:16 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Sat, 23 Jun 2018 10:16:25 +0000 (20:16 +1000)
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
16 files changed:
chat/Makefile.linux
pppd/Makefile.linux
pppd/auth.c
pppd/main.c
pppd/options.c
pppd/plugins/Makefile.linux
pppd/plugins/pppoatm/Makefile.linux
pppd/plugins/pppol2tp/Makefile.linux
pppd/plugins/radius/Makefile.linux
pppd/plugins/radius/radius.c
pppd/plugins/rp-pppoe/Makefile.linux
pppd/pppcrypt.c
pppd/pppd.8
pppd/pppd.h
pppdump/Makefile.linux
pppstats/Makefile.linux

index 1065ac51957632606a777711f222887a5f6a98d8..0732ec80dc2736431b1ec9178411ff0bd9e3d100 100644 (file)
@@ -18,7 +18,7 @@ INSTALL= install
 all:   chat
 
 chat:  chat.o
-       $(CC) -o chat chat.o
+       $(CC) $(LDFLAGS) -o chat chat.o
 
 chat.o:        chat.c
        $(CC) -c $(CFLAGS) -o chat.o chat.c
index a74c914fd3acf84dbcaac360e6f5cabd3582f802..8d5ce99d92202c4326730393c0d9e56d327fbefe 100644 (file)
@@ -35,10 +35,10 @@ endif
 COPTS = -O2 -pipe -Wall -g
 LIBS =
 
-# Uncomment the next 2 lines to include support for Microsoft's
+# Uncomment the next line to include support for Microsoft's
 # MS-CHAP authentication protocol.  Also, edit plugins/radius/Makefile.linux.
 CHAPMS=y
-USE_CRYPT=y
+#USE_CRYPT=y
 # Don't use MSLANMAN unless you really know what you're doing.
 #MSLANMAN=y
 # Uncomment the next line to include support for MPPE.  CHAPMS (above) must
@@ -60,6 +60,11 @@ HAVE_MULTILINK=y
 # Linux distributions: Please leave TDB ENABLED in your builds.
 USE_TDB=y
 
+# Uncomment the next line to enable Type=notify services in systemd
+# If enabled, and the user sets the up_sdnotify option, then
+# pppd will not detach and will notify systemd when up.
+#SYSTEMD=y
+
 HAS_SHADOW=y
 #USE_PAM=y
 HAVE_INET6=y
@@ -132,7 +137,8 @@ endif
 
 ifdef NEEDDES
 ifndef USE_CRYPT
-LIBS     += -ldes $(LIBS)
+CFLAGS   += -I/usr/include/openssl
+LIBS     += -lcrypto
 else
 CFLAGS   += -DUSE_CRYPT=1
 endif
@@ -170,9 +176,14 @@ LIBS     += -llock
 CFLAGS   += -DLOCKLIB=1
 endif
 
+ifdef SYSTEMD
+LIBS += -lsystemd
+CFLAGS   += -DSYSTEMD=1
+endif
+
 ifdef PLUGIN
 CFLAGS += -DPLUGIN
-LDFLAGS        += -Wl,-E
+LDFLAGS_PLUGIN += -Wl,-E
 LIBS   += -ldl
 endif
 
@@ -214,7 +225,7 @@ install: pppd
        $(INSTALL) -c -m 444 pppd.8 $(MANDIR)
 
 pppd: $(PPPDOBJS)
-       $(CC) $(CFLAGS) $(LDFLAGS) -o pppd $(PPPDOBJS) $(LIBS)
+       $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_PLUGIN) -o pppd $(PPPDOBJS) $(LIBS)
 
 srp-entry:     srp-entry.c
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ srp-entry.c $(LIBS)
index 4271af687102dc62e3c2e3b47d3fc8ab1d70d0f8..7457eda227bf19c2d09b79dd4e0b031da6bc1bf9 100644 (file)
 #endif
 #include <time.h>
 
+#ifdef SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "pppd.h"
 #include "fsm.h"
 #include "lcp.h"
@@ -1099,8 +1103,15 @@ np_up(unit, proto)
        /*
         * Detach now, if the updetach option was given.
         */
-       if (updetach && !nodetach)
+       if (updetach && !nodetach) {
+           dbglog("updetach is set. Now detaching.");
            detach();
+#ifdef SYSTEMD
+       } else if (nodetach && up_sdnotify) {
+           dbglog("up_sdnotify is set. Now notifying systemd: READY=1");
+           sd_notify(0, "READY=1");
+#endif
+       }
     }
     ++num_np_up;
 }
index 76b67d2485b71ce4dc11c6a9cd7ecfd2293f21d9..e09b6ffcce32bd06389d91da6276f24c1e009007 100644 (file)
@@ -1751,7 +1751,7 @@ update_script_environment()
                script_env[i] = newstring;
            else
                add_script_env(i, newstring);
-       } else {
+       } else if (p != NULL) {
            remove_script_env(i);
        }
     }
index 177488ca681392c3971e432642c7e97a0638a894..5db580a0e270c0628fb99d1400423599a1f0ce5e 100644 (file)
@@ -97,6 +97,9 @@ char  devnam[MAXPATHLEN];     /* Device name */
 bool   nodetach = 0;           /* Don't detach from controlling tty */
 bool   updetach = 0;           /* Detach once link is up */
 bool   master_detach;          /* Detach when we're (only) multilink master */
+#ifdef SYSTEMD
+bool   up_sdnotify = 0;        /* Notify systemd once link is up */
+#endif
 int    maxconnect = 0;         /* Maximum connect time */
 char   user[MAXNAMELEN];       /* Username for PAP */
 char   passwd[MAXSECRETLEN];   /* Password for PAP */
@@ -209,6 +212,11 @@ option_t general_options[] = {
       "Don't detach from controlling tty", OPT_PRIO | 1 },
     { "-detach", o_bool, &nodetach,
       "Don't detach from controlling tty", OPT_ALIAS | OPT_PRIOSUB | 1 },
+#ifdef SYSTEMD
+    { "up_sdnotify", o_bool, &up_sdnotify,
+      "Notify systemd once link is up (implies nodetach)",
+      OPT_PRIOSUB | OPT_A2COPY | 1, &nodetach },
+#endif
     { "updetach", o_bool, &updetach,
       "Detach from controlling tty once link is up",
       OPT_PRIOSUB | OPT_A2CLR | 1, &nodetach },
@@ -984,7 +992,7 @@ print_option(opt, mainopt, printer, arg)
                        p = (char *) opt->addr2;
                        if ((opt->flags & OPT_STATIC) == 0)
                                p = *(char **)p;
-                       printer("%q", p);
+                       printer(arg, "%q", p);
                } else if (opt->flags & OPT_A2LIST) {
                        struct option_value *ovp;
 
@@ -1745,7 +1753,7 @@ user_unsetenv(argv)
        option_error("unexpected = in name: %s", arg);
        return 0;
     }
-    if (arg == '\0') {
+    if (*arg == '\0') {
        option_error("missing variable name for unset");
        return 0;
     }
index 8a90e393a0578fd4885bfda0fabfd688735eeaf5..af5384381cb07c27fa4043824f80b6ab69807fa9 100644 (file)
@@ -1,7 +1,7 @@
 #CC    = gcc
 COPTS  = -O2 -g
 CFLAGS = $(COPTS) -I.. -I../../include -fPIC
-LDFLAGS        = -shared
+LDFLAGS_SHARED = -shared
 INSTALL        = install
 
 DESTDIR = $(INSTROOT)@DESTDIR@
@@ -30,7 +30,7 @@ all:  $(PLUGINS)
        for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d all || exit $$?; done
 
 %.so: %.c
-       $(CC) -o $@ $(LDFLAGS) $(CFLAGS) $^
+       $(CC) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) $(CFLAGS) $^
 
 VERSION = $(shell awk -F '"' '/VERSION/ { print $$2; }' ../patchlevel.h)
 
index 20f62e631d23c18361ce3164c2fbe2179d0abe90..59dde0e1643266230057fbbb82eaa5e986d03d05 100644 (file)
@@ -1,7 +1,7 @@
 #CC    = gcc
 COPTS  = -O2 -g
 CFLAGS = $(COPTS) -I../.. -I../../../include -fPIC
-LDFLAGS        = -shared
+LDFLAGS_SHARED = -shared
 INSTALL        = install
 
 #***********************************************************************
@@ -33,7 +33,7 @@ endif
 all: $(PLUGIN)
 
 $(PLUGIN): $(PLUGIN_OBJS)
-       $(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $^ $(LIBS)
 
 install: all
        $(INSTALL) -d -m 755 $(LIBDIR)
index ea3538e22d56a9299614d64094fbdb43a2eab004..7981a9549a4ad5f40d2a686dd909d6f976ace5b8 100644 (file)
@@ -1,7 +1,7 @@
 #CC    = gcc
 COPTS  = -O2 -g
 CFLAGS = $(COPTS) -I. -I../.. -I../../../include -fPIC
-LDFLAGS        = -shared
+LDFLAGS_SHARED = -shared
 INSTALL        = install
 
 #***********************************************************************
@@ -16,7 +16,7 @@ PLUGINS := pppol2tp.so openl2tp.so
 all: $(PLUGINS)
 
 %.so: %.o
-       $(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $^ $(LIBS)
 
 install: all
        $(INSTALL) -d -m 755 $(LIBDIR)
index 24ed3e580c4db6aeca129dd22dbe6de5f2d1ff5f..e7022636906d8219d75165fda6ffccda695c9fe0 100644 (file)
@@ -43,13 +43,13 @@ install: all
        $(INSTALL) -c -m 444 pppd-radattr.8 $(MANDIR)
 
 radius.so: radius.o libradiusclient.a
-       $(CC) -o radius.so -shared radius.o libradiusclient.a
+       $(CC) $(LDFLAGS) -o radius.so -shared radius.o libradiusclient.a
 
 radattr.so: radattr.o
-       $(CC) -o radattr.so -shared radattr.o
+       $(CC) $(LDFLAGS) -o radattr.so -shared radattr.o
 
 radrealms.so: radrealms.o
-       $(CC) -o radrealms.so -shared radrealms.o
+       $(CC) $(LDFLAGS) -o radrealms.so -shared radrealms.o
 
 CLIENTOBJS = avpair.o buildreq.o config.o dict.o ip_util.o \
        clientid.o sendserver.o lock.o util.o md5.o
index 4ba5f523ea0748af986aec1257ea9263e8fafe74..fbf872006005b59ca5472f73b1a5c1b69007bef4 100644 (file)
@@ -996,6 +996,10 @@ radius_acct_stop(void)
 
     rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE);
 
+    if (rstate.class_len > 0)
+       rc_avpair_add(&send, PW_CLASS,
+                     rstate.class, rstate.class_len, VENDOR_NONE);
+
     av_type = PW_STATUS_STOP;
     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
 
@@ -1140,6 +1144,10 @@ radius_acct_interim(void *ignored)
 
     rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE);
 
+    if (rstate.class_len > 0)
+       rc_avpair_add(&send, PW_CLASS,
+                     rstate.class, rstate.class_len, VENDOR_NONE);
+
     av_type = PW_STATUS_ALIVE;
     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
 
index 5d7a2719545d2e52f4f9b62ea51dff2697b736d6..9803aeb4ebbae07bb7d8a527f942b753eb5b404e 100644 (file)
@@ -30,7 +30,7 @@ CFLAGS=$(COPTS) -I../../../include '-DRP_VERSION="$(RP_VERSION)"'
 all: rp-pppoe.so pppoe-discovery
 
 pppoe-discovery: pppoe-discovery.o debug.o
-       $(CC) -o pppoe-discovery pppoe-discovery.o debug.o
+       $(CC) $(LDFLAGS) -o pppoe-discovery pppoe-discovery.o debug.o
 
 pppoe-discovery.o: pppoe-discovery.c
        $(CC) $(CFLAGS) -c -o pppoe-discovery.o pppoe-discovery.c
@@ -39,7 +39,7 @@ debug.o: debug.c
        $(CC) $(CFLAGS) -c -o debug.o debug.c
 
 rp-pppoe.so: plugin.o discovery.o if.o common.o
-       $(CC) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
+       $(CC) $(LDFLAGS) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
 
 install: all
        $(INSTALL) -d -m 755 $(LIBDIR)
index 8b85b13276ab30fd51a9ab7ad5352f605453acdb..6b35375edc5e4b1a02485c9630140b32b7de52b7 100644 (file)
@@ -64,7 +64,7 @@ u_char *des_key;      /* OUT 64 bit DES key with parity bits added */
        des_key[7] = Get7Bits(key, 49);
 
 #ifndef USE_CRYPT
-       des_set_odd_parity((des_cblock *)des_key);
+       DES_set_odd_parity((DES_cblock *)des_key);
 #endif
 }
 
@@ -158,25 +158,25 @@ u_char *clear;    /* OUT 8 octets */
 }
 
 #else /* USE_CRYPT */
-static des_key_schedule        key_schedule;
+static DES_key_schedule        key_schedule;
 
 bool
 DesSetkey(key)
 u_char *key;
 {
-       des_cblock des_key;
+       DES_cblock des_key;
        MakeKey(key, des_key);
-       des_set_key(&des_key, key_schedule);
+       DES_set_key(&des_key, &key_schedule);
        return (1);
 }
 
 bool
-DesEncrypt(clear, key, cipher)
+DesEncrypt(clear, cipher)
 u_char *clear; /* IN  8 octets */
 u_char *cipher;        /* OUT 8 octets */
 {
-       des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher,
-           key_schedule, 1);
+       DES_ecb_encrypt((DES_cblock *)clear, (DES_cblock *)cipher,
+           &key_schedule, 1);
        return (1);
 }
 
@@ -185,8 +185,8 @@ DesDecrypt(cipher, clear)
 u_char *cipher;        /* IN  8 octets */
 u_char *clear; /* OUT 8 octets */
 {
-       des_ecb_encrypt((des_cblock *)cipher, (des_cblock *)clear,
-           key_schedule, 0);
+       DES_ecb_encrypt((DES_cblock *)cipher, (DES_cblock *)clear,
+           &key_schedule, 0);
        return (1);
 }
 
index 06e945fce998080090da52837d1d3b69306c19a7..76a209766f2afc89b8e43187d87c05271f740ae5 100644 (file)
@@ -1100,6 +1100,15 @@ it has successfully established the ppp connection (to the point where
 the first network control protocol, usually the IP control protocol,
 has come up).
 .TP
+.B up_sdnotify
+Use this option to run pppd in systemd service units of Type=notify
+(\fBup_sdnotify\fR implies \fBnodetach\fR).
+When \fBup_sdnotify\fR is enabled, pppd will notify systemd once
+it has successfully established the ppp connection (to the point where
+the first network control protocl, usually the IP control protocol,
+has come up). This option is only availble when pppd is compiled with
+systemd support.
+.TP
 .B usehostname
 Enforce the use of the hostname (with domain name appended, if given)
 as the name of the local system for authentication purposes (overrides
index 1a1bf0b99582fa323cb0ee587d79c248642a7896..6e3743fd9c97de74caf9638e717aa60525bebabb 100644 (file)
@@ -295,6 +295,9 @@ extern int  inspeed;        /* Input/Output speed requested */
 extern u_int32_t netmask;      /* IP netmask to set on interface */
 extern bool    lockflag;       /* Create lock file to lock the serial dev */
 extern bool    nodetach;       /* Don't detach from controlling tty */
+#ifdef SYSTEMD
+extern bool    up_sdnotify;    /* Notify systemd once link is up (implies nodetach) */
+#endif
 extern bool    updetach;       /* Detach from controlling tty when link up */
 extern bool    master_detach;  /* Detach when multilink master without link */
 extern char    *initializer;   /* Script to initialize physical link */
index ac028f6bf4f0d121f38ff1519ee2632c1a663df8..cdf7ac4341fb4859d105970bf53ff208cd06f7cd 100644 (file)
@@ -10,7 +10,7 @@ INSTALL= install
 all:   pppdump
 
 pppdump: $(OBJS)
-       $(CC) -o pppdump $(OBJS)
+       $(CC) $(LDFLAGS) -o pppdump $(OBJS)
 
 clean:
        rm -f pppdump $(OBJS) *~
index cca6f0f61d87f70016e903dbad7821dc87473249..71afbe67eff4916bfd70bb4ba9bf01b8d1c3d374 100644 (file)
@@ -26,7 +26,7 @@ install: pppstats
        $(INSTALL) -c -m 444 pppstats.8 $(MANDIR)
 
 pppstats: $(PPPSTATSRCS)
-       $(CC) $(CFLAGS) -o pppstats pppstats.c $(LIBS)
+       $(CC) $(CFLAGS) $(LDFLAGS) -o pppstats pppstats.c $(LIBS)
 
 clean:
        rm -f pppstats *~ #* core