From: Eivind Næss Date: Mon, 30 May 2022 05:14:08 +0000 (-0700) Subject: For Linux, use the Linux / Glibc based defines instead of included headers X-Git-Tag: ppp-2.5.0~36^2~5 X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=199e97bae9c03f5cec5202a511b5c436aff05af9 For Linux, use the Linux / Glibc based defines instead of included headers This is to ensure compatibility with the OS you are compiling against and that headers are maintained in upstream projects. - Moved PPP_EAP and PPP_ECP into respective header files in lieu of not currently existing in the linux/ppp_defs.h - Unchained the top-level ${topsrc_dir}/include, this folder is included for prosterity and may continue to exist on github, but in the future eliminated from distribution - Bogus upstream file in glibc for , its content should be replaced with a simple include to . The lack of an appropriate ifreq structure with ppp_stats or ppp_comp_stats, implementet that inline (and tested). - Updated instances where PPP_FCS() macro would expand the fcstab, while PPP_GOODFCS and PPP_INITFCS is provided in , the latter is tied to a lookup table. It's used in two places, so add the PPP_FCS macro where applicable. Signed-off-by: Eivind Næss --- diff --git a/pppd/Makefile.am b/pppd/Makefile.am index c316ea4..405671a 100644 --- a/pppd/Makefile.am +++ b/pppd/Makefile.am @@ -7,7 +7,7 @@ utest_chap_CPPFLAGS = -DUNIT_TEST utest_chap_LDFLAGS = utest_peap_SOURCES = peap.c utils.c mppe.c -utest_peap_CPPFLAGS = -DUNIT_TEST -I${top_srcdir}/include +utest_peap_CPPFLAGS = -DUNIT_TEST utest_peap_LDFLAGS = if WITH_SRP @@ -68,7 +68,7 @@ pppd_SOURCES = \ upap.c \ utils.c -pppd_CPPFLAGS = -I${top_srcdir}/include -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"' +pppd_CPPFLAGS = -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"' pppd_LDFLAGS = pppd_LIBS = diff --git a/pppd/demand.c b/pppd/demand.c index 3e32079..d610d69 100644 --- a/pppd/demand.c +++ b/pppd/demand.c @@ -210,6 +210,7 @@ static u_short fcstab[256] = { 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; +#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) /* * loop_chars - process characters received from the loopback. diff --git a/pppd/eap.h b/pppd/eap.h index fbc7201..96c5f69 100644 --- a/pppd/eap.h +++ b/pppd/eap.h @@ -29,6 +29,12 @@ extern "C" { #endif + +#ifndef PPP_EAP +#define PPP_EAP 0xc227 +#endif + + /* * Packet header = Code, id, length. */ diff --git a/pppd/ecp.h b/pppd/ecp.h index 162dace..807a100 100644 --- a/pppd/ecp.h +++ b/pppd/ecp.h @@ -32,6 +32,14 @@ */ #include "pppdconf.h" +#ifndef PPP_ECP_H +#define PPP_ECP_H + +#ifndef PPP_ECP +#define PPP_ECP 0x8053 +#endif + + typedef struct ecp_options { bool required; /* Is ECP required? */ unsigned enctype; /* Encryption type */ @@ -44,3 +52,5 @@ extern ecp_options ecp_allowoptions[]; extern ecp_options ecp_hisoptions[]; extern struct protent ecp_protent; + +#endif diff --git a/pppd/lcp.c b/pppd/lcp.c index 91e73e7..9dc883e 100644 --- a/pppd/lcp.c +++ b/pppd/lcp.c @@ -51,6 +51,7 @@ #include "pppd.h" #include "fsm.h" #include "lcp.h" +#include "eap.h" #include "chap-new.h" #include "magic.h" diff --git a/pppd/plugins/Makefile.am b/pppd/plugins/Makefile.am index 292daf2..2826148 100644 --- a/pppd/plugins/Makefile.am +++ b/pppd/plugins/Makefile.am @@ -1,7 +1,7 @@ pppd_plugin_LTLIBRARIES = minconn.la passprompt.la passwordfd.la winbind.la pppd_plugindir = $(PPPD_PLUGIN_DIR) -PLUGIN_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} +PLUGIN_CPPFLAGS = -I${top_srcdir} PLUGIN_LDFLAGS = -module -avoid-version minconn_la_CPPFLAGS = $(PLUGIN_CPPFLAGS) diff --git a/pppd/plugins/pppoatm/Makefile.am b/pppd/plugins/pppoatm/Makefile.am index 478aa96..1bc77c1 100644 --- a/pppd/plugins/pppoatm/Makefile.am +++ b/pppd/plugins/pppoatm/Makefile.am @@ -6,7 +6,7 @@ noinst_HEADERS = \ atmres.h \ atmsap.h -pppoatm_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} +pppoatm_la_CPPFLAGS = -I${top_srcdir} pppoatm_la_LDFLAGS = -module -avoid-version pppoatm_la_SOURCES = pppoatm.c diff --git a/pppd/plugins/pppoe/Makefile.am b/pppd/plugins/pppoe/Makefile.am index ce25cd6..6cea70a 100644 --- a/pppd/plugins/pppoe/Makefile.am +++ b/pppd/plugins/pppoe/Makefile.am @@ -6,9 +6,9 @@ dist_man8_MANS = pppoe-discovery.8 noinst_HEADERS = \ pppoe.h -pppoe_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} +pppoe_la_CPPFLAGS = -I${top_srcdir} pppoe_la_LDFLAGS = -module -avoid-version pppoe_la_SOURCES = plugin.c discovery.c if.c common.c -pppoe_discovery_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/include +pppoe_discovery_CPPFLAGS = -I${top_srcdir} pppoe_discovery_SOURCES = pppoe-discovery.c discovery.c if.c common.c diff --git a/pppd/plugins/pppol2tp/Makefile.am b/pppd/plugins/pppol2tp/Makefile.am index c109d22..1018981 100644 --- a/pppd/plugins/pppol2tp/Makefile.am +++ b/pppd/plugins/pppol2tp/Makefile.am @@ -4,10 +4,10 @@ pppd_plugindir = $(PPPD_PLUGIN_DIR) noinst_HEADERS = \ l2tp_event.h -pppol2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} +pppol2tp_la_CPPFLAGS = -I${top_srcdir} pppol2tp_la_LDFLAGS = -module -avoid-version pppol2tp_la_SOURCES = pppol2tp.c -openl2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} +openl2tp_la_CPPFLAGS = -I${top_srcdir} openl2tp_la_LDFLAGS = -module -avoid-version openl2tp_la_SOURCES = openl2tp.c diff --git a/pppd/plugins/radius/Makefile.am b/pppd/plugins/radius/Makefile.am index b9f9e14..ec637ae 100644 --- a/pppd/plugins/radius/Makefile.am +++ b/pppd/plugins/radius/Makefile.am @@ -25,7 +25,7 @@ EXTRA_ETC = \ etc/realms \ etc/servers -RADIUS_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} -DRC_LOG_FACILITY=LOG_DAEMON +RADIUS_CPPFLAGS = -I${top_srcdir} -DRC_LOG_FACILITY=LOG_DAEMON RADIUS_LDFLAGS = -module -avoid-version $(LDFLAGS) radius_la_CPPFLAGS = $(RADIUS_CPPFLAGS) diff --git a/pppd/sys-linux.c b/pppd/sys-linux.c index b68babd..d16f9bf 100644 --- a/pppd/sys-linux.c +++ b/pppd/sys-linux.c @@ -126,8 +126,8 @@ #include #include -#include -#include +#include + #ifdef PPP_WITH_IPV6CP #include @@ -1476,20 +1476,21 @@ get_ppp_stats_ioctl(int u, struct pppd_stats *stats) static u_int32_t iwraps = 0; static u_int32_t owraps = 0; - struct ifpppstatsreq req; + struct ifreq req; + struct ppp_stats data; memset (&req, 0, sizeof (req)); - req.stats_ptr = (caddr_t) &req.stats; - strlcpy(req.ifr__name, ifname, sizeof(req.ifr__name)); + req.ifr_data = (caddr_t) &data; + strlcpy(req.ifr_name, ifname, sizeof(req.ifr_name)); if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) { error("Couldn't get PPP statistics: %m"); return 0; } - stats->bytes_in = req.stats.p.ppp_ibytes; - stats->bytes_out = req.stats.p.ppp_obytes; - stats->pkts_in = req.stats.p.ppp_ipackets; - stats->pkts_out = req.stats.p.ppp_opackets; + stats->bytes_in = data.p.ppp_ibytes; + stats->bytes_out = data.p.ppp_obytes; + stats->pkts_in = data.p.ppp_ipackets; + stats->pkts_out = data.p.ppp_opackets; if (stats->bytes_in < previbytes) ++iwraps; diff --git a/pppdump/Makefile.am b/pppdump/Makefile.am index 2df7e0e..186f34e 100644 --- a/pppdump/Makefile.am +++ b/pppdump/Makefile.am @@ -2,7 +2,6 @@ sbin_PROGRAMS = pppdump dist_man8_MANS = pppdump.8 pppdump_SOURCES = pppdump.c bsd-comp.c deflate.c zlib.c -pppdump_CFLAGS = -I${top_srcdir}/include/net noinst_HEADERS = \ ppp-comp.h \ diff --git a/pppdump/bsd-comp.c b/pppdump/bsd-comp.c index 9d45f0b..7ad6289 100644 --- a/pppdump/bsd-comp.c +++ b/pppdump/bsd-comp.c @@ -46,7 +46,8 @@ #include #include #include -#include "ppp_defs.h" +#include + #include "ppp-comp.h" #if DO_BSD_COMPRESS @@ -250,14 +251,15 @@ bsd_comp_stats(void *state, struct compstat *stats) stats->comp_packets = db->comp_count; stats->inc_bytes = db->incomp_bytes; stats->inc_packets = db->incomp_count; - stats->ratio = db->in_count; + + u_int ratio = db->in_count; out = db->bytes_out; - if (stats->ratio <= 0x7fffff) - stats->ratio <<= 8; + if (ratio <= 0x7fffff) + ratio <<= 8; else out >>= 8; if (out != 0) - stats->ratio /= out; + stats->ratio = ratio / out; } /* diff --git a/pppdump/deflate.c b/pppdump/deflate.c index 5668a4d..0f090b2 100644 --- a/pppdump/deflate.c +++ b/pppdump/deflate.c @@ -41,7 +41,8 @@ #include #include #include -#include "ppp_defs.h" +#include + #include "ppp-comp.h" #include "zlib.h" @@ -115,12 +116,13 @@ z_comp_stats(void *arg, struct compstat *stats) *stats = state->stats; stats->ratio = stats->unc_bytes; out = stats->comp_bytes + stats->unc_bytes; - if (stats->ratio <= 0x7ffffff) - stats->ratio <<= 8; + u_int ratio = stats->ratio; + if (ratio <= 0x7ffffff) + ratio <<= 8; else out >>= 8; if (out != 0) - stats->ratio /= out; + stats->ratio = ratio / out; } /* diff --git a/pppdump/pppdump.c b/pppdump/pppdump.c index 130300a..8944ca5 100644 --- a/pppdump/pppdump.c +++ b/pppdump/pppdump.c @@ -38,7 +38,7 @@ #include #include #include -#include "ppp_defs.h" +#include #include "ppp-comp.h" int hexmode; @@ -233,6 +233,7 @@ static u_short fcstab[256] = { 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 }; +#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) struct pkt { int cnt; diff --git a/pppstats/Makefile.am b/pppstats/Makefile.am index d7d74e0..4c8b83f 100644 --- a/pppstats/Makefile.am +++ b/pppstats/Makefile.am @@ -5,10 +5,6 @@ pppstats_SOURCES = pppstats.c pppstats_CFLAGS = pppstats_CPPFLAGS = -if LINUX -pppstats_CFLAGS += -I${top_srcdir}/include -endif - if SUNOS pppstats_CPPFLAGS += -DSTREAMS endif diff --git a/pppstats/pppstats.c b/pppstats/pppstats.c index cbea00b..44a254d 100644 --- a/pppstats/pppstats.c +++ b/pppstats/pppstats.c @@ -62,7 +62,6 @@ static const char rcsid[] = "$Id: pppstats.c,v 1.29 2002/10/27 12:56:26 fcusack #ifndef __linux__ #include #include -#include #else /* Linux */ #if __GLIBC__ >= 2 @@ -74,6 +73,7 @@ static const char rcsid[] = "$Id: pppstats.c,v 1.29 2002/10/27 12:56:26 fcusack #endif #include #include + #endif /* __linux__ */ #else /* STREAMS */ @@ -137,15 +137,11 @@ catchalarm(int arg) static void get_ppp_stats(struct ppp_stats *curp) { - struct ifpppstatsreq req; + struct ifreq req; memset (&req, 0, sizeof (req)); -#ifdef __linux__ - req.stats_ptr = (caddr_t) &req.stats; -#undef ifr_name -#define ifr_name ifr__name -#endif + req.ifr_data = (caddr_t) curp; strncpy(req.ifr_name, interface, IFNAMSIZ); req.ifr_name[IFNAMSIZ - 1] = 0; @@ -157,25 +153,21 @@ get_ppp_stats(struct ppp_stats *curp) perror("couldn't get PPP statistics"); exit(1); } - *curp = req.stats; } static void get_ppp_cstats(struct ppp_comp_stats *csp) { - struct ifpppcstatsreq creq; + struct ifreq req; + struct ppp_comp_stats stats; - memset (&creq, 0, sizeof (creq)); + memset (&req, 0, sizeof (req)); -#ifdef __linux__ - creq.stats_ptr = (caddr_t) &creq.stats; -#undef ifr_name -#define ifr_name ifr__name -#endif + req.ifr_data = (caddr_t) &stats; - strncpy(creq.ifr_name, interface, IFNAMSIZ); - creq.ifr_name[IFNAMSIZ - 1] = 0; - if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) { + strncpy(req.ifr_name, interface, IFNAMSIZ); + req.ifr_name[IFNAMSIZ - 1] = 0; + if (ioctl(s, SIOCGPPPCSTATS, &req) < 0) { fprintf(stderr, "%s: ", progname); if (errno == ENOTTY) { fprintf(stderr, "no kernel compression support\n"); @@ -189,28 +181,26 @@ get_ppp_cstats(struct ppp_comp_stats *csp) } #ifdef __linux__ - if (creq.stats.c.bytes_out == 0) { - creq.stats.c.bytes_out = creq.stats.c.comp_bytes + creq.stats.c.inc_bytes; - creq.stats.c.in_count = creq.stats.c.unc_bytes; + if (stats.c.bytes_out == 0) { + stats.c.bytes_out = stats.c.comp_bytes + stats.c.inc_bytes; + stats.c.in_count = stats.c.unc_bytes; } - if (creq.stats.c.bytes_out == 0) - creq.stats.c.ratio = 0.0; + if (stats.c.bytes_out == 0) + stats.c.ratio = 0.0; else - creq.stats.c.ratio = 256.0 * creq.stats.c.in_count / - creq.stats.c.bytes_out; + stats.c.ratio = 256.0 * stats.c.in_count / stats.c.bytes_out; - if (creq.stats.d.bytes_out == 0) { - creq.stats.d.bytes_out = creq.stats.d.comp_bytes + creq.stats.d.inc_bytes; - creq.stats.d.in_count = creq.stats.d.unc_bytes; + if (stats.d.bytes_out == 0) { + stats.d.bytes_out = stats.d.comp_bytes + stats.d.inc_bytes; + stats.d.in_count = stats.d.unc_bytes; } - if (creq.stats.d.bytes_out == 0) - creq.stats.d.ratio = 0.0; + if (stats.d.bytes_out == 0) + stats.d.ratio = 0.0; else - creq.stats.d.ratio = 256.0 * creq.stats.d.in_count / - creq.stats.d.bytes_out; + stats.d.ratio = 256.0 * stats.d.in_count / stats.d.bytes_out; #endif - *csp = creq.stats; + *csp = stats; } #else /* STREAMS */