From: Paul Mackerras Date: Sat, 23 Jun 2018 10:16:25 +0000 (+1000) Subject: Merge branch 'pppoe-discovery-cleanup' of https://github.com/TDT-AG/ppp X-Git-Tag: ppp-2.4.8~31 X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=5c765a67fd25f9d84e71ed61ace37c8c97f6be15;hp=70a8ad3dbd8af3b52d624550fc3343d1849c3f76 Merge branch 'pppoe-discovery-cleanup' of https://github.com/TDT-AG/ppp Signed-off-by: Paul Mackerras --- diff --git a/chat/Makefile.linux b/chat/Makefile.linux index 1065ac5..0732ec8 100644 --- a/chat/Makefile.linux +++ b/chat/Makefile.linux @@ -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 diff --git a/pppd/Makefile.linux b/pppd/Makefile.linux index a74c914..8d5ce99 100644 --- a/pppd/Makefile.linux +++ b/pppd/Makefile.linux @@ -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) diff --git a/pppd/auth.c b/pppd/auth.c index 4271af6..7457eda 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -100,6 +100,10 @@ #endif #include +#ifdef SYSTEMD +#include +#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; } diff --git a/pppd/main.c b/pppd/main.c index 76b67d2..e09b6ff 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -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); } } diff --git a/pppd/options.c b/pppd/options.c index 177488c..5db580a 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -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; } diff --git a/pppd/plugins/Makefile.linux b/pppd/plugins/Makefile.linux index 8a90e39..af53843 100644 --- a/pppd/plugins/Makefile.linux +++ b/pppd/plugins/Makefile.linux @@ -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) diff --git a/pppd/plugins/pppoatm/Makefile.linux b/pppd/plugins/pppoatm/Makefile.linux index 20f62e6..59dde0e 100644 --- a/pppd/plugins/pppoatm/Makefile.linux +++ b/pppd/plugins/pppoatm/Makefile.linux @@ -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) diff --git a/pppd/plugins/pppol2tp/Makefile.linux b/pppd/plugins/pppol2tp/Makefile.linux index ea3538e..7981a95 100644 --- a/pppd/plugins/pppol2tp/Makefile.linux +++ b/pppd/plugins/pppol2tp/Makefile.linux @@ -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) diff --git a/pppd/plugins/radius/Makefile.linux b/pppd/plugins/radius/Makefile.linux index 24ed3e5..e702263 100644 --- a/pppd/plugins/radius/Makefile.linux +++ b/pppd/plugins/radius/Makefile.linux @@ -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 diff --git a/pppd/plugins/radius/radius.c b/pppd/plugins/radius/radius.c index 4ba5f52..fbf8720 100644 --- a/pppd/plugins/radius/radius.c +++ b/pppd/plugins/radius/radius.c @@ -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); diff --git a/pppd/plugins/rp-pppoe/Makefile.linux b/pppd/plugins/rp-pppoe/Makefile.linux index 5d7a271..9803aeb 100644 --- a/pppd/plugins/rp-pppoe/Makefile.linux +++ b/pppd/plugins/rp-pppoe/Makefile.linux @@ -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) diff --git a/pppd/pppcrypt.c b/pppd/pppcrypt.c index 8b85b13..6b35375 100644 --- a/pppd/pppcrypt.c +++ b/pppd/pppcrypt.c @@ -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); } diff --git a/pppd/pppd.8 b/pppd/pppd.8 index 06e945f..76a2097 100644 --- a/pppd/pppd.8 +++ b/pppd/pppd.8 @@ -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 diff --git a/pppd/pppd.h b/pppd/pppd.h index 1a1bf0b..6e3743f 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -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 */ diff --git a/pppdump/Makefile.linux b/pppdump/Makefile.linux index ac028f6..cdf7ac4 100644 --- a/pppdump/Makefile.linux +++ b/pppdump/Makefile.linux @@ -10,7 +10,7 @@ INSTALL= install all: pppdump pppdump: $(OBJS) - $(CC) -o pppdump $(OBJS) + $(CC) $(LDFLAGS) -o pppdump $(OBJS) clean: rm -f pppdump $(OBJS) *~ diff --git a/pppstats/Makefile.linux b/pppstats/Makefile.linux index cca6f0f..71afbe6 100644 --- a/pppstats/Makefile.linux +++ b/pppstats/Makefile.linux @@ -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