Initial commit
Some checks failed
Build Kernel / Build all affected Kernels (push) Has been cancelled
Build all core packages / Build all core packages for selected target (push) Has been cancelled
Build and Push prebuilt tools container / Build and Push all prebuilt containers (push) Has been cancelled
Build Toolchains / Build Toolchains for each target (push) Has been cancelled
Build host tools / Build host tools for linux and macos based systems (push) Has been cancelled
Coverity scan build / Coverity x86/64 build (push) Has been cancelled

This commit is contained in:
domenico
2025-06-24 14:35:53 +02:00
commit c06fb25d1f
9263 changed files with 1750214 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
From: Shiji Yang <yangshiji66@outlook.com>
Date: Fri, 4 Oct 2024 12:19:42 +0000
Subject: [PATCH] pppd/crypto: fix build without openssl
Compile openssl relevant code only when PPP_WITH_OPENSSL is defined.
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
---
pppd/crypto.c | 4 ++++
1 file changed, 4 insertions(+)
--- a/pppd/crypto.c
+++ b/pppd/crypto.c
@@ -199,6 +199,7 @@ int PPP_crypto_init()
{
int retval = 0;
+#ifdef PPP_WITH_OPENSSL
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
g_crypto_ctx.legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (g_crypto_ctx.legacy == NULL)
@@ -214,6 +215,7 @@ int PPP_crypto_init()
goto done;
}
#endif
+#endif
retval = 1;
@@ -224,6 +226,7 @@ done:
int PPP_crypto_deinit()
{
+#ifdef PPP_WITH_OPENSSL
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
if (g_crypto_ctx.legacy) {
OSSL_PROVIDER_unload(g_crypto_ctx.legacy);
@@ -239,6 +242,7 @@ int PPP_crypto_deinit()
#if OPENSSL_VERSION_NUMBER < 0x10100000L
ERR_free_strings();
#endif
+#endif
return 1;
}

View File

@@ -0,0 +1,27 @@
From: Shiji Yang <yangshiji66@outlook.com>
Date: Fri, 4 Oct 2024 14:02:14 +0000
Subject: [PATCH] pppd: make pid directory before create the pid file
If multilink feature is not enabled, the '/var/run/pppd' directory
won't be created before adding pid file.
Fixes error message:
'Failed to create pid file /var/run/pppd/pppoe-wan.pid: No such file or directory'
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
---
pppd/main.c | 3 +++
1 file changed, 3 insertions(+)
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -921,6 +921,9 @@ create_pidfile(int pid)
{
FILE *pidfile;
+#ifndef PPP_WITH_TDB
+ mkdir_recursive(PPP_PATH_VARRUN);
+#endif
slprintf(pidfilename, sizeof(pidfilename), "%s/%s.pid",
PPP_PATH_VARRUN, ifname);
if ((pidfile = fopen(pidfilename, "w")) != NULL) {

View File

@@ -0,0 +1,42 @@
From: Tan Zien <nabsdh9@gmail.com>
Date: Tue, 1 Oct 2024 10:38:45 +0800
Subject: [PATCH] pppd/crypto: fix gcc 14 build
fix this:
crypto.c: In function 'PPP_crypto_error':
crypto.c:178:11: error: implicit declaration of function 'vsnprintf' [-Wimplicit-function-declaration]
178 | off = vsnprintf(buf, len, fmt, args);
| ^~~~~~~~~
crypto.c:41:1: note: include '<stdio.h>' or provide a declaration of 'vsnprintf'
40 | #include "crypto-priv.h"
+++ |+#include <stdio.h>
41 |
crypto.c:178:26: warning: 'vsnprintf' argument 2 type is 'int' where 'long unsigned int' is expected in a call to built-in function declared without prototype [-Wbuiltin-declaration-mismatch]
178 | off = vsnprintf(buf, len, fmt, args);
| ^~~
<built-in>: note: built-in 'vsnprintf' declared here
Signed-off-by: Tan Zien <nabsdh9@gmail.com>
---
pppd/crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/pppd/crypto.c
+++ b/pppd/crypto.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "pppd.h"
#include "crypto.h"
@@ -247,7 +248,6 @@ int PPP_crypto_deinit()
}
#ifdef UNIT_TEST
-#include <stdio.h>
int debug;
int error_count;

View File

@@ -0,0 +1,170 @@
--- a/pppd/demand.c
+++ b/pppd/demand.c
@@ -40,6 +40,8 @@
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
+#include <unistd.h>
+#include <syslog.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -47,6 +49,8 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#ifdef PPP_WITH_FILTER
#include <pcap-bpf.h>
#endif
@@ -223,6 +227,14 @@ loop_chars(unsigned char *p, int n)
int c, rv;
rv = 0;
+
+/* check for synchronous connection... */
+
+ if ( (p[0] == 0xFF) && (p[1] == 0x03) ) {
+ rv = loop_frame(p,n);
+ return rv;
+ }
+
for (; n > 0; --n) {
c = *p++;
if (c == PPP_FLAG) {
@@ -299,16 +311,100 @@ loop_frame(unsigned char *frame, int len
* loopback, now that the real serial link is up.
*/
void
-demand_rexmit(int proto)
+demand_rexmit(int proto, u_int32_t newip)
{
struct packet *pkt, *prev, *nextpkt;
+ unsigned short checksum;
+ unsigned short pkt_checksum = 0;
+ unsigned iphdr;
+ struct timeval tv;
+ char cv = 0;
+ char ipstr[16];
prev = NULL;
pkt = pend_q;
pend_q = NULL;
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ select(0,NULL,NULL,NULL,&tv); /* Sleep for 1 Seconds */
for (; pkt != NULL; pkt = nextpkt) {
nextpkt = pkt->next;
if (PPP_PROTOCOL(pkt->data) == proto) {
+ if ( (proto == PPP_IP) && newip ) {
+ /* Get old checksum */
+
+ iphdr = (pkt->data[4] & 15) << 2;
+ checksum = *((unsigned short *) (pkt->data+14));
+ if (checksum == 0xFFFF) {
+ checksum = 0;
+ }
+
+
+ if (pkt->data[13] == 17) {
+ pkt_checksum = *((unsigned short *) (pkt->data+10+iphdr));
+ if (pkt_checksum) {
+ cv = 1;
+ if (pkt_checksum == 0xFFFF) {
+ pkt_checksum = 0;
+ }
+ }
+ else {
+ cv = 0;
+ }
+ }
+
+ if (pkt->data[13] == 6) {
+ pkt_checksum = *((unsigned short *) (pkt->data+20+iphdr));
+ cv = 1;
+ if (pkt_checksum == 0xFFFF) {
+ pkt_checksum = 0;
+ }
+ }
+
+ /* Delete old Source-IP-Address */
+ checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
+ checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
+
+ pkt_checksum -= *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
+ pkt_checksum -= *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
+
+ /* Change Source-IP-Address */
+ * ((u_int32_t *) (pkt->data + 16)) = newip;
+
+ /* Add new Source-IP-Address */
+ checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
+ checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
+
+ pkt_checksum += *((unsigned short *) (pkt->data+16)) ^ 0xFFFF;
+ pkt_checksum += *((unsigned short *) (pkt->data+18)) ^ 0xFFFF;
+
+ /* Write new checksum */
+ if (!checksum) {
+ checksum = 0xFFFF;
+ }
+ *((unsigned short *) (pkt->data+14)) = checksum;
+ if (pkt->data[13] == 6) {
+ *((unsigned short *) (pkt->data+20+iphdr)) = pkt_checksum;
+ }
+ if (cv && (pkt->data[13] == 17) ) {
+ *((unsigned short *) (pkt->data+10+iphdr)) = pkt_checksum;
+ }
+
+ /* Log Packet */
+ strcpy(ipstr,inet_ntoa(*( (struct in_addr *) (pkt->data+16))));
+ if (pkt->data[13] == 1) {
+ syslog(LOG_INFO,"Open ICMP %s -> %s\n",
+ ipstr,
+ inet_ntoa(*( (struct in_addr *) (pkt->data+20))));
+ } else {
+ syslog(LOG_INFO,"Open %s %s:%d -> %s:%d\n",
+ pkt->data[13] == 6 ? "TCP" : "UDP",
+ ipstr,
+ ntohs(*( (short *) (pkt->data+iphdr+4))),
+ inet_ntoa(*( (struct in_addr *) (pkt->data+20))),
+ ntohs(*( (short *) (pkt->data+iphdr+6))));
+ }
+ }
output(0, pkt->data, pkt->length);
free(pkt);
} else {
--- a/pppd/ipcp.c
+++ b/pppd/ipcp.c
@@ -1915,7 +1915,7 @@ ipcp_up(fsm *f)
proxy_arp_set[f->unit] = 1;
}
- demand_rexmit(PPP_IP);
+ demand_rexmit(PPP_IP,go->ouraddr);
sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
} else {
--- a/pppd/ipv6cp.c
+++ b/pppd/ipv6cp.c
@@ -1338,7 +1338,7 @@ ipv6cp_up(fsm *f)
if (sif6defaultroute(f->unit, go->ourid, ho->hisid))
default_route_set[f->unit] = 1;
}
- demand_rexmit(PPP_IPV6);
+ demand_rexmit(PPP_IPV6,0);
sifnpmode(f->unit, PPP_IPV6, NPMODE_PASS);
} else {
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -368,7 +368,7 @@ void demand_conf(void); /* config interf
void demand_block(void); /* set all NPs to queue up packets */
void demand_unblock(void); /* set all NPs to pass packets */
void demand_discard(void); /* set all NPs to discard packets */
-void demand_rexmit(int); /* retransmit saved frames for an NP */
+void demand_rexmit(int, u_int32_t); /* retransmit saved frames for an NP */
int loop_chars(unsigned char *, int); /* process chars from loopback */
int loop_frame(unsigned char *, int); /* should we bring link up? */

View File

@@ -0,0 +1,72 @@
--- a/pppd/plugins/radius/config.c
+++ b/pppd/plugins/radius/config.c
@@ -381,31 +381,37 @@ static int test_config(char *filename)
}
#endif
+#if 0
if (rc_conf_int("login_tries") <= 0)
{
error("%s: login_tries <= 0 is illegal", filename);
return (-1);
}
+#endif
if (rc_conf_str("seqfile") == NULL)
{
error("%s: seqfile not specified", filename);
return (-1);
}
+#if 0
if (rc_conf_int("login_timeout") <= 0)
{
error("%s: login_timeout <= 0 is illegal", filename);
return (-1);
}
+#endif
if (rc_conf_str("mapfile") == NULL)
{
error("%s: mapfile not specified", filename);
return (-1);
}
+#if 0
if (rc_conf_str("nologin") == NULL)
{
error("%s: nologin not specified", filename);
return (-1);
}
+#endif
return 0;
}
--- a/pppd/plugins/radius/options.h
+++ b/pppd/plugins/radius/options.h
@@ -31,24 +31,21 @@ typedef struct _option {
static SERVER acctserver = {0};
static SERVER authserver = {0};
-int default_tries = 4;
-int default_timeout = 60;
-
static OPTION config_options[] = {
/* internally used options */
{"config_file", OT_STR, ST_UNDEF, NULL},
/* General options */
{"auth_order", OT_AUO, ST_UNDEF, NULL},
-{"login_tries", OT_INT, ST_UNDEF, &default_tries},
-{"login_timeout", OT_INT, ST_UNDEF, &default_timeout},
-{"nologin", OT_STR, ST_UNDEF, "/etc/nologin"},
-{"issue", OT_STR, ST_UNDEF, "/etc/radiusclient/issue"},
+{"login_tries", OT_INT, ST_UNDEF, NULL},
+{"login_timeout", OT_INT, ST_UNDEF, NULL},
+{"nologin", OT_STR, ST_UNDEF, NULL},
+{"issue", OT_STR, ST_UNDEF, NULL},
/* RADIUS specific options */
{"authserver", OT_SRV, ST_UNDEF, &authserver},
{"acctserver", OT_SRV, ST_UNDEF, &acctserver},
{"servers", OT_STR, ST_UNDEF, NULL},
{"dictionary", OT_STR, ST_UNDEF, NULL},
-{"login_radius", OT_STR, ST_UNDEF, "/usr/sbin/login.radius"},
+{"login_radius", OT_STR, ST_UNDEF, NULL},
{"seqfile", OT_STR, ST_UNDEF, NULL},
{"mapfile", OT_STR, ST_UNDEF, NULL},
{"default_realm", OT_STR, ST_UNDEF, NULL},

View File

@@ -0,0 +1,25 @@
pppd: Cap MTU to the user configured value
This patchs caps the calculated MTU value in lcp.c to the user specified "mru"
option value. Without this patch pppd would advertise a different MTU value
compared to what is set on the local interface in some cases.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/lcp.c
+++ b/pppd/lcp.c
@@ -1888,12 +1888,12 @@ lcp_up(fsm *f)
* the interface MTU is set to the lowest of that, the
* MTU we want to use, and our link MRU.
*/
- mtu = ho->neg_mru? ho->mru: PPP_MRU;
+ mtu = MIN(ho->neg_mru? ho->mru: PPP_MRU, ao->mru);
mru = go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU;
#ifdef PPP_WITH_MULTILINK
if (!(multilink && go->neg_mrru && ho->neg_mrru))
#endif /* PPP_WITH_MULTILINK */
- ppp_set_mtu(f->unit, MIN(MIN(mtu, mru), ao->mru));
+ ppp_set_mtu(f->unit, MIN(mtu, mru));
ppp_send_config(f->unit, mtu,
(ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
ho->neg_pcompression, ho->neg_accompression);

View File

@@ -0,0 +1,24 @@
pppd: Do not clobber exit codes on hangup
When a modem hangup occurs, pppd unconditionally sets the exit status code
to EXIT_HANGUP. This patch only sets EXIT_HANGUP if the exit status code is
not already set to an error value.
The motiviation of this patch is to allow applications which remote control
pppd to react properly on errors, e.g. only redial (relaunch pppd) if there
was a hangup, but not if the CHAP authentication failed.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -1152,7 +1152,8 @@ get_input(void)
}
notice("Modem hangup");
hungup = 1;
- code = EXIT_HANGUP;
+ if (code == EXIT_OK)
+ code = EXIT_HANGUP;
lcp_lowerdown(0); /* serial link is no longer available */
link_terminated(0);
return;

View File

@@ -0,0 +1,203 @@
pppd: Implement support for precompiled pcap filters
This patch implements support for precompiled pcap filters which is useful to
support dial-on-demand on memory constrained embedded devices without having
to link the full libpcap into pppd to generate the filters during runtime.
Two new options are introduced; "precompiled-pass-filter" specifies a pre-
compiled filter file containing rules to match packets which should be passed,
"precompiled-active-filter" specifies a filter file containing rules to match
packets which are treated as active.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/configure.ac
+++ b/configure.ac
@@ -306,6 +306,9 @@ AM_CONDITIONAL(PPP_WITH_PAM, test "x${wi
# With libpcap support, activate pppd on network activity
AX_CHECK_PCAP
+# internal statically linked pcap
+AM_CONDITIONAL(PPP_WITH_PRECOMPILED_FILTER, test "x${with_static_pcap}" = "xyes")
+
#
# SunOS provides a version of libpcap that would work, but SunOS has no support for activity filter
AM_CONDITIONAL([PPP_WITH_FILTER], [ test "x${with_pcap}" = "xyes" && test "x${build_sunos}" != "xyes" ])
@@ -359,6 +362,7 @@ $PACKAGE_NAME version $PACKAGE_VERSION
With libatm..........: ${with_atm:-no}
With libpam..........: ${with_pam:-no}
With libpcap.........: ${with_pcap:-no}
+ With static libpcap..: ${with_static_pcap:-no}
With libsrp..........: ${with_srp:-no}
C Compiler...........: $CC $CFLAGS
Linker...............: $LD $LDFLAGS $LIBS
--- a/pppd/Makefile.am
+++ b/pppd/Makefile.am
@@ -138,6 +138,12 @@ pppd_LDFLAGS += $(PCAP_LDFLAGS)
pppd_LIBS += $(PCAP_LIBS)
endif
+if PPP_WITH_PRECOMPILED_FILTER
+pppd_SOURCES += pcap_pcc.c
+pppd_include_HEADERS += pcap_pcc.h
+pppd_LIBS += $(STAGING_DIR)/usr/lib/libpcap.a
+endif
+
if PPP_WITH_PLUGINS
pppd_CPPFLAGS += -DPPPD_PLUGIN_DIR='"@PPPD_PLUGIN_DIR@"'
pppd_LIBS += -ldl
--- a/pppd/options.c
+++ b/pppd/options.c
@@ -62,6 +62,7 @@
#ifdef PPP_WITH_FILTER
#include <pcap.h>
+#include <pcap-bpf.h>
/*
* There have been 3 or 4 different names for this in libpcap CVS, but
* this seems to be what they have settled on...
@@ -182,6 +183,13 @@ static int setlogfile(char **);
static int loadplugin(char **);
#endif
+#ifdef PPP_WITH_PRECOMPILED_FILTER
+#include "pcap_pcc.h"
+static int setprecompiledpassfilter(char **);
+static int setprecompiledactivefilter(char **);
+#undef PPP_WITH_FILTER
+#endif
+
#ifdef PPP_WITH_FILTER
static int setpassfilter(char **);
static int setactivefilter(char **);
@@ -391,6 +399,14 @@ struct option general_options[] = {
"set filter for active pkts", OPT_PRIO },
#endif
+#ifdef PPP_WITH_PRECOMPILED_FILTER
+ { "precompiled-pass-filter", 1, setprecompiledpassfilter,
+ "set precompiled filter for packets to pass", OPT_PRIO },
+
+ { "precompiled-active-filter", 1, setprecompiledactivefilter,
+ "set precompiled filter for active pkts", OPT_PRIO },
+#endif
+
{ "maxoctets", o_int, &maxoctets,
"Set connection traffic limit",
OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
@@ -1666,6 +1682,27 @@ callfile(char **argv)
return ok;
}
+#ifdef PPP_WITH_PRECOMPILED_FILTER
+/*
+ * setprecompiledpassfilter - Set the pass filter for packets using a
+ * precompiled expression
+ */
+static int
+setprecompiledpassfilter(char **argv)
+{
+ return pcap_pre_compiled (*argv, &pass_filter);
+}
+
+/*
+ * setactivefilter - Set the active filter for packets
+ */
+static int
+setprecompiledactivefilter(char **argv)
+{
+ return pcap_pre_compiled (*argv, &active_filter);
+}
+#endif
+
#ifdef PPP_WITH_FILTER
/*
* setpassfilter - Set the pass filter for packets
--- /dev/null
+++ b/pppd/pcap_pcc.c
@@ -0,0 +1,75 @@
+#include <pcap.h>
+#include <pcap-bpf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "options.h"
+#include "pppd.h"
+
+int pcap_pre_compiled (char * fname, struct bpf_program *p)
+{
+ char buf[128];
+ int line = 0, size = 0, index=0, ret=1;
+ FILE *f = fopen (fname, "r");
+ if (!f)
+ {
+ ppp_option_error("error opening precompiled active-filter '%s': %s",
+ fname, strerror (errno));
+ return 0;
+ }
+ while (fgets (buf, 127, f))
+ {
+ line++;
+ if (*buf == '#')
+ continue;
+ if (size)
+ {
+ /*
+ struct bpf_insn {
+ u_short code;
+ u_char jt;
+ u_char jf;
+ bpf_int32 k;
+ }
+ */
+ struct bpf_insn * insn = & p->bf_insns[index];
+ unsigned code, jt, jf, k;
+ if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4)
+ {
+ goto err;
+ }
+ insn->code = code;
+ insn->jt = jt;
+ insn->jf = jf;
+ insn->k = k;
+ index++;
+ }
+ else
+ {
+ if (sscanf (buf, "%u", &size) != 1)
+ {
+ goto err;
+ }
+ p->bf_len = size;
+ p->bf_insns = (struct bpf_insn *)
+ malloc (size * sizeof (struct bpf_insn));
+ }
+ }
+ if (size != index)
+ {
+ ppp_option_error("error in precompiled active-filter,"
+ " expected %d expressions, got %dn",
+ size, index);
+ ret = 0;
+ }
+ fclose(f);
+ return ret;
+
+err:
+ ppp_option_error("error in precompiled active-filter"
+ " expression line %s:%d (wrong size)\n",
+ fname, line);
+ fclose (f);
+ return 0;
+}
--- /dev/null
+++ b/pppd/pcap_pcc.h
@@ -0,0 +1,7 @@
+#ifndef PCAP_PCC_H
+#define PCAP_PCC_H
+
+#include <pcap.h>
+
+int pcap_pre_compiled (char * fname, struct bpf_program *p);
+#endif /* PCAP_PCC_H */

View File

@@ -0,0 +1,147 @@
From: George Kashperko <george@znau.edu.ua>
Make mlppp support more generic interface naming other than pppX
Signed-off-by: George Kashperko <george@znau.edu.ua>
---
pppd/multilink.c | 55 +++++++++++++++++++++++++++++++++------------
pppd/sys-linux.c | 12 +++++++++
2 files changed, 53 insertions(+), 14 deletions(-)
--- a/pppd/multilink.c
+++ b/pppd/multilink.c
@@ -40,6 +40,7 @@
#include <signal.h>
#include <netinet/in.h>
#include <unistd.h>
+#include <net/if.h>
#include "pppd-private.h"
#include "fsm.h"
@@ -62,7 +63,8 @@ static void iterate_bundle_links(void (*
static int get_default_epdisc(struct epdisc *);
static int parse_num(char *str, const char *key, int *valp);
-static int owns_unit(TDB_DATA pid, int unit);
+static int parse_str(char *str, const char *key, char *buf, int buflen);
+static int owns_link(TDB_DATA pid, char *ifname);
#define set_ip_epdisc(ep, addr) do { \
ep->length = 4; \
@@ -215,35 +217,38 @@ mp_join_bundle(void)
key.dptr = bundle_id;
key.dsize = p - bundle_id;
pid = tdb_fetch(pppdb, key);
+
if (pid.dptr != NULL) {
+ char tmp[IFNAMSIZ];
+
/* bundle ID exists, see if the pppd record exists */
rec = tdb_fetch(pppdb, pid);
+
if (rec.dptr != NULL && rec.dsize > 0) {
/* make sure the string is null-terminated */
rec.dptr[rec.dsize-1] = 0;
- /* parse the interface number */
- parse_num(rec.dptr, "UNIT=", &unit);
+
/* check the pid value */
if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid)
+ || !parse_str(rec.dptr, "IFNAME=", tmp, sizeof(tmp))
+ || !parse_num(rec.dptr, "IFUNIT=", &unit)
|| !process_exists(pppd_pid)
- || !owns_unit(pid, unit))
+ || !owns_link(pid, tmp))
unit = -1;
free(rec.dptr);
}
free(pid.dptr);
- }
- if (unit >= 0) {
/* attach to existing unit */
- if (bundle_attach(unit)) {
+ if (unit >= 0 && bundle_attach(unit)) {
set_ifunit(0);
ppp_script_setenv("BUNDLE", bundle_id + 7, 0);
make_bundle_links(1);
unlock_db();
- info("Link attached to %s", ifname);
+ info("Link attached to %s", tmp);
return 1;
+ /* attach failed because bundle doesn't exist */
}
- /* attach failed because bundle doesn't exist */
}
/* we have to make a new bundle */
@@ -423,20 +428,39 @@ parse_num(char *str, const char *key, in
return 0;
}
+static int
+parse_str(char *str, const char *key, char *buf, int buflen)
+{
+ char *p, *endp;
+ int i;
+
+ p = strstr(str, key);
+ if (p) {
+ p += strlen(key);
+ while (--buflen && *p != 0 && *p != ';')
+ *(buf++) = *(p++);
+ *buf = 0;
+ return 1;
+ }
+ return 0;
+}
+
/*
- * Check whether the pppd identified by `key' still owns ppp unit `unit'.
+ * Check whether the pppd identified by `key' still owns ppp link `ifname'.
*/
static int
-owns_unit(TDB_DATA key, int unit)
+owns_link(TDB_DATA key, char *ifname)
{
- char ifkey[32];
+ char ifkey[7 + IFNAMSIZ];
TDB_DATA kd, vd;
int ret = 0;
- slprintf(ifkey, sizeof(ifkey), "UNIT=%d", unit);
+ slprintf(ifkey, sizeof(ifkey), "IFNAME=%s", ifname);
+
kd.dptr = ifkey;
kd.dsize = strlen(ifkey);
vd = tdb_fetch(pppdb, kd);
+
if (vd.dptr != NULL) {
ret = vd.dsize == key.dsize
&& memcmp(vd.dptr, key.dptr, vd.dsize) == 0;
--- a/pppd/sys-linux.c
+++ b/pppd/sys-linux.c
@@ -984,6 +984,16 @@ void cfg_bundle(int mrru, int mtru, int
add_fd(ppp_dev_fd);
}
+static void
+setenv_ifunit(void)
+{
+#ifdef USE_TDB
+ char tmp[11];
+ slprintf(tmp, sizeof(tmp), "%d", ifunit);
+ ppp_script_setenv("IFUNIT", tmp, 0);
+#endif
+}
+
/*
* make_new_bundle - create a new PPP unit (i.e. a bundle)
* and connect our channel to it. This should only get called
@@ -1002,6 +1012,8 @@ void make_new_bundle(int mrru, int mtru,
/* set the mrru and flags */
cfg_bundle(mrru, mtru, rssn, tssn);
+
+ setenv_ifunit();
}
/*

View File

@@ -0,0 +1,34 @@
pppd: Fill in default gateway on Linux
On Linux, when pppd creates the default route, it does not set the peer
address as gateway, leading to a default route without gateway address.
This behaviour breaks various downstream programs which attempt to infer
the default gateway IP address from the system default route entry.
This patch addresses the issue by filling in the peer address as gateway
when generating the default route entry.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/sys-linux.c
+++ b/pppd/sys-linux.c
@@ -2251,6 +2251,9 @@ int sifdefaultroute (int unit, u_int32_t
memset (&rt, 0, sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
+ SET_SA_FAMILY(rt.rt_gateway, AF_INET);
+ SIN_ADDR(rt.rt_gateway) = gateway;
+
rt.rt_dev = ifname;
rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */
@@ -2259,7 +2262,7 @@ int sifdefaultroute (int unit, u_int32_t
SIN_ADDR(rt.rt_genmask) = 0L;
}
- rt.rt_flags = RTF_UP;
+ rt.rt_flags = RTF_UP | RTF_GATEWAY;
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
if ( ! ok_error ( errno ))
error("default route ioctl(SIOCADDRT): %m");

View File

@@ -0,0 +1,160 @@
pppd: Remove runtime kernel checks
On embedded system distributions the required kernel features for pppd are
more or less guaranteed to be present, so there is not much point in
performing runtime checks, it just increases the binary size.
This patch removes the runtime kernel feature checks.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/sys-linux.c
+++ b/pppd/sys-linux.c
@@ -224,14 +224,10 @@ static fd_set in_fds; /* set of fds tha
static int max_in_fd; /* highest fd set in in_fds */
static int has_proxy_arp = 0;
-static int driver_version = 0;
-static int driver_modification = 0;
-static int driver_patch = 0;
-static int driver_is_old = 0;
static int restore_term = 0; /* 1 => we've munged the terminal */
static struct termios inittermios; /* Initial TTY termios */
-int new_style_driver = 0;
+static const int new_style_driver = 1;
static char loop_name[20];
static unsigned char inbuf[512]; /* buffer for chars read from loopback */
@@ -249,9 +245,8 @@ static int dynaddr_set; /* 1 if ip_dyna
static int looped; /* 1 if using loop */
static int link_mtu; /* mtu for the link (not bundle) */
-static struct utsname utsname; /* for the kernel version */
-static int kernel_version;
#define KVERSION(j,n,p) ((j)*1000000 + (n)*1000 + (p))
+static const int kernel_version = KVERSION(4,9,0);
#define MAX_IFS 100
@@ -1970,11 +1965,12 @@ int ccp_fatal_error (int unit)
*
* path_to_procfs - find the path to the proc file system mount point
*/
-static char proc_path[MAXPATHLEN];
-static int proc_path_len;
+static char proc_path[MAXPATHLEN] = "/proc";
+static int proc_path_len = 5;
static char *path_to_procfs(const char *tail)
{
+#if 0
struct mntent *mntent;
FILE *fp;
@@ -1996,6 +1992,7 @@ static char *path_to_procfs(const char *
fclose (fp);
}
}
+#endif
strlcpy(proc_path + proc_path_len, tail,
sizeof(proc_path) - proc_path_len);
@@ -2889,6 +2886,8 @@ ppp_registered(void)
int ppp_check_kernel_support(void)
{
+ return 1; /* OpenWrt support ppp device "/dev/ppp" by default */
+#if 0
int s, ok, fd;
struct ifreq ifr;
int size;
@@ -3016,6 +3015,7 @@ int ppp_check_kernel_support(void)
}
close(s);
return ok;
+#endif
}
#ifndef HAVE_LOGWTMP
@@ -3577,6 +3577,7 @@ get_pty(int *master_fdp, int *slave_fdp,
}
#endif /* TIOCGPTN */
+#if 0
if (sfd < 0) {
/* the old way - scan through the pty name space */
for (i = 0; i < 64; ++i) {
@@ -3601,6 +3602,7 @@ get_pty(int *master_fdp, int *slave_fdp,
}
}
}
+#endif
if (sfd < 0)
return 0;
@@ -3716,6 +3718,7 @@ get_host_seed(void)
int
sys_check_options(void)
{
+#if 0
if (demand && driver_is_old) {
ppp_option_error("demand dialling is not supported by kernel driver "
"version %d.%d.%d", driver_version, driver_modification,
@@ -3726,6 +3729,7 @@ sys_check_options(void)
warn("Warning: multilink is not supported by the kernel driver");
multilink = 0;
}
+#endif
return 1;
}
--- a/pppd/plugins/pppoatm/pppoatm.c
+++ b/pppd/plugins/pppoatm/pppoatm.c
@@ -180,10 +180,6 @@ static void disconnect_pppoatm(void)
void plugin_init(void)
{
#ifdef linux
- extern int new_style_driver; /* From sys-linux.c */
- if (!ppp_check_kernel_support() && !new_style_driver)
- fatal("Kernel doesn't support ppp_generic - "
- "needed for PPPoATM");
#else
fatal("No PPPoATM support on this OS");
#endif
--- a/pppd/plugins/pppoe/plugin.c
+++ b/pppd/plugins/pppoe/plugin.c
@@ -57,9 +57,6 @@ static char const RCSID[] =
char pppd_version[] = PPPD_VERSION;
-/* From sys-linux.c in pppd -- MUST FIX THIS! */
-extern int new_style_driver;
-
char *pppd_pppoe_service = NULL;
static char *acName = NULL;
static char *existingSession = NULL;
@@ -421,10 +418,6 @@ PPPoEDevnameHook(char *cmd, char **argv,
void
plugin_init(void)
{
- if (!ppp_check_kernel_support() && !new_style_driver) {
- fatal("Linux kernel does not support PPPoE -- are you running 2.4.x?");
- }
-
ppp_add_options(Options);
info("PPPoE plugin from pppd %s", PPPD_VERSION);
--- a/pppd/plugins/pppol2tp/pppol2tp.c
+++ b/pppd/plugins/pppol2tp/pppol2tp.c
@@ -501,10 +501,6 @@ static void pppol2tp_cleanup(void)
void plugin_init(void)
{
#if defined(__linux__)
- extern int new_style_driver; /* From sys-linux.c */
- if (!ppp_check_kernel_support() && !new_style_driver)
- fatal("Kernel doesn't support ppp_generic - "
- "needed for PPPoL2TP");
#else
fatal("No PPPoL2TP support on this OS");
#endif

View File

@@ -0,0 +1,39 @@
pppd: Remove the "record" option
On many embedded systems there is not enough space to record PPP session
information to the permanent storage, therfore remove this option.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -187,7 +187,6 @@ extern int holdoff; /* Dead time before
extern bool holdoff_specified; /* true if user gave a holdoff value */
extern bool notty; /* Stdin/out is not a tty */
extern char *pty_socket; /* Socket to connect to pty */
-extern char *record_file; /* File to record chars sent/received */
extern int maxfail; /* Max # of unsuccessful connection attempts */
extern char linkname[]; /* logical name for link */
extern bool tune_kernel; /* May alter kernel settings as necessary */
--- a/pppd/tty.c
+++ b/pppd/tty.c
@@ -150,7 +150,7 @@ char *disconnect_script = NULL; /* Scrip
char *welcomer = NULL; /* Script to run after phys link estab. */
char *ptycommand = NULL; /* Command to run on other side of pty */
bool notty = 0; /* Stdin/out is not a tty */
-char *record_file = NULL; /* File to record chars sent/received */
+static char *const record_file = NULL; /* File to record chars sent/received */
int max_data_rate; /* max bytes/sec through charshunt */
bool sync_serial = 0; /* Device is synchronous serial device */
char *pty_socket = NULL; /* Socket to connect to pty */
@@ -206,8 +206,10 @@ static struct option tty_options[] = {
"Send and receive over socket, arg is host:port",
OPT_PRIO | OPT_DEVNAM },
+#if 0
{ "record", o_string, &record_file,
"Record characters sent/received to file", OPT_PRIO },
+#endif
{ "crtscts", o_int, &crtscts,
"Set hardware (RTS/CTS) flow control",

View File

@@ -0,0 +1,151 @@
pppd: Remove historical protocol names
Remove a number of historical protocol entries from pppd's builtin list, this
reduced the binary size without loss of features.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -984,14 +984,17 @@ struct protocol_list {
const char *name;
} protocol_list[] = {
{ 0x21, "IP" },
+#if 0
{ 0x23, "OSI Network Layer" },
{ 0x25, "Xerox NS IDP" },
{ 0x27, "DECnet Phase IV" },
{ 0x29, "Appletalk" },
{ 0x2b, "Novell IPX" },
+#endif
{ 0x2d, "VJ compressed TCP/IP" },
{ 0x2f, "VJ uncompressed TCP/IP" },
{ 0x31, "Bridging PDU" },
+#if 0
{ 0x33, "Stream Protocol ST-II" },
{ 0x35, "Banyan Vines" },
{ 0x39, "AppleTalk EDDP" },
@@ -1005,8 +1008,11 @@ struct protocol_list {
{ 0x49, "Serial Data Transport Protocol (PPP-SDTP)" },
{ 0x4b, "SNA over 802.2" },
{ 0x4d, "SNA" },
+#endif
{ 0x4f, "IP6 Header Compression" },
+#if 0
{ 0x51, "KNX Bridging Data" },
+#endif
{ 0x53, "Encryption" },
{ 0x55, "Individual Link Encryption" },
{ 0x57, "IPv6" },
@@ -1017,12 +1023,15 @@ struct protocol_list {
{ 0x65, "RTP IPHC Compressed non-TCP" },
{ 0x67, "RTP IPHC Compressed UDP 8" },
{ 0x69, "RTP IPHC Compressed RTP 8" },
+#if 0
{ 0x6f, "Stampede Bridging" },
{ 0x73, "MP+" },
{ 0xc1, "NTCITS IPI" },
+#endif
{ 0xfb, "single-link compression" },
{ 0xfd, "Compressed Datagram" },
{ 0x0201, "802.1d Hello Packets" },
+#if 0
{ 0x0203, "IBM Source Routing BPDU" },
{ 0x0205, "DEC LANBridge100 Spanning Tree" },
{ 0x0207, "Cisco Discovery Protocol" },
@@ -1034,15 +1043,19 @@ struct protocol_list {
{ 0x0231, "Luxcom" },
{ 0x0233, "Sigma Network Systems" },
{ 0x0235, "Apple Client Server Protocol" },
+#endif
{ 0x0281, "MPLS Unicast" },
{ 0x0283, "MPLS Multicast" },
+#if 0
{ 0x0285, "IEEE p1284.4 standard - data packets" },
{ 0x0287, "ETSI TETRA Network Protocol Type 1" },
+#endif
{ 0x0289, "Multichannel Flow Treatment Protocol" },
{ 0x2063, "RTP IPHC Compressed TCP No Delta" },
{ 0x2065, "RTP IPHC Context State" },
{ 0x2067, "RTP IPHC Compressed UDP 16" },
{ 0x2069, "RTP IPHC Compressed RTP 16" },
+#if 0
{ 0x4001, "Cray Communications Control Protocol" },
{ 0x4003, "CDPD Mobile Network Registration Protocol" },
{ 0x4005, "Expand accelerator protocol" },
@@ -1053,8 +1066,10 @@ struct protocol_list {
{ 0x4023, "RefTek Protocol" },
{ 0x4025, "Fibre Channel" },
{ 0x4027, "EMIT Protocols" },
+#endif
{ 0x405b, "Vendor-Specific Protocol (VSP)" },
{ 0x8021, "Internet Protocol Control Protocol" },
+#if 0
{ 0x8023, "OSI Network Layer Control Protocol" },
{ 0x8025, "Xerox NS IDP Control Protocol" },
{ 0x8027, "DECnet Phase IV Control Protocol" },
@@ -1063,7 +1078,9 @@ struct protocol_list {
{ 0x8031, "Bridging NCP" },
{ 0x8033, "Stream Protocol Control Protocol" },
{ 0x8035, "Banyan Vines Control Protocol" },
+#endif
{ 0x803d, "Multi-Link Control Protocol" },
+#if 0
{ 0x803f, "NETBIOS Framing Control Protocol" },
{ 0x8041, "Cisco Systems Control Protocol" },
{ 0x8043, "Ascom Timeplex" },
@@ -1072,18 +1089,24 @@ struct protocol_list {
{ 0x8049, "Serial Data Control Protocol (PPP-SDCP)" },
{ 0x804b, "SNA over 802.2 Control Protocol" },
{ 0x804d, "SNA Control Protocol" },
+#endif
{ 0x804f, "IP6 Header Compression Control Protocol" },
+#if 0
{ 0x8051, "KNX Bridging Control Protocol" },
+#endif
{ 0x8053, "Encryption Control Protocol" },
{ 0x8055, "Individual Link Encryption Control Protocol" },
{ 0x8057, "IPv6 Control Protocol" },
{ 0x8059, "PPP Muxing Control Protocol" },
{ 0x805b, "Vendor-Specific Network Control Protocol (VSNCP)" },
+#if 0
{ 0x806f, "Stampede Bridging Control Protocol" },
{ 0x8073, "MP+ Control Protocol" },
{ 0x80c1, "NTCITS IPI Control Protocol" },
+#endif
{ 0x80fb, "Single Link Compression Control Protocol" },
{ 0x80fd, "Compression Control Protocol" },
+#if 0
{ 0x8207, "Cisco Discovery Protocol Control" },
{ 0x8209, "Netcs Twin Routing" },
{ 0x820b, "STP - Control Protocol" },
@@ -1092,24 +1115,29 @@ struct protocol_list {
{ 0x8281, "MPLSCP" },
{ 0x8285, "IEEE p1284.4 standard - Protocol Control" },
{ 0x8287, "ETSI TETRA TNP1 Control Protocol" },
+#endif
{ 0x8289, "Multichannel Flow Treatment Protocol" },
{ 0xc021, "Link Control Protocol" },
{ 0xc023, "Password Authentication Protocol" },
{ 0xc025, "Link Quality Report" },
+#if 0
{ 0xc027, "Shiva Password Authentication Protocol" },
{ 0xc029, "CallBack Control Protocol (CBCP)" },
{ 0xc02b, "BACP Bandwidth Allocation Control Protocol" },
{ 0xc02d, "BAP" },
+#endif
{ 0xc05b, "Vendor-Specific Authentication Protocol (VSAP)" },
{ 0xc081, "Container Control Protocol" },
{ 0xc223, "Challenge Handshake Authentication Protocol" },
{ 0xc225, "RSA Authentication Protocol" },
{ 0xc227, "Extensible Authentication Protocol" },
+#if 0
{ 0xc229, "Mitsubishi Security Info Exch Ptcl (SIEP)" },
{ 0xc26f, "Stampede Bridging Authorization Protocol" },
{ 0xc281, "Proprietary Authentication Protocol" },
{ 0xc283, "Proprietary Authentication Protocol" },
{ 0xc481, "Proprietary Node ID Authentication Protocol" },
+#endif
{ 0, NULL },
};

View File

@@ -0,0 +1,28 @@
pppd: Support "nomp" option even if multilink support is off
This patch moves the "nomp" option entry outside of the defines protecting
the multilink specific code. The motivation is to allow "nomp" even if pppd
does not support multilink, so that controlling programs can unconditionally
pass it to pppd regardless of the compile time features.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/pppd/options.c
+++ b/pppd/options.c
@@ -379,13 +379,14 @@ struct option general_options[] = {
"Enable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 1 },
{ "nomultilink", o_bool, &multilink,
"Disable multilink operation", OPT_PRIOSUB | 0 },
- { "nomp", o_bool, &multilink,
- "Disable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 0 },
{ "bundle", o_string, &bundle_name,
"Bundle name for multilink", OPT_PRIO },
#endif /* PPP_WITH_MULTILINK */
+ { "nomp", o_bool, &multilink,
+ "Disable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 0 },
+
#ifdef PPP_WITH_PLUGINS
{ "plugin", o_special, (void *)loadplugin,
"Load a plug-in module into pppd", OPT_PRIV | OPT_A2LIST },

File diff suppressed because it is too large Load Diff