]> git.ozlabs.org Git - ppp.git/commitdiff
config: Include some extra files in the tarball master v2.5.2
authorPaul Mackerras <paulus@ozlabs.org>
Tue, 31 Dec 2024 04:24:46 +0000 (15:24 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Tue, 31 Dec 2024 04:57:20 +0000 (15:57 +1100)
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
232 files changed:
.gitattributes [new file with mode: 0644]
.github/workflows/buildroot.yaml
.github/workflows/solaris.yaml
.github/workflows/ubuntu.yaml
AUTHORS
Changes-2.4 [new file with mode: 0644]
LICENSE.BSD [new file with mode: 0644]
LICENSE.GPL-2 [new file with mode: 0644]
Makefile.am
PLUGINS
README
README.MSCHAP80
README.cbcp
README.eap-tls
README.linux
README.sol2
chat/chat.8
chat/chat.c
common/Makefile.am [deleted file]
common/zlib.c [deleted file]
common/zlib.h [deleted file]
configure.ac
contrib/Makefile.am [deleted file]
contrib/pppgetpass/.gitignore [deleted file]
contrib/pppgetpass/Makefile.am [deleted file]
contrib/pppgetpass/pppgetpass.8 [deleted file]
contrib/pppgetpass/pppgetpass.gtk.c [deleted file]
contrib/pppgetpass/pppgetpass.sh [deleted file]
contrib/pppgetpass/pppgetpass.vt.c [deleted file]
etc.ppp/chap-secrets [deleted file]
etc.ppp/chap-secrets.example [new file with mode: 0644]
etc.ppp/eaptls-client [deleted file]
etc.ppp/eaptls-client.example [new file with mode: 0644]
etc.ppp/eaptls-server [deleted file]
etc.ppp/eaptls-server.example [new file with mode: 0644]
etc.ppp/openssl.cnf [deleted file]
etc.ppp/openssl.cnf.example [new file with mode: 0644]
etc.ppp/options [deleted file]
etc.ppp/options.example [new file with mode: 0644]
etc.ppp/pap-secrets [deleted file]
etc.ppp/pap-secrets.example [new file with mode: 0644]
include/Makefile.am
include/linux/if_ppp.h [deleted file]
include/linux/ppp-comp.h
include/linux/ppp_defs.h
include/net/if_ppp.h [deleted file]
include/net/ppp-comp.h [deleted file]
include/net/ppp_defs.h [deleted file]
include/net/pppio.h [deleted file]
include/net/slcompress.h [deleted file]
include/net/vjcompress.h [deleted file]
m4/ax_check_openssl.m4
m4/ax_check_pam.m4
modules/Makefile.am [deleted file]
modules/bsd-comp.c [deleted file]
modules/deflate.c [deleted file]
modules/if_ppp.c [deleted file]
modules/ppp.c [deleted file]
modules/ppp_ahdlc.c [deleted file]
modules/ppp_comp.c [deleted file]
modules/ppp_mod.h [deleted file]
modules/vjcompress.c [deleted file]
pppd/.gitignore
pppd/Makefile.am
pppd/auth.c
pppd/cbcp.c
pppd/cbcp.h
pppd/ccp.c
pppd/ccp.h
pppd/chap-md5.c
pppd/chap-md5.h
pppd/chap-new.c [deleted file]
pppd/chap-new.h [deleted file]
pppd/chap.c [new file with mode: 0644]
pppd/chap.h [new file with mode: 0644]
pppd/chap_ms.c
pppd/chap_ms.h
pppd/crypto-priv.h [new file with mode: 0644]
pppd/crypto.c [new file with mode: 0644]
pppd/crypto.h [new file with mode: 0644]
pppd/crypto_ms.c [new file with mode: 0644]
pppd/crypto_ms.h [new file with mode: 0644]
pppd/demand.c
pppd/eap-tls.c
pppd/eap.c
pppd/eap.h
pppd/ecp.c
pppd/ecp.h
pppd/eui64.c
pppd/eui64.h
pppd/fsm.c
pppd/fsm.h
pppd/ipcp.c
pppd/ipcp.h
pppd/ipv6cp.c
pppd/ipv6cp.h
pppd/lcp.c
pppd/lcp.h
pppd/magic.c
pppd/magic.h
pppd/main.c
pppd/md4.c [deleted file]
pppd/md4.h [deleted file]
pppd/md5.c [deleted file]
pppd/md5.h [deleted file]
pppd/mppe.c
pppd/mppe.h
pppd/multilink.c
pppd/multilink.h [new file with mode: 0644]
pppd/options.c
pppd/options.h [new file with mode: 0644]
pppd/pathnames.h
pppd/peap.c
pppd/plugins/Makefile.am
pppd/plugins/minconn.c
pppd/plugins/passprompt.c [deleted file]
pppd/plugins/passwordfd.c
pppd/plugins/pppoatm/ans.c
pppd/plugins/pppoatm/atmres.h
pppd/plugins/pppoatm/pppoatm.c
pppd/plugins/pppoatm/text2qos.c
pppd/plugins/pppoe/Makefile.am
pppd/plugins/pppoe/common.c
pppd/plugins/pppoe/config.h.in
pppd/plugins/pppoe/discovery.c
pppd/plugins/pppoe/if.c
pppd/plugins/pppoe/plugin.c
pppd/plugins/pppoe/pppoe-discovery.8
pppd/plugins/pppoe/pppoe-discovery.c
pppd/plugins/pppoe/pppoe.h
pppd/plugins/pppol2tp/openl2tp.c
pppd/plugins/pppol2tp/pppol2tp.c
pppd/plugins/radius/Makefile.am
pppd/plugins/radius/avpair.c
pppd/plugins/radius/buildreq.c
pppd/plugins/radius/clientid.c
pppd/plugins/radius/config.c
pppd/plugins/radius/dict.c
pppd/plugins/radius/etc/dictionary.microsoft
pppd/plugins/radius/includes.h
pppd/plugins/radius/ip_util.c
pppd/plugins/radius/lock.c
pppd/plugins/radius/md5.c
pppd/plugins/radius/options.h
pppd/plugins/radius/pathnames.h
pppd/plugins/radius/pppd-radattr.8
pppd/plugins/radius/pppd-radius.8
pppd/plugins/radius/radattr.c
pppd/plugins/radius/radius.c
pppd/plugins/radius/radiusclient.h
pppd/plugins/radius/radrealms.c
pppd/plugins/radius/sendserver.c
pppd/plugins/radius/util.c
pppd/plugins/winbind.c
pppd/ppp-des.c [new file with mode: 0644]
pppd/ppp-md4.c [new file with mode: 0644]
pppd/ppp-md5.c [new file with mode: 0644]
pppd/ppp-sha1.c [new file with mode: 0644]
pppd/pppcrypt.c [deleted file]
pppd/pppcrypt.h [deleted file]
pppd/pppd-private.h [new file with mode: 0644]
pppd/pppd.8
pppd/pppd.h
pppd/pppdconf.h.in
pppd/session.c
pppd/session.h
pppd/sha1.c [deleted file]
pppd/sha1.h [deleted file]
pppd/spinlock.h
pppd/srp-entry.8
pppd/sys-linux.c
pppd/sys-solaris.c
pppd/tdb.c
pppd/tdb.h
pppd/tls.c
pppd/tty.c
pppd/upap.c
pppd/upap.h
pppd/utils.c
pppd/utils_utest.c [new file with mode: 0644]
pppdump/Makefile.am
pppdump/bsd-comp.c [deleted file]
pppdump/deflate.c [deleted file]
pppdump/ppp-comp.h [deleted file]
pppdump/pppdump.8
pppdump/pppdump.c
pppdump/zlib.c [deleted file]
pppdump/zlib.h [deleted file]
pppstats/pppstats.8
pppstats/pppstats.c
sample/options.ttyXX [deleted file]
scripts/Makefile.am
scripts/README [deleted file]
scripts/autopppd
scripts/callback [deleted file]
scripts/chat-callback [deleted file]
scripts/chatchat/README [deleted file]
scripts/chatchat/chatchat.c [deleted file]
scripts/ip-down.local.add [deleted file]
scripts/ip-up.local.add [deleted file]
scripts/lcp_rtt_dump [new file with mode: 0755]
scripts/lcp_rtt_exporter [new file with mode: 0644]
scripts/options-rsh-loc [deleted file]
scripts/options-rsh-rem [deleted file]
scripts/options-ssh-loc [deleted file]
scripts/options-ssh-rem [deleted file]
scripts/poff
scripts/ppp-off [deleted file]
scripts/ppp-on [deleted file]
scripts/ppp-on-dialer [deleted file]
scripts/ppp-on-rsh [deleted file]
scripts/ppp-on-ssh [deleted file]
scripts/redialer [deleted file]
scripts/secure-card [deleted file]
solaris/Makedefs [deleted file]
solaris/Makedefs.gcc [deleted file]
solaris/Makedefs.sol2 [deleted file]
solaris/Makefile.sol2 [deleted file]
solaris/Makefile.sol2-64 [deleted file]
solaris/Makefile.sol2-64x [deleted file]
solaris/Makefile.sol2gcc [deleted file]
solaris/Makefile.sol2gcc-64 [deleted file]
solaris/Makefile.sol2gcc-64x [deleted file]
solaris/Makefile.top [deleted file]
solaris/ppp.c [deleted file]
solaris/ppp.conf [deleted file]
solaris/ppp_ahdlc.c [deleted file]
solaris/ppp_ahdlc_mod.c [deleted file]
solaris/ppp_comp.c [deleted file]
solaris/ppp_comp_mod.c [deleted file]
solaris/ppp_mod.c [deleted file]
solaris/ppp_mod.h [deleted file]

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..834c029
--- /dev/null
@@ -0,0 +1,2 @@
+# Exclude .git* files from being exported.
+.git* export-ignore
index a131f94b5e176ac3a9eb7f5d3e49096ad750bf03..4353069757e4065fdf333032eac14bc7d0d7b623 100644 (file)
@@ -4,21 +4,33 @@ on: [push, pull_request]
 jobs:
   buildroot:
     name: Buildroot
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-latest
     strategy:
       matrix:
-        defconfig_name: [qemu_x86_defconfig, qemu_x86_64_defconfig, raspberrypi4_defconfig, raspberrypi4_64_defconfig, qemu_ppc64le_pseries_defconfig, qemu_mips32r2_malta_defconfig, qemu_mips64_malta_defconfig]
-        libc_name: [glibc, uclibc, musl]
+        defconfig_name:
+          - qemu_x86_defconfig
+          - qemu_x86_64_defconfig
+          - raspberrypi4_defconfig
+          - raspberrypi4_64_defconfig
+          - qemu_ppc64le_pseries_defconfig
+          - qemu_mips32r2_malta_defconfig
+          - qemu_mips64_malta_defconfig
+          - qemu_riscv32_virt_defconfig
+          - qemu_riscv64_virt_defconfig
+        libc_name:
+          - glibc
+          - uclibc
+          - musl
     env:
-      PPP_CI_VERSION: v1.0
+      CI_VERSION: v1.1
       BUILDROOT_DIRECTORY_NAME: buildroot-${{ matrix.defconfig_name }}-${{ matrix.libc_name }}
     steps:
-      - name: Retrieve prebuilt Buildroot image...
+      - name: Retrieve the prebuilt Buildroot image
         working-directory: /home/runner
         run: |
-          wget https://github.com/ppp-project/ppp-ci/releases/download/${{ env.PPP_CI_VERSION }}/${{ env.BUILDROOT_DIRECTORY_NAME }}.tar.zst
-          tar -xf ${{ env.BUILDROOT_DIRECTORY_NAME }}.tar.zst
-      - name: Select latest PPP upstream version
+          wget https://github.com/ppp-project/ppp-ci/releases/download/${{ env.CI_VERSION }}/${{ env.BUILDROOT_DIRECTORY_NAME }}.tar.zst
+          tar --zstd --strip-components=2 -xf ${{ env.BUILDROOT_DIRECTORY_NAME }}.tar.zst
+      - name: Select the latest PPP upstream version
         working-directory: /home/runner/${{ env.BUILDROOT_DIRECTORY_NAME }}/package/pppd
         run: |
           # Get package sources from head of current branch
index 9ede782fe8928c7bf9f2d5c4263a212588356d83..441be16a2e12357745ef6bebe4ca0833797360c6 100644 (file)
@@ -3,16 +3,15 @@ on: [push, pull_request]
 
 jobs:
   solaris:
-    runs-on: macos-10.15
+    runs-on: ubuntu-22.04
     steps:
     - name: Checkout PPP sources
-      uses: actions/checkout@v2
+      uses: actions/checkout@v4
     - name: Build
-      uses: vmactions/solaris-vm@v0.0.4
+      uses: vmactions/solaris-vm@v1.0.9
       with:
+        release: "11.4-gcc"
         run: |
-          pkg update
-          pkg install gcc automake autoconf libtool
           ./autogen.sh CFLAGS="-Wno-deprecated-declarations"
           make
           make install
index 028193b794170cfd3a9215977cdae146026d7fb4..410daf6e0c61db9f6751a9bdf8b10c0c8b673411 100644 (file)
@@ -5,13 +5,17 @@ jobs:
   build_and_test:
     runs-on: ubuntu-latest
     env:
-      configure_flags: --enable-ipxcp --enable-multilink
+      configure_flags: --enable-multilink --enable-systemd --enable-cbcp
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v4
 
     - name: install required packages
-      run: sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install build-essential autoconf automake pkg-config libtool m4 autoconf-archive libssl-dev libatm1-dev libpcap-dev
+      run: |
+        sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq update
+        sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install \
+          build-essential autoconf automake pkg-config libtool m4 autoconf-archive \
+          libssl-dev libatm1-dev libpcap-dev libsystemd-dev libpam0g-dev
 
     - name: configure
       run: ./autogen.sh ${{ env.configure_flags }}
@@ -19,5 +23,38 @@ jobs:
     - name: build
       run: make V=1 CFLAGS="-O2 -g -Wno-unused-result"
 
+    - name: run auto tests
+      run: VERBOSE=true make check
+
     - name: distcheck
       run: make distcheck DISTCHECK_CONFIGURE_FLAGS="${{ env.configure_flags }}"
+
+  build_and_test_asan:
+    runs-on: ubuntu-latest
+    env:
+      configure_flags: --enable-multilink --enable-systemd --enable-cbcp
+      CFLAGS: '-fsanitize=address -ggdb'
+      LDFLAGS: '-fsanitize=address'
+
+    steps:
+    - uses: actions/checkout@v4
+
+    - name: install required packages
+      run: |
+        sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq update
+        sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install \
+          build-essential autoconf automake pkg-config libtool m4 autoconf-archive \
+          libssl-dev libatm1-dev libpcap-dev libsystemd-dev libpam0g-dev
+
+    - name: configure
+      run: ./autogen.sh ${{ env.configure_flags }}
+
+    - name: build
+      run: make V=1 CFLAGS="-O2 -g -Wno-unused-result"
+
+    - name: run auto tests
+      run: VERBOSE=true make check
+
+    - name: distcheck
+      run: make distcheck DISTCHECK_CONFIGURE_FLAGS="${{ env.configure_flags }}"
+
diff --git a/AUTHORS b/AUTHORS
index ff1a48f248c2e42831c6780a29828e5b6d5b0f7a..8efb380e1760e916695bb4697f0225e89d316847 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,6 +2,6 @@ The pppd Project
 https://github.com/ppp-project/ppp
 
 Primary Author of this package:
-Linux                  Paul Mackerras <paulus@samba.org>
+Linux                  Paul Mackerras <paulus@ozlabs.org>
 Solaris                        James Carlson <carlson@workingcode.com>
 
diff --git a/Changes-2.4 b/Changes-2.4
new file mode 100644 (file)
index 0000000..c2d0939
--- /dev/null
@@ -0,0 +1,275 @@
+What's new in ppp-2.4.9.
+************************
+
+* Support for new EAP (Extensible Authentication Protocol) methods:
+  - Support for EAP-TLS, from Jan Just Keijser and others
+  - Support for EAP-MSCHAPv2, from Eivind Næss, Thomas Omerzu, Tijs
+    Van Buggenhout and others
+
+* New pppd options:
+  - chap-timeout
+  - chapms-strip-domain
+  - replacedefaultroute
+  - noreplacedefaultroute
+  - ipv6cp-accept-remote
+  - lcp-echo-adaptive
+  - ip-up-script
+  - ip-down-script
+  - ca
+  - capath
+  - cert
+  - key
+  - crl-dir
+  - crl
+  - max-tls-version
+  - need-peer-eap
+
+* Fixes for CVE-2020-8597 and CVE-2015-3310.
+
+* libpcap is now required when compiling on Linux (previously, if
+  libpcap was not present, pppd would be compiled without packet
+  filtering support).
+
+* The rp-pppoe plugin has been renamed to pppoe, to distinguish it
+  from the upstream rp-pppoe code.  Its options have changed names,
+  but the old names are kept as aliases.
+
+* The configure script now supports cross-compilation.
+
+* Many bug fixes and cleanups.
+  
+
+What was new in ppp-2.4.8.
+**************************
+
+* New pppd options have been added:
+  - ifname, to set the name for the PPP interface device
+  - defaultroute-metric, to set the metric for the default route
+  - defaultroute6, to add an IPv6 default route (with nodefaultroute6
+    to prevent adding an IPv6 default route)
+  - up_sdnotify, to have pppd notify systemd when the link is up.
+
+* The rp-pppoe plugin has new options:
+  - host-uniq, to set the Host-Uniq value to send
+  - pppoe-padi-timeout, to set the timeout for discovery packets
+  - pppoe-padi-attempts, to set the number of discovery attempts.
+
+* Added the CLASS attribute in radius packets.
+
+* Sundry bug fixes.
+
+* Fixed warnings and issues found by static analysis.
+
+* Added Submitting-patches.md.
+
+
+What was new in ppp-2.4.7.
+**************************
+
+* Fixed a potential security issue in parsing option files (CVE-2014-3158).
+
+* There is a new "stop-bits" option, which takes an argument of 1 or 2,
+  indicating the number of stop bits to use for async serial ports.
+
+* Various bug fixes.
+
+
+What was new in ppp-2.4.6.
+**************************
+
+* Man page updates.
+
+* Several bug fixes.
+
+* Options files can now set and unset environment variables for
+  scripts.
+
+* The timeout for chat scripts can now be taken from an environment
+  variable.
+
+* There is a new option, master_detach, which allows pppd to detach
+  from the controlling terminal when it is the multilink bundle master
+  but its own link has terminated, even if the nodetach option has
+  been given.
+
+
+What was new in ppp-2.4.5.
+**************************
+
+* Under Linux, pppd can now operate in a mode where it doesn't request
+  the peer's IP address, as some peers refuse to supply an IP address.
+  Since Linux supports device routes as well as gateway routes, it's
+  possible to have no remote IP address assigned to the ppp interface
+  and still route traffic over it.
+
+* Pppd now works better with 3G modems that do strange things such as
+  sending IPCP Configure-Naks with the same values over and over again.
+
+* The PPP over L2TP plugin is included, which works with the pppol2tp
+  PPP channel code in the Linux kernel.  This allows pppd to be used
+  to set up tunnels using the Layer 2 Tunneling Protocol.
+
+* A new 'enable-session' option has been added, which enables session
+  accounting via PAM or wtwp/wtmpx, as appropriate.  See the pppd man
+  page for details.
+
+* Several bugs have been fixed.
+
+
+What was new in ppp-2.4.4.
+**************************
+
+* Pppd will now run /etc/ppp/ip-pre-up, if it exists, after creating
+  the ppp interface and configuring its IP addresses but before
+  bringing it up.  This can be used, for example, for adding firewall
+  rules for the interface.
+
+* Lots of bugs fixed, particularly in the area of demand-dialled and
+  persistent connections.
+
+* The rp-pppoe plugin now accepts any interface name (that isn't an
+  existing pppd option name) without putting "nic-" on the front of
+  it, not just eth*, nas*, tap* and br*.
+
+
+What was new in ppp-2.4.3.
+**************************
+
+* The configure script now accepts --prefix and --sysconfdir options.
+  These default to /usr/local and /etc.  If you want pppd put in
+  /usr/sbin as before, use ./configure --prefix=/usr.
+
+* Doing `make install' no longer puts example configuration files in
+  /etc/ppp.  Use `make install-etcppp' if you want that.
+
+* The code has been updated to work with version 0.8.3 of libpcap.
+  Unfortunately the libpcap maintainers removed support for the
+  "inbound" and "outbound" keywords on PPP links, meaning that if you
+  link pppd with libpcap-0.8.3, you can't use those keywords in the
+  active-filter and pass-filter expressions.  The support has been
+  reinstated in the CVS version and should be in future libpcap
+  releases.  If you need the in/outbound keywords, use a later release
+  than 0.8.3, or get the CVS version from http://www.tcpdump.org.
+
+* There is a new option, child-timeout, which sets the length of time
+  that pppd will wait for child processes (such as the command
+  specified with the pty option) to exit before exiting itself.  It
+  defaults to 5 seconds.  After the timeout, pppd will send a SIGTERM
+  to any remaining child processes and exit.  A value of 0 means no
+  timeout.
+
+* Various bugs have been fixed, including some CBCP packet parsing
+  bugs that could lead to the peer being able to crash pppd if CBCP
+  support is enabled.
+
+* Various fixes and enhancements to the radius and rp-pppoe plugins
+  have been added.
+
+* There is a new winbind plugin, from Andrew Bartlet of the Samba
+  team, which provides the ability to authenticate the peer against an
+  NT domain controller using MS-CHAP or MS-CHAPV2.
+
+* There is a new pppoatm plugin, by various authors, sent in by David
+  Woodhouse.
+
+* The multilink code has been substantially reworked.  The first pppd
+  for a bundle still controls the ppp interface, but it doesn't exit
+  until all the links in the bundle have terminated.  If the first
+  pppd is signalled to exit, it signals all the other pppds
+  controlling links in the bundle.
+
+* The TDB code has been updated to the latest version.  This should
+  eliminate the problem that some people have seen where the database
+  file (/var/run/pppd.tdb) keeps on growing.  Unfortunately, however,
+  the new code uses an incompatible database format.  For this reason,
+  pppd now uses /var/run/pppd2.tdb as the database filename.
+
+
+What was new in ppp-2.4.2.
+**************************
+
+* The CHAP code has been rewritten.  Pppd now has support for MS-CHAP
+  V1 and V2 authentication, both as server and client.  The new CHAP
+  code is cleaner than the old code and avoids some copyright problems
+  that existed in the old code.
+
+* MPPE (Microsoft Point-to-Point Encryption) support has been added,
+  although the current implementation shouldn't be considered
+  completely secure.  (There is no assurance that the current code
+  won't ever transmit an unencrypted packet.)
+
+* James Carlson's implementation of the Extensible Authentication
+  Protocol (EAP) has been added.
+
+* Support for the Encryption Control Protocol (ECP) has been added.
+
+* Some new plug-ins have been included:
+  - A plug-in for kernel-mode PPPoE (PPP over Ethernet)
+  - A plug-in for supplying the PAP password over a pipe from another
+    process
+  - A plug-in for authenticating using a Radius server.
+
+* Updates and bug-fixes for the Solaris port.
+
+* The CBCP (Call Back Control Protocol) code has been updated.  There
+  are new options `remotenumber' and `allow-number'.
+
+* Extra hooks for plugins to use have been added.
+
+* There is now a `maxoctets' option, which causes pppd to terminate
+  the link once the number of bytes passed on the link exceeds a given
+  value.
+
+* There are now options to control whether pppd can use the IPCP
+  IP-Address and IP-Addresses options: `ipcp-no-address' and
+  `ipcp-no-addresses'.
+
+* Fixed several bugs, including potential buffer overflows in chat.
+
+
+What was new in ppp-2.4.1.
+**************************
+
+* Pppd can now print out the set of options that are in effect.  The
+  new `dump' option causes pppd to print out the option values after
+  option parsing is complete.  The `dryrun' option causes pppd to
+  print the options and then exit.
+
+* The option parsing code has been fixed so that options in the
+  per-tty options file are parsed correctly, and don't override values
+  from the command line in most cases.
+
+* The plugin option now looks in /usr/lib/pppd/<pppd-version> (for
+  example, /usr/lib/pppd/2.4.1b1) for shared objects for plugins if
+  there is no slash in the plugin name.
+
+* When loading a plugin, pppd will now check the version of pppd for
+  which the plugin was compiled, and refuse to load it if it is
+  different to pppd's version string.  To enable this, the plugin
+  source needs to #include "pppd.h" and have a line saying:
+       char pppd_version[] = VERSION;
+
+* There is a bug in zlib, discovered by James Carlson, which can cause
+  kernel memory corruption if Deflate is used with the lowest setting,
+  8.  As a workaround pppd will now insist on using at least 9.
+
+* Pppd should compile on Solaris and SunOS again.
+
+* Pppd should now set the MTU correctly on demand-dialled interfaces.
+
+
+What was new in ppp-2.4.0.
+**************************
+
+* Multilink: this package now allows you to combine multiple serial
+  links into one logical link or `bundle', for increased bandwidth and
+  reduced latency.  This is currently only supported under the
+  2.4.x and later Linux kernels.
+
+* All the pppd processes running on a system now write information
+  into a common database.  I used the `tdb' code from samba for this.
+
+* New hooks have been added.
+
+For a list of the changes made during the 2.3 series releases of this
+package, see the Changes-2.3 file.
diff --git a/LICENSE.BSD b/LICENSE.BSD
new file mode 100644 (file)
index 0000000..c7a0aa4
--- /dev/null
@@ -0,0 +1,26 @@
+Copyright (c) The Regents of the University of California.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. Neither the name of the University nor the names of its contributors
+   may be used to endorse or promote products derived from this software
+   without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
diff --git a/LICENSE.GPL-2 b/LICENSE.GPL-2
new file mode 100644 (file)
index 0000000..d159169
--- /dev/null
@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
index d7b376cd45b6e57d132b4a0572cd5bbfcaf6ea1a..98d773084f02c50e9256bbc3128afdb80cefcb1f 100644 (file)
@@ -1,43 +1,33 @@
 ACLOCAL_AMFLAGS="-Im4"
 
-SUBDIRS = chat contrib pppd pppstats pppdump
+SUBDIRS = chat pppd pppstats pppdump
 
 if PPP_WITH_PLUGINS
 SUBDIRS += pppd/plugins
 endif
 
-DIST_SUBDIRS = $(SUBDIRS) common include modules scripts
-
-#
-# *HACK*
-#   This is to work around the kernel module for PPP on Sun Solaris
-if SUNOS
-all-am:
-       (cd solaris ; $(MAKE) -f Makefile)
-
-clean-generic:
-       (cd solaris ; $(MAKE) -f Makefile clean)
-
-install-am:
-       (cd solaris ; $(MAKE) -f Makefile install)
-endif
+DIST_SUBDIRS = $(SUBDIRS) include scripts
 
 install-data-hook:
        (cd $(DESTDIR)/$(sysconfdir)/$(PACKAGE) ; \
-        chmod 600 chap-secrets pap-secrets eaptls-server eaptls-client)
+        chmod 600 chap-secrets.example pap-secrets.example \
+        eaptls-server.example eaptls-client.example)
 
 sampledir = $(sysconfdir)/$(PACKAGE)
 sample_DATA = \
-    etc.ppp/options \
-    etc.ppp/chap-secrets \
-    etc.ppp/pap-secrets \
-    etc.ppp/eaptls-server \
-    etc.ppp/eaptls-client \
-    etc.ppp/openssl.cnf
+    etc.ppp/options.example \
+    etc.ppp/chap-secrets.example \
+    etc.ppp/pap-secrets.example \
+    etc.ppp/eaptls-server.example \
+    etc.ppp/eaptls-client.example \
+    etc.ppp/openssl.cnf.example
 
 EXTRA_README = \
     Changes-2.3 \
+    Changes-2.4 \
     FAQ \
+    LICENSE.BSD \
+    LICENSE.GPL-2 \
     README \
     README.cbcp \
     README.eap-srp \
@@ -51,30 +41,12 @@ EXTRA_README = \
     README.pwfd \
     README.sol2 \
     PLUGINS \
+    SECURITY.md \
     SETUP \
-    Submitting-patches.md
-
-EXTRA_SOLARIS = \
-    solaris/Makedefs \
-    solaris/Makedefs.gcc \
-    solaris/Makedefs.sol2 \
-    solaris/Makefile.sol2 \
-    solaris/Makefile.sol2-64 \
-    solaris/Makefile.sol2-64x \
-    solaris/Makefile.sol2gcc \
-    solaris/Makefile.sol2gcc-64 \
-    solaris/Makefile.sol2gcc-64x \
-    solaris/Makefile.top \
-    solaris/ppp_ahdlc.c \
-    solaris/ppp_ahdlc_mod.c \
-    solaris/ppp.c \
-    solaris/ppp_comp.c \
-    solaris/ppp_comp_mod.c \
-    solaris/ppp.conf \
-    solaris/ppp_mod.c \
-    solaris/ppp_mod.h
+    Submitting-patches.md \
+    autogen.sh
 
 EXTRA_DIST= \
     $(sample_DATA) \
     $(EXTRA_README) \
-    $(EXTRA_SOLARIS)
+    sample
diff --git a/PLUGINS b/PLUGINS
index a655a9c765ef6a29f8b1963a1afbf5ce4adf97a1..96292ed47d9ab0548235b91b45cbcda6f2f26b5a 100644 (file)
--- a/PLUGINS
+++ b/PLUGINS
@@ -35,14 +35,16 @@ implements a `minconnect' option, which specifies a minimum connect
 time before the idle timeout applies.
 
 Plugins can access global variables within pppd, so it is useful for
-them to #include "pppd.h" from the pppd source directory.
+them to #include "pppd.h" from the pppd source directory. Other
+header files can be included such as chap.h, mppe.h, and upap.h as
+needed per project.
 
 Every plugin must contain a global procedure called `plugin_init'.
 This procedure will get called (with no arguments) immediately after
 the plugin is loaded.  Every plugin should also contain a variable
 called pppd_version declared as follows:
 
-char pppd_version[] = VERSION;
+char pppd_version[] = PPPD_VERSION;
 
 If this declaration is included, pppd will not load the module if its
 version number differs from that compiled into the plugin binary.
@@ -50,7 +52,7 @@ version number differs from that compiled into the plugin binary.
 Plugins can affect the behaviour of pppd in at least four ways:
 
 1. They can add extra options which pppd will then recognize.  This is
-   done by calling the add_options() procedure with a pointer to an
+   done by calling the ppp_add_options() procedure with a pointer to an
    array of option_t structures.  The last entry in the array must
    have its name field set to NULL.
 
@@ -241,12 +243,15 @@ the bundle, if we are doing multilink.
 A plugin registers itself with a notifier by declaring a procedure of
 the form:
 
-void my_notify_proc(void *opaque, int arg);
+void (ppp_notify_fn)(void *opaque, int arg);
 
 and then registering the procedure with the appropriate notifier with
 a call of the form
 
-       add_notifier(&interesting_notifier, my_notify_proc, opaque);
+       ppp_add_notify(ppp_notify_t, ppp_notify_fn, opaque);
+
+The ppp_notify_t is an enumerated type that describes which notifier
+to attach the function to. Example: NF_EXIT, NF_SIGNALED, NF_IP_UP
 
 The `opaque' parameter in the add_notifier call will be passed to
 my_notify_proc every time it is called.  The `arg' parameter to
@@ -255,33 +260,70 @@ my_notify_proc depends on the notifier.
 A notify procedure can be removed from the list for a notifier with a
 call of the form
 
-       remove_notifier(&interesting_notifier, my_notify_proc, opaque);
+       ppp_del_notify(ppp_notify_t, ppp_notify_fn, opaque);
 
 Here is a list of the currently-implemented notifiers in pppd.
 
-* pidchange.  This notifier is called in the parent when pppd has
+* NF_PID_CHANGE.  This notifier is called in the parent when pppd has
   forked and the child is continuing pppd's processing, i.e. when pppd
   detaches from its controlling terminal.  The argument is the pid of
   the child.
 
-* phasechange.  This is called when pppd moves from one phase of
+* NF_PHASE_CHANGE.  This is called when pppd moves from one phase of
   operation to another.  The argument is the new phase number.
 
-* exitnotify.  This is called just before pppd exits.  The argument is
+* NF_EXIT.  This is called just before pppd exits.  The argument is
   the status with which pppd will exit (i.e. the argument to exit()).
 
-* sigreceived.  This is called when a signal is received, from within
+* NF_SIGNALED.  This is called when a signal is received, from within
   the signal handler.  The argument is the signal number.
 
-* ip_up_notifier.  This is called when IPCP has come up.
+* NF_IP_UP.  This is called when IPCP has come up.
+
+* NF_IP_DOWN.  This is called when IPCP goes down.
+
+* NF_IPV6_UP.  This is called when IP6CP has come up.
 
-* ip_down_notifier.  This is called when IPCP goes down.
+* NF_IPV6_DOWN.  This is called when IP6CP goes down.
 
-* auth_up_notifier.  This is called when the peer has successfully
+* NF_AUTH_UP.  This is called when the peer has successfully
   authenticated itself.
 
-* link_down_notifier.  This is called when the link goes down.
+* NF_LINK_DOWN.  This is called when the link goes down.
+
+* NF_FORK.  Called for each time pppd exists as a new process (child). 
+
+
+Regarding MPPE keys and key-material for 2.5.0 release
+
+Sometimes it is necessary for a plugin to access details related to
+the authentication process. The NF_AUTH_UP callback notifier (client only)
+allows a plugin to inspect e.g. key details after authentication has been
+completed, but before the key material is cleared from memory for security
+reasons.
+
+There are in particularly 3 functions that allow one to inspect these
+keys:
+
+* bool mppe_keys_isset()
+* int mppe_get_recv_key(unsigned char *key, int length)
+* int mppe_get_send_key(unsigned char *key, int length)
+
+The first function indicates whether or not the key material is set and
+is valid. The two latter functions will allow one to obtain a copy
+of the respective receive and send keys. The return value of these
+functions is the length of the valid key material. For security reasons,
+one should take care to clear these copies when work is complete. The
+max length of MPPE receive ands send keys are up to 32 bytes long, or
+of MPPE_MAX_KEY_SIZE length.
 
+The previous definitions of MPPE_MAX_KEY_LEN is the maximum length in
+which the Linux kernel will accept for MPPE key lengths. Plugins would
+access the MPPE keys directly via the:
 
+  extern u_char mppe_send_key[MPPE_MAX_KEY_LEN]
+  extern u_char mppe_recv_key[MPPE_MAX_KEY_LEN]
 
-## $Id: PLUGINS,v 1.8 2008/06/15 07:02:18 paulus Exp $ ##
+variables. The 2.5.0 release prohibits the direct access of these
+variables by making them static and private in favor of using the new
+API.
diff --git a/README b/README
index fc997f4395f0ae4b820c8826e885e8f03ec86439..67e6abb4306b7850246a091a52f3d37e7b8ce760 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,7 @@
-This is the README file for ppp-2.4, a package which implements the
+This is the README file for ppp-2.5, a package which implements the
 Point-to-Point Protocol (PPP) to provide Internet connections over
-serial lines.
+serial lines and other types of links which can be considered to be
+point-to-point links.
 
 
 Introduction.
@@ -9,7 +10,7 @@ Introduction.
 The Point-to-Point Protocol (PPP) provides a standard way to establish
 a network connection over a serial link.  At present, this package
 supports IP and IPV6 and the protocols layered above them, such as TCP
-and UDP.  The Linux port of this package also has support for IPX.
+and UDP.
 
 This PPP implementation consists of two parts:
 
@@ -23,10 +24,9 @@ the link and sets up the ppp network interface.  Pppd includes support
 for authentication, so you can control which other systems may make a
 PPP connection and what IP addresses they may use.
 
-The platforms supported by this package are Linux and Solaris.  I have
-code for NeXTStep, FreeBSD, SunOS 4.x, SVR4, Tru64 (Digital Unix), AIX
-and Ultrix but no active maintainers for these platforms.  Code for
-all of these except AIX is included in the ppp-2.3.11 release.
+The platforms supported by this package are Linux and Solaris.
+(There is also code to support various old flavours of Unix in the git
+repository, but it is quite old and unmaintained.)
 
 The kernel code for Linux is no longer distributed with this package,
 since the relevant kernel code is in the official Linux kernel source
@@ -35,6 +35,12 @@ Linux distributions.  The Linux kernel code supports using PPP over
 things other than serial ports, such as PPP over Ethernet and PPP over
 ATM.
 
+Similarly, the kernel code for Solaris is no longer distributed with
+this package.  See the Illumos web site for pointers to the kernel
+module source code and build environment.
+
+  https://www.illumos.org/
+
 
 Installation.
 *************
@@ -61,281 +67,106 @@ use any IP address.  (This only applies where the peer is
 authenticating itself to you, of course.)
 
 
-What's new in ppp-2.4.9.
-************************
-
-* Support for new EAP (Extensible Authentication Protocol) methods:
-  - Support for EAP-TLS, from Jan Just Keijser and others
-  - Support for EAP-MSCHAPv2, from Eivind Næss, Thomas Omerzu, Tijs
-    Van Buggenhout and others
-
-* New pppd options:
-  - chap-timeout
-  - chapms-strip-domain
-  - replacedefaultroute
-  - noreplacedefaultroute
-  - ipv6cp-accept-remote
-  - lcp-echo-adaptive
-  - ip-up-script
-  - ip-down-script
-  - ca
-  - capath
-  - cert
-  - key
-  - crl-dir
-  - crl
-  - max-tls-version
-  - need-peer-eap
-
-* Fixes for CVE-2020-8597 and CVE-2015-3310.
-
-* libpcap is now required when compiling on Linux (previously, if
-  libpcap was not present, pppd would be compiled without packet
-  filtering support).
-
-* The rp-pppoe plugin has been renamed to pppoe, to distinguish it
-  from the upstream rp-pppoe code.  Its options have changed names,
-  but the old names are kept as aliases.
-
-* The configure script now supports cross-compilation.
-
-* Many bug fixes and cleanups.
-  
-
-What was new in ppp-2.4.8.
-**************************
-
-* New pppd options have been added:
-  - ifname, to set the name for the PPP interface device
-  - defaultroute-metric, to set the metric for the default route
-  - defaultroute6, to add an IPv6 default route (with nodefaultroute6
-    to prevent adding an IPv6 default route)
-  - up_sdnotify, to have pppd notify systemd when the link is up.
-
-* The rp-pppoe plugin has new options:
-  - host-uniq, to set the Host-Uniq value to send
-  - pppoe-padi-timeout, to set the timeout for discovery packets
-  - pppoe-padi-attempts, to set the number of discovery attempts.
-
-* Added the CLASS attribute in radius packets.
-
-* Sundry bug fixes.
-
-* Fixed warnings and issues found by static analysis.
-
-* Added Submitting-patches.md.
-
-
-What was new in ppp-2.4.7.
-**************************
-
-* Fixed a potential security issue in parsing option files (CVE-2014-3158).
-
-* There is a new "stop-bits" option, which takes an argument of 1 or 2,
-  indicating the number of stop bits to use for async serial ports.
-
-* Various bug fixes.
-
-
-What was new in ppp-2.4.6.
-**************************
-
-* Man page updates.
-
-* Several bug fixes.
-
-* Options files can now set and unset environment variables for
-  scripts.
-
-* The timeout for chat scripts can now be taken from an environment
-  variable.
-
-* There is a new option, master_detach, which allows pppd to detach
-  from the controlling terminal when it is the multilink bundle master
-  but its own link has terminated, even if the nodetach option has
-  been given.
+What's new in ppp-2.5.2
+***********************
 
+* Some old and probably unused code has been removed, notably the
+  pppgetpass program and the passprompt plugin, and some of the files
+  in the sample and scripts directories.
 
-What was new in ppp-2.4.5.
-**************************
-
-* Under Linux, pppd can now operate in a mode where it doesn't request
-  the peer's IP address, as some peers refuse to supply an IP address.
-  Since Linux supports device routes as well as gateway routes, it's
-  possible to have no remote IP address assigned to the ppp interface
-  and still route traffic over it.
-
-* Pppd now works better with 3G modems that do strange things such as
-  sending IPCP Configure-Naks with the same values over and over again.
-
-* The PPP over L2TP plugin is included, which works with the pppol2tp
-  PPP channel code in the Linux kernel.  This allows pppd to be used
-  to set up tunnels using the Layer 2 Tunneling Protocol.
-
-* A new 'enable-session' option has been added, which enables session
-  accounting via PAM or wtwp/wtmpx, as appropriate.  See the pppd man
-  page for details.
-
-* Several bugs have been fixed.
-
-
-What was new in ppp-2.4.4.
-**************************
-
-* Pppd will now run /etc/ppp/ip-pre-up, if it exists, after creating
-  the ppp interface and configuring its IP addresses but before
-  bringing it up.  This can be used, for example, for adding firewall
-  rules for the interface.
-
-* Lots of bugs fixed, particularly in the area of demand-dialled and
-  persistent connections.
-
-* The rp-pppoe plugin now accepts any interface name (that isn't an
-  existing pppd option name) without putting "nic-" on the front of
-  it, not just eth*, nas*, tap* and br*.
-
+* If a remote number has been set, it is available to scripts in the
+  REMOTENUMBER environment variable.
 
-What was new in ppp-2.4.3.
-**************************
-
-* The configure script now accepts --prefix and --sysconfdir options.
-  These default to /usr/local and /etc.  If you want pppd put in
-  /usr/sbin as before, use ./configure --prefix=/usr.
-
-* Doing `make install' no longer puts example configuration files in
-  /etc/ppp.  Use `make install-etcppp' if you want that.
-
-* The code has been updated to work with version 0.8.3 of libpcap.
-  Unfortunately the libpcap maintainers removed support for the
-  "inbound" and "outbound" keywords on PPP links, meaning that if you
-  link pppd with libpcap-0.8.3, you can't use those keywords in the
-  active-filter and pass-filter expressions.  The support has been
-  reinstated in the CVS version and should be in future libpcap
-  releases.  If you need the in/outbound keywords, use a later release
-  than 0.8.3, or get the CVS version from http://www.tcpdump.org.
-
-* There is a new option, child-timeout, which sets the length of time
-  that pppd will wait for child processes (such as the command
-  specified with the pty option) to exit before exiting itself.  It
-  defaults to 5 seconds.  After the timeout, pppd will send a SIGTERM
-  to any remaining child processes and exit.  A value of 0 means no
-  timeout.
-
-* Various bugs have been fixed, including some CBCP packet parsing
-  bugs that could lead to the peer being able to crash pppd if CBCP
-  support is enabled.
-
-* Various fixes and enhancements to the radius and rp-pppoe plugins
-  have been added.
-
-* There is a new winbind plugin, from Andrew Bartlet of the Samba
-  team, which provides the ability to authenticate the peer against an
-  NT domain controller using MS-CHAP or MS-CHAPV2.
-
-* There is a new pppoatm plugin, by various authors, sent in by David
-  Woodhouse.
-
-* The multilink code has been substantially reworked.  The first pppd
-  for a bundle still controls the ppp interface, but it doesn't exit
-  until all the links in the bundle have terminated.  If the first
-  pppd is signalled to exit, it signals all the other pppds
-  controlling links in the bundle.
-
-* The TDB code has been updated to the latest version.  This should
-  eliminate the problem that some people have seen where the database
-  file (/var/run/pppd.tdb) keeps on growing.  Unfortunately, however,
-  the new code uses an incompatible database format.  For this reason,
-  pppd now uses /var/run/pppd2.tdb as the database filename.
-
-
-What was new in ppp-2.4.2.
-**************************
-
-* The CHAP code has been rewritten.  Pppd now has support for MS-CHAP
-  V1 and V2 authentication, both as server and client.  The new CHAP
-  code is cleaner than the old code and avoids some copyright problems
-  that existed in the old code.
+* The Solaris port has been updated, including updated installation
+  instructions in README.sol2.
 
-* MPPE (Microsoft Point-to-Point Encryption) support has been added,
-  although the current implementation shouldn't be considered
-  completely secure.  (There is no assurance that the current code
-  won't ever transmit an unencrypted packet.)
+* Various other bug fixes and minor enhancements.
 
-* James Carlson's implementation of the Extensible Authentication
-  Protocol (EAP) has been added.
 
-* Support for the Encryption Control Protocol (ECP) has been added.
+What was new in ppp-2.5.1
+*************************
 
-* Some new plug-ins have been included:
-  - A plug-in for kernel-mode PPPoE (PPP over Ethernet)
-  - A plug-in for supplying the PAP password over a pipe from another
-    process
-  - A plug-in for authenticating using a Radius server.
+* The files copied to /etc/ppp (or <sysconfdir>/ppp) now have
+  ".example" appended to their filenames, so as to indicate that they
+  are just examples, and to avoid overwriting existing configuration
+  files.
 
-* Updates and bug-fixes for the Solaris port.
+* Pppd can now measure and log the round-trip time (RTT) of LCP
+  echo-requests and record them in a binary file structured as a
+  circular buffer.  Other programs or scripts can examine the file and
+  provide real-time statistics on link latency.  This is enabled by a
+  new "lcp-rtt-file" option.
 
-* The CBCP (Call Back Control Protocol) code has been updated.  There
-  are new options `remotenumber' and `allow-number'.
+* New scripts net-init, net-pre-up and net-down are executed in the
+  process of bringing the network interface up and down.  They provide
+  additional, more deterministic ways for pppd to interact with the
+  rest of the networking configuration.
 
-* Extra hooks for plugins to use have been added.
+* New options have been added to allow the system administrator to
+  set the location of various scripts and secrets files.
 
-* There is now a `maxoctets' option, which causes pppd to terminate
-  the link once the number of bytes passed on the link exceeds a given
-  value.
+* A new "noresolvconf" option tells pppd not to write the
+  /etc/ppp/resolv.conf file; DNS server addresses, if obtained from
+  the peer, are still passed to scripts in the environment.
 
-* There are now options to control whether pppd can use the IPCP
-  IP-Address and IP-Addresses options: `ipcp-no-address' and
-  `ipcp-no-addresses'.
+* Pppd will now create the directory for the TDB connection database
+  if it doesn't already exist.
 
-* Fixed several bugs, including potential buffer overflows in chat.
-
-
-What was new in ppp-2.4.1.
-**************************
+* Kernel module code for Solaris is no longer included.
 
-* Pppd can now print out the set of options that are in effect.  The
-  new `dump' option causes pppd to print out the option values after
-  option parsing is complete.  The `dryrun' option causes pppd to
-  print the options and then exit.
+* Support for decompressing compressed packets has been removed from
+  pppdump, because the zlib code used was old and potentially
+  vulnerable.
 
-* The option parsing code has been fixed so that options in the
-  per-tty options file are parsed correctly, and don't override values
-  from the command line in most cases.
+* Some old code has been removed.
 
-* The plugin option now looks in /usr/lib/pppd/<pppd-version> (for
-  example, /usr/lib/pppd/2.4.1b1) for shared objects for plugins if
-  there is no slash in the plugin name.
+* Various other bug fixes and minor enhancements.
 
-* When loading a plugin, pppd will now check the version of pppd for
-  which the plugin was compiled, and refuse to load it if it is
-  different to pppd's version string.  To enable this, the plugin
-  source needs to #include "pppd.h" and have a line saying:
-       char pppd_version[] = VERSION;
 
-* There is a bug in zlib, discovered by James Carlson, which can cause
-  kernel memory corruption if Deflate is used with the lowest setting,
-  8.  As a workaround pppd will now insist on using at least 9.
-
-* Pppd should compile on Solaris and SunOS again.
-
-* Pppd should now set the MTU correctly on demand-dialled interfaces.
-
-
-What was new in ppp-2.4.0.
+What was new in ppp-2.5.0.
 **************************
 
-* Multilink: this package now allows you to combine multiple serial
-  links into one logical link or `bundle', for increased bandwidth and
-  reduced latency.  This is currently only supported under the
-  2.4.x and later Linux kernels.
-
-* All the pppd processes running on a system now write information
-  into a common database.  I used the `tdb' code from samba for this.
+The 2.5.0 release is a major release of pppd which contains breaking 
+changes for third-party plugins, a complete revamp of the build-system
+and that allows for flexibility of configuring features as needed.
+
+In Summary:
+* Support for PEAP authentication by Eivind Næss and Rustam Kovhaev
+* Support for loading PKCS12 certificate envelopes 
+* Adoption of GNU Autoconf / Automake build environment, by Eivind Næss
+  and others.
+* Support for pkgconfig tool has been added by Eivind Næss.
+* Bunch of fixes and cleanup to PPPoE and IPv6 support by Pali Rohár.
+* Major revision to PPPD's Plugin API by Eivind Næss.
+  - Defines in which describes what features was included in pppd
+  - Functions now prefixed with explicit ppp_* to indicate that
+    pppd functions being called.
+  - Header files were renamed to better align with their features,
+    and now use proper include guards
+  - A pppdconf.h file is supplied to allow third-party modules to use
+    the same feature defines pppd was compiled with.
+  - No extern declarations of internal variable names of pppd, 
+    continued use of these extern variables are considered 
+    unstable.
+* Lots of internal fixes and cleanups for Radius and PPPoE by Jaco Kroon
+* Dropped IPX support, as Linux has dropped support in version 5.15
+  for this protocol.
+* Many more fixes and cleanups.
+* Pppd is no longer installed setuid-root.
+* New pppd options:
+  - ipv6cp-noremote, ipv6cp-nosend, ipv6cp-use-remotenumber,
+    ipv6-up-script, ipv6-down-script
+  - -v, show-options
+  - usepeerwins, ipcp-no-address, ipcp-no-addresses, nosendip
+* On Linux, any baud rate can be set on a serial port provided the
+  kernel serial driver supports that.
 
-* New hooks have been added.
+Note that if you have built and installed previous versions of this
+package and you want to continue having configuration and TDB files in
+/etc/ppp, you will need to use the --sysconfdir option to ./configure.
 
-For a list of the changes made during the 2.3 series releases of this
-package, see the Changes-2.3 file.
+For a list of the changes made during the 2.4 series releases of this
+package, see the Changes-2.4 file.
 
 
 Compression methods.
@@ -353,17 +184,17 @@ ever expand packets.
 Contacts.
 *********
 
-The comp.protocols.ppp newsgroup is a useful place to get help if you
-have trouble getting your ppp connections to work.  Please do not send
-me questions of the form "please help me get connected to my ISP" -
-I'm sorry, but I simply do not have the time to answer all the
-questions like this that I get.
+Most communication relating to this package happens on github at
+https://github.com/ppp-project/ppp/.  The linux-ppp@vger.kernel.org
+mailing list also exists and can be used.
 
-If you find bugs in this package, please report them to the maintainer
-for the port for the operating system you are using:
+If you find bugs in this package, the best thing to do is to create an
+issue on github.  If you can't or don't want to do that, you can post
+to linux-ppp@vger.kernel.org, or report them to the maintainer for the
+port for the operating system you are using:
 
-Linux                  Paul Mackerras <paulus@samba.org>
-Solaris                        James Carlson <carlson@workingcode.com>
+Linux                  Paul Mackerras <paulus@ozlabs.org>
+Solaris                        James Carlson <carlsonj@workingcode.com>
 
 
 Copyrights:
@@ -372,7 +203,7 @@ Copyrights:
 All of the code can be freely used and redistributed.  The individual
 source files each have their own copyright and permission notice.
 Pppd, pppstats and pppdump are under BSD-style notices.  Some of the
-pppd plugins are GPL'd.  Chat is public domain.
+pppd plugins are GPL'd.  Chat has an MIT licence notice.
 
 
 Distribution:
index 2c3172ab77f535c099892493f01d602de5c00a31..ed773c593f09e32de57784b887d53ccec663fe19 100644 (file)
@@ -28,8 +28,9 @@ requesting MS-CHAP:
   rcvd [LCP ConfReq id=0x2 <asyncmap 0x0> <auth MS> <magic 0x46a3>]
                                            ^^^^^^^
 
-MS-CHAP is enabled by default under Linux in pppd/Makefile.linux by
-the line "CHAPMS=y".
+MS-CHAP support in pppd (along with MPPE support) can be enabled or
+disabled at configure time using the --enable-microsoft-extensions and
+--disable-microsoft-extensions arguments.  The default is enabled.
 
 
 CONFIGURATION
index f1e4ba123435481d6f1e1d4459486298edc5aeee..bb7f91b59ad6268d2e9a081c74d22646de9bc57f 100644 (file)
@@ -22,8 +22,9 @@ The ietf task group has decided to recommend that the LCP sequence be
 extended to permit the callback operation. For this reason, these
 patches are not 'part' of pppd but are an adjunct to the code.
 
-To enable CBCP support, all that is required is to uncomment the line
-in Makefile.linux that sets CBCP=y and recompile pppd.
+CBCP support is enabled or disabled in pppd at configure time using the
+--enable-cbcp and --disable-cbcp arguments to ./configure.  The default
+is disabled.
 
 I use such script to make a callback:
 
index ad81ab25fbcd443369252b54bd3a74a4b4ca7b92..025dcfddccf9978b2016435741329a86b43acbf7 100644 (file)
@@ -17,9 +17,11 @@ EAP-TLS authentication support for PPP
     mechanism. It also provides optional encryption using the MPPE
     protocol.
 
-    This patch provide EAP-TLS support to pppd.
-    This authentication method can be used in both client or server
-    mode.
+    EAP-TLS support is included in pppd, and is enabled or disabled
+    at configure time by using the --enable-eaptls and --disable-eaptls
+    arguments to ./configure.
+
+    This authentication method can be used in both client and server mode.
 
 2. Building
 
index d441427e4d2885c5c897b876354cd87daad097e5..eccf27aa2ca94ffd405bbffeb87aef919b727e16 100644 (file)
@@ -95,8 +95,8 @@ If you obtained this package in .rpm or .deb format, you simply follow
 the usual procedure for installing the package.
 
 If you are using the .tar.gz form of this package, then cd into the
-ppp-2.4.5 directory you obtained by unpacking the archive and issue
-the following commands:
+directory you obtained by unpacking the archive and issue the
+following commands:
 
 $ ./configure
 $ make
@@ -108,8 +108,12 @@ If the /etc/ppp configuration directory doesn't exist, the `make
 install' step will create it and install some default configuration
 files.
 
+The ./configure script can take various optional arguments to control
+what features are included, what directories are used for installation,
+etc.  Type "./configure --help" to see a list of options.
 
-2.3 System setup for 2.4 kernels
+
+2.3 System setup for 2.4 (and later) kernels
 
 Under the 2.4 series kernels, pppd needs to be able to open /dev/ppp,
 character device (108,0).  If you are using udev (as most distributions
@@ -151,7 +155,7 @@ unsubscribe linux-ppp
 To send a message to the list, email it to linux-ppp@vger.kernel.org.
 You don't have to be subscribed to send messages to the list.
 
-You can also email me (paulus@samba.org) but I am overloaded with
+You can also email me (paulus@ozlabs.org) but I am overloaded with
 email and I can't respond to most messages I get in a timely fashion.
 
 There are also several relevant news groups, such as comp.protocols.ppp,
index 742166480c6e9f2981172efbe624570a685839e2..05901eddb78583dcf25d4f0b2cde2922e38798bc 100644 (file)
-This file describes the installation process for ppp-2.4 on systems
-running Solaris.  The Solaris and SVR4 ports share a lot of code but
-are not identical.  The STREAMS kernel modules and driver for Solaris
-are in the solaris directory (and use some code from the modules
-directory).
-
-NOTE: Although the kernel driver and modules have been designed to
-operate correctly on SMP systems, they have not been extensively
-tested on SMP machines.  Some users of SMP Solaris x86 systems have
-reported system problems apparently linked to the use of previous
-versions of this software.  I believe these problems have been fixed.
-
-
-Installation.
+Introduction.
 *************
 
-1. Run the configure script and make the user-level programs and the
-   kernel modules.
-
-       ./configure
-       make
-
-    The configure script will automatically find Sun's cc if it's in
-    the standard location (/opt/SUNWspro/bin/cc).  If you do not have
-    Sun's WorkShop compiler, configure will attempt to use 'gcc'.  If
-    this is found and you have a 64 bit kernel, it will check that gcc
-    accepts the "-m64" option, which is required to build kernel
-    modules.
-
-    You should not have to edit the Makefiles for most ordinary cases.
-
-2. Install the programs and kernel modules: as root, do
-
-       make install
-
-    This installs pppd, chat and pppstats in /usr/local/bin and the
-    kernel modules in /kernel/drv and /kernel/strmod, and creates the
-    /etc/ppp directory and populates it with default configuration
-    files.  You can change the installation directories by editing
-    solaris/Makedefs.  If you have a 64 bit kernel, the 64-bit drivers
-    are installed in /kernel/drv/sparcv9 and /kernel/strmod/sparcv9.
-
-    If your system normally has only one network interface at boot
-    time, the default Solaris system startup scripts will disable IP
-    forwarding in the IP kernel module.  This will prevent the remote
-    machine from using the local machine as a gateway to access other
-    hosts.  The solution is to create an /etc/ppp/ip-up script
-    containing something like this:
-
-       #!/bin/sh
-       /usr/sbin/ndd -set /dev/ip ip_forwarding 1
-
-    See the man page for ip(7p) for details.
-
-Integrated pppd
-***************
+  This file describes the installation process for ppp-2.5 on systems
+  running an OpenSolaris-derived OS, such as Illumos or OpenIndiana.
+  For these systems, the STREAMS kernel modules are supplied with the
+  OS itself and are used as-is by this distribution. For more
+  information on these distributions (including kernel source) see:
 
-  Solaris 8 07/01 (Update 5) and later have an integrated version of
-  pppd, known as "Solaris PPP 4.0," and is based on ppp-2.4.0.  This
-  version comes with the standard Solaris software distribution and is
-  supported by Sun.  It is fully tested in 64-bit and SMP modes, and
-  with bundled and unbundled synchronous drivers.  Solaris 8 10/01
-  (Update 6) and later includes integrated PPPoE client and server
-  support, with kernel-resident data handling.  See pppd(1M).
+    https://www.illumos.org/
+    https://illumos.org/docs/about/distro/
 
-  The feature is part of the regular full installation, and is
-  provided by these packages:
+  For Oracle Solaris systems, either use the vendor-supplied PPP
+  implementation ("Solaris PPP 4.0" based on pppd-2.4.0), or download
+  an older version of the pppd sources here:
 
-       SUNWpppd        - 32-bit mode kernel drivers
-       SUNWpppdr       - root-resident /etc/ppp config samples
-       SUNWpppdu       - /usr/bin/pppd itself, plus chat
-       SUNWpppdx       - 64-bit mode kernel drivers
-       SUNWpppdt       - PPPoE support
-       SUNWpppg        - GPL'd optional 'pppdump' and plugins
-       SUNWpppgS       - Source for GPL'd optional features
+    https://download.samba.org/pub/ppp/
 
-  Use the open source version of pppd if you wish to recompile to add
-  new features or to experiment with the code.  Production systems,
-  however, should run the Sun-supplied version, if at all possible.
+  The last version known to compile and run correctly on Oracle
+  Solaris 10 is pppd-2.4.8. It may be possible to compile and use
+  newer versions on either Solaris 11 or by installing third-party
+  compilers; this has not been tested.
 
-  You can run both versions on a single system if you wish.  The
-  Solaris PPP 4.0 interfaces are named "spppN," while this open source
-  version names its interfaces as "pppN".  The STREAMS modules are
-  similarly separated.  The Sun-supplied pppd lives in /usr/bin/pppd,
-  while the open source version installs (by default) in
-  /usr/local/bin/pppd.
 
-Dynamic STREAMS Re-Plumbing Support.
-************************************
-
-  Solaris 8 (and later) includes dynamic re-plumbing support.  With
-  this feature, modules below ip can be inserted, or removed, without
-  having the ip stream be unplumbed, and re-plumbed again.  All state
-  in ip for the interface will be preserved as modules are added or
-  removed.  Users can install (or upgrade) modules such as firewall,
-  bandwidth manager, cache manager, tunneling, etc., without shutting
-  the interface down.
-
-  To support this, ppp driver now uses /dev/udp instead of /dev/ip for
-  the ip stream. The interface stream (where ip module pushed on top
-  of ppp) is then I_PLINK'ed below the ip stream. /dev/udp is used
-  because STREAMS will not let a driver be PLINK'ed under itself, and
-  /dev/ip is typically the driver at the bottom of the tunneling
-  interfaces stream.  The mux ids of the ip streams are then added
-  using SIOCSxIFMUXID ioctl.
-
-  Users will be able to see the modules on the interface stream by,
-  for example:
-
-    pikapon# ifconfig ppp modlist
-    0 ip
-    1 ppp
-
-  Or arbitrarily if bandwidth manager and firewall modules are installed:
-
-    pikapon# ifconfig hme0 modlist
-    0 arp
-    1 ip
-    2 ipqos
-    3 firewall
-    4 hme
-
-Snoop Support.
-**************
-
-  This version includes support for /usr/sbin/snoop.  Tests have been
-  done on Solaris 7 through 9. Only IPv4 and IPv6 packets will be sent
-  up to stream(s) marked as promiscuous (i.e., those used by snoop).
-
-  Users will be able to see the packets on the ppp interface by, for
-  example:
-
-    snoop -d ppp0
-
-  See the man page for snoop(1M) for details.
-
-IPv6 Support.
+Installation.
 *************
 
-  This is for Solaris 8 and later.
-
-  This version has been tested under Solaris 8 and 9 running IPv6.
-  Interoperability testing has only been done between Solaris machines
-  in terms of the IPV6 NCP.  An additional command line option for the
-  pppd daemon has been added: ipv6cp-use-persistent.
+1. Make sure you have a suitable compiler installed. This package was
+   tested with "pkg install gcc-14" but other modern compilers should
+   work.
 
-  By default, compilation for IPv6 support is not enabled.  Uncomment
-  the necessary lines in pppd/Makefile.sol2 to enable it.  Once done,
-  the quickest way to get IPv6 running is to add the following
-  somewhere in the command line option:
+2. Run the configure script and build the package.
 
-       +ipv6 ipv6cp-use-persistent
+     ./configure --with-runtime-dir=/var/run --with-logfile-dir=/var/log/ppp
+     make
 
-  The persistent id for the link-local address was added to conform to
-  RFC 2472; such that if there's an EUI-48 available, use that to make
-  up the EUI-64.  As of now, the Solaris implementation extracts the
-  EUI-48 id from the Ethernet's MAC address (the ethernet interface
-  needs to be up).  Future work might support other ways of obtaining
-  a unique yet persistent id, such as EEPROM serial numbers, etc.
+   The configure script will automatically find the compiler if it's in
+   the standard location (/usr/bin/gcc). By default, everything will be
+   installed in /usr/local. Use "--prefix" to choose a different
+   installation directory if desired. Use "./configure -h" to see other
+   options.
 
-  There need not be any up/down scripts for ipv6,
-  e.g. /etc/ppp/ipv6-up or /etc/ppp/ipv6-down, to trigger IPv6
-  neighbor discovery for auto configuration and routing.  The in.ndpd
-  daemon will perform all of the necessary jobs in the
-  background. /etc/inet/ndpd.conf can be further customized to enable
-  the machine as an IPv6 router. See the man page for in.ndpd(1M) and
-  ndpd.conf(4) for details.
+3. Install the programs.
 
-  Below is a sample output of "ifconfig -a" with persistent link-local
-  address.  Note the UNNUMBERED flag is set because hme0 and ppp0 both
-  have identical link-local IPv6 addresses:
+     sudo make install
 
-lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
-        inet 127.0.0.1 netmask ff000000 
-hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
-        inet 129.146.86.248 netmask ffffff00 broadcast 129.146.86.255
-        ether 8:0:20:8d:38:c1 
-lo0: flags=2000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6> mtu 8252 index 1
-        inet6 ::1/128 
-hme0: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 2
-        ether 8:0:20:8d:38:c1 
-        inet6 fe80::a00:20ff:fe8d:38c1/10 
-hme0:1: flags=2080841<UP,RUNNING,MULTICAST,ADDRCONF,IPv6> mtu 1500 index 2
-        inet6 fec0::56:a00:20ff:fe8d:38c1/64 
-hme0:2: flags=2080841<UP,RUNNING,MULTICAST,ADDRCONF,IPv6> mtu 1500 index 2
-        inet6 2000::56:a00:20ff:fe8d:38c1/64 
-hme0:3: flags=2080841<UP,RUNNING,MULTICAST,ADDRCONF,IPv6> mtu 1500 index 2
-        inet6 2::56:a00:20ff:fe8d:38c1/64 
-ppp0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> mtu 1500 index 12
-        inet 172.16.1.1 --> 172.16.1.2 netmask ffffff00 
-ppp0: flags=2202851<UP,POINTOPOINT,RUNNING,MULTICAST,UNNUMBERED,NONUD,IPv6> mtu 1500 index 12
-        inet6 fe80::a00:20ff:fe8d:38c1/10 --> fe80::a00:20ff:fe7a:24fb
+   This installs the following:
 
-  Note also that a plumbed ipv6 interface stream will exist throughout
-  the entire PPP session in the case where the peer rejects IPV6CP,
-  which further causes the interface state to stay down. Unplumbing
-  will happen when the daemon exits. This is done by design and is not
-  a bug.
+     /usr/local/sbin            pppd, chat, pppstats, pppdump
+     /usr/local/share/man/man8  man pages
+     /usr/local/include/pppd    plug-in header files
+     /usr/local/lib/pppd/$VER  plug-in modules
+     /usr/local/etc/ppp         example configuration files
+    
+   If your system normally has only one network interface at boot
+   time, the default Solaris system startup scripts will disable IP
+   forwarding in the IP kernel module.  This will prevent the remote
+   machine from using the local machine as a gateway to access other
+   hosts.  The solution is to create an /etc/ppp/ip-up script
+   containing something like this:
 
-64-bit Support.
-***************
+     #!/bin/sh
+     /usr/sbin/ndd -set /dev/ip ip_forwarding 1
 
-  This version has been tested under Solaris 7 through 9 in both 32-
-  and 64-bit environments (Ultra class machines).  Installing the
-  package by executing "make install" will result in additional files
-  residing in /kernel/drv/sparcv9 and /kernel/strmod/sparcv9
-  subdirectories.
+   See the man page for ip(7p) for details.
 
-  64-bit modules and driver have been compiled and tested using Sun's
-  cc and gcc.
 
 Synchronous Serial Support.
 ***************************
@@ -218,14 +74,8 @@ Synchronous Serial Support.
   was tested with a Cisco router.
 
   The ppp daemon does not directly support controlling the serial
-  interface.  It relies on the /usr/sbin/syncinit command to
-  initialize HDLC mode and clocking.
-
-  There is a confirmed bug with NRZ/NRZI mode in the /dev/se_hdlc
-  driver, and Solaris patch 104596-11 is needed to correct it.
-  (However this patch seems to introduce other serial problems.  If
-  you don't apply the patch, the workaround is to change the nrzi mode
-  to yes or no, whichever works.)
+  interface.  It relies on the OS-supplied /usr/sbin/syncinit command
+  to initialize HDLC mode and clocking.
 
   How to start pppd with synchronous support:
 
index 6d10836c424085aae55b0a6dd194dcaa69ae0f82..2d1b74b45cfee3acb5ce0bdb2ab1c03f70d8adec 100644 (file)
@@ -1,6 +1,5 @@
 .\" -*- nroff -*-
 .\" manual page [] for chat 1.8
-.\" $Id: chat.8,v 1.11 2004/11/13 12:22:49 paulus Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
index 64d96c230bfcd943c28e9182711c7fbaee7d20ad..788c42bdea904c721b558d1a02c3001402117158 100644 (file)
@@ -1,7 +1,32 @@
+/* SPDX-License-Identifier: MIT */
 /*
  *     Chat -- a program for automatic session establishment (i.e. dial
  *             the phone and log in).
  *
+ * This version is Copyright 1995-2024 Paul Mackerras <paulus@ozlabs.org>
+ * based on the original public-domain version by Karl Fox.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the “Software”), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *
  * Standard termination codes:
  *  0 - successful completion of the script
  *  1 - invalid argument, expect string too large, etc.
@@ -11,7 +36,6 @@
  *  5 - the second string declared as "ABORT"
  *  6 - ... and so on for successive ABORT strings.
  *
- *     This software is in the public domain.
  *
  * -----------------
  *     22-May-99 added environment substitutuion, enabled with -E switch.
@@ -182,7 +206,7 @@ int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0;
 int clear_abort_next = 0;
 
 char *report_string[MAX_REPORTS] ;
-char  report_buffer[256] ;
+char  report_buffer[4096] ;
 int n_reports = 0, report_next = 0, report_gathering = 0 ; 
 int clear_report_next = 0;
 
@@ -198,7 +222,7 @@ SIGTYPE sigalrm (int signo);
 SIGTYPE sigint (int signo);
 SIGTYPE sigterm (int signo);
 SIGTYPE sighup (int signo);
-void unalarm (void);
+void checksigs(void);
 void init (void);
 void set_tty_parameters (void);
 int  echo_stderr (int);
@@ -215,7 +239,6 @@ char *character (int c);
 void chat_expect (register char *s);
 char *clean (register char *s, int sending);
 void break_sequence (void);
-void terminate (int status);
 void pack_array (char **array, int end);
 char *expect_strtok (char *, char *);
 int vfmtmsg (char *, int, const char *, va_list);      /* vsprintf++ */
@@ -347,16 +370,12 @@ main(int argc, char **argv)
        report_fp = stderr;
 
     if (to_log) {
-#ifdef ultrix
-       openlog("chat", LOG_PID);
-#else
        openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
 
        if (verbose)
            setlogmask(LOG_UPTO(LOG_INFO));
        else
            setlogmask(LOG_UPTO(LOG_WARNING));
-#endif
     }
 
     init();
@@ -373,6 +392,7 @@ main(int argc, char **argv)
 
            if ((arg = ARG(argc, argv)) != NULL)
                chat_send(arg);
+           checksigs();
        }
     }
 
@@ -444,8 +464,10 @@ void do_file (char *chat_file)
            else
                chat_expect (arg);
            sendflg = !sendflg;
+           checksigs();
        }
     }
+    checksigs();
     fclose (cfp);
 }
 
@@ -499,59 +521,68 @@ void fatal(int code, const char *fmt, ...)
 }
 
 int alarmed = 0;
+int alarmsig = 0;
 
 SIGTYPE sigalrm(int signo)
 {
     int flags;
 
     alarm(1);
-    alarmed = 1;               /* Reset alarm to avoid race window */
-    signal(SIGALRM, sigalrm);  /* that can cause hanging in read() */
-
-    if ((flags = fcntl(0, F_GETFL, 0)) == -1)
-       fatal(2, "Can't get file mode flags on stdin: %m");
-
-    if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
-       fatal(2, "Can't set file mode flags on stdin: %m");
-
-    if (verbose)
-       msgf("alarm");
+    alarmed = 1;
+    alarmsig = 1;
 }
 
-void unalarm(void)
-{
-    int flags;
-
-    if ((flags = fcntl(0, F_GETFL, 0)) == -1)
-       fatal(2, "Can't get file mode flags on stdin: %m");
-
-    if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
-       fatal(2, "Can't set file mode flags on stdin: %m");
-}
+const char *fatalsig = NULL;
 
 SIGTYPE sigint(int signo)
 {
-    fatal(2, "SIGINT");
+    fatalsig = "SIGINT";
 }
 
 SIGTYPE sigterm(int signo)
 {
-    fatal(2, "SIGTERM");
+    fatalsig = "SIGTERM";
 }
 
 SIGTYPE sighup(int signo)
 {
-    fatal(2, "SIGHUP");
+    fatalsig = "SIGHUP";
+}
+
+void checksigs(void)
+{
+    int err;
+    const char *signame;
+
+    if (fatalsig) {
+       signame = fatalsig;
+       fatalsig = NULL;
+       alarmsig = 0;
+       fatal(2, signame);
+    }
+    if (alarmsig && verbose) {
+       err = errno;
+       msgf("alarm");
+       errno = err;
+       alarmsig = 0;
+    }
 }
 
 void init(void)
 {
-    signal(SIGINT, sigint);
-    signal(SIGTERM, sigterm);
-    signal(SIGHUP, sighup);
+    struct sigaction sa;
+
+    memset(&sa, 0, sizeof(sa));
+    sa.sa_handler = sigint;
+    sigaction(SIGINT, &sa, NULL);
+    sa.sa_handler = sigterm;
+    sigaction(SIGTERM, &sa, NULL);
+    sa.sa_handler = sighup;
+    sigaction(SIGHUP, &sa, NULL);
 
     set_tty_parameters();
-    signal(SIGALRM, sigalrm);
+    sa.sa_handler = sigalrm;
+    sigaction(SIGALRM, &sa, NULL);
     alarm(0);
     alarmed = 0;
 }
@@ -602,7 +633,7 @@ void terminate(int status)
        int c, rep_len;
 
        rep_len = strlen(report_buffer);
-       while (rep_len + 1 <= sizeof(report_buffer)) {
+       while (rep_len + 1 < sizeof(report_buffer)) {
            alarm(1);
            c = get_char();
            alarm(0);
@@ -945,6 +976,7 @@ void chat_expect (char *s)
            break;
 
        chat_send (reply);
+       checksigs();
     }
 
 /*
@@ -987,6 +1019,7 @@ int chat_send (register char *s)
 {
     char file_data[STR_LEN];
     int len, ret = 0;
+    struct sigaction sa;
 
     if (say_next) {
        say_next = 0;
@@ -999,10 +1032,13 @@ int chat_send (register char *s)
 
     if (hup_next) {
         hup_next = 0;
+       memset(&sa, 0, sizeof(sa));
+
        if (strcmp(s, "OFF") == 0)
-           signal(SIGHUP, SIG_IGN);
+           sa.sa_handler = SIG_IGN;
         else
-           signal(SIGHUP, sighup);
+           sa.sa_handler = sighup;
+       sigaction(SIGHUP, &sa, NULL);
         return 0;
     }
 
@@ -1121,7 +1157,7 @@ int chat_send (register char *s)
 
        if (verbose)
            msgf("timeout set to %d seconds", timeout);
-
+       free(s);
        return 0;
     }
 
@@ -1179,6 +1215,7 @@ int get_char(void)
     char c;
 
     status = read(0, &c, 1);
+    checksigs();
 
     switch (status) {
     case 1:
@@ -1188,12 +1225,6 @@ int get_char(void)
        msgf("warning: read() on stdin returned %d", status);
 
     case -1:
-       if ((status = fcntl(0, F_GETFL, 0)) == -1)
-           fatal(2, "Can't get file mode flags on stdin: %m");
-
-       if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
-           fatal(2, "Can't set file mode flags on stdin: %m");
-       
        return (-1);
     }
 }
@@ -1204,8 +1235,10 @@ int put_char(int c)
     char ch = c;
 
     usleep(10000);             /* inter-character typing delay (?) */
+    checksigs();
 
     status = write(1, &ch, 1);
+    checksigs();
 
     switch (status) {
     case 1:
@@ -1215,12 +1248,6 @@ int put_char(int c)
        msgf("warning: write() on stdout returned %d", status);
        
     case -1:
-       if ((status = fcntl(0, F_GETFL, 0)) == -1)
-           fatal(2, "Can't get file mode flags on stdin, %m");
-
-       if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
-           fatal(2, "Can't set file mode flags on stdin: %m");
-       
        return (-1);
     }
 }
@@ -1244,8 +1271,11 @@ int write_char(int c)
 
 int put_string(register char *s)
 {
+    char *s1;
     quiet = 0;
+
     s = clean(s, 1);
+    s1 = s;
 
     if (verbose) {
        if (quiet)
@@ -1260,8 +1290,10 @@ int put_string(register char *s)
        register char c = *s++;
 
        if (c != '\\') {
-           if (!write_char (c))
+           if (!write_char (c)) {
+               free(s1);
                return 0;
+           }
            continue;
        }
 
@@ -1280,14 +1312,18 @@ int put_string(register char *s)
            break;
 
        default:
-           if (!write_char (c))
+           if (!write_char (c)) {
+               free(s1);
                return 0;
+           }
            break;
        }
+       checksigs();
     }
 
     alarm(0);
     alarmed = 0;
+    free(s1);
     return (1);
 }
 
@@ -1320,6 +1356,7 @@ int echo_stderr(int n)
        need_lf = 1;
        break;
     }
+    checksigs();
     return ret;
 }
 
@@ -1331,10 +1368,10 @@ int get_string(register char *string)
     char temp[STR_LEN];
     int c, printed = 0, len, minlen;
     register char *s = temp, *end = s + STR_LEN;
-    char *logged = temp;
+    char *s1, *logged = temp;
 
     fail_reason = (char *)0;
-    string = clean(string, 0);
+    string = s1 = clean(string, 0);
     len = strlen(string);
     minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1;
 
@@ -1344,12 +1381,14 @@ int get_string(register char *string)
     if (len > STR_LEN) {
        msgf("expect string is too long");
        exit_code = 1;
+       free(s1);
        return 0;
     }
 
     if (len == 0) {
        if (verbose)
            msgf("got it");
+       free(s1);
        return (1);
     }
 
@@ -1397,6 +1436,7 @@ int get_string(register char *string)
                    strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now);
                    strcat (report_buffer, report_string[n]);
 
+                   free(report_string[n]);
                    report_string[n] = (char *) NULL;
                    report_gathering = 1;
                    break;
@@ -1406,8 +1446,10 @@ int get_string(register char *string)
        else {
            if (!iscntrl (c)) {
                int rep_len = strlen (report_buffer);
-               report_buffer[rep_len]     = c;
-               report_buffer[rep_len + 1] = '\0';
+               if ((rep_len + 1) < sizeof(report_buffer)) {
+                   report_buffer[rep_len]     = c;
+                   report_buffer[rep_len + 1] = '\0';
+               }
            }
            else {
                report_gathering = 0;
@@ -1426,6 +1468,7 @@ int get_string(register char *string)
 
            alarm(0);
            alarmed = 0;
+           free(s1);
            return (1);
        }
 
@@ -1442,6 +1485,7 @@ int get_string(register char *string)
                alarmed = 0;
                exit_code = n + 4;
                strcpy(fail_reason = fail_buffer, abort_string[n]);
+               free(s1);
                return (0);
            }
        }
@@ -1473,6 +1517,7 @@ int get_string(register char *string)
 
     exit_code = 3;
     alarmed   = 0;
+    free(s1);
     return (0);
 }
 
diff --git a/common/Makefile.am b/common/Makefile.am
deleted file mode 100644 (file)
index 27169d5..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-EXTRA_ZLIB = \
-    zlib.c \
-    zlib.h
-
-EXTRA_DIST = \
-    $(EXTRA_ZLIB)
diff --git a/common/zlib.c b/common/zlib.c
deleted file mode 100644 (file)
index 58c7939..0000000
+++ /dev/null
@@ -1,5379 +0,0 @@
-/*
- * This file is derived from various .h and .c files from the zlib-1.0.4
- * distribution by Jean-loup Gailly and Mark Adler, with some additions
- * by Paul Mackerras to aid in implementing Deflate compression and
- * decompression for PPP packets.  See zlib.h for conditions of
- * distribution and use.
- *
- * Changes that have been made include:
- * - added Z_PACKET_FLUSH (see zlib.h for details)
- * - added inflateIncomp and deflateOutputPending
- * - allow strm->next_out to be NULL, meaning discard the output
- *
- * $Id: zlib.c,v 1.12 2002/04/02 13:34:03 dfs Exp $
- */
-
-/* 
- *  ==FILEVERSION 971210==
- *
- * This marker is used by the Linux installation script to determine
- * whether an up-to-date version of this file is already installed.
- */
-
-#define NO_DUMMY_DECL
-#define NO_ZCFUNCS
-#define MY_ZCALLOC
-
-#if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL))
-#define inflate        inflate_ppp     /* FreeBSD already has an inflate :-( */
-#endif
-
-
-/* +++ zutil.h */
-/* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* From: zutil.h,v 1.16 1996/07/24 13:41:13 me Exp $ */
-
-#ifndef _Z_UTIL_H
-#define _Z_UTIL_H
-
-#include "zlib.h"
-
-#if defined(KERNEL) || defined(_KERNEL)
-/* Assume this is a *BSD or SVR4 kernel */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/systm.h>
-#undef u
-#  define HAVE_MEMCPY
-#  define memcpy(d, s, n)      bcopy((s), (d), (n))
-#  define memset(d, v, n)      bzero((d), (n))
-#  define memcmp               bcmp
-
-#else
-#if defined(__KERNEL__)
-/* Assume this is a Linux kernel */
-#include <linux/string.h>
-#define HAVE_MEMCPY
-
-#else /* not kernel */
-
-#if defined(MSDOS)||defined(VMS)||defined(CRAY)||defined(WIN32)||defined(RISCOS)
-#   include <stddef.h>
-#   include <errno.h>
-#else
-    extern int errno;
-#endif
-#ifdef STDC
-#  include <string.h>
-#  include <stdlib.h>
-#endif
-#endif /* __KERNEL__ */
-#endif /* _KERNEL || KERNEL */
-
-#ifndef local
-#  define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-typedef unsigned char  uch;
-typedef uch FAR uchf;
-typedef unsigned short ush;
-typedef ush FAR ushf;
-typedef unsigned long  ulg;
-
-extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
-/* (size given to avoid silly warnings with Visual C++) */
-
-#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
-
-#define ERR_RETURN(strm,err) \
-  return (strm->msg = (char*)ERR_MSG(err), (err))
-/* To be used only when the state is known to be valid */
-
-        /* common constants */
-
-#ifndef DEF_WBITS
-#  define DEF_WBITS MAX_WBITS
-#endif
-/* default windowBits for decompression. MAX_WBITS is for compression only */
-
-#if MAX_MEM_LEVEL >= 8
-#  define DEF_MEM_LEVEL 8
-#else
-#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
-#endif
-/* default memLevel */
-
-#define STORED_BLOCK 0
-#define STATIC_TREES 1
-#define DYN_TREES    2
-/* The three kinds of block type */
-
-#define MIN_MATCH  3
-#define MAX_MATCH  258
-/* The minimum and maximum match lengths */
-
-#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
-
-        /* target dependencies */
-
-#ifdef MSDOS
-#  define OS_CODE  0x00
-#  ifdef __TURBOC__
-#    include <alloc.h>
-#  else /* MSC or DJGPP */
-#    include <malloc.h>
-#  endif
-#endif
-
-#ifdef OS2
-#  define OS_CODE  0x06
-#endif
-
-#ifdef WIN32 /* Window 95 & Windows NT */
-#  define OS_CODE  0x0b
-#endif
-
-#if defined(VAXC) || defined(VMS)
-#  define OS_CODE  0x02
-#  define FOPEN(name, mode) \
-     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
-#endif
-
-#ifdef AMIGA
-#  define OS_CODE  0x01
-#endif
-
-#if defined(ATARI) || defined(atarist)
-#  define OS_CODE  0x05
-#endif
-
-#ifdef MACOS
-#  define OS_CODE  0x07
-#endif
-
-#ifdef __50SERIES /* Prime/PRIMOS */
-#  define OS_CODE  0x0F
-#endif
-
-#ifdef TOPS20
-#  define OS_CODE  0x0a
-#endif
-
-#if defined(_BEOS_) || defined(RISCOS)
-#  define fdopen(fd,mode) NULL /* No fdopen() */
-#endif
-
-        /* Common defaults */
-
-#ifndef OS_CODE
-#  define OS_CODE  0x03  /* assume Unix */
-#endif
-
-#ifndef FOPEN
-#  define FOPEN(name, mode) fopen((name), (mode))
-#endif
-
-         /* functions */
-
-#ifdef HAVE_STRERROR
-   extern char *strerror OF((int));
-#  define zstrerror(errnum) strerror(errnum)
-#else
-#  define zstrerror(errnum) ""
-#endif
-
-#if defined(pyr)
-#  define NO_MEMCPY
-#endif
-#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(_MSC_VER)
- /* Use our own functions for small and medium model with MSC <= 5.0.
-  * You may have to use the same strategy for Borland C (untested).
-  */
-#  define NO_MEMCPY
-#endif
-#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
-#  define HAVE_MEMCPY
-#endif
-#ifdef HAVE_MEMCPY
-#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
-#    define zmemcpy _fmemcpy
-#    define zmemcmp _fmemcmp
-#    define zmemzero(dest, len) _fmemset(dest, 0, len)
-#  else
-#    define zmemcpy memcpy
-#    define zmemcmp memcmp
-#    define zmemzero(dest, len) memset(dest, 0, len)
-#  endif
-#else
-   extern void zmemcpy  OF((Bytef* dest, Bytef* source, uInt len));
-   extern int  zmemcmp  OF((Bytef* s1,   Bytef* s2, uInt len));
-   extern void zmemzero OF((Bytef* dest, uInt len));
-#endif
-
-/* Diagnostic functions */
-#ifdef DEBUG_ZLIB
-#  include <stdio.h>
-#  ifndef verbose
-#    define verbose 0
-#  endif
-   extern void z_error    OF((char *m));
-#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
-#  define Trace(x) fprintf x
-#  define Tracev(x) {if (verbose) fprintf x ;}
-#  define Tracevv(x) {if (verbose>1) fprintf x ;}
-#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-#  define Assert(cond,msg)
-#  define Trace(x)
-#  define Tracev(x)
-#  define Tracevv(x)
-#  define Tracec(c,x)
-#  define Tracecv(c,x)
-#endif
-
-
-typedef uLong (*check_func) OF((uLong check, const Bytef *buf, uInt len));
-
-voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
-void   zcfree  OF((voidpf opaque, voidpf ptr));
-
-#define ZALLOC(strm, items, size) \
-           (*((strm)->zalloc))((strm)->opaque, (items), (size))
-#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
-#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
-
-#endif /* _Z_UTIL_H */
-/* --- zutil.h */
-
-/* +++ deflate.h */
-/* deflate.h -- internal compression state
- * Copyright (C) 1995-1996 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* From: deflate.h,v 1.10 1996/07/02 12:41:00 me Exp $ */
-
-#ifndef _DEFLATE_H
-#define _DEFLATE_H
-
-/* #include "zutil.h" */
-
-/* ===========================================================================
- * Internal compression state.
- */
-
-#define LENGTH_CODES 29
-/* number of length codes, not counting the special END_BLOCK code */
-
-#define LITERALS  256
-/* number of literal bytes 0..255 */
-
-#define L_CODES (LITERALS+1+LENGTH_CODES)
-/* number of Literal or Length codes, including the END_BLOCK code */
-
-#define D_CODES   30
-/* number of distance codes */
-
-#define BL_CODES  19
-/* number of codes used to transfer the bit lengths */
-
-#define HEAP_SIZE (2*L_CODES+1)
-/* maximum heap size */
-
-#define MAX_BITS 15
-/* All codes must not exceed MAX_BITS bits */
-
-#define INIT_STATE    42
-#define BUSY_STATE   113
-#define FINISH_STATE 666
-/* Stream status */
-
-
-/* Data structure describing a single value and its code string. */
-typedef struct ct_data_s {
-    union {
-        ush  freq;       /* frequency count */
-        ush  code;       /* bit string */
-    } fc;
-    union {
-        ush  dad;        /* father node in Huffman tree */
-        ush  len;        /* length of bit string */
-    } dl;
-} FAR ct_data;
-
-#define Freq fc.freq
-#define Code fc.code
-#define Dad  dl.dad
-#define Len  dl.len
-
-typedef struct static_tree_desc_s  static_tree_desc;
-
-typedef struct tree_desc_s {
-    ct_data *dyn_tree;           /* the dynamic tree */
-    int     max_code;            /* largest code with non zero frequency */
-    static_tree_desc *stat_desc; /* the corresponding static tree */
-} FAR tree_desc;
-
-typedef ush Pos;
-typedef Pos FAR Posf;
-typedef unsigned IPos;
-
-/* A Pos is an index in the character window. We use short instead of int to
- * save space in the various tables. IPos is used only for parameter passing.
- */
-
-typedef struct deflate_state {
-    z_streamp strm;      /* pointer back to this zlib stream */
-    int   status;        /* as the name implies */
-    Bytef *pending_buf;  /* output still pending */
-    ulg   pending_buf_size; /* size of pending_buf */
-    Bytef *pending_out;  /* next pending byte to output to the stream */
-    int   pending;       /* nb of bytes in the pending buffer */
-    int   noheader;      /* suppress zlib header and adler32 */
-    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */
-    Byte  method;        /* STORED (for zip only) or DEFLATED */
-    int   last_flush;    /* value of flush param for previous deflate call */
-
-                /* used by deflate.c: */
-
-    uInt  w_size;        /* LZ77 window size (32K by default) */
-    uInt  w_bits;        /* log2(w_size)  (8..16) */
-    uInt  w_mask;        /* w_size - 1 */
-
-    Bytef *window;
-    /* Sliding window. Input bytes are read into the second half of the window,
-     * and move to the first half later to keep a dictionary of at least wSize
-     * bytes. With this organization, matches are limited to a distance of
-     * wSize-MAX_MATCH bytes, but this ensures that IO is always
-     * performed with a length multiple of the block size. Also, it limits
-     * the window size to 64K, which is quite useful on MSDOS.
-     * To do: use the user input buffer as sliding window.
-     */
-
-    ulg window_size;
-    /* Actual size of window: 2*wSize, except when the user input buffer
-     * is directly used as sliding window.
-     */
-
-    Posf *prev;
-    /* Link to older string with same hash index. To limit the size of this
-     * array to 64K, this link is maintained only for the last 32K strings.
-     * An index in this array is thus a window index modulo 32K.
-     */
-
-    Posf *head; /* Heads of the hash chains or NIL. */
-
-    uInt  ins_h;          /* hash index of string to be inserted */
-    uInt  hash_size;      /* number of elements in hash table */
-    uInt  hash_bits;      /* log2(hash_size) */
-    uInt  hash_mask;      /* hash_size-1 */
-
-    uInt  hash_shift;
-    /* Number of bits by which ins_h must be shifted at each input
-     * step. It must be such that after MIN_MATCH steps, the oldest
-     * byte no longer takes part in the hash key, that is:
-     *   hash_shift * MIN_MATCH >= hash_bits
-     */
-
-    long block_start;
-    /* Window position at the beginning of the current output block. Gets
-     * negative when the window is moved backwards.
-     */
-
-    uInt match_length;           /* length of best match */
-    IPos prev_match;             /* previous match */
-    int match_available;         /* set if previous match exists */
-    uInt strstart;               /* start of string to insert */
-    uInt match_start;            /* start of matching string */
-    uInt lookahead;              /* number of valid bytes ahead in window */
-
-    uInt prev_length;
-    /* Length of the best match at previous step. Matches not greater than this
-     * are discarded. This is used in the lazy match evaluation.
-     */
-
-    uInt max_chain_length;
-    /* To speed up deflation, hash chains are never searched beyond this
-     * length.  A higher limit improves compression ratio but degrades the
-     * speed.
-     */
-
-    uInt max_lazy_match;
-    /* Attempt to find a better match only when the current match is strictly
-     * smaller than this value. This mechanism is used only for compression
-     * levels >= 4.
-     */
-#   define max_insert_length  max_lazy_match
-    /* Insert new strings in the hash table only if the match length is not
-     * greater than this length. This saves time but degrades compression.
-     * max_insert_length is used only for compression levels <= 3.
-     */
-
-    int level;    /* compression level (1..9) */
-    int strategy; /* favor or force Huffman coding*/
-
-    uInt good_match;
-    /* Use a faster search when the previous match is longer than this */
-
-    int nice_match; /* Stop searching when current match exceeds this */
-
-                /* used by trees.c: */
-    /* Didn't use ct_data typedef below to supress compiler warning */
-    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
-    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
-    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
-
-    struct tree_desc_s l_desc;               /* desc. for literal tree */
-    struct tree_desc_s d_desc;               /* desc. for distance tree */
-    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
-
-    ush bl_count[MAX_BITS+1];
-    /* number of codes at each bit length for an optimal tree */
-
-    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
-    int heap_len;               /* number of elements in the heap */
-    int heap_max;               /* element of largest frequency */
-    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
-     * The same heap array is used to build all trees.
-     */
-
-    uch depth[2*L_CODES+1];
-    /* Depth of each subtree used as tie breaker for trees of equal frequency
-     */
-
-    uchf *l_buf;          /* buffer for literals or lengths */
-
-    uInt  lit_bufsize;
-    /* Size of match buffer for literals/lengths.  There are 4 reasons for
-     * limiting lit_bufsize to 64K:
-     *   - frequencies can be kept in 16 bit counters
-     *   - if compression is not successful for the first block, all input
-     *     data is still in the window so we can still emit a stored block even
-     *     when input comes from standard input.  (This can also be done for
-     *     all blocks if lit_bufsize is not greater than 32K.)
-     *   - if compression is not successful for a file smaller than 64K, we can
-     *     even emit a stored file instead of a stored block (saving 5 bytes).
-     *     This is applicable only for zip (not gzip or zlib).
-     *   - creating new Huffman trees less frequently may not provide fast
-     *     adaptation to changes in the input data statistics. (Take for
-     *     example a binary file with poorly compressible code followed by
-     *     a highly compressible string table.) Smaller buffer sizes give
-     *     fast adaptation but have of course the overhead of transmitting
-     *     trees more frequently.
-     *   - I can't count above 4
-     */
-
-    uInt last_lit;      /* running index in l_buf */
-
-    ushf *d_buf;
-    /* Buffer for distances. To simplify the code, d_buf and l_buf have
-     * the same number of elements. To use different lengths, an extra flag
-     * array would be necessary.
-     */
-
-    ulg opt_len;        /* bit length of current block with optimal trees */
-    ulg static_len;     /* bit length of current block with static trees */
-    ulg compressed_len; /* total bit length of compressed file */
-    uInt matches;       /* number of string matches in current block */
-    int last_eob_len;   /* bit length of EOB code for last block */
-
-#ifdef DEBUG_ZLIB
-    ulg bits_sent;      /* bit length of the compressed data */
-#endif
-
-    ush bi_buf;
-    /* Output buffer. bits are inserted starting at the bottom (least
-     * significant bits).
-     */
-    int bi_valid;
-    /* Number of valid bits in bi_buf.  All bits above the last valid bit
-     * are always zero.
-     */
-
-} FAR deflate_state;
-
-/* Output a byte on the stream.
- * IN assertion: there is enough room in pending_buf.
- */
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
-
-
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
-/* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
- */
-
-#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
-/* In order to simplify the code, particularly on 16 bit machines, match
- * distances are limited to MAX_DIST instead of WSIZE.
- */
-
-        /* in trees.c */
-void _tr_init         OF((deflate_state *s));
-int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));
-ulg  _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,
-                         int eof));
-void _tr_align        OF((deflate_state *s));
-void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
-                          int eof));
-void _tr_stored_type_only OF((deflate_state *));
-
-#endif
-/* --- deflate.h */
-
-/* +++ deflate.c */
-/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process depends on being able to identify portions
- *      of the input text which are identical to earlier input (within a
- *      sliding window trailing behind the input currently being processed).
- *
- *      The most straightforward technique turns out to be the fastest for
- *      most input files: try all possible matches and select the longest.
- *      The key feature of this algorithm is that insertions into the string
- *      dictionary are very simple and thus fast, and deletions are avoided
- *      completely. Insertions are performed at each input character, whereas
- *      string matches are performed only when the previous match ends. So it
- *      is preferable to spend more time in matches to allow very fast string
- *      insertions and avoid deletions. The matching algorithm for small
- *      strings is inspired from that of Rabin & Karp. A brute force approach
- *      is used to find longer strings when a small match has been found.
- *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
- *      (by Leonid Broukhis).
- *         A previous version of this file used a more sophisticated algorithm
- *      (by Fiala and Greene) which is guaranteed to run in linear amortized
- *      time, but has a larger average cost, uses more memory and is patented.
- *      However the F&G algorithm may be faster for some highly redundant
- *      files if the parameter max_chain_length (described below) is too large.
- *
- *  ACKNOWLEDGEMENTS
- *
- *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
- *      I found it in 'freeze' written by Leonid Broukhis.
- *      Thanks to many people for bug reports and testing.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
- *      Available in ftp://ds.internic.net/rfc/rfc1951.txt
- *
- *      A description of the Rabin and Karp algorithm is given in the book
- *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
- *
- *      Fiala,E.R., and Greene,D.H.
- *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
- *
- */
-
-/* From: deflate.c,v 1.15 1996/07/24 13:40:58 me Exp $ */
-
-/* #include "deflate.h" */
-
-char deflate_copyright[] = " deflate 1.0.4 Copyright 1995-1996 Jean-loup Gailly ";
-/*
-  If you use the zlib library in a product, an acknowledgment is welcome
-  in the documentation of your product. If for some reason you cannot
-  include such an acknowledgment, I would appreciate that you keep this
-  copyright string in the executable of your product.
- */
-
-/* ===========================================================================
- *  Function prototypes.
- */
-typedef enum {
-    need_more,      /* block not completed, need more input or more output */
-    block_done,     /* block flush performed */
-    finish_started, /* finish started, need only more output at next deflate */
-    finish_done     /* finish done, accept no more input or output */
-} block_state;
-
-typedef block_state (*compress_func) OF((deflate_state *s, int flush));
-/* Compression function. Returns the block state after the call. */
-
-local void fill_window    OF((deflate_state *s));
-local block_state deflate_stored OF((deflate_state *s, int flush));
-local block_state deflate_fast   OF((deflate_state *s, int flush));
-local block_state deflate_slow   OF((deflate_state *s, int flush));
-local void lm_init        OF((deflate_state *s));
-local void putShortMSB    OF((deflate_state *s, uInt b));
-local void flush_pending  OF((z_streamp strm));
-local int read_buf        OF((z_streamp strm, charf *buf, unsigned size));
-#ifdef ASMV
-      void match_init OF((void)); /* asm code initialization */
-      uInt longest_match  OF((deflate_state *s, IPos cur_match));
-#else
-local uInt longest_match  OF((deflate_state *s, IPos cur_match));
-#endif
-
-#ifdef DEBUG_ZLIB
-local  void check_match OF((deflate_state *s, IPos start, IPos match,
-                            int length));
-#endif
-
-/* ===========================================================================
- * Local data
- */
-
-#define NIL 0
-/* Tail of hash chains */
-
-#ifndef TOO_FAR
-#  define TOO_FAR 4096
-#endif
-/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
-
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
-/* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
- */
-
-/* Values for max_lazy_match, good_match and max_chain_length, depending on
- * the desired pack level (0..9). The values given below have been tuned to
- * exclude worst case performance for pathological files. Better values may be
- * found for specific files.
- */
-typedef struct config_s {
-   ush good_length; /* reduce lazy search above this match length */
-   ush max_lazy;    /* do not perform lazy search above this match length */
-   ush nice_length; /* quit search above this match length */
-   ush max_chain;
-   compress_func func;
-} config;
-
-local config configuration_table[10] = {
-/*      good lazy nice chain */
-/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
-/* 1 */ {4,    4,  8,    4, deflate_fast}, /* maximum speed, no lazy matches */
-/* 2 */ {4,    5, 16,    8, deflate_fast},
-/* 3 */ {4,    6, 32,   32, deflate_fast},
-
-/* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
-/* 5 */ {8,   16, 32,   32, deflate_slow},
-/* 6 */ {8,   16, 128, 128, deflate_slow},
-/* 7 */ {8,   32, 128, 256, deflate_slow},
-/* 8 */ {32, 128, 258, 1024, deflate_slow},
-/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
-
-/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
- * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
- * meaning.
- */
-
-#define EQUAL 0
-/* result of memcmp for equal strings */
-
-#ifndef NO_DUMMY_DECL
-struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
-#endif
-
-/* ===========================================================================
- * Update a hash value with the given input byte
- * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
- *    input characters, so that a running hash key can be computed from the
- *    previous key instead of complete recalculation each time.
- */
-#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
-
-
-/* ===========================================================================
- * Insert string str in the dictionary and set match_head to the previous head
- * of the hash chain (the most recent string with same hash key). Return
- * the previous length of the hash chain.
- * IN  assertion: all calls to to INSERT_STRING are made with consecutive
- *    input characters and the first MIN_MATCH bytes of str are valid
- *    (except for the last MIN_MATCH-1 bytes of the input file).
- */
-#define INSERT_STRING(s, str, match_head) \
-   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
-    s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
-    s->head[s->ins_h] = (Pos)(str))
-
-/* ===========================================================================
- * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
- * prev[] will be initialized on the fly.
- */
-#define CLEAR_HASH(s) \
-    s->head[s->hash_size-1] = NIL; \
-    zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
-
-/* ========================================================================= */
-int deflateInit_(strm, level, version, stream_size)
-    z_streamp strm;
-    int level;
-    const char *version;
-    int stream_size;
-{
-    return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
-                        Z_DEFAULT_STRATEGY, version, stream_size);
-    /* To do: ignore strm->next_in if we use it as window */
-}
-
-/* ========================================================================= */
-int deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
-                 version, stream_size)
-    z_streamp strm;
-    int  level;
-    int  method;
-    int  windowBits;
-    int  memLevel;
-    int  strategy;
-    const char *version;
-    int stream_size;
-{
-    deflate_state *s;
-    int noheader = 0;
-    static char* my_version = ZLIB_VERSION;
-
-    ushf *overlay;
-    /* We overlay pending_buf and d_buf+l_buf. This works since the average
-     * output size for (length,distance) codes is <= 24 bits.
-     */
-
-    if (version == Z_NULL || version[0] != my_version[0] ||
-        stream_size != sizeof(z_stream)) {
-       return Z_VERSION_ERROR;
-    }
-    if (strm == Z_NULL) return Z_STREAM_ERROR;
-
-    strm->msg = Z_NULL;
-#ifndef NO_ZCFUNCS
-    if (strm->zalloc == Z_NULL) {
-       strm->zalloc = zcalloc;
-       strm->opaque = (voidpf)0;
-    }
-    if (strm->zfree == Z_NULL) strm->zfree = zcfree;
-#endif
-
-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
-
-    if (windowBits < 0) { /* undocumented feature: suppress zlib header */
-        noheader = 1;
-        windowBits = -windowBits;
-    }
-    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
-        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
-       strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
-        return Z_STREAM_ERROR;
-    }
-    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
-    if (s == Z_NULL) return Z_MEM_ERROR;
-    strm->state = (struct internal_state FAR *)s;
-    s->strm = strm;
-
-    s->noheader = noheader;
-    s->w_bits = windowBits;
-    s->w_size = 1 << s->w_bits;
-    s->w_mask = s->w_size - 1;
-
-    s->hash_bits = memLevel + 7;
-    s->hash_size = 1 << s->hash_bits;
-    s->hash_mask = s->hash_size - 1;
-    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-
-    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
-    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
-    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
-
-    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
-
-    overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
-    s->pending_buf = (uchf *) overlay;
-    s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
-
-    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
-        s->pending_buf == Z_NULL) {
-        strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
-        deflateEnd (strm);
-        return Z_MEM_ERROR;
-    }
-    s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
-    s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
-
-    s->level = level;
-    s->strategy = strategy;
-    s->method = (Byte)method;
-
-    return deflateReset(strm);
-}
-
-/* ========================================================================= */
-int deflateSetDictionary (strm, dictionary, dictLength)
-    z_streamp strm;
-    const Bytef *dictionary;
-    uInt  dictLength;
-{
-    deflate_state *s;
-    uInt length = dictLength;
-    uInt n;
-    IPos hash_head = 0;
-
-    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
-       return Z_STREAM_ERROR;
-
-    s = (deflate_state *) strm->state;
-    if (s->status != INIT_STATE) return Z_STREAM_ERROR;
-
-    strm->adler = adler32(strm->adler, dictionary, dictLength);
-
-    if (length < MIN_MATCH) return Z_OK;
-    if (length > MAX_DIST(s)) {
-       length = MAX_DIST(s);
-#ifndef USE_DICT_HEAD
-       dictionary += dictLength - length; /* use the tail of the dictionary */
-#endif
-    }
-    zmemcpy((charf *)s->window, dictionary, length);
-    s->strstart = length;
-    s->block_start = (long)length;
-
-    /* Insert all strings in the hash table (except for the last two bytes).
-     * s->lookahead stays null, so s->ins_h will be recomputed at the next
-     * call of fill_window.
-     */
-    s->ins_h = s->window[0];
-    UPDATE_HASH(s, s->ins_h, s->window[1]);
-    for (n = 0; n <= length - MIN_MATCH; n++) {
-       INSERT_STRING(s, n, hash_head);
-    }
-    if (hash_head) hash_head = 0;  /* to make compiler happy */
-    return Z_OK;
-}
-
-/* ========================================================================= */
-int deflateReset (strm)
-    z_streamp strm;
-{
-    deflate_state *s;
-    
-    if (strm == Z_NULL || strm->state == Z_NULL ||
-        strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
-
-    strm->total_in = strm->total_out = 0;
-    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
-    strm->data_type = Z_UNKNOWN;
-
-    s = (deflate_state *)strm->state;
-    s->pending = 0;
-    s->pending_out = s->pending_buf;
-
-    if (s->noheader < 0) {
-        s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
-    }
-    s->status = s->noheader ? BUSY_STATE : INIT_STATE;
-    strm->adler = 1;
-    s->last_flush = Z_NO_FLUSH;
-
-    _tr_init(s);
-    lm_init(s);
-
-    return Z_OK;
-}
-
-/* ========================================================================= */
-int deflateParams(strm, level, strategy)
-    z_streamp strm;
-    int level;
-    int strategy;
-{
-    deflate_state *s;
-    compress_func func;
-    int err = Z_OK;
-
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    s = (deflate_state *) strm->state;
-
-    if (level == Z_DEFAULT_COMPRESSION) {
-       level = 6;
-    }
-    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
-       return Z_STREAM_ERROR;
-    }
-    func = configuration_table[s->level].func;
-
-    if (func != configuration_table[level].func && strm->total_in != 0) {
-       /* Flush the last buffer: */
-       err = deflate(strm, Z_PARTIAL_FLUSH);
-    }
-    if (s->level != level) {
-       s->level = level;
-       s->max_lazy_match   = configuration_table[level].max_lazy;
-       s->good_match       = configuration_table[level].good_length;
-       s->nice_match       = configuration_table[level].nice_length;
-       s->max_chain_length = configuration_table[level].max_chain;
-    }
-    s->strategy = strategy;
-    return err;
-}
-
-/* =========================================================================
- * Put a short in the pending buffer. The 16-bit value is put in MSB order.
- * IN assertion: the stream state is correct and there is enough room in
- * pending_buf.
- */
-local void putShortMSB (s, b)
-    deflate_state *s;
-    uInt b;
-{
-    put_byte(s, (Byte)(b >> 8));
-    put_byte(s, (Byte)(b & 0xff));
-}   
-
-/* =========================================================================
- * Flush as much pending output as possible. All deflate() output goes
- * through this function so some applications may wish to modify it
- * to avoid allocating a large strm->next_out buffer and copying into it.
- * (See also read_buf()).
- */
-local void flush_pending(strm)
-    z_streamp strm;
-{
-    deflate_state *s = (deflate_state *) strm->state;
-    unsigned len = s->pending;
-
-    if (len > strm->avail_out) len = strm->avail_out;
-    if (len == 0) return;
-
-    if (strm->next_out != Z_NULL) {
-       zmemcpy(strm->next_out, s->pending_out, len);
-       strm->next_out += len;
-    }
-    s->pending_out += len;
-    strm->total_out += len;
-    strm->avail_out  -= len;
-    s->pending -= len;
-    if (s->pending == 0) {
-        s->pending_out = s->pending_buf;
-    }
-}
-
-/* ========================================================================= */
-int deflate (strm, flush)
-    z_streamp strm;
-    int flush;
-{
-    int old_flush; /* value of flush param for previous deflate call */
-    deflate_state *s;
-
-    if (strm == Z_NULL || strm->state == Z_NULL ||
-       flush > Z_FINISH || flush < 0) {
-        return Z_STREAM_ERROR;
-    }
-    s = (deflate_state *) strm->state;
-
-    if ((strm->next_in == Z_NULL && strm->avail_in != 0) ||
-       (s->status == FINISH_STATE && flush != Z_FINISH)) {
-        ERR_RETURN(strm, Z_STREAM_ERROR);
-    }
-    if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
-
-    s->strm = strm; /* just in case */
-    old_flush = s->last_flush;
-    s->last_flush = flush;
-
-    /* Write the zlib header */
-    if (s->status == INIT_STATE) {
-
-        uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
-        uInt level_flags = (s->level-1) >> 1;
-
-        if (level_flags > 3) level_flags = 3;
-        header |= (level_flags << 6);
-       if (s->strstart != 0) header |= PRESET_DICT;
-        header += 31 - (header % 31);
-
-        s->status = BUSY_STATE;
-        putShortMSB(s, header);
-
-       /* Save the adler32 of the preset dictionary: */
-       if (s->strstart != 0) {
-           putShortMSB(s, (uInt)(strm->adler >> 16));
-           putShortMSB(s, (uInt)(strm->adler & 0xffff));
-       }
-       strm->adler = 1L;
-    }
-
-    /* Flush as much pending output as possible */
-    if (s->pending != 0) {
-        flush_pending(strm);
-        if (strm->avail_out == 0) {
-           /* Since avail_out is 0, deflate will be called again with
-            * more output space, but possibly with both pending and
-            * avail_in equal to zero. There won't be anything to do,
-            * but this is not an error situation so make sure we
-            * return OK instead of BUF_ERROR at next call of deflate:
-             */
-           s->last_flush = -1;
-           return Z_OK;
-       }
-
-    /* Make sure there is something to do and avoid duplicate consecutive
-     * flushes. For repeated and useless calls with Z_FINISH, we keep
-     * returning Z_STREAM_END instead of Z_BUFF_ERROR.
-     */
-    } else if (strm->avail_in == 0 && flush <= old_flush &&
-              flush != Z_FINISH) {
-        ERR_RETURN(strm, Z_BUF_ERROR);
-    }
-
-    /* User must not provide more input after the first FINISH: */
-    if (s->status == FINISH_STATE && strm->avail_in != 0) {
-        ERR_RETURN(strm, Z_BUF_ERROR);
-    }
-
-    /* Start a new block or continue the current one.
-     */
-    if (strm->avail_in != 0 || s->lookahead != 0 ||
-        (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
-        block_state bstate;
-
-       bstate = (*(configuration_table[s->level].func))(s, flush);
-
-        if (bstate == finish_started || bstate == finish_done) {
-            s->status = FINISH_STATE;
-        }
-        if (bstate == need_more || bstate == finish_started) {
-           if (strm->avail_out == 0) {
-               s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
-           }
-           return Z_OK;
-           /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
-            * of deflate should use the same flush parameter to make sure
-            * that the flush is complete. So we don't have to output an
-            * empty block here, this will be done at next call. This also
-            * ensures that for a very small output buffer, we emit at most
-            * one empty block.
-            */
-       }
-        if (bstate == block_done) {
-            if (flush == Z_PARTIAL_FLUSH) {
-                _tr_align(s);
-           } else if (flush == Z_PACKET_FLUSH) {
-               /* Output just the 3-bit `stored' block type value,
-                  but not a zero length. */
-               _tr_stored_type_only(s);
-            } else { /* FULL_FLUSH or SYNC_FLUSH */
-                _tr_stored_block(s, (char*)0, 0L, 0);
-                /* For a full flush, this empty block will be recognized
-                 * as a special marker by inflate_sync().
-                 */
-                if (flush == Z_FULL_FLUSH) {
-                    CLEAR_HASH(s);             /* forget history */
-                }
-            }
-            flush_pending(strm);
-           if (strm->avail_out == 0) {
-             s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
-             return Z_OK;
-           }
-        }
-    }
-    Assert(strm->avail_out > 0, "bug2");
-
-    if (flush != Z_FINISH) return Z_OK;
-    if (s->noheader) return Z_STREAM_END;
-
-    /* Write the zlib trailer (adler32) */
-    putShortMSB(s, (uInt)(strm->adler >> 16));
-    putShortMSB(s, (uInt)(strm->adler & 0xffff));
-    flush_pending(strm);
-    /* If avail_out is zero, the application will call deflate again
-     * to flush the rest.
-     */
-    s->noheader = -1; /* write the trailer only once! */
-    return s->pending != 0 ? Z_OK : Z_STREAM_END;
-}
-
-/* ========================================================================= */
-int deflateEnd (strm)
-    z_streamp strm;
-{
-    int status;
-    deflate_state *s;
-
-    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
-    s = (deflate_state *) strm->state;
-
-    status = s->status;
-    if (status != INIT_STATE && status != BUSY_STATE &&
-       status != FINISH_STATE) {
-      return Z_STREAM_ERROR;
-    }
-
-    /* Deallocate in reverse order of allocations: */
-    TRY_FREE(strm, s->pending_buf);
-    TRY_FREE(strm, s->head);
-    TRY_FREE(strm, s->prev);
-    TRY_FREE(strm, s->window);
-
-    ZFREE(strm, s);
-    strm->state = Z_NULL;
-
-    return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
-}
-
-/* =========================================================================
- * Copy the source state to the destination state.
- */
-int deflateCopy (dest, source)
-    z_streamp dest;
-    z_streamp source;
-{
-    deflate_state *ds;
-    deflate_state *ss;
-    ushf *overlay;
-
-    if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL)
-        return Z_STREAM_ERROR;
-    ss = (deflate_state *) source->state;
-
-    zmemcpy(dest, source, sizeof(*dest));
-
-    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
-    if (ds == Z_NULL) return Z_MEM_ERROR;
-    dest->state = (struct internal_state FAR *) ds;
-    zmemcpy(ds, ss, sizeof(*ds));
-    ds->strm = dest;
-
-    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
-    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
-    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
-    overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
-    ds->pending_buf = (uchf *) overlay;
-
-    if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
-        ds->pending_buf == Z_NULL) {
-        deflateEnd (dest);
-        return Z_MEM_ERROR;
-    }
-    /* ??? following zmemcpy doesn't work for 16-bit MSDOS */
-    zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
-    zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
-    zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
-    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
-
-    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
-    ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
-    ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
-
-    ds->l_desc.dyn_tree = ds->dyn_ltree;
-    ds->d_desc.dyn_tree = ds->dyn_dtree;
-    ds->bl_desc.dyn_tree = ds->bl_tree;
-
-    return Z_OK;
-}
-
-/* ===========================================================================
- * Return the number of bytes of output which are immediately available
- * for output from the decompressor.
- */
-int deflateOutputPending (strm)
-    z_streamp strm;
-{
-    if (strm == Z_NULL || strm->state == Z_NULL) return 0;
-    
-    return ((deflate_state *)(strm->state))->pending;
-}
-
-/* ===========================================================================
- * Read a new buffer from the current input stream, update the adler32
- * and total number of bytes read.  All deflate() input goes through
- * this function so some applications may wish to modify it to avoid
- * allocating a large strm->next_in buffer and copying from it.
- * (See also flush_pending()).
- */
-local int read_buf(strm, buf, size)
-    z_streamp strm;
-    charf *buf;
-    unsigned size;
-{
-    unsigned len = strm->avail_in;
-
-    if (len > size) len = size;
-    if (len == 0) return 0;
-
-    strm->avail_in  -= len;
-
-    if (!((deflate_state *)(strm->state))->noheader) {
-        strm->adler = adler32(strm->adler, strm->next_in, len);
-    }
-    zmemcpy(buf, strm->next_in, len);
-    strm->next_in  += len;
-    strm->total_in += len;
-
-    return (int)len;
-}
-
-/* ===========================================================================
- * Initialize the "longest match" routines for a new zlib stream
- */
-local void lm_init (s)
-    deflate_state *s;
-{
-    s->window_size = (ulg)2L*s->w_size;
-
-    CLEAR_HASH(s);
-
-    /* Set the default configuration parameters:
-     */
-    s->max_lazy_match   = configuration_table[s->level].max_lazy;
-    s->good_match       = configuration_table[s->level].good_length;
-    s->nice_match       = configuration_table[s->level].nice_length;
-    s->max_chain_length = configuration_table[s->level].max_chain;
-
-    s->strstart = 0;
-    s->block_start = 0L;
-    s->lookahead = 0;
-    s->match_length = s->prev_length = MIN_MATCH-1;
-    s->match_available = 0;
-    s->ins_h = 0;
-#ifdef ASMV
-    match_init(); /* initialize the asm code */
-#endif
-}
-
-/* ===========================================================================
- * Set match_start to the longest match starting at the given string and
- * return its length. Matches shorter or equal to prev_length are discarded,
- * in which case the result is equal to prev_length and match_start is
- * garbage.
- * IN assertions: cur_match is the head of the hash chain for the current
- *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
- * OUT assertion: the match length is not greater than s->lookahead.
- */
-#ifndef ASMV
-/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
- * match.S. The code will be functionally equivalent.
- */
-local uInt longest_match(s, cur_match)
-    deflate_state *s;
-    IPos cur_match;                             /* current match */
-{
-    unsigned chain_length = s->max_chain_length;/* max hash chain length */
-    register Bytef *scan = s->window + s->strstart; /* current string */
-    register Bytef *match;                       /* matched string */
-    register int len;                           /* length of current match */
-    int best_len = s->prev_length;              /* best match length so far */
-    int nice_match = s->nice_match;             /* stop if match long enough */
-    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-        s->strstart - (IPos)MAX_DIST(s) : NIL;
-    /* Stop when cur_match becomes <= limit. To simplify the code,
-     * we prevent matches with the string of window index 0.
-     */
-    Posf *prev = s->prev;
-    uInt wmask = s->w_mask;
-
-#ifdef UNALIGNED_OK
-    /* Compare two bytes at a time. Note: this is not always beneficial.
-     * Try with and without -DUNALIGNED_OK to check.
-     */
-    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
-    register ush scan_start = *(ushf*)scan;
-    register ush scan_end   = *(ushf*)(scan+best_len-1);
-#else
-    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
-    register Byte scan_end1  = scan[best_len-1];
-    register Byte scan_end   = scan[best_len];
-#endif
-
-    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
-     * It is easy to get rid of this optimization if necessary.
-     */
-    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
-    /* Do not waste too much time if we already have a good match: */
-    if (s->prev_length >= s->good_match) {
-        chain_length >>= 2;
-    }
-    /* Do not look for matches beyond the end of the input. This is necessary
-     * to make deflate deterministic.
-     */
-    if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
-
-    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
-    do {
-        Assert(cur_match < s->strstart, "no future");
-        match = s->window + cur_match;
-
-        /* Skip to next match if the match length cannot increase
-         * or if the match length is less than 2:
-         */
-#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
-        /* This code assumes sizeof(unsigned short) == 2. Do not use
-         * UNALIGNED_OK if your compiler uses a different size.
-         */
-        if (*(ushf*)(match+best_len-1) != scan_end ||
-            *(ushf*)match != scan_start) continue;
-
-        /* It is not necessary to compare scan[2] and match[2] since they are
-         * always equal when the other bytes match, given that the hash keys
-         * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
-         * strstart+3, +5, ... up to strstart+257. We check for insufficient
-         * lookahead only every 4th comparison; the 128th check will be made
-         * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
-         * necessary to put more guard bytes at the end of the window, or
-         * to check more often for insufficient lookahead.
-         */
-        Assert(scan[2] == match[2], "scan[2]?");
-        scan++, match++;
-        do {
-        } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 scan < strend);
-        /* The funny "do {}" generates better code on most compilers */
-
-        /* Here, scan <= window+strstart+257 */
-        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-        if (*scan == *match) scan++;
-
-        len = (MAX_MATCH - 1) - (int)(strend-scan);
-        scan = strend - (MAX_MATCH-1);
-
-#else /* UNALIGNED_OK */
-
-        if (match[best_len]   != scan_end  ||
-            match[best_len-1] != scan_end1 ||
-            *match            != *scan     ||
-            *++match          != scan[1])      continue;
-
-        /* The check at best_len-1 can be removed because it will be made
-         * again later. (This heuristic is not always a win.)
-         * It is not necessary to compare scan[2] and match[2] since they
-         * are always equal when the other bytes match, given that
-         * the hash keys are equal and that HASH_BITS >= 8.
-         */
-        scan += 2, match++;
-        Assert(*scan == *match, "match[2]?");
-
-        /* We check for insufficient lookahead only every 8th comparison;
-         * the 256th check will be made at strstart+258.
-         */
-        do {
-        } while (*++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 scan < strend);
-
-        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
-        len = MAX_MATCH - (int)(strend - scan);
-        scan = strend - MAX_MATCH;
-
-#endif /* UNALIGNED_OK */
-
-        if (len > best_len) {
-            s->match_start = cur_match;
-            best_len = len;
-            if (len >= nice_match) break;
-#ifdef UNALIGNED_OK
-            scan_end = *(ushf*)(scan+best_len-1);
-#else
-            scan_end1  = scan[best_len-1];
-            scan_end   = scan[best_len];
-#endif
-        }
-    } while ((cur_match = prev[cur_match & wmask]) > limit
-             && --chain_length != 0);
-
-    if ((uInt)best_len <= s->lookahead) return best_len;
-    return s->lookahead;
-}
-#endif /* ASMV */
-
-#ifdef DEBUG_ZLIB
-/* ===========================================================================
- * Check that the match at match_start is indeed a match.
- */
-local void check_match(s, start, match, length)
-    deflate_state *s;
-    IPos start, match;
-    int length;
-{
-    /* check that the match is indeed a match */
-    if (zmemcmp((charf *)s->window + match,
-                (charf *)s->window + start, length) != EQUAL) {
-        fprintf(stderr, " start %u, match %u, length %d\n",
-               start, match, length);
-        do {
-           fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
-       } while (--length != 0);
-        z_error("invalid match");
-    }
-    if (z_verbose > 1) {
-        fprintf(stderr,"\\[%d,%d]", start-match, length);
-        do { putc(s->window[start++], stderr); } while (--length != 0);
-    }
-}
-#else
-#  define check_match(s, start, match, length)
-#endif
-
-/* ===========================================================================
- * Fill the window when the lookahead becomes insufficient.
- * Updates strstart and lookahead.
- *
- * IN assertion: lookahead < MIN_LOOKAHEAD
- * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
- *    At least one byte has been read, or avail_in == 0; reads are
- *    performed for at least two bytes (required for the zip translate_eol
- *    option -- not supported here).
- */
-local void fill_window(s)
-    deflate_state *s;
-{
-    register unsigned n, m;
-    register Posf *p;
-    unsigned more;    /* Amount of free space at the end of the window. */
-    uInt wsize = s->w_size;
-
-    do {
-        more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
-
-        /* Deal with !@#$% 64K limit: */
-        if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
-            more = wsize;
-
-        } else if (more == (unsigned)(-1)) {
-            /* Very unlikely, but possible on 16 bit machine if strstart == 0
-             * and lookahead == 1 (input done one byte at time)
-             */
-            more--;
-
-        /* If the window is almost full and there is insufficient lookahead,
-         * move the upper half to the lower one to make room in the upper half.
-         */
-        } else if (s->strstart >= wsize+MAX_DIST(s)) {
-
-            zmemcpy((charf *)s->window, (charf *)s->window+wsize,
-                   (unsigned)wsize);
-            s->match_start -= wsize;
-            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
-            s->block_start -= (long) wsize;
-
-            /* Slide the hash table (could be avoided with 32 bit values
-               at the expense of memory usage). We slide even when level == 0
-               to keep the hash table consistent if we switch back to level > 0
-               later. (Using level 0 permanently is not an optimal usage of
-               zlib, so we don't care about this pathological case.)
-             */
-            n = s->hash_size;
-            p = &s->head[n];
-            do {
-                m = *--p;
-                *p = (Pos)(m >= wsize ? m-wsize : NIL);
-            } while (--n);
-
-            n = wsize;
-            p = &s->prev[n];
-            do {
-                m = *--p;
-                *p = (Pos)(m >= wsize ? m-wsize : NIL);
-                /* If n is not on any hash chain, prev[n] is garbage but
-                 * its value will never be used.
-                 */
-            } while (--n);
-            more += wsize;
-        }
-        if (s->strm->avail_in == 0) return;
-
-        /* If there was no sliding:
-         *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
-         *    more == window_size - lookahead - strstart
-         * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
-         * => more >= window_size - 2*WSIZE + 2
-         * In the BIG_MEM or MMAP case (not yet supported),
-         *   window_size == input_size + MIN_LOOKAHEAD  &&
-         *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
-         * Otherwise, window_size == 2*WSIZE so more >= 2.
-         * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
-         */
-        Assert(more >= 2, "more < 2");
-
-        n = read_buf(s->strm, (charf *)s->window + s->strstart + s->lookahead,
-                     more);
-        s->lookahead += n;
-
-        /* Initialize the hash value now that we have some input: */
-        if (s->lookahead >= MIN_MATCH) {
-            s->ins_h = s->window[s->strstart];
-            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
-#if MIN_MATCH != 3
-            Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-        }
-        /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
-         * but this is not important since only literal bytes will be emitted.
-         */
-
-    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
-}
-
-/* ===========================================================================
- * Flush the current block, with given end-of-file flag.
- * IN assertion: strstart is set to the end of the current match.
- */
-#define FLUSH_BLOCK_ONLY(s, eof) { \
-   _tr_flush_block(s, (s->block_start >= 0L ? \
-                   (charf *)&s->window[(unsigned)s->block_start] : \
-                   (charf *)Z_NULL), \
-               (ulg)((long)s->strstart - s->block_start), \
-               (eof)); \
-   s->block_start = s->strstart; \
-   flush_pending(s->strm); \
-   Tracev((stderr,"[FLUSH]")); \
-}
-
-/* Same but force premature exit if necessary. */
-#define FLUSH_BLOCK(s, eof) { \
-   FLUSH_BLOCK_ONLY(s, eof); \
-   if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
-}
-
-/* ===========================================================================
- * Copy without compression as much as possible from the input stream, return
- * the current block state.
- * This function does not insert new strings in the dictionary since
- * uncompressible data is probably not useful. This function is used
- * only for the level=0 compression option.
- * NOTE: this function should be optimized to avoid extra copying from
- * window to pending_buf.
- */
-local block_state deflate_stored(s, flush)
-    deflate_state *s;
-    int flush;
-{
-    /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
-     * to pending_buf_size, and each stored block has a 5 byte header:
-     */
-    ulg max_block_size = 0xffff;
-    ulg max_start;
-
-    if (max_block_size > s->pending_buf_size - 5) {
-        max_block_size = s->pending_buf_size - 5;
-    }
-
-    /* Copy as much as possible from input to output: */
-    for (;;) {
-        /* Fill the window as much as possible: */
-        if (s->lookahead <= 1) {
-
-            Assert(s->strstart < s->w_size+MAX_DIST(s) ||
-                  s->block_start >= (long)s->w_size, "slide too late");
-
-            fill_window(s);
-            if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
-
-            if (s->lookahead == 0) break; /* flush the current block */
-        }
-       Assert(s->block_start >= 0L, "block gone");
-
-       s->strstart += s->lookahead;
-       s->lookahead = 0;
-
-       /* Emit a stored block if pending_buf will be full: */
-       max_start = s->block_start + max_block_size;
-        if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
-           /* strstart == 0 is possible when wraparound on 16-bit machine */
-           s->lookahead = (uInt)(s->strstart - max_start);
-           s->strstart = (uInt)max_start;
-            FLUSH_BLOCK(s, 0);
-       }
-       /* Flush if we may have to slide, otherwise block_start may become
-         * negative and the data will be gone:
-         */
-        if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
-            FLUSH_BLOCK(s, 0);
-       }
-    }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
-}
-
-/* ===========================================================================
- * Compress as much as possible from the input stream, return the current
- * block state.
- * This function does not perform lazy evaluation of matches and inserts
- * new strings in the dictionary only for unmatched strings or for short
- * matches. It is used only for the fast compression options.
- */
-local block_state deflate_fast(s, flush)
-    deflate_state *s;
-    int flush;
-{
-    IPos hash_head = NIL; /* head of the hash chain */
-    int bflush;           /* set if current block must be flushed */
-
-    for (;;) {
-        /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
-         * string following the next match.
-         */
-        if (s->lookahead < MIN_LOOKAHEAD) {
-            fill_window(s);
-            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
-               return need_more;
-           }
-            if (s->lookahead == 0) break; /* flush the current block */
-        }
-
-        /* Insert the string window[strstart .. strstart+2] in the
-         * dictionary, and set hash_head to the head of the hash chain:
-         */
-        if (s->lookahead >= MIN_MATCH) {
-            INSERT_STRING(s, s->strstart, hash_head);
-        }
-
-        /* Find the longest match, discarding those <= prev_length.
-         * At this point we have always match_length < MIN_MATCH
-         */
-        if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
-            /* To simplify the code, we prevent matches with the string
-             * of window index 0 (in particular we have to avoid a match
-             * of the string with itself at the start of the input file).
-             */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
-                s->match_length = longest_match (s, hash_head);
-            }
-            /* longest_match() sets match_start */
-        }
-        if (s->match_length >= MIN_MATCH) {
-            check_match(s, s->strstart, s->match_start, s->match_length);
-
-            bflush = _tr_tally(s, s->strstart - s->match_start,
-                               s->match_length - MIN_MATCH);
-
-            s->lookahead -= s->match_length;
-
-            /* Insert new strings in the hash table only if the match length
-             * is not too large. This saves time but degrades compression.
-             */
-            if (s->match_length <= s->max_insert_length &&
-                s->lookahead >= MIN_MATCH) {
-                s->match_length--; /* string at strstart already in hash table */
-                do {
-                    s->strstart++;
-                    INSERT_STRING(s, s->strstart, hash_head);
-                    /* strstart never exceeds WSIZE-MAX_MATCH, so there are
-                     * always MIN_MATCH bytes ahead.
-                     */
-                } while (--s->match_length != 0);
-                s->strstart++; 
-            } else {
-                s->strstart += s->match_length;
-                s->match_length = 0;
-                s->ins_h = s->window[s->strstart];
-                UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
-#if MIN_MATCH != 3
-                Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
-                 * matter since it will be recomputed at next deflate call.
-                 */
-            }
-        } else {
-            /* No match, output a literal byte */
-            Tracevv((stderr,"%c", s->window[s->strstart]));
-            bflush = _tr_tally (s, 0, s->window[s->strstart]);
-            s->lookahead--;
-            s->strstart++; 
-        }
-        if (bflush) FLUSH_BLOCK(s, 0);
-    }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
-}
-
-/* ===========================================================================
- * Same as above, but achieves better compression. We use a lazy
- * evaluation for matches: a match is finally adopted only if there is
- * no better match at the next window position.
- */
-local block_state deflate_slow(s, flush)
-    deflate_state *s;
-    int flush;
-{
-    IPos hash_head = NIL;    /* head of hash chain */
-    int bflush;              /* set if current block must be flushed */
-
-    /* Process the input block. */
-    for (;;) {
-        /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
-         * string following the next match.
-         */
-        if (s->lookahead < MIN_LOOKAHEAD) {
-            fill_window(s);
-            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
-               return need_more;
-           }
-            if (s->lookahead == 0) break; /* flush the current block */
-        }
-
-        /* Insert the string window[strstart .. strstart+2] in the
-         * dictionary, and set hash_head to the head of the hash chain:
-         */
-        if (s->lookahead >= MIN_MATCH) {
-            INSERT_STRING(s, s->strstart, hash_head);
-        }
-
-        /* Find the longest match, discarding those <= prev_length.
-         */
-        s->prev_length = s->match_length, s->prev_match = s->match_start;
-        s->match_length = MIN_MATCH-1;
-
-        if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
-            s->strstart - hash_head <= MAX_DIST(s)) {
-            /* To simplify the code, we prevent matches with the string
-             * of window index 0 (in particular we have to avoid a match
-             * of the string with itself at the start of the input file).
-             */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
-                s->match_length = longest_match (s, hash_head);
-            }
-            /* longest_match() sets match_start */
-
-            if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
-                 (s->match_length == MIN_MATCH &&
-                  s->strstart - s->match_start > TOO_FAR))) {
-
-                /* If prev_match is also MIN_MATCH, match_start is garbage
-                 * but we will ignore the current match anyway.
-                 */
-                s->match_length = MIN_MATCH-1;
-            }
-        }
-        /* If there was a match at the previous step and the current
-         * match is not better, output the previous match:
-         */
-        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
-            uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
-            /* Do not insert strings in hash table beyond this. */
-
-            check_match(s, s->strstart-1, s->prev_match, s->prev_length);
-
-            bflush = _tr_tally(s, s->strstart -1 - s->prev_match,
-                               s->prev_length - MIN_MATCH);
-
-            /* Insert in hash table all strings up to the end of the match.
-             * strstart-1 and strstart are already inserted. If there is not
-             * enough lookahead, the last two strings are not inserted in
-             * the hash table.
-             */
-            s->lookahead -= s->prev_length-1;
-            s->prev_length -= 2;
-            do {
-                if (++s->strstart <= max_insert) {
-                    INSERT_STRING(s, s->strstart, hash_head);
-                }
-            } while (--s->prev_length != 0);
-            s->match_available = 0;
-            s->match_length = MIN_MATCH-1;
-            s->strstart++;
-
-            if (bflush) FLUSH_BLOCK(s, 0);
-
-        } else if (s->match_available) {
-            /* If there was no match at the previous position, output a
-             * single literal. If there was a match but the current match
-             * is longer, truncate the previous match to a single literal.
-             */
-            Tracevv((stderr,"%c", s->window[s->strstart-1]));
-            if (_tr_tally (s, 0, s->window[s->strstart-1])) {
-                FLUSH_BLOCK_ONLY(s, 0);
-            }
-            s->strstart++;
-            s->lookahead--;
-            if (s->strm->avail_out == 0) return need_more;
-        } else {
-            /* There is no previous match to compare with, wait for
-             * the next step to decide.
-             */
-            s->match_available = 1;
-            s->strstart++;
-            s->lookahead--;
-        }
-    }
-    Assert (flush != Z_NO_FLUSH, "no flush?");
-    if (s->match_available) {
-        Tracevv((stderr,"%c", s->window[s->strstart-1]));
-        _tr_tally (s, 0, s->window[s->strstart-1]);
-        s->match_available = 0;
-    }
-    FLUSH_BLOCK(s, flush == Z_FINISH);
-    return flush == Z_FINISH ? finish_done : block_done;
-}
-/* --- deflate.c */
-
-/* +++ trees.c */
-/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-1996 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process uses several Huffman trees. The more
- *      common source values are represented by shorter bit sequences.
- *
- *      Each code tree is stored in a compressed form which is itself
- * a Huffman encoding of the lengths of all the code strings (in
- * ascending order by source values).  The actual code strings are
- * reconstructed from the lengths in the inflate process, as described
- * in the deflate specification.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
- *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
- *
- *      Storer, James A.
- *          Data Compression:  Methods and Theory, pp. 49-50.
- *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
- *
- *      Sedgewick, R.
- *          Algorithms, p290.
- *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
- */
-
-/* From: trees.c,v 1.11 1996/07/24 13:41:06 me Exp $ */
-
-/* #include "deflate.h" */
-
-#ifdef DEBUG_ZLIB
-#  include <ctype.h>
-#endif
-
-/* ===========================================================================
- * Constants
- */
-
-#define MAX_BL_BITS 7
-/* Bit length codes must not exceed MAX_BL_BITS bits */
-
-#define END_BLOCK 256
-/* end of block literal code */
-
-#define REP_3_6      16
-/* repeat previous bit length 3-6 times (2 bits of repeat count) */
-
-#define REPZ_3_10    17
-/* repeat a zero length 3-10 times  (3 bits of repeat count) */
-
-#define REPZ_11_138  18
-/* repeat a zero length 11-138 times  (7 bits of repeat count) */
-
-local int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
-   = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
-
-local int extra_dbits[D_CODES] /* extra bits for each distance code */
-   = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
-
-local int extra_blbits[BL_CODES]/* extra bits for each bit length code */
-   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
-
-local uch bl_order[BL_CODES]
-   = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
-/* The lengths of the bit length codes are sent in order of decreasing
- * probability, to avoid transmitting the lengths for unused bit length codes.
- */
-
-#define Buf_size (8 * 2*sizeof(char))
-/* Number of bits used within bi_buf. (bi_buf might be implemented on
- * more than 16 bits on some systems.)
- */
-
-/* ===========================================================================
- * Local data. These are initialized only once.
- */
-
-local ct_data static_ltree[L_CODES+2];
-/* The static literal tree. Since the bit lengths are imposed, there is no
- * need for the L_CODES extra codes used during heap construction. However
- * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
- * below).
- */
-
-local ct_data static_dtree[D_CODES];
-/* The static distance tree. (Actually a trivial tree since all codes use
- * 5 bits.)
- */
-
-local uch dist_code[512];
-/* distance codes. The first 256 values correspond to the distances
- * 3 .. 258, the last 256 values correspond to the top 8 bits of
- * the 15 bit distances.
- */
-
-local uch length_code[MAX_MATCH-MIN_MATCH+1];
-/* length code for each normalized match length (0 == MIN_MATCH) */
-
-local int base_length[LENGTH_CODES];
-/* First normalized length for each code (0 = MIN_MATCH) */
-
-local int base_dist[D_CODES];
-/* First normalized distance for each code (0 = distance of 1) */
-
-struct static_tree_desc_s {
-    ct_data *static_tree;        /* static tree or NULL */
-    intf    *extra_bits;         /* extra bits for each code or NULL */
-    int     extra_base;          /* base index for extra_bits */
-    int     elems;               /* max number of elements in the tree */
-    int     max_length;          /* max bit length for the codes */
-};
-
-local static_tree_desc  static_l_desc =
-{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
-
-local static_tree_desc  static_d_desc =
-{static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS};
-
-local static_tree_desc  static_bl_desc =
-{(ct_data *)0, extra_blbits, 0,      BL_CODES, MAX_BL_BITS};
-
-/* ===========================================================================
- * Local (static) routines in this file.
- */
-
-local void tr_static_init OF((void));
-local void init_block     OF((deflate_state *s));
-local void pqdownheap     OF((deflate_state *s, ct_data *tree, int k));
-local void gen_bitlen     OF((deflate_state *s, tree_desc *desc));
-local void gen_codes      OF((ct_data *tree, int max_code, ushf *bl_count));
-local void build_tree     OF((deflate_state *s, tree_desc *desc));
-local void scan_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local int  build_bl_tree  OF((deflate_state *s));
-local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
-                              int blcodes));
-local void compress_block OF((deflate_state *s, ct_data *ltree,
-                              ct_data *dtree));
-local void set_data_type  OF((deflate_state *s));
-local unsigned bi_reverse OF((unsigned value, int length));
-local void bi_windup      OF((deflate_state *s));
-local void bi_flush       OF((deflate_state *s));
-local void copy_block     OF((deflate_state *s, charf *buf, unsigned len,
-                              int header));
-
-#ifndef DEBUG_ZLIB
-#  define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
-   /* Send a code of the given tree. c and tree must not have side effects */
-
-#else /* DEBUG_ZLIB */
-#  define send_code(s, c, tree) \
-     { if (verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
-       send_bits(s, tree[c].Code, tree[c].Len); }
-#endif
-
-#define d_code(dist) \
-   ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)])
-/* Mapping from a distance to a distance code. dist is the distance - 1 and
- * must not have side effects. dist_code[256] and dist_code[257] are never
- * used.
- */
-
-/* ===========================================================================
- * Output a short LSB first on the stream.
- * IN assertion: there is enough room in pendingBuf.
- */
-#define put_short(s, w) { \
-    put_byte(s, (uch)((w) & 0xff)); \
-    put_byte(s, (uch)((ush)(w) >> 8)); \
-}
-
-/* ===========================================================================
- * Send a value on a given number of bits.
- * IN assertion: length <= 16 and value fits in length bits.
- */
-#ifdef DEBUG_ZLIB
-local void send_bits      OF((deflate_state *s, int value, int length));
-
-local void send_bits(s, value, length)
-    deflate_state *s;
-    int value;  /* value to send */
-    int length; /* number of bits */
-{
-    Tracevv((stderr," l %2d v %4x ", length, value));
-    Assert(length > 0 && length <= 15, "invalid length");
-    s->bits_sent += (ulg)length;
-
-    /* If not enough room in bi_buf, use (valid) bits from bi_buf and
-     * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
-     * unused bits in value.
-     */
-    if (s->bi_valid > (int)Buf_size - length) {
-        s->bi_buf |= (value << s->bi_valid);
-        put_short(s, s->bi_buf);
-        s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
-        s->bi_valid += length - Buf_size;
-    } else {
-        s->bi_buf |= value << s->bi_valid;
-        s->bi_valid += length;
-    }
-}
-#else /* !DEBUG_ZLIB */
-
-#define send_bits(s, value, length) \
-{ int len = length;\
-  if (s->bi_valid > (int)Buf_size - len) {\
-    int val = value;\
-    s->bi_buf |= (val << s->bi_valid);\
-    put_short(s, s->bi_buf);\
-    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
-    s->bi_valid += len - Buf_size;\
-  } else {\
-    s->bi_buf |= (value) << s->bi_valid;\
-    s->bi_valid += len;\
-  }\
-}
-#endif /* DEBUG_ZLIB */
-
-
-#define MAX(a,b) (a >= b ? a : b)
-/* the arguments must not have side effects */
-
-/* ===========================================================================
- * Initialize the various 'constant' tables. In a multi-threaded environment,
- * this function may be called by two threads concurrently, but this is
- * harmless since both invocations do exactly the same thing.
- */
-local void tr_static_init()
-{
-    static int static_init_done = 0;
-    int n;        /* iterates over tree elements */
-    int bits;     /* bit counter */
-    int length;   /* length value */
-    int code;     /* code value */
-    int dist;     /* distance index */
-    ush bl_count[MAX_BITS+1];
-    /* number of codes at each bit length for an optimal tree */
-
-    if (static_init_done) return;
-
-    /* Initialize the mapping length (0..255) -> length code (0..28) */
-    length = 0;
-    for (code = 0; code < LENGTH_CODES-1; code++) {
-        base_length[code] = length;
-        for (n = 0; n < (1<<extra_lbits[code]); n++) {
-            length_code[length++] = (uch)code;
-        }
-    }
-    Assert (length == 256, "tr_static_init: length != 256");
-    /* Note that the length 255 (match length 258) can be represented
-     * in two different ways: code 284 + 5 bits or code 285, so we
-     * overwrite length_code[255] to use the best encoding:
-     */
-    length_code[length-1] = (uch)code;
-
-    /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
-    dist = 0;
-    for (code = 0 ; code < 16; code++) {
-        base_dist[code] = dist;
-        for (n = 0; n < (1<<extra_dbits[code]); n++) {
-            dist_code[dist++] = (uch)code;
-        }
-    }
-    Assert (dist == 256, "tr_static_init: dist != 256");
-    dist >>= 7; /* from now on, all distances are divided by 128 */
-    for ( ; code < D_CODES; code++) {
-        base_dist[code] = dist << 7;
-        for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
-            dist_code[256 + dist++] = (uch)code;
-        }
-    }
-    Assert (dist == 256, "tr_static_init: 256+dist != 512");
-
-    /* Construct the codes of the static literal tree */
-    for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
-    n = 0;
-    while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
-    while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
-    while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
-    while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
-    /* Codes 286 and 287 do not exist, but we must include them in the
-     * tree construction to get a canonical Huffman tree (longest code
-     * all ones)
-     */
-    gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
-
-    /* The static distance tree is trivial: */
-    for (n = 0; n < D_CODES; n++) {
-        static_dtree[n].Len = 5;
-        static_dtree[n].Code = bi_reverse((unsigned)n, 5);
-    }
-    static_init_done = 1;
-}
-
-/* ===========================================================================
- * Initialize the tree data structures for a new zlib stream.
- */
-void _tr_init(s)
-    deflate_state *s;
-{
-    tr_static_init();
-
-    s->compressed_len = 0L;
-
-    s->l_desc.dyn_tree = s->dyn_ltree;
-    s->l_desc.stat_desc = &static_l_desc;
-
-    s->d_desc.dyn_tree = s->dyn_dtree;
-    s->d_desc.stat_desc = &static_d_desc;
-
-    s->bl_desc.dyn_tree = s->bl_tree;
-    s->bl_desc.stat_desc = &static_bl_desc;
-
-    s->bi_buf = 0;
-    s->bi_valid = 0;
-    s->last_eob_len = 8; /* enough lookahead for inflate */
-#ifdef DEBUG_ZLIB
-    s->bits_sent = 0L;
-#endif
-
-    /* Initialize the first block of the first file: */
-    init_block(s);
-}
-
-/* ===========================================================================
- * Initialize a new block.
- */
-local void init_block(s)
-    deflate_state *s;
-{
-    int n; /* iterates over tree elements */
-
-    /* Initialize the trees. */
-    for (n = 0; n < L_CODES;  n++) s->dyn_ltree[n].Freq = 0;
-    for (n = 0; n < D_CODES;  n++) s->dyn_dtree[n].Freq = 0;
-    for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
-
-    s->dyn_ltree[END_BLOCK].Freq = 1;
-    s->opt_len = s->static_len = 0L;
-    s->last_lit = s->matches = 0;
-}
-
-#define SMALLEST 1
-/* Index within the heap array of least frequent node in the Huffman tree */
-
-
-/* ===========================================================================
- * Remove the smallest element from the heap and recreate the heap with
- * one less element. Updates heap and heap_len.
- */
-#define pqremove(s, tree, top) \
-{\
-    top = s->heap[SMALLEST]; \
-    s->heap[SMALLEST] = s->heap[s->heap_len--]; \
-    pqdownheap(s, tree, SMALLEST); \
-}
-
-/* ===========================================================================
- * Compares to subtrees, using the tree depth as tie breaker when
- * the subtrees have equal frequency. This minimizes the worst case length.
- */
-#define smaller(tree, n, m, depth) \
-   (tree[n].Freq < tree[m].Freq || \
-   (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
-
-/* ===========================================================================
- * Restore the heap property by moving down the tree starting at node k,
- * exchanging a node with the smallest of its two sons if necessary, stopping
- * when the heap property is re-established (each father smaller than its
- * two sons).
- */
-local void pqdownheap(s, tree, k)
-    deflate_state *s;
-    ct_data *tree;  /* the tree to restore */
-    int k;               /* node to move down */
-{
-    int v = s->heap[k];
-    int j = k << 1;  /* left son of k */
-    while (j <= s->heap_len) {
-        /* Set j to the smallest of the two sons: */
-        if (j < s->heap_len &&
-            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
-            j++;
-        }
-        /* Exit if v is smaller than both sons */
-        if (smaller(tree, v, s->heap[j], s->depth)) break;
-
-        /* Exchange v with the smallest son */
-        s->heap[k] = s->heap[j];  k = j;
-
-        /* And continue down the tree, setting j to the left son of k */
-        j <<= 1;
-    }
-    s->heap[k] = v;
-}
-
-/* ===========================================================================
- * Compute the optimal bit lengths for a tree and update the total bit length
- * for the current block.
- * IN assertion: the fields freq and dad are set, heap[heap_max] and
- *    above are the tree nodes sorted by increasing frequency.
- * OUT assertions: the field len is set to the optimal bit length, the
- *     array bl_count contains the frequencies for each bit length.
- *     The length opt_len is updated; static_len is also updated if stree is
- *     not null.
- */
-local void gen_bitlen(s, desc)
-    deflate_state *s;
-    tree_desc *desc;    /* the tree descriptor */
-{
-    ct_data *tree  = desc->dyn_tree;
-    int max_code   = desc->max_code;
-    ct_data *stree = desc->stat_desc->static_tree;
-    intf *extra    = desc->stat_desc->extra_bits;
-    int base       = desc->stat_desc->extra_base;
-    int max_length = desc->stat_desc->max_length;
-    int h;              /* heap index */
-    int n, m;           /* iterate over the tree elements */
-    int bits;           /* bit length */
-    int xbits;          /* extra bits */
-    ush f;              /* frequency */
-    int overflow = 0;   /* number of elements with bit length too large */
-
-    for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
-
-    /* In a first pass, compute the optimal bit lengths (which may
-     * overflow in the case of the bit length tree).
-     */
-    tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
-
-    for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
-        n = s->heap[h];
-        bits = tree[tree[n].Dad].Len + 1;
-        if (bits > max_length) bits = max_length, overflow++;
-        tree[n].Len = (ush)bits;
-        /* We overwrite tree[n].Dad which is no longer needed */
-
-        if (n > max_code) continue; /* not a leaf node */
-
-        s->bl_count[bits]++;
-        xbits = 0;
-        if (n >= base) xbits = extra[n-base];
-        f = tree[n].Freq;
-        s->opt_len += (ulg)f * (bits + xbits);
-        if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
-    }
-    if (overflow == 0) return;
-
-    Trace((stderr,"\nbit length overflow\n"));
-    /* This happens for example on obj2 and pic of the Calgary corpus */
-
-    /* Find the first bit length which could increase: */
-    do {
-        bits = max_length-1;
-        while (s->bl_count[bits] == 0) bits--;
-        s->bl_count[bits]--;      /* move one leaf down the tree */
-        s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
-        s->bl_count[max_length]--;
-        /* The brother of the overflow item also moves one step up,
-         * but this does not affect bl_count[max_length]
-         */
-        overflow -= 2;
-    } while (overflow > 0);
-
-    /* Now recompute all bit lengths, scanning in increasing frequency.
-     * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
-     * lengths instead of fixing only the wrong ones. This idea is taken
-     * from 'ar' written by Haruhiko Okumura.)
-     */
-    for (bits = max_length; bits != 0; bits--) {
-        n = s->bl_count[bits];
-        while (n != 0) {
-            m = s->heap[--h];
-            if (m > max_code) continue;
-            if (tree[m].Len != (unsigned) bits) {
-                Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
-                s->opt_len += ((long)bits - (long)tree[m].Len)
-                              *(long)tree[m].Freq;
-                tree[m].Len = (ush)bits;
-            }
-            n--;
-        }
-    }
-}
-
-/* ===========================================================================
- * Generate the codes for a given tree and bit counts (which need not be
- * optimal).
- * IN assertion: the array bl_count contains the bit length statistics for
- * the given tree and the field len is set for all tree elements.
- * OUT assertion: the field code is set for all tree elements of non
- *     zero code length.
- */
-local void gen_codes (tree, max_code, bl_count)
-    ct_data *tree;             /* the tree to decorate */
-    int max_code;              /* largest code with non zero frequency */
-    ushf *bl_count;            /* number of codes at each bit length */
-{
-    ush next_code[MAX_BITS+1]; /* next code value for each bit length */
-    ush code = 0;              /* running code value */
-    int bits;                  /* bit index */
-    int n;                     /* code index */
-
-    /* The distribution counts are first used to generate the code values
-     * without bit reversal.
-     */
-    for (bits = 1; bits <= MAX_BITS; bits++) {
-        next_code[bits] = code = (code + bl_count[bits-1]) << 1;
-    }
-    /* Check that the bit counts in bl_count are consistent. The last code
-     * must be all ones.
-     */
-    Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
-            "inconsistent bit counts");
-    Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
-
-    for (n = 0;  n <= max_code; n++) {
-        int len = tree[n].Len;
-        if (len == 0) continue;
-        /* Now reverse the bits */
-        tree[n].Code = bi_reverse(next_code[len]++, len);
-
-        Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
-             n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
-    }
-}
-
-/* ===========================================================================
- * Construct one Huffman tree and assigns the code bit strings and lengths.
- * Update the total bit length for the current block.
- * IN assertion: the field freq is set for all tree elements.
- * OUT assertions: the fields len and code are set to the optimal bit length
- *     and corresponding code. The length opt_len is updated; static_len is
- *     also updated if stree is not null. The field max_code is set.
- */
-local void build_tree(s, desc)
-    deflate_state *s;
-    tree_desc *desc; /* the tree descriptor */
-{
-    ct_data *tree   = desc->dyn_tree;
-    ct_data *stree  = desc->stat_desc->static_tree;
-    int elems       = desc->stat_desc->elems;
-    int n, m;          /* iterate over heap elements */
-    int max_code = -1; /* largest code with non zero frequency */
-    int node;          /* new node being created */
-
-    /* Construct the initial heap, with least frequent element in
-     * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
-     * heap[0] is not used.
-     */
-    s->heap_len = 0, s->heap_max = HEAP_SIZE;
-
-    for (n = 0; n < elems; n++) {
-        if (tree[n].Freq != 0) {
-            s->heap[++(s->heap_len)] = max_code = n;
-            s->depth[n] = 0;
-        } else {
-            tree[n].Len = 0;
-        }
-    }
-
-    /* The pkzip format requires that at least one distance code exists,
-     * and that at least one bit should be sent even if there is only one
-     * possible code. So to avoid special checks later on we force at least
-     * two codes of non zero frequency.
-     */
-    while (s->heap_len < 2) {
-        node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
-        tree[node].Freq = 1;
-        s->depth[node] = 0;
-        s->opt_len--; if (stree) s->static_len -= stree[node].Len;
-        /* node is 0 or 1 so it does not have extra bits */
-    }
-    desc->max_code = max_code;
-
-    /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
-     * establish sub-heaps of increasing lengths:
-     */
-    for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
-
-    /* Construct the Huffman tree by repeatedly combining the least two
-     * frequent nodes.
-     */
-    node = elems;              /* next internal node of the tree */
-    do {
-        pqremove(s, tree, n);  /* n = node of least frequency */
-        m = s->heap[SMALLEST]; /* m = node of next least frequency */
-
-        s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
-        s->heap[--(s->heap_max)] = m;
-
-        /* Create a new node father of n and m */
-        tree[node].Freq = tree[n].Freq + tree[m].Freq;
-        s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
-        tree[n].Dad = tree[m].Dad = (ush)node;
-#ifdef DUMP_BL_TREE
-        if (tree == s->bl_tree) {
-            fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
-                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
-        }
-#endif
-        /* and insert the new node in the heap */
-        s->heap[SMALLEST] = node++;
-        pqdownheap(s, tree, SMALLEST);
-
-    } while (s->heap_len >= 2);
-
-    s->heap[--(s->heap_max)] = s->heap[SMALLEST];
-
-    /* At this point, the fields freq and dad are set. We can now
-     * generate the bit lengths.
-     */
-    gen_bitlen(s, (tree_desc *)desc);
-
-    /* The field len is now set, we can generate the bit codes */
-    gen_codes ((ct_data *)tree, max_code, s->bl_count);
-}
-
-/* ===========================================================================
- * Scan a literal or distance tree to determine the frequencies of the codes
- * in the bit length tree.
- */
-local void scan_tree (s, tree, max_code)
-    deflate_state *s;
-    ct_data *tree;   /* the tree to be scanned */
-    int max_code;    /* and its largest code of non zero frequency */
-{
-    int n;                     /* iterates over all tree elements */
-    int prevlen = -1;          /* last emitted length */
-    int curlen;                /* length of current code */
-    int nextlen = tree[0].Len; /* length of next code */
-    int count = 0;             /* repeat count of the current code */
-    int max_count = 7;         /* max repeat count */
-    int min_count = 4;         /* min repeat count */
-
-    if (nextlen == 0) max_count = 138, min_count = 3;
-    tree[max_code+1].Len = (ush)0xffff; /* guard */
-
-    for (n = 0; n <= max_code; n++) {
-        curlen = nextlen; nextlen = tree[n+1].Len;
-        if (++count < max_count && curlen == nextlen) {
-            continue;
-        } else if (count < min_count) {
-            s->bl_tree[curlen].Freq += count;
-        } else if (curlen != 0) {
-            if (curlen != prevlen) s->bl_tree[curlen].Freq++;
-            s->bl_tree[REP_3_6].Freq++;
-        } else if (count <= 10) {
-            s->bl_tree[REPZ_3_10].Freq++;
-        } else {
-            s->bl_tree[REPZ_11_138].Freq++;
-        }
-        count = 0; prevlen = curlen;
-        if (nextlen == 0) {
-            max_count = 138, min_count = 3;
-        } else if (curlen == nextlen) {
-            max_count = 6, min_count = 3;
-        } else {
-            max_count = 7, min_count = 4;
-        }
-    }
-}
-
-/* ===========================================================================
- * Send a literal or distance tree in compressed form, using the codes in
- * bl_tree.
- */
-local void send_tree (s, tree, max_code)
-    deflate_state *s;
-    ct_data *tree; /* the tree to be scanned */
-    int max_code;       /* and its largest code of non zero frequency */
-{
-    int n;                     /* iterates over all tree elements */
-    int prevlen = -1;          /* last emitted length */
-    int curlen;                /* length of current code */
-    int nextlen = tree[0].Len; /* length of next code */
-    int count = 0;             /* repeat count of the current code */
-    int max_count = 7;         /* max repeat count */
-    int min_count = 4;         /* min repeat count */
-
-    /* tree[max_code+1].Len = -1; */  /* guard already set */
-    if (nextlen == 0) max_count = 138, min_count = 3;
-
-    for (n = 0; n <= max_code; n++) {
-        curlen = nextlen; nextlen = tree[n+1].Len;
-        if (++count < max_count && curlen == nextlen) {
-            continue;
-        } else if (count < min_count) {
-            do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
-
-        } else if (curlen != 0) {
-            if (curlen != prevlen) {
-                send_code(s, curlen, s->bl_tree); count--;
-            }
-            Assert(count >= 3 && count <= 6, " 3_6?");
-            send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
-
-        } else if (count <= 10) {
-            send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
-
-        } else {
-            send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
-        }
-        count = 0; prevlen = curlen;
-        if (nextlen == 0) {
-            max_count = 138, min_count = 3;
-        } else if (curlen == nextlen) {
-            max_count = 6, min_count = 3;
-        } else {
-            max_count = 7, min_count = 4;
-        }
-    }
-}
-
-/* ===========================================================================
- * Construct the Huffman tree for the bit lengths and return the index in
- * bl_order of the last bit length code to send.
- */
-local int build_bl_tree(s)
-    deflate_state *s;
-{
-    int max_blindex;  /* index of last bit length code of non zero freq */
-
-    /* Determine the bit length frequencies for literal and distance trees */
-    scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
-    scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
-
-    /* Build the bit length tree: */
-    build_tree(s, (tree_desc *)(&(s->bl_desc)));
-    /* opt_len now includes the length of the tree representations, except
-     * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
-     */
-
-    /* Determine the number of bit length codes to send. The pkzip format
-     * requires that at least 4 bit length codes be sent. (appnote.txt says
-     * 3 but the actual value used is 4.)
-     */
-    for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
-        if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
-    }
-    /* Update opt_len to include the bit length tree and counts */
-    s->opt_len += 3*(max_blindex+1) + 5+5+4;
-    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
-            s->opt_len, s->static_len));
-
-    return max_blindex;
-}
-
-/* ===========================================================================
- * Send the header for a block using dynamic Huffman trees: the counts, the
- * lengths of the bit length codes, the literal tree and the distance tree.
- * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
- */
-local void send_all_trees(s, lcodes, dcodes, blcodes)
-    deflate_state *s;
-    int lcodes, dcodes, blcodes; /* number of codes for each tree */
-{
-    int rank;                    /* index in bl_order */
-
-    Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
-    Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
-            "too many codes");
-    Tracev((stderr, "\nbl counts: "));
-    send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
-    send_bits(s, dcodes-1,   5);
-    send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
-    for (rank = 0; rank < blcodes; rank++) {
-        Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
-        send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
-    }
-    Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
-
-    send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
-    Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
-
-    send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
-    Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
-}
-
-/* ===========================================================================
- * Send a stored block
- */
-void _tr_stored_block(s, buf, stored_len, eof)
-    deflate_state *s;
-    charf *buf;       /* input block */
-    ulg stored_len;   /* length of input block */
-    int eof;          /* true if this is the last block for a file */
-{
-    send_bits(s, (STORED_BLOCK<<1)+eof, 3);  /* send block type */
-    s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
-    s->compressed_len += (stored_len + 4) << 3;
-
-    copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
-}
-
-/* Send just the `stored block' type code without any length bytes or data.
- */
-void _tr_stored_type_only(s)
-    deflate_state *s;
-{
-    send_bits(s, (STORED_BLOCK << 1), 3);
-    bi_windup(s);
-    s->compressed_len = (s->compressed_len + 3) & ~7L;
-}
-
-
-/* ===========================================================================
- * Send one empty static block to give enough lookahead for inflate.
- * This takes 10 bits, of which 7 may remain in the bit buffer.
- * The current inflate code requires 9 bits of lookahead. If the
- * last two codes for the previous block (real code plus EOB) were coded
- * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
- * the last real code. In this case we send two empty static blocks instead
- * of one. (There are no problems if the previous block is stored or fixed.)
- * To simplify the code, we assume the worst case of last real code encoded
- * on one bit only.
- */
-void _tr_align(s)
-    deflate_state *s;
-{
-    send_bits(s, STATIC_TREES<<1, 3);
-    send_code(s, END_BLOCK, static_ltree);
-    s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
-    bi_flush(s);
-    /* Of the 10 bits for the empty block, we have already sent
-     * (10 - bi_valid) bits. The lookahead for the last real code (before
-     * the EOB of the previous block) was thus at least one plus the length
-     * of the EOB plus what we have just sent of the empty static block.
-     */
-    if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
-        send_bits(s, STATIC_TREES<<1, 3);
-        send_code(s, END_BLOCK, static_ltree);
-        s->compressed_len += 10L;
-        bi_flush(s);
-    }
-    s->last_eob_len = 7;
-}
-
-/* ===========================================================================
- * Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file. This function
- * returns the total compressed length for the file so far.
- */
-ulg _tr_flush_block(s, buf, stored_len, eof)
-    deflate_state *s;
-    charf *buf;       /* input block, or NULL if too old */
-    ulg stored_len;   /* length of input block */
-    int eof;          /* true if this is the last block for a file */
-{
-    ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
-    int max_blindex = 0;  /* index of last bit length code of non zero freq */
-
-    /* Build the Huffman trees unless a stored block is forced */
-    if (s->level > 0) {
-
-        /* Check if the file is ascii or binary */
-       if (s->data_type == Z_UNKNOWN) set_data_type(s);
-
-       /* Construct the literal and distance trees */
-       build_tree(s, (tree_desc *)(&(s->l_desc)));
-       Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
-               s->static_len));
-
-       build_tree(s, (tree_desc *)(&(s->d_desc)));
-       Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
-               s->static_len));
-       /* At this point, opt_len and static_len are the total bit lengths of
-        * the compressed block data, excluding the tree representations.
-        */
-
-       /* Build the bit length tree for the above two trees, and get the index
-        * in bl_order of the last bit length code to send.
-        */
-       max_blindex = build_bl_tree(s);
-
-       /* Determine the best encoding. Compute first the block length in bytes*/
-       opt_lenb = (s->opt_len+3+7)>>3;
-       static_lenb = (s->static_len+3+7)>>3;
-
-       Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
-               opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
-               s->last_lit));
-
-       if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
-
-    } else {
-        Assert(buf != (char*)0, "lost buf");
-       opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
-    }
-
-    /* If compression failed and this is the first and last block,
-     * and if the .zip file can be seeked (to rewrite the local header),
-     * the whole file is transformed into a stored file:
-     */
-#ifdef STORED_FILE_OK
-#  ifdef FORCE_STORED_FILE
-    if (eof && s->compressed_len == 0L) { /* force stored file */
-#  else
-    if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
-#  endif
-        /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
-        if (buf == (charf*)0) error ("block vanished");
-
-        copy_block(s, buf, (unsigned)stored_len, 0); /* without header */
-        s->compressed_len = stored_len << 3;
-        s->method = STORED;
-    } else
-#endif /* STORED_FILE_OK */
-
-#ifdef FORCE_STORED
-    if (buf != (char*)0) { /* force stored block */
-#else
-    if (stored_len+4 <= opt_lenb && buf != (char*)0) {
-                       /* 4: two words for the lengths */
-#endif
-        /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
-         * Otherwise we can't have processed more than WSIZE input bytes since
-         * the last block flush, because compression would have been
-         * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
-         * transform a block into a stored block.
-         */
-        _tr_stored_block(s, buf, stored_len, eof);
-
-#ifdef FORCE_STATIC
-    } else if (static_lenb >= 0) { /* force static trees */
-#else
-    } else if (static_lenb == opt_lenb) {
-#endif
-        send_bits(s, (STATIC_TREES<<1)+eof, 3);
-        compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
-        s->compressed_len += 3 + s->static_len;
-    } else {
-        send_bits(s, (DYN_TREES<<1)+eof, 3);
-        send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
-                       max_blindex+1);
-        compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
-        s->compressed_len += 3 + s->opt_len;
-    }
-    Assert (s->compressed_len == s->bits_sent, "bad compressed size");
-    init_block(s);
-
-    if (eof) {
-        bi_windup(s);
-        s->compressed_len += 7;  /* align on byte boundary */
-    }
-    Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
-           s->compressed_len-7*eof));
-
-    return s->compressed_len >> 3;
-}
-
-/* ===========================================================================
- * Save the match info and tally the frequency counts. Return true if
- * the current block must be flushed.
- */
-int _tr_tally (s, dist, lc)
-    deflate_state *s;
-    unsigned dist;  /* distance of matched string */
-    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
-{
-    s->d_buf[s->last_lit] = (ush)dist;
-    s->l_buf[s->last_lit++] = (uch)lc;
-    if (dist == 0) {
-        /* lc is the unmatched char */
-        s->dyn_ltree[lc].Freq++;
-    } else {
-        s->matches++;
-        /* Here, lc is the match length - MIN_MATCH */
-        dist--;             /* dist = match distance - 1 */
-        Assert((ush)dist < (ush)MAX_DIST(s) &&
-               (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
-               (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
-
-        s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
-        s->dyn_dtree[d_code(dist)].Freq++;
-    }
-
-    /* Try to guess if it is profitable to stop the current block here */
-    if (s->level > 2 && (s->last_lit & 0xfff) == 0) {
-        /* Compute an upper bound for the compressed length */
-        ulg out_length = (ulg)s->last_lit*8L;
-        ulg in_length = (ulg)((long)s->strstart - s->block_start);
-        int dcode;
-        for (dcode = 0; dcode < D_CODES; dcode++) {
-            out_length += (ulg)s->dyn_dtree[dcode].Freq *
-                (5L+extra_dbits[dcode]);
-        }
-        out_length >>= 3;
-        Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
-               s->last_lit, in_length, out_length,
-               100L - out_length*100L/in_length));
-        if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
-    }
-    return (s->last_lit == s->lit_bufsize-1);
-    /* We avoid equality with lit_bufsize because of wraparound at 64K
-     * on 16 bit machines and because stored blocks are restricted to
-     * 64K-1 bytes.
-     */
-}
-
-/* ===========================================================================
- * Send the block data compressed using the given Huffman trees
- */
-local void compress_block(s, ltree, dtree)
-    deflate_state *s;
-    ct_data *ltree; /* literal tree */
-    ct_data *dtree; /* distance tree */
-{
-    unsigned dist;      /* distance of matched string */
-    int lc;             /* match length or unmatched char (if dist == 0) */
-    unsigned lx = 0;    /* running index in l_buf */
-    unsigned code;      /* the code to send */
-    int extra;          /* number of extra bits to send */
-
-    if (s->last_lit != 0) do {
-        dist = s->d_buf[lx];
-        lc = s->l_buf[lx++];
-        if (dist == 0) {
-            send_code(s, lc, ltree); /* send a literal byte */
-            Tracecv(isgraph(lc), (stderr," '%c' ", lc));
-        } else {
-            /* Here, lc is the match length - MIN_MATCH */
-            code = length_code[lc];
-            send_code(s, code+LITERALS+1, ltree); /* send the length code */
-            extra = extra_lbits[code];
-            if (extra != 0) {
-                lc -= base_length[code];
-                send_bits(s, lc, extra);       /* send the extra length bits */
-            }
-            dist--; /* dist is now the match distance - 1 */
-            code = d_code(dist);
-            Assert (code < D_CODES, "bad d_code");
-
-            send_code(s, code, dtree);       /* send the distance code */
-            extra = extra_dbits[code];
-            if (extra != 0) {
-                dist -= base_dist[code];
-                send_bits(s, dist, extra);   /* send the extra distance bits */
-            }
-        } /* literal or match pair ? */
-
-        /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
-        Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
-
-    } while (lx < s->last_lit);
-
-    send_code(s, END_BLOCK, ltree);
-    s->last_eob_len = ltree[END_BLOCK].Len;
-}
-
-/* ===========================================================================
- * Set the data type to ASCII or BINARY, using a crude approximation:
- * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
- * IN assertion: the fields freq of dyn_ltree are set and the total of all
- * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
- */
-local void set_data_type(s)
-    deflate_state *s;
-{
-    int n = 0;
-    unsigned ascii_freq = 0;
-    unsigned bin_freq = 0;
-    while (n < 7)        bin_freq += s->dyn_ltree[n++].Freq;
-    while (n < 128)    ascii_freq += s->dyn_ltree[n++].Freq;
-    while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
-    s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
-}
-
-/* ===========================================================================
- * Reverse the first len bits of a code, using straightforward code (a faster
- * method would use a table)
- * IN assertion: 1 <= len <= 15
- */
-local unsigned bi_reverse(code, len)
-    unsigned code; /* the value to invert */
-    int len;       /* its bit length */
-{
-    register unsigned res = 0;
-    do {
-        res |= code & 1;
-        code >>= 1, res <<= 1;
-    } while (--len > 0);
-    return res >> 1;
-}
-
-/* ===========================================================================
- * Flush the bit buffer, keeping at most 7 bits in it.
- */
-local void bi_flush(s)
-    deflate_state *s;
-{
-    if (s->bi_valid == 16) {
-        put_short(s, s->bi_buf);
-        s->bi_buf = 0;
-        s->bi_valid = 0;
-    } else if (s->bi_valid >= 8) {
-        put_byte(s, (Byte)s->bi_buf);
-        s->bi_buf >>= 8;
-        s->bi_valid -= 8;
-    }
-}
-
-/* ===========================================================================
- * Flush the bit buffer and align the output on a byte boundary
- */
-local void bi_windup(s)
-    deflate_state *s;
-{
-    if (s->bi_valid > 8) {
-        put_short(s, s->bi_buf);
-    } else if (s->bi_valid > 0) {
-        put_byte(s, (Byte)s->bi_buf);
-    }
-    s->bi_buf = 0;
-    s->bi_valid = 0;
-#ifdef DEBUG_ZLIB
-    s->bits_sent = (s->bits_sent+7) & ~7;
-#endif
-}
-
-/* ===========================================================================
- * Copy a stored block, storing first the length and its
- * one's complement if requested.
- */
-local void copy_block(s, buf, len, header)
-    deflate_state *s;
-    charf    *buf;    /* the input data */
-    unsigned len;     /* its length */
-    int      header;  /* true if block header must be written */
-{
-    bi_windup(s);        /* align on byte boundary */
-    s->last_eob_len = 8; /* enough lookahead for inflate */
-
-    if (header) {
-        put_short(s, (ush)len);   
-        put_short(s, (ush)~len);
-#ifdef DEBUG_ZLIB
-        s->bits_sent += 2*16;
-#endif
-    }
-#ifdef DEBUG_ZLIB
-    s->bits_sent += (ulg)len<<3;
-#endif
-    /* bundle up the put_byte(s, *buf++) calls */
-    zmemcpy(&s->pending_buf[s->pending], buf, len);
-    s->pending += len;
-}
-/* --- trees.c */
-
-/* +++ inflate.c */
-/* inflate.c -- zlib interface to inflate modules
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-
-/* +++ infblock.h */
-/* infblock.h -- header to use infblock.c
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-struct inflate_blocks_state;
-typedef struct inflate_blocks_state FAR inflate_blocks_statef;
-
-extern inflate_blocks_statef * inflate_blocks_new OF((
-    z_streamp z,
-    check_func c,               /* check function */
-    uInt w));                   /* window size */
-
-extern int inflate_blocks OF((
-    inflate_blocks_statef *,
-    z_streamp ,
-    int));                      /* initial return code */
-
-extern void inflate_blocks_reset OF((
-    inflate_blocks_statef *,
-    z_streamp ,
-    uLongf *));                  /* check value on output */
-
-extern int inflate_blocks_free OF((
-    inflate_blocks_statef *,
-    z_streamp ,
-    uLongf *));                  /* check value on output */
-
-extern void inflate_set_dictionary OF((
-    inflate_blocks_statef *s,
-    const Bytef *d,  /* dictionary */
-    uInt  n));       /* dictionary length */
-
-extern int inflate_addhistory OF((
-    inflate_blocks_statef *,
-    z_streamp));
-
-extern int inflate_packet_flush OF((
-    inflate_blocks_statef *));
-/* --- infblock.h */
-
-#ifndef NO_DUMMY_DECL
-struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
-#endif
-
-/* inflate private state */
-struct internal_state {
-
-  /* mode */
-  enum {
-      METHOD,   /* waiting for method byte */
-      FLAG,     /* waiting for flag byte */
-      DICT4,    /* four dictionary check bytes to go */
-      DICT3,    /* three dictionary check bytes to go */
-      DICT2,    /* two dictionary check bytes to go */
-      DICT1,    /* one dictionary check byte to go */
-      DICT0,    /* waiting for inflateSetDictionary */
-      BLOCKS,   /* decompressing blocks */
-      CHECK4,   /* four check bytes to go */
-      CHECK3,   /* three check bytes to go */
-      CHECK2,   /* two check bytes to go */
-      CHECK1,   /* one check byte to go */
-      DONE,     /* finished check, done */
-      BAD}      /* got an error--stay here */
-    mode;               /* current inflate mode */
-
-  /* mode dependent information */
-  union {
-    uInt method;        /* if FLAGS, method byte */
-    struct {
-      uLong was;                /* computed check value */
-      uLong need;               /* stream check value */
-    } check;            /* if CHECK, check values to compare */
-    uInt marker;        /* if BAD, inflateSync's marker bytes count */
-  } sub;        /* submode */
-
-  /* mode independent information */
-  int  nowrap;          /* flag for no wrapper */
-  uInt wbits;           /* log2(window size)  (8..15, defaults to 15) */
-  inflate_blocks_statef 
-    *blocks;            /* current inflate_blocks state */
-
-};
-
-
-int inflateReset(z)
-z_streamp z;
-{
-  uLong c;
-
-  if (z == Z_NULL || z->state == Z_NULL)
-    return Z_STREAM_ERROR;
-  z->total_in = z->total_out = 0;
-  z->msg = Z_NULL;
-  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
-  inflate_blocks_reset(z->state->blocks, z, &c);
-  Trace((stderr, "inflate: reset\n"));
-  return Z_OK;
-}
-
-
-int inflateEnd(z)
-z_streamp z;
-{
-  uLong c;
-
-  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
-    return Z_STREAM_ERROR;
-  if (z->state->blocks != Z_NULL)
-    inflate_blocks_free(z->state->blocks, z, &c);
-  ZFREE(z, z->state);
-  z->state = Z_NULL;
-  Trace((stderr, "inflate: end\n"));
-  return Z_OK;
-}
-
-
-int inflateInit2_(z, w, version, stream_size)
-z_streamp z;
-int w;
-const char *version;
-int stream_size;
-{
-  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
-      stream_size != sizeof(z_stream))
-      return Z_VERSION_ERROR;
-
-  /* initialize state */
-  if (z == Z_NULL)
-    return Z_STREAM_ERROR;
-  z->msg = Z_NULL;
-#ifndef NO_ZCFUNCS
-  if (z->zalloc == Z_NULL)
-  {
-    z->zalloc = zcalloc;
-    z->opaque = (voidpf)0;
-  }
-  if (z->zfree == Z_NULL) z->zfree = zcfree;
-#endif
-  if ((z->state = (struct internal_state FAR *)
-       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
-    return Z_MEM_ERROR;
-  z->state->blocks = Z_NULL;
-
-  /* handle undocumented nowrap option (no zlib header or check) */
-  z->state->nowrap = 0;
-  if (w < 0)
-  {
-    w = - w;
-    z->state->nowrap = 1;
-  }
-
-  /* set window size */
-  if (w < 8 || w > 15)
-  {
-    inflateEnd(z);
-    return Z_STREAM_ERROR;
-  }
-  z->state->wbits = (uInt)w;
-
-  /* create inflate_blocks state */
-  if ((z->state->blocks =
-      inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
-      == Z_NULL)
-  {
-    inflateEnd(z);
-    return Z_MEM_ERROR;
-  }
-  Trace((stderr, "inflate: allocated\n"));
-
-  /* reset state */
-  inflateReset(z);
-  return Z_OK;
-}
-
-
-int inflateInit_(z, version, stream_size)
-z_streamp z;
-const char *version;
-int stream_size;
-{
-  return inflateInit2_(z, DEF_WBITS, version, stream_size);
-}
-
-
-#define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;}
-#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
-
-int inflate(z, f)
-z_streamp z;
-int f;
-{
-  int r;
-  uInt b;
-
-  if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL || f < 0)
-    return Z_STREAM_ERROR;
-  r = Z_BUF_ERROR;
-  while (1) switch (z->state->mode)
-  {
-    case METHOD:
-      NEEDBYTE
-      if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
-      {
-        z->state->mode = BAD;
-        z->msg = (char*)"unknown compression method";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
-      {
-        z->state->mode = BAD;
-        z->msg = (char*)"invalid window size";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      z->state->mode = FLAG;
-    case FLAG:
-      NEEDBYTE
-      b = NEXTBYTE;
-      if (((z->state->sub.method << 8) + b) % 31)
-      {
-        z->state->mode = BAD;
-        z->msg = (char*)"incorrect header check";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      Trace((stderr, "inflate: zlib header ok\n"));
-      if (!(b & PRESET_DICT))
-      {
-        z->state->mode = BLOCKS;
-       break;
-      }
-      z->state->mode = DICT4;
-    case DICT4:
-      NEEDBYTE
-      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
-      z->state->mode = DICT3;
-    case DICT3:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
-      z->state->mode = DICT2;
-    case DICT2:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
-      z->state->mode = DICT1;
-    case DICT1:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE;
-      z->adler = z->state->sub.check.need;
-      z->state->mode = DICT0;
-      return Z_NEED_DICT;
-    case DICT0:
-      z->state->mode = BAD;
-      z->msg = (char*)"need dictionary";
-      z->state->sub.marker = 0;       /* can try inflateSync */
-      return Z_STREAM_ERROR;
-    case BLOCKS:
-      r = inflate_blocks(z->state->blocks, z, r);
-      if (f == Z_PACKET_FLUSH && z->avail_in == 0 && z->avail_out != 0)
-         r = inflate_packet_flush(z->state->blocks);
-      if (r == Z_DATA_ERROR)
-      {
-        z->state->mode = BAD;
-        z->state->sub.marker = 0;       /* can try inflateSync */
-        break;
-      }
-      if (r != Z_STREAM_END)
-        return r;
-      r = Z_OK;
-      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
-      if (z->state->nowrap)
-      {
-        z->state->mode = DONE;
-        break;
-      }
-      z->state->mode = CHECK4;
-    case CHECK4:
-      NEEDBYTE
-      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
-      z->state->mode = CHECK3;
-    case CHECK3:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
-      z->state->mode = CHECK2;
-    case CHECK2:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
-      z->state->mode = CHECK1;
-    case CHECK1:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE;
-
-      if (z->state->sub.check.was != z->state->sub.check.need)
-      {
-        z->state->mode = BAD;
-        z->msg = (char*)"incorrect data check";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      Trace((stderr, "inflate: zlib check ok\n"));
-      z->state->mode = DONE;
-    case DONE:
-      return Z_STREAM_END;
-    case BAD:
-      return Z_DATA_ERROR;
-    default:
-      return Z_STREAM_ERROR;
-  }
-
- empty:
-  if (f != Z_PACKET_FLUSH)
-    return r;
-  z->state->mode = BAD;
-  z->msg = (char *)"need more for packet flush";
-  z->state->sub.marker = 0;       /* can try inflateSync */
-  return Z_DATA_ERROR;
-}
-
-
-int inflateSetDictionary(z, dictionary, dictLength)
-z_streamp z;
-const Bytef *dictionary;
-uInt  dictLength;
-{
-  uInt length = dictLength;
-
-  if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
-    return Z_STREAM_ERROR;
-
-  if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
-  z->adler = 1L;
-
-  if (length >= ((uInt)1<<z->state->wbits))
-  {
-    length = (1<<z->state->wbits)-1;
-    dictionary += dictLength - length;
-  }
-  inflate_set_dictionary(z->state->blocks, dictionary, length);
-  z->state->mode = BLOCKS;
-  return Z_OK;
-}
-
-/*
- * This subroutine adds the data at next_in/avail_in to the output history
- * without performing any output.  The output buffer must be "caught up";
- * i.e. no pending output (hence s->read equals s->write), and the state must
- * be BLOCKS (i.e. we should be willing to see the start of a series of
- * BLOCKS).  On exit, the output will also be caught up, and the checksum
- * will have been updated if need be.
- */
-
-int inflateIncomp(z)
-z_stream *z;
-{
-    if (z->state->mode != BLOCKS)
-       return Z_DATA_ERROR;
-    return inflate_addhistory(z->state->blocks, z);
-}
-
-
-int inflateSync(z)
-z_streamp z;
-{
-  uInt n;       /* number of bytes to look at */
-  Bytef *p;     /* pointer to bytes */
-  uInt m;       /* number of marker bytes found in a row */
-  uLong r, w;   /* temporaries to save total_in and total_out */
-
-  /* set up */
-  if (z == Z_NULL || z->state == Z_NULL)
-    return Z_STREAM_ERROR;
-  if (z->state->mode != BAD)
-  {
-    z->state->mode = BAD;
-    z->state->sub.marker = 0;
-  }
-  if ((n = z->avail_in) == 0)
-    return Z_BUF_ERROR;
-  p = z->next_in;
-  m = z->state->sub.marker;
-
-  /* search */
-  while (n && m < 4)
-  {
-    if (*p == (Byte)(m < 2 ? 0 : 0xff))
-      m++;
-    else if (*p)
-      m = 0;
-    else
-      m = 4 - m;
-    p++, n--;
-  }
-
-  /* restore */
-  z->total_in += p - z->next_in;
-  z->next_in = p;
-  z->avail_in = n;
-  z->state->sub.marker = m;
-
-  /* return no joy or set up to restart on a new block */
-  if (m != 4)
-    return Z_DATA_ERROR;
-  r = z->total_in;  w = z->total_out;
-  inflateReset(z);
-  z->total_in = r;  z->total_out = w;
-  z->state->mode = BLOCKS;
-  return Z_OK;
-}
-
-#undef NEEDBYTE
-#undef NEXTBYTE
-/* --- inflate.c */
-
-/* +++ infblock.c */
-/* infblock.c -- interpret and process block types to last block
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-/* #include "infblock.h" */
-
-/* +++ inftrees.h */
-/* inftrees.h -- header to use inftrees.c
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* Huffman code lookup table entry--this entry is four bytes for machines
-   that have 16-bit pointers (e.g. PC's in the small or medium model). */
-
-typedef struct inflate_huft_s FAR inflate_huft;
-
-struct inflate_huft_s {
-  union {
-    struct {
-      Byte Exop;        /* number of extra bits or operation */
-      Byte Bits;        /* number of bits in this code or subcode */
-    } what;
-    Bytef *pad;         /* pad structure to a power of 2 (4 bytes for */
-  } word;               /*  16-bit, 8 bytes for 32-bit machines) */
-  union {
-    uInt Base;          /* literal, length base, or distance base */
-    inflate_huft *Next; /* pointer to next level of table */
-  } more;
-};
-
-#ifdef DEBUG_ZLIB
-  extern uInt inflate_hufts;
-#endif
-
-extern int inflate_trees_bits OF((
-    uIntf *,                    /* 19 code lengths */
-    uIntf *,                    /* bits tree desired/actual depth */
-    inflate_huft * FAR *,       /* bits tree result */
-    z_streamp ));               /* for zalloc, zfree functions */
-
-extern int inflate_trees_dynamic OF((
-    uInt,                       /* number of literal/length codes */
-    uInt,                       /* number of distance codes */
-    uIntf *,                    /* that many (total) code lengths */
-    uIntf *,                    /* literal desired/actual bit depth */
-    uIntf *,                    /* distance desired/actual bit depth */
-    inflate_huft * FAR *,       /* literal/length tree result */
-    inflate_huft * FAR *,       /* distance tree result */
-    z_streamp ));               /* for zalloc, zfree functions */
-
-extern int inflate_trees_fixed OF((
-    uIntf *,                    /* literal desired/actual bit depth */
-    uIntf *,                    /* distance desired/actual bit depth */
-    inflate_huft * FAR *,       /* literal/length tree result */
-    inflate_huft * FAR *));     /* distance tree result */
-
-extern int inflate_trees_free OF((
-    inflate_huft *,             /* tables to free */
-    z_streamp ));               /* for zfree function */
-
-/* --- inftrees.h */
-
-/* +++ infcodes.h */
-/* infcodes.h -- header to use infcodes.c
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-struct inflate_codes_state;
-typedef struct inflate_codes_state FAR inflate_codes_statef;
-
-extern inflate_codes_statef *inflate_codes_new OF((
-    uInt, uInt,
-    inflate_huft *, inflate_huft *,
-    z_streamp ));
-
-extern int inflate_codes OF((
-    inflate_blocks_statef *,
-    z_streamp ,
-    int));
-
-extern void inflate_codes_free OF((
-    inflate_codes_statef *,
-    z_streamp ));
-
-/* --- infcodes.h */
-
-/* +++ infutil.h */
-/* infutil.h -- types and macros common to blocks and codes
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-#ifndef _INFUTIL_H
-#define _INFUTIL_H
-
-typedef enum {
-      TYPE,     /* get type bits (3, including end bit) */
-      LENS,     /* get lengths for stored */
-      STORED,   /* processing stored block */
-      TABLE,    /* get table lengths */
-      BTREE,    /* get bit lengths tree for a dynamic block */
-      DTREE,    /* get length, distance trees for a dynamic block */
-      CODES,    /* processing fixed or dynamic block */
-      DRY,      /* output remaining window bytes */
-      DONEB,    /* finished last block, done */
-      BADB}     /* got a data error--stuck here */
-inflate_block_mode;
-
-/* inflate blocks semi-private state */
-struct inflate_blocks_state {
-
-  /* mode */
-  inflate_block_mode  mode;     /* current inflate_block mode */
-
-  /* mode dependent information */
-  union {
-    uInt left;          /* if STORED, bytes left to copy */
-    struct {
-      uInt table;               /* table lengths (14 bits) */
-      uInt index;               /* index into blens (or border) */
-      uIntf *blens;             /* bit lengths of codes */
-      uInt bb;                  /* bit length tree depth */
-      inflate_huft *tb;         /* bit length decoding tree */
-    } trees;            /* if DTREE, decoding info for trees */
-    struct {
-      inflate_huft *tl;
-      inflate_huft *td;         /* trees to free */
-      inflate_codes_statef 
-         *codes;
-    } decode;           /* if CODES, current state */
-  } sub;                /* submode */
-  uInt last;            /* true if this block is the last block */
-
-  /* mode independent information */
-  uInt bitk;            /* bits in bit buffer */
-  uLong bitb;           /* bit buffer */
-  Bytef *window;        /* sliding window */
-  Bytef *end;           /* one byte after sliding window */
-  Bytef *read;          /* window read pointer */
-  Bytef *write;         /* window write pointer */
-  check_func checkfn;   /* check function */
-  uLong check;          /* check on output */
-
-};
-
-
-/* defines for inflate input/output */
-/*   update pointers and return */
-#define UPDBITS {s->bitb=b;s->bitk=k;}
-#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
-#define UPDOUT {s->write=q;}
-#define UPDATE {UPDBITS UPDIN UPDOUT}
-#define LEAVE {UPDATE return inflate_flush(s,z,r);}
-/*   get bytes and bits */
-#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
-#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
-#define NEXTBYTE (n--,*p++)
-#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
-#define DUMPBITS(j) {b>>=(j);k-=(j);}
-/*   output bytes */
-#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
-#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
-#define WWRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
-#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
-#define NEEDOUT {if(m==0){WWRAP if(m==0){FLUSH WWRAP if(m==0) LEAVE}}r=Z_OK;}
-#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
-/*   load local pointers */
-#define LOAD {LOADIN LOADOUT}
-
-/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
-extern uInt inflate_mask[17];
-
-/* copy as much as possible from the sliding window to the output area */
-extern int inflate_flush OF((
-    inflate_blocks_statef *,
-    z_streamp ,
-    int));
-
-#ifndef NO_DUMMY_DECL
-struct internal_state      {int dummy;}; /* for buggy compilers */
-#endif
-
-#endif
-/* --- infutil.h */
-
-#ifndef NO_DUMMY_DECL
-struct inflate_codes_state {int dummy;}; /* for buggy compilers */
-#endif
-
-/* Table for deflate from PKZIP's appnote.txt. */
-local const uInt border[] = { /* Order of the bit length code lengths */
-        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
-/*
-   Notes beyond the 1.93a appnote.txt:
-
-   1. Distance pointers never point before the beginning of the output
-      stream.
-   2. Distance pointers can point back across blocks, up to 32k away.
-   3. There is an implied maximum of 7 bits for the bit length table and
-      15 bits for the actual data.
-   4. If only one code exists, then it is encoded using one bit.  (Zero
-      would be more efficient, but perhaps a little confusing.)  If two
-      codes exist, they are coded using one bit each (0 and 1).
-   5. There is no way of sending zero distance codes--a dummy must be
-      sent if there are none.  (History: a pre 2.0 version of PKZIP would
-      store blocks with no distance codes, but this was discovered to be
-      too harsh a criterion.)  Valid only for 1.93a.  2.04c does allow
-      zero distance codes, which is sent as one code of zero bits in
-      length.
-   6. There are up to 286 literal/length codes.  Code 256 represents the
-      end-of-block.  Note however that the static length tree defines
-      288 codes just to fill out the Huffman codes.  Codes 286 and 287
-      cannot be used though, since there is no length base or extra bits
-      defined for them.  Similarily, there are up to 30 distance codes.
-      However, static trees define 32 codes (all 5 bits) to fill out the
-      Huffman codes, but the last two had better not show up in the data.
-   7. Unzip can check dynamic Huffman blocks for complete code sets.
-      The exception is that a single code would not be complete (see #4).
-   8. The five bits following the block type is really the number of
-      literal codes sent minus 257.
-   9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
-      (1+6+6).  Therefore, to output three times the length, you output
-      three codes (1+1+1), whereas to output four times the same length,
-      you only need two codes (1+3).  Hmm.
-  10. In the tree reconstruction algorithm, Code = Code + Increment
-      only if BitLength(i) is not zero.  (Pretty obvious.)
-  11. Correction: 4 Bits: # of Bit Length codes - 4     (4 - 19)
-  12. Note: length code 284 can represent 227-258, but length code 285
-      really is 258.  The last length deserves its own, short code
-      since it gets used a lot in very redundant files.  The length
-      258 is special since 258 - 3 (the min match length) is 255.
-  13. The literal/length and distance code bit lengths are read as a
-      single stream of lengths.  It is possible (and advantageous) for
-      a repeat code (16, 17, or 18) to go across the boundary between
-      the two sets of lengths.
- */
-
-
-void inflate_blocks_reset(s, z, c)
-inflate_blocks_statef *s;
-z_streamp z;
-uLongf *c;
-{
-  if (s->checkfn != Z_NULL)
-    *c = s->check;
-  if (s->mode == BTREE || s->mode == DTREE)
-    ZFREE(z, s->sub.trees.blens);
-  if (s->mode == CODES)
-  {
-    inflate_codes_free(s->sub.decode.codes, z);
-    inflate_trees_free(s->sub.decode.td, z);
-    inflate_trees_free(s->sub.decode.tl, z);
-  }
-  s->mode = TYPE;
-  s->bitk = 0;
-  s->bitb = 0;
-  s->read = s->write = s->window;
-  if (s->checkfn != Z_NULL)
-    z->adler = s->check = (*s->checkfn)(0L, Z_NULL, 0);
-  Trace((stderr, "inflate:   blocks reset\n"));
-}
-
-
-inflate_blocks_statef *inflate_blocks_new(z, c, w)
-z_streamp z;
-check_func c;
-uInt w;
-{
-  inflate_blocks_statef *s;
-
-  if ((s = (inflate_blocks_statef *)ZALLOC
-       (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
-    return s;
-  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
-  {
-    ZFREE(z, s);
-    return Z_NULL;
-  }
-  s->end = s->window + w;
-  s->checkfn = c;
-  s->mode = TYPE;
-  Trace((stderr, "inflate:   blocks allocated\n"));
-  inflate_blocks_reset(s, z, &s->check);
-  return s;
-}
-
-
-#ifdef DEBUG_ZLIB
-  extern uInt inflate_hufts;
-#endif
-int inflate_blocks(s, z, r)
-inflate_blocks_statef *s;
-z_streamp z;
-int r;
-{
-  uInt t;               /* temporary storage */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-
-  /* copy input/output information to locals (UPDATE macro restores) */
-  LOAD
-
-  /* process input based on current state */
-  while (1) switch (s->mode)
-  {
-    case TYPE:
-      NEEDBITS(3)
-      t = (uInt)b & 7;
-      s->last = t & 1;
-      switch (t >> 1)
-      {
-        case 0:                         /* stored */
-          Trace((stderr, "inflate:     stored block%s\n",
-                 s->last ? " (last)" : ""));
-          DUMPBITS(3)
-          t = k & 7;                    /* go to byte boundary */
-          DUMPBITS(t)
-          s->mode = LENS;               /* get length of stored block */
-          break;
-        case 1:                         /* fixed */
-          Trace((stderr, "inflate:     fixed codes block%s\n",
-                 s->last ? " (last)" : ""));
-          {
-            uInt bl, bd;
-            inflate_huft *tl, *td;
-
-            inflate_trees_fixed(&bl, &bd, &tl, &td);
-            s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
-            if (s->sub.decode.codes == Z_NULL)
-            {
-              r = Z_MEM_ERROR;
-              LEAVE
-            }
-            s->sub.decode.tl = Z_NULL;  /* don't try to free these */
-            s->sub.decode.td = Z_NULL;
-          }
-          DUMPBITS(3)
-          s->mode = CODES;
-          break;
-        case 2:                         /* dynamic */
-          Trace((stderr, "inflate:     dynamic codes block%s\n",
-                 s->last ? " (last)" : ""));
-          DUMPBITS(3)
-          s->mode = TABLE;
-          break;
-        case 3:                         /* illegal */
-          DUMPBITS(3)
-          s->mode = BADB;
-          z->msg = (char*)"invalid block type";
-          r = Z_DATA_ERROR;
-          LEAVE
-      }
-      break;
-    case LENS:
-      NEEDBITS(32)
-      if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
-      {
-        s->mode = BADB;
-        z->msg = (char*)"invalid stored block lengths";
-        r = Z_DATA_ERROR;
-        LEAVE
-      }
-      s->sub.left = (uInt)b & 0xffff;
-      b = k = 0;                      /* dump bits */
-      Tracev((stderr, "inflate:       stored length %u\n", s->sub.left));
-      s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
-      break;
-    case STORED:
-      if (n == 0)
-        LEAVE
-      NEEDOUT
-      t = s->sub.left;
-      if (t > n) t = n;
-      if (t > m) t = m;
-      zmemcpy(q, p, t);
-      p += t;  n -= t;
-      q += t;  m -= t;
-      if ((s->sub.left -= t) != 0)
-        break;
-      Tracev((stderr, "inflate:       stored end, %lu total out\n",
-              z->total_out + (q >= s->read ? q - s->read :
-              (s->end - s->read) + (q - s->window))));
-      s->mode = s->last ? DRY : TYPE;
-      break;
-    case TABLE:
-      NEEDBITS(14)
-      s->sub.trees.table = t = (uInt)b & 0x3fff;
-#ifndef PKZIP_BUG_WORKAROUND
-      if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
-      {
-        s->mode = BADB;
-        z->msg = (char*)"too many length or distance symbols";
-        r = Z_DATA_ERROR;
-        LEAVE
-      }
-#endif
-      t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
-      if (t < 19)
-        t = 19;
-      if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
-      {
-        r = Z_MEM_ERROR;
-        LEAVE
-      }
-      DUMPBITS(14)
-      s->sub.trees.index = 0;
-      Tracev((stderr, "inflate:       table sizes ok\n"));
-      s->mode = BTREE;
-    case BTREE:
-      while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
-      {
-        NEEDBITS(3)
-        s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
-        DUMPBITS(3)
-      }
-      while (s->sub.trees.index < 19)
-        s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
-      s->sub.trees.bb = 7;
-      t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
-                             &s->sub.trees.tb, z);
-      if (t != Z_OK)
-      {
-        r = t;
-        if (r == Z_DATA_ERROR) {
-          s->mode = BADB;
-          ZFREE(z, s->sub.trees.blens);
-        }
-        LEAVE
-      }
-      s->sub.trees.index = 0;
-      Tracev((stderr, "inflate:       bits tree ok\n"));
-      s->mode = DTREE;
-    case DTREE:
-      while (t = s->sub.trees.table,
-             s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
-      {
-        inflate_huft *h;
-        uInt i, j, c;
-
-        t = s->sub.trees.bb;
-        NEEDBITS(t)
-        h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
-        t = h->word.what.Bits;
-        c = h->more.Base;
-        if (c < 16)
-        {
-          DUMPBITS(t)
-          s->sub.trees.blens[s->sub.trees.index++] = c;
-        }
-        else /* c == 16..18 */
-        {
-          i = c == 18 ? 7 : c - 14;
-          j = c == 18 ? 11 : 3;
-          NEEDBITS(t + i)
-          DUMPBITS(t)
-          j += (uInt)b & inflate_mask[i];
-          DUMPBITS(i)
-          i = s->sub.trees.index;
-          t = s->sub.trees.table;
-          if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
-              (c == 16 && i < 1))
-          {
-            inflate_trees_free(s->sub.trees.tb, z);
-            ZFREE(z, s->sub.trees.blens);
-            s->mode = BADB;
-            z->msg = (char*)"invalid bit length repeat";
-            r = Z_DATA_ERROR;
-            LEAVE
-          }
-          c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
-          do {
-            s->sub.trees.blens[i++] = c;
-          } while (--j);
-          s->sub.trees.index = i;
-        }
-      }
-      inflate_trees_free(s->sub.trees.tb, z);
-      s->sub.trees.tb = Z_NULL;
-      {
-        uInt bl, bd;
-        inflate_huft *tl, *td;
-        inflate_codes_statef *c;
-
-        bl = 9;         /* must be <= 9 for lookahead assumptions */
-        bd = 6;         /* must be <= 9 for lookahead assumptions */
-        t = s->sub.trees.table;
-#ifdef DEBUG_ZLIB
-      inflate_hufts = 0;
-#endif
-        t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
-                                  s->sub.trees.blens, &bl, &bd, &tl, &td, z);
-        if (t != Z_OK)
-        {
-          if (t == (uInt)Z_DATA_ERROR) {
-            s->mode = BADB;
-            ZFREE(z, s->sub.trees.blens);
-          }
-          r = t;
-          LEAVE
-        }
-        ZFREE(z, s->sub.trees.blens);
-        Tracev((stderr, "inflate:       trees ok, %d * %d bytes used\n",
-              inflate_hufts, sizeof(inflate_huft)));
-        if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
-        {
-          inflate_trees_free(td, z);
-          inflate_trees_free(tl, z);
-          r = Z_MEM_ERROR;
-          LEAVE
-        }
-        s->sub.decode.codes = c;
-        s->sub.decode.tl = tl;
-        s->sub.decode.td = td;
-      }
-      s->mode = CODES;
-    case CODES:
-      UPDATE
-      if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
-        return inflate_flush(s, z, r);
-      r = Z_OK;
-      inflate_codes_free(s->sub.decode.codes, z);
-      inflate_trees_free(s->sub.decode.td, z);
-      inflate_trees_free(s->sub.decode.tl, z);
-      LOAD
-      Tracev((stderr, "inflate:       codes end, %lu total out\n",
-              z->total_out + (q >= s->read ? q - s->read :
-              (s->end - s->read) + (q - s->window))));
-      if (!s->last)
-      {
-        s->mode = TYPE;
-        break;
-      }
-      if (k > 7)              /* return unused byte, if any */
-      {
-        Assert(k < 16, "inflate_codes grabbed too many bytes")
-        k -= 8;
-        n++;
-        p--;                    /* can always return one */
-      }
-      s->mode = DRY;
-    case DRY:
-      FLUSH
-      if (s->read != s->write)
-        LEAVE
-      s->mode = DONEB;
-    case DONEB:
-      r = Z_STREAM_END;
-      LEAVE
-    case BADB:
-      r = Z_DATA_ERROR;
-      LEAVE
-    default:
-      r = Z_STREAM_ERROR;
-      LEAVE
-  }
-}
-
-
-int inflate_blocks_free(s, z, c)
-inflate_blocks_statef *s;
-z_streamp z;
-uLongf *c;
-{
-  inflate_blocks_reset(s, z, c);
-  ZFREE(z, s->window);
-  ZFREE(z, s);
-  Trace((stderr, "inflate:   blocks freed\n"));
-  return Z_OK;
-}
-
-
-void inflate_set_dictionary(s, d, n)
-inflate_blocks_statef *s;
-const Bytef *d;
-uInt  n;
-{
-  zmemcpy((charf *)s->window, d, n);
-  s->read = s->write = s->window + n;
-}
-
-/*
- * This subroutine adds the data at next_in/avail_in to the output history
- * without performing any output.  The output buffer must be "caught up";
- * i.e. no pending output (hence s->read equals s->write), and the state must
- * be BLOCKS (i.e. we should be willing to see the start of a series of
- * BLOCKS).  On exit, the output will also be caught up, and the checksum
- * will have been updated if need be.
- */
-int inflate_addhistory(s, z)
-inflate_blocks_statef *s;
-z_stream *z;
-{
-    uLong b;              /* bit buffer */  /* NOT USED HERE */
-    uInt k;               /* bits in bit buffer */ /* NOT USED HERE */
-    uInt t;               /* temporary storage */
-    Bytef *p;             /* input data pointer */
-    uInt n;               /* bytes available there */
-    Bytef *q;             /* output window write pointer */
-    uInt m;               /* bytes to end of window or read pointer */
-
-    if (s->read != s->write)
-       return Z_STREAM_ERROR;
-    if (s->mode != TYPE)
-       return Z_DATA_ERROR;
-
-    /* we're ready to rock */
-    LOAD
-    /* while there is input ready, copy to output buffer, moving
-     * pointers as needed.
-     */
-    while (n) {
-       t = n;  /* how many to do */
-       /* is there room until end of buffer? */
-       if (t > m) t = m;
-       /* update check information */
-       if (s->checkfn != Z_NULL)
-           s->check = (*s->checkfn)(s->check, q, t);
-       zmemcpy(q, p, t);
-       q += t;
-       p += t;
-       n -= t;
-       z->total_out += t;
-       s->read = q;    /* drag read pointer forward */
-/*      WWRAP  */      /* expand WWRAP macro by hand to handle s->read */
-       if (q == s->end) {
-           s->read = q = s->window;
-           m = WAVAIL;
-       }
-    }
-    UPDATE
-    return Z_OK;
-}
-
-
-/*
- * At the end of a Deflate-compressed PPP packet, we expect to have seen
- * a `stored' block type value but not the (zero) length bytes.
- */
-int inflate_packet_flush(s)
-    inflate_blocks_statef *s;
-{
-    if (s->mode != LENS)
-       return Z_DATA_ERROR;
-    s->mode = TYPE;
-    return Z_OK;
-}
-/* --- infblock.c */
-
-/* +++ inftrees.c */
-/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-/* #include "inftrees.h" */
-
-char inflate_copyright[] = " inflate 1.0.4 Copyright 1995-1996 Mark Adler ";
-/*
-  If you use the zlib library in a product, an acknowledgment is welcome
-  in the documentation of your product. If for some reason you cannot
-  include such an acknowledgment, I would appreciate that you keep this
-  copyright string in the executable of your product.
- */
-
-#ifndef NO_DUMMY_DECL
-struct internal_state  {int dummy;}; /* for buggy compilers */
-#endif
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-
-local int huft_build OF((
-    uIntf *,            /* code lengths in bits */
-    uInt,               /* number of codes */
-    uInt,               /* number of "simple" codes */
-    const uIntf *,      /* list of base values for non-simple codes */
-    const uIntf *,      /* list of extra bits for non-simple codes */
-    inflate_huft * FAR*,/* result: starting table */
-    uIntf *,            /* maximum lookup bits (returns actual) */
-    z_streamp ));       /* for zalloc function */
-
-local voidpf falloc OF((
-    voidpf,             /* opaque pointer (not used) */
-    uInt,               /* number of items */
-    uInt));             /* size of item */
-
-/* Tables for deflate from PKZIP's appnote.txt. */
-local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
-        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
-        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
-        /* see note #13 above about 258 */
-local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
-        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
-        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
-local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
-        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
-        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
-        8193, 12289, 16385, 24577};
-local const uInt cpdext[30] = { /* Extra bits for distance codes */
-        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
-        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
-        12, 12, 13, 13};
-
-/*
-   Huffman code decoding is performed using a multi-level table lookup.
-   The fastest way to decode is to simply build a lookup table whose
-   size is determined by the longest code.  However, the time it takes
-   to build this table can also be a factor if the data being decoded
-   is not very long.  The most common codes are necessarily the
-   shortest codes, so those codes dominate the decoding time, and hence
-   the speed.  The idea is you can have a shorter table that decodes the
-   shorter, more probable codes, and then point to subsidiary tables for
-   the longer codes.  The time it costs to decode the longer codes is
-   then traded against the time it takes to make longer tables.
-
-   This results of this trade are in the variables lbits and dbits
-   below.  lbits is the number of bits the first level table for literal/
-   length codes can decode in one step, and dbits is the same thing for
-   the distance codes.  Subsequent tables are also less than or equal to
-   those sizes.  These values may be adjusted either when all of the
-   codes are shorter than that, in which case the longest code length in
-   bits is used, or when the shortest code is *longer* than the requested
-   table size, in which case the length of the shortest code in bits is
-   used.
-
-   There are two different values for the two tables, since they code a
-   different number of possibilities each.  The literal/length table
-   codes 286 possible values, or in a flat code, a little over eight
-   bits.  The distance table codes 30 possible values, or a little less
-   than five bits, flat.  The optimum values for speed end up being
-   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
-   The optimum values may differ though from machine to machine, and
-   possibly even between compilers.  Your mileage may vary.
- */
-
-
-/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
-#define BMAX 15         /* maximum bit length of any code */
-#define N_MAX 288       /* maximum number of codes in any set */
-
-#ifdef DEBUG_ZLIB
-  uInt inflate_hufts;
-#endif
-
-local int huft_build(b, n, s, d, e, t, m, zs)
-uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
-uInt n;                 /* number of codes (assumed <= N_MAX) */
-uInt s;                 /* number of simple-valued codes (0..s-1) */
-const uIntf *d;         /* list of base values for non-simple codes */
-const uIntf *e;         /* list of extra bits for non-simple codes */
-inflate_huft * FAR *t;  /* result: starting table */
-uIntf *m;               /* maximum lookup bits, returns actual */
-z_streamp zs;           /* for zalloc function */
-/* Given a list of code lengths and a maximum table size, make a set of
-   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
-   if the given code set is incomplete (the tables are still built in this
-   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
-   lengths), or Z_MEM_ERROR if not enough memory. */
-{
-
-  uInt a;                       /* counter for codes of length k */
-  uInt c[BMAX+1];               /* bit length count table */
-  uInt f;                       /* i repeats in table every f entries */
-  int g;                        /* maximum code length */
-  int h;                        /* table level */
-  register uInt i;              /* counter, current code */
-  register uInt j;              /* counter */
-  register int k;               /* number of bits in current code */
-  int l;                        /* bits per table (returned in m) */
-  register uIntf *p;            /* pointer into c[], b[], or v[] */
-  inflate_huft *q;              /* points to current table */
-  struct inflate_huft_s r;      /* table entry for structure assignment */
-  inflate_huft *u[BMAX];        /* table stack */
-  uInt v[N_MAX];                /* values in order of bit length */
-  register int w;               /* bits before this table == (l * h) */
-  uInt x[BMAX+1];               /* bit offsets, then code stack */
-  uIntf *xp;                    /* pointer into x */
-  int y;                        /* number of dummy codes added */
-  uInt z;                       /* number of entries in current table */
-
-
-  /* Generate counts for each bit length */
-  p = c;
-#define C0 *p++ = 0;
-#define C2 C0 C0 C0 C0
-#define C4 C2 C2 C2 C2
-  C4                            /* clear c[]--assume BMAX+1 is 16 */
-  p = b;  i = n;
-  do {
-    c[*p++]++;                  /* assume all entries <= BMAX */
-  } while (--i);
-  if (c[0] == n)                /* null input--all zero length codes */
-  {
-    *t = (inflate_huft *)Z_NULL;
-    *m = 0;
-    return Z_OK;
-  }
-
-
-  /* Find minimum and maximum length, bound *m by those */
-  l = *m;
-  for (j = 1; j <= BMAX; j++)
-    if (c[j])
-      break;
-  k = j;                        /* minimum code length */
-  if ((uInt)l < j)
-    l = j;
-  for (i = BMAX; i; i--)
-    if (c[i])
-      break;
-  g = i;                        /* maximum code length */
-  if ((uInt)l > i)
-    l = i;
-  *m = l;
-
-
-  /* Adjust last length count to fill out codes, if needed */
-  for (y = 1 << j; j < i; j++, y <<= 1)
-    if ((y -= c[j]) < 0)
-      return Z_DATA_ERROR;
-  if ((y -= c[i]) < 0)
-    return Z_DATA_ERROR;
-  c[i] += y;
-
-
-  /* Generate starting offsets into the value table for each length */
-  x[1] = j = 0;
-  p = c + 1;  xp = x + 2;
-  while (--i) {                 /* note that i == g from above */
-    *xp++ = (j += *p++);
-  }
-
-
-  /* Make a table of values in order of bit lengths */
-  p = b;  i = 0;
-  do {
-    if ((j = *p++) != 0)
-      v[x[j]++] = i;
-  } while (++i < n);
-  n = x[g];                   /* set n to length of v */
-
-
-  /* Generate the Huffman codes and for each, make the table entries */
-  x[0] = i = 0;                 /* first Huffman code is zero */
-  p = v;                        /* grab values in bit order */
-  h = -1;                       /* no tables yet--level -1 */
-  w = -l;                       /* bits decoded == (l * h) */
-  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
-  q = (inflate_huft *)Z_NULL;   /* ditto */
-  z = 0;                        /* ditto */
-
-  /* go through the bit lengths (k already is bits in shortest code) */
-  for (; k <= g; k++)
-  {
-    a = c[k];
-    while (a--)
-    {
-      /* here i is the Huffman code of length k bits for value *p */
-      /* make tables up to required level */
-      while (k > w + l)
-      {
-        h++;
-        w += l;                 /* previous table always l bits */
-
-        /* compute minimum size table less than or equal to l bits */
-        z = g - w;
-        z = z > (uInt)l ? l : z;        /* table size upper limit */
-        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
-        {                       /* too few codes for k-w bit table */
-          f -= a + 1;           /* deduct codes from patterns left */
-          xp = c + k;
-          if (j < z)
-            while (++j < z)     /* try smaller tables up to z bits */
-            {
-              if ((f <<= 1) <= *++xp)
-                break;          /* enough codes to use up j bits */
-              f -= *xp;         /* else deduct codes from patterns */
-            }
-        }
-        z = 1 << j;             /* table entries for j-bit table */
-
-        /* allocate and link in new table */
-        if ((q = (inflate_huft *)ZALLOC
-             (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
-        {
-          if (h)
-            inflate_trees_free(u[0], zs);
-          return Z_MEM_ERROR;   /* not enough memory */
-        }
-#ifdef DEBUG_ZLIB
-        inflate_hufts += z + 1;
-#endif
-        *t = q + 1;             /* link to list for huft_free() */
-        *(t = &(q->next)) = Z_NULL;
-        u[h] = ++q;             /* table starts after link */
-
-        /* connect to last table, if there is one */
-        if (h)
-        {
-          x[h] = i;             /* save pattern for backing up */
-          r.bits = (Byte)l;     /* bits to dump before this table */
-          r.exop = (Byte)j;     /* bits in this table */
-          r.next = q;           /* pointer to this table */
-          j = i >> (w - l);     /* (get around Turbo C bug) */
-          u[h-1][j] = r;        /* connect to last table */
-        }
-      }
-
-      /* set up table entry in r */
-      r.bits = (Byte)(k - w);
-      if (p >= v + n)
-        r.exop = 128 + 64;      /* out of values--invalid code */
-      else if (*p < s)
-      {
-        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
-        r.base = *p++;          /* simple code is just the value */
-      }
-      else
-      {
-        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
-        r.base = d[*p++ - s];
-      }
-
-      /* fill code-like entries with r */
-      f = 1 << (k - w);
-      for (j = i >> w; j < z; j += f)
-        q[j] = r;
-
-      /* backwards increment the k-bit code i */
-      for (j = 1 << (k - 1); i & j; j >>= 1)
-        i ^= j;
-      i ^= j;
-
-      /* backup over finished tables */
-      while ((i & ((1 << w) - 1)) != x[h])
-      {
-        h--;                    /* don't need to update q */
-        w -= l;
-      }
-    }
-  }
-
-
-  /* Return Z_BUF_ERROR if we were given an incomplete table */
-  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
-}
-
-
-int inflate_trees_bits(c, bb, tb, z)
-uIntf *c;               /* 19 code lengths */
-uIntf *bb;              /* bits tree desired/actual depth */
-inflate_huft * FAR *tb; /* bits tree result */
-z_streamp z;            /* for zfree function */
-{
-  int r;
-
-  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
-  if (r == Z_DATA_ERROR)
-    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
-  else if (r == Z_BUF_ERROR || *bb == 0)
-  {
-    inflate_trees_free(*tb, z);
-    z->msg = (char*)"incomplete dynamic bit lengths tree";
-    r = Z_DATA_ERROR;
-  }
-  return r;
-}
-
-
-int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
-uInt nl;                /* number of literal/length codes */
-uInt nd;                /* number of distance codes */
-uIntf *c;               /* that many (total) code lengths */
-uIntf *bl;              /* literal desired/actual bit depth */
-uIntf *bd;              /* distance desired/actual bit depth */
-inflate_huft * FAR *tl; /* literal/length tree result */
-inflate_huft * FAR *td; /* distance tree result */
-z_streamp z;            /* for zfree function */
-{
-  int r;
-
-  /* build literal/length tree */
-  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z);
-  if (r != Z_OK || *bl == 0)
-  {
-    if (r == Z_DATA_ERROR)
-      z->msg = (char*)"oversubscribed literal/length tree";
-    else if (r != Z_MEM_ERROR)
-    {
-      inflate_trees_free(*tl, z);
-      z->msg = (char*)"incomplete literal/length tree";
-      r = Z_DATA_ERROR;
-    }
-    return r;
-  }
-
-  /* build distance tree */
-  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z);
-  if (r != Z_OK || (*bd == 0 && nl > 257))
-  {
-    if (r == Z_DATA_ERROR)
-      z->msg = (char*)"oversubscribed distance tree";
-    else if (r == Z_BUF_ERROR) {
-#ifdef PKZIP_BUG_WORKAROUND
-      r = Z_OK;
-    }
-#else
-      inflate_trees_free(*td, z);
-      z->msg = (char*)"incomplete distance tree";
-      r = Z_DATA_ERROR;
-    }
-    else if (r != Z_MEM_ERROR)
-    {
-      z->msg = (char*)"empty distance tree with lengths";
-      r = Z_DATA_ERROR;
-    }
-    inflate_trees_free(*tl, z);
-    return r;
-#endif
-  }
-
-  /* done */
-  return Z_OK;
-}
-
-
-/* build fixed tables only once--keep them here */
-local int fixed_built = 0;
-#define FIXEDH 530      /* number of hufts used by fixed tables */
-local inflate_huft fixed_mem[FIXEDH];
-local uInt fixed_bl;
-local uInt fixed_bd;
-local inflate_huft *fixed_tl;
-local inflate_huft *fixed_td;
-
-
-local voidpf falloc(q, n, s)
-voidpf q;       /* opaque pointer */
-uInt n;         /* number of items */
-uInt s;         /* size of item */
-{
-  Assert(s == sizeof(inflate_huft) && n <= *(intf *)q,
-         "inflate_trees falloc overflow");
-  *(intf *)q -= n+s-s; /* s-s to avoid warning */
-  return (voidpf)(fixed_mem + *(intf *)q);
-}
-
-
-int inflate_trees_fixed(bl, bd, tl, td)
-uIntf *bl;               /* literal desired/actual bit depth */
-uIntf *bd;               /* distance desired/actual bit depth */
-inflate_huft * FAR *tl;  /* literal/length tree result */
-inflate_huft * FAR *td;  /* distance tree result */
-{
-  /* build fixed tables if not already (multiple overlapped executions ok) */
-  if (!fixed_built)
-  {
-    int k;              /* temporary variable */
-    unsigned c[288];    /* length list for huft_build */
-    z_stream z;         /* for falloc function */
-    int f = FIXEDH;     /* number of hufts left in fixed_mem */
-
-    /* set up fake z_stream for memory routines */
-    z.zalloc = falloc;
-    z.zfree = Z_NULL;
-    z.opaque = (voidpf)&f;
-
-    /* literal table */
-    for (k = 0; k < 144; k++)
-      c[k] = 8;
-    for (; k < 256; k++)
-      c[k] = 9;
-    for (; k < 280; k++)
-      c[k] = 7;
-    for (; k < 288; k++)
-      c[k] = 8;
-    fixed_bl = 7;
-    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
-
-    /* distance table */
-    for (k = 0; k < 30; k++)
-      c[k] = 5;
-    fixed_bd = 5;
-    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
-
-    /* done */
-    Assert(f == 0, "invalid build of fixed tables");
-    fixed_built = 1;
-  }
-  *bl = fixed_bl;
-  *bd = fixed_bd;
-  *tl = fixed_tl;
-  *td = fixed_td;
-  return Z_OK;
-}
-
-
-int inflate_trees_free(t, z)
-inflate_huft *t;        /* table to free */
-z_streamp z;            /* for zfree function */
-/* Free the malloc'ed tables built by huft_build(), which makes a linked
-   list of the tables it made, with the links in a dummy first entry of
-   each table. */
-{
-  register inflate_huft *p, *q, *r;
-
-  /* Reverse linked list */
-  p = Z_NULL;
-  q = t;
-  while (q != Z_NULL)
-  {
-    r = (q - 1)->next;
-    (q - 1)->next = p;
-    p = q;
-    q = r;
-  }
-  /* Go through linked list, freeing from the malloced (t[-1]) address. */
-  while (p != Z_NULL)
-  {
-    q = (--p)->next;
-    ZFREE(z,p);
-    p = q;
-  } 
-  return Z_OK;
-}
-/* --- inftrees.c */
-
-/* +++ infcodes.c */
-/* infcodes.c -- process literals and length/distance pairs
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-/* #include "inftrees.h" */
-/* #include "infblock.h" */
-/* #include "infcodes.h" */
-/* #include "infutil.h" */
-
-/* +++ inffast.h */
-/* inffast.h -- header to use inffast.c
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-extern int inflate_fast OF((
-    uInt,
-    uInt,
-    inflate_huft *,
-    inflate_huft *,
-    inflate_blocks_statef *,
-    z_streamp ));
-/* --- inffast.h */
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-/* inflate codes private state */
-struct inflate_codes_state {
-
-  /* mode */
-  enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
-      START,    /* x: set up for LEN */
-      LEN,      /* i: get length/literal/eob next */
-      LENEXT,   /* i: getting length extra (have base) */
-      DIST,     /* i: get distance next */
-      DISTEXT,  /* i: getting distance extra */
-      COPY,     /* o: copying bytes in window, waiting for space */
-      LIT,      /* o: got literal, waiting for output space */
-      WASH,     /* o: got eob, possibly still output waiting */
-      END,      /* x: got eob and all data flushed */
-      BADCODE}  /* x: got error */
-    mode;               /* current inflate_codes mode */
-
-  /* mode dependent information */
-  uInt len;
-  union {
-    struct {
-      inflate_huft *tree;       /* pointer into tree */
-      uInt need;                /* bits needed */
-    } code;             /* if LEN or DIST, where in tree */
-    uInt lit;           /* if LIT, literal */
-    struct {
-      uInt get;                 /* bits to get for extra */
-      uInt dist;                /* distance back to copy from */
-    } copy;             /* if EXT or COPY, where and how much */
-  } sub;                /* submode */
-
-  /* mode independent information */
-  Byte lbits;           /* ltree bits decoded per branch */
-  Byte dbits;           /* dtree bits decoder per branch */
-  inflate_huft *ltree;          /* literal/length/eob tree */
-  inflate_huft *dtree;          /* distance tree */
-
-};
-
-
-inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
-uInt bl, bd;
-inflate_huft *tl;
-inflate_huft *td; /* need separate declaration for Borland C++ */
-z_streamp z;
-{
-  inflate_codes_statef *c;
-
-  if ((c = (inflate_codes_statef *)
-       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
-  {
-    c->mode = START;
-    c->lbits = (Byte)bl;
-    c->dbits = (Byte)bd;
-    c->ltree = tl;
-    c->dtree = td;
-    Tracev((stderr, "inflate:       codes new\n"));
-  }
-  return c;
-}
-
-
-int inflate_codes(s, z, r)
-inflate_blocks_statef *s;
-z_streamp z;
-int r;
-{
-  uInt j;               /* temporary storage */
-  inflate_huft *t;      /* temporary pointer */
-  uInt e;               /* extra bits or operation */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-  Bytef *f;             /* pointer to copy strings from */
-  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */
-
-  /* copy input/output information to locals (UPDATE macro restores) */
-  LOAD
-
-  /* process input and output based on current state */
-  while (1) switch (c->mode)
-  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
-    case START:         /* x: set up for LEN */
-#ifndef SLOW
-      if (m >= 258 && n >= 10)
-      {
-        UPDATE
-        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
-        LOAD
-        if (r != Z_OK)
-        {
-          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
-          break;
-        }
-      }
-#endif /* !SLOW */
-      c->sub.code.need = c->lbits;
-      c->sub.code.tree = c->ltree;
-      c->mode = LEN;
-    case LEN:           /* i: get length/literal/eob next */
-      j = c->sub.code.need;
-      NEEDBITS(j)
-      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
-      DUMPBITS(t->bits)
-      e = (uInt)(t->exop);
-      if (e == 0)               /* literal */
-      {
-        c->sub.lit = t->base;
-        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                 "inflate:         literal '%c'\n" :
-                 "inflate:         literal 0x%02x\n", t->base));
-        c->mode = LIT;
-        break;
-      }
-      if (e & 16)               /* length */
-      {
-        c->sub.copy.get = e & 15;
-        c->len = t->base;
-        c->mode = LENEXT;
-        break;
-      }
-      if ((e & 64) == 0)        /* next table */
-      {
-        c->sub.code.need = e;
-        c->sub.code.tree = t->next;
-        break;
-      }
-      if (e & 32)               /* end of block */
-      {
-        Tracevv((stderr, "inflate:         end of block\n"));
-        c->mode = WASH;
-        break;
-      }
-      c->mode = BADCODE;        /* invalid code */
-      z->msg = (char*)"invalid literal/length code";
-      r = Z_DATA_ERROR;
-      LEAVE
-    case LENEXT:        /* i: getting length extra (have base) */
-      j = c->sub.copy.get;
-      NEEDBITS(j)
-      c->len += (uInt)b & inflate_mask[j];
-      DUMPBITS(j)
-      c->sub.code.need = c->dbits;
-      c->sub.code.tree = c->dtree;
-      Tracevv((stderr, "inflate:         length %u\n", c->len));
-      c->mode = DIST;
-    case DIST:          /* i: get distance next */
-      j = c->sub.code.need;
-      NEEDBITS(j)
-      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
-      DUMPBITS(t->bits)
-      e = (uInt)(t->exop);
-      if (e & 16)               /* distance */
-      {
-        c->sub.copy.get = e & 15;
-        c->sub.copy.dist = t->base;
-        c->mode = DISTEXT;
-        break;
-      }
-      if ((e & 64) == 0)        /* next table */
-      {
-        c->sub.code.need = e;
-        c->sub.code.tree = t->next;
-        break;
-      }
-      c->mode = BADCODE;        /* invalid code */
-      z->msg = (char*)"invalid distance code";
-      r = Z_DATA_ERROR;
-      LEAVE
-    case DISTEXT:       /* i: getting distance extra */
-      j = c->sub.copy.get;
-      NEEDBITS(j)
-      c->sub.copy.dist += (uInt)b & inflate_mask[j];
-      DUMPBITS(j)
-      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
-      c->mode = COPY;
-    case COPY:          /* o: copying bytes in window, waiting for space */
-#ifndef __TURBOC__ /* Turbo C bug for following expression */
-      f = (uInt)(q - s->window) < c->sub.copy.dist ?
-          s->end - (c->sub.copy.dist - (q - s->window)) :
-          q - c->sub.copy.dist;
-#else
-      f = q - c->sub.copy.dist;
-      if ((uInt)(q - s->window) < c->sub.copy.dist)
-        f = s->end - (c->sub.copy.dist - (uInt)(q - s->window));
-#endif
-      while (c->len)
-      {
-        NEEDOUT
-        OUTBYTE(*f++)
-        if (f == s->end)
-          f = s->window;
-        c->len--;
-      }
-      c->mode = START;
-      break;
-    case LIT:           /* o: got literal, waiting for output space */
-      NEEDOUT
-      OUTBYTE(c->sub.lit)
-      c->mode = START;
-      break;
-    case WASH:          /* o: got eob, possibly more output */
-      FLUSH
-      if (s->read != s->write)
-        LEAVE
-      c->mode = END;
-    case END:
-      r = Z_STREAM_END;
-      LEAVE
-    case BADCODE:       /* x: got error */
-      r = Z_DATA_ERROR;
-      LEAVE
-    default:
-      r = Z_STREAM_ERROR;
-      LEAVE
-  }
-}
-
-
-void inflate_codes_free(c, z)
-inflate_codes_statef *c;
-z_streamp z;
-{
-  ZFREE(z, c);
-  Tracev((stderr, "inflate:       codes free\n"));
-}
-/* --- infcodes.c */
-
-/* +++ infutil.c */
-/* inflate_util.c -- data and routines common to blocks and codes
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-/* #include "infblock.h" */
-/* #include "inftrees.h" */
-/* #include "infcodes.h" */
-/* #include "infutil.h" */
-
-#ifndef NO_DUMMY_DECL
-struct inflate_codes_state {int dummy;}; /* for buggy compilers */
-#endif
-
-/* And'ing with mask[n] masks the lower n bits */
-uInt inflate_mask[17] = {
-    0x0000,
-    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
-    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
-};
-
-
-/* copy as much as possible from the sliding window to the output area */
-int inflate_flush(s, z, r)
-inflate_blocks_statef *s;
-z_streamp z;
-int r;
-{
-  uInt n;
-  Bytef *p;
-  Bytef *q;
-
-  /* local copies of source and destination pointers */
-  p = z->next_out;
-  q = s->read;
-
-  /* compute number of bytes to copy as far as end of window */
-  n = (uInt)((q <= s->write ? s->write : s->end) - q);
-  if (n > z->avail_out) n = z->avail_out;
-  if (n && r == Z_BUF_ERROR) r = Z_OK;
-
-  /* update counters */
-  z->avail_out -= n;
-  z->total_out += n;
-
-  /* update check information */
-  if (s->checkfn != Z_NULL)
-    z->adler = s->check = (*s->checkfn)(s->check, q, n);
-
-  /* copy as far as end of window */
-  if (p != Z_NULL) {
-    zmemcpy(p, q, n);
-    p += n;
-  }
-  q += n;
-
-  /* see if more to copy at beginning of window */
-  if (q == s->end)
-  {
-    /* wrap pointers */
-    q = s->window;
-    if (s->write == s->end)
-      s->write = s->window;
-
-    /* compute bytes to copy */
-    n = (uInt)(s->write - q);
-    if (n > z->avail_out) n = z->avail_out;
-    if (n && r == Z_BUF_ERROR) r = Z_OK;
-
-    /* update counters */
-    z->avail_out -= n;
-    z->total_out += n;
-
-    /* update check information */
-    if (s->checkfn != Z_NULL)
-      z->adler = s->check = (*s->checkfn)(s->check, q, n);
-
-    /* copy */
-    if (p != Z_NULL) {
-      zmemcpy(p, q, n);
-      p += n;
-    }
-    q += n;
-  }
-
-  /* update pointers */
-  z->next_out = p;
-  s->read = q;
-
-  /* done */
-  return r;
-}
-/* --- infutil.c */
-
-/* +++ inffast.c */
-/* inffast.c -- process literals and length/distance pairs fast
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* #include "zutil.h" */
-/* #include "inftrees.h" */
-/* #include "infblock.h" */
-/* #include "infcodes.h" */
-/* #include "infutil.h" */
-/* #include "inffast.h" */
-
-#ifndef NO_DUMMY_DECL
-struct inflate_codes_state {int dummy;}; /* for buggy compilers */
-#endif
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-/* macros for bit input with no checking and for returning unused bytes */
-#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
-#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
-
-/* Called with number of bytes left to write in window at least 258
-   (the maximum string length) and number of input bytes available
-   at least ten.  The ten bytes are six bytes for the longest length/
-   distance pair plus four bytes for overloading the bit buffer. */
-
-int inflate_fast(bl, bd, tl, td, s, z)
-uInt bl, bd;
-inflate_huft *tl;
-inflate_huft *td; /* need separate declaration for Borland C++ */
-inflate_blocks_statef *s;
-z_streamp z;
-{
-  inflate_huft *t;      /* temporary pointer */
-  uInt e;               /* extra bits or operation */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-  uInt ml;              /* mask for literal/length tree */
-  uInt md;              /* mask for distance tree */
-  uInt c;               /* bytes to copy */
-  uInt d;               /* distance back to copy from */
-  Bytef *r;             /* copy source pointer */
-
-  /* load input, output, bit values */
-  LOAD
-
-  /* initialize masks */
-  ml = inflate_mask[bl];
-  md = inflate_mask[bd];
-
-  /* do until not enough input or output space for fast loop */
-  do {                          /* assume called with m >= 258 && n >= 10 */
-    /* get literal/length code */
-    GRABBITS(20)                /* max bits for literal/length code */
-    if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
-    {
-      DUMPBITS(t->bits)
-      Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                "inflate:         * literal '%c'\n" :
-                "inflate:         * literal 0x%02x\n", t->base));
-      *q++ = (Byte)t->base;
-      m--;
-      continue;
-    }
-    do {
-      DUMPBITS(t->bits)
-      if (e & 16)
-      {
-        /* get extra bits for length */
-        e &= 15;
-        c = t->base + ((uInt)b & inflate_mask[e]);
-        DUMPBITS(e)
-        Tracevv((stderr, "inflate:         * length %u\n", c));
-
-        /* decode distance base of block to copy */
-        GRABBITS(15);           /* max bits for distance code */
-        e = (t = td + ((uInt)b & md))->exop;
-        do {
-          DUMPBITS(t->bits)
-          if (e & 16)
-          {
-            /* get extra bits to add to distance base */
-            e &= 15;
-            GRABBITS(e)         /* get extra bits (up to 13) */
-            d = t->base + ((uInt)b & inflate_mask[e]);
-            DUMPBITS(e)
-            Tracevv((stderr, "inflate:         * distance %u\n", d));
-
-            /* do the copy */
-            m -= c;
-            if ((uInt)(q - s->window) >= d)     /* offset before dest */
-            {                                   /*  just copy */
-              r = q - d;
-              *q++ = *r++;  c--;        /* minimum count is three, */
-              *q++ = *r++;  c--;        /*  so unroll loop a little */
-            }
-            else                        /* else offset after destination */
-            {
-              e = d - (uInt)(q - s->window); /* bytes from offset to end */
-              r = s->end - e;           /* pointer to offset */
-              if (c > e)                /* if source crosses, */
-              {
-                c -= e;                 /* copy to end of window */
-                do {
-                  *q++ = *r++;
-                } while (--e);
-                r = s->window;          /* copy rest from start of window */
-              }
-            }
-            do {                        /* copy all or what's left */
-              *q++ = *r++;
-            } while (--c);
-            break;
-          }
-          else if ((e & 64) == 0)
-            e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
-          else
-          {
-            z->msg = (char*)"invalid distance code";
-            UNGRAB
-            UPDATE
-            return Z_DATA_ERROR;
-          }
-        } while (1);
-        break;
-      }
-      if ((e & 64) == 0)
-      {
-        if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
-        {
-          DUMPBITS(t->bits)
-          Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                    "inflate:         * literal '%c'\n" :
-                    "inflate:         * literal 0x%02x\n", t->base));
-          *q++ = (Byte)t->base;
-          m--;
-          break;
-        }
-      }
-      else if (e & 32)
-      {
-        Tracevv((stderr, "inflate:         * end of block\n"));
-        UNGRAB
-        UPDATE
-        return Z_STREAM_END;
-      }
-      else
-      {
-        z->msg = (char*)"invalid literal/length code";
-        UNGRAB
-        UPDATE
-        return Z_DATA_ERROR;
-      }
-    } while (1);
-  } while (m >= 258 && n >= 10);
-
-  /* not enough input or output--restore pointers and return */
-  UNGRAB
-  UPDATE
-  return Z_OK;
-}
-/* --- inffast.c */
-
-/* +++ zutil.c */
-/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: zutil.c,v 1.17 1996/07/24 13:41:12 me Exp $ */
-
-#ifdef DEBUG_ZLIB
-#include <stdio.h>
-#endif
-
-/* #include "zutil.h" */
-
-#ifndef NO_DUMMY_DECL
-struct internal_state      {int dummy;}; /* for buggy compilers */
-#endif
-
-#ifndef STDC
-extern void exit OF((int));
-#endif
-
-const char *z_errmsg[10] = {
-"need dictionary",     /* Z_NEED_DICT       2  */
-"stream end",          /* Z_STREAM_END      1  */
-"",                    /* Z_OK              0  */
-"file error",          /* Z_ERRNO         (-1) */
-"stream error",        /* Z_STREAM_ERROR  (-2) */
-"data error",          /* Z_DATA_ERROR    (-3) */
-"insufficient memory", /* Z_MEM_ERROR     (-4) */
-"buffer error",        /* Z_BUF_ERROR     (-5) */
-"incompatible version",/* Z_VERSION_ERROR (-6) */
-""};
-
-
-const char *zlibVersion()
-{
-    return ZLIB_VERSION;
-}
-
-#ifdef DEBUG_ZLIB
-void z_error (m)
-    char *m;
-{
-    fprintf(stderr, "%s\n", m);
-    exit(1);
-}
-#endif
-
-#ifndef HAVE_MEMCPY
-
-void zmemcpy(dest, source, len)
-    Bytef* dest;
-    Bytef* source;
-    uInt  len;
-{
-    if (len == 0) return;
-    do {
-        *dest++ = *source++; /* ??? to be unrolled */
-    } while (--len != 0);
-}
-
-int zmemcmp(s1, s2, len)
-    Bytef* s1;
-    Bytef* s2;
-    uInt  len;
-{
-    uInt j;
-
-    for (j = 0; j < len; j++) {
-        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
-    }
-    return 0;
-}
-
-void zmemzero(dest, len)
-    Bytef* dest;
-    uInt  len;
-{
-    if (len == 0) return;
-    do {
-        *dest++ = 0;  /* ??? to be unrolled */
-    } while (--len != 0);
-}
-#endif
-
-#ifdef __TURBOC__
-#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
-/* Small and medium model in Turbo C are for now limited to near allocation
- * with reduced MAX_WBITS and MAX_MEM_LEVEL
- */
-#  define MY_ZCALLOC
-
-/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
- * and farmalloc(64K) returns a pointer with an offset of 8, so we
- * must fix the pointer. Warning: the pointer must be put back to its
- * original form in order to free it, use zcfree().
- */
-
-#define MAX_PTR 10
-/* 10*64K = 640K */
-
-local int next_ptr = 0;
-
-typedef struct ptr_table_s {
-    voidpf org_ptr;
-    voidpf new_ptr;
-} ptr_table;
-
-local ptr_table table[MAX_PTR];
-/* This table is used to remember the original form of pointers
- * to large buffers (64K). Such pointers are normalized with a zero offset.
- * Since MSDOS is not a preemptive multitasking OS, this table is not
- * protected from concurrent access. This hack doesn't work anyway on
- * a protected system like OS/2. Use Microsoft C instead.
- */
-
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
-    voidpf buf = opaque; /* just to make some compilers happy */
-    ulg bsize = (ulg)items*size;
-
-    /* If we allocate less than 65520 bytes, we assume that farmalloc
-     * will return a usable pointer which doesn't have to be normalized.
-     */
-    if (bsize < 65520L) {
-        buf = farmalloc(bsize);
-        if (*(ush*)&buf != 0) return buf;
-    } else {
-        buf = farmalloc(bsize + 16L);
-    }
-    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
-    table[next_ptr].org_ptr = buf;
-
-    /* Normalize the pointer to seg:0 */
-    *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
-    *(ush*)&buf = 0;
-    table[next_ptr++].new_ptr = buf;
-    return buf;
-}
-
-void  zcfree (voidpf opaque, voidpf ptr)
-{
-    int n;
-    if (*(ush*)&ptr != 0) { /* object < 64K */
-        farfree(ptr);
-        return;
-    }
-    /* Find the original pointer */
-    for (n = 0; n < next_ptr; n++) {
-        if (ptr != table[n].new_ptr) continue;
-
-        farfree(table[n].org_ptr);
-        while (++n < next_ptr) {
-            table[n-1] = table[n];
-        }
-        next_ptr--;
-        return;
-    }
-    ptr = opaque; /* just to make some compilers happy */
-    Assert(0, "zcfree: ptr not found");
-}
-#endif
-#endif /* __TURBOC__ */
-
-
-#if defined(M_I86) && !defined(__32BIT__)
-/* Microsoft C in 16-bit mode */
-
-#  define MY_ZCALLOC
-
-#if (!defined(_MSC_VER) || (_MSC_VER < 600))
-#  define _halloc  halloc
-#  define _hfree   hfree
-#endif
-
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
-    if (opaque) opaque = 0; /* to make compiler happy */
-    return _halloc((long)items, size);
-}
-
-void  zcfree (voidpf opaque, voidpf ptr)
-{
-    if (opaque) opaque = 0; /* to make compiler happy */
-    _hfree(ptr);
-}
-
-#endif /* MSC */
-
-
-#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-
-#ifndef STDC
-extern voidp  calloc OF((uInt items, uInt size));
-extern void   free   OF((voidpf ptr));
-#endif
-
-voidpf zcalloc (opaque, items, size)
-    voidpf opaque;
-    unsigned items;
-    unsigned size;
-{
-    if (opaque) items += size - size; /* make compiler happy */
-    return (voidpf)calloc(items, size);
-}
-
-void  zcfree (opaque, ptr)
-    voidpf opaque;
-    voidpf ptr;
-{
-    free(ptr);
-    if (opaque) return; /* make compiler happy */
-}
-
-#endif /* MY_ZCALLOC */
-/* --- zutil.c */
-
-/* +++ adler32.c */
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995-1996 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: adler32.c,v 1.10 1996/05/22 11:52:18 me Exp $ */
-
-/* #include "zlib.h" */
-
-#define BASE 65521L /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
-#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
-#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
-#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
-#define DO16(buf)   DO8(buf,0); DO8(buf,8);
-
-/* ========================================================================= */
-uLong adler32(adler, buf, len)
-    uLong adler;
-    const Bytef *buf;
-    uInt len;
-{
-    unsigned long s1 = adler & 0xffff;
-    unsigned long s2 = (adler >> 16) & 0xffff;
-    int k;
-
-    if (buf == Z_NULL) return 1L;
-
-    while (len > 0) {
-        k = len < NMAX ? len : NMAX;
-        len -= k;
-        while (k >= 16) {
-            DO16(buf);
-           buf += 16;
-            k -= 16;
-        }
-        if (k != 0) do {
-            s1 += *buf++;
-           s2 += s1;
-        } while (--k);
-        s1 %= BASE;
-        s2 %= BASE;
-    }
-    return (s2 << 16) | s1;
-}
-/* --- adler32.c */
diff --git a/common/zlib.h b/common/zlib.h
deleted file mode 100644 (file)
index 702a402..0000000
+++ /dev/null
@@ -1,1010 +0,0 @@
-/*     $Id: zlib.h,v 1.7 1997/11/27 06:03:33 paulus Exp $      */
-
-/*
- * This file is derived from zlib.h and zconf.h from the zlib-1.0.4
- * distribution by Jean-loup Gailly and Mark Adler, with some additions
- * by Paul Mackerras to aid in implementing Deflate compression and
- * decompression for PPP packets.
- */
-
-/*
- *  ==FILEVERSION 971127==
- *
- * This marker is used by the Linux installation script to determine
- * whether an up-to-date version of this file is already installed.
- */
-
-
-/* +++ zlib.h */
-/* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 1.0.4, Jul 24th, 1996.
-
-  Copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jean-loup Gailly        Mark Adler
-  gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
-
-
-  The data format used by the zlib library is described by RFCs (Request for
-  Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
-  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
-*/
-
-#ifndef _ZLIB_H
-#define _ZLIB_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* +++ zconf.h */
-/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: zconf.h,v 1.20 1996/07/02 15:09:28 me Exp $ */
-
-#ifndef _ZCONF_H
-#define _ZCONF_H
-
-/*
- * If you *really* need a unique prefix for all types and library functions,
- * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
- */
-#ifdef Z_PREFIX
-#  define deflateInit_ z_deflateInit_
-#  define deflate      z_deflate
-#  define deflateEnd   z_deflateEnd
-#  define inflateInit_         z_inflateInit_
-#  define inflate      z_inflate
-#  define inflateEnd   z_inflateEnd
-#  define deflateInit2_        z_deflateInit2_
-#  define deflateSetDictionary z_deflateSetDictionary
-#  define deflateCopy  z_deflateCopy
-#  define deflateReset z_deflateReset
-#  define deflateParams        z_deflateParams
-#  define inflateInit2_        z_inflateInit2_
-#  define inflateSetDictionary z_inflateSetDictionary
-#  define inflateSync  z_inflateSync
-#  define inflateReset z_inflateReset
-#  define compress     z_compress
-#  define uncompress   z_uncompress
-#  define adler32      z_adler32
-#  define crc32                z_crc32
-#  define get_crc_table z_get_crc_table
-
-#  define Byte         z_Byte
-#  define uInt         z_uInt
-#  define uLong                z_uLong
-#  define Bytef                z_Bytef
-#  define charf                z_charf
-#  define intf         z_intf
-#  define uIntf                z_uIntf
-#  define uLongf       z_uLongf
-#  define voidpf       z_voidpf
-#  define voidp                z_voidp
-#endif
-
-#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
-#  define WIN32
-#endif
-#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
-#  ifndef __32BIT__
-#    define __32BIT__
-#  endif
-#endif
-#if defined(__MSDOS__) && !defined(MSDOS)
-#  define MSDOS
-#endif
-
-/*
- * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
- * than 64k bytes at a time (needed on systems with 16-bit int).
- */
-#if defined(MSDOS) && !defined(__32BIT__)
-#  define MAXSEG_64K
-#endif
-#ifdef MSDOS
-#  define UNALIGNED_OK
-#endif
-
-#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32))  && !defined(STDC)
-#  define STDC
-#endif
-#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
-#  define STDC
-#endif
-
-#ifndef STDC
-#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
-#    define const
-#  endif
-#endif
-
-/* Some Mac compilers merge all .h files incorrectly: */
-#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
-#  define NO_DUMMY_DECL
-#endif
-
-/* Maximum value for memLevel in deflateInit2 */
-#ifndef MAX_MEM_LEVEL
-#  ifdef MAXSEG_64K
-#    define MAX_MEM_LEVEL 8
-#  else
-#    define MAX_MEM_LEVEL 9
-#  endif
-#endif
-
-/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
-#ifndef MAX_WBITS
-#  define MAX_WBITS   15 /* 32K LZ77 window */
-#endif
-
-/* The memory requirements for deflate are (in bytes):
-            1 << (windowBits+2)   +  1 << (memLevel+9)
- that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
- plus a few kilobytes for small objects. For example, if you want to reduce
- the default memory requirements from 256K to 128K, compile with
-     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
- Of course this will generally degrade compression (there's no free lunch).
-
-   The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
- for small objects.
-*/
-
-                        /* Type declarations */
-
-#ifndef OF /* function prototypes */
-#  ifdef STDC
-#    define OF(args)  args
-#  else
-#    define OF(args)  ()
-#  endif
-#endif
-
-/* The following definitions for FAR are needed only for MSDOS mixed
- * model programming (small or medium model with some far allocations).
- * This was tested only with MSC; for other MSDOS compilers you may have
- * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
- * just define FAR to be empty.
- */
-#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
-   /* MSC small or medium model */
-#  define SMALL_MEDIUM
-#  ifdef _MSC_VER
-#    define FAR __far
-#  else
-#    define FAR far
-#  endif
-#endif
-#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
-#  ifndef __32BIT__
-#    define SMALL_MEDIUM
-#    define FAR __far
-#  endif
-#endif
-#ifndef FAR
-#   define FAR
-#endif
-
-typedef unsigned char  Byte;  /* 8 bits */
-typedef unsigned int   uInt;  /* 16 bits or more */
-typedef unsigned long  uLong; /* 32 bits or more */
-
-#if defined(__BORLANDC__) && defined(SMALL_MEDIUM)
-   /* Borland C/C++ ignores FAR inside typedef */
-#  define Bytef Byte FAR
-#else
-   typedef Byte  FAR Bytef;
-#endif
-typedef char  FAR charf;
-typedef int   FAR intf;
-typedef uInt  FAR uIntf;
-typedef uLong FAR uLongf;
-
-#ifdef STDC
-   typedef void FAR *voidpf;
-   typedef void     *voidp;
-#else
-   typedef Byte FAR *voidpf;
-   typedef Byte     *voidp;
-#endif
-
-
-/* Compile with -DZLIB_DLL for Windows DLL support */
-#if (defined(_WINDOWS) || defined(WINDOWS)) && defined(ZLIB_DLL)
-#  include <windows.h>
-#  define EXPORT  WINAPI
-#else
-#  define EXPORT
-#endif
-
-#endif /* _ZCONF_H */
-/* --- zconf.h */
-
-#define ZLIB_VERSION "1.0.4P"
-
-/* 
-     The 'zlib' compression library provides in-memory compression and
-  decompression functions, including integrity checks of the uncompressed
-  data.  This version of the library supports only one compression method
-  (deflation) but other algorithms may be added later and will have the same
-  stream interface.
-
-     For compression the application must provide the output buffer and
-  may optionally provide the input buffer for optimization. For decompression,
-  the application must provide the input buffer and may optionally provide
-  the output buffer for optimization.
-
-     Compression can be done in a single step if the buffers are large
-  enough (for example if an input file is mmap'ed), or can be done by
-  repeated calls of the compression function.  In the latter case, the
-  application must provide more input and/or consume the output
-  (providing more output space) before each call.
-
-     The library does not install any signal handler. It is recommended to
-  add at least a handler for SIGSEGV when decompressing; the library checks
-  the consistency of the input data whenever possible but may go nuts
-  for some forms of corrupted input.
-*/
-
-typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
-
-struct internal_state;
-
-typedef struct z_stream_s {
-    Bytef    *next_in;  /* next input byte */
-    uInt     avail_in;  /* number of bytes available at next_in */
-    uLong    total_in;  /* total nb of input bytes read so far */
-
-    Bytef    *next_out; /* next output byte should be put there */
-    uInt     avail_out; /* remaining free space at next_out */
-    uLong    total_out; /* total nb of bytes output so far */
-
-    char     *msg;      /* last error message, NULL if no error */
-    struct internal_state FAR *state; /* not visible by applications */
-
-    alloc_func zalloc;  /* used to allocate the internal state */
-    free_func  zfree;   /* used to free the internal state */
-    voidpf     opaque;  /* private data object passed to zalloc and zfree */
-
-    int     data_type;  /* best guess about the data type: ascii or binary */
-    uLong   adler;      /* adler32 value of the uncompressed data */
-    uLong   reserved;   /* reserved for future use */
-} z_stream;
-
-typedef z_stream FAR *z_streamp;
-
-/*
-   The application must update next_in and avail_in when avail_in has
-   dropped to zero. It must update next_out and avail_out when avail_out
-   has dropped to zero. The application must initialize zalloc, zfree and
-   opaque before calling the init function. All other fields are set by the
-   compression library and must not be updated by the application.
-
-   The opaque value provided by the application will be passed as the first
-   parameter for calls of zalloc and zfree. This can be useful for custom
-   memory management. The compression library attaches no meaning to the
-   opaque value.
-
-   zalloc must return Z_NULL if there is not enough memory for the object.
-   On 16-bit systems, the functions zalloc and zfree must be able to allocate
-   exactly 65536 bytes, but will not be required to allocate more than this
-   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
-   pointers returned by zalloc for objects of exactly 65536 bytes *must*
-   have their offset normalized to zero. The default allocation function
-   provided by this library ensures this (see zutil.c). To reduce memory
-   requirements and avoid any allocation of 64K objects, at the expense of
-   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
-
-   The fields total_in and total_out can be used for statistics or
-   progress reports. After compression, total_in holds the total size of
-   the uncompressed data and may be saved for use in the decompressor
-   (particularly if the decompressor wants to decompress everything in
-   a single step).
-*/
-
-                        /* constants */
-
-#define Z_NO_FLUSH      0
-#define Z_PARTIAL_FLUSH 1
-#define Z_PACKET_FLUSH 2
-#define Z_SYNC_FLUSH    3
-#define Z_FULL_FLUSH    4
-#define Z_FINISH        5
-/* Allowed flush values; see deflate() below for details */
-
-#define Z_OK            0
-#define Z_STREAM_END    1
-#define Z_NEED_DICT     2
-#define Z_ERRNO        (-1)
-#define Z_STREAM_ERROR (-2)
-#define Z_DATA_ERROR   (-3)
-#define Z_MEM_ERROR    (-4)
-#define Z_BUF_ERROR    (-5)
-#define Z_VERSION_ERROR (-6)
-/* Return codes for the compression/decompression functions. Negative
- * values are errors, positive values are used for special but normal events.
- */
-
-#define Z_NO_COMPRESSION         0
-#define Z_BEST_SPEED             1
-#define Z_BEST_COMPRESSION       9
-#define Z_DEFAULT_COMPRESSION  (-1)
-/* compression levels */
-
-#define Z_FILTERED            1
-#define Z_HUFFMAN_ONLY        2
-#define Z_DEFAULT_STRATEGY    0
-/* compression strategy; see deflateInit2() below for details */
-
-#define Z_BINARY   0
-#define Z_ASCII    1
-#define Z_UNKNOWN  2
-/* Possible values of the data_type field */
-
-#define Z_DEFLATED   8
-/* The deflate compression method (the only one supported in this version) */
-
-#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
-
-#define zlib_version zlibVersion()
-/* for compatibility with versions < 1.0.2 */
-
-                        /* basic functions */
-
-extern const char * EXPORT zlibVersion OF((void));
-/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
-   If the first character differs, the library code actually used is
-   not compatible with the zlib.h header file used by the application.
-   This check is automatically made by deflateInit and inflateInit.
- */
-
-/* 
-extern int EXPORT deflateInit OF((z_streamp strm, int level));
-
-     Initializes the internal stream state for compression. The fields
-   zalloc, zfree and opaque must be initialized before by the caller.
-   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
-   use default allocation functions.
-
-     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
-   1 gives best speed, 9 gives best compression, 0 gives no compression at
-   all (the input data is simply copied a block at a time).
-   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
-   compression (currently equivalent to level 6).
-
-     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
-   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
-   with the version assumed by the caller (ZLIB_VERSION).
-   msg is set to null if there is no error message.  deflateInit does not
-   perform any compression: this will be done by deflate().
-*/
-
-
-extern int EXPORT deflate OF((z_streamp strm, int flush));
-/*
-  Performs one or both of the following actions:
-
-  - Compress more input starting at next_in and update next_in and avail_in
-    accordingly. If not all input can be processed (because there is not
-    enough room in the output buffer), next_in and avail_in are updated and
-    processing will resume at this point for the next call of deflate().
-
-  - Provide more output starting at next_out and update next_out and avail_out
-    accordingly. This action is forced if the parameter flush is non zero.
-    Forcing flush frequently degrades the compression ratio, so this parameter
-    should be set only when necessary (in interactive applications).
-    Some output may be provided even if flush is not set.
-
-  Before the call of deflate(), the application should ensure that at least
-  one of the actions is possible, by providing more input and/or consuming
-  more output, and updating avail_in or avail_out accordingly; avail_out
-  should never be zero before the call. The application can consume the
-  compressed output when it wants, for example when the output buffer is full
-  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
-  and with zero avail_out, it must be called again after making room in the
-  output buffer because there might be more output pending.
-
-    If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
-  block is terminated and flushed to the output buffer so that the
-  decompressor can get all input data available so far. For method 9, a future
-  variant on method 8, the current block will be flushed but not terminated.
-  Z_SYNC_FLUSH has the same effect as partial flush except that the compressed
-  output is byte aligned (the compressor can clear its internal bit buffer)
-  and the current block is always terminated; this can be useful if the
-  compressor has to be restarted from scratch after an interruption (in which
-  case the internal state of the compressor may be lost).
-    If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
-  special marker is output and the compression dictionary is discarded; this
-  is useful to allow the decompressor to synchronize if one compressed block
-  has been damaged (see inflateSync below).  Flushing degrades compression and
-  so should be used only when necessary.  Using Z_FULL_FLUSH too often can
-  seriously degrade the compression. If deflate returns with avail_out == 0,
-  this function must be called again with the same value of the flush
-  parameter and more output space (updated avail_out), until the flush is
-  complete (deflate returns with non-zero avail_out).
-
-    If the parameter flush is set to Z_PACKET_FLUSH, the compression
-  block is terminated, and a zero-length stored block is output,
-  omitting the length bytes (the effect of this is that the 3-bit type
-  code 000 for a stored block is output, and the output is then
-  byte-aligned).  This is designed for use at the end of a PPP packet.
-
-    If the parameter flush is set to Z_FINISH, pending input is processed,
-  pending output is flushed and deflate returns with Z_STREAM_END if there
-  was enough output space; if deflate returns with Z_OK, this function must be
-  called again with Z_FINISH and more output space (updated avail_out) but no
-  more input data, until it returns with Z_STREAM_END or an error. After
-  deflate has returned Z_STREAM_END, the only possible operations on the
-  stream are deflateReset or deflateEnd.
-  
-    Z_FINISH can be used immediately after deflateInit if all the compression
-  is to be done in a single step. In this case, avail_out must be at least
-  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
-  Z_STREAM_END, then it must be called again as described above.
-
-    deflate() may update data_type if it can make a good guess about
-  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
-  binary. This field is only for information purposes and does not affect
-  the compression algorithm in any manner.
-
-    deflate() returns Z_OK if some progress has been made (more input
-  processed or more output produced), Z_STREAM_END if all input has been
-  consumed and all output has been produced (only when flush is set to
-  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
-  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
-*/
-
-
-extern int EXPORT deflateEnd OF((z_streamp strm));
-/*
-     All dynamically allocated data structures for this stream are freed.
-   This function discards any unprocessed input and does not flush any
-   pending output.
-
-     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
-   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
-   prematurely (some input or output was discarded). In the error case,
-   msg may be set but then points to a static string (which must not be
-   deallocated).
-*/
-
-
-/* 
-extern int EXPORT inflateInit OF((z_streamp strm));
-
-     Initializes the internal stream state for decompression. The fields
-   zalloc, zfree and opaque must be initialized before by the caller.  If
-   zalloc and zfree are set to Z_NULL, inflateInit updates them to use default
-   allocation functions.
-
-     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_VERSION_ERROR if the zlib library version is incompatible
-   with the version assumed by the caller.  msg is set to null if there is no
-   error message. inflateInit does not perform any decompression: this will be
-   done by inflate().
-*/
-
-
-extern int EXPORT inflate OF((z_streamp strm, int flush));
-/*
-  Performs one or both of the following actions:
-
-  - Decompress more input starting at next_in and update next_in and avail_in
-    accordingly. If not all input can be processed (because there is not
-    enough room in the output buffer), next_in is updated and processing
-    will resume at this point for the next call of inflate().
-
-  - Provide more output starting at next_out and update next_out and avail_out
-    accordingly.  inflate() provides as much output as possible, until there
-    is no more input data or no more space in the output buffer (see below
-    about the flush parameter).
-
-  Before the call of inflate(), the application should ensure that at least
-  one of the actions is possible, by providing more input and/or consuming
-  more output, and updating the next_* and avail_* values accordingly.
-  The application can consume the uncompressed output when it wants, for
-  example when the output buffer is full (avail_out == 0), or after each
-  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
-  must be called again after making room in the output buffer because there
-  might be more output pending.
-
-    If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
-  inflate flushes as much output as possible to the output buffer. The
-  flushing behavior of inflate is not specified for values of the flush
-  parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
-  current implementation actually flushes as much output as possible
-  anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
-  has been consumed, it is expecting to see the length field of a stored
-  block; if not, it returns Z_DATA_ERROR.
-
-    inflate() should normally be called until it returns Z_STREAM_END or an
-  error. However if all decompression is to be performed in a single step
-  (a single call of inflate), the parameter flush should be set to
-  Z_FINISH. In this case all pending input is processed and all pending
-  output is flushed; avail_out must be large enough to hold all the
-  uncompressed data. (The size of the uncompressed data may have been saved
-  by the compressor for this purpose.) The next operation on this stream must
-  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
-  is never required, but can be used to inform inflate that a faster routine
-  may be used for the single inflate() call.
-
-    inflate() returns Z_OK if some progress has been made (more input
-  processed or more output produced), Z_STREAM_END if the end of the
-  compressed data has been reached and all uncompressed output has been
-  produced, Z_NEED_DICT if a preset dictionary is needed at this point (see
-  inflateSetDictionary below), Z_DATA_ERROR if the input data was corrupted,
-  Z_STREAM_ERROR if the stream structure was inconsistent (for example if
-  next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
-  Z_BUF_ERROR if no progress is possible or if there was not enough room in
-  the output buffer when Z_FINISH is used. In the Z_DATA_ERROR case, the
-  application may then call inflateSync to look for a good compression block.
-  In the Z_NEED_DICT case, strm->adler is set to the Adler32 value of the
-  dictionary chosen by the compressor.
-*/
-
-
-extern int EXPORT inflateEnd OF((z_streamp strm));
-/*
-     All dynamically allocated data structures for this stream are freed.
-   This function discards any unprocessed input and does not flush any
-   pending output.
-
-     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
-   was inconsistent. In the error case, msg may be set but then points to a
-   static string (which must not be deallocated).
-*/
-
-                        /* Advanced functions */
-
-/*
-    The following functions are needed only in some special applications.
-*/
-
-/*   
-extern int EXPORT deflateInit2 OF((z_streamp strm,
-                                   int  level,
-                                   int  method,
-                                   int  windowBits,
-                                   int  memLevel,
-                                   int  strategy));
-
-     This is another version of deflateInit with more compression options. The
-   fields next_in, zalloc, zfree and opaque must be initialized before by
-   the caller.
-
-     The method parameter is the compression method. It must be Z_DEFLATED in
-   this version of the library. (Method 9 will allow a 64K history buffer and
-   partial block flushes.)
-
-     The windowBits parameter is the base two logarithm of the window size
-   (the size of the history buffer).  It should be in the range 8..15 for this
-   version of the library (the value 16 will be allowed for method 9). Larger
-   values of this parameter result in better compression at the expense of
-   memory usage. The default value is 15 if deflateInit is used instead.
-
-     The memLevel parameter specifies how much memory should be allocated
-   for the internal compression state. memLevel=1 uses minimum memory but
-   is slow and reduces compression ratio; memLevel=9 uses maximum memory
-   for optimal speed. The default value is 8. See zconf.h for total memory
-   usage as a function of windowBits and memLevel.
-
-     The strategy parameter is used to tune the compression algorithm. Use the
-   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
-   filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
-   string match).  Filtered data consists mostly of small values with a
-   somewhat random distribution. In this case, the compression algorithm is
-   tuned to compress them better. The effect of Z_FILTERED is to force more
-   Huffman coding and less string matching; it is somewhat intermediate
-   between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
-   the compression ratio but not the correctness of the compressed output even
-   if it is not set appropriately.
-
-     If next_in is not null, the library will use this buffer to hold also
-   some history information; the buffer must either hold the entire input
-   data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
-   is null, the library will allocate its own history buffer (and leave next_in
-   null). next_out need not be provided here but must be provided by the
-   application for the next call of deflate().
-
-     If the history buffer is provided by the application, next_in must
-   must never be changed by the application since the compressor maintains
-   information inside this buffer from call to call; the application
-   must provide more input only by increasing avail_in. next_in is always
-   reset by the library in this case.
-
-      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
-   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
-   an invalid method). msg is set to null if there is no error message.
-   deflateInit2 does not perform any compression: this will be done by
-   deflate(). 
-*/
-                            
-extern int EXPORT deflateSetDictionary OF((z_streamp strm,
-                                           const Bytef *dictionary,
-                                          uInt  dictLength));
-/*
-     Initializes the compression dictionary (history buffer) from the given
-   byte sequence without producing any compressed output. This function must
-   be called immediately after deflateInit or deflateInit2, before any call
-   of deflate. The compressor and decompressor must use exactly the same
-   dictionary (see inflateSetDictionary).
-     The dictionary should consist of strings (byte sequences) that are likely
-   to be encountered later in the data to be compressed, with the most commonly
-   used strings preferably put towards the end of the dictionary. Using a
-   dictionary is most useful when the data to be compressed is short and
-   can be predicted with good accuracy; the data can then be compressed better
-   than with the default empty dictionary. In this version of the library,
-   only the last 32K bytes of the dictionary are used.
-     Upon return of this function, strm->adler is set to the Adler32 value
-   of the dictionary; the decompressor may later use this value to determine
-   which dictionary has been used by the compressor. (The Adler32 value
-   applies to the whole dictionary even if only a subset of the dictionary is
-   actually used by the compressor.)
-
-     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
-   parameter is invalid (such as NULL dictionary) or the stream state
-   is inconsistent (for example if deflate has already been called for this
-   stream). deflateSetDictionary does not perform any compression: this will
-   be done by deflate(). 
-*/
-
-extern int EXPORT deflateCopy OF((z_streamp dest,
-                                  z_streamp source));
-/*
-     Sets the destination stream as a complete copy of the source stream.  If
-   the source stream is using an application-supplied history buffer, a new
-   buffer is allocated for the destination stream.  The compressed output
-   buffer is always application-supplied. It's the responsibility of the
-   application to provide the correct values of next_out and avail_out for the
-   next call of deflate.
-
-     This function can be useful when several compression strategies will be
-   tried, for example when there are several ways of pre-processing the input
-   data with a filter. The streams that will be discarded should then be freed
-   by calling deflateEnd.  Note that deflateCopy duplicates the internal
-   compression state which can be quite large, so this strategy is slow and
-   can consume lots of memory.
-
-     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
-   (such as zalloc being NULL). msg is left unchanged in both source and
-   destination.
-*/
-
-extern int EXPORT deflateReset OF((z_streamp strm));
-/*
-     This function is equivalent to deflateEnd followed by deflateInit,
-   but does not free and reallocate all the internal compression state.
-   The stream will keep the same compression level and any other attributes
-   that may have been set by deflateInit2.
-
-      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NULL).
-*/
-
-extern int EXPORT deflateParams OF((z_streamp strm, int level, int strategy));
-/*
-     Dynamically update the compression level and compression strategy.
-   This can be used to switch between compression and straight copy of
-   the input data, or to switch to a different kind of input data requiring
-   a different strategy. If the compression level is changed, the input
-   available so far is compressed with the old level (and may be flushed);
-   the new level will take effect only at the next call of deflate().
-
-     Before the call of deflateParams, the stream state must be set as for
-   a call of deflate(), since the currently available input may have to
-   be compressed and flushed. In particular, strm->avail_out must be non-zero.
-
-     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
-   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
-   if strm->avail_out was zero.
-*/
-
-extern int EXPORT deflateOutputPending OF((z_streamp strm));
-/*
-     Returns the number of bytes of output which are immediately
-   available from the compressor (i.e. without any further input
-   or flush).
-*/
-
-/*   
-extern int EXPORT inflateInit2 OF((z_streamp strm,
-                                   int  windowBits));
-
-     This is another version of inflateInit with more compression options. The
-   fields next_out, zalloc, zfree and opaque must be initialized before by
-   the caller.
-
-     The windowBits parameter is the base two logarithm of the maximum window
-   size (the size of the history buffer).  It should be in the range 8..15 for
-   this version of the library (the value 16 will be allowed soon). The
-   default value is 15 if inflateInit is used instead. If a compressed stream
-   with a larger window size is given as input, inflate() will return with
-   the error code Z_DATA_ERROR instead of trying to allocate a larger window.
-
-     If next_out is not null, the library will use this buffer for the history
-   buffer; the buffer must either be large enough to hold the entire output
-   data, or have at least 1<<windowBits bytes.  If next_out is null, the
-   library will allocate its own buffer (and leave next_out null). next_in
-   need not be provided here but must be provided by the application for the
-   next call of inflate().
-
-     If the history buffer is provided by the application, next_out must
-   never be changed by the application since the decompressor maintains
-   history information inside this buffer from call to call; the application
-   can only reset next_out to the beginning of the history buffer when
-   avail_out is zero and all output has been consumed.
-
-      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
-   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
-   windowBits < 8). msg is set to null if there is no error message.
-   inflateInit2 does not perform any decompression: this will be done by
-   inflate().
-*/
-
-extern int EXPORT inflateSetDictionary OF((z_streamp strm,
-                                          const Bytef *dictionary,
-                                          uInt  dictLength));
-/*
-     Initializes the decompression dictionary (history buffer) from the given
-   uncompressed byte sequence. This function must be called immediately after
-   a call of inflate if this call returned Z_NEED_DICT. The dictionary chosen
-   by the compressor can be determined from the Adler32 value returned by this
-   call of inflate. The compressor and decompressor must use exactly the same
-   dictionary (see deflateSetDictionary).
-
-     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
-   parameter is invalid (such as NULL dictionary) or the stream state is
-   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
-   expected one (incorrect Adler32 value). inflateSetDictionary does not
-   perform any decompression: this will be done by subsequent calls of
-   inflate().
-*/
-
-extern int EXPORT inflateSync OF((z_streamp strm));
-/* 
-    Skips invalid compressed data until the special marker (see deflate()
-  above) can be found, or until all available input is skipped. No output
-  is provided.
-
-    inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
-  if no more input was provided, Z_DATA_ERROR if no marker has been found,
-  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
-  case, the application may save the current current value of total_in which
-  indicates where valid compressed data was found. In the error case, the
-  application may repeatedly call inflateSync, providing more input each time,
-  until success or end of the input data.
-*/
-
-extern int EXPORT inflateReset OF((z_streamp strm));
-/*
-     This function is equivalent to inflateEnd followed by inflateInit,
-   but does not free and reallocate all the internal decompression state.
-   The stream will keep attributes that may have been set by inflateInit2.
-
-      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NULL).
-*/
-
-extern int inflateIncomp OF((z_stream *strm));
-/*
-     This function adds the data at next_in (avail_in bytes) to the output
-   history without performing any output.  There must be no pending output,
-   and the decompressor must be expecting to see the start of a block.
-   Calling this function is equivalent to decompressing a stored block
-   containing the data at next_in (except that the data is not output).
-*/
-
-                        /* utility functions */
-
-/*
-     The following utility functions are implemented on top of the
-   basic stream-oriented functions. To simplify the interface, some
-   default options are assumed (compression level, window size,
-   standard memory allocation functions). The source code of these
-   utility functions can easily be modified if you need special options.
-*/
-
-extern int EXPORT compress OF((Bytef *dest,   uLongf *destLen,
-                              const Bytef *source, uLong sourceLen));
-/*
-     Compresses the source buffer into the destination buffer.  sourceLen is
-   the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be at least 0.1% larger than
-   sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
-   compressed buffer.
-     This function can be used to compress a whole file at once if the
-   input file is mmap'ed.
-     compress returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer.
-*/
-
-extern int EXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
-                                const Bytef *source, uLong sourceLen));
-/*
-     Decompresses the source buffer into the destination buffer.  sourceLen is
-   the byte length of the source buffer. Upon entry, destLen is the total
-   size of the destination buffer, which must be large enough to hold the
-   entire uncompressed data. (The size of the uncompressed data must have
-   been saved previously by the compressor and transmitted to the decompressor
-   by some mechanism outside the scope of this compression library.)
-   Upon exit, destLen is the actual size of the compressed buffer.
-     This function can be used to decompress a whole file at once if the
-   input file is mmap'ed.
-
-     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_BUF_ERROR if there was not enough room in the output
-   buffer, or Z_DATA_ERROR if the input data was corrupted.
-*/
-
-
-typedef voidp gzFile;
-
-extern gzFile EXPORT gzopen  OF((const char *path, const char *mode));
-/*
-     Opens a gzip (.gz) file for reading or writing. The mode parameter
-   is as in fopen ("rb" or "wb") but can also include a compression level
-   ("wb9").  gzopen can be used to read a file which is not in gzip format;
-   in this case gzread will directly read from the file without decompression.
-     gzopen returns NULL if the file could not be opened or if there was
-   insufficient memory to allocate the (de)compression state; errno
-   can be checked to distinguish the two cases (if errno is zero, the
-   zlib error is Z_MEM_ERROR).
-*/
-
-extern gzFile EXPORT gzdopen  OF((int fd, const char *mode));
-/*
-     gzdopen() associates a gzFile with the file descriptor fd.  File
-   descriptors are obtained from calls like open, dup, creat, pipe or
-   fileno (in the file has been previously opened with fopen).
-   The mode parameter is as in gzopen.
-     The next call of gzclose on the returned gzFile will also close the
-   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
-   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
-     gzdopen returns NULL if there was insufficient memory to allocate
-   the (de)compression state.
-*/
-
-extern int EXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
-/*
-     Reads the given number of uncompressed bytes from the compressed file.
-   If the input file was not in gzip format, gzread copies the given number
-   of bytes into the buffer.
-     gzread returns the number of uncompressed bytes actually read (0 for
-   end of file, -1 for error). */
-
-extern int EXPORT    gzwrite OF((gzFile file, const voidp buf, unsigned len));
-/*
-     Writes the given number of uncompressed bytes into the compressed file.
-   gzwrite returns the number of uncompressed bytes actually written
-   (0 in case of error).
-*/
-
-extern int EXPORT    gzflush OF((gzFile file, int flush));
-/*
-     Flushes all pending output into the compressed file. The parameter
-   flush is as in the deflate() function. The return value is the zlib
-   error number (see function gzerror below). gzflush returns Z_OK if
-   the flush parameter is Z_FINISH and all output could be flushed.
-     gzflush should be called only when strictly necessary because it can
-   degrade compression.
-*/
-
-extern int EXPORT    gzclose OF((gzFile file));
-/*
-     Flushes all pending output if necessary, closes the compressed file
-   and deallocates all the (de)compression state. The return value is the zlib
-   error number (see function gzerror below).
-*/
-
-extern const char * EXPORT gzerror OF((gzFile file, int *errnum));
-/*
-     Returns the error message for the last error which occurred on the
-   given compressed file. errnum is set to zlib error number. If an
-   error occurred in the file system and not in the compression library,
-   errnum is set to Z_ERRNO and the application may consult errno
-   to get the exact error code.
-*/
-
-                        /* checksum functions */
-
-/*
-     These functions are not related to compression but are exported
-   anyway because they might be useful in applications using the
-   compression library.
-*/
-
-extern uLong EXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
-
-/*
-     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
-   return the updated checksum. If buf is NULL, this function returns
-   the required initial value for the checksum.
-   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
-   much faster. Usage example:
-
-     uLong adler = adler32(0L, Z_NULL, 0);
-
-     while (read_buffer(buffer, length) != EOF) {
-       adler = adler32(adler, buffer, length);
-     }
-     if (adler != original_adler) error();
-*/
-
-extern uLong EXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
-/*
-     Update a running crc with the bytes buf[0..len-1] and return the updated
-   crc. If buf is NULL, this function returns the required initial value
-   for the crc. Pre- and post-conditioning (one's complement) is performed
-   within this function so it shouldn't be done by the application.
-   Usage example:
-
-     uLong crc = crc32(0L, Z_NULL, 0);
-
-     while (read_buffer(buffer, length) != EOF) {
-       crc = crc32(crc, buffer, length);
-     }
-     if (crc != original_crc) error();
-*/
-
-
-                        /* various hacks, don't look :) */
-
-/* deflateInit and inflateInit are macros to allow checking the zlib version
- * and the compiler's view of z_stream:
- */
-extern int EXPORT deflateInit_ OF((z_streamp strm, int level,
-                                  const char *version, int stream_size));
-extern int EXPORT inflateInit_ OF((z_streamp strm,
-                                  const char *version, int stream_size));
-extern int EXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
-                                   int windowBits, int memLevel, int strategy,
-                                   const char *version, int stream_size));
-extern int EXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
-                                   const char *version, int stream_size));
-#define deflateInit(strm, level) \
-        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
-#define inflateInit(strm) \
-        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
-#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
-        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
-                     (strategy),           ZLIB_VERSION, sizeof(z_stream))
-#define inflateInit2(strm, windowBits) \
-        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
-
-#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
-    struct internal_state {int dummy;}; /* hack for buggy compilers */
-#endif
-
-uLongf *get_crc_table OF((void)); /* can be used by asm versions of crc32() */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZLIB_H */
-/* --- zlib.h */
index 5a134fa4cf59f29e4a80edf6cc874982313def7f..8f20192cdae1974e3a1e74020720e9192c8c7312 100644 (file)
@@ -1,6 +1,6 @@
 AC_PREREQ([2.69])
 AC_INIT([ppp],
-        [2.4.10-dev],
+        [2.5.2],
         [https://github.com/ppp-project/ppp])
 
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
@@ -12,13 +12,14 @@ AM_MAINTAINER_MODE([enable])
 AC_LANG(C)
 AC_CONFIG_SRCDIR([pppd/main.c])
 AC_CONFIG_HEADERS([pppd/config.h pppd/pppdconf.h pppd/plugins/pppoe/config.h])
+AC_ENABLE_STATIC(no)
 
 # Checks for programs.
 AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_INSTALL
-AC_PROG_LIBTOOL
 AC_PROG_LN_S
+LT_INIT
 
 PKG_PROG_PKG_CONFIG
 
@@ -51,6 +52,8 @@ AC_CHECK_HEADERS([  \
     crypt.h         \
     paths.h         \
     shadow.h        \
+    stddef.h        \
+    stdarg.h        \
     sys/dlpi.h      \
     sys/ioctl.h     \
     sys/socket.h    \
@@ -72,7 +75,17 @@ AM_COND_IF([LINUX], [
         linux/if_ether.h        \
         linux/if_packet.h       \
         netinet/if_ether.h      \
-        netpacket/packet.h])])
+        netpacket/packet.h])
+
+    AC_MSG_CHECKING([for struct sockaddr_ll in <linux/if_packet.h>])
+    AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([@%:@include <linux/if_packet.h>], [sizeof(struct sockaddr_ll)])],
+       [AC_MSG_RESULT([yes])
+        AC_DEFINE(HAVE_STRUCT_SOCKADDR_LL, 1, [Struct sockaddr_ll is present on system])
+       ],
+       AC_MSG_RESULT([no]))
+])
+
 
 AC_CHECK_SIZEOF(unsigned int)
 AC_CHECK_SIZEOF(unsigned long)
@@ -106,7 +119,7 @@ AM_CONDITIONAL(WITH_SYSTEMD, test "x${enable_systemd}" = "xyes")
 AM_COND_IF([WITH_SYSTEMD],
     AC_DEFINE([SYSTEMD], 1, [Enable support for systemd notifications]))
 AS_IF([test "x${enable_systemd}" = "xyes"], [
-       PKG_CHECK_MODULES([systemd], [systemd])])
+       PKG_CHECK_MODULES([SYSTEMD], [libsystemd])])
 
 #
 # Enable Callback Protocol Support, disabled by default
@@ -117,15 +130,15 @@ AM_COND_IF([PPP_WITH_CBCP],
     AC_DEFINE([PPP_WITH_CBCP], 1, [Have Callback Protocol support]))
 
 #
-# Disable Microsoft extensions will remove CHAP and MPPE support
+# Disable Microsoft extensions will remove CHAP, MPPE and PEAP support
 AC_ARG_ENABLE([microsoft-extensions],
-    AS_HELP_STRING([--disable-microsoft-extensions], [Disable Microsoft CHAP / MPPE extensions]))
+    AS_HELP_STRING([--disable-microsoft-extensions], [Disable Microsoft CHAP / MPPE / PEAP extensions]))
 
 AM_CONDITIONAL(PPP_WITH_CHAPMS, test "x${enable_microsoft_extensions}" != "xno")
 AM_COND_IF([PPP_WITH_CHAPMS],
     AC_DEFINE([PPP_WITH_CHAPMS], 1, [Have Microsoft CHAP support]))
 
-AM_CONDITIONAL(PPP_WITH_MPPE, test "x${enable_microsoft_extensions}" != "xno")
+AM_CONDITIONAL(PPP_WITH_MPPE, test "x${build_sunos}" != "xyes" && test "x${enable_microsoft_extensions}" != "xno")
 AM_COND_IF([PPP_WITH_MPPE],
     AC_DEFINE([PPP_WITH_MPPE], 1, [Have Microsoft MPPE support]))
 
@@ -180,9 +193,9 @@ AM_CONDITIONAL(PPP_WITH_EAPTLS, test "x${enable_eaptls}" != "xno")
 # Disable PEAP support
 AC_ARG_ENABLE([peap],
     AS_HELP_STRING([--disable-peap], [Disable PEAP authentication support]))
-AS_IF([test "x${enable_peap}" != "xno"],
+AS_IF([test "x${enable_peap}" != "xno" && test "x${enable_microsoft_extensions}" != "xno"],
     AC_DEFINE([PPP_WITH_PEAP], 1, [Have PEAP authentication support]))
-AM_CONDITIONAL([PPP_WITH_PEAP], test "x${enable_peap}" != "xno")
+AM_CONDITIONAL([PPP_WITH_PEAP], test "x${enable_peap}" != "xno" && test "x${enable_microsoft_extensions}" != "xno")
 
 #
 # Disable OpenSSL engine support
@@ -194,7 +207,7 @@ AS_IF([test "x$enable_openssl_engine" != "xno"], [],
 #
 # Specify runtime directory
 AC_ARG_WITH([plugin-dir],
-       AC_HELP_STRING([--with-plugin-dir=DIR], [Specify the plugin directory for pppd]))
+       AS_HELP_STRING([--with-plugin-dir=DIR],[Specify the plugin directory for pppd]))
 AS_IF([test -n "$with_plugin_dir"],
        [PPPD_PLUGIN_DIR="$with_plugin_dir"],
        [PPPD_PLUGIN_DIR="${libdir}/pppd/$VERSION"])
@@ -203,25 +216,49 @@ AC_SUBST(PPPD_PLUGIN_DIR, "$PPPD_PLUGIN_DIR", [The pppd plugin directory])
 #
 # Specify runtime directory
 AC_ARG_WITH([runtime-dir],
-       AC_HELP_STRING([--with-runtime-dir=DIR], [Specify the runtime directory for pppd]))
+       AS_HELP_STRING([--with-runtime-dir=DIR],[Specify the runtime directory for pppd]))
 AS_IF([test -n "$with_runtime_dir"],
        [PPPD_RUNTIME_DIR="$with_runtime_dir"],
-       [PPPD_RUNTIME_DIR="${localstatedir}/run/pppd"])
+       [PPPD_RUNTIME_DIR="${runstatedir}/pppd"])
 AC_SUBST(PPPD_RUNTIME_DIR)
 
 #
 # Specify runtime directory
 AC_ARG_WITH([logfile-dir],
-       AC_HELP_STRING([--with-logfile-dir=DIR], [Specify the log directory for pppd]))
+       AS_HELP_STRING([--with-logfile-dir=DIR],[Specify the log directory for pppd]))
 AS_IF([test -n "$with_logfile_dir"],
        [PPPD_LOGFILE_DIR="$with_logfile_dir"],
-       [PPPD_LOGFILE_DIR="${localstatedir}/log/pppd"])
+       [PPPD_LOGFILE_DIR="${localstatedir}/log/ppp"])
 AC_SUBST(PPPD_LOGFILE_DIR)
 
+#
+# System CA certificates path
+AC_ARG_WITH(system-ca-path,
+    AS_HELP_STRING([--with-system-ca-path=/path/to/ssl/certs], [path to system CA certificates]),
+    [
+       case "$withval" in
+       "" | y | ye | yes)
+            with_system_ca_path="${sysconfdir}/ssl/certs"
+            ;;
+       n | no)
+            ;;
+       *)
+            with_system_ca_path="$withval"
+            ;;
+       esac
+    ],[with_system_ca_path="${sysconfdir}/ssl/certs"])
+AM_CONDITIONAL(PPP_WITH_SYSTEM_CA_PATH, [test "$with_system_ca_path" != "no"])
+AM_COND_IF(PPP_WITH_SYSTEM_CA_PATH, [
+    SYSTEM_CA_PATH="$with_system_ca_path"
+])
+AC_SUBST(SYSTEM_CA_PATH)
+
 #
 # Check for OpenSSL
 AX_CHECK_OPENSSL
-AM_CONDITIONAL(WITH_OPENSSL, test "x${with_openssl}" != "xno")
+AM_CONDITIONAL(PPP_WITH_OPENSSL, test "x${with_openssl}" != "xno")
+AM_COND_IF([PPP_WITH_OPENSSL],
+    AC_DEFINE([PPP_WITH_OPENSSL], 1, [PPP is compiled with openssl support]))
 
 #
 # Check if OpenSSL has compiled in support for various ciphers
@@ -236,29 +273,20 @@ AS_IF([test "x${with_openssl}" != "xno" ], [
 ])
 
 AM_CONDITIONAL([OPENSSL_HAVE_MD4], test "x${ac_cv_openssl_md4}" = "xyes")
-AM_COND_IF([OPENSSL_HAVE_MD4],,
-    AC_DEFINE([USE_MD4], 1, [Use MD4 included with pppd]))
+AM_COND_IF([OPENSSL_HAVE_MD4],
+    AC_DEFINE([OPENSSL_HAVE_MD4], 1, [Use MD4 included with openssl]))
 
 AM_CONDITIONAL([OPENSSL_HAVE_MD5], test "x${ac_cv_openssl_md5}" = "xyes")
-AM_COND_IF([OPENSSL_HAVE_MD5],,
-    AC_DEFINE([USE_MD5], 1, [Use MD5 included with pppd]))
+AM_COND_IF([OPENSSL_HAVE_MD5],
+    AC_DEFINE([OPENSSL_HAVE_MD5], 1, [Use MD5 included with openssl]))
 
 AM_CONDITIONAL([OPENSSL_HAVE_SHA], test "x${ac_cv_openssl_sha}" = "xyes")
-AM_COND_IF([OPENSSL_HAVE_SHA],,
-    AC_DEFINE([USE_SHA], 1, [Use SHA included with pppd]))
+AM_COND_IF([OPENSSL_HAVE_SHA],
+    AC_DEFINE([OPENSSL_HAVE_SHA], 1, [Use SHA included with openssl]))
 
 AM_CONDITIONAL([OPENSSL_HAVE_DES], test "x${ac_cv_openssl_des}" = "xyes")
-AM_COND_IF([OPENSSL_HAVE_DES],,
-    AC_DEFINE([USE_CRYPT], 1, [Use DES included with pppd]))
-
-#
-# If OpenSSL doesn't support DES, then use the one from libcrypt (glibc dropped support for this in 2.27).
-AS_IF([test "x${ac_cv_openssl_des}" = "xno" ], [
-    AC_CHECK_LIB([crypt], [encrypt],
-        [LIBS="$LIBS -lcrypt"],
-        [AC_MSG_ERROR([OpenSSL not found or does not support DES, and libcrypt also doesn't support encrypt])]
-    )
-])
+AM_COND_IF([OPENSSL_HAVE_DES],
+    AC_DEFINE([OPENSSL_HAVE_DES], 1, [Use DES included with openssl]))
 
 #
 # With libsrp support
@@ -289,25 +317,12 @@ AM_COND_IF([PPP_WITH_FILTER], [
         ])
     ])
 
-#
-# Some contributions require GTK/GLIB
-AC_ARG_WITH([gtk], AS_HELP_STRING([--with-gtk], [Build contributions with the GTK+ interface]))
-if test "x${with_gtk}" = "xyes"; then
-    PKG_CHECK_MODULES([GTK], [gtk+-2.0])
-    PKG_CHECK_MODULES([GLIB], [glib-2.0])
-fi
-AM_CONDITIONAL([WITH_GTK], test "x${with_gtk}" = "xyes")
-
 AC_DEFINE_UNQUOTED(PPPD_VERSION, "$VERSION", [Version of pppd])
 
 AC_CONFIG_FILES([
     Makefile
     chat/Makefile
-    contrib/Makefile
-    contrib/pppgetpass/Makefile
-    common/Makefile
     include/Makefile
-    modules/Makefile
     pppd/Makefile
     pppd/pppd.pc
     pppd/plugins/Makefile
@@ -322,78 +337,13 @@ AC_CONFIG_FILES([
 AC_OUTPUT
 
 
-AS_IF([test "x${build_sunos}" = "xyes" ], [[
-    echo "
-Setting up SunOS kernel module(s)"
-    mkmkf() {
-        rm -f $2
-        if [ -f $1 ]; then
-            echo "  $2 <= $1"
-            sed -e "s,@DESTDIR@,$prefix,g" \
-                -e "s,@SYSCONF@,$sysconfdir,g" \
-                -e "s,@CC@,$CC,g" \
-                -e "s|@CFLAGS@|$CFLAGS|g" $1 > $2
-        fi
-    }
-
-    release=`uname -r`
-    karch=`/usr/bin/isainfo -k`
-    makext="sol2"
-    archvariant=
-
-    case "$karch" in
-        amd64)
-            archvariant='-64x'
-            ;;
-        sparcv9)
-            archvariant='-64'
-            ;;
-        *)
-            ;;
-    esac
-
-    usegcc=$CC
-    if [ -x /opt/SUNWspro/bin/cc -a "$usegcc" != gcc ] &&
-       /opt/SUNWspro/bin/cc -flags >/dev/null 2>&1; then
-      if [ "$archvariant" = "-64x" ]; then
-        ( cd /tmp; echo "int x;" > ppp$$.c
-         /opt/SUNWspro/bin/cc -c -errwarn -xchip=opteron -m64 ppp$$.c >/dev/null 2>&1 || (
-           echo "WorkShop C is unable to make 64 bit modules, and your $karch system needs"
-           echo "them.  Consider upgrading cc on this machine."
-           rm -f ppp$$.c
-           exit 1
-         ) || exit 1
-         rm -f ppp$$.c ppp$$.o
-        ) || exit 1
-      fi
-    elif gcc --version >/dev/null 2>&1; then
-      archvariant=gcc$archvariant
-      compiletype=.gcc
-      if [ "$archvariant" = "gcc-64" -o"$archvariant" = "gcc-64x" ]; then
-        ( cd /tmp; touch ppp$$.c
-         gcc -c -m64 ppp$$.c >/dev/null 2>&1 || (
-           echo "gcc is unable to make 64 bit modules, and your $karch system needs them."
-           echo "Consider upgrading gcc on this machine, or switching to Sun WorkShop."
-           rm -f ppp$$.c
-           exit 1
-         ) || exit 1
-         rm -f ppp$$.c ppp$$.o
-        ) || exit 1
-      fi
-    else
-      echo "C compiler not found; hoping for the best."
-    fi
-
-    mkmkf solaris/Makedefs$compiletype Makedefs.com
-    mkmkf solaris/Makefile.sol2$archvariant solaris/Makefile
-]])
-
 echo "
 $PACKAGE_NAME version $PACKAGE_VERSION
     Prefix...............: $prefix
     Runtime Dir..........: $PPPD_RUNTIME_DIR
     Logfile Dir..........: $PPPD_LOGFILE_DIR
     Plugin Dir...........: $PPPD_PLUGIN_DIR
+    System CA Path ......: ${SYSTEM_CA_PATH:-not set}
     With OpenSSL.........: ${with_openssl:-yes}
     With libatm..........: ${with_atm:-no}
     With libpam..........: ${with_pam:-no}
@@ -409,6 +359,5 @@ Features enabled
     CBCP.................: ${enable_cbcp:-no}
     IPV6CP...............: ${enable_ipv6cp:-yes}
     EAP-TLS..............: ${enable_eaptls:-yes}
-    PEAP.................: ${enable_peap:-yes}
     systemd notifications: ${enable_systemd:-no}
 "
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
deleted file mode 100644 (file)
index fb9a390..0000000
+++ /dev/null
@@ -1 +0,0 @@
-SUBDIRS = pppgetpass
diff --git a/contrib/pppgetpass/.gitignore b/contrib/pppgetpass/.gitignore
deleted file mode 100644 (file)
index 1b8a1c8..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-pppgetpass.vt
-pppgetpass.gtk
diff --git a/contrib/pppgetpass/Makefile.am b/contrib/pppgetpass/Makefile.am
deleted file mode 100644 (file)
index 530e82f..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-noinst_PROGRAMS = pppgetpass.vt
-noinst_man8_MANS = pppgetpass.8
-
-pppgetpass_vt_SOURCES = pppgetpass.vt.c
-pppgetpass_vt_CPPFLAGS = -Wno-unused-result
-
-if WITH_GTK
-noinst_PROGRAMS += pppgetpass.gtk
-
-pppgetpass_gtk_SOURCES = pppgetpass.gtk.c
-pppgetpass_gtk_CPPFLAGS = -Wno-deprecated-declarations -Wno-discarded-qualifiers
-pppgetpass_gtk_CPPFLAGS += $(GLIB_CFLAGS) $(GTK_CFLAGS)
-pppgetpass_gtk_LDADD = $(GLIB_LIBS) $(GTK_LIBS)
-endif
-
-EXTRA_DIST = \
-    pppgetpass.sh
diff --git a/contrib/pppgetpass/pppgetpass.8 b/contrib/pppgetpass/pppgetpass.8
deleted file mode 100644 (file)
index ade5769..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-.TH PPPGETPASS 8 "26 Sep 1999"
-.SH NAME
-pppgetpass \- prompt for PAP password
-.SH SYNOPSIS
-.B pppgetpass
-.I client server fd
-.SH DESCRIPTION
-.B pppgetpass
-the outer half of a plugin for PAP password prompting in pppd.
-If the peer requires PAP, and the
-.B passprompt.so
-plugin is loaded into pppd, it will run
-.B /usr/sbin/pppgetpass
-(or another program specified by the
-.B promptprog
-option) to prompt the user for the password.
-.SH SEE ALSO
-pppd(8)
diff --git a/contrib/pppgetpass/pppgetpass.gtk.c b/contrib/pppgetpass/pppgetpass.gtk.c
deleted file mode 100644 (file)
index 48ca042..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtkbutton.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtksignal.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-
-int outfd;
-int err;
-
-static void okpressed(void *widget, void *clientdata)
-{
-  GtkWidget *answer=clientdata;
-  gchar *pass;
-  int passlen;
-  ssize_t wrote;
-  (void)widget;
-
-  pass=gtk_entry_get_text(GTK_ENTRY(answer));
-
-  passlen=strlen(pass);
-  if(!passlen)
-    return;
-
-  if((wrote=write(outfd, pass, passlen))!=passlen) {
-    if(wrote<0)
-      syslog(LOG_ERR, "write error on outpipe: %m");
-    else
-      syslog(LOG_ERR, "short write on outpipe");
-    err=1;
-  }
-  gtk_main_quit();
-}
-
-int main(int argc, char **argv)
-{
-  GtkWidget *mainwindow, *vbox, *question, *answer, *ok;
-  char buf[1024];
-  gtk_init(&argc, &argv);
-
-  openlog(argv[0], LOG_PID, LOG_DAEMON);
-  if(argc!=4) {
-    syslog(LOG_WARNING, "Usage error");
-    return 1;
-  }
-  outfd=atoi(argv[3]);
-  mainwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
-  gtk_window_set_title(GTK_WINDOW(mainwindow), "pppgetpass");
-  gtk_signal_connect(GTK_OBJECT(mainwindow), "destroy",
-                     GTK_SIGNAL_FUNC(gtk_main_quit), 0);
-
-  vbox=gtk_vbox_new(FALSE, 5);
-  gtk_container_add(GTK_CONTAINER(mainwindow), vbox);
-  gtk_widget_show(vbox);
-
-  if(argv[1][0] && argv[2][0])
-    snprintf(buf, sizeof buf, "Password for PPP client %s on server %s: ", argv[1], argv[2]);
-  else if(argv[1][0] && !argv[2][0])
-    snprintf(buf, sizeof buf, "Password for PPP client %s: ", argv[1]);
-  else if(!argv[1][0] && argv[2][0])
-    snprintf(buf, sizeof buf, "Password for PPP on server %s: ", argv[2]);
-  else
-    snprintf(buf, sizeof buf, "Enter PPP password: ");
-  question=gtk_label_new(buf);
-  gtk_box_pack_start(GTK_BOX(vbox), question, FALSE, TRUE, 0);
-  gtk_widget_show(question);
-
-  answer=gtk_entry_new();
-  gtk_entry_set_visibility(GTK_ENTRY(answer), 0);
-  gtk_box_pack_start(GTK_BOX(vbox), answer, FALSE, TRUE, 0);
-  gtk_widget_show(answer);
-
-  ok=gtk_button_new_with_label("OK");
-  gtk_box_pack_start(GTK_BOX(vbox), ok, FALSE, TRUE, 0);
-  gtk_signal_connect(GTK_OBJECT(ok), "clicked",
-                     GTK_SIGNAL_FUNC(okpressed), answer);
-  gtk_widget_show(ok);
-
-  gtk_widget_show(mainwindow);
-  gtk_main();
-
-  return err;
-}
diff --git a/contrib/pppgetpass/pppgetpass.sh b/contrib/pppgetpass/pppgetpass.sh
deleted file mode 100644 (file)
index 09c4805..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-if [ -z "$DISPLAY" ]; then
-  exec pppgetpass.vt "$@"
-else
-  exec pppgetpass.gtk "$@"
-fi
diff --git a/contrib/pppgetpass/pppgetpass.vt.c b/contrib/pppgetpass/pppgetpass.vt.c
deleted file mode 100644 (file)
index a152088..0000000
+++ /dev/null
@@ -1,218 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <syslog.h>
-#include <termios.h>
-#include <sys/vt.h>
-
-static int console_owner(uid_t, int);
-
-int main(int argc, char **argv)
-{
-  int console;
-  uid_t uid;
-  struct vt_stat origstate;
-  int openvtnum;
-  char openvtname[256];
-  int openvt;
-  gid_t gid;
-  int chowned;
-  FILE *fp;
-  struct termios t;
-  char pass[256], *nl;
-  int outfd, passlen;
-  ssize_t wrote;
-  console=open("/dev/console", O_RDWR);
-
-  uid=getuid();
-  gid=getgid();
-  seteuid(uid);
-
-  openlog(argv[0], LOG_PID, LOG_DAEMON);
-
-  if(argc!=4) {
-    syslog(LOG_WARNING, "Usage error");
-    return 1;
-  }
-
-  if(console<0) {
-    syslog(LOG_ERR, "open(/dev/console): %m");
-    return 1;
-  }
-
-  if(ioctl(console, VT_GETSTATE, &origstate)<0) {
-    syslog(LOG_ERR, "VT_GETSTATE: %m");
-    return 1;
-  }
-
-  if(uid) {
-    if(!console_owner(uid, origstate.v_active)) {
-      int i;
-      for(i=0;i<64;++i) {
-        if(i!=origstate.v_active && console_owner(uid, i))
-          break;
-      }
-      if(i==64) {
-        syslog(LOG_WARNING, "run by uid %lu not at console", (unsigned long)uid);
-        return 1;
-      }
-    }
-  }
-
-  if(ioctl(console, VT_OPENQRY, &openvtnum)<0) {
-    syslog(LOG_ERR, "VT_OPENQRY: %m");
-    return 1;
-  }
-  if(openvtnum==-1) {
-    syslog(LOG_ERR, "No free VTs");
-    return 1;
-  }
-
-  snprintf(openvtname, sizeof openvtname, "/dev/tty%d", openvtnum);
-  seteuid(0);
-  openvt=open(openvtname, O_RDWR);
-  if(openvt<0) {
-    seteuid(uid);
-    syslog(LOG_ERR, "open(%s): %m", openvtname);
-    return 1;
-  }
-
-  chowned=fchown(openvt, uid, gid);
-  if(chowned<0) {
-    seteuid(uid);
-    syslog(LOG_ERR, "fchown(%s): %m", openvtname);
-    return 1;
-  }
-
-  close(console);
-
-  if(ioctl(openvt, VT_ACTIVATE, openvtnum)<0) {
-    seteuid(uid);
-    syslog(LOG_ERR, "VT_ACTIVATE(%d): %m", openvtnum);
-    return 1;
-  }
-
-  while(ioctl(openvt, VT_WAITACTIVE, openvtnum)<0) {
-    if(errno!=EINTR) {
-      ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-      seteuid(uid);
-      syslog(LOG_ERR, "VT_WAITACTIVE(%d): %m", openvtnum);
-      return 1;
-    }
-  }
-
-  seteuid(uid);
-  fp=fdopen(openvt, "r+");
-  if(!fp) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    syslog(LOG_ERR, "fdopen(%s): %m", openvtname);
-    return 1;
-  }
-
-  if(tcgetattr(openvt, &t)<0) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    syslog(LOG_ERR, "tcgetattr(%s): %m", openvtname);
-    return 1;
-  }
-  t.c_lflag &= ~ECHO;
-  if(tcsetattr(openvt, TCSANOW, &t)<0) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    syslog(LOG_ERR, "tcsetattr(%s): %m", openvtname);
-    return 1;
-  }
-
-  if(fprintf(fp, "\033[2J\033[H")<0) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    syslog(LOG_ERR, "write error on %s: %m", openvtname);
-    return 1;
-  }
-  if(argv[1][0] && argv[2][0]) {
-    if(fprintf(fp, "Password for PPP client %s on server %s: ", argv[1], argv[2])<0) {
-      seteuid(0);
-      ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-      seteuid(uid);
-      syslog(LOG_ERR, "write error on %s: %m", openvtname);
-      return 1;
-    }
-  } else if(argv[1][0] && !argv[2][0]) {
-    if(fprintf(fp, "Password for PPP client %s: ", argv[1])<0) {
-      syslog(LOG_ERR, "write error on %s: %m", openvtname);
-      seteuid(0);
-      ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-      seteuid(uid);
-      return 1;
-    }
-  } else if(!argv[1][0] && argv[2][0]) {
-    if(fprintf(fp, "Password for PPP on server %s: ", argv[2])<0) {
-      seteuid(0);
-      ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-      seteuid(uid);
-      syslog(LOG_ERR, "write error on %s: %m", openvtname);
-      return 1;
-    }
-  } else {
-    if(fprintf(fp, "Enter PPP password: ")<0) {
-      seteuid(0);
-      ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-      seteuid(uid);
-      syslog(LOG_ERR, "write error on %s: %m", openvtname);
-      return 1;
-    }
-  }
-
-  if(!fgets(pass, sizeof pass, fp)) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    if(ferror(fp)) {
-      syslog(LOG_ERR, "read error on %s: %m", openvtname);
-    }
-    return 1;
-  }
-  if((nl=strchr(pass, '\n'))) 
-    *nl=0;
-  passlen=strlen(pass);
-  
-  outfd=atoi(argv[3]);
-  if((wrote=write(outfd, pass, passlen))!=passlen) {
-    seteuid(0);
-    ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-    seteuid(uid);
-    if(wrote<0)
-      syslog(LOG_ERR, "write error on outpipe: %m");
-    else
-      syslog(LOG_ERR, "short write on outpipe");
-    return 1;
-  }
-
-  seteuid(0);
-  ioctl(openvt, VT_ACTIVATE, origstate.v_active);
-  seteuid(uid);
-  return 0;
-}
-
-static int console_owner(uid_t uid, int cons)
-{
-  char name[256];
-  struct stat st;
-  snprintf(name, sizeof name, "/dev/tty%d", cons);
-  if(stat(name, &st)<0) {
-    if(errno!=ENOENT)
-      syslog(LOG_ERR, "stat(%s): %m", name);
-    return 0;
-  }
-  return uid==st.st_uid;
-}
diff --git a/etc.ppp/chap-secrets b/etc.ppp/chap-secrets
deleted file mode 100644 (file)
index 7d1c3cd..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# Secrets for authentication using CHAP
-# client       server  secret                  IP addresses
diff --git a/etc.ppp/chap-secrets.example b/etc.ppp/chap-secrets.example
new file mode 100644 (file)
index 0000000..7d1c3cd
--- /dev/null
@@ -0,0 +1,2 @@
+# Secrets for authentication using CHAP
+# client       server  secret                  IP addresses
diff --git a/etc.ppp/eaptls-client b/etc.ppp/eaptls-client
deleted file mode 100644 (file)
index 7782f0e..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Parameters for authentication using EAP-TLS (client)
-
-# client name (can be *)
-# server name (can be *)
-# client certificate file (required)
-# server certificate file (optional, if unused put '-')
-# CA certificate file (required)
-# client private key file (required)
-
-#client        server  /root/cert/client.crt   -       /root/cert/ca.crt       /root/cert/client.key
diff --git a/etc.ppp/eaptls-client.example b/etc.ppp/eaptls-client.example
new file mode 100644 (file)
index 0000000..7782f0e
--- /dev/null
@@ -0,0 +1,10 @@
+# Parameters for authentication using EAP-TLS (client)
+
+# client name (can be *)
+# server name (can be *)
+# client certificate file (required)
+# server certificate file (optional, if unused put '-')
+# CA certificate file (required)
+# client private key file (required)
+
+#client        server  /root/cert/client.crt   -       /root/cert/ca.crt       /root/cert/client.key
diff --git a/etc.ppp/eaptls-server b/etc.ppp/eaptls-server
deleted file mode 100644 (file)
index fa53cbd..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# Parameters for authentication using EAP-TLS (server)
-
-# client name (can be *)
-# server name (can be *)
-# client certificate file (optional, if unused put '-')
-# server certificate file (required)
-# CA certificate file (required)
-# server private key file (required)
-# allowed addresses (required, can be *)
-
-#client        server  -       /root/cert/server.crt   /root/cert/ca.crt       /root/cert/server.key   192.168.1.0/24
diff --git a/etc.ppp/eaptls-server.example b/etc.ppp/eaptls-server.example
new file mode 100644 (file)
index 0000000..fa53cbd
--- /dev/null
@@ -0,0 +1,11 @@
+# Parameters for authentication using EAP-TLS (server)
+
+# client name (can be *)
+# server name (can be *)
+# client certificate file (optional, if unused put '-')
+# server certificate file (required)
+# CA certificate file (required)
+# server private key file (required)
+# allowed addresses (required, can be *)
+
+#client        server  -       /root/cert/server.crt   /root/cert/ca.crt       /root/cert/server.key   192.168.1.0/24
diff --git a/etc.ppp/openssl.cnf b/etc.ppp/openssl.cnf
deleted file mode 100644 (file)
index dd32f30..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-openssl_conf = openssl_def
-
-[ openssl_def ]
-engines = engine_section
-
-[ engine_section ]
-pkcs11 = pkcs11_section
-
-[ pkcs11_section ]
-engine_id = pkcs11
-dynamic_path = /usr/lib64/openssl/engines/engine_pkcs11.so
-MODULE_PATH = /usr/lib64/libeTPkcs11.so
-init = 0
-
diff --git a/etc.ppp/openssl.cnf.example b/etc.ppp/openssl.cnf.example
new file mode 100644 (file)
index 0000000..dd32f30
--- /dev/null
@@ -0,0 +1,14 @@
+openssl_conf = openssl_def
+
+[ openssl_def ]
+engines = engine_section
+
+[ engine_section ]
+pkcs11 = pkcs11_section
+
+[ pkcs11_section ]
+engine_id = pkcs11
+dynamic_path = /usr/lib64/openssl/engines/engine_pkcs11.so
+MODULE_PATH = /usr/lib64/libeTPkcs11.so
+init = 0
+
diff --git a/etc.ppp/options b/etc.ppp/options
deleted file mode 100644 (file)
index 4b67b6a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lock
diff --git a/etc.ppp/options.example b/etc.ppp/options.example
new file mode 100644 (file)
index 0000000..4b67b6a
--- /dev/null
@@ -0,0 +1 @@
+lock
diff --git a/etc.ppp/pap-secrets b/etc.ppp/pap-secrets
deleted file mode 100644 (file)
index f8b7dce..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# Secrets for authentication using PAP
-# client       server  secret                  IP addresses
diff --git a/etc.ppp/pap-secrets.example b/etc.ppp/pap-secrets.example
new file mode 100644 (file)
index 0000000..f8b7dce
--- /dev/null
@@ -0,0 +1,2 @@
+# Secrets for authentication using PAP
+# client       server  secret                  IP addresses
index 2a576c19d95c59a4b35585ffe8fdec5dc1f45c6b..c92a9fa883cfeb8b58ab27bc40c7b5b6a8fa6e81 100644 (file)
@@ -1,13 +1,6 @@
 EXTRA_HEADERS = \
-    linux/if_ppp.h \
     linux/ppp-comp.h \
-    linux/ppp_defs.h \
-    net/if_ppp.h \
-    net/ppp-comp.h \
-    net/ppp_defs.h \
-    net/pppio.h \
-    net/slcompress.h \
-    net/vjcompress.h
+    linux/ppp_defs.h
 
 EXTRA_DIST = \
     $(EXTRA_HEADERS)
diff --git a/include/linux/if_ppp.h b/include/linux/if_ppp.h
deleted file mode 100644 (file)
index 1101fc7..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*     $Id: if_ppp.h,v 1.23 2002/12/06 09:49:15 paulus Exp $   */
-
-/*
- * if_ppp.h - Point-to-Point Protocol definitions.
- *
- * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name "Carnegie Mellon University" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For permission or any legal
- *    details, please contact
- *      Office of Technology Transfer
- *      Carnegie Mellon University
- *      5000 Forbes Avenue
- *      Pittsburgh, PA  15213-3890
- *      (412) 268-4387, fax: (412) 268-7395
- *      tech-transfer@andrew.cmu.edu
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Computing Services
- *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
- *
- * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
- * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-/*
- *  ==FILEVERSION 20000724==
- *
- *  NOTE TO MAINTAINERS:
- *     If you modify this file at all, please set the above date.
- *     if_ppp.h is shipped with a PPP distribution as well as with the kernel;
- *     if everyone increases the FILEVERSION number above, then scripts
- *     can do the right thing when deciding whether to install a new if_ppp.h
- *     file.  Don't change the format of that line otherwise, so the
- *     installation script can recognize it.
- */
-
-#ifndef _IF_PPP_H_
-#define _IF_PPP_H_
-
-/*
- * Packet sizes
- */
-
-#define        PPP_MTU         1500    /* Default MTU (size of Info field) */
-#define PPP_MAXMRU     65000   /* Largest MRU we allow */
-#define PROTO_IPX      0x002b  /* protocol numbers */
-#define PROTO_DNA_RT    0x0027  /* DNA Routing */
-
-
-/*
- * Bit definitions for flags.
- */
-
-#define SC_COMP_PROT   0x00000001      /* protocol compression (output) */
-#define SC_COMP_AC     0x00000002      /* header compression (output) */
-#define        SC_COMP_TCP     0x00000004      /* TCP (VJ) compression (output) */
-#define SC_NO_TCP_CCID 0x00000008      /* disable VJ connection-id comp. */
-#define SC_REJ_COMP_AC 0x00000010      /* reject adrs/ctrl comp. on input */
-#define SC_REJ_COMP_TCP        0x00000020      /* reject TCP (VJ) comp. on input */
-#define SC_CCP_OPEN    0x00000040      /* Look at CCP packets */
-#define SC_CCP_UP      0x00000080      /* May send/recv compressed packets */
-#define SC_ENABLE_IP   0x00000100      /* IP packets may be exchanged */
-#define SC_LOOP_TRAFFIC        0x00000200      /* send traffic to pppd */
-#define SC_MULTILINK   0x00000400      /* do multilink encapsulation */
-#define SC_MP_SHORTSEQ 0x00000800      /* use short MP sequence numbers */
-#define SC_COMP_RUN    0x00001000      /* compressor has been inited */
-#define SC_DECOMP_RUN  0x00002000      /* decompressor has been inited */
-#define SC_MP_XSHORTSEQ        0x00004000      /* transmit short MP seq numbers */
-#define SC_DEBUG       0x00010000      /* enable debug messages */
-#define SC_LOG_INPKT   0x00020000      /* log contents of good pkts recvd */
-#define SC_LOG_OUTPKT  0x00040000      /* log contents of pkts sent */
-#define SC_LOG_RAWIN   0x00080000      /* log all chars received */
-#define SC_LOG_FLUSH   0x00100000      /* log all chars flushed */
-#define        SC_SYNC         0x00200000      /* synchronous serial mode */
-#define        SC_MASK         0x0f200fff      /* bits that user can change */
-
-/* state bits */
-#define SC_XMIT_BUSY   0x10000000      /* (used by isdn_ppp?) */
-#define SC_RCV_ODDP    0x08000000      /* have rcvd char with odd parity */
-#define SC_RCV_EVNP    0x04000000      /* have rcvd char with even parity */
-#define SC_RCV_B7_1    0x02000000      /* have rcvd char with bit 7 = 1 */
-#define SC_RCV_B7_0    0x01000000      /* have rcvd char with bit 7 = 0 */
-#define SC_DC_FERROR   0x00800000      /* fatal decomp error detected */
-#define SC_DC_ERROR    0x00400000      /* non-fatal decomp error detected */
-
-/*
- * Ioctl definitions.
- */
-
-struct npioctl {
-       int             protocol;       /* PPP protocol, e.g. PPP_IP */
-       enum NPmode     mode;
-};
-
-/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
-struct ppp_option_data {
-       __u8    *ptr;
-       __u32   length;
-       int     transmit;
-};
-
-struct ifpppstatsreq {
-       struct ifreq     b;
-       struct ppp_stats stats;                 /* statistic information */
-};
-
-struct ifpppcstatsreq {
-       struct ifreq          b;
-       struct ppp_comp_stats stats;
-};
-
-#define ifr__name       b.ifr_ifrn.ifrn_name
-#define stats_ptr       b.ifr_ifru.ifru_data
-
-/*
- * Ioctl definitions.
- */
-
-#define        PPPIOCGFLAGS    _IOR('t', 90, int)      /* get configuration flags */
-#define        PPPIOCSFLAGS    _IOW('t', 89, int)      /* set configuration flags */
-#define        PPPIOCGASYNCMAP _IOR('t', 88, int)      /* get async map */
-#define        PPPIOCSASYNCMAP _IOW('t', 87, int)      /* set async map */
-#define        PPPIOCGUNIT     _IOR('t', 86, int)      /* get ppp unit number */
-#define        PPPIOCGRASYNCMAP _IOR('t', 85, int)     /* get receive async map */
-#define        PPPIOCSRASYNCMAP _IOW('t', 84, int)     /* set receive async map */
-#define        PPPIOCGMRU      _IOR('t', 83, int)      /* get max receive unit */
-#define        PPPIOCSMRU      _IOW('t', 82, int)      /* set max receive unit */
-#define        PPPIOCSMAXCID   _IOW('t', 81, int)      /* set VJ max slot ID */
-#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
-#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
-#define PPPIOCXFERUNIT _IO('t', 78)            /* transfer PPP unit */
-#define PPPIOCSCOMPRESS        _IOW('t', 77, struct ppp_option_data)
-#define PPPIOCGNPMODE  _IOWR('t', 76, struct npioctl) /* get NP mode */
-#define PPPIOCSNPMODE  _IOW('t', 75, struct npioctl)  /* set NP mode */
-#define PPPIOCSPASS    _IOW('t', 71, struct sock_fprog) /* set pass filter */
-#define PPPIOCSACTIVE  _IOW('t', 70, struct sock_fprog) /* set active filt */
-#define PPPIOCGDEBUG   _IOR('t', 65, int)      /* Read debug level */
-#define PPPIOCSDEBUG   _IOW('t', 64, int)      /* Set debug level */
-#define PPPIOCGIDLE    _IOR('t', 63, struct ppp_idle) /* get idle time */
-#define PPPIOCNEWUNIT  _IOWR('t', 62, int)     /* create new ppp unit */
-#define PPPIOCATTACH   _IOW('t', 61, int)      /* attach to ppp unit */
-#define PPPIOCDETACH   _IOW('t', 60, int)      /* detach from ppp unit/chan */
-#define PPPIOCSMRRU    _IOW('t', 59, int)      /* set multilink MRU */
-#define PPPIOCCONNECT  _IOW('t', 58, int)      /* connect channel to unit */
-#define PPPIOCDISCONN  _IO('t', 57)            /* disconnect channel */
-#define PPPIOCATTCHAN  _IOW('t', 56, int)      /* attach to ppp channel */
-#define PPPIOCGCHAN    _IOR('t', 55, int)      /* get ppp channel number */
-
-#define SIOCGPPPSTATS   (SIOCDEVPRIVATE + 0)
-#define SIOCGPPPVER     (SIOCDEVPRIVATE + 1)   /* NEVER change this!! */
-#define SIOCGPPPCSTATS  (SIOCDEVPRIVATE + 2)
-
-#if !defined(ifr_mtu)
-#define ifr_mtu        ifr_ifru.ifru_metric
-#endif
-
-#endif /* _IF_PPP_H_ */
index d30cacbd49ae288be9537c3fd256f972b34ed5c2..b1ed76d2a73db9b09b9895f2a990d9a92831b463 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * ppp-comp.h - Definitions for doing PPP packet compression.
  *
- * Copyright (c) 1984 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp-comp.h,v 1.10 2002/12/06 09:49:15 paulus Exp $
- */
-
-/*
- *  ==FILEVERSION 20020319==
- *
- *  NOTE TO MAINTAINERS:
- *     If you modify this file at all, please set the above date.
- *     ppp-comp.h is shipped with a PPP distribution as well as with the kernel;
- *     if everyone increases the FILEVERSION number above, then scripts
- *     can do the right thing when deciding whether to install a new ppp-comp.h
- *     file.  Don't change the format of that line otherwise, so the
- *     installation script can recognize it.
  */
 
 #ifndef _NET_PPP_COMP_H
index ef4232b462151d2e106aadfa604e5ba5e8342461..5f20649ca5a76e530216f078273094668e6da34b 100644 (file)
@@ -1,9 +1,7 @@
-/*     $Id: ppp_defs.h,v 1.11 2002/12/06 09:49:15 paulus Exp $ */
-
 /*
  * ppp_defs.h - PPP definitions.
  *
- * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/*
- *  ==FILEVERSION 20020521==
- *
- *  NOTE TO MAINTAINERS:
- *     If you modify this file at all, please set the above date.
- *     ppp_defs.h is shipped with a PPP distribution as well as with the kernel;
- *     if everyone increases the FILEVERSION number above, then scripts
- *     can do the right thing when deciding whether to install a new ppp_defs.h
- *     file.  Don't change the format of that line otherwise, so the
- *     installation script can recognize it.
- */
-
 #ifndef _PPP_DEFS_H_
 #define _PPP_DEFS_H_
 
diff --git a/include/net/if_ppp.h b/include/net/if_ppp.h
deleted file mode 100644 (file)
index 1beb470..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/*     $Id: if_ppp.h,v 1.19 2002/12/06 09:49:15 paulus Exp $   */
-
-/*
- * if_ppp.h - Point-to-Point Protocol definitions.
- *
- * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name "Carnegie Mellon University" must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission. For permission or any legal
- *    details, please contact
- *      Office of Technology Transfer
- *      Carnegie Mellon University
- *      5000 Forbes Avenue
- *      Pittsburgh, PA  15213-3890
- *      (412) 268-4387, fax: (412) 268-7395
- *      tech-transfer@andrew.cmu.edu
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Computing Services
- *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
- *
- * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
- * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _IF_PPP_H_
-#define _IF_PPP_H_
-
-/*
- * Bit definitions for flags.
- */
-#define SC_COMP_PROT   0x00000001      /* protocol compression (output) */
-#define SC_COMP_AC     0x00000002      /* header compression (output) */
-#define        SC_COMP_TCP     0x00000004      /* TCP (VJ) compression (output) */
-#define SC_NO_TCP_CCID 0x00000008      /* disable VJ connection-id comp. */
-#define SC_REJ_COMP_AC 0x00000010      /* reject adrs/ctrl comp. on input */
-#define SC_REJ_COMP_TCP        0x00000020      /* reject TCP (VJ) comp. on input */
-#define SC_CCP_OPEN    0x00000040      /* Look at CCP packets */
-#define SC_CCP_UP      0x00000080      /* May send/recv compressed packets */
-#define SC_DEBUG       0x00010000      /* enable debug messages */
-#define SC_LOG_INPKT   0x00020000      /* log contents of good pkts recvd */
-#define SC_LOG_OUTPKT  0x00040000      /* log contents of pkts sent */
-#define SC_LOG_RAWIN   0x00080000      /* log all chars received */
-#define SC_LOG_FLUSH   0x00100000      /* log all chars flushed */
-#define SC_RCV_B7_0    0x01000000      /* have rcvd char with bit 7 = 0 */
-#define SC_RCV_B7_1    0x02000000      /* have rcvd char with bit 7 = 1 */
-#define SC_RCV_EVNP    0x04000000      /* have rcvd char with even parity */
-#define SC_RCV_ODDP    0x08000000      /* have rcvd char with odd parity */
-#define SC_SYNC                0x00200000      /* use synchronous HDLC framing */
-#define        SC_MASK         0x0fff00ff      /* bits that user can change */
-
-/*
- * State bits in sc_flags, not changeable by user.
- */
-#define SC_TIMEOUT     0x00000400      /* timeout is currently pending */
-#define SC_VJ_RESET    0x00000800      /* need to reset VJ decomp */
-#define SC_COMP_RUN    0x00001000      /* compressor has been inited */
-#define SC_DECOMP_RUN  0x00002000      /* decompressor has been inited */
-#define SC_DC_ERROR    0x00004000      /* non-fatal decomp error detected */
-#define SC_DC_FERROR   0x00008000      /* fatal decomp error detected */
-#define SC_TBUSY       0x10000000      /* xmitter doesn't need a packet yet */
-#define SC_PKTLOST     0x20000000      /* have lost or dropped a packet */
-#define        SC_FLUSH        0x40000000      /* flush input until next PPP_FLAG */
-#define        SC_ESCAPED      0x80000000      /* saw a PPP_ESCAPE */
-
-/*
- * Ioctl definitions.
- */
-
-struct npioctl {
-    int                protocol;       /* PPP procotol, e.g. PPP_IP */
-    enum NPmode        mode;
-};
-
-/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */
-struct ppp_option_data {
-       u_char  *ptr;
-       u_int   length;
-       int     transmit;
-};
-
-struct ifpppstatsreq {
-    char ifr_name[IFNAMSIZ];
-    struct ppp_stats stats;
-};
-
-struct ifpppcstatsreq {
-    char ifr_name[IFNAMSIZ];
-    struct ppp_comp_stats stats;
-};
-
-/*
- * Ioctl definitions.
- */
-
-#define        PPPIOCGFLAGS    _IOR('t', 90, int)      /* get configuration flags */
-#define        PPPIOCSFLAGS    _IOW('t', 89, int)      /* set configuration flags */
-#define        PPPIOCGASYNCMAP _IOR('t', 88, int)      /* get async map */
-#define        PPPIOCSASYNCMAP _IOW('t', 87, int)      /* set async map */
-#define        PPPIOCGUNIT     _IOR('t', 86, int)      /* get ppp unit number */
-#define        PPPIOCGRASYNCMAP _IOR('t', 85, int)     /* get receive async map */
-#define        PPPIOCSRASYNCMAP _IOW('t', 84, int)     /* set receive async map */
-#define        PPPIOCGMRU      _IOR('t', 83, int)      /* get max receive unit */
-#define        PPPIOCSMRU      _IOW('t', 82, int)      /* set max receive unit */
-#define        PPPIOCSMAXCID   _IOW('t', 81, int)      /* set VJ max slot ID */
-#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */
-#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */
-#define PPPIOCXFERUNIT _IO('t', 78)            /* transfer PPP unit */
-#define PPPIOCSCOMPRESS        _IOW('t', 77, struct ppp_option_data)
-#define PPPIOCGNPMODE  _IOWR('t', 76, struct npioctl) /* get NP mode */
-#define PPPIOCSNPMODE  _IOW('t', 75, struct npioctl)  /* set NP mode */
-#define PPPIOCGIDLE    _IOR('t', 74, struct ppp_idle) /* get idle time */
-#ifdef PPP_WITH_FILTER
-#define PPPIOCSPASS    _IOW('t', 71, struct bpf_program) /* set pass filter */
-#define PPPIOCSACTIVE  _IOW('t', 70, struct bpf_program) /* set active filt */
-#endif /* PPP_WITH_FILTER */
-
-/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */
-#define PPPIOCGMTU     _IOR('t', 73, int)      /* get interface MTU */
-#define PPPIOCSMTU     _IOW('t', 72, int)      /* set interface MTU */
-
-/*
- * These two are interface ioctls so that pppstats can do them on
- * a socket without having to open the serial device.
- */
-#define SIOCGPPPSTATS  _IOWR('i', 123, struct ifpppstatsreq)
-#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq)
-
-#if !defined(ifr_mtu)
-#define ifr_mtu        ifr_ifru.ifru_metric
-#endif
-
-#if (defined(_KERNEL) || defined(KERNEL)) && !defined(NeXT)
-void pppattach(void);
-void pppintr(void);
-#endif
-#endif /* _IF_PPP_H_ */
diff --git a/include/net/ppp-comp.h b/include/net/ppp-comp.h
deleted file mode 100644 (file)
index b09ef71..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * ppp-comp.h - Definitions for doing PPP packet compression.
- *
- * Copyright (c) 1984 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp-comp.h,v 1.13 2002/12/06 09:49:15 paulus Exp $
- */
-
-#ifndef _NET_PPP_COMP_H
-#define _NET_PPP_COMP_H
-
-/*
- * The following symbols control whether we include code for
- * various compression methods.
- */
-#ifndef DO_BSD_COMPRESS
-#define DO_BSD_COMPRESS        1       /* by default, include BSD-Compress */
-#endif
-#ifndef DO_DEFLATE
-#define DO_DEFLATE     1       /* by default, include Deflate */
-#endif
-#define DO_PREDICTOR_1 0
-#define DO_PREDICTOR_2 0
-
-/*
- * Structure giving methods for compression/decompression.
- */
-#ifdef PACKETPTR
-struct compressor {
-       int     compress_proto; /* CCP compression protocol number */
-
-       /* Allocate space for a compressor (transmit side) */
-       void    *(*comp_alloc)(u_char *options, int opt_len);
-       /* Free space used by a compressor */
-       void    (*comp_free)(void *state);
-       /* Initialize a compressor */
-       int     (*comp_init)(void *state, u_char *options, int opt_len,
-                            int unit, int hdrlen, int debug);
-       /* Reset a compressor */
-       void    (*comp_reset)(void *state);
-       /* Compress a packet */
-       int     (*compress)(void *state, PACKETPTR *mret,
-                           PACKETPTR mp, int orig_len, int max_len);
-       /* Return compression statistics */
-       void    (*comp_stat)(void *state, struct compstat *stats);
-
-       /* Allocate space for a decompressor (receive side) */
-       void    *(*decomp_alloc)(u_char *options, int opt_len);
-       /* Free space used by a decompressor */
-       void    (*decomp_free)(void *state);
-       /* Initialize a decompressor */
-       int     (*decomp_init)(void *state, u_char *options, int opt_len,
-                              int unit, int hdrlen, int mru, int debug);
-       /* Reset a decompressor */
-       void    (*decomp_reset)(void *state);
-       /* Decompress a packet. */
-       int     (*decompress)(void *state, PACKETPTR mp,
-                             PACKETPTR *dmpp);
-       /* Update state for an incompressible packet received */
-       void    (*incomp)(void *state, PACKETPTR mp);
-       /* Return decompression statistics */
-       void    (*decomp_stat)(void *state, struct compstat *stats);
-};
-#endif /* PACKETPTR */
-
-/*
- * Return values for decompress routine.
- * We need to make these distinctions so that we can disable certain
- * useful functionality, namely sending a CCP reset-request as a result
- * of an error detected after decompression.  This is to avoid infringing
- * a patent held by Motorola.
- * Don't you just lurve software patents.
- */
-#define DECOMP_OK              0       /* everything went OK */
-#define DECOMP_ERROR           1       /* error detected before decomp. */
-#define DECOMP_FATALERROR      2       /* error detected after decomp. */
-
-/*
- * CCP codes.
- */
-#define CCP_CONFREQ    1
-#define CCP_CONFACK    2
-#define CCP_TERMREQ    5
-#define CCP_TERMACK    6
-#define CCP_RESETREQ   14
-#define CCP_RESETACK   15
-
-/*
- * Max # bytes for a CCP option
- */
-#define CCP_MAX_OPTION_LENGTH  32
-
-/*
- * Parts of a CCP packet.
- */
-#define CCP_CODE(dp)           ((dp)[0])
-#define CCP_ID(dp)             ((dp)[1])
-#define CCP_LENGTH(dp)         (((dp)[2] << 8) + (dp)[3])
-#define CCP_HDRLEN             4
-
-#define CCP_OPT_CODE(dp)       ((dp)[0])
-#define CCP_OPT_LENGTH(dp)     ((dp)[1])
-#define CCP_OPT_MINLEN         2
-
-/*
- * Definitions for BSD-Compress.
- */
-#define CI_BSD_COMPRESS                21      /* config. option for BSD-Compress */
-#define CILEN_BSD_COMPRESS     3       /* length of config. option */
-
-/* Macros for handling the 3rd byte of the BSD-Compress config option. */
-#define BSD_NBITS(x)           ((x) & 0x1F)    /* number of bits requested */
-#define BSD_VERSION(x)         ((x) >> 5)      /* version of option format */
-#define BSD_CURRENT_VERSION    1               /* current version number */
-#define BSD_MAKE_OPT(v, n)     (((v) << 5) | (n))
-
-#define BSD_MIN_BITS           9       /* smallest code size supported */
-#define BSD_MAX_BITS           15      /* largest code size supported */
-
-/*
- * Definitions for Deflate.
- */
-#define CI_DEFLATE             26      /* config option for Deflate */
-#define CI_DEFLATE_DRAFT       24      /* value used in original draft RFC */
-#define CILEN_DEFLATE          4       /* length of its config option */
-
-#define DEFLATE_MIN_SIZE       8
-#define DEFLATE_MAX_SIZE       15
-#define DEFLATE_METHOD_VAL     8
-#define DEFLATE_SIZE(x)                (((x) >> 4) + DEFLATE_MIN_SIZE)
-#define DEFLATE_METHOD(x)      ((x) & 0x0F)
-#define DEFLATE_MAKE_OPT(w)    ((((w) - DEFLATE_MIN_SIZE) << 4) \
-                                + DEFLATE_METHOD_VAL)
-#define DEFLATE_CHK_SEQUENCE   0
-
-/*
- * Definitions for MPPE.
- */
-#define CI_MPPE                        18      /* config option for MPPE */
-#define CILEN_MPPE             6       /* length of config option */
-
-/*
- * Definitions for other, as yet unsupported, compression methods.
- */
-#define CI_PREDICTOR_1         1       /* config option for Predictor-1 */
-#define CILEN_PREDICTOR_1      2       /* length of its config option */
-#define CI_PREDICTOR_2         2       /* config option for Predictor-2 */
-#define CILEN_PREDICTOR_2      2       /* length of its config option */
-
-#endif /* _NET_PPP_COMP_H */
diff --git a/include/net/ppp_defs.h b/include/net/ppp_defs.h
deleted file mode 100644 (file)
index a5112b3..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/*     $Id: ppp_defs.h,v 1.17 2002/12/06 09:49:15 paulus Exp $ */
-
-/*
- * ppp_defs.h - PPP definitions.
- *
- * Copyright (c) 1984 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _PPP_DEFS_H_
-#define _PPP_DEFS_H_
-
-/*
- * The basic PPP frame.
- */
-#define PPP_HDRLEN     4       /* octets for standard ppp header */
-#define PPP_FCSLEN     2       /* octets for FCS */
-
-/*
- * Packet sizes
- *
- * Note - lcp shouldn't be allowed to negotiate stuff outside these
- *       limits.  See lcp.h in the pppd directory.
- * (XXX - these constants should simply be shared by lcp.c instead
- *       of living in lcp.h)
- */
-#define        PPP_MTU         1500    /* Default MTU (size of Info field) */
-#define PPP_MAXMTU     65535 - (PPP_HDRLEN + PPP_FCSLEN)
-#define PPP_MINMTU     64
-#define PPP_MRU                1500    /* default MRU = max length of info field */
-#define PPP_MAXMRU     65000   /* Largest MRU we allow */
-#define PPP_MINMRU     128
-
-#define PPP_ADDRESS(p) (((u_char *)(p))[0])
-#define PPP_CONTROL(p) (((u_char *)(p))[1])
-#define PPP_PROTOCOL(p)        ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3])
-
-/*
- * Significant octet values.
- */
-#define        PPP_ALLSTATIONS 0xff    /* All-Stations broadcast address */
-#define        PPP_UI          0x03    /* Unnumbered Information */
-#define        PPP_FLAG        0x7e    /* Flag Sequence */
-#define        PPP_ESCAPE      0x7d    /* Asynchronous Control Escape */
-#define        PPP_TRANS       0x20    /* Asynchronous transparency modifier */
-
-/*
- * Protocol field values.
- */
-#define PPP_IP         0x21    /* Internet Protocol */
-#define PPP_AT         0x29    /* AppleTalk Protocol */
-#define PPP_IPX                0x2b    /* IPX protocol */
-#define        PPP_VJC_COMP    0x2d    /* VJ compressed TCP */
-#define        PPP_VJC_UNCOMP  0x2f    /* VJ uncompressed TCP */
-#define PPP_IPV6       0x57    /* Internet Protocol Version 6 */
-#define PPP_COMP       0xfd    /* compressed packet */
-#define PPP_IPCP       0x8021  /* IP Control Protocol */
-#define PPP_ATCP       0x8029  /* AppleTalk Control Protocol */
-#define PPP_IPXCP      0x802b  /* IPX Control Protocol */
-#define PPP_IPV6CP     0x8057  /* IPv6 Control Protocol */
-#define PPP_CCP                0x80fd  /* Compression Control Protocol */
-#define PPP_ECP                0x8053  /* Encryption Control Protocol */
-#define PPP_LCP                0xc021  /* Link Control Protocol */
-#define PPP_PAP                0xc023  /* Password Authentication Protocol */
-#define PPP_LQR                0xc025  /* Link Quality Report protocol */
-#define PPP_CHAP       0xc223  /* Cryptographic Handshake Auth. Protocol */
-#define PPP_CBCP       0xc029  /* Callback Control Protocol */
-#define PPP_EAP                0xc227  /* Extensible Authentication Protocol */
-
-/*
- * Values for FCS calculations.
- */
-#define PPP_INITFCS    0xffff  /* Initial FCS value */
-#define PPP_GOODFCS    0xf0b8  /* Good final FCS value */
-#define PPP_FCS(fcs, c)        (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
-
-/*
- * A 32-bit unsigned integral type.
- */
-
-#if !defined(__BIT_TYPES_DEFINED__) && !defined(_BITYPES) \
- && !defined(__FreeBSD__) && (NS_TARGET < 40)
-#ifdef UINT32_T
-typedef UINT32_T       u_int32_t;
-#else
-typedef unsigned int   u_int32_t;
-typedef unsigned short  u_int16_t;
-#endif
-#endif
-
-/*
- * Extended asyncmap - allows any character to be escaped.
- */
-typedef u_int32_t      ext_accm[8];
-
-/*
- * What to do with network protocol (NP) packets.
- */
-enum NPmode {
-    NPMODE_PASS,               /* pass the packet through */
-    NPMODE_DROP,               /* silently drop the packet */
-    NPMODE_ERROR,              /* return an error */
-    NPMODE_QUEUE               /* save it up for later. */
-};
-
-/*
- * Statistics.
- */
-struct pppstat {
-    unsigned int ppp_ibytes;   /* bytes received */
-    unsigned int ppp_ipackets; /* packets received */
-    unsigned int ppp_ierrors;  /* receive errors */
-    unsigned int ppp_obytes;   /* bytes sent */
-    unsigned int ppp_opackets; /* packets sent */
-    unsigned int ppp_oerrors;  /* transmit errors */
-};
-
-struct vjstat {
-    unsigned int vjs_packets;  /* outbound packets */
-    unsigned int vjs_compressed; /* outbound compressed packets */
-    unsigned int vjs_searches; /* searches for connection state */
-    unsigned int vjs_misses;   /* times couldn't find conn. state */
-    unsigned int vjs_uncompressedin; /* inbound uncompressed packets */
-    unsigned int vjs_compressedin; /* inbound compressed packets */
-    unsigned int vjs_errorin;  /* inbound unknown type packets */
-    unsigned int vjs_tossed;   /* inbound packets tossed because of error */
-};
-
-struct ppp_stats {
-    struct pppstat p;          /* basic PPP statistics */
-    struct vjstat vj;          /* VJ header compression statistics */
-};
-
-struct compstat {
-    unsigned int unc_bytes;    /* total uncompressed bytes */
-    unsigned int unc_packets;  /* total uncompressed packets */
-    unsigned int comp_bytes;   /* compressed bytes */
-    unsigned int comp_packets; /* compressed packets */
-    unsigned int inc_bytes;    /* incompressible bytes */
-    unsigned int inc_packets;  /* incompressible packets */
-    unsigned int ratio;                /* recent compression ratio << 8 */
-};
-
-struct ppp_comp_stats {
-    struct compstat c;         /* packet compression statistics */
-    struct compstat d;         /* packet decompression statistics */
-};
-
-/*
- * The following structure records the time in seconds since
- * the last NP packet was sent or received.
- */
-struct ppp_idle {
-    time_t xmit_idle;          /* time since last NP packet sent */
-    time_t recv_idle;          /* time since last NP packet received */
-};
-
-#endif /* _PPP_DEFS_H_ */
diff --git a/include/net/pppio.h b/include/net/pppio.h
deleted file mode 100644 (file)
index 54cfe44..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * pppio.h - ioctl and other misc. definitions for STREAMS modules.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: pppio.h,v 1.9 2002/12/06 09:49:15 paulus Exp $
- */
-
-#define _PPPIO(n)      (('p' << 8) + (n))
-
-#define PPPIO_NEWPPA   _PPPIO(130)     /* allocate a new PPP unit */
-#define PPPIO_GETSTAT  _PPPIO(131)     /* get PPP statistics */
-#define PPPIO_GETCSTAT _PPPIO(132)     /* get PPP compression stats */
-#define PPPIO_MTU      _PPPIO(133)     /* set max transmission unit */
-#define PPPIO_MRU      _PPPIO(134)     /* set max receive unit */
-#define PPPIO_CFLAGS   _PPPIO(135)     /* set/clear/get compression flags */
-#define PPPIO_XCOMP    _PPPIO(136)     /* alloc transmit compressor */
-#define PPPIO_RCOMP    _PPPIO(137)     /* alloc receive decompressor */
-#define PPPIO_XACCM    _PPPIO(138)     /* set transmit asyncmap */
-#define PPPIO_RACCM    _PPPIO(139)     /* set receive asyncmap */
-#define PPPIO_VJINIT   _PPPIO(140)     /* initialize VJ comp/decomp */
-#define PPPIO_ATTACH   _PPPIO(141)     /* attach to a ppa (without putmsg) */
-#define PPPIO_LASTMOD  _PPPIO(142)     /* mark last ppp module */
-#define PPPIO_GCLEAN   _PPPIO(143)     /* get 8-bit-clean flags */
-#define PPPIO_DEBUG    _PPPIO(144)     /* request debug information */
-#define PPPIO_BIND     _PPPIO(145)     /* bind to SAP */
-#define PPPIO_NPMODE   _PPPIO(146)     /* set mode for handling data pkts */
-#define PPPIO_GIDLE    _PPPIO(147)     /* get time since last data pkt */
-#define PPPIO_PASSFILT _PPPIO(148)     /* set filter for packets to pass */
-#define PPPIO_ACTIVEFILT _PPPIO(149)   /* set filter for "link active" pkts */
-
-/*
- * Values for PPPIO_CFLAGS
- */
-#define COMP_AC                0x1             /* compress address/control */
-#define DECOMP_AC      0x2             /* decompress address/control */
-#define COMP_PROT      0x4             /* compress PPP protocol */
-#define DECOMP_PROT    0x8             /* decompress PPP protocol */
-
-#define COMP_VJC       0x10            /* compress TCP/IP headers */
-#define COMP_VJCCID    0x20            /* compress connection ID as well */
-#define DECOMP_VJC     0x40            /* decompress TCP/IP headers */
-#define DECOMP_VJCCID  0x80            /* accept compressed connection ID */
-
-#define CCP_ISOPEN     0x100           /* look at CCP packets */
-#define CCP_ISUP       0x200           /* do packet comp/decomp */
-#define CCP_ERROR      0x400           /* (status) error in packet decomp */
-#define CCP_FATALERROR 0x800           /* (status) fatal error ditto */
-#define CCP_COMP_RUN   0x1000          /* (status) seen CCP ack sent */
-#define CCP_DECOMP_RUN 0x2000          /* (status) seen CCP ack rcvd */
-
-/*
- * Values for 8-bit-clean flags.
- */
-#define RCV_B7_0       1               /* have rcvd char with bit 7 = 0 */
-#define RCV_B7_1       2               /* have rcvd char with bit 7 = 1 */
-#define RCV_EVNP       4               /* have rcvd char with even parity */
-#define RCV_ODDP       8               /* have rcvd char with odd parity */
-
-/*
- * Values for the first byte of M_CTL messages passed between
- * PPP modules.
- */
-#define PPPCTL_OERROR  0xe0            /* output error [up] */
-#define PPPCTL_IERROR  0xe1            /* input error (e.g. FCS) [up] */
-#define PPPCTL_MTU     0xe2            /* set MTU [down] */
-#define PPPCTL_MRU     0xe3            /* set MRU [down] */
-#define PPPCTL_UNIT    0xe4            /* note PPP unit number [down] */
-
-/*
- * Values for the integer argument to PPPIO_DEBUG.
- */
-#define PPPDBG_DUMP    0x10000         /* print out debug info now */
-#define PPPDBG_LOG     0x100           /* log various things */
-#define PPPDBG_DRIVER  0               /* identifies ppp driver as target */
-#define PPPDBG_IF      1               /* identifies ppp network i/f target */
-#define PPPDBG_COMP    2               /* identifies ppp compression target */
-#define PPPDBG_AHDLC   3               /* identifies ppp async hdlc target */
diff --git a/include/net/slcompress.h b/include/net/slcompress.h
deleted file mode 100644 (file)
index 3712a1a..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Definitions for tcp compression routines.
- *
- * $Id: slcompress.h,v 1.4 1994/09/21 06:50:08 paulus Exp $
- *
- * Copyright (c) 1989 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- *     Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
- *     - Initial distribution.
- */
-
-#ifndef _SLCOMPRESS_H_
-#define _SLCOMPRESS_H_
-
-#define MAX_STATES 16          /* must be > 2 and < 256 */
-#define MAX_HDR MLEN           /* XXX 4bsd-ism: should really be 128 */
-
-/*
- * Compressed packet format:
- *
- * The first octet contains the packet type (top 3 bits), TCP
- * 'push' bit, and flags that indicate which of the 4 TCP sequence
- * numbers have changed (bottom 5 bits).  The next octet is a
- * conversation number that associates a saved IP/TCP header with
- * the compressed packet.  The next two octets are the TCP checksum
- * from the original datagram.  The next 0 to 15 octets are
- * sequence number changes, one change per bit set in the header
- * (there may be no changes and there are two special cases where
- * the receiver implicitly knows what changed -- see below).
- * 
- * There are 5 numbers which can change (they are always inserted
- * in the following order): TCP urgent pointer, window,
- * acknowlegement, sequence number and IP ID.  (The urgent pointer
- * is different from the others in that its value is sent, not the
- * change in value.)  Since typical use of SLIP links is biased
- * toward small packets (see comments on MTU/MSS below), changes
- * use a variable length coding with one octet for numbers in the
- * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
- * range 256 - 65535 or 0.  (If the change in sequence number or
- * ack is more than 65535, an uncompressed packet is sent.)
- */
-
-/*
- * Packet types (must not conflict with IP protocol version)
- *
- * The top nibble of the first octet is the packet type.  There are
- * three possible types: IP (not proto TCP or tcp with one of the
- * control flags set); uncompressed TCP (a normal IP/TCP packet but
- * with the 8-bit protocol field replaced by an 8-bit connection id --
- * this type of packet syncs the sender & receiver); and compressed
- * TCP (described above).
- *
- * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
- * is logically part of the 4-bit "changes" field that follows.  Top
- * three bits are actual packet type.  For backward compatibility
- * and in the interest of conserving bits, numbers are chosen so the
- * IP protocol version number (4) which normally appears in this nibble
- * means "IP packet".
- */
-
-/* packet types */
-#define TYPE_IP 0x40
-#define TYPE_UNCOMPRESSED_TCP 0x70
-#define TYPE_COMPRESSED_TCP 0x80
-#define TYPE_ERROR 0x00
-
-/* Bits in first octet of compressed packet */
-#define NEW_C  0x40    /* flag bits for what changed in a packet */
-#define NEW_I  0x20
-#define NEW_S  0x08
-#define NEW_A  0x04
-#define NEW_W  0x02
-#define NEW_U  0x01
-
-/* reserved, special-case values of above */
-#define SPECIAL_I (NEW_S|NEW_W|NEW_U)          /* echoed interactive traffic */
-#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
-#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
-
-#define TCP_PUSH_BIT 0x10
-
-
-/*
- * "state" data for each active tcp conversation on the wire.  This is
- * basically a copy of the entire IP/TCP header from the last packet
- * we saw from the conversation together with a small identifier
- * the transmit & receive ends of the line use to locate saved header.
- */
-struct cstate {
-       struct cstate *cs_next; /* next most recently used cstate (xmit only) */
-       u_short cs_hlen;        /* size of hdr (receive only) */
-       u_char cs_id;           /* connection # associated with this state */
-       u_char cs_filler;
-       union {
-               char csu_hdr[MAX_HDR];
-               struct ip csu_ip;       /* ip/tcp hdr from most recent packet */
-       } slcs_u;
-};
-#define cs_ip slcs_u.csu_ip
-#define cs_hdr slcs_u.csu_hdr
-
-/*
- * all the state data for one serial line (we need one of these
- * per line).
- */
-struct slcompress {
-       struct cstate *last_cs; /* most recently used tstate */
-       u_char last_recv;       /* last rcvd conn. id */
-       u_char last_xmit;       /* last sent conn. id */
-       u_short flags;
-#ifndef SL_NO_STATS
-       int sls_packets;        /* outbound packets */
-       int sls_compressed;     /* outbound compressed packets */
-       int sls_searches;       /* searches for connection state */
-       int sls_misses;         /* times couldn't find conn. state */
-       int sls_uncompressedin; /* inbound uncompressed packets */
-       int sls_compressedin;   /* inbound compressed packets */
-       int sls_errorin;        /* inbound unknown type packets */
-       int sls_tossed;         /* inbound packets tossed because of error */
-#endif
-       struct cstate tstate[MAX_STATES];       /* xmit connection states */
-       struct cstate rstate[MAX_STATES];       /* receive connection states */
-};
-/* flag values */
-#define SLF_TOSS 1             /* tossing rcvd frames because of input err */
-
-void   sl_compress_init(struct slcompress *);
-void   sl_compress_setup(struct slcompress *, int);
-u_int  sl_compress_tcp(struct mbuf *,
-           struct ip *, struct slcompress *, int);
-int    sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *);
-int    sl_uncompress_tcp_core(u_char *, int, int, u_int,
-           struct slcompress *, u_char **, u_int *);
-
-#endif /* _SLCOMPRESS_H_ */
diff --git a/include/net/vjcompress.h b/include/net/vjcompress.h
deleted file mode 100644 (file)
index ba1ee1f..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Definitions for tcp compression routines.
- *
- * $Id: vjcompress.h,v 1.3 1996/05/28 00:55:33 paulus Exp $
- *
- * Copyright (c) 1989 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- *     Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
- *     - Initial distribution.
- */
-
-#ifndef _VJCOMPRESS_H_
-#define _VJCOMPRESS_H_
-
-#define MAX_STATES 16          /* must be > 2 and < 256 */
-#define MAX_HDR           128
-
-/*
- * Compressed packet format:
- *
- * The first octet contains the packet type (top 3 bits), TCP
- * 'push' bit, and flags that indicate which of the 4 TCP sequence
- * numbers have changed (bottom 5 bits).  The next octet is a
- * conversation number that associates a saved IP/TCP header with
- * the compressed packet.  The next two octets are the TCP checksum
- * from the original datagram.  The next 0 to 15 octets are
- * sequence number changes, one change per bit set in the header
- * (there may be no changes and there are two special cases where
- * the receiver implicitly knows what changed -- see below).
- * 
- * There are 5 numbers which can change (they are always inserted
- * in the following order): TCP urgent pointer, window,
- * acknowlegement, sequence number and IP ID.  (The urgent pointer
- * is different from the others in that its value is sent, not the
- * change in value.)  Since typical use of SLIP links is biased
- * toward small packets (see comments on MTU/MSS below), changes
- * use a variable length coding with one octet for numbers in the
- * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
- * range 256 - 65535 or 0.  (If the change in sequence number or
- * ack is more than 65535, an uncompressed packet is sent.)
- */
-
-/*
- * Packet types (must not conflict with IP protocol version)
- *
- * The top nibble of the first octet is the packet type.  There are
- * three possible types: IP (not proto TCP or tcp with one of the
- * control flags set); uncompressed TCP (a normal IP/TCP packet but
- * with the 8-bit protocol field replaced by an 8-bit connection id --
- * this type of packet syncs the sender & receiver); and compressed
- * TCP (described above).
- *
- * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
- * is logically part of the 4-bit "changes" field that follows.  Top
- * three bits are actual packet type.  For backward compatibility
- * and in the interest of conserving bits, numbers are chosen so the
- * IP protocol version number (4) which normally appears in this nibble
- * means "IP packet".
- */
-
-/* packet types */
-#define TYPE_IP 0x40
-#define TYPE_UNCOMPRESSED_TCP 0x70
-#define TYPE_COMPRESSED_TCP 0x80
-#define TYPE_ERROR 0x00
-
-/* Bits in first octet of compressed packet */
-#define NEW_C  0x40    /* flag bits for what changed in a packet */
-#define NEW_I  0x20
-#define NEW_S  0x08
-#define NEW_A  0x04
-#define NEW_W  0x02
-#define NEW_U  0x01
-
-/* reserved, special-case values of above */
-#define SPECIAL_I (NEW_S|NEW_W|NEW_U)          /* echoed interactive traffic */
-#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
-#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
-
-#define TCP_PUSH_BIT 0x10
-
-
-/*
- * "state" data for each active tcp conversation on the wire.  This is
- * basically a copy of the entire IP/TCP header from the last packet
- * we saw from the conversation together with a small identifier
- * the transmit & receive ends of the line use to locate saved header.
- */
-struct cstate {
-    struct cstate *cs_next;    /* next most recently used state (xmit only) */
-    u_short cs_hlen;           /* size of hdr (receive only) */
-    u_char cs_id;              /* connection # associated with this state */
-    u_char cs_filler;
-    union {
-       char csu_hdr[MAX_HDR];
-       struct ip csu_ip;       /* ip/tcp hdr from most recent packet */
-    } vjcs_u;
-};
-#define cs_ip vjcs_u.csu_ip
-#define cs_hdr vjcs_u.csu_hdr
-
-/*
- * all the state data for one serial line (we need one of these per line).
- */
-struct vjcompress {
-    struct cstate *last_cs;    /* most recently used tstate */
-    u_char last_recv;          /* last rcvd conn. id */
-    u_char last_xmit;          /* last sent conn. id */
-    u_short flags;
-#ifndef VJ_NO_STATS
-    struct vjstat stats;
-#endif
-    struct cstate tstate[MAX_STATES];  /* xmit connection states */
-    struct cstate rstate[MAX_STATES];  /* receive connection states */
-};
-
-/* flag values */
-#define VJF_TOSS 1             /* tossing rcvd frames because of input err */
-
-extern void  vj_compress_init(struct vjcompress *comp, int max_state);
-extern u_int vj_compress_tcp(struct ip *ip, u_int mlen,
-                               struct vjcompress *comp, int compress_cid_flag,
-                               u_char **vjhdrp);
-extern void  vj_uncompress_err(struct vjcompress *comp);
-extern int   vj_uncompress_uncomp(u_char *buf, int buflen,
-                               struct vjcompress *comp);
-extern int   vj_uncompress_tcp(u_char *buf, int buflen, int total_len,
-                               struct vjcompress *comp, u_char **hdrp,
-                               u_int *hlenp);
-
-#endif /* _VJCOMPRESS_H_ */
index 8ae39cae61b617b82a7e96207616b052bd3d2e91..de8c524a839fdee080592ac6398e3454753490a4 100644 (file)
@@ -55,6 +55,20 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
         ])
 
     AS_IF([test "${with_openssl}" != "no"], [
+        # if pkg-config is installed and openssl has installed a .pc file,
+        # then use that information and don't search ssldirs
+        AC_PATH_PROG([PKG_CONFIG], [pkg-config])
+        if test x"$PKG_CONFIG" != x""; then
+            OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
+            if test $? = 0; then
+                OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
+                OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
+                found=true
+            fi
+        fi
+    ])
+
+    AS_IF([test "${with_openssl}" != "no" && test "${found}" != "true"], [
         OPENSSL_INCLUDES=
         for ssldir in $ssldirs; do
             AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
@@ -69,22 +83,8 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
                 AC_MSG_RESULT([no])
             ])
         done])
-     
-    AS_IF([test "${with_openssl}" != "no" && test ! ${found}], [ 
-        # if pkg-config is installed and openssl has installed a .pc file,
-        # then use that information and don't search ssldirs
-        AC_PATH_PROG([PKG_CONFIG], [pkg-config])
-        if test x"$PKG_CONFIG" != x""; then
-            OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
-            if test $? = 0; then
-                OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
-                OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
-                found=true
-            fi
-        fi
-    ])
 
-    AS_IF([test "${with_openssl}" != "no" && test ${found}], [
+    AS_IF([test "${with_openssl}" != "no" && test "${found}" = "true" ], [
 
         # try the preprocessor and linker with our new flags,
         # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
index b17a7573c8741f3a379df93bc6bca501535985c3..3b2a48c102813f10709a0519619bf9da373490f5 100644 (file)
 
 AC_DEFUN([AX_CHECK_PAM], [
     AC_ARG_WITH([pam],
-        [AS_HELP_STRING([--with-pam=DIR],
-            [With libpam support, see ftp.redhat.com:/pub/pam])],
-        [
-            case "$withval" in
-            "" | y | ye | yes)
-                pamdirs="/usr/local /usr/lib /usr"  
-              ;;
-            n | no)
-                with_pam="no"
-              ;;
-            *)
-                pamdirs="$withval"
-              ;;
-            esac
-        ])
+        [AS_HELP_STRING([--with-pam=yes|no|DIR],
+            [With libpam support, see ftp.redhat.com:/pub/pam])])
+
+    AS_CASE(["$with_pam"],
+        [ye|y], [with_pam=yes],
+        [n], [with_pam=no])
     
-    if [ test "x${with_pam}" != "xno" ] ; then
-        PAM_LIBS="-lpam"
-        for pamdir in $pamdirs; do
-            AC_MSG_CHECKING([for pam_appl.h in $pamdir])
-            if test -f "$pamdir/include/security/pam_appl.h"; then
-                PAM_CFLAGS="-I$pamdir/include"
-                PAM_LDFLAGS="-L$pamdir/lib"
-                AC_MSG_RESULT([yes])
-                break
-            else
-                AC_MSG_RESULT([no])
-            fi
-        done
+    AS_IF([test "x$with_pam" != "xno"], [
+        AS_CASE(["$with_pam"],
+            [""|yes], [PKG_CHECK_MODULES([PAM], [pam], [pamdirs=],
+                        [pamdirs="/usr/local /usr/lib /usr"])],
+            [pamdirs="$with_pam"])
+
+        AS_IF([test -n "$pamdirs"], [
+            PAM_LIBS="-lpam"
+            for pamdir in $pamdirs; do
+                AC_MSG_CHECKING([for pam_appl.h in $pamdir])
+                if test -f "$pamdir/include/security/pam_appl.h"; then
+                    PAM_CFLAGS="-I$pamdir/include"
+                    PAM_LDFLAGS="-L$pamdir/lib"
+                    AC_MSG_RESULT([yes])
+                    break
+                else
+                    AC_MSG_RESULT([no])
+                fi
+            done
+        ])
 
         # try the preprocessor and linker with our new flags,
         # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
@@ -87,7 +85,7 @@ AC_DEFUN([AX_CHECK_PAM], [
         AC_SUBST([PAM_CFLAGS])
         AC_SUBST([PAM_LIBS])
         AC_SUBST([PAM_LDFLAGS])
-    fi
+    ])
     AM_CONDITIONAL(WITH_LIBPAM, test "x${with_pam}" != "xno")
 ])
 
diff --git a/modules/Makefile.am b/modules/Makefile.am
deleted file mode 100644 (file)
index ddd53bc..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-EXTRA_MODULE = \
-    bsd-comp.c \
-    deflate.c \
-    if_ppp.c \
-    ppp_ahdlc.c \
-    ppp.c \
-    ppp_comp.c \
-    ppp_mod.h \
-    vjcompress.c
-
-EXTRA_DIST = \
-    $(EXTRA_MODULE)
diff --git a/modules/bsd-comp.c b/modules/bsd-comp.c
deleted file mode 100644 (file)
index fb52aa2..0000000
+++ /dev/null
@@ -1,1120 +0,0 @@
-/* Because this code is derived from the 4.3BSD compress source:
- *
- *
- * Copyright (c) 1985, 1986 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * James A. Woods, derived from original work by Spencer Thomas
- * and Joseph Orost.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * This version is for use with STREAMS under SunOS 4.x,
- * Digital UNIX, AIX 4.x, and SVR4 systems including Solaris 2.
- *
- * $Id: bsd-comp.c,v 1.21 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-#ifdef AIX4
-#include <net/net_globals.h>
-#endif
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stream.h>
-#include <net/ppp_defs.h>
-#include "ppp_mod.h"
-
-#ifdef SVR4
-#include <sys/byteorder.h>
-#ifndef _BIG_ENDIAN
-#define BSD_LITTLE_ENDIAN
-#endif
-#endif
-
-#ifdef __osf__
-#undef FIRST
-#undef LAST
-#define BSD_LITTLE_ENDIAN
-#endif
-
-#ifdef SOL2
-#include <sys/sunddi.h>
-#endif
-
-#define PACKETPTR      mblk_t *
-#include <net/ppp-comp.h>
-
-#if DO_BSD_COMPRESS
-
-/*
- * PPP "BSD compress" compression
- *  The differences between this compression and the classic BSD LZW
- *  source are obvious from the requirement that the classic code worked
- *  with files while this handles arbitrarily long streams that
- *  are broken into packets.  They are:
- *
- *     When the code size expands, a block of junk is not emitted by
- *         the compressor and not expected by the decompressor.
- *
- *     New codes are not necessarily assigned every time an old
- *         code is output by the compressor.  This is because a packet
- *         end forces a code to be emitted, but does not imply that a
- *         new sequence has been seen.
- *
- *     The compression ratio is checked at the first end of a packet
- *         after the appropriate gap.  Besides simplifying and speeding
- *         things up, this makes it more likely that the transmitter
- *         and receiver will agree when the dictionary is cleared when
- *         compression is not going well.
- */
-
-/*
- * A dictionary for doing BSD compress.
- */
-struct bsd_db {
-    int            totlen;                     /* length of this structure */
-    u_int   hsize;                     /* size of the hash table */
-    u_char  hshift;                    /* used in hash function */
-    u_char  n_bits;                    /* current bits/code */
-    u_char  maxbits;
-    u_char  debug;
-    u_char  unit;
-    u_short seqno;                     /* sequence number of next packet */
-    u_int   hdrlen;                    /* header length to preallocate */
-    u_int   mru;
-    u_int   maxmaxcode;                        /* largest valid code */
-    u_int   max_ent;                   /* largest code in use */
-    u_int   in_count;                  /* uncompressed bytes, aged */
-    u_int   bytes_out;                 /* compressed bytes, aged */
-    u_int   ratio;                     /* recent compression ratio */
-    u_int   checkpoint;                        /* when to next check the ratio */
-    u_int   clear_count;               /* times dictionary cleared */
-    u_int   incomp_count;              /* incompressible packets */
-    u_int   incomp_bytes;              /* incompressible bytes */
-    u_int   uncomp_count;              /* uncompressed packets */
-    u_int   uncomp_bytes;              /* uncompressed bytes */
-    u_int   comp_count;                        /* compressed packets */
-    u_int   comp_bytes;                        /* compressed bytes */
-    u_short *lens;                     /* array of lengths of codes */
-    struct bsd_dict {
-       union {                         /* hash value */
-           u_int32_t   fcode;
-           struct {
-#ifdef BSD_LITTLE_ENDIAN
-               u_short prefix;         /* preceding code */
-               u_char  suffix;         /* last character of new code */
-               u_char  pad;
-#else
-               u_char  pad;
-               u_char  suffix;         /* last character of new code */
-               u_short prefix;         /* preceding code */
-#endif
-           } hs;
-       } f;
-       u_short codem1;                 /* output of hash table -1 */
-       u_short cptr;                   /* map code to hash table entry */
-    } dict[1];
-};
-
-#define BSD_OVHD       2               /* BSD compress overhead/packet */
-#define BSD_INIT_BITS  BSD_MIN_BITS
-
-static void    *bsd_comp_alloc(u_char *options, int opt_len);
-static void    *bsd_decomp_alloc(u_char *options, int opt_len);
-static void    bsd_free(void *state);
-static int     bsd_comp_init(void *state, u_char *options, int opt_len,
-                                  int unit, int hdrlen, int debug);
-static int     bsd_decomp_init(void *state, u_char *options, int opt_len,
-                                    int unit, int hdrlen, int mru, int debug);
-static int     bsd_compress(void *state, mblk_t **mret,
-                                 mblk_t *mp, int slen, int maxolen);
-static void    bsd_incomp(void *state, mblk_t *dmsg);
-static int     bsd_decompress(void *state, mblk_t *cmp, mblk_t **dmpp);
-static void    bsd_reset(void *state);
-static void    bsd_comp_stats(void *state, struct compstat *stats);
-
-/*
- * Procedures exported to ppp_comp.c.
- */
-struct compressor ppp_bsd_compress = {
-    CI_BSD_COMPRESS,           /* compress_proto */
-    bsd_comp_alloc,            /* comp_alloc */
-    bsd_free,                  /* comp_free */
-    bsd_comp_init,             /* comp_init */
-    bsd_reset,                 /* comp_reset */
-    bsd_compress,              /* compress */
-    bsd_comp_stats,            /* comp_stat */
-    bsd_decomp_alloc,          /* decomp_alloc */
-    bsd_free,                  /* decomp_free */
-    bsd_decomp_init,           /* decomp_init */
-    bsd_reset,                 /* decomp_reset */
-    bsd_decompress,            /* decompress */
-    bsd_incomp,                        /* incomp */
-    bsd_comp_stats,            /* decomp_stat */
-};
-
-/*
- * the next two codes should not be changed lightly, as they must not
- * lie within the contiguous general code space.
- */
-#define CLEAR  256                     /* table clear output code */
-#define FIRST  257                     /* first free entry */
-#define LAST   255
-
-#define MAXCODE(b)     ((1 << (b)) - 1)
-#define BADCODEM1      MAXCODE(BSD_MAX_BITS)
-
-#define BSD_HASH(prefix,suffix,hshift) ((((u_int32_t)(suffix)) << (hshift)) \
-                                        ^ (u_int32_t)(prefix))
-#define BSD_KEY(prefix,suffix)         ((((u_int32_t)(suffix)) << 16) \
-                                        + (u_int32_t)(prefix))
-
-#define CHECK_GAP      10000           /* Ratio check interval */
-
-#define RATIO_SCALE_LOG        8
-#define RATIO_SCALE    (1<<RATIO_SCALE_LOG)
-#define RATIO_MAX      (0x7fffffff>>RATIO_SCALE_LOG)
-
-#define DECOMP_CHUNK   256
-
-/*
- * clear the dictionary
- */
-static void
-bsd_clear(db)
-    struct bsd_db *db;
-{
-    db->clear_count++;
-    db->max_ent = FIRST-1;
-    db->n_bits = BSD_INIT_BITS;
-    db->ratio = 0;
-    db->bytes_out = 0;
-    db->in_count = 0;
-    db->checkpoint = CHECK_GAP;
-}
-
-/*
- * If the dictionary is full, then see if it is time to reset it.
- *
- * Compute the compression ratio using fixed-point arithmetic
- * with 8 fractional bits.
- *
- * Since we have an infinite stream instead of a single file,
- * watch only the local compression ratio.
- *
- * Since both peers must reset the dictionary at the same time even in
- * the absence of CLEAR codes (while packets are incompressible), they
- * must compute the same ratio.
- */
-static int                             /* 1=output CLEAR */
-bsd_check(db)
-    struct bsd_db *db;
-{
-    u_int new_ratio;
-
-    if (db->in_count >= db->checkpoint) {
-       /* age the ratio by limiting the size of the counts */
-       if (db->in_count >= RATIO_MAX
-           || db->bytes_out >= RATIO_MAX) {
-           db->in_count -= db->in_count/4;
-           db->bytes_out -= db->bytes_out/4;
-       }
-
-       db->checkpoint = db->in_count + CHECK_GAP;
-
-       if (db->max_ent >= db->maxmaxcode) {
-           /* Reset the dictionary only if the ratio is worse,
-            * or if it looks as if it has been poisoned
-            * by incompressible data.
-            *
-            * This does not overflow, because
-            *  db->in_count <= RATIO_MAX.
-            */
-           new_ratio = db->in_count << RATIO_SCALE_LOG;
-           if (db->bytes_out != 0)
-               new_ratio /= db->bytes_out;
-
-           if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
-               bsd_clear(db);
-               return 1;
-           }
-           db->ratio = new_ratio;
-       }
-    }
-    return 0;
-}
-
-/*
- * Return statistics.
- */
-static void
-bsd_comp_stats(state, stats)
-    void *state;
-    struct compstat *stats;
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int out;
-
-    stats->unc_bytes = db->uncomp_bytes;
-    stats->unc_packets = db->uncomp_count;
-    stats->comp_bytes = db->comp_bytes;
-    stats->comp_packets = db->comp_count;
-    stats->inc_bytes = db->incomp_bytes;
-    stats->inc_packets = db->incomp_count;
-    stats->ratio = db->in_count;
-    out = db->bytes_out;
-    if (stats->ratio <= 0x7fffff)
-       stats->ratio <<= 8;
-    else
-       out >>= 8;
-    if (out != 0)
-       stats->ratio /= out;
-}
-
-/*
- * Reset state, as on a CCP ResetReq.
- */
-static void
-bsd_reset(state)
-    void *state;
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-
-    db->seqno = 0;
-    bsd_clear(db);
-    db->clear_count = 0;
-}
-
-/*
- * Allocate space for a (de) compressor.
- */
-static void *
-bsd_alloc(options, opt_len, decomp)
-    u_char *options;
-    int opt_len, decomp;
-{
-    int bits;
-    u_int newlen, hsize, hshift, maxmaxcode;
-    struct bsd_db *db;
-
-    if (opt_len != 3 || options[0] != CI_BSD_COMPRESS || options[1] != 3
-       || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
-       return NULL;
-
-    bits = BSD_NBITS(options[2]);
-    switch (bits) {
-    case 9:                    /* needs 82152 for both directions */
-    case 10:                   /* needs 84144 */
-    case 11:                   /* needs 88240 */
-    case 12:                   /* needs 96432 */
-       hsize = 5003;
-       hshift = 4;
-       break;
-    case 13:                   /* needs 176784 */
-       hsize = 9001;
-       hshift = 5;
-       break;
-    case 14:                   /* needs 353744 */
-       hsize = 18013;
-       hshift = 6;
-       break;
-    case 15:                   /* needs 691440 */
-       hsize = 35023;
-       hshift = 7;
-       break;
-    case 16:                   /* needs 1366160--far too much, */
-       /* hsize = 69001; */    /* and 69001 is too big for cptr */
-       /* hshift = 8; */       /* in struct bsd_db */
-       /* break; */
-    default:
-       return NULL;
-    }
-
-    maxmaxcode = MAXCODE(bits);
-    newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
-#ifdef __osf__
-    db = (struct bsd_db *) ALLOC_SLEEP(newlen);
-#else
-    db = (struct bsd_db *) ALLOC_NOSLEEP(newlen);
-#endif
-    if (!db)
-       return NULL;
-    bzero(db, sizeof(*db) - sizeof(db->dict));
-
-    if (!decomp) {
-       db->lens = NULL;
-    } else {
-#ifdef __osf__
-       db->lens = (u_short *) ALLOC_SLEEP((maxmaxcode+1) * sizeof(db->lens[0]));
-#else
-       db->lens = (u_short *) ALLOC_NOSLEEP((maxmaxcode+1) * sizeof(db->lens[0]));
-#endif
-       if (!db->lens) {
-           FREE(db, newlen);
-           return NULL;
-       }
-    }
-
-    db->totlen = newlen;
-    db->hsize = hsize;
-    db->hshift = hshift;
-    db->maxmaxcode = maxmaxcode;
-    db->maxbits = bits;
-
-    return (void *) db;
-}
-
-static void
-bsd_free(state)
-    void *state;
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-
-    if (db->lens)
-       FREE(db->lens, (db->maxmaxcode+1) * sizeof(db->lens[0]));
-    FREE(db, db->totlen);
-}
-
-static void *
-bsd_comp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
-{
-    return bsd_alloc(options, opt_len, 0);
-}
-
-static void *
-bsd_decomp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
-{
-    return bsd_alloc(options, opt_len, 1);
-}
-
-/*
- * Initialize the database.
- */
-static int
-bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
-    struct bsd_db *db;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug, decomp;
-{
-    int i;
-
-    if (opt_len < CILEN_BSD_COMPRESS
-       || options[0] != CI_BSD_COMPRESS || options[1] != CILEN_BSD_COMPRESS
-       || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION
-       || BSD_NBITS(options[2]) != db->maxbits
-       || decomp && db->lens == NULL)
-       return 0;
-
-    if (decomp) {
-       i = LAST+1;
-       while (i != 0)
-           db->lens[--i] = 1;
-    }
-    i = db->hsize;
-    while (i != 0) {
-       db->dict[--i].codem1 = BADCODEM1;
-       db->dict[i].cptr = 0;
-    }
-
-    db->unit = unit;
-    db->hdrlen = hdrlen;
-    db->mru = mru;
-    if (debug)
-       db->debug = 1;
-
-    bsd_reset(db);
-
-    return 1;
-}
-
-static int
-bsd_comp_init(state, options, opt_len, unit, hdrlen, debug)
-    void *state;
-    u_char *options;
-    int opt_len, unit, hdrlen, debug;
-{
-    return bsd_init((struct bsd_db *) state, options, opt_len,
-                   unit, hdrlen, 0, debug, 0);
-}
-
-static int
-bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug)
-    void *state;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug;
-{
-    return bsd_init((struct bsd_db *) state, options, opt_len,
-                   unit, hdrlen, mru, debug, 1);
-}
-
-
-/*
- * compress a packet
- *     One change from the BSD compress command is that when the
- *     code size expands, we do not output a bunch of padding.
- *
- * N.B. at present, we ignore the hdrlen specified in the comp_init call.
- */
-static int                     /* new slen */
-bsd_compress(state, mretp, mp, slen, maxolen)
-    void *state;
-    mblk_t **mretp;            /* return compressed mbuf chain here */
-    mblk_t *mp;                        /* from here */
-    int slen;                  /* uncompressed length */
-    int maxolen;               /* max compressed length */
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    int hshift = db->hshift;
-    u_int max_ent = db->max_ent;
-    u_int n_bits = db->n_bits;
-    u_int bitno = 32;
-    u_int32_t accm = 0, fcode;
-    struct bsd_dict *dictp;
-    u_char c;
-    int hval, disp, ent, ilen;
-    mblk_t *np, *mret;
-    u_char *rptr, *wptr;
-    u_char *cp_end;
-    int olen;
-    mblk_t *m, **mnp;
-
-#define PUTBYTE(v) {                                   \
-    if (wptr) {                                                \
-       *wptr++ = (v);                                  \
-       if (wptr >= cp_end) {                           \
-           m->b_wptr = wptr;                           \
-           m = m->b_cont;                              \
-           if (m) {                                    \
-               wptr = m->b_wptr;                       \
-               cp_end = m->b_datap->db_lim;            \
-           } else                                      \
-               wptr = NULL;                            \
-       }                                               \
-    }                                                  \
-    ++olen;                                            \
-}
-
-#define OUTPUT(ent) {                                  \
-    bitno -= n_bits;                                   \
-    accm |= ((ent) << bitno);                          \
-    do {                                               \
-       PUTBYTE(accm >> 24);                            \
-       accm <<= 8;                                     \
-       bitno += 8;                                     \
-    } while (bitno <= 24);                             \
-}
-
-    /*
-     * First get the protocol and check that we're
-     * interested in this packet.
-     */
-    *mretp = NULL;
-    rptr = mp->b_rptr;
-    if (rptr + PPP_HDRLEN > mp->b_wptr) {
-       if (!pullupmsg(mp, PPP_HDRLEN))
-           return 0;
-       rptr = mp->b_rptr;
-    }
-    ent = PPP_PROTOCOL(rptr);          /* get the protocol */
-    if (ent < 0x21 || ent > 0xf9)
-       return 0;
-
-    /* Don't generate compressed packets which are larger than
-       the uncompressed packet. */
-    if (maxolen > slen)
-       maxolen = slen;
-
-    /* Allocate enough message blocks to give maxolen total space. */
-    mnp = &mret;
-    for (olen = maxolen; olen > 0; ) {
-       m = allocb((olen < 4096? olen: 4096), BPRI_MED);
-       *mnp = m;
-       if (m == NULL) {
-           if (mret != NULL) {
-               freemsg(mret);
-               mnp = &mret;
-           }
-           break;
-       }
-       mnp = &m->b_cont;
-       olen -= m->b_datap->db_lim - m->b_wptr;
-    }
-    *mnp = NULL;
-
-    if ((m = mret) != NULL) {
-       wptr = m->b_wptr;
-       cp_end = m->b_datap->db_lim;
-    } else
-       wptr = cp_end = NULL;
-    olen = 0;
-
-    /*
-     * Copy the PPP header over, changing the protocol,
-     * and install the 2-byte sequence number.
-     */
-    if (wptr) {
-       wptr[0] = PPP_ADDRESS(rptr);
-       wptr[1] = PPP_CONTROL(rptr);
-       wptr[2] = 0;            /* change the protocol */
-       wptr[3] = PPP_COMP;
-       wptr[4] = db->seqno >> 8;
-       wptr[5] = db->seqno;
-       wptr += PPP_HDRLEN + BSD_OVHD;
-    }
-    ++db->seqno;
-    rptr += PPP_HDRLEN;
-
-    slen = mp->b_wptr - rptr;
-    ilen = slen + 1;
-    np = mp->b_cont;
-    for (;;) {
-       if (slen <= 0) {
-           if (!np)
-               break;
-           rptr = np->b_rptr;
-           slen = np->b_wptr - rptr;
-           np = np->b_cont;
-           if (!slen)
-               continue;   /* handle 0-length buffers */
-           ilen += slen;
-       }
-
-       slen--;
-       c = *rptr++;
-       fcode = BSD_KEY(ent, c);
-       hval = BSD_HASH(ent, c, hshift);
-       dictp = &db->dict[hval];
-
-       /* Validate and then check the entry. */
-       if (dictp->codem1 >= max_ent)
-           goto nomatch;
-       if (dictp->f.fcode == fcode) {
-           ent = dictp->codem1+1;
-           continue;   /* found (prefix,suffix) */
-       }
-
-       /* continue probing until a match or invalid entry */
-       disp = (hval == 0) ? 1 : hval;
-       do {
-           hval += disp;
-           if (hval >= db->hsize)
-               hval -= db->hsize;
-           dictp = &db->dict[hval];
-           if (dictp->codem1 >= max_ent)
-               goto nomatch;
-       } while (dictp->f.fcode != fcode);
-       ent = dictp->codem1 + 1;        /* finally found (prefix,suffix) */
-       continue;
-
-    nomatch:
-       OUTPUT(ent);            /* output the prefix */
-
-       /* code -> hashtable */
-       if (max_ent < db->maxmaxcode) {
-           struct bsd_dict *dictp2;
-           /* expand code size if needed */
-           if (max_ent >= MAXCODE(n_bits))
-               db->n_bits = ++n_bits;
-
-           /* Invalidate old hash table entry using
-            * this code, and then take it over.
-            */
-           dictp2 = &db->dict[max_ent+1];
-           if (db->dict[dictp2->cptr].codem1 == max_ent)
-               db->dict[dictp2->cptr].codem1 = BADCODEM1;
-           dictp2->cptr = hval;
-           dictp->codem1 = max_ent;
-           dictp->f.fcode = fcode;
-
-           db->max_ent = ++max_ent;
-       }
-       ent = c;
-    }
-
-    OUTPUT(ent);               /* output the last code */
-    db->bytes_out += olen;
-    db->in_count += ilen;
-    if (bitno < 32)
-       ++db->bytes_out;        /* count complete bytes */
-
-    if (bsd_check(db))
-       OUTPUT(CLEAR);          /* do not count the CLEAR */
-
-    /*
-     * Pad dribble bits of last code with ones.
-     * Do not emit a completely useless byte of ones.
-     */
-    if (bitno != 32)
-       PUTBYTE((accm | (0xff << (bitno-8))) >> 24);
-
-    /*
-     * Increase code size if we would have without the packet
-     * boundary and as the decompressor will.
-     */
-    if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
-       db->n_bits++;
-
-    db->uncomp_bytes += ilen;
-    ++db->uncomp_count;
-    if (olen + PPP_HDRLEN + BSD_OVHD > maxolen && mret != NULL) {
-       /* throw away the compressed stuff if it is longer than uncompressed */
-       freemsg(mret);
-       mret = NULL;
-       ++db->incomp_count;
-       db->incomp_bytes += ilen;
-    } else if (wptr != NULL) {
-       m->b_wptr = wptr;
-       if (m->b_cont) {
-           freemsg(m->b_cont);
-           m->b_cont = NULL;
-       }
-       ++db->comp_count;
-       db->comp_bytes += olen + BSD_OVHD;
-    }
-
-    *mretp = mret;
-    return olen + PPP_HDRLEN + BSD_OVHD;
-#undef OUTPUT
-#undef PUTBYTE
-}
-
-
-/*
- * Update the "BSD Compress" dictionary on the receiver for
- * incompressible data by pretending to compress the incoming data.
- */
-static void
-bsd_incomp(state, dmsg)
-    void *state;
-    mblk_t *dmsg;
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int hshift = db->hshift;
-    u_int max_ent = db->max_ent;
-    u_int n_bits = db->n_bits;
-    struct bsd_dict *dictp;
-    u_int32_t fcode;
-    u_char c;
-    long hval, disp;
-    int slen, ilen;
-    u_int bitno = 7;
-    u_char *rptr;
-    u_int ent;
-
-    rptr = dmsg->b_rptr;
-    if (rptr + PPP_HDRLEN > dmsg->b_wptr) {
-       if (!pullupmsg(dmsg, PPP_HDRLEN))
-           return;
-       rptr = dmsg->b_rptr;
-    }
-    ent = PPP_PROTOCOL(rptr);          /* get the protocol */
-    if (ent < 0x21 || ent > 0xf9)
-       return;
-
-    db->seqno++;
-    ilen = 1;          /* count the protocol as 1 byte */
-    rptr += PPP_HDRLEN;
-    for (;;) {
-       slen = dmsg->b_wptr - rptr;
-       if (slen <= 0) {
-           dmsg = dmsg->b_cont;
-           if (!dmsg)
-               break;
-           rptr = dmsg->b_rptr;
-           continue;           /* skip zero-length buffers */
-       }
-       ilen += slen;
-
-       do {
-           c = *rptr++;
-           fcode = BSD_KEY(ent, c);
-           hval = BSD_HASH(ent, c, hshift);
-           dictp = &db->dict[hval];
-
-           /* validate and then check the entry */
-           if (dictp->codem1 >= max_ent)
-               goto nomatch;
-           if (dictp->f.fcode == fcode) {
-               ent = dictp->codem1+1;
-               continue;   /* found (prefix,suffix) */
-           }
-
-           /* continue probing until a match or invalid entry */
-           disp = (hval == 0) ? 1 : hval;
-           do {
-               hval += disp;
-               if (hval >= db->hsize)
-                   hval -= db->hsize;
-               dictp = &db->dict[hval];
-               if (dictp->codem1 >= max_ent)
-                   goto nomatch;
-           } while (dictp->f.fcode != fcode);
-           ent = dictp->codem1+1;
-           continue;   /* finally found (prefix,suffix) */
-
-       nomatch:                /* output (count) the prefix */
-           bitno += n_bits;
-
-           /* code -> hashtable */
-           if (max_ent < db->maxmaxcode) {
-               struct bsd_dict *dictp2;
-               /* expand code size if needed */
-               if (max_ent >= MAXCODE(n_bits))
-                   db->n_bits = ++n_bits;
-
-               /* Invalidate previous hash table entry
-                * assigned this code, and then take it over.
-                */
-               dictp2 = &db->dict[max_ent+1];
-               if (db->dict[dictp2->cptr].codem1 == max_ent)
-                   db->dict[dictp2->cptr].codem1 = BADCODEM1;
-               dictp2->cptr = hval;
-               dictp->codem1 = max_ent;
-               dictp->f.fcode = fcode;
-
-               db->max_ent = ++max_ent;
-               db->lens[max_ent] = db->lens[ent]+1;
-           }
-           ent = c;
-       } while (--slen != 0);
-    }
-    bitno += n_bits;           /* output (count) the last code */
-    db->bytes_out += bitno/8;
-    db->in_count += ilen;
-    (void)bsd_check(db);
-
-    ++db->incomp_count;
-    db->incomp_bytes += ilen;
-    ++db->uncomp_count;
-    db->uncomp_bytes += ilen;
-
-    /* Increase code size if we would have without the packet
-     * boundary and as the decompressor will.
-     */
-    if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
-       db->n_bits++;
-}
-
-
-/*
- * Decompress "BSD Compress"
- *
- * Because of patent problems, we return DECOMP_ERROR for errors
- * found by inspecting the input data and for system problems, but
- * DECOMP_FATALERROR for any errors which could possibly be said to
- * be being detected "after" decompression.  For DECOMP_ERROR,
- * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
- * infringing a patent of Motorola's if we do, so we take CCP down
- * instead.
- *
- * Given that the frame has the correct sequence number and a good FCS,
- * errors such as invalid codes in the input most likely indicate a
- * bug, so we return DECOMP_FATALERROR for them in order to turn off
- * compression, even though they are detected by inspecting the input.
- */
-static int
-bsd_decompress(state, cmsg, dmpp)
-    void *state;
-    mblk_t *cmsg, **dmpp;
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int max_ent = db->max_ent;
-    u_int32_t accm = 0;
-    u_int bitno = 32;          /* 1st valid bit in accm */
-    u_int n_bits = db->n_bits;
-    u_int tgtbitno = 32-n_bits;        /* bitno when we have a code */
-    struct bsd_dict *dictp;
-    int explen, i, seq, len;
-    u_int incode, oldcode, finchar;
-    u_char *p, *rptr, *wptr;
-    mblk_t *dmsg, *mret;
-    int adrs, ctrl, ilen;
-    int dlen, space, codelen, extra;
-
-    /*
-     * Get at least the BSD Compress header in the first buffer
-     */
-    rptr = cmsg->b_rptr;
-    if (rptr + PPP_HDRLEN + BSD_OVHD >= cmsg->b_wptr) {
-       if (!pullupmsg(cmsg, PPP_HDRLEN + BSD_OVHD + 1)) {
-           if (db->debug)
-               printf("bsd_decomp%d: failed to pullup\n", db->unit);
-           return DECOMP_ERROR;
-       }
-       rptr = cmsg->b_rptr;
-    }
-
-    /*
-     * Save the address/control from the PPP header
-     * and then get the sequence number.
-     */
-    adrs = PPP_ADDRESS(rptr);
-    ctrl = PPP_CONTROL(rptr);
-    rptr += PPP_HDRLEN;
-    seq = (rptr[0] << 8) + rptr[1];
-    rptr += BSD_OVHD;
-    ilen = len = cmsg->b_wptr - rptr;
-
-    /*
-     * Check the sequence number and give up if it is not what we expect.
-     */
-    if (seq != db->seqno++) {
-       if (db->debug)
-           printf("bsd_decomp%d: bad sequence # %d, expected %d\n",
-                  db->unit, seq, db->seqno - 1);
-       return DECOMP_ERROR;
-    }
-
-    /*
-     * Allocate one message block to start with.
-     */
-    if ((dmsg = allocb(DECOMP_CHUNK + db->hdrlen, BPRI_MED)) == NULL)
-       return DECOMP_ERROR;
-    mret = dmsg;
-    dmsg->b_wptr += db->hdrlen;
-    dmsg->b_rptr = wptr = dmsg->b_wptr;
-
-    /* Fill in the ppp header, but not the last byte of the protocol
-       (that comes from the decompressed data). */
-    wptr[0] = adrs;
-    wptr[1] = ctrl;
-    wptr[2] = 0;
-    wptr += PPP_HDRLEN - 1;
-    space = dmsg->b_datap->db_lim - wptr;
-
-    oldcode = CLEAR;
-    explen = 0;
-    for (;;) {
-       if (len == 0) {
-           cmsg = cmsg->b_cont;
-           if (!cmsg)          /* quit at end of message */
-               break;
-           rptr = cmsg->b_rptr;
-           len = cmsg->b_wptr - rptr;
-           ilen += len;
-           continue;           /* handle 0-length buffers */
-       }
-
-       /*
-        * Accumulate bytes until we have a complete code.
-        * Then get the next code, relying on the 32-bit,
-        * unsigned accm to mask the result.
-        */
-       bitno -= 8;
-       accm |= *rptr++ << bitno;
-       --len;
-       if (tgtbitno < bitno)
-           continue;
-       incode = accm >> tgtbitno;
-       accm <<= n_bits;
-       bitno += n_bits;
-
-       if (incode == CLEAR) {
-           /*
-            * The dictionary must only be cleared at
-            * the end of a packet.  But there could be an
-            * empty message block at the end.
-            */
-           if (len > 0 || cmsg->b_cont != 0) {
-               if (cmsg->b_cont)
-                   len += msgdsize(cmsg->b_cont);
-               if (len > 0) {
-                   freemsg(dmsg);
-                   if (db->debug)
-                       printf("bsd_decomp%d: bad CLEAR\n", db->unit);
-                   return DECOMP_FATALERROR;
-               }
-           }
-           bsd_clear(db);
-           explen = ilen = 0;
-           break;
-       }
-
-       if (incode > max_ent + 2 || incode > db->maxmaxcode
-           || incode > max_ent && oldcode == CLEAR) {
-           freemsg(dmsg);
-           if (db->debug) {
-               printf("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
-                      db->unit, incode, oldcode);
-               printf("max_ent=0x%x dlen=%d seqno=%d\n",
-                      max_ent, dlen, db->seqno);
-           }
-           return DECOMP_FATALERROR;   /* probably a bug */
-       }
-
-       /* Special case for KwKwK string. */
-       if (incode > max_ent) {
-           finchar = oldcode;
-           extra = 1;
-       } else {
-           finchar = incode;
-           extra = 0;
-       }
-
-       codelen = db->lens[finchar];
-       explen += codelen + extra;
-       if (explen > db->mru + 1) {
-           freemsg(dmsg);
-           if (db->debug)
-               printf("bsd_decomp%d: ran out of mru\n", db->unit);
-           return DECOMP_FATALERROR;
-       }
-
-       /*
-        * Decode this code and install it in the decompressed buffer.
-        */
-       space -= codelen + extra;
-       if (space < 0) {
-           /* Allocate another message block. */
-           dmsg->b_wptr = wptr;
-           dlen = codelen + extra;
-           if (dlen < DECOMP_CHUNK)
-               dlen = DECOMP_CHUNK;
-           if ((dmsg->b_cont = allocb(dlen, BPRI_MED)) == NULL) {
-               freemsg(dmsg);
-               return DECOMP_ERROR;
-           }
-           dmsg = dmsg->b_cont;
-           wptr = dmsg->b_wptr;
-           space = dmsg->b_datap->db_lim - wptr - codelen - extra;
-       }
-       p = (wptr += codelen);
-       while (finchar > LAST) {
-           dictp = &db->dict[db->dict[finchar].cptr];
-#ifdef DEBUG
-           --codelen;
-           if (codelen <= 0) {
-               freemsg(dmsg);
-               printf("bsd_decomp%d: fell off end of chain ", db->unit);
-               printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
-                      incode, finchar, db->dict[finchar].cptr, max_ent);
-               return DECOMP_FATALERROR;
-           }
-           if (dictp->codem1 != finchar-1) {
-               freemsg(dmsg);
-               printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ",
-                      db->unit, incode, finchar);
-               printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode,
-                      db->dict[finchar].cptr, dictp->codem1);
-               return DECOMP_FATALERROR;
-           }
-#endif
-           *--p = dictp->f.hs.suffix;
-           finchar = dictp->f.hs.prefix;
-       }
-       *--p = finchar;
-
-#ifdef DEBUG
-       if (--codelen != 0)
-           printf("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n",
-                  db->unit, codelen, incode, max_ent);
-#endif
-
-       if (extra)              /* the KwKwK case again */
-           *wptr++ = finchar;
-
-       /*
-        * If not first code in a packet, and
-        * if not out of code space, then allocate a new code.
-        *
-        * Keep the hash table correct so it can be used
-        * with uncompressed packets.
-        */
-       if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
-           struct bsd_dict *dictp2;
-           u_int32_t fcode;
-           int hval, disp;
-
-           fcode = BSD_KEY(oldcode,finchar);
-           hval = BSD_HASH(oldcode,finchar,db->hshift);
-           dictp = &db->dict[hval];
-
-           /* look for a free hash table entry */
-           if (dictp->codem1 < max_ent) {
-               disp = (hval == 0) ? 1 : hval;
-               do {
-                   hval += disp;
-                   if (hval >= db->hsize)
-                       hval -= db->hsize;
-                   dictp = &db->dict[hval];
-               } while (dictp->codem1 < max_ent);
-           }
-
-           /*
-            * Invalidate previous hash table entry
-            * assigned this code, and then take it over
-            */
-           dictp2 = &db->dict[max_ent+1];
-           if (db->dict[dictp2->cptr].codem1 == max_ent) {
-               db->dict[dictp2->cptr].codem1 = BADCODEM1;
-           }
-           dictp2->cptr = hval;
-           dictp->codem1 = max_ent;
-           dictp->f.fcode = fcode;
-
-           db->max_ent = ++max_ent;
-           db->lens[max_ent] = db->lens[oldcode]+1;
-
-           /* Expand code size if needed. */
-           if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
-               db->n_bits = ++n_bits;
-               tgtbitno = 32-n_bits;
-           }
-       }
-       oldcode = incode;
-    }
-    dmsg->b_wptr = wptr;
-
-    /*
-     * Keep the checkpoint right so that incompressible packets
-     * clear the dictionary at the right times.
-     */
-    db->bytes_out += ilen;
-    db->in_count += explen;
-    if (bsd_check(db) && db->debug) {
-       printf("bsd_decomp%d: peer should have cleared dictionary\n",
-              db->unit);
-    }
-
-    ++db->comp_count;
-    db->comp_bytes += ilen + BSD_OVHD;
-    ++db->uncomp_count;
-    db->uncomp_bytes += explen;
-
-    *dmpp = mret;
-    return DECOMP_OK;
-}
-#endif /* DO_BSD_COMPRESS */
diff --git a/modules/deflate.c b/modules/deflate.c
deleted file mode 100644 (file)
index 2702326..0000000
+++ /dev/null
@@ -1,772 +0,0 @@
-/*
- * ppp_deflate.c - interface the zlib procedures for Deflate compression
- * and decompression (as used by gzip) to the PPP code.
- * This version is for use with STREAMS under SunOS 4.x, Solaris 2,
- * SVR4, OSF/1 and AIX 4.x.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: deflate.c,v 1.12 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-#ifdef AIX4
-#include <net/net_globals.h>
-#endif
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stream.h>
-#include <net/ppp_defs.h>
-#include "ppp_mod.h"
-
-#define PACKETPTR      mblk_t *
-#include <net/ppp-comp.h>
-
-#ifdef __osf__
-#include "zlib.h"
-#else
-#include "../common/zlib.h"
-#endif
-
-#ifdef SOL2
-#include <sys/sunddi.h>
-#endif
-
-#if DO_DEFLATE
-
-#define DEFLATE_DEBUG  1
-
-/*
- * State for a Deflate (de)compressor.
- */
-struct deflate_state {
-    int                seqno;
-    int                w_size;
-    int                unit;
-    int                hdrlen;
-    int                mru;
-    int                debug;
-    z_stream   strm;
-    struct compstat stats;
-};
-
-#define DEFLATE_OVHD   2               /* Deflate overhead/packet */
-
-static void    *z_alloc(void *, u_int items, u_int size);
-static void    *z_alloc_init(void *, u_int items, u_int size);
-static void    z_free(void *, void *ptr);
-static void    *z_comp_alloc(u_char *options, int opt_len);
-static void    *z_decomp_alloc(u_char *options, int opt_len);
-static void    z_comp_free(void *state);
-static void    z_decomp_free(void *state);
-static int     z_comp_init(void *state, u_char *options, int opt_len,
-                           int unit, int hdrlen, int debug);
-static int     z_decomp_init(void *state, u_char *options, int opt_len,
-                             int unit, int hdrlen, int mru, int debug);
-static int     z_compress(void *state, mblk_t **mret,
-                          mblk_t *mp, int slen, int maxolen);
-static void    z_incomp(void *state, mblk_t *dmsg);
-static int     z_decompress(void *state, mblk_t *cmp,
-                                   mblk_t **dmpp);
-static void    z_comp_reset(void *state);
-static void    z_decomp_reset(void *state);
-static void    z_comp_stats(void *state, struct compstat *stats);
-
-/*
- * Procedures exported to ppp_comp.c.
- */
-struct compressor ppp_deflate = {
-    CI_DEFLATE,                        /* compress_proto */
-    z_comp_alloc,              /* comp_alloc */
-    z_comp_free,               /* comp_free */
-    z_comp_init,               /* comp_init */
-    z_comp_reset,              /* comp_reset */
-    z_compress,                        /* compress */
-    z_comp_stats,              /* comp_stat */
-    z_decomp_alloc,            /* decomp_alloc */
-    z_decomp_free,             /* decomp_free */
-    z_decomp_init,             /* decomp_init */
-    z_decomp_reset,            /* decomp_reset */
-    z_decompress,              /* decompress */
-    z_incomp,                  /* incomp */
-    z_comp_stats,              /* decomp_stat */
-};
-
-struct compressor ppp_deflate_draft = {
-    CI_DEFLATE_DRAFT,          /* compress_proto */
-    z_comp_alloc,              /* comp_alloc */
-    z_comp_free,               /* comp_free */
-    z_comp_init,               /* comp_init */
-    z_comp_reset,              /* comp_reset */
-    z_compress,                        /* compress */
-    z_comp_stats,              /* comp_stat */
-    z_decomp_alloc,            /* decomp_alloc */
-    z_decomp_free,             /* decomp_free */
-    z_decomp_init,             /* decomp_init */
-    z_decomp_reset,            /* decomp_reset */
-    z_decompress,              /* decompress */
-    z_incomp,                  /* incomp */
-    z_comp_stats,              /* decomp_stat */
-};
-
-#define DECOMP_CHUNK   512
-
-/*
- * Space allocation and freeing routines for use by zlib routines.
- */
-struct zchunk {
-    u_int      size;
-    u_int      guard;
-};
-
-#define GUARD_MAGIC    0x77a6011a
-
-static void *
-z_alloc_init(notused, items, size)
-    void *notused;
-    u_int items, size;
-{
-    struct zchunk *z;
-
-    size = items * size + sizeof(struct zchunk);
-#ifdef __osf__
-    z = (struct zchunk *) ALLOC_SLEEP(size);
-#else
-    z = (struct zchunk *) ALLOC_NOSLEEP(size);
-#endif
-    z->size = size;
-    z->guard = GUARD_MAGIC;
-    return (void *) (z + 1);
-}
-
-static void *
-z_alloc(notused, items, size)
-    void *notused;
-    u_int items, size;
-{
-    struct zchunk *z;
-
-    size = items * size + sizeof(struct zchunk);
-    z = (struct zchunk *) ALLOC_NOSLEEP(size);
-    z->size = size;
-    z->guard = GUARD_MAGIC;
-    return (void *) (z + 1);
-}
-
-static void
-z_free(notused, ptr)
-    void *notused;
-    void *ptr;
-{
-    struct zchunk *z = ((struct zchunk *) ptr) - 1;
-
-    if (z->guard != GUARD_MAGIC) {
-       printf("ppp: z_free of corrupted chunk at %x (%x, %x)\n",
-              z, z->size, z->guard);
-       return;
-    }
-    FREE(z, z->size);
-}
-
-/*
- * Allocate space for a compressor.
- */
-static void *
-z_comp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
-{
-    struct deflate_state *state;
-    int w_size;
-
-    if (opt_len != CILEN_DEFLATE
-       || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return NULL;
-    w_size = DEFLATE_SIZE(options[2]);
-    /*
-     * N.B. the 9 below should be DEFLATE_MIN_SIZE (8), but using
-     * 8 will cause kernel crashes because of a bug in zlib.
-     */
-    if (w_size < 9 || w_size > DEFLATE_MAX_SIZE)
-       return NULL;
-
-
-#ifdef __osf__
-    state = (struct deflate_state *) ALLOC_SLEEP(sizeof(*state));
-#else
-    state = (struct deflate_state *) ALLOC_NOSLEEP(sizeof(*state));
-#endif
-
-    if (state == NULL)
-       return NULL;
-
-    state->strm.next_in = NULL;
-    state->strm.zalloc = (alloc_func) z_alloc_init;
-    state->strm.zfree = (free_func) z_free;
-    if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL,
-                    -w_size, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
-       FREE(state, sizeof(*state));
-       return NULL;
-    }
-
-    state->strm.zalloc = (alloc_func) z_alloc;
-    state->w_size = w_size;
-    bzero(&state->stats, sizeof(state->stats));
-    return (void *) state;
-}
-
-static void
-z_comp_free(arg)
-    void *arg;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    deflateEnd(&state->strm);
-    FREE(state, sizeof(*state));
-}
-
-static int
-z_comp_init(arg, options, opt_len, unit, hdrlen, debug)
-    void *arg;
-    u_char *options;
-    int opt_len, unit, hdrlen, debug;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    if (opt_len < CILEN_DEFLATE
-       || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || DEFLATE_SIZE(options[2]) != state->w_size
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return 0;
-
-    state->seqno = 0;
-    state->unit = unit;
-    state->hdrlen = hdrlen;
-    state->debug = debug;
-
-    deflateReset(&state->strm);
-
-    return 1;
-}
-
-static void
-z_comp_reset(arg)
-    void *arg;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    state->seqno = 0;
-    deflateReset(&state->strm);
-}
-
-static int
-z_compress(arg, mret, mp, orig_len, maxolen)
-    void *arg;
-    mblk_t **mret;             /* compressed packet (out) */
-    mblk_t *mp;                /* uncompressed packet (in) */
-    int orig_len, maxolen;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_char *rptr, *wptr;
-    int proto, olen, wspace, r, flush;
-    mblk_t *m;
-
-    /*
-     * Check that the protocol is in the range we handle.
-     */
-    *mret = NULL;
-    rptr = mp->b_rptr;
-    if (rptr + PPP_HDRLEN > mp->b_wptr) {
-       if (!pullupmsg(mp, PPP_HDRLEN))
-           return 0;
-       rptr = mp->b_rptr;
-    }
-    proto = PPP_PROTOCOL(rptr);
-    if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
-       return orig_len;
-
-    /* Allocate one mblk initially. */
-    if (maxolen > orig_len)
-       maxolen = orig_len;
-    if (maxolen <= PPP_HDRLEN + 2) {
-       wspace = 0;
-       m = NULL;
-    } else {
-       wspace = maxolen + state->hdrlen;
-       if (wspace > 4096)
-           wspace = 4096;
-       m = allocb(wspace, BPRI_MED);
-    }
-    if (m != NULL) {
-       *mret = m;
-       if (state->hdrlen + PPP_HDRLEN + 2 < wspace) {
-           m->b_rptr += state->hdrlen;
-           m->b_wptr = m->b_rptr;
-           wspace -= state->hdrlen;
-       }
-       wptr = m->b_wptr;
-
-       /*
-        * Copy over the PPP header and store the 2-byte sequence number.
-        */
-       wptr[0] = PPP_ADDRESS(rptr);
-       wptr[1] = PPP_CONTROL(rptr);
-       wptr[2] = PPP_COMP >> 8;
-       wptr[3] = PPP_COMP;
-       wptr += PPP_HDRLEN;
-       wptr[0] = state->seqno >> 8;
-       wptr[1] = state->seqno;
-       wptr += 2;
-       state->strm.next_out = wptr;
-       state->strm.avail_out = wspace - (PPP_HDRLEN + 2);
-    } else {
-       state->strm.next_out = NULL;
-       state->strm.avail_out = 1000000;
-    }
-    ++state->seqno;
-
-    rptr += (proto > 0xff)? 2: 3;      /* skip 1st proto byte if 0 */
-    state->strm.next_in = rptr;
-    state->strm.avail_in = mp->b_wptr - rptr;
-    mp = mp->b_cont;
-    flush = (mp == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
-    olen = 0;
-    for (;;) {
-       r = deflate(&state->strm, flush);
-       if (r != Z_OK) {
-           printf("z_compress: deflate returned %d (%s)\n",
-                  r, (state->strm.msg? state->strm.msg: ""));
-           break;
-       }
-       if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
-           break;              /* all done */
-       if (state->strm.avail_in == 0 && mp != NULL) {
-           state->strm.next_in = mp->b_rptr;
-           state->strm.avail_in = mp->b_wptr - mp->b_rptr;
-           mp = mp->b_cont;
-           if (mp == NULL)
-               flush = Z_PACKET_FLUSH;
-       }
-       if (state->strm.avail_out == 0) {
-           if (m != NULL) {
-               m->b_wptr += wspace;
-               olen += wspace;
-               wspace = maxolen - olen;
-               if (wspace <= 0) {
-                   wspace = 0;
-                   m->b_cont = NULL;
-               } else {
-                   if (wspace < 32)
-                       wspace = 32;
-                   else if (wspace > 4096)
-                       wspace = 4096;
-                   m->b_cont = allocb(wspace, BPRI_MED);
-               }
-               m = m->b_cont;
-               if (m != NULL) {
-                   state->strm.next_out = m->b_wptr;
-                   state->strm.avail_out = wspace;
-               }
-           }
-           if (m == NULL) {
-               state->strm.next_out = NULL;
-               state->strm.avail_out = 1000000;
-           }
-       }
-    }
-    if (m != NULL) {
-       m->b_wptr += wspace - state->strm.avail_out;
-       olen += wspace - state->strm.avail_out;
-    }
-
-    /*
-     * See if we managed to reduce the size of the packet.
-     */
-    if (olen < orig_len && m != NULL) {
-       state->stats.comp_bytes += olen;
-       state->stats.comp_packets++;
-    } else {
-       if (*mret != NULL) {
-           freemsg(*mret);
-           *mret = NULL;
-       }
-       state->stats.inc_bytes += orig_len;
-       state->stats.inc_packets++;
-       olen = orig_len;
-    }
-    state->stats.unc_bytes += orig_len;
-    state->stats.unc_packets++;
-
-    return olen;
-}
-
-static void
-z_comp_stats(arg, stats)
-    void *arg;
-    struct compstat *stats;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_int out;
-
-    *stats = state->stats;
-    stats->ratio = stats->unc_bytes;
-    out = stats->comp_bytes + stats->unc_bytes;
-    if (stats->ratio <= 0x7ffffff)
-       stats->ratio <<= 8;
-    else
-       out >>= 8;
-    if (out != 0)
-       stats->ratio /= out;
-}
-
-/*
- * Allocate space for a decompressor.
- */
-static void *
-z_decomp_alloc(options, opt_len)
-    u_char *options;
-    int opt_len;
-{
-    struct deflate_state *state;
-    int w_size;
-
-    if (opt_len != CILEN_DEFLATE
-       || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return NULL;
-    w_size = DEFLATE_SIZE(options[2]);
-    /*
-     * N.B. the 9 below should be DEFLATE_MIN_SIZE (8), but using
-     * 8 will cause kernel crashes because of a bug in zlib.
-     */
-    if (w_size < 9 || w_size > DEFLATE_MAX_SIZE)
-       return NULL;
-
-#ifdef __osf__
-    state = (struct deflate_state *) ALLOC_SLEEP(sizeof(*state));
-#else
-    state = (struct deflate_state *) ALLOC_NOSLEEP(sizeof(*state));
-#endif
-    if (state == NULL)
-       return NULL;
-
-    state->strm.next_out = NULL;
-    state->strm.zalloc = (alloc_func) z_alloc_init;
-    state->strm.zfree = (free_func) z_free;
-    if (inflateInit2(&state->strm, -w_size) != Z_OK) {
-       FREE(state, sizeof(*state));
-       return NULL;
-    }
-
-    state->strm.zalloc = (alloc_func) z_alloc;
-    state->w_size = w_size;
-    bzero(&state->stats, sizeof(state->stats));
-    return (void *) state;
-}
-
-static void
-z_decomp_free(arg)
-    void *arg;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    inflateEnd(&state->strm);
-    FREE(state, sizeof(*state));
-}
-
-static int
-z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
-    void *arg;
-    u_char *options;
-    int opt_len, unit, hdrlen, mru, debug;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    if (opt_len < CILEN_DEFLATE
-       || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || DEFLATE_SIZE(options[2]) != state->w_size
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return 0;
-
-    state->seqno = 0;
-    state->unit = unit;
-    state->hdrlen = hdrlen;
-    state->debug = debug;
-    state->mru = mru;
-
-    inflateReset(&state->strm);
-
-    return 1;
-}
-
-static void
-z_decomp_reset(arg)
-    void *arg;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    state->seqno = 0;
-    inflateReset(&state->strm);
-}
-
-/*
- * Decompress a Deflate-compressed packet.
- *
- * Because of patent problems, we return DECOMP_ERROR for errors
- * found by inspecting the input data and for system problems, but
- * DECOMP_FATALERROR for any errors which could possibly be said to
- * be being detected "after" decompression.  For DECOMP_ERROR,
- * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
- * infringing a patent of Motorola's if we do, so we take CCP down
- * instead.
- *
- * Given that the frame has the correct sequence number and a good FCS,
- * errors such as invalid codes in the input most likely indicate a
- * bug, so we return DECOMP_FATALERROR for them in order to turn off
- * compression, even though they are detected by inspecting the input.
- */
-static int
-z_decompress(arg, mi, mop)
-    void *arg;
-    mblk_t *mi, **mop;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    mblk_t *mo, *mo_head;
-    u_char *rptr, *wptr;
-    int rlen, olen, ospace;
-    int seq, i, flush, r, decode_proto;
-    u_char hdr[PPP_HDRLEN + DEFLATE_OVHD];
-
-    *mop = NULL;
-    rptr = mi->b_rptr;
-    for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i) {
-       while (rptr >= mi->b_wptr) {
-           mi = mi->b_cont;
-           if (mi == NULL)
-               return DECOMP_ERROR;
-           rptr = mi->b_rptr;
-       }
-       hdr[i] = *rptr++;
-    }
-
-    /* Check the sequence number. */
-    seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1];
-    if (seq != state->seqno) {
-#if !DEFLATE_DEBUG
-       if (state->debug)
-#endif
-           printf("z_decompress%d: bad seq # %d, expected %d\n",
-                  state->unit, seq, state->seqno);
-       return DECOMP_ERROR;
-    }
-    ++state->seqno;
-
-    /* Allocate an output message block. */
-    mo = allocb(DECOMP_CHUNK + state->hdrlen, BPRI_MED);
-    if (mo == NULL)
-       return DECOMP_ERROR;
-    mo_head = mo;
-    mo->b_cont = NULL;
-    mo->b_rptr += state->hdrlen;
-    mo->b_wptr = wptr = mo->b_rptr;
-    ospace = DECOMP_CHUNK;
-    olen = 0;
-
-    /*
-     * Fill in the first part of the PPP header.  The protocol field
-     * comes from the decompressed data.
-     */
-    wptr[0] = PPP_ADDRESS(hdr);
-    wptr[1] = PPP_CONTROL(hdr);
-    wptr[2] = 0;
-
-    /*
-     * Set up to call inflate.  We set avail_out to 1 initially so we can
-     * look at the first byte of the output and decide whether we have
-     * a 1-byte or 2-byte protocol field.
-     */
-    state->strm.next_in = rptr;
-    state->strm.avail_in = mi->b_wptr - rptr;
-    mi = mi->b_cont;
-    flush = (mi == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
-    rlen = state->strm.avail_in + PPP_HDRLEN + DEFLATE_OVHD;
-    state->strm.next_out = wptr + 3;
-    state->strm.avail_out = 1;
-    decode_proto = 1;
-
-    /*
-     * Call inflate, supplying more input or output as needed.
-     */
-    for (;;) {
-       r = inflate(&state->strm, flush);
-       if (r != Z_OK) {
-#if !DEFLATE_DEBUG
-           if (state->debug)
-#endif
-               printf("z_decompress%d: inflate returned %d (%s)\n",
-                      state->unit, r, (state->strm.msg? state->strm.msg: ""));
-           freemsg(mo_head);
-           return DECOMP_FATALERROR;
-       }
-       if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
-           break;              /* all done */
-       if (state->strm.avail_in == 0 && mi != NULL) {
-           state->strm.next_in = mi->b_rptr;
-           state->strm.avail_in = mi->b_wptr - mi->b_rptr;
-           rlen += state->strm.avail_in;
-           mi = mi->b_cont;
-           if (mi == NULL)
-               flush = Z_PACKET_FLUSH;
-       }
-       if (state->strm.avail_out == 0) {
-           if (decode_proto) {
-               state->strm.avail_out = ospace - PPP_HDRLEN;
-               if ((wptr[3] & 1) == 0) {
-                   /* 2-byte protocol field */
-                   wptr[2] = wptr[3];
-                   --state->strm.next_out;
-                   ++state->strm.avail_out;
-               }
-               decode_proto = 0;
-           } else {
-               mo->b_wptr += ospace;
-               olen += ospace;
-               mo->b_cont = allocb(DECOMP_CHUNK, BPRI_MED);
-               mo = mo->b_cont;
-               if (mo == NULL) {
-                   freemsg(mo_head);
-                   return DECOMP_ERROR;
-               }
-               state->strm.next_out = mo->b_rptr;
-               state->strm.avail_out = ospace = DECOMP_CHUNK;
-           }
-       }
-    }
-    if (decode_proto) {
-       freemsg(mo_head);
-       return DECOMP_ERROR;
-    }
-    mo->b_wptr += ospace - state->strm.avail_out;
-    olen += ospace - state->strm.avail_out;
-
-#if DEFLATE_DEBUG
-    if (olen > state->mru + PPP_HDRLEN)
-       printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
-              state->unit, olen, state->mru + PPP_HDRLEN);
-#endif
-
-    state->stats.unc_bytes += olen;
-    state->stats.unc_packets++;
-    state->stats.comp_bytes += rlen;
-    state->stats.comp_packets++;
-
-    *mop = mo_head;
-    return DECOMP_OK;
-}
-
-/*
- * Incompressible data has arrived - add it to the history.
- */
-static void
-z_incomp(arg, mi)
-    void *arg;
-    mblk_t *mi;
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_char *rptr;
-    int rlen, proto, r;
-
-    /*
-     * Check that the protocol is one we handle.
-     */
-    rptr = mi->b_rptr;
-    if (rptr + PPP_HDRLEN > mi->b_wptr) {
-       if (!pullupmsg(mi, PPP_HDRLEN))
-           return;
-       rptr = mi->b_rptr;
-    }
-    proto = PPP_PROTOCOL(rptr);
-    if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
-       return;
-
-    ++state->seqno;
-
-    /*
-     * Iterate through the message blocks, adding the characters in them
-     * to the decompressor's history.  For the first block, we start
-     * at the either the 1st or 2nd byte of the protocol field,
-     * depending on whether the protocol value is compressible.
-     */
-    rlen = mi->b_wptr - mi->b_rptr;
-    state->strm.next_in = rptr + 3;
-    state->strm.avail_in = rlen - 3;
-    if (proto > 0xff) {
-       --state->strm.next_in;
-       ++state->strm.avail_in;
-    }
-    for (;;) {
-       r = inflateIncomp(&state->strm);
-       if (r != Z_OK) {
-           /* gak! */
-#if !DEFLATE_DEBUG
-           if (state->debug)
-#endif
-               printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
-                      state->unit, r, (state->strm.msg? state->strm.msg: ""));
-           return;
-       }
-       mi = mi->b_cont;
-       if (mi == NULL)
-           break;
-       state->strm.next_in = mi->b_rptr;
-       state->strm.avail_in = mi->b_wptr - mi->b_rptr;
-       rlen += state->strm.avail_in;
-    }
-
-    /*
-     * Update stats.
-     */
-    state->stats.inc_bytes += rlen;
-    state->stats.inc_packets++;
-    state->stats.unc_bytes += rlen;
-    state->stats.unc_packets++;
-}
-
-#endif /* DO_DEFLATE */
diff --git a/modules/if_ppp.c b/modules/if_ppp.c
deleted file mode 100644 (file)
index e150923..0000000
+++ /dev/null
@@ -1,873 +0,0 @@
-/*
- * if_ppp.c - a network interface connected to a STREAMS module.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: if_ppp.c,v 1.18 2002/12/06 09:49:15 paulus Exp $
- */
-
-/*
- * This file is used under SunOS 4 and Digital UNIX.
- *
- * This file provides the glue between PPP and IP.
- */
-
-#define INET   1
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/netisr.h>
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include <netinet/in.h>
-#include <netinet/in_var.h>
-#ifdef __osf__
-#include <sys/ioctl.h>
-#include <net/if_types.h>
-#else
-#include <sys/sockio.h>
-#endif
-#include "ppp_mod.h"
-
-#include <sys/stream.h>
-
-#ifdef SNIT_SUPPORT
-#include <sys/time.h>
-#include <net/nit_if.h>
-#include <netinet/if_ether.h>
-#endif
-
-#ifdef __osf__
-#define SIOCSIFMTU SIOCSIPMTU
-#define SIOCGIFMTU SIOCRIPMTU
-#define IFA_ADDR(ifa)   (*(ifa)->ifa_addr)
-#else
-#define IFA_ADDR(ifa)   ((ifa)->ifa_addr)
-#endif
-
-#define ifr_mtu                ifr_metric
-
-static int if_ppp_open(queue_t *, int, int, int);
-static int if_ppp_close(queue_t *, int);
-static int if_ppp_wput(queue_t *, mblk_t *);
-static int if_ppp_rput(queue_t *, mblk_t *);
-
-#define PPP_IF_ID 0x8021
-static struct module_info minfo = {
-    PPP_IF_ID, "if_ppp", 0, INFPSZ, 4096, 128
-};
-
-static struct qinit rinit = {
-    if_ppp_rput, NULL, if_ppp_open, if_ppp_close, NULL, &minfo, NULL
-};
-
-static struct qinit winit = {
-    if_ppp_wput, NULL, NULL, NULL, NULL, &minfo, NULL
-};
-
-struct streamtab if_pppinfo = {
-    &rinit, &winit, NULL, NULL
-};
-
-typedef struct if_ppp_state {
-    int unit;
-    queue_t *q;
-    int flags;
-} if_ppp_t;
-
-/* Values for flags */
-#define DBGLOG         1
-
-static int if_ppp_count;       /* Number of currently-active streams */
-
-static int ppp_nalloc;         /* Number of elements of ifs and states */
-static struct ifnet **ifs;     /* Array of pointers to interface structs */
-static if_ppp_t **states;      /* Array of pointers to state structs */
-
-static int if_ppp_output(struct ifnet *, struct mbuf *,
-                        struct sockaddr *);
-static int if_ppp_ioctl(struct ifnet *, u_int, caddr_t);
-static struct mbuf *make_mbufs(mblk_t *, int);
-static mblk_t *make_message(struct mbuf *, int);
-
-#ifdef SNIT_SUPPORT
-/* Fake ether header for SNIT */
-static struct ether_header snit_ehdr = {{0}, {0}, ETHERTYPE_IP};
-#endif
-
-#ifndef __osf__
-static void ppp_if_detach(struct ifnet *);
-
-/*
- * Detach all the interfaces before unloading.
- * Not sure this works.
- */
-int
-if_ppp_unload()
-{
-    int i;
-
-    if (if_ppp_count > 0)
-       return EBUSY;
-    for (i = 0; i < ppp_nalloc; ++i)
-       if (ifs[i] != 0)
-           ppp_if_detach(ifs[i]);
-    if (ifs) {
-       FREE(ifs, ppp_nalloc * sizeof (struct ifnet *));
-       FREE(states, ppp_nalloc * sizeof (struct if_ppp_t *));
-    }
-    ppp_nalloc = 0;
-    return 0;
-}
-#endif /* __osf__ */
-
-/*
- * STREAMS module entry points.
- */
-static int
-if_ppp_open(q, dev, flag, sflag)
-    queue_t *q;
-    int dev;
-    int flag, sflag;
-{
-    if_ppp_t *sp;
-
-    if (q->q_ptr == 0) {
-       sp = (if_ppp_t *) ALLOC_SLEEP(sizeof (if_ppp_t));
-       if (sp == 0)
-           return OPENFAIL;
-       bzero(sp, sizeof (if_ppp_t));
-       q->q_ptr = (caddr_t) sp;
-       WR(q)->q_ptr = (caddr_t) sp;
-       sp->unit = -1;          /* no interface unit attached at present */
-       sp->q = WR(q);
-       sp->flags = 0;
-       ++if_ppp_count;
-    }
-    return 0;
-}
-
-static int
-if_ppp_close(q, flag)
-    queue_t *q;
-    int flag;
-{
-    if_ppp_t *sp;
-    struct ifnet *ifp;
-
-    sp = (if_ppp_t *) q->q_ptr;
-    if (sp != 0) {
-       if (sp->flags & DBGLOG)
-           printf("if_ppp closed, q=%x sp=%x\n", q, sp);
-       if (sp->unit >= 0) {
-           if (sp->unit < ppp_nalloc) {
-               states[sp->unit] = 0;
-               ifp = ifs[sp->unit];
-               if (ifp != 0)
-                   ifp->if_flags &= ~(IFF_UP | IFF_RUNNING);
-#ifdef DEBUG
-           } else {
-               printf("if_ppp: unit %d nonexistent!\n", sp->unit);
-#endif
-           }
-       }
-       FREE(sp, sizeof (if_ppp_t));
-       --if_ppp_count;
-    }
-    return 0;
-}
-
-static int
-if_ppp_wput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    if_ppp_t *sp;
-    struct iocblk *iop;
-    int error, unit;
-    struct ifnet *ifp;
-
-    sp = (if_ppp_t *) q->q_ptr;
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       /*
-        * Now why would we be getting data coming in here??
-        */
-       if (sp->flags & DBGLOG)
-           printf("if_ppp: got M_DATA len=%d\n", msgdsize(mp));
-       freemsg(mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-
-       if (sp->flags & DBGLOG)
-           printf("if_ppp: got ioctl cmd=%x count=%d\n",
-                  iop->ioc_cmd, iop->ioc_count);
-
-       switch (iop->ioc_cmd) {
-       case PPPIO_NEWPPA:              /* well almost */
-           if (iop->ioc_count != sizeof(int) || sp->unit >= 0)
-               break;
-           if ((error = NOTSUSER()) != 0)
-               break;
-           unit = *(int *)mp->b_cont->b_rptr;
-
-           /* Check that this unit isn't already in use */
-           if (unit < ppp_nalloc && states[unit] != 0) {
-               error = EADDRINUSE;
-               break;
-           }
-
-           /* Extend ifs and states arrays if necessary. */
-           error = ENOSR;
-           if (unit >= ppp_nalloc) {
-               int newn;
-               struct ifnet **newifs;
-               if_ppp_t **newstates;
-
-               newn = unit + 4;
-               if (sp->flags & DBGLOG)
-                   printf("if_ppp: extending ifs to %d\n", newn);
-               newifs = (struct ifnet **)
-                   ALLOC_NOSLEEP(newn * sizeof (struct ifnet *));
-               if (newifs == 0)
-                   break;
-               bzero(newifs, newn * sizeof (struct ifnet *));
-               newstates = (if_ppp_t **)
-                   ALLOC_NOSLEEP(newn * sizeof (struct if_ppp_t *));
-               if (newstates == 0) {
-                   FREE(newifs, newn * sizeof (struct ifnet *));
-                   break;
-               }
-               bzero(newstates, newn * sizeof (struct if_ppp_t *));
-               bcopy(ifs, newifs, ppp_nalloc * sizeof(struct ifnet *));
-               bcopy(states, newstates, ppp_nalloc * sizeof(if_ppp_t *));
-               if (ifs) {
-                   FREE(ifs, ppp_nalloc * sizeof(struct ifnet *));
-                   FREE(states, ppp_nalloc * sizeof(if_ppp_t *));
-               }
-               ifs = newifs;
-               states = newstates;
-               ppp_nalloc = newn;
-           }
-
-           /* Allocate a new ifnet struct if necessary. */
-           ifp = ifs[unit];
-           if (ifp == 0) {
-               ifp = (struct ifnet *) ALLOC_NOSLEEP(sizeof (struct ifnet));
-               if (ifp == 0)
-                   break;
-               bzero(ifp, sizeof (struct ifnet));
-               ifs[unit] = ifp;
-               ifp->if_name = "ppp";
-               ifp->if_unit = unit;
-               ifp->if_mtu = PPP_MTU;
-               ifp->if_flags = IFF_POINTOPOINT | IFF_RUNNING;
-#ifndef __osf__
-#ifdef IFF_MULTICAST
-               ifp->if_flags |= IFF_MULTICAST;
-#endif
-#endif /* __osf__ */
-               ifp->if_output = if_ppp_output;
-#ifdef __osf__
-               ifp->if_version = "Point-to-Point Protocol, version 2.3.11";
-               ifp->if_mediamtu = PPP_MTU;
-               ifp->if_type = IFT_PPP;
-               ifp->if_hdrlen = PPP_HDRLEN;
-               ifp->if_addrlen = 0;
-               ifp->if_flags |= IFF_NOARP | IFF_SIMPLEX | IFF_NOTRAILERS;
-#ifdef IFF_VAR_MTU
-               ifp->if_flags |= IFF_VAR_MTU;
-#endif
-#ifdef NETMASTERCPU
-               ifp->if_affinity = NETMASTERCPU;
-#endif
-#endif
-               ifp->if_ioctl = if_ppp_ioctl;
-               ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
-               if_attach(ifp);
-               if (sp->flags & DBGLOG)
-                   printf("if_ppp: created unit %d\n", unit);
-           } else {
-               ifp->if_mtu = PPP_MTU;
-               ifp->if_flags |= IFF_RUNNING;
-           }
-
-           states[unit] = sp;
-           sp->unit = unit;
-
-           error = 0;
-           iop->ioc_count = 0;
-           if (sp->flags & DBGLOG)
-               printf("if_ppp: attached unit %d, sp=%x q=%x\n", unit,
-                      sp, sp->q);
-           break;
-
-       case PPPIO_DEBUG:
-           error = -1;
-           if (iop->ioc_count == sizeof(int)) {
-               if (*(int *)mp->b_cont->b_rptr == PPPDBG_LOG + PPPDBG_IF) {
-                   printf("if_ppp: debug log enabled, q=%x sp=%x\n", q, sp);
-                   sp->flags |= DBGLOG;
-                   error = 0;
-                   iop->ioc_count = 0;
-               }
-           }
-           break;
-
-       default:
-           error = -1;
-           break;
-       }
-
-       if (sp->flags & DBGLOG)
-           printf("if_ppp: ioctl result %d\n", error);
-       if (error < 0)
-           putnext(q, mp);
-       else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       } else {
-           mp->b_datap->db_type = M_IOCNAK;
-           iop->ioc_count = 0;
-           iop->ioc_error = error;
-           qreply(q, mp);
-       }
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-    return 0;
-}
-
-static int
-if_ppp_rput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    if_ppp_t *sp;
-    int proto, s;
-    struct mbuf *mb;
-    struct ifqueue *inq;
-    struct ifnet *ifp;
-    int len;
-
-    sp = (if_ppp_t *) q->q_ptr;
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       /*
-        * Convert the message into an mbuf chain
-        * and inject it into the network code.
-        */
-       if (sp->flags & DBGLOG)
-           printf("if_ppp: rput pkt len %d data %x %x %x %x %x %x %x %x\n",
-                  msgdsize(mp), mp->b_rptr[0], mp->b_rptr[1], mp->b_rptr[2],
-                  mp->b_rptr[3], mp->b_rptr[4], mp->b_rptr[5], mp->b_rptr[6],
-                  mp->b_rptr[7]);
-
-       if (sp->unit < 0) {
-           freemsg(mp);
-           break;
-       }
-       if (sp->unit >= ppp_nalloc || (ifp = ifs[sp->unit]) == 0) {
-#ifdef DEBUG
-           printf("if_ppp: no unit %d!\n", sp->unit);
-#endif
-           freemsg(mp);
-           break;
-       }
-
-       if ((ifp->if_flags & IFF_UP) == 0) {
-           freemsg(mp);
-           break;
-       }
-       ++ifp->if_ipackets;
-
-       proto = PPP_PROTOCOL(mp->b_rptr);
-       adjmsg(mp, PPP_HDRLEN);
-       len = msgdsize(mp);
-       mb = make_mbufs(mp, sizeof(struct ifnet *));
-       freemsg(mp);
-       if (mb == NULL) {
-           if (sp->flags & DBGLOG)
-               printf("if_ppp%d: make_mbufs failed\n", ifp->if_unit);
-           ++ifp->if_ierrors;
-           break;
-       }
-
-#ifdef SNIT_SUPPORT
-       if (proto == PPP_IP && (ifp->if_flags & IFF_PROMISC)) {
-           struct nit_if nif;
-
-           nif.nif_header = (caddr_t) &snit_ehdr;
-           nif.nif_hdrlen = sizeof(snit_ehdr);
-           nif.nif_bodylen = len;
-           nif.nif_promisc = 0;
-           snit_intr(ifp, mb, &nif);
-       }
-#endif
-
-/*
- * For Digital UNIX, there's space set aside in the header mbuf
- * for the interface info.
- *
- * For Sun it's smuggled around via a pointer at the front of the mbuf.
- */
-#ifdef __osf__
-        mb->m_pkthdr.rcvif = ifp;
-        mb->m_pkthdr.len = len;
-#else
-       mb->m_off -= sizeof(struct ifnet *);
-       mb->m_len += sizeof(struct ifnet *);
-       *mtod(mb, struct ifnet **) = ifp;
-#endif
-
-       inq = 0;
-       switch (proto) {
-       case PPP_IP:
-           inq = &ipintrq;
-           schednetisr(NETISR_IP);
-       }
-
-       if (inq != 0) {
-           s = splhigh();
-           if (IF_QFULL(inq)) {
-               IF_DROP(inq);
-               ++ifp->if_ierrors;
-               if (sp->flags & DBGLOG)
-                   printf("if_ppp: inq full, proto=%x\n", proto);
-               m_freem(mb);
-           } else {
-               IF_ENQUEUE(inq, mb);
-           }
-           splx(s);
-       } else {
-           if (sp->flags & DBGLOG)
-               printf("if_ppp%d: proto=%x?\n", ifp->if_unit, proto);
-           ++ifp->if_ierrors;
-           m_freem(mb);
-       }
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-    return 0;
-}
-
-/*
- * Network code wants to output a packet.
- * Turn it into a STREAMS message and send it down.
- */
-static int
-if_ppp_output(ifp, m0, dst)
-    struct ifnet *ifp;
-    struct mbuf *m0;
-    struct sockaddr *dst;
-{
-    mblk_t *mp;
-    int proto, s;
-    if_ppp_t *sp;
-    u_char *p;
-
-    if ((ifp->if_flags & IFF_UP) == 0) {
-       m_freem(m0);
-       return ENETDOWN;
-    }
-
-    if ((unsigned)ifp->if_unit >= ppp_nalloc) {
-#ifdef DEBUG
-       printf("if_ppp_output: unit %d?\n", ifp->if_unit);
-#endif
-       m_freem(m0);
-       return EINVAL;
-    }
-    sp = states[ifp->if_unit];
-    if (sp == 0) {
-#ifdef DEBUG
-       printf("if_ppp_output: no queue?\n");
-#endif
-       m_freem(m0);
-       return ENETDOWN;
-    }
-
-    if (sp->flags & DBGLOG) {
-       p = mtod(m0, u_char *);
-       printf("if_ppp_output%d: af=%d data=%x %x %x %x %x %x %x %x q=%x\n",
-              ifp->if_unit, dst->sa_family, p[0], p[1], p[2], p[3], p[4],
-              p[5], p[6], p[7], sp->q);
-    }
-
-    switch (dst->sa_family) {
-    case AF_INET:
-       proto = PPP_IP;
-#ifdef SNIT_SUPPORT
-       if (ifp->if_flags & IFF_PROMISC) {
-           struct nit_if nif;
-           struct mbuf *m;
-           int len;
-
-           for (len = 0, m = m0; m != NULL; m = m->m_next)
-               len += m->m_len;
-           nif.nif_header = (caddr_t) &snit_ehdr;
-           nif.nif_hdrlen = sizeof(snit_ehdr);
-           nif.nif_bodylen = len;
-           nif.nif_promisc = 0;
-           snit_intr(ifp, m0, &nif);
-       }
-#endif
-       break;
-
-    default:
-       m_freem(m0);
-       return EAFNOSUPPORT;
-    }
-
-    ++ifp->if_opackets;
-    mp = make_message(m0, PPP_HDRLEN);
-    m_freem(m0);
-    if (mp == 0) {
-       ++ifp->if_oerrors;
-       return ENOBUFS;
-    }
-    mp->b_rptr -= PPP_HDRLEN;
-    mp->b_rptr[0] = PPP_ALLSTATIONS;
-    mp->b_rptr[1] = PPP_UI;
-    mp->b_rptr[2] = proto >> 8;
-    mp->b_rptr[3] = proto;
-
-    s = splstr();
-    if (sp->flags & DBGLOG)
-       printf("if_ppp: putnext(%x, %x), r=%x w=%x p=%x\n",
-              sp->q, mp, mp->b_rptr, mp->b_wptr, proto);
-    putnext(sp->q, mp);
-    splx(s);
-
-    return 0;
-}
-
-/*
- * Socket ioctl routine for ppp interfaces.
- */
-static int
-if_ppp_ioctl(ifp, cmd, data)
-    struct ifnet *ifp;
-    u_int cmd;
-    caddr_t data;
-{
-    int s, error;
-    struct ifreq *ifr = (struct ifreq *) data;
-    struct ifaddr *ifa = (struct ifaddr *) data;
-    u_short mtu;
-
-    error = 0;
-    s = splimp();
-    switch (cmd) {
-    case SIOCSIFFLAGS:
-       if ((ifp->if_flags & IFF_RUNNING) == 0)
-           ifp->if_flags &= ~IFF_UP;
-       break;
-
-    case SIOCSIFADDR:
-       if (IFA_ADDR(ifa).sa_family != AF_INET)
-           error = EAFNOSUPPORT;
-       break;
-
-    case SIOCSIFDSTADDR:
-       if (IFA_ADDR(ifa).sa_family != AF_INET)
-           error = EAFNOSUPPORT;
-       break;
-
-    case SIOCSIFMTU:
-       if ((error = NOTSUSER()) != 0)
-           break;
-#ifdef __osf__
-       /* this hack is necessary because ifioctl checks ifr_data
-        * in 4.0 and 5.0, but ifr_data and ifr_metric overlay each 
-        * other in the definition of struct ifreq so pppd can't set both.
-        */
-        bcopy(ifr->ifr_data, &mtu, sizeof (u_short));
-        ifr->ifr_mtu = mtu;
-#endif
-
-       if (ifr->ifr_mtu < PPP_MINMTU || ifr->ifr_mtu > PPP_MAXMTU) {
-           error = EINVAL;
-           break;
-       }
-       ifp->if_mtu = ifr->ifr_mtu;
-       break;
-
-    case SIOCGIFMTU:
-       ifr->ifr_mtu = ifp->if_mtu;
-       break;
-
-    case SIOCADDMULTI:
-    case SIOCDELMULTI:
-       switch(ifr->ifr_addr.sa_family) {
-       case AF_INET:
-           break;
-       default:
-           error = EAFNOSUPPORT;
-           break;
-       }
-       break;
-
-    default:
-       error = EINVAL;
-    }
-    splx(s);
-    return (error);
-}
-
-/*
- * Turn a STREAMS message into an mbuf chain.
- */
-static struct mbuf *
-make_mbufs(mp, off)
-    mblk_t *mp;
-    int off;
-{
-    struct mbuf *head, **prevp, *m;
-    int len, space, n;
-    unsigned char *cp, *dp;
-
-    len = msgdsize(mp);
-    if (len == 0)
-       return 0;
-    prevp = &head;
-    space = 0;
-    cp = mp->b_rptr;
-#ifdef __osf__
-    MGETHDR(m, M_DONTWAIT, MT_DATA);
-    m->m_len = 0;
-    space = MHLEN;
-    *prevp = m;
-    prevp = &m->m_next;
-    dp = mtod(m, unsigned char *);
-    len -= space;
-    off = 0;
-#endif
-    for (;;) {
-       while (cp >= mp->b_wptr) {
-           mp = mp->b_cont;
-           if (mp == 0) {
-               *prevp = 0;
-               return head;
-           }
-           cp = mp->b_rptr;
-       }
-       n = mp->b_wptr - cp;
-       if (space == 0) {
-           MGET(m, M_DONTWAIT, MT_DATA);
-           *prevp = m;
-           if (m == 0) {
-               if (head != 0)
-                   m_freem(head);
-               return 0;
-           }
-           if (len + off > 2 * MLEN) {
-#ifdef __osf__
-               MCLGET(m, M_DONTWAIT);
-#else
-               MCLGET(m);
-#endif
-           }
-#ifdef __osf__
-           space = ((m->m_flags & M_EXT) ? MCLBYTES : MLEN);
-#else
-           space = (m->m_off > MMAXOFF? MCLBYTES: MLEN) - off;
-           m->m_off += off;
-#endif
-           m->m_len = 0;
-           len -= space;
-           dp = mtod(m, unsigned char *);
-           off = 0;
-           prevp = &m->m_next;
-       }
-       if (n > space)
-           n = space;
-       bcopy(cp, dp, n);
-       cp += n;
-       dp += n;
-       space -= n;
-       m->m_len += n;
-    }
-}
-
-/*
- * Turn an mbuf chain into a STREAMS message.
- */
-#define ALLOCB_MAX     4096
-
-static mblk_t *
-make_message(m, off)
-    struct mbuf *m;
-    int off;
-{
-    mblk_t *head, **prevp, *mp;
-    int len, space, n, nb;
-    unsigned char *cp, *dp;
-    struct mbuf *nm;
-
-    len = 0;
-    for (nm = m; nm != 0; nm = nm->m_next)
-       len += nm->m_len;
-    prevp = &head;
-    space = 0;
-    cp = mtod(m, unsigned char *);
-    nb = m->m_len;
-    for (;;) {
-       while (nb <= 0) {
-           m = m->m_next;
-           if (m == 0) {
-               *prevp = 0;
-               return head;
-           }
-           cp = mtod(m, unsigned char *);
-           nb = m->m_len;
-       }
-       if (space == 0) {
-           space = len + off;
-           if (space > ALLOCB_MAX)
-               space = ALLOCB_MAX;
-           mp = allocb(space, BPRI_LO);
-           *prevp = mp;
-           if (mp == 0) {
-               if (head != 0)
-                   freemsg(head);
-               return 0;
-           }
-           dp = mp->b_rptr += off;
-           space -= off;
-           len -= space;
-           off = 0;
-           prevp = &mp->b_cont;
-       }
-       n = nb < space? nb: space;
-       bcopy(cp, dp, n);
-       cp += n;
-       dp += n;
-       nb -= n;
-       space -= n;
-       mp->b_wptr = dp;
-    }
-}
-
-/*
- * Digital UNIX doesn't allow for removing ifnet structures
- * from the list.  But then we're not using this as a loadable
- * module anyway, so that's OK.
- *
- * Under SunOS, this should allow the module to be unloaded.
- * Unfortunately, it doesn't seem to detach all the references,
- * so your system may well crash after you unload this module :-(
- */
-#ifndef __osf__
-
-/*
- * Remove an interface from the system.
- * This routine contains magic.
- */
-#include <net/route.h>
-#include <netinet/in_pcb.h>
-#include <netinet/ip_var.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-
-static void
-ppp_if_detach(ifp)
-    struct ifnet *ifp;
-{
-    int s;
-    struct inpcb *pcb;
-    struct ifaddr *ifa;
-    struct in_ifaddr **inap;
-    struct ifnet **ifpp;
-
-    s = splhigh();
-
-    /*
-     * Clear the interface from any routes currently cached in
-     * TCP or UDP protocol control blocks.
-     */
-    for (pcb = tcb.inp_next; pcb != &tcb; pcb = pcb->inp_next)
-       if (pcb->inp_route.ro_rt && pcb->inp_route.ro_rt->rt_ifp == ifp)
-           in_losing(pcb);
-    for (pcb = udb.inp_next; pcb != &udb; pcb = pcb->inp_next)
-       if (pcb->inp_route.ro_rt && pcb->inp_route.ro_rt->rt_ifp == ifp)
-           in_losing(pcb);
-
-    /*
-     * Delete routes through all addresses of the interface.
-     */
-    for (ifa = ifp->if_addrlist; ifa != 0; ifa = ifa->ifa_next) {
-       rtinit(ifa, ifa, SIOCDELRT, RTF_HOST);
-       rtinit(ifa, ifa, SIOCDELRT, 0);
-    }
-
-    /*
-     * Unlink the interface's address(es) from the in_ifaddr list.
-     */
-    for (inap = &in_ifaddr; *inap != 0; ) {
-       if ((*inap)->ia_ifa.ifa_ifp == ifp)
-           *inap = (*inap)->ia_next;
-       else
-           inap = &(*inap)->ia_next;
-    }
-
-    /*
-     * Delete the interface from the ifnet list.
-     */
-    for (ifpp = &ifnet; (*ifpp) != 0; ) {
-       if (*ifpp == ifp)
-           break;
-       ifpp = &(*ifpp)->if_next;
-    }
-    if (*ifpp == 0)
-       printf("couldn't find interface ppp%d in ifnet list\n", ifp->if_unit);
-    else
-       *ifpp = ifp->if_next;
-
-    splx(s);
-}
-
-#endif /* __osf__ */
diff --git a/modules/ppp.c b/modules/ppp.c
deleted file mode 100644 (file)
index f5fb71f..0000000
+++ /dev/null
@@ -1,2486 +0,0 @@
-/*
- * ppp.c - STREAMS multiplexing pseudo-device driver for PPP.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * This file is used under Solaris 2, SVR4, SunOS 4, and Digital UNIX.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-#include <sys/errno.h>
-#ifdef __osf__
-#include <sys/ioctl.h>
-#include <sys/cmn_err.h>
-#define queclass(mp)   ((mp)->b_band & QPCTL)
-#else
-#include <sys/ioccom.h>
-#endif
-#include <sys/time.h>
-#ifdef SVR4
-#include <sys/cmn_err.h>
-#include <sys/conf.h>
-#include <sys/dlpi.h>
-#include <sys/ddi.h>
-#ifdef SOL2
-#include <sys/ksynch.h>
-#include <sys/kstat.h>
-#include <sys/sunddi.h>
-#include <sys/ethernet.h>
-#else
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#endif /* SOL2 */
-#else /* not SVR4 */
-#include <sys/user.h>
-#endif /* SVR4 */
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-/*
- * Modifications marked with #ifdef PRIOQ are for priority queueing of
- * interactive traffic, and are due to Marko Zec <zec@japa.tel.fer.hr>.
- */
-#ifdef PRIOQ
-#endif /* PRIOQ */
-
-#include <netinet/in.h>        /* leave this outside of PRIOQ for htons */
-
-/*
- * The IP module may use this SAP value for IP packets.
- */
-#ifndef ETHERTYPE_IP
-#define ETHERTYPE_IP   0x800
-#endif
-
-#if !defined(ETHERTYPE_IPV6) 
-#define ETHERTYPE_IPV6 0x86dd
-#endif /* !defined(ETHERTYPE_IPV6) */
-
-#if !defined(ETHERTYPE_ALLSAP) && defined(SOL2)
-#define ETHERTYPE_ALLSAP   0
-#endif /* !defined(ETHERTYPE_ALLSAP) && defined(SOL2) */
-
-#if !defined(PPP_ALLSAP) && defined(SOL2)
-#define PPP_ALLSAP  PPP_ALLSTATIONS
-#endif /* !defined(PPP_ALLSAP) && defined(SOL2) */
-
-extern time_t time;
-
-#ifdef SOL2
-/*
- * We use this reader-writer lock to ensure that the lower streams
- * stay connected to the upper streams while the lower-side put and
- * service procedures are running.  Essentially it is an existence
- * lock for the upper stream associated with each lower stream.
- */
-krwlock_t ppp_lower_lock;
-#define LOCK_LOWER_W   rw_enter(&ppp_lower_lock, RW_WRITER)
-#define LOCK_LOWER_R   rw_enter(&ppp_lower_lock, RW_READER)
-#define TRYLOCK_LOWER_R        rw_tryenter(&ppp_lower_lock, RW_READER)
-#define UNLOCK_LOWER   rw_exit(&ppp_lower_lock)
-
-#define MT_ENTER(x)    mutex_enter(x)
-#define MT_EXIT(x)     mutex_exit(x)
-
-/*
- * Notes on multithreaded implementation for Solaris 2:
- *
- * We use an inner perimeter around each queue pair and an outer
- * perimeter around the whole driver.  The inner perimeter is
- * entered exclusively for all entry points (open, close, put,
- * service).  The outer perimeter is entered exclusively for open
- * and close and shared for put and service.  This is all done for
- * us by the streams framework.
- *
- * I used to think that the perimeters were entered for the lower
- * streams' put and service routines as well as for the upper streams'.
- * Because of problems experienced by people, and after reading the
- * documentation more closely, I now don't think that is true.  So we
- * now use ppp_lower_lock to give us an existence guarantee on the
- * upper stream controlling each lower stream.
- *
- * Shared entry to the outer perimeter protects the existence of all
- * the upper streams and their upperstr_t structures, and guarantees
- * that the following fields of any upperstr_t won't change:
- * nextmn, next, nextppa.  It guarantees that the lowerq field of an
- * upperstr_t won't go from non-zero to zero, that the global `ppas'
- * won't change and that the no lower stream will get unlinked.
- *
- * Shared (reader) access to ppa_lower_lock guarantees that no lower
- * stream will be unlinked and that the lowerq field of all upperstr_t
- * structures won't change.
- */
-
-#else /* SOL2 */
-#define LOCK_LOWER_W   0
-#define LOCK_LOWER_R   0
-#define TRYLOCK_LOWER_R        1
-#define UNLOCK_LOWER   0
-#define MT_ENTER(x)    0
-#define MT_EXIT(x)     0
-
-#endif /* SOL2 */
-
-/*
- * Private information; one per upper stream.
- */
-typedef struct upperstr {
-    minor_t mn;                        /* minor device number */
-    struct upperstr *nextmn;   /* next minor device */
-    queue_t *q;                        /* read q associated with this upper stream */
-    int flags;                 /* flag bits, see below */
-    int state;                 /* current DLPI state */
-    int sap;                   /* service access point */
-    int req_sap;               /* which SAP the DLPI client requested */
-    struct upperstr *ppa;      /* control stream for our ppa */
-    struct upperstr *next;     /* next stream for this ppa */
-    uint ioc_id;               /* last ioctl ID for this stream */
-    enum NPmode npmode;                /* what to do with packets on this SAP */
-    unsigned char rblocked;    /* flow control has blocked upper read strm */
-       /* N.B. rblocked is only changed by control stream's put/srv procs */
-    /*
-     * There is exactly one control stream for each PPA.
-     * The following fields are only used for control streams.
-     */
-    int ppa_id;
-    queue_t *lowerq;           /* write queue attached below this PPA */
-    struct upperstr *nextppa;  /* next control stream */
-    int mru;
-    int mtu;
-    struct pppstat stats;      /* statistics */
-    time_t last_sent;          /* time last NP packet sent */
-    time_t last_recv;          /* time last NP packet rcvd */
-#ifdef SOL2
-    kmutex_t stats_lock;       /* lock for stats updates */
-    kstat_t *kstats;           /* stats for netstat */
-#endif /* SOL2 */
-#ifdef LACHTCP
-    int ifflags;
-    char ifname[IFNAMSIZ];
-    struct ifstats ifstats;
-#endif /* LACHTCP */
-} upperstr_t;
-
-/* Values for flags */
-#define US_PRIV                1       /* stream was opened by superuser */
-#define US_CONTROL     2       /* stream is a control stream */
-#define US_BLOCKED     4       /* flow ctrl has blocked lower write stream */
-#define US_LASTMOD     8       /* no PPP modules below us */
-#define US_DBGLOG      0x10    /* log various occurrences */
-#define US_RBLOCKED    0x20    /* flow ctrl has blocked upper read stream */
-
-#if defined(SOL2)
-#if DL_CURRENT_VERSION >= 2
-#define US_PROMISC     0x40    /* stream is promiscuous */
-#endif /* DL_CURRENT_VERSION >= 2 */
-#define US_RAWDATA     0x80    /* raw M_DATA, no DLPI header */
-#endif /* defined(SOL2) */
-
-#ifdef PRIOQ
-static u_char max_band=0;
-static u_char def_band=0;
-
-#define IPPORT_DEFAULT         65535
-
-/*
- * Port priority table
- * Highest priority ports are listed first, lowest are listed last.
- * ICMP & packets using unlisted ports will be treated as "default".
- * If IPPORT_DEFAULT is not listed here, "default" packets will be 
- * assigned lowest priority.
- * Each line should be terminated with "0".
- * Line containing only "0" marks the end of the list.
- */
-
-static u_short prioq_table[]= {
-    113, 53, 0,
-    22, 23, 513, 517, 518, 0,
-    514, 21, 79, 111, 0,
-    25, 109, 110, 0,
-    IPPORT_DEFAULT, 0,
-    20, 70, 80, 8001, 8008, 8080, 0, /* 8001,8008,8080 - common proxy ports */
-0 };
-
-#endif /* PRIOQ */
-
-
-static upperstr_t *minor_devs = NULL;
-static upperstr_t *ppas = NULL;
-
-#ifdef SVR4
-static int pppopen(queue_t *, dev_t *, int, int, cred_t *);
-static int pppclose(queue_t *, int, cred_t *);
-#else
-static int pppopen(queue_t *, int, int, int);
-static int pppclose(queue_t *, int);
-#endif /* SVR4 */
-static int pppurput(queue_t *, mblk_t *);
-static int pppuwput(queue_t *, mblk_t *);
-static int pppursrv(queue_t *);
-static int pppuwsrv(queue_t *);
-static int ppplrput(queue_t *, mblk_t *);
-static int ppplwput(queue_t *, mblk_t *);
-static int ppplrsrv(queue_t *);
-static int ppplwsrv(queue_t *);
-#ifndef NO_DLPI
-static void dlpi_request(queue_t *, mblk_t *, upperstr_t *);
-static void dlpi_error(queue_t *, upperstr_t *, int, int, int);
-static void dlpi_ok(queue_t *, int);
-#endif
-static int send_data(mblk_t *, upperstr_t *);
-static void new_ppa(queue_t *, mblk_t *);
-static void attach_ppa(queue_t *, mblk_t *);
-static void detach_ppa(queue_t *, mblk_t *);
-static void detach_lower(queue_t *, mblk_t *);
-static void debug_dump(queue_t *, mblk_t *);
-static upperstr_t *find_dest(upperstr_t *, int);
-#if defined(SOL2)
-static upperstr_t *find_promisc(upperstr_t *, int);
-static mblk_t *prepend_ether(upperstr_t *, mblk_t *, int);
-static mblk_t *prepend_udind(upperstr_t *, mblk_t *, int);
-static void promisc_sendup(upperstr_t *, mblk_t *, int, int);
-#endif /* defined(SOL2) */
-static int putctl2(queue_t *, int, int, int);
-static int putctl4(queue_t *, int, int, int);
-static int pass_packet(upperstr_t *ppa, mblk_t *mp, int outbound);
-#ifdef FILTER_PACKETS
-static int ip_hard_filter(upperstr_t *ppa, mblk_t *mp, int outbound);
-#endif /* FILTER_PACKETS */
-
-#define PPP_ID 0xb1a6
-static struct module_info ppp_info = {
-#ifdef PRIOQ
-    PPP_ID, "ppp", 0, 512, 512, 384
-#else
-    PPP_ID, "ppp", 0, 512, 512, 128
-#endif /* PRIOQ */
-};
-
-static struct qinit pppurint = {
-    pppurput, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
-};
-
-static struct qinit pppuwint = {
-    pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-static struct qinit ppplrint = {
-    ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-static struct qinit ppplwint = {
-    ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-#ifdef LACHTCP
-extern struct ifstats *ifstats;
-int pppdevflag = 0;
-#endif
-
-struct streamtab pppinfo = {
-    &pppurint, &pppuwint,
-    &ppplrint, &ppplwint
-};
-
-int ppp_count;
-
-/*
- * How we maintain statistics.
- */
-#ifdef SOL2
-#define INCR_IPACKETS(ppa)                             \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++; \
-       }
-#define INCR_IERRORS(ppa)                              \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++; \
-       }
-#define INCR_OPACKETS(ppa)                             \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++; \
-       }
-#define INCR_OERRORS(ppa)                              \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++; \
-       }
-#endif
-
-#ifdef LACHTCP
-#define INCR_IPACKETS(ppa)     ppa->ifstats.ifs_ipackets++;
-#define INCR_IERRORS(ppa)      ppa->ifstats.ifs_ierrors++;
-#define INCR_OPACKETS(ppa)     ppa->ifstats.ifs_opackets++;
-#define INCR_OERRORS(ppa)      ppa->ifstats.ifs_oerrors++;
-#endif
-
-/*
- * STREAMS driver entry points.
- */
-static int
-#ifdef SVR4
-pppopen(q, devp, oflag, sflag, credp)
-    queue_t *q;
-    dev_t *devp;
-    int oflag, sflag;
-    cred_t *credp;
-#else
-pppopen(q, dev, oflag, sflag)
-    queue_t *q;
-    int dev;                   /* really dev_t */
-    int oflag, sflag;
-#endif
-{
-    upperstr_t *up;
-    upperstr_t **prevp;
-    minor_t mn;
-#ifdef PRIOQ
-    u_short *ptr;
-    u_char new_band;
-#endif /* PRIOQ */
-
-    if (q->q_ptr)
-       DRV_OPEN_OK(dev);       /* device is already open */
-
-#ifdef PRIOQ
-    /* Calculate max_bband & def_band from definitions in prioq.h
-       This colud be done at some more approtiate time (less often)
-       but this way it works well so I'll just leave it here */
-
-    max_band = 1;
-    def_band = 0;
-    ptr = prioq_table;
-    while (*ptr) {
-        new_band = 1;
-        while (*ptr)
-           if (*ptr++ == IPPORT_DEFAULT) {
-               new_band = 0;
-               def_band = max_band;
-           }
-        max_band += new_band;
-        ptr++;
-    }
-    if (def_band)
-        def_band = max_band - def_band;
-    --max_band;
-#endif /* PRIOQ */
-
-    if (sflag == CLONEOPEN) {
-       mn = 0;
-       for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
-           if (up->mn != mn)
-               break;
-           ++mn;
-       }
-    } else {
-#ifdef SVR4
-       mn = getminor(*devp);
-#else
-       mn = minor(dev);
-#endif
-       for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
-           if (up->mn >= mn)
-               break;
-       }
-       if (up->mn == mn) {
-           /* this can't happen */
-           q->q_ptr = WR(q)->q_ptr = (caddr_t) up;
-           DRV_OPEN_OK(dev);
-       }
-    }
-
-    /*
-     * Construct a new minor node.
-     */
-    up = (upperstr_t *) ALLOC_SLEEP(sizeof(upperstr_t));
-    bzero((caddr_t) up, sizeof(upperstr_t));
-    if (up == 0) {
-       DPRINT("pppopen: out of kernel memory\n");
-       OPEN_ERROR(ENXIO);
-    }
-    up->nextmn = *prevp;
-    *prevp = up;
-    up->mn = mn;
-#ifdef SVR4
-    *devp = makedevice(getmajor(*devp), mn);
-#endif
-    up->q = q;
-    if (NOTSUSER() == 0)
-       up->flags |= US_PRIV;
-#ifndef NO_DLPI
-    up->state = DL_UNATTACHED;
-#endif
-#ifdef LACHTCP
-    up->ifflags = IFF_UP | IFF_POINTOPOINT;
-#endif
-    up->sap = -1;
-    up->last_sent = up->last_recv = time;
-    up->npmode = NPMODE_DROP;
-    q->q_ptr = (caddr_t) up;
-    WR(q)->q_ptr = (caddr_t) up;
-    noenable(WR(q));
-#ifdef SOL2
-    mutex_init(&up->stats_lock, NULL, MUTEX_DRIVER, NULL);
-#endif
-    ++ppp_count;
-
-    qprocson(q);
-    DRV_OPEN_OK(makedev(major(dev), mn));
-}
-
-static int
-#ifdef SVR4
-pppclose(q, flag, credp)
-    queue_t *q;
-    int flag;
-    cred_t *credp;
-#else
-pppclose(q, flag)
-    queue_t *q;
-    int flag;
-#endif
-{
-    upperstr_t *up, **upp;
-    upperstr_t *as, *asnext;
-    upperstr_t **prevp;
-
-    qprocsoff(q);
-
-    up = (upperstr_t *) q->q_ptr;
-    if (up == 0) {
-       DPRINT("pppclose: q_ptr = 0\n");
-       return 0;
-    }
-    if (up->flags & US_DBGLOG)
-       DPRINT2("ppp/%d: close, flags=%x\n", up->mn, up->flags);
-    if (up->flags & US_CONTROL) {
-#ifdef LACHTCP
-       struct ifstats *ifp, *pifp;
-#endif
-       if (up->lowerq != 0) {
-           /* Gack! the lower stream should have be unlinked earlier! */
-           DPRINT1("ppp%d: lower stream still connected on close?\n",
-                   up->mn);
-           LOCK_LOWER_W;
-           up->lowerq->q_ptr = 0;
-           RD(up->lowerq)->q_ptr = 0;
-           up->lowerq = 0;
-           UNLOCK_LOWER;
-       }
-
-       /*
-        * This stream represents a PPA:
-        * For all streams attached to the PPA, clear their
-        * references to this PPA.
-        * Then remove this PPA from the list of PPAs.
-        */
-       for (as = up->next; as != 0; as = asnext) {
-           asnext = as->next;
-           as->next = 0;
-           as->ppa = 0;
-           if (as->flags & US_BLOCKED) {
-               as->flags &= ~US_BLOCKED;
-               flushq(WR(as->q), FLUSHDATA);
-           }
-       }
-       for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
-           if (*upp == up) {
-               *upp = up->nextppa;
-               break;
-           }
-#ifdef LACHTCP
-       /* Remove the statistics from the active list.  */
-       for (ifp = ifstats, pifp = 0; ifp; ifp = ifp->ifs_next) {
-           if (ifp == &up->ifstats) {
-               if (pifp)
-                   pifp->ifs_next = ifp->ifs_next;
-               else
-                   ifstats = ifp->ifs_next;
-               break;
-           }
-           pifp = ifp;
-       }
-#endif
-    } else {
-       /*
-        * If this stream is attached to a PPA,
-        * remove it from the PPA's list.
-        */
-       if ((as = up->ppa) != 0) {
-           for (; as->next != 0; as = as->next)
-               if (as->next == up) {
-                   as->next = up->next;
-                   break;
-               }
-       }
-    }
-
-#ifdef SOL2
-    if (up->kstats)
-       kstat_delete(up->kstats);
-    mutex_destroy(&up->stats_lock);
-#endif
-
-    q->q_ptr = NULL;
-    WR(q)->q_ptr = NULL;
-
-    for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
-       if (*prevp == up) {
-           *prevp = up->nextmn;
-           break;
-       }
-    }
-    FREE(up, sizeof(upperstr_t));
-    --ppp_count;
-
-    return 0;
-}
-
-/*
- * A message from on high.  We do one of three things:
- *     - qreply()
- *     - put the message on the lower write stream
- *     - queue it for our service routine
- */
-static int
-pppuwput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *ppa, *nps;
-    struct iocblk *iop;
-    struct linkblk *lb;
-#ifdef LACHTCP
-    struct ifreq *ifr;
-    int i;
-#endif
-    queue_t *lq;
-    int error, n, sap;
-    mblk_t *mq;
-    struct ppp_idle *pip;
-#ifdef PRIOQ
-    queue_t *tlq;
-#endif /* PRIOQ */
-#ifdef NO_DLPI
-    upperstr_t *os;
-#endif
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppuwput: q_ptr = 0!\n");
-       return 0;
-    }
-    if (mp == 0) {
-       DPRINT1("pppuwput/%d: mp = 0!\n", us->mn);
-       return 0;
-    }
-    if (mp->b_datap == 0) {
-       DPRINT1("pppuwput/%d: mp->b_datap = 0!\n", us->mn);
-       return 0;
-    }
-    switch (mp->b_datap->db_type) {
-#ifndef NO_DLPI
-    case M_PCPROTO:
-    case M_PROTO:
-       dlpi_request(q, mp, us);
-       break;
-#endif /* NO_DLPI */
-
-    case M_DATA:
-       if (us->flags & US_DBGLOG)
-           DPRINT3("ppp/%d: uwput M_DATA len=%d flags=%x\n",
-                   us->mn, msgdsize(mp), us->flags);
-       if (us->ppa == 0 || msgdsize(mp) > us->ppa->mtu + PPP_HDRLEN
-#ifndef NO_DLPI
-           || (us->flags & US_CONTROL) == 0
-#endif /* NO_DLPI */
-           ) {
-           DPRINT1("pppuwput: junk data len=%d\n", msgdsize(mp));
-           freemsg(mp);
-           break;
-       }
-#ifdef NO_DLPI
-       if ((us->flags & US_CONTROL) == 0 && !pass_packet(us, mp, 1))
-           break;
-#endif
-       if (!send_data(mp, us))
-           putq(q, mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       if (us->flags & US_DBGLOG)
-           DPRINT3("ppp/%d: ioctl %x count=%d\n",
-                   us->mn, iop->ioc_cmd, iop->ioc_count);
-       switch (iop->ioc_cmd) {
-#if defined(SOL2)
-       case DLIOCRAW:      /* raw M_DATA mode */
-           us->flags |= US_RAWDATA;
-           error = 0;
-           break;
-#endif /* defined(SOL2) */
-       case I_LINK:
-           if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_LINK b_cont = 0!\n", us->mn);
-               break;
-           }
-           lb = (struct linkblk *) mp->b_cont->b_rptr;
-           lq = lb->l_qbot;
-           if (lq == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_LINK l_qbot = 0!\n", us->mn);
-               break;
-           }
-           LOCK_LOWER_W;
-           us->lowerq = lq;
-           lq->q_ptr = (caddr_t) q;
-           RD(lq)->q_ptr = (caddr_t) us->q;
-           UNLOCK_LOWER;
-           iop->ioc_count = 0;
-           error = 0;
-           us->flags &= ~US_LASTMOD;
-           /* Unblock upper streams which now feed this lower stream. */
-           qenable(q);
-           /* Send useful information down to the modules which
-              are now linked below us. */
-           putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
-           putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
-           putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
-#ifdef PRIOQ
-            /* Lower tty driver's queue hiwat/lowat from default 4096/128
-               to 256/128 since we don't want queueing of data on
-               output to physical device */
-
-            freezestr(lq);
-            for (tlq = lq; tlq->q_next != NULL; tlq = tlq->q_next)
-               ;
-            strqset(tlq, QHIWAT, 0, 256);
-            strqset(tlq, QLOWAT, 0, 128);
-            unfreezestr(lq);
-#endif /* PRIOQ */
-           break;
-
-       case I_UNLINK:
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_UNLINK b_cont = 0!\n", us->mn);
-               break;
-           }
-           lb = (struct linkblk *) mp->b_cont->b_rptr;
-#if DEBUG
-           if (us->lowerq != lb->l_qbot) {
-               DPRINT2("ppp unlink: lowerq=%x qbot=%x\n",
-                       us->lowerq, lb->l_qbot);
-               break;
-           }
-#endif
-           iop->ioc_count = 0;
-           qwriter(q, mp, detach_lower, PERIM_OUTER);
-           error = -1;
-           break;
-
-       case PPPIO_NEWPPA:
-           if (us->flags & US_CONTROL)
-               break;
-           if ((us->flags & US_PRIV) == 0) {
-               error = EPERM;
-               break;
-           }
-           /* Arrange to return an int */
-           if ((mq = mp->b_cont) == 0
-               || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
-               mq = allocb(sizeof(int), BPRI_HI);
-               if (mq == 0) {
-                   error = ENOSR;
-                   break;
-               }
-               if (mp->b_cont != 0)
-                   freemsg(mp->b_cont);
-               mp->b_cont = mq;
-               mq->b_cont = 0;
-           }
-           iop->ioc_count = sizeof(int);
-           mq->b_wptr = mq->b_rptr + sizeof(int);
-           qwriter(q, mp, new_ppa, PERIM_OUTER);
-           error = -1;
-           break;
-
-       case PPPIO_ATTACH:
-           /* like dlpi_attach, for programs which can't write to
-              the stream (like pppstats) */
-           if (iop->ioc_count != sizeof(int) || us->ppa != 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_ATTACH b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
-               if (ppa->ppa_id == n)
-                   break;
-           if (ppa == 0)
-               break;
-           us->ppa = ppa;
-           iop->ioc_count = 0;
-           qwriter(q, mp, attach_ppa, PERIM_OUTER);
-           error = -1;
-           break;
-
-#ifdef NO_DLPI
-       case PPPIO_BIND:
-           /* Attach to a given SAP. */
-           if (iop->ioc_count != sizeof(int) || us->ppa == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_BIND b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           /* n must be a valid PPP network protocol number. */
-           if (n < 0x21 || n > 0x3fff || (n & 0x101) != 1)
-               break;
-           /* check that no other stream is bound to this sap already. */
-           for (os = us->ppa; os != 0; os = os->next)
-               if (os->sap == n)
-                   break;
-           if (os != 0)
-               break;
-           us->sap = n;
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-#endif /* NO_DLPI */
-
-       case PPPIO_MRU:
-           if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_MRU b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n <= 0 || n > PPP_MAXMRU)
-               break;
-           if (n < PPP_MRU)
-               n = PPP_MRU;
-           us->mru = n;
-           if (us->lowerq)
-               putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_MTU:
-           if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_MTU b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n <= 0 || n > PPP_MAXMTU)
-               break;
-           us->mtu = n;
-#ifdef LACHTCP
-           /* The MTU reported in netstat, not used as IP max packet size! */
-           us->ifstats.ifs_mtu = n;
-#endif
-           if (us->lowerq)
-               putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_LASTMOD:
-           us->flags |= US_LASTMOD;
-           error = 0;
-           break;
-
-       case PPPIO_DEBUG:
-           if (iop->ioc_count != sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_DEBUG b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
-               qwriter(q, NULL, debug_dump, PERIM_OUTER);
-               iop->ioc_count = 0;
-               error = -1;
-           } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) {
-               DPRINT1("ppp/%d: debug log enabled\n", us->mn);
-               us->flags |= US_DBGLOG;
-               iop->ioc_count = 0;
-               error = 0;
-           } else {
-               if (us->ppa == 0 || us->ppa->lowerq == 0)
-                   break;
-               putnext(us->ppa->lowerq, mp);
-               error = -1;
-           }
-           break;
-
-       case PPPIO_NPMODE:
-           if (iop->ioc_count != 2 * sizeof(int))
-               break;
-           if ((us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_NPMODE b_cont = 0!\n", us->mn);
-               break;
-           }
-           sap = ((int *)mp->b_cont->b_rptr)[0];
-           for (nps = us->next; nps != 0; nps = nps->next) {
-               if (us->flags & US_DBGLOG)
-                   DPRINT2("us = 0x%x, us->next->sap = 0x%x\n", nps, nps->sap);
-               if (nps->sap == sap)
-                   break;
-           }
-           if (nps == 0) {
-               if (us->flags & US_DBGLOG)
-                   DPRINT2("ppp/%d: no stream for sap %x\n", us->mn, sap);
-               break;
-           }
-           /* XXX possibly should use qwriter here */
-           nps->npmode = (enum NPmode) ((int *)mp->b_cont->b_rptr)[1];
-           if (nps->npmode != NPMODE_QUEUE && (nps->flags & US_BLOCKED) != 0)
-               qenable(WR(nps->q));
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_GIDLE:
-           if ((ppa = us->ppa) == 0)
-               break;
-           mq = allocb(sizeof(struct ppp_idle), BPRI_HI);
-           if (mq == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = mq;
-           mq->b_cont = 0;
-           pip = (struct ppp_idle *) mq->b_wptr;
-           pip->xmit_idle = time - ppa->last_sent;
-           pip->recv_idle = time - ppa->last_recv;
-           mq->b_wptr += sizeof(struct ppp_idle);
-           iop->ioc_count = sizeof(struct ppp_idle);
-           error = 0;
-           break;
-
-#ifdef LACHTCP
-       case SIOCSIFNAME:
-           /* Sent from IP down to us.  Attach the ifstats structure.  */
-           if (iop->ioc_count != sizeof(struct ifreq) || us->ppa == 0)
-               break;
-           ifr = (struct ifreq *)mp->b_cont->b_rptr;
-           /* Find the unit number in the interface name.  */
-           for (i = 0; i < IFNAMSIZ; i++) {
-               if (ifr->ifr_name[i] == 0 ||
-                   (ifr->ifr_name[i] >= '0' &&
-                    ifr->ifr_name[i] <= '9'))
-                   break;
-               else
-                   us->ifname[i] = ifr->ifr_name[i];
-           }
-           us->ifname[i] = 0;
-
-           /* Convert the unit number to binary.  */
-           for (n = 0; i < IFNAMSIZ; i++) {
-               if (ifr->ifr_name[i] == 0) {
-                   break;
-               }
-               else {
-                   n = n * 10 + ifr->ifr_name[i] - '0';
-               }
-           }
-
-           /* Verify the ppa.  */
-           if (us->ppa->ppa_id != n)
-               break;
-           ppa = us->ppa;
-
-           /* Set up the netstat block.  */
-           strncpy (ppa->ifname, us->ifname, IFNAMSIZ);
-
-           ppa->ifstats.ifs_name = ppa->ifname;
-           ppa->ifstats.ifs_unit = n;
-           ppa->ifstats.ifs_active = us->state != DL_UNBOUND;
-           ppa->ifstats.ifs_mtu = ppa->mtu;
-
-           /* Link in statistics used by netstat.  */
-           ppa->ifstats.ifs_next = ifstats;
-           ifstats = &ppa->ifstats;
-
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case SIOCGIFFLAGS:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           ((struct iocblk_in *)iop)->ioc_ifflags = us->ifflags;
-           error = 0;
-           break;
-
-       case SIOCSIFFLAGS:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           us->ifflags = ((struct iocblk_in *)iop)->ioc_ifflags;
-           error = 0;
-           break;
-
-       case SIOCSIFADDR:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           us->ifflags |= IFF_RUNNING;
-           ((struct iocblk_in *)iop)->ioc_ifflags |= IFF_RUNNING;
-           error = 0;
-           break;
-
-       case SIOCSIFMTU:
-           /*
-            * Vanilla SVR4 systems don't handle SIOCSIFMTU, rather
-            * they take the MTU from the DL_INFO_ACK we sent in response
-            * to their DL_INFO_REQ.  Fortunately, they will update the
-            * MTU if we send an unsolicited DL_INFO_ACK up.
-            */
-           if ((mq = allocb(sizeof(dl_info_req_t), BPRI_HI)) == 0)
-               break;          /* should do bufcall */
-           ((union DL_primitives *)mq->b_rptr)->dl_primitive = DL_INFO_REQ;
-           mq->b_wptr = mq->b_rptr + sizeof(dl_info_req_t);
-           dlpi_request(q, mq, us);
-           error = 0;
-           break;
-
-       case SIOCGIFNETMASK:
-       case SIOCSIFNETMASK:
-       case SIOCGIFADDR:
-       case SIOCGIFDSTADDR:
-       case SIOCSIFDSTADDR:
-       case SIOCGIFMETRIC:
-           error = 0;
-           break;
-#endif /* LACHTCP */
-
-       default:
-           if (us->ppa == 0 || us->ppa->lowerq == 0)
-               break;
-           us->ioc_id = iop->ioc_id;
-           error = -1;
-           switch (iop->ioc_cmd) {
-           case PPPIO_GETSTAT:
-           case PPPIO_GETCSTAT:
-               if (us->flags & US_LASTMOD) {
-                   error = EINVAL;
-                   break;
-               }
-               putnext(us->ppa->lowerq, mp);
-               break;
-           default:
-               if (us->flags & US_PRIV)
-                   putnext(us->ppa->lowerq, mp);
-               else {
-                   DPRINT1("ppp ioctl %x rejected\n", iop->ioc_cmd);
-                   error = EPERM;
-               }
-               break;
-           }
-           break;
-       }
-
-       if (error > 0) {
-           iop->ioc_error = error;
-           mp->b_datap->db_type = M_IOCNAK;
-           qreply(q, mp);
-       } else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_FLUSH:
-       if (us->flags & US_DBGLOG)
-           DPRINT2("ppp/%d: flush %x\n", us->mn, *mp->b_rptr);
-       if (*mp->b_rptr & FLUSHW)
-           flushq(q, FLUSHDATA);
-       if (*mp->b_rptr & FLUSHR) {
-           *mp->b_rptr &= ~FLUSHW;
-           qreply(q, mp);
-       } else
-           freemsg(mp);
-       break;
-
-    default:
-       freemsg(mp);
-       break;
-    }
-    return 0;
-}
-
-#ifndef NO_DLPI
-static void
-dlpi_request(q, mp, us)
-    queue_t *q;
-    mblk_t *mp;
-    upperstr_t *us;
-{
-    union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
-    int size = mp->b_wptr - mp->b_rptr;
-    mblk_t *reply, *np;
-    upperstr_t *ppa, *os;
-    int sap, len;
-    dl_info_ack_t *info;
-    dl_bind_ack_t *ackp;
-#if DL_CURRENT_VERSION >= 2
-    dl_phys_addr_ack_t *paddrack;
-    static struct ether_addr eaddr = {0};
-#endif
-
-    if (us->flags & US_DBGLOG)
-       DPRINT3("ppp/%d: dlpi prim %x len=%d\n", us->mn,
-               d->dl_primitive, size);
-    switch (d->dl_primitive) {
-    case DL_INFO_REQ:
-       if (size < sizeof(dl_info_req_t))
-           goto badprim;
-       if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       reply->b_datap->db_type = M_PCPROTO;
-       info = (dl_info_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_info_ack_t);
-       bzero((caddr_t) info, sizeof(dl_info_ack_t));
-       info->dl_primitive = DL_INFO_ACK;
-       info->dl_max_sdu = us->ppa? us->ppa->mtu: PPP_MAXMTU;
-       info->dl_min_sdu = 1;
-       info->dl_addr_length = sizeof(uint);
-       info->dl_mac_type = DL_ETHER;   /* a bigger lie */
-       info->dl_current_state = us->state;
-       info->dl_service_mode = DL_CLDLS;
-       info->dl_provider_style = DL_STYLE2;
-#if DL_CURRENT_VERSION >= 2
-       info->dl_sap_length = sizeof(uint);
-       info->dl_version = DL_CURRENT_VERSION;
-#endif
-       qreply(q, reply);
-       break;
-
-    case DL_ATTACH_REQ:
-       if (size < sizeof(dl_attach_req_t))
-           goto badprim;
-       if (us->state != DL_UNATTACHED || us->ppa != 0) {
-           dlpi_error(q, us, DL_ATTACH_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
-           if (ppa->ppa_id == d->attach_req.dl_ppa)
-               break;
-       if (ppa == 0) {
-           dlpi_error(q, us, DL_ATTACH_REQ, DL_BADPPA, 0);
-           break;
-       }
-       us->ppa = ppa;
-       qwriter(q, mp, attach_ppa, PERIM_OUTER);
-       return;
-
-    case DL_DETACH_REQ:
-       if (size < sizeof(dl_detach_req_t))
-           goto badprim;
-       if (us->state != DL_UNBOUND || us->ppa == 0) {
-           dlpi_error(q, us, DL_DETACH_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       qwriter(q, mp, detach_ppa, PERIM_OUTER);
-       return;
-
-    case DL_BIND_REQ:
-       if (size < sizeof(dl_bind_req_t))
-           goto badprim;
-       if (us->state != DL_UNBOUND || us->ppa == 0) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-#if 0
-       /* apparently this test fails (unnecessarily?) on some systems */
-       if (d->bind_req.dl_service_mode != DL_CLDLS) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_UNSUPPORTED, 0);
-           break;
-       }
-#endif
-
-       /* saps must be valid PPP network protocol numbers,
-          except that we accept ETHERTYPE_IP in place of PPP_IP. */
-       sap = d->bind_req.dl_sap;
-       us->req_sap = sap;
-
-#if defined(SOL2)
-       if (us->flags & US_DBGLOG)
-           DPRINT2("DL_BIND_REQ: ip gives sap = 0x%x, us = 0x%x", sap, us);
-
-       if (sap == ETHERTYPE_IP)            /* normal IFF_IPV4 */
-           sap = PPP_IP;
-       else if (sap == ETHERTYPE_IPV6)     /* when IFF_IPV6 is set */
-           sap = PPP_IPV6;
-       else if (sap == ETHERTYPE_ALLSAP)   /* snoop gives sap of 0 */
-           sap = PPP_ALLSAP;
-       else {
-           DPRINT2("DL_BIND_REQ: unrecognized sap = 0x%x, us = 0x%x", sap, us);
-           dlpi_error(q, us, DL_BIND_REQ, DL_BADADDR, 0);
-           break;
-       }
-#else
-       if (sap == ETHERTYPE_IP)
-           sap = PPP_IP;
-       if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_BADADDR, 0);
-           break;
-       }
-#endif /* defined(SOL2) */
-
-       /* check that no other stream is bound to this sap already. */
-       for (os = us->ppa; os != 0; os = os->next)
-           if (os->sap == sap)
-               break;
-       if (os != 0) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_NOADDR, 0);
-           break;
-       }
-
-       us->sap = sap;
-       us->state = DL_IDLE;
-
-       if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(uint),
-                           BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       ackp = (dl_bind_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(uint);
-       reply->b_datap->db_type = M_PCPROTO;
-       bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
-       ackp->dl_primitive = DL_BIND_ACK;
-       ackp->dl_sap = sap;
-       ackp->dl_addr_length = sizeof(uint);
-       ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
-       *(uint *)(ackp+1) = sap;
-       qreply(q, reply);
-       break;
-
-    case DL_UNBIND_REQ:
-       if (size < sizeof(dl_unbind_req_t))
-           goto badprim;
-       if (us->state != DL_IDLE) {
-           dlpi_error(q, us, DL_UNBIND_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       us->sap = -1;
-       us->state = DL_UNBOUND;
-#ifdef LACHTCP
-       us->ppa->ifstats.ifs_active = 0;
-#endif
-       dlpi_ok(q, DL_UNBIND_REQ);
-       break;
-
-    case DL_UNITDATA_REQ:
-       if (size < sizeof(dl_unitdata_req_t))
-           goto badprim;
-       if (us->state != DL_IDLE) {
-           dlpi_error(q, us, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       if ((ppa = us->ppa) == 0) {
-           cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
-           break;
-       }
-       len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
-       if (len > ppa->mtu) {
-           DPRINT2("dlpi data too large (%d > %d)\n", len, ppa->mtu);
-           break;
-       }
-
-#if defined(SOL2)
-       /*
-        * Should there be any promiscuous stream(s), send the data
-        * up for each promiscuous stream that we recognize.
-        */
-       if (mp->b_cont)
-           promisc_sendup(ppa, mp->b_cont, us->sap, 0);
-#endif /* defined(SOL2) */
-
-       mp->b_band = 0;
-#ifdef PRIOQ
-        /* Extract s_port & d_port from IP-packet, the code is a bit
-           dirty here, but so am I, too... */
-        if (mp->b_datap->db_type == M_PROTO && us->sap == PPP_IP
-           && mp->b_cont != 0) {
-           u_char *bb, *tlh;
-           int iphlen, len;
-           u_short *ptr;
-           u_char band_unset, cur_band, syn;
-           u_short s_port, d_port;
-
-            bb = mp->b_cont->b_rptr; /* bb points to IP-header*/
-           len = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
-            syn = 0;
-           s_port = IPPORT_DEFAULT;
-           d_port = IPPORT_DEFAULT;
-           if (len >= 20) {    /* 20 = minimum length of IP header */
-               iphlen = (bb[0] & 0x0f) * 4;
-               tlh = bb + iphlen;
-               len -= iphlen;
-               switch (bb[9]) {
-               case IPPROTO_TCP:
-                   if (len >= 20) {          /* min length of TCP header */
-                       s_port = (tlh[0] << 8) + tlh[1];
-                       d_port = (tlh[2] << 8) + tlh[3];
-                       syn = tlh[13] & 0x02;
-                   }
-                   break;
-               case IPPROTO_UDP:
-                   if (len >= 8) {           /* min length of UDP header */
-                       s_port = (tlh[0] << 8) + tlh[1];
-                       d_port = (tlh[2] << 8) + tlh[3];
-                   }
-                   break;
-               }
-           }
-
-            /*
-            * Now calculate b_band for this packet from the
-            * port-priority table.
-            */
-            ptr = prioq_table;
-            cur_band = max_band;
-            band_unset = 1;
-            while (*ptr) {
-                while (*ptr && band_unset)
-                    if (s_port == *ptr || d_port == *ptr++) {
-                        mp->b_band = cur_band;
-                        band_unset = 0;
-                        break;
-                   }
-                ptr++;
-                cur_band--;
-           }
-            if (band_unset)
-               mp->b_band = def_band;
-            /* It may be usable to urge SYN packets a bit */
-            if (syn)
-               mp->b_band++;
-       }
-#endif /* PRIOQ */
-       /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
-       if (mp->b_datap->db_ref > 1) {
-           np = allocb(PPP_HDRLEN, BPRI_HI);
-           if (np == 0)
-               break;          /* gak! */
-           np->b_cont = mp->b_cont;
-           mp->b_cont = 0;
-           freeb(mp);
-           mp = np;
-       } else
-           mp->b_datap->db_type = M_DATA;
-       /* XXX should use dl_dest_addr_offset/length here,
-          but we would have to translate ETHERTYPE_IP -> PPP_IP */
-       mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
-       mp->b_rptr[0] = PPP_ALLSTATIONS;
-       mp->b_rptr[1] = PPP_UI;
-       mp->b_rptr[2] = us->sap >> 8;
-       mp->b_rptr[3] = us->sap;
-       if (pass_packet(us, mp, 1)) {
-           if (!send_data(mp, us))
-               putq(q, mp);
-       }
-       return;
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_PHYS_ADDR_REQ:
-       if (size < sizeof(dl_phys_addr_req_t))
-           goto badprim;
-
-       /*
-        * Don't check state because ifconfig sends this one down too
-        */
-
-       if ((reply = allocb(sizeof(dl_phys_addr_ack_t)+ETHERADDRL, 
-                       BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       reply->b_datap->db_type = M_PCPROTO;
-       paddrack = (dl_phys_addr_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_phys_addr_ack_t);
-       bzero((caddr_t) paddrack, sizeof(dl_phys_addr_ack_t)+ETHERADDRL);
-       paddrack->dl_primitive = DL_PHYS_ADDR_ACK;
-       paddrack->dl_addr_length = ETHERADDRL;
-       paddrack->dl_addr_offset = sizeof(dl_phys_addr_ack_t);
-       bcopy(&eaddr, reply->b_wptr, ETHERADDRL);
-       reply->b_wptr += ETHERADDRL;
-       qreply(q, reply);
-       break;
-
-#if defined(SOL2)
-    case DL_PROMISCON_REQ:
-       if (size < sizeof(dl_promiscon_req_t))
-           goto badprim;
-       us->flags |= US_PROMISC;
-       dlpi_ok(q, DL_PROMISCON_REQ);
-       break;
-
-    case DL_PROMISCOFF_REQ:
-       if (size < sizeof(dl_promiscoff_req_t))
-           goto badprim;
-       us->flags &= ~US_PROMISC;
-       dlpi_ok(q, DL_PROMISCOFF_REQ);
-       break;
-#else
-    case DL_PROMISCON_REQ:         /* fall thru */
-    case DL_PROMISCOFF_REQ:        /* fall thru */
-#endif /* defined(SOL2) */
-#endif /* DL_CURRENT_VERSION >= 2 */
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_SET_PHYS_ADDR_REQ:
-    case DL_SUBS_BIND_REQ:
-    case DL_SUBS_UNBIND_REQ:
-    case DL_ENABMULTI_REQ:
-    case DL_DISABMULTI_REQ:
-    case DL_XID_REQ:
-    case DL_TEST_REQ:
-    case DL_REPLY_UPDATE_REQ:
-    case DL_REPLY_REQ:
-    case DL_DATA_ACK_REQ:
-#endif
-    case DL_CONNECT_REQ:
-    case DL_TOKEN_REQ:
-       dlpi_error(q, us, d->dl_primitive, DL_NOTSUPPORTED, 0);
-       break;
-
-    case DL_CONNECT_RES:
-    case DL_DISCONNECT_REQ:
-    case DL_RESET_REQ:
-    case DL_RESET_RES:
-       dlpi_error(q, us, d->dl_primitive, DL_OUTSTATE, 0);
-       break;
-
-    case DL_UDQOS_REQ:
-       dlpi_error(q, us, d->dl_primitive, DL_BADQOSTYPE, 0);
-       break;
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_TEST_RES:
-    case DL_XID_RES:
-       break;
-#endif
-
-    default:
-       cmn_err(CE_CONT, "ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
-       /* fall through */
-    badprim:
-       dlpi_error(q, us, d->dl_primitive, DL_BADPRIM, 0);
-       break;
-    }
-    freemsg(mp);
-}
-
-static void
-dlpi_error(q, us, prim, err, uerr)
-    queue_t *q;
-    upperstr_t *us;
-    int prim, err, uerr;
-{
-    mblk_t *reply;
-    dl_error_ack_t *errp;
-
-    if (us->flags & US_DBGLOG)
-        DPRINT3("ppp/%d: dlpi error, prim=%x, err=%x\n", us->mn, prim, err);
-    reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
-    if (reply == 0)
-       return;                 /* XXX should do bufcall */
-    reply->b_datap->db_type = M_PCPROTO;
-    errp = (dl_error_ack_t *) reply->b_wptr;
-    reply->b_wptr += sizeof(dl_error_ack_t);
-    errp->dl_primitive = DL_ERROR_ACK;
-    errp->dl_error_primitive = prim;
-    errp->dl_errno = err;
-    errp->dl_unix_errno = uerr;
-    qreply(q, reply);
-}
-
-static void
-dlpi_ok(q, prim)
-    queue_t *q;
-    int prim;
-{
-    mblk_t *reply;
-    dl_ok_ack_t *okp;
-
-    reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
-    if (reply == 0)
-       return;                 /* XXX should do bufcall */
-    reply->b_datap->db_type = M_PCPROTO;
-    okp = (dl_ok_ack_t *) reply->b_wptr;
-    reply->b_wptr += sizeof(dl_ok_ack_t);
-    okp->dl_primitive = DL_OK_ACK;
-    okp->dl_correct_primitive = prim;
-    qreply(q, reply);
-}
-#endif /* NO_DLPI */
-
-static int
-pass_packet(us, mp, outbound)
-    upperstr_t *us;
-    mblk_t *mp;
-    int outbound;
-{
-    int pass;
-    upperstr_t *ppa;
-
-    if ((ppa = us->ppa) == 0) {
-       freemsg(mp);
-       return 0;
-    }
-
-#ifdef FILTER_PACKETS
-    pass = ip_hard_filter(us, mp, outbound);
-#else
-    /*
-     * Here is where we might, in future, decide whether to pass
-     * or drop the packet, and whether it counts as link activity.
-     */
-    pass = 1;
-#endif /* FILTER_PACKETS */
-
-    if (pass < 0) {
-       /* pass only if link already up, and don't update time */
-       if (ppa->lowerq == 0) {
-           freemsg(mp);
-           return 0;
-       }
-       pass = 1;
-    } else if (pass) {
-       if (outbound)
-           ppa->last_sent = time;
-       else
-           ppa->last_recv = time;
-    }
-
-    return pass;
-}
-
-/*
- * We have some data to send down to the lower stream (or up the
- * control stream, if we don't have a lower stream attached).
- * Returns 1 if the message was dealt with, 0 if it wasn't able
- * to be sent on and should therefore be queued up.
- */
-static int
-send_data(mp, us)
-    mblk_t *mp;
-    upperstr_t *us;
-{
-    upperstr_t *ppa;
-
-    if ((us->flags & US_BLOCKED) || us->npmode == NPMODE_QUEUE)
-       return 0;
-    ppa = us->ppa;
-    if (ppa == 0 || us->npmode == NPMODE_DROP || us->npmode == NPMODE_ERROR) {
-       if (us->flags & US_DBGLOG)
-           DPRINT2("ppp/%d: dropping pkt (npmode=%d)\n", us->mn, us->npmode);
-       freemsg(mp);
-       return 1;
-    }
-    if (ppa->lowerq == 0) {
-       /* try to send it up the control stream */
-        if (bcanputnext(ppa->q, mp->b_band)) {
-           /*
-            * The message seems to get corrupted for some reason if
-            * we just send the message up as it is, so we send a copy.
-            */
-           mblk_t *np = copymsg(mp);
-           freemsg(mp);
-           if (np != 0)
-               putnext(ppa->q, np);
-           return 1;
-       }
-    } else {
-        if (bcanputnext(ppa->lowerq, mp->b_band)) {
-           MT_ENTER(&ppa->stats_lock);
-           ppa->stats.ppp_opackets++;
-           ppa->stats.ppp_obytes += msgdsize(mp);
-#ifdef INCR_OPACKETS
-           INCR_OPACKETS(ppa);
-#endif
-           MT_EXIT(&ppa->stats_lock);
-           /*
-            * The lower queue is only ever detached while holding an
-            * exclusive lock on the whole driver.  So we can be confident
-            * that the lower queue is still there.
-            */
-           putnext(ppa->lowerq, mp);
-           return 1;
-       }
-    }
-    us->flags |= US_BLOCKED;
-    return 0;
-}
-
-/*
- * Allocate a new PPA id and link this stream into the list of PPAs.
- * This procedure is called with an exclusive lock on all queues in
- * this driver.
- */
-static void
-new_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *up, **usp;
-    int ppa_id;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("new_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-    usp = &ppas;
-    ppa_id = 0;
-    while ((up = *usp) != 0 && ppa_id == up->ppa_id) {
-       ++ppa_id;
-       usp = &up->nextppa;
-    }
-    us->ppa_id = ppa_id;
-    us->ppa = us;
-    us->next = 0;
-    us->nextppa = *usp;
-    *usp = us;
-    us->flags |= US_CONTROL;
-    us->npmode = NPMODE_PASS;
-
-    us->mtu = PPP_MTU;
-    us->mru = PPP_MRU;
-
-#ifdef SOL2
-    /*
-     * Create a kstats record for our statistics, so netstat -i works.
-     */
-    if (us->kstats == 0) {
-       char unit[32];
-
-       sprintf(unit, "ppp%d", us->ppa->ppa_id);
-       us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
-                                 "net", KSTAT_TYPE_NAMED, 4, 0);
-       if (us->kstats != 0) {
-           kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
-
-           strcpy(kn[0].name, "ipackets");
-           kn[0].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[1].name, "ierrors");
-           kn[1].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[2].name, "opackets");
-           kn[2].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[3].name, "oerrors");
-           kn[3].data_type = KSTAT_DATA_ULONG;
-           kstat_install(us->kstats);
-       }
-    }
-#endif /* SOL2 */
-
-    *(int *)mp->b_cont->b_rptr = ppa_id;
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-static void
-attach_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *t;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("attach_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-#ifndef NO_DLPI
-    us->state = DL_UNBOUND;
-#endif
-    for (t = us->ppa; t->next != 0; t = t->next)
-       ;
-    t->next = us;
-    us->next = 0;
-    if (mp->b_datap->db_type == M_IOCTL) {
-       mp->b_datap->db_type = M_IOCACK;
-       qreply(q, mp);
-    } else {
-#ifndef NO_DLPI
-       dlpi_ok(q, DL_ATTACH_REQ);
-#endif
-    }
-}
-
-static void
-detach_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *t;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("detach_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-    for (t = us->ppa; t->next != 0; t = t->next)
-       if (t->next == us) {
-           t->next = us->next;
-           break;
-       }
-    us->next = 0;
-    us->ppa = 0;
-#ifndef NO_DLPI
-    us->state = DL_UNATTACHED;
-    dlpi_ok(q, DL_DETACH_REQ);
-#endif
-}
-
-/*
- * We call this with qwriter in order to give the upper queue procedures
- * the guarantee that the lower queue is not going to go away while
- * they are executing.
- */
-static void
-detach_lower(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("detach_lower: q_ptr = 0!\n");
-       return;
-    }
-
-    LOCK_LOWER_W;
-    us->lowerq->q_ptr = 0;
-    RD(us->lowerq)->q_ptr = 0;
-    us->lowerq = 0;
-    UNLOCK_LOWER;
-
-    /* Unblock streams which now feed back up the control stream. */
-    qenable(us->q);
-
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-static int
-pppuwsrv(q)
-    queue_t *q;
-{
-    upperstr_t *us, *as;
-    mblk_t *mp;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppuwsrv: q_ptr = 0!\n");
-       return 0;
-    }
-
-    /*
-     * If this is a control stream, then this service procedure
-     * probably got enabled because of flow control in the lower
-     * stream being enabled (or because of the lower stream going
-     * away).  Therefore we enable the service procedure of all
-     * attached upper streams.
-     */
-    if (us->flags & US_CONTROL) {
-       for (as = us->next; as != 0; as = as->next)
-           qenable(WR(as->q));
-    }
-
-    /* Try to send on any data queued here. */
-    us->flags &= ~US_BLOCKED;
-    while ((mp = getq(q)) != 0) {
-       if (!send_data(mp, us)) {
-           putbq(q, mp);
-           break;
-       }
-    }
-
-    return 0;
-}
-
-/* should never get called... */
-static int
-ppplwput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    putnext(q, mp);
-    return 0;
-}
-
-static int
-ppplwsrv(q)
-    queue_t *q;
-{
-    queue_t *uq;
-
-    /*
-     * Flow control has back-enabled this stream:
-     * enable the upper write service procedure for
-     * the upper control stream for this lower stream.
-     */
-    LOCK_LOWER_R;
-    uq = (queue_t *) q->q_ptr;
-    if (uq != 0)
-       qenable(uq);
-    UNLOCK_LOWER;
-    return 0;
-}
-
-/*
- * This should only get called for control streams.
- */
-static int
-pppurput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *ppa, *us;
-    int proto, len;
-    struct iocblk *iop;
-
-    ppa = (upperstr_t *) q->q_ptr;
-    if (ppa == 0) {
-       DPRINT("pppurput: q_ptr = 0!\n");
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_CTL:
-       MT_ENTER(&ppa->stats_lock);
-       switch (*mp->b_rptr) {
-       case PPPCTL_IERROR:
-#ifdef INCR_IERRORS
-           INCR_IERRORS(ppa);
-#endif
-           ppa->stats.ppp_ierrors++;
-           break;
-       case PPPCTL_OERROR:
-#ifdef INCR_OERRORS
-           INCR_OERRORS(ppa);
-#endif
-           ppa->stats.ppp_oerrors++;
-           break;
-       }
-       MT_EXIT(&ppa->stats_lock);
-       freemsg(mp);
-       break;
-
-    case M_IOCACK:
-    case M_IOCNAK:
-       /*
-        * Attempt to match up the response with the stream
-        * that the request came from.
-        */
-       iop = (struct iocblk *) mp->b_rptr;
-       for (us = ppa; us != 0; us = us->next)
-           if (us->ioc_id == iop->ioc_id)
-               break;
-       if (us == 0)
-           freemsg(mp);
-       else
-           putnext(us->q, mp);
-       break;
-
-    case M_HANGUP:
-       /*
-        * The serial device has hung up.  We don't want to send
-        * the M_HANGUP message up to pppd because that will stop
-        * us from using the control stream any more.  Instead we
-        * send a zero-length message as an end-of-file indication.
-        */
-       freemsg(mp);
-       mp = allocb(1, BPRI_HI);
-       if (mp == 0) {
-           DPRINT1("ppp/%d: couldn't allocate eof message!\n", ppa->mn);
-           break;
-       }
-       putnext(ppa->q, mp);
-       break;
-
-    default:
-       if (mp->b_datap->db_type == M_DATA) {
-           len = msgdsize(mp);
-           if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
-               PULLUP(mp, PPP_HDRLEN);
-               if (mp == 0) {
-                   DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len);
-                   break;
-               }
-           }
-           MT_ENTER(&ppa->stats_lock);
-           ppa->stats.ppp_ipackets++;
-           ppa->stats.ppp_ibytes += len;
-#ifdef INCR_IPACKETS
-           INCR_IPACKETS(ppa);
-#endif
-           MT_EXIT(&ppa->stats_lock);
-
-           proto = PPP_PROTOCOL(mp->b_rptr);
-
-#if defined(SOL2)
-           /*
-            * Should there be any promiscuous stream(s), send the data
-            * up for each promiscuous stream that we recognize.
-            */
-           promisc_sendup(ppa, mp, proto, 1);
-#endif /* defined(SOL2) */
-
-           if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
-               /*
-                * A data packet for some network protocol.
-                * Queue it on the upper stream for that protocol.
-                * XXX could we just putnext it?  (would require thought)
-                * The rblocked flag is there to ensure that we keep
-                * messages in order for each network protocol.
-                */
-               if (!pass_packet(us, mp, 0))
-                   break;
-               if (!us->rblocked && !canput(us->q))
-                   us->rblocked = 1;
-               if (!us->rblocked)
-                   putq(us->q, mp);
-               else
-                   putq(q, mp);
-               break;
-           }
-       }
-       /*
-        * A control frame, a frame for an unknown protocol,
-        * or some other message type.
-        * Send it up to pppd via the control stream.
-        */
-       if (queclass(mp) == QPCTL || canputnext(ppa->q))
-           putnext(ppa->q, mp);
-       else
-           putq(q, mp);
-       break;
-    }
-
-    return 0;
-}
-
-static int
-pppursrv(q)
-    queue_t *q;
-{
-    upperstr_t *us, *as;
-    mblk_t *mp, *hdr;
-#ifndef NO_DLPI
-    dl_unitdata_ind_t *ud;
-#endif
-    int proto;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppursrv: q_ptr = 0!\n");
-       return 0;
-    }
-
-    if (us->flags & US_CONTROL) {
-       /*
-        * A control stream.
-        * If there is no lower queue attached, run the write service
-        * routines of other upper streams attached to this PPA.
-        */
-       if (us->lowerq == 0) {
-           as = us;
-           do {
-               if (as->flags & US_BLOCKED)
-                   qenable(WR(as->q));
-               as = as->next;
-           } while (as != 0);
-       }
-
-       /*
-        * Messages get queued on this stream's read queue if they
-        * can't be queued on the read queue of the attached stream
-        * that they are destined for.  This is for flow control -
-        * when this queue fills up, the lower read put procedure will
-        * queue messages there and the flow control will propagate
-        * down from there.
-        */
-       while ((mp = getq(q)) != 0) {
-           proto = PPP_PROTOCOL(mp->b_rptr);
-           if (proto < 0x8000 && (as = find_dest(us, proto)) != 0) {
-               if (!canput(as->q))
-                   break;
-               putq(as->q, mp);
-           } else {
-               if (!canputnext(q))
-                   break;
-               putnext(q, mp);
-           }
-       }
-       if (mp) {
-           putbq(q, mp);
-       } else {
-           /* can now put stuff directly on network protocol streams again */
-           for (as = us->next; as != 0; as = as->next)
-               as->rblocked = 0;
-       }
-
-       /*
-        * If this stream has a lower stream attached,
-        * enable the read queue's service routine.
-        * XXX we should really only do this if the queue length
-        * has dropped below the low-water mark.
-        */
-       if (us->lowerq != 0)
-           qenable(RD(us->lowerq));
-               
-    } else {
-       /*
-        * A network protocol stream.  Put a DLPI header on each
-        * packet and send it on.
-        * (Actually, it seems that the IP module will happily
-        * accept M_DATA messages without the DL_UNITDATA_IND header.)
-        */
-       while ((mp = getq(q)) != 0) {
-           if (!canputnext(q)) {
-               putbq(q, mp);
-               break;
-           }
-#ifndef NO_DLPI
-           proto = PPP_PROTOCOL(mp->b_rptr);
-           mp->b_rptr += PPP_HDRLEN;
-           hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint),
-                        BPRI_MED);
-           if (hdr == 0) {
-               /* XXX should put it back and use bufcall */
-               freemsg(mp);
-               continue;
-           }
-           hdr->b_datap->db_type = M_PROTO;
-           ud = (dl_unitdata_ind_t *) hdr->b_wptr;
-           hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint);
-           hdr->b_cont = mp;
-           ud->dl_primitive = DL_UNITDATA_IND;
-           ud->dl_dest_addr_length = sizeof(uint);
-           ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
-           ud->dl_src_addr_length = sizeof(uint);
-           ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(uint);
-#if DL_CURRENT_VERSION >= 2
-           ud->dl_group_address = 0;
-#endif
-           /* Send the DLPI client the data with the SAP they requested,
-              (e.g. ETHERTYPE_IP) rather than the PPP protocol number
-              (e.g. PPP_IP) */
-           ((uint *)(ud + 1))[0] = us->req_sap;        /* dest SAP */
-           ((uint *)(ud + 1))[1] = us->req_sap;        /* src SAP */
-           putnext(q, hdr);
-#else /* NO_DLPI */
-           putnext(q, mp);
-#endif /* NO_DLPI */
-       }
-       /*
-        * Now that we have consumed some packets from this queue,
-        * enable the control stream's read service routine so that we
-        * can process any packets for us that might have got queued
-        * there for flow control reasons.
-        */
-       if (us->ppa)
-           qenable(us->ppa->q);
-    }
-
-    return 0;
-}
-
-static upperstr_t *
-find_dest(ppa, proto)
-    upperstr_t *ppa;
-    int proto;
-{
-    upperstr_t *us;
-
-    for (us = ppa->next; us != 0; us = us->next)
-       if (proto == us->sap)
-           break;
-    return us;
-}
-
-#if defined (SOL2)
-/*
- * Test upstream promiscuous conditions. As of now, only pass IPv4 and
- * Ipv6 packets upstream (let PPP packets be decoded elsewhere).
- */
-static upperstr_t *
-find_promisc(us, proto)
-    upperstr_t *us;
-    int proto;
-{
-
-    if ((proto != PPP_IP) && (proto != PPP_IPV6))
-       return (upperstr_t *)0;
-
-    for ( ; us; us = us->next) {
-       if ((us->flags & US_PROMISC) && (us->state == DL_IDLE))
-           return us;
-    }
-
-    return (upperstr_t *)0;
-}
-
-/*
- * Prepend an empty Ethernet header to msg for snoop, et al.
- */
-static mblk_t *
-prepend_ether(us, mp, proto)
-    upperstr_t *us;
-    mblk_t *mp;
-    int proto;
-{
-    mblk_t *eh;
-    int type;
-
-    if ((eh = allocb(sizeof(struct ether_header), BPRI_HI)) == 0) {
-       freemsg(mp);
-       return (mblk_t *)0;
-    }
-
-    if (proto == PPP_IP)
-       type = ETHERTYPE_IP;
-    else if (proto == PPP_IPV6)
-       type = ETHERTYPE_IPV6;
-    else 
-       type = proto;       /* What else? Let decoder decide */
-
-    eh->b_wptr += sizeof(struct ether_header);
-    bzero((caddr_t)eh->b_rptr, sizeof(struct ether_header));
-    ((struct ether_header *)eh->b_rptr)->ether_type = htons((short)type);
-    eh->b_cont = mp;
-    return (eh);
-}
-
-/*
- * Prepend DL_UNITDATA_IND mblk to msg
- */
-static mblk_t *
-prepend_udind(us, mp, proto)
-    upperstr_t *us;
-    mblk_t *mp;
-    int proto;
-{
-    dl_unitdata_ind_t *dlu;
-    mblk_t *dh;
-    size_t size;
-
-    size = sizeof(dl_unitdata_ind_t);
-    if ((dh = allocb(size, BPRI_MED)) == 0) {
-       freemsg(mp);
-       return (mblk_t *)0;
-    }
-
-    dh->b_datap->db_type = M_PROTO;
-    dh->b_wptr = dh->b_datap->db_lim;
-    dh->b_rptr = dh->b_wptr - size;
-
-    dlu = (dl_unitdata_ind_t *)dh->b_rptr;
-    dlu->dl_primitive = DL_UNITDATA_IND;
-    dlu->dl_dest_addr_length = 0;
-    dlu->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
-    dlu->dl_src_addr_length = 0;
-    dlu->dl_src_addr_offset = sizeof(dl_unitdata_ind_t);
-    dlu->dl_group_address = 0;
-
-    dh->b_cont = mp;
-    return (dh);
-}
-
-/*
- * For any recognized promiscuous streams, send data upstream
- */
-static void
-promisc_sendup(ppa, mp, proto, skip)
-    upperstr_t *ppa;
-    mblk_t *mp;
-    int proto, skip;
-{
-    mblk_t *dup_mp, *dup_dup_mp;
-    upperstr_t *prus, *nprus;
-
-    if ((prus = find_promisc(ppa, proto)) != 0) {
-       if (dup_mp = dupmsg(mp)) {
-
-           if (skip)
-               dup_mp->b_rptr += PPP_HDRLEN;
-
-           for ( ; nprus = find_promisc(prus->next, proto); 
-                   prus = nprus) {
-
-               if (dup_dup_mp = dupmsg(dup_mp)) {
-                   if (canputnext(prus->q)) {
-                       if (prus->flags & US_RAWDATA) {
-                           dup_dup_mp = prepend_ether(prus, dup_dup_mp, proto);
-                           putnext(prus->q, dup_dup_mp);
-                       } else {
-                           dup_dup_mp = prepend_udind(prus, dup_dup_mp, proto);
-                           putnext(prus->q, dup_dup_mp);
-                       }
-                   } else {
-                       DPRINT("ppp_urput: data to promisc q dropped\n");
-                       freemsg(dup_dup_mp);
-                   }
-               }
-           }
-
-           if (canputnext(prus->q)) {
-               if (prus->flags & US_RAWDATA) {
-                   dup_mp = prepend_ether(prus, dup_mp, proto);
-                   putnext(prus->q, dup_mp);
-               } else {
-                   dup_mp = prepend_udind(prus, dup_mp, proto);
-                   putnext(prus->q, dup_mp);
-               }
-           } else {
-               DPRINT("ppp_urput: data to promisc q dropped\n");
-               freemsg(dup_mp);
-           }
-       }
-    }
-}
-#endif /* defined(SOL2) */
-
-/*
- * We simply put the message on to the associated upper control stream
- * (either here or in ppplrsrv).  That way we enter the perimeters
- * before looking through the list of attached streams to decide which
- * stream it should go up.
- */
-static int
-ppplrput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    queue_t *uq;
-    struct iocblk *iop;
-
-    switch (mp->b_datap->db_type) {
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       iop->ioc_error = EINVAL;
-       mp->b_datap->db_type = M_IOCNAK;
-       qreply(q, mp);
-       return 0;
-    case M_FLUSH:
-       if (*mp->b_rptr & FLUSHR)
-           flushq(q, FLUSHDATA);
-       if (*mp->b_rptr & FLUSHW) {
-           *mp->b_rptr &= ~FLUSHR;
-           qreply(q, mp);
-       } else
-           freemsg(mp);
-       return 0;
-    }
-
-    /*
-     * If we can't get the lower lock straight away, queue this one
-     * rather than blocking, to avoid the possibility of deadlock.
-     */
-    if (!TRYLOCK_LOWER_R) {
-       putq(q, mp);
-       return 0;
-    }
-
-    /*
-     * Check that we're still connected to the driver.
-     */
-    uq = (queue_t *) q->q_ptr;
-    if (uq == 0) {
-       UNLOCK_LOWER;
-       DPRINT1("ppplrput: q = %x, uq = 0??\n", q);
-       freemsg(mp);
-       return 0;
-    }
-
-    /*
-     * Try to forward the message to the put routine for the upper
-     * control stream for this lower stream.
-     * If there are already messages queued here, queue this one so
-     * they don't get out of order.
-     */
-    if (queclass(mp) == QPCTL || (qsize(q) == 0 && canput(uq)))
-       put(uq, mp);
-    else
-       putq(q, mp);
-
-    UNLOCK_LOWER;
-    return 0;
-}
-
-static int
-ppplrsrv(q)
-    queue_t *q;
-{
-    mblk_t *mp;
-    queue_t *uq;
-
-    /*
-     * Packets get queued here for flow control reasons
-     * or if the lrput routine couldn't get the lower lock
-     * without blocking.
-     */
-    LOCK_LOWER_R;
-    uq = (queue_t *) q->q_ptr;
-    if (uq == 0) {
-       UNLOCK_LOWER;
-       flushq(q, FLUSHALL);
-       DPRINT1("ppplrsrv: q = %x, uq = 0??\n", q);
-       return 0;
-    }
-    while ((mp = getq(q)) != 0) {
-       if (queclass(mp) == QPCTL || canput(uq))
-           put(uq, mp);
-       else {
-           putbq(q, mp);
-           break;
-       }
-    }
-    UNLOCK_LOWER;
-    return 0;
-}
-
-static int
-putctl2(q, type, code, val)
-    queue_t *q;
-    int type, code, val;
-{
-    mblk_t *mp;
-
-    mp = allocb(2, BPRI_HI);
-    if (mp == 0)
-       return 0;
-    mp->b_datap->db_type = type;
-    mp->b_wptr[0] = code;
-    mp->b_wptr[1] = val;
-    mp->b_wptr += 2;
-    putnext(q, mp);
-    return 1;
-}
-
-static int
-putctl4(q, type, code, val)
-    queue_t *q;
-    int type, code, val;
-{
-    mblk_t *mp;
-
-    mp = allocb(4, BPRI_HI);
-    if (mp == 0)
-       return 0;
-    mp->b_datap->db_type = type;
-    mp->b_wptr[0] = code;
-    ((short *)mp->b_wptr)[1] = val;
-    mp->b_wptr += 4;
-    putnext(q, mp);
-    return 1;
-}
-
-static void
-debug_dump(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us;
-    queue_t *uq, *lq;
-
-    DPRINT("ppp upper streams:\n");
-    for (us = minor_devs; us != 0; us = us->nextmn) {
-       uq = us->q;
-       DPRINT3(" %d: q=%x rlev=%d",
-               us->mn, uq, (uq? qsize(uq): 0));
-       DPRINT3(" wlev=%d flags=0x%b", (uq? qsize(WR(uq)): 0),
-               us->flags, "\020\1priv\2control\3blocked\4last");
-       DPRINT3(" state=%x sap=%x req_sap=%x", us->state, us->sap,
-               us->req_sap);
-       if (us->ppa == 0)
-           DPRINT(" ppa=?\n");
-       else
-           DPRINT1(" ppa=%d\n", us->ppa->ppa_id);
-       if (us->flags & US_CONTROL) {
-           lq = us->lowerq;
-           DPRINT3("    control for %d lq=%x rlev=%d",
-                   us->ppa_id, lq, (lq? qsize(RD(lq)): 0));
-           DPRINT3(" wlev=%d mru=%d mtu=%d\n",
-                   (lq? qsize(lq): 0), us->mru, us->mtu);
-       }
-    }
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-#ifdef FILTER_PACKETS
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-
-#define MAX_IPHDR    128     /* max TCP/IP header size */
-
-
-/* The following table contains a hard-coded list of protocol/port pairs.
- * Any matching packets are either discarded unconditionally, or, 
- * if ok_if_link_up is non-zero when a connection does not currently exist
- * (i.e., they go through if the connection is present, but never initiate
- * a dial-out).
- * This idea came from a post by dm@garage.uun.org (David Mazieres)
- */
-static struct pktfilt_tab { 
-       int proto; 
-       u_short port; 
-       u_short ok_if_link_up; 
-} pktfilt_tab[] = {
-       { IPPROTO_UDP,  520,    1 },    /* RIP, ok to pass if link is up */
-       { IPPROTO_UDP,  123,    1 },    /* NTP, don't keep up the link for it */
-       { -1,           0,      0 }     /* terminator entry has port == -1 */
-};
-
-
-static int
-ip_hard_filter(us, mp, outbound)
-    upperstr_t *us;
-    mblk_t *mp;
-    int outbound;
-{
-    struct ip *ip;
-    struct pktfilt_tab *pft;
-    mblk_t *temp_mp;
-    int proto;
-    int len, hlen;
-
-
-    /* Note, the PPP header has already been pulled up in all cases */
-    proto = PPP_PROTOCOL(mp->b_rptr);
-    if (us->flags & US_DBGLOG)
-        DPRINT3("ppp/%d: filter, proto=0x%x, out=%d\n", us->mn, proto, outbound);
-
-    switch (proto)
-    {
-    case PPP_IP:
-       if ((mp->b_wptr - mp->b_rptr) == PPP_HDRLEN && mp->b_cont != 0) {
-           temp_mp = mp->b_cont;
-           len = msgdsize(temp_mp);
-           hlen = (len < MAX_IPHDR) ? len : MAX_IPHDR;
-           PULLUP(temp_mp, hlen);
-           if (temp_mp == 0) {
-               DPRINT2("ppp/%d: filter, pullup next failed, len=%d\n", 
-                       us->mn, hlen);
-               mp->b_cont = 0;         /* PULLUP() freed the rest */
-               freemsg(mp);
-               return 0;
-           }
-           ip = (struct ip *)mp->b_cont->b_rptr;
-       }
-       else {
-           len = msgdsize(mp);
-           hlen = (len < (PPP_HDRLEN+MAX_IPHDR)) ? len : (PPP_HDRLEN+MAX_IPHDR);
-           PULLUP(mp, hlen);
-           if (mp == 0) {
-               DPRINT2("ppp/%d: filter, pullup failed, len=%d\n", 
-                       us->mn, hlen);
-               return 0;
-           }
-           ip = (struct ip *)(mp->b_rptr + PPP_HDRLEN);
-       }
-
-       /* For IP traffic, certain packets (e.g., RIP) may be either
-        *   1.  ignored - dropped completely
-        *   2.  will not initiate a connection, but
-        *       will be passed if a connection is currently up.
-        */
-       for (pft=pktfilt_tab; pft->proto != -1; pft++) {
-           if (ip->ip_p == pft->proto) {
-               switch(pft->proto) {
-               case IPPROTO_UDP:
-                   if (((struct udphdr *) &((int *)ip)[ip->ip_hl])->uh_dport
-                               == htons(pft->port)) goto endfor;
-                   break;
-               case IPPROTO_TCP:
-                   if (((struct tcphdr *) &((int *)ip)[ip->ip_hl])->th_dport
-                               == htons(pft->port)) goto endfor;
-                   break;
-               }       
-           }
-       }
-       endfor:
-       if (pft->proto != -1) {
-           if (us->flags & US_DBGLOG)
-               DPRINT3("ppp/%d: found IP pkt, proto=0x%x (%d)\n", 
-                               us->mn, pft->proto, pft->port);
-           /* Discard if not connected, or if not pass_with_link_up */
-           /* else, if link is up let go by, but don't update time */
-           return pft->ok_if_link_up? -1: 0;
-       }
-        break;
-    } /* end switch (proto) */
-
-    return 1;
-}
-#endif /* FILTER_PACKETS */
-
diff --git a/modules/ppp_ahdlc.c b/modules/ppp_ahdlc.c
deleted file mode 100644 (file)
index 68e0907..0000000
+++ /dev/null
@@ -1,871 +0,0 @@
-/*
- * ppp_ahdlc.c - STREAMS module for doing PPP asynchronous HDLC.
- *
- * Re-written by Adi Masputra <adi.masputra@sun.com>, based on 
- * the original ppp_ahdlc.c
- *
- * Copyright (c) 2000 by Sun Microsystems, Inc.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation is hereby granted, provided that the above copyright
- * notice appears in all copies.  
- *
- * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
- * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
- * OR MODIFICATIONS.
- */
-
-/*
- * This file is used under Solaris 2, SVR4, SunOS 4, and Digital UNIX.
- */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stream.h>
-#include <sys/errno.h>
-
-#ifdef SVR4
-#include <sys/conf.h>
-#include <sys/kmem.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#else
-#include <sys/user.h>
-#ifdef __osf__
-#include <sys/cmn_err.h>
-#endif
-#endif /* SVR4 */
-
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-/*
- * Right now, mutex is only enabled for Solaris 2.x
- */
-#if defined(SOL2)
-#define USE_MUTEX
-#endif /* SOL2 */
-
-/*
- * intpointer_t and uintpointer_t are signed and unsigned integer types 
- * large enough to hold any data pointer; that is, data pointers can be 
- * assigned into or from these integer types without losing precision.
- * On recent Solaris releases, these types are defined in sys/int_types.h,
- * but not on SunOS 4.x or the earlier Solaris versions.
- */
-#if defined(_LP64) || defined(_I32LPx)
-typedef long                    intpointer_t;
-typedef unsigned long           uintpointer_t;
-#else
-typedef int                     intpointer_t;
-typedef unsigned int            uintpointer_t;
-#endif
-
-MOD_OPEN_DECL(ahdlc_open);
-MOD_CLOSE_DECL(ahdlc_close);
-static int ahdlc_wput(queue_t *, mblk_t *);
-static int ahdlc_rput(queue_t *, mblk_t *);
-static void ahdlc_encode(queue_t *, mblk_t *);
-static void ahdlc_decode(queue_t *, mblk_t *);
-static int msg_byte(mblk_t *, unsigned int);
-
-#if defined(SOL2)
-/*
- * Don't send HDLC start flag is last transmit is within 1.5 seconds -
- * FLAG_TIME is defined is microseconds
- */
-#define FLAG_TIME   1500
-#define ABS(x)     (x >= 0 ? x : (-x))
-#endif /* SOL2 */
-
-/*
- * Extract byte i of message mp 
- */
-#define MSG_BYTE(mp, i)        ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
-                        msg_byte((mp), (i)))
-
-/* 
- * Is this LCP packet one we have to transmit using LCP defaults? 
- */
-#define LCP_USE_DFLT(mp)       (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
-
-/*
- * Standard STREAMS declarations
- */
-static struct module_info minfo = {
-    0x7d23, "ppp_ahdl", 0, INFPSZ, 32768, 512
-};
-
-static struct qinit rinit = {
-    ahdlc_rput, NULL, ahdlc_open, ahdlc_close, NULL, &minfo, NULL
-};
-
-static struct qinit winit = {
-    ahdlc_wput, NULL, NULL, NULL, NULL, &minfo, NULL
-};
-
-#if defined(SVR4) && !defined(SOL2)
-int phdldevflag = 0;
-#define ppp_ahdlcinfo phdlinfo
-#endif /* defined(SVR4) && !defined(SOL2) */
-
-struct streamtab ppp_ahdlcinfo = {
-    &rinit,                        /* ptr to st_rdinit */
-    &winit,                        /* ptr to st_wrinit */
-    NULL,                          /* ptr to st_muxrinit */
-    NULL,                          /* ptr to st_muxwinit */
-#if defined(SUNOS4)
-    NULL                           /* ptr to ptr to st_modlist */
-#endif /* SUNOS4 */
-};
-
-#if defined(SUNOS4)
-int ppp_ahdlc_count = 0;           /* open counter */
-#endif /* SUNOS4 */
-
-/*
- * Per-stream state structure
- */
-typedef struct ahdlc_state {
-#if defined(USE_MUTEX)
-    kmutex_t       lock;                   /* lock for this structure */
-#endif /* USE_MUTEX */
-    int                    flags;                  /* link flags */
-    mblk_t         *rx_buf;                /* ptr to receive buffer */
-    int                    rx_buf_size;            /* receive buffer size */
-    ushort_t       infcs;                  /* calculated rx HDLC FCS */
-    u_int32_t      xaccm[8];               /* 256-bit xmit ACCM */
-    u_int32_t      raccm;                  /* 32-bit rcv ACCM */
-    int                    mtu;                    /* interface MTU */
-    int                    mru;                    /* link MRU */
-    int                    unit;                   /* current PPP unit number */
-    struct pppstat  stats;                 /* statistic structure */
-#if defined(SOL2)
-    clock_t        flag_time;              /* time in usec between flags */
-    clock_t        lbolt;                  /* last updated lbolt */
-#endif /* SOL2 */
-} ahdlc_state_t;
-
-/*
- * Values for flags 
- */
-#define ESCAPED                0x100   /* last saw escape char on input */
-#define IFLUSH         0x200   /* flushing input due to error */
-
-/* 
- * RCV_B7_1, etc., defined in net/pppio.h, are stored in flags also. 
- */
-#define RCV_FLAGS      (RCV_B7_1|RCV_B7_0|RCV_ODDP|RCV_EVNP)
-
-/*
- * FCS lookup table as calculated by genfcstab.
- */
-static u_short fcstab[256] = {
-       0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
-       0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
-       0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
-       0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
-       0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
-       0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
-       0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
-       0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
-       0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
-       0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
-       0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
-       0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
-       0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
-       0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
-       0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
-       0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
-       0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
-       0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
-       0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
-       0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
-       0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
-       0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
-       0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
-       0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
-       0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
-       0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
-       0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
-       0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
-       0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
-       0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
-       0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
-       0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
-};
-
-static u_int32_t paritytab[8] =
-{
-       0x96696996, 0x69969669, 0x69969669, 0x96696996,
-       0x69969669, 0x96696996, 0x96696996, 0x69969669
-};
-
-/*
- * STREAMS module open (entry) point
- */
-MOD_OPEN(ahdlc_open)
-{
-    ahdlc_state_t   *state;
-
-    /*
-     * Return if it's already opened
-     */
-    if (q->q_ptr) {
-       return 0;
-    }
-
-    /*
-     * This can only be opened as a module
-     */
-    if (sflag != MODOPEN) {
-       return 0;
-    }
-
-    state = (ahdlc_state_t *) ALLOC_NOSLEEP(sizeof(ahdlc_state_t));
-    if (state == 0)
-       OPEN_ERROR(ENOSR);
-    bzero((caddr_t) state, sizeof(ahdlc_state_t));
-
-    q->q_ptr    = (caddr_t) state;
-    WR(q)->q_ptr = (caddr_t) state;
-
-#if defined(USE_MUTEX)
-    mutex_init(&state->lock, NULL, MUTEX_DEFAULT, NULL);
-    mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-
-    state->xaccm[0] = ~0;          /* escape 0x00 through 0x1f */
-    state->xaccm[3] = 0x60000000;   /* escape 0x7d and 0x7e */
-    state->mru     = PPP_MRU;      /* default of 1500 bytes */
-#if defined(SOL2)
-    state->flag_time = drv_usectohz(FLAG_TIME);
-#endif /* SOL2 */
-
-#if defined(USE_MUTEX)
-    mutex_exit(&state->lock);
-#endif /* USE_MUTEX */ 
-
-#if defined(SUNOS4)
-    ppp_ahdlc_count++;
-#endif /* SUNOS4 */
-
-    qprocson(q);
-    
-    return 0;
-}
-
-/*
- * STREAMS module close (exit) point
- */
-MOD_CLOSE(ahdlc_close)
-{
-    ahdlc_state_t   *state;
-
-    qprocsoff(q);
-
-    state = (ahdlc_state_t *) q->q_ptr;
-
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_close\n");
-       return 0;
-    }
-
-#if defined(USE_MUTEX)
-    mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-
-    if (state->rx_buf != 0) {
-       freemsg(state->rx_buf);
-       state->rx_buf = 0;
-    }
-
-#if defined(USE_MUTEX)
-    mutex_exit(&state->lock);
-    mutex_destroy(&state->lock);
-#endif /* USE_MUTEX */
-
-    FREE(q->q_ptr, sizeof(ahdlc_state_t));
-    q->q_ptr        = NULL;
-    OTHERQ(q)->q_ptr = NULL;
-
-#if defined(SUNOS4)
-    if (ppp_ahdlc_count)
-       ppp_ahdlc_count--;
-#endif /* SUNOS4 */
-    
-    return 0;
-}
-
-/*
- * Write side put routine
- */
-static int
-ahdlc_wput(q, mp)
-    queue_t    *q;
-    mblk_t     *mp;
-{
-    ahdlc_state_t      *state;
-    struct iocblk      *iop;
-    int                        error;
-    mblk_t             *np;
-    struct ppp_stats   *psp;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_wput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       /*
-        * A data packet - do character-stuffing and FCS, and
-        * send it onwards.
-        */
-       ahdlc_encode(q, mp);
-       freemsg(mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       switch (iop->ioc_cmd) {
-       case PPPIO_XACCM:
-           if ((iop->ioc_count < sizeof(u_int32_t)) || 
-               (iop->ioc_count > sizeof(ext_accm))) {
-               break;
-           }
-           if (mp->b_cont == 0) {
-               DPRINT1("ahdlc_wput/%d: PPPIO_XACCM b_cont = 0!\n", state->unit);
-               break;
-           }
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           bcopy((caddr_t)mp->b_cont->b_rptr, (caddr_t)state->xaccm,
-                 iop->ioc_count);
-           state->xaccm[2] &= ~0x40000000;     /* don't escape 0x5e */
-           state->xaccm[3] |= 0x60000000;      /* do escape 0x7d, 0x7e */
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_RACCM:
-           if (iop->ioc_count != sizeof(u_int32_t))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ahdlc_wput/%d: PPPIO_RACCM b_cont = 0!\n", state->unit);
-               break;
-           }
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           bcopy((caddr_t)mp->b_cont->b_rptr, (caddr_t)&state->raccm,
-                 sizeof(u_int32_t));
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_GCLEAN:
-           np = allocb(sizeof(int), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           *(int *)np->b_wptr = state->flags & RCV_FLAGS;
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           np->b_wptr += sizeof(int);
-           iop->ioc_count = sizeof(int);
-           error = 0;
-           break;
-
-       case PPPIO_GETSTAT:
-           np = allocb(sizeof(struct ppp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           psp = (struct ppp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_stats);
-           bzero((caddr_t)psp, sizeof(struct ppp_stats));
-           psp->p = state->stats;
-           iop->ioc_count = sizeof(struct ppp_stats);
-           error = 0;
-           break;
-
-       case PPPIO_LASTMOD:
-           /* we knew this anyway */
-           error = 0;
-           break;
-
-       default:
-           error = -1;
-           break;
-       }
-
-       if (error < 0)
-           putnext(q, mp);
-       else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       } else {
-           mp->b_datap->db_type = M_IOCNAK;
-           iop->ioc_count = 0;
-           iop->ioc_error = error;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_CTL:
-       switch (*mp->b_rptr) {
-       case PPPCTL_MTU:
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           state->mtu = ((unsigned short *)mp->b_rptr)[1];
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           freemsg(mp);
-           break;
-       case PPPCTL_MRU:
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           state->mru = ((unsigned short *)mp->b_rptr)[1];
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           freemsg(mp);
-           break;
-       case PPPCTL_UNIT:
-#if defined(USE_MUTEX)
-           mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-           state->unit = mp->b_rptr[1];
-#if defined(USE_MUTEX)
-           mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-           break;
-       default:
-           putnext(q, mp);
-       }
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-/*
- * Read side put routine
- */
-static int
-ahdlc_rput(q, mp)
-    queue_t *q;
-    mblk_t  *mp;
-{
-    ahdlc_state_t *state;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_rput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       ahdlc_decode(q, mp);
-       break;
-
-    case M_HANGUP:
-#if defined(USE_MUTEX)
-       mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-       if (state->rx_buf != 0) {
-           /* XXX would like to send this up for debugging */
-           freemsg(state->rx_buf);
-           state->rx_buf = 0;
-       }
-       state->flags = IFLUSH;
-#if defined(USE_MUTEX)
-       mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-    return 0;
-}
-
-/*
- * Extract bit c from map m, to determine if c needs to be escaped
- */
-#define IN_TX_MAP(c, m)        ((m)[(c) >> 5] & (1 << ((c) & 0x1f)))
-
-static void
-ahdlc_encode(q, mp)
-    queue_t    *q;
-    mblk_t     *mp;
-{
-    ahdlc_state_t      *state;
-    u_int32_t          *xaccm, loc_xaccm[8];
-    ushort_t           fcs;
-    size_t             outmp_len;
-    mblk_t             *outmp, *tmp;
-    uchar_t            *dp, fcs_val;
-    int                        is_lcp, code;
-#if defined(SOL2)
-    clock_t            lbolt;
-#endif /* SOL2 */
-
-    if (msgdsize(mp) < 4) {
-       return;
-    }
-
-    state = (ahdlc_state_t *)q->q_ptr;
-#if defined(USE_MUTEX)
-    mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-
-    /*
-     * Allocate an output buffer large enough to handle a case where all
-     * characters need to be escaped
-     */
-    outmp_len = (msgdsize(mp)   << 1) +                /* input block x 2 */
-               (sizeof(fcs)     << 2) +                /* HDLC FCS x 4 */
-               (sizeof(uchar_t) << 1);                 /* HDLC flags x 2 */
-
-    outmp = allocb(outmp_len, BPRI_MED);
-    if (outmp == NULL) {
-       state->stats.ppp_oerrors++;
-#if defined(USE_MUTEX)
-       mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-       putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-       return;
-    }
-
-#if defined(SOL2)
-    /*
-     * Check if our last transmit happenned within flag_time, using
-     * the system's LBOLT value in clock ticks
-     */
-    if (drv_getparm(LBOLT, &lbolt) != -1) {
-       if (ABS((clock_t)lbolt - state->lbolt) > state->flag_time) {
-           *outmp->b_wptr++ = PPP_FLAG;
-       } 
-       state->lbolt = lbolt;
-    } else {
-       *outmp->b_wptr++ = PPP_FLAG;
-    }
-#else
-    /*
-     * If the driver below still has a message to process, skip the
-     * HDLC flag, otherwise, put one in the beginning
-     */
-    if (qsize(q->q_next) == 0) {
-       *outmp->b_wptr++ = PPP_FLAG;
-    }
-#endif
-
-    /*
-     * All control characters must be escaped for LCP packets with code
-     * values between 1 (Conf-Req) and 7 (Code-Rej).
-     */
-    is_lcp = ((MSG_BYTE(mp, 0) == PPP_ALLSTATIONS) && 
-             (MSG_BYTE(mp, 1) == PPP_UI) && 
-             (MSG_BYTE(mp, 2) == (PPP_LCP >> 8)) &&
-             (MSG_BYTE(mp, 3) == (PPP_LCP & 0xff)) &&
-             LCP_USE_DFLT(mp));
-
-    xaccm = state->xaccm;
-    if (is_lcp) {
-       bcopy((caddr_t)state->xaccm, (caddr_t)loc_xaccm, sizeof(loc_xaccm));
-       loc_xaccm[0] = ~0;      /* force escape on 0x00 through 0x1f */
-       xaccm = loc_xaccm;
-    }
-
-    fcs = PPP_INITFCS;         /* Initial FCS is 0xffff */
-
-    /*
-     * Process this block and the rest (if any) attached to the this one
-     */
-    for (tmp = mp; tmp; tmp = tmp->b_cont) {
-       if (tmp->b_datap->db_type == M_DATA) {
-           for (dp = tmp->b_rptr; dp < tmp->b_wptr; dp++) {
-               fcs = PPP_FCS(fcs, *dp);
-               if (IN_TX_MAP(*dp, xaccm)) {
-                   *outmp->b_wptr++ = PPP_ESCAPE;
-                   *outmp->b_wptr++ = *dp ^ PPP_TRANS;
-               } else {
-                   *outmp->b_wptr++ = *dp;
-               }
-           }
-       } else {
-           continue;   /* skip if db_type is something other than M_DATA */
-       }
-    }
-
-    /*
-     * Append the HDLC FCS, making sure that escaping is done on any
-     * necessary bytes
-     */
-    fcs_val = (fcs ^ 0xffff) & 0xff;
-    if (IN_TX_MAP(fcs_val, xaccm)) {
-       *outmp->b_wptr++ = PPP_ESCAPE;
-       *outmp->b_wptr++ = fcs_val ^ PPP_TRANS;
-    } else {
-       *outmp->b_wptr++ = fcs_val;
-    }
-
-    fcs_val = ((fcs ^ 0xffff) >> 8) & 0xff;
-    if (IN_TX_MAP(fcs_val, xaccm)) {
-       *outmp->b_wptr++ = PPP_ESCAPE;
-       *outmp->b_wptr++ = fcs_val ^ PPP_TRANS;
-    } else {
-       *outmp->b_wptr++ = fcs_val;
-    }
-
-    /*
-     * And finally, append the HDLC flag, and send it away
-     */
-    *outmp->b_wptr++ = PPP_FLAG;
-
-    state->stats.ppp_obytes += msgdsize(outmp);
-    state->stats.ppp_opackets++;
-
-#if defined(USE_MUTEX)
-    mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-
-    putnext(q, outmp);
-    return;
-}
-
-/*
- * Checks the 32-bit receive ACCM to see if the byte needs un-escaping
- */
-#define IN_RX_MAP(c, m)        ((((unsigned int) (uchar_t) (c)) < 0x20) && \
-                       (m) & (1 << (c)))
-
-
-/*
- * Process received characters.
- */
-static void
-ahdlc_decode(q, mp)
-    queue_t *q;
-    mblk_t  *mp;
-{
-    ahdlc_state_t   *state;
-    mblk_t         *om;
-    uchar_t        *dp;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-
-#if defined(USE_MUTEX)
-    mutex_enter(&state->lock);
-#endif /* USE_MUTEX */
-
-    state->stats.ppp_ibytes += msgdsize(mp);
-
-    for (; mp != 0; om = mp->b_cont, freeb(mp), mp = om)
-    for (dp = mp->b_rptr; dp < mp->b_wptr; dp++) {
-
-       /*
-        * This should detect the lack of 8-bit communication channel
-        * which is necessary for PPP to work. In addition, it also
-        * checks on the parity.
-        */
-       if (*dp & 0x80)
-           state->flags |= RCV_B7_1;
-       else
-           state->flags |= RCV_B7_0;
-
-       if (paritytab[*dp >> 5] & (1 << (*dp & 0x1f)))
-           state->flags |= RCV_ODDP;
-       else
-           state->flags |= RCV_EVNP;
-
-       /*
-        * So we have a HDLC flag ...
-        */
-       if (*dp == PPP_FLAG) {
-
-           /*
-            * If we think that it marks the beginning of the frame,
-            * then continue to process the next octects
-            */
-           if ((state->flags & IFLUSH) ||
-               (state->rx_buf == 0) ||
-               (msgdsize(state->rx_buf) == 0)) {
-
-               state->flags &= ~IFLUSH;
-               continue;
-           }
-
-           /*
-            * We get here because the above condition isn't true,
-            * in which case the HDLC flag was there to mark the end
-            * of the frame (or so we think)
-            */
-           om = state->rx_buf;
-
-           if (state->infcs == PPP_GOODFCS) {
-               state->stats.ppp_ipackets++;
-               adjmsg(om, -PPP_FCSLEN);
-               putnext(q, om);
-           } else {
-               DPRINT2("ppp%d: bad fcs (len=%d)\n",
-                    state->unit, msgdsize(state->rx_buf));
-               freemsg(state->rx_buf);
-               state->flags &= ~(IFLUSH | ESCAPED);
-               state->stats.ppp_ierrors++;
-               putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-           }
-
-           state->rx_buf = 0;
-           continue;
-       }
-
-       if (state->flags & IFLUSH) {
-           continue;
-       }
-
-       /*
-        * Allocate a receive buffer, large enough to store a frame (after
-        * un-escaping) of at least 1500 octets. If MRU is negotiated to
-        * be more than the default, then allocate that much. In addition,
-        * we add an extra 32-bytes for a fudge factor
-        */ 
-       if (state->rx_buf == 0) {
-           state->rx_buf_size  = (state->mru < PPP_MRU ? PPP_MRU : state->mru);
-           state->rx_buf_size += (sizeof(u_int32_t) << 3);
-           state->rx_buf = allocb(state->rx_buf_size, BPRI_MED);
-
-           /*
-            * If allocation fails, try again on the next frame
-            */
-           if (state->rx_buf == 0) {
-               state->flags |= IFLUSH;
-               continue;
-           }
-           state->flags &= ~(IFLUSH | ESCAPED);
-           state->infcs  = PPP_INITFCS;
-       }
-
-       if (*dp == PPP_ESCAPE) {
-           state->flags |= ESCAPED;
-           continue;
-       }
-
-       /*
-        * Make sure we un-escape the necessary characters, as well as the
-        * ones in our receive async control character map
-        */
-       if (state->flags & ESCAPED) {
-           *dp ^= PPP_TRANS;
-           state->flags &= ~ESCAPED;
-       } else if (IN_RX_MAP(*dp, state->raccm)) 
-           continue;
-
-       /*
-        * Unless the peer lied to us about the negotiated MRU, we should
-        * never get a frame which is too long. If it happens, toss it away
-        * and grab the next incoming one
-        */
-       if (msgdsize(state->rx_buf) < state->rx_buf_size) {
-           state->infcs = PPP_FCS(state->infcs, *dp);
-           *state->rx_buf->b_wptr++ = *dp;
-       } else {
-           DPRINT2("ppp%d: frame too long (%d)\n",
-               state->unit, msgdsize(state->rx_buf));
-           freemsg(state->rx_buf);
-           state->rx_buf     = 0;
-           state->flags     |= IFLUSH;
-       }
-    }
-
-#if defined(USE_MUTEX)
-    mutex_exit(&state->lock);
-#endif /* USE_MUTEX */
-}
-
-static int
-msg_byte(mp, i)
-    mblk_t *mp;
-    unsigned int i;
-{
-    while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
-       mp = mp->b_cont;
-    if (mp == 0)
-       return -1;
-    return mp->b_rptr[i];
-}
diff --git a/modules/ppp_comp.c b/modules/ppp_comp.c
deleted file mode 100644 (file)
index 9e204d9..0000000
+++ /dev/null
@@ -1,1132 +0,0 @@
-/*
- * ppp_comp.c - STREAMS module for kernel-level compression and CCP support.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * This file is used under SVR4, Solaris 2, SunOS 4, and Digital UNIX.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/stream.h>
-
-#ifdef SVR4
-#include <sys/conf.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#else
-#include <sys/user.h>
-#ifdef __osf__
-#include <sys/cmn_err.h>
-#endif
-#endif /* SVR4 */
-
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-#ifdef __osf__
-#include <sys/mbuf.h>
-#include <sys/protosw.h>
-#endif
-
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <net/vjcompress.h>
-
-#define PACKETPTR      mblk_t *
-#include <net/ppp-comp.h>
-
-MOD_OPEN_DECL(ppp_comp_open);
-MOD_CLOSE_DECL(ppp_comp_close);
-static int ppp_comp_rput(queue_t *, mblk_t *);
-static int ppp_comp_rsrv(queue_t *);
-static int ppp_comp_wput(queue_t *, mblk_t *);
-static int ppp_comp_wsrv(queue_t *);
-static void ppp_comp_ccp(queue_t *, mblk_t *, int);
-static int msg_byte(mblk_t *, unsigned int);
-
-/* Extract byte i of message mp. */
-#define MSG_BYTE(mp, i)        ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
-                        msg_byte((mp), (i)))
-
-/* Is this LCP packet one we have to transmit using LCP defaults? */
-#define LCP_USE_DFLT(mp)       (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
-
-#define PPP_COMP_ID 0xbadf
-static struct module_info minfo = {
-#ifdef PRIOQ
-    PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16512, 16384,
-#else
-    PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16384, 4096,
-#endif
-};
-
-static struct qinit r_init = {
-    ppp_comp_rput, ppp_comp_rsrv, ppp_comp_open, ppp_comp_close,
-    NULL, &minfo, NULL
-};
-
-static struct qinit w_init = {
-    ppp_comp_wput, ppp_comp_wsrv, NULL, NULL, NULL, &minfo, NULL
-};
-
-#if defined(SVR4) && !defined(SOL2)
-int pcmpdevflag = 0;
-#define ppp_compinfo pcmpinfo
-#endif
-struct streamtab ppp_compinfo = {
-    &r_init, &w_init, NULL, NULL
-};
-
-int ppp_comp_count;            /* number of module instances in use */
-
-#ifdef __osf__
-
-static void ppp_comp_alloc(comp_state_t *);
-typedef struct memreq {
-    unsigned char comp_opts[20];
-    int cmd;
-    int thread_status;
-    char *returned_mem;
-} memreq_t;
-
-#endif
-
-typedef struct comp_state {
-    int                flags;
-    int                mru;
-    int                mtu;
-    int                unit;
-    struct compressor *xcomp;
-    void       *xstate;
-    struct compressor *rcomp;
-    void       *rstate;
-    struct vjcompress vj_comp;
-    int                vj_last_ierrors;
-    struct pppstat stats;
-#ifdef __osf__
-    memreq_t   memreq;
-    thread_t   thread;
-#endif
-} comp_state_t;
-
-
-#ifdef __osf__
-extern task_t first_task;
-#endif
-
-/* Bits in flags are as defined in pppio.h. */
-#define CCP_ERR                (CCP_ERROR | CCP_FATALERROR)
-#define LAST_MOD       0x1000000       /* no ppp modules below us */
-#define DBGLOG         0x2000000       /* log debugging stuff */
-
-#define MAX_IPHDR      128     /* max TCP/IP header size */
-#define MAX_VJHDR      20      /* max VJ compressed header size (?) */
-
-#undef MIN             /* just in case */
-#define MIN(a, b)      ((a) < (b)? (a): (b))
-
-/*
- * List of compressors we know about.
- */
-
-#if DO_BSD_COMPRESS
-extern struct compressor ppp_bsd_compress;
-#endif
-#if DO_DEFLATE
-extern struct compressor ppp_deflate, ppp_deflate_draft;
-#endif
-
-struct compressor *ppp_compressors[] = {
-#if DO_BSD_COMPRESS
-    &ppp_bsd_compress,
-#endif
-#if DO_DEFLATE
-    &ppp_deflate,
-    &ppp_deflate_draft,
-#endif
-    NULL
-};
-
-/*
- * STREAMS module entry points.
- */
-MOD_OPEN(ppp_comp_open)
-{
-    comp_state_t *cp;
-#ifdef __osf__
-    thread_t thread;
-#endif
-
-    if (q->q_ptr == NULL) {
-       cp = (comp_state_t *) ALLOC_SLEEP(sizeof(comp_state_t));
-       if (cp == NULL)
-           OPEN_ERROR(ENOSR);
-       bzero((caddr_t)cp, sizeof(comp_state_t));
-       WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
-       cp->mru = PPP_MRU;
-       cp->mtu = PPP_MTU;
-       cp->xstate = NULL;
-       cp->rstate = NULL;
-       vj_compress_init(&cp->vj_comp, -1);
-#ifdef __osf__
-       if (!(thread = kernel_thread_w_arg(first_task, ppp_comp_alloc, (void *)cp)))
-               OPEN_ERROR(ENOSR);
-       cp->thread = thread;
-#endif
-       ++ppp_comp_count;
-       qprocson(q);
-    }
-    return 0;
-}
-
-MOD_CLOSE(ppp_comp_close)
-{
-    comp_state_t *cp;
-
-    qprocsoff(q);
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp != NULL) {
-       if (cp->xstate != NULL)
-           (*cp->xcomp->comp_free)(cp->xstate);
-       if (cp->rstate != NULL)
-           (*cp->rcomp->decomp_free)(cp->rstate);
-#ifdef __osf__
-       if (!cp->thread)
-           printf("ppp_comp_close: NULL thread!\n");
-       else
-           thread_terminate(cp->thread);
-#endif
-       FREE(cp, sizeof(comp_state_t));
-       q->q_ptr = NULL;
-       OTHERQ(q)->q_ptr = NULL;
-       --ppp_comp_count;
-    }
-    return 0;
-}
-
-#ifdef __osf__
-
-/* thread for calling back to a compressor's memory allocator
- * Needed for Digital UNIX since it's VM can't handle requests
- * for large amounts of memory without blocking.  The thread
- * provides a context in which we can call a memory allocator
- * that may block.
- */
-static void
-ppp_comp_alloc(comp_state_t *cp)
-{
-    int len, cmd;
-    unsigned char *compressor_options;
-    thread_t thread;
-    void *(*comp_allocator)();
-
-
-#if defined(MAJOR_VERSION) && (MAJOR_VERSION <= 2)
-
-    /* In 2.x and earlier the argument gets passed
-     * in the thread structure itself.  Yuck.
-     */
-    thread = current_thread();
-    cp = thread->reply_port;
-    thread->reply_port = PORT_NULL;
-
-#endif
-
-    for (;;) {
-       assert_wait((vm_offset_t)&cp->memreq.thread_status, TRUE);
-       thread_block();
-
-       if (thread_should_halt(current_thread()))
-           thread_halt_self();
-       cmd = cp->memreq.cmd;
-       compressor_options = &cp->memreq.comp_opts[0];
-       len = compressor_options[1];
-       if (cmd == PPPIO_XCOMP) {
-           cp->memreq.returned_mem = cp->xcomp->comp_alloc(compressor_options, len);
-           if (!cp->memreq.returned_mem) {
-               cp->memreq.thread_status = ENOSR;
-           } else {
-               cp->memreq.thread_status = 0;
-           }
-       } else {
-           cp->memreq.returned_mem = cp->rcomp->decomp_alloc(compressor_options, len);
-           if (!cp->memreq.returned_mem) {
-               cp->memreq.thread_status = ENOSR;
-           } else {
-               cp->memreq.thread_status = 0;
-           }
-       }
-    }
-}
-
-#endif /* __osf__ */
-
-/* here's the deal with memory allocation under Digital UNIX.
- * Some other may also benefit from this...
- * We can't ask for huge chunks of memory in a context where
- * the caller can't be put to sleep (like, here.)  The alloc
- * is likely to fail.  Instead we do this: the first time we
- * get called, kick off a thread to do the allocation.  Return
- * immediately to the caller with EAGAIN, as an indication that
- * they should send down the ioctl again.  By the time the
- * second call comes in it's likely that the memory allocation
- * thread will have returned with the requested memory.  We will
- * continue to return EAGAIN however until the thread has completed.
- * When it has, we return zero (and the memory) if the allocator
- * was successful and ENOSR otherwise.
- *
- * Callers of the RCOMP and XCOMP ioctls are encouraged (but not
- * required) to loop for some number of iterations with a small
- * delay in the loop body (for instance a 1/10-th second "sleep"
- * via select.)
- */
-static int
-ppp_comp_wput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    struct iocblk *iop;
-    comp_state_t *cp;
-    int error, len, n;
-    int flags, mask;
-    mblk_t *np;
-    struct compressor **comp;
-    struct ppp_stats *psp;
-    struct ppp_comp_stats *csp;
-    unsigned char *opt_data;
-    int nxslots, nrslots;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_wput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-
-    case M_DATA:
-       putq(q, mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       switch (iop->ioc_cmd) {
-
-       case PPPIO_CFLAGS:
-           /* set/get CCP state */
-           if (iop->ioc_count != 2 * sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_CFLAGS b_cont = 0!\n", cp->unit);
-               break;
-           }
-           flags = ((int *) mp->b_cont->b_rptr)[0];
-           mask = ((int *) mp->b_cont->b_rptr)[1];
-           cp->flags = (cp->flags & ~mask) | (flags & mask);
-           if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
-               if (cp->xstate != NULL) {
-                   (*cp->xcomp->comp_free)(cp->xstate);
-                   cp->xstate = NULL;
-               }
-               if (cp->rstate != NULL) {
-                   (*cp->rcomp->decomp_free)(cp->rstate);
-                   cp->rstate = NULL;
-               }
-               cp->flags &= ~CCP_ISUP;
-           }
-           error = 0;
-           iop->ioc_count = sizeof(int);
-           ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
-           mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
-           break;
-
-       case PPPIO_VJINIT:
-           /*
-            * Initialize VJ compressor/decompressor
-            */
-           if (iop->ioc_count != 2)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_VJINIT b_cont = 0!\n", cp->unit);
-               break;
-           }
-           nxslots = mp->b_cont->b_rptr[0] + 1;
-           nrslots = mp->b_cont->b_rptr[1] + 1;
-           if (nxslots > MAX_STATES || nrslots > MAX_STATES)
-               break;
-           vj_compress_init(&cp->vj_comp, nxslots);
-           cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_XCOMP:
-       case PPPIO_RCOMP:
-           if (iop->ioc_count <= 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_[XR]COMP b_cont = 0!\n", cp->unit);
-               break;
-           }
-           opt_data = mp->b_cont->b_rptr;
-           len = mp->b_cont->b_wptr - opt_data;
-           if (len > iop->ioc_count)
-               len = iop->ioc_count;
-           if (opt_data[1] < 2 || opt_data[1] > len)
-               break;
-           for (comp = ppp_compressors; *comp != NULL; ++comp)
-               if ((*comp)->compress_proto == opt_data[0]) {
-                   /* here's the handler! */
-                   error = 0;
-#ifndef __osf__
-                   if (iop->ioc_cmd == PPPIO_XCOMP) {
-                       /* A previous call may have fetched memory for a compressor
-                        * that's now being retired or reset.  Free it using it's
-                        * mechanism for freeing stuff.
-                        */
-                       if (cp->xstate != NULL) {
-                           (*cp->xcomp->comp_free)(cp->xstate);
-                           cp->xstate = NULL;
-                       }
-                       cp->xcomp = *comp;
-                       cp->xstate = (*comp)->comp_alloc(opt_data, len);
-                       if (cp->xstate == NULL)
-                           error = ENOSR;
-                   } else {
-                       if (cp->rstate != NULL) {
-                           (*cp->rcomp->decomp_free)(cp->rstate);
-                           cp->rstate = NULL;
-                       }
-                       cp->rcomp = *comp;
-                       cp->rstate = (*comp)->decomp_alloc(opt_data, len);
-                       if (cp->rstate == NULL)
-                           error = ENOSR;
-                   }
-#else
-                   if ((error = cp->memreq.thread_status) != EAGAIN)
-                   if (iop->ioc_cmd == PPPIO_XCOMP) {
-                       if (cp->xstate) {
-                           (*cp->xcomp->comp_free)(cp->xstate);
-                           cp->xstate = 0;
-                       }
-                       /* sanity check for compressor options
-                        */
-                       if (sizeof (cp->memreq.comp_opts) < len) {
-                           printf("can't handle options for compressor %d (%d)\n", opt_data[0],
-                               opt_data[1]);
-                           cp->memreq.thread_status = ENOSR;
-                           cp->memreq.returned_mem = 0;
-                       }
-                       /* fill in request for the thread and kick it off
-                        */
-                       if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
-                           bcopy(opt_data, cp->memreq.comp_opts, len);
-                           cp->memreq.cmd = PPPIO_XCOMP;
-                           cp->xcomp = *comp;
-                           error = cp->memreq.thread_status = EAGAIN;
-                           thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
-                       } else {
-                           cp->xstate = cp->memreq.returned_mem;
-                           cp->memreq.returned_mem = 0;
-                           cp->memreq.thread_status = 0;
-                       }
-                   } else {
-                       if (cp->rstate) {
-                           (*cp->rcomp->decomp_free)(cp->rstate);
-                           cp->rstate = NULL;
-                       }
-                       if (sizeof (cp->memreq.comp_opts) < len) {
-                           printf("can't handle options for compressor %d (%d)\n", opt_data[0],
-                               opt_data[1]);
-                           cp->memreq.thread_status = ENOSR;
-                           cp->memreq.returned_mem = 0;
-                       }
-                       if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
-                           bcopy(opt_data, cp->memreq.comp_opts, len);
-                           cp->memreq.cmd = PPPIO_RCOMP;
-                           cp->rcomp = *comp;
-                           error = cp->memreq.thread_status = EAGAIN;
-                           thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
-                       } else {
-                           cp->rstate = cp->memreq.returned_mem;
-                           cp->memreq.returned_mem = 0;
-                           cp->memreq.thread_status = 0;
-                       }
-                   }
-#endif
-                   break;
-               }
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_GETSTAT:
-           if ((cp->flags & LAST_MOD) == 0) {
-               error = -1;     /* let the ppp_ahdl module handle it */
-               break;
-           }
-           np = allocb(sizeof(struct ppp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           psp = (struct ppp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_stats);
-           iop->ioc_count = sizeof(struct ppp_stats);
-           psp->p = cp->stats;
-           psp->vj = cp->vj_comp.stats;
-           error = 0;
-           break;
-
-       case PPPIO_GETCSTAT:
-           np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           csp = (struct ppp_comp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_comp_stats);
-           iop->ioc_count = sizeof(struct ppp_comp_stats);
-           bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
-           if (cp->xstate != 0)
-               (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
-           if (cp->rstate != 0)
-               (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
-           error = 0;
-           break;
-
-       case PPPIO_DEBUG:
-           if (iop->ioc_count != sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_DEBUG b_cont = 0!\n", cp->unit);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n == PPPDBG_LOG + PPPDBG_COMP) {
-               DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
-               cp->flags |= DBGLOG;
-               error = 0;
-               iop->ioc_count = 0;
-           } else {
-               error = -1;
-           }
-           break;
-
-       case PPPIO_LASTMOD:
-           cp->flags |= LAST_MOD;
-           error = 0;
-           break;
-
-       default:
-           error = -1;
-           break;
-       }
-
-       if (error < 0)
-           putnext(q, mp);
-       else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       } else {
-           mp->b_datap->db_type = M_IOCNAK;
-           iop->ioc_error = error;
-           iop->ioc_count = 0;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_CTL:
-       switch (*mp->b_rptr) {
-       case PPPCTL_MTU:
-           cp->mtu = ((unsigned short *)mp->b_rptr)[1];
-           break;
-       case PPPCTL_MRU:
-           cp->mru = ((unsigned short *)mp->b_rptr)[1];
-           break;
-       case PPPCTL_UNIT:
-           cp->unit = mp->b_rptr[1];
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_wsrv(q)
-    queue_t *q;
-{
-    mblk_t *mp, *cmp = NULL;
-    comp_state_t *cp;
-    int len, proto, type, hlen, code;
-    struct ip *ip;
-    unsigned char *vjhdr, *dp;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_wsrv\n");
-       return 0;
-    }
-
-    while ((mp = getq(q)) != 0) {
-       /* assert(mp->b_datap->db_type == M_DATA) */
-#ifdef PRIOQ
-        if (!bcanputnext(q,mp->b_band))
-#else
-        if (!canputnext(q))
-#endif /* PRIOQ */
-       {
-           putbq(q, mp);
-           break;
-       }
-
-       /*
-        * First check the packet length and work out what the protocol is.
-        */
-       len = msgdsize(mp);
-       if (len < PPP_HDRLEN) {
-           DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
-           freemsg(mp);
-           cp->stats.ppp_oerrors++;
-           putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-           continue;
-       }
-       proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
-
-       /*
-        * Make sure we've got enough data in the first mblk
-        * and that we are its only user.
-        */
-       if (proto == PPP_CCP)
-           hlen = len;
-       else if (proto == PPP_IP)
-           hlen = PPP_HDRLEN + MAX_IPHDR;
-       else
-           hlen = PPP_HDRLEN;
-       if (hlen > len)
-           hlen = len;
-       if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
-           PULLUP(mp, hlen);
-           if (mp == 0) {
-               DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
-               cp->stats.ppp_oerrors++;
-               putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-               continue;
-           }
-       }
-
-       /*
-        * Do VJ compression if requested.
-        */
-       if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
-           ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
-           if (ip->ip_p == IPPROTO_TCP) {
-               type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
-                                      (cp->flags & COMP_VJCCID), &vjhdr);
-               switch (type) {
-               case TYPE_UNCOMPRESSED_TCP:
-                   mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
-                   break;
-               case TYPE_COMPRESSED_TCP:
-                   dp = vjhdr - PPP_HDRLEN;
-                   dp[1] = mp->b_rptr[1]; /* copy control field */
-                   dp[0] = mp->b_rptr[0]; /* copy address field */
-                   dp[2] = 0;             /* set protocol field */
-                   dp[3] = proto = PPP_VJC_COMP;
-                   mp->b_rptr = dp;
-                   break;
-               }
-           }
-       }
-
-       /*
-        * Do packet compression if enabled.
-        */
-       if (proto == PPP_CCP)
-           ppp_comp_ccp(q, mp, 0);
-       else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
-                && cp->xstate != NULL) {
-           len = msgdsize(mp);
-           (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
-                       (cp->flags & CCP_ISUP? cp->mtu + PPP_HDRLEN: 0));
-           if (cmp != NULL) {
-#ifdef PRIOQ
-               cmp->b_band=mp->b_band;
-#endif /* PRIOQ */
-               freemsg(mp);
-               mp = cmp;
-           }
-       }
-
-       /*
-        * Do address/control and protocol compression if enabled.
-        */
-       if ((cp->flags & COMP_AC)
-           && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
-           mp->b_rptr += 2;    /* drop the address & ctrl fields */
-           if (proto < 0x100 && (cp->flags & COMP_PROT))
-               ++mp->b_rptr;   /* drop the high protocol byte */
-       } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
-           /* shuffle up the address & ctrl fields */
-           mp->b_rptr[2] = mp->b_rptr[1];
-           mp->b_rptr[1] = mp->b_rptr[0];
-           ++mp->b_rptr;
-       }
-
-       cp->stats.ppp_opackets++;
-       cp->stats.ppp_obytes += msgdsize(mp);
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_rput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    comp_state_t *cp;
-    struct iocblk *iop;
-    struct ppp_stats *psp;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_rput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-
-    case M_DATA:
-       putq(q, mp);
-       break;
-
-    case M_IOCACK:
-       iop = (struct iocblk *) mp->b_rptr;
-       switch (iop->ioc_cmd) {
-       case PPPIO_GETSTAT:
-           /*
-            * Catch this on the way back from the ppp_ahdl module
-            * so we can fill in the VJ stats.
-            */
-           if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
-               break;
-           psp = (struct ppp_stats *) mp->b_cont->b_rptr;
-           psp->vj = cp->vj_comp.stats;
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    case M_CTL:
-       switch (mp->b_rptr[0]) {
-       case PPPCTL_IERROR:
-           ++cp->stats.ppp_ierrors;
-           break;
-       case PPPCTL_OERROR:
-           ++cp->stats.ppp_oerrors;
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_rsrv(q)
-    queue_t *q;
-{
-    int proto, rv, i;
-    mblk_t *mp, *dmp = NULL, *np;
-    uchar_t *dp, *iphdr;
-    comp_state_t *cp;
-    int len, hlen, vjlen;
-    u_int iphlen;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_rsrv\n");
-       return 0;
-    }
-
-    while ((mp = getq(q)) != 0) {
-       /* assert(mp->b_datap->db_type == M_DATA) */
-       if (!canputnext(q)) {
-           putbq(q, mp);
-           break;
-       }
-
-       len = msgdsize(mp);
-       cp->stats.ppp_ibytes += len;
-       cp->stats.ppp_ipackets++;
-
-       /*
-        * First work out the protocol and where the PPP header ends.
-        */
-       i = 0;
-       proto = MSG_BYTE(mp, 0);
-       if (proto == PPP_ALLSTATIONS) {
-           i = 2;
-           proto = MSG_BYTE(mp, 2);
-       }
-       if ((proto & 1) == 0) {
-           ++i;
-           proto = (proto << 8) + MSG_BYTE(mp, i);
-       }
-       hlen = i + 1;
-
-       /*
-        * Now reconstruct a complete, contiguous PPP header at the
-        * start of the packet.
-        */
-       if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
-                  + ((cp->flags & DECOMP_PROT)? 1: 2)) {
-           /* count these? */
-           goto bad;
-       }
-       if (mp->b_rptr + hlen > mp->b_wptr) {
-           adjmsg(mp, hlen);   /* XXX check this call */
-           hlen = 0;
-       }
-       if (hlen != PPP_HDRLEN) {
-           /*
-            * We need to put some bytes on the front of the packet
-            * to make a full-length PPP header.
-            * If we can put them in *mp, we do, otherwise we
-            * tack another mblk on the front.
-            * XXX we really shouldn't need to carry around
-            * the address and control at this stage.
-            */
-           dp = mp->b_rptr + hlen - PPP_HDRLEN;
-           if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
-               np = allocb(PPP_HDRLEN, BPRI_MED);
-               if (np == 0)
-                   goto bad;
-               np->b_cont = mp;
-               mp->b_rptr += hlen;
-               mp = np;
-               dp = mp->b_wptr;
-               mp->b_wptr += PPP_HDRLEN;
-           } else
-               mp->b_rptr = dp;
-
-           dp[0] = PPP_ALLSTATIONS;
-           dp[1] = PPP_UI;
-           dp[2] = proto >> 8;
-           dp[3] = proto;
-       }
-
-       /*
-        * Now see if we have a compressed packet to decompress,
-        * or a CCP packet to take notice of.
-        */
-       proto = PPP_PROTOCOL(mp->b_rptr);
-       if (proto == PPP_CCP) {
-           len = msgdsize(mp);
-           if (mp->b_wptr < mp->b_rptr + len) {
-               PULLUP(mp, len);
-               if (mp == 0)
-                   goto bad;
-           }
-           ppp_comp_ccp(q, mp, 1);
-       } else if (proto == PPP_COMP) {
-           if ((cp->flags & CCP_ISUP)
-               && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
-               && (cp->flags & CCP_ERR) == 0) {
-               rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
-               switch (rv) {
-               case DECOMP_OK:
-                   freemsg(mp);
-                   mp = dmp;
-                   if (mp == NULL) {
-                       /* no error, but no packet returned either. */
-                       continue;
-                   }
-                   break;
-               case DECOMP_ERROR:
-                   cp->flags |= CCP_ERROR;
-                   ++cp->stats.ppp_ierrors;
-                   putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-                   break;
-               case DECOMP_FATALERROR:
-                   cp->flags |= CCP_FATALERROR;
-                   ++cp->stats.ppp_ierrors;
-                   putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-                   break;
-               }
-           }
-       } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
-           (*cp->rcomp->incomp)(cp->rstate, mp);
-       }
-
-       /*
-        * Now do VJ decompression.
-        */
-       proto = PPP_PROTOCOL(mp->b_rptr);
-       if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
-           len = msgdsize(mp) - PPP_HDRLEN;
-           if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
-               goto bad;
-
-           /*
-            * Advance past the ppp header.
-            * Here we assume that the whole PPP header is in the first mblk.
-            */
-           np = mp;
-           dp = np->b_rptr + PPP_HDRLEN;
-           if (dp >= mp->b_wptr) {
-               np = np->b_cont;
-               dp = np->b_rptr;
-           }
-
-           /*
-            * Make sure we have sufficient contiguous data at this point.
-            */
-           hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
-           if (hlen > len)
-               hlen = len;
-           if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
-               PULLUP(mp, hlen + PPP_HDRLEN);
-               if (mp == 0)
-                   goto bad;
-               np = mp;
-               dp = np->b_rptr + PPP_HDRLEN;
-           }
-
-           if (proto == PPP_VJC_COMP) {
-               /*
-                * Decompress VJ-compressed packet.
-                * First reset compressor if an input error has occurred.
-                */
-               if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT1("ppp%d: resetting VJ\n", cp->unit);
-                   vj_uncompress_err(&cp->vj_comp);
-                   cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-               }
-
-               vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
-                                         &cp->vj_comp, &iphdr, &iphlen);
-               if (vjlen < 0) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
-                               cp->unit, len);
-                   ++cp->vj_last_ierrors;  /* so we don't reset next time */
-                   goto bad;
-               }
-
-               /* drop ppp and vj headers off */
-               if (mp != np) {
-                   freeb(mp);
-                   mp = np;
-               }
-               mp->b_rptr = dp + vjlen;
-
-               /* allocate a new mblk for the ppp and ip headers */
-               if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
-                   goto bad;
-               dp = np->b_rptr;        /* prepend mblk with TCP/IP hdr */
-               dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
-               dp[1] = PPP_UI;
-               dp[2] = PPP_IP >> 8;
-               dp[3] = PPP_IP;
-               bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
-               np->b_wptr = dp + iphlen + PPP_HDRLEN;
-               np->b_cont = mp;
-
-               /* XXX there seems to be a bug which causes panics in strread
-                  if we make an mbuf with only the IP header in it :-( */
-               if (mp->b_wptr - mp->b_rptr > 4) {
-                   bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
-                   mp->b_rptr += 4;
-                   np->b_wptr += 4;
-               } else {
-                   bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
-                         mp->b_wptr - mp->b_rptr);
-                   np->b_wptr += mp->b_wptr - mp->b_rptr;
-                   np->b_cont = mp->b_cont;
-                   freeb(mp);
-               }
-
-               mp = np;
-
-           } else {
-               /*
-                * "Decompress" a VJ-uncompressed packet.
-                */
-               cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-               if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
-                               cp->unit, len);
-                   ++cp->vj_last_ierrors;  /* don't need to reset next time */
-                   goto bad;
-               }
-               mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
-           }
-       }
-
-       putnext(q, mp);
-       continue;
-
-    bad:
-       if (mp != 0)
-           freemsg(mp);
-       cp->stats.ppp_ierrors++;
-       putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-    }
-
-    return 0;
-}
-
-/*
- * Handle a CCP packet being sent or received.
- * Here all the data in the packet is in a single mbuf.
- */
-static void
-ppp_comp_ccp(q, mp, rcvd)
-    queue_t *q;
-    mblk_t *mp;
-    int rcvd;
-{
-    int len, clen;
-    comp_state_t *cp;
-    unsigned char *dp;
-
-    len = msgdsize(mp);
-    if (len < PPP_HDRLEN + CCP_HDRLEN)
-       return;
-
-    cp = (comp_state_t *) q->q_ptr;
-    dp = mp->b_rptr + PPP_HDRLEN;
-    len -= PPP_HDRLEN;
-    clen = CCP_LENGTH(dp);
-    if (clen > len)
-       return;
-
-    switch (CCP_CODE(dp)) {
-    case CCP_CONFREQ:
-    case CCP_TERMREQ:
-    case CCP_TERMACK:
-       cp->flags &= ~CCP_ISUP;
-       break;
-
-    case CCP_CONFACK:
-       if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
-           && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
-           && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
-           if (!rcvd) {
-               if (cp->xstate != NULL
-                   && (*cp->xcomp->comp_init)
-                       (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
-                        cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
-                   cp->flags |= CCP_COMP_RUN;
-           } else {
-               if (cp->rstate != NULL
-                   && (*cp->rcomp->decomp_init)
-                       (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
-                        cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
-                   cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
-           }
-       }
-       break;
-
-    case CCP_RESETACK:
-       if (cp->flags & CCP_ISUP) {
-           if (!rcvd) {
-               if (cp->xstate && (cp->flags & CCP_COMP_RUN))
-                   (*cp->xcomp->comp_reset)(cp->xstate);
-           } else {
-               if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
-                   (*cp->rcomp->decomp_reset)(cp->rstate);
-                   cp->flags &= ~CCP_ERROR;
-               }
-           }
-       }
-       break;
-    }
-}
-
-#if 0
-dump_msg(mp)
-    mblk_t *mp;
-{
-    dblk_t *db;
-
-    while (mp != 0) {
-       db = mp->b_datap;
-       DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
-       DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
-       DPRINT2("  base=%x lim=%x", db->db_base, db->db_lim);
-       DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
-       mp = mp->b_cont;
-    }
-}
-#endif
-
-static int
-msg_byte(mp, i)
-    mblk_t *mp;
-    unsigned int i;
-{
-    while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
-       mp = mp->b_cont;
-    if (mp == 0)
-       return -1;
-    return mp->b_rptr[i];
-}
diff --git a/modules/ppp_mod.h b/modules/ppp_mod.h
deleted file mode 100644 (file)
index 792c4d4..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Miscellaneous definitions for PPP STREAMS modules.
- */
-
-/*
- * Macros for allocating and freeing kernel memory.
- */
-#ifdef SVR4                    /* SVR4, including Solaris 2 */
-#include <sys/kmem.h>
-#define ALLOC_SLEEP(n)         kmem_alloc((n), KM_SLEEP)
-#define ALLOC_NOSLEEP(n)       kmem_alloc((n), KM_NOSLEEP)
-#define FREE(p, n)             kmem_free((p), (n))
-#endif
-
-#ifdef SUNOS4
-#include <sys/kmem_alloc.h>    /* SunOS 4.x */
-#define ALLOC_SLEEP(n)         kmem_alloc((n), KMEM_SLEEP)
-#define ALLOC_NOSLEEP(n)       kmem_alloc((n), KMEM_NOSLEEP)
-#define FREE(p, n)             kmem_free((p), (n))
-#define NOTSUSER()             (suser()? 0: EPERM)
-#define bcanputnext(q, band)   canputnext((q))
-#endif /* SunOS 4 */
-
-#ifdef __osf__
-#include <sys/malloc.h>
-
-/* caution: this mirrors macros in sys/malloc.h, and uses interfaces
- * which are subject to change.
- * The problems are that:
- *     - the official MALLOC macro wants the lhs of the assignment as an argument,
- *      and it takes care of the assignment itself (yuck.)
- *     - PPP insists on using "FREE" which conflicts with a macro of the same name.
- *
- */
-#ifdef BUCKETINDX /* V2.0 */
-#define ALLOC_SLEEP(n)         (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_WAITOK)
-#define ALLOC_NOSLEEP(n)       (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_NOWAIT)
-#else
-#define ALLOC_SLEEP(n)         (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_WAITOK)
-#define ALLOC_NOSLEEP(n)       (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_NOWAIT)
-#endif
-
-#define bcanputnext(q, band)   canputnext((q))
-
-#ifdef FREE
-#undef FREE
-#endif
-#define FREE(p, n)             free((void *)(p), M_DEVBUF)
-
-#define NO_DLPI 1
-
-#ifndef IFT_PPP
-#define IFT_PPP 0x17
-#endif
-
-#include <sys/proc.h>
-#define NOTSUSER()             (suser(u.u_procp->p_rcred, &u.u_acflag) ? EPERM : 0)
-
-/* #include "ppp_osf.h" */
-
-#endif /* __osf__ */
-
-#ifdef AIX4
-#define ALLOC_SLEEP(n)         xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
-#define ALLOC_NOSLEEP(n)       xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
-#define FREE(p, n)             xmfree((p), pinned_heap)
-#define NOTSUSER()             (suser()? 0: EPERM)
-#endif /* AIX */
-
-/*
- * Macros for printing debugging stuff.
- */
-#ifdef DEBUG
-#if defined(SVR4) || defined(__osf__)
-#if defined(SNI)
-#include <sys/strlog.h>
-#define STRLOG_ID              4712
-#define DPRINT(f)              strlog(STRLOG_ID, 0, 0, SL_TRACE, f)
-#define DPRINT1(f, a1)         strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1)
-#define DPRINT2(f, a1, a2)     strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2, a3)
-#else
-#define DPRINT(f)              cmn_err(CE_CONT, f)
-#define DPRINT1(f, a1)         cmn_err(CE_CONT, f, a1)
-#define DPRINT2(f, a1, a2)     cmn_err(CE_CONT, f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) cmn_err(CE_CONT, f, a1, a2, a3)
-#endif /* SNI */
-#else
-#define DPRINT(f)              printf(f)
-#define DPRINT1(f, a1)         printf(f, a1)
-#define DPRINT2(f, a1, a2)     printf(f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) printf(f, a1, a2, a3)
-#endif /* SVR4 or OSF */
-
-#else
-#define DPRINT(f)              0
-#define DPRINT1(f, a1)         0
-#define DPRINT2(f, a1, a2)     0
-#define DPRINT3(f, a1, a2, a3) 0
-#endif /* DEBUG */
-
-#ifndef SVR4
-typedef unsigned char uchar_t;
-typedef unsigned short ushort_t;
-#ifndef __osf__
-typedef int minor_t;
-#endif
-#endif
-
-/*
- * If we don't have multithreading support, define substitutes.
- */
-#ifndef D_MP
-# define qprocson(q)
-# define qprocsoff(q)
-# define put(q, mp)    ((*(q)->q_qinfo->qi_putp)((q), (mp)))
-# define canputnext(q) canput((q)->q_next)
-# define qwriter(q, mp, func, scope)   (func)((q), (mp))
-#endif
-
-#ifdef D_MP
-/* Use msgpullup if we have other multithreading support. */
-#define PULLUP(mp, len)                                \
-    do {                                       \
-       mblk_t *np = msgpullup((mp), (len));    \
-       freemsg((mp));                          \
-       mp = np;                                \
-    } while (0)
-
-#else
-/* Use pullupmsg if we don't have any multithreading support. */
-#define PULLUP(mp, len)                        \
-    do {                               \
-       if (!pullupmsg((mp), (len))) {  \
-           freemsg((mp));              \
-           mp = 0;                     \
-       }                               \
-    } while (0)
-#endif
-
-/*
- * How to declare the open and close procedures for a module.
- */
-#ifdef SVR4
-#define MOD_OPEN_DECL(name)    \
-static int name(queue_t *, dev_t *, int, int, cred_t *)
-
-#define MOD_CLOSE_DECL(name)   \
-static int name(queue_t *, int, cred_t *)
-
-#define MOD_OPEN(name)                         \
-static int name(q, devp, flag, sflag, credp)   \
-    queue_t *q;                                        \
-    dev_t *devp;                               \
-    int flag, sflag;                           \
-    cred_t *credp;
-
-#define MOD_CLOSE(name)                \
-static int name(q, flag, credp)        \
-    queue_t *q;                        \
-    int flag;                  \
-    cred_t *credp;
-
-#define OPEN_ERROR(x)          return (x)
-#define DRV_OPEN_OK(dev)       return 0
-
-#define NOTSUSER()             (drv_priv(credp))
-
-#else  /* not SVR4 */
-#define MOD_OPEN_DECL(name)    \
-static int name(queue_t *, int, int, int)
-
-#define MOD_CLOSE_DECL(name)   \
-static int name(queue_t *, int)
-
-#define MOD_OPEN(name)         \
-static int name(q, dev, flag, sflag)   \
-    queue_t *q;                                \
-    int dev;                           \
-    int flag, sflag;
-
-#define MOD_CLOSE(name)                \
-static int name(q, flag)       \
-    queue_t *q;                        \
-    int flag;
-
-#define OPEN_ERROR(x)          { u.u_error = (x); return OPENFAIL; }
-#define DRV_OPEN_OK(dev)       return (dev)
-
-#endif /* SVR4 */
diff --git a/modules/vjcompress.c b/modules/vjcompress.c
deleted file mode 100644 (file)
index 0b17083..0000000
+++ /dev/null
@@ -1,591 +0,0 @@
-/*
- * Routines to compress and uncompess tcp packets (for transmission
- * over low speed serial lines.
- *
- * Copyright (c) 1989 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- *     Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
- *     - Initial distribution.
- *
- * Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au,
- * so that the entire packet being decompressed doesn't have
- * to be in contiguous memory (just the compressed header).
- */
-
-/*
- * This version is used under SunOS 4.x, Digital UNIX, AIX 4.x,
- * and SVR4 systems including Solaris 2.
- *
- * $Id: vjcompress.c,v 1.11 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-
-#ifdef SVR4
-#ifndef __GNUC__
-#include <sys/byteorder.h>     /* for ntohl, etc. */
-#else
-/* make sure we don't get the gnu "fixed" one! */
-#include "/usr/include/sys/byteorder.h"
-#endif
-#endif
-
-#ifdef __osf__
-#include <net/net_globals.h>
-#endif
-#include <netinet/in.h>
-
-#ifdef AIX4
-#define _NETINET_IN_SYSTM_H_
-typedef u_long  n_long;
-#else
-#include <netinet/in_systm.h>
-#endif
-
-#ifdef SOL2
-#include <sys/sunddi.h>
-#endif
-
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-
-#include <net/ppp_defs.h>
-#include <net/vjcompress.h>
-
-#ifndef VJ_NO_STATS
-#define INCR(counter) ++comp->stats.counter
-#else
-#define INCR(counter)
-#endif
-
-#define BCMP(p1, p2, n) bcmp((char *)(p1), (char *)(p2), (int)(n))
-#undef  BCOPY
-#define BCOPY(p1, p2, n) bcopy((char *)(p1), (char *)(p2), (int)(n))
-#ifndef KERNEL
-#define ovbcopy bcopy
-#endif
-
-#ifdef __osf__
-#define getip_hl(base) (((base).ip_vhl)&0xf)
-#define getth_off(base)        ((((base).th_xoff)&0xf0)>>4)
-
-#else
-#define getip_hl(base) ((base).ip_hl)
-#define getth_off(base)        ((base).th_off)
-#endif
-
-void
-vj_compress_init(comp, max_state)
-    struct vjcompress *comp;
-    int max_state;
-{
-    register u_int i;
-    register struct cstate *tstate = comp->tstate;
-
-    if (max_state == -1)
-       max_state = MAX_STATES - 1;
-    bzero((char *)comp, sizeof(*comp));
-    for (i = max_state; i > 0; --i) {
-       tstate[i].cs_id = i;
-       tstate[i].cs_next = &tstate[i - 1];
-    }
-    tstate[0].cs_next = &tstate[max_state];
-    tstate[0].cs_id = 0;
-    comp->last_cs = &tstate[0];
-    comp->last_recv = 255;
-    comp->last_xmit = 255;
-    comp->flags = VJF_TOSS;
-}
-
-
-/* ENCODE encodes a number that is known to be non-zero.  ENCODEZ
- * checks for zero (since zero has to be encoded in the long, 3 byte
- * form).
- */
-#define ENCODE(n) { \
-       if ((u_short)(n) >= 256) { \
-               *cp++ = 0; \
-               cp[1] = (n); \
-               cp[0] = (n) >> 8; \
-               cp += 2; \
-       } else { \
-               *cp++ = (n); \
-       } \
-}
-#define ENCODEZ(n) { \
-       if ((u_short)(n) >= 256 || (u_short)(n) == 0) { \
-               *cp++ = 0; \
-               cp[1] = (n); \
-               cp[0] = (n) >> 8; \
-               cp += 2; \
-       } else { \
-               *cp++ = (n); \
-       } \
-}
-
-#define DECODEL(f) { \
-       if (*cp == 0) {\
-               u_int32_t tmp = ntohl(f) + ((cp[1] << 8) | cp[2]); \
-               (f) = htonl(tmp); \
-               cp += 3; \
-       } else { \
-               u_int32_t tmp = ntohl(f) + (u_int32_t)*cp++; \
-               (f) = htonl(tmp); \
-       } \
-}
-
-#define DECODES(f) { \
-       if (*cp == 0) {\
-               u_short tmp = ntohs(f) + ((cp[1] << 8) | cp[2]); \
-               (f) = htons(tmp); \
-               cp += 3; \
-       } else { \
-               u_short tmp = ntohs(f) + (u_int32_t)*cp++; \
-               (f) = htons(tmp); \
-       } \
-}
-
-#define DECODEU(f) { \
-       if (*cp == 0) {\
-               (f) = htons((cp[1] << 8) | cp[2]); \
-               cp += 3; \
-       } else { \
-               (f) = htons((u_int32_t)*cp++); \
-       } \
-}
-
-u_int
-vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp)
-    register struct ip *ip;
-    u_int mlen;
-    struct vjcompress *comp;
-    int compress_cid;
-    u_char **vjhdrp;
-{
-    register struct cstate *cs = comp->last_cs->cs_next;
-    register u_int hlen = getip_hl(*ip);
-    register struct tcphdr *oth;
-    register struct tcphdr *th;
-    register u_int deltaS, deltaA;
-    register u_int changes = 0;
-    u_char new_seq[16];
-    register u_char *cp = new_seq;
-
-    /*
-     * Bail if this is an IP fragment or if the TCP packet isn't
-     * `compressible' (i.e., ACK isn't set or some other control bit is
-     * set).  (We assume that the caller has already made sure the
-     * packet is IP proto TCP).
-     */
-    if ((ip->ip_off & htons(0x3fff)) || mlen < 40)
-       return (TYPE_IP);
-
-    th = (struct tcphdr *)&((int *)ip)[hlen];
-    if ((th->th_flags & (TH_SYN|TH_FIN|TH_RST|TH_ACK)) != TH_ACK)
-       return (TYPE_IP);
-    /*
-     * Packet is compressible -- we're going to send either a
-     * COMPRESSED_TCP or UNCOMPRESSED_TCP packet.  Either way we need
-     * to locate (or create) the connection state.  Special case the
-     * most recently used connection since it's most likely to be used
-     * again & we don't have to do any reordering if it's used.
-     */
-    INCR(vjs_packets);
-    if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr ||
-       ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr ||
-       *(int *)th != ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) {
-       /*
-        * Wasn't the first -- search for it.
-        *
-        * States are kept in a circularly linked list with
-        * last_cs pointing to the end of the list.  The
-        * list is kept in lru order by moving a state to the
-        * head of the list whenever it is referenced.  Since
-        * the list is short and, empirically, the connection
-        * we want is almost always near the front, we locate
-        * states via linear search.  If we don't find a state
-        * for the datagram, the oldest state is (re-)used.
-        */
-       register struct cstate *lcs;
-       register struct cstate *lastcs = comp->last_cs;
-
-       do {
-           lcs = cs; cs = cs->cs_next;
-           INCR(vjs_searches);
-           if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr
-               && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr
-               && *(int *)th == ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)])
-               goto found;
-       } while (cs != lastcs);
-
-       /*
-        * Didn't find it -- re-use oldest cstate.  Send an
-        * uncompressed packet that tells the other side what
-        * connection number we're using for this conversation.
-        * Note that since the state list is circular, the oldest
-        * state points to the newest and we only need to set
-        * last_cs to update the lru linkage.
-        */
-       INCR(vjs_misses);
-       comp->last_cs = lcs;
-       hlen += getth_off(*th);
-       hlen <<= 2;
-       if (hlen > mlen)
-           return (TYPE_IP);
-       goto uncompressed;
-
-    found:
-       /*
-        * Found it -- move to the front on the connection list.
-        */
-       if (cs == lastcs)
-           comp->last_cs = lcs;
-       else {
-           lcs->cs_next = cs->cs_next;
-           cs->cs_next = lastcs->cs_next;
-           lastcs->cs_next = cs;
-       }
-    }
-
-    /*
-     * Make sure that only what we expect to change changed. The first
-     * line of the `if' checks the IP protocol version, header length &
-     * type of service.  The 2nd line checks the "Don't fragment" bit.
-     * The 3rd line checks the time-to-live and protocol (the protocol
-     * check is unnecessary but costless).  The 4th line checks the TCP
-     * header length.  The 5th line checks IP options, if any.  The 6th
-     * line checks TCP options, if any.  If any of these things are
-     * different between the previous & current datagram, we send the
-     * current datagram `uncompressed'.
-     */
-    oth = (struct tcphdr *)&((int *)&cs->cs_ip)[hlen];
-    deltaS = hlen;
-    hlen += getth_off(*th);
-    hlen <<= 2;
-    if (hlen > mlen)
-       return (TYPE_IP);
-
-    if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0] ||
-       ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3] ||
-       ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4] ||
-       getth_off(*th) != getth_off(*oth) ||
-       (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) ||
-       (getth_off(*th) > 5 && BCMP(th + 1, oth + 1, (getth_off(*th) - 5) << 2)))
-       goto uncompressed;
-
-    /*
-     * Figure out which of the changing fields changed.  The
-     * receiver expects changes in the order: urgent, window,
-     * ack, seq (the order minimizes the number of temporaries
-     * needed in this section of code).
-     */
-    if (th->th_flags & TH_URG) {
-       deltaS = ntohs(th->th_urp);
-       ENCODEZ(deltaS);
-       changes |= NEW_U;
-    } else if (th->th_urp != oth->th_urp)
-       /* argh! URG not set but urp changed -- a sensible
-        * implementation should never do this but RFC793
-        * doesn't prohibit the change so we have to deal
-        * with it. */
-       goto uncompressed;
-
-    if ((deltaS = (u_short)(ntohs(th->th_win) - ntohs(oth->th_win))) > 0) {
-       ENCODE(deltaS);
-       changes |= NEW_W;
-    }
-
-    if ((deltaA = ntohl(th->th_ack) - ntohl(oth->th_ack)) > 0) {
-       if (deltaA > 0xffff)
-           goto uncompressed;
-       ENCODE(deltaA);
-       changes |= NEW_A;
-    }
-
-    if ((deltaS = ntohl(th->th_seq) - ntohl(oth->th_seq)) > 0) {
-       if (deltaS > 0xffff)
-           goto uncompressed;
-       ENCODE(deltaS);
-       changes |= NEW_S;
-    }
-
-    switch(changes) {
-
-    case 0:
-       /*
-        * Nothing changed. If this packet contains data and the
-        * last one didn't, this is probably a data packet following
-        * an ack (normal on an interactive connection) and we send
-        * it compressed.  Otherwise it's probably a retransmit,
-        * retransmitted ack or window probe.  Send it uncompressed
-        * in case the other side missed the compressed version.
-        */
-       if (ip->ip_len != cs->cs_ip.ip_len &&
-           ntohs(cs->cs_ip.ip_len) == hlen)
-           break;
-
-       /* (fall through) */
-
-    case SPECIAL_I:
-    case SPECIAL_D:
-       /*
-        * actual changes match one of our special case encodings --
-        * send packet uncompressed.
-        */
-       goto uncompressed;
-
-    case NEW_S|NEW_A:
-       if (deltaS == deltaA && deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
-           /* special case for echoed terminal traffic */
-           changes = SPECIAL_I;
-           cp = new_seq;
-       }
-       break;
-
-    case NEW_S:
-       if (deltaS == ntohs(cs->cs_ip.ip_len) - hlen) {
-           /* special case for data xfer */
-           changes = SPECIAL_D;
-           cp = new_seq;
-       }
-       break;
-    }
-
-    deltaS = ntohs(ip->ip_id) - ntohs(cs->cs_ip.ip_id);
-    if (deltaS != 1) {
-       ENCODEZ(deltaS);
-       changes |= NEW_I;
-    }
-    if (th->th_flags & TH_PUSH)
-       changes |= TCP_PUSH_BIT;
-    /*
-     * Grab the cksum before we overwrite it below.  Then update our
-     * state with this packet's header.
-     */
-    deltaA = ntohs(th->th_sum);
-    BCOPY(ip, &cs->cs_ip, hlen);
-
-    /*
-     * We want to use the original packet as our compressed packet.
-     * (cp - new_seq) is the number of bytes we need for compressed
-     * sequence numbers.  In addition we need one byte for the change
-     * mask, one for the connection id and two for the tcp checksum.
-     * So, (cp - new_seq) + 4 bytes of header are needed.  hlen is how
-     * many bytes of the original packet to toss so subtract the two to
-     * get the new packet size.
-     */
-    deltaS = cp - new_seq;
-    cp = (u_char *)ip;
-    if (compress_cid == 0 || comp->last_xmit != cs->cs_id) {
-       comp->last_xmit = cs->cs_id;
-       hlen -= deltaS + 4;
-       *vjhdrp = (cp += hlen);
-       *cp++ = changes | NEW_C;
-       *cp++ = cs->cs_id;
-    } else {
-       hlen -= deltaS + 3;
-       *vjhdrp = (cp += hlen);
-       *cp++ = changes;
-    }
-    *cp++ = deltaA >> 8;
-    *cp++ = deltaA;
-    BCOPY(new_seq, cp, deltaS);
-    INCR(vjs_compressed);
-    return (TYPE_COMPRESSED_TCP);
-
-    /*
-     * Update connection state cs & send uncompressed packet (that is,
-     * a regular ip/tcp packet but with the 'conversation id' we hope
-     * to use on future compressed packets in the protocol field).
-     */
- uncompressed:
-    BCOPY(ip, &cs->cs_ip, hlen);
-    ip->ip_p = cs->cs_id;
-    comp->last_xmit = cs->cs_id;
-    return (TYPE_UNCOMPRESSED_TCP);
-}
-
-/*
- * Called when we may have missed a packet.
- */
-void
-vj_uncompress_err(comp)
-    struct vjcompress *comp;
-{
-    comp->flags |= VJF_TOSS;
-    INCR(vjs_errorin);
-}
-
-/*
- * "Uncompress" a packet of type TYPE_UNCOMPRESSED_TCP.
- */
-int
-vj_uncompress_uncomp(buf, buflen, comp)
-    u_char *buf;
-    int buflen;
-    struct vjcompress *comp;
-{
-    register u_int hlen;
-    register struct cstate *cs;
-    register struct ip *ip;
-
-    ip = (struct ip *) buf;
-    hlen = getip_hl(*ip) << 2;
-    if (ip->ip_p >= MAX_STATES
-       || hlen + sizeof(struct tcphdr) > buflen
-       || (hlen += getth_off(*((struct tcphdr *)&((char *)ip)[hlen])) << 2)
-           > buflen
-       || hlen > MAX_HDR) {
-       comp->flags |= VJF_TOSS;
-       INCR(vjs_errorin);
-       return (0);
-    }
-    cs = &comp->rstate[comp->last_recv = ip->ip_p];
-    comp->flags &=~ VJF_TOSS;
-    ip->ip_p = IPPROTO_TCP;
-    BCOPY(ip, &cs->cs_ip, hlen);
-    cs->cs_hlen = hlen;
-    INCR(vjs_uncompressedin);
-    return (1);
-}
-
-/*
- * Uncompress a packet of type TYPE_COMPRESSED_TCP.
- * The packet starts at buf and is of total length total_len.
- * The first buflen bytes are at buf; this must include the entire
- * compressed TCP/IP header.  This procedure returns the length
- * of the VJ header, with a pointer to the uncompressed IP header
- * in *hdrp and its length in *hlenp.
- */
-int
-vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp)
-    u_char *buf;
-    int buflen, total_len;
-    struct vjcompress *comp;
-    u_char **hdrp;
-    u_int *hlenp;
-{
-    register u_char *cp;
-    register u_int hlen, changes;
-    register struct tcphdr *th;
-    register struct cstate *cs;
-    register u_short *bp;
-    register u_int vjlen;
-    register u_int32_t tmp;
-
-    INCR(vjs_compressedin);
-    cp = buf;
-    changes = *cp++;
-    if (changes & NEW_C) {
-       /* Make sure the state index is in range, then grab the state.
-        * If we have a good state index, clear the 'discard' flag. */
-       if (*cp >= MAX_STATES)
-           goto bad;
-
-       comp->flags &=~ VJF_TOSS;
-       comp->last_recv = *cp++;
-    } else {
-       /* this packet has an implicit state index.  If we've
-        * had a line error since the last time we got an
-        * explicit state index, we have to toss the packet. */
-       if (comp->flags & VJF_TOSS) {
-           INCR(vjs_tossed);
-           return (-1);
-       }
-    }
-    cs = &comp->rstate[comp->last_recv];
-    hlen = getip_hl(cs->cs_ip) << 2;
-    th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen];
-    th->th_sum = htons((*cp << 8) | cp[1]);
-    cp += 2;
-    if (changes & TCP_PUSH_BIT)
-       th->th_flags |= TH_PUSH;
-    else
-       th->th_flags &=~ TH_PUSH;
-
-    switch (changes & SPECIALS_MASK) {
-    case SPECIAL_I:
-       {
-           register u_int32_t i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
-           /* some compilers can't nest inline assembler.. */
-           tmp = ntohl(th->th_ack) + i;
-           th->th_ack = htonl(tmp);
-           tmp = ntohl(th->th_seq) + i;
-           th->th_seq = htonl(tmp);
-       }
-       break;
-
-    case SPECIAL_D:
-       /* some compilers can't nest inline assembler.. */
-       tmp = ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len) - cs->cs_hlen;
-       th->th_seq = htonl(tmp);
-       break;
-
-    default:
-       if (changes & NEW_U) {
-           th->th_flags |= TH_URG;
-           DECODEU(th->th_urp);
-       } else
-           th->th_flags &=~ TH_URG;
-       if (changes & NEW_W)
-           DECODES(th->th_win);
-       if (changes & NEW_A)
-           DECODEL(th->th_ack);
-       if (changes & NEW_S)
-           DECODEL(th->th_seq);
-       break;
-    }
-    if (changes & NEW_I) {
-       DECODES(cs->cs_ip.ip_id);
-    } else {
-       cs->cs_ip.ip_id = ntohs(cs->cs_ip.ip_id) + 1;
-       cs->cs_ip.ip_id = htons(cs->cs_ip.ip_id);
-    }
-
-    /*
-     * At this point, cp points to the first byte of data in the
-     * packet.  Fill in the IP total length and update the IP
-     * header checksum.
-     */
-    vjlen = cp - buf;
-    buflen -= vjlen;
-    if (buflen < 0)
-       /* we must have dropped some characters (crc should detect
-        * this but the old slip framing won't) */
-       goto bad;
-
-    total_len += cs->cs_hlen - vjlen;
-    cs->cs_ip.ip_len = htons(total_len);
-
-    /* recompute the ip header checksum */
-    bp = (u_short *) &cs->cs_ip;
-    cs->cs_ip.ip_sum = 0;
-    for (changes = 0; hlen > 0; hlen -= 2)
-       changes += *bp++;
-    changes = (changes & 0xffff) + (changes >> 16);
-    changes = (changes & 0xffff) + (changes >> 16);
-    cs->cs_ip.ip_sum = ~ changes;
-
-    *hdrp = (u_char *) &cs->cs_ip;
-    *hlenp = cs->cs_hlen;
-    return vjlen;
-
- bad:
-    comp->flags |= VJF_TOSS;
-    INCR(vjs_errorin);
-    return (-1);
-}
index 566600304fb731b8da93db3a2abfc24954637806..895bf37c7e6a273dde48cbf182fe93281e7a3caa 100644 (file)
@@ -1 +1,2 @@
 pppd
+srp-entry
index 7dc6cdd33e5456b070974896163b6185265c6136..93dbeedb3c282a8e3e4b9a59ee0019da7fa5bf51 100644 (file)
@@ -2,7 +2,7 @@ sbin_PROGRAMS = pppd
 dist_man8_MANS = pppd.8
 check_PROGRAMS =
 
-utest_chap_SOURCES = chap_ms.c pppcrypt.c utils.c
+utest_chap_SOURCES = chap_ms.c utils.c crypto_ms.c
 utest_chap_CPPFLAGS = -DUNIT_TEST
 utest_chap_LDFLAGS =
 
@@ -10,9 +10,24 @@ utest_peap_SOURCES = peap.c utils.c mppe.c
 utest_peap_CPPFLAGS = -DUNIT_TEST
 utest_peap_LDFLAGS =
 
+utest_crypto_SOURCES = crypto.c utils.c
+utest_crypto_CPPFLAGS = -DUNIT_TEST
+utest_crypto_LDFLAGS =
+
+utest_pppcrypt_SOURCES = crypto_ms.c
+utest_pppcrypt_CPPFLAGS = -DUNIT_TEST_MSCRYPTO
+utest_pppcrypt_LDFLAGS =
+
+check_PROGRAMS += utest_crypto
+
+utest_utils_SOURCES = utils.c utils_utest.c
+utest_utils_CPPFLAGS = -DUNIT_TEST
+utest_utils_LDFLAGS =
+
+check_PROGRAMS += utest_utils
+
 if WITH_SRP
 sbin_PROGRAMS += srp-entry
-dist_man8_MANS += srp-entry.8
 endif
 
 pkgconfigdir   = $(libdir)/pkgconfig
@@ -22,11 +37,11 @@ pppd_includedir = $(includedir)/pppd
 pppd_include_HEADERS = \
     cbcp.h \
     ccp.h \
-    chap-md5.h \
+    chap.h \
     chap_ms.h \
-    chap-new.h \
+    crypto.h \
+    crypto_ms.h \
     eap.h \
-    eap-tls.h \
     ecp.h \
     eui64.h \
     fsm.h \
@@ -34,26 +49,31 @@ pppd_include_HEADERS = \
     ipv6cp.h \
     lcp.h \
     magic.h \
-    md4.h \
-    md5.h \
     mppe.h \
-    pathnames.h \
-    peap.h \
-    pppcrypt.h \
+    multilink.h \
     pppd.h \
+    options.h \
     pppdconf.h \
     session.h \
-    sha1.h \
+    upap.h 
+
+# Headers to be distributed, but not installed in /usr/include/pppd
+noinst_HEADERS = \
+    chap-md5.h \
+    crypto-priv.h \
+    eap-tls.h \
+    pathnames.h \
+    peap.h \
+    pppd-private.h \
     spinlock.h \
     tls.h \
-    tdb.h \
-    upap.h 
+    tdb.h
 
 pppd_SOURCES = \
     auth.c \
     ccp.c \
     chap-md5.c \
-    chap-new.c \
+    chap.c \
     demand.c \
     eap.c \
     ecp.c \
@@ -68,12 +88,21 @@ pppd_SOURCES = \
     upap.c \
     utils.c
 
-pppd_CPPFLAGS = -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"'
+# Things produced by the build process, to be installed but not distributed
+BUILT_SOURCE = \
+    pppdconf.h
+
+pppd_CPPFLAGS = -DSYSCONFDIR=\"${sysconfdir}\" -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"'
 pppd_LDFLAGS =
 pppd_LIBS =
 
+if PPP_WITH_SYSTEM_CA_PATH
+pppd_CPPFLAGS += -DSYSTEM_CA_PATH='"@SYSTEM_CA_PATH@"'
+endif
+
 if LINUX
-pppd_SOURCES += sys-linux.c termios_linux.h
+pppd_SOURCES += sys-linux.c
+noinst_HEADERS += termios_linux.h
 pppd_LIBS += $(CRYPT_LIBS) $(UTIL_LIBS)
 endif
 
@@ -84,12 +113,13 @@ pppd_LIBS += -lsocket -lnsl
 endif
 
 if PPP_WITH_CHAPMS
-pppd_SOURCES += chap_ms.c
-pppd_SOURCES += pppcrypt.c
+pppd_SOURCES += chap_ms.c crypto_ms.c
 check_PROGRAMS += utest_chap
+check_PROGRAMS += utest_pppcrypt
 else
 if WITH_SRP
-pppd_SOURCES += pppcrypt.c
+pppd_SOURCES += crypto_ms.c
+check_PROGRAMS += utest_pppcrypt
 endif
 endif
 
@@ -146,29 +176,23 @@ pppd_SOURCES += peap.c
 check_PROGRAMS += utest_peap
 endif
 
-noinst_LTLIBRARIES = libppp_crypt.la
-libppp_crypt_la_SOURCES=
+noinst_LTLIBRARIES = libppp_crypto.la
+libppp_crypto_la_SOURCES=crypto.c ppp-md5.c ppp-md4.c ppp-sha1.c ppp-des.c
 
-if !WITH_OPENSSL
-libppp_crypt_la_SOURCES += md4.c md5.c sha1.c
-else
-libppp_crypt_la_CPPFLAGS=$(OPENSSL_INCLUDES)
-libppp_crypt_la_LDFLAGS=$(OPENSSL_LDFLAGS)
-libppp_crypt_la_LIBADD=$(OPENSSL_LIBS)
-if !OPENSSL_HAVE_SHA
-libppp_crypt_la_SOURCES += sha1.c
-endif
-if !OPENSSL_HAVE_MD5
-libppp_crypt_la_SOURCES += md5.c
-endif
-if !OPENSSL_HAVE_MD4
-libppp_crypt_la_SOURCES += md4.c
-endif
+if PPP_WITH_OPENSSL
+pppd_CPPFLAGS += $(OPENSSL_INCLUDES)
+
+libppp_crypto_la_CPPFLAGS=$(OPENSSL_INCLUDES)
+libppp_crypto_la_LDFLAGS=$(OPENSSL_LDFLAGS)
+libppp_crypto_la_LIBADD=$(OPENSSL_LIBS)
 endif
 
-utest_peap_LDADD = libppp_crypt.la
-utest_chap_LDADD = libppp_crypt.la
-pppd_LIBS += libppp_crypt.la
+utest_peap_LDADD = libppp_crypto.la
+utest_chap_LDADD = libppp_crypto.la
+utest_crypto_LDADD = libppp_crypto.la
+utest_pppcrypt_LDADD = libppp_crypto.la
+
+pppd_LIBS += libppp_crypto.la
 
 if WITH_SYSTEMD
 pppd_CPPFLAGS += $(SYSTEMD_CFLAGS)
@@ -180,6 +204,7 @@ srp_entry_SOURCES = srp-entry.c
 srp_entry_CPPFLAGS = $(OPENSSL_INCLUDES) $(SRP_CFLAGS)
 srp_entry_LDADD = $(SRP_LIBS) $(OPENSSL_LIBS)
 srp_entry_LDFLAGS = $(OPENSSL_LDFLAGS) $(SRP_LDFLAGS)
+dist_srp_entry_MANS = srp-entry.8
 
 pppd_CPPFLAGS += $(SRP_CFLAGS)
 pppd_LDFLAGS += $(SRP_LDFLAGS)
@@ -189,7 +214,8 @@ endif
 pppd_LDADD = $(pppd_LIBS)
 
 EXTRA_DIST = \
-    ppp.pam
+    ppp.pam \
+    srp-entry.8
 
 TESTS = $(check_PROGRAMS)
 
index fc2839009c35d0c76836d15f3ece65208b4bf9c9..a78a697920f435da14e91d34aead7e76deb17058 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * auth.c - PPP authentication and phase control.
  *
- * Copyright (c) 1993-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1993-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -68,8 +64,6 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: auth.c,v 1.117 2008/07/01 12:27:56 paulus Exp $"
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -83,6 +77,7 @@
 #include <grp.h>
 #include <string.h>
 #include <strings.h>
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <systemd/sd-daemon.h>
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "ccp.h"
 #include "ecp.h"
 #include "ipcp.h"
 #include "upap.h"
-#include "chap-new.h"
+#include "chap.h"
 #include "eap.h"
 #ifdef PPP_WITH_EAPTLS
 #include "eap-tls.h"
 #ifdef PPP_WITH_CBCP
 #include "cbcp.h"
 #endif
+#include "multilink.h"
 #include "pathnames.h"
 #include "session.h"
 
@@ -179,28 +176,26 @@ static bool default_auth;
 int (*idle_time_hook)(struct ppp_idle *) = NULL;
 
 /* Hook for a plugin to say whether we can possibly authenticate any peer */
-int (*pap_check_hook)(void) = NULL;
+pap_check_hook_fn *pap_check_hook = NULL;
 
 /* Hook for a plugin to check the PAP user and password */
-int (*pap_auth_hook)(char *user, char *passwd, char **msgp,
-                    struct wordlist **paddrs,
-                    struct wordlist **popts) = NULL;
+pap_auth_hook_fn *pap_auth_hook = NULL;
 
 /* Hook for a plugin to know about the PAP user logout */
-void (*pap_logout_hook)(void) = NULL;
+pap_logout_hook_fn *pap_logout_hook = NULL;
 
 /* Hook for a plugin to get the PAP password for authenticating us */
-int (*pap_passwd_hook)(char *user, char *passwd) = NULL;
+pap_passwd_hook_fn *pap_passwd_hook = NULL;
 
 /* Hook for a plugin to say if we can possibly authenticate a peer using CHAP */
-int (*chap_check_hook)(void) = NULL;
+chap_check_hook_fn *chap_check_hook = NULL;
 
 /* Hook for a plugin to get the CHAP password for authenticating us */
-int (*chap_passwd_hook)(char *user, char *passwd) = NULL;
+chap_passwd_hook_fn *chap_passwd_hook = NULL;
 
 #ifdef PPP_WITH_EAPTLS
 /* Hook for a plugin to get the EAP-TLS password for authenticating us */
-int (*eaptls_passwd_hook)(char *user, char *passwd) = NULL;
+eaptls_passwd_hook_fn *eaptls_passwd_hook = NULL;
 #endif
 
 /* Hook for a plugin to say whether it is OK if the peer
@@ -210,11 +205,6 @@ int (*null_auth_hook)(struct wordlist **paddrs,
 
 int (*allowed_address_hook)(u_int32_t addr) = NULL;
 
-#ifdef PPP_WITH_MULTILINK
-/* Hook for plugin to hear when an interface joins a multilink bundle */
-void (*multilink_join_hook)(void) = NULL;
-#endif
-
 /* A notifier for when the peer has authenticated itself,
    and we are proceeding to the network phase. */
 struct notifier *auth_up_notifier = NULL;
@@ -258,6 +248,8 @@ bool explicit_remote = 0;   /* User specified explicit remote name */
 bool explicit_user = 0;                /* Set if "user" option supplied */
 bool explicit_passwd = 0;      /* Set if "password" option supplied */
 char remote_name[MAXNAMELEN];  /* Peer's name for authentication */
+char path_upapfile[MAXPATHLEN];        /* Pathname of pap-secrets file */
+char path_chapfile[MAXPATHLEN];        /* Pathname of chap-secrets file */
 
 #if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
 char *cacert_file  = NULL;  /* CA certificate file (pem format) */
@@ -322,7 +314,7 @@ static void check_maxoctets (void *);
 /*
  * Authentication-related options.
  */
-option_t auth_options[] = {
+struct option auth_options[] = {
     { "auth", o_bool, &auth_required,
       "Require authentication from peer", OPT_PRIO | 1 },
     { "noauth", o_bool, &auth_required,
@@ -422,6 +414,14 @@ option_t auth_options[] = {
       "Set remote name for authentication", OPT_PRIO | OPT_STATIC,
       &explicit_remote, MAXNAMELEN },
 
+    { "pap-secrets", o_string, path_upapfile,
+      "Set pathname of pap-secrets", OPT_PRIO | OPT_PRIV | OPT_STATIC,
+      NULL, MAXPATHLEN },
+
+    { "chap-secrets", o_string, path_chapfile,
+      "Set pathname of chap-secrets", OPT_PRIO | OPT_PRIV | OPT_STATIC,
+      NULL, MAXPATHLEN },
+
     { "login", o_bool, &uselogin,
       "Use system password database for PAP", OPT_A2COPY | 1 ,
       &session_mgmt },
@@ -469,6 +469,37 @@ option_t auth_options[] = {
     { NULL }
 };
 
+const char *
+ppp_remote_name()
+{
+    return remote_name;
+}
+
+const char *
+ppp_get_remote_number(void)
+{
+    return remote_number;
+}
+
+void
+ppp_set_remote_number(const char *buf)
+{
+    if (buf) {
+        strlcpy(remote_number, buf, sizeof(remote_number));
+        ppp_script_setenv("REMOTENUMBER", remote_number, 0);
+    }
+}
+
+const char *
+ppp_peer_authname(char *buf, size_t bufsz)
+{
+    if (buf && bufsz > 0) {
+        strlcpy(buf, peer_authname, bufsz);
+        return buf;
+    }
+    return peer_authname;
+}
+
 /*
  * setupapfile - specifies UPAP info for authenticating with peer.
  */
@@ -489,7 +520,7 @@ setupapfile(char **argv)
        novm("+ua file name");
     euid = geteuid();
     if (seteuid(getuid()) == -1) {
-       option_error("unable to reset uid before opening %s: %m", fname);
+       ppp_option_error("unable to reset uid before opening %s: %m", fname);
         free(fname);
        return 0;
     }
@@ -497,7 +528,7 @@ setupapfile(char **argv)
     if (seteuid(euid) == -1)
        fatal("unable to regain privileges: %m");
     if (ufile == NULL) {
-       option_error("unable to open user login data file %s", fname);
+       ppp_option_error("unable to open user login data file %s", fname);
         free(fname);
        return 0;
     }
@@ -508,7 +539,7 @@ setupapfile(char **argv)
     if (fgets(u, MAXNAMELEN - 1, ufile) == NULL
        || fgets(p, MAXSECRETLEN - 1, ufile) == NULL) {
        fclose(ufile);
-       option_error("unable to read user login data file %s", fname);
+       ppp_option_error("unable to read user login data file %s", fname);
         free(fname);
        return 0;
     }
@@ -547,7 +578,7 @@ privgroup(char **argv)
 
     g = getgrnam(*argv);
     if (g == 0) {
-       option_error("group %s is unknown", *argv);
+       ppp_option_error("group %s is unknown", *argv);
        return 0;
     }
     for (i = 0; i < ngroups; ++i) {
@@ -616,7 +647,7 @@ link_required(int unit)
  */
 void start_link(int unit)
 {
-    status = EXIT_CONNECT_FAILED;
+    ppp_set_status(EXIT_CONNECT_FAILED);
     new_phase(PHASE_SERIALCONN);
 
     hungup = 0;
@@ -634,7 +665,7 @@ void start_link(int unit)
      */
     fd_ppp = the_channel->establish_ppp(devfd);
     if (fd_ppp < 0) {
-       status = EXIT_FATAL_ERROR;
+       ppp_set_status(EXIT_FATAL_ERROR);
        goto disconnect;
     }
 
@@ -646,12 +677,12 @@ void start_link(int unit)
      * incoming events (reply, timeout, etc.).
      */
     if (ifunit >= 0)
-       notice("Connect: %s <--> %s", ifname, ppp_devnam);
+       notice("Connect: %s <--> %s", ifname, ppp_devname);
     else
-       notice("Starting negotiation on %s", ppp_devnam);
+       notice("Starting negotiation on %s", ppp_devname);
     add_fd(fd_ppp);
 
-    status = EXIT_NEGOTIATION_FAILED;
+    ppp_set_status(EXIT_NEGOTIATION_FAILED);
     new_phase(PHASE_ESTABLISH);
 
     lcp_lowerup(0);
@@ -675,7 +706,7 @@ void start_link(int unit)
 void
 link_terminated(int unit)
 {
-    if (phase == PHASE_DEAD || phase == PHASE_MASTER)
+    if (in_phase(PHASE_DEAD) || in_phase(PHASE_MASTER))
        return;
     new_phase(PHASE_DISCONNECT);
 
@@ -684,7 +715,7 @@ link_terminated(int unit)
     }
     session_end(devnam);
 
-    if (!doing_multilink) {
+    if (!mp_on()) {
        notice("Connection terminated.");
        print_link_stats();
     } else
@@ -695,9 +726,8 @@ link_terminated(int unit)
      * can happen that another pppd gets the same unit and then
      * we delete its pid file.
      */
-    if (!doing_multilink && !demand)
+    if (!demand && !mp_on())
        remove_pidfiles();
-
     /*
      * If we may want to bring the link up again, transfer
      * the ppp unit back to the loopback.  Set the
@@ -707,14 +737,14 @@ link_terminated(int unit)
        remove_fd(fd_ppp);
        clean_check();
        the_channel->disestablish_ppp(devfd);
-       if (doing_multilink)
+       if (mp_on())
            mp_exit_bundle();
        fd_ppp = -1;
     }
     if (!hungup)
        lcp_lowerdown(0);
-    if (!doing_multilink && !demand)
-       script_unsetenv("IFNAME");
+    if (!mp_on() && !demand)
+       ppp_script_unsetenv("IFNAME");
 
     /*
      * Run disconnector script, if requested.
@@ -727,7 +757,7 @@ link_terminated(int unit)
     if (the_channel->cleanup)
        (*the_channel->cleanup)();
 
-    if (doing_multilink && multilink_master) {
+    if (mp_on() && mp_master()) {
        if (!bundle_terminating) {
            new_phase(PHASE_MASTER);
            if (master_detach && !detached)
@@ -748,14 +778,15 @@ link_down(int unit)
        notify(link_down_notifier, 0);
        auth_state = s_down;
        if (auth_script_state == s_up && auth_script_pid == 0) {
-           update_link_stats(unit);
+           ppp_get_link_stats(NULL);
            auth_script_state = s_down;
-           auth_script(_PATH_AUTHDOWN);
+           auth_script(PPP_PATH_AUTHDOWN);
        }
     }
-    if (!doing_multilink) {
+    if (!mp_on())
+    {
        upper_layers_down(unit);
-       if (phase != PHASE_DEAD && phase != PHASE_MASTER)
+       if (!in_phase(PHASE_DEAD) && !in_phase(PHASE_MASTER))
            new_phase(PHASE_ESTABLISH);
     }
     /* XXX if doing_multilink, should do something to stop
@@ -799,13 +830,11 @@ link_established(int unit)
     /*
      * Tell higher-level protocols that LCP is up.
      */
-    if (!doing_multilink) {
+    if (!mp_on())
        for (i = 0; (protp = protocols[i]) != NULL; ++i)
            if (protp->protocol != PPP_LCP && protp->enabled_flag
                && protp->lowerup != NULL)
                (*protp->lowerup)(unit);
-    }
-
     if (!auth_required && noauth_addrs != NULL)
        set_allowed_addrs(unit, NULL, NULL);
 
@@ -821,7 +850,7 @@ link_established(int unit)
            set_allowed_addrs(unit, NULL, NULL);
        } else if (!wo->neg_upap || uselogin || !null_login(unit)) {
            warn("peer refused to authenticate: terminating link");
-           status = EXIT_PEER_AUTH_FAILED;
+           ppp_set_status(EXIT_PEER_AUTH_FAILED);
            lcp_close(unit, "peer refused to authenticate");
            return;
        }
@@ -831,14 +860,14 @@ link_established(int unit)
     if (need_peer_eap && !ao->neg_eap) {
        warn("eap required to authenticate us but no suitable secrets");
        lcp_close(unit, "couldn't negotiate eap");
-       status = EXIT_AUTH_TOPEER_FAILED;
+       ppp_set_status(EXIT_AUTH_TOPEER_FAILED);
        return;
     }
 
     if (need_peer_eap && !ho->neg_eap) {
        warn("peer doesn't want to authenticate us with eap");
        lcp_close(unit, "couldn't negotiate eap");
-       status = EXIT_PEER_AUTH_FAILED;
+       ppp_set_status(EXIT_PEER_AUTH_FAILED);
        return;
     }
 #endif
@@ -899,7 +928,7 @@ network_phase(int unit)
        auth_state = s_up;
        if (auth_script_state == s_down && auth_script_pid == 0) {
            auth_script_state = s_up;
-           auth_script(_PATH_AUTHUP);
+           auth_script(PPP_PATH_AUTHUP);
        }
     }
 
@@ -996,7 +1025,7 @@ auth_peer_fail(int unit, int protocol)
     /*
      * Authentication failure: take the link down
      */
-    status = EXIT_PEER_AUTH_FAILED;
+    ppp_set_status(EXIT_PEER_AUTH_FAILED);
     lcp_close(unit, "Authentication failed");
 }
 
@@ -1008,10 +1037,12 @@ auth_peer_success(int unit, int protocol, int prot_flavor,
                  char *name, int namelen)
 {
     int bit;
+    const char *prot;
 
     switch (protocol) {
     case PPP_CHAP:
        bit = CHAP_PEER;
+       prot = "CHAP";
        switch (prot_flavor) {
        case CHAP_MD5:
            bit |= CHAP_MD5_PEER;
@@ -1028,12 +1059,15 @@ auth_peer_success(int unit, int protocol, int prot_flavor,
        break;
     case PPP_PAP:
        bit = PAP_PEER;
+       prot = "PAP";
        break;
     case PPP_EAP:
        bit = EAP_PEER;
+       prot = "EAP";
        break;
     default:
        warn("auth_peer_success: unknown protocol %x", protocol);
+       prot = "unknown protocol";
        return;
     }
 
@@ -1044,7 +1078,8 @@ auth_peer_success(int unit, int protocol, int prot_flavor,
        namelen = sizeof(peer_authname) - 1;
     BCOPY(name, peer_authname, namelen);
     peer_authname[namelen] = 0;
-    script_setenv("PEERNAME", peer_authname, 0);
+    ppp_script_setenv("PEERNAME", peer_authname, 0);
+    notice("Peer %q authenticated with %s", peer_authname, prot);
 
     /* Save the authentication method for later. */
     auth_done[unit] |= bit;
@@ -1071,7 +1106,7 @@ auth_withpeer_fail(int unit, int protocol)
      * is no point in persisting without any way to get updated
      * authentication secrets.
      */
-    status = EXIT_AUTH_TOPEER_FAILED;
+    ppp_set_status(EXIT_AUTH_TOPEER_FAILED);
     lcp_close(unit, "Failed to authenticate ourselves to peer");
 }
 
@@ -1143,14 +1178,14 @@ np_up(int unit, int proto)
        /*
         * At this point we consider that the link has come up successfully.
         */
-       status = EXIT_OK;
+       ppp_set_status(EXIT_OK);
        unsuccess = 0;
        new_phase(PHASE_RUNNING);
 
        if (idle_time_hook != 0)
            tlim = (*idle_time_hook)(NULL);
        else
-           tlim = idle_time_limit;
+           tlim = ppp_get_max_idle_time();
        if (tlim > 0)
            TIMEOUT(check_idle, NULL, tlim);
 
@@ -1158,9 +1193,13 @@ np_up(int unit, int proto)
         * Set a timeout to close the connection once the maximum
         * connect time has expired.
         */
-       if (maxconnect > 0)
-           TIMEOUT(connect_time_expired, 0, maxconnect);
+       if (ppp_get_max_connect_time() > 0)
+           TIMEOUT(connect_time_expired, 0, ppp_get_max_connect_time());
 
+       /*
+        * Configure a check to see if session has outlived it's limit
+        *   in terms of octets
+        */
        if (maxoctets > 0)
            TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
 
@@ -1206,33 +1245,41 @@ np_finished(int unit, int proto)
     }
 }
 
+/*
+ * Periodic callback to check if session has reached its limit. The period defaults
+ * to 1 second and is configurable by setting "mo-timeout" in configuration
+ */
 static void
 check_maxoctets(void *arg)
 {
-    unsigned int used;
-
-    update_link_stats(ifunit);
-    link_stats_valid=0;
-    
-    switch(maxoctets_dir) {
-       case PPP_OCTETS_DIRECTION_IN:
-           used = link_stats.bytes_in;
-           break;
-       case PPP_OCTETS_DIRECTION_OUT:
-           used = link_stats.bytes_out;
-           break;
-       case PPP_OCTETS_DIRECTION_MAXOVERAL:
-       case PPP_OCTETS_DIRECTION_MAXSESSION:
-           used = (link_stats.bytes_in > link_stats.bytes_out) ? link_stats.bytes_in : link_stats.bytes_out;
-           break;
-       default:
-           used = link_stats.bytes_in+link_stats.bytes_out;
-           break;
+    unsigned int used = 0;
+    ppp_link_stats_st stats;
+
+    if (ppp_get_link_stats(&stats)) {
+        switch(maxoctets_dir) {
+            case PPP_OCTETS_DIRECTION_IN:
+                used = stats.bytes_in;
+                break;
+            case PPP_OCTETS_DIRECTION_OUT:
+                used = stats.bytes_out;
+                break;
+            case PPP_OCTETS_DIRECTION_MAXOVERAL:
+            case PPP_OCTETS_DIRECTION_MAXSESSION:
+                used = (stats.bytes_in > stats.bytes_out)
+                                ? stats.bytes_in
+                                : stats.bytes_out;
+                break;
+            default:
+                used = stats.bytes_in+stats.bytes_out;
+                break;
+        }
     }
+
     if (used > maxoctets) {
        notice("Traffic limit reached. Limit: %u Used: %u", maxoctets, used);
-       status = EXIT_TRAFFIC_LIMIT;
+       ppp_set_status(EXIT_TRAFFIC_LIMIT);
        lcp_close(0, "Traffic limit");
+       link_stats_print = 0;
        need_holdoff = 0;
     } else {
         TIMEOUT(check_maxoctets, NULL, maxoctets_timeout);
@@ -1256,12 +1303,12 @@ check_idle(void *arg)
        tlim = idle_time_hook(&idle);
     } else {
        itime = MIN(idle.xmit_idle, idle.recv_idle);
-       tlim = idle_time_limit - itime;
+       tlim = ppp_get_max_idle_time() - itime;
     }
     if (tlim <= 0) {
        /* link is idle: shut it down. */
        notice("Terminating connection due to lack of activity.");
-       status = EXIT_IDLE_TIMEOUT;
+       ppp_set_status(EXIT_IDLE_TIMEOUT);
        lcp_close(0, "Link inactive");
        need_holdoff = 0;
     } else {
@@ -1276,8 +1323,9 @@ static void
 connect_time_expired(void *arg)
 {
     info("Connect time expired");
-    status = EXIT_CONNECT_TIME;
+    ppp_set_status(EXIT_CONNECT_TIME);
     lcp_close(0, "Connect time expired");      /* Close connection */
+    need_holdoff = 0;
 }
 
 /*
@@ -1292,12 +1340,20 @@ auth_check_options(void)
 
     /* Default our_name to hostname, and user to our_name */
     if (our_name[0] == 0 || usehostname)
-       strlcpy(our_name, hostname, sizeof(our_name));
+        strlcpy(our_name, hostname, sizeof(our_name));
+
     /* If a blank username was explicitly given as an option, trust
        the user and don't use our_name */
     if (user[0] == 0 && !explicit_user)
        strlcpy(user, our_name, sizeof(user));
 
+#if defined(SYSTEM_CA_PATH) && (defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP))
+    /* Use system default for CA Path if not specified */
+    if (!ca_path) {
+        ca_path = SYSTEM_CA_PATH;
+    }
+#endif
+
     /*
      * If we have a default route, require the peer to authenticate
      * unless the noauth option was given or the real user is root.
@@ -1354,21 +1410,21 @@ auth_check_options(void)
 
     if (auth_required && !can_auth && noauth_addrs == NULL) {
        if (default_auth) {
-           option_error(
+           ppp_option_error(
 "By default the remote system is required to authenticate itself");
-           option_error(
+           ppp_option_error(
 "(because this system has a default route to the internet)");
        } else if (explicit_remote)
-           option_error(
+           ppp_option_error(
 "The remote system (%s) is required to authenticate itself",
                         remote_name);
        else
-           option_error(
+           ppp_option_error(
 "The remote system is required to authenticate itself");
-       option_error(
+       ppp_option_error(
 "but I couldn't find any suitable secret (password) for it to use to do so.");
        if (lacks_ip)
-           option_error(
+           ppp_option_error(
 "(None of the available passwords would let it use an IP address.)");
 
        exit(1);
@@ -1489,7 +1545,7 @@ check_passwd(int unit,
      * Open the file of pap secrets and scan for a suitable secret
      * for authenticating this user.
      */
-    filename = _PATH_UPAPFILE;
+    filename = path_upapfile;
     addrs = opts = NULL;
     ret = UPAP_AUTHNAK;
     f = fopen(filename, "r");
@@ -1590,7 +1646,7 @@ null_login(int unit)
      * Open the file of pap secrets and scan for a suitable secret.
      */
     if (ret <= 0) {
-       filename = _PATH_UPAPFILE;
+       filename = path_upapfile;
        addrs = NULL;
        f = fopen(filename, "r");
        if (f == NULL)
@@ -1637,7 +1693,7 @@ get_pap_passwd(char *passwd)
            return ret;
     }
 
-    filename = _PATH_UPAPFILE;
+    filename = path_upapfile;
     f = fopen(filename, "r");
     if (f == NULL)
        return 0;
@@ -1674,7 +1730,7 @@ have_pap_secret(int *lacks_ipp)
            return ret;
     }
 
-    filename = _PATH_UPAPFILE;
+    filename = path_upapfile;
     f = fopen(filename, "r");
     if (f == NULL)
        return 0;
@@ -1716,7 +1772,7 @@ have_chap_secret(char *client, char *server,
        }
     }
 
-    filename = _PATH_CHAPFILE;
+    filename = path_chapfile;
     f = fopen(filename, "r");
     if (f == NULL)
        return 0;
@@ -1754,7 +1810,7 @@ have_srp_secret(char *client, char *server, int need_ip, int *lacks_ipp)
     char *filename;
     struct wordlist *addrs;
 
-    filename = _PATH_SRPFILE;
+    filename = PPP_PATH_SRPFILE;
     f = fopen(filename, "r");
     if (f == NULL)
        return 0;
@@ -1802,7 +1858,7 @@ get_secret(int unit, char *client, char *server,
            return 0;
        }
     } else {
-       filename = _PATH_CHAPFILE;
+       filename = path_chapfile;
        addrs = NULL;
        secbuf[0] = 0;
 
@@ -1856,7 +1912,7 @@ get_srp_secret(int unit, char *client, char *server,
     if (!am_server && passwd[0] != '\0') {
        strlcpy(secret, passwd, MAXWORDLEN);
     } else {
-       filename = _PATH_SRPFILE;
+       filename = PPP_PATH_SRPFILE;
        addrs = NULL;
 
        fp = fopen(filename, "r");
@@ -2049,7 +2105,7 @@ auth_ip_addr(int unit, u_int32_t addr)
     int ok;
 
     /* don't allow loopback or multicast address */
-    if (bad_ip_adrs(addr))
+    if (ppp_bad_ip_addr(addr))
        return 0;
 
     if (allowed_address_hook) {
@@ -2077,12 +2133,10 @@ ip_addr_check(u_int32_t addr, struct permitted_ip *addrs)
 }
 
 /*
- * bad_ip_adrs - return 1 if the IP address is one we don't want
- * to use, such as an address in the loopback net or a multicast address.
- * addr is in network byte order.
+ * Check if given addr in network byte order is in the looback network, or a multicast address.
  */
-int
-bad_ip_adrs(u_int32_t addr)
+bool
+ppp_bad_ip_addr(u_int32_t addr)
 {
     addr = ntohl(addr);
     return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
@@ -2113,7 +2167,7 @@ int
 auth_number(void)
 {
     struct wordlist *wp = permitted_numbers;
-    int l;
+    size_t l;
 
     /* Allow all if no authorization list. */
     if (!wp)
@@ -2123,9 +2177,10 @@ auth_number(void)
     while (wp) {
        /* trailing '*' wildcard */
        l = strlen(wp->word);
-       if ((wp->word)[l - 1] == '*')
-           l--;
-       if (!strncasecmp(wp->word, remote_number, l))
+       if (l > 0 && (wp->word)[l - 1] == '*') {
+           if (!strncasecmp(wp->word, remote_number, l - 1))
+               return 1;
+       } else if (strcasecmp(wp->word, remote_number) == 0)
            return 1;
        wp = wp->next;
     }
@@ -2359,13 +2414,13 @@ auth_script_done(void *arg)
     case s_up:
        if (auth_state == s_down) {
            auth_script_state = s_down;
-           auth_script(_PATH_AUTHDOWN);
+           auth_script(PPP_PATH_AUTHDOWN);
        }
        break;
     case s_down:
        if (auth_state == s_up) {
            auth_script_state = s_up;
-           auth_script(_PATH_AUTHUP);
+           auth_script(PPP_PATH_AUTHUP);
        }
        break;
     }
@@ -2419,7 +2474,7 @@ have_eaptls_secret_server(char *client, char *server,
     char cacertfile[MAXWORDLEN];
     char pkfile[MAXWORDLEN];
 
-    filename = _PATH_EAPTLSSERVFILE;
+    filename = PPP_PATH_EAPTLSSERVFILE;
     f = fopen(filename, "r");
     if (f == NULL)
                return 0;
@@ -2476,7 +2531,7 @@ have_eaptls_secret_client(char *client, char *server)
        if (pkcs12_file)
                return 1;
 
-    filename = _PATH_EAPTLSCLIFILE;
+    filename = PPP_PATH_EAPTLSCLIFILE;
     f = fopen(filename, "r");
     if (f == NULL)
                return 0;
@@ -2694,7 +2749,7 @@ get_eaptls_secret(int unit, char *client, char *server,
        }
        else
        {
-               filename = (am_server ? _PATH_EAPTLSSERVFILE : _PATH_EAPTLSCLIFILE);
+               filename = (am_server ? PPP_PATH_EAPTLSSERVFILE : PPP_PATH_EAPTLSCLIFILE);
                addrs = NULL;
 
                fp = fopen(filename, "r");
index 87bf9c002c0c72c3600216936a3edb4fe3519c4d..8c33cf6392bfb5effb9a52a099427e8f5d63d875 100644 (file)
 #include <sys/types.h>
 #include <sys/time.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "cbcp.h"
 #include "fsm.h"
 #include "lcp.h"
+#include "options.h"
 
 
 /*
@@ -52,7 +53,7 @@
  */
 static int setcbcp (char **);
 
-static option_t cbcp_option_list[] = {
+static struct option cbcp_option_list[] = {
     { "callback", o_special, (void *)setcbcp,
       "Ask for callback", OPT_PRIO | OPT_A2STRVAL, &cbcp[0].us_number },
     { NULL }
@@ -461,6 +462,6 @@ static void
 cbcp_up(cbcp_state *us)
 {
     persist = 0;
-    status = EXIT_CALLBACK;
+    ppp_set_status(EXIT_CALLBACK);
     lcp_close(0, "Call me back, please");
 }
index c74b5f8c8a2daef6f70ddb8851f9fd5f21f5eaa9..4bd106be6b9fe30004ce14c796138053b165d5ee 100644 (file)
@@ -1,8 +1,44 @@
-#ifndef CBCP_H
-#define CBCP_H
+/*
+ * Copyright (c) 1995 Pedro Roque Marques.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The names of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by Pedro Roque Marques
+ *     <pedro_m@yahoo.com>"
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef PPP_CBCP_H
+#define PPP_CBCP_H
 
 #include "pppdconf.h"
 
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
 typedef struct cbcp_state {
     int    us_unit;    /* Interface unit number */
     u_char us_id;              /* Current id */
@@ -25,4 +61,9 @@ extern struct protent cbcp_protent;
 #define CB_CONF_USER   2
 #define CB_CONF_ADMIN  3
 #define CB_CONF_LIST   4
+
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_CBCP_H
index 088a163c3f68370623b09ee3ecf61ea6436ca419..732091f6012b69df3571dd8beffe8d7e1d30a604 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * ccp.c - PPP Compression Control Protocol.
  *
- * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -32,8 +28,6 @@
 #include "config.h"
 #endif
 
-#define RCSID  "$Id: ccp.c,v 1.50 2005/06/26 19:34:41 carlsonj Exp $"
-
 #include <stdlib.h>
 #include <string.h>
 #if defined(SOL2)
@@ -42,7 +36,8 @@
 #include <linux/ppp-comp.h>
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "ccp.h"
 
@@ -75,7 +70,7 @@ static char deflate_value[8];
 bool refuse_mppe_stateful = 1;         /* Allow stateful mode? */
 #endif
 
-static option_t ccp_option_list[] = {
+static struct option ccp_option_list[] = {
     { "noccp", o_bool, &ccp_protent.enabled_flag,
       "Disable CCP negotiation" },
     { "-ccp", o_bool, &ccp_protent.enabled_flag,
@@ -276,12 +271,12 @@ setbsdcomp(char **argv)
        abits = strtol(str, &endp, 0);
     }
     if (*endp != 0 || endp == str) {
-       option_error("invalid parameter '%s' for bsdcomp option", *argv);
+       ppp_option_error("invalid parameter '%s' for bsdcomp option", *argv);
        return 0;
     }
     if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
        || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
-       option_error("bsdcomp option values must be 0 or %d .. %d",
+       ppp_option_error("bsdcomp option values must be 0 or %d .. %d",
                     BSD_MIN_BITS, BSD_MAX_BITS);
        return 0;
     }
@@ -314,13 +309,13 @@ setdeflate(char **argv)
        abits = strtol(str, &endp, 0);
     }
     if (*endp != 0 || endp == str) {
-       option_error("invalid parameter '%s' for deflate option", *argv);
+       ppp_option_error("invalid parameter '%s' for deflate option", *argv);
        return 0;
     }
     if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
        || (abits != 0 && (abits < DEFLATE_MIN_SIZE
                          || abits > DEFLATE_MAX_SIZE))) {
-       option_error("deflate option values must be 0 or %d .. %d",
+       ppp_option_error("deflate option values must be 0 or %d .. %d",
                     DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
        return 0;
     }
@@ -684,7 +679,10 @@ static int
        + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0)
        + (go->predictor_1? CILEN_PREDICTOR_1: 0)
        + (go->predictor_2? CILEN_PREDICTOR_2: 0)
-       + (go->mppe? CILEN_MPPE: 0);
+#ifdef PPP_WITH_MPPE
+       + (go->mppe? CILEN_MPPE: 0)
+#endif
+        ;
 }
 
 /*
@@ -1175,9 +1173,9 @@ ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak)
                     * because MPPE frames **grow**.  The kernel [must]
                     * allocate MPPE_PAD extra bytes in xmit buffers.
                     */
-                   mtu = netif_get_mtu(f->unit);
+                   mtu = ppp_get_mtu(f->unit);
                    if (mtu)
-                       netif_set_mtu(f->unit, mtu - MPPE_PAD);
+                       ppp_set_mtu(f->unit, mtu - MPPE_PAD);
                    else
                        newret = CONFREJ;
                }
index a37695c18373f23a2d11eef36e7e8e0cda06288b..785f702767a8e7395329328353ae2ed8c38ba16d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * ccp.h - Definitions for PPP Compression Control Protocol.
  *
- * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ccp.h,v 1.12 2004/11/04 10:02:26 paulus Exp $
  */
 #ifndef PPP_CCP_H
 #define PPP_CCP_H
 
 #include "pppdconf.h"
 
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
 typedef struct ccp_options {
     bool bsd_compress;         /* do BSD Compress? */
     bool deflate;              /* do Deflate? */
@@ -41,9 +39,9 @@ typedef struct ccp_options {
     bool predictor_2;          /* do Predictor-2? */
     bool deflate_correct;      /* use correct code for deflate? */
     bool deflate_draft;                /* use draft RFC code for deflate? */
-    u_char mppe;               /* MPPE bitfield */
-    u_short bsd_bits;          /* # bits/code for BSD Compress */
-    u_short deflate_size;      /* lg(window size) for Deflate */
+    unsigned char mppe;                /* MPPE bitfield */
+    unsigned short bsd_bits;           /* # bits/code for BSD Compress */
+    unsigned short deflate_size;       /* lg(window size) for Deflate */
     short method;              /* code for chosen compression method */
 } ccp_options;
 
@@ -55,4 +53,8 @@ extern ccp_options ccp_hisoptions[];
 
 extern struct protent ccp_protent;
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_CCP_H
index 000f880e89e3d0859698b018689437acb120023e..7b66ae2598c181dc6ede4f3244e9247360176993 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * chap-md5.c - New CHAP/MD5 implementation.
  *
- * Copyright (c) 2003 Paul Mackerras. All rights reserved.
+ * Copyright (c) 2003-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: chap-md5.c,v 1.4 2004/11/09 22:39:25 paulus Exp $"
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include <stdlib.h>
 #include <string.h>
-#include "pppd.h"
-#include "chap-new.h"
+#include "pppd-private.h"
+#include "chap.h"
 #include "chap-md5.h"
 #include "magic.h"
-#include "md5.h"
+#include "crypto.h"
 
-#define MD5_HASH_SIZE          16
 #define MD5_MIN_CHALLENGE      16
 #define MD5_MAX_CHALLENGE      24
 
@@ -63,27 +56,43 @@ chap_md5_verify_response(int id, char *name,
                         unsigned char *challenge, unsigned char *response,
                         char *message, int message_space)
 {
-       MD5_CTX ctx;
        unsigned char idbyte = id;
-       unsigned char hash[MD5_HASH_SIZE];
+       unsigned char hash[MD5_DIGEST_LENGTH];
+       unsigned int  hash_len = MD5_DIGEST_LENGTH;
        int challenge_len, response_len;
+       bool success = 0;
 
        challenge_len = *challenge++;
        response_len = *response++;
-       if (response_len == MD5_HASH_SIZE) {
+       if (response_len == MD5_DIGEST_LENGTH) {
+
                /* Generate hash of ID, secret, challenge */
-               MD5_Init(&ctx);
-               MD5_Update(&ctx, &idbyte, 1);
-               MD5_Update(&ctx, secret, secret_len);
-               MD5_Update(&ctx, challenge, challenge_len);
-               MD5_Final(hash, &ctx);
-
-               /* Test if our hash matches the peer's response */
-               if (memcmp(hash, response, MD5_HASH_SIZE) == 0) {
-                       slprintf(message, message_space, "Access granted");
-                       return 1;
+               PPP_MD_CTX* ctx = PPP_MD_CTX_new();
+               if (ctx) {
+
+                       if (PPP_DigestInit(ctx, PPP_md5())) {
+
+                               if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
+
+                                       if (PPP_DigestUpdate(ctx, secret, secret_len)) {
+
+                                               if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
+
+                                                       if (PPP_DigestFinal(ctx, hash, &hash_len)) {
+
+                                                               success = 1;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       PPP_MD_CTX_free(ctx);
                }
        }
+       if (success && memcmp(hash, response, hash_len) == 0) {
+               slprintf(message, message_space, "Access granted");
+               return 1;
+       }
        slprintf(message, message_space, "Access denied");
        return 0;
 }
@@ -93,16 +102,34 @@ chap_md5_make_response(unsigned char *response, int id, char *our_name,
                       unsigned char *challenge, char *secret, int secret_len,
                       unsigned char *private)
 {
-       MD5_CTX ctx;
        unsigned char idbyte = id;
        int challenge_len = *challenge++;
+       int hash_len = MD5_DIGEST_LENGTH;
+
+       response[0] = 0;
+       PPP_MD_CTX* ctx = PPP_MD_CTX_new();
+       if (ctx) {
+
+               if (PPP_DigestInit(ctx, PPP_md5())) {
+
+                       if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
+
+                               if (PPP_DigestUpdate(ctx, secret, secret_len)) {
 
-       MD5_Init(&ctx);
-       MD5_Update(&ctx, &idbyte, 1);
-       MD5_Update(&ctx, (u_char *)secret, secret_len);
-       MD5_Update(&ctx, challenge, challenge_len);
-       MD5_Final(&response[1], &ctx);
-       response[0] = MD5_HASH_SIZE;
+                                       if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
+
+                                               if (PPP_DigestFinal(ctx, &response[1], &hash_len)) {
+
+                                                       response[0] = hash_len;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               PPP_MD_CTX_free(ctx);
+       }
+       if (response[0] == 0)
+               warn("Error occurred in preparing CHAP-Response");
 }
 
 static struct chap_digest_type md5_digest = {
index 55f9ba25f63c055802bb87d8fc7bc68c969eed5c..62fca9e8eb03d6408b09387e37629d91facf1092 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * chap-md5.h - New CHAP/MD5 implementation.
  *
- * Copyright (c) 2003 Paul Mackerras. All rights reserved.
+ * Copyright (c) 2003-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
diff --git a/pppd/chap-new.c b/pppd/chap-new.c
deleted file mode 100644 (file)
index 565713f..0000000
+++ /dev/null
@@ -1,704 +0,0 @@
-/*
- * chap-new.c - New CHAP implementation.
- *
- * Copyright (c) 2003 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#define RCSID  "$Id: chap-new.c,v 1.9 2007/06/19 02:08:35 carlsonj Exp $"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include "pppd.h"
-#include "session.h"
-#include "chap-new.h"
-#include "chap-md5.h"
-
-#ifdef PPP_WITH_CHAPMS
-#include "chap_ms.h"
-#define MDTYPE_ALL (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
-#else
-#define MDTYPE_ALL (MDTYPE_MD5)
-#endif
-
-int chap_mdtype_all = MDTYPE_ALL;
-
-/* Hook for a plugin to validate CHAP challenge */
-int (*chap_verify_hook)(char *name, char *ourname, int id,
-                       struct chap_digest_type *digest,
-                       unsigned char *challenge, unsigned char *response,
-                       char *message, int message_space) = NULL;
-
-/*
- * Option variables.
- */
-int chap_server_timeout_time = 3;
-int chap_max_transmits = 10;
-int chap_rechallenge_time = 0;
-int chap_client_timeout_time = 60;
-int chapms_strip_domain = 0;
-
-/*
- * Command-line options.
- */
-static option_t chap_option_list[] = {
-       { "chap-restart", o_int, &chap_server_timeout_time,
-         "Set timeout for CHAP (as server)", OPT_PRIO },
-       { "chap-max-challenge", o_int, &chap_max_transmits,
-         "Set max #xmits for challenge", OPT_PRIO },
-       { "chap-interval", o_int, &chap_rechallenge_time,
-         "Set interval for rechallenge", OPT_PRIO },
-       { "chap-timeout", o_int, &chap_client_timeout_time,
-         "Set timeout for CHAP (as client)", OPT_PRIO },
-       { "chapms-strip-domain", o_bool, &chapms_strip_domain,
-         "Strip the domain prefix before the Username", 1 },
-       { NULL }
-};
-
-/*
- * Internal state.
- */
-static struct chap_client_state {
-       int flags;
-       char *name;
-       struct chap_digest_type *digest;
-       unsigned char priv[64];         /* private area for digest's use */
-} client;
-
-/*
- * These limits apply to challenge and response packets we send.
- * The +4 is the +1 that we actually need rounded up.
- */
-#define CHAL_MAX_PKTLEN        (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN)
-#define RESP_MAX_PKTLEN        (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN)
-
-static struct chap_server_state {
-       int flags;
-       int id;
-       char *name;
-       struct chap_digest_type *digest;
-       int challenge_xmits;
-       int challenge_pktlen;
-       unsigned char challenge[CHAL_MAX_PKTLEN];
-       char message[256];
-} server;
-
-/* Values for flags in chap_client_state and chap_server_state */
-#define LOWERUP                        1
-#define AUTH_STARTED           2
-#define AUTH_DONE              4
-#define AUTH_FAILED            8
-#define TIMEOUT_PENDING                0x10
-#define CHALLENGE_VALID                0x20
-
-/*
- * Prototypes.
- */
-static void chap_init(int unit);
-static void chap_lowerup(int unit);
-static void chap_lowerdown(int unit);
-static void chap_server_timeout(void *arg);
-static void chap_client_timeout(void *arg);
-static void chap_generate_challenge(struct chap_server_state *ss);
-static void chap_handle_response(struct chap_server_state *ss, int code,
-               unsigned char *pkt, int len);
-static int chap_verify_response(char *name, char *ourname, int id,
-               struct chap_digest_type *digest,
-               unsigned char *challenge, unsigned char *response,
-               char *message, int message_space);
-static void chap_respond(struct chap_client_state *cs, int id,
-               unsigned char *pkt, int len);
-static void chap_handle_status(struct chap_client_state *cs, int code, int id,
-               unsigned char *pkt, int len);
-static void chap_protrej(int unit);
-static void chap_input(int unit, unsigned char *pkt, int pktlen);
-static int chap_print_pkt(unsigned char *p, int plen,
-               void (*printer)(void *, char *, ...), void *arg);
-
-/* List of digest types that we know about */
-static struct chap_digest_type *chap_digests;
-
-/*
- * chap_init - reset to initial state.
- */
-static void
-chap_init(int unit)
-{
-       memset(&client, 0, sizeof(client));
-       memset(&server, 0, sizeof(server));
-
-       chap_md5_init();
-#ifdef PPP_WITH_CHAPMS
-       chapms_init();
-#endif
-}
-
-/*
- * Add a new digest type to the list.
- */
-void
-chap_register_digest(struct chap_digest_type *dp)
-{
-       dp->next = chap_digests;
-       chap_digests = dp;
-}
-
-/*
- * Lookup a digest type by code
- */
-struct chap_digest_type *
-chap_find_digest(int digest_code) {
-       struct chap_digest_type *dp = NULL;
-       for (dp = chap_digests; dp != NULL; dp = dp->next)
-               if (dp->code == digest_code)
-                       break;
-       return dp;
-}
-
-/*
- * chap_lowerup - we can start doing stuff now.
- */
-static void
-chap_lowerup(int unit)
-{
-       struct chap_client_state *cs = &client;
-       struct chap_server_state *ss = &server;
-
-       cs->flags |= LOWERUP;
-       ss->flags |= LOWERUP;
-       if (ss->flags & AUTH_STARTED)
-               chap_server_timeout(ss);
-}
-
-static void
-chap_lowerdown(int unit)
-{
-       struct chap_client_state *cs = &client;
-       struct chap_server_state *ss = &server;
-
-       if (cs->flags & TIMEOUT_PENDING)
-               UNTIMEOUT(chap_client_timeout, cs);
-       cs->flags = 0;
-       if (ss->flags & TIMEOUT_PENDING)
-               UNTIMEOUT(chap_server_timeout, ss);
-       ss->flags = 0;
-}
-
-/*
- * chap_auth_peer - Start authenticating the peer.
- * If the lower layer is already up, we start sending challenges,
- * otherwise we wait for the lower layer to come up.
- */
-void
-chap_auth_peer(int unit, char *our_name, int digest_code)
-{
-       struct chap_server_state *ss = &server;
-       struct chap_digest_type *dp;
-
-       if (ss->flags & AUTH_STARTED) {
-               error("CHAP: peer authentication already started!");
-               return;
-       }
-
-       dp = chap_find_digest(digest_code);
-       if (dp == NULL)
-               fatal("CHAP digest 0x%x requested but not available",
-                     digest_code);
-
-       ss->digest = dp;
-       ss->name = our_name;
-       /* Start with a random ID value */
-       ss->id = (unsigned char)(drand48() * 256);
-       ss->flags |= AUTH_STARTED;
-       if (ss->flags & LOWERUP)
-               chap_server_timeout(ss);
-}
-
-/*
- * chap_auth_with_peer - Prepare to authenticate ourselves to the peer.
- * There isn't much to do until we receive a challenge.
- */
-void
-chap_auth_with_peer(int unit, char *our_name, int digest_code)
-{
-       struct chap_client_state *cs = &client;
-       struct chap_digest_type *dp;
-
-       if (cs->flags & AUTH_STARTED) {
-               error("CHAP: authentication with peer already started!");
-               return;
-       }
-       for (dp = chap_digests; dp != NULL; dp = dp->next)
-               if (dp->code == digest_code)
-                       break;
-       if (dp == NULL)
-               fatal("CHAP digest 0x%x requested but not available",
-                     digest_code);
-
-       cs->digest = dp;
-       cs->name = our_name;
-       cs->flags |= AUTH_STARTED | TIMEOUT_PENDING;
-       TIMEOUT(chap_client_timeout, cs, chap_client_timeout_time);
-}
-
-/*
- * chap_server_timeout - It's time to send another challenge to the peer.
- * This could be either a retransmission of a previous challenge,
- * or a new challenge to start re-authentication.
- */
-static void
-chap_server_timeout(void *arg)
-{
-       struct chap_server_state *ss = arg;
-
-       ss->flags &= ~TIMEOUT_PENDING;
-       if ((ss->flags & CHALLENGE_VALID) == 0) {
-               ss->challenge_xmits = 0;
-               chap_generate_challenge(ss);
-               ss->flags |= CHALLENGE_VALID;
-       } else if (ss->challenge_xmits >= chap_max_transmits) {
-               ss->flags &= ~CHALLENGE_VALID;
-               ss->flags |= AUTH_DONE | AUTH_FAILED;
-               auth_peer_fail(0, PPP_CHAP);
-               return;
-       }
-
-       output(0, ss->challenge, ss->challenge_pktlen);
-       ++ss->challenge_xmits;
-       ss->flags |= TIMEOUT_PENDING;
-       TIMEOUT(chap_server_timeout, arg, chap_server_timeout_time);
-}
-
-/* chap_client_timeout - Authentication with peer timed out. */
-static void
-chap_client_timeout(void *arg)
-{
-       struct chap_client_state *cs = arg;
-
-       cs->flags &= ~TIMEOUT_PENDING;
-       cs->flags |= AUTH_DONE | AUTH_FAILED;
-       error("CHAP authentication timed out");
-       auth_withpeer_fail(0, PPP_CHAP);
-}
-
-/*
- * chap_generate_challenge - generate a challenge string and format
- * the challenge packet in ss->challenge_pkt.
- */
-static void
-chap_generate_challenge(struct chap_server_state *ss)
-{
-       int clen = 1, nlen, len;
-       unsigned char *p;
-
-       p = ss->challenge;
-       MAKEHEADER(p, PPP_CHAP);
-       p += CHAP_HDRLEN;
-       ss->digest->generate_challenge(p);
-       clen = *p;
-       nlen = strlen(ss->name);
-       memcpy(p + 1 + clen, ss->name, nlen);
-
-       len = CHAP_HDRLEN + 1 + clen + nlen;
-       ss->challenge_pktlen = PPP_HDRLEN + len;
-
-       p = ss->challenge + PPP_HDRLEN;
-       p[0] = CHAP_CHALLENGE;
-       p[1] = ++ss->id;
-       p[2] = len >> 8;
-       p[3] = len;
-}
-
-/*
- * chap_handle_response - check the response to our challenge.
- */
-static void
-chap_handle_response(struct chap_server_state *ss, int id,
-                    unsigned char *pkt, int len)
-{
-       int response_len, ok, mlen;
-       unsigned char *response, *p;
-       char *name = NULL;      /* initialized to shut gcc up */
-       int (*verifier)(char *, char *, int, struct chap_digest_type *,
-               unsigned char *, unsigned char *, char *, int);
-       char rname[MAXNAMELEN+1];
-
-       if ((ss->flags & LOWERUP) == 0)
-               return;
-       if (id != ss->challenge[PPP_HDRLEN+1] || len < 2)
-               return;
-       if (ss->flags & CHALLENGE_VALID) {
-               response = pkt;
-               GETCHAR(response_len, pkt);
-               len -= response_len + 1;        /* length of name */
-               name = (char *)pkt + response_len;
-               if (len < 0)
-                       return;
-
-               if (ss->flags & TIMEOUT_PENDING) {
-                       ss->flags &= ~TIMEOUT_PENDING;
-                       UNTIMEOUT(chap_server_timeout, ss);
-               }
-
-               if (explicit_remote) {
-                       name = remote_name;
-               } else {
-                       /* Null terminate and clean remote name. */
-                       slprintf(rname, sizeof(rname), "%.*v", len, name);
-                       name = rname;
-
-                       /* strip the MS domain name */
-                       if (chapms_strip_domain && strrchr(rname, '\\')) {
-                               char tmp[MAXNAMELEN+1];
-
-                               strcpy(tmp, strrchr(rname, '\\') + 1);
-                               strcpy(rname, tmp);
-                       }
-               }
-
-               if (chap_verify_hook)
-                       verifier = chap_verify_hook;
-               else
-                       verifier = chap_verify_response;
-               ok = (*verifier)(name, ss->name, id, ss->digest,
-                                ss->challenge + PPP_HDRLEN + CHAP_HDRLEN,
-                                response, ss->message, sizeof(ss->message));
-               if (!ok || !auth_number()) {
-                       ss->flags |= AUTH_FAILED;
-                       warn("Peer %q failed CHAP authentication", name);
-               }
-       } else if ((ss->flags & AUTH_DONE) == 0)
-               return;
-
-       /* send the response */
-       p = outpacket_buf;
-       MAKEHEADER(p, PPP_CHAP);
-       mlen = strlen(ss->message);
-       len = CHAP_HDRLEN + mlen;
-       p[0] = (ss->flags & AUTH_FAILED)? CHAP_FAILURE: CHAP_SUCCESS;
-       p[1] = id;
-       p[2] = len >> 8;
-       p[3] = len;
-       if (mlen > 0)
-               memcpy(p + CHAP_HDRLEN, ss->message, mlen);
-       output(0, outpacket_buf, PPP_HDRLEN + len);
-
-       if (ss->flags & CHALLENGE_VALID) {
-               ss->flags &= ~CHALLENGE_VALID;
-               if (!(ss->flags & AUTH_DONE) && !(ss->flags & AUTH_FAILED)) {
-                   /*
-                    * Auth is OK, so now we need to check session restrictions
-                    * to ensure everything is OK, but only if we used a
-                    * plugin, and only if we're configured to check.  This
-                    * allows us to do PAM checks on PPP servers that
-                    * authenticate against ActiveDirectory, and use AD for
-                    * account info (like when using Winbind integrated with
-                    * PAM).
-                    */
-                   if (session_mgmt &&
-                       session_check(name, NULL, devnam, NULL) == 0) {
-                       ss->flags |= AUTH_FAILED;
-                       warn("Peer %q failed CHAP Session verification", name);
-                   }
-               }
-               if (ss->flags & AUTH_FAILED) {
-                       auth_peer_fail(0, PPP_CHAP);
-               } else {
-                       if ((ss->flags & AUTH_DONE) == 0)
-                               auth_peer_success(0, PPP_CHAP,
-                                                 ss->digest->code,
-                                                 name, strlen(name));
-                       if (chap_rechallenge_time) {
-                               ss->flags |= TIMEOUT_PENDING;
-                               TIMEOUT(chap_server_timeout, ss,
-                                       chap_rechallenge_time);
-                       }
-               }
-               ss->flags |= AUTH_DONE;
-       }
-}
-
-/*
- * chap_verify_response - check whether the peer's response matches
- * what we think it should be.  Returns 1 if it does (authentication
- * succeeded), or 0 if it doesn't.
- */
-static int
-chap_verify_response(char *name, char *ourname, int id,
-                    struct chap_digest_type *digest,
-                    unsigned char *challenge, unsigned char *response,
-                    char *message, int message_space)
-{
-       int ok;
-       unsigned char secret[MAXSECRETLEN];
-       int secret_len;
-
-       /* Get the secret that the peer is supposed to know */
-       if (!get_secret(0, name, ourname, (char *)secret, &secret_len, 1)) {
-               error("No CHAP secret found for authenticating %q", name);
-               return 0;
-       }
-
-       ok = digest->verify_response(id, name, secret, secret_len, challenge,
-                                    response, message, message_space);
-       memset(secret, 0, sizeof(secret));
-
-       return ok;
-}
-
-/*
- * chap_respond - Generate and send a response to a challenge.
- */
-static void
-chap_respond(struct chap_client_state *cs, int id,
-            unsigned char *pkt, int len)
-{
-       int clen, nlen;
-       int secret_len;
-       unsigned char *p;
-       unsigned char response[RESP_MAX_PKTLEN];
-       char rname[MAXNAMELEN+1];
-       char secret[MAXSECRETLEN+1];
-
-       if ((cs->flags & (LOWERUP | AUTH_STARTED)) != (LOWERUP | AUTH_STARTED))
-               return;         /* not ready */
-       if (len < 2 || len < pkt[0] + 1)
-               return;         /* too short */
-       clen = pkt[0];
-       nlen = len - (clen + 1);
-
-       /* Null terminate and clean remote name. */
-       slprintf(rname, sizeof(rname), "%.*v", nlen, pkt + clen + 1);
-
-       /* Microsoft doesn't send their name back in the PPP packet */
-       if (explicit_remote || (remote_name[0] != 0 && rname[0] == 0))
-               strlcpy(rname, remote_name, sizeof(rname));
-
-       /* get secret for authenticating ourselves with the specified host */
-       if (!get_secret(0, cs->name, rname, secret, &secret_len, 0)) {
-               secret_len = 0; /* assume null secret if can't find one */
-               warn("No CHAP secret found for authenticating us to %q", rname);
-       }
-
-       p = response;
-       MAKEHEADER(p, PPP_CHAP);
-       p += CHAP_HDRLEN;
-
-       cs->digest->make_response(p, id, cs->name, pkt,
-                                 secret, secret_len, cs->priv);
-       memset(secret, 0, secret_len);
-
-       clen = *p;
-       nlen = strlen(cs->name);
-       memcpy(p + clen + 1, cs->name, nlen);
-
-       p = response + PPP_HDRLEN;
-       len = CHAP_HDRLEN + clen + 1 + nlen;
-       p[0] = CHAP_RESPONSE;
-       p[1] = id;
-       p[2] = len >> 8;
-       p[3] = len;
-
-       output(0, response, PPP_HDRLEN + len);
-}
-
-static void
-chap_handle_status(struct chap_client_state *cs, int code, int id,
-                  unsigned char *pkt, int len)
-{
-       const char *msg = NULL;
-
-       if ((cs->flags & (AUTH_DONE|AUTH_STARTED|LOWERUP))
-           != (AUTH_STARTED|LOWERUP))
-               return;
-       cs->flags |= AUTH_DONE;
-
-       UNTIMEOUT(chap_client_timeout, cs);
-       cs->flags &= ~TIMEOUT_PENDING;
-
-       if (code == CHAP_SUCCESS) {
-               /* used for MS-CHAP v2 mutual auth, yuck */
-               if (cs->digest->check_success != NULL) {
-                       if (!(*cs->digest->check_success)(id, pkt, len))
-                               code = CHAP_FAILURE;
-               } else
-                       msg = "CHAP authentication succeeded";
-       } else {
-               if (cs->digest->handle_failure != NULL)
-                       (*cs->digest->handle_failure)(pkt, len);
-               else
-                       msg = "CHAP authentication failed";
-       }
-       if (msg) {
-               if (len > 0)
-                       info("%s: %.*v", msg, len, pkt);
-               else
-                       info("%s", msg);
-       }
-       if (code == CHAP_SUCCESS)
-               auth_withpeer_success(0, PPP_CHAP, cs->digest->code);
-       else {
-               cs->flags |= AUTH_FAILED;
-               error("CHAP authentication failed");
-               auth_withpeer_fail(0, PPP_CHAP);
-       }
-}
-
-static void
-chap_input(int unit, unsigned char *pkt, int pktlen)
-{
-       struct chap_client_state *cs = &client;
-       struct chap_server_state *ss = &server;
-       unsigned char code, id;
-       int len;
-
-       if (pktlen < CHAP_HDRLEN)
-               return;
-       GETCHAR(code, pkt);
-       GETCHAR(id, pkt);
-       GETSHORT(len, pkt);
-       if (len < CHAP_HDRLEN || len > pktlen)
-               return;
-       len -= CHAP_HDRLEN;
-
-       switch (code) {
-       case CHAP_CHALLENGE:
-               chap_respond(cs, id, pkt, len);
-               break;
-       case CHAP_RESPONSE:
-               chap_handle_response(ss, id, pkt, len);
-               break;
-       case CHAP_FAILURE:
-       case CHAP_SUCCESS:
-               chap_handle_status(cs, code, id, pkt, len);
-               break;
-       }
-}
-
-static void
-chap_protrej(int unit)
-{
-       struct chap_client_state *cs = &client;
-       struct chap_server_state *ss = &server;
-
-       if (ss->flags & TIMEOUT_PENDING) {
-               ss->flags &= ~TIMEOUT_PENDING;
-               UNTIMEOUT(chap_server_timeout, ss);
-       }
-       if (ss->flags & AUTH_STARTED) {
-               ss->flags = 0;
-               auth_peer_fail(0, PPP_CHAP);
-       }
-       if ((cs->flags & (AUTH_STARTED|AUTH_DONE)) == AUTH_STARTED) {
-               cs->flags &= ~AUTH_STARTED;
-               error("CHAP authentication failed due to protocol-reject");
-               auth_withpeer_fail(0, PPP_CHAP);
-       }
-}
-
-/*
- * chap_print_pkt - print the contents of a CHAP packet.
- */
-static char *chap_code_names[] = {
-       "Challenge", "Response", "Success", "Failure"
-};
-
-static int
-chap_print_pkt(unsigned char *p, int plen,
-              void (*printer)(void *, char *, ...), void *arg)
-{
-       int code, id, len;
-       int clen, nlen;
-       unsigned char x;
-
-       if (plen < CHAP_HDRLEN)
-               return 0;
-       GETCHAR(code, p);
-       GETCHAR(id, p);
-       GETSHORT(len, p);
-       if (len < CHAP_HDRLEN || len > plen)
-               return 0;
-
-       if (code >= 1 && code <= sizeof(chap_code_names) / sizeof(char *))
-               printer(arg, " %s", chap_code_names[code-1]);
-       else
-               printer(arg, " code=0x%x", code);
-       printer(arg, " id=0x%x", id);
-       len -= CHAP_HDRLEN;
-       switch (code) {
-       case CHAP_CHALLENGE:
-       case CHAP_RESPONSE:
-               if (len < 1)
-                       break;
-               clen = p[0];
-               if (len < clen + 1)
-                       break;
-               ++p;
-               nlen = len - clen - 1;
-               printer(arg, " <");
-               for (; clen > 0; --clen) {
-                       GETCHAR(x, p);
-                       printer(arg, "%.2x", x);
-               }
-               printer(arg, ">, name = ");
-               print_string((char *)p, nlen, printer, arg);
-               break;
-       case CHAP_FAILURE:
-       case CHAP_SUCCESS:
-               printer(arg, " ");
-               print_string((char *)p, len, printer, arg);
-               break;
-       default:
-               for (clen = len; clen > 0; --clen) {
-                       GETCHAR(x, p);
-                       printer(arg, " %.2x", x);
-               }
-       }
-
-       return len + CHAP_HDRLEN;
-}
-
-struct protent chap_protent = {
-       PPP_CHAP,
-       chap_init,
-       chap_input,
-       chap_protrej,
-       chap_lowerup,
-       chap_lowerdown,
-       NULL,           /* open */
-       NULL,           /* close */
-       chap_print_pkt,
-       NULL,           /* datainput */
-       1,              /* enabled_flag */
-       "CHAP",         /* name */
-       NULL,           /* data_name */
-       chap_option_list,
-       NULL,           /* check_options */
-};
diff --git a/pppd/chap-new.h b/pppd/chap-new.h
deleted file mode 100644 (file)
index 9ebec54..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * chap-new.c - New CHAP implementation.
- *
- * Copyright (c) 2003 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef PPP_CHAP_NEW_H
-#define PPP_CHAP_NEW_H
-
-#include "pppdconf.h"
-
-/*
- * CHAP packets begin with a standard header with code, id, len (2 bytes).
- */
-#define CHAP_HDRLEN    4
-
-/*
- * Values for the code field.
- */
-#define CHAP_CHALLENGE 1
-#define CHAP_RESPONSE  2
-#define CHAP_SUCCESS   3
-#define CHAP_FAILURE   4
-
-/*
- * CHAP digest codes.
- */
-#define CHAP_MD5               5
-#define CHAP_MICROSOFT         0x80
-#define CHAP_MICROSOFT_V2      0x81
-
-/*
- * Semi-arbitrary limits on challenge and response fields.
- */
-#define MAX_CHALLENGE_LEN      64
-#define MAX_RESPONSE_LEN       64
-
-/* bitmask of supported algorithms */
-#define MDTYPE_MICROSOFT_V2    0x1
-#define MDTYPE_MICROSOFT       0x2
-#define MDTYPE_MD5             0x4
-#define MDTYPE_NONE            0
-
-/* hashes supported by this instance of pppd */
-extern int chap_mdtype_all;
-
-/* Return the digest alg. ID for the most preferred digest type. */
-#define CHAP_DIGEST(mdtype) \
-    ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
-    ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
-    ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
-    0
-
-/* Return the bit flag (lsb set) for our most preferred digest type. */
-#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
-
-/* Return the bit flag for a given digest algorithm ID. */
-#define CHAP_MDTYPE_D(digest) \
-    ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
-    ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
-    ((digest) == CHAP_MD5)? MDTYPE_MD5: \
-    0
-
-/* Can we do the requested digest? */
-#define CHAP_CANDIGEST(mdtype, digest) \
-    ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
-    ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
-    ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
-    0
-
-/*
- * The code for each digest type has to supply one of these.
- */
-struct chap_digest_type {
-       int code;
-
-       /*
-        * Note: challenge and response arguments below are formatted as
-        * a length byte followed by the actual challenge/response data.
-        */
-       void (*generate_challenge)(unsigned char *challenge);
-       int (*verify_response)(int id, char *name,
-               unsigned char *secret, int secret_len,
-               unsigned char *challenge, unsigned char *response,
-               char *message, int message_space);
-       void (*make_response)(unsigned char *response, int id, char *our_name,
-               unsigned char *challenge, char *secret, int secret_len,
-               unsigned char *priv);
-       int (*check_success)(int id, unsigned char *pkt, int len);
-       void (*handle_failure)(unsigned char *pkt, int len);
-
-       struct chap_digest_type *next;
-};
-
-/* Hook for a plugin to validate CHAP challenge */
-extern int (*chap_verify_hook)(char *name, char *ourname, int id,
-                       struct chap_digest_type *digest,
-                       unsigned char *challenge, unsigned char *response,
-                       char *message, int message_space);
-
-/* Called by digest code to register a digest type */
-extern void chap_register_digest(struct chap_digest_type *);
-
-/* Lookup a digest handler by type */
-extern struct chap_digest_type *chap_find_digest(int digest_code);
-
-/* Called by authentication code to start authenticating the peer. */
-extern void chap_auth_peer(int unit, char *our_name, int digest_code);
-
-/* Called by auth. code to start authenticating us to the peer. */
-extern void chap_auth_with_peer(int unit, char *our_name, int digest_code);
-
-/* Represents the CHAP protocol to the main pppd code */
-extern struct protent chap_protent;
-
-#endif
diff --git a/pppd/chap.c b/pppd/chap.c
new file mode 100644 (file)
index 0000000..7af7991
--- /dev/null
@@ -0,0 +1,692 @@
+/*
+ * chap.c - New CHAP implementation.
+ *
+ * Copyright (c) 2003-2024 Paul Mackerras. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "pppd-private.h"
+#include "options.h"
+#include "session.h"
+#include "chap.h"
+#include "chap-md5.h"
+
+#ifdef PPP_WITH_CHAPMS
+#include "chap_ms.h"
+#define MDTYPE_ALL (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5)
+#else
+#define MDTYPE_ALL (MDTYPE_MD5)
+#endif
+
+int chap_mdtype_all = MDTYPE_ALL;
+
+/* Hook for a plugin to validate CHAP challenge */
+chap_verify_hook_fn *chap_verify_hook = NULL;
+
+/*
+ * Option variables.
+ */
+int chap_server_timeout_time = 3;
+int chap_max_transmits = 10;
+int chap_rechallenge_time = 0;
+int chap_client_timeout_time = 60;
+int chapms_strip_domain = 0;
+
+/*
+ * Command-line options.
+ */
+static struct option chap_option_list[] = {
+       { "chap-restart", o_int, &chap_server_timeout_time,
+         "Set timeout for CHAP (as server)", OPT_PRIO },
+       { "chap-max-challenge", o_int, &chap_max_transmits,
+         "Set max #xmits for challenge", OPT_PRIO },
+       { "chap-interval", o_int, &chap_rechallenge_time,
+         "Set interval for rechallenge", OPT_PRIO },
+       { "chap-timeout", o_int, &chap_client_timeout_time,
+         "Set timeout for CHAP (as client)", OPT_PRIO },
+       { "chapms-strip-domain", o_bool, &chapms_strip_domain,
+         "Strip the domain prefix before the Username", 1 },
+       { NULL }
+};
+
+/*
+ * Internal state.
+ */
+static struct chap_client_state {
+       int flags;
+       char *name;
+       struct chap_digest_type *digest;
+       unsigned char priv[64];         /* private area for digest's use */
+} client;
+
+/*
+ * These limits apply to challenge and response packets we send.
+ * The +4 is the +1 that we actually need rounded up.
+ */
+#define CHAL_MAX_PKTLEN        (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN)
+#define RESP_MAX_PKTLEN        (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN)
+
+static struct chap_server_state {
+       int flags;
+       int id;
+       char *name;
+       struct chap_digest_type *digest;
+       int challenge_xmits;
+       int challenge_pktlen;
+       unsigned char challenge[CHAL_MAX_PKTLEN];
+       char message[256];
+} server;
+
+/* Values for flags in chap_client_state and chap_server_state */
+#define LOWERUP                        1
+#define AUTH_STARTED           2
+#define AUTH_DONE              4
+#define AUTH_FAILED            8
+#define TIMEOUT_PENDING                0x10
+#define CHALLENGE_VALID                0x20
+
+/*
+ * Prototypes.
+ */
+static void chap_init(int unit);
+static void chap_lowerup(int unit);
+static void chap_lowerdown(int unit);
+static void chap_server_timeout(void *arg);
+static void chap_client_timeout(void *arg);
+static void chap_generate_challenge(struct chap_server_state *ss);
+static void chap_handle_response(struct chap_server_state *ss, int code,
+               unsigned char *pkt, int len);
+static chap_verify_hook_fn chap_verify_response;
+static void chap_respond(struct chap_client_state *cs, int id,
+               unsigned char *pkt, int len);
+static void chap_handle_status(struct chap_client_state *cs, int code, int id,
+               unsigned char *pkt, int len);
+static void chap_protrej(int unit);
+static void chap_input(int unit, unsigned char *pkt, int pktlen);
+static int chap_print_pkt(unsigned char *p, int plen,
+               void (*printer)(void *, char *, ...), void *arg);
+
+/* List of digest types that we know about */
+static struct chap_digest_type *chap_digests;
+
+/*
+ * chap_init - reset to initial state.
+ */
+static void
+chap_init(int unit)
+{
+       memset(&client, 0, sizeof(client));
+       memset(&server, 0, sizeof(server));
+
+       chap_md5_init();
+#ifdef PPP_WITH_CHAPMS
+       chapms_init();
+#endif
+}
+
+/*
+ * Add a new digest type to the list.
+ */
+void
+chap_register_digest(struct chap_digest_type *dp)
+{
+       dp->next = chap_digests;
+       chap_digests = dp;
+}
+
+/*
+ * Lookup a digest type by code
+ */
+struct chap_digest_type *
+chap_find_digest(int digest_code) {
+       struct chap_digest_type *dp = NULL;
+       for (dp = chap_digests; dp != NULL; dp = dp->next)
+               if (dp->code == digest_code)
+                       break;
+       return dp;
+}
+
+/*
+ * chap_lowerup - we can start doing stuff now.
+ */
+static void
+chap_lowerup(int unit)
+{
+       struct chap_client_state *cs = &client;
+       struct chap_server_state *ss = &server;
+
+       cs->flags |= LOWERUP;
+       ss->flags |= LOWERUP;
+       if (ss->flags & AUTH_STARTED)
+               chap_server_timeout(ss);
+}
+
+static void
+chap_lowerdown(int unit)
+{
+       struct chap_client_state *cs = &client;
+       struct chap_server_state *ss = &server;
+
+       if (cs->flags & TIMEOUT_PENDING)
+               UNTIMEOUT(chap_client_timeout, cs);
+       cs->flags = 0;
+       if (ss->flags & TIMEOUT_PENDING)
+               UNTIMEOUT(chap_server_timeout, ss);
+       ss->flags = 0;
+}
+
+/*
+ * chap_auth_peer - Start authenticating the peer.
+ * If the lower layer is already up, we start sending challenges,
+ * otherwise we wait for the lower layer to come up.
+ */
+void
+chap_auth_peer(int unit, char *our_name, int digest_code)
+{
+       struct chap_server_state *ss = &server;
+       struct chap_digest_type *dp;
+
+       if (ss->flags & AUTH_STARTED) {
+               error("CHAP: peer authentication already started!");
+               return;
+       }
+
+       dp = chap_find_digest(digest_code);
+       if (dp == NULL)
+               fatal("CHAP digest 0x%x requested but not available",
+                     digest_code);
+
+       ss->digest = dp;
+       ss->name = our_name;
+       /* Start with a random ID value */
+       ss->id = (unsigned char)(drand48() * 256);
+       ss->flags |= AUTH_STARTED;
+       if (ss->flags & LOWERUP)
+               chap_server_timeout(ss);
+}
+
+/*
+ * chap_auth_with_peer - Prepare to authenticate ourselves to the peer.
+ * There isn't much to do until we receive a challenge.
+ */
+void
+chap_auth_with_peer(int unit, char *our_name, int digest_code)
+{
+       struct chap_client_state *cs = &client;
+       struct chap_digest_type *dp;
+
+       if (cs->flags & AUTH_STARTED) {
+               error("CHAP: authentication with peer already started!");
+               return;
+       }
+       for (dp = chap_digests; dp != NULL; dp = dp->next)
+               if (dp->code == digest_code)
+                       break;
+       if (dp == NULL)
+               fatal("CHAP digest 0x%x requested but not available",
+                     digest_code);
+
+       cs->digest = dp;
+       cs->name = our_name;
+       cs->flags |= AUTH_STARTED | TIMEOUT_PENDING;
+       TIMEOUT(chap_client_timeout, cs, chap_client_timeout_time);
+}
+
+/*
+ * chap_server_timeout - It's time to send another challenge to the peer.
+ * This could be either a retransmission of a previous challenge,
+ * or a new challenge to start re-authentication.
+ */
+static void
+chap_server_timeout(void *arg)
+{
+       struct chap_server_state *ss = arg;
+
+       ss->flags &= ~TIMEOUT_PENDING;
+       if ((ss->flags & CHALLENGE_VALID) == 0) {
+               ss->challenge_xmits = 0;
+               chap_generate_challenge(ss);
+               ss->flags |= CHALLENGE_VALID;
+       } else if (ss->challenge_xmits >= chap_max_transmits) {
+               ss->flags &= ~CHALLENGE_VALID;
+               ss->flags |= AUTH_DONE | AUTH_FAILED;
+               auth_peer_fail(0, PPP_CHAP);
+               return;
+       }
+
+       output(0, ss->challenge, ss->challenge_pktlen);
+       ++ss->challenge_xmits;
+       ss->flags |= TIMEOUT_PENDING;
+       TIMEOUT(chap_server_timeout, arg, chap_server_timeout_time);
+}
+
+/* chap_client_timeout - Authentication with peer timed out. */
+static void
+chap_client_timeout(void *arg)
+{
+       struct chap_client_state *cs = arg;
+
+       cs->flags &= ~TIMEOUT_PENDING;
+       cs->flags |= AUTH_DONE | AUTH_FAILED;
+       error("CHAP authentication timed out");
+       auth_withpeer_fail(0, PPP_CHAP);
+}
+
+/*
+ * chap_generate_challenge - generate a challenge string and format
+ * the challenge packet in ss->challenge_pkt.
+ */
+static void
+chap_generate_challenge(struct chap_server_state *ss)
+{
+       int clen = 1, nlen, len;
+       unsigned char *p;
+
+       p = ss->challenge;
+       MAKEHEADER(p, PPP_CHAP);
+       p += CHAP_HDRLEN;
+       ss->digest->generate_challenge(p);
+       clen = *p;
+       nlen = strlen(ss->name);
+       memcpy(p + 1 + clen, ss->name, nlen);
+
+       len = CHAP_HDRLEN + 1 + clen + nlen;
+       ss->challenge_pktlen = PPP_HDRLEN + len;
+
+       p = ss->challenge + PPP_HDRLEN;
+       p[0] = CHAP_CHALLENGE;
+       p[1] = ++ss->id;
+       p[2] = len >> 8;
+       p[3] = len;
+}
+
+/*
+ * chap_handle_response - check the response to our challenge.
+ */
+static void
+chap_handle_response(struct chap_server_state *ss, int id,
+                    unsigned char *pkt, int len)
+{
+       int response_len, ok, mlen;
+       unsigned char *response, *p;
+       char *name = NULL;
+       chap_verify_hook_fn *verifier;
+       char rname[MAXNAMELEN+1];
+
+       if ((ss->flags & LOWERUP) == 0)
+               return;
+       if (id != ss->challenge[PPP_HDRLEN+1] || len < 2)
+               return;
+       if (ss->flags & CHALLENGE_VALID) {
+               response = pkt;
+               GETCHAR(response_len, pkt);
+               len -= response_len + 1;        /* length of name */
+               name = (char *)pkt + response_len;
+               if (len < 0)
+                       return;
+
+               if (ss->flags & TIMEOUT_PENDING) {
+                       ss->flags &= ~TIMEOUT_PENDING;
+                       UNTIMEOUT(chap_server_timeout, ss);
+               }
+
+               if (explicit_remote) {
+                       name = remote_name;
+               } else {
+                       /* Null terminate and clean remote name. */
+                       slprintf(rname, sizeof(rname), "%.*v", len, name);
+                       name = rname;
+
+                       /* strip the MS domain name */
+                       if (chapms_strip_domain && strrchr(rname, '\\')) {
+                               char tmp[MAXNAMELEN+1];
+
+                               strcpy(tmp, strrchr(rname, '\\') + 1);
+                               strcpy(rname, tmp);
+                       }
+               }
+
+               if (chap_verify_hook)
+                       verifier = chap_verify_hook;
+               else
+                       verifier = chap_verify_response;
+               ok = (*verifier)(name, ss->name, id, ss->digest,
+                                ss->challenge + PPP_HDRLEN + CHAP_HDRLEN,
+                                response, ss->message, sizeof(ss->message));
+               if (!ok || !auth_number()) {
+                       ss->flags |= AUTH_FAILED;
+                       warn("Peer %q failed CHAP authentication", name);
+               }
+       } else if ((ss->flags & AUTH_DONE) == 0)
+               return;
+
+       /* send the response */
+       p = outpacket_buf;
+       MAKEHEADER(p, PPP_CHAP);
+       mlen = strlen(ss->message);
+       len = CHAP_HDRLEN + mlen;
+       p[0] = (ss->flags & AUTH_FAILED)? CHAP_FAILURE: CHAP_SUCCESS;
+       p[1] = id;
+       p[2] = len >> 8;
+       p[3] = len;
+       if (mlen > 0)
+               memcpy(p + CHAP_HDRLEN, ss->message, mlen);
+       output(0, outpacket_buf, PPP_HDRLEN + len);
+
+       if (ss->flags & CHALLENGE_VALID) {
+               ss->flags &= ~CHALLENGE_VALID;
+               if (!(ss->flags & AUTH_DONE) && !(ss->flags & AUTH_FAILED)) {
+                   /*
+                    * Auth is OK, so now we need to check session restrictions
+                    * to ensure everything is OK, but only if we used a
+                    * plugin, and only if we're configured to check.  This
+                    * allows us to do PAM checks on PPP servers that
+                    * authenticate against ActiveDirectory, and use AD for
+                    * account info (like when using Winbind integrated with
+                    * PAM).
+                    */
+                   if (session_mgmt &&
+                       session_check(name, NULL, devnam, NULL) == 0) {
+                       ss->flags |= AUTH_FAILED;
+                       warn("Peer %q failed CHAP Session verification", name);
+                   }
+               }
+               if (ss->flags & AUTH_FAILED) {
+                       auth_peer_fail(0, PPP_CHAP);
+               } else {
+                       if ((ss->flags & AUTH_DONE) == 0)
+                               auth_peer_success(0, PPP_CHAP,
+                                                 ss->digest->code,
+                                                 name, strlen(name));
+                       if (chap_rechallenge_time) {
+                               ss->flags |= TIMEOUT_PENDING;
+                               TIMEOUT(chap_server_timeout, ss,
+                                       chap_rechallenge_time);
+                       }
+               }
+               ss->flags |= AUTH_DONE;
+       }
+}
+
+/*
+ * chap_verify_response - check whether the peer's response matches
+ * what we think it should be.  Returns 1 if it does (authentication
+ * succeeded), or 0 if it doesn't.
+ */
+static int
+chap_verify_response(char *name, char *ourname, int id,
+                    struct chap_digest_type *digest,
+                    unsigned char *challenge, unsigned char *response,
+                    char *message, int message_space)
+{
+       int ok;
+       unsigned char secret[MAXSECRETLEN];
+       int secret_len;
+
+       /* Get the secret that the peer is supposed to know */
+       if (!get_secret(0, name, ourname, (char *)secret, &secret_len, 1)) {
+               error("No CHAP secret found for authenticating %q", name);
+               return 0;
+       }
+
+       ok = digest->verify_response(id, name, secret, secret_len, challenge,
+                                    response, message, message_space);
+       memset(secret, 0, sizeof(secret));
+
+       return ok;
+}
+
+/*
+ * chap_respond - Generate and send a response to a challenge.
+ */
+static void
+chap_respond(struct chap_client_state *cs, int id,
+            unsigned char *pkt, int len)
+{
+       int clen, nlen;
+       int secret_len;
+       unsigned char *p;
+       unsigned char response[RESP_MAX_PKTLEN];
+       char rname[MAXNAMELEN+1];
+       char secret[MAXSECRETLEN+1];
+
+       if ((cs->flags & (LOWERUP | AUTH_STARTED)) != (LOWERUP | AUTH_STARTED))
+               return;         /* not ready */
+       if (len < 2 || len < pkt[0] + 1)
+               return;         /* too short */
+       clen = pkt[0];
+       nlen = len - (clen + 1);
+
+       /* Null terminate and clean remote name. */
+       slprintf(rname, sizeof(rname), "%.*v", nlen, pkt + clen + 1);
+
+       /* Microsoft doesn't send their name back in the PPP packet */
+       if (explicit_remote || (remote_name[0] != 0 && rname[0] == 0))
+               strlcpy(rname, remote_name, sizeof(rname));
+
+       /* get secret for authenticating ourselves with the specified host */
+       if (!get_secret(0, cs->name, rname, secret, &secret_len, 0)) {
+               secret_len = 0; /* assume null secret if can't find one */
+               warn("No CHAP secret found for authenticating us to %q", rname);
+       }
+
+       p = response;
+       MAKEHEADER(p, PPP_CHAP);
+       p += CHAP_HDRLEN;
+
+       cs->digest->make_response(p, id, cs->name, pkt,
+                                 secret, secret_len, cs->priv);
+       memset(secret, 0, secret_len);
+
+       clen = *p;
+       nlen = strlen(cs->name);
+       memcpy(p + clen + 1, cs->name, nlen);
+
+       p = response + PPP_HDRLEN;
+       len = CHAP_HDRLEN + clen + 1 + nlen;
+       p[0] = CHAP_RESPONSE;
+       p[1] = id;
+       p[2] = len >> 8;
+       p[3] = len;
+
+       output(0, response, PPP_HDRLEN + len);
+}
+
+static void
+chap_handle_status(struct chap_client_state *cs, int code, int id,
+                  unsigned char *pkt, int len)
+{
+       const char *msg = NULL;
+
+       if ((cs->flags & (AUTH_DONE|AUTH_STARTED|LOWERUP))
+           != (AUTH_STARTED|LOWERUP))
+               return;
+       cs->flags |= AUTH_DONE;
+
+       UNTIMEOUT(chap_client_timeout, cs);
+       cs->flags &= ~TIMEOUT_PENDING;
+
+       if (code == CHAP_SUCCESS) {
+               /* used for MS-CHAP v2 mutual auth, yuck */
+               if (cs->digest->check_success != NULL) {
+                       if (!(*cs->digest->check_success)(id, pkt, len))
+                               code = CHAP_FAILURE;
+               } else
+                       msg = "CHAP authentication succeeded";
+       } else {
+               if (cs->digest->handle_failure != NULL)
+                       (*cs->digest->handle_failure)(pkt, len);
+               else
+                       msg = "CHAP authentication failed";
+       }
+       if (msg) {
+               if (len > 0)
+                       info("%s: %.*v", msg, len, pkt);
+               else
+                       info("%s", msg);
+       }
+       if (code == CHAP_SUCCESS)
+               auth_withpeer_success(0, PPP_CHAP, cs->digest->code);
+       else {
+               cs->flags |= AUTH_FAILED;
+               error("CHAP authentication failed");
+               auth_withpeer_fail(0, PPP_CHAP);
+       }
+}
+
+static void
+chap_input(int unit, unsigned char *pkt, int pktlen)
+{
+       struct chap_client_state *cs = &client;
+       struct chap_server_state *ss = &server;
+       unsigned char code, id;
+       int len;
+
+       if (pktlen < CHAP_HDRLEN)
+               return;
+       GETCHAR(code, pkt);
+       GETCHAR(id, pkt);
+       GETSHORT(len, pkt);
+       if (len < CHAP_HDRLEN || len > pktlen)
+               return;
+       len -= CHAP_HDRLEN;
+
+       switch (code) {
+       case CHAP_CHALLENGE:
+               chap_respond(cs, id, pkt, len);
+               break;
+       case CHAP_RESPONSE:
+               chap_handle_response(ss, id, pkt, len);
+               break;
+       case CHAP_FAILURE:
+       case CHAP_SUCCESS:
+               chap_handle_status(cs, code, id, pkt, len);
+               break;
+       }
+}
+
+static void
+chap_protrej(int unit)
+{
+       struct chap_client_state *cs = &client;
+       struct chap_server_state *ss = &server;
+
+       if (ss->flags & TIMEOUT_PENDING) {
+               ss->flags &= ~TIMEOUT_PENDING;
+               UNTIMEOUT(chap_server_timeout, ss);
+       }
+       if (ss->flags & AUTH_STARTED) {
+               ss->flags = 0;
+               auth_peer_fail(0, PPP_CHAP);
+       }
+       if ((cs->flags & (AUTH_STARTED|AUTH_DONE)) == AUTH_STARTED) {
+               cs->flags &= ~AUTH_STARTED;
+               error("CHAP authentication failed due to protocol-reject");
+               auth_withpeer_fail(0, PPP_CHAP);
+       }
+}
+
+/*
+ * chap_print_pkt - print the contents of a CHAP packet.
+ */
+static char *chap_code_names[] = {
+       "Challenge", "Response", "Success", "Failure"
+};
+
+static int
+chap_print_pkt(unsigned char *p, int plen,
+              void (*printer)(void *, char *, ...), void *arg)
+{
+       int code, id, len;
+       int clen, nlen;
+       unsigned char x;
+
+       if (plen < CHAP_HDRLEN)
+               return 0;
+       GETCHAR(code, p);
+       GETCHAR(id, p);
+       GETSHORT(len, p);
+       if (len < CHAP_HDRLEN || len > plen)
+               return 0;
+
+       if (code >= 1 && code <= sizeof(chap_code_names) / sizeof(char *))
+               printer(arg, " %s", chap_code_names[code-1]);
+       else
+               printer(arg, " code=0x%x", code);
+       printer(arg, " id=0x%x", id);
+       len -= CHAP_HDRLEN;
+       switch (code) {
+       case CHAP_CHALLENGE:
+       case CHAP_RESPONSE:
+               if (len < 1)
+                       break;
+               clen = p[0];
+               if (len < clen + 1)
+                       break;
+               ++p;
+               nlen = len - clen - 1;
+               printer(arg, " <");
+               for (; clen > 0; --clen) {
+                       GETCHAR(x, p);
+                       printer(arg, "%.2x", x);
+               }
+               printer(arg, ">, name = ");
+               print_string((char *)p, nlen, printer, arg);
+               break;
+       case CHAP_FAILURE:
+       case CHAP_SUCCESS:
+               printer(arg, " ");
+               print_string((char *)p, len, printer, arg);
+               break;
+       default:
+               for (clen = len; clen > 0; --clen) {
+                       GETCHAR(x, p);
+                       printer(arg, " %.2x", x);
+               }
+       }
+
+       return len + CHAP_HDRLEN;
+}
+
+struct protent chap_protent = {
+       PPP_CHAP,
+       chap_init,
+       chap_input,
+       chap_protrej,
+       chap_lowerup,
+       chap_lowerdown,
+       NULL,           /* open */
+       NULL,           /* close */
+       chap_print_pkt,
+       NULL,           /* datainput */
+       1,              /* enabled_flag */
+       "CHAP",         /* name */
+       NULL,           /* data_name */
+       chap_option_list,
+       NULL,           /* check_options */
+};
diff --git a/pppd/chap.h b/pppd/chap.h
new file mode 100644 (file)
index 0000000..77c077e
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * chap.h - New CHAP implementation.
+ *
+ * Copyright (c) 2003-2024 Paul Mackerras. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef PPP_CHAP_NEW_H
+#define PPP_CHAP_NEW_H
+
+#include "pppdconf.h"
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+/*
+ * CHAP packets begin with a standard header with code, id, len (2 bytes).
+ */
+#define CHAP_HDRLEN    4
+
+/*
+ * Values for the code field.
+ */
+#define CHAP_CHALLENGE 1
+#define CHAP_RESPONSE  2
+#define CHAP_SUCCESS   3
+#define CHAP_FAILURE   4
+
+/*
+ * CHAP digest codes.
+ */
+#define CHAP_MD5               5
+#define CHAP_MICROSOFT         0x80
+#define CHAP_MICROSOFT_V2      0x81
+
+/*
+ * Semi-arbitrary limits on challenge and response fields.
+ */
+#define MAX_CHALLENGE_LEN      64
+#define MAX_RESPONSE_LEN       64
+
+/* bitmask of supported algorithms */
+#define MDTYPE_MICROSOFT_V2    0x1
+#define MDTYPE_MICROSOFT       0x2
+#define MDTYPE_MD5             0x4
+#define MDTYPE_NONE            0
+
+/* hashes supported by this instance of pppd */
+extern int chap_mdtype_all;
+
+/* Return the digest alg. ID for the most preferred digest type. */
+#define CHAP_DIGEST(mdtype) \
+    ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
+    ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
+    ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
+    0
+
+/* Return the bit flag (lsb set) for our most preferred digest type. */
+#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
+
+/* Return the bit flag for a given digest algorithm ID. */
+#define CHAP_MDTYPE_D(digest) \
+    ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
+    ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
+    ((digest) == CHAP_MD5)? MDTYPE_MD5: \
+    0
+
+/* Can we do the requested digest? */
+#define CHAP_CANDIGEST(mdtype, digest) \
+    ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
+    ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
+    ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
+    0
+
+
+/*
+ * The code for each digest type has to supply one of these.
+ */
+struct chap_digest_type {
+       int code;
+
+       /*
+        * Note: challenge and response arguments below are formatted as
+        * a length byte followed by the actual challenge/response data.
+        */
+       void (*generate_challenge)(unsigned char *challenge);
+       int (*verify_response)(int id, char *name,
+               unsigned char *secret, int secret_len,
+               unsigned char *challenge, unsigned char *response,
+               char *message, int message_space);
+       void (*make_response)(unsigned char *response, int id, char *our_name,
+               unsigned char *challenge, char *secret, int secret_len,
+               unsigned char *priv);
+       int (*check_success)(int id, unsigned char *pkt, int len);
+       void (*handle_failure)(unsigned char *pkt, int len);
+
+       struct chap_digest_type *next;
+};
+
+/*
+ * This function will return a value of 1 to indicate that a plugin intend to supply
+ *   a username or a password to pppd through the chap_passwd_hook callback.
+ *
+ * Return a value > 0 to avoid parsing the chap-secrets file.
+ */
+typedef int (chap_check_hook_fn)(void);
+extern chap_check_hook_fn *chap_check_hook;
+
+/*
+ * A plugin can chose to supply its own user and password overriding whatever
+ *   has been provided by the configuration. Hook is only valid when pppd is
+ *   acting as a client.
+ *
+ * The maximum size of the user argument is always MAXNAMELEN
+ * The length of the password is always MAXWORDLEN, however; secrets can't be
+ *   longer than MAXSECRETLEN
+ *
+ * Return a value < 0 to fail the connection.
+ */
+typedef int (chap_passwd_hook_fn)(char *user, char *password);
+extern chap_passwd_hook_fn *chap_passwd_hook;
+
+/*
+ * A plugin can chose to replace the default chap_verify_response function with
+ *   one of their own.
+ */
+typedef int (chap_verify_hook_fn)(char *name, char *ourname, int id,
+                       struct chap_digest_type *digest,
+                       unsigned char *challenge, unsigned char *response,
+                       char *message, int message_space);
+extern chap_verify_hook_fn *chap_verify_hook;
+
+/* Called by digest code to register a digest type */
+extern void chap_register_digest(struct chap_digest_type *);
+
+/* Lookup a digest handler by type */
+extern struct chap_digest_type *chap_find_digest(int digest_code);
+
+/* Called by authentication code to start authenticating the peer. */
+extern void chap_auth_peer(int unit, char *our_name, int digest_code);
+
+/* Called by auth. code to start authenticating us to the peer. */
+extern void chap_auth_with_peer(int unit, char *our_name, int digest_code);
+
+/* Represents the CHAP protocol to the main pppd code */
+extern struct protent chap_protent;
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif // PPP_CHAP_NEW_H
index 8e59280cbee6aab7b284b13a5222fa2b322a2f8e..6c8ef9196188c025e3e59c4db8ba1dbfc6234ea7 100644 (file)
@@ -74,8 +74,6 @@
  *
  */
 
-#define RCSID  "$Id: chap_ms.c,v 1.38 2007/12/01 20:10:51 carlsonj Exp $"
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 #include <linux/ppp-comp.h>
 #endif
 
-#include "pppd.h"
-#include "chap-new.h"
+#include "pppd-private.h"
+#include "options.h"
+#include "chap.h"
 #include "chap_ms.h"
-#include "md4.h"
-#include "sha1.h"
-#include "pppcrypt.h"
 #include "magic.h"
 #include "mppe.h"
+#include "crypto.h"
+#include "crypto_ms.h"
 
 #ifdef UNIT_TEST
 #undef PPP_WITH_MPPE
 #endif
 
 static void    ascii2unicode (char[], int, u_char[]);
-static void    NTPasswordHash (u_char *, int, u_char[MD4_SIGNATURE_SIZE]);
-static void    ChallengeResponse (u_char *, u_char *, u_char[24]);
+static void    NTPasswordHash (u_char *, int, unsigned char *);
+static int     ChallengeResponse (u_char *, u_char *, u_char*);
 static void    ChapMS_NT (u_char *, char *, int, u_char[24]);
 static void    ChapMS2_NT (u_char *, u_char[16], char *, char *, int,
                                u_char[24]);
@@ -140,7 +138,7 @@ static char *mschap2_peer_challenge = NULL;
 /*
  * Command-line options.
  */
-static option_t chapms_option_list[] = {
+static struct option chapms_option_list[] = {
 #ifdef PPP_WITH_MSLANMAN
        { "ms-lanman", o_bool, &ms_lanman,
          "Use LanMan passwd when using MS-CHAP", 1 },
@@ -504,31 +502,31 @@ print_msg:
        free(msg);
 }
 
-static void
+static int
 ChallengeResponse(u_char *challenge,
-                 u_char PasswordHash[MD4_SIGNATURE_SIZE],
-                 u_char response[24])
+                 u_char *PasswordHash,
+                 u_char *response)
 {
-    u_char    ZPasswordHash[21];
+    u_char ZPasswordHash[24];
+    PPP_CIPHER_CTX *ctx;
 
     BZERO(ZPasswordHash, sizeof(ZPasswordHash));
-    BCOPY(PasswordHash, ZPasswordHash, MD4_SIGNATURE_SIZE);
+    BCOPY(PasswordHash, ZPasswordHash, MD4_DIGEST_LENGTH);
 
 #if 0
     dbglog("ChallengeResponse - ZPasswordHash %.*B",
           sizeof(ZPasswordHash), ZPasswordHash);
 #endif
 
-    (void) DesSetkey(ZPasswordHash + 0);
-    DesEncrypt(challenge, response + 0);
-    (void) DesSetkey(ZPasswordHash + 7);
-    DesEncrypt(challenge, response + 8);
-    (void) DesSetkey(ZPasswordHash + 14);
-    DesEncrypt(challenge, response + 16);
+    if (DesEncrypt(challenge, ZPasswordHash + 0,  response + 0) &&
+        DesEncrypt(challenge, ZPasswordHash + 7,  response + 8) &&
+        DesEncrypt(challenge, ZPasswordHash + 14, response + 16))
+        return 1;
 
 #if 0
     dbglog("ChallengeResponse - response %.24B", response);
 #endif
+    return 0;
 }
 
 void
@@ -536,23 +534,40 @@ ChallengeHash(u_char PeerChallenge[16], u_char *rchallenge,
              char *username, u_char Challenge[8])
     
 {
-    SHA1_CTX   sha1Context;
-    u_char     sha1Hash[SHA1_SIGNATURE_SIZE];
-    char       *user;
+    PPP_MD_CTX* ctx;
+    u_char     hash[SHA_DIGEST_LENGTH];
+    int     hash_len;
+    const char *user;
 
     /* remove domain from "domain\username" */
     if ((user = strrchr(username, '\\')) != NULL)
        ++user;
     else
        user = username;
+    
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, PeerChallenge, 16)) {
+
+                if (PPP_DigestUpdate(ctx, rchallenge, 16)) {
+
+                    if (PPP_DigestUpdate(ctx, user, strlen(user))) {
+                        
+                        hash_len = SHA_DIGEST_LENGTH;
+                        if (PPP_DigestFinal(ctx, hash, &hash_len)) {
 
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, PeerChallenge, 16);
-    SHA1_Update(&sha1Context, rchallenge, 16);
-    SHA1_Update(&sha1Context, (unsigned char *)user, strlen(user));
-    SHA1_Final(sha1Hash, &sha1Context);
+                            BCOPY(hash, Challenge, 8);
+                        }
+                    }
+                }
+            }
+        }
 
-    BCOPY(sha1Hash, Challenge, 8);
+        PPP_MD_CTX_free(ctx);
+    }
 }
 
 /*
@@ -573,28 +588,22 @@ ascii2unicode(char ascii[], int ascii_len, u_char unicode[])
 }
 
 static void
-NTPasswordHash(u_char *secret, int secret_len, u_char hash[MD4_SIGNATURE_SIZE])
+NTPasswordHash(u_char *secret, int secret_len, unsigned char* hash)
 {
-#if defined(__NetBSD__) || !defined(USE_MD4)
-    /* NetBSD uses the libc md4 routines which take bytes instead of bits */
-    int                        mdlen = secret_len;
-#else
-    int                        mdlen = secret_len * 8;
-#endif
-    MD4_CTX            md4Context;
-
-    MD4Init(&md4Context);
-#if !defined(USE_MD4)
-    /* Internal MD4Update can take at most 64 bytes at a time */
-    while (mdlen > 512) {
-       MD4Update(&md4Context, secret, 512);
-       secret += 64;
-       mdlen -= 512;
-    }
-#endif
-    MD4Update(&md4Context, secret, mdlen);
-    MD4Final(hash, &md4Context);
+    PPP_MD_CTX* ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
 
+        if (PPP_DigestInit(ctx, PPP_md4())) {
+
+            if (PPP_DigestUpdate(ctx, secret, secret_len)) {
+
+                int hash_len = MD4_DIGEST_LENGTH;
+                PPP_DigestFinal(ctx, hash, &hash_len);
+            }
+        }
+        
+        PPP_MD_CTX_free(ctx);
+    }
 }
 
 static void
@@ -602,7 +611,7 @@ ChapMS_NT(u_char *rchallenge, char *secret, int secret_len,
          u_char NTResponse[24])
 {
     u_char     unicodePassword[MAX_NT_PASSWORD * 2];
-    u_char     PasswordHash[MD4_SIGNATURE_SIZE];
+    u_char     PasswordHash[MD4_DIGEST_LENGTH];
 
     /* Hash the Unicode version of the secret (== password). */
     ascii2unicode(secret, secret_len, unicodePassword);
@@ -616,7 +625,7 @@ ChapMS2_NT(u_char *rchallenge, u_char PeerChallenge[16], char *username,
           char *secret, int secret_len, u_char NTResponse[24])
 {
     u_char     unicodePassword[MAX_NT_PASSWORD * 2];
-    u_char     PasswordHash[MD4_SIGNATURE_SIZE];
+    u_char     PasswordHash[MD4_DIGEST_LENGTH];
     u_char     Challenge[8];
 
     ChallengeHash(PeerChallenge, rchallenge, username, Challenge);
@@ -637,26 +646,27 @@ ChapMS_LANMan(u_char *rchallenge, char *secret, int secret_len,
 {
     int                        i;
     u_char             UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
-    u_char             PasswordHash[MD4_SIGNATURE_SIZE];
+    u_char             PasswordHash[MD4_DIGEST_LENGTH];
 
     /* LANMan password is case insensitive */
     BZERO(UcasePassword, sizeof(UcasePassword));
     for (i = 0; i < secret_len; i++)
        UcasePassword[i] = (u_char)toupper(secret[i]);
-    (void) DesSetkey(UcasePassword + 0);
-    DesEncrypt( StdText, PasswordHash + 0 );
-    (void) DesSetkey(UcasePassword + 7);
-    DesEncrypt( StdText, PasswordHash + 8 );
-    ChallengeResponse(rchallenge, PasswordHash, &response[MS_CHAP_LANMANRESP]);
+
+    if (DesEncrypt(StdText, UcasePassword + 0, PasswordHash + 0) &&
+        DesEncrypt(StdText, UcasePassword + 7, PasswordHash + 8)) {
+
+        ChallengeResponse(rchallenge, PasswordHash, &response[MS_CHAP_LANMANRESP]);
+    }
 }
 #endif
 
 
 void
-GenerateAuthenticatorResponse(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
-                             u_char NTResponse[24], u_char PeerChallenge[16],
-                             u_char *rchallenge, char *username,
-                             u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1])
+GenerateAuthenticatorResponse(unsigned char* PasswordHashHash,
+                             unsigned char *NTResponse, unsigned char *PeerChallenge,
+                             unsigned char *rchallenge, char *username,
+                             unsigned char *authResponse)
 {
     /*
      * "Magic" constants used in response generation, from RFC 2759.
@@ -674,27 +684,58 @@ GenerateAuthenticatorResponse(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
          0x6E };
 
     int                i;
-    SHA1_CTX   sha1Context;
-    u_char     Digest[SHA1_SIGNATURE_SIZE];
+    PPP_MD_CTX *ctx;
+    u_char     Digest[SHA_DIGEST_LENGTH] = {};
+    int     hash_len;
     u_char     Challenge[8];
 
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
-    SHA1_Update(&sha1Context, NTResponse, 24);
-    SHA1_Update(&sha1Context, Magic1, sizeof(Magic1));
-    SHA1_Final(Digest, &sha1Context);
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, PasswordHashHash, MD4_DIGEST_LENGTH)) {
+
+                if (PPP_DigestUpdate(ctx, NTResponse, 24)) {
 
+                    if (PPP_DigestUpdate(ctx, Magic1, sizeof(Magic1))) {
+                        
+                        hash_len = sizeof(Digest);
+                        PPP_DigestFinal(ctx, Digest, &hash_len);
+                    }
+                }
+            }
+        }
+        PPP_MD_CTX_free(ctx);
+    }
+    
     ChallengeHash(PeerChallenge, rchallenge, username, Challenge);
 
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, Digest, sizeof(Digest));
-    SHA1_Update(&sha1Context, Challenge, sizeof(Challenge));
-    SHA1_Update(&sha1Context, Magic2, sizeof(Magic2));
-    SHA1_Final(Digest, &sha1Context);
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, Digest, sizeof(Digest))) {
+
+                if (PPP_DigestUpdate(ctx, Challenge, sizeof(Challenge))) {
+
+                    if (PPP_DigestUpdate(ctx, Magic2, sizeof(Magic2))) {
+                        
+                        hash_len = sizeof(Digest);
+                        PPP_DigestFinal(ctx, Digest, &hash_len);
+                    }
+                }
+            }
+        }
+
+        PPP_MD_CTX_free(ctx);
+    }
 
     /* Convert to ASCII hex string. */
-    for (i = 0; i < MAX((MS_AUTH_RESPONSE_LENGTH / 2), sizeof(Digest)); i++)
-       sprintf((char *)&authResponse[i * 2], "%02X", Digest[i]);
+    for (i = 0; i < MAX((MS_AUTH_RESPONSE_LENGTH / 2), sizeof(Digest)); i++) {
+        sprintf((char *)&authResponse[i * 2], "%02X", Digest[i]);
+    }
 }
 
 
@@ -706,8 +747,8 @@ GenerateAuthenticatorResponsePlain
                 u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1])
 {
     u_char     unicodePassword[MAX_NT_PASSWORD * 2];
-    u_char     PasswordHash[MD4_SIGNATURE_SIZE];
-    u_char     PasswordHashHash[MD4_SIGNATURE_SIZE];
+    u_char     PasswordHash[MD4_DIGEST_LENGTH];
+    u_char     PasswordHashHash[MD4_DIGEST_LENGTH];
 
     /* Hash (x2) the Unicode version of the secret (== password). */
     ascii2unicode(secret, secret_len, unicodePassword);
@@ -729,8 +770,8 @@ static void
 Set_Start_Key(u_char *rchallenge, char *secret, int secret_len)
 {
     u_char     unicodePassword[MAX_NT_PASSWORD * 2];
-    u_char     PasswordHash[MD4_SIGNATURE_SIZE];
-    u_char     PasswordHashHash[MD4_SIGNATURE_SIZE];
+    u_char     PasswordHash[MD4_DIGEST_LENGTH];
+    u_char     PasswordHashHash[MD4_DIGEST_LENGTH];
 
     /* Hash (x2) the Unicode version of the secret (== password). */
     ascii2unicode(secret, secret_len, unicodePassword);
@@ -747,8 +788,8 @@ static void
 SetMasterKeys(char *secret, int secret_len, u_char NTResponse[24], int IsServer)
 {
     u_char     unicodePassword[MAX_NT_PASSWORD * 2];
-    u_char     PasswordHash[MD4_SIGNATURE_SIZE];
-    u_char     PasswordHashHash[MD4_SIGNATURE_SIZE];
+    u_char     PasswordHash[MD4_DIGEST_LENGTH];
+    u_char     PasswordHashHash[MD4_DIGEST_LENGTH];
     /* Hash (x2) the Unicode version of the secret (== password). */
     ascii2unicode(secret, secret_len, unicodePassword);
     NTPasswordHash(unicodePassword, secret_len * 2, PasswordHash);
@@ -794,7 +835,7 @@ ChapMS(u_char *rchallenge, char *secret, int secret_len,
  * Authenticator Response.
  */
 void
-ChapMS2(u_char *rchallenge, u_char *PeerChallenge,
+ChapMS2(unsigned char *rchallenge, unsigned char *PeerChallenge,
        char *user, char *secret, int secret_len, unsigned char *response,
        u_char authResponse[], int authenticator)
 {
@@ -853,7 +894,7 @@ chapms_init(void)
 {
        chap_register_digest(&chapms_digest);
        chap_register_digest(&chapms2_digest);
-       add_options(chapms_option_list);
+       ppp_add_options(chapms_option_list);
 }
 #else
 
@@ -874,10 +915,10 @@ void random_bytes(unsigned char *bytes, int len)
 
 
 int test_chap_v1(void) {
-    char *secret = "TestPassword";
+    char *secret = "MyPw";
 
     unsigned char challenge[8] = {
-        0x6c, 0x8d, 0x4b, 0xa1, 0x2b, 0x5c, 0x13, 0xc3
+        0x10, 0x2D, 0xB5, 0xDF, 0x08, 0x5D, 0x30, 0x41
     };
     unsigned char response[MS_CHAP_RESPONSE_LEN] = {
     };
@@ -886,9 +927,10 @@ int test_chap_v1(void) {
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 
-        0x91, 0x09, 0x61, 0x5a, 0x0c, 0xac, 0xac, 0x55,
-        0x1f, 0x60, 0xe2, 0x9c, 0x00, 0xac, 0x24, 0xda,
-        0x6e, 0xa5, 0x7b, 0xdb, 0x1d, 0x6a, 0x17, 0xc5,
+        0x4E, 0x9D, 0x3C, 0x8F, 0x9C, 0xFD, 0x38, 0x5D,
+        0x5B, 0xF4, 0xD3, 0x24, 0x67, 0x91, 0x95, 0x6C,
+        0xA4, 0xC3, 0x51, 0xAB, 0x40, 0x9A, 0x3D, 0x61,
+
         0x01
     };
 
@@ -929,6 +971,8 @@ int test_chap_v2(void) {
 }
 
 int main(int argc, char *argv[]) {
+    
+    PPP_crypto_init();
 
     if (test_chap_v1()) {
         printf("CHAPv1 failed\n");
@@ -940,6 +984,8 @@ int main(int argc, char *argv[]) {
         return -1;
     }
 
+    PPP_crypto_deinit();
+
     printf("Success\n");
     return 0;
 }
index 7b08cfff312317cfec7b353b811ec05c37358950..7bcbbfcce4196fa9e04a5a9d40e18e93b960473f 100644 (file)
@@ -26,8 +26,6 @@
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: chap_ms.h,v 1.13 2004/11/15 22:13:26 paulus Exp $
  */
 
 #ifndef PPP_CHAPMS_H
 
 #include "pppdconf.h"
 
-#define MD4_SIGNATURE_SIZE     16      /* 16 bytes in a MD4 message digest */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MAX_NT_PASSWORD                256     /* Max (Unicode) chars in an NT pass */
 
 #define MS_CHAP_RESPONSE_LEN   49      /* Response length for MS-CHAP */
@@ -79,13 +80,25 @@ void ChapMS (u_char *, char *, int, u_char *);
 void ChapMS2 (u_char *, u_char *, char *, char *, int,
              u_char *, u_char[MS_AUTH_RESPONSE_LENGTH+1], int);
 
-void   ChallengeHash (u_char[16], u_char *, char *, u_char[8]);
+void ChallengeHash (u_char[16], u_char *, char *, u_char[8]);
 
-void GenerateAuthenticatorResponse(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
-                       u_char NTResponse[24], u_char PeerChallenge[16],
-                       u_char *rchallenge, char *username,
-                       u_char authResponse[MS_AUTH_RESPONSE_LENGTH+1]);
+
+/**
+ * PasswordHashHash - 16 bytes representing the NT Password Hash Hash
+ * NTResponse - 24 bytes  represending the NTResponse parameter
+ * PeerChallenge - 16 bytes challange for peer
+ * rchallenge - 16 bytes challenge provided by peer
+ * authResponse - 24 + 1 byte to store the authenticator response
+ */
+void GenerateAuthenticatorResponse(unsigned char *PasswordHashHash,
+                       unsigned char *NTResponse, unsigned char *PeerChallenge,
+                       unsigned char *rchallenge, char *username,
+                       unsigned char *authResponse);
 
 void chapms_init(void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* PPP_CHAPMS_H */
diff --git a/pppd/crypto-priv.h b/pppd/crypto-priv.h
new file mode 100644 (file)
index 0000000..6c9d152
--- /dev/null
@@ -0,0 +1,69 @@
+/* ppp-crypo-priv.h - Crypto private data structures
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef PPP_CRYPTO_PRIV_H
+#define PPP_CRYPTO_PRIV_H
+
+#include "crypto.h"
+
+#define MAX_KEY_SIZE 32
+#define MAX_IV_SIZE 32
+
+struct _PPP_MD
+{
+    int  (*init_fn)(PPP_MD_CTX *ctx);
+    int  (*update_fn)(PPP_MD_CTX *ctx, const void *data, size_t cnt);
+    int  (*final_fn)(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *outlen);
+    void (*clean_fn)(PPP_MD_CTX *ctx);
+};
+
+struct _PPP_MD_CTX
+{
+    PPP_MD md;
+    void *priv;
+};
+
+struct _PPP_CIPHER
+{
+    int  (*init_fn)(PPP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv);
+    int  (*update_fn)(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
+    int  (*final_fn)(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
+    void (*clean_fn)(PPP_CIPHER_CTX *ctx);
+};
+
+struct _PPP_CIPHER_CTX
+{
+    PPP_CIPHER cipher;
+    unsigned char key[MAX_KEY_SIZE];
+    unsigned char iv[MAX_IV_SIZE];
+    int is_encr;
+    void *priv;
+};
+
+
+#endif
diff --git a/pppd/crypto.c b/pppd/crypto.c
new file mode 100644 (file)
index 0000000..8e98261
--- /dev/null
@@ -0,0 +1,571 @@
+/* ppp-crypto.c - Generic API for access to crypto/digest functions.
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "pppd.h"
+#include "crypto.h"
+#include "crypto-priv.h"
+
+#ifdef PPP_WITH_OPENSSL
+#include <openssl/opensslv.h>
+#include <openssl/err.h>
+
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#include <openssl/provider.h>
+struct crypto_ctx {
+
+    OSSL_PROVIDER *legacy;
+    OSSL_PROVIDER *provider;
+} g_crypto_ctx;
+#endif
+#endif
+
+PPP_MD_CTX *PPP_MD_CTX_new()
+{
+    return (PPP_MD_CTX*) calloc(1, sizeof(PPP_MD_CTX));
+}
+
+void PPP_MD_CTX_free(PPP_MD_CTX* ctx)
+{
+    if (ctx) {
+        if (ctx->md.clean_fn) {
+            ctx->md.clean_fn(ctx);
+        }
+        free(ctx);
+    }
+}
+
+int PPP_DigestInit(PPP_MD_CTX *ctx, const PPP_MD *type)
+{
+    int ret = 0;
+    if (ctx) {
+        ctx->md = *type;
+        if (ctx->md.init_fn) {
+            ret = ctx->md.init_fn(ctx);
+            if (!ret) {
+                PPP_crypto_error("Could not initialize digest");
+            }
+        }
+    }
+    return ret;
+}
+
+int PPP_DigestUpdate(PPP_MD_CTX *ctx, const void *data, size_t length)
+{
+    int ret = 0;
+    if (ctx && ctx->md.update_fn) {
+        ret = ctx->md.update_fn(ctx, data, length);
+        if (!ret) {
+            PPP_crypto_error("Could not update digest");
+        }
+    }
+    return ret;
+}
+
+int PPP_DigestFinal(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *outlen)
+{
+    int ret = 0;
+    if (ctx && ctx->md.final_fn) {
+        ret = ctx->md.final_fn(ctx, out, outlen);
+        if (!ret) {
+            PPP_crypto_error("Could not perform final digest");
+        }
+    }
+    return ret;
+}
+
+PPP_CIPHER_CTX *PPP_CIPHER_CTX_new(void)
+{
+    return calloc(1, sizeof(PPP_CIPHER_CTX));
+}
+
+void PPP_CIPHER_CTX_free(PPP_CIPHER_CTX *ctx)
+{
+    if (ctx) {
+        if (ctx->cipher.clean_fn) {
+            ctx->cipher.clean_fn(ctx);
+        }
+        memset(ctx->iv, 0, sizeof(ctx->iv));
+        memset(ctx->key, 0, sizeof(ctx->key));
+        free(ctx);
+    }
+}
+
+int PPP_CipherInit(PPP_CIPHER_CTX *ctx, const PPP_CIPHER *cipher, const unsigned char *key, const unsigned char *iv, int encr)
+{
+    int ret = 0;
+    if (ctx && cipher) {
+        ret = 1;
+        ctx->is_encr = encr;
+        ctx->cipher = *cipher;
+        if (ctx->cipher.init_fn) {
+            ret = ctx->cipher.init_fn(ctx, key, iv);
+            if (!ret) {
+                PPP_crypto_error("Could not initialize cipher");
+            }
+        }
+    }
+    return ret;
+}
+
+int PPP_CipherUpdate(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
+{
+    int ret = 0;
+    if (ctx && ctx->cipher.update_fn) {
+        ret = ctx->cipher.update_fn(ctx, out, outl, in, inl);
+        if (!ret) {
+            PPP_crypto_error("Could not perform crypto operation");
+        }
+    }
+    return ret;
+}
+
+int PPP_CipherFinal(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
+{
+    int ret = 0;
+    if (ctx && ctx->cipher.final_fn) {
+        ret = ctx->cipher.final_fn(ctx, out, outl);
+        if (!ret) {
+            PPP_crypto_error("Could not perform final crypto operation");
+        }
+    }
+    return ret;
+}
+
+void
+PPP_crypto_error(char *fmt, ...)
+{
+    va_list args;
+    char buf[1024];
+    int len = sizeof(buf);
+    int off = 0;
+    int err = 0;
+
+    va_start(args, fmt);
+    off = vsnprintf(buf, len, fmt, args);
+    va_end(args);
+
+#ifdef PPP_WITH_OPENSSL
+    err = ERR_peek_error();
+    if (err == 0 || (len-off) < 130) {
+        error("%s", buf);
+        return;
+    }
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+    ERR_load_crypto_strings();
+#endif
+    error("%s, %s\n", buf, ERR_reason_error_string(err));
+#else
+    error("%s", buf);
+#endif
+}
+
+
+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)
+    {
+        PPP_crypto_error("Could not load legacy provider");
+        goto done;
+    }
+
+    g_crypto_ctx.provider = OSSL_PROVIDER_load(NULL, "default");
+    if (g_crypto_ctx.provider == NULL)
+    {
+        PPP_crypto_error("Could not load default provider");
+        goto done;
+    }
+#endif
+#endif
+
+    retval = 1;
+
+done:
+
+    return retval;
+}
+
+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);
+        g_crypto_ctx.legacy = NULL;
+    }
+
+    if (g_crypto_ctx.provider) {
+        OSSL_PROVIDER_unload(g_crypto_ctx.provider);
+        g_crypto_ctx.provider = NULL;
+    }
+#endif
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+    ERR_free_strings();
+#endif
+#endif
+    return 1;
+}
+
+#ifdef UNIT_TEST
+
+int debug;
+int error_count;
+int unsuccess;
+
+
+int test_md4()
+{
+    PPP_MD_CTX* ctx = NULL;
+    int success = 0;
+
+    unsigned char data[84] = {
+        0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+        0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69,
+        0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
+        0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65,
+        0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20,
+        0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
+        0x6b, 0x65, 0x79, 0x2e
+    };
+
+    unsigned int  hash_len;
+    unsigned char hash[MD4_DIGEST_LENGTH];
+    unsigned char result[MD4_DIGEST_LENGTH] = {
+        0x58, 0xcb, 0x37, 0x91, 0x1d, 0x06, 0x7b, 0xdf,
+        0xfd, 0x48, 0x6d, 0x87, 0x4a, 0x35, 0x5b, 0xd4
+    };
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx) {
+
+        if (PPP_DigestInit(ctx, PPP_md4())) {
+
+            if (PPP_DigestUpdate(ctx, &data, sizeof(data))) {
+
+                hash_len = sizeof(hash);
+                if (PPP_DigestFinal(ctx, hash, &hash_len)) {
+
+                    if (memcmp(hash, result, MD4_DIGEST_LENGTH) == 0) {
+                        success = 1;
+                    }
+                }
+            }
+        }
+        PPP_MD_CTX_free(ctx);
+    }
+
+    return success;
+}
+
+int test_md5()
+{
+    PPP_MD_CTX* ctx = NULL;
+    int success = 0;
+
+    unsigned char data[84] = {
+        0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+        0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69,
+        0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
+        0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65,
+        0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20,
+        0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
+        0x6b, 0x65, 0x79, 0x2e
+    };
+
+    unsigned int  hash_len;
+    unsigned char hash[MD5_DIGEST_LENGTH];
+    unsigned char result[MD5_DIGEST_LENGTH] = {
+        0x8b, 0xe3, 0x5e, 0x2c, 0x9f, 0x95, 0xbf, 0x4e,
+        0x16, 0xe4, 0x53, 0xbe, 0x52, 0xf4, 0xbc, 0x4e
+    };
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx) {
+
+        if (PPP_DigestInit(ctx, PPP_md5())) {
+
+            if (PPP_DigestUpdate(ctx, &data, sizeof(data))) {
+
+                hash_len = sizeof(hash);
+                if (PPP_DigestFinal(ctx, hash, &hash_len)) {
+
+                    if (memcmp(hash, result, MD5_DIGEST_LENGTH) == 0) {
+                        success = 1;
+                    }
+                }
+            }
+        }
+        PPP_MD_CTX_free(ctx);
+    }
+
+    return success;
+}
+
+int test_sha()
+{
+    PPP_MD_CTX* ctx = NULL;
+    int success = 0;
+
+    unsigned char data[84] = {
+        0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+        0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69,
+        0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
+        0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65,
+        0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20,
+        0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20,
+        0x6b, 0x65, 0x79, 0x2e
+    };
+
+    unsigned int  hash_len;
+    unsigned char hash[SHA_DIGEST_LENGTH];
+    unsigned char result[SHA_DIGEST_LENGTH] = {
+        0xa8, 0x03, 0xae, 0x21, 0x30, 0xd8, 0x40, 0xbe,
+        0x27, 0xa3, 0x47, 0xc7, 0x7a, 0x90, 0xe6, 0xa3,
+        0x5b, 0xd5, 0x0e, 0x45
+    };
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, &data, sizeof(data))) {
+
+                hash_len = sizeof(hash);
+                if (PPP_DigestFinal(ctx, hash, &hash_len)) {
+
+                    if (memcmp(hash, result, SHA_DIGEST_LENGTH) == 0) {
+                        success = 1;
+                    }
+                }
+            }
+        }
+        PPP_MD_CTX_free(ctx);
+    }
+
+    return success;
+}
+
+int test_des_encrypt()
+{
+    PPP_CIPHER_CTX* ctx = NULL;
+    int success = 0;
+
+    unsigned char key[8] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+    };
+
+    unsigned char plain[80] = {
+        0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+        0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69,
+        0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
+        0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65,
+        0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20,
+        0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20
+    };
+    unsigned char expect[80] = {
+        0x45, 0xdb, 0x80, 0x45, 0x16, 0xd0, 0x6d, 0x60,
+        0x92, 0x23, 0x4b, 0xd3, 0x9d, 0x36, 0xb8, 0x1a,
+        0xa4, 0x1a, 0xf7, 0xb1, 0x60, 0xfb, 0x74, 0x16,
+        0xa6, 0xdc, 0xe1, 0x14, 0xb7, 0xed, 0x48, 0x5a,
+        0x2b, 0xed, 0x68, 0x9d, 0x19, 0xd6, 0xb1, 0xb8,
+        0x91, 0xff, 0xea, 0x62, 0xac, 0xe7, 0x49, 0xdd,
+        0xfa, 0x4d, 0xa4, 0x01, 0x3f, 0xea, 0xca, 0xb4,
+        0xb6, 0xdc, 0xd3, 0x04, 0x45, 0x07, 0x74, 0xed,
+        0xa6, 0xdc, 0xe1, 0x14, 0xb7, 0xed, 0x48, 0x5a,
+        0xbb, 0x9b, 0x13, 0x31, 0xf4, 0xa9, 0x32, 0x49
+    };
+
+    unsigned char cipher[80] = {};
+    int cipher_len = 0;
+    int offset = 0;
+
+
+    ctx = PPP_CIPHER_CTX_new();
+    if (ctx) {
+
+        if (PPP_CipherInit(ctx, PPP_des_ecb(), key, NULL, 1)) {
+
+            if (PPP_CipherUpdate(ctx, cipher, &cipher_len, plain, sizeof(plain))) {
+
+                offset += cipher_len;
+
+                if (PPP_CipherFinal(ctx, cipher+offset, &cipher_len)) {
+
+                    if (memcmp(cipher, expect, 80) == 0) {
+
+                        success = 1;
+                    }
+                }
+            }
+        }
+        PPP_CIPHER_CTX_free(ctx);
+    }
+
+    return success;
+}
+
+
+int test_des_decrypt()
+{
+    PPP_CIPHER_CTX* ctx = NULL;
+    int success = 0;
+
+    unsigned char key[8] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+    };
+
+    unsigned char cipher[80] = {
+        0x45, 0xdb, 0x80, 0x45, 0x16, 0xd0, 0x6d, 0x60,
+        0x92, 0x23, 0x4b, 0xd3, 0x9d, 0x36, 0xb8, 0x1a,
+        0xa4, 0x1a, 0xf7, 0xb1, 0x60, 0xfb, 0x74, 0x16,
+        0xa6, 0xdc, 0xe1, 0x14, 0xb7, 0xed, 0x48, 0x5a,
+        0x2b, 0xed, 0x68, 0x9d, 0x19, 0xd6, 0xb1, 0xb8,
+        0x91, 0xff, 0xea, 0x62, 0xac, 0xe7, 0x49, 0xdd,
+        0xfa, 0x4d, 0xa4, 0x01, 0x3f, 0xea, 0xca, 0xb4,
+        0xb6, 0xdc, 0xd3, 0x04, 0x45, 0x07, 0x74, 0xed,
+        0xa6, 0xdc, 0xe1, 0x14, 0xb7, 0xed, 0x48, 0x5a,
+        0xbb, 0x9b, 0x13, 0x31, 0xf4, 0xa9, 0x32, 0x49
+    };
+
+    unsigned char expect[80] = {
+        0x4f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63,
+        0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x73, 0x69,
+        0x64, 0x65, 0x2c, 0x20, 0x74, 0x68, 0x69, 0x73,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x73, 0x65, 0x6e, 0x64, 0x20, 0x6b, 0x65, 0x79,
+        0x3b, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65,
+        0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20,
+        0x73, 0x69, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x74,
+        0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
+        0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x20
+    };
+
+    unsigned char plain[80] = {};
+    int outlen = 0;
+    int offset = 0;
+
+    ctx = PPP_CIPHER_CTX_new();
+    if (ctx) {
+
+        if (PPP_CipherInit(ctx, PPP_des_ecb(), key, NULL, 0)) {
+
+            if (PPP_CipherUpdate(ctx, plain, &outlen, cipher, sizeof(cipher))) {
+
+                offset += outlen;
+
+                if (PPP_CipherFinal(ctx, plain+offset, &outlen)) {
+
+                    if (memcmp(plain, expect, 80) == 0) {
+
+                        success = 1;
+                    }
+                }
+            }
+        }
+        PPP_CIPHER_CTX_free(ctx);
+    }
+
+    return success;
+}
+
+int main(int argc, char *argv[])
+{
+    int failure = 0;
+
+    if (!PPP_crypto_init()) {
+        printf("Couldn't initialize crypto test\n");
+        return -1;
+    }
+
+    if (!test_md4()) {
+        printf("MD4 test failed\n");
+        failure++;
+    }
+
+    if (!test_md5()) {
+        printf("MD5 test failed\n");
+        failure++;
+    }
+
+    if (!test_sha()) {
+        printf("SHA test failed\n");
+        failure++;
+    }
+
+    if (!test_des_encrypt()) {
+        printf("DES encryption test failed\n");
+        failure++;
+    }
+
+    if (!test_des_decrypt()) {
+        printf("DES decryption test failed\n");
+        failure++;
+    }
+
+    if (!PPP_crypto_deinit()) {
+        printf("Couldn't deinitialize crypto test\n");
+        return -1;
+    }
+
+    return failure;
+}
+
+#endif
diff --git a/pppd/crypto.h b/pppd/crypto.h
new file mode 100644 (file)
index 0000000..013aefd
--- /dev/null
@@ -0,0 +1,168 @@
+/* ppp-crypto.h - Generic API for access to crypto/digest functions.
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef PPP_CRYPTO_H
+#define PPP_CRYPTO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef MD5_DIGEST_LENGTH
+#define MD5_DIGEST_LENGTH 16
+#endif
+
+#ifndef MD4_DIGEST_LENGTH
+#define MD4_DIGEST_LENGTH 16
+#endif
+
+#ifndef SHA_DIGEST_LENGTH
+#define SHA_DIGEST_LENGTH 20
+#endif
+
+struct _PPP_MD_CTX;
+struct _PPP_MD;
+
+typedef struct _PPP_MD_CTX PPP_MD_CTX;
+typedef struct _PPP_MD PPP_MD;
+
+/*
+ * Create a new Message Digest context object
+ */
+PPP_MD_CTX *PPP_MD_CTX_new();
+
+/*
+ * Free the Message Digest context
+ */
+void PPP_MD_CTX_free(PPP_MD_CTX*);
+
+/*
+ * Fetch the MD4 algorithm
+ */
+const PPP_MD *PPP_md4(void);
+
+/*
+ * Fetch the MD5 algorithm
+ */
+const PPP_MD *PPP_md5(void);
+
+/*
+ * Fetch the SHA1 algorithm
+ */
+const PPP_MD *PPP_sha1(void);
+
+/*
+ * Initializes a context object
+ */
+int PPP_DigestInit(PPP_MD_CTX *ctx,
+        const PPP_MD *type);
+
+/*
+ * For each iteration update the context with more input
+ */
+int PPP_DigestUpdate(PPP_MD_CTX *ctx,
+        const void *data, size_t cnt);
+
+/*
+ * Perform the final operation, and output the digest
+ */
+int PPP_DigestFinal(PPP_MD_CTX *ctx,
+        unsigned char *out, unsigned int *outlen);
+
+
+struct _PPP_CIPHER_CTX;
+struct _PPP_CIPHER;
+
+typedef struct _PPP_CIPHER_CTX PPP_CIPHER_CTX;
+typedef struct _PPP_CIPHER PPP_CIPHER;
+
+
+/*
+ * Create a new Cipher Context
+ */
+PPP_CIPHER_CTX *PPP_CIPHER_CTX_new(void);
+
+/*
+ * Release the Cipher Context
+ */
+void PPP_CIPHER_CTX_free(PPP_CIPHER_CTX *ctx);
+
+/*
+ * Fetch the DES in ECB mode cipher algorithm
+ */
+const PPP_CIPHER *PPP_des_ecb(void);
+
+/*
+ * Set the particular data directly
+ */
+void PPP_CIPHER_CTX_set_cipher_data(PPP_CIPHER_CTX *ctx,
+        const unsigned char *key);
+
+/*
+ * Initialize the crypto operation
+ */
+int PPP_CipherInit(PPP_CIPHER_CTX *ctx,
+        const PPP_CIPHER *cipher,
+        const unsigned char *key,
+        const unsigned char *iv,
+        int encr);
+
+/*
+ * Encrypt input data, and store it in the output buffer
+ */
+int PPP_CipherUpdate(PPP_CIPHER_CTX *ctx,
+        unsigned char *out, int *outl,
+        const unsigned char *in, int inl);
+
+/*
+ * Finish the crypto operation, and fetch any outstanding bytes
+ */
+int PPP_CipherFinal(PPP_CIPHER_CTX *ctx,
+        unsigned char *out, int *outl);
+
+/*
+ * Log an error message to the log and append the crypto error
+ */
+void PPP_crypto_error(char *fmt, ...);
+
+/*
+ * Global initialization, must be called once per process
+ */
+int PPP_crypto_init();
+
+/*
+ * Global deinitialization
+ */
+int PPP_crypto_deinit();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PPP_CRYPTO_H
diff --git a/pppd/crypto_ms.c b/pppd/crypto_ms.c
new file mode 100644 (file)
index 0000000..ccf8129
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
+ *
+ * Extracted from chap_ms.c by James Carlson.
+ *
+ * Copyright (c) 1995 Eric Rosenquist.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sections of this code holds different copyright information.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stddef.h>
+
+#include "crypto.h"
+#include "crypto_ms.h"
+
+
+/*
+ * DES_set_odd_parity function are imported from openssl 3.0 project with the 
+ * follwoing license:
+ *
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+typedef unsigned char DES_cblock[8];
+#define DES_KEY_SZ      (sizeof(DES_cblock))
+
+static const unsigned char odd_parity[256] = {
+    1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
+    16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
+    32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
+    49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
+    64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
+    81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
+    97, 97, 98, 98, 100, 100, 103, 103, 104, 104, 107, 107, 109, 109, 110,
+    110,
+    112, 112, 115, 115, 117, 117, 118, 118, 121, 121, 122, 122, 124, 124, 127,
+    127,
+    128, 128, 131, 131, 133, 133, 134, 134, 137, 137, 138, 138, 140, 140, 143,
+    143,
+    145, 145, 146, 146, 148, 148, 151, 151, 152, 152, 155, 155, 157, 157, 158,
+    158,
+    161, 161, 162, 162, 164, 164, 167, 167, 168, 168, 171, 171, 173, 173, 174,
+    174,
+    176, 176, 179, 179, 181, 181, 182, 182, 185, 185, 186, 186, 188, 188, 191,
+    191,
+    193, 193, 194, 194, 196, 196, 199, 199, 200, 200, 203, 203, 205, 205, 206,
+    206,
+    208, 208, 211, 211, 213, 213, 214, 214, 217, 217, 218, 218, 220, 220, 223,
+    223,
+    224, 224, 227, 227, 229, 229, 230, 230, 233, 233, 234, 234, 236, 236, 239,
+    239,
+    241, 241, 242, 242, 244, 244, 247, 247, 248, 248, 251, 251, 253, 253, 254,
+    254
+};
+
+static void DES_set_odd_parity(DES_cblock *key)
+{
+    unsigned int i;
+    for (i = 0; i < DES_KEY_SZ; i++)
+        (*key)[i] = odd_parity[(*key)[i]];
+}
+
+static unsigned char
+Get7Bits(const unsigned char *input, int startBit)
+{
+       unsigned int word;
+
+       word  = (unsigned)input[startBit / 8] << 8;
+       word |= (unsigned)input[startBit / 8 + 1];
+
+       word >>= 15 - (startBit % 8 + 7);
+
+       return word & 0xFE;
+}
+
+static void
+MakeKey(const unsigned char *key, unsigned char *des_key)
+{
+       /* key     IN  56 bit DES key missing parity bits */
+       /* des_key OUT 64 bit DES key with parity bits added */
+       des_key[0] = Get7Bits(key,  0);
+       des_key[1] = Get7Bits(key,  7);
+       des_key[2] = Get7Bits(key, 14);
+       des_key[3] = Get7Bits(key, 21);
+       des_key[4] = Get7Bits(key, 28);
+       des_key[5] = Get7Bits(key, 35);
+       des_key[6] = Get7Bits(key, 42);
+       des_key[7] = Get7Bits(key, 49);
+
+       DES_set_odd_parity((DES_cblock *)des_key);
+}
+
+int
+DesEncrypt(const unsigned char *clear, const unsigned char *key, unsigned char *cipher)
+{
+    int retval = 0;
+    unsigned int clen = 0;
+    unsigned char des_key[8];
+
+    PPP_CIPHER_CTX *ctx = PPP_CIPHER_CTX_new();
+    if (ctx) {
+
+        MakeKey(key, des_key);
+        
+        if (PPP_CipherInit(ctx, PPP_des_ecb(), des_key, NULL, 1)) {
+
+            if (PPP_CipherUpdate(ctx, cipher, &clen, clear, 8)) {
+
+                if (PPP_CipherFinal(ctx, cipher + clen, &clen)) {
+
+                    retval = 1;
+                }
+            }
+        }
+        
+        PPP_CIPHER_CTX_free(ctx);
+    }
+
+       return (retval);
+}
+
+int
+DesDecrypt(const unsigned char *cipher, const unsigned char *key, unsigned char *clear)
+{
+    int retval = 0;
+    unsigned int clen = 0;
+    unsigned char des_key[8];
+
+    PPP_CIPHER_CTX *ctx = PPP_CIPHER_CTX_new();
+    if (ctx) {
+
+        MakeKey(key, des_key);
+        
+        if (PPP_CipherInit(ctx, PPP_des_ecb(), des_key, NULL, 0)) {
+
+            if (PPP_CipherUpdate(ctx, clear, &clen, cipher, 8)) {
+
+                if (PPP_CipherFinal(ctx, clear + clen, &clen)) {
+
+                    retval = 1;
+                }
+            }
+        }
+        
+        PPP_CIPHER_CTX_free(ctx);
+    }
+
+       return (retval);
+}
+
+#ifdef UNIT_TEST_MSCRYPTO
+
+#include <string.h>
+#include <stdio.h>
+
+/**
+ * The test-vectors are taken from RFC2759.
+ */
+int test_encrypt()
+{
+    unsigned char Challenge[8] = { 
+        0xD0, 0x2E, 0x43, 0x86, 0xBC, 0xE9, 0x12, 0x26
+    };  
+
+    unsigned char ZPasswordHash[24] = {
+        0x44, 0xEB, 0xBA, 0x8D, 0x53, 0x12, 0xB8, 0xD6,
+        0x11, 0x47, 0x44, 0x11, 0xF5, 0x69, 0x89, 0xAE
+    };
+
+    unsigned char expected[24] = { 
+        0x82, 0x30, 0x9E, 0xCD, 0x8D, 0x70, 0x8B, 0x5E, 
+        0xA0, 0x8F, 0xAA, 0x39, 0x81, 0xCD, 0x83, 0x54, 
+        0x42, 0x33, 0x11, 0x4A, 0x3D, 0x85, 0xD6, 0xDF
+    };  
+    unsigned char response[24] = {}; 
+    unsigned int retval = 0;
+
+    DesEncrypt(Challenge, ZPasswordHash + 0,  response + 0);
+    DesEncrypt(Challenge, ZPasswordHash + 7,  response + 8);
+    DesEncrypt(Challenge, ZPasswordHash + 14, response + 16);
+
+    return memcmp(response, expected, sizeof(response)) == 0;
+}
+
+int test_decrypt()
+{
+    unsigned char Challenge[8] = {
+        0xD0, 0x2E, 0x43, 0x86, 0xBC, 0xE9, 0x12, 0x26
+    };
+
+    unsigned char ZPasswordHash[24] = {
+        0x44, 0xEB, 0xBA, 0x8D, 0x53, 0x12, 0xB8, 0xD6,
+        0x11, 0x47, 0x44, 0x11, 0xF5, 0x69, 0x89, 0xAE
+    };
+
+    unsigned char Response[24] = {
+        0x82, 0x30, 0x9E, 0xCD, 0x8D, 0x70, 0x8B, 0x5E,
+        0xA0, 0x8F, 0xAA, 0x39, 0x81, 0xCD, 0x83, 0x54,
+        0x42, 0x33, 0x11, 0x4A, 0x3D, 0x85, 0xD6, 0xDF
+    };
+    unsigned char Output[8];
+    unsigned int failure = 0;
+
+    if (DesDecrypt(Response + 0, ZPasswordHash + 0, Output)) {
+        failure += memcmp(Challenge, Output, sizeof(Challenge));
+    }
+
+    if (DesDecrypt(Response + 8, ZPasswordHash + 7, Output)) {
+        failure += memcmp(Challenge, Output, sizeof(Challenge));
+    }
+
+    if (DesDecrypt(Response +16, ZPasswordHash +14, Output)) {
+        failure += memcmp(Challenge, Output, sizeof(Challenge));
+    }
+
+    return failure == 0;
+}
+
+int main(int argc, char *argv[])
+{
+    int failure = 0;
+
+    if (!PPP_crypto_init()) {
+        printf("Couldn't initialize crypto test\n");
+        return -1;
+    }
+
+    if (!test_encrypt()) {
+        printf("CHAP DES encryption test failed\n");
+        failure++;
+    }
+
+    if (!test_decrypt()) {
+        printf("CHAP DES decryption test failed\n");
+        failure++;
+    }
+
+    if (!PPP_crypto_deinit()) {
+        printf("Couldn't deinitialize crypto test\n");
+        return -1;
+    }
+
+    return failure;
+}
+
+#endif
diff --git a/pppd/crypto_ms.h b/pppd/crypto_ms.h
new file mode 100644 (file)
index 0000000..38111fd
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
+ *
+ * Extracted from chap_ms.c by James Carlson.
+ * Updated to better reflect RFC2759 by Eivind Naess
+ *
+ * Copyright (c) 2022 Eivind Naess.  All rights reserved.
+ * Copyright (c) 1995 Eric Rosenquist.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef PPP_PPPCRYPT_H
+#define        PPP_PPPCRYPT_H
+
+#include "pppdconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the DES encrypt functions as described by RFC2759.
+ * 
+ * Parameters:
+ * const unsigned char *clear:
+ *      A 8 byte input array to be encrypted
+ * 
+ * const unsigned char *key:
+ *      A raw 7-byte array to be expanded to 8 with odd-parity
+ *
+ * unsigned char *cipher:
+ *      A 8 byte outut array providing space for the output data
+ *
+ * DesEncrypt returns 1 on success
+ */
+int DesEncrypt(const unsigned char *clear, const unsigned char *key,
+        unsigned char *cipher);
+
+/**
+ * This is the DES decrypt functions as described by RFC2759.
+ * 
+ * Parameters:
+ * const unsigned char *cipher:
+ *      A 8 byte input array to be decrypted
+ *
+ * const unsigned char *key:
+ *      A raw 7-byte array to be expanded to a 8-byte key with odd-parity
+ *
+ * unsigned char *clear:
+ *      A 8 byte output array providing space for the output data
+ *
+ * DesDecrypt returns 1 on success
+ */
+int DesDecrypt(const unsigned char *cipher, const unsigned char *key,
+        unsigned char *clear);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PPP_PPPCRYPT_H */
index d610d69ac282ea83d9ca841bdea21b7c6663906a..d8c46fea032beddc20587d8e81d574244ab40a4e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * demand.c - Support routines for demand-dialling.
  *
- * Copyright (c) 1996-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1996-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -28,8 +24,6 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: demand.c,v 1.20 2005/08/25 12:14:18 paulus Exp $"
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -51,7 +45,7 @@
 #include <pcap-bpf.h>
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
 #include "ipcp.h"
 #include "lcp.h"
@@ -97,7 +91,7 @@ demand_conf(void)
     flush_flag = 0;
     fcs = PPP_INITFCS;
 
-    netif_set_mtu(0, MIN(lcp_allowoptions[0].mru, PPP_MRU));
+    ppp_set_mtu(0, MIN(lcp_allowoptions[0].mru, PPP_MRU));
     if (ppp_send_config(0, PPP_MRU, (u_int32_t) 0, 0, 0) < 0
        || ppp_recv_config(0, PPP_MRU, (u_int32_t) 0, 0, 0) < 0)
            fatal("Couldn't set up demand-dialled PPP interface: %m");
index 69e34a1d7cc9023f37f9b0f18474b89bd80df438..4c0b99b33125af1c4f9176964bb562722744121e 100644 (file)
@@ -51,7 +51,7 @@
 #include <openssl/x509v3.h>
 #include <openssl/pkcs12.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "tls.h"
 #include "eap.h"
 #include "eap-tls.h"
@@ -158,10 +158,10 @@ CONF *eaptls_ssl_load_config( void )
 
     config = NCONF_new( NULL );
     dbglog( "Loading OpenSSL config file" );
-    ret_code = NCONF_load( config, _PATH_OPENSSLCONFFILE, &error_line );
+    ret_code = NCONF_load( config, PPP_PATH_OPENSSLCONFFILE, &error_line );
     if (ret_code == 0)
     {
-        warn( "EAP-TLS: Error in OpenSSL config file %s at line %d", _PATH_OPENSSLCONFFILE, error_line );
+        warn( "EAP-TLS: Error in OpenSSL config file %s at line %d", PPP_PATH_OPENSSLCONFFILE, error_line );
         NCONF_free( config );
         config = NULL;
         ERR_clear_error();
@@ -171,7 +171,9 @@ CONF *eaptls_ssl_load_config( void )
 #ifndef OPENSSL_NO_ENGINE
     ENGINE_load_builtin_engines();
 #endif
+#if !defined(LIBRESSL_VERSION_NUMBER) || (LIBRESSL_VERSION_NUMBER < 0x4000000fL)
     OPENSSL_load_builtin_modules();
+#endif
    
     dbglog( "Loading OpenSSL configured modules" );
     if (CONF_modules_load( config, NULL, 0 ) <= 0 )
index 4ad67a5c5eb70810ccbfb632819eb98907394d21..70154664432e8e90904d901bf311aa6511036a57 100644 (file)
 #include <assert.h>
 #include <errno.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "pathnames.h"
-#include "md5.h"
+#include "crypto.h"
+#include "crypto_ms.h"
 #include "eap.h"
 #ifdef PPP_WITH_PEAP
 #include "peap.h"
 #include <t_pwd.h>
 #include <t_server.h>
 #include <t_client.h>
-#include "pppcrypt.h"
 #endif /* PPP_WITH_SRP */
 
-#ifndef SHA_DIGESTSIZE
-#define        SHA_DIGESTSIZE 20
-#endif
-
 #ifdef PPP_WITH_EAPTLS
 #include "eap-tls.h"
 #endif /* PPP_WITH_EAPTLS */
 
 #ifdef PPP_WITH_CHAPMS
+#include "chap.h"
 #include "chap_ms.h"
-#include "chap-new.h"
 
 extern int chapms_strip_domain;
 #endif /* PPP_WITH_CHAPMS */
@@ -104,7 +101,7 @@ static char *pn_secret = NULL;              /* Pseudonym generating secret */
 /*
  * Command-line options.
  */
-static option_t eap_option_list[] = {
+static struct option eap_option_list[] = {
     { "eap-restart", o_int, &eap_states[0].es_server.ea_timeout,
       "Set retransmit timeout for EAP Requests (server)" },
     { "eap-max-sreq", o_int, &eap_states[0].es_server.ea_maxrequests,
@@ -333,24 +330,33 @@ eap_send_success(eap_state *esp)
  * date.
  */
 static bool
-pncrypt_setkey(int timeoffs)
+pncrypt_getkey(int timeoffs, unsigned char *key, int keylen)
 {
        struct tm *tp;
        char tbuf[9];
-       SHA1_CTX ctxt;
-       u_char dig[SHA_DIGESTSIZE];
+       PPP_MD_CTX *ctxt;
        time_t reftime;
 
        if (pn_secret == NULL)
                return (0);
        reftime = time(NULL) + timeoffs;
        tp = localtime(&reftime);
-       SHA1Init(&ctxt);
-       SHA1Update(&ctxt, pn_secret, strlen(pn_secret));
-       strftime(tbuf, sizeof (tbuf), "%Y%m%d", tp);
-       SHA1Update(&ctxt, tbuf, strlen(tbuf));
-       SHA1Final(dig, &ctxt);
-       return (DesSetkey(dig));
+
+       ctxt = PPP_MD_CTX_new();
+       if (ctxt) {
+
+           strftime(tbuf, sizeof (tbuf), "%Y%m%d", tp);
+
+           PPP_DigestInit(ctxt, PPP_sha1());
+           PPP_DigestUpdate(ctxt, pn_secret, strlen(pn_secret));
+           PPP_DigestUpdate(ctxt, tbuf, strlen(tbuf));
+           PPP_DigestFinal(ctxt, key, &keylen);
+
+           PPP_MD_CTX_free(ctxt);
+           return 1;
+       }
+
+       return (0);
 }
 
 static char base64[] =
@@ -435,12 +441,12 @@ static void
 eap_figure_next_state(eap_state *esp, int status)
 {
 #ifdef PPP_WITH_SRP
-       unsigned char secbuf[MAXWORDLEN], clear[8], *sp, *dp;
+       unsigned char secbuf[MAXWORDLEN], clear[8], *sp, *dp, key[SHA_DIGEST_LENGTH];
        struct t_pw tpw;
        struct t_confent *tce, mytce;
        char *cp, *cp2;
        struct t_server *ts;
-       int id, i, plen, toffs;
+       int id, i, plen, clen, toffs, keylen;
        u_char vals[2];
        struct b64state bs;
 #endif /* PPP_WITH_SRP */
@@ -486,11 +492,12 @@ eap_figure_next_state(eap_state *esp, int status)
                            secbuf);
                        toffs = 0;
                        for (i = 0; i < 5; i++) {
-                               pncrypt_setkey(toffs);
+                               pncrypt_getkey(toffs, key, keylen);
                                toffs -= 86400;
-                               if (!DesDecrypt(secbuf, clear)) {
+
+                               if (!DesDecrypt(secbuf, key, clear)) {
                                        dbglog("no DES here; cannot decode "
-                                           "pseudonym");
+                                               "pseudonym");
                                        return;
                                }
                                id = *(unsigned char *)clear;
@@ -512,7 +519,7 @@ eap_figure_next_state(eap_state *esp, int status)
                                dp += i;
                                sp = secbuf + 8;
                                while (plen > 0) {
-                                       (void) DesDecrypt(sp, dp);
+                                       DesDecrypt(sp, key, dp);
                                        sp += 8;
                                        dp += 8;
                                        plen -= 8;
@@ -812,10 +819,10 @@ eap_send_request(eap_state *esp)
        char *str;
 #ifdef PPP_WITH_SRP
        struct t_server *ts;
-       u_char clear[8], cipher[8], dig[SHA_DIGESTSIZE], *optr, *cp;
-       int i, j;
+       u_char clear[8], cipher[8], dig[SHA_DIGEST_LENGTH], *optr, *cp, key[SHA_DIGEST_LENGTH];
+       int i, j, diglen, clen, keylen = sizeof(key);
        struct b64state b64;
-       SHA1_CTX ctxt;
+       PPP_MD_CTX *ctxt;
 #endif /* PPP_WITH_SRP */
 
        /* Handle both initial auth and restart */
@@ -975,10 +982,10 @@ eap_send_request(eap_state *esp)
                PUTLONG(SRPVAL_EBIT, outp);
                ts = (struct t_server *)esp->es_server.ea_session;
                assert(ts != NULL);
-               BCOPY(t_serverresponse(ts), outp, SHA_DIGESTSIZE);
-               INCPTR(SHA_DIGESTSIZE, outp);
+               BCOPY(t_serverresponse(ts), outp, SHA_DIGEST_LENGTH);
+               INCPTR(SHA_DIGEST_LENGTH, outp);
 
-               if (pncrypt_setkey(0)) {
+               if (pncrypt_getkey(0, key, keylen)) {
                        /* Generate pseudonym */
                        optr = outp;
                        cp = (unsigned char *)esp->es_server.ea_peer;
@@ -988,15 +995,17 @@ eap_send_request(eap_state *esp)
                        BCOPY(cp, clear + 1, j);
                        i -= j;
                        cp += j;
-                       if (!DesEncrypt(clear, cipher)) {
+
+                       if (!DesEncrypt(clear, key, cipher)) {
                                dbglog("no DES here; not generating pseudonym");
                                break;
-                       }
+            }
+
                        BZERO(&b64, sizeof (b64));
                        outp++;         /* space for pseudonym length */
                        outp += b64enc(&b64, cipher, 8, outp);
                        while (i >= 8) {
-                               (void) DesEncrypt(cp, cipher);
+                               DesEncrypt(cp, key, cipher);
                                outp += b64enc(&b64, cipher, 8, outp);
                                cp += 8;
                                i -= 8;
@@ -1008,7 +1017,8 @@ eap_send_request(eap_state *esp)
                                        *cp++ = drand48() * 0x100;
                                        i++;
                                }
-                               (void) DesEncrypt(clear, cipher);
+
+                               DesEncrypt(clear, key, cipher);
                                outp += b64enc(&b64, cipher, 8, outp);
                        }
                        outp += b64flush(&b64, outp);
@@ -1016,32 +1026,40 @@ eap_send_request(eap_state *esp)
                        /* Set length and pad out to next 20 octet boundary */
                        i = outp - optr - 1;
                        *optr = i;
-                       i %= SHA_DIGESTSIZE;
+                       i %= SHA_DIGEST_LENGTH;
                        if (i != 0) {
-                               while (i < SHA_DIGESTSIZE) {
+                               while (i < SHA_DIGEST_LENGTH) {
                                        *outp++ = drand48() * 0x100;
                                        i++;
                                }
                        }
 
                        /* Obscure the pseudonym with SHA1 hash */
-                       SHA1Init(&ctxt);
-                       SHA1Update(&ctxt, &esp->es_server.ea_id, 1);
-                       SHA1Update(&ctxt, esp->es_server.ea_skey,
-                           SESSION_KEY_LEN);
-                       SHA1Update(&ctxt, esp->es_server.ea_peer,
-                           esp->es_server.ea_peerlen);
-                       while (optr < outp) {
-                               SHA1Final(dig, &ctxt);
-                               cp = dig;
-                               while (cp < dig + SHA_DIGESTSIZE)
-                                       *optr++ ^= *cp++;
-                               SHA1Init(&ctxt);
-                               SHA1Update(&ctxt, &esp->es_server.ea_id, 1);
-                               SHA1Update(&ctxt, esp->es_server.ea_skey,
-                                   SESSION_KEY_LEN);
-                               SHA1Update(&ctxt, optr - SHA_DIGESTSIZE,
-                                   SHA_DIGESTSIZE);
+                       ctxt = PPP_MD_CTX_new();
+                       if (ctxt) {
+
+                               PPP_DigestInit(ctxt, PPP_sha1());
+                               PPP_DigestUpdate(ctxt, &esp->es_server.ea_id, 1);
+                               PPP_DigestUpdate(ctxt, &esp->es_server.ea_skey,
+                                       SESSION_KEY_LEN);
+                               PPP_DigestUpdate(ctxt,  esp->es_server.ea_peer,
+                                       esp->es_server.ea_peerlen);
+                               while (optr < outp) {
+                                       diglen = SHA_DIGEST_LENGTH;
+                                       PPP_DigestFinal(ctxt, dig, &diglen);
+                                       cp = dig;
+                                       while (cp < dig + SHA_DIGEST_LENGTH)
+                                               *optr++ ^= *cp++;
+
+                                       PPP_DigestInit(ctxt, PPP_sha1());
+                                       PPP_DigestUpdate(ctxt, &esp->es_server.ea_id, 1);
+                                       PPP_DigestUpdate(ctxt, esp->es_server.ea_skey,
+                                               SESSION_KEY_LEN);
+                                       PPP_DigestUpdate(ctxt, optr - SHA_DIGEST_LENGTH,
+                                               SHA_DIGEST_LENGTH);
+                               }
+
+                               PPP_MD_CTX_free(ctxt);
                        }
                }
                break;
@@ -1322,19 +1340,19 @@ eap_chap_response(eap_state *esp, u_char id, u_char *hash,
        int msglen;
 
        outp = outpacket_buf;
-    
+
        MAKEHEADER(outp, PPP_EAP);
 
        PUTCHAR(EAP_RESPONSE, outp);
        PUTCHAR(id, outp);
        esp->es_client.ea_id = id;
-       msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + MD5_SIGNATURE_SIZE +
+       msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + MD5_DIGEST_LENGTH +
            namelen;
        PUTSHORT(msglen, outp);
        PUTCHAR(EAPT_MD5CHAP, outp);
-       PUTCHAR(MD5_SIGNATURE_SIZE, outp);
-       BCOPY(hash, outp, MD5_SIGNATURE_SIZE);
-       INCPTR(MD5_SIGNATURE_SIZE, outp);
+       PUTCHAR(MD5_DIGEST_LENGTH, outp);
+       BCOPY(hash, outp, MD5_DIGEST_LENGTH);
+       INCPTR(MD5_DIGEST_LENGTH, outp);
        if (namelen > 0) {
                BCOPY(name, outp, namelen);
        }
@@ -1388,12 +1406,12 @@ eap_srpval_response(eap_state *esp, u_char id, u_int32_t flags, u_char *str)
        PUTCHAR(id, outp);
        esp->es_client.ea_id = id;
        msglen = EAP_HEADERLEN + 2 * sizeof (u_char) + sizeof (u_int32_t) +
-           SHA_DIGESTSIZE;
+           SHA_DIGEST_LENGTH;
        PUTSHORT(msglen, outp);
        PUTCHAR(EAPT_SRP, outp);
        PUTCHAR(EAPSRP_CVALIDATOR, outp);
        PUTLONG(flags, outp);
-       BCOPY(str, outp, SHA_DIGESTSIZE);
+       BCOPY(str, outp, SHA_DIGEST_LENGTH);
 
        output(esp->es_unit, outpacket_buf, PPP_HDRLEN + msglen);
 }
@@ -1503,7 +1521,7 @@ name_of_pn_file(void)
                errno = EINVAL;
                return (NULL);
        }
-       file = _PATH_PSEUDONYM;
+       file = PPP_PATH_PSEUDONYM;
        pl = strlen(user) + strlen(file) + 2;
        path = malloc(pl);
        if (path == NULL)
@@ -1547,9 +1565,9 @@ write_pseudonym(eap_state *esp, u_char *inp, int len, int id)
 {
        u_char val;
        u_char *datp, *digp;
-       SHA1_CTX ctxt;
-       u_char dig[SHA_DIGESTSIZE];
-       int dsize, fd, olen = len;
+       PPP_MD_CTX *ctxt;
+       u_char dig[SHA_DIGEST_LENGTH];
+       int dsize, fd, olen = len, diglen = sizeof(dig);
 
        /*
         * Do the decoding by working backwards.  This eliminates the need
@@ -1557,22 +1575,30 @@ write_pseudonym(eap_state *esp, u_char *inp, int len, int id)
         */
        val = id;
        while (len > 0) {
-               if ((dsize = len % SHA_DIGESTSIZE) == 0)
-                       dsize = SHA_DIGESTSIZE;
+               if ((dsize = len % SHA_DIGEST_LENGTH) == 0)
+                       dsize = SHA_DIGEST_LENGTH;
                len -= dsize;
                datp = inp + len;
-               SHA1Init(&ctxt);
-               SHA1Update(&ctxt, &val, 1);
-               SHA1Update(&ctxt, esp->es_client.ea_skey, SESSION_KEY_LEN);
-               if (len > 0) {
-                       SHA1Update(&ctxt, datp, SHA_DIGESTSIZE);
-               } else {
-                       SHA1Update(&ctxt, esp->es_client.ea_name,
-                           esp->es_client.ea_namelen);
+               ctxt = PPP_MD_CTX_new();
+               if (ctxt) {
+
+                       PPP_DigestInit(ctxt, PPP_sha1());
+                       PPP_DigestUpdate(ctxt, &val, 1);
+                       PPP_DigestUpdate(ctxt, esp->es_client.ea_skey,
+                                       SESSION_KEY_LEN);
+                       if (len > 0) {
+                               PPP_DigestUpdate(ctxt, datp, SHA_DIGEST_LENGTH);
+                       } else {
+                               PPP_DigestUpdate(ctxt, esp->es_client.ea_name,
+                                       esp->es_client.ea_namelen);
+                       }
+                       PPP_DigestFinal(ctxt, dig, &diglen);
+
+                       for (digp = dig; digp < dig + SHA_DIGEST_LENGTH; digp++)
+                               *datp++ ^= *digp;
+
+                       PPP_MD_CTX_free(ctxt);
                }
-               SHA1Final(dig, &ctxt);
-               for (digp = dig; digp < dig + SHA_DIGESTSIZE; digp++)
-                       *datp++ ^= *digp;
        }
 
        /* Now check that the result is sane */
@@ -1642,8 +1668,9 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
        int secret_len;
        char secret[MAXWORDLEN];
        char rhostname[256];
-       MD5_CTX mdContext;
-       u_char hash[MD5_SIGNATURE_SIZE];
+       PPP_MD_CTX *mdctx;
+       u_char hash[MD5_DIGEST_LENGTH];
+       int hashlen = MD5_DIGEST_LENGTH;
 #ifdef PPP_WITH_EAPTLS
        u_char flags;
        struct eaptls_session *ets = esp->es_client.ea_session;
@@ -1653,8 +1680,9 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
        struct t_client *tc;
        struct t_num sval, gval, Nval, *Ap, Bval;
        u_char vals[2];
-       SHA1_CTX ctxt;
-       u_char dig[SHA_DIGESTSIZE];
+       PPP_MD_CTX *ctxt;
+       u_char dig[SHA_DIGEST_LENGTH];
+       int diglen = sizeof(dig);
        int fd;
 #endif /* PPP_WITH_SRP */
 
@@ -1780,15 +1808,29 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
                        eap_send_nak(esp, id, EAPT_SRP);
                        break;
                }
-               MD5_Init(&mdContext);
-               typenum = id;
-               MD5_Update(&mdContext, &typenum, 1);
-               MD5_Update(&mdContext, (u_char *)secret, secret_len);
-               BZERO(secret, sizeof (secret));
-               MD5_Update(&mdContext, inp, vallen);
-               MD5_Final(hash, &mdContext);
-               eap_chap_response(esp, id, hash, esp->es_client.ea_name,
-                   esp->es_client.ea_namelen);
+
+               mdctx = PPP_MD_CTX_new();
+               if (mdctx != NULL) {
+                       if (PPP_DigestInit(mdctx, PPP_md5())) {
+                               typenum = id;
+                               if (PPP_DigestUpdate(mdctx, &typenum, 1)) {
+                                       if (PPP_DigestUpdate(mdctx, secret, secret_len)) {
+                                               BZERO(secret, sizeof(secret));
+                                               if (PPP_DigestUpdate(mdctx, inp, vallen)) {
+                                                       if (PPP_DigestFinal(mdctx, hash, &hashlen)) {
+                                                               eap_chap_response(esp, id, hash, esp->es_client.ea_name,
+                                                                               esp->es_client.ea_namelen);
+                                                               PPP_MD_CTX_free(mdctx);
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       PPP_MD_CTX_free(mdctx);
+               }
+               dbglog("EAP: Invalid MD5 checksum");
+        eap_send_nak(esp, id, EAPT_SRP);
                break;
 
 #ifdef PPP_WITH_EAPTLS
@@ -2065,7 +2107,7 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
                                            esp->es_client.ea_id, id);
                                }
                        } else {
-                               len -= sizeof (u_int32_t) + SHA_DIGESTSIZE;
+                               len -= sizeof (u_int32_t) + SHA_DIGEST_LENGTH;
                                if (len < 0 || t_clientverify(tc, inp +
                                        sizeof (u_int32_t)) != 0) {
                                        error("EAP: SRP server verification "
@@ -2075,7 +2117,7 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
                                GETLONG(esp->es_client.ea_keyflags, inp);
                                /* Save pseudonym if user wants it. */
                                if (len > 0 && esp->es_usepseudo) {
-                                       INCPTR(SHA_DIGESTSIZE, inp);
+                                       INCPTR(SHA_DIGEST_LENGTH, inp);
                                        write_pseudonym(esp, inp, len, id);
                                }
                        }
@@ -2092,17 +2134,24 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
                                warn("EAP: malformed Lightweight rechallenge");
                                return;
                        }
-                       SHA1Init(&ctxt);
-                       vals[0] = id;
-                       SHA1Update(&ctxt, vals, 1);
-                       SHA1Update(&ctxt, esp->es_client.ea_skey,
-                           SESSION_KEY_LEN);
-                       SHA1Update(&ctxt, inp, len);
-                       SHA1Update(&ctxt, esp->es_client.ea_name,
-                           esp->es_client.ea_namelen);
-                       SHA1Final(dig, &ctxt);
-                       eap_srp_response(esp, id, EAPSRP_LWRECHALLENGE, dig,
-                           SHA_DIGESTSIZE);
+                       ctxt = PPP_MD_CTX_new();
+                       if (ctxt) {
+
+                               vals[0] = id;
+                               PPP_DigestInit(ctxt, PPP_sha1());
+                               PPP_DigestUpdate(ctxt, vals, 1);
+                               PPP_DigestUpdate(ctxt, esp->es_client.ea_skey,
+                                       SESSION_KEY_LEN);
+                               PPP_DigestUpdate(ctxt, inp, len);
+                               PPP_DigestUpdate(ctxt, esp->es_client.ea_name,
+                                       esp->es_client.ea_namelen);
+                               PPP_DigestFinal(ctxt, dig, &diglen);
+
+                               PPP_MD_CTX_free(ctxt);
+
+                               eap_srp_response(esp, id, EAPSRP_LWRECHALLENGE, dig,
+                                       SHA_DIGEST_LENGTH);
+                       }
                        break;
 
                default:
@@ -2112,7 +2161,7 @@ eap_request(eap_state *esp, u_char *inp, int id, int len)
                }
                break;
 #endif /* PPP_WITH_SRP */
-    
+
 #ifdef PPP_WITH_CHAPMS
         case EAPT_MSCHAPV2:
            if (len < 4) {
@@ -2279,13 +2328,15 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
        int secret_len;
        char secret[MAXSECRETLEN];
        char rhostname[256];
-       MD5_CTX mdContext;
-       u_char hash[MD5_SIGNATURE_SIZE];
+       PPP_MD_CTX *mdctx;
+       u_char hash[MD5_DIGEST_LENGTH];
+       int hashlen = MD5_DIGEST_LENGTH;
 #ifdef PPP_WITH_SRP
        struct t_server *ts;
        struct t_num A;
-       SHA1_CTX ctxt;
-       u_char dig[SHA_DIGESTSIZE];
+       PPP_MD_CTX *ctxt;
+       u_char dig[SHA_DIGEST_LENGTH];
+       int diglen = sizeof(dig);
 #endif /* PPP_WITH_SRP */
 
 #ifdef PPP_WITH_EAPTLS
@@ -2294,8 +2345,7 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
 #endif /* PPP_WITH_EAPTLS */
 #ifdef PPP_WITH_CHAPMS
        u_char opcode;
-       int (*chap_verifier)(char *, char *, int, struct chap_digest_type *,
-               unsigned char *, unsigned char *, char *, int);
+        chap_verify_hook_fn *chap_verifier;
        char response_message[256];
 #endif /* PPP_WITH_CHAPMS */
 
@@ -2517,21 +2567,42 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
                        eap_send_failure(esp);
                        break;
                }
-               MD5_Init(&mdContext);
-               MD5_Update(&mdContext, &esp->es_server.ea_id, 1);
-               MD5_Update(&mdContext, (u_char *)secret, secret_len);
-               BZERO(secret, sizeof (secret));
-               MD5_Update(&mdContext, esp->es_challenge, esp->es_challen);
-               MD5_Final(hash, &mdContext);
-               if (BCMP(hash, inp, MD5_SIGNATURE_SIZE) != 0) {
-                       eap_send_failure(esp);
-                       break;
+
+               mdctx = PPP_MD_CTX_new();
+               if (mdctx != NULL) {
+
+                       if (PPP_DigestInit(mdctx, PPP_md5())) {
+
+                               if (PPP_DigestUpdate(mdctx, &esp->es_server.ea_id, 1)) {
+
+                                       if (PPP_DigestUpdate(mdctx, &secret, secret_len)) {
+
+                                               BZERO(secret, sizeof(secret));
+                                               if (PPP_DigestUpdate(mdctx, esp->es_challenge, esp->es_challen)) {
+
+                                                       if (PPP_DigestFinal(mdctx, hash, &hashlen)) {
+
+                                                               if (BCMP(hash, inp, MD5_DIGEST_LENGTH) == 0) {
+                                                                       esp->es_server.ea_type = EAPT_MD5CHAP;
+                                                                       eap_send_success(esp);
+                                                                       eap_figure_next_state(esp, 0);
+
+                                                                       if (esp->es_rechallenge != 0) {
+                                                                               TIMEOUT(eap_rechallenge, esp, esp->es_rechallenge);
+                                                                       }
+                                                                       PPP_MD_CTX_free(mdctx);
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
+                       PPP_MD_CTX_free(mdctx);
                }
-               esp->es_server.ea_type = EAPT_MD5CHAP;
-               eap_send_success(esp);
-               eap_figure_next_state(esp, 0);
-               if (esp->es_rechallenge != 0)
-                       TIMEOUT(eap_rechallenge, esp, esp->es_rechallenge);
+
+               eap_send_failure(esp);
                break;
 
 #ifdef PPP_WITH_CHAPMS
@@ -2583,7 +2654,7 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
                                char tmp[MAXNAMELEN+1];
 
                                strcpy(tmp, strrchr(rhostname, '\\') + 1);
-                               strcpy(rhostname, tmp);
+                               strlcpy(rhostname, tmp, sizeof(rhostname));
                        }
 
                        if (chap_verify_hook)
@@ -2675,9 +2746,9 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
                                eap_figure_next_state(esp, 1);
                                break;
                        }
-                       if (len < sizeof (u_int32_t) + SHA_DIGESTSIZE) {
+                       if (len < sizeof (u_int32_t) + SHA_DIGEST_LENGTH) {
                                error("EAP: M1 length %d < %d", len,
-                                   sizeof (u_int32_t) + SHA_DIGESTSIZE);
+                                   sizeof (u_int32_t) + SHA_DIGEST_LENGTH);
                                eap_figure_next_state(esp, 1);
                                break;
                        }
@@ -2714,29 +2785,37 @@ eap_response(eap_state *esp, u_char *inp, int id, int len)
                                info("EAP: unexpected SRP Subtype 4 Response");
                                return;
                        }
-                       if (len != SHA_DIGESTSIZE) {
+                       if (len != SHA_DIGEST_LENGTH) {
                                error("EAP: bad Lightweight rechallenge "
                                    "response");
                                return;
                        }
-                       SHA1Init(&ctxt);
-                       vallen = id;
-                       SHA1Update(&ctxt, &vallen, 1);
-                       SHA1Update(&ctxt, esp->es_server.ea_skey,
-                           SESSION_KEY_LEN);
-                       SHA1Update(&ctxt, esp->es_challenge, esp->es_challen);
-                       SHA1Update(&ctxt, esp->es_server.ea_peer,
-                           esp->es_server.ea_peerlen);
-                       SHA1Final(dig, &ctxt);
-                       if (BCMP(dig, inp, SHA_DIGESTSIZE) != 0) {
-                               error("EAP: failed Lightweight rechallenge");
-                               eap_send_failure(esp);
-                               break;
+                       ctxt = PPP_MD_CTX_new();
+                       if (ctxt) {
+                               vallen = id;
+
+                               PPP_DigestInit(ctxt, PPP_sha1());
+                               PPP_DigestUpdate(ctxt, &vallen, 1);
+                               PPP_DigestUpdate(ctxt, esp->es_server.ea_skey,
+                                       SESSION_KEY_LEN);
+                               PPP_DigestUpdate(ctxt, esp->es_challenge, esp->es_challen);
+                               PPP_DigestUpdate(ctxt, esp->es_server.ea_peer,
+                                       esp->es_server.ea_peerlen);
+                               PPP_DigestFinal(ctxt, dig, &diglen);
+
+                               PPP_MD_CTX_free(ctxt);
+
+                               if (BCMP(dig, inp, SHA_DIGEST_LENGTH) != 0) {
+                                       error("EAP: failed Lightweight rechallenge");
+                                       eap_send_failure(esp);
+                                       break;
+                               }
+
+                               esp->es_server.ea_state = eapOpen;
+                               if (esp->es_lwrechallenge != 0)
+                                       TIMEOUT(srp_lwrechallenge, esp,
+                                               esp->es_lwrechallenge);
                        }
-                       esp->es_server.ea_state = eapOpen;
-                       if (esp->es_lwrechallenge != 0)
-                               TIMEOUT(srp_lwrechallenge, esp,
-                                   esp->es_lwrechallenge);
                        break;
                }
                break;
@@ -3129,10 +3208,10 @@ eap_printpkt(u_char *inp, int inlen,
                                if (uval != 0) {
                                        printer(arg, " f<%X>", uval);
                                }
-                               if ((vallen = len) > SHA_DIGESTSIZE)
-                                       vallen = SHA_DIGESTSIZE;
+                               if ((vallen = len) > SHA_DIGEST_LENGTH)
+                                       vallen = SHA_DIGEST_LENGTH;
                                printer(arg, " <M2%.*B%s>", len, inp,
-                                   len < SHA_DIGESTSIZE ? "?" : "");
+                                   len < SHA_DIGEST_LENGTH ? "?" : "");
                                INCPTR(vallen, inp);
                                len -= vallen;
                                if (len > 0) {
@@ -3302,7 +3381,7 @@ eap_printpkt(u_char *inp, int inlen,
                                        printer(arg, " f<%X>", uval);
                                }
                                printer(arg, " <M1%.*B%s>", len, inp,
-                                   len == SHA_DIGESTSIZE ? "" : "?");
+                                   len == SHA_DIGEST_LENGTH ? "" : "?");
                                INCPTR(len, inp);
                                len = 0;
                                break;
@@ -3312,9 +3391,9 @@ eap_printpkt(u_char *inp, int inlen,
 
                        case EAPSRP_LWRECHALLENGE:
                                printer(arg, " <Response%.*B%s>", len, inp,
-                                   len == SHA_DIGESTSIZE ? "" : "?");
-                               if ((vallen = len) > SHA_DIGESTSIZE)
-                                       vallen = SHA_DIGESTSIZE;
+                                   len == SHA_DIGEST_LENGTH ? "" : "?");
+                               if ((vallen = len) > SHA_DIGEST_LENGTH)
+                                       vallen = SHA_DIGEST_LENGTH;
                                INCPTR(vallen, inp);
                                len -= vallen;
                                break;
index 01697a8b4b85c1eb1d4945759d21ce2d16d095e5..a9a1d82dd47ca14f61c93f856e2009baf6309407 100644 (file)
@@ -16,8 +16,6 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * Original version by James Carlson
- *
- * $Id: eap.h,v 1.2 2003/06/11 23:56:26 paulus Exp $
  */
 
 #ifndef PPP_EAP_H
@@ -94,7 +92,6 @@ extern "C" {
 #define        SRP_PSEUDO_ID   "pseudo_"
 #define        SRP_PSEUDO_LEN  7
 
-#define MD5_SIGNATURE_SIZE     16
 #define MIN_CHALLENGE_LENGTH   16
 #define MAX_CHALLENGE_LENGTH   24
 
@@ -146,11 +143,11 @@ struct eap_auth {
        char *ea_name;          /* Our name */
        char *ea_peer;          /* Peer's name */
        void *ea_session;       /* Authentication library linkage */
-       u_char *ea_skey;        /* Shared encryption key */
+       unsigned char *ea_skey; /* Shared encryption key */
        int ea_timeout;         /* Time to wait (for retransmit/fail) */
        int ea_maxrequests;     /* Max Requests allowed */
-       u_short ea_namelen;     /* Length of our name */
-       u_short ea_peerlen;     /* Length of peer's name */
+       unsigned short ea_namelen;      /* Length of our name */
+       unsigned short ea_peerlen;      /* Length of peer's name */
        enum eap_state_code ea_state;
 #ifdef PPP_WITH_EAPTLS
        enum eap_state_code ea_prev_state;
@@ -158,11 +155,11 @@ struct eap_auth {
 #ifdef PPP_WITH_CHAPMS
         struct chap_digest_type *digest;
 #endif
-       u_char ea_id;           /* Current id */
-       u_char ea_requests;     /* Number of Requests sent/received */
-       u_char ea_responses;    /* Number of Responses */
-       u_char ea_type;         /* One of EAPT_* */
-       u_int32_t ea_keyflags;  /* SRP shared key usage flags */
+       unsigned char ea_id;            /* Current id */
+       unsigned char ea_requests;      /* Number of Requests sent/received */
+       unsigned char ea_responses;     /* Number of Responses */
+       unsigned char ea_type;          /* One of EAPT_* */
+       uint32_t ea_keyflags;   /* SRP shared key usage flags */
 #ifdef PPP_WITH_EAPTLS
        bool ea_using_eaptls;
 #endif
@@ -184,7 +181,7 @@ typedef struct eap_state {
        bool es_usepseudo;              /* Use SRP Pseudonym if offered one */
        int es_usedpseudo;              /* Set if we already sent PN */
        int es_challen;                 /* Length of challenge string */
-       u_char es_challenge[MAX_CHALLENGE_LENGTH];
+       unsigned char es_challenge[MAX_CHALLENGE_LENGTH];
 } eap_state;
 
 /*
@@ -207,6 +204,11 @@ void eap_authpeer (int unit, char *localname);
 
 extern struct protent eap_protent;
 
+#ifdef PPP_WITH_EAPTLS
+typedef int (eaptls_passwd_hook_fn)(char *user, char *passwd);
+extern eaptls_passwd_hook_fn *eaptls_passwd_hook;
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 9570f389561ffc7daec9d0df7c8872baff8199ab..44c06d9e52187c3c4c949400e8340347aaf26bfa 100644 (file)
@@ -30,7 +30,7 @@
  *
  * Derived from ccp.c, which is:
  *
- * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
 #include <string.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "ecp.h"
 
-static option_t ecp_option_list[] = {
+static struct option ecp_option_list[] = {
     { "noecp", o_bool, &ecp_protent.enabled_flag,
       "Disable ECP negotiation" },
     { "-ecp", o_bool, &ecp_protent.enabled_flag,
index 5a0df4d1468120fdf53f01ebb74a6c8e76ed43fa..b01969bb6e40b6d0f1e9491db5b479c868d2e5e9 100644 (file)
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ecp.h,v 1.2 2003/01/10 07:12:36 fcusack Exp $
  */
 #ifndef PPP_ECP_H
 #define PPP_ECP_H
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifndef PPP_ECP
 #define PPP_ECP 0x8053
 #endif
@@ -53,4 +55,8 @@ extern ecp_options ecp_hisoptions[];
 
 extern struct protent ecp_protent;
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_ECP_H
index 7978c06c204d887e6bdce9a7ea8cb2f5fcca68ee..bc84e8dee81a952ee8ce75108b412641fa2c28cd 100644 (file)
@@ -38,7 +38,7 @@
 #include "config.h"
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
 
 
 /*
index f29200b818d7efd0fbfb1e2914a39255f99954b6..c24733d1248ac16b372926178f0206d341311ec6 100644 (file)
 
 #include "pppdconf.h"
 
-#if !defined(PPP_WITH_IPV6CP)
-#error "this file should only be included when PPP_WITH_IPV6CP is defined"
-#endif /* not defined(PPP_WITH_IPV6CP) */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(SOL2)
+#include <netinet/in.h>
+
+typedef union {
+    uint8_t    e8[8];          /* lower 64-bit IPv6 address */
+    uint32_t   e32[2];         /* lower 64-bit IPv6 address */
+} eui64_t;
+
+/*
+ * Declare the two below, since in.h only defines them when _KERNEL
+ * is declared - which shouldn't be true when dealing with user-land programs
+ */
+#define        s6_addr8        _S6_un._S6_u8
+#define        s6_addr32       _S6_un._S6_u32
+
+#else /* else if not defined(SOL2) */
+
+/*
+ * TODO:
+ *
+ * Maybe this should be done by processing struct in6_addr directly...
+ */
+typedef union
+{
+    u_int8_t e8[8];
+    u_int16_t e16[4];
+    u_int32_t e32[2];
+} eui64_t;
+
+#endif /* defined(SOL2) */
 
 #define eui64_iszero(e)                (((e).e32[0] | (e).e32[1]) == 0)
 #define eui64_equals(e, o)     (((e).e32[0] == (o).e32[0]) && \
 
 char *eui64_ntoa(eui64_t);     /* Returns ascii representation of id */
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* PPP_EUI64_H */
index 17cb76f8fd11e2cd53943ff598c57e0273419dd3..09ff5e0517282d575442dc8362af929c5eb34ddd 100644 (file)
@@ -54,7 +54,7 @@
 #include <string.h>
 #include <sys/types.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
 
 
index 1cda6cffbde6b8addb4da1279689bc2b8caf153f..92f024ab048469bcefb491c72e0d86bfa49182e1 100644 (file)
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $
  */
 #ifndef PPP_FSM_H
 #define PPP_FSM_H
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Packet header = Code, id, length.
  */
 #define HEADERLEN      4
 
-
 /*
  *  CP (LCP, IPCP, etc.) codes.
  */
@@ -72,9 +73,9 @@ typedef struct fsm {
     int protocol;              /* Data Link Layer Protocol field value */
     int state;                 /* State */
     int flags;                 /* Contains option bits */
-    u_char id;                 /* Current id */
-    u_char reqid;              /* Current request id */
-    u_char seen_ack;           /* Have received valid Ack/Nak/Rej to Req */
+    unsigned char id;                  /* Current id */
+    unsigned char reqid;               /* Current request id */
+    unsigned char seen_ack;            /* Have received valid Ack/Nak/Rej to Req */
     int timeouttime;           /* Timeout time in milliseconds */
     int maxconfreqtransmits;   /* Maximum Configure-Request transmissions */
     int retransmits;           /* Number of retransmissions left */
@@ -92,15 +93,15 @@ typedef struct fsm_callbacks {
     void (*resetci)(fsm *);    /* Reset our Configuration Information */
     int  (*cilen)(fsm *);      /* Length of our Configuration Information */
     void (*addci)              /* Add our Configuration Information */
-               (fsm *, u_char *, int *);
+               (fsm *, unsigned char *, int *);
     int  (*ackci)              /* ACK our Configuration Information */
-               (fsm *, u_char *, int);
+               (fsm *, unsigned char *, int);
     int  (*nakci)              /* NAK our Configuration Information */
-               (fsm *, u_char *, int, int);
+               (fsm *, unsigned char *, int, int);
     int  (*rejci)              /* Reject our Configuration Information */
-               (fsm *, u_char *, int);
+               (fsm *, unsigned char *, int);
     int  (*reqci)              /* Request peer's Configuration Information */
-               (fsm *, u_char *, int *, int);
+               (fsm *, unsigned char *, int *, int);
     void (*up)(fsm *);         /* Called when fsm reaches OPENED state */
     void (*down)(fsm *);       /* Called when fsm leaves OPENED state */
     void (*starting)(fsm *);   /* Called when we want the lower layer */
@@ -108,7 +109,7 @@ typedef struct fsm_callbacks {
     void (*protreject)(int);   /* Called when Protocol-Reject received */
     void (*retransmit)(fsm *); /* Retransmission is necessary */
     int  (*extcode)            /* Called when unknown code received */
-               (fsm *, int, int, u_char *, int);
+               (fsm *, int, int, unsigned char *, int);
     char *proto_name;          /* String name for protocol (for messages) */
 } fsm_callbacks;
 
@@ -153,9 +154,9 @@ void fsm_lowerup (fsm *);
 void fsm_lowerdown (fsm *);
 void fsm_open (fsm *);
 void fsm_close (fsm *, char *);
-void fsm_input (fsm *, u_char *, int);
+void fsm_input (fsm *, unsigned char *, int);
 void fsm_protreject (fsm *);
-void fsm_sdata (fsm *, int, int, u_char *, int);
+void fsm_sdata (fsm *, int, int, unsigned char *, int);
 
 
 /*
@@ -163,4 +164,8 @@ void fsm_sdata (fsm *, int, int, u_char *, int);
  */
 extern int peer_mru[];         /* currently negotiated peer MRU (per unit) */
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_FSM_H
index 0dc251e503d725f4bec5f7f81953fafcc0f04168..ded4370783e32a9a1ce1e3ffd35af02d9d1bc4ba 100644 (file)
 #include "config.h"
 #endif
 
-/*
- * TODO:
- */
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -59,7 +55,8 @@
 #include <arpa/inet.h>
 #include <net/if.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "ipcp.h"
 #include "pathnames.h"
@@ -71,19 +68,16 @@ ipcp_options ipcp_gotoptions[NUM_PPP];      /* Options that peer ack'd */
 ipcp_options ipcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
 ipcp_options ipcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
 
+char   *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
 u_int32_t netmask = 0;         /* IP netmask to set on interface */
 
 bool   disable_defaultip = 0;  /* Don't use hostname for default IP adrs */
 bool   noremoteip = 0;         /* Let him have no IP address */
 
-/* Hook for a plugin to know when IP protocol has come up */
-void (*ip_up_hook)(void) = NULL;
+ip_up_hook_fn *ip_up_hook = NULL;
+ip_down_hook_fn *ip_down_hook = NULL;
+ip_choose_hook_fn *ip_choose_hook = NULL;
 
-/* Hook for a plugin to know when IP protocol has come down */
-void (*ip_down_hook)(void) = NULL;
-
-/* Hook for a plugin to choose the remote IP address */
-void (*ip_choose_hook)(u_int32_t *) = NULL;
 
 /* Notifiers for when IPCP goes up and down */
 struct notifier *ip_up_notifier = NULL;
@@ -94,6 +88,7 @@ static int default_route_set[NUM_PPP];        /* Have set up a default route */
 static int proxy_arp_set[NUM_PPP];     /* Have created proxy arp entry */
 static bool usepeerdns;                        /* Ask peer for DNS addrs */
 static bool usepeerwins;               /* Ask peer for WINS addrs */
+static bool noresolvconf;              /* Do not create resolv.conf */
 static int ipcp_is_up;                 /* have called np_up() */
 static int ipcp_is_open;               /* haven't called np_finished() */
 static bool ask_for_local;             /* request our address from peer */
@@ -142,9 +137,9 @@ static int setdnsaddr (char **);
 static int setwinsaddr (char **);
 static int setnetmask (char **);
 int setipaddr (char *, char **, int);
-static void printipaddr (option_t *, void (*)(void *, char *,...),void *);
+static void printipaddr (struct option *, void (*)(void *, char *,...),void *);
 
-static option_t ipcp_option_list[] = {
+static struct option ipcp_option_list[] = {
     { "noip", o_bool, &ipcp_protent.enabled_flag,
       "Disable IP and IPCP" },
     { "-ip", o_bool, &ipcp_protent.enabled_flag,
@@ -225,6 +220,9 @@ static option_t ipcp_option_list[] = {
     { "usepeerwins", o_bool, &usepeerwins,
       "Ask peer for WINS address(es)", 1 },
 
+    { "noresolvconf", o_bool, &noresolvconf,
+      "Do not create resolv.conf", 1 },
+
     { "netmask", o_special, (void *)setnetmask,
       "set netmask", OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, netmask_str },
 
@@ -337,10 +335,10 @@ setvjslots(char **argv)
 {
     int value;
 
-    if (!int_option(*argv, &value))
+    if (!ppp_int_option(*argv, &value))
        return 0;
     if (value < 2 || value > 16) {
-       option_error("vj-max-slots value must be between 2 and 16");
+       ppp_option_error("vj-max-slots value must be between 2 and 16");
        return 0;
     }
     ipcp_wantoptions [0].maxslotindex =
@@ -361,7 +359,7 @@ setdnsaddr(char **argv)
     dns = inet_addr(*argv);
     if (dns == (u_int32_t) -1) {
        if ((hp = gethostbyname(*argv)) == NULL) {
-           option_error("invalid address parameter '%s' for ms-dns option",
+           ppp_option_error("invalid address parameter '%s' for ms-dns option",
                         *argv);
            return 0;
        }
@@ -396,7 +394,7 @@ setwinsaddr(char **argv)
     wins = inet_addr(*argv);
     if (wins == (u_int32_t) -1) {
        if ((hp = gethostbyname(*argv)) == NULL) {
-           option_error("invalid address parameter '%s' for ms-wins option",
+           ppp_option_error("invalid address parameter '%s' for ms-wins option",
                         *argv);
            return 0;
        }
@@ -447,13 +445,13 @@ setipaddr(char *arg, char **argv, int doit)
        *colon = '\0';
        if ((local = inet_addr(arg)) == (u_int32_t) -1) {
            if ((hp = gethostbyname(arg)) == NULL) {
-               option_error("unknown host: %s", arg);
+               ppp_option_error("unknown host: %s", arg);
                return 0;
            }
            local = *(u_int32_t *)hp->h_addr;
        }
-       if (bad_ip_adrs(local)) {
-           option_error("bad local IP address %s", ip_ntoa(local));
+       if (ppp_bad_ip_addr(local)) {
+           ppp_option_error("bad local IP address %s", ip_ntoa(local));
            return 0;
        }
        if (local != 0)
@@ -468,15 +466,15 @@ setipaddr(char *arg, char **argv, int doit)
     if (*++colon != '\0' && option_priority >= prio_remote) {
        if ((remote = inet_addr(colon)) == (u_int32_t) -1) {
            if ((hp = gethostbyname(colon)) == NULL) {
-               option_error("unknown host: %s", colon);
+               ppp_option_error("unknown host: %s", colon);
                return 0;
            }
            remote = *(u_int32_t *)hp->h_addr;
            if (remote_name[0] == 0)
                strlcpy(remote_name, colon, sizeof(remote_name));
        }
-       if (bad_ip_adrs(remote)) {
-           option_error("bad remote IP address %s", ip_ntoa(remote));
+       if (ppp_bad_ip_addr(remote)) {
+           ppp_option_error("bad remote IP address %s", ip_ntoa(remote));
            return 0;
        }
        if (remote != 0)
@@ -488,7 +486,7 @@ setipaddr(char *arg, char **argv, int doit)
 }
 
 static void
-printipaddr(option_t *opt, void (*printer) (void *, char *, ...), void *arg)
+printipaddr(struct option *opt, void (*printer) (void *, char *, ...), void *arg)
 {
        ipcp_options *wo = &ipcp_wantoptions[0];
 
@@ -519,7 +517,7 @@ setnetmask(char **argv)
     mask = htonl(mask);
 
     if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) {
-       option_error("invalid netmask value '%s'", *argv);
+       ppp_option_error("invalid netmask value '%s'", *argv);
        return 0;
     }
 
@@ -560,6 +558,11 @@ parse_dotted_ip(char *p, u_int32_t *vp)
     return p - p0;
 }
 
+const char *ppp_ipparam()
+{
+    return ipparam;
+}
+
 
 /*
  * ipcp_init - Initialize IPCP.
@@ -1438,14 +1441,14 @@ ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree)
     ipcp_options *ho = &ipcp_hisoptions[f->unit];
     ipcp_options *ao = &ipcp_allowoptions[f->unit];
     u_char *cip, *next;                /* Pointer to current and next CIs */
-    u_short cilen, citype;     /* Parsed len, type */
+    u_int32_t cilen, citype;   /* Parsed len, type */
     u_short cishort;           /* Parsed short value */
     u_int32_t tl, ciaddr1, ciaddr2;/* Parsed address values */
     int rc = CONFACK;          /* Final packet return code */
     int orc;                   /* Individual option return code */
     u_char *p;                 /* Pointer to next char to parse */
     u_char *ucp = inp;         /* Pointer to current output char */
-    int l = *len;              /* Length left */
+    u_int32_t l = *len;                /* Length left */
     u_char maxslotindex, cflag;
     int d;
 
@@ -1737,7 +1740,7 @@ ip_check_options(void)
        wo->accept_local = 1;   /* don't insist on this default value */
        if ((hp = gethostbyname(hostname)) != NULL) {
            local = *(u_int32_t *)hp->h_addr;
-           if (local != 0 && !bad_ip_adrs(local))
+           if (local != 0 && !ppp_bad_ip_addr(local))
                wo->ouraddr = local;
        }
     }
@@ -1767,7 +1770,7 @@ ip_demand_conf(int u)
     }
     if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
        return 0;
-    ipcp_script(_PATH_IPPREUP, 1);
+    ipcp_script(path_ippreup, 1);
     if (!sifup(u))
        return 0;
     if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
@@ -1832,29 +1835,29 @@ ipcp_up(fsm *f)
        warn("Could not determine remote IP address: defaulting to %I",
             ho->hisaddr);
     }
-    script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
+    ppp_script_setenv("IPLOCAL", ip_ntoa(go->ouraddr), 0);
     if (ho->hisaddr != 0)
-       script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
+       ppp_script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr), 1);
 
     if (!go->req_dns1)
            go->dnsaddr[0] = 0;
     if (!go->req_dns2)
            go->dnsaddr[1] = 0;
     if (go->dnsaddr[0])
-       script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
+       ppp_script_setenv("DNS1", ip_ntoa(go->dnsaddr[0]), 0);
     if (go->dnsaddr[1])
-       script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
+       ppp_script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
     if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
-       script_setenv("USEPEERDNS", "1", 0);
+       ppp_script_setenv("USEPEERDNS", "1", 0);
        create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
     }
 
     if (go->winsaddr[0])
-        script_setenv("WINS1", ip_ntoa(go->winsaddr[0]), 0);
+        ppp_script_setenv("WINS1", ip_ntoa(go->winsaddr[0]), 0);
     if (go->winsaddr[1])
-        script_setenv("WINS2", ip_ntoa(go->winsaddr[1]), 0);
+        ppp_script_setenv("WINS2", ip_ntoa(go->winsaddr[1]), 0);
     if (usepeerwins && (go->winsaddr[0] || go->winsaddr[1]))
-        script_setenv("USEPEERWINS", "1", 0);
+        ppp_script_setenv("USEPEERWINS", "1", 0);
 
     /*
      * Check that the peer is allowed to use the IP address it wants.
@@ -1879,17 +1882,17 @@ ipcp_up(fsm *f)
                                      wo->replace_default_route);
            if (go->ouraddr != wo->ouraddr) {
                warn("Local IP address changed to %I", go->ouraddr);
-               script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
+               ppp_script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
                wo->ouraddr = go->ouraddr;
            } else
-               script_unsetenv("OLDIPLOCAL");
+               ppp_script_unsetenv("OLDIPLOCAL");
            if (ho->hisaddr != wo->hisaddr) {
                warn("Remote IP address changed to %I", ho->hisaddr);
                if (wo->hisaddr != 0)
-                   script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
+                   ppp_script_setenv("OLDIPREMOTE", ip_ntoa(wo->hisaddr), 0);
                wo->hisaddr = ho->hisaddr;
            } else
-               script_unsetenv("OLDIPREMOTE");
+               ppp_script_unsetenv("OLDIPREMOTE");
 
            /* Set the interface to the new addresses */
            mask = GetMask(go->ouraddr);
@@ -1933,7 +1936,7 @@ ipcp_up(fsm *f)
        ifindex = if_nametoindex(ifname);
 
        /* run the pre-up script, if any, and wait for it to finish */
-       ipcp_script(_PATH_IPPREUP, 1);
+       ipcp_script(path_ippreup, 1);
 
        /* check if preup script renamed the interface */
        if (!if_indextoname(ifindex, ifname)) {
@@ -2016,7 +2019,7 @@ ipcp_down(fsm *f)
      * before the interface is marked down. */
     /* XXX more correct: we must get the stats before running the notifiers,
      * at least for the radius plugin */
-    update_link_stats(f->unit);
+    ppp_get_link_stats(NULL);
     notify(ip_down_notifier, 0);
     if (ip_down_hook)
        ip_down_hook();
@@ -2027,7 +2030,7 @@ ipcp_down(fsm *f)
     sifvjcomp(f->unit, 0, 0, 0);
 
     print_link_stats(); /* _after_ running the notifiers and ip_down_hook(),
-                        * because print_link_stats() sets link_stats_valid
+                        * because print_link_stats() sets link_stats_print
                         * to 0 (zero) */
 
     /*
@@ -2153,20 +2156,23 @@ create_resolv(u_int32_t peerdns1, u_int32_t peerdns2)
 {
     FILE *f;
 
-    f = fopen(_PATH_RESOLV, "w");
+    if (noresolvconf)
+       return;
+
+    f = fopen(PPP_PATH_RESOLV, "w");
     if (f == NULL) {
-       error("Failed to create %s: %m", _PATH_RESOLV);
+       error("Failed to create %s: %m", PPP_PATH_RESOLV);
        return;
     }
 
     if (peerdns1)
        fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1));
 
-    if (peerdns2)
+    if (peerdns2 && peerdns2 != peerdns1)
        fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2));
 
     if (ferror(f))
-       error("Write failed to %s: %m", _PATH_RESOLV);
+       error("Write failed to %s: %m", PPP_PATH_RESOLV);
 
     fclose(f);
 }
index 0e449319b64bf56336a16ea297999716302dfd84..b3f6e28d06d1c761d93b9f71f891bf2e7cc865ff 100644 (file)
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Options.
  */
@@ -85,9 +89,9 @@ typedef struct ipcp_options {
     int  vj_protocol;          /* protocol value to use in VJ option */
     int  maxslotindex;         /* values for RFC1332 VJ compression neg. */
     bool cflag;
-    u_int32_t ouraddr, hisaddr;        /* Addresses in NETWORK BYTE ORDER */
-    u_int32_t dnsaddr[2];      /* Primary and secondary MS DNS entries */
-    u_int32_t winsaddr[2];     /* Primary and secondary MS WINS entries */
+    uint32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */
+    uint32_t dnsaddr[2];       /* Primary and secondary MS DNS entries */
+    uint32_t winsaddr[2];      /* Primary and secondary MS WINS entries */
 } ipcp_options;
 
 extern fsm ipcp_fsm[];
@@ -96,8 +100,30 @@ extern ipcp_options ipcp_gotoptions[];
 extern ipcp_options ipcp_allowoptions[];
 extern ipcp_options ipcp_hisoptions[];
 
-char *ip_ntoa(u_int32_t);
+char *ip_ntoa(uint32_t);
 
 extern struct protent ipcp_protent;
 
+/*
+ * Hook for a plugin to know when IP protocol has come up
+ */
+typedef void (ip_up_hook_fn)(void);
+extern ip_up_hook_fn *ip_up_hook;
+
+/*
+ * Hook for a plugin to know when IP protocol has come down
+ */
+typedef void (ip_down_hook_fn)(void);
+extern ip_down_hook_fn *ip_down_hook;
+
+/*
+ * Hook for a plugin to choose the remote IP address
+ */
+typedef void (ip_choose_hook_fn)(uint32_t *);
+extern ip_choose_hook_fn *ip_choose_hook;
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* PPP_IPCP_H */
index 5a99841429f67a8bbb57e5261a81b25a9bc865b9..a36b1d942be4d530215078aebba7699156ebc75a 100644 (file)
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "eui64.h"
 #include "ipcp.h"
@@ -183,11 +184,8 @@ static int default_route_set[NUM_PPP];             /* Have set up a default route */
 static int ipv6cp_is_up;
 static bool ipv6cp_noremote;
 
-/* Hook for a plugin to know when IPv6 protocol has come up */
-void (*ipv6_up_hook)(void) = NULL;
-
-/* Hook for a plugin to know when IPv6 protocol has come down */
-void (*ipv6_down_hook)(void) = NULL;
+ipv6_up_hook_fn *ipv6_up_hook = NULL;
+ipv6_down_hook_fn *ipv6_down_hook = NULL;
 
 /* Notifiers for when IPCPv6 goes up and down */
 struct notifier *ipv6_up_notifier = NULL;
@@ -231,10 +229,10 @@ static fsm_callbacks ipv6cp_callbacks = { /* IPV6CP callback routines */
  * Command-line options.
  */
 static int setifaceid (char **arg);
-static void printifaceid (option_t *,
+static void printifaceid (struct option *,
                          void (*)(void *, char *, ...), void *);
 
-static option_t ipv6cp_option_list[] = {
+static struct option ipv6cp_option_list[] = {
     { "ipv6", o_special, (void *)setifaceid,
       "Set interface identifiers for IPV6",
       OPT_A2PRINTER, (void *)printifaceid },
@@ -373,7 +371,7 @@ setifaceid(char **argv)
        *comma = '\0';
 
        if (inet_pton(AF_INET6, arg, &addr) == 0 || !VALIDID(addr)) {
-           option_error("Illegal interface identifier (local): %s", arg);
+           ppp_option_error("Illegal interface identifier (local): %s", arg);
            return 0;
        }
 
@@ -390,7 +388,7 @@ setifaceid(char **argv)
      */
     if (*comma != 0 && *++comma != '\0') {
        if (inet_pton(AF_INET6, comma, &addr) == 0 || !VALIDID(addr)) {
-           option_error("Illegal interface identifier (remote): %s", comma);
+           ppp_option_error("Illegal interface identifier (remote): %s", comma);
            return 0;
        }
        if (option_priority >= prio_remote) {
@@ -408,7 +406,7 @@ setifaceid(char **argv)
 char *llv6_ntoa(eui64_t ifaceid);
 
 static void
-printifaceid(option_t *opt, void (*printer) (void *, char *, ...), void *arg)
+printifaceid(struct option *opt, void (*printer) (void *, char *, ...), void *arg)
 {
        ipv6cp_options *wo = &ipv6cp_wantoptions[0];
 
@@ -1302,9 +1300,9 @@ ipv6cp_up(fsm *f)
            return;
        }
     }
-    script_setenv("LLLOCAL", llv6_ntoa(go->ourid), 0);
+    ppp_script_setenv("LLLOCAL", llv6_ntoa(go->ourid), 0);
     if (!eui64_iszero(ho->hisid))
-        script_setenv("LLREMOTE", llv6_ntoa(ho->hisid), 0);
+        ppp_script_setenv("LLREMOTE", llv6_ntoa(ho->hisid), 0);
 
 #ifdef IPV6CP_COMP
     /* set tcp compression */
@@ -1398,7 +1396,7 @@ static void
 ipv6cp_down(fsm *f)
 {
     IPV6CPDEBUG(("ipv6cp: down"));
-    update_link_stats(f->unit);
+    ppp_get_link_stats(NULL);
     notify(ipv6_down_notifier, 0);
     if (ipv6_down_hook)
        ipv6_down_hook();
@@ -1492,7 +1490,7 @@ ipv6cp_script_done(void *arg)
 static void
 ipv6cp_script(char *script)
 {
-    char strspeed[32], strlocal[32], strremote[32];
+    char strspeed[32], strlocal[64], strremote[64];
     char *argv[8];
 
     sprintf(strspeed, "%d", baud_rate);
index 172b6eb85794d6ba99475bb2012e787148c721aa..3be5885abbda926c42b0c2a50aee2d4c4e589ac6 100644 (file)
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*  Original version, based on RFC2023 :
 
     Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt,
@@ -174,4 +178,20 @@ extern ipv6cp_options ipv6cp_hisoptions[];
 
 extern struct protent ipv6cp_protent;
 
+/*
+ * Hook for a plugin to know when IPv6 protocol has come up
+ */
+typedef void (ipv6_up_hook_fn)(void);
+extern ipv6_up_hook_fn *ipv6_up_hook;
+
+/*
+ * Hook for a plugin to know when IPv6 protocol has come down
+ */
+typedef void (ipv6_down_hook_fn)(void);
+extern ipv6_down_hook_fn *ipv6_down_hook;
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif
index 9dc883e47ce85a634df6c42b884a512379bd3559..0876b8af0acccb0a802fd343ba1218b7ba735a25 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
+#include <time.h>
+#include <arpa/inet.h>
+#include <sys/mman.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "eap.h"
-#include "chap-new.h"
+#include "chap.h"
 #include "magic.h"
-
+#include "multilink.h"
 
 /*
  * When the link comes up we want to be able to wait for a short while,
 
 static void lcp_delayed_up(void *);
 
+/*
+ * These definitions relate to the measurement and logging of round-trip
+ * time (RTT) of LCP echo-requests implemented in lcp_rtt_update_buffer().
+ */
+#define LCP_RTT_MAGIC 0x19450425
+#define LCP_RTT_HEADER_LENGTH 4
+#define LCP_RTT_FILE_SIZE 8192
+#define LCP_RTT_ELEMENTS (LCP_RTT_FILE_SIZE / sizeof(u_int32_t) - LCP_RTT_HEADER_LENGTH) / 2
+
 /*
  * LCP-related command-line options.
  */
 int    lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
 int    lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
 bool   lcp_echo_adaptive = 0;  /* request echo only if the link was idle */
+char   *lcp_rtt_file = NULL;   /* measure the RTT of LCP echo-requests */
 bool   lax_recv = 0;           /* accept control chars in asyncmap */
 bool   noendpoint = 0;         /* don't send/accept endpoint discriminator */
 
@@ -82,7 +98,7 @@ static int setendpoint(char **);
 static void printendpoint(option_t *, void (*)(void *, char *, ...), void *);
 #endif /* PPP_WITH_MULTILINK */
 
-static option_t lcp_option_list[] = {
+static struct option lcp_option_list[] = {
     /* LCP options */
     { "-all", o_special_noarg, (void *)noopt,
       "Don't request/allow any LCP options" },
@@ -151,6 +167,9 @@ static option_t lcp_option_list[] = {
       "Set time in seconds between LCP echo requests", OPT_PRIO },
     { "lcp-echo-adaptive", o_bool, &lcp_echo_adaptive,
       "Suppress LCP echo requests if traffic was received", 1 },
+    { "lcp-rtt-file", o_string, &lcp_rtt_file,
+      "Filename for logging the round-trip time of LCP echo requests",
+      OPT_PRIO | OPT_PRIV },
     { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
       "Set time in seconds between LCP retransmissions", OPT_PRIO },
     { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
@@ -196,6 +215,8 @@ lcp_options lcp_hisoptions[NUM_PPP];        /* Options that we ack'd */
 static int lcp_echos_pending = 0;      /* Number of outstanding echo msgs */
 static int lcp_echo_number   = 0;      /* ID number of next echo frame */
 static int lcp_echo_timer_running = 0;  /* set if a timer is running */
+static int lcp_rtt_file_fd = 0;                /* fd for the opened LCP RTT file */
+static u_int32_t *lcp_rtt_buffer = NULL; /* the mmap'ed LCP RTT file */
 
 static u_char nak_buffer[PPP_MRU];     /* where we construct a nak packet */
 
@@ -312,7 +333,7 @@ setendpoint(char **argv)
        lcp_wantoptions[0].neg_endpoint = 1;
        return 1;
     }
-    option_error("Can't parse '%s' as an endpoint discriminator", *argv);
+    ppp_option_error("Can't parse '%s' as an endpoint discriminator", *argv);
     return 0;
 }
 
@@ -389,11 +410,11 @@ lcp_close(int unit, char *reason)
     fsm *f = &lcp_fsm[unit];
     int oldstate;
 
-    if (phase != PHASE_DEAD && phase != PHASE_MASTER)
+    if (!in_phase(PHASE_DEAD) && !in_phase(PHASE_MASTER))
        new_phase(PHASE_TERMINATE);
 
     if (f->flags & DELAYED_UP) {
-       untimeout(lcp_delayed_up, f);
+       UNTIMEOUT(lcp_delayed_up, f);
        f->state = STOPPED;
     }
     oldstate = f->state;
@@ -435,7 +456,7 @@ lcp_lowerup(int unit)
 
     if (listen_time != 0) {
        f->flags |= DELAYED_UP;
-       timeout(lcp_delayed_up, f, 0, listen_time * 1000);
+       ppp_timeout(lcp_delayed_up, f, 0, listen_time * 1000);
     } else
        fsm_lowerup(f);
 }
@@ -451,7 +472,7 @@ lcp_lowerdown(int unit)
 
     if (f->flags & DELAYED_UP) {
        f->flags &= ~DELAYED_UP;
-       untimeout(lcp_delayed_up, f);
+       UNTIMEOUT(lcp_delayed_up, f);
     } else
        fsm_lowerdown(&lcp_fsm[unit]);
 }
@@ -482,7 +503,7 @@ lcp_input(int unit, u_char *p, int len)
 
     if (f->flags & DELAYED_UP) {
        f->flags &= ~DELAYED_UP;
-       untimeout(lcp_delayed_up, f);
+       UNTIMEOUT(lcp_delayed_up, f);
        fsm_lowerup(f);
     }
     fsm_input(f, p, len);
@@ -1276,7 +1297,7 @@ lcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject)
        if (looped_back) {
            if (++try.numloops >= lcp_loopbackfail) {
                notice("Serial line is looped back.");
-               status = EXIT_LOOPBACK;
+               ppp_set_status(EXIT_LOOPBACK);
                lcp_close(f->unit, "Loopback detected");
            }
        } else
@@ -1872,7 +1893,7 @@ lcp_up(fsm *f)
 #ifdef PPP_WITH_MULTILINK
     if (!(multilink && go->neg_mrru && ho->neg_mrru))
 #endif /* PPP_WITH_MULTILINK */
-       netif_set_mtu(f->unit, MIN(MIN(mtu, mru), ao->mru));
+       ppp_set_mtu(f->unit, MIN(MIN(mtu, mru), ao->mru));
     ppp_send_config(f->unit, mtu,
                    (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
                    ho->neg_pcompression, ho->neg_accompression);
@@ -2186,7 +2207,7 @@ void LcpLinkFailure (fsm *f)
     if (f->state == OPENED) {
        info("No response to %d echo-requests", lcp_echos_pending);
         notice("Serial link appears to be disconnected.");
-       status = EXIT_PEER_DEAD;
+       ppp_set_status(EXIT_PEER_DEAD);
        lcp_close(f->unit, "Peer not responding");
     }
 }
@@ -2224,6 +2245,73 @@ LcpEchoTimeout (void *arg)
     }
 }
 
+/*
+ * Log the round-trip time (RTT) of the received LCP echo-request.
+ *
+ * The header section at the beginning of lcp_rtt_file contains
+ * LCP_RTT_HEADER_LENGTH fields, each a u_int32_t in network byte order:
+ * [0] LCP_RTT_MAGIC
+ * [1] status (1: the file is open and is being written)
+ * [2] index of the most recently updated element
+ * [3] the value of the lcp-echo-interval parameter
+ *
+ * The header is followed by a ring buffer of LCP_RTT_ELEMENTS elements, each
+ * containing a pair of u_int32_t in network byte order with this content:
+ * [0] UNIX timestamp
+ * [1] bits 24-31: the number of lost LCP echo replies
+ *     bits 0-23:  the measured RTT in microseconds
+ *
+ * The timestamp is unsigned to support storing dates beyond 2038.
+ *
+ * Consumers of lcp_rtt_file are expected to:
+ * - read the complete file of arbitrary length
+ * - check the magic number
+ * - process the data elements starting at the index
+ * - ignore any elements with a timestamp of 0
+ */
+static void
+lcp_rtt_update_buffer (unsigned long rtt)
+{
+    volatile u_int32_t *const ring_header = lcp_rtt_buffer;
+    volatile u_int32_t *const ring_buffer = lcp_rtt_buffer
+       + LCP_RTT_HEADER_LENGTH;
+    unsigned int next_entry, lost;
+
+    /* choose the next entry where the data will be stored */
+    if (ntohl(ring_header[2]) >= (LCP_RTT_ELEMENTS - 1) * 2)
+       next_entry = 0;                         /* go back to the beginning */
+    else
+       next_entry = ntohl(ring_header[2]) + 2; /* use the next one */
+
+    /* update the data element */
+    /* storing the timestamp in an *unsigned* long allows dates up to 2106 */
+    ring_buffer[next_entry] = htonl((u_int32_t) time(NULL));
+    lost = lcp_echos_pending - 1;
+    if (lost > 0xFF)
+       lost = 0xFF;            /* truncate the lost packets count to 256 */
+    if (rtt > 0xFFFFFF)
+       rtt = 0xFFFFFF;         /* truncate the RTT to 16777216 */
+    /* use bits 24-31 for the lost packets count and bits 0-23 for the RTT */
+    ring_buffer[next_entry + 1] = htonl((u_int32_t) ((lost << 24) + rtt));
+
+    /* update the pointer to the (just updated) most current data element */
+    ring_header[2] = htonl(next_entry);
+
+    /* In theory, CPUs implementing a weakly-consistent memory model do not
+     * guarantee that these three memory store operations to the buffer will
+     * be seen in the same order by the reader process.
+     * This means that a process reading the file could see the index
+     * having been updated before the element that the index points to had
+     * been written.
+     * But in practice we expect that the read(2) system call used by
+     * consumers processes is atomic with respect to the following msync(2)
+     * call, so we ignore the issue.
+     */
+
+    if (msync(lcp_rtt_buffer, LCP_RTT_FILE_SIZE, MS_ASYNC) < 0)
+       error("msync() for %s failed: %m", lcp_rtt_file);
+}
+
 /*
  * LcpEchoReply - LCP has received a reply to the echo
  */
@@ -2245,6 +2333,30 @@ lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
        return;
     }
 
+    if (lcp_rtt_file_fd && len >= 16) {
+       long lcp_rtt_magic;
+
+       /*
+        * If the magic word is found at the beginning of the data section
+        * of the frame then read the timestamp which follows and subtract
+        * it from the current time to compute the round trip time.
+        */
+       GETLONG(lcp_rtt_magic, inp);
+       if (lcp_rtt_magic == LCP_RTT_MAGIC) {
+           struct timespec ts;
+           unsigned long req_sec, req_nsec, rtt;
+
+           clock_gettime(CLOCK_MONOTONIC, &ts);
+           GETLONG(req_sec, inp);
+           GETLONG(req_nsec, inp);
+           /* compute the RTT in microseconds */
+           rtt = (ts.tv_sec - req_sec) * 1000000
+               + (ts.tv_nsec / 1000 - req_nsec / 1000);
+           /* log the RTT */
+           lcp_rtt_update_buffer(rtt);
+       }
+    }
+
     /* Reset the number of outstanding echo frames */
     lcp_echos_pending = 0;
 }
@@ -2257,7 +2369,7 @@ static void
 LcpSendEchoRequest (fsm *f)
 {
     u_int32_t lcp_magic;
-    u_char pkt[4], *pktp;
+    u_char pkt[16], *pktp;
 
     /*
      * Detect the failure of the peer at this point.
@@ -2279,6 +2391,8 @@ LcpSendEchoRequest (fsm *f)
 
        if (get_ppp_stats(f->unit, &cur_stats) && cur_stats.pkts_in != last_pkts_in) {
            last_pkts_in = cur_stats.pkts_in;
+           /* receipt of traffic indicates the link is working... */
+           lcp_echos_pending = 0;
            return;
        }
     }
@@ -2290,11 +2404,73 @@ LcpSendEchoRequest (fsm *f)
         lcp_magic = lcp_gotoptions[f->unit].magicnumber;
        pktp = pkt;
        PUTLONG(lcp_magic, pktp);
+
+       /* Put a timestamp in the data section of the frame */
+       if (lcp_rtt_file_fd) {
+           struct timespec ts;
+
+           PUTLONG(LCP_RTT_MAGIC, pktp);
+           clock_gettime(CLOCK_MONOTONIC, &ts);
+           PUTLONG((u_int32_t)ts.tv_sec, pktp);
+           PUTLONG((u_int32_t)ts.tv_nsec, pktp);
+       }
+
         fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
        ++lcp_echos_pending;
     }
 }
 
+static void
+lcp_rtt_open_file (void)
+{
+    volatile u_int32_t *ring_header;
+
+    if (!lcp_rtt_file)
+       return;
+
+    lcp_rtt_file_fd = open(lcp_rtt_file, O_RDWR | O_CREAT, 0644);
+    if (lcp_rtt_file_fd < 0) {
+       error("Can't open the RTT log file %s: %m", lcp_rtt_file);
+       lcp_rtt_file_fd = 0;
+       return;
+    }
+
+    if (ftruncate(lcp_rtt_file_fd, LCP_RTT_FILE_SIZE) < 0)
+       fatal("ftruncate() of %s failed: %m", lcp_rtt_file);
+    lcp_rtt_buffer = mmap(0, LCP_RTT_FILE_SIZE, PROT_READ | PROT_WRITE,
+           MAP_SHARED, lcp_rtt_file_fd, 0);
+    if (lcp_rtt_buffer == MAP_FAILED)
+       fatal("mmap() of %s failed: %m", lcp_rtt_file);
+    ring_header = lcp_rtt_buffer;
+
+    /* initialize the ring buffer */
+    if (ring_header[0] != htonl(LCP_RTT_MAGIC)) {
+       memset(lcp_rtt_buffer, 0, LCP_RTT_FILE_SIZE);
+       ring_header[0] = htonl(LCP_RTT_MAGIC);
+    }
+
+    ring_header[3] = htonl(lcp_echo_interval);
+    ring_header[1] = htonl(1); /* status: LCP up, file opened */
+}
+
+static void
+lcp_rtt_close_file (void)
+{
+    volatile u_int32_t *const ring_header = lcp_rtt_buffer;
+
+    if (!lcp_rtt_file_fd)
+       return;
+
+    ring_header[1] = htonl(0); /* status: LCP down, file closed */
+
+    if (munmap(lcp_rtt_buffer, LCP_RTT_FILE_SIZE) < 0)
+       error("munmap() of %s failed: %m", lcp_rtt_file);
+    if (close(lcp_rtt_file_fd) < 0)
+       error("close() of %s failed: %m", lcp_rtt_file);
+    lcp_rtt_buffer = NULL;
+    lcp_rtt_file_fd = 0;
+}
+
 /*
  * lcp_echo_lowerup - Start the timer for the LCP frame
  */
@@ -2308,6 +2484,9 @@ lcp_echo_lowerup (int unit)
     lcp_echos_pending      = 0;
     lcp_echo_number        = 0;
     lcp_echo_timer_running = 0;
+
+    /* Open the file where the LCP RTT data will be logged */
+    lcp_rtt_open_file();
   
     /* If a timeout interval is specified then start the timer */
     if (lcp_echo_interval != 0)
@@ -2327,4 +2506,7 @@ lcp_echo_lowerdown (int unit)
         UNTIMEOUT (LcpEchoTimeout, f);
         lcp_echo_timer_running = 0;
     }
+
+    /* Close the file containing the LCP RTT data */
+    lcp_rtt_close_file();
 }
index c01313d869aa59015ff95262b7ddea0f0949c53b..bdf18d03eadc7007a9e663fd6a0d54c944b6f61d 100644 (file)
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 /*
  * Options.
  */
 /* Value used as data for CI_CALLBACK option */
 #define CBCP_OPT       6       /* Use callback control protocol */
 
+/* An endpoint discriminator, used with multilink. */
+#define MAX_ENDP_LEN   20      /* maximum length of discriminator value */
+struct epdisc {
+    unsigned char      class;
+    unsigned char      length;
+    unsigned char      value[MAX_ENDP_LEN];
+};
+
 /*
  * The state of options is described by an lcp_options structure.
  */
@@ -106,11 +119,11 @@ typedef struct lcp_options {
     bool neg_endpoint;         /* negotiate endpoint discriminator */
     int  mru;                  /* Value of MRU */
     int         mrru;                  /* Value of MRRU, and multilink enable */
-    u_char chap_mdtype;                /* which MD types (hashing algorithm) */
-    u_int32_t asyncmap;                /* Value of async map */
-    u_int32_t magicnumber;
+    unsigned char chap_mdtype;         /* which MD types (hashing algorithm) */
+    uint32_t asyncmap;         /* Value of async map */
+    uint32_t magicnumber;
     int  numloops;             /* Number of loops during magic number neg. */
-    u_int32_t lqr_period;      /* Reporting period for LQR 1/100ths second */
+    uint32_t lqr_period;       /* Reporting period for LQR 1/100ths second */
     struct epdisc endpoint;    /* endpoint discriminator */
 } lcp_options;
 
@@ -128,7 +141,7 @@ void lcp_open(int);
 void lcp_close(int, char *);
 void lcp_lowerup(int);
 void lcp_lowerdown(int);
-void lcp_sprotrej(int, u_char *, int); /* send protocol reject */
+void lcp_sprotrej(int, unsigned char *, int);  /* send protocol reject */
 
 extern struct protent lcp_protent;
 
@@ -136,4 +149,9 @@ extern struct protent lcp_protent;
    before deciding the link is looped-back. */
 #define DEFLOOPBACKFAIL        10
 
+
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_LCP_H
index 6a5a7eb28ee67cac69db337c3f833b5c0d42c45f..5e50f1d329bd54dfcab88f06c5ca5049608c80d9 100644 (file)
@@ -50,7 +50,7 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "magic.h"
 
 
index 70e4ce528238390da2367aab47b01a3e075fe9b4..68cbf9be24d395d92cb53610c0e410d6623df3f3 100644 (file)
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void magic_init (void);        /* Initialize the magic number generator */
 u_int32_t magic (void);        /* Returns the next magic number */
 
 /* Fill buffer with random bytes */
 void random_bytes (unsigned char *buf, int len);
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif // PPP_MAGIC_H
index 49319e2a81a7fbd4e8cc6cce5e131b931de8f1b6..3b3fc4542f3fa4c46645f85f8f26752abab65d39 100644 (file)
@@ -39,7 +39,7 @@
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * Copyright (c) 1999-2020 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -95,7 +91,8 @@
 #include <inttypes.h>
 #include <net/if.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "magic.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "ipv6cp.h"
 #endif
 #include "upap.h"
-#include "chap-new.h"
+#include "chap.h"
 #include "eap.h"
 #include "ccp.h"
 #include "ecp.h"
 #include "pathnames.h"
+#include "crypto.h"
+#include "multilink.h"
 
 #ifdef PPP_WITH_TDB
 #include "tdb.h"
 #include "atcp.h"
 #endif
 
-
 /* interface vars */
 char ifname[IFNAMSIZ];         /* Interface name */
 int ifunit;                    /* Interface unit number */
@@ -133,7 +131,6 @@ char *progname;                     /* Name of this program */
 char hostname[MAXNAMELEN];     /* Our hostname */
 static char pidfilename[MAXPATHLEN];   /* name of pid file */
 static char linkpidfile[MAXPATHLEN];   /* name of linkname pid file */
-char ppp_devnam[MAXPATHLEN];   /* name of PPP tty (maybe ttypx) */
 uid_t uid;                     /* Our real user-id */
 struct notifier *pidchange = NULL;
 struct notifier *phasechange = NULL;
@@ -145,7 +142,7 @@ int hungup;                 /* terminal has been hung up */
 int privileged;                        /* we're running as real uid root */
 int need_holdoff;              /* need holdoff period before restarting */
 int detached;                  /* have detached from terminal */
-volatile int status;           /* exit status for pppd */
+volatile int code;             /* exit status for pppd */
 int unsuccess;                 /* # unsuccessful connection attempts */
 int do_callback;               /* != 0 if we should do callback next */
 int doing_callback;            /* != 0 if we are doing callback */
@@ -170,7 +167,7 @@ static int fd_loop;         /* fd for getting demand-dial packets */
 int fd_devnull;                        /* fd for /dev/null */
 int devfd = -1;                        /* fd of underlying device */
 int fd_ppp = -1;               /* fd for talking PPP */
-int phase;                     /* where the link is at */
+ppp_phase_t phase;             /* where the link is at */
 int kill_link;
 int asked_to_quit;
 int open_ccp_flag;
@@ -205,6 +202,7 @@ static struct pppd_stats old_link_stats;
 struct pppd_stats link_stats;
 unsigned link_connect_time;
 int link_stats_valid;
+int link_stats_print;
 
 int error_count;
 
@@ -246,6 +244,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);
@@ -260,6 +259,72 @@ void print_link_stats(void);
 extern char    *getlogin(void);
 int main(int, char *[]);
 
+const char *ppp_hostname()
+{
+    return hostname;
+}
+
+bool ppp_signaled(int sig)
+{
+    if (sig == SIGTERM)
+        return !!got_sigterm;
+    if (sig == SIGUSR2)
+        return !!got_sigusr2;
+    if (sig == SIGHUP)
+        return !!got_sighup;
+    return false;
+}
+
+ppp_exit_code_t ppp_status()
+{
+   return code;
+}
+
+void ppp_set_status(ppp_exit_code_t value)
+{
+    code = value;
+}
+
+void ppp_set_session_number(int number)
+{
+    ppp_session_number = number;
+}
+
+int ppp_get_session_number()
+{
+    return ppp_session_number;
+}
+
+const char *ppp_ifname()
+{
+    return ifname;
+}
+
+int ppp_get_ifname(char *buf, size_t bufsz)
+{
+    if (buf) {
+        return strlcpy(buf, ifname, bufsz);
+    }
+    return false;
+}
+
+void ppp_set_ifname(const char *name)
+{
+    if (name) {
+        strlcpy(ifname, name, sizeof(ifname));
+    }
+}
+
+int ppp_ifunit()
+{
+    return ifunit;
+}
+
+int ppp_get_link_uptime()
+{
+    return link_connect_time;
+}
+
 /*
  * PPP Data Link Layer "protocol" table.
  * One entry per supported protocol.
@@ -294,14 +359,23 @@ main(int argc, char *argv[])
     struct protent *protp;
     char numbuf[16];
 
-    strlcpy(path_ipup, _PATH_IPUP, MAXPATHLEN);
-    strlcpy(path_ipdown, _PATH_IPDOWN, MAXPATHLEN);
+    strlcpy(path_upapfile, PPP_PATH_UPAPFILE, MAXPATHLEN);
+    strlcpy(path_chapfile, PPP_PATH_CHAPFILE, MAXPATHLEN);
+
+    strlcpy(path_net_init, PPP_PATH_NET_INIT, MAXPATHLEN);
+    strlcpy(path_net_preup, PPP_PATH_NET_PREUP, MAXPATHLEN);
+    strlcpy(path_net_down, PPP_PATH_NET_DOWN, MAXPATHLEN);
+
+    strlcpy(path_ipup, PPP_PATH_IPUP, MAXPATHLEN);
+    strlcpy(path_ipdown, PPP_PATH_IPDOWN, MAXPATHLEN);
+    strlcpy(path_ippreup, PPP_PATH_IPPREUP, MAXPATHLEN);
 
 #ifdef PPP_WITH_IPV6CP
-    strlcpy(path_ipv6up, _PATH_IPV6UP, MAXPATHLEN);
-    strlcpy(path_ipv6down, _PATH_IPV6DOWN, MAXPATHLEN);
+    strlcpy(path_ipv6up, PPP_PATH_IPV6UP, MAXPATHLEN);
+    strlcpy(path_ipv6down, PPP_PATH_IPV6DOWN, MAXPATHLEN);
 #endif
     link_stats_valid = 0;
+    link_stats_print = 1;
     new_phase(PHASE_INITIALIZE);
 
     script_env = NULL;
@@ -309,8 +383,13 @@ main(int argc, char *argv[])
     /* Initialize syslog facilities */
     reopen_log();
 
-    if (gethostname(hostname, MAXNAMELEN) < 0 ) {
-       option_error("Couldn't get hostname: %m");
+    /* Initialize crypto libraries */
+    if (!PPP_crypto_init()) {
+        exit(1);
+    }
+
+    if (gethostname(hostname, sizeof(hostname)) < 0 ) {
+       ppp_option_error("Couldn't get hostname: %m");
        exit(1);
     }
     hostname[MAXNAMELEN-1] = 0;
@@ -321,7 +400,7 @@ main(int argc, char *argv[])
     uid = getuid();
     privileged = uid == 0;
     slprintf(numbuf, sizeof(numbuf), "%d", uid);
-    script_setenv("ORIG_UID", numbuf, 0);
+    ppp_script_setenv("ORIG_UID", numbuf, 0);
 
     ngroups = getgroups(NGROUPS_MAX, groups);
 
@@ -348,7 +427,7 @@ main(int argc, char *argv[])
      * Parse, in order, the system options file, the user's options file,
      * and the command line arguments.
      */
-    if (!options_from_file(_PATH_SYSOPTIONS, !privileged, 0, 1)
+    if (!ppp_options_from_file(PPP_PATH_SYSOPTIONS, !privileged, 0, 1)
        || !options_from_user()
        || !parse_args(argc-1, argv+1))
        exit(EXIT_OPTION_ERROR);
@@ -364,17 +443,22 @@ main(int argc, char *argv[])
     if (debug)
        setlogmask(LOG_UPTO(LOG_DEBUG));
 
+    if (show_options) {
+       showopts();
+       die(0);
+    }
+
     /*
      * Check that we are running as root.
      */
     if (geteuid() != 0) {
-       option_error("must be root to run %s, since it is not setuid-root",
+       ppp_option_error("must be root to run %s, since it is not setuid-root",
                     argv[0]);
        exit(EXIT_NOT_ROOT);
     }
 
-    if (!ppp_available()) {
-       option_error("%s", no_ppp_msg);
+    if (!ppp_check_kernel_support()) {
+       ppp_option_error("%s", no_ppp_msg);
        exit(EXIT_NO_KERNEL_SUPPORT);
     }
 
@@ -385,9 +469,7 @@ main(int argc, char *argv[])
     if (!sys_check_options())
        exit(EXIT_OPTION_ERROR);
     auth_check_options();
-#ifdef PPP_WITH_MULTILINK
     mp_check_options();
-#endif
     for (i = 0; (protp = protocols[i]) != NULL; ++i)
        if (protp->check_options != NULL)
            (*protp->check_options)();
@@ -405,9 +487,9 @@ main(int argc, char *argv[])
        die(0);
 
     /* Make sure fds 0, 1, 2 are open to somewhere. */
-    fd_devnull = open(_PATH_DEVNULL, O_RDWR);
+    fd_devnull = open(PPP_DEVNULL, O_RDWR);
     if (fd_devnull < 0)
-       fatal("Couldn't open %s: %m", _PATH_DEVNULL);
+       fatal("Couldn't open %s: %m", PPP_DEVNULL);
     while (fd_devnull <= 2) {
        i = dup(fd_devnull);
        if (i < 0)
@@ -421,12 +503,12 @@ main(int argc, char *argv[])
     sys_init();
 
 #ifdef PPP_WITH_TDB
-    pppdb = tdb_open(_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
+    pppdb = tdb_open(PPP_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644);
     if (pppdb != NULL) {
        slprintf(db_key, sizeof(db_key), "pppd%d", getpid());
        update_db_entry();
     } else {
-       warn("Warning: couldn't open ppp database %s", _PATH_PPPDB);
+       warn("Warning: couldn't open ppp database %s", PPP_PATH_PPPDB);
        if (multilink) {
            warn("Warning: disabling multilink");
            multilink = 0;
@@ -449,12 +531,12 @@ main(int argc, char *argv[])
            p = "(unknown)";
     }
     syslog(LOG_NOTICE, "pppd %s started by %s, uid %d", VERSION, p, uid);
-    script_setenv("PPPLOGNAME", p, 0);
+    ppp_script_setenv("PPPLOGNAME", p, 0);
 
     if (devnam[0])
-       script_setenv("DEVICE", devnam, 1);
+       ppp_script_setenv("DEVICE", devnam, 1);
     slprintf(numbuf, sizeof(numbuf), "%d", getpid());
-    script_setenv("PPPD_PID", numbuf, 1);
+    ppp_script_setenv("PPPD_PID", numbuf, 1);
 
     setup_signals();
 
@@ -485,7 +567,7 @@ main(int argc, char *argv[])
        listen_time = 0;
        need_holdoff = 1;
        devfd = -1;
-       status = EXIT_OK;
+       code = EXIT_OK;
        ++unsuccess;
        doing_callback = do_callback;
        do_callback = 0;
@@ -515,18 +597,20 @@ main(int argc, char *argv[])
            info("Starting link");
        }
 
-       get_time(&start_time);
-       script_unsetenv("CONNECT_TIME");
-       script_unsetenv("BYTES_SENT");
-       script_unsetenv("BYTES_RCVD");
+       ppp_get_time(&start_time);
+       ppp_script_unsetenv("CONNECT_TIME");
+       ppp_script_unsetenv("BYTES_SENT");
+       ppp_script_unsetenv("BYTES_RCVD");
 
        lcp_open(0);            /* Start protocol */
        start_link(0);
        while (phase != PHASE_DEAD) {
            handle_events();
            get_input();
-           if (kill_link)
+           if (kill_link) {
                lcp_close(0, "User request");
+               need_holdoff = 0;
+           }
            if (asked_to_quit) {
                bundle_terminating = 1;
                if (phase == PHASE_MASTER)
@@ -581,7 +665,8 @@ main(int argc, char *argv[])
        }
     }
 
-    die(status);
+    PPP_crypto_deinit();
+    die(code);
     return 0;
 }
 
@@ -612,15 +697,15 @@ handle_events(void)
        info("Hangup (SIGHUP)");
        kill_link = 1;
        got_sighup = 0;
-       if (status != EXIT_HANGUP)
-           status = EXIT_USER_REQUEST;
+       if (code != EXIT_HANGUP)
+           code = EXIT_USER_REQUEST;
     }
     if (got_sigterm) {
        info("Terminating on signal %d", got_sigterm);
        kill_link = 1;
        asked_to_quit = 1;
        persist = 0;
-       status = EXIT_USER_REQUEST;
+       code = EXIT_USER_REQUEST;
        got_sigterm = 0;
     }
     if (got_sigchld) {
@@ -724,6 +809,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.
@@ -738,13 +843,16 @@ set_ifunit(int iskey)
     else
        slprintf(ifname, sizeof(ifname), "%s%d", PPP_DRV_NAME, ifunit);
     info("Using interface %s", ifname);
-    script_setenv("IFNAME", ifname, iskey);
+    ppp_script_setenv("IFNAME", ifname, iskey);
     slprintf(ifkey, sizeof(ifkey), "%d", ifunit);
-    script_setenv("UNIT", ifkey, iskey);
+    ppp_script_setenv("UNIT", ifkey, iskey);
     if (iskey) {
        create_pidfile(getpid());       /* write pid to file */
        create_linkpidfile(getpid());
     }
+    if (*remote_number)
+        ppp_script_setenv("REMOTENUMBER", remote_number, 0);
+    run_net_script(path_net_init, 1);
 }
 
 /*
@@ -787,7 +895,7 @@ detach(void)
     if (log_default)
        log_to_fd = -1;
     slprintf(numbuf, sizeof(numbuf), "%d", getpid());
-    script_setenv("PPPD_PID", numbuf, 1);
+    ppp_script_setenv("PPPD_PID", numbuf, 1);
 
     /* wait for parent to finish updating pid & lock files and die */
     close(pipefd[1]);
@@ -813,8 +921,9 @@ create_pidfile(int pid)
 {
     FILE *pidfile;
 
-    slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid",
-            _PATH_VARRUN, ifname);
+    mkdir_recursive(PPP_PATH_VARRUN);
+    slprintf(pidfilename, sizeof(pidfilename), "%s/%s.pid",
+            PPP_PATH_VARRUN, ifname);
     if ((pidfile = fopen(pidfilename, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
        (void) fclose(pidfile);
@@ -831,9 +940,9 @@ create_linkpidfile(int pid)
 
     if (linkname[0] == 0)
        return;
-    script_setenv("LINKNAME", linkname, 1);
-    slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid",
-            _PATH_VARRUN, linkname);
+    ppp_script_setenv("LINKNAME", linkname, 1);
+    slprintf(linkpidfile, sizeof(linkpidfile), "%s/ppp-%s.pid",
+            PPP_PATH_VARRUN, linkname);
     if ((pidfile = fopen(linkpidfile, "w")) != NULL) {
        fprintf(pidfile, "%d\n", pid);
        if (ifname[0])
@@ -1034,14 +1143,15 @@ get_input(void)
        return;
 
     if (len == 0) {
-       if (bundle_eof && multilink_master) {
+       if (bundle_eof && mp_master()) {
            notice("Last channel has disconnected");
            mp_bundle_terminated();
            return;
        }
        notice("Modem hangup");
        hungup = 1;
-       status = EXIT_HANGUP;
+       code = EXIT_HANGUP;
+       need_holdoff = 0;
        lcp_lowerdown(0);       /* serial link is no longer available */
        link_terminated(0);
        return;
@@ -1145,21 +1255,45 @@ ppp_recv_config(int unit, int mru, u_int32_t accm, int pcomp, int accomp)
  * new_phase - signal the start of a new phase of pppd's operation.
  */
 void
-new_phase(int p)
+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(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(path_net_down, 0);
+       break;
+    }
+
     phase = p;
     if (new_phase_hook)
        (*new_phase_hook)(p);
     notify(phasechange, p);
 }
 
+bool
+in_phase(ppp_phase_t p)
+{
+    return (phase == p);
+}
+
 /*
  * die - clean up state and exit with the specified status.
  */
 void
 die(int status)
 {
-    if (!doing_multilink || multilink_master)
+
+    if (!mp_on() || mp_master())
        print_link_stats();
     cleanup();
     notify(exitnotify, status);
@@ -1195,12 +1329,12 @@ print_link_stats(void)
     /*
      * Print connect time and statistics.
      */
-    if (link_stats_valid) {
+    if (link_stats_print && link_stats_valid) {
        int t = (link_connect_time + 5) / 6;    /* 1/10ths of minutes */
        info("Connect time %d.%d minutes.", t/10, t%10);
-       info("Sent %u bytes, received %u bytes.",
+       info("Sent %llu bytes, received %llu bytes.",
            link_stats.bytes_out, link_stats.bytes_in);
-       link_stats_valid = 0;
+       link_stats_print = 0;
     }
 }
 
@@ -1210,9 +1344,9 @@ print_link_stats(void)
 void
 reset_link_stats(int u)
 {
-    if (!get_ppp_stats(u, &old_link_stats))
-       return;
-    get_time(&start_time);
+    get_ppp_stats(u, &old_link_stats);
+    ppp_get_time(&start_time);
+    link_stats_print = 1;
 }
 
 /*
@@ -1225,7 +1359,7 @@ update_link_stats(int u)
     char numbuf[32];
 
     if (!get_ppp_stats(u, &link_stats)
-       || get_time(&now) < 0)
+       || ppp_get_time(&now) < 0)
        return;
     link_connect_time = now.tv_sec - start_time.tv_sec;
     link_stats_valid = 1;
@@ -1236,11 +1370,24 @@ update_link_stats(int u)
     link_stats.pkts_out  -= old_link_stats.pkts_out;
 
     slprintf(numbuf, sizeof(numbuf), "%u", link_connect_time);
-    script_setenv("CONNECT_TIME", numbuf, 0);
+    ppp_script_setenv("CONNECT_TIME", numbuf, 0);
     snprintf(numbuf, sizeof(numbuf), "%" PRIu64, link_stats.bytes_out);
-    script_setenv("BYTES_SENT", numbuf, 0);
+    ppp_script_setenv("BYTES_SENT", numbuf, 0);
     snprintf(numbuf, sizeof(numbuf), "%" PRIu64, link_stats.bytes_in);
-    script_setenv("BYTES_RCVD", numbuf, 0);
+    ppp_script_setenv("BYTES_RCVD", numbuf, 0);
+}
+
+bool
+ppp_get_link_stats(ppp_link_stats_st *stats)
+{
+    update_link_stats(0);
+    if (stats != NULL &&
+        link_stats_valid) {
+
+        memcpy(stats, &link_stats, sizeof(*stats));
+        return true;
+    }
+    return false;
 }
 
 
@@ -1258,7 +1405,7 @@ static struct timeval timenow;            /* Current time */
  * timeout - Schedule a timeout.
  */
 void
-timeout(void (*func)(void *), void *arg, int secs, int usecs)
+ppp_timeout(void (*func)(void *), void *arg, int secs, int usecs)
 {
     struct callout *newp, *p, **pp;
 
@@ -1269,7 +1416,7 @@ timeout(void (*func)(void *), void *arg, int secs, int usecs)
        fatal("Out of memory in timeout()!");
     newp->c_arg = arg;
     newp->c_func = func;
-    get_time(&timenow);
+    ppp_get_time(&timenow);
     newp->c_time.tv_sec = timenow.tv_sec + secs;
     newp->c_time.tv_usec = timenow.tv_usec + usecs;
     if (newp->c_time.tv_usec >= 1000000) {
@@ -1294,7 +1441,7 @@ timeout(void (*func)(void *), void *arg, int secs, int usecs)
  * untimeout - Unschedule a timeout.
  */
 void
-untimeout(void (*func)(void *), void *arg)
+ppp_untimeout(void (*func)(void *), void *arg)
 {
     struct callout **copp, *freep;
 
@@ -1321,7 +1468,7 @@ calltimeout(void)
     while (callout != NULL) {
        p = callout;
 
-       if (get_time(&timenow) < 0)
+       if (ppp_get_time(&timenow) < 0)
            fatal("Failed to get time of day: %m");
        if (!(p->c_time.tv_sec < timenow.tv_sec
              || (p->c_time.tv_sec == timenow.tv_sec
@@ -1345,7 +1492,7 @@ timeleft(struct timeval *tvp)
     if (callout == NULL)
        return NULL;
 
-    get_time(&timenow);
+    ppp_get_time(&timenow);
     tvp->tv_sec = callout->c_time.tv_sec - timenow.tv_sec;
     tvp->tv_usec = callout->c_time.tv_usec - timenow.tv_usec;
     if (tvp->tv_usec < 0) {
@@ -1524,14 +1671,14 @@ bad_signal(int sig)
 }
 
 /*
- * safe_fork - Create a child process.  The child closes all the
+ * ppp_safe_fork - Create a child process.  The child closes all the
  * file descriptors that we don't want to leak to a script.
  * The parent waits for the child to do this before returning.
  * This also arranges for the specified fds to be dup'd to
  * fds 0, 1, 2 in the child.
  */
 pid_t
-safe_fork(int infd, int outfd, int errfd)
+ppp_safe_fork(int infd, int outfd, int errfd)
 {
        pid_t pid;
        int fd, pipefd[2];
@@ -1562,7 +1709,7 @@ safe_fork(int infd, int outfd, int errfd)
        }
 
        /* Executing in the child */
-       sys_close();
+       ppp_sys_close();
 #ifdef PPP_WITH_TDB
        if (pppdb != NULL)
                tdb_close(pppdb);
@@ -1655,7 +1802,7 @@ update_system_environment(void)
 /*
  * device_script - run a program to talk to the specified fds
  * (e.g. to run the connector or disconnector script).
- * stderr gets connected to the log fd or to the _PATH_CONNERRS file.
+ * stderr gets connected to the log fd or to the PPP_PATH_CONNERRS file.
  */
 int
 device_script(char *program, int in, int out, int dont_wait)
@@ -1668,10 +1815,10 @@ device_script(char *program, int in, int out, int dont_wait)
     if (log_to_fd >= 0)
        errfd = log_to_fd;
     else
-       errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0644);
+       errfd = open(PPP_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0644);
 
     ++conn_running;
-    pid = safe_fork(in, out, errfd);
+    pid = ppp_safe_fork(in, out, errfd);
 
     if (pid != 0 && log_to_fd < 0)
        close(errfd);
@@ -1721,7 +1868,7 @@ device_script(char *program, int in, int out, int dont_wait)
  * and update the script environment.  Note that we intentionally do
  * not update the TDB.  These changes are layered on top right before
  * exec.  It is not possible to use script_setenv() or
- * script_unsetenv() safely after this routine is run.
+ * ppp_script_unsetenv() safely after this routine is run.
  */
 static void
 update_script_environment(void)
@@ -1765,7 +1912,7 @@ update_script_environment(void)
  * reap_kids) iff the return value is > 0.
  */
 pid_t
-run_program(char *prog, char **args, int must_exist, void (*done)(void *), void *arg, int wait)
+run_program(char *prog, char * const *args, int must_exist, void (*done)(void *), void *arg, int wait)
 {
     int pid, status, ret;
     struct stat sbuf;
@@ -1784,7 +1931,7 @@ run_program(char *prog, char **args, int must_exist, void (*done)(void *), void
        return 0;
     }
 
-    pid = safe_fork(fd_devnull, fd_devnull, fd_devnull);
+    pid = ppp_safe_fork(fd_devnull, fd_devnull, fd_devnull);
     if (pid == -1) {
        error("Failed to create child process for %s: %m", prog);
        return -1;
@@ -1933,21 +2080,46 @@ reap_kids(void)
     return 0;
 }
 
+
+struct notifier **get_notifier_by_type(ppp_notify_t type)
+{
+    struct notifier **list[NF_MAX_NOTIFY] = {
+        [NF_PID_CHANGE  ] = &pidchange,
+        [NF_PHASE_CHANGE] = &phasechange,
+        [NF_EXIT        ] = &exitnotify,
+        [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,
+    };
+    return list[type];
+}
+
 /*
  * add_notifier - add a new function to be called when something happens.
  */
 void
-add_notifier(struct notifier **notif, notify_func func, void *arg)
+ppp_add_notify(ppp_notify_t type, ppp_notify_fn *func, void *arg)
 {
-    struct notifier *np;
-
-    np = malloc(sizeof(struct notifier));
-    if (np == 0)
-       novm("notifier struct");
-    np->next = *notif;
-    np->func = func;
-    np->arg = arg;
-    *notif = np;
+    struct notifier **notif = get_notifier_by_type(type);
+    if (notif) {
+
+       struct notifier *np = malloc(sizeof(struct notifier));
+       if (np == 0)
+           novm("notifier struct");
+       np->next = *notif;
+       np->func = func;
+       np->arg = arg;
+       *notif = np;
+    } else {
+       error("Could not find notifier function for: %d", type);
+    }
 }
 
 /*
@@ -1955,16 +2127,21 @@ add_notifier(struct notifier **notif, notify_func func, void *arg)
  * be called when something happens.
  */
 void
-remove_notifier(struct notifier **notif, notify_func func, void *arg)
+ppp_del_notify(ppp_notify_t type, ppp_notify_fn *func, void *arg)
 {
-    struct notifier *np;
-
-    for (; (np = *notif) != 0; notif = &np->next) {
-       if (np->func == func && np->arg == arg) {
-           *notif = np->next;
-           free(np);
-           break;
+    struct notifier **notif = get_notifier_by_type(type);
+    if (notif) {
+       struct notifier *np;
+
+       for (; (np = *notif) != 0; notif = &np->next) {
+           if (np->func == func && np->arg == arg) {
+               *notif = np->next;
+               free(np);
+               break;
+           }
        }
+    } else {
+       error("Could not find notifier function for: %d", type);
     }
 }
 
@@ -1986,17 +2163,17 @@ 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);
 }
 
 /*
- * script_setenv - set an environment variable value to be used
+ * ppp_script_setenv - set an environment variable value to be used
  * for scripts that we run (e.g. ip-up, auth-up, etc.)
  */
 void
-script_setenv(char *var, char *value, int iskey)
+ppp_script_setenv(char *var, char *value, int iskey)
 {
     size_t varl = strlen(var);
     size_t vl = varl + strlen(value) + 2;
@@ -2053,11 +2230,11 @@ script_setenv(char *var, char *value, int iskey)
 }
 
 /*
- * script_unsetenv - remove a variable from the environment
+ * ppp_script_unsetenv - remove a variable from the environment
  * for scripts.
  */
 void
-script_unsetenv(char *var)
+ppp_script_unsetenv(char *var)
 {
     int vl = strlen(var);
     int i;
diff --git a/pppd/md4.c b/pppd/md4.c
deleted file mode 100644 (file)
index 88f3413..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
-** ********************************************************************
-** md4.c -- Implementation of MD4 Message Digest Algorithm           **
-** Updated: 2/16/90 by Ronald L. Rivest                              **
-** (C) 1990 RSA Data Security, Inc.                                  **
-** ********************************************************************
-*/
-
-/*
-** To use MD4:
-**   -- Include md4.h in your program
-**   -- Declare an MDstruct MD to hold the state of the digest
-**          computation.
-**   -- Initialize MD using MDbegin(&MD)
-**   -- For each full block (64 bytes) X you wish to process, call
-**          MD4Update(&MD,X,512)
-**      (512 is the number of bits in a full block.)
-**   -- For the last block (less than 64 bytes) you wish to process,
-**          MD4Update(&MD,X,n)
-**      where n is the number of bits in the partial block. A partial
-**      block terminates the computation, so every MD computation
-**      should terminate by processing a partial block, even if it
-**      has n = 0.
-**   -- The message digest is available in MD.buffer[0] ...
-**      MD.buffer[3].  (Least-significant byte of each word
-**      should be output first.)
-**   -- You can print out the digest using MDprint(&MD)
-*/
-
-/* Implementation notes:
-** This implementation assumes that ints are 32-bit quantities.
-*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define TRUE  1
-#define FALSE 0
-
-/* Compile-time includes
-*/
-#include <stdio.h>
-#include "md4.h"
-#include "pppd.h"
-
-/* Compile-time declarations of MD4 "magic constants".
-*/
-#define I0  0x67452301       /* Initial values for MD buffer */
-#define I1  0xefcdab89
-#define I2  0x98badcfe
-#define I3  0x10325476
-#define C2  013240474631     /* round 2 constant = sqrt(2) in octal */
-#define C3  015666365641     /* round 3 constant = sqrt(3) in octal */
-/* C2 and C3 are from Knuth, The Art of Programming, Volume 2
-** (Seminumerical Algorithms), Second Edition (1981), Addison-Wesley.
-** Table 2, page 660.
-*/
-
-#define fs1  3               /* round 1 shift amounts */
-#define fs2  7
-#define fs3 11
-#define fs4 19
-#define gs1  3               /* round 2 shift amounts */
-#define gs2  5
-#define gs3  9
-#define gs4 13
-#define hs1  3               /* round 3 shift amounts */
-#define hs2  9
-#define hs3 11
-#define hs4 15
-
-/* Compile-time macro declarations for MD4.
-** Note: The "rot" operator uses the variable "tmp".
-** It assumes tmp is declared as unsigned int, so that the >>
-** operator will shift in zeros rather than extending the sign bit.
-*/
-#define f(X,Y,Z)             ((X&Y) | ((~X)&Z))
-#define g(X,Y,Z)             ((X&Y) | (X&Z) | (Y&Z))
-#define h(X,Y,Z)             (X^Y^Z)
-#define rot(X,S)             (tmp=X,(tmp<<S) | (tmp>>(32-S)))
-#define ff(A,B,C,D,i,s)      A = rot((A + f(B,C,D) + X[i]),s)
-#define gg(A,B,C,D,i,s)      A = rot((A + g(B,C,D) + X[i] + C2),s)
-#define hh(A,B,C,D,i,s)      A = rot((A + h(B,C,D) + X[i] + C3),s)
-
-/* MD4print(MDp)
-** Print message digest buffer MDp as 32 hexadecimal digits.
-** Order is from low-order byte of buffer[0] to high-order byte of
-** buffer[3].
-** Each byte is printed with high-order hexadecimal digit first.
-** This is a user-callable routine.
-*/
-void
-MD4Print(MD4_CTX *MDp)
-{
-  int i,j;
-  for (i=0;i<4;i++)
-    for (j=0;j<32;j=j+8)
-      printf("%02x",(MDp->buffer[i]>>j) & 0xFF);
-}
-
-/* MD4Init(MDp)
-** Initialize message digest buffer MDp.
-** This is a user-callable routine.
-*/
-void
-MD4Init(MD4_CTX *MDp)
-{
-  int i;
-  MDp->buffer[0] = I0;
-  MDp->buffer[1] = I1;
-  MDp->buffer[2] = I2;
-  MDp->buffer[3] = I3;
-  for (i=0;i<8;i++) MDp->count[i] = 0;
-  MDp->done = 0;
-}
-
-/* MDblock(MDp,X)
-** Update message digest buffer MDp->buffer using 16-word data block X.
-** Assumes all 16 words of X are full of data.
-** Does not update MDp->count.
-** This routine is not user-callable.
-*/
-static void
-MDblock(MD4_CTX *MDp, unsigned char *Xb)
-{
-  register unsigned int tmp, A, B, C, D;
-  unsigned int X[16];
-  int i;
-
-  for (i = 0; i < 16; ++i) {
-    X[i] = Xb[0] + (Xb[1] << 8) + (Xb[2] << 16) + (Xb[3] << 24);
-    Xb += 4;
-  }
-
-  A = MDp->buffer[0];
-  B = MDp->buffer[1];
-  C = MDp->buffer[2];
-  D = MDp->buffer[3];
-  /* Update the message digest buffer */
-  ff(A , B , C , D ,  0 , fs1); /* Round 1 */
-  ff(D , A , B , C ,  1 , fs2);
-  ff(C , D , A , B ,  2 , fs3);
-  ff(B , C , D , A ,  3 , fs4);
-  ff(A , B , C , D ,  4 , fs1);
-  ff(D , A , B , C ,  5 , fs2);
-  ff(C , D , A , B ,  6 , fs3);
-  ff(B , C , D , A ,  7 , fs4);
-  ff(A , B , C , D ,  8 , fs1);
-  ff(D , A , B , C ,  9 , fs2);
-  ff(C , D , A , B , 10 , fs3);
-  ff(B , C , D , A , 11 , fs4);
-  ff(A , B , C , D , 12 , fs1);
-  ff(D , A , B , C , 13 , fs2);
-  ff(C , D , A , B , 14 , fs3);
-  ff(B , C , D , A , 15 , fs4);
-  gg(A , B , C , D ,  0 , gs1); /* Round 2 */
-  gg(D , A , B , C ,  4 , gs2);
-  gg(C , D , A , B ,  8 , gs3);
-  gg(B , C , D , A , 12 , gs4);
-  gg(A , B , C , D ,  1 , gs1);
-  gg(D , A , B , C ,  5 , gs2);
-  gg(C , D , A , B ,  9 , gs3);
-  gg(B , C , D , A , 13 , gs4);
-  gg(A , B , C , D ,  2 , gs1);
-  gg(D , A , B , C ,  6 , gs2);
-  gg(C , D , A , B , 10 , gs3);
-  gg(B , C , D , A , 14 , gs4);
-  gg(A , B , C , D ,  3 , gs1);
-  gg(D , A , B , C ,  7 , gs2);
-  gg(C , D , A , B , 11 , gs3);
-  gg(B , C , D , A , 15 , gs4);
-  hh(A , B , C , D ,  0 , hs1); /* Round 3 */
-  hh(D , A , B , C ,  8 , hs2);
-  hh(C , D , A , B ,  4 , hs3);
-  hh(B , C , D , A , 12 , hs4);
-  hh(A , B , C , D ,  2 , hs1);
-  hh(D , A , B , C , 10 , hs2);
-  hh(C , D , A , B ,  6 , hs3);
-  hh(B , C , D , A , 14 , hs4);
-  hh(A , B , C , D ,  1 , hs1);
-  hh(D , A , B , C ,  9 , hs2);
-  hh(C , D , A , B ,  5 , hs3);
-  hh(B , C , D , A , 13 , hs4);
-  hh(A , B , C , D ,  3 , hs1);
-  hh(D , A , B , C , 11 , hs2);
-  hh(C , D , A , B ,  7 , hs3);
-  hh(B , C , D , A , 15 , hs4);
-  MDp->buffer[0] += A;
-  MDp->buffer[1] += B;
-  MDp->buffer[2] += C;
-  MDp->buffer[3] += D;
-}
-
-/* MD4Update(MDp,X,count)
-** Input: X -- a pointer to an array of unsigned characters.
-**        count -- the number of bits of X to use.
-**          (if not a multiple of 8, uses high bits of last byte.)
-** Update MDp using the number of bits of X given by count.
-** This is the basic input routine for an MD4 user.
-** The routine completes the MD computation when count < 512, so
-** every MD computation should end with one call to MD4Update with a
-** count less than 512.  A call with count 0 will be ignored if the
-** MD has already been terminated (done != 0), so an extra call with
-** count 0 can be given as a "courtesy close" to force termination
-** if desired.
-*/
-void
-MD4Update(MD4_CTX *MDp, unsigned char *X, unsigned int count)
-{
-  unsigned int i, tmp, bit, byte, mask;
-  unsigned char XX[64];
-  unsigned char *p;
-
-  /* return with no error if this is a courtesy close with count
-  ** zero and MDp->done is true.
-  */
-  if (count == 0 && MDp->done) return;
-  /* check to see if MD is already done and report error */
-  if (MDp->done)
-  { printf("\nError: MD4Update MD already done."); return; }
-
-  /* Add count to MDp->count */
-  tmp = count;
-  p = MDp->count;
-  while (tmp)
-  { tmp += *p;
-  *p++ = tmp;
-  tmp = tmp >> 8;
-  }
-
-  /* Process data */
-  if (count == 512)
-  { /* Full block of data to handle */
-    MDblock(MDp,X);
-  }
-  else if (count > 512) /* Check for count too large */
-  {
-    printf("\nError: MD4Update called with illegal count value %d.",
-          count);
-    return;
-  }
-  else /* partial block -- must be last block so finish up */
-  {
-    /* Find out how many bytes and residual bits there are */
-    byte = count >> 3;
-    bit =  count & 7;
-    /* Copy X into XX since we need to modify it */
-    if (count)
-      for (i=0;i<=byte;i++) XX[i] = X[i];
-    for (i=byte+1;i<64;i++) XX[i] = 0;
-    /* Add padding '1' bit and low-order zeros in last byte */
-    mask = 1 << (7 - bit);
-    XX[byte] = (XX[byte] | mask) & ~( mask - 1);
-    /* If room for bit count, finish up with this block */
-    if (byte <= 55)
-    {
-      for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
-      MDblock(MDp,XX);
-    }
-    else /* need to do two blocks to finish up */
-    {
-      MDblock(MDp,XX);
-      for (i=0;i<56;i++) XX[i] = 0;
-      for (i=0;i<8;i++)  XX[56+i] = MDp->count[i];
-      MDblock(MDp,XX);
-    }
-    /* Set flag saying we're done with MD computation */
-    MDp->done = 1;
-  }
-}
-
-/*
-** Finish up MD4 computation and return message digest.
-*/
-void
-MD4Final(unsigned char *buf, MD4_CTX *MD)
-{
-  int i, j;
-  unsigned int w;
-
-  MD4Update(MD, NULL, 0);
-  for (i = 0; i < 4; ++i) {
-    w = MD->buffer[i];
-    for (j = 0; j < 4; ++j) {
-      *buf++ = w;
-      w >>= 8;
-    }
-  }
-}
-
-/*
-** End of md4.c
-****************************(cut)***********************************/
diff --git a/pppd/md4.h b/pppd/md4.h
deleted file mode 100644 (file)
index 546ea02..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-
-/*
-** ********************************************************************
-** md4.h -- Header file for implementation of                        **
-** MD4 Message Digest Algorithm                                      **
-** Updated: 2/13/90 by Ronald L. Rivest                              **
-** (C) 1990 RSA Data Security, Inc.                                  **
-** ********************************************************************
-*/
-#ifndef PPP_MD4_H
-#define PPP_MD4_H
-
-#include "pppdconf.h"
-
-#ifndef USE_MD4
-#include <openssl/md4.h>
-#define MD4Init MD4_Init
-#define MD4Update MD4_Update
-#define MD4Final MD4_Final
-#else
-
-/* MDstruct is the data structure for a message digest computation.
-*/
-typedef struct {
-       unsigned int buffer[4]; /* Holds 4-word result of MD computation */
-       unsigned char count[8]; /* Number of bits processed so far */
-       unsigned int done;      /* Nonzero means MD computation finished */
-} MD4_CTX;
-
-/* MD4Init(MD4_CTX *)
-** Initialize the MD4_CTX prepatory to doing a message digest
-** computation.
-*/
-extern void MD4Init(MD4_CTX *MD);
-
-/* MD4Update(MD,X,count)
-** Input: X -- a pointer to an array of unsigned characters.
-**        count -- the number of bits of X to use (an unsigned int).
-** Updates MD using the first "count" bits of X.
-** The array pointed to by X is not modified.
-** If count is not a multiple of 8, MD4Update uses high bits of
-** last byte.
-** This is the basic input routine for a user.
-** The routine terminates the MD computation when count < 512, so
-** every MD computation should end with one call to MD4Update with a
-** count less than 512.  Zero is OK for a count.
-*/
-extern void MD4Update(MD4_CTX *MD, unsigned char *X, unsigned int count);
-
-/* MD4Print(MD)
-** Prints message digest buffer MD as 32 hexadecimal digits.
-** Order is from low-order byte of buffer[0] to high-order byte
-** of buffer[3].
-** Each byte is printed with high-order hexadecimal digit first.
-*/
-extern void MD4Print(MD4_CTX *);
-
-/* MD4Final(buf, MD)
-** Returns message digest from MD and terminates the message
-** digest computation.
-*/
-extern void MD4Final(unsigned char *, MD4_CTX *);
-
-/*
-** End of md4.h
-****************************(cut)***********************************/
-#endif  /* USE_MD4 */
-#endif  /* PPP_MD4_H */
diff --git a/pppd/md5.c b/pppd/md5.c
deleted file mode 100644 (file)
index 9fb3397..0000000
+++ /dev/null
@@ -1,303 +0,0 @@
-
-
-/*
- ***********************************************************************
- ** md5.c -- the source code for MD5 routines                         **
- ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
- ** Created: 2/17/90 RLR                                              **
- ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
- ***********************************************************************
- */
-
-/*
- ***********************************************************************
- ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
- **                                                                   **
- ** License to copy and use this software is granted provided that    **
- ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
- ** Digest Algorithm" in all material mentioning or referencing this  **
- ** software or this function.                                        **
- **                                                                   **
- ** License is also granted to make and use derivative works          **
- ** provided that such works are identified as "derived from the RSA  **
- ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
- ** material mentioning or referencing the derived work.              **
- **                                                                   **
- ** RSA Data Security, Inc. makes no representations concerning       **
- ** either the merchantability of this software or the suitability    **
- ** of this software for any particular purpose.  It is provided "as  **
- ** is" without express or implied warranty of any kind.              **
- **                                                                   **
- ** These notices must be retained in any copies of any part of this  **
- ** documentation and/or software.                                    **
- ***********************************************************************
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-#include "md5.h"
-
-/*
- ***********************************************************************
- **  Message-digest routines:                                         **
- **  To form the message digest for a message M                       **
- **    (1) Initialize a context buffer mdContext using MD5_Init       **
- **    (2) Call MD5_Update on mdContext and M                         **
- **    (3) Call MD5_Final on mdContext                                **
- **  The message digest is now in mdContext->digest[0...15]           **
- ***********************************************************************
- */
-
-/* forward declaration */
-static void Transform (UINT4 *buf, UINT4 *in);
-
-static unsigned char PADDING[64] = {
-  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-/* F, G, H and I are basic MD5 functions */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define I(x, y, z) ((y) ^ ((x) | (~z)))
-
-/* ROTATE_LEFT rotates x left n bits */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
-
-/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
-/* Rotation is separate from addition to prevent recomputation */
-#define FF(a, b, c, d, x, s, ac) \
-  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
-   (a) = ROTATE_LEFT ((a), (s)); \
-   (a) += (b); \
-  }
-#define GG(a, b, c, d, x, s, ac) \
-  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
-   (a) = ROTATE_LEFT ((a), (s)); \
-   (a) += (b); \
-  }
-#define HH(a, b, c, d, x, s, ac) \
-  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
-   (a) = ROTATE_LEFT ((a), (s)); \
-   (a) += (b); \
-  }
-#define II(a, b, c, d, x, s, ac) \
-  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
-   (a) = ROTATE_LEFT ((a), (s)); \
-   (a) += (b); \
-  }
-
-#ifdef __STDC__
-#define UL(x)  x##U
-#else
-#define UL(x)  x
-#endif
-
-/* The routine MD5_Init initializes the message-digest context
-   mdContext. All fields are set to zero.
- */
-void MD5_Init (MD5_CTX *mdContext)
-{
-  mdContext->i[0] = mdContext->i[1] = (UINT4)0;
-
-  /* Load magic initialization constants.
-   */
-  mdContext->buf[0] = (UINT4)0x67452301;
-  mdContext->buf[1] = (UINT4)0xefcdab89;
-  mdContext->buf[2] = (UINT4)0x98badcfe;
-  mdContext->buf[3] = (UINT4)0x10325476;
-}
-
-/* The routine MD5Update updates the message-digest context to
-   account for the presence of each of the characters inBuf[0..inLen-1]
-   in the message whose digest is being computed.
- */
-void MD5_Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
-{
-  UINT4 in[16];
-  int mdi;
-  unsigned int i, ii;
-
-  /* compute number of bytes mod 64 */
-  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
-
-  /* update number of bits */
-  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
-    mdContext->i[1]++;
-  mdContext->i[0] += ((UINT4)inLen << 3);
-  mdContext->i[1] += ((UINT4)inLen >> 29);
-
-  while (inLen--) {
-    /* add new character to buffer, increment mdi */
-    mdContext->in[mdi++] = *inBuf++;
-
-    /* transform if necessary */
-    if (mdi == 0x40) {
-      for (i = 0, ii = 0; i < 16; i++, ii += 4)
-        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
-                (((UINT4)mdContext->in[ii+2]) << 16) |
-                (((UINT4)mdContext->in[ii+1]) << 8) |
-                ((UINT4)mdContext->in[ii]);
-      Transform (mdContext->buf, in);
-      mdi = 0;
-    }
-  }
-}
-
-/* The routine MD5Final terminates the message-digest computation and
-   ends with the desired message digest in mdContext->digest[0...15].
- */
-void MD5_Final (unsigned char hash[], MD5_CTX *mdContext)
-{
-  UINT4 in[16];
-  int mdi;
-  unsigned int i, ii;
-  unsigned int padLen;
-
-  /* save number of bits */
-  in[14] = mdContext->i[0];
-  in[15] = mdContext->i[1];
-
-  /* compute number of bytes mod 64 */
-  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
-
-  /* pad out to 56 mod 64 */
-  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
-  MD5_Update (mdContext, PADDING, padLen);
-
-  /* append length in bits and transform */
-  for (i = 0, ii = 0; i < 14; i++, ii += 4)
-    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
-            (((UINT4)mdContext->in[ii+2]) << 16) |
-            (((UINT4)mdContext->in[ii+1]) << 8) |
-            ((UINT4)mdContext->in[ii]);
-  Transform (mdContext->buf, in);
-
-  /* store buffer in digest */
-  for (i = 0, ii = 0; i < 4; i++, ii += 4) {
-    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
-    mdContext->digest[ii+1] =
-      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
-    mdContext->digest[ii+2] =
-      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
-    mdContext->digest[ii+3] =
-      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
-  }
-  memcpy(hash, mdContext->digest, 16);
-}
-
-/* Basic MD5 step. Transforms buf based on in.
- */
-static void Transform (UINT4 *buf, UINT4 *in)
-{
-  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
-
-  /* Round 1 */
-#define S11 7
-#define S12 12
-#define S13 17
-#define S14 22
-  FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
-  FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
-  FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
-  FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
-  FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
-  FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
-  FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
-  FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
-  FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
-  FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
-  FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
-  FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
-  FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
-  FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
-  FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
-  FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
-
-  /* Round 2 */
-#define S21 5
-#define S22 9
-#define S23 14
-#define S24 20
-  GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
-  GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
-  GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
-  GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
-  GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
-  GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */
-  GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
-  GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
-  GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
-  GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
-  GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
-  GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
-  GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
-  GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
-  GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
-  GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
-
-  /* Round 3 */
-#define S31 4
-#define S32 11
-#define S33 16
-#define S34 23
-  HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
-  HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
-  HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
-  HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
-  HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
-  HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
-  HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
-  HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
-  HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
-  HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
-  HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
-  HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */
-  HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
-  HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
-  HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
-  HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
-
-  /* Round 4 */
-#define S41 6
-#define S42 10
-#define S43 15
-#define S44 21
-  II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
-  II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
-  II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
-  II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
-  II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
-  II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
-  II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
-  II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
-  II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
-  II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
-  II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
-  II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
-  II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
-  II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
-  II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
-  II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
-
-  buf[0] += a;
-  buf[1] += b;
-  buf[2] += c;
-  buf[3] += d;
-}
-
-/*
- ***********************************************************************
- ** End of md5.c                                                      **
- ******************************** (cut) ********************************
- */
diff --git a/pppd/md5.h b/pppd/md5.h
deleted file mode 100644 (file)
index 31f410d..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- ***********************************************************************
- ** md5.h -- header file for implementation of MD5                    **
- ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
- ** Created: 2/17/90 RLR                                              **
- ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version               **
- ** Revised (for MD5): RLR 4/27/91                                    **
- **   -- G modified to have y&~z instead of y&z                       **
- **   -- FF, GG, HH modified to add in last register done             **
- **   -- Access pattern: round 2 works mod 5, round 3 works mod 3     **
- **   -- distinct additive constant for each step                     **
- **   -- round 4 added, working mod 7                                 **
- ***********************************************************************
- */
-
-/*
- ***********************************************************************
- ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
- **                                                                   **
- ** License to copy and use this software is granted provided that    **
- ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
- ** Digest Algorithm" in all material mentioning or referencing this  **
- ** software or this function.                                        **
- **                                                                   **
- ** License is also granted to make and use derivative works          **
- ** provided that such works are identified as "derived from the RSA  **
- ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
- ** material mentioning or referencing the derived work.              **
- **                                                                   **
- ** RSA Data Security, Inc. makes no representations concerning       **
- ** either the merchantability of this software or the suitability    **
- ** of this software for any particular purpose.  It is provided "as  **
- ** is" without express or implied warranty of any kind.              **
- **                                                                   **
- ** These notices must be retained in any copies of any part of this  **
- ** documentation and/or software.                                    **
- ***********************************************************************
- */
-#ifndef PPP_MD5_H
-#define PPP_MD5_H
-
-#include "pppdconf.h"
-
-#ifndef USE_MD5
-#include <openssl/md5.h>
-#else
-
-/* typedef a 32-bit type */
-#ifdef _LP64
-typedef unsigned int UINT4;
-typedef int          INT4;
-#else
-typedef unsigned long UINT4;
-typedef long          INT4;
-#endif
-#define _UINT4_T
-
-/* Data structure for MD5 (Message-Digest) computation */
-typedef struct {
-  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */
-  UINT4 buf[4];                                    /* scratch buffer */
-  unsigned char in[64];                              /* input buffer */
-  unsigned char digest[16];     /* actual digest after MD5Final call */
-} MD5_CTX;
-
-void MD5_Init (MD5_CTX *mdContext);
-void MD5_Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen);
-void MD5_Final (unsigned char hash[], MD5_CTX *mdContext);
-
-#endif /* USE_MD5 */
-#endif /* PPP_MD5_H */
index f1b7abf0ab206b8f7fd31a78c2d23557c84d2245..880b2784cb09c9227210a25426dd67ec4ef28716 100644 (file)
@@ -1,7 +1,7 @@
-/* mppe.c - MPPE key implementation
+/* mppe.c - MPPE key implementation
  *
  * Copyright (c) 2020 Eivind Naess. All rights reserved.
- * Copyright (c) 2008 Paul Mackerras. All rights reserved.
+ * Copyright (c) 2008-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,6 @@
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
  */
 
 #ifdef HAVE_CONFIG_H
 #include <string.h>
 
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
-#include "md4.h"
-#include "sha1.h"
 #include "ccp.h"
 #include "chap_ms.h"
 #include "mppe.h"
+#include "crypto.h"
 
 u_char mppe_send_key[MPPE_MAX_KEY_SIZE];
 u_char mppe_recv_key[MPPE_MAX_KEY_SIZE];
@@ -111,16 +109,33 @@ mppe_clear_keys(void)
  * RFC 2548 (RADIUS support) requires us to export this function (ugh).
  */
 void
-mppe_set_chapv1(u_char *rchallenge, u_char PasswordHashHash[MD4_SIGNATURE_SIZE])
+mppe_set_chapv1(unsigned char *rchallenge, unsigned char *PasswordHashHash)
 {
-    SHA1_CTX   sha1Context;
-    u_char     Digest[SHA1_SIGNATURE_SIZE];
+    PPP_MD_CTX *ctx;
+    u_char Digest[SHA_DIGEST_LENGTH];
+    int DigestLen;
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, PasswordHashHash, MD4_DIGEST_LENGTH)) {
+
+                if (PPP_DigestUpdate(ctx, PasswordHashHash, MD4_DIGEST_LENGTH)) {
+
+                    if (PPP_DigestUpdate(ctx, rchallenge, 8)) {
+                        
+                        DigestLen = SHA_DIGEST_LENGTH;
+                        PPP_DigestFinal(ctx, Digest, &DigestLen);
+                    }
+                }
+            }
+        }
+        
+        PPP_MD_CTX_free(ctx);
+    }
 
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
-    SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
-    SHA1_Update(&sha1Context, rchallenge, 8);
-    SHA1_Final(Digest, &sha1Context);
 
     /* Same key in both directions. */
     mppe_set_keys(Digest, Digest, sizeof(Digest));
@@ -133,13 +148,15 @@ mppe_set_chapv1(u_char *rchallenge, u_char PasswordHashHash[MD4_SIGNATURE_SIZE])
  * NTHashHash from the server.
  */
 void
-mppe_set_chapv2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
-              u_char NTResponse[MS_AUTH_NTRESP_LEN], int IsServer)
+mppe_set_chapv2(unsigned char *PasswordHashHash, unsigned char *NTResponse,
+        int IsServer)
 {
-    SHA1_CTX   sha1Context;
-    u_char     MasterKey[SHA1_SIGNATURE_SIZE];
-    u_char     SendKey[SHA1_SIGNATURE_SIZE];
-    u_char     RecvKey[SHA1_SIGNATURE_SIZE];
+    PPP_MD_CTX *ctx;
+    
+    u_char     MasterKey[SHA_DIGEST_LENGTH];
+    u_char     SendKey[SHA_DIGEST_LENGTH];
+    u_char     RecvKey[SHA_DIGEST_LENGTH];
+    int KeyLen;
 
     u_char SHApad1[40] =
        { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -183,11 +200,26 @@ mppe_set_chapv2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
          0x6b, 0x65, 0x79, 0x2e };
     u_char *s;
 
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE);
-    SHA1_Update(&sha1Context, NTResponse, 24);
-    SHA1_Update(&sha1Context, Magic1, sizeof(Magic1));
-    SHA1_Final(MasterKey, &sha1Context);
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, PasswordHashHash, MD4_DIGEST_LENGTH)) {
+
+                if (PPP_DigestUpdate(ctx, NTResponse, 24)) {
+
+                    if (PPP_DigestUpdate(ctx, Magic1, sizeof(Magic1))) {
+                        
+                        KeyLen = SHA_DIGEST_LENGTH;
+                        PPP_DigestFinal(ctx, MasterKey, &KeyLen);
+                    }
+                }
+            }
+        }
+        
+        PPP_MD_CTX_free(ctx);
+    }
 
     /*
      * generate send key
@@ -196,12 +228,31 @@ mppe_set_chapv2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
        s = Magic3;
     else
        s = Magic2;
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, MasterKey, 16);
-    SHA1_Update(&sha1Context, SHApad1, sizeof(SHApad1));
-    SHA1_Update(&sha1Context, s, 84);
-    SHA1_Update(&sha1Context, SHApad2, sizeof(SHApad2));
-    SHA1_Final(SendKey, &sha1Context);
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, MasterKey, 16)) {
+
+                if (PPP_DigestUpdate(ctx, SHApad1, sizeof(SHApad1))) {
+
+                    if (PPP_DigestUpdate(ctx, s, 84)) {
+
+                        if (PPP_DigestUpdate(ctx, SHApad2, sizeof(SHApad2))) {
+                        
+                            KeyLen = SHA_DIGEST_LENGTH;
+                            PPP_DigestFinal(ctx, SendKey, &KeyLen);
+                        }
+                    }
+                }
+            }
+        }
+        
+        PPP_MD_CTX_free(ctx);
+    }
+
 
     /*
      * generate recv key
@@ -210,14 +261,32 @@ mppe_set_chapv2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
        s = Magic2;
     else
        s = Magic3;
-    SHA1_Init(&sha1Context);
-    SHA1_Update(&sha1Context, MasterKey, 16);
-    SHA1_Update(&sha1Context, SHApad1, sizeof(SHApad1));
-    SHA1_Update(&sha1Context, s, 84);
-    SHA1_Update(&sha1Context, SHApad2, sizeof(SHApad2));
-    SHA1_Final(RecvKey, &sha1Context);
-
-    mppe_set_keys(SendKey, RecvKey, SHA1_SIGNATURE_SIZE);
+
+    ctx = PPP_MD_CTX_new();
+    if (ctx != NULL) {
+
+        if (PPP_DigestInit(ctx, PPP_sha1())) {
+
+            if (PPP_DigestUpdate(ctx, MasterKey, 16)) {
+
+                if (PPP_DigestUpdate(ctx, SHApad1, sizeof(SHApad1))) {
+
+                    if (PPP_DigestUpdate(ctx, s, 84)) {
+
+                        if (PPP_DigestUpdate(ctx, SHApad2, sizeof(SHApad2))) {
+                        
+                            KeyLen = SHA_DIGEST_LENGTH;
+                            PPP_DigestFinal(ctx, RecvKey, &KeyLen);
+                        }
+                    }
+                }
+            }
+        }
+        
+        PPP_MD_CTX_free(ctx);
+    }
+
+    mppe_set_keys(SendKey, RecvKey, SHA_DIGEST_LENGTH);
 }
 
 #ifndef UNIT_TEST
index ade208f1d4b784ed2211cefb4c69cfcf0c3c14f1..8ff27b974741bb634c9c7542eda9697826bdfe7d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * mppe.h - Definitions for MPPE
  *
- * Copyright (c) 2008 Paul Mackerras. All rights reserved.
+ * Copyright (c) 2008-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 #define MPPE_PAD               4       /* MPPE growth per frame */
 #define MPPE_MAX_KEY_SIZE      32      /* Largest key length */
 #define MPPE_MAX_KEY_LEN       16      /* Largest key size accepted by the kernel */
@@ -72,7 +68,7 @@
 /* Build a CI from mppe opts (see RFC 3078) */
 #define MPPE_OPTS_TO_CI(opts, ci)              \
     do {                                       \
-       u_char *ptr = ci; /* u_char[4] */       \
+       unsigned char *ptr = ci; /* unsigned char[4] */ \
                                                \
        /* H bit */                             \
        if (opts & MPPE_OPT_STATEFUL)           \
@@ -94,7 +90,7 @@
 /* The reverse of the above */
 #define MPPE_CI_TO_OPTS(ci, opts)              \
     do {                                       \
-       u_char *ptr = ci; /* u_char[4] */       \
+       unsigned char *ptr = ci; /* unsigned char[4] */ \
                                                \
        opts = 0;                               \
                                                \
 
 #if PPP_WITH_MPPE
 
-/*
- * NOTE:
- *   Access to these variables directly is discuraged. Please
- *   change your code to use below accessor functions.
- */
-
-/* The key material generated which is used for MPPE send key */
-extern u_char mppe_send_key[MPPE_MAX_KEY_SIZE];
-/* The key material generated which is used for MPPE recv key */
-extern u_char mppe_recv_key[MPPE_MAX_KEY_SIZE];
-/* Keys are set if value is non-zero */
-extern int mppe_keys_set;
-
 /* These values are the RADIUS attribute values--see RFC 2548. */
 #define MPPE_ENC_POL_ENC_ALLOWED 1
 #define MPPE_ENC_POL_ENC_REQUIRED 2
@@ -154,17 +137,17 @@ void mppe_set_enc_types (int policy, int types);
  * Set the MPPE send and recv keys. NULL values for keys are ignored
  *   and input values are cleared to avoid leaving them on the stack
  */
-void mppe_set_keys(u_char *send_key, u_char *recv_key, int keylen);
+void mppe_set_keys(unsigned char *send_key, unsigned char *recv_key, int keylen);
 
 /*
  * Get the MPPE recv key
  */
-int mppe_get_recv_key(u_char *recv_key, int length);
+int mppe_get_recv_key(unsigned char *recv_key, int length);
 
 /*
  * Get the MPPE send key
  */
-int mppe_get_send_key(u_char *send_key, int length);
+int mppe_get_send_key(unsigned char *send_key, int length);
 
 /*
  * Clear the MPPE keys
@@ -179,13 +162,18 @@ bool mppe_keys_isset(void);
 /*
  * Set mppe_xxxx_key from NT Password Hash Hash (MSCHAPv1), see RFC3079
  */
-void mppe_set_chapv1(u_char *rchallenge, u_char PasswordHashHash[MD4_SIGNATURE_SIZE]);
+void mppe_set_chapv1(unsigned char *rchallenge, unsigned char *PasswordHashHash);
 
 /*
  * Set the mppe_xxxx_key from MS-CHAP-v2 credentials, see RFC3079
  */
-void mppe_set_chapv2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE],
-                   u_char NTResponse[MS_AUTH_NTRESP_LEN], int IsServer);
+void mppe_set_chapv2(unsigned char *PasswordHashHash,
+                   unsigned char *NTResponse, int IsServer);
 
 #endif  // #ifdef PPP_WITH_MPPE
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif  // #ifdef PPP_MPPE_H
index 6f17cf87eeb10df66e68430cab87b476c1bf6c25..d5423da570531fc7c9265ab9d8cf2e3cecb99c93 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * multilink.c - support routines for multilink.
  *
- * Copyright (c) 2000-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 2000-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 #include <netinet/in.h>
 #include <unistd.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "tdb.h"
+#include "multilink.h"
 
 bool endpoint_specified;       /* user gave explicit endpoint discriminator */
 char *bundle_id;               /* identifier for our bundle */
@@ -78,6 +75,18 @@ static int owns_unit(TDB_DATA pid, int unit);
 
 #define process_exists(n)      (kill((n), 0) == 0 || errno != ESRCH)
 
+multilink_join_hook_fn *multilink_join_hook = NULL;
+
+bool mp_master()
+{
+    return multilink_master;
+}
+
+bool mp_on()
+{
+    return doing_multilink;
+}
+
 void
 mp_check_options(void)
 {
@@ -139,12 +148,12 @@ mp_join_bundle(void)
                if (demand) {
                        /* already have a bundle */
                        cfg_bundle(0, 0, 0, 0);
-                       netif_set_mtu(0, mtu);
+                       ppp_set_mtu(0, mtu);
                        return 0;
                }
                make_new_bundle(0, 0, 0, 0);
                set_ifunit(1);
-               netif_set_mtu(0, mtu);
+               ppp_set_mtu(0, mtu);
                return 0;
        }
 
@@ -189,8 +198,8 @@ mp_join_bundle(void)
        mtu = MIN(ho->mrru, ao->mru);
        if (demand) {
                cfg_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf);
-               netif_set_mtu(0, mtu);
-               script_setenv("BUNDLE", bundle_id + 7, 1);
+               ppp_set_mtu(0, mtu);
+               ppp_script_setenv("BUNDLE", bundle_id + 7, 1);
                return 0;
        }
 
@@ -224,7 +233,7 @@ mp_join_bundle(void)
                /* attach to existing unit */
                if (bundle_attach(unit)) {
                        set_ifunit(0);
-                       script_setenv("BUNDLE", bundle_id + 7, 0);
+                       ppp_script_setenv("BUNDLE", bundle_id + 7, 0);
                        make_bundle_links(1);
                        unlock_db();
                        info("Link attached to %s", ifname);
@@ -236,8 +245,8 @@ mp_join_bundle(void)
        /* we have to make a new bundle */
        make_new_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf);
        set_ifunit(1);
-       netif_set_mtu(0, mtu);
-       script_setenv("BUNDLE", bundle_id + 7, 1);
+       ppp_set_mtu(0, mtu);
+       ppp_script_setenv("BUNDLE", bundle_id + 7, 1);
        make_bundle_links(0);
        unlock_db();
        info("New bundle %s created", ifname);
@@ -273,7 +282,7 @@ void mp_bundle_terminated(void)
        print_link_stats();
        if (!demand) {
                remove_pidfiles();
-               script_unsetenv("IFNAME");
+               ppp_script_unsetenv("IFNAME");
        }
 
        lock_db();
@@ -449,7 +458,7 @@ get_default_epdisc(struct epdisc *ep)
        hp = gethostbyname(hostname);
        if (hp != NULL) {
                addr = *(u_int32_t *)hp->h_addr;
-               if (!bad_ip_adrs(addr)) {
+               if (!ppp_bad_ip_addr(addr)) {
                        addr = ntohl(addr);
                        if (!LOCAL_IP_ADDR(addr)) {
                                ep->class = EPD_IP;
diff --git a/pppd/multilink.h b/pppd/multilink.h
new file mode 100644 (file)
index 0000000..07ea4b2
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * multilink.h - support routines for multilink.
+ *
+ * Copyright (c) 2000-2024 Paul Mackerras. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef PPP_MULTILINK_H
+#define PPP_MULTILINK_H
+
+#include "pppdconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * values for epdisc.class
+ */
+#define EPD_NULL        0      /* null discriminator, no data */
+#define EPD_LOCAL       1
+#define EPD_IP          2
+#define EPD_MAC         3
+#define EPD_MAGIC       4
+#define EPD_PHONENUM    5
+
+struct epdisc;
+
+#ifdef PPP_WITH_MULTILINK
+
+/*
+ * Check multilink-related options
+ */
+void mp_check_options(void);
+
+/*
+ * Join our link to an appropriate bundle
+ */
+int mp_join_bundle(void);
+
+/*
+ * Disconnected our link from the bundle
+ */
+void mp_exit_bundle(void);
+
+/*
+ * Multipoint bundle terminated
+ */
+void mp_bundle_terminated(void);
+
+/*
+ * Acting as a multilink master
+ */
+bool mp_master();
+
+/*
+ * Was multilink negotiated
+ */
+bool mp_on();
+
+/*
+ * Convert an endpoint discriminator to a string
+ */
+char *epdisc_to_str(struct epdisc *);
+
+/*
+ * Convert a string to an endpoint discriminator
+ */
+int str_to_epdisc(struct epdisc *, char *);
+
+/*
+ * Hook for plugin to hear when an interface joins a multilink bundle
+ */
+typedef void (multilink_join_hook_fn)(void);
+extern multilink_join_hook_fn *multilink_join_hook;
+
+#else
+
+#define mp_check_options(x)     ((void)0)
+#define mp_join_bundle(x)       ((void)0)
+#define mp_exit_bundle(x)       ((void)0)
+#define mp_bundle_terminated(x) ((void)0)
+
+static inline bool mp_on() {
+    return false;
+}
+
+static inline bool mp_master() {
+    return false;
+}
+
+#endif // PPP_WITH_MULTILINK
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PPP_MULTILINK_H
index 1fbe46e642c316b28096f557f5ed5dc83cae0551..879223d16ee9b0387dfa7568df396e5e3833857d 100644 (file)
@@ -77,7 +77,9 @@
 #endif
 #endif /* PPP_WITH_FILTER */
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
+#include "upap.h"
 #include "pathnames.h"
 
 #if defined(ultrix) || defined(NeXT)
@@ -97,7 +99,6 @@ struct option_value {
 int    debug = 0;              /* Debug flag */
 int    kdebugflag = 0;         /* Tell kernel to print debug messages */
 int    default_device = 1;     /* Using /dev/tty or equivalent */
-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 */
@@ -110,7 +111,6 @@ char        passwd[MAXSECRETLEN];   /* Password for PAP */
 bool   persist = 0;            /* Reopen link after it goes down */
 char   our_name[MAXNAMELEN];   /* Our name for authentication purposes */
 bool   demand = 0;             /* do dial-on-demand */
-char   *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
 int    idle_time_limit = 0;    /* Disconnect if idle for this many seconds */
 int    holdoff = 30;           /* # seconds to pause before reconnecting */
 bool   holdoff_specified;      /* true if a holdoff value has been given */
@@ -121,12 +121,17 @@ char      linkname[MAXPATHLEN];   /* logical name for link */
 bool   tune_kernel;            /* may alter kernel settings */
 int    connect_delay = 1000;   /* wait this many ms after connect script */
 int    req_unit = -1;          /* requested interface unit */
+char   path_net_init[MAXPATHLEN]; /* pathname of net-init script */
+char   path_net_preup[MAXPATHLEN];/* pathname of net-pre-up script */
+char   path_net_down[MAXPATHLEN]; /* pathname of net-down script */
 char   path_ipup[MAXPATHLEN];  /* pathname of ip-up script */
 char   path_ipdown[MAXPATHLEN];/* pathname of ip-down script */
+char   path_ippreup[MAXPATHLEN]; /* pathname of ip-pre-up script */
 char   req_ifname[IFNAMSIZ];   /* requested interface name */
 bool   multilink = 0;          /* Enable multilink operation */
 char   *bundle_name = NULL;    /* bundle name for multilink */
 bool   dump_options;           /* print out option values */
+bool   show_options;           /* print all supported options and exit */
 bool   dryrun;                 /* print out option values and exit */
 char   *domain;                /* domain name set by domain option */
 int    child_wait = 5;         /* # seconds to wait for children at exit */
@@ -139,11 +144,11 @@ char      path_ipv6down[MAXPATHLEN]; /* pathname of ipv6-down script */
 #endif
 
 unsigned int  maxoctets = 0;    /* default - no limit */
-int maxoctets_dir = 0;       /* default - sum of traffic */
+session_limit_dir_t maxoctets_dir = PPP_OCTETS_DIRECTION_SUM; /* default - sum of traffic */
 int maxoctets_timeout = 1;   /* default 1 second */ 
 
 
-extern option_t auth_options[];
+extern struct option auth_options[];
 extern struct stat devstat;
 
 #ifdef PPP_WITH_FILTER
@@ -151,7 +156,7 @@ struct      bpf_program pass_filter;/* Filter program for packets to pass */
 struct bpf_program active_filter; /* Filter program for link-active pkts */
 #endif
 
-static option_t *curopt;       /* pointer to option being processed */
+static struct option *curopt;  /* pointer to option being processed */
 char *current_option;          /* the name of the option being parsed */
 int  privileged_option;                /* set iff the current option came from root */
 char *option_source;           /* string saying where the option came from */
@@ -185,20 +190,20 @@ static int setactivefilter(char **);
 static int setmodir(char **);
 
 static int user_setenv(char **);
-static void user_setprint(option_t *, printer_func, void *);
+static void user_setprint(struct option *, printer_func, void *);
 static int user_unsetenv(char **);
-static void user_unsetprint(option_t *, printer_func, void *);
+static void user_unsetprint(struct option *, printer_func, void *);
 
-static option_t *find_option(char *name);
-static int process_option(option_t *, char *, char **);
-static int n_arguments(option_t *);
+static struct option *find_option(char *name);
+static int process_option(struct option *, char *, char **);
+static int n_arguments(struct option *);
 static int number_option(char *, u_int32_t *, int);
 
 /*
  * Structure to store extra lists of options.
  */
 struct option_list {
-    option_t *options;
+    struct option *options;
     struct option_list *next;
 };
 
@@ -207,7 +212,7 @@ static struct option_list *extra_options = NULL;
 /*
  * Valid arguments.
  */
-option_t general_options[] = {
+struct option general_options[] = {
     { "debug", o_int, &debug,
       "Increase debugging level", OPT_INC | OPT_NOARG | 1 },
     { "-d", o_int, &debug,
@@ -263,6 +268,10 @@ option_t general_options[] = {
 
     { "--version", o_special_noarg, (void *)showversion,
       "Show version number" },
+    { "-v", o_special_noarg, (void *)showversion,
+      "Show version number" },
+    { "show-options", o_bool, &show_options,
+      "Show all options and exit", 1 },
     { "--help", o_special_noarg, (void *)showhelp,
       "Show brief listing of options" },
     { "-h", o_special_noarg, (void *)showhelp,
@@ -326,12 +335,25 @@ option_t general_options[] = {
       "Metric to use for the default route (Linux only; -1 for default behavior)",
       OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 },
 
+    { "net-init-script", o_string, path_net_init,
+      "Set pathname of net-init script",
+      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
+    { "net-pre-up-script", o_string, path_net_preup,
+      "Set pathname of net-preup script",
+      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
+    { "net-down-script", o_string, path_net_down,
+      "Set pathname of net-down script",
+      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
+
     { "ip-up-script", o_string, path_ipup,
       "Set pathname of ip-up script",
       OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
     { "ip-down-script", o_string, path_ipdown,
       "Set pathname of ip-down script",
       OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
+    { "ip-pre-up-script", o_string, path_ippreup,
+      "Set pathname of ip-pre-up script",
+      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
 
 #ifdef PPP_WITH_IPV6CP
     { "ipv6-up-script", o_string, path_ipv6up,
@@ -390,23 +412,108 @@ option_t general_options[] = {
 #define IMPLEMENTATION ""
 #endif
 
-static char *usage_string = "\
-pppd version %s\n\
-Usage: %s [ options ], where options are:\n\
-       <device>        Communicate over the named device\n\
-       <speed>         Set the baud rate to <speed>\n\
-       <loc>:<rem>     Set the local and/or remote interface IP\n\
-                       addresses.  Either one may be omitted.\n\
-       asyncmap <n>    Set the desired async map to hex <n>\n\
-       auth            Require authentication from peer\n\
-        connect <p>     Invoke shell command <p> to set up the serial line\n\
-       crtscts         Use hardware RTS/CTS flow control\n\
-       defaultroute    Add default route through interface\n\
-       file <f>        Take options from file <f>\n\
-       modem           Use modem control lines\n\
-       mru <n>         Set MRU value to <n> for negotiation\n\
-See pppd(8) for more options.\n\
-";
+int
+ppp_get_max_idle_time()
+{
+    return idle_time_limit;
+}
+
+void
+ppp_set_max_idle_time(unsigned int max)
+{
+    idle_time_limit = max;
+}
+
+int
+ppp_get_max_connect_time()
+{
+    return maxconnect;
+}
+
+void
+ppp_set_max_connect_time(unsigned int max)
+{
+    maxconnect = max;
+}
+
+void
+ppp_set_session_limit(unsigned int octets)
+{
+    maxoctets = octets;
+}
+
+void
+ppp_set_session_limit_dir(unsigned int dir)
+{
+    if (dir > 4)
+        dir = PPP_OCTETS_DIRECTION_SUM;
+    maxoctets_dir = (session_limit_dir_t) dir;
+}
+
+bool
+debug_on()
+{
+    return !!debug;
+}
+
+int
+ppp_get_path(ppp_path_t type, char *buf, size_t bufsz)
+{
+    const char *path;
+
+    if (buf && bufsz > 0) {
+        switch (type) {
+        case PPP_DIR_LOG:
+            path = PPP_PATH_VARLOG;
+            break;
+        case PPP_DIR_RUNTIME:
+            path = PPP_PATH_VARRUN;
+            break;
+#ifdef PPP_WITH_PLUGINS
+        case PPP_DIR_PLUGIN:
+            path = PPP_PATH_PLUGIN;
+            break;
+#endif
+        case PPP_DIR_CONF:
+            path = PPP_PATH_CONFDIR;
+            break;
+        }
+        return strlcpy(buf, path, bufsz);
+    }
+    return -1;
+}
+
+int
+ppp_get_filepath(ppp_path_t type, const char *name, char *buf, size_t bufsz)
+{
+    const char *path;
+
+    if (buf && bufsz > 0) {
+        switch (type) {
+        case PPP_DIR_LOG:
+            path = PPP_PATH_VARLOG;
+            break;
+        case PPP_DIR_RUNTIME:
+            path = PPP_PATH_VARRUN;
+            break;
+#ifdef PPP_WITH_PLUGINS
+        case PPP_DIR_PLUGIN:
+            path = PPP_PATH_PLUGIN;
+            break;
+#endif
+       case PPP_DIR_CONF:
+            path = PPP_PATH_CONFDIR;
+            break;
+        }
+        return slprintf(buf, bufsz, "%s/%s", path, name);
+    }
+    return -1;
+}
+
+bool ppp_persist()
+{
+    return !!persist;
+}
 
 /*
  * parse_args - parse a string of arguments from the command line.
@@ -415,7 +522,7 @@ int
 parse_args(int argc, char **argv)
 {
     char *arg;
-    option_t *opt;
+    struct option *opt;
     int n;
 
     privileged_option = privileged;
@@ -426,13 +533,13 @@ parse_args(int argc, char **argv)
        --argc;
        opt = find_option(arg);
        if (opt == NULL) {
-           option_error("unrecognized option '%s'", arg);
+           ppp_option_error("unrecognized option '%s'", arg);
            usage();
            return 0;
        }
        n = n_arguments(opt);
        if (argc < n) {
-           option_error("too few parameters for option %s", arg);
+           ppp_option_error("too few parameters for option %s", arg);
            return 0;
        }
        if (!process_option(opt, arg, argv))
@@ -448,11 +555,11 @@ parse_args(int argc, char **argv)
  * and interpret them.
  */
 int
-options_from_file(char *filename, int must_exist, int check_prot, int priv)
+ppp_options_from_file(char *filename, int must_exist, int check_prot, int priv)
 {
     FILE *f;
     int i, newline, ret, err;
-    option_t *opt;
+    struct option *opt;
     int oldpriv, n;
     char *oldsource;
     uid_t euid;
@@ -462,7 +569,7 @@ options_from_file(char *filename, int must_exist, int check_prot, int priv)
 
     euid = geteuid();
     if (check_prot && seteuid(getuid()) == -1) {
-       option_error("unable to drop privileges to open %s: %m", filename);
+       ppp_option_error("unable to drop privileges to open %s: %m", filename);
        return 0;
     }
     f = fopen(filename, "r");
@@ -476,7 +583,7 @@ options_from_file(char *filename, int must_exist, int check_prot, int priv)
                warn("Warning: can't open options file %s: %m", filename);
            return 1;
        }
-       option_error("Can't open options file %s: %m", filename);
+       ppp_option_error("Can't open options file %s: %m", filename);
        return 0;
     }
 
@@ -490,14 +597,14 @@ options_from_file(char *filename, int must_exist, int check_prot, int priv)
     while (getword(f, cmd, &newline, filename)) {
        opt = find_option(cmd);
        if (opt == NULL) {
-           option_error("In file %s: unrecognized option '%s'",
+           ppp_option_error("In file %s: unrecognized option '%s'",
                         filename, cmd);
            goto err;
        }
        n = n_arguments(opt);
        for (i = 0; i < n; ++i) {
            if (!getword(f, args[i], &newline, filename)) {
-               option_error(
+               ppp_option_error(
                        "In file %s: too few parameters for option '%s'",
                        filename, cmd);
                goto err;
@@ -511,6 +618,7 @@ options_from_file(char *filename, int must_exist, int check_prot, int priv)
 
 err:
     fclose(f);
+    free(option_source);
     privileged_option = oldpriv;
     option_source = oldsource;
     return ret;
@@ -531,14 +639,14 @@ options_from_user(void)
     pw = getpwuid(getuid());
     if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
        return 1;
-    file = _PATH_USEROPT;
+    file = PPP_PATH_USEROPT;
     pl = strlen(user) + strlen(file) + 2;
     path = malloc(pl);
     if (path == NULL)
        novm("init file name");
     slprintf(path, pl, "%s/%s", user, file);
     option_priority = OPRIO_CFGFILE;
-    ret = options_from_file(path, 0, 1, privileged);
+    ret = ppp_options_from_file(path, 0, 1, privileged);
     free(path);
     return ret;
 }
@@ -563,17 +671,17 @@ options_for_tty(void)
        dev = p + 5;
     if (dev[0] == 0 || strcmp(dev, "tty") == 0)
        return 1;               /* don't look for /etc/ppp/options.tty */
-    pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
+    pl = strlen(PPP_PATH_TTYOPT) + strlen(dev) + 1;
     path = malloc(pl);
     if (path == NULL)
        novm("tty init file name");
-    slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
+    slprintf(path, pl, "%s%s", PPP_PATH_TTYOPT, dev);
     /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
-    for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
+    for (p = path + strlen(PPP_PATH_TTYOPT); *p != 0; ++p)
        if (*p == '/')
            *p = '.';
     option_priority = OPRIO_CFGFILE;
-    ret = options_from_file(path, 0, 0, 1);
+    ret = ppp_options_from_file(path, 0, 0, 1);
     free(path);
     return ret;
 }
@@ -585,7 +693,7 @@ int
 options_from_list(struct wordlist *w, int priv)
 {
     char *argv[MAXARGS];
-    option_t *opt;
+    struct option *opt;
     int i, n, ret = 0;
     struct wordlist *w0;
 
@@ -596,7 +704,7 @@ options_from_list(struct wordlist *w, int priv)
     while (w != NULL) {
        opt = find_option(w->word);
        if (opt == NULL) {
-           option_error("In secrets file: unrecognized option '%s'",
+           ppp_option_error("In secrets file: unrecognized option '%s'",
                         w->word);
            goto err;
        }
@@ -605,7 +713,7 @@ options_from_list(struct wordlist *w, int priv)
        for (i = 0; i < n; ++i) {
            w = w->next;
            if (w == NULL) {
-               option_error(
+               ppp_option_error(
                        "In secrets file: too few parameters for option '%s'",
                        w0->word);
                goto err;
@@ -623,10 +731,10 @@ err:
 }
 
 /*
- * match_option - see if this option matches an option_t structure.
+ * match_option - see if this option matches an option structure.
  */
 static int
-match_option(char *name, option_t *opt, int dowild)
+match_option(char *name, struct option *opt, int dowild)
 {
        int (*match)(char *, char **, int);
 
@@ -643,10 +751,10 @@ match_option(char *name, option_t *opt, int dowild)
  * looking for an entry with the given name.
  * This could be optimized by using a hash table.
  */
-static option_t *
+static struct option *
 find_option(char *name)
 {
-       option_t *opt;
+       struct option *opt;
        struct option_list *list;
        int i, dowild;
 
@@ -677,7 +785,7 @@ find_option(char *name)
  * process_option - process one new-style option.
  */
 static int
-process_option(option_t *opt, char *cmd, char **argv)
+process_option(struct option *opt, char *cmd, char **argv)
 {
     u_int32_t v;
     int iv, a;
@@ -686,7 +794,7 @@ process_option(option_t *opt, char *cmd, char **argv)
     int (*wildp)(char *, char **, int);
     char *optopt = (opt->type == o_wild)? "": " option";
     int prio = option_priority;
-    option_t *mainopt = opt;
+    struct option *mainopt = opt;
 
     current_option = opt->name;
     if ((opt->flags & OPT_PRIVFIX) && privileged_option)
@@ -697,7 +805,7 @@ process_option(option_t *opt, char *cmd, char **argv)
        if (prio < mainopt->priority) {
            /* new value doesn't override old */
            if (prio == OPRIO_CMDLINE && mainopt->priority > OPRIO_ROOT) {
-               option_error("%s%s set in %s cannot be overridden\n",
+               ppp_option_error("%s%s set in %s cannot be overridden\n",
                             opt->name, optopt, mainopt->source);
                return 0;
            }
@@ -708,22 +816,22 @@ process_option(option_t *opt, char *cmd, char **argv)
                 opt->name, optopt, option_source);
     }
 
-    if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
-       option_error("%s%s cannot be changed after initialization",
+    if ((opt->flags & OPT_INITONLY) && !in_phase(PHASE_INITIALIZE)) {
+       ppp_option_error("%s%s cannot be changed after initialization",
                     opt->name, optopt);
        return 0;
     }
     if ((opt->flags & OPT_PRIV) && !privileged_option) {
-       option_error("using the %s%s requires root privilege",
+       ppp_option_error("using the %s%s requires root privilege",
                     opt->name, optopt);
        return 0;
     }
     if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
-       option_error("%s%s is disabled", opt->name, optopt);
+       ppp_option_error("%s%s is disabled", opt->name, optopt);
        return 0;
     }
     if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
-       option_error("the %s%s may not be changed in %s",
+       ppp_option_error("the %s%s may not be changed in %s",
                     opt->name, optopt, option_source);
        return 0;
     }
@@ -745,7 +853,7 @@ process_option(option_t *opt, char *cmd, char **argv)
     case o_int:
        iv = 0;
        if ((opt->flags & OPT_NOARG) == 0) {
-           if (!int_option(*argv, &iv))
+           if (!ppp_int_option(*argv, &iv))
                return 0;
            if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
                 || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
@@ -753,15 +861,15 @@ process_option(option_t *opt, char *cmd, char **argv)
                char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
                switch (opt->flags & OPT_LIMITS) {
                case OPT_LLIMIT:
-                   option_error("%s value must be%s >= %d",
+                   ppp_option_error("%s value must be%s >= %d",
                                 opt->name, zok, opt->lower_limit);
                    break;
                case OPT_ULIMIT:
-                   option_error("%s value must be%s <= %d",
+                   ppp_option_error("%s value must be%s <= %d",
                                 opt->name, zok, opt->upper_limit);
                    break;
                case OPT_LIMITS:
-                   option_error("%s value must be%s between %d and %d",
+                   ppp_option_error("%s value must be%s between %d and %d",
                                opt->name, zok, opt->lower_limit, opt->upper_limit);
                    break;
                }
@@ -778,7 +886,7 @@ process_option(option_t *opt, char *cmd, char **argv)
            int oldv = *(int *)(opt->addr);
            if ((opt->flags & OPT_ZEROINF) ?
                (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
-               option_error("%s value cannot be increased", opt->name);
+               ppp_option_error("%s value cannot be increased", opt->name);
                return 0;
            }
        }
@@ -875,7 +983,7 @@ process_option(option_t *opt, char *cmd, char **argv)
 int
 override_value(char *option, int priority, const char *source)
 {
-       option_t *opt;
+       struct option *opt;
 
        opt = find_option(option);
        if (opt == NULL)
@@ -894,7 +1002,7 @@ override_value(char *option, int priority, const char *source)
  * n_arguments - tell how many arguments an option takes
  */
 static int
-n_arguments(option_t *opt)
+n_arguments(struct option *opt)
 {
        return (opt->type == o_bool || opt->type == o_special_noarg
                || (opt->flags & OPT_NOARG))? 0: 1;
@@ -904,7 +1012,7 @@ n_arguments(option_t *opt)
  * add_options - add a list of options to the set we grok.
  */
 void
-add_options(option_t *opt)
+ppp_add_options(struct option *opt)
 {
     struct option_list *list;
 
@@ -930,7 +1038,7 @@ check_options(void)
  * print_option - print out an option and its value
  */
 static void
-print_option(option_t *opt, option_t *mainopt, printer_func printer, void *arg)
+print_option(struct option *opt, struct option *mainopt, printer_func printer, void *arg)
 {
        int i, v;
        char *p;
@@ -992,8 +1100,8 @@ print_option(option_t *opt, option_t *mainopt, printer_func printer, void *arg)
                        printer(arg, " ");
                }
                if (opt->flags & OPT_A2PRINTER) {
-                       void (*oprt)(option_t *, printer_func, void *);
-                       oprt = (void (*)(option_t *, printer_func, void *))
+                       void (*oprt)(struct option *, printer_func, void *);
+                       oprt = (void (*)(struct option *, printer_func, void *))
                                opt->addr2;
                        (*oprt)(opt, printer, arg);
                } else if (opt->flags & OPT_A2STRVAL) {
@@ -1029,7 +1137,7 @@ print_option(option_t *opt, option_t *mainopt, printer_func printer, void *arg)
  * array of options.
  */
 static void
-print_option_list(option_t *opt, printer_func printer, void *arg)
+print_option_list(struct option *opt, printer_func printer, void *arg)
 {
        while (opt->name != NULL) {
                if (opt->priority != OPRIO_DEFAULT
@@ -1066,8 +1174,33 @@ print_options(printer_func printer, void *arg)
 static void
 usage(void)
 {
-    if (phase == PHASE_INITIALIZE)
-       fprintf(stderr, usage_string, VERSION, progname);
+    FILE *fp = stderr;
+    if (in_phase(PHASE_INITIALIZE)) {
+        fprintf(fp, "%s v%s\n", PACKAGE_NAME, PACKAGE_VERSION);
+        fprintf(fp, "Copyright (C) 1999-2024 Paul Mackerras, and others. All rights reserved.\n\n");
+
+
+        fprintf(fp, "License BSD: The 3 clause BSD license <https://opensource.org/licenses/BSD-3-Clause>\n");
+        fprintf(fp, "This is free software: you are free to change and redistribute it.\n");
+        fprintf(fp, "There is NO WARRANTY, to the extent permitted by law.\n\n");
+
+        fprintf(fp, "Report Bugs:\n   %s\n\n", PACKAGE_BUGREPORT);
+        fprintf(fp, "Usage: %s [ options ], where options are:\n", progname);
+        fprintf(fp, "   <device>        Communicate over the named device\n");
+        fprintf(fp, "   <speed>         Set the baud rate to <speed>\n");
+        fprintf(fp, "   <loc>:<rem>     Set the local and/or remote interface IP\n");
+        fprintf(fp, "                   addresses.  Either one may be omitted.\n");
+        fprintf(fp, "   asyncmap <n>    Set the desired async map to hex <n>\n");
+        fprintf(fp, "   auth            Require authentication from peer\n");
+        fprintf(fp, "   connect <p>     Invoke shell command <p> to set up the serial line\n");
+        fprintf(fp, "   crtscts         Use hardware RTS/CTS flow control\n");
+        fprintf(fp, "   defaultroute    Add default route through interface\n");
+        fprintf(fp, "   file <f>        Take options from file <f>\n");
+        fprintf(fp, "   modem           Use modem control lines\n");
+        fprintf(fp, "   mru <n>         Set MRU value to <n> for negotiation\n");
+        fprintf(fp, "   show-options    Display an extended list of options\n");
+        fprintf(fp, "See pppd(8) for more options.\n");
+    }
 }
 
 /*
@@ -1076,7 +1209,7 @@ usage(void)
 static int
 showhelp(char **argv)
 {
-    if (phase == PHASE_INITIALIZE) {
+    if (in_phase(PHASE_INITIALIZE)) {
        usage();
        exit(0);
     }
@@ -1089,7 +1222,7 @@ showhelp(char **argv)
 static int
 showversion(char **argv)
 {
-    if (phase == PHASE_INITIALIZE) {
+    if (in_phase(PHASE_INITIALIZE)) {
        fprintf(stdout, "pppd version %s\n", VERSION);
        exit(0);
     }
@@ -1097,12 +1230,67 @@ showversion(char **argv)
 }
 
 /*
- * option_error - print a message about an error in an option.
+ * Print a set of options including the name of the group of options
+ */
+static void
+showopts_list(FILE *fp, const char *title, struct option *list, ...)
+{
+       struct option *opt = list;
+    va_list varg;
+
+    if (opt && opt->name) {
+        va_start(varg, list);
+        vfprintf(fp, title, varg);
+        fprintf(fp, ":\n");
+        va_end(varg);
+
+        do {
+            fprintf(fp, "    %-22s %s\n", opt->name, opt->description?:"");
+            opt++;
+        } while (opt && opt->name);
+
+        fprintf(fp, "\n");
+    }
+}
+
+/*
+ * Dumps the list of available options
+ */
+void
+showopts(void)
+{
+    struct option_list *list;
+    FILE *fp = stderr;
+    int i = 0;
+
+    showopts_list(fp, "General Options",
+            general_options);
+
+    showopts_list(fp, "Authentication Options",
+            auth_options);
+
+    for (list = extra_options; list != NULL; list = list->next)
+               showopts_list(fp, "Extra Options", list->options);
+
+    showopts_list(fp, "Channel Options",
+            the_channel->options);
+
+    for (i = 0; protocols[i] != NULL; ++i) {
+        if (protocols[i]->options != NULL) {
+            showopts_list(fp, "%s Options",
+                    protocols[i]->options,
+                    protocols[i]->name);
+        }
+    }
+}
+
+/*
+ * ppp_option_error - print a message about an error in an option.
  * The message is logged, and also sent to
- * stderr if phase == PHASE_INITIALIZE.
+ * stderr if in_phase(PHASE_INITIALIZE).
  */
 void
-option_error(char *fmt, ...)
+ppp_option_error(char *fmt, ...)
 {
     va_list args;
     char buf[1024];
@@ -1110,7 +1298,7 @@ option_error(char *fmt, ...)
     va_start(args, fmt);
     vslprintf(buf, sizeof(buf), fmt, args);
     va_end(args);
-    if (phase == PHASE_INITIALIZE)
+    if (in_phase(PHASE_INITIALIZE))
        fprintf(stderr, "%s: %s\n", progname, buf);
     syslog(LOG_ERR, "%s", buf);
 }
@@ -1357,7 +1545,7 @@ getword(FILE *f, char *word, int *newlinep, char *filename)
        if (ferror(f)) {
            if (errno == 0)
                errno = EIO;
-           option_error("Error reading %s: %m", filename);
+           ppp_option_error("Error reading %s: %m", filename);
            die(1);
        }
        /*
@@ -1367,7 +1555,7 @@ getword(FILE *f, char *word, int *newlinep, char *filename)
        if (len == 0)
            return 0;
        if (quoted)
-           option_error("warning: quoted word runs to end of file (%.20s...)",
+           ppp_option_error("warning: quoted word runs to end of file (%.20s...)",
                         filename, word);
     }
 
@@ -1375,7 +1563,7 @@ getword(FILE *f, char *word, int *newlinep, char *filename)
      * Warn if the word was too long, and append a terminating null.
      */
     if (len >= MAXWORDLEN) {
-       option_error("warning: word in file %s too long (%.20s...)",
+       ppp_option_error("warning: word in file %s too long (%.20s...)",
                     filename, word);
        len = MAXWORDLEN - 1;
     }
@@ -1397,7 +1585,7 @@ number_option(char *str, u_int32_t *valp, int base)
 
     *valp = strtoul(str, &ptr, base);
     if (ptr == str) {
-       option_error("invalid numeric parameter '%s' for %s option",
+       ppp_option_error("invalid numeric parameter '%s' for %s option",
                     str, current_option);
        return 0;
     }
@@ -1411,7 +1599,7 @@ number_option(char *str, u_int32_t *valp, int base)
  * if there is an error.
  */
 int
-int_option(char *str, int *valp)
+ppp_int_option(char *str, int *valp)
 {
     u_int32_t v;
 
@@ -1432,7 +1620,7 @@ int_option(char *str, int *valp)
 static int
 readfile(char **argv)
 {
-    return options_from_file(*argv, 1, 1, privileged_option);
+    return ppp_options_from_file(*argv, 1, 1, privileged_option);
 }
 
 /*
@@ -1462,17 +1650,17 @@ callfile(char **argv)
        }
     }
     if (!ok) {
-       option_error("call option value may not contain .. or start with /");
+       ppp_option_error("call option value may not contain .. or start with /");
        return 0;
     }
 
-    l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
+    l = strlen(arg) + strlen(PPP_PATH_PEERFILES) + 1;
     if ((fname = (char *) malloc(l)) == NULL)
        novm("call file name");
-    slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
-    script_setenv("CALL_FILE", arg, 0);
+    slprintf(fname, l, "%s%s", PPP_PATH_PEERFILES, arg);
+    ppp_script_setenv("CALL_FILE", arg, 0);
 
-    ok = options_from_file(fname, 1, 1, 1);
+    ok = ppp_options_from_file(fname, 1, 1, 1);
 
     free(fname);
     return ok;
@@ -1490,7 +1678,7 @@ setpassfilter(char **argv)
 
     pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
     if (pcap_compile(pc, &pass_filter, *argv, 1, netmask) == -1) {
-       option_error("error in pass-filter expression: %s\n",
+       ppp_option_error("error in pass-filter expression: %s\n",
                     pcap_geterr(pc));
        ret = 0;
     }
@@ -1510,7 +1698,7 @@ setactivefilter(char **argv)
 
     pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
     if (pcap_compile(pc, &active_filter, *argv, 1, netmask) == -1) {
-       option_error("error in active-filter expression: %s\n",
+       ppp_option_error("error in active-filter expression: %s\n",
                     pcap_geterr(pc));
        ret = 0;
     }
@@ -1545,7 +1733,7 @@ setlogfile(char **argv)
 
     euid = geteuid();
     if (!privileged_option && seteuid(getuid()) == -1) {
-       option_error("unable to drop permissions to open %s: %m", *argv);
+       ppp_option_error("unable to drop permissions to open %s: %m", *argv);
        return 0;
     }
     fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
@@ -1556,7 +1744,7 @@ setlogfile(char **argv)
        fatal("unable to regain privileges: %m");
     if (fd < 0) {
        errno = err;
-       option_error("Can't open log file %s: %m", *argv);
+       ppp_option_error("Can't open log file %s: %m", *argv);
        return 0;
     }
     strlcpy(logfile_name, *argv, sizeof(logfile_name));
@@ -1597,7 +1785,7 @@ loadplugin(char **argv)
     const char *vers;
 
     if (strchr(arg, '/') == 0) {
-       const char *base = _PATH_PLUGIN;
+       const char *base = PPP_PATH_PLUGIN;
        int l = strlen(base) + strlen(arg) + 2;
        path = malloc(l);
        if (path == 0)
@@ -1610,25 +1798,27 @@ loadplugin(char **argv)
     if (handle == 0) {
        err = dlerror();
        if (err != 0)
-           option_error("%s", err);
-       option_error("Couldn't load plugin %s", arg);
+           ppp_option_error("%s", err);
+       ppp_option_error("Couldn't load plugin %s", arg);
        goto err;
     }
     init = (void (*)(void))dlsym(handle, "plugin_init");
     if (init == 0) {
-       option_error("%s has no initialization entry point", arg);
+       ppp_option_error("%s has no initialization entry point", arg);
        goto errclose;
     }
     vers = (const char *) dlsym(handle, "pppd_version");
     if (vers == 0) {
        warn("Warning: plugin %s has no version information", arg);
     } else if (strcmp(vers, VERSION) != 0) {
-       option_error("Plugin %s is for pppd version %s, this is %s",
+       ppp_option_error("Plugin %s is for pppd version %s, this is %s",
                     arg, vers, VERSION);
        goto errclose;
     }
     info("Plugin %s loaded.", arg);
     (*init)();
+    if (path != arg)
+       free(path);
     return 1;
 
  errclose:
@@ -1651,11 +1841,11 @@ user_setenv(char **argv)
     struct userenv *uep, **insp;
 
     if ((eqp = strchr(arg, '=')) == NULL) {
-       option_error("missing = in name=value: %s", arg);
+       ppp_option_error("missing = in name=value: %s", arg);
        return 0;
     }
     if (eqp == arg) {
-       option_error("missing variable name: %s", arg);
+       ppp_option_error("missing variable name: %s", arg);
        return 0;
     }
     for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
@@ -1670,6 +1860,10 @@ user_setenv(char **argv)
     /* The name never changes, so allocate it with the structure */
     if (uep == NULL) {
        uep = malloc(sizeof (*uep) + (eqp-arg));
+       if (uep == NULL) {
+               novm("environment variable");
+               return 1;
+       }
        strncpy(uep->ue_name, arg, eqp-arg);
        uep->ue_name[eqp-arg] = '\0';
        uep->ue_next = NULL;
@@ -1696,7 +1890,7 @@ user_setenv(char **argv)
 }
 
 static void
-user_setprint(option_t *opt, printer_func printer, void *arg)
+user_setprint(struct option *opt, printer_func printer, void *arg)
 {
     struct userenv *uep, *uepnext;
 
@@ -1722,11 +1916,11 @@ user_unsetenv(char **argv)
     char *arg = argv[0];
 
     if (strchr(arg, '=') != NULL) {
-       option_error("unexpected = in name: %s", arg);
+       ppp_option_error("unexpected = in name: %s", arg);
        return 0;
     }
     if (*arg == '\0') {
-       option_error("missing variable name for unset");
+       ppp_option_error("missing variable name for unset");
        return 0;
     }
     for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
@@ -1739,6 +1933,10 @@ user_unsetenv(char **argv)
     /* The name never changes, so allocate it with the structure */
     if (uep == NULL) {
        uep = malloc(sizeof (*uep) + strlen(arg));
+       if (uep == NULL) {
+               novm("environment variable");
+               return 1;
+       }
        strcpy(uep->ue_name, arg);
        uep->ue_next = NULL;
        insp = &userenv_list;
@@ -1764,7 +1962,7 @@ user_unsetenv(char **argv)
 }
 
 static void
-user_unsetprint(option_t *opt, printer_func printer, void *arg)
+user_unsetprint(struct option *opt, printer_func printer, void *arg)
 {
     struct userenv *uep, *uepnext;
 
diff --git a/pppd/options.h b/pppd/options.h
new file mode 100644 (file)
index 0000000..4ed0892
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * options.h - header declarations for option processing for PPP.
+ *
+ * Copyright (c) 2000-2024 Paul Mackerras. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef PPP_OPTIONS_H
+#define PPP_OPTIONS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum opt_type {
+       o_special_noarg,
+       o_special,
+       o_bool,
+       o_int,
+       o_uint32,
+       o_string,
+       o_wild
+};
+
+struct option {
+       char    *name;          /* name of the option */
+       enum opt_type type;
+       void    *addr;
+       char    *description;
+       unsigned int flags;
+       void    *addr2;
+       int     upper_limit;
+       int     lower_limit;
+       const char *source;
+       short int priority;
+       short int winner;
+};
+
+typedef struct option option_t;
+
+/* Values for flags */
+#define OPT_VALUE      0xff    /* mask for presupplied value */
+#define OPT_HEX                0x100   /* int option is in hex */
+#define OPT_NOARG      0x200   /* option doesn't take argument */
+#define OPT_OR         0x400   /* for u32, OR in argument to value */
+#define OPT_INC                0x400   /* for o_int, increment value */
+#define OPT_A2OR       0x800   /* for o_bool, OR arg to *(u_char *)addr2 */
+#define OPT_PRIV       0x1000  /* privileged option */
+#define OPT_STATIC     0x2000  /* string option goes into static array */
+#define OPT_NOINCR     0x2000  /* for o_int, value mustn't be increased */
+#define OPT_LLIMIT     0x4000  /* check value against lower limit */
+#define OPT_ULIMIT     0x8000  /* check value against upper limit */
+#define OPT_LIMITS     (OPT_LLIMIT|OPT_ULIMIT)
+#define OPT_ZEROOK     0x10000 /* 0 value is OK even if not within limits */
+#define OPT_HIDE       0x10000 /* for o_string, print value as ?????? */
+#define OPT_A2LIST     0x20000 /* for o_special, keep list of values */
+#define OPT_A2CLRB     0x20000 /* o_bool, clr val bits in *(u_char *)addr2 */
+#define OPT_ZEROINF    0x40000 /* with OPT_NOINCR, 0 == infinity */
+#define OPT_PRIO       0x80000 /* process option priorities for this option */
+#define OPT_PRIOSUB    0x100000 /* subsidiary member of priority group */
+#define OPT_ALIAS      0x200000 /* option is alias for previous option */
+#define OPT_A2COPY     0x400000 /* addr2 -> second location to rcv value */
+#define OPT_ENABLE     0x800000 /* use *addr2 as enable for option */
+#define OPT_A2CLR      0x1000000 /* clear *(bool *)addr2 */
+#define OPT_PRIVFIX    0x2000000 /* user can't override if set by root */
+#define OPT_INITONLY   0x4000000 /* option can only be set in init phase */
+#define OPT_DEVEQUIV   0x8000000 /* equiv to device name */
+#define OPT_DEVNAM     (OPT_INITONLY | OPT_DEVEQUIV)
+#define OPT_A2PRINTER  0x10000000 /* *addr2 printer_func to print option */
+#define OPT_A2STRVAL   0x20000000 /* *addr2 points to current string value */
+#define OPT_NOPRINT    0x40000000 /* don't print this option at all */
+
+#define OPT_VAL(x)     ((x) & OPT_VALUE)
+
+/* Values for priority */
+#define OPRIO_DEFAULT   0      /* a default value */
+#define OPRIO_CFGFILE   1      /* value from a configuration file */
+#define OPRIO_CMDLINE   2      /* value from the command line */
+#define OPRIO_SECFILE   3      /* value from options in a secrets file */
+#define OPRIO_ROOT      100    /* added to priority if OPT_PRIVFIX && root */
+
+/* Add additional supported options by e.g. plug-in */
+void ppp_add_options(struct option *options);
+
+/* Parse options from an options file */
+int ppp_options_from_file(char *filename, int must_exist, int check_prot,
+                      int privileged);
+
+/* Simplified number_option for decimal ints */
+int ppp_int_option(char *name, int *value);
+
+/* Print an error message about an option */
+void ppp_option_error(char *fmt, ...);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // PPP_OPTIONS_H
index 57a130e1c2e3b4278226366aa2c9c58e2edcd87e..ddc5e76db00a31237fa476e3c17fe6aebbf48911 100644 (file)
@@ -1,5 +1,42 @@
 /*
- * define path names
+ * pathnames.h - define default paths for pppd
+ *
+ * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Paths are controlled by configure. Typically, one would pass the following options
+ * to configure:
+ *    ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
+ *
+ * Note that if the prefix variable do control all the other directory variables, e.g
+ * sysconfdir is ${prefix}/etc. Setting prefix to /usr, you'll have to override
+ * sysconfdir with /etc to avoid installing config files into /usr/etc.
+ *
+ * In addition, there are three explicit variables that has overrides via configure:
+ * - PPPD_RUNTIME_DIR, set by --with-runtime-dir=<dir>
+ * - PPPD_LOGFILE_DIR, set by --with-logfile-dir=<dir>
+ * - PPPD_PLUGIN_DIR, set by --with-plugin-dir=<dir>
  */
 #ifndef PPP_PATHNAMES_H
 #define PPP_PATHNAMES_H
 #endif /* HAVE_PATHS_H */
 
 #ifndef _PATH_DEVNULL
-#define _PATH_DEVNULL  "/dev/null"
+#define _PATH_DEVNULL           "/dev/null"
 #endif
 
+#define PPP_DEVNULL             _PATH_DEVNULL
+
+/*
+ * PPPD_RUNTIME_DIR is set by passing --with-runtime-dir=<path> via configure
+ *    the default value set by configure when option is absent is ${localstatedir}/run/pppd
+ */
 #ifdef PPPD_RUNTIME_DIR
-#undef  _PATH_VARRUN
-#define _PATH_VARRUN   PPPD_RUNTIME_DIR "/"
+#define PPP_PATH_VARRUN         PPPD_RUNTIME_DIR
+#else
+#define PPP_PATH_VARRUN         _PATH_VARRUN
 #endif
 
+/*
+ * PPPD_LOGFILE_DIR is set by passing --with-logfile-dir=<path> via configure
+ *    the default value set by configure when option is absent is ${localstatedir}/log/ppp
+ */
 #ifdef PPPD_LOGFILE_DIR
-#undef  _PATH_VARLOG
-#define _PATH_VARLOG    PPPD_LOGFILE_DIR
+#define PPP_PATH_VARLOG         PPPD_LOGFILE_DIR
+#else
+#define PPP_PATH_VARLOG         _PATH_VARRUN "/log/ppp"
 #endif
 
+/*
+ * PPPD_PLUGIN_DIR is set by passing --with-plugin-dir=<path> via configure
+ *    the default value set by configure when option is absent is ${libdir}/pppd/${version}
+ */
 #ifdef PPPD_PLUGIN_DIR
-#define _PATH_PLUGIN    PPPD_PLUGIN_DIR
-#else
-#ifdef __STDC__
-#define _PATH_PLUGIN   DESTDIR "/lib/pppd/" VERSION
-#else  /* __STDC__ */
-#define _PATH_PLUGIN   "/usr/lib/pppd"
-#endif /* __STDC__ */
+#define PPP_PATH_PLUGIN         PPPD_PLUGIN_DIR
 #endif /* PPPD_PLUGIN_DIR */
 
-#ifndef _ROOT_PATH
-#define _ROOT_PATH
-#endif
+#define PPP_PATH_CONFDIR        SYSCONFDIR "/ppp"
 
-#define _PATH_UPAPFILE          _ROOT_PATH "/etc/ppp/pap-secrets"
-#define _PATH_CHAPFILE          _ROOT_PATH "/etc/ppp/chap-secrets"
-#define _PATH_SRPFILE   _ROOT_PATH "/etc/ppp/srp-secrets"
+#define PPP_PATH_UPAPFILE       PPP_PATH_CONFDIR "/pap-secrets"
+#define PPP_PATH_CHAPFILE       PPP_PATH_CONFDIR "/chap-secrets"
+#define PPP_PATH_SRPFILE        PPP_PATH_CONFDIR "/srp-secrets"
 
 #ifdef PPP_WITH_EAPTLS
-#define _PATH_EAPTLSCLIFILE    _ROOT_PATH "/etc/ppp/eaptls-client"
-#define _PATH_EAPTLSSERVFILE   _ROOT_PATH "/etc/ppp/eaptls-server"
-#define _PATH_OPENSSLCONFFILE  _ROOT_PATH "/etc/ppp/openssl.cnf"
+#define PPP_PATH_EAPTLSCLIFILE  PPP_PATH_CONFDIR "/eaptls-client"
+#define PPP_PATH_EAPTLSSERVFILE PPP_PATH_CONFDIR "/eaptls-server"
+#define PPP_PATH_OPENSSLCONFFILE PPP_PATH_CONFDIR "/openssl.cnf"
 #endif /* PPP_WITH_EAPTLS */
 
-#define _PATH_SYSOPTIONS _ROOT_PATH "/etc/ppp/options"
-#define _PATH_IPUP      _ROOT_PATH "/etc/ppp/ip-up"
-#define _PATH_IPDOWN    _ROOT_PATH "/etc/ppp/ip-down"
-#define _PATH_IPPREUP   _ROOT_PATH "/etc/ppp/ip-pre-up"
-#define _PATH_AUTHUP    _ROOT_PATH "/etc/ppp/auth-up"
-#define _PATH_AUTHDOWN  _ROOT_PATH "/etc/ppp/auth-down"
-#define _PATH_TTYOPT    _ROOT_PATH "/etc/ppp/options."
-#define _PATH_CONNERRS  _ROOT_PATH _PATH_VARLOG "/connect-errors"
-#define _PATH_PEERFILES         _ROOT_PATH "/etc/ppp/peers/"
-#define _PATH_RESOLV    _ROOT_PATH "/etc/ppp/resolv.conf"
+#define PPP_PATH_SYSOPTIONS     PPP_PATH_CONFDIR "/options"
+#define PPP_PATH_IPUP           PPP_PATH_CONFDIR "/ip-up"
+#define PPP_PATH_IPDOWN         PPP_PATH_CONFDIR "/ip-down"
+#define PPP_PATH_IPPREUP        PPP_PATH_CONFDIR "/ip-pre-up"
+#define PPP_PATH_AUTHUP         PPP_PATH_CONFDIR "/auth-up"
+#define PPP_PATH_AUTHDOWN       PPP_PATH_CONFDIR "/auth-down"
+#define PPP_PATH_TTYOPT         PPP_PATH_CONFDIR "/options."
+#define PPP_PATH_PEERFILES      PPP_PATH_CONFDIR "/peers/"
+#define PPP_PATH_RESOLV         PPP_PATH_CONFDIR "/resolv.conf"
 
-#define _PATH_USEROPT   ".ppprc"
-#define        _PATH_PSEUDONYM  ".ppp_pseudonym"
+#define PPP_PATH_NET_INIT      PPP_PATH_CONFDIR "/net-init"
+#define PPP_PATH_NET_PREUP     PPP_PATH_CONFDIR "/net-pre-up"
+#define PPP_PATH_NET_DOWN      PPP_PATH_CONFDIR "/net-down"
+
+#define PPP_PATH_CONNERRS       PPP_PATH_VARLOG  "/connect-errors"
+
+#define PPP_PATH_USEROPT        ".ppprc"
+#define PPP_PATH_PSEUDONYM         ".ppp_pseudonym"
 
 #ifdef PPP_WITH_IPV6CP
-#define _PATH_IPV6UP     _ROOT_PATH "/etc/ppp/ipv6-up"
-#define _PATH_IPV6DOWN   _ROOT_PATH "/etc/ppp/ipv6-down"
+#define PPP_PATH_IPV6UP         PPP_PATH_CONFDIR "/ipv6-up"
+#define PPP_PATH_IPV6DOWN       PPP_PATH_CONFDIR "/ipv6-down"
+#endif
+
+#define PPP_PATH_PPPDB          PPP_PATH_VARRUN  "/pppd2.tdb"
+
+#ifdef __linux__
+#define PPP_PATH_LOCKDIR        "/var/lock"
+#else
+#ifdef SVR4
+#define PPP_PATH_LOCKDIR        "/var/spool/locks"
+#else
+#define PPP_PATH_LOCKDIR        "/var/spool/lock"
+#endif
 #endif
 
-#ifdef __STDC__
-#define _PATH_PPPDB    _ROOT_PATH _PATH_VARRUN "pppd2.tdb"
-#else /* __STDC__ */
-#define _PATH_PPPDB    _PPP_VARRUN "pppd2.tdb"
-#endif /* __STDC__ */
 
 #endif /* PPP_PATHNAMES_H */
index d6e5fcff9012edc68f5e902808b44a9164e91a1b..243a8bd1344d880bddd0a94768a88c5c6c46ed3c 100644 (file)
  *    https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-peap
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <openssl/rand.h>
 #include <openssl/err.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "eap.h"
 #include "tls.h"
-#include "chap-new.h"
+#include "chap.h"
 #include "chap_ms.h"
 #include "mppe.h"
 #include "peap.h"
@@ -436,6 +440,7 @@ void peap_do_inner_eap(u_char *in_buf, int in_len, eap_state *esp, int id,
                }
                case CHAP_FAILURE: {
 
+                       u_char status = CHAP_FAILURE;
                        psm->chap->handle_failure(in_buf, in_len);
                        PUTCHAR(EAPT_MSCHAPV2, outp);
                        PUTCHAR(status, outp);
index 2826148c79ffb79f71711bf86e76b07b2c0e9c65..9480d51b4543ba97426cfe9b5ee67daeb97eaa38 100644 (file)
@@ -1,4 +1,4 @@
-pppd_plugin_LTLIBRARIES = minconn.la passprompt.la passwordfd.la winbind.la
+pppd_plugin_LTLIBRARIES = minconn.la passwordfd.la winbind.la
 pppd_plugindir = $(PPPD_PLUGIN_DIR)
 
 PLUGIN_CPPFLAGS = -I${top_srcdir}
@@ -8,10 +8,6 @@ minconn_la_CPPFLAGS = $(PLUGIN_CPPFLAGS)
 minconn_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 minconn_la_SOURCES = minconn.c
 
-passprompt_la_CPPFLAGS = $(PLUGIN_CPPFLAGS)
-passprompt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-passprompt_la_SOURCES = passprompt.c
-
 passwordfd_la_CPPFLAGS = $(PLUGIN_CPPFLAGS)
 passwordfd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 passwordfd_la_SOURCES = passwordfd.c
index 82bef4890931ea2ad496e43f50752b5017ecd68d..016526d5936b47c0a9fd512690008dd75fc2c5d9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * minconn.c - pppd plugin to implement a `minconnect' option.
  *
- * Copyright (c) 1999 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 
 #include <stddef.h>
 #include <time.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <sys/types.h>
+
 #include <pppd/pppd.h>
+#include <pppd/options.h>
+
+#if !defined(SOL2)
+#include <linux/ppp_defs.h>
+#else
+#include <net/ppp_defs.h>
+#endif
 
 char pppd_version[] = PPPD_VERSION;
 
 static int minconnect = 0;
 
-static option_t my_options[] = {
+static struct option my_options[] = {
        { "minconnect", o_int, &minconnect,
          "Set minimum connect time before idle timeout applies" },
        { NULL }
@@ -52,16 +55,16 @@ static int my_get_idle(struct ppp_idle *idle)
        time_t t;
 
        if (idle == NULL)
-               return minconnect? minconnect: idle_time_limit;
+               return minconnect ? minconnect: ppp_get_max_idle_time();
        t = idle->xmit_idle;
        if (idle->recv_idle < t)
                t = idle->recv_idle;
-       return idle_time_limit - t;
+       return ppp_get_max_idle_time() - t;
 }
 
 void plugin_init(void)
 {
        info("plugin_init");
-       add_options(my_options);
+       ppp_add_options(my_options);
        idle_time_hook = my_get_idle;
 }
diff --git a/pppd/plugins/passprompt.c b/pppd/plugins/passprompt.c
deleted file mode 100644 (file)
index 14a199f..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * passprompt.c - pppd plugin to invoke an external PAP password prompter
- *
- * Copyright 1999 Paul Mackerras, Alan Curry.
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version
- *  2 of the License, or (at your option) any later version.
- */
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <sys/param.h>
-#include <limits.h>
-#include <syslog.h>
-#include <pppd/pppd.h>
-
-char pppd_version[] = PPPD_VERSION;
-
-static char promptprog[PATH_MAX+1];
-static int promptprog_refused = 0;
-
-static option_t options[] = {
-    { "promptprog", o_string, promptprog,
-      "External PAP password prompting program",
-      OPT_STATIC, NULL, PATH_MAX },
-    { NULL }
-};
-
-static int promptpass(char *user, char *passwd)
-{
-    int p[2];
-    pid_t kid;
-    int readgood, wstat, ret;
-    ssize_t red;
-
-    if (promptprog_refused || promptprog[0] == 0 || access(promptprog, X_OK) < 0)
-       return -1;      /* sorry, can't help */
-
-    if (!passwd)
-       return 1;
-
-    if (pipe(p)) {
-       warn("Can't make a pipe for %s", promptprog);
-       return 0;
-    }
-    if ((kid = fork()) == (pid_t) -1) {
-       warn("Can't fork to run %s", promptprog);
-       close(p[0]);
-       close(p[1]);
-       return 0;
-    }
-    if (!kid) {
-       /* we are the child, exec the program */
-       char *argv[5], fdstr[32];
-       sys_close();
-       closelog();
-       close(p[0]);
-       ret = seteuid(getuid());
-       if (ret != 0) {
-               warn("Couldn't set effective user id");
-       }
-       ret = setegid(getgid());
-       if (ret != 0) {
-               warn("Couldn't set effective user id");
-       }
-       argv[0] = promptprog;
-       argv[1] = user;
-       argv[2] = remote_name;
-       sprintf(fdstr, "%d", p[1]);
-       argv[3] = fdstr;
-       argv[4] = 0;
-       execv(*argv, argv);
-       _exit(127);
-    }
-
-    /* we are the parent, read the password from the pipe */
-    close(p[1]);
-    readgood = 0;
-    do {
-       red = read(p[0], passwd + readgood, MAXSECRETLEN-1 - readgood);
-       if (red == 0)
-           break;
-       if (red < 0) {
-           if (errno == EINTR && !got_sigterm)
-               continue;
-           error("Can't read secret from %s: %m", promptprog);
-           readgood = -1;
-           break;
-       }
-       readgood += red;
-    } while (readgood < MAXSECRETLEN - 1);
-    close(p[0]);
-
-    /* now wait for child to exit */
-    while (waitpid(kid, &wstat, 0) < 0) {
-       if (errno != EINTR || got_sigterm) {
-           warn("error waiting for %s: %m", promptprog);
-           break;
-       }
-    }
-
-    if (readgood < 0)
-       return 0;
-    passwd[readgood] = 0;
-    if (!WIFEXITED(wstat))
-       warn("%s terminated abnormally", promptprog);
-    if (WEXITSTATUS(wstat)) {
-           warn("%s exited with code %d", promptprog, WEXITSTATUS(wstat));
-           /* code when cancel was hit in the prompt prog */
-           if (WEXITSTATUS(wstat) == 128) {
-               promptprog_refused = 1;
-           }
-           return -1;
-    }
-    return 1;
-}
-
-void plugin_init(void)
-{
-    add_options(options);
-    pap_passwd_hook = promptpass;
-#ifdef PPP_WITH_EAPTLS
-    eaptls_passwd_hook = promptpass;
-#endif
-}
index 6f8bc6f0be78265838f8f5733833f4c974fe7e82..be3088c532206f7bd06f8c6b29b87ad9e05aeb16 100644 (file)
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/time.h>
 
 #include <pppd/pppd.h>
+#include <pppd/upap.h>
+#include <pppd/chap.h>
+#include <pppd/eap.h>
+#include <pppd/options.h>
 
 char pppd_version[] = PPPD_VERSION;
 
-static int passwdfd = -1;
 static char save_passwd[MAXSECRETLEN];
 
-static option_t options[] = {
-    { "passwordfd", o_int, &passwdfd,
-      "Receive password on this file descriptor" },
-    { NULL }
-};
-
-static int pwfd_check (void)
-{
-    return 1;
-}
-
-static int pwfd_passwd (char *user, char *passwd)
+static int pwfd_read_password(char **argv)
 {
-    int readgood, red;
-
-    if (passwdfd == -1)
-       return -1;
+    ssize_t readgood, red;
+    int passwdfd;
+    char passwd[MAXSECRETLEN];
 
-    if (passwd == NULL)
-       return 1;
-
-    if (passwdfd == -2) {
-       strcpy (passwd, save_passwd);
-       return 1;
-    }
+    if (!ppp_int_option(argv[0], &passwdfd))
+       return 0;
 
     readgood = 0;
     do {
@@ -65,14 +55,31 @@ static int pwfd_passwd (char *user, char *passwd)
 
     passwd[readgood] = 0;
     strcpy (save_passwd, passwd);
-    passwdfd = -2;
 
     return 1;
 }
 
+static struct option options[] = {
+    { "passwordfd", o_special, pwfd_read_password,
+      "Receive password on this file descriptor" },
+    { NULL }
+};
+
+static int pwfd_check (void)
+{
+    return 1;
+}
+
+static int pwfd_passwd (char *user, char *passwd)
+{
+    if (passwd != NULL)
+       strcpy(passwd, save_passwd);
+    return 1;
+}
+
 void plugin_init (void)
 {
-    add_options (options);
+    ppp_add_options (options);
 
     pap_check_hook = pwfd_check;
     pap_passwd_hook = pwfd_passwd;
index 973eb33597d50b9808143926c1b7e058b35c51d0..c949f23adc24ab29f3669a0a55e8612cb61c0f10 100644 (file)
 #define MAX_ANSWER 2048
 #define MAX_NAME   1024
 
-#define MAX_LINE               2048    /* in /etc/e164_cc */
-#define E164_CC_DEFAULT_LEN       2
-#define E164_CC_FILE           "/etc/e164_cc"
-
 #define GET16(pos) (((pos)[0] << 8) | (pos)[1])
 
 
@@ -134,129 +130,3 @@ int ans_byname(const char *text,struct sockaddr_atmsvc *addr,int length,
     if (!ans(text,T_ATMA,addr,length)) return 0;
     return ans(text,T_NSAP,addr,length);
 }
-
-
-static int encode_nsap(char *buf,const unsigned char *addr)
-{
-    static int fmt_dcc[] = { 2,12,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-      4,2,0 };
-    static int fmt_e164[] = { 2,12,1,1,1,1,1,1,1,1,16,2,0 };
-    int *fmt;
-    int pos,i,j;
-
-    switch (*addr) {
-       case ATM_AFI_DCC:
-       case ATM_AFI_ICD:
-       case ATM_AFI_LOCAL:
-       case ATM_AFI_DCC_GROUP:
-       case ATM_AFI_ICD_GROUP:
-       case ATM_AFI_LOCAL_GROUP:
-           fmt = fmt_dcc;
-           break;
-       case ATM_AFI_E164:
-       case ATM_AFI_E164_GROUP:
-           fmt = fmt_e164;
-           break;
-       default:
-           return TRY_OTHER;
-    }
-    pos = 2*ATM_ESA_LEN;
-    for (i = 0; fmt[i]; i++) {
-       pos -= fmt[i];
-       for (j = 0; j < fmt[i]; j++)
-           sprintf(buf++,"%x",
-             (addr[(pos+j) >> 1] >> 4*(1-((pos+j) & 1))) & 0xf);
-       *buf++ = '.';
-    }
-    strcpy(buf,"AESA.ATMA.INT.");
-    return 0;
-}
-
-
-static int encode_nsap_new(char *buf,const unsigned char *addr)
-{
-    int i;
-    int digit;
-
-    for (i = 20; i; ) {
-        i--;
-        digit = addr[i] & 0x0F;
-        *(buf++) = digit + (digit >= 10 ? '7' : '0');
-        *(buf++) = '.';
-        digit = ((unsigned char) (addr[i])) >> 4;
-        *(buf++) = digit + (digit >= 10 ? '7' : '0');
-        *(buf++) = '.';
-    }
-    strcpy (buf, "NSAP.INT.");
-    return 0;
-}
-
-
-static int cc_len(int p0,int p1)
-{
-    static char *cc_table = NULL;
-    FILE *file;
-    char buffer[MAX_LINE];
-    char *here;
-    int cc;
-
-    if (!cc_table) {
-       if (!(cc_table = malloc(100))) {
-           perror("malloc");
-           return E164_CC_DEFAULT_LEN;
-       }
-       memset(cc_table,E164_CC_DEFAULT_LEN,100);
-       if (!(file = fopen(E164_CC_FILE,"r")))
-           perror(E164_CC_FILE);
-       else {
-           while (fgets(buffer,MAX_LINE,file)) {
-               here = strchr(buffer,'#');
-               if (here) *here = 0;
-               if (sscanf(buffer,"%d",&cc) == 1) {
-                   if (cc < 10) cc_table[cc] = 1;
-                   else if (cc < 100) cc_table[cc] = 2;
-                       else cc_table[cc/10] = 3;
-               }
-           }
-           fclose(file);
-       }
-    }
-    if (cc_table[p0] == 1) return 1;
-    return cc_table[p0*10+p1];
-}
-
-
-static int encode_e164(char *buf,const char *addr)
-{
-    const char *prefix,*here;
-
-    prefix = addr+cc_len(addr[0]-48,addr[1]-48);
-    here = strchr(addr,0);
-    while (here > prefix) {
-       *buf++ = *--here;
-       *buf++ = '.';
-    }
-    while (here > addr) *buf++ = *addr++;
-    strcpy(buf,".E164.ATMA.INT.");
-    return 0;
-}
-
-
-int ans_byaddr(char *buffer,int length,const struct sockaddr_atmsvc *addr,
-  int flags)
-{
-    char tmp[MAX_NAME]; /* could be smaller ... */
-    int res;
-
-    if (addr->sas_addr.prv) {
-        res = encode_nsap(tmp,addr->sas_addr.prv);
-        if (!res && !ans(tmp,T_PTR,buffer,length)) return 0;
-       res = encode_nsap_new(tmp,addr->sas_addr.prv);
-        if (res < 0) return res;
-       return ans(tmp,T_PTR,buffer,length);
-    } else {
-        res = encode_e164(tmp,addr->sas_addr.pub);
-        if (res < 0) return res;
-        return ans(tmp,T_PTR,buffer,length);
-    }
-}
index d5b3b8c3822c9b962312babee97a365cdfdbc294..3cbc77e625f5f662d5933d7f38caa27f1e8111b5 100644 (file)
@@ -30,7 +30,5 @@
 
 int ans_byname(const char *text,struct sockaddr_atmsvc *addr,int length,
   int flags);
-int ans_byaddr(char *buffer,int length,const struct sockaddr_atmsvc *addr,
-  int flags);
 
 #endif
index 5ac03c8483d66e44f40da04f1ab7f7290b3a72c0..39d3dbdf4cab33c45434464413fe8c7a6ebfe926 100644 (file)
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#include <stdbool.h>
+#include <stdarg.h>
 
 #include <pppd/pppd.h>
-#include <pppd/pathnames.h>
+#include <pppd/options.h>
 #include <pppd/fsm.h> /* Needed for lcp.h to include cleanly */
 #include <pppd/lcp.h>
 
@@ -42,8 +44,9 @@ static int pppoatm_max_mtu, pppoatm_max_mru;
 static int setdevname_pppoatm(const char *cp, const char **argv, int doit);
 struct channel pppoa_channel;
 static int pppoa_fd = -1;
+static char devnam[MAXNAMELEN];
 
-static option_t pppoa_options[] = {
+static struct option pppoa_options[] = {
        { "device name", o_wild, (void *) &setdevname_pppoatm,
          "ATM service provider IDs: VPI.VCI",
          OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG  | OPT_A2STRVAL | OPT_STATIC,
@@ -89,7 +92,8 @@ static int setdevname_pppoatm(const char *cp, const char **argv, int doit)
                return 1;
 
        memcpy(&pvcaddr, &addr, sizeof pvcaddr);
-       strlcpy(devnam, cp, MAXPATHLEN);
+       strlcpy(devnam, cp, sizeof(devnam));
+       ppp_set_devnam(devnam);
        devstat.st_mode = S_IFSOCK;
        if (the_channel != &pppoa_channel) {
                the_channel = &pppoa_channel;
@@ -163,7 +167,7 @@ static int connect_pppoatm(void)
        pppoatm_max_mtu = lcp_allowoptions[0].mru;
        pppoatm_max_mru = lcp_wantoptions[0].mru;
        set_line_discipline_pppoatm(fd);
-       strlcpy(ppp_devnam, devnam, MAXPATHLEN);
+       ppp_set_pppdevnam(devnam);
        pppoa_fd = fd;
        return fd;
 }
@@ -177,13 +181,13 @@ void plugin_init(void)
 {
 #ifdef linux
        extern int new_style_driver;    /* From sys-linux.c */
-       if (!ppp_available() && !new_style_driver)
+       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
-       add_options(pppoa_options);
+       ppp_add_options(pppoa_options);
 }
 
 struct channel pppoa_channel = {
@@ -192,8 +196,8 @@ struct channel pppoa_channel = {
     .check_options = NULL,
     .connect = &connect_pppoatm,
     .disconnect = &disconnect_pppoatm,
-    .establish_ppp = &generic_establish_ppp,
-    .disestablish_ppp = &generic_disestablish_ppp,
+    .establish_ppp = &ppp_generic_establish,
+    .disestablish_ppp = &ppp_generic_disestablish,
     .send_config = NULL,
     .recv_config = NULL,
     .close = NULL,
index 060407a026075e0746828dbcfe9389617b623182..2da1e50157a31ea9085bbeab31b87b62fc9e855d 100644 (file)
@@ -66,8 +66,9 @@ int __t2q_get_rate(const char **text,int up)
     }
     else if (!strncmp(end,"cps",3)) end += 3;
        else if (!strncmp(end,"bps",3)) {
-               rate = (rate+(up ? 8*ATM_CELL_PAYLOAD-1 : 0))/8/
-                 ATM_CELL_PAYLOAD;
+               if (up && rate % (8 * ATM_CELL_PAYLOAD) == 0)
+                       up = 0;
+               rate = rate / (8 * ATM_CELL_PAYLOAD) + !!up;
                end += 3;
            }
            else if (multiplier) return RATE_ERROR;
index 6cea70aae967c96fd17b9e9a3749febdeeae3cbf..4ce0a482aa0e9bfbf8d10843d458c1adc15f6c52 100644 (file)
@@ -6,7 +6,7 @@ dist_man8_MANS = pppoe-discovery.8
 noinst_HEADERS = \
     pppoe.h
 
-pppoe_la_CPPFLAGS = -I${top_srcdir}
+pppoe_la_CPPFLAGS = -I${top_srcdir} -DSYSCONFDIR=\"${sysconfdir}\" -DPLUGIN
 pppoe_la_LDFLAGS = -module -avoid-version
 pppoe_la_SOURCES = plugin.c discovery.c if.c common.c
 
index 31811f59a9fbf3af05d79ff94f698ed5d7a0d321..8d3b21a146501e9c08900f0eb764928f29363c93 100644 (file)
@@ -13,9 +13,6 @@
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: common.c,v 1.3 2008/06/09 08:34:23 paulus Exp $";
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
index 0c4d9daed9360e6e92431e5bebc57f96e2203aa6..d7d61c01c0414e3fd10b43ec7f6e8c8e6770e110 100644 (file)
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the <stdarg.h> header file. */
+#undef HAVE_STDARG_H
+
+/* Define to 1 if you have the <stdbool.h> header file. */
+#undef HAVE_STDBOOL_H
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#undef HAVE_STDDEF_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
 /* The size of `unsigned int', as computed by sizeof. */
 #undef SIZEOF_UNSIGNED_INT
 
@@ -54,3 +69,5 @@
 /* The size of `unsigned short', as computed by sizeof. */
 #undef SIZEOF_UNSIGNED_SHORT
 
+/* Define to 1 if the system has the type `struct sockaddr_ll'. */
+#undef HAVE_STRUCT_SOCKADDR_LL
index a5c2c62fdc383738edf8d5edb65101a6cc5b3b98..86bda611b2d11022213777c8c69ed847b297ca88 100644 (file)
@@ -8,9 +8,6 @@
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: discovery.c,v 1.6 2008/06/15 04:35:50 paulus Exp $";
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -44,6 +41,15 @@ static char const RCSID[] =
 
 #include <signal.h>
 
+#ifdef PLUGIN
+#define signaled(x) ppp_signaled(x)
+#define get_time(x) ppp_get_time(x)
+#else
+int signaled(int signal);
+int get_time(struct timeval *tv);
+
+#endif
+
 /* Calculate time remaining until *exp, return 0 if now >= *exp */
 static int time_left(struct timeval *diff, struct timeval *exp)
 {
@@ -149,6 +155,10 @@ parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data,
            !strncmp((char *) data, conn->acName, len)) {
            pc->acNameOK = 1;
        }
+       /* save a copy of the AC name if we can */
+       conn->actualACname = realloc(conn->actualACname, len + 1);
+       if (conn->actualACname)
+           strlcpy(conn->actualACname, (char *) data, len + 1);
        break;
     case TAG_SERVICE_NAME:
        pc->seenServiceName = 1;
@@ -370,7 +380,7 @@ sendPADI(PPPoEConnection *conn)
 * Waits for a PADO packet and copies useful information
 ***********************************************************************/
 void
-waitForPADO(PPPoEConnection *conn, int timeout)
+waitForPADO(PPPoEConnection *conn, int timeout, int waitWholeTimeoutForPADO)
 {
     fd_set readable;
     int r;
@@ -404,7 +414,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)
 
            while(1) {
                r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
-               if (r >= 0 || errno != EINTR || got_sigterm) break;
+               if (r >= 0 || errno != EINTR || signaled(SIGTERM)) break;
            }
            if (r < 0) {
                error("select (waitForPADO): %m");
@@ -471,7 +481,7 @@ waitForPADO(PPPoEConnection *conn, int timeout)
                conn->discoveryState = STATE_RECEIVED_PADO;
            }
        }
-    } while (pppoe_verbose >= 1 || conn->discoveryState != STATE_RECEIVED_PADO);
+    } while (waitWholeTimeoutForPADO || conn->discoveryState != STATE_RECEIVED_PADO);
 }
 
 /***********************************************************************
@@ -595,7 +605,7 @@ waitForPADS(PPPoEConnection *conn, int timeout)
 
            while(1) {
                r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
-               if (r >= 0 || errno != EINTR || got_sigterm) break;
+               if (r >= 0 || errno != EINTR || signaled(SIGTERM)) break;
            }
            if (r < 0) {
                error("select (waitForPADS): %m");
@@ -659,14 +669,14 @@ waitForPADS(PPPoEConnection *conn, int timeout)
 * Performs the PPPoE discovery phase 1
 ***********************************************************************/
 void
-discovery1(PPPoEConnection *conn)
+discovery1(PPPoEConnection *conn, int waitWholeTimeoutForPADO)
 {
     int padiAttempts = 0;
     int timeout = conn->discoveryTimeout;
 
     do {
        padiAttempts++;
-       if (got_sigterm || padiAttempts > conn->discoveryAttempts) {
+       if (signaled(SIGTERM) || padiAttempts > conn->discoveryAttempts) {
            warn("Timeout waiting for PADO packets");
            close(conn->discoverySocket);
            conn->discoverySocket = -1;
@@ -674,7 +684,7 @@ discovery1(PPPoEConnection *conn)
        }
        sendPADI(conn);
        conn->discoveryState = STATE_SENT_PADI;
-       waitForPADO(conn, timeout);
+       waitForPADO(conn, timeout, waitWholeTimeoutForPADO);
 
        timeout *= 2;
     } while (conn->discoveryState == STATE_SENT_PADI);
@@ -697,7 +707,7 @@ discovery2(PPPoEConnection *conn)
 
     do {
        padrAttempts++;
-       if (got_sigterm || padrAttempts > conn->discoveryAttempts) {
+       if (signaled(SIGTERM) || padrAttempts > conn->discoveryAttempts) {
            warn("Timeout waiting for PADS packets");
            close(conn->discoverySocket);
            conn->discoverySocket = -1;
index a3c384815ce2552055a152169293062af073b697..8a0f608b9598a3322c874c62b85f564ea3b2110d 100644 (file)
@@ -13,9 +13,6 @@
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: if.c,v 1.2 2008/06/09 08:34:23 paulus Exp $";
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -99,6 +96,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     int fd;
     struct ifreq ifr;
     int domain, stype;
+    size_t maxlen;
 
 #ifdef HAVE_STRUCT_SOCKADDR_LL
     struct sockaddr_ll sa;
@@ -111,11 +109,18 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
 #ifdef HAVE_STRUCT_SOCKADDR_LL
     domain = PF_PACKET;
     stype = SOCK_RAW;
+    maxlen = IFNAMSIZ;
 #else
     domain = PF_INET;
     stype = SOCK_PACKET;
+    maxlen = sizeof(sa.sa_data);
 #endif
 
+    if (strlen(ifname) >= maxlen) {
+       error("Can't use interface %.16s: name is too long", ifname);
+       return -1;
+    }
+
     if ((fd = socket(domain, stype, htons(type))) < 0) {
        /* Give a more helpful message for the common error case */
        if (errno == EPERM) {
@@ -175,7 +180,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     sa.sll_ifindex = ifr.ifr_ifindex;
 
 #else
-    strcpy(sa.sa_data, ifname);
+    strlcpy(sa.sa_data, ifname, sizeof(sa.sa_data));
 #endif
 
     /* We're only interested in packets on specified interface */
@@ -205,14 +210,14 @@ sendPacket(PPPoEConnection *conn, int sock, PPPoEPacket *pkt, int size)
 {
     int err;
 
-    if (debug)
+    if (debug_on())
        pppoe_log_packet("Send ", pkt);
 #if defined(HAVE_STRUCT_SOCKADDR_LL)
     err = send(sock, pkt, size, 0);
 #else
     struct sockaddr sa;
 
-    strcpy(sa.sa_data, conn->ifName);
+    strlcpy(sa.sa_data, conn->ifName, sizeof(sa.sa_data));
     err = sendto(sock, pkt, size, 0, &sa, sizeof(sa));
 #endif
     if (err < 0) {
@@ -240,7 +245,7 @@ receivePacket(int sock, PPPoEPacket *pkt, int *size)
        error("error receiving pppoe packet: %m");
        return -1;
     }
-    if (debug)
+    if (debug_on())
        pppoe_log_packet("Recv ", pkt);
     return 0;
 }
index 92d049353c49b24b6bb81f295a37317cfd1cd778..b429a2fdff719389744a78b342b698aae617f74b 100644 (file)
@@ -22,9 +22,6 @@
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: plugin.c,v 1.17 2008/06/15 04:35:50 paulus Exp $";
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -49,17 +46,11 @@ static char const RCSID[] =
 #include <linux/if_pppox.h>
 
 #include <pppd/pppd.h>
+#include <pppd/options.h>
 #include <pppd/fsm.h>
 #include <pppd/lcp.h>
 #include <pppd/ipcp.h>
 #include <pppd/ccp.h>
-/* #include <pppd/pathnames.h> ?, see below ... */
-
-#ifndef _ROOT_PATH
-#define _ROOT_PATH ""
-#endif
-
-#define _PATH_ETHOPT         _ROOT_PATH "/etc/ppp/options."
 
 char pppd_version[] = PPPD_VERSION;
 
@@ -75,9 +66,10 @@ unsigned char pppoe_reqd_mac_addr[6];
 static char *pppoe_host_uniq;
 static int pppoe_padi_timeout = PADI_TIMEOUT;
 static int pppoe_padi_attempts = MAX_PADI_ATTEMPTS;
+static char devnam[MAXNAMELEN];
 
 static int PPPoEDevnameHook(char *cmd, char **argv, int doit);
-static option_t Options[] = {
+static struct option Options[] = {
     { "device name", o_wild, (void *) &PPPoEDevnameHook,
       "PPPoE device name",
       OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG  | OPT_A2STRVAL | OPT_STATIC,
@@ -133,8 +125,6 @@ PPPOEInitDevice(void)
     conn->ifName = devnam;
     conn->discoverySocket = -1;
     conn->sessionSocket = -1;
-    conn->discoveryTimeout = pppoe_padi_timeout;
-    conn->discoveryAttempts = pppoe_padi_attempts;
     return 1;
 }
 
@@ -153,6 +143,7 @@ PPPOEConnectDevice(void)
     struct sockaddr_pppox sp;
     struct ifreq ifr;
     int s;
+    char remote_number[MAXNAMELEN];
 
     /* Open session socket before discovery phase, to avoid losing session */
     /* packets sent by peer just after PADS packet (noted on some Cisco    */
@@ -201,7 +192,7 @@ PPPOEConnectDevice(void)
 
     conn->acName = acName;
     conn->serviceName = pppd_pppoe_service;
-    strlcpy(ppp_devnam, devnam, MAXPATHLEN);
+    ppp_set_pppdevnam(devnam);
     if (existingSession) {
        unsigned int mac[ETH_ALEN];
        int i, ses;
@@ -221,7 +212,7 @@ PPPOEConnectDevice(void)
            error("Failed to create PPPoE discovery socket: %m");
            goto errout;
        }
-       discovery1(conn);
+       discovery1(conn, 0);
        /* discovery1() may update conn->mtu and conn->mru */
        lcp_allowoptions[0].mru = conn->mtu;
        lcp_wantoptions[0].mru = conn->mru;
@@ -240,7 +231,7 @@ PPPOEConnectDevice(void)
     }
 
     /* Set PPPoE session-number for further consumption */
-    ppp_session_number = ntohs(conn->session);
+    ppp_set_session_number(ntohs(conn->session));
 
     sp.sa_family = AF_PPPOX;
     sp.sa_protocol = PX_PROTO_OE;
@@ -256,17 +247,12 @@ PPPOEConnectDevice(void)
            (unsigned) conn->peerEth[3],
            (unsigned) conn->peerEth[4],
            (unsigned) conn->peerEth[5]);
+    warn("Connected to %s via interface %s", remote_number, conn->ifName);
+    ppp_set_remote_number(remote_number);
 
-    warn("Connected to %02X:%02X:%02X:%02X:%02X:%02X via interface %s",
-        (unsigned) conn->peerEth[0],
-        (unsigned) conn->peerEth[1],
-        (unsigned) conn->peerEth[2],
-        (unsigned) conn->peerEth[3],
-        (unsigned) conn->peerEth[4],
-        (unsigned) conn->peerEth[5],
-        conn->ifName);
-
-    script_setenv("MACREMOTE", remote_number, 0);
+    ppp_script_setenv("MACREMOTE", remote_number, 0);
+    if (conn->actualACname)
+       ppp_script_setenv("ACNAME", conn->actualACname, 0);
 
     if (connect(conn->sessionSocket, (struct sockaddr *) &sp,
                sizeof(struct sockaddr_pppox)) < 0) {
@@ -321,22 +307,31 @@ PPPOEDisconnectDevice(void)
                sizeof(struct sockaddr_pppox)) < 0 && errno != EALREADY)
        error("Failed to disconnect PPPoE socket: %d %m", errno);
     close(conn->sessionSocket);
+    if (conn->discoverySocket < 0)
+       conn->discoverySocket =
+            openInterface(conn->ifName, Eth_PPPOE_Discovery, NULL);
     if (conn->discoverySocket >= 0) {
         sendPADT(conn, NULL);
        close(conn->discoverySocket);
     }
+    free(conn->actualACname);
+    conn->actualACname = NULL;
 }
 
 static void
 PPPOEDeviceOptions(void)
 {
+    char name[MAXPATHLEN];
     char buf[MAXPATHLEN];
 
-    strlcpy(buf, _PATH_ETHOPT, MAXPATHLEN);
-    strlcat(buf, devnam, MAXPATHLEN);
-    if (!options_from_file(buf, 0, 0, 1))
-       exit(EXIT_OPTION_ERROR);
-
+    slprintf(name, sizeof(name), "options.%s", devnam);
+       if (ppp_get_filepath(PPP_DIR_CONF, name, buf, sizeof(buf)) < sizeof(buf)) {
+               if (!ppp_options_from_file(buf, 0, 0, 1)) {
+                       exit(EXIT_OPTION_ERROR);
+               }
+       } else {
+               exit(EXIT_OPTION_ERROR);
+       }
 }
 
 struct channel pppoe_channel;
@@ -396,14 +391,15 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
     /* Close socket */
     close(fd);
     if (r && doit) {
-       strlcpy(devnam, cmd, MAXPATHLEN);
+       strlcpy(devnam, cmd, sizeof(devnam));
        if (the_channel != &pppoe_channel) {
 
            the_channel = &pppoe_channel;
-           modem = 0;
+           ppp_set_modem(0);
 
            PPPOEInitDevice();
        }
+       ppp_set_devnam(devnam);
        return 1;
     }
 
@@ -422,11 +418,11 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
 void
 plugin_init(void)
 {
-    if (!ppp_available() && !new_style_driver) {
+    if (!ppp_check_kernel_support() && !new_style_driver) {
        fatal("Linux kernel does not support PPPoE -- are you running 2.4.x?");
     }
 
-    add_options(Options);
+    ppp_add_options(Options);
 
     info("PPPoE plugin from pppd %s", PPPD_VERSION);
 }
@@ -440,7 +436,7 @@ void pppoe_check_options(void)
        if (sscanf(pppoe_reqd_mac, "%x:%x:%x:%x:%x:%x",
                   &mac[0], &mac[1], &mac[2], &mac[3],
                   &mac[4], &mac[5]) != 6) {
-           option_error("cannot parse pppoe-mac option value");
+           ppp_option_error("cannot parse pppoe-mac option value");
            exit(EXIT_OPTION_ERROR);
        }
        for (i = 0; i < 6; ++i)
@@ -474,6 +470,9 @@ void pppoe_check_options(void)
 
     ccp_allowoptions[0].bsd_compress = 0;
     ccp_wantoptions[0].bsd_compress = 0;
+
+    conn->discoveryTimeout = pppoe_padi_timeout;
+    conn->discoveryAttempts = pppoe_padi_attempts;
 }
 
 struct channel pppoe_channel = {
@@ -482,8 +481,8 @@ struct channel pppoe_channel = {
     .check_options = pppoe_check_options,
     .connect = &PPPOEConnectDevice,
     .disconnect = &PPPOEDisconnectDevice,
-    .establish_ppp = &generic_establish_ppp,
-    .disestablish_ppp = &generic_disestablish_ppp,
+    .establish_ppp = &ppp_generic_establish,
+    .disestablish_ppp = &ppp_generic_disestablish,
     .send_config = NULL,
     .recv_config = &PPPOERecvConfig,
     .close = NULL,
index e048f66b5d2f6b4966076bd3a1fcd47cf48d18cb..3ea62d1cb4d9e79930ce46aa0c712bfc50ba1ed6 100644 (file)
@@ -81,6 +81,6 @@ version number and usage information, then exit.
 .RE
 .SH AUTHORS
 \fBpppoe\-discovery\fR was written by Marco d'Itri <md@linux.it>,
-based on \fBpppoe\fR by David F. Skoll <dfs@roaringpenguin.com>.
+based on \fBpppoe\fR by Dianne Skoll <dianne@skoll.ca>.
 .SH SEE ALSO
-pppoe(8), pppoe-sniff(8)
+pppoe(8), pppoe\-sniff(8)
index b698bca7b17fd56d68fa7e30c8de353056d41ad5..79ad805cfabd93c6119b9dc2d5e047b6fb3c384d 100644 (file)
@@ -22,6 +22,8 @@
 #include <time.h>
 #include <signal.h>
 #include <sys/time.h>
+#include <stdbool.h>
+#include <stdint.h>
 
 #include "pppoe.h"
 
@@ -31,7 +33,7 @@ int pppoe_verbose;
 static FILE *debugFile;
 
 void
-fatal(char *fmt, ...)
+fatal(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -42,7 +44,7 @@ fatal(char *fmt, ...)
 }
 
 void
-error(char *fmt, ...)
+error(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -52,7 +54,7 @@ error(char *fmt, ...)
 }
 
 void
-warn(char *fmt, ...)
+warn(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -62,7 +64,7 @@ warn(char *fmt, ...)
 }
 
 void
-info(char *fmt, ...)
+info(const char *fmt, ...)
 {
     va_list pvar;
     va_start(pvar, fmt);
@@ -124,6 +126,17 @@ get_time(struct timeval *tv)
     return gettimeofday(tv, NULL);
 }
 
+int signaled(int signal) {
+    if (signal == SIGTERM)
+        return got_sigterm;
+    return 0;
+}
+
+bool debug_on()
+{
+    return !!debug;
+}
+
 static void
 term_handler(int signum)
 {
@@ -245,7 +258,7 @@ int main(int argc, char *argv[])
        exit(1);
     }
 
-    discovery1(conn);
+    discovery1(conn, 1);
 
     if (!conn->numPADOs)
        exit(1);
index 1517e34f61ba07870113beff724885e654ef4d60..1952dcb2efccff60a7280d1829343b4e4c5d2fdf 100644 (file)
@@ -9,8 +9,6 @@
 * This program may be distributed according to the terms of the GNU
 * General Public License, version 2 or (at your option) any later version.
 *
-* $Id: pppoe.h,v 1.4 2008/06/15 04:35:50 paulus Exp $
-*
 ***********************************************************************/
 
 #include <stdio.h>             /* For FILE */
@@ -242,6 +240,7 @@ typedef struct PPPoEConnectionStruct {
     int storedmru;             /* Stored MRU */
     int mtu;
     int mru;
+    char *actualACname;                /* Name of AC we connected to */
 } PPPoEConnection;
 
 /* Structure used to determine acceptable PADO or PADS packet */
@@ -272,7 +271,7 @@ void initPPP(void);
 void clampMSS(PPPoEPacket *packet, char const *dir, int clampMss);
 UINT16_t computeTCPChecksum(unsigned char *ipHdr, unsigned char *tcpHdr);
 UINT16_t pppFCS16(UINT16_t fcs, unsigned char *cp, int len);
-void discovery1(PPPoEConnection *conn);
+void discovery1(PPPoEConnection *conn, int waitWholeTimeoutForPADO);
 void discovery2(PPPoEConnection *conn);
 unsigned char *findTag(PPPoEPacket *packet, UINT16_t tagType,
                       PPPoETag *tag);
@@ -322,3 +321,10 @@ do {\
 #define NOT_UNICAST(e) ((e[0] & 0x01) != 0)
 #define BROADCAST(e) ((e[0] & e[1] & e[2] & e[3] & e[4] & e[5]) == 0xFF)
 #define NOT_BROADCAST(e) ((e[0] & e[1] & e[2] & e[3] & e[4] & e[5]) != 0xFF)
+
+#ifndef MIN
+#define MIN(a, b)      ((a) < (b)? (a): (b))
+#endif
+#ifndef MAX
+#define MAX(a, b)      ((a) > (b)? (a): (b))
+#endif
index 2ba870716f62a3908f3b9098bdff4ac104e7c656..11600417afc7655708cb2e32ce0e78e59308de07 100644 (file)
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <signal.h>
 #include <linux/version.h>
 #include <linux/sockios.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
 
 #include <pppd/pppd.h>
-#include <pppd/pathnames.h>
+#include <pppd/options.h>
 #include <pppd/fsm.h>
 #include <pppd/lcp.h>
 #include <pppd/ccp.h>
 #include <pppd/ipcp.h>
+#include <pppd/multilink.h>
 
 
 #ifndef aligned_u64
@@ -49,7 +54,6 @@
 #include <linux/types.h>
 #include <linux/if_ether.h>
 #include <linux/ppp_defs.h>
-#include <linux/if_ppp.h>
 #include <linux/if_pppox.h>
 #include <linux/if_pppol2tp.h>
 
@@ -71,7 +75,9 @@ static void (*old_pppol2tp_send_accm_hook)(int tunnel_id, int session_id,
                                           uint32_t recv_accm) = NULL;
 static void (*old_pppol2tp_ip_updown_hook)(int tunnel_id, int session_id,
                                           int up) = NULL;
-static void (*old_multilink_join_hook)(void) = NULL;
+#ifdef PPP_WITH_MULTILINK
+static multilink_join_hook_fn *old_multilink_join_hook = NULL;
+#endif
 
 /*****************************************************************************
  * OpenL2TP interface.
@@ -177,8 +183,12 @@ static void openl2tp_ppp_updown_ind(int tunnel_id, int session_id, int up)
        uint16_t tid = tunnel_id;
        uint16_t sid = session_id;
        uint8_t state = up;
-       int unit = ifunit;
-       char *user_name = NULL;
+       int unit = 0;
+       char ifname[MAXNAMELEN];
+       char user_name[MAXNAMELEN];
+
+       unit = ppp_ifunit();
+       ppp_get_ifname(ifname, sizeof(ifname));
 
        if (openl2tp_fd < 0) {
                result = openl2tp_client_create();
@@ -187,9 +197,8 @@ static void openl2tp_ppp_updown_ind(int tunnel_id, int session_id, int up)
                }
        }
 
-       if (peer_authname[0] != '\0') {
-               user_name = strdup(peer_authname);
-       }
+       if (!ppp_peer_authname(user_name, sizeof(user_name)))
+               user_name[0] = '\0';
 
        msg->msg_signature = OPENL2TP_MSG_SIGNATURE;
        msg->msg_type = OPENL2TP_MSG_TYPE_PPP_UPDOWN_IND;
@@ -225,7 +234,7 @@ static void openl2tp_ppp_updown_ind(int tunnel_id, int session_id, int up)
        memcpy(&tlv->tlv_value[0], ifname, tlv->tlv_len);
        msg->msg_len += sizeof(*tlv) + ALIGN32(tlv->tlv_len);
 
-       if (user_name != NULL) {
+       if (user_name[0] != '\0') {
                tlv = (void *) &msg->msg_data[msg->msg_len];
                tlv->tlv_type = OPENL2TP_TLV_TYPE_PPP_USER_NAME;
                tlv->tlv_len = strlen(user_name) + 1;
@@ -249,9 +258,6 @@ out:
                (*old_pppol2tp_ip_updown_hook)(tunnel_id, session_id, up);
        }
 
-       if (user_name != NULL)
-               free(user_name);
-
        return;
 }
 
@@ -273,14 +279,16 @@ out:
  * multilink bundle.
  *****************************************************************************/
 
+#ifdef PPP_WITH_MULTILINK
 static void openl2tp_multilink_join_ind(void)
 {
-       if (doing_multilink && !multilink_master) {
+       if (mp_on() && !mp_master()) {
                /* send event only if not master */
                openl2tp_ppp_updown_ind(pppol2tp_tunnel_id,
                                        pppol2tp_session_id, 1);
        }
 }
+#endif
 
 /*****************************************************************************
  * Application init
@@ -294,7 +302,9 @@ void plugin_init(void)
        old_pppol2tp_ip_updown_hook = pppol2tp_ip_updown_hook;
        pppol2tp_ip_updown_hook = openl2tp_ppp_updown_ind;
 
+#ifdef PPP_WITH_MULTILINK
        old_multilink_join_hook = multilink_join_hook;
        multilink_join_hook = openl2tp_multilink_join_ind;
+#endif
 }
 
index c1eaa9afeb88e23df5ecdc52fd51ca21cb1e0aa9..3b9737ee04b9a37970bbe3d7919a6d90ac4489b9 100644 (file)
 #include <net/if.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <signal.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <stdio.h>
+
 #include <linux/version.h>
 #include <linux/sockios.h>
+#include <linux/ppp-ioctl.h>
 
 #ifndef aligned_u64
 /* should be defined in sys/types.h */
 #include <linux/types.h>
 #include <linux/if_ether.h>
 #include <linux/ppp_defs.h>
-#include <linux/if_ppp.h>
 #include <linux/if_pppox.h>
 #include <linux/if_pppol2tp.h>
 
 #include <pppd/pppd.h>
-#include <pppd/pathnames.h>
+#include <pppd/options.h>
 #include <pppd/fsm.h>
 #include <pppd/lcp.h>
 #include <pppd/ccp.h>
@@ -86,7 +92,7 @@ void (*pppol2tp_send_accm_hook)(int tunnel_id, int session_id,
 /* Hook provided to allow other plugins to handle IP up/down */
 void (*pppol2tp_ip_updown_hook)(int tunnel_id, int session_id, int up) = NULL;
 
-static option_t pppol2tp_options[] = {
+static struct option pppol2tp_options[] = {
        { "pppol2tp", o_special, &setdevname_pppol2tp,
          "FD for PPPoL2TP socket", OPT_DEVNAM | OPT_A2STRVAL,
           &pppol2tp_fd_str },
@@ -133,7 +139,7 @@ static int setdevname_pppol2tp(char **argv)
        if (device_got_set)
                return 0;
 
-       if (!int_option(*argv, &pppol2tp_fd))
+       if (!ppp_int_option(*argv, &pppol2tp_fd))
                return 0;
 
        if(getsockname(pppol2tp_fd, (struct sockaddr *)&s, &len) < 0) {
@@ -158,7 +164,7 @@ static int setdevname_pppol2tp(char **argv)
 
        /* Setup option defaults. Compression options are disabled! */
 
-       modem = 0;
+       ppp_set_modem(false);
 
        lcp_allowoptions[0].neg_accompression = 1;
        lcp_wantoptions[0].neg_accompression = 0;
@@ -199,7 +205,7 @@ static void disconnect_pppol2tp(void)
 }
 
 static void send_config_pppol2tp(int mtu,
-                             u_int32_t asyncmap,
+                             uint32_t asyncmap,
                              int pcomp,
                              int accomp)
 {
@@ -217,14 +223,14 @@ static void send_config_pppol2tp(int mtu,
                fd = socket(AF_INET, SOCK_DGRAM, 0);
                if (fd >= 0) {
                        memset (&ifr, '\0', sizeof (ifr));
-                       strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+                       ppp_get_ifname(ifr.ifr_name, sizeof(ifr.ifr_name));
                        strlcpy(ifr.ifr_newname, pppol2tp_ifname,
                                sizeof(ifr.ifr_name));
                        ioctl(fd, SIOCSIFNAME, (caddr_t) &ifr);
-                       strlcpy(ifname, pppol2tp_ifname, 32);
+                       ppp_set_ifname(pppol2tp_ifname);
                        if (pppol2tp_debug_mask & PPPOL2TP_MSG_CONTROL) {
                                dbglog("ppp%d: interface name %s",
-                                      ifunit, ifname);
+                                       ppp_ifunit(), ppp_ifname());
                        }
                }
                close(fd);
@@ -234,7 +240,7 @@ static void send_config_pppol2tp(int mtu,
                warn("Overriding mtu %d to %d", mtu, lcp_allowoptions[0].mru);
                mtu = lcp_allowoptions[0].mru;
        }
-       netif_set_mtu(ifunit, mtu);
+       ppp_set_mtu(ppp_ifunit(), mtu);
 
        reorderto[0] = '\0';
        if (pppol2tp_reorder_timeout > 0)
@@ -279,7 +285,7 @@ static void send_config_pppol2tp(int mtu,
 }
 
 static void recv_config_pppol2tp(int mru,
-                             u_int32_t asyncmap,
+                             uint32_t asyncmap,
                              int pcomp,
                              int accomp)
 {
@@ -288,7 +294,7 @@ static void recv_config_pppol2tp(int mru,
                     lcp_allowoptions[0].mru);
                mru = lcp_allowoptions[0].mru;
        }
-       if ((ifunit >= 0) && ioctl(pppol2tp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+       if ((ppp_ifunit() >= 0) && ioctl(pppol2tp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
                error("Couldn't set PPP MRU: %m");
 }
 
@@ -496,22 +502,22 @@ void plugin_init(void)
 {
 #if defined(__linux__)
        extern int new_style_driver;    /* From sys-linux.c */
-       if (!ppp_available() && !new_style_driver)
+       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
-       add_options(pppol2tp_options);
+       ppp_add_options(pppol2tp_options);
 
        /* Hook up ip up/down notifiers to send indicator to openl2tpd
         * that the link is up
         */
-       add_notifier(&ip_up_notifier, pppol2tp_ip_up, NULL);
-       add_notifier(&ip_down_notifier, pppol2tp_ip_down, NULL);
-#ifdef INET6
-       add_notifier(&ipv6_up_notifier, pppol2tp_ip_up, NULL);
-       add_notifier(&ipv6_down_notifier, pppol2tp_ip_down, NULL);
+       ppp_add_notify(NF_IP_UP, pppol2tp_ip_up, NULL);
+       ppp_add_notify(NF_IP_DOWN, pppol2tp_ip_down, NULL);
+#ifdef PPP_WITH_IPV6CP
+       ppp_add_notify(NF_IPV6_UP, pppol2tp_ip_up, NULL);
+       ppp_add_notify(NF_IPV6_DOWN, pppol2tp_ip_down, NULL);
 #endif
 }
 
@@ -521,8 +527,8 @@ struct channel pppol2tp_channel = {
     .check_options = &pppol2tp_check_options,
     .connect = &connect_pppol2tp,
     .disconnect = &disconnect_pppol2tp,
-    .establish_ppp = &generic_establish_ppp,
-    .disestablish_ppp = &generic_disestablish_ppp,
+    .establish_ppp = &ppp_generic_establish,
+    .disestablish_ppp = &ppp_generic_disestablish,
     .send_config = &send_config_pppol2tp,
     .recv_config = &recv_config_pppol2tp,
     .close = NULL,
index ec637ae7897e17ed85c020fbcf4de3f9e6c93004..3897e988bf49b851c6dc26d6777e380aeeb33589 100644 (file)
@@ -32,9 +32,6 @@ radius_la_CPPFLAGS = $(RADIUS_CPPFLAGS)
 radius_la_LDFLAGS = $(RADIUS_LDFLAGS)
 radius_la_SOURCES = radius.c
 radius_la_LIBADD = libradiusclient.la
-if WITH_OPENSSL
-radius_la_LIBADD += $(OPENSSL_LIBS)
-endif
 
 radattr_la_CPPFLAGS = $(RADIUS_CPPFLAGS)
 radattr_la_LDFLAGS = $(RADIUS_LDFLAGS)
@@ -46,18 +43,8 @@ radrealms_la_SOURCES = radrealms.c
 
 libradiusclient_la_SOURCES = \
     avpair.c buildreq.c config.c dict.c ip_util.c \
-       clientid.c sendserver.c lock.c util.c
-libradiusclient_la_CPPFLAGS = $(RADIUS_CPPFLAGS)
-
-if !WITH_OPENSSL
-libradiusclient_la_SOURCES += md5.c
-else
-if OPENSSL_HAVE_MD5
-libradiusclient_la_SOURCES += md5.c
-else
-libradiusclient_la_CPPFLAGS += $(OPENSSL_INCLUDES)
-endif
-endif
+       clientid.c sendserver.c lock.c util.c md5.c
+libradiusclient_la_CPPFLAGS = $(RADIUS_CPPFLAGS) -DSYSCONFDIR=\"${sysconfdir}\"
 
 EXTRA_DIST = \
     $(EXTRA_FILES) \
index 0dc9a85d13a6be0b4e8e939961e754e5a7ce2b00..5ad1cc902040b84c63528ea2eccc5600e079c876 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: avpair.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
@@ -31,7 +29,7 @@ static void rc_extract_vendor_specific_attributes(int attrlen,
  *
  */
 
-VALUE_PAIR *rc_avpair_add (VALUE_PAIR **list, int attrid, void *pval, int len,
+VALUE_PAIR *rc_avpair_add (VALUE_PAIR **list, int attrid, const void *pval, int len,
                           int vendorcode)
 {
        VALUE_PAIR     *vp;
@@ -57,7 +55,7 @@ VALUE_PAIR *rc_avpair_add (VALUE_PAIR **list, int attrid, void *pval, int len,
  *
  */
 
-int rc_avpair_assign (VALUE_PAIR *vp, void *pval, int len)
+int rc_avpair_assign (VALUE_PAIR *vp, const void *pval, int len)
 {
        int     result = -1;
 
@@ -65,19 +63,19 @@ int rc_avpair_assign (VALUE_PAIR *vp, void *pval, int len)
        {
                case PW_TYPE_STRING:
 
-                       if (((len == 0) && (strlen ((char *) pval)) > AUTH_STRING_LEN)
+                       if (((len == 0) && (strlen ((const char *) pval)) > AUTH_STRING_LEN)
                            || (len > AUTH_STRING_LEN)) {
                                error("rc_avpair_assign: bad attribute length");
                                return result;
                    }
 
                        if (len > 0) {
-                               memcpy(vp->strvalue, (char *)pval, len);
+                               memcpy(vp->strvalue, (const char *)pval, len);
                                vp->strvalue[len] = '\0';
                                vp->lvalue = len;
                        } else {
-                       strncpy ((char*) vp->strvalue, (char *) pval, AUTH_STRING_LEN);
-                       vp->lvalue = strlen((char *) pval);
+                       strncpy ((char*) vp->strvalue, (const char *) pval, AUTH_STRING_LEN);
+                       vp->lvalue = strlen((const char *) pval);
                        }
 
                        result = 0;
@@ -107,7 +105,7 @@ int rc_avpair_assign (VALUE_PAIR *vp, void *pval, int len)
  *
  */
 
-VALUE_PAIR *rc_avpair_new (int attrid, void *pval, int len, int vendorcode)
+VALUE_PAIR *rc_avpair_new (int attrid, const void *pval, int len, int vendorcode)
 {
        VALUE_PAIR     *vp = (VALUE_PAIR *) NULL;
        DICT_ATTR      *pda;
@@ -426,7 +424,7 @@ void rc_avpair_insert (VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
        else /* look for the "p" entry in the "a" list (or run to end) */
        {
                this_node = *a;
-               while (this_node != (VALUE_PAIR *) NULL)
+               while (this_node->next != (VALUE_PAIR *) NULL)
                {
                        if (this_node == p)
                        {
@@ -699,6 +697,7 @@ int rc_avpair_tostr (VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
        struct in_addr  inad;
        unsigned char         *ptr;
        char            *str;
+       time_t tmptime;
 
        *name = *value = '\0';
 
@@ -752,8 +751,9 @@ int rc_avpair_tostr (VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
                break;
 
            case PW_TYPE_DATE:
+               tmptime = pair->lvalue;
                strftime (buffer, sizeof (buffer), "%m/%d/%y %H:%M:%S",
-                         gmtime ((time_t *) & pair->lvalue));
+                         gmtime (&tmptime));
                strncpy(value, buffer, lv-1);
                break;
 
index 562790aa7887ea8d174021cce062a85abbcf843c..fe6a8543aea91d1148b3861416065388a810dedd 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: buildreq.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1997 Lars Fenneberg
  *
  * See the file COPYRIGHT for the respective terms and conditions.
@@ -327,7 +325,7 @@ int rc_acct_using_server(SERVER *acctserver,
        if ((adt_vp = rc_avpair_add(&(data.send_pairs), PW_ACCT_DELAY_TIME, &dtime.tv_sec, 0, VENDOR_NONE)) == NULL)
                return (ERROR_RC);
 
-       get_time(&start_time);
+       ppp_get_time(&start_time);
        result = ERROR_RC;
        for(i=0; (i<acctserver->max) && (result != OK_RC) && (result != BADRESP_RC)
                ; i++)
@@ -339,7 +337,7 @@ int rc_acct_using_server(SERVER *acctserver,
                rc_buildreq(&data, PW_ACCOUNTING_REQUEST, acctserver->name[i],
                            acctserver->port[i], timeout, retries);
 
-               get_time(&dtime);
+               ppp_get_time(&dtime);
                dtime.tv_sec -= start_time.tv_sec;
                rc_avpair_assign(adt_vp, &dtime.tv_sec, 0);
 
index 09ec3d04c56346e309d0c209690214dcbe9dd3d8..94a23a6f90b732978e8d795258cd2f7946b6ab0c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: clientid.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * See the file COPYRIGHT for the respective terms and conditions.
@@ -68,10 +66,15 @@ int rc_read_mapfile(char *filename)
 
                        if ((p = (struct map2id_s *)malloc(sizeof(*p))) == NULL) {
                                novm("rc_read_mapfile");
+                               fclose(mapfd);
                                return (-1);
                        }
 
-                       p->name = strdup(name);
+                       if ((p->name = strdup(name)) == NULL) {
+                               novm("rc_read_mapfile");
+                               fclose(mapfd);
+                               return (-1);
+                       }
                        p->id = atoi(id);
                        p->next = map2id_list;
                        map2id_list = p;
@@ -79,6 +82,7 @@ int rc_read_mapfile(char *filename)
                } else {
 
                        error("rc_read_mapfile: malformed line in %s, line %d", filename, lnr);
+                       fclose(mapfd);
                        return (-1);
 
                }
@@ -101,7 +105,7 @@ int rc_read_mapfile(char *filename)
  * Returns: port id, zero if no entry found
  */
 
-UINT4 rc_map2id(char *name)
+UINT4 rc_map2id(const char *name)
 {
        struct map2id_s *p;
        char ttyname[PATH_MAX];
index 47c172cccf00234b9bcc135a63a14e9a30c7006b..0499911d0243539e63a99d0552b96ec78dd3c70d 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: config.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
@@ -212,6 +210,7 @@ int rc_read_config(char *filename)
 
                if ((pos = strcspn(p, "\t ")) == 0) {
                        error("%s: line %d: bogus format: %s", filename, line, p);
+                       fclose(configfd);
                        return (-1);
                }
 
@@ -224,6 +223,7 @@ int rc_read_config(char *filename)
 
                if (option->status != ST_UNDEF) {
                        error("%s: line %d: duplicate option line: %s", filename, line, p);
+                       fclose(configfd);
                        return (-1);
                }
 
@@ -233,20 +233,28 @@ int rc_read_config(char *filename)
 
                switch (option->type) {
                        case OT_STR:
-                                if (set_option_str(filename, line, option, p) < 0)
+                               if (set_option_str(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_INT:
-                                if (set_option_int(filename, line, option, p) < 0)
+                               if (set_option_int(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_SRV:
-                                if (set_option_srv(filename, line, option, p) < 0)
+                               if (set_option_srv(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_AUO:
-                                if (set_option_auo(filename, line, option, p) < 0)
+                               if (set_option_auo(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        default:
                                fatal("rc_read_config: impossible case branch!");
index 6f2657d719ae4a3806c7e67eb85207640b171050..fca8a8baf9d3d6ab8bc1b391045a6c37631f3275 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: dict.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 2002 Roaring Penguin Software Inc.
  *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
index da3a317c019abafd6e2401946113eea17a411388..8c7d33cbdba03985fd90e37c68bc7b4005e8221b 100644 (file)
@@ -1,8 +1,6 @@
 #
 #      Microsoft's VSA's, from RFC 2548
 #
-#      $Id: dictionary.microsoft,v 1.1 2004/11/14 07:26:26 paulus Exp $
-#
 
 VENDOR         Microsoft       311     Microsoft
 
index 1e6d87a9173086202eb9fb32b6ea678e8abe3f09..dae1b3b9bb507ee9daea760692753a73a646b079 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: includes.h,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
index 1f6a76e480f935a8410188d079e8424bb45b5ea3..43a7ff0d26c3d779c6d9358364ca62bd50d525bd 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: ip_util.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
@@ -26,7 +24,7 @@
  * Returns: 0 on failure
  */
 
-UINT4 rc_get_ipaddr (char *host)
+UINT4 rc_get_ipaddr (const char *host)
 {
        struct hostent *hp;
 
@@ -51,7 +49,7 @@ UINT4 rc_get_ipaddr (char *host)
  *
  */
 
-int rc_good_ipaddr (char *addr)
+int rc_good_ipaddr (const char *addr)
 {
        int             dot_count;
        int             digit_count;
@@ -127,7 +125,7 @@ UINT4 rc_own_ipaddress(void)
        static UINT4 this_host_ipaddr = 0;
 
        if (!this_host_ipaddr) {
-               if ((this_host_ipaddr = rc_get_ipaddr (hostname)) == 0) {
+               if ((this_host_ipaddr = rc_get_ipaddr (ppp_hostname())) == 0) {
                        error("rc_own_ipaddress: couldn't get own IP address");
                        return 0;
                }
index 482e97cdb63127f62d4c6b5a8e7d3c43022cefd2..50e54faa1e5821eae3087bccb64bceb12329597e 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: lock.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1997 Lars Fenneberg
  *
  * See the file COPYRIGHT for the respective terms and conditions.
index 8acfb38c49a3a9e791f87ceccb9eedcabd067cbc..5038c9ae765d8ce3fe36496adaa56557a3ac4852 100644 (file)
@@ -1,13 +1,27 @@
-/*
- * $Id: md5.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- */
-#include <pppd/md5.h>
+#include <stddef.h>
 
-void rc_md5_calc (unsigned char *output, unsigned char *input, unsigned int inlen)
+#include <pppd/crypto.h>
+
+int rc_md5_calc(unsigned char *out, const unsigned char *in, unsigned int inl)
 {
-       MD5_CTX         context;
+    int retval = 0;
+    int outl = MD5_DIGEST_LENGTH;
+
+    PPP_MD_CTX *ctx = PPP_MD_CTX_new();
+    if (ctx) {
+
+        if (PPP_DigestInit(ctx, PPP_md5())) {
+
+            if (PPP_DigestUpdate(ctx, in, inl)) {
+
+                if (PPP_DigestFinal(ctx, out, &outl)) {
+
+                    retval = 1;
+                }
+            }
+        }
 
-       MD5_Init (&context);
-       MD5_Update (&context, input, inlen);
-       MD5_Final (output, &context);
+        PPP_MD_CTX_free(ctx);
+    }
+    return retval;
 }
index f4ad986a032efa472ebd2a6c49c2e66a1a816457..4842882503ce373fe246f8e66533d580742000c8 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: options.h,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1996 Lars Fenneberg
  *
  * See the file COPYRIGHT for the respective terms and conditions. 
index 5aa4c60b9c161211a52cdc1f0b501f17a546c03f..0a8495e71e91bef722579942f453534fbe318db2 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: pathnames.h,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
 #ifndef PATHNAMES_H
 #define PATHNAMES_H
 
-#define _PATH_DEV_URANDOM      "/dev/urandom"          /* Linux only */
-#define _PATH_ETC_ISSUE                "/etc/issue"
+#define PPP_PATH_DEV_URANDOM   "/dev/urandom"          /* Linux only */
+#define PPP_PATH_ETC_ISSUE             "/etc/issue"
 
 /* normally defined in the Makefile */
-#ifndef _PATH_ETC_RADIUSCLIENT_CONF
-#define _PATH_ETC_RADIUSCLIENT_CONF       "/etc/radiusclient.conf"
+#ifndef PPP_PATH_ETC_RADIUSCLIENT_CONF
+#define PPP_PATH_ETC_RADIUSCLIENT_CONF       SYSCONFDIR "/radiusclient.conf"
 #endif
 
 #endif /* PATHNAMES_H */
index 22d190bbdbc3fc48a12cfaa8a7875a23e9d3786d..5c54d2eb45415fc45cf5d96442afcd3b3aa9a67a 100644 (file)
@@ -1,5 +1,4 @@
 .\" manual page [] for RADATTR plugin for pppd 2.4
-.\" $Id: pppd-radattr.8,v 1.2 2003/04/25 07:33:20 fcusack Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
@@ -24,7 +23,7 @@ where
 .I pppN
 is the name of the PPP interface.  The RADIUS attributes are stored
 one per line in the format "Attribute-Name Attribute-Value".  This
-format is convenient for use in /etc/ppp/ip-up and /etc/ppp/ip-down
+format is convenient for use in /etc/ppp/ip\-up and /etc/ppp/ip\-down
 scripts.
 .LP
 Note that you
@@ -38,7 +37,7 @@ To use the plugin, simply supply the
 options to pppd.
 
 .SH SEE ALSO
-.BR pppd (8) " pppd-radius" (8)
+.BR pppd (8) " pppd\-radius" (8)
 
 .SH AUTHOR
-David F. Skoll <dfs@roaringpenguin.com>
+Dianne Skoll <dianne@skoll.ca>
index a8c103c274bdec6775a9dafe8d6c3b0835997f28..939385116887229a831afd7f1bc93ccb4c1df4bb 100644 (file)
@@ -1,5 +1,4 @@
 .\" manual page [] for RADIUS plugin for pppd 2.4
-.\" $Id: pppd-radius.8,v 1.5 2004/03/26 13:27:17 kad Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
@@ -19,9 +18,9 @@ plugin radius.so
 .LP
 The RADIUS plugin for pppd permits pppd to perform PAP, CHAP, MS-CHAP and
 MS-CHAPv2 authentication against a RADIUS server instead of the usual
-.I /etc/ppp/pap-secrets
+.I /etc/ppp/pap\-secrets
 and
-.I /etc/ppp/chap-secrets
+.I /etc/ppp/chap\-secrets
 files.
 .LP
 The RADIUS plugin is built on a library called
@@ -33,7 +32,7 @@ plugin
 .SH OPTIONS
 The RADIUS plugin introduces one additional pppd option:
 .TP
-.BI "radius-config-file " filename
+.BI "radius\-config\-file " filename
 The file
 .I filename
 is taken as the radiusclient configuration file.  If this option is not
@@ -44,10 +43,10 @@ as the configuration file.
 .BI "avpair " attribute=value
 Adds an Attribute-Value pair to be passed on to the RADIUS server on each request.
 .TP
-.BI map-to-ifname
+.BI map\-to\-ifname
 Sets Radius NAS-Port attribute to number equal to interface name (Default)
 .TP
-.BI map-to-ttyname
+.BI map\-to\-ttyname
 Sets Radius NAS-Port attribute value via libradiusclient library
 
 .SH USAGE
@@ -61,7 +60,7 @@ RADIUS server should assign an IP address to the peer using the RADIUS
 Framed-IP-Address attribute.
 
 .SH SEE ALSO
-.BR pppd (8) " pppd-radattr" (8)
+.BR pppd (8) " pppd\-radattr" (8)
 
 .SH AUTHOR
-David F. Skoll <dfs@roaringpenguin.com>
+Dianne Skoll <dianne@skoll.ca>
index 16f7fba0f1b1680bf986971ee9818291dd50367c..69ee766c19496bfb3d1b69f4a5ba8059858da70a 100644 (file)
 *
 ***********************************************************************/
 
-static char const RCSID[] =
-"$Id: radattr.c,v 1.2 2004/10/28 00:24:40 paulus Exp $";
-
 #include <stdio.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stdbool.h>
 #include <pppd/pppd.h>
 
 #include "radiusclient.h"
@@ -47,11 +48,11 @@ plugin_init(void)
     /* calling cleanup() on link down is problematic because print_attributes()
        is called only after PAP or CHAP authentication, but not when the link
        should go up again for any other reason */
-    add_notifier(&link_down_notifier, cleanup, NULL);
+    ppp_add_notify(NF_LINK_DOWN, cleanup, NULL);
 #endif
 
     /* Just in case... */
-    add_notifier(&exitnotify, cleanup, NULL);
+    ppp_add_notify(NF_EXIT, cleanup, NULL);
     info("RADATTR plugin initialized.");
 }
 
@@ -75,7 +76,7 @@ print_attributes(VALUE_PAIR *vp)
     int cnt = 0;
     mode_t old_umask;
 
-    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
+    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
     old_umask = umask(077);
     fp = fopen(fname, "w");
     umask(old_umask);
@@ -110,7 +111,7 @@ cleanup(void *opaque, int arg)
 {
     char fname[512];
 
-    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ifname);
+    slprintf(fname, sizeof(fname), "/var/run/radattr.%s", ppp_ifname());
     (void) remove(fname);
     dbglog("RADATTR plugin removed file %s.", fname);
 }
index 02875b4fec2069de9d31339b80df793bf8a709e5..cec02f4e678a42deb424e1e13cfc1d81898273a7 100644 (file)
@@ -23,8 +23,6 @@
 * General Public License, version 2 or (at your option) any later version.
 *
 ***********************************************************************/
-static char const RCSID[] =
-"$Id: radius.c,v 1.32 2008/05/26 09:18:08 paulus Exp $";
 
 #include <syslog.h>
 #include <sys/types.h>
@@ -33,16 +31,20 @@ static char const RCSID[] =
 #include <string.h>
 #include <netinet/in.h>
 #include <stdlib.h>
+#include <stdarg.h>
+#include <stdbool.h>
 
 #include <pppd/pppd.h>
-#include <pppd/chap-new.h>
+#include <pppd/options.h>
+#include <pppd/chap.h>
+#include <pppd/upap.h>
 #ifdef PPP_WITH_CHAPMS
 #include <pppd/chap_ms.h>
 #ifdef PPP_WITH_MPPE
 #include <pppd/mppe.h>
-#include <pppd/md5.h>
 #endif
 #endif
+#include <pppd/crypto.h>
 #include <pppd/fsm.h>
 #include <pppd/ipcp.h>
 
@@ -50,8 +52,6 @@ static char const RCSID[] =
 
 #define BUF_LEN 1024
 
-#define MD5_HASH_SIZE  16
-
 #define MSDNS 1
 
 static char *config_file = NULL;
@@ -72,28 +72,20 @@ static option_t Options[] = {
     { NULL }
 };
 
-static int radius_secret_check(void);
-static int radius_pap_auth(char *user,
-                          char *passwd,
-                          char **msgp,
-                          struct wordlist **paddrs,
-                          struct wordlist **popts);
-static int radius_chap_verify(char *user, char *ourname, int id,
-                             struct chap_digest_type *digest,
-                             unsigned char *challenge,
-                             unsigned char *response,
-                             char *message, int message_space);
+static pap_check_hook_fn radius_secret_check;
+static pap_auth_hook_fn radius_pap_auth;
+static chap_verify_hook_fn radius_chap_verify;
 
 static void radius_ip_up(void *opaque, int arg);
 static void radius_ip_down(void *opaque, int arg);
-static void make_username_realm(char *user);
+static void make_username_realm(const char *user);
 static int radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
                            struct chap_digest_type *digest,
                            unsigned char *challenge,
                            char *message, int message_space);
 static void radius_choose_ip(u_int32_t *addrp);
 static int radius_init(char *msg);
-static int get_client_port(char *ifname);
+static int get_client_port(const char *ifname);
 static int radius_allowed_address(u_int32_t addr);
 static void radius_acct_interim(void *);
 #ifdef PPP_WITH_MPPE
@@ -162,15 +154,15 @@ plugin_init(void)
     ip_choose_hook = radius_choose_ip;
     allowed_address_hook = radius_allowed_address;
 
-    add_notifier(&ip_up_notifier, radius_ip_up, NULL);
-    add_notifier(&ip_down_notifier, radius_ip_down, NULL);
+    ppp_add_notify(NF_IP_UP, radius_ip_up, NULL);
+    ppp_add_notify(NF_IP_DOWN, radius_ip_down, NULL);
 
     memset(&rstate, 0, sizeof(rstate));
 
     strlcpy(rstate.config_file, "/etc/radiusclient/radiusclient.conf",
            sizeof(rstate.config_file));
 
-    add_options(Options);
+    ppp_add_options(Options);
 
     info("RADIUS plugin initialized.");
 }
@@ -254,6 +246,8 @@ radius_pap_auth(char *user,
     UINT4 av_type;
     int result;
     static char radius_msg[BUF_LEN];
+    const char *remote_number;
+    const char *ipparam;
 
     radius_msg[0] = 0;
     *msgp = radius_msg;
@@ -276,7 +270,7 @@ radius_pap_auth(char *user,
 
     /* Hack... the "port" is the ppp interface number.  Should really be
        the tty */
-    rstate.client_port = get_client_port(portnummap ? devnam : ifname);
+    rstate.client_port = get_client_port(portnummap ? ppp_devnam() : ppp_ifname());
 
     av_type = PW_FRAMED;
     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
@@ -286,7 +280,9 @@ radius_pap_auth(char *user,
 
     rc_avpair_add(&send, PW_USER_NAME, rstate.user , 0, VENDOR_NONE);
     rc_avpair_add(&send, PW_USER_PASSWORD, passwd, 0, VENDOR_NONE);
-    if (*remote_number) {
+    remote_number = ppp_get_remote_number();
+    ipparam = ppp_ipparam();
+    if (remote_number) {
        rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0,
                       VENDOR_NONE);
     } else if (ipparam)
@@ -351,6 +347,8 @@ radius_chap_verify(char *user, char *ourname, int id,
 #else
     REQUEST_INFO *req_info = NULL;
 #endif
+    const char *remote_number;
+    const char *ipparam;
 
     challenge_len = *challenge++;
     response_len = *response++;
@@ -376,7 +374,7 @@ radius_chap_verify(char *user, char *ourname, int id,
     /* Put user with potentially realm added in rstate.user */
     if (!rstate.done_chap_once) {
        make_username_realm(user);
-       rstate.client_port = get_client_port (portnummap ? devnam : ifname);
+       rstate.client_port = get_client_port (portnummap ? ppp_devnam() : ppp_ifname());
        if (radius_pre_auth_hook) {
            radius_pre_auth_hook(rstate.user,
                                 &rstate.authserver,
@@ -400,15 +398,15 @@ radius_chap_verify(char *user, char *ourname, int id,
     switch (digest->code) {
     case CHAP_MD5:
        /* CHAP-Challenge and CHAP-Password */
-       if (response_len != MD5_HASH_SIZE)
+       if (response_len != MD5_DIGEST_LENGTH)
            return 0;
        cpassword[0] = id;
-       memcpy(&cpassword[1], response, MD5_HASH_SIZE);
+       memcpy(&cpassword[1], response, MD5_DIGEST_LENGTH);
 
        rc_avpair_add(&send, PW_CHAP_CHALLENGE,
                      challenge, challenge_len, VENDOR_NONE);
        rc_avpair_add(&send, PW_CHAP_PASSWORD,
-                     cpassword, MD5_HASH_SIZE + 1, VENDOR_NONE);
+                     cpassword, MD5_DIGEST_LENGTH + 1, VENDOR_NONE);
        break;
 
 #ifdef PPP_WITH_CHAPMS
@@ -453,7 +451,9 @@ radius_chap_verify(char *user, char *ourname, int id,
 #endif
     }
 
-    if (*remote_number) {
+    remote_number = ppp_get_remote_number();
+    ipparam = ppp_ipparam();
+    if (remote_number) {
        rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0,
                       VENDOR_NONE);
     } else if (ipparam)
@@ -506,7 +506,7 @@ radius_chap_verify(char *user, char *ourname, int id,
 * then the default realm from the radiusclient config file is added.
 ***********************************************************************/
 static void
-make_username_realm(char *user)
+make_username_realm(const char *user)
 {
     char *default_realm;
 
@@ -592,27 +592,27 @@ radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
 
            case PW_SESSION_TIMEOUT:
                /* Session timeout */
-               maxconnect = vp->lvalue;
+               ppp_set_max_connect_time(vp->lvalue);
                break;
            case PW_FILTER_ID:
                /* packet filter, will be handled via ip-(up|down) script */
-               script_setenv("RADIUS_FILTER_ID", (char*) vp->strvalue, 1);
+               ppp_script_setenv("RADIUS_FILTER_ID", (char*) vp->strvalue, 1);
                break;
            case PW_FRAMED_ROUTE:
                /* route, will be handled via ip-(up|down) script */
-               script_setenv("RADIUS_FRAMED_ROUTE", (char*) vp->strvalue, 1);
+               ppp_script_setenv("RADIUS_FRAMED_ROUTE", (char*) vp->strvalue, 1);
                break;
            case PW_IDLE_TIMEOUT:
                /* idle parameter */
-               idle_time_limit = vp->lvalue;
+               ppp_set_max_idle_time(vp->lvalue);
                break;
            case PW_SESSION_OCTETS_LIMIT:
                /* Session traffic limit */
-               maxoctets = vp->lvalue;
+               ppp_set_session_limit(vp->lvalue);
                break;
            case PW_OCTETS_DIRECTION:
                /* Session traffic limit direction check */
-               maxoctets_dir = ( vp->lvalue > 4 ) ? 0 : vp->lvalue ;
+               ppp_set_session_limit_dir(vp->lvalue);
                break;
            case PW_ACCT_INTERIM_INTERVAL:
                /* Send accounting updates every few seconds */
@@ -633,7 +633,7 @@ radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
                } else if (remote != 0xfffffffe) {
                    /* 0xfffffffe means NAS should select an ip address */
                    remote = htonl(vp->lvalue);
-                   if (bad_ip_adrs (remote)) {
+                   if (ppp_bad_ip_addr (remote)) {
                        slprintf(msg, BUF_LEN, "RADIUS: bad remote IP address %I for %s",
                                 remote, rstate.user);
                        return -1;
@@ -647,13 +647,14 @@ radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info,
                 break;
            case PW_CLASS:
                /* Save Class attribute to pass it in accounting request */
-               if (vp->lvalue <= MAXCLASSLEN) {
+               // if (vp->lvalue <= MAXCLASSLEN) { // <- Attribute could be this big, but vp->strvalue is limited to AUTH_STRING_LEN characters
+               if (vp->lvalue <= AUTH_STRING_LEN) {
                    rstate.class_len=vp->lvalue;
                    memcpy(rstate.class, vp->strvalue, rstate.class_len);
                } /* else too big for our buffer - ignore it */
                break;
            case PW_FRAMED_MTU:
-               netif_set_mtu(rstate.client_port,MIN(netif_get_mtu(rstate.client_port),vp->lvalue));
+               ppp_set_mtu(rstate.client_port,MIN(ppp_get_mtu(rstate.client_port),vp->lvalue));
                break;
            }
 
@@ -772,9 +773,12 @@ radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info,
                   unsigned char *challenge)
 {
     int i;
-    MD5_CTX Context;
-    u_char  plain[32];
-    u_char  buf[16];
+    int status = 0;
+    PPP_MD_CTX *ctx;
+    unsigned char plain[32];
+    unsigned char buf[MD5_DIGEST_LENGTH];
+    unsigned int  buflen;
+
 
     if (vp->lvalue != 32) {
        error("RADIUS: Incorrect attribute length (%d) for MS-CHAP-MPPE-Keys",
@@ -784,30 +788,70 @@ radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info,
 
     memcpy(plain, vp->strvalue, sizeof(plain));
 
-    MD5_Init(&Context);
-    MD5_Update(&Context, req_info->secret, strlen(req_info->secret));
-    MD5_Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN);
-    MD5_Final(buf, &Context);
+    ctx = PPP_MD_CTX_new();
+    if (ctx) {
 
-    for (i = 0; i < 16; i++)
-       plain[i] ^= buf[i];
+        if (PPP_DigestInit(ctx, PPP_md5())) {
 
-    MD5_Init(&Context);
-    MD5_Update(&Context, req_info->secret, strlen(req_info->secret));
-    MD5_Update(&Context, vp->strvalue, 16);
-    MD5_Final(buf, &Context);
+            if (PPP_DigestUpdate(ctx, req_info->secret, strlen(req_info->secret))) {
 
-    for(i = 0; i < 16; i++)
-       plain[i + 16] ^= buf[i];
+                if (PPP_DigestUpdate(ctx, req_info->request_vector, AUTH_VECTOR_LEN)) {
 
-    /*
-     * Annoying.  The "key" returned is just the NTPasswordHashHash, which
-     * the NAS (us) doesn't need; we only need the start key.  So we have
-     * to generate the start key, sigh.  NB: We do not support the LM-Key.
-     */
-    mppe_set_chapv1(challenge, &plain[8]);
+                    buflen = sizeof(buf);
+                    if (PPP_DigestFinal(ctx, buf, &buflen)) {
+
+                        status = 1;
+                    }
+                }
+            }
+        }
+        PPP_MD_CTX_free(ctx);
+    }
+
+    if (status) {
+
+        for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
+            plain[i] ^= buf[i];
+        }
+
+        status = 0;
+        ctx = PPP_MD_CTX_new();
+        if (ctx) {
+
+            if (PPP_DigestInit(ctx, PPP_md5())) {
+
+                if (PPP_DigestUpdate(ctx, req_info->secret, strlen(req_info->secret))) {
 
-    return 0;    
+                    if (PPP_DigestUpdate(ctx, vp->strvalue, 16)) {
+
+                        buflen = MD5_DIGEST_LENGTH;
+                        if (PPP_DigestFinal(ctx, buf, &buflen)) {
+
+                            status = 1;
+                        }
+                    }
+                }
+            }
+            PPP_MD_CTX_free(ctx);
+        }
+
+        if (status) {
+
+            for(i = 0; i < MD5_DIGEST_LENGTH; i++) {
+                plain[i + 16] ^= buf[i];
+            }
+
+            /*
+             * Annoying.  The "key" returned is just the NTPasswordHashHash, which
+             * the NAS (us) doesn't need; we only need the start key.  So we have
+             * to generate the start key, sigh.  NB: We do not support the LM-Key.
+             */
+            mppe_set_chapv1(challenge, &plain[8]);
+            return 0;
+        }
+    }
+
+    return -1;
 }
 
 /**********************************************************************
@@ -825,11 +869,13 @@ static int
 radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info)
 {
     int i;
-    MD5_CTX Context;
-    u_char  *salt = vp->strvalue;
-    u_char  *crypt = vp->strvalue + 2;
-    u_char  plain[32];
-    u_char  buf[MD5_HASH_SIZE];
+    int status = 0;
+    PPP_MD_CTX *ctx;
+    unsigned char *salt = vp->strvalue;
+    unsigned char *crypt = vp->strvalue + 2;
+    unsigned char plain[32];
+    unsigned char buf[MD5_DIGEST_LENGTH];
+    unsigned int  buflen;
     char    *type = "Send";
 
     if (vp->attribute == PW_MS_MPPE_RECV_KEY)
@@ -848,33 +894,75 @@ radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info)
 
     memcpy(plain, crypt, 32);
 
-    MD5_Init(&Context);
-    MD5_Update(&Context, req_info->secret, strlen(req_info->secret));
-    MD5_Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN);
-    MD5_Update(&Context, salt, 2);
-    MD5_Final(buf, &Context);
+    ctx = PPP_MD_CTX_new();
+    if (!ctx) {
+       error("RADIUS: Error creating PPP_MD_CTX for MS-MPPE-%s-Key attribute", type);
+       return -1;
+    }
 
-    for (i = 0; i < 16; i++)
+    buflen = sizeof(buf);
+    if (!PPP_DigestInit(ctx, PPP_md5())) {
+       error("RADIUS: Error setting hash algorithm to MD5 for MS-MPPE-%s-Key attribute", type);
+    } else if (!PPP_DigestUpdate(ctx, req_info->secret, strlen(req_info->secret))) {
+       error("RADIUS: Error mixing in radius secret for MS-MPPE-%s-Key attribute", type);
+    } else if (!PPP_DigestUpdate(ctx, req_info->request_vector, AUTH_VECTOR_LEN)) {
+       error("RADIUS: Error mixing in request vector for MS-MPPE-%s-Key attribute", type);
+    } else if (!PPP_DigestUpdate(ctx, salt, 2)) {
+       error("RADIUS: Error mixing in salt for MS-MPPE-%s-Key attribute", type);
+    } else if (!PPP_DigestFinal(ctx, buf, &buflen)) {
+       error("RADIUS: Error finalizing key buffer for MS-MPPE-%s-Key attribute", type);
+    } else {
+       status = 1;
+    }
+
+    PPP_MD_CTX_free(ctx);
+
+    if (!status)
+       return -1;
+
+    for (i = 0; i < 16; i++) {
        plain[i] ^= buf[i];
+    }
 
     if (plain[0] != 16) {
        error("RADIUS: Incorrect key length (%d) for MS-MPPE-%s-Key attribute",
-             (int) plain[0], type);
+               (int) plain[0], type);
        return -1;
     }
 
-    MD5_Init(&Context);
-    MD5_Update(&Context, req_info->secret, strlen(req_info->secret));
-    MD5_Update(&Context, crypt, 16);
-    MD5_Final(buf, &Context);
+    status = 0;
+    ctx = PPP_MD_CTX_new();
+    if (!ctx) {
+       error("RADIUS: Error creating PPP_MD_CTX for MS-MPPE-%s-Key(2) attribute", type);
+       return -1;
+    }
+
+    buflen = sizeof(buf);
+
+    if (!PPP_DigestInit(ctx, PPP_md5())) {
+       error("RADIUS: Error setting hash algorithm to MD5 for MS-MPPE-%s-Key(2) attribute", type);
+    } else if (!PPP_DigestUpdate(ctx, req_info->secret, strlen(req_info->secret))) {
+       error("RADIUS: Error mixing in radius secret for MS-MPPE-%s-Key(2) attribute", type);
+    } else if (!PPP_DigestUpdate(ctx, crypt, 16)) {
+       error("RADIUS: Error mixing in crypt vector for MS-MPPE-%s-Key(2) attribute", type);
+    } else if (!PPP_DigestFinal(ctx, buf, &buflen)) {
+       error("RADIUS: Error finalizing key buffer for MS-MPPE-%s-Key(2) attribute", type);
+    } else {
+       status = 1;
+    }
+
+    PPP_MD_CTX_free(ctx);
+
+    if (!status)
+       return -1;
 
     plain[16] ^= buf[0]; /* only need the first byte */
 
-    if (vp->attribute == PW_MS_MPPE_SEND_KEY)
+    if (vp->attribute == PW_MS_MPPE_SEND_KEY) {
        mppe_set_keys(plain + 1, NULL, 16);
-    else
+    } else {
        mppe_set_keys(NULL, plain + 1, 16);
-
+    }
     return 0;
 }
 #endif /* PPP_WITH_MPPE */
@@ -896,6 +984,8 @@ radius_acct_start(void)
     VALUE_PAIR *send = NULL;
     ipcp_options *ho = &ipcp_hisoptions[0];
     u_int32_t hisaddr;
+    const char *remote_number;
+    const char *ipparam;
 
     if (!rstate.initialized) {
        return;
@@ -923,7 +1013,9 @@ radius_acct_start(void)
     av_type = PW_PPP;
     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
 
-    if (*remote_number) {
+    remote_number = ppp_get_remote_number();
+    ipparam = ppp_ipparam();
+    if (remote_number) {
        rc_avpair_add(&send, PW_CALLING_STATION_ID,
                       remote_number, 0, VENDOR_NONE);
     } else if (ipparam)
@@ -933,7 +1025,7 @@ radius_acct_start(void)
     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
 
 
-    av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) );
+    av_type = ( ppp_using_pty() ? PW_VIRTUAL : ( ppp_sync_serial() ? PW_SYNC : PW_ASYNC ) );
     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
 
     hisaddr = ho->hisaddr;
@@ -961,7 +1053,7 @@ radius_acct_start(void)
 
     /* Kick off periodic accounting reports */
     if (rstate.acct_interim_interval) {
-       TIMEOUT(radius_acct_interim, NULL, rstate.acct_interim_interval);
+       ppp_timeout(radius_acct_interim, NULL, rstate.acct_interim_interval, 0);
     }
 }
 
@@ -982,13 +1074,16 @@ radius_acct_stop(void)
     ipcp_options *ho = &ipcp_hisoptions[0];
     u_int32_t hisaddr;
     int result;
+    const char *remote_number;
+    const char *ipparam;
+    ppp_link_stats_st stats;
 
     if (!rstate.initialized) {
        return;
     }
 
     if (rstate.acct_interim_interval)
-       UNTIMEOUT(radius_acct_interim, NULL);
+       ppp_untimeout(radius_acct_interim, NULL);
 
     rc_avpair_add(&send, PW_ACCT_SESSION_ID, rstate.session_id,
                   0, VENDOR_NONE);
@@ -1011,50 +1106,55 @@ radius_acct_stop(void)
     av_type = PW_RADIUS;
     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
 
+    if (ppp_get_link_stats(&stats)) {
 
-    if (link_stats_valid) {
-       av_type = link_connect_time;
+       av_type = ppp_get_link_uptime();
        rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);
 
-       av_type = link_stats.bytes_out & 0xFFFFFFFF;
+       av_type = stats.bytes_out & 0xFFFFFFFF;
        rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);
 
-       if (link_stats.bytes_out > 0xFFFFFFFF) {
-           av_type = link_stats.bytes_out >> 32;
+       if (stats.bytes_out > 0xFFFFFFFF) {
+           av_type = stats.bytes_out >> 32;
            rc_avpair_add(&send, PW_ACCT_OUTPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);
        }
 
-       av_type = link_stats.bytes_in & 0xFFFFFFFF;
+       av_type = stats.bytes_in & 0xFFFFFFFF;
        rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);
 
-       if (link_stats.bytes_in > 0xFFFFFFFF) {
-           av_type = link_stats.bytes_in >> 32;
+       if (stats.bytes_in > 0xFFFFFFFF) {
+           av_type = stats.bytes_in >> 32;
            rc_avpair_add(&send, PW_ACCT_INPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);
        }
 
-       av_type = link_stats.pkts_out;
+       av_type = stats.pkts_out;
        rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);
 
-       av_type = link_stats.pkts_in;
+       av_type = stats.pkts_in;
        rc_avpair_add(&send, PW_ACCT_INPUT_PACKETS, &av_type, 0, VENDOR_NONE);
     }
 
-    if (*remote_number) {
+    remote_number = ppp_get_remote_number();
+    ipparam = ppp_ipparam();
+    if (remote_number) {
        rc_avpair_add(&send, PW_CALLING_STATION_ID,
                       remote_number, 0, VENDOR_NONE);
     } else if (ipparam)
        rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE);
 
-    av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) );
+    av_type = ( ppp_using_pty() ? PW_VIRTUAL : ( ppp_sync_serial() ? PW_SYNC : PW_ASYNC ) );
     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
 
     av_type = PW_NAS_ERROR;
-    switch( status ) {
+    switch( ppp_status() ) {
        case EXIT_OK:
-       case EXIT_USER_REQUEST:
            av_type = PW_USER_REQUEST;
            break;
 
+       case EXIT_USER_REQUEST:
+           av_type = PW_ADMIN_RESET;
+           break;
+
        case EXIT_HANGUP:
        case EXIT_PEER_DEAD:
        case EXIT_CONNECT_FAILED:
@@ -1137,6 +1237,9 @@ radius_acct_interim(void *ignored)
     ipcp_options *ho = &ipcp_hisoptions[0];
     u_int32_t hisaddr;
     int result;
+    const char *remote_number;
+    const char *ipparam;
+    ppp_link_stats_st stats;
 
     if (!rstate.initialized) {
        return;
@@ -1163,45 +1266,43 @@ radius_acct_interim(void *ignored)
     av_type = PW_RADIUS;
     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
 
-    /* Update link stats */
-    update_link_stats(0);
-
-    if (link_stats_valid) {
-       link_stats_valid = 0; /* Force later code to update */
+    if (ppp_get_link_stats(&stats)) {
 
-       av_type = link_connect_time;
+       av_type = ppp_get_link_uptime();
        rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);
 
-       av_type = link_stats.bytes_out & 0xFFFFFFFF;
+       av_type = stats.bytes_out & 0xFFFFFFFF;
        rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);
 
-       if (link_stats.bytes_out > 0xFFFFFFFF) {
-           av_type = link_stats.bytes_out >> 32;
+       if (stats.bytes_out > 0xFFFFFFFF) {
+           av_type = stats.bytes_out >> 32;
            rc_avpair_add(&send, PW_ACCT_OUTPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);
        }
 
-       av_type = link_stats.bytes_in & 0xFFFFFFFF;
+       av_type = stats.bytes_in & 0xFFFFFFFF;
        rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);
 
-       if (link_stats.bytes_in > 0xFFFFFFFF) {
-           av_type = link_stats.bytes_in >> 32;
+       if (stats.bytes_in > 0xFFFFFFFF) {
+           av_type = stats.bytes_in >> 32;
            rc_avpair_add(&send, PW_ACCT_INPUT_GIGAWORDS, &av_type, 0, VENDOR_NONE);
        }
 
-       av_type = link_stats.pkts_out;
+       av_type = stats.pkts_out;
        rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);
 
-       av_type = link_stats.pkts_in;
+       av_type = stats.pkts_in;
        rc_avpair_add(&send, PW_ACCT_INPUT_PACKETS, &av_type, 0, VENDOR_NONE);
     }
 
-    if (*remote_number) {
+    remote_number = ppp_get_remote_number();
+    ipparam = ppp_ipparam();
+    if (remote_number) {
        rc_avpair_add(&send, PW_CALLING_STATION_ID,
                       remote_number, 0, VENDOR_NONE);
     } else if (ipparam)
        rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE);
 
-    av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) );
+    av_type = ( ppp_using_pty() ? PW_VIRTUAL : ( ppp_sync_serial() ? PW_SYNC : PW_ASYNC ) );
     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
 
     hisaddr = ho->hisaddr;
@@ -1227,7 +1328,7 @@ radius_acct_interim(void *ignored)
     rc_avpair_free(send);
 
     /* Schedule another one */
-    TIMEOUT(radius_acct_interim, NULL, rstate.acct_interim_interval);
+    ppp_timeout(radius_acct_interim, NULL, rstate.acct_interim_interval, 0);
 }
 
 /**********************************************************************
@@ -1324,7 +1425,7 @@ radius_init(char *msg)
 *  Extracts the port number from the interface name
 ***********************************************************************/
 static int
-get_client_port(char *ifname)
+get_client_port(const char *ifname)
 {
     int port;
     if (sscanf(ifname, "ppp%d", &port) == 1) {
index 96449be22cab468abb3ba695fe9f2f93296e8adb..0af23ac349240b049e1c2804084a292ac4721484 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: radiusclient.h,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997,1998 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
 #include <sys/types.h>
 #include <stdio.h>
 #include <time.h>
+#include <stdbool.h>
+
 #include <pppd/pppd.h>
+#include <pppd/options.h>
 
 #ifndef _UINT4_T
 /* This works for all machines that Linux runs on... */
@@ -399,9 +400,9 @@ typedef struct env
 
 /*     avpair.c                */
 
-VALUE_PAIR *rc_avpair_add(VALUE_PAIR **, int, void *, int, int);
-int rc_avpair_assign(VALUE_PAIR *, void *, int);
-VALUE_PAIR *rc_avpair_new(int, void *, int, int);
+VALUE_PAIR *rc_avpair_add(VALUE_PAIR **, int, const void *, int, int);
+int rc_avpair_assign(VALUE_PAIR *, const void *, int);
+VALUE_PAIR *rc_avpair_new(int, const void *, int, int);
 VALUE_PAIR *rc_avpair_gen(AUTH_HDR *);
 VALUE_PAIR *rc_avpair_get(VALUE_PAIR *, UINT4);
 VALUE_PAIR *rc_avpair_copy(VALUE_PAIR *);
@@ -427,7 +428,7 @@ int rc_check(char *, unsigned short, char *);
 /*     clientid.c              */
 
 int rc_read_mapfile(char *);
-UINT4 rc_map2id(char *);
+UINT4 rc_map2id(const char *);
 
 /*     config.c                */
 
@@ -449,8 +450,8 @@ VENDOR_DICT * rc_dict_getvendor(int);
 
 /*     ip_util.c               */
 
-UINT4 rc_get_ipaddr(char *);
-int rc_good_ipaddr(char *);
+UINT4 rc_get_ipaddr(const char *);
+int rc_good_ipaddr(const char *);
 const char *rc_ip_hostname(UINT4);
 UINT4 rc_own_ipaddress(void);
 UINT4 rc_own_bind_ipaddress(void);
@@ -468,6 +469,6 @@ void rc_mdelay(int);
 
 /* md5.c                       */
 
-void rc_md5_calc(unsigned char *, unsigned char *, unsigned int);
+int rc_md5_calc(unsigned char *out, const unsigned char *in, unsigned int inl);
 
 #endif /* RADIUSCLIENT_H */
index 27955e06d079c4a9caaee048a7fe3cc490ae7a06..2702a40b084a574bec435f1591ce307a546fcf1a 100644 (file)
 *
 */
 
-static char const RCSID[] =
-    "$Id: radrealms.c,v 1.2 2004/11/14 07:26:26 paulus Exp $";
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <sys/param.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <sys/types.h>
+
 #include <pppd/pppd.h>
 
 #include "radiusclient.h"
@@ -69,7 +71,7 @@ lookup_realm(char const *user,
     }
     
     if ((fd = fopen(radrealms_config, "r")) == NULL) {
-       option_error("cannot open %s", radrealms_config);
+       ppp_option_error("cannot open %s", radrealms_config);
        free(auths);
        free(accts);
        return;
@@ -89,7 +91,7 @@ lookup_realm(char const *user,
        if (p == NULL || (strcmp(p, "authserver") !=0
            && strcmp(p, "acctserver"))) {
            fclose(fd);
-           option_error("%s: invalid line %d: %s", radrealms_config,
+           ppp_option_error("%s: invalid line %d: %s", radrealms_config,
                         line, buffer);
            free(auths);
            free(accts);
@@ -105,7 +107,7 @@ lookup_realm(char const *user,
 
        if ((p = strtok(NULL, "\t ")) == NULL) {
            fclose(fd);
-           option_error("%s: realm name missing on line %d: %s",
+           ppp_option_error("%s: realm name missing on line %d: %s",
                         radrealms_config, line, buffer);
            free(auths);
            free(accts);
@@ -117,7 +119,7 @@ lookup_realm(char const *user,
            info(" - Matched realm %s", p);
            if ((p = strtok(NULL, ":")) == NULL) {
                fclose(fd);
-               option_error("%s: server address missing on line %d: %s",
+               ppp_option_error("%s: server address missing on line %d: %s",
                             radrealms_config, line, buffer);
                free(auths);
                free(accts);
@@ -127,7 +129,7 @@ lookup_realm(char const *user,
            info(" - Address is '%s'",p);
            if ((p = strtok(NULL, "\t ")) == NULL) {
                fclose(fd);
-               option_error("%s: server port missing on line %d:  %s",
+               ppp_option_error("%s: server port missing on line %d:  %s",
                             radrealms_config, line, buffer);
                free(auths);
                free(accts);
@@ -143,9 +145,13 @@ lookup_realm(char const *user,
 
     if (accts->max)
        *acctserver = accts;
+    else
+       free(accts);
 
     if (auths->max)
        *authserver = auths;
+    else
+       free(auths);
 
     return;
 }
@@ -155,6 +161,6 @@ plugin_init(void)
 {
     radius_pre_auth_hook = lookup_realm;
 
-    add_options(Options);
+    ppp_add_options(Options);
     info("RADIUS Realms plugin initialized.");
 }
index f6012868e2dbbbcb6de5f3a4806088d0c9f761a9..54648958ced2088250bc0508253e308efce8dcfa 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: sendserver.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
@@ -17,6 +15,7 @@
 #include <includes.h>
 #include <radiusclient.h>
 #include <pathnames.h>
+#include <signal.h>
 
 static void rc_random_vector (unsigned char *);
 static int rc_check_reply (AUTH_HDR *, int, char *, unsigned char *, unsigned char);
@@ -303,7 +302,7 @@ int rc_send_server (SEND_DATA *data, char *msg, REQUEST_INFO *info)
                FD_SET (sockfd, &readfds);
                if (select (sockfd + 1, &readfds, NULL, NULL, &authtime) < 0)
                {
-                       if (errno == EINTR && !got_sigterm)
+                       if (errno == EINTR && !ppp_signaled(SIGTERM))
                                continue;
                        error("rc_send_server: select: %m");
                        memset (secret, '\0', sizeof (secret));
@@ -491,7 +490,7 @@ static void rc_random_vector (unsigned char *vector)
    we use /dev/urandom here, as /dev/random might block and we don't
    need that much randomness. BTW, great idea, Ted!     -lf, 03/18/95  */
 
-       if ((fd = open(_PATH_DEV_URANDOM, O_RDONLY)) >= 0)
+       if ((fd = open(PPP_PATH_DEV_URANDOM, O_RDONLY)) >= 0)
        {
                unsigned char *pos;
                int readcount;
index 4065724926ae44a1a1433a2b0ef25e01e9ec35bc..aaadb283d41e079b99476a6f4fc3ad08f7309387 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: util.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
- *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
index 71c0d038fbaa4e852ddfd90a3c7d0fae72e5c54f..7af6ed1ae5effad2b200601ed678ae0805b23645 100644 (file)
@@ -7,9 +7,10 @@
 * 
 * Based on the structure of the radius module.
 *
+* Copyright 1999-2024 Paul Mackerras <paulus@ozlabs.org>
 * Copyright (C) 2003 Andrew Bartlet <abartlet@samba.org>
 *
-* Copyright 1999 Paul Mackerras, Alan Curry. 
+* Copyright 1999 Alan Curry.
 * (pipe read code from passpromt.c)
 *
 * Copyright (C) 2002 Roaring Penguin Software Inc.
 #include <stdlib.h>
 #include <errno.h>
 #include <ctype.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
 
 #include <pppd/pppd.h>
-#include <pppd/chap-new.h>
+#include <pppd/options.h>
+#include <pppd/chap.h>
 #include <pppd/chap_ms.h>
+#include <pppd/upap.h>
 #include <pppd/fsm.h>
 #include <pppd/ipcp.h>
 #include <pppd/mppe.h>
+#include <pppd/crypto.h>
 
 #define BUF_LEN 1024
 
@@ -66,7 +74,7 @@ static int set_ntlm_auth(char **argv)
 
        p = argv[0];
        if (p[0] != '/') {
-               option_error("ntlm_auth-helper argument must be full path");
+               ppp_option_error("ntlm_auth-helper argument must be full path");
                return 0;
        }
        p = strdup(p);
@@ -80,26 +88,16 @@ static int set_ntlm_auth(char **argv)
        return 1;
 }
 
-static option_t Options[] = {
+static struct option Options[] = {
        { "ntlm_auth-helper", o_special, (void *) &set_ntlm_auth,
          "Path to ntlm_auth executable", OPT_PRIV },
        { NULL }
 };
 
-static int
-winbind_secret_check(void);
-
-static int winbind_pap_auth(char *user,
-                          char *passwd,
-                          char **msgp,
-                          struct wordlist **paddrs,
-                          struct wordlist **popts);
-static int winbind_chap_verify(char *user, char *ourname, int id,
-                              struct chap_digest_type *digest,
-                              unsigned char *challenge,
-                              unsigned char *response,
-                              char *message, int message_space);
-static int winbind_allowed_address(u_int32_t addr); 
+static pap_check_hook_fn winbind_secret_check;
+static pap_auth_hook_fn winbind_pap_auth;
+static chap_verify_hook_fn winbind_chap_verify;
+static int winbind_allowed_address(uint32_t addr);
 
 char pppd_version[] = PPPD_VERSION;
 
@@ -126,7 +124,7 @@ plugin_init(void)
     /* Don't ask the peer for anything other than MS-CHAP or MS-CHAP V2 */
     chap_mdtype_all &= (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT);
     
-    add_options(Options);
+    ppp_add_options(Options);
 
     info("WINBIND plugin initialized.");
 }
@@ -284,7 +282,7 @@ unsigned int run_ntlm_auth(const char *username,
                return NOT_AUTHENTICATED;
         }
 
-        forkret = safe_fork(child_in[0], child_out[1], 2);
+        forkret = ppp_safe_fork(child_in[0], child_out[1], 2);
         if (forkret == -1) {
                if (error_string) {
                        *error_string = strdup("fork failed!");
@@ -435,19 +433,19 @@ unsigned int run_ntlm_auth(const char *username,
        }
 
         /* parent */
-        if (close(child_out[0]) == -1) {
-                close(child_in[1]);
+        if (fclose(pipe_out) == -1) {
+                fclose(pipe_in);
                 notice("error closing pipe?!? for child OUT[0]");
                 return NOT_AUTHENTICATED;
         }
 
        /* parent */
-        if (close(child_in[1]) == -1) {
+        if (fclose(pipe_in) == -1) {
                 notice("error closing pipe?!? for child IN[1]");
                 return NOT_AUTHENTICATED;
         }
 
-       while ((wait(&status) == -1) && errno == EINTR && !got_sigterm)
+       while ((wait(&status) == -1) && errno == EINTR && !ppp_signaled(SIGTERM))
                 ;
 
        if ((authenticated == AUTHENTICATED) && nt_key && !got_user_session_key) {
@@ -522,7 +520,7 @@ winbind_chap_verify(char *user, char *ourname, int id,
        int challenge_len, response_len;
        char domainname[256];
        char *domain;
-       char *username;
+       const char *username;
        char *p;
        unsigned char saresponse[MS_AUTH_RESPONSE_LENGTH+1];
 
@@ -556,7 +554,7 @@ winbind_chap_verify(char *user, char *ourname, int id,
                u_char *lm_response = NULL;
                int nt_response_size = 0;
                int lm_response_size = 0;
-               u_char session_key[16];
+               u_char session_key[MD4_DIGEST_LENGTH];
                
                if (response_len != MS_CHAP_RESPONSE_LEN)
                        break;                  /* not even the right length */
@@ -608,7 +606,7 @@ winbind_chap_verify(char *user, char *ourname, int id,
        case CHAP_MICROSOFT_V2:
        {
                u_char Challenge[8];
-               u_char session_key[MD4_SIGNATURE_SIZE];
+               u_char session_key[MD4_DIGEST_LENGTH];
                char *error_string = NULL;
                
                if (response_len != MS_CHAP2_RESPONSE_LEN)
@@ -668,7 +666,7 @@ winbind_chap_verify(char *user, char *ourname, int id,
 }
 
 static int 
-winbind_allowed_address(u_int32_t addr) 
+winbind_allowed_address(uint32_t addr)
 {
        ipcp_options *wo = &ipcp_wantoptions[0];
        if (wo->hisaddr !=0 && wo->hisaddr == addr) {
diff --git a/pppd/ppp-des.c b/pppd/ppp-des.c
new file mode 100644 (file)
index 0000000..3ef8f95
--- /dev/null
@@ -0,0 +1,730 @@
+/*
+ * ppp-des.c - PPP/DES implementation for MS-CHAP and EAP SRP-SHA1
+ *
+ * Extracted from chap_ms.c by James Carlson.
+ * Added abstraction via PPP_Digest* callbacks by Eivind Næss
+ *
+ * Copyright (c) 1995 Eric Rosenquist. All rights reserved.
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sections of this code holds different copyright information.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "crypto-priv.h"
+
+#ifdef OPENSSL_HAVE_DES
+
+#include <openssl/evp.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define EVP_CIPHER_CTX_reset EVP_CIPHER_CTX_cleanup
+#endif
+
+static int des_init(PPP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv)
+{
+    if (ctx) {
+        EVP_CIPHER_CTX *cc = EVP_CIPHER_CTX_new();
+        if (cc) {
+
+            if (key) {
+                memcpy(ctx->key, key, 8);
+            }
+            if (iv) {
+                memcpy(ctx->iv, iv, 8);
+            }
+
+            if (EVP_CipherInit(cc, EVP_des_ecb(), ctx->key, ctx->iv, ctx->is_encr)) {
+
+                if (EVP_CIPHER_CTX_set_padding(cc, 0)) {
+                    ctx->priv = cc;
+                    return 1;
+                }
+            }
+
+            EVP_CIPHER_CTX_free(cc);
+        }
+    }
+    return 0;
+}
+
+static int des_update(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
+{
+    if (ctx) {
+        return EVP_CipherUpdate((EVP_CIPHER_CTX*) ctx->priv, out, outl, in, inl);
+    }
+    return 0;
+}
+
+static int des_final(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
+{
+    if (ctx) {
+        return EVP_CipherFinal((EVP_CIPHER_CTX*) ctx->priv, out, outl);
+    }
+    return 0;
+}
+
+static void des_clean(PPP_CIPHER_CTX *ctx)
+{
+    if (ctx->priv) {
+        EVP_CIPHER_CTX_free((EVP_CIPHER_CTX*) ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#else
+
+/*
+ * DES related functions are imported from openssl 3.0 project with the 
+ * follwoing license:
+ *
+ * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+typedef unsigned int DES_LONG;
+typedef unsigned char DES_cblock[8];
+typedef struct DES_ks {
+    union {
+        DES_cblock cblock;
+        /*
+         * make sure things are correct size on machines with 8 byte longs
+         */
+        DES_LONG deslong[2];
+    } ks[16];
+} DES_key_schedule;
+
+
+#define c2l(c,l)        (l =((DES_LONG)(*((c)++)))    , \
+                         l|=((DES_LONG)(*((c)++)))<< 8L, \
+                         l|=((DES_LONG)(*((c)++)))<<16L, \
+                         l|=((DES_LONG)(*((c)++)))<<24L)
+
+# define l2c(l,c)        (*((c)++)=(unsigned char)(((l)     )&0xff), \
+                         *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
+                         *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
+                         *((c)++)=(unsigned char)(((l)>>24L)&0xff))
+
+#define ITERATIONS 16
+
+#define ROTATE(a,n)     (((a)>>(n))+((a)<<(32-(n))))
+
+# define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
+        (b)^=(t),\
+        (a)^=((t)<<(n)))
+
+#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
+        (a)=(a)^(t)^(t>>(16-(n))))
+
+# define IP(l,r) \
+        { \
+        register DES_LONG tt; \
+        PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \
+        PERM_OP(l,r,tt,16,0x0000ffffL); \
+        PERM_OP(r,l,tt, 2,0x33333333L); \
+        PERM_OP(l,r,tt, 8,0x00ff00ffL); \
+        PERM_OP(r,l,tt, 1,0x55555555L); \
+        }
+
+# define FP(l,r) \
+        { \
+        register DES_LONG tt; \
+        PERM_OP(l,r,tt, 1,0x55555555L); \
+        PERM_OP(r,l,tt, 8,0x00ff00ffL); \
+        PERM_OP(l,r,tt, 2,0x33333333L); \
+        PERM_OP(r,l,tt,16,0x0000ffffL); \
+        PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
+        }
+
+#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g)
+#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \
+        u=R^s[S  ]; \
+        t=R^s[S+1]
+
+#define D_ENCRYPT(LL,R,S) { \
+        LOAD_DATA_tmp(R,S,u,t,E0,E1); \
+        t=ROTATE(t,4); \
+        LL^= \
+            DES_SPtrans[0][(u>> 2L)&0x3f]^ \
+            DES_SPtrans[2][(u>>10L)&0x3f]^ \
+            DES_SPtrans[4][(u>>18L)&0x3f]^ \
+            DES_SPtrans[6][(u>>26L)&0x3f]^ \
+            DES_SPtrans[1][(t>> 2L)&0x3f]^ \
+            DES_SPtrans[3][(t>>10L)&0x3f]^ \
+            DES_SPtrans[5][(t>>18L)&0x3f]^ \
+            DES_SPtrans[7][(t>>26L)&0x3f]; }
+
+
+static const DES_LONG DES_SPtrans[8][64] = {
+    {
+        /* nibble 0 */
+        0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
+        0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L,
+        0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L,
+        0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L,
+        0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L,
+        0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L,
+        0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L,
+        0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L,
+        0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L,
+        0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L,
+        0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L,
+        0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L,
+        0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L,
+        0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L,
+        0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L,
+        0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L,
+    },
+    {
+        /* nibble 1 */
+        0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L,
+        0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L,
+        0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L,
+        0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L,
+        0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L,
+        0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L,
+        0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L,
+        0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L,
+        0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L,
+        0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L,
+        0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L,
+        0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L,
+        0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L,
+        0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L,
+        0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L,
+        0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L,
+    },
+    {
+        /* nibble 2 */
+        0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L,
+        0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L,
+        0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L,
+        0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L,
+        0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L,
+        0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L,
+        0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L,
+        0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L,
+        0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L,
+        0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L,
+        0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L,
+        0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L,
+        0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L,
+        0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L,
+        0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L,
+        0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L,
+    },
+    {
+        /* nibble 3 */
+        0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L,
+        0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L,
+        0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L,
+        0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L,
+        0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L,
+        0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L,
+        0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L,
+        0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L,
+        0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L,
+        0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L,
+        0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L,
+        0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L,
+        0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L,
+        0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L,
+        0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L,
+        0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L,
+    },
+    {
+        /* nibble 4 */
+        0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L,
+        0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L,
+        0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L,
+        0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L,
+        0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L,
+        0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L,
+        0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L,
+        0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L,
+        0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L,
+        0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L,
+        0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L,
+        0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L,
+        0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L,
+        0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L,
+        0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L,
+        0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L,
+    },
+    {
+        /* nibble 5 */
+        0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L,
+        0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L,
+        0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L,
+        0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L,
+        0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L,
+        0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L,
+        0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L,
+        0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L,
+        0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L,
+        0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L,
+        0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L,
+        0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L,
+        0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L,
+        0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L,
+        0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L,
+        0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L,
+    },
+    {
+        /* nibble 6 */
+        0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L,
+        0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L,
+        0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L,
+        0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L,
+        0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L,
+        0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L,
+        0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L,
+        0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L,
+        0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L,
+        0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L,
+        0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L,
+        0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L,
+        0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L,
+        0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L,
+        0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L,
+        0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L,
+    },
+    {
+        /* nibble 7 */
+        0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L,
+        0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L,
+        0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L,
+        0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L,
+        0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L,
+        0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L,
+        0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L,
+        0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L,
+        0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L,
+        0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L,
+        0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L,
+        0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L,
+        0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L,
+        0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L,
+        0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L,
+        0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L,
+    }
+};
+
+static const DES_LONG des_skb[8][64] = {
+    {
+     /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+     0x00000000L, 0x00000010L, 0x20000000L, 0x20000010L,
+     0x00010000L, 0x00010010L, 0x20010000L, 0x20010010L,
+     0x00000800L, 0x00000810L, 0x20000800L, 0x20000810L,
+     0x00010800L, 0x00010810L, 0x20010800L, 0x20010810L,
+     0x00000020L, 0x00000030L, 0x20000020L, 0x20000030L,
+     0x00010020L, 0x00010030L, 0x20010020L, 0x20010030L,
+     0x00000820L, 0x00000830L, 0x20000820L, 0x20000830L,
+     0x00010820L, 0x00010830L, 0x20010820L, 0x20010830L,
+     0x00080000L, 0x00080010L, 0x20080000L, 0x20080010L,
+     0x00090000L, 0x00090010L, 0x20090000L, 0x20090010L,
+     0x00080800L, 0x00080810L, 0x20080800L, 0x20080810L,
+     0x00090800L, 0x00090810L, 0x20090800L, 0x20090810L,
+     0x00080020L, 0x00080030L, 0x20080020L, 0x20080030L,
+     0x00090020L, 0x00090030L, 0x20090020L, 0x20090030L,
+     0x00080820L, 0x00080830L, 0x20080820L, 0x20080830L,
+     0x00090820L, 0x00090830L, 0x20090820L, 0x20090830L,
+     },
+    {
+     /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
+     0x00000000L, 0x02000000L, 0x00002000L, 0x02002000L,
+     0x00200000L, 0x02200000L, 0x00202000L, 0x02202000L,
+     0x00000004L, 0x02000004L, 0x00002004L, 0x02002004L,
+     0x00200004L, 0x02200004L, 0x00202004L, 0x02202004L,
+     0x00000400L, 0x02000400L, 0x00002400L, 0x02002400L,
+     0x00200400L, 0x02200400L, 0x00202400L, 0x02202400L,
+     0x00000404L, 0x02000404L, 0x00002404L, 0x02002404L,
+     0x00200404L, 0x02200404L, 0x00202404L, 0x02202404L,
+     0x10000000L, 0x12000000L, 0x10002000L, 0x12002000L,
+     0x10200000L, 0x12200000L, 0x10202000L, 0x12202000L,
+     0x10000004L, 0x12000004L, 0x10002004L, 0x12002004L,
+     0x10200004L, 0x12200004L, 0x10202004L, 0x12202004L,
+     0x10000400L, 0x12000400L, 0x10002400L, 0x12002400L,
+     0x10200400L, 0x12200400L, 0x10202400L, 0x12202400L,
+     0x10000404L, 0x12000404L, 0x10002404L, 0x12002404L,
+     0x10200404L, 0x12200404L, 0x10202404L, 0x12202404L,
+     },
+    {
+     /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
+     0x00000000L, 0x00000001L, 0x00040000L, 0x00040001L,
+     0x01000000L, 0x01000001L, 0x01040000L, 0x01040001L,
+     0x00000002L, 0x00000003L, 0x00040002L, 0x00040003L,
+     0x01000002L, 0x01000003L, 0x01040002L, 0x01040003L,
+     0x00000200L, 0x00000201L, 0x00040200L, 0x00040201L,
+     0x01000200L, 0x01000201L, 0x01040200L, 0x01040201L,
+     0x00000202L, 0x00000203L, 0x00040202L, 0x00040203L,
+     0x01000202L, 0x01000203L, 0x01040202L, 0x01040203L,
+     0x08000000L, 0x08000001L, 0x08040000L, 0x08040001L,
+     0x09000000L, 0x09000001L, 0x09040000L, 0x09040001L,
+     0x08000002L, 0x08000003L, 0x08040002L, 0x08040003L,
+     0x09000002L, 0x09000003L, 0x09040002L, 0x09040003L,
+     0x08000200L, 0x08000201L, 0x08040200L, 0x08040201L,
+     0x09000200L, 0x09000201L, 0x09040200L, 0x09040201L,
+     0x08000202L, 0x08000203L, 0x08040202L, 0x08040203L,
+     0x09000202L, 0x09000203L, 0x09040202L, 0x09040203L,
+     },
+    {
+     /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
+     0x00000000L, 0x00100000L, 0x00000100L, 0x00100100L,
+     0x00000008L, 0x00100008L, 0x00000108L, 0x00100108L,
+     0x00001000L, 0x00101000L, 0x00001100L, 0x00101100L,
+     0x00001008L, 0x00101008L, 0x00001108L, 0x00101108L,
+     0x04000000L, 0x04100000L, 0x04000100L, 0x04100100L,
+     0x04000008L, 0x04100008L, 0x04000108L, 0x04100108L,
+     0x04001000L, 0x04101000L, 0x04001100L, 0x04101100L,
+     0x04001008L, 0x04101008L, 0x04001108L, 0x04101108L,
+     0x00020000L, 0x00120000L, 0x00020100L, 0x00120100L,
+     0x00020008L, 0x00120008L, 0x00020108L, 0x00120108L,
+     0x00021000L, 0x00121000L, 0x00021100L, 0x00121100L,
+     0x00021008L, 0x00121008L, 0x00021108L, 0x00121108L,
+     0x04020000L, 0x04120000L, 0x04020100L, 0x04120100L,
+     0x04020008L, 0x04120008L, 0x04020108L, 0x04120108L,
+     0x04021000L, 0x04121000L, 0x04021100L, 0x04121100L,
+     0x04021008L, 0x04121008L, 0x04021108L, 0x04121108L,
+     },
+    {
+     /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
+     0x00000000L, 0x10000000L, 0x00010000L, 0x10010000L,
+     0x00000004L, 0x10000004L, 0x00010004L, 0x10010004L,
+     0x20000000L, 0x30000000L, 0x20010000L, 0x30010000L,
+     0x20000004L, 0x30000004L, 0x20010004L, 0x30010004L,
+     0x00100000L, 0x10100000L, 0x00110000L, 0x10110000L,
+     0x00100004L, 0x10100004L, 0x00110004L, 0x10110004L,
+     0x20100000L, 0x30100000L, 0x20110000L, 0x30110000L,
+     0x20100004L, 0x30100004L, 0x20110004L, 0x30110004L,
+     0x00001000L, 0x10001000L, 0x00011000L, 0x10011000L,
+     0x00001004L, 0x10001004L, 0x00011004L, 0x10011004L,
+     0x20001000L, 0x30001000L, 0x20011000L, 0x30011000L,
+     0x20001004L, 0x30001004L, 0x20011004L, 0x30011004L,
+     0x00101000L, 0x10101000L, 0x00111000L, 0x10111000L,
+     0x00101004L, 0x10101004L, 0x00111004L, 0x10111004L,
+     0x20101000L, 0x30101000L, 0x20111000L, 0x30111000L,
+     0x20101004L, 0x30101004L, 0x20111004L, 0x30111004L,
+     },
+    {   
+     /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
+     0x00000000L, 0x08000000L, 0x00000008L, 0x08000008L,
+     0x00000400L, 0x08000400L, 0x00000408L, 0x08000408L,
+     0x00020000L, 0x08020000L, 0x00020008L, 0x08020008L,
+     0x00020400L, 0x08020400L, 0x00020408L, 0x08020408L,
+     0x00000001L, 0x08000001L, 0x00000009L, 0x08000009L,
+     0x00000401L, 0x08000401L, 0x00000409L, 0x08000409L,
+     0x00020001L, 0x08020001L, 0x00020009L, 0x08020009L,
+     0x00020401L, 0x08020401L, 0x00020409L, 0x08020409L,
+     0x02000000L, 0x0A000000L, 0x02000008L, 0x0A000008L,
+     0x02000400L, 0x0A000400L, 0x02000408L, 0x0A000408L,
+     0x02020000L, 0x0A020000L, 0x02020008L, 0x0A020008L,
+     0x02020400L, 0x0A020400L, 0x02020408L, 0x0A020408L,
+     0x02000001L, 0x0A000001L, 0x02000009L, 0x0A000009L,
+     0x02000401L, 0x0A000401L, 0x02000409L, 0x0A000409L,
+     0x02020001L, 0x0A020001L, 0x02020009L, 0x0A020009L,
+     0x02020401L, 0x0A020401L, 0x02020409L, 0x0A020409L,
+     },
+    {
+     /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
+     0x00000000L, 0x00000100L, 0x00080000L, 0x00080100L,
+     0x01000000L, 0x01000100L, 0x01080000L, 0x01080100L,
+     0x00000010L, 0x00000110L, 0x00080010L, 0x00080110L,
+     0x01000010L, 0x01000110L, 0x01080010L, 0x01080110L,
+     0x00200000L, 0x00200100L, 0x00280000L, 0x00280100L,
+     0x01200000L, 0x01200100L, 0x01280000L, 0x01280100L,
+     0x00200010L, 0x00200110L, 0x00280010L, 0x00280110L,
+     0x01200010L, 0x01200110L, 0x01280010L, 0x01280110L,
+     0x00000200L, 0x00000300L, 0x00080200L, 0x00080300L,
+     0x01000200L, 0x01000300L, 0x01080200L, 0x01080300L,
+     0x00000210L, 0x00000310L, 0x00080210L, 0x00080310L,
+     0x01000210L, 0x01000310L, 0x01080210L, 0x01080310L,
+     0x00200200L, 0x00200300L, 0x00280200L, 0x00280300L,
+     0x01200200L, 0x01200300L, 0x01280200L, 0x01280300L,
+     0x00200210L, 0x00200310L, 0x00280210L, 0x00280310L,
+     0x01200210L, 0x01200310L, 0x01280210L, 0x01280310L,
+     },
+    {
+     /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
+     0x00000000L, 0x04000000L, 0x00040000L, 0x04040000L,
+     0x00000002L, 0x04000002L, 0x00040002L, 0x04040002L,
+     0x00002000L, 0x04002000L, 0x00042000L, 0x04042000L,
+     0x00002002L, 0x04002002L, 0x00042002L, 0x04042002L,
+     0x00000020L, 0x04000020L, 0x00040020L, 0x04040020L,
+     0x00000022L, 0x04000022L, 0x00040022L, 0x04040022L,
+     0x00002020L, 0x04002020L, 0x00042020L, 0x04042020L,
+     0x00002022L, 0x04002022L, 0x00042022L, 0x04042022L,
+     0x00000800L, 0x04000800L, 0x00040800L, 0x04040800L,
+     0x00000802L, 0x04000802L, 0x00040802L, 0x04040802L,
+     0x00002800L, 0x04002800L, 0x00042800L, 0x04042800L,
+     0x00002802L, 0x04002802L, 0x00042802L, 0x04042802L,
+     0x00000820L, 0x04000820L, 0x00040820L, 0x04040820L,
+     0x00000822L, 0x04000822L, 0x00040822L, 0x04040822L,
+     0x00002820L, 0x04002820L, 0x00042820L, 0x04042820L,
+     0x00002822L, 0x04002822L, 0x00042822L, 0x04042822L,
+     }
+};
+
+
+static void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
+{
+    register DES_LONG l, r, t, u;
+    register DES_LONG *s; 
+
+    r = data[0];
+    l = data[1];
+
+    IP(r, l); 
+    /*  
+     * Things have been modified so that the initial rotate is done outside
+     * the loop.  This required the DES_SPtrans values in sp.h to be rotated
+     * 1 bit to the right. One perl script later and things have a 5% speed
+     * up on a sparc2. Thanks to Richard Outerbridge for pointing this out.
+     */
+    /* clear the top bits on machines with 8byte longs */
+    /* shift left by 2 */
+    r = ROTATE(r, 29) & 0xffffffffL;
+    l = ROTATE(l, 29) & 0xffffffffL;
+
+    s = ks->ks->deslong;
+    /*  
+     * I don't know if it is worth the effort of loop unrolling the inner
+     * loop
+     */
+    if (enc) {
+        D_ENCRYPT(l, r, 0);     /* 1 */
+        D_ENCRYPT(r, l, 2);     /* 2 */
+        D_ENCRYPT(l, r, 4);     /* 3 */
+        D_ENCRYPT(r, l, 6);     /* 4 */
+        D_ENCRYPT(l, r, 8);     /* 5 */
+        D_ENCRYPT(r, l, 10);    /* 6 */
+        D_ENCRYPT(l, r, 12);    /* 7 */
+        D_ENCRYPT(r, l, 14);    /* 8 */
+        D_ENCRYPT(l, r, 16);    /* 9 */
+        D_ENCRYPT(r, l, 18);    /* 10 */
+        D_ENCRYPT(l, r, 20);    /* 11 */
+        D_ENCRYPT(r, l, 22);    /* 12 */
+        D_ENCRYPT(l, r, 24);    /* 13 */
+        D_ENCRYPT(r, l, 26);    /* 14 */
+        D_ENCRYPT(l, r, 28);    /* 15 */
+        D_ENCRYPT(r, l, 30);    /* 16 */
+    } else {
+        D_ENCRYPT(l, r, 30);    /* 16 */
+        D_ENCRYPT(r, l, 28);    /* 15 */
+        D_ENCRYPT(l, r, 26);    /* 14 */
+        D_ENCRYPT(r, l, 24);    /* 13 */
+        D_ENCRYPT(l, r, 22);    /* 12 */
+        D_ENCRYPT(r, l, 20);    /* 11 */
+        D_ENCRYPT(l, r, 18);    /* 10 */
+        D_ENCRYPT(r, l, 16);    /* 9 */
+        D_ENCRYPT(l, r, 14);    /* 8 */
+        D_ENCRYPT(r, l, 12);    /* 7 */
+        D_ENCRYPT(l, r, 10);    /* 6 */
+        D_ENCRYPT(r, l, 8);     /* 5 */
+        D_ENCRYPT(l, r, 6);     /* 4 */
+        D_ENCRYPT(r, l, 4);     /* 3 */
+        D_ENCRYPT(l, r, 2);     /* 2 */
+        D_ENCRYPT(r, l, 0);     /* 1 */
+    }   
+
+    /* rotate and clear the top bits on machines with 8byte longs */
+    l = ROTATE(l, 3) & 0xffffffffL;
+    r = ROTATE(r, 3) & 0xffffffffL;
+
+    FP(r, l); 
+    data[0] = l;
+    data[1] = r;
+    l = r = t = u = 0;
+}
+
+
+static void DES_ecb_encrypt(const DES_cblock *input, DES_cblock *output,
+                     DES_key_schedule *ks, int enc)
+{
+    register DES_LONG l;
+    DES_LONG ll[2];
+    const unsigned char *in = &(*input)[0];
+    unsigned char *out = &(*output)[0];
+
+    c2l(in, l); 
+    ll[0] = l;
+    c2l(in, l); 
+    ll[1] = l;
+    DES_encrypt1(ll, ks, enc);
+    l = ll[0];
+    l2c(l, out);
+    l = ll[1];
+    l2c(l, out);
+    l = ll[0] = ll[1] = 0;
+}
+
+
+static void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule)
+{
+    static const int shifts2[16] =
+        { 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 };
+    register DES_LONG c, d, t, s, t2;
+    register const unsigned char *in;
+    register DES_LONG *k;
+    register int i;
+
+#ifdef OPENBSD_DEV_CRYPTO
+    memcpy(schedule->key, key, sizeof(schedule->key));
+    schedule->session = NULL;
+#endif
+    k = &schedule->ks->deslong[0];
+    in = &(*key)[0];
+
+    c2l(in, c);
+    c2l(in, d);
+
+    /*
+     * do PC1 in 47 simple operations. Thanks to John Fletcher
+     * for the inspiration.
+     */
+    PERM_OP(d, c, t, 4, 0x0f0f0f0fL);
+    HPERM_OP(c, t, -2, 0xcccc0000L);
+    HPERM_OP(d, t, -2, 0xcccc0000L);
+    PERM_OP(d, c, t, 1, 0x55555555L);
+    PERM_OP(c, d, t, 8, 0x00ff00ffL);
+    PERM_OP(d, c, t, 1, 0x55555555L);
+    d = (((d & 0x000000ffL) << 16L) | (d & 0x0000ff00L) |
+         ((d & 0x00ff0000L) >> 16L) | ((c & 0xf0000000L) >> 4L));
+    c &= 0x0fffffffL;
+
+    for (i = 0; i < ITERATIONS; i++) {
+        if (shifts2[i]) {
+            c = ((c >> 2L) | (c << 26L));
+            d = ((d >> 2L) | (d << 26L));
+        } else {
+            c = ((c >> 1L) | (c << 27L));
+            d = ((d >> 1L) | (d << 27L));
+        }
+        c &= 0x0fffffffL;
+        d &= 0x0fffffffL;
+        /*
+         * could be a few less shifts but I am to lazy at this point in time
+         * to investigate
+         */
+        s = des_skb[0][(c) & 0x3f] |
+            des_skb[1][((c >> 6L) & 0x03) | ((c >> 7L) & 0x3c)] |
+            des_skb[2][((c >> 13L) & 0x0f) | ((c >> 14L) & 0x30)] |
+            des_skb[3][((c >> 20L) & 0x01) | ((c >> 21L) & 0x06) |
+                       ((c >> 22L) & 0x38)];
+        t = des_skb[4][(d) & 0x3f] |
+            des_skb[5][((d >> 7L) & 0x03) | ((d >> 8L) & 0x3c)] |
+            des_skb[6][(d >> 15L) & 0x3f] |
+            des_skb[7][((d >> 21L) & 0x0f) | ((d >> 22L) & 0x30)];
+
+        /* table contained 0213 4657 */
+        t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL;
+        *(k++) = ROTATE(t2, 30) & 0xffffffffL;
+
+        t2 = ((s >> 16L) | (t & 0xffff0000L));
+        *(k++) = ROTATE(t2, 26) & 0xffffffffL;
+    }
+}
+
+/* End of import of OpenSSL DES encryption functions */
+
+static int des_init(PPP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv)
+{
+    DES_key_schedule *ks = calloc(1, sizeof(DES_key_schedule));
+    if (ks) {
+
+        if (key) {
+            memcpy(ctx->key, key, 8);
+        }
+
+        if (iv) {
+            memcpy(ctx->iv, iv, 8);
+        }
+
+        if (key) {
+            DES_set_key((DES_cblock*) &ctx->key, ks);
+        }
+
+        ctx->priv = ks;
+        return 1;
+    }
+
+    return 0;
+}
+
+static int des_update(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
+{
+    int offset = 0;
+    inl = inl / 8;
+    while (offset < inl) {
+        DES_ecb_encrypt((DES_cblock *)in + offset, (DES_cblock *)out + offset,
+            (DES_key_schedule*) ctx->priv, ctx->is_encr);
+        offset ++;
+    }
+
+    *outl = offset * 8;
+    return 1;
+}
+
+static int des_final(PPP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
+{
+    return 1;
+}
+
+static void des_clean(PPP_CIPHER_CTX *ctx)
+{
+    if (ctx->priv) {
+        free(ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#endif
+
+static PPP_CIPHER ppp_des = {
+    .init_fn = des_init,
+    .update_fn = des_update,
+    .final_fn = des_final,
+    .clean_fn = des_clean,
+};
+
+const PPP_CIPHER *PPP_des_ecb(void)
+{
+    return &ppp_des;
+}
+
diff --git a/pppd/ppp-md4.c b/pppd/ppp-md4.c
new file mode 100644 (file)
index 0000000..c581110
--- /dev/null
@@ -0,0 +1,444 @@
+/* ppp-md4.c - MD4 Digest implementation
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sections of this code holds different copyright information.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "crypto-priv.h"
+
+
+#ifdef OPENSSL_HAVE_MD4
+#include <openssl/evp.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
+#define EVP_MD_CTX_new EVP_MD_CTX_create
+#endif
+
+
+static int md4_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        EVP_MD_CTX *mctx = EVP_MD_CTX_new();
+        if (mctx) {
+            if (EVP_DigestInit(mctx, EVP_md4())) {
+                ctx->priv = mctx;
+                return 1;
+            }
+            EVP_MD_CTX_free(mctx);
+        }
+    }
+    return 0;
+}
+
+static int md4_update(PPP_MD_CTX *ctx, const void *data, size_t len)
+{
+    if (EVP_DigestUpdate((EVP_MD_CTX*) ctx->priv, data, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static int md4_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    if (EVP_DigestFinal((EVP_MD_CTX*) ctx->priv, out, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static void md4_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        EVP_MD_CTX_free(ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+
+#else // !OPENSSL_HAVE_MD4
+
+#define TRUE  1
+#define FALSE 0
+
+/*
+** ********************************************************************
+** md4.c -- Implementation of MD4 Message Digest Algorithm           **
+** Updated: 2/16/90 by Ronald L. Rivest                              **
+** (C) 1990 RSA Data Security, Inc.                                  **
+** ********************************************************************
+*/
+
+/*
+** To use MD4:
+**   -- Include md4.h in your program
+**   -- Declare an MDstruct MD to hold the state of the digest
+**          computation.
+**   -- Initialize MD using MDbegin(&MD)
+**   -- For each full block (64 bytes) X you wish to process, call
+**          MD4Update(&MD,X,512)
+**      (512 is the number of bits in a full block.)
+**   -- For the last block (less than 64 bytes) you wish to process,
+**          MD4Update(&MD,X,n)
+**      where n is the number of bits in the partial block. A partial
+**      block terminates the computation, so every MD computation
+**      should terminate by processing a partial block, even if it
+**      has n = 0.
+**   -- The message digest is available in MD.buffer[0] ...
+**      MD.buffer[3].  (Least-significant byte of each word
+**      should be output first.)
+**   -- You can print out the digest using MDprint(&MD)
+*/
+
+/* Implementation notes:
+** This implementation assumes that ints are 32-bit quantities.
+*/
+
+/* MDstruct is the data structure for a message digest computation.
+*/
+typedef struct {
+       unsigned int buffer[4]; /* Holds 4-word result of MD computation */
+       unsigned char count[8]; /* Number of bits processed so far */
+       unsigned int done;      /* Nonzero means MD computation finished */
+} MD4_CTX;
+
+
+/* Compile-time declarations of MD4 "magic constants".
+*/
+#define I0  0x67452301       /* Initial values for MD buffer */
+#define I1  0xefcdab89
+#define I2  0x98badcfe
+#define I3  0x10325476
+#define C2  013240474631     /* round 2 constant = sqrt(2) in octal */
+#define C3  015666365641     /* round 3 constant = sqrt(3) in octal */
+/* C2 and C3 are from Knuth, The Art of Programming, Volume 2
+** (Seminumerical Algorithms), Second Edition (1981), Addison-Wesley.
+** Table 2, page 660.
+*/
+
+#define fs1  3               /* round 1 shift amounts */
+#define fs2  7
+#define fs3 11
+#define fs4 19
+#define gs1  3               /* round 2 shift amounts */
+#define gs2  5
+#define gs3  9
+#define gs4 13
+#define hs1  3               /* round 3 shift amounts */
+#define hs2  9
+#define hs3 11
+#define hs4 15
+
+/* Compile-time macro declarations for MD4.
+** Note: The "rot" operator uses the variable "tmp".
+** It assumes tmp is declared as unsigned int, so that the >>
+** operator will shift in zeros rather than extending the sign bit.
+*/
+#define f(X,Y,Z)             ((X&Y) | ((~X)&Z))
+#define g(X,Y,Z)             ((X&Y) | (X&Z) | (Y&Z))
+#define h(X,Y,Z)             (X^Y^Z)
+#define rot(X,S)             (tmp=X,(tmp<<S) | (tmp>>(32-S)))
+#define ff(A,B,C,D,i,s)      A = rot((A + f(B,C,D) + X[i]),s)
+#define gg(A,B,C,D,i,s)      A = rot((A + g(B,C,D) + X[i] + C2),s)
+#define hh(A,B,C,D,i,s)      A = rot((A + h(B,C,D) + X[i] + C3),s)
+
+/* MD4print(MDp)
+** Print message digest buffer MDp as 32 hexadecimal digits.
+** Order is from low-order byte of buffer[0] to high-order byte of
+** buffer[3].
+** Each byte is printed with high-order hexadecimal digit first.
+** This is a user-callable routine.
+*/
+static void
+MD4Print(MD4_CTX *MDp)
+{
+  int i,j;
+  for (i=0;i<4;i++)
+    for (j=0;j<32;j=j+8)
+      printf("%02x",(MDp->buffer[i]>>j) & 0xFF);
+}
+
+/* MD4Init(MDp)
+** Initialize message digest buffer MDp.
+** This is a user-callable routine.
+*/
+static void
+MD4Init(MD4_CTX *MDp)
+{
+  int i;
+  MDp->buffer[0] = I0;
+  MDp->buffer[1] = I1;
+  MDp->buffer[2] = I2;
+  MDp->buffer[3] = I3;
+  for (i=0;i<8;i++) MDp->count[i] = 0;
+  MDp->done = 0;
+}
+
+/* MDblock(MDp,X)
+** Update message digest buffer MDp->buffer using 16-word data block X.
+** Assumes all 16 words of X are full of data.
+** Does not update MDp->count.
+** This routine is not user-callable.
+*/
+static void
+MDblock(MD4_CTX *MDp, unsigned char *Xb)
+{
+  register unsigned int tmp, A, B, C, D;
+  unsigned int X[16];
+  int i;
+
+  for (i = 0; i < 16; ++i) {
+    X[i] = Xb[0] + (Xb[1] << 8) + (Xb[2] << 16) + (Xb[3] << 24);
+    Xb += 4;
+  }
+
+  A = MDp->buffer[0];
+  B = MDp->buffer[1];
+  C = MDp->buffer[2];
+  D = MDp->buffer[3];
+  /* Update the message digest buffer */
+  ff(A , B , C , D ,  0 , fs1); /* Round 1 */
+  ff(D , A , B , C ,  1 , fs2);
+  ff(C , D , A , B ,  2 , fs3);
+  ff(B , C , D , A ,  3 , fs4);
+  ff(A , B , C , D ,  4 , fs1);
+  ff(D , A , B , C ,  5 , fs2);
+  ff(C , D , A , B ,  6 , fs3);
+  ff(B , C , D , A ,  7 , fs4);
+  ff(A , B , C , D ,  8 , fs1);
+  ff(D , A , B , C ,  9 , fs2);
+  ff(C , D , A , B , 10 , fs3);
+  ff(B , C , D , A , 11 , fs4);
+  ff(A , B , C , D , 12 , fs1);
+  ff(D , A , B , C , 13 , fs2);
+  ff(C , D , A , B , 14 , fs3);
+  ff(B , C , D , A , 15 , fs4);
+  gg(A , B , C , D ,  0 , gs1); /* Round 2 */
+  gg(D , A , B , C ,  4 , gs2);
+  gg(C , D , A , B ,  8 , gs3);
+  gg(B , C , D , A , 12 , gs4);
+  gg(A , B , C , D ,  1 , gs1);
+  gg(D , A , B , C ,  5 , gs2);
+  gg(C , D , A , B ,  9 , gs3);
+  gg(B , C , D , A , 13 , gs4);
+  gg(A , B , C , D ,  2 , gs1);
+  gg(D , A , B , C ,  6 , gs2);
+  gg(C , D , A , B , 10 , gs3);
+  gg(B , C , D , A , 14 , gs4);
+  gg(A , B , C , D ,  3 , gs1);
+  gg(D , A , B , C ,  7 , gs2);
+  gg(C , D , A , B , 11 , gs3);
+  gg(B , C , D , A , 15 , gs4);
+  hh(A , B , C , D ,  0 , hs1); /* Round 3 */
+  hh(D , A , B , C ,  8 , hs2);
+  hh(C , D , A , B ,  4 , hs3);
+  hh(B , C , D , A , 12 , hs4);
+  hh(A , B , C , D ,  2 , hs1);
+  hh(D , A , B , C , 10 , hs2);
+  hh(C , D , A , B ,  6 , hs3);
+  hh(B , C , D , A , 14 , hs4);
+  hh(A , B , C , D ,  1 , hs1);
+  hh(D , A , B , C ,  9 , hs2);
+  hh(C , D , A , B ,  5 , hs3);
+  hh(B , C , D , A , 13 , hs4);
+  hh(A , B , C , D ,  3 , hs1);
+  hh(D , A , B , C , 11 , hs2);
+  hh(C , D , A , B ,  7 , hs3);
+  hh(B , C , D , A , 15 , hs4);
+  MDp->buffer[0] += A;
+  MDp->buffer[1] += B;
+  MDp->buffer[2] += C;
+  MDp->buffer[3] += D;
+}
+
+/* MD4Update(MDp,X,count)
+** Input: X -- a pointer to an array of unsigned characters.
+**        count -- the number of bits of X to use.
+**          (if not a multiple of 8, uses high bits of last byte.)
+** Update MDp using the number of bits of X given by count.
+** This is the basic input routine for an MD4 user.
+** The routine completes the MD computation when count < 512, so
+** every MD computation should end with one call to MD4Update with a
+** count less than 512.  A call with count 0 will be ignored if the
+** MD has already been terminated (done != 0), so an extra call with
+** count 0 can be given as a "courtesy close" to force termination
+** if desired.
+*/
+static void
+MD4Update(MD4_CTX *MDp, unsigned char *X, unsigned int count)
+{
+  unsigned int i, tmp, bit, byte, mask;
+  unsigned char XX[64];
+  unsigned char *p;
+
+  /* return with no error if this is a courtesy close with count
+  ** zero and MDp->done is true.
+  */
+  if (count == 0 && MDp->done) return;
+  /* check to see if MD is already done and report error */
+  if (MDp->done)
+  { printf("\nError: MD4Update MD already done."); return; }
+
+  /* Add count to MDp->count */
+  tmp = count;
+  p = MDp->count;
+  while (tmp)
+  { tmp += *p;
+  *p++ = tmp;
+  tmp = tmp >> 8;
+  }
+
+  /* Process data */
+  if (count == 512)
+  { /* Full block of data to handle */
+    MDblock(MDp,X);
+  }
+  else if (count > 512) /* Check for count too large */
+  {
+    printf("\nError: MD4Update called with illegal count value %u.",
+          count);
+    return;
+  }
+  else /* partial block -- must be last block so finish up */
+  {
+    /* Find out how many bytes and residual bits there are */
+    byte = count >> 3;
+    bit =  count & 7;
+    /* Copy X into XX since we need to modify it */
+    if (count)
+      for (i=0;i<=byte;i++) XX[i] = X[i];
+    for (i=byte+1;i<64;i++) XX[i] = 0;
+    /* Add padding '1' bit and low-order zeros in last byte */
+    mask = 1 << (7 - bit);
+    XX[byte] = (XX[byte] | mask) & ~( mask - 1);
+    /* If room for bit count, finish up with this block */
+    if (byte <= 55)
+    {
+      for (i=0;i<8;i++) XX[56+i] = MDp->count[i];
+      MDblock(MDp,XX);
+    }
+    else /* need to do two blocks to finish up */
+    {
+      MDblock(MDp,XX);
+      for (i=0;i<56;i++) XX[i] = 0;
+      for (i=0;i<8;i++)  XX[56+i] = MDp->count[i];
+      MDblock(MDp,XX);
+    }
+    /* Set flag saying we're done with MD computation */
+    MDp->done = 1;
+  }
+}
+
+/*
+** Finish up MD4 computation and return message digest.
+*/
+static void
+MD4Final(unsigned char *buf, MD4_CTX *MD)
+{
+  int i, j;
+  unsigned int w;
+
+  MD4Update(MD, NULL, 0);
+  for (i = 0; i < 4; ++i) {
+    w = MD->buffer[i];
+    for (j = 0; j < 4; ++j) {
+      *buf++ = w;
+      w >>= 8;
+    }
+  }
+}
+
+/*
+** End of md4.c
+****************************(cut)***********************************/
+
+static int md4_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        MD4_CTX *mctx = calloc(1, sizeof(MD4_CTX));
+        if (mctx) {
+            MD4Init(mctx);
+            ctx->priv = mctx;
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static int md4_update(PPP_MD_CTX *ctx, const void *data, size_t len)
+{
+#if defined(__NetBSD__)
+    /* NetBSD uses the libc md4 routines which take bytes instead of bits */
+    int                        mdlen = len;
+#else
+    int                        mdlen = len * 8;
+#endif
+
+    /* Internal MD4Update can take at most 64 bytes at a time */
+    while (mdlen > 512) {
+        MD4Update((MD4_CTX*) ctx->priv, (unsigned char*) data, 512);
+        data += 64;
+        mdlen -= 512;
+    }
+    MD4Update((MD4_CTX*) ctx->priv, (unsigned char*) data, mdlen);
+    return 1;
+}
+
+static int md4_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    MD4Final(out, (MD4_CTX*) ctx->priv);
+    return 1;
+}
+
+static void md4_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        free(ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#endif
+
+static PPP_MD ppp_md4 = {
+    .init_fn = md4_init,
+    .update_fn = md4_update,
+    .final_fn = md4_final,
+    .clean_fn = md4_clean,
+};
+
+const PPP_MD *PPP_md4(void)
+{
+    return &ppp_md4;
+}
diff --git a/pppd/ppp-md5.c b/pppd/ppp-md5.c
new file mode 100644 (file)
index 0000000..ac39c01
--- /dev/null
@@ -0,0 +1,451 @@
+/* ppp-md5.c - MD5 Digest implementation
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Sections of this code holds different copyright information.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "crypto-priv.h"
+
+#ifdef OPENSSL_HAVE_MD5
+#include <openssl/evp.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
+#define EVP_MD_CTX_new EVP_MD_CTX_create
+#endif
+
+static int md5_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        EVP_MD_CTX *mctx = EVP_MD_CTX_new();
+        if (mctx) {
+            if (EVP_DigestInit((EVP_MD_CTX*) mctx, EVP_md5())) {
+                ctx->priv = mctx;
+                return 1;
+            }
+            EVP_MD_CTX_free(mctx);
+        }
+    }
+    return 0;
+}
+
+static int md5_update(PPP_MD_CTX *ctx, const void *data, size_t len)
+{
+    if (EVP_DigestUpdate((EVP_MD_CTX*) ctx->priv, data, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static int md5_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    if (EVP_DigestFinal((EVP_MD_CTX*) ctx->priv, out, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static void md5_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        EVP_MD_CTX_free((EVP_MD_CTX*) ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#else // !OPENSSL_HAVE_MD5
+
+/*
+ ***********************************************************************
+ ** md5.c -- the source code for MD5 routines                         **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm              **
+ ** Created: 2/17/90 RLR                                              **
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved.  **
+ **                                                                   **
+ ** License to copy and use this software is granted provided that    **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message-     **
+ ** Digest Algorithm" in all material mentioning or referencing this  **
+ ** software or this function.                                        **
+ **                                                                   **
+ ** License is also granted to make and use derivative works          **
+ ** provided that such works are identified as "derived from the RSA  **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all          **
+ ** material mentioning or referencing the derived work.              **
+ **                                                                   **
+ ** RSA Data Security, Inc. makes no representations concerning       **
+ ** either the merchantability of this software or the suitability    **
+ ** of this software for any particular purpose.  It is provided "as  **
+ ** is" without express or implied warranty of any kind.              **
+ **                                                                   **
+ ** These notices must be retained in any copies of any part of this  **
+ ** documentation and/or software.                                    **
+ ***********************************************************************
+ */
+
+
+/* typedef a 32-bit type */
+#ifdef _LP64
+typedef unsigned int UINT4;
+typedef int          INT4;
+#else
+typedef unsigned long UINT4;
+typedef long          INT4;
+#endif
+#define _UINT4_T
+
+/* Data structure for MD5 (Message-Digest) computation */
+typedef struct {
+  UINT4 i[2];                   /* number of _bits_ handled mod 2^64 */
+  UINT4 buf[4];                                    /* scratch buffer */
+  unsigned char in[64];                              /* input buffer */
+  unsigned char digest[16];     /* actual digest after MD5Final call */
+} MD5_CTX;
+
+
+/*
+ ***********************************************************************
+ **  Message-digest routines:                                         **
+ **  To form the message digest for a message M                       **
+ **    (1) Initialize a context buffer mdContext using MD5_Init       **
+ **    (2) Call MD5_Update on mdContext and M                         **
+ **    (3) Call MD5_Final on mdContext                                **
+ **  The message digest is now in mdContext->digest[0...15]           **
+ ***********************************************************************
+ */
+
+/* forward declaration */
+static void Transform (UINT4 *buf, UINT4 *in);
+
+static unsigned char PADDING[64] = {
+  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* F, G, H and I are basic MD5 functions */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
+/* Rotation is separate from addition to prevent recomputation */
+#define FF(a, b, c, d, x, s, ac) \
+  {(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define GG(a, b, c, d, x, s, ac) \
+  {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define HH(a, b, c, d, x, s, ac) \
+  {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+#define II(a, b, c, d, x, s, ac) \
+  {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+   (a) = ROTATE_LEFT ((a), (s)); \
+   (a) += (b); \
+  }
+
+#ifdef __STDC__
+#define UL(x)  x##U
+#else
+#define UL(x)  x
+#endif
+
+/* The routine MD5_Init initializes the message-digest context
+   mdContext. All fields are set to zero.
+ */
+static void MD5_Init (MD5_CTX *mdContext)
+{
+  mdContext->i[0] = mdContext->i[1] = (UINT4)0;
+
+  /* Load magic initialization constants.
+   */
+  mdContext->buf[0] = (UINT4)0x67452301;
+  mdContext->buf[1] = (UINT4)0xefcdab89;
+  mdContext->buf[2] = (UINT4)0x98badcfe;
+  mdContext->buf[3] = (UINT4)0x10325476;
+}
+
+/* The routine MD5Update updates the message-digest context to
+   account for the presence of each of the characters inBuf[0..inLen-1]
+   in the message whose digest is being computed.
+ */
+static void MD5_Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)
+{
+  UINT4 in[16];
+  int mdi;
+  unsigned int i, ii;
+
+  /* compute number of bytes mod 64 */
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+  /* update number of bits */
+  if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0])
+    mdContext->i[1]++;
+  mdContext->i[0] += ((UINT4)inLen << 3);
+  mdContext->i[1] += ((UINT4)inLen >> 29);
+
+  while (inLen--) {
+    /* add new character to buffer, increment mdi */
+    mdContext->in[mdi++] = *inBuf++;
+
+    /* transform if necessary */
+    if (mdi == 0x40) {
+      for (i = 0, ii = 0; i < 16; i++, ii += 4)
+        in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+                (((UINT4)mdContext->in[ii+2]) << 16) |
+                (((UINT4)mdContext->in[ii+1]) << 8) |
+                ((UINT4)mdContext->in[ii]);
+      Transform (mdContext->buf, in);
+      mdi = 0;
+    }
+  }
+}
+
+/* The routine MD5Final terminates the message-digest computation and
+   ends with the desired message digest in mdContext->digest[0...15].
+ */
+static void MD5_Final (unsigned char hash[], MD5_CTX *mdContext)
+{
+  UINT4 in[16];
+  int mdi;
+  unsigned int i, ii;
+  unsigned int padLen;
+
+  /* save number of bits */
+  in[14] = mdContext->i[0];
+  in[15] = mdContext->i[1];
+
+  /* compute number of bytes mod 64 */
+  mdi = (int)((mdContext->i[0] >> 3) & 0x3F);
+
+  /* pad out to 56 mod 64 */
+  padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
+  MD5_Update (mdContext, PADDING, padLen);
+
+  /* append length in bits and transform */
+  for (i = 0, ii = 0; i < 14; i++, ii += 4)
+    in[i] = (((UINT4)mdContext->in[ii+3]) << 24) |
+            (((UINT4)mdContext->in[ii+2]) << 16) |
+            (((UINT4)mdContext->in[ii+1]) << 8) |
+            ((UINT4)mdContext->in[ii]);
+  Transform (mdContext->buf, in);
+
+  /* store buffer in digest */
+  for (i = 0, ii = 0; i < 4; i++, ii += 4) {
+    mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF);
+    mdContext->digest[ii+1] =
+      (unsigned char)((mdContext->buf[i] >> 8) & 0xFF);
+    mdContext->digest[ii+2] =
+      (unsigned char)((mdContext->buf[i] >> 16) & 0xFF);
+    mdContext->digest[ii+3] =
+      (unsigned char)((mdContext->buf[i] >> 24) & 0xFF);
+  }
+  memcpy(hash, mdContext->digest, 16);
+}
+
+/* Basic MD5 step. Transforms buf based on in.
+ */
+static void Transform (UINT4 *buf, UINT4 *in)
+{
+  UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
+
+  /* Round 1 */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+  FF ( a, b, c, d, in[ 0], S11, UL(3614090360)); /* 1 */
+  FF ( d, a, b, c, in[ 1], S12, UL(3905402710)); /* 2 */
+  FF ( c, d, a, b, in[ 2], S13, UL( 606105819)); /* 3 */
+  FF ( b, c, d, a, in[ 3], S14, UL(3250441966)); /* 4 */
+  FF ( a, b, c, d, in[ 4], S11, UL(4118548399)); /* 5 */
+  FF ( d, a, b, c, in[ 5], S12, UL(1200080426)); /* 6 */
+  FF ( c, d, a, b, in[ 6], S13, UL(2821735955)); /* 7 */
+  FF ( b, c, d, a, in[ 7], S14, UL(4249261313)); /* 8 */
+  FF ( a, b, c, d, in[ 8], S11, UL(1770035416)); /* 9 */
+  FF ( d, a, b, c, in[ 9], S12, UL(2336552879)); /* 10 */
+  FF ( c, d, a, b, in[10], S13, UL(4294925233)); /* 11 */
+  FF ( b, c, d, a, in[11], S14, UL(2304563134)); /* 12 */
+  FF ( a, b, c, d, in[12], S11, UL(1804603682)); /* 13 */
+  FF ( d, a, b, c, in[13], S12, UL(4254626195)); /* 14 */
+  FF ( c, d, a, b, in[14], S13, UL(2792965006)); /* 15 */
+  FF ( b, c, d, a, in[15], S14, UL(1236535329)); /* 16 */
+
+  /* Round 2 */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+  GG ( a, b, c, d, in[ 1], S21, UL(4129170786)); /* 17 */
+  GG ( d, a, b, c, in[ 6], S22, UL(3225465664)); /* 18 */
+  GG ( c, d, a, b, in[11], S23, UL( 643717713)); /* 19 */
+  GG ( b, c, d, a, in[ 0], S24, UL(3921069994)); /* 20 */
+  GG ( a, b, c, d, in[ 5], S21, UL(3593408605)); /* 21 */
+  GG ( d, a, b, c, in[10], S22, UL(  38016083)); /* 22 */
+  GG ( c, d, a, b, in[15], S23, UL(3634488961)); /* 23 */
+  GG ( b, c, d, a, in[ 4], S24, UL(3889429448)); /* 24 */
+  GG ( a, b, c, d, in[ 9], S21, UL( 568446438)); /* 25 */
+  GG ( d, a, b, c, in[14], S22, UL(3275163606)); /* 26 */
+  GG ( c, d, a, b, in[ 3], S23, UL(4107603335)); /* 27 */
+  GG ( b, c, d, a, in[ 8], S24, UL(1163531501)); /* 28 */
+  GG ( a, b, c, d, in[13], S21, UL(2850285829)); /* 29 */
+  GG ( d, a, b, c, in[ 2], S22, UL(4243563512)); /* 30 */
+  GG ( c, d, a, b, in[ 7], S23, UL(1735328473)); /* 31 */
+  GG ( b, c, d, a, in[12], S24, UL(2368359562)); /* 32 */
+
+  /* Round 3 */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+  HH ( a, b, c, d, in[ 5], S31, UL(4294588738)); /* 33 */
+  HH ( d, a, b, c, in[ 8], S32, UL(2272392833)); /* 34 */
+  HH ( c, d, a, b, in[11], S33, UL(1839030562)); /* 35 */
+  HH ( b, c, d, a, in[14], S34, UL(4259657740)); /* 36 */
+  HH ( a, b, c, d, in[ 1], S31, UL(2763975236)); /* 37 */
+  HH ( d, a, b, c, in[ 4], S32, UL(1272893353)); /* 38 */
+  HH ( c, d, a, b, in[ 7], S33, UL(4139469664)); /* 39 */
+  HH ( b, c, d, a, in[10], S34, UL(3200236656)); /* 40 */
+  HH ( a, b, c, d, in[13], S31, UL( 681279174)); /* 41 */
+  HH ( d, a, b, c, in[ 0], S32, UL(3936430074)); /* 42 */
+  HH ( c, d, a, b, in[ 3], S33, UL(3572445317)); /* 43 */
+  HH ( b, c, d, a, in[ 6], S34, UL(  76029189)); /* 44 */
+  HH ( a, b, c, d, in[ 9], S31, UL(3654602809)); /* 45 */
+  HH ( d, a, b, c, in[12], S32, UL(3873151461)); /* 46 */
+  HH ( c, d, a, b, in[15], S33, UL( 530742520)); /* 47 */
+  HH ( b, c, d, a, in[ 2], S34, UL(3299628645)); /* 48 */
+
+  /* Round 4 */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+  II ( a, b, c, d, in[ 0], S41, UL(4096336452)); /* 49 */
+  II ( d, a, b, c, in[ 7], S42, UL(1126891415)); /* 50 */
+  II ( c, d, a, b, in[14], S43, UL(2878612391)); /* 51 */
+  II ( b, c, d, a, in[ 5], S44, UL(4237533241)); /* 52 */
+  II ( a, b, c, d, in[12], S41, UL(1700485571)); /* 53 */
+  II ( d, a, b, c, in[ 3], S42, UL(2399980690)); /* 54 */
+  II ( c, d, a, b, in[10], S43, UL(4293915773)); /* 55 */
+  II ( b, c, d, a, in[ 1], S44, UL(2240044497)); /* 56 */
+  II ( a, b, c, d, in[ 8], S41, UL(1873313359)); /* 57 */
+  II ( d, a, b, c, in[15], S42, UL(4264355552)); /* 58 */
+  II ( c, d, a, b, in[ 6], S43, UL(2734768916)); /* 59 */
+  II ( b, c, d, a, in[13], S44, UL(1309151649)); /* 60 */
+  II ( a, b, c, d, in[ 4], S41, UL(4149444226)); /* 61 */
+  II ( d, a, b, c, in[11], S42, UL(3174756917)); /* 62 */
+  II ( c, d, a, b, in[ 2], S43, UL( 718787259)); /* 63 */
+  II ( b, c, d, a, in[ 9], S44, UL(3951481745)); /* 64 */
+
+  buf[0] += a;
+  buf[1] += b;
+  buf[2] += c;
+  buf[3] += d;
+}
+
+/*
+ ***********************************************************************
+ ** End of md5.c                                                      **
+ ******************************** (cut) ********************************
+ */
+
+static int md5_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        MD5_CTX *md5 = calloc(1, sizeof(MD5_CTX));
+        if (md5 != NULL) {
+            MD5_Init(md5);
+            ctx->priv = md5;
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static int md5_update(PPP_MD_CTX *ctx, const void *data, size_t len)
+{
+    MD5_Update((MD5_CTX*) ctx->priv, (void*) data, len);
+    return 1;
+}
+
+static int md5_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    MD5_Final(out, (MD5_CTX*) ctx->priv);
+    return 1;
+}
+
+static void md5_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        free(ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#endif
+
+static PPP_MD ppp_md5 = {
+    .init_fn = md5_init,
+    .update_fn = md5_update,
+    .final_fn = md5_final,
+    .clean_fn  = md5_clean,
+};
+
+const PPP_MD *PPP_md5(void)
+{
+    return &ppp_md5;
+}
+
diff --git a/pppd/ppp-sha1.c b/pppd/ppp-sha1.c
new file mode 100644 (file)
index 0000000..9ff3a24
--- /dev/null
@@ -0,0 +1,312 @@
+/* ppp-sha1.c - SHA1 Digest implementation
+ *
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sections of this code holds different copyright information.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stddef.h>
+
+#include "crypto-priv.h"
+
+
+/* #define SHA1HANDSOFF * Copies data before messing with it. */
+#ifdef OPENSSL_HAVE_SHA
+#include <openssl/evp.h>
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
+#define EVP_MD_CTX_new EVP_MD_CTX_create
+#endif
+
+static int sha1_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        EVP_MD_CTX *mctx = EVP_MD_CTX_new();
+        if (mctx) {
+            if (EVP_DigestInit(mctx, EVP_sha1())) {
+                ctx->priv = mctx;
+                return 1;
+            }
+            EVP_MD_CTX_free(mctx);
+        }
+    }
+    return 0;
+}
+
+static int sha1_update(PPP_MD_CTX *ctx, const void *data, size_t len)
+{
+    if (EVP_DigestUpdate((EVP_MD_CTX*) ctx->priv, data, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static int sha1_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    if (EVP_DigestFinal((EVP_MD_CTX*) ctx->priv, out, len)) {
+        return 1;
+    }
+    return 0;
+}
+
+static void sha1_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        EVP_MD_CTX_free((EVP_MD_CTX*) ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+
+#else // !OPENSSL_HAVE_SHA
+
+/*
+ * ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
+ *
+ * SHA-1 in C
+ * By Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ *
+ * Test Vectors (from FIPS PUB 180-1)
+ * "abc"
+ * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
+ * A million repetitions of "a"
+ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+ */
+
+#include <string.h>
+#include <netinet/in.h>        /* htonl() */
+
+typedef struct {
+    uint32_t state[5];
+    uint32_t count[2];
+    unsigned char buffer[64];
+} SHA1_CTX;
+
+
+static void
+SHA1_Transform(uint32_t[5], const unsigned char[64]);
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/* blk0() and blk() perform the initial expand. */
+/* I got the idea of expanding during the round function from SSLeay */
+#define blk0(i) (block->l[i] = htonl(block->l[i]))
+#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
+    ^block->l[(i+2)&15]^block->l[i&15],1))
+
+/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
+#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
+#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
+#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
+
+
+/* Hash a single 512-bit block. This is the core of the algorithm. */
+
+static void
+SHA1_Transform(uint32_t state[5], const unsigned char buffer[64])
+{
+    uint32_t a, b, c, d, e;
+    typedef union {
+       unsigned char c[64];
+       uint32_t l[16];
+    } CHAR64LONG16;
+    CHAR64LONG16 *block;
+
+#ifdef SHA1HANDSOFF
+    static unsigned char workspace[64];
+    block = (CHAR64LONG16 *) workspace;
+    memcpy(block, buffer, 64);
+#else
+    block = (CHAR64LONG16 *) buffer;
+#endif
+    /* Copy context->state[] to working vars */
+    a = state[0];
+    b = state[1];
+    c = state[2];
+    d = state[3];
+    e = state[4];
+    /* 4 rounds of 20 operations each. Loop unrolled. */
+    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
+    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
+    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
+    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
+    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
+    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
+    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
+    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
+    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
+    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
+    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
+    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
+    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
+    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
+    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
+    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
+    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
+    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
+    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
+    /* Add the working vars back into context.state[] */
+    state[0] += a;
+    state[1] += b;
+    state[2] += c;
+    state[3] += d;
+    state[4] += e;
+    /* Wipe variables */
+    a = b = c = d = e = 0;
+}
+
+
+/* SHA1Init - Initialize new context */
+
+static void
+SHA1_Init(SHA1_CTX *context)
+{
+    /* SHA1 initialization constants */
+    context->state[0] = 0x67452301;
+    context->state[1] = 0xEFCDAB89;
+    context->state[2] = 0x98BADCFE;
+    context->state[3] = 0x10325476;
+    context->state[4] = 0xC3D2E1F0;
+    context->count[0] = context->count[1] = 0;
+}
+
+
+/* Run your data through this. */
+
+static void
+SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
+{
+    unsigned int i, j;
+
+    j = (context->count[0] >> 3) & 63;
+    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
+    context->count[1] += (len >> 29);
+    i = 64 - j;
+    while (len >= i) {
+       memcpy(&context->buffer[j], data, i);
+       SHA1_Transform(context->state, context->buffer);
+       data += i;
+       len -= i;
+       i = 64;
+       j = 0;
+    }
+
+    memcpy(&context->buffer[j], data, len);
+}
+
+
+/* Add padding and return the message digest. */
+
+static void
+SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
+{
+    uint32_t i, j;
+    unsigned char finalcount[8];
+
+    for (i = 0; i < 8; i++) {
+        finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
+         >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
+    }
+    SHA1_Update(context, (unsigned char *) "\200", 1);
+    while ((context->count[0] & 504) != 448) {
+       SHA1_Update(context, (unsigned char *) "\0", 1);
+    }
+    SHA1_Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */
+    for (i = 0; i < 20; i++) {
+       digest[i] = (unsigned char)
+                    ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
+    }
+    /* Wipe variables */
+    i = j = 0;
+    memset(context->buffer, 0, 64);
+    memset(context->state, 0, 20);
+    memset(context->count, 0, 8);
+    memset(&finalcount, 0, 8);
+#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
+    SHA1Transform(context->state, context->buffer);
+#endif
+}
+
+static int sha1_init(PPP_MD_CTX *ctx)
+{
+    if (ctx) {
+        SHA1_CTX *mctx = calloc(1, sizeof(SHA1_CTX));
+        if (mctx) {
+            SHA1_Init(mctx);
+            ctx->priv = mctx;
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static int sha1_update(PPP_MD_CTX* ctx, const void *data, size_t len)
+{
+    SHA1_Update((SHA1_CTX*) ctx->priv, (void*) data, len);
+    return 1;
+}
+
+static int sha1_final(PPP_MD_CTX *ctx, unsigned char *out, unsigned int *len)
+{
+    SHA1_Final(out, (SHA1_CTX*) ctx->priv);
+    return 1;
+}
+
+static void sha1_clean(PPP_MD_CTX *ctx)
+{
+    if (ctx->priv) {
+        free(ctx->priv);
+        ctx->priv = NULL;
+    }
+}
+
+#endif
+
+static PPP_MD ppp_sha1 = {
+    .init_fn = sha1_init,
+    .update_fn = sha1_update,
+    .final_fn = sha1_final,
+    .clean_fn = sha1_clean,
+};
+
+const PPP_MD *PPP_sha1(void)
+{
+    return &ppp_sha1;
+}
+
diff --git a/pppd/pppcrypt.c b/pppd/pppcrypt.c
deleted file mode 100644 (file)
index a954d62..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
- *
- * Extracted from chap_ms.c by James Carlson.
- *
- * Copyright (c) 1995 Eric Rosenquist.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <errno.h>
-
-#include "pppd.h"
-#include "pppcrypt.h"
-
-static u_char
-Get7Bits(u_char *input, int startBit)
-{
-       unsigned int word;
-
-       word  = (unsigned)input[startBit / 8] << 8;
-       word |= (unsigned)input[startBit / 8 + 1];
-
-       word >>= 15 - (startBit % 8 + 7);
-
-       return word & 0xFE;
-}
-
-static void
-MakeKey(u_char *key, u_char *des_key)
-{
-       /* key     IN  56 bit DES key missing parity bits */
-       /* des_key OUT 64 bit DES key with parity bits added */
-       des_key[0] = Get7Bits(key,  0);
-       des_key[1] = Get7Bits(key,  7);
-       des_key[2] = Get7Bits(key, 14);
-       des_key[3] = Get7Bits(key, 21);
-       des_key[4] = Get7Bits(key, 28);
-       des_key[5] = Get7Bits(key, 35);
-       des_key[6] = Get7Bits(key, 42);
-       des_key[7] = Get7Bits(key, 49);
-
-#ifndef USE_CRYPT
-       DES_set_odd_parity((DES_cblock *)des_key);
-#endif
-}
-
-#ifdef USE_CRYPT
-/*
- * in == 8-byte string (expanded version of the 56-bit key)
- * out == 64-byte string where each byte is either 1 or 0
- * Note that the low-order "bit" is always ignored by by setkey()
- */
-static void
-Expand(u_char *in, u_char *out)
-{
-        int j, c;
-        int i;
-
-        for (i = 0; i < 64; in++){
-               c = *in;
-                for (j = 7; j >= 0; j--)
-                        *out++ = (c >> j) & 01;
-                i += 8;
-        }
-}
-
-/* The inverse of Expand
- */
-static void
-Collapse(u_char *in, u_char *out)
-{
-        int j;
-        int i;
-       unsigned int c;
-
-       for (i = 0; i < 64; i += 8, out++) {
-           c = 0;
-           for (j = 7; j >= 0; j--, in++)
-               c |= *in << j;
-           *out = c & 0xff;
-       }
-}
-
-bool
-DesSetkey(u_char *key)
-{
-       u_char des_key[8];
-       u_char crypt_key[66];
-
-       MakeKey(key, des_key);
-       Expand(des_key, crypt_key);
-       errno = 0;
-       setkey((const char *)crypt_key);
-       if (errno != 0)
-               return (0);
-       return (1);
-}
-
-bool
-DesEncrypt(u_char *clear, u_char *cipher)
-{
-       u_char des_input[66];
-
-       Expand(clear, des_input);
-       errno = 0;
-       encrypt((char *)des_input, 0);
-       if (errno != 0)
-               return (0);
-       Collapse(des_input, cipher);
-       return (1);
-}
-
-bool
-DesDecrypt(u_char *cipher, u_char *clear)
-{
-       u_char des_input[66];
-
-       Expand(cipher, des_input);
-       errno = 0;
-       encrypt((char *)des_input, 1);
-       if (errno != 0)
-               return (0);
-       Collapse(des_input, clear);
-       return (1);
-}
-
-#else /* USE_CRYPT */
-static DES_key_schedule        key_schedule;
-
-bool
-DesSetkey(u_char *key)
-{
-       DES_cblock des_key;
-       MakeKey(key, des_key);
-       DES_set_key(&des_key, &key_schedule);
-       return (1);
-}
-
-bool
-DesEncrypt(u_char *clear, u_char *cipher)
-{
-       DES_ecb_encrypt((DES_cblock *)clear, (DES_cblock *)cipher,
-           &key_schedule, 1);
-       return (1);
-}
-
-bool
-DesDecrypt(u_char *cipher, u_char *clear)
-{
-       DES_ecb_encrypt((DES_cblock *)cipher, (DES_cblock *)clear,
-           &key_schedule, 0);
-       return (1);
-}
-
-#endif /* USE_CRYPT */
diff --git a/pppd/pppcrypt.h b/pppd/pppcrypt.h
deleted file mode 100644 (file)
index fff396c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1
- *
- * Extracted from chap_ms.c by James Carlson.
- *
- * Copyright (c) 1995 Eric Rosenquist.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-#ifndef PPP_PPPCRYPT_H
-#define        PPP_PPPCRYPT_H
-
-#include "pppdconf.h"
-
-#ifdef HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-
-#ifndef USE_CRYPT
-#include <openssl/des.h>
-#endif
-
-extern bool    DesSetkey(u_char *);
-extern bool    DesEncrypt(u_char *, u_char *);
-extern bool    DesDecrypt(u_char *, u_char *);
-
-#endif /* PPP_PPPCRYPT_H */
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
new file mode 100644 (file)
index 0000000..d8ec443
--- /dev/null
@@ -0,0 +1,634 @@
+/*
+ * pppd-private.h - PPP daemon private declarations.
+ *
+ * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name "Carnegie Mellon University" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For permission or any legal
+ *    details, please contact
+ *      Office of Technology Transfer
+ *      Carnegie Mellon University
+ *      5000 Forbes Avenue
+ *      Pittsburgh, PA  15213-3890
+ *      (412) 268-4387, fax: (412) 268-7395
+ *      tech-transfer@andrew.cmu.edu
+ *
+ * 4. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by Computing Services
+ *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
+ *
+ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef PPP_PPPD_PRIVATE_H
+#define PPP_PPPD_PRIVATE_H
+
+#include <stdio.h>             /* for FILE */
+#include <stdlib.h>            /* for encrypt */
+#include <unistd.h>            /* for setkey */
+#if defined(SOL2)
+#include <net/ppp_defs.h>
+#else
+#include <linux/ppp_defs.h>
+#endif
+
+#include "pppd.h"
+
+#ifdef PPP_WITH_IPV6CP
+#include "eui64.h"
+#endif
+
+/*
+ * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name.
+ * Where should PPP_DRV_NAME come from? Do we include it here?
+ */
+#if !defined(PPP_DRV_NAME)
+#if defined(SOL2)
+#define PPP_DRV_NAME   "sppp"
+#else
+#define PPP_DRV_NAME   "ppp"
+#endif /* defined(SOL2) */
+#endif /* !defined(PPP_DRV_NAME) */
+
+
+#ifndef GIDSET_TYPE
+#define GIDSET_TYPE    gid_t
+#endif
+
+/* Structure representing a list of permitted IP addresses. */
+struct permitted_ip {
+    int                permit;         /* 1 = permit, 0 = forbid */
+    u_int32_t  base;           /* match if (addr & mask) == base */
+    u_int32_t  mask;           /* base and mask are in network byte order */
+};
+
+struct notifier {
+    struct notifier *next;
+    ppp_notify_fn *func;
+    void *arg;
+};
+
+/*
+ * Global variables.
+ */
+
+extern int     hungup;         /* Physical layer has disconnected */
+extern int     ifunit;         /* Interface unit number */
+extern char    ifname[];       /* Interface name (IFNAMSIZ) */
+extern char    hostname[];     /* Our hostname */
+extern unsigned char   outpacket_buf[]; /* Buffer for outgoing packets */
+extern int     devfd;          /* fd of underlying device */
+extern int     fd_ppp;         /* fd for talking PPP */
+extern int     baud_rate;      /* Current link speed in bits/sec */
+extern char    *progname;      /* Name of this program */
+extern int     redirect_stderr;/* Connector's stderr should go to file */
+extern char    peer_authname[];/* Authenticated name of peer */
+extern int     auth_done[NUM_PPP]; /* Methods actually used for auth */
+extern int     privileged;     /* We were run by real-uid root */
+extern int     need_holdoff;   /* Need holdoff period after link terminates */
+extern char    **script_env;   /* Environment variables for scripts */
+extern int     detached;       /* Have detached from controlling tty */
+extern GIDSET_TYPE groups[];   /* groups the user is in */
+extern int     ngroups;        /* How many groups valid in groups */
+extern int     link_stats_valid; /* set if link_stats is valid */
+extern int     link_stats_print; /* set if link_stats is to be printed on link termination */
+extern int     log_to_fd;      /* logging to this fd as well as syslog */
+extern bool    log_default;    /* log_to_fd is default (stdout) */
+extern char    *no_ppp_msg;    /* message to print if ppp not in kernel */
+extern bool    devnam_fixed;   /* can no longer change devnam */
+extern int     unsuccess;      /* # unsuccessful connection attempts */
+extern int     do_callback;    /* set if we want to do callback next */
+extern int     doing_callback; /* set if this is a callback */
+extern int     error_count;    /* # of times error() has been called */
+extern char    ppp_devname[];  /* name of PPP tty (maybe ttypx) */
+extern int     fd_devnull;     /* fd open to /dev/null */
+
+extern int     listen_time;    /* time to listen first (ms) */
+extern bool    bundle_eof;
+extern bool    bundle_terminating;
+
+extern struct notifier *pidchange;   /* for notifications of pid changing */
+extern struct notifier *phasechange; /* for notifications of phase changes */
+extern struct notifier *exitnotify;  /* for notification that we're exiting */
+extern struct notifier *sigreceived; /* notification of received signal */
+extern struct notifier *ip_up_notifier;     /* IPCP has come up */
+extern struct notifier *ip_down_notifier;   /* IPCP has gone down */
+extern struct notifier *ipv6_up_notifier;   /* IPV6CP has come up */
+extern struct notifier *ipv6_down_notifier; /* IPV6CP has gone down */
+extern struct notifier *auth_up_notifier; /* peer has authenticated */
+extern struct notifier *link_down_notifier; /* link has gone down */
+extern struct notifier *fork_notifier; /* we are a new child process */
+
+
+/* Values for do_callback and doing_callback */
+#define CALLBACK_DIALIN                1       /* we are expecting the call back */
+#define CALLBACK_DIALOUT       2       /* we are dialling out to call back */
+
+/*
+ * Variables set by command-line options.
+ */
+
+extern int     debug;          /* Debug flag */
+extern int     kdebugflag;     /* Tell kernel to print debug messages */
+extern int     default_device; /* Using /dev/tty or equivalent */
+extern char    devnam[];       /* Device name */
+extern char remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */
+extern int  ppp_session_number; /* Session number (eg PPPoE session) */
+extern int     crtscts;        /* Use hardware flow control */
+extern int     stop_bits;      /* Number of serial port stop bits */
+extern bool    modem;          /* Use modem control lines */
+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 (options.c) */
+extern char    *initializer;   /* Script to initialize physical link */
+extern char    *connect_script; /* Script to establish physical link */
+extern char    *disconnect_script; /* Script to disestablish physical link */
+extern char    *welcomer;      /* Script to welcome client after connection */
+extern char    *ptycommand;    /* Command to run on other side of pty */
+extern char    user[MAXNAMELEN];/* Our name for authenticating ourselves */
+extern char    passwd[MAXSECRETLEN];   /* Password for PAP or CHAP */
+extern bool    auth_required;  /* Peer is required to authenticate */
+extern bool    persist;        /* Reopen link after it goes down */
+extern bool    uselogin;       /* Use /etc/passwd for checking PAP */
+extern bool    session_mgmt;   /* Do session management (login records) */
+extern char    our_name[MAXNAMELEN];/* Our name for authentication purposes */
+extern char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
+extern char    path_upapfile[];/* Pathname of pap-secrets file */
+extern char    path_chapfile[];/* Pathname of chap-secrets file */
+extern bool    explicit_remote;/* remote_name specified with remotename opt */
+extern bool    demand;         /* Do dial-on-demand */
+extern char    *ipparam;       /* Extra parameter for ip up/down scripts */
+extern bool    cryptpap;       /* Others' PAP passwords are encrypted */
+extern int     holdoff;        /* Dead time before restarting */
+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 */
+extern int     connect_delay;  /* Time to delay after connect script */
+extern int     max_data_rate;  /* max bytes/sec through charshunt */
+extern int     req_unit;       /* interface unit number to use */
+extern char    path_net_init[]; /* pathname of net-init script */
+extern char    path_net_preup[];/* pathname of net-pre-up script */
+extern char    path_net_down[]; /* pathname of net-down script */
+extern char    path_ipup[];    /* pathname of ip-up script */
+extern char    path_ipdown[];  /* pathname of ip-down script */
+extern char    path_ippreup[]; /* pathname of ip-pre-up script */
+extern char    req_ifname[]; /* interface name to use (IFNAMSIZ) */
+extern bool    multilink;      /* enable multilink operation (options.c) */
+extern bool    noendpoint;     /* don't send or accept endpt. discrim. */
+extern char    *bundle_name;   /* bundle name for multilink */
+extern bool    dump_options;   /* print out option values */
+extern bool    show_options;   /* show all option names and descriptions */
+extern bool    dryrun;         /* check everything, print options, exit */
+extern int     child_wait;     /* # seconds to wait for children at end */
+extern char *current_option;    /* the name of the option being parsed */
+extern int  privileged_option;  /* set iff the current option came from root */
+extern char *option_source;     /* string saying where the option came from */
+extern int  option_priority;    /* priority of current options */
+
+#ifdef PPP_WITH_IPV6CP
+extern char    path_ipv6up[]; /* pathname of ipv6-up script */
+extern char    path_ipv6down[]; /* pathname of ipv6-down script */
+#endif
+
+#if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
+#define TLS_VERIFY_NONE     "none"
+#define TLS_VERIFY_NAME     "name"
+#define TLS_VERIFY_SUBJECT  "subject"
+#define TLS_VERIFY_SUFFIX   "suffix"
+
+extern char *crl_dir;
+extern char *crl_file;
+extern char *ca_path;
+extern char *cacert_file;
+
+extern char *max_tls_version;
+extern bool tls_verify_key_usage;
+extern char *tls_verify_method;
+#endif /* PPP_WITH_EAPTLS || PPP_WITH_PEAP */
+
+#ifdef PPP_WITH_EAPTLS
+extern char *pkcs12_file;
+#endif /* PPP_WITH_EAPTLS */
+
+typedef enum {
+    PPP_OCTETS_DIRECTION_SUM,
+    PPP_OCTETS_DIRECTION_IN,
+    PPP_OCTETS_DIRECTION_OUT,
+    PPP_OCTETS_DIRECTION_MAXOVERAL,
+    PPP_OCTETS_DIRECTION_MAXSESSION             /* Same as MAXOVERALL, but a little different for RADIUS */
+} session_limit_dir_t;
+
+extern unsigned int        maxoctets;           /* Maximum octetes per session (in bytes) */
+extern session_limit_dir_t maxoctets_dir;       /* Direction */
+extern int                 maxoctets_timeout;   /* Timeout for check of octets limit */
+
+#ifdef PPP_WITH_FILTER
+extern struct  bpf_program pass_filter;   /* Filter for pkts to pass */
+extern struct  bpf_program active_filter; /* Filter for link-active pkts */
+#endif
+
+#ifdef PPP_WITH_MSLANMAN
+extern bool    ms_lanman;      /* Use LanMan password instead of NT */
+                               /* Has meaning only with MS-CHAP challenges */
+#endif
+
+/* Values for auth_pending, auth_done */
+#define PAP_WITHPEER   0x1
+#define PAP_PEER       0x2
+#define CHAP_WITHPEER  0x4
+#define CHAP_PEER      0x8
+#define EAP_WITHPEER   0x10
+#define EAP_PEER       0x20
+
+/* Values for auth_done only */
+#define CHAP_MD5_WITHPEER      0x40
+#define CHAP_MD5_PEER          0x80
+#define CHAP_MS_SHIFT          8       /* LSB position for MS auths */
+#define CHAP_MS_WITHPEER       0x100
+#define CHAP_MS_PEER           0x200
+#define CHAP_MS2_WITHPEER      0x400
+#define CHAP_MS2_PEER          0x800
+
+
+/*
+ * This structure contains environment variables that are set or unset
+ * by the user.
+ */
+struct userenv {
+       struct userenv *ue_next;
+       char *ue_value;         /* value (set only) */
+       bool ue_isset;          /* 1 for set, 0 for unset */
+       bool ue_priv;           /* from privileged source */
+       const char *ue_source;  /* source name */
+       char ue_name[1];        /* variable name */
+};
+
+extern struct userenv *userenv_list;
+
+/*
+ * Prototypes.
+ */
+
+/* Procedures exported from main.c. */
+void set_ifunit(int);  /* set stuff that depends on ifunit */
+void detach(void);     /* Detach from controlling tty */
+void die(int);         /* Cleanup and exit */
+void quit(void);               /* like die(1) */
+
+void record_child(int, char *, void (*) (void *), void *, int);
+int  device_script(char *cmd, int in, int out, int dont_wait);
+                               /* Run `cmd' with given stdin and stdout */
+pid_t run_program(char *prog, char * const * args, int must_exist,
+                 void (*done)(void *), void *arg, int wait);
+                               /* Run program prog with args in child */
+void reopen_log(void); /* (re)open the connection to syslog */
+void print_link_stats(void); /* Print stats, if available */
+void reset_link_stats(int); /* Reset (init) stats when link goes up */
+void new_phase(ppp_phase_t);   /* signal start of new phase */
+bool in_phase(ppp_phase_t);
+void notify(struct notifier *, int);
+int  ppp_send_config(int, int, u_int32_t, int, int);
+int  ppp_recv_config(int, int, u_int32_t, int, int);
+const char *protocol_name(int);
+void remove_pidfiles(void);
+void lock_db(void);
+void unlock_db(void);
+
+/* Procedures exported from tty.c. */
+void tty_init(void);
+
+void print_string(char *, int,  printer_func, void *);
+                               /* Format a string for output */
+ssize_t complete_read(int, void *, size_t);
+                               /* read a complete buffer */
+
+/* Procedures exported from auth.c */
+void link_required(int);         /* we are starting to use the link */
+void start_link(int);    /* bring the link up now */
+void link_terminated(int);  /* we are finished with the link */
+void link_down(int);     /* the LCP layer has left the Opened state */
+void upper_layers_down(int);/* take all NCPs down */
+void link_established(int); /* the link is up; authenticate now */
+void start_networks(int);   /* start all the network control protos */
+void continue_networks(int); /* start network [ip, etc] control protos */
+void np_up(int, int);    /* a network protocol has come up */
+void np_down(int, int);          /* a network protocol has gone down */
+void np_finished(int, int); /* a network protocol no longer needs link */
+void auth_peer_fail(int, int);
+                               /* peer failed to authenticate itself */
+void auth_peer_success(int, int, int, char *, int);
+                               /* peer successfully authenticated itself */
+void auth_withpeer_fail(int, int);
+                               /* we failed to authenticate ourselves */
+void auth_withpeer_success(int, int, int);
+                               /* we successfully authenticated ourselves */
+void auth_check_options(void);
+                               /* check authentication options supplied */
+void auth_reset(int);  /* check what secrets we have */
+int  check_passwd(int, char *, int, char *, int, char **);
+                               /* Check peer-supplied username/password */
+int  get_secret(int, char *, char *, char *, int *, int);
+                               /* get "secret" for chap */
+int  get_srp_secret(int unit, char *client, char *server, char *secret,
+    int am_server);
+int  auth_ip_addr(int, u_int32_t);
+                               /* check if IP address is authorized */
+int  auth_number(void);        /* check if remote number is authorized */
+
+/* Procedures exported from demand.c */
+void demand_conf(void);        /* config interface(s) for demand-dial */
+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 */
+int  loop_chars(unsigned char *, int); /* process chars from loopback */
+int  loop_frame(unsigned char *, int); /* should we bring link up? */
+
+/* Procedures exported from sys-*.c */
+void sys_init(void);   /* Do system-dependent initialization */
+void sys_cleanup(void);        /* Restore system state before exiting */
+int  sys_check_options(void); /* Check options specified */
+int  get_pty(int *, int *, char *, int);       /* Get pty master/slave */
+int  open_ppp_loopback(void); /* Open loopback for demand-dialling */
+int  tty_establish_ppp(int);  /* Turn serial port into a ppp interface */
+void tty_disestablish_ppp(int); /* Restore port to normal operation */
+void make_new_bundle(int, int, int, int); /* Create new bundle */
+int  bundle_attach(int);       /* Attach link to existing bundle */
+void cfg_bundle(int, int, int, int); /* Configure existing bundle */
+void destroy_bundle(void); /* Tell driver to destroy bundle */
+void clean_check(void);        /* Check if line was 8-bit clean */
+void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
+void restore_tty(int); /* Restore port's original parameters */
+void setdtr(int, int); /* Raise or lower port's DTR line */
+void output(int, unsigned char *, int); /* Output a PPP packet */
+void wait_input(struct timeval *);
+                               /* Wait for input, with timeout */
+void add_fd(int);              /* Add fd to set to wait for */
+void remove_fd(int);   /* Remove fd from set to wait for */
+int  read_packet(unsigned char *); /* Read PPP packet */
+int  get_loop_output(void); /* Read pkts from loopback */
+void tty_send_config(int, u_int32_t, int, int);
+                               /* Configure i/f transmit parameters */
+void tty_set_xaccm(ext_accm);
+                               /* Set extended transmit ACCM */
+void tty_recv_config(int, u_int32_t, int, int);
+                               /* Configure i/f receive parameters */
+int  ccp_test(int, unsigned char *, int, int);
+                               /* Test support for compression scheme */
+void ccp_flags_set(int, int, int);
+                               /* Set kernel CCP state */
+int  ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
+int  get_idle_time(int, struct ppp_idle *);
+                               /* Find out how long link has been idle */
+int  get_ppp_stats(int, struct pppd_stats *);
+                               /* Return link statistics */
+int  sifvjcomp(int, int, int, int);
+                               /* Configure VJ TCP header compression */
+int  sifup(int);               /* Configure i/f up for one protocol */
+int  sifnpmode(int u, int proto, enum NPmode mode);
+                               /* Set mode for handling packets for proto */
+int  sifdown(int);     /* Configure i/f down for one protocol */
+int  sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
+                               /* Configure IPv4 addresses for i/f */
+int  cifaddr(int, u_int32_t, u_int32_t);
+                               /* Reset i/f IP addresses */
+#ifdef PPP_WITH_IPV6CP
+int  sif6up(int);              /* Configure i/f up for IPv6 */
+int  sif6down(int);    /* Configure i/f down for IPv6 */
+int  sif6addr(int, eui64_t, eui64_t);
+                               /* Configure IPv6 addresses for i/f */
+int  cif6addr(int, eui64_t, eui64_t);
+                               /* Remove an IPv6 address from i/f */
+#endif
+int  sifdefaultroute(int, u_int32_t, u_int32_t, bool replace_default_rt);
+                               /* Create default route through i/f */
+int  cifdefaultroute(int, u_int32_t, u_int32_t);
+                               /* Delete default route through i/f */
+#ifdef PPP_WITH_IPV6CP
+int  sif6defaultroute(int, eui64_t, eui64_t);
+                               /* Create default IPv6 route through i/f */
+int  cif6defaultroute(int, eui64_t, eui64_t);
+                               /* Delete default IPv6 route through i/f */
+#endif
+int  sifproxyarp(int, u_int32_t);
+                               /* Add proxy ARP entry for peer */
+int  cifproxyarp(int, u_int32_t);
+                               /* Delete proxy ARP entry for peer */
+u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
+int  mkdir_recursive(const char *); /* Recursively create directory */
+int  lock(char *);     /* Create lock file for device */
+int  relock(int);              /* Rewrite lock file with new pid */
+void unlock(void);     /* Delete previously-created lock file */
+void logwtmp(const char *, const char *, const char *);
+                               /* Write entry to wtmp file */
+int  get_host_seed(void);      /* Get host-dependent random number seed */
+int  have_route_to(u_int32_t); /* Check if route to addr exists */
+#ifdef PPP_WITH_FILTER
+int  set_filters(struct bpf_program *pass, struct bpf_program *active);
+                               /* Set filter programs in kernel */
+#endif
+int  get_if_hwaddr(unsigned char *addr, char *name);
+int  get_first_ether_hwaddr(unsigned char *addr);
+
+/* Procedures exported from options.c */
+int setipaddr(char *, char **, int); /* Set local/remote ip addresses */
+int  parse_args(int argc, char **argv);
+                               /* Parse options from arguments given */
+int  getword(FILE *f, char *word, int *newlinep, char *filename);
+                               /* Read a word from a file */
+int  options_from_user(void); /* Parse options from user's .ppprc */
+int  options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
+struct wordlist;
+int  options_from_list(struct wordlist *, int privileged);
+                               /* Parse options from a wordlist */
+void check_options(void);      /* check values after all options parsed */
+int  override_value(char *, int, const char *);
+                               /* override value if permitted by priority */
+void print_options(printer_func, void *);
+                               /* print out values of all options */
+void showopts(void);
+                /* show all option names and description */
+int parse_dotted_ip(char *, u_int32_t *);
+
+/*
+ * Inline versions of get/put char/short/long.
+ * Pointer is advanced; we assume that both arguments
+ * are lvalues and will already be in registers.
+ * cp MUST be unsigned char *.
+ */
+#define GETCHAR(c, cp) { \
+       (c) = *(cp)++; \
+}
+#define PUTCHAR(c, cp) { \
+       *(cp)++ = (unsigned char) (c); \
+}
+
+
+#define GETSHORT(s, cp) { \
+       (s) = *(cp)++ << 8; \
+       (s) |= *(cp)++; \
+}
+#define PUTSHORT(s, cp) { \
+       *(cp)++ = (unsigned char) ((s) >> 8); \
+       *(cp)++ = (unsigned char) (s); \
+}
+
+#define GETLONG(l, cp) { \
+       (l) = *(cp)++ << 8; \
+       (l) |= *(cp)++; (l) <<= 8; \
+       (l) |= *(cp)++; (l) <<= 8; \
+       (l) |= *(cp)++; \
+}
+#define PUTLONG(l, cp) { \
+       *(cp)++ = (unsigned char) ((l) >> 24); \
+       *(cp)++ = (unsigned char) ((l) >> 16); \
+       *(cp)++ = (unsigned char) ((l) >> 8); \
+       *(cp)++ = (unsigned char) (l); \
+}
+
+#define INCPTR(n, cp)  ((cp) += (n))
+#define DECPTR(n, cp)  ((cp) -= (n))
+
+/*
+ * System dependent definitions for user-level 4.3BSD UNIX implementation.
+ */
+
+#define TIMEOUT(r, f, t)       ppp_timeout((r), (f), (t), 0)
+#define UNTIMEOUT(r, f)                ppp_untimeout((r), (f))
+
+#define BCOPY(s, d, l)         memcpy(d, s, l)
+#define BZERO(s, n)            memset(s, 0, n)
+#define        BCMP(s1, s2, l)         memcmp(s1, s2, l)
+
+#define PRINTMSG(m, l)         { info("Remote message: %0.*v", l, m); }
+
+/*
+ * MAKEHEADER - Add Header fields to a packet.
+ */
+#define MAKEHEADER(p, t) { \
+    PUTCHAR(PPP_ALLSTATIONS, p); \
+    PUTCHAR(PPP_UI, p); \
+    PUTSHORT(t, p); }
+
+/*
+ * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
+ * useful for finding out why your connection isn't being established.
+ */
+#ifdef DEBUGALL
+#define DEBUGMAIN      1
+#define DEBUGFSM       1
+#define DEBUGLCP       1
+#define DEBUGIPCP      1
+#define DEBUGIPV6CP    1
+#define DEBUGUPAP      1
+#define DEBUGCHAP      1
+#endif
+
+#ifndef LOG_PPP                        /* we use LOG_LOCAL2 for syslog by default */
+#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
+  || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
+  || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
+#define LOG_PPP LOG_LOCAL2
+#else
+#define LOG_PPP LOG_DAEMON
+#endif
+#endif /* LOG_PPP */
+
+#ifdef DEBUGMAIN
+#define MAINDEBUG(x)   if (debug) dbglog x
+#else
+#define MAINDEBUG(x)
+#endif
+
+#ifdef DEBUGSYS
+#define SYSDEBUG(x)    if (debug) dbglog x
+#else
+#define SYSDEBUG(x)
+#endif
+
+#ifdef DEBUGFSM
+#define FSMDEBUG(x)    if (debug) dbglog x
+#else
+#define FSMDEBUG(x)
+#endif
+
+#ifdef DEBUGLCP
+#define LCPDEBUG(x)    if (debug) dbglog x
+#else
+#define LCPDEBUG(x)
+#endif
+
+#ifdef DEBUGIPCP
+#define IPCPDEBUG(x)   if (debug) dbglog x
+#else
+#define IPCPDEBUG(x)
+#endif
+
+#ifdef DEBUGIPV6CP
+#define IPV6CPDEBUG(x)  if (debug) dbglog x
+#else
+#define IPV6CPDEBUG(x)
+#endif
+
+#ifdef DEBUGUPAP
+#define UPAPDEBUG(x)   if (debug) dbglog x
+#else
+#define UPAPDEBUG(x)
+#endif
+
+#ifdef DEBUGCHAP
+#define CHAPDEBUG(x)   if (debug) dbglog x
+#else
+#define CHAPDEBUG(x)
+#endif
+
+#ifndef SIGTYPE
+#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
+#define SIGTYPE void
+#else
+#define SIGTYPE int
+#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
+#endif /* SIGTYPE */
+
+#ifndef MIN
+#define MIN(a, b)      ((a) < (b)? (a): (b))
+#endif
+#ifndef MAX
+#define MAX(a, b)      ((a) > (b)? (a): (b))
+#endif
+
+#ifndef offsetof
+#define offsetof(type, member) ((size_t) &((type *)0)->member)
+#endif
+
+#endif
index 79b5bea5c4a3fdf3220dfb158cfec8b5ad7051df..3a787a0f5357048e4f354f7a7d3d1d743482a751 100644 (file)
@@ -1,12 +1,11 @@
-.\" manual page [] for pppd 2.4
-.\" $Id: pppd.8,v 1.90 2008/03/26 12:09:40 paulus Exp $
+.\" manual page [] for pppd 2.5.x
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
 .\" IP indented paragraph
 .\" TP hanging label
 .\" 
-.\" Copyright (c) 1993-2003 Paul Mackerras <paulus@samba.org>
+.\" Copyright (c) 1993-2024 Paul Mackerras <paulus@ozlabs.org>
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
 .\" purpose with or without fee is hereby granted, provided that the above
@@ -476,7 +475,8 @@ exclude the password string from the log.  This is the default.
 Specifies how many seconds to wait before re-initiating the link after
 it terminates.  This option only has any effect if the \fIpersist\fR
 or \fIdemand\fR option is used.  The holdoff period is not applied if
-the link was terminated because it was idle.
+the link was terminated because it was idle, connect time expired,
+modem hangup or user request.
 .TP
 .B idle \fIn
 Specifies that pppd should disconnect if the link is idle for \fIn\fR
@@ -637,6 +637,10 @@ Set the maximum number of LCP terminate-request transmissions to
 Set the LCP restart interval (retransmission timeout) to \fIn\fR
 seconds (default 3).
 .TP
+.B lcp\-rtt\-file \fIfilename
+Sets the file where the round-trip time (RTT) of LCP echo-request frames
+will be logged.
+.TP
 .B linkname \fIname\fR
 Sets the logical name of the link to \fIname\fR.  Pppd will create a
 file named \fBppp\-\fIname\fB.pid\fR in /var/run (or /etc/ppp on some
@@ -687,7 +691,7 @@ network control protocol comes up).
 Terminate after \fIn\fR consecutive failed connection attempts.  A
 value of 0 means no limit.  The default value is 10.
 .TP
-.B max-tls-version \fIstring
+.B max\-tls-\version \fIstring
 (EAP-TLS, or PEAP) Configures the max allowed TLS version used during
 negotiation with a peer.  The default value for this is \fI1.2\fR.  Values
 allowed for this option is \fI1.0.\fR, \fI1.1\fR, \fI1.2\fR, \fI1.3\fR.
@@ -756,11 +760,18 @@ will be used as the name to send to the peer when authenticating the
 local system to the peer.  (Note that pppd does not append the domain
 name to \fIname\fR.)
 .TP
+.B netmask \fImask
+Set the IPV4 network mask on the PPP interface to the given
+\fImask\fR, which can be given in dotted-quad notation or as a single
+hexadecimal number preceded by 0x.  This option is not normally
+needed because the PPP interface is a point-to-point connection, but
+in some specialized circumstances it can be useful.
+.TP
 .B noaccomp
 Disable Address/Control compression in both directions (send and
 receive).
 .TP
-.B need-peer-eap
+.B need\-peer\-eap
 (EAP-TLS) Require the peer to verify our authentication credentials.
 .TP
 .B noauth
@@ -1136,13 +1147,13 @@ The device used by pppd with this option must have sync support.
 Currently supports Microgate SyncLink adapters
 under Linux and FreeBSD 2.2.8 and later.
 .TP
-.B tls-verify-method \fIstring
+.B tls\-verify\-method \fIstring
 (EAP-TLS, or PEAP) Match the value specified for \fIremotename\fR to that that
 of the X509 certificates subject name, common name, or suffix of the common
 name.  Respective values allowed for this option is: \fInone\fR, \fIsubject\fR,
 \fIname\fR, or \fIsuffix\fR.  The default value for this option is \fIname\fR.
 .TP
-.B tls-verify-key-usage
+.B tls\-verify\-key\-usage
 (EAP-TLS, or PEAP) Enables examination of peer certificate's purpose, and
 extended key usage attributes.
 .TP
@@ -1190,7 +1201,8 @@ by the peer (if any) are passed to the /etc/ppp/ip\-up script in the
 environment variables DNS1 and DNS2, and the environment variable
 USEPEERDNS will be set to 1.  In addition, pppd will create an
 /etc/ppp/resolv.conf file containing one or two nameserver lines with
-the address(es) supplied by the peer.
+the address(es) supplied by the peer (unless the \fInoresolvconf\fR
+option is given).
 .TP
 .B usepeerwins
 Ask the peer for up to 2 WINS server addresses.  The addresses supplied
@@ -1202,6 +1214,9 @@ Please note that some modems (like the Huawei E220) requires this option in
 order to avoid a race condition that results in the incorrect DNS servers
 being assigned.
 .TP
+.B noresolvconf
+Do not create the /etc/ppp/resolv.conf file.
+.TP
 .B user \fIname
 Sets the name used for authenticating the local system to the peer to
 \fIname\fR.
@@ -1233,36 +1248,36 @@ by specifying ppp'd option \fBnic-eth0\fR. Prefix \fBnic-\fR for this
 option may be avoided if interface name is unambiguous and does not
 look like any other pppd's option.
 .TP
-.B pppoe-service \fIname
+.B pppoe\-service \fIname
 Connect to specified PPPoE service name. For backward compatibility also
 \fBrp_pppoe_service\fP option name is supported.
 .TP
-.B pppoe-ac \fIname
+.B pppoe\-ac \fIname
 Connect to specified PPPoE access concentrator name. For backward
 compatibility also \fBrp_pppoe_ac\fP option name is supported.
 .TP
-.B pppoe-sess \fIsessid\fP:\fImacaddr
+.B pppoe\-sess \fIsessid\fP:\fImacaddr
 Attach to existing PPPoE session. For backward compatibility also
 \fBrp_pppoe_sess\fP option name is supported.
 .TP
-.B pppoe-verbose \fIn
+.B pppoe\-verbose \fIn
 Be verbose about discovered access concentrators. When set to 2 or bigger
 value then dump also discovery packets. For backward compatibility also
 \fBrp_pppoe_verbose\fP option name is supported.
 .TP
-.B pppoe-mac \fImacaddr
+.B pppoe\-mac \fImacaddr
 Connect to specified MAC address.
 .TP
-.B pppoe-host-uniq \fIstring
+.B pppoe\-host\-uniq \fIstring
 Set the PPPoE Host-Uniq tag to the supplied hex string.
 By default PPPoE Host-Uniq tag is set to the pppd's process PID.
 For backward compatibility this option may be specified without
 \fBpppoe-\fP prefix.
 .TP
-.B pppoe-padi-timeout \fIn
+.B pppoe\-padi\-timeout \fIn
 Initial timeout for discovery packets in seconds (default 5).
 .TP
-.B pppoe-padi-attempts \fIn
+.B pppoe\-padi\-attempts \fIn
 Number of discovery attempts (default 3).
 .SH OPTIONS FILES
 Options can be taken from files as well as the command line.  Pppd
@@ -1729,8 +1744,8 @@ We failed to authenticate ourselves to the peer.
 Pppd invokes scripts at various stages in its processing which can be
 used to perform site-specific ancillary processing.  These scripts are
 usually shell scripts, but could be executable code files instead.
-Pppd does not wait for the scripts to finish (except for the ip-pre-up
-script).  The scripts are
+Pppd does not wait for the scripts to finish (except for the net\-init,
+net\-pre\-up and ip\-pre\-up scripts).  The scripts are
 executed as root (with the real and effective user-id set to 0), so
 that they can do things such as update routing tables or run
 privileged daemons.  Be careful that the contents of these scripts do
@@ -1766,6 +1781,12 @@ set when IPV6CP has come up.
 The authenticated name of the peer.  This is only set if the peer
 authenticates itself.
 .TP
+.B REMOTENUMBER
+The remote's number as provided to pppd by the remotenumber option.  The
+meaning of this varies based on the type of connection, xl2tpd for example can
+either provide the dialing number AVP or the remote's IP address.  pppoe-server
+typically provides the MAC address.
+.TP
 .B SPEED
 The baud rate of the tty device.
 .TP
@@ -1813,6 +1834,11 @@ first WINS server address supplied.
 .B WINS2
 If the peer supplies WINS server addresses, this variable is set to the
 second WINS server address supplied.
+.TP
+.B ACNAME
+If the pppoe plugin is used to establish a connection to an access
+concentrator (AC), this variable is set to the name of the AC, as
+supplied by the AC.
 .P
 .P
 Pppd invokes the following scripts, if they exist.  It is not an error
@@ -1840,6 +1866,14 @@ IP addresses assigned but is still down.  This can be used to
 add firewall rules before any IP traffic can pass through the
 interface.  Pppd will wait for this script to finish before bringing
 the interface up, so this script should run quickly.
+.PP
+WARNING:  Please note that on systems where a single interface carries multiple
+protocols (Linux) ip-pre-up is NOT actually guaranteed to execute prior to the
+interface moving into an up state, although IP information won't be known you
+should consider using net-pre-up instead, alternatively, disable other NCPs
+such that IPv4 is the only negotiated protocol - which will also result in a
+guarantee that ip-pre-up is called prior to the interface going into an UP
+state.
 .TP
 .B /etc/ppp/ip\-up
 A program or script which is executed when the link is available for
@@ -1869,6 +1903,27 @@ Similar to /etc/ppp/ip\-down, but it is executed when IPv6 packets can no
 longer be transmitted on the link. It is executed with the same parameters 
 as the ipv6\-up script.
 .TP
+.B /etc/ppp/net\-init
+This script will be executed the moment the ppp unit number is known.  This
+script will be waited for and should not cause significant delays.  This can be
+used to update book-keeping type systems external to ppp and provides the only
+guaranteed point where a script can be executed knowing the ppp unit number
+prior to LCP being initiated.  It is executed with the parameters
+.IP
+\fIinterface\-name tty\-device speed ipparam
+.TP
+.B /etc/ppp/net\-pre\-up
+This script will be executed just prior to NCP negotiations initiating, and is
+guaranteed to be executed whilst the interface (Linux) and/or sub-interfaces
+(Solaris) as the case may be is/are still down.  ppp will block waiting for
+this script to complete, and the interface may be safely renamed in this script
+(using for example "ip li set dev $1 name ppp-foobar".  The parameters are the
+same as for net\-init.
+.TP
+.B /etc/ppp/net\-down
+This script will be executed just prior to ppp terminating and will not be
+waited for.  The parameters are the same as for net\-init.
+.TP
 .B /var/run/ppp\fIn\fB.pid \fR(BSD or Linux), \fB/etc/ppp/ppp\fIn\fB.pid \fR(others)
 Process-ID for pppd process on ppp interface unit \fIn\fR.
 .TP
@@ -2013,7 +2068,7 @@ of a fatal decompression error.  (Fatal decompression errors generally
 indicate a bug in one or other implementation.)
 
 .SH AUTHORS
-Paul Mackerras (paulus@samba.org), based on earlier work by
+Paul Mackerras (paulus@ozlabs.org), based on earlier work by
 Drew Perkins,
 Brad Clements,
 Karl Fox,
@@ -2075,7 +2130,7 @@ are met:
 .br
      (412) 268-4387, fax: (412) 268-7395
 .br
-     tech-transfer@andrew.cmu.edu
+     tech\-transfer@andrew.cmu.edu
 .LP
 3b. The name(s) of the authors of this software must not be used to
    endorse or promote products derived from this software without
@@ -2088,7 +2143,7 @@ are met:
     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 .br
    "This product includes software developed by Paul Mackerras
-    <paulus@samba.org>".
+    <paulus@ozlabs.org>".
 .br
    "This product includes software developed by Pedro Roque Marques
     <pedro_m@yahoo.com>".
index bd9faf0f993396742e87862d076b86e9be672b5b..4f020215c7f8d510a0a123c4bdfe9bf3a406075a 100644 (file)
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: pppd.h,v 1.96 2008/06/23 11:47:18 paulus Exp $
  */
 
 #ifndef PPP_PPPD_H
 #define PPP_PPPD_H
 
-#include "pppdconf.h"
-
-#include <stdio.h>             /* for FILE */
-#include <stdlib.h>            /* for encrypt */
-#include <unistd.h>            /* for setkey */
 #include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
 #include <stdint.h>
-#include <sys/types.h>         /* for u_int32_t, if defined */
-#if defined(SOL2)
-#include <net/ppp_defs.h>
-#else
-#include <linux/ppp_defs.h>
-#endif
-
-#ifdef PPP_WITH_IPV6CP
-#if defined(SOL2)
-#include <netinet/in.h>
-
-typedef union {
-    uint8_t    e8[8];          /* lower 64-bit IPv6 address */
-    uint32_t   e32[2];         /* lower 64-bit IPv6 address */
-} eui64_t;
-
-/*
- * Declare the two below, since in.h only defines them when _KERNEL
- * is declared - which shouldn't be true when dealing with user-land programs
- */
-#define        s6_addr8        _S6_un._S6_u8
-#define        s6_addr32       _S6_un._S6_u32
+#include <sys/types.h>
 
-#else /* else if not defined(SOL2) */
-
-/*
- * TODO:
- *
- * Maybe this should be done by processing struct in6_addr directly...
- */
-typedef union
-{
-    u_int8_t e8[8];
-    u_int16_t e16[4];
-    u_int32_t e32[2];
-} eui64_t;
+#include "pppdconf.h"
 
-#endif /* defined(SOL2) */
+#ifdef __cplusplus
+extern "C" {
 #endif
 
 /*
- * Limits.
+ * Limits
  */
-
 #define NUM_PPP                1       /* One PPP interface supported (per process) */
 #define MAXWORDLEN     1024    /* max length of word in file (incl null) */
 #define MAXARGS                1       /* max # args to a command */
 #define MAXNAMELEN     256     /* max length of hostname or name for auth */
 #define MAXSECRETLEN   256     /* max length of password or secret */
 
+
 /*
- * If PPP_DRV_NAME is not defined, use the default "ppp" as the device name.
- * Where should PPP_DRV_NAME come from? Do we include it here?
+ * Values for phase.
  */
-#if !defined(PPP_DRV_NAME)
-#define PPP_DRV_NAME   "ppp"
-#endif /* !defined(PPP_DRV_NAME) */
+typedef enum ppp_phase
+{
+    PHASE_DEAD,
+    PHASE_INITIALIZE,
+    PHASE_SERIALCONN,
+    PHASE_DORMANT,
+    PHASE_ESTABLISH,
+    PHASE_AUTHENTICATE,
+    PHASE_CALLBACK,
+    PHASE_NETWORK,
+    PHASE_RUNNING,
+    PHASE_TERMINATE,
+    PHASE_DISCONNECT,
+    PHASE_HOLDOFF,
+    PHASE_MASTER,
+} ppp_phase_t;
 
 /*
- * Option descriptor structure.
+ * Values for exit codes
  */
+typedef enum ppp_exit_code
+{
+    EXIT_OK                 = 0,
+    EXIT_FATAL_ERROR        = 1,
+    EXIT_OPTION_ERROR       = 2,
+    EXIT_NOT_ROOT           = 3,
+    EXIT_NO_KERNEL_SUPPORT  = 4,
+    EXIT_USER_REQUEST       = 5,
+    EXIT_LOCK_FAILED        = 6,
+    EXIT_OPEN_FAILED        = 7,
+    EXIT_CONNECT_FAILED     = 8,
+    EXIT_PTYCMD_FAILED      = 9,
+    EXIT_NEGOTIATION_FAILED = 10,
+    EXIT_PEER_AUTH_FAILED   = 11,
+    EXIT_IDLE_TIMEOUT       = 12,
+    EXIT_CONNECT_TIME       = 13,
+    EXIT_CALLBACK           = 14,
+    EXIT_PEER_DEAD          = 15,
+    EXIT_HANGUP             = 16,
+    EXIT_LOOPBACK           = 17,
+    EXIT_INIT_FAILED        = 18,
+    EXIT_AUTH_TOPEER_FAILED = 19,
+    EXIT_TRAFFIC_LIMIT      = 20,
+    EXIT_CNID_AUTH_FAILED   = 21
+} ppp_exit_code_t;
 
-typedef unsigned char  bool;
-
-enum opt_type {
-       o_special_noarg = 0,
-       o_special = 1,
-       o_bool,
-       o_int,
-       o_uint32,
-       o_string,
-       o_wild
-};
-
-typedef struct {
-       char    *name;          /* name of the option */
-       enum opt_type type;
-       void    *addr;
-       char    *description;
-       unsigned int flags;
-       void    *addr2;
-       int     upper_limit;
-       int     lower_limit;
-       const char *source;
-       short int priority;
-       short int winner;
-} option_t;
-
-/* Values for flags */
-#define OPT_VALUE      0xff    /* mask for presupplied value */
-#define OPT_HEX                0x100   /* int option is in hex */
-#define OPT_NOARG      0x200   /* option doesn't take argument */
-#define OPT_OR         0x400   /* for u32, OR in argument to value */
-#define OPT_INC                0x400   /* for o_int, increment value */
-#define OPT_A2OR       0x800   /* for o_bool, OR arg to *(u_char *)addr2 */
-#define OPT_PRIV       0x1000  /* privileged option */
-#define OPT_STATIC     0x2000  /* string option goes into static array */
-#define OPT_NOINCR     0x2000  /* for o_int, value mustn't be increased */
-#define OPT_LLIMIT     0x4000  /* check value against lower limit */
-#define OPT_ULIMIT     0x8000  /* check value against upper limit */
-#define OPT_LIMITS     (OPT_LLIMIT|OPT_ULIMIT)
-#define OPT_ZEROOK     0x10000 /* 0 value is OK even if not within limits */
-#define OPT_HIDE       0x10000 /* for o_string, print value as ?????? */
-#define OPT_A2LIST     0x20000 /* for o_special, keep list of values */
-#define OPT_A2CLRB     0x20000 /* o_bool, clr val bits in *(u_char *)addr2 */
-#define OPT_ZEROINF    0x40000 /* with OPT_NOINCR, 0 == infinity */
-#define OPT_PRIO       0x80000 /* process option priorities for this option */
-#define OPT_PRIOSUB    0x100000 /* subsidiary member of priority group */
-#define OPT_ALIAS      0x200000 /* option is alias for previous option */
-#define OPT_A2COPY     0x400000 /* addr2 -> second location to rcv value */
-#define OPT_ENABLE     0x800000 /* use *addr2 as enable for option */
-#define OPT_A2CLR      0x1000000 /* clear *(bool *)addr2 */
-#define OPT_PRIVFIX    0x2000000 /* user can't override if set by root */
-#define OPT_INITONLY   0x4000000 /* option can only be set in init phase */
-#define OPT_DEVEQUIV   0x8000000 /* equiv to device name */
-#define OPT_DEVNAM     (OPT_INITONLY | OPT_DEVEQUIV)
-#define OPT_A2PRINTER  0x10000000 /* *addr2 printer_func to print option */
-#define OPT_A2STRVAL   0x20000000 /* *addr2 points to current string value */
-#define OPT_NOPRINT    0x40000000 /* don't print this option at all */
-
-#define OPT_VAL(x)     ((x) & OPT_VALUE)
-
-/* Values for priority */
-#define OPRIO_DEFAULT  0       /* a default value */
-#define OPRIO_CFGFILE  1       /* value from a configuration file */
-#define OPRIO_CMDLINE  2       /* value from the command line */
-#define OPRIO_SECFILE  3       /* value from options in a secrets file */
-#define OPRIO_ROOT     100     /* added to priority if OPT_PRIVFIX && root */
-
-#ifndef GIDSET_TYPE
-#define GIDSET_TYPE    gid_t
-#endif
-
-/* Structure representing a list of permitted IP addresses. */
-struct permitted_ip {
-    int                permit;         /* 1 = permit, 0 = forbid */
-    u_int32_t  base;           /* match if (addr & mask) == base */
-    u_int32_t  mask;           /* base and mask are in network byte order */
-};
+/*
+ * Type of notifier callbacks
+ */
+typedef enum
+{
+    NF_PID_CHANGE,
+    NF_PHASE_CHANGE,
+    NF_EXIT,
+    NF_SIGNALED,
+    NF_IP_UP,
+    NF_IP_DOWN,
+    NF_IPV6_UP,
+    NF_IPV6_DOWN,
+    NF_AUTH_UP,
+    NF_LINK_DOWN,
+    NF_FORK,
+    NF_MAX_NOTIFY
+} ppp_notify_t;
+
+typedef enum
+{
+    PPP_DIR_LOG,
+    PPP_DIR_RUNTIME,
+    PPP_DIR_CONF,
+    PPP_DIR_PLUGIN,
+} ppp_path_t;
 
 /*
  * Unfortunately, the linux kernel driver uses a different structure
@@ -198,267 +147,36 @@ struct permitted_ip {
  * This structure serves as a common representation for the bits
  * pppd needs.
  */
-struct pppd_stats {
+struct pppd_stats
+{
     uint64_t           bytes_in;
     uint64_t           bytes_out;
     unsigned int       pkts_in;
     unsigned int       pkts_out;
 };
+typedef struct pppd_stats ppp_link_stats_st;
 
-/* Used for storing a sequence of words.  Usually malloced. */
+/*
+ * Used for storing a sequence of words.  Usually malloced.
+ */
 struct wordlist {
     struct wordlist    *next;
     char               *word;
 };
 
-/* An endpoint discriminator, used with multilink. */
-#define MAX_ENDP_LEN   20      /* maximum length of discriminator value */
-struct epdisc {
-    unsigned char      class;
-    unsigned char      length;
-    unsigned char      value[MAX_ENDP_LEN];
-};
-
-/* values for epdisc.class */
-#define EPD_NULL       0       /* null discriminator, no data */
-#define EPD_LOCAL      1
-#define EPD_IP         2
-#define EPD_MAC                3
-#define EPD_MAGIC      4
-#define EPD_PHONENUM   5
-
-typedef void (*notify_func)(void *, int);
+struct option;
 typedef void (*printer_func)(void *, char *, ...);
 
-struct notifier {
-    struct notifier *next;
-    notify_func            func;
-    void           *arg;
-};
-
-/*
- * Global variables.
- */
-
-extern int     got_sigterm;    /* SIGINT or SIGTERM was received */
-extern int     hungup;         /* Physical layer has disconnected */
-extern int     ifunit;         /* Interface unit number */
-extern char    ifname[];       /* Interface name (IFNAMSIZ) */
-extern char    hostname[];     /* Our hostname */
-extern u_char  outpacket_buf[]; /* Buffer for outgoing packets */
-extern int     devfd;          /* fd of underlying device */
-extern int     fd_ppp;         /* fd for talking PPP */
-extern int     phase;          /* Current state of link - see values below */
-extern int     baud_rate;      /* Current link speed in bits/sec */
-extern char    *progname;      /* Name of this program */
-extern int     redirect_stderr;/* Connector's stderr should go to file */
-extern char    peer_authname[];/* Authenticated name of peer */
-extern int     auth_done[NUM_PPP]; /* Methods actually used for auth */
-extern int     privileged;     /* We were run by real-uid root */
-extern int     need_holdoff;   /* Need holdoff period after link terminates */
-extern char    **script_env;   /* Environment variables for scripts */
-extern int     detached;       /* Have detached from controlling tty */
-extern GIDSET_TYPE groups[];   /* groups the user is in */
-extern int     ngroups;        /* How many groups valid in groups */
-extern struct pppd_stats link_stats; /* byte/packet counts etc. for link */
-extern int     link_stats_valid; /* set if link_stats is valid */
-extern unsigned        link_connect_time; /* time the link was up for */
-extern int     using_pty;      /* using pty as device (notty or pty opt.) */
-extern int     log_to_fd;      /* logging to this fd as well as syslog */
-extern bool    log_default;    /* log_to_fd is default (stdout) */
-extern char    *no_ppp_msg;    /* message to print if ppp not in kernel */
-extern volatile int status;    /* exit status for pppd */
-extern bool    devnam_fixed;   /* can no longer change devnam */
-extern int     unsuccess;      /* # unsuccessful connection attempts */
-extern int     do_callback;    /* set if we want to do callback next */
-extern int     doing_callback; /* set if this is a callback */
-extern int     error_count;    /* # of times error() has been called */
-extern char    ppp_devnam[];   /* name of PPP tty (maybe ttypx) */
-extern char     remote_number[MAXNAMELEN]; /* Remote telephone number, if avail. */
-extern int      ppp_session_number; /* Session number (eg PPPoE session) */
-extern int     fd_devnull;     /* fd open to /dev/null */
-
-extern int     listen_time;    /* time to listen first (ms) */
-extern bool    doing_multilink;
-extern bool    multilink_master;
-extern bool    bundle_eof;
-extern bool    bundle_terminating;
-
-extern struct notifier *pidchange;   /* for notifications of pid changing */
-extern struct notifier *phasechange; /* for notifications of phase changes */
-extern struct notifier *exitnotify;  /* for notification that we're exiting */
-extern struct notifier *sigreceived; /* notification of received signal */
-extern struct notifier *ip_up_notifier;     /* IPCP has come up */
-extern struct notifier *ip_down_notifier;   /* IPCP has gone down */
-extern struct notifier *ipv6_up_notifier;   /* IPV6CP has come up */
-extern struct notifier *ipv6_down_notifier; /* IPV6CP has gone down */
-extern struct notifier *auth_up_notifier; /* peer has authenticated */
-extern struct notifier *link_down_notifier; /* link has gone down */
-extern struct notifier *fork_notifier; /* we are a new child process */
-
-/* Values for do_callback and doing_callback */
-#define CALLBACK_DIALIN                1       /* we are expecting the call back */
-#define CALLBACK_DIALOUT       2       /* we are dialling out to call back */
-
-/*
- * Variables set by command-line options.
- */
-
-extern int     debug;          /* Debug flag */
-extern int     kdebugflag;     /* Tell kernel to print debug messages */
-extern int     default_device; /* Using /dev/tty or equivalent */
-extern char    devnam[];       /* Device name */
-extern int     crtscts;        /* Use hardware flow control */
-extern int     stop_bits;      /* Number of serial port stop bits */
-extern bool    modem;          /* Use modem control lines */
-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 */
-extern char    *connect_script; /* Script to establish physical link */
-extern char    *disconnect_script; /* Script to disestablish physical link */
-extern char    *welcomer;      /* Script to welcome client after connection */
-extern char    *ptycommand;    /* Command to run on other side of pty */
-extern int     maxconnect;     /* Maximum connect time (seconds) */
-extern char    user[MAXNAMELEN];/* Our name for authenticating ourselves */
-extern char    passwd[MAXSECRETLEN];   /* Password for PAP or CHAP */
-extern bool    auth_required;  /* Peer is required to authenticate */
-extern bool    persist;        /* Reopen link after it goes down */
-extern bool    uselogin;       /* Use /etc/passwd for checking PAP */
-extern bool    session_mgmt;   /* Do session management (login records) */
-extern char    our_name[MAXNAMELEN];/* Our name for authentication purposes */
-extern char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
-extern bool    explicit_remote;/* remote_name specified with remotename opt */
-extern bool    demand;         /* Do dial-on-demand */
-extern char    *ipparam;       /* Extra parameter for ip up/down scripts */
-extern bool    cryptpap;       /* Others' PAP passwords are encrypted */
-extern int     idle_time_limit;/* Shut down link if idle for this long */
-extern int     holdoff;        /* Dead time before restarting */
-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 bool    sync_serial;    /* Device is synchronous serial device */
-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 */
-extern int     connect_delay;  /* Time to delay after connect script */
-extern int     max_data_rate;  /* max bytes/sec through charshunt */
-extern int     req_unit;       /* interface unit number to use */
-extern char    path_ipup[];    /* pathname of ip-up script */
-extern char    path_ipdown[];  /* pathname of ip-down script */
-extern char    req_ifname[]; /* interface name to use (IFNAMSIZ) */
-extern bool    multilink;      /* enable multilink operation */
-extern bool    noendpoint;     /* don't send or accept endpt. discrim. */
-extern char    *bundle_name;   /* bundle name for multilink */
-extern bool    dump_options;   /* print out option values */
-extern bool    dryrun;         /* check everything, print options, exit */
-extern int     child_wait;     /* # seconds to wait for children at end */
-
-#ifdef PPP_WITH_IPV6CP
-extern char    path_ipv6up[]; /* pathname of ipv6-up script */
-extern char    path_ipv6down[]; /* pathname of ipv6-down script */
-#endif
-
-#if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP)
-#define TLS_VERIFY_NONE     "none"
-#define TLS_VERIFY_NAME     "name"
-#define TLS_VERIFY_SUBJECT  "subject"
-#define TLS_VERIFY_SUFFIX   "suffix"
-
-extern char *crl_dir;
-extern char *crl_file;
-extern char *ca_path;
-extern char *cacert_file;
-
-extern char *max_tls_version;
-extern bool tls_verify_key_usage;
-extern char *tls_verify_method;
-#endif /* PPP_WITH_EAPTLS || PPP_WITH_PEAP */
-
-#ifdef PPP_WITH_EAPTLS
-extern char *pkcs12_file;
-#endif /* PPP_WITH_EAPTLS */
-
-extern unsigned int maxoctets;      /* Maximum octetes per session (in bytes) */
-extern int       maxoctets_dir;      /* Direction :
-                                     0 - in+out (default)
-                                     1 - in
-                                     2 - out
-                                     3 - max(in,out) */
-extern int       maxoctets_timeout;  /* Timeout for check of octets limit */
-#define PPP_OCTETS_DIRECTION_SUM        0
-#define PPP_OCTETS_DIRECTION_IN         1
-#define PPP_OCTETS_DIRECTION_OUT        2
-#define PPP_OCTETS_DIRECTION_MAXOVERAL  3
-/* same as previos, but little different on RADIUS side */
-#define PPP_OCTETS_DIRECTION_MAXSESSION 4
-
-#ifdef PPP_WITH_FILTER
-extern struct  bpf_program pass_filter;   /* Filter for pkts to pass */
-extern struct  bpf_program active_filter; /* Filter for link-active pkts */
-#endif
-
-#ifdef PPP_WITH_MSLANMAN
-extern bool    ms_lanman;      /* Use LanMan password instead of NT */
-                               /* Has meaning only with MS-CHAP challenges */
-#endif
-
-/* Values for auth_pending, auth_done */
-#define PAP_WITHPEER   0x1
-#define PAP_PEER       0x2
-#define CHAP_WITHPEER  0x4
-#define CHAP_PEER      0x8
-#define EAP_WITHPEER   0x10
-#define EAP_PEER       0x20
-
-/* Values for auth_done only */
-#define CHAP_MD5_WITHPEER      0x40
-#define CHAP_MD5_PEER          0x80
-#define CHAP_MS_SHIFT          8       /* LSB position for MS auths */
-#define CHAP_MS_WITHPEER       0x100
-#define CHAP_MS_PEER           0x200
-#define CHAP_MS2_WITHPEER      0x400
-#define CHAP_MS2_PEER          0x800
-
-extern char *current_option;   /* the name of the option being parsed */
-extern int  privileged_option; /* set iff the current option came from root */
-extern char *option_source;    /* string saying where the option came from */
-extern int  option_priority;   /* priority of current options */
-
-/*
- * Values for phase.
- */
-#define PHASE_DEAD             0
-#define PHASE_INITIALIZE       1
-#define PHASE_SERIALCONN       2
-#define PHASE_DORMANT          3
-#define PHASE_ESTABLISH                4
-#define PHASE_AUTHENTICATE     5
-#define PHASE_CALLBACK         6
-#define PHASE_NETWORK          7
-#define PHASE_RUNNING          8
-#define PHASE_TERMINATE                9
-#define PHASE_DISCONNECT       10
-#define PHASE_HOLDOFF          11
-#define PHASE_MASTER           12
-
 /*
- * The following struct gives the addresses of procedures to call
- * for a particular protocol.
+ * The following struct gives the addresses of procedures to call for a particular protocol.
  */
 struct protent {
-    u_short protocol;          /* PPP protocol number */
+    /* PPP protocol number */
+    unsigned short protocol;
     /* Initialization procedure */
     void (*init)(int unit);
     /* Process a received packet */
-    void (*input)(int unit, u_char *pkt, int len);
+    void (*input)(int unit, unsigned char *pkt, int len);
     /* Process a received protocol-reject */
     void (*protrej)(int unit);
     /* Lower layer has come up */
@@ -470,34 +188,37 @@ struct protent {
     /* Close the protocol */
     void (*close)(int unit, char *reason);
     /* Print a packet in readable form */
-    int  (*printpkt)(u_char *pkt, int len, printer_func printer, void *arg);
+    int  (*printpkt)(unsigned char *pkt, int len, printer_func printer, void *arg);
     /* Process a received data packet */
-    void (*datainput)(int unit, u_char *pkt, int len);
-    bool enabled_flag;         /* 0 iff protocol is disabled */
-    char *name;                        /* Text name of protocol */
-    char *data_name;           /* Text name of corresponding data protocol */
-    option_t *options;         /* List of command-line options */
+    void (*datainput)(int unit, unsigned char *pkt, int len);
+    /* 0 iff protocol is disabled */
+    bool enabled_flag;
+    /* Text name of protocol */
+    char *name;
+    /* Text name of corresponding data protocol */
+    char *data_name;
+    /* List of command-line options */
+    struct option *options;
     /* Check requested options, assign defaults */
     void (*check_options)(void);
     /* Configure interface for demand-dial */
     int  (*demand_conf)(int unit);
     /* Say whether to bring up link for this pkt */
-    int  (*active_pkt)(u_char *pkt, int len);
+    int  (*active_pkt)(unsigned char *pkt, int len);
 };
 
 /* Table of pointers to supported protocols */
 extern struct protent *protocols[];
 
+
 /*
- * This struct contains pointers to a set of procedures for
- * doing operations on a "channel".  A channel provides a way
- * to send and receive PPP packets - the canonical example is
- * a serial port device in PPP line discipline (or equivalently
- * with PPP STREAMS modules pushed onto it).
+ * This struct contains pointers to a set of procedures for doing operations on a "channel".  
+ * A channel provides a way to send and receive PPP packets - the canonical example is a serial 
+ * port device in PPP line discipline (or equivalently with PPP STREAMS modules pushed onto it).
  */
 struct channel {
        /* set of options for this channel */
-       option_t *options;
+       struct option *options;
        /* find and process a per-channel options file */
        void (*process_extra_options)(void);
        /* check all the options that have been given */
@@ -511,9 +232,9 @@ struct channel {
        /* take the channel out of PPP `mode', restore loopback if demand */
        void (*disestablish_ppp)(int);
        /* set the transmit-side PPP parameters of the channel */
-       void (*send_config)(int, u_int32_t, int, int);
+       void (*send_config)(int, uint32_t, int, int);
        /* set the receive-side PPP parameters of the channel */
-       void (*recv_config)(int, u_int32_t, int, int);
+       void (*recv_config)(int, uint32_t, int, int);
        /* cleanup on error or normal exit */
        void (*cleanup)(void);
        /* close the device, called in children after fork */
@@ -522,469 +243,329 @@ struct channel {
 
 extern struct channel *the_channel;
 
+
 /*
- * This structure contains environment variables that are set or unset
- * by the user.
+ * Functions for string formatting and debugging
  */
-struct userenv {
-       struct userenv *ue_next;
-       char *ue_value;         /* value (set only) */
-       bool ue_isset;          /* 1 for set, 0 for unset */
-       bool ue_priv;           /* from privileged source */
-       const char *ue_source;  /* source name */
-       char ue_name[1];        /* variable name */
-};
 
-extern struct userenv *userenv_list;
-
-/*
- * Prototypes.
- */
-
-/* Procedures exported from main.c. */
-void set_ifunit(int);  /* set stuff that depends on ifunit */
-void detach(void);     /* Detach from controlling tty */
-void die(int);         /* Cleanup and exit */
-void quit(void);               /* like die(1) */
-void novm(char *);     /* Say we ran out of memory, and die */
-void timeout(void (*func)(void *), void *arg, int s, int us);
-                               /* Call func(arg) after s.us seconds */
-void untimeout(void (*func)(void *), void *arg);
-                               /* Cancel call to func(arg) */
-void record_child(int, char *, void (*) (void *), void *, int);
-pid_t safe_fork(int, int, int);        /* Fork & close stuff in child */
-int  device_script(char *cmd, int in, int out, int dont_wait);
-                               /* Run `cmd' with given stdin and stdout */
-pid_t run_program(char *prog, char **args, int must_exist,
-                 void (*done)(void *), void *arg, int wait);
-                               /* Run program prog with args in child */
-void reopen_log(void); /* (re)open the connection to syslog */
-void print_link_stats(void); /* Print stats, if available */
-void reset_link_stats(int); /* Reset (init) stats when link goes up */
-void update_link_stats(int); /* Get stats at link termination */
-void script_setenv(char *, char *, int);       /* set script env var */
-void script_unsetenv(char *);          /* unset script env var */
-void new_phase(int);   /* signal start of new phase */
-void add_notifier(struct notifier **, notify_func, void *);
-void remove_notifier(struct notifier **, notify_func, void *);
-void notify(struct notifier *, int);
-int  ppp_send_config(int, int, u_int32_t, int, int);
-int  ppp_recv_config(int, int, u_int32_t, int, int);
-const char *protocol_name(int);
-void remove_pidfiles(void);
-void lock_db(void);
-void unlock_db(void);
-
-/* Procedures exported from tty.c. */
-void tty_init(void);
-
-/* Procedures exported from utils.c. */
-void log_packet(u_char *, int, char *, int);
-                               /* Format a packet and log it with syslog */
-void print_string(char *, int,  printer_func, void *);
-                               /* Format a string for output */
-int slprintf(char *, int, char *, ...);                /* sprintf++ */
-int vslprintf(char *, int, char *, va_list);   /* vsprintf++ */
-size_t strlcpy(char *, const char *, size_t);  /* safe strcpy */
-size_t strlcat(char *, const char *, size_t);  /* safe strncpy */
-void dbglog(char *, ...);      /* log a debug message */
-void info(char *, ...);        /* log an informational message */
-void notice(char *, ...);      /* log a notice-level message */
-void warn(char *, ...);        /* log a warning message */
-void error(char *, ...);       /* log an error message */
-void fatal(char *, ...);       /* log an error message and die(1) */
-void init_pr_log(const char *, int); /* initialize for using pr_log */
-void pr_log(void *, char *, ...);      /* printer fn, output to syslog */
-void end_pr_log(void); /* finish up after using pr_log */
-void dump_packet(const char *, u_char *, int);
-                               /* dump packet to debug log if interesting */
-ssize_t complete_read(int, void *, size_t);
-                               /* read a complete buffer */
-
-/* Procedures exported from auth.c */
-void link_required(int);         /* we are starting to use the link */
-void start_link(int);    /* bring the link up now */
-void link_terminated(int);  /* we are finished with the link */
-void link_down(int);     /* the LCP layer has left the Opened state */
-void upper_layers_down(int);/* take all NCPs down */
-void link_established(int); /* the link is up; authenticate now */
-void start_networks(int);   /* start all the network control protos */
-void continue_networks(int); /* start network [ip, etc] control protos */
-void np_up(int, int);    /* a network protocol has come up */
-void np_down(int, int);          /* a network protocol has gone down */
-void np_finished(int, int); /* a network protocol no longer needs link */
-void auth_peer_fail(int, int);
-                               /* peer failed to authenticate itself */
-void auth_peer_success(int, int, int, char *, int);
-                               /* peer successfully authenticated itself */
-void auth_withpeer_fail(int, int);
-                               /* we failed to authenticate ourselves */
-void auth_withpeer_success(int, int, int);
-                               /* we successfully authenticated ourselves */
-void auth_check_options(void);
-                               /* check authentication options supplied */
-void auth_reset(int);  /* check what secrets we have */
-int  check_passwd(int, char *, int, char *, int, char **);
-                               /* Check peer-supplied username/password */
-int  get_secret(int, char *, char *, char *, int *, int);
-                               /* get "secret" for chap */
-int  get_srp_secret(int unit, char *client, char *server, char *secret,
-    int am_server);
-int  auth_ip_addr(int, u_int32_t);
-                               /* check if IP address is authorized */
-int  auth_number(void);        /* check if remote number is authorized */
-int  bad_ip_adrs(u_int32_t);
-                               /* check if IP address is unreasonable */
-
-/* Procedures exported from demand.c */
-void demand_conf(void);        /* config interface(s) for demand-dial */
-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 */
-int  loop_chars(unsigned char *, int); /* process chars from loopback */
-int  loop_frame(unsigned char *, int); /* should we bring link up? */
-
-/* Procedures exported from multilink.c */
-#ifdef PPP_WITH_MULTILINK
-void mp_check_options(void); /* Check multilink-related options */
-int  mp_join_bundle(void);  /* join our link to an appropriate bundle */
-void mp_exit_bundle(void);  /* have disconnected our link from bundle */
-void mp_bundle_terminated(void);
-char *epdisc_to_str(struct epdisc *); /* string from endpoint discrim. */
-int  str_to_epdisc(struct epdisc *, char *); /* endpt disc. from str */
-#else
-#define mp_bundle_terminated() /* nothing */
-#define mp_exit_bundle()       /* nothing */
-#define doing_multilink                0
-#define multilink_master       0
-#endif
+/* Is debug enabled */
+bool debug_on();
 
-/* Procedures exported from sys-*.c */
-void sys_init(void);   /* Do system-dependent initialization */
-void sys_cleanup(void);        /* Restore system state before exiting */
-int  sys_check_options(void); /* Check options specified */
-void sys_close(void);  /* Clean up in a child before execing */
-int  ppp_available(void);      /* Test whether ppp kernel support exists */
-int  get_pty(int *, int *, char *, int);       /* Get pty master/slave */
-int  open_ppp_loopback(void); /* Open loopback for demand-dialling */
-int  tty_establish_ppp(int);  /* Turn serial port into a ppp interface */
-void tty_disestablish_ppp(int); /* Restore port to normal operation */
-void generic_disestablish_ppp(int dev_fd); /* Restore device setting */
-int  generic_establish_ppp(int dev_fd); /* Make a ppp interface */
-void make_new_bundle(int, int, int, int); /* Create new bundle */
-int  bundle_attach(int);       /* Attach link to existing bundle */
-void cfg_bundle(int, int, int, int); /* Configure existing bundle */
-void destroy_bundle(void); /* Tell driver to destroy bundle */
-void clean_check(void);        /* Check if line was 8-bit clean */
-void set_up_tty(int, int); /* Set up port's speed, parameters, etc. */
-void restore_tty(int); /* Restore port's original parameters */
-void setdtr(int, int); /* Raise or lower port's DTR line */
-void output(int, u_char *, int); /* Output a PPP packet */
-void wait_input(struct timeval *);
-                               /* Wait for input, with timeout */
-void add_fd(int);              /* Add fd to set to wait for */
-void remove_fd(int);   /* Remove fd from set to wait for */
-int  read_packet(u_char *); /* Read PPP packet */
-int  get_loop_output(void); /* Read pkts from loopback */
-void tty_send_config(int, u_int32_t, int, int);
-                               /* Configure i/f transmit parameters */
-void tty_set_xaccm(ext_accm);
-                               /* Set extended transmit ACCM */
-void tty_recv_config(int, u_int32_t, int, int);
-                               /* Configure i/f receive parameters */
-int  ccp_test(int, u_char *, int, int);
-                               /* Test support for compression scheme */
-void ccp_flags_set(int, int, int);
-                               /* Set kernel CCP state */
-int  ccp_fatal_error(int); /* Test for fatal decomp error in kernel */
-int  get_idle_time(int, struct ppp_idle *);
-                               /* Find out how long link has been idle */
-int  get_ppp_stats(int, struct pppd_stats *);
-                               /* Return link statistics */
-void netif_set_mtu(int, int); /* Set PPP interface MTU */
-int  netif_get_mtu(int);      /* Get PPP interface MTU */
-int  sifvjcomp(int, int, int, int);
-                               /* Configure VJ TCP header compression */
-int  sifup(int);               /* Configure i/f up for one protocol */
-int  sifnpmode(int u, int proto, enum NPmode mode);
-                               /* Set mode for handling packets for proto */
-int  sifdown(int);     /* Configure i/f down for one protocol */
-int  sifaddr(int, u_int32_t, u_int32_t, u_int32_t);
-                               /* Configure IPv4 addresses for i/f */
-int  cifaddr(int, u_int32_t, u_int32_t);
-                               /* Reset i/f IP addresses */
-#ifdef PPP_WITH_IPV6CP
-int  sif6up(int);              /* Configure i/f up for IPv6 */
-int  sif6down(int);    /* Configure i/f down for IPv6 */
-int  sif6addr(int, eui64_t, eui64_t);
-                               /* Configure IPv6 addresses for i/f */
-int  cif6addr(int, eui64_t, eui64_t);
-                               /* Remove an IPv6 address from i/f */
-#endif
-int  sifdefaultroute(int, u_int32_t, u_int32_t, bool replace_default_rt);
-                               /* Create default route through i/f */
-int  cifdefaultroute(int, u_int32_t, u_int32_t);
-                               /* Delete default route through i/f */
-#ifdef PPP_WITH_IPV6CP
-int  sif6defaultroute(int, eui64_t, eui64_t);
-                               /* Create default IPv6 route through i/f */
-int  cif6defaultroute(int, eui64_t, eui64_t);
-                               /* Delete default IPv6 route through i/f */
-#endif
-int  sifproxyarp(int, u_int32_t);
-                               /* Add proxy ARP entry for peer */
-int  cifproxyarp(int, u_int32_t);
-                               /* Delete proxy ARP entry for peer */
-u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
-int  lock(char *);     /* Create lock file for device */
-int  relock(int);              /* Rewrite lock file with new pid */
-void unlock(void);     /* Delete previously-created lock file */
-void logwtmp(const char *, const char *, const char *);
-                               /* Write entry to wtmp file */
-int  get_host_seed(void);      /* Get host-dependent random number seed */
-int  have_route_to(u_int32_t); /* Check if route to addr exists */
-#ifdef PPP_WITH_FILTER
-int  set_filters(struct bpf_program *pass, struct bpf_program *active);
-                               /* Set filter programs in kernel */
-#endif
-int  get_if_hwaddr(u_char *addr, char *name);
-int  get_first_ether_hwaddr(u_char *addr);
-int get_time(struct timeval *);
-                               /* Get current time, monotonic if possible. */
-
-/* Procedures exported from options.c */
-int setipaddr(char *, char **, int); /* Set local/remote ip addresses */
-int  parse_args(int argc, char **argv);
-                               /* Parse options from arguments given */
-int  options_from_file(char *filename, int must_exist, int check_prot,
-                      int privileged);
-                               /* Parse options from an options file */
-int  options_from_user(void); /* Parse options from user's .ppprc */
-int  options_for_tty(void); /* Parse options from /etc/ppp/options.tty */
-int  options_from_list(struct wordlist *, int privileged);
-                               /* Parse options from a wordlist */
-int  getword(FILE *f, char *word, int *newlinep, char *filename);
-                               /* Read a word from a file */
-void option_error(char *fmt, ...);
-                               /* Print an error message about an option */
-int int_option(char *, int *);
-                               /* Simplified number_option for decimal ints */
-void add_options(option_t *); /* Add extra options */
-void check_options(void);      /* check values after all options parsed */
-int  override_value(char *, int, const char *);
-                               /* override value if permitted by priority */
-void print_options(printer_func, void *);
-                               /* print out values of all options */
-
-int parse_dotted_ip(char *, u_int32_t *);
-
-/*
- * Hooks to enable plugins to change various things.
+/* Safe sprintf++ */
+int slprintf(char *, int, const char *, ...);
+
+/* vsprintf++ */
+int vslprintf(char *, int, const char *, va_list);
+
+/* safe strcpy */
+size_t strlcpy(char *, const char *, size_t);
+
+/* safe strncpy */
+size_t strlcat(char *, const char *, size_t);
+
+/* log a debug message */
+void dbglog(const char *, ...);
+
+/* log an informational message */
+void info(const char *, ...);
+
+/* log a notice-level message */
+void notice(const char *, ...);
+
+/* log a warning message */
+void warn(const char *, ...);
+
+/* log an error message */
+void error(const char *, ...);
+
+/* log an error message and die(1) */
+void fatal(const char *, ...);
+
+/* Say we ran out of memory, and die */
+void novm(const char *);
+
+/* Format a packet and log it with syslog */
+void log_packet(unsigned char *, int, char *, int);
+
+/* dump packet to debug log if interesting */
+void dump_packet(const char *, unsigned char *, int);
+
+/* initialize for using pr_log */
+void init_pr_log(const char *, int);
+
+/* printer fn, output to syslog */
+void pr_log(void *, char *, ...);
+
+/* finish up after using pr_log */
+void end_pr_log(void);
+
+/*
+ * Get the current exist status of pppd
  */
-extern int (*new_phase_hook)(int);
-extern int (*idle_time_hook)(struct ppp_idle *);
-extern int (*holdoff_hook)(void);
-extern int (*pap_check_hook)(void);
-extern int (*pap_auth_hook)(char *user, char *passwd, char **msgp,
-                           struct wordlist **paddrs,
-                           struct wordlist **popts);
-extern void (*pap_logout_hook)(void);
-extern int (*pap_passwd_hook)(char *user, char *passwd);
-extern int (*allowed_address_hook)(u_int32_t addr);
-extern void (*ip_up_hook)(void);
-extern void (*ip_down_hook)(void);
-extern void (*ip_choose_hook)(u_int32_t *);
-extern void (*ipv6_up_hook)(void);
-extern void (*ipv6_down_hook)(void);
-
-extern int (*chap_check_hook)(void);
-extern int (*chap_passwd_hook)(char *user, char *passwd);
-extern void (*multilink_join_hook)(void);
-
-#ifdef PPP_WITH_EAPTLS
-extern int (*eaptls_passwd_hook)(char *user, char *passwd);
-#endif
+ppp_exit_code_t ppp_status();
 
-/* Let a plugin snoop sent and received packets.  Useful for L2TP */
-extern void (*snoop_recv_hook)(unsigned char *p, int len);
-extern void (*snoop_send_hook)(unsigned char *p, int len);
+/*
+ * Set the exit status
+ */
+void ppp_set_status(ppp_exit_code_t code);
 
 /*
- * Inline versions of get/put char/short/long.
- * Pointer is advanced; we assume that both arguments
- * are lvalues and will already be in registers.
- * cp MUST be u_char *.
+ * Configure the session's maximum number of octets
  */
-#define GETCHAR(c, cp) { \
-       (c) = *(cp)++; \
-}
-#define PUTCHAR(c, cp) { \
-       *(cp)++ = (u_char) (c); \
-}
+void ppp_set_session_limit(unsigned int octets);
 
+/*
+ * Which direction to limit the number of octets
+ */
+void ppp_set_session_limit_dir(unsigned int direction);
 
-#define GETSHORT(s, cp) { \
-       (s) = *(cp)++ << 8; \
-       (s) |= *(cp)++; \
-}
-#define PUTSHORT(s, cp) { \
-       *(cp)++ = (u_char) ((s) >> 8); \
-       *(cp)++ = (u_char) (s); \
-}
+/*
+ * Get the current link stats, returns true when valid and false if otherwise
+ */
+bool ppp_get_link_stats(ppp_link_stats_st *stats);
 
-#define GETLONG(l, cp) { \
-       (l) = *(cp)++ << 8; \
-       (l) |= *(cp)++; (l) <<= 8; \
-       (l) |= *(cp)++; (l) <<= 8; \
-       (l) |= *(cp)++; \
-}
-#define PUTLONG(l, cp) { \
-       *(cp)++ = (u_char) ((l) >> 24); \
-       *(cp)++ = (u_char) ((l) >> 16); \
-       *(cp)++ = (u_char) ((l) >> 8); \
-       *(cp)++ = (u_char) (l); \
-}
+/*
+ * Get pppd's notion of time
+ */
+int ppp_get_time(struct timeval *);
 
-#define INCPTR(n, cp)  ((cp) += (n))
-#define DECPTR(n, cp)  ((cp) -= (n))
+/*
+ * Schedule a callback in s.us seconds from now
+ */
+typedef void (*ppp_timer_cb)(void *arg);
+void ppp_timeout(ppp_timer_cb func, void *arg, int s, int us);
 
 /*
- * System dependent definitions for user-level 4.3BSD UNIX implementation.
+ * Cancel any pending timer callbacks
  */
+void ppp_untimeout(void (*func)(void *), void *arg);
 
-#define TIMEOUT(r, f, t)       timeout((r), (f), (t), 0)
-#define UNTIMEOUT(r, f)                untimeout((r), (f))
+/*
+ * Clean up in a child before execing
+ */
+void ppp_sys_close(void);
 
-#define BCOPY(s, d, l)         memcpy(d, s, l)
-#define BZERO(s, n)            memset(s, 0, n)
-#define        BCMP(s1, s2, l)         memcmp(s1, s2, l)
+/*
+ * Fork & close stuff in child
+ */
+pid_t ppp_safe_fork(int, int, int);
 
-#define PRINTMSG(m, l)         { info("Remote message: %0.*v", l, m); }
+/*
+ * Get the current hostname
+ */
+const char *ppp_hostname();
 
 /*
- * MAKEHEADER - Add Header fields to a packet.
+ * Is pppd using pty as a device (opposed to notty or pty opt).
  */
-#define MAKEHEADER(p, t) { \
-    PUTCHAR(PPP_ALLSTATIONS, p); \
-    PUTCHAR(PPP_UI, p); \
-    PUTSHORT(t, p); }
+bool ppp_using_pty();
 
 /*
- * Exit status values.
+ * Device is synchronous serial device
  */
-#define EXIT_OK                        0
-#define EXIT_FATAL_ERROR       1
-#define EXIT_OPTION_ERROR      2
-#define EXIT_NOT_ROOT          3
-#define EXIT_NO_KERNEL_SUPPORT 4
-#define EXIT_USER_REQUEST      5
-#define EXIT_LOCK_FAILED       6
-#define EXIT_OPEN_FAILED       7
-#define EXIT_CONNECT_FAILED    8
-#define EXIT_PTYCMD_FAILED     9
-#define EXIT_NEGOTIATION_FAILED        10
-#define EXIT_PEER_AUTH_FAILED  11
-#define EXIT_IDLE_TIMEOUT      12
-#define EXIT_CONNECT_TIME      13
-#define EXIT_CALLBACK          14
-#define EXIT_PEER_DEAD         15
-#define EXIT_HANGUP            16
-#define EXIT_LOOPBACK          17
-#define EXIT_INIT_FAILED       18
-#define EXIT_AUTH_TOPEER_FAILED        19
-#define EXIT_TRAFFIC_LIMIT     20
-#define EXIT_CNID_AUTH_FAILED  21
+bool ppp_sync_serial();
 
 /*
- * Debug macros.  Slightly useful for finding bugs in pppd, not particularly
- * useful for finding out why your connection isn't being established.
+ * Modem mode
  */
-#ifdef DEBUGALL
-#define DEBUGMAIN      1
-#define DEBUGFSM       1
-#define DEBUGLCP       1
-#define DEBUGIPCP      1
-#define DEBUGIPV6CP    1
-#define DEBUGUPAP      1
-#define DEBUGCHAP      1
-#endif
+bool ppp_get_modem();
 
-#ifndef LOG_PPP                        /* we use LOG_LOCAL2 for syslog by default */
-#if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUGSYS) \
-  || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) \
-  || defined(DEBUGCHAP) || defined(DEBUG) || defined(DEBUGIPV6CP)
-#define LOG_PPP LOG_LOCAL2
-#else
-#define LOG_PPP LOG_DAEMON
-#endif
-#endif /* LOG_PPP */
+/*
+ * Control the mode of the tty terminal
+ */
+void ppp_set_modem(bool on);
 
-#ifdef DEBUGMAIN
-#define MAINDEBUG(x)   if (debug) dbglog x
-#else
-#define MAINDEBUG(x)
-#endif
+/*
+ * Set the current session number, e.g. for PPPoE
+ */
+void ppp_set_session_number(int number);
 
-#ifdef DEBUGSYS
-#define SYSDEBUG(x)    if (debug) dbglog x
-#else
-#define SYSDEBUG(x)
-#endif
+/*
+ * Set the current session number, e.g. for PPPoE
+ */
+int ppp_get_session_number(void);
 
-#ifdef DEBUGFSM
-#define FSMDEBUG(x)    if (debug) dbglog x
-#else
-#define FSMDEBUG(x)
-#endif
+/*
+ * Check if pppd got signaled, returns 0 if not signaled, returns -1 on failure, and the signal number when signaled.
+ */
+bool ppp_signaled(int sig);
 
-#ifdef DEBUGLCP
-#define LCPDEBUG(x)    if (debug) dbglog x
-#else
-#define LCPDEBUG(x)
-#endif
+/*
+ * Maximum connect time in seconds
+ */
+int ppp_get_max_connect_time(void);
 
-#ifdef DEBUGIPCP
-#define IPCPDEBUG(x)   if (debug) dbglog x
-#else
-#define IPCPDEBUG(x)
-#endif
+/*
+ * Set the maximum connect time in seconds
+ */
+void ppp_set_max_connect_time(unsigned int max);
 
-#ifdef DEBUGIPV6CP
-#define IPV6CPDEBUG(x)  if (debug) dbglog x
-#else
-#define IPV6CPDEBUG(x)
-#endif
+/*
+ * Get the link idle time before shutting the link down
+ */
+int ppp_get_max_idle_time(void);
 
-#ifdef DEBUGUPAP
-#define UPAPDEBUG(x)   if (debug) dbglog x
-#else
-#define UPAPDEBUG(x)
-#endif
+/*
+ * Set the link idle time before shutting the link down
+ */
+void ppp_set_max_idle_time(unsigned int idle);
 
-#ifdef DEBUGCHAP
-#define CHAPDEBUG(x)   if (debug) dbglog x
-#else
-#define CHAPDEBUG(x)
-#endif
+/*
+ * Get the duration the link was up (uptime)
+ */
+int ppp_get_link_uptime();
+
+/*
+ * Get the ipparam configured with pppd
+ */
+const char *ppp_ipparam();
 
-#ifndef SIGTYPE
-#if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
-#define SIGTYPE void
-#else
-#define SIGTYPE int
-#endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
-#endif /* SIGTYPE */
+/*
+ * check if IP address is unreasonable
+ */
+bool ppp_bad_ip_addr(uint32_t);
 
-#ifndef MIN
-#define MIN(a, b)      ((a) < (b)? (a): (b))
-#endif
-#ifndef MAX
-#define MAX(a, b)      ((a) > (b)? (a): (b))
-#endif
+/*
+ * Expose an environment variable to scripts
+ */
+void ppp_script_setenv(char *, char *, int);
+
+/*
+ * Unexpose an environment variable to scripts
+ */
+void ppp_script_unsetenv(char *);
+
+/*
+ * Test whether ppp kernel support exists
+ */
+int ppp_check_kernel_support(void);
+
+/*
+ * Restore device setting
+ */
+void ppp_generic_disestablish(int dev_fd);
+
+/*
+ * Set the interface MTU
+ */
+void ppp_set_mtu(int, int);
+
+/*
+ * Get the interface MTU
+ */
+int  ppp_get_mtu(int);
+
+/*
+ * Make a ppp interface
+ */
+int ppp_generic_establish(int dev_fd);
+
+/*
+ * Get the peer's authentication name
+ */
+const char *ppp_peer_authname(char *buf, size_t bufsz);
+
+/*
+ * Get the remote name
+ */
+const char *ppp_remote_name();
+
+/*
+ * Get the remote number (if set), otherwise return NULL
+ */
+const char *ppp_get_remote_number(void);
 
-#ifndef offsetof
-#define offsetof(type, member) ((size_t) &((type *)0)->member)
+/*
+ * Set the remote number, typically it's a MAC address
+ */
+void ppp_set_remote_number(const char *buf);
+
+/*
+ * Get the current interface unit for the pppX device
+ */
+int ppp_ifunit();
+
+/*
+ * Get the current interface name
+ */
+const char *ppp_ifname();
+
+/*
+ * Get the current interface name
+ */
+int ppp_get_ifname(char *buf, size_t bufsz);
+
+/*
+ * Set the current interface name, ifname is a \0 terminated string
+ */
+void ppp_set_ifname(const char *ifname);
+
+/*
+ * Set the original devnam (prior to any renaming, etc).
+ */
+int ppp_set_pppdevnam(const char *name);
+
+/*
+ * Get the original devnam (prior to any renaming, etc).
+ */
+const char *ppp_pppdevnam();
+
+/*
+ * Get the current devnam, e.g. /dev/ttyS0, /dev/ptmx
+ */
+const char *ppp_devnam();
+
+/*
+ * Set the device name
+ */
+int ppp_set_devnam(const char *name);
+
+/*
+ * Definition for the notify callback function
+ *   ctx - contextual argument provided with the registration
+ *   arg - anything passed by the notification, e.g. phase, pid, etc
+ */
+typedef void (ppp_notify_fn)(void *ctx, int arg);
+
+/*
+ * Add a callback notification for when a given event has occured
+ */
+void ppp_add_notify(ppp_notify_t type, ppp_notify_fn *func, void *ctx);
+
+/*
+ * Remove a callback notification previously registered
+ */
+void ppp_del_notify(ppp_notify_t type, ppp_notify_fn *func, void *ctx);
+
+/*
+ * Get the path prefix in which a file is installed
+ */
+int ppp_get_path(ppp_path_t type, char *buf, size_t bufsz);
+
+/*
+ * Get the file with path prefix
+ */
+int ppp_get_filepath(ppp_path_t type, const char *name, char *buf, size_t bufsz);
+
+/*
+ * Check if pppd is to re-open link after it goes down
+ */
+bool ppp_persist();
+
+/*
+ * Hooks to enable plugins to hook into various parts of the code
+ */
+
+struct ppp_idle; /* Declared in <linux/ppp_defs.h> */
+extern int (*idle_time_hook)(struct ppp_idle *);
+extern int (*new_phase_hook)(int);
+extern int (*holdoff_hook)(void);
+extern int  (*allowed_address_hook)(uint32_t addr);
+extern void (*snoop_recv_hook)(unsigned char *p, int len);
+extern void (*snoop_send_hook)(unsigned char *p, int len);
+
+#ifdef __cplusplus
+}
 #endif
 
 #endif /* PPP_PPPD_H */
index 64c37f7f6c97b77f49535a53a216a0761c01b375..9fb6f4b0ffd07740d3e7db8008bd5bcc80f286e0 100644 (file)
@@ -1,3 +1,31 @@
+/* 
+ * Copyright (c) 2022 Eivind Næss. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The name(s) of the authors of this software must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission.
+ *
+ * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 /*
  * This file is generated by configure and sets the features enabled
  *   in pppd when configured.
 /* Have PEAP authentication support */
 #undef PPP_WITH_PEAP
 
-/* Use included des included with pppd */
-#undef USE_CRYPT
-
-/* Use included md4 included with pppd */
-#undef USE_MD4
-
-/* Use included md5 included with pppd */
-#undef USE_MD5
-
-/* Use included sha included with pppd */
-#undef USE_SHA
-
 /* The pppd version */
 #undef PPPD_VERSION
 
index 8ab5b8b294d7f37ddd95c865fe37a3dca70b630e..f08d8e191ef65794ed21575facbcb66563523563 100644 (file)
@@ -17,7 +17,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
@@ -89,7 +89,7 @@
 #include <utmp.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include "pppd.h"
+#include "pppd-private.h"
 #include "session.h"
 
 #ifdef PPP_WITH_PAM
index 0b91a03e5d62e5c921540c4fb92862e44b08b41a..b3c46b4333717c8cfc90871bb893cddd55e88eda 100644 (file)
@@ -17,7 +17,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
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define SESS_AUTH  1   /* Check User Authentication */
 #define SESS_ACCT  2   /* Check Account Validity */
 
@@ -89,4 +93,8 @@ session_start(const int flags, const char* user, const char* passwd, const char*
 void
 session_end(const char* tty);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif // PPP_SESSION_H
diff --git a/pppd/sha1.c b/pppd/sha1.c
deleted file mode 100644 (file)
index 4fc5345..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * ftp://ftp.funet.fi/pub/crypt/hash/sha/sha1.c
- * 
- * SHA-1 in C
- * By Steve Reid <steve@edmweb.com>
- * 100% Public Domain
- * 
- * Test Vectors (from FIPS PUB 180-1)
- * "abc"
- * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
- * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
- * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
- * A million repetitions of "a"
- * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-/* #define SHA1HANDSOFF * Copies data before messing with it. */
-
-#include <string.h>
-#include <time.h>
-#include <netinet/in.h>        /* htonl() */
-#include "sha1.h"
-
-static void
-SHA1_Transform(u_int32_t[5], const unsigned char[64]);
-
-#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
-
-/* blk0() and blk() perform the initial expand. */
-/* I got the idea of expanding during the round function from SSLeay */
-#define blk0(i) (block->l[i] = htonl(block->l[i]))
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
-    ^block->l[(i+2)&15]^block->l[i&15],1))
-
-/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
-#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
-#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
-#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
-#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
-#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
-
-
-/* Hash a single 512-bit block. This is the core of the algorithm. */
-
-static void
-SHA1_Transform(u_int32_t state[5], const unsigned char buffer[64])
-{
-    u_int32_t a, b, c, d, e;
-    typedef union {
-       unsigned char c[64];
-       u_int32_t l[16];
-    } CHAR64LONG16;
-    CHAR64LONG16 *block;
-
-#ifdef SHA1HANDSOFF
-    static unsigned char workspace[64];
-    block = (CHAR64LONG16 *) workspace;
-    memcpy(block, buffer, 64);
-#else
-    block = (CHAR64LONG16 *) buffer;
-#endif
-    /* Copy context->state[] to working vars */
-    a = state[0];
-    b = state[1];
-    c = state[2];
-    d = state[3];
-    e = state[4];
-    /* 4 rounds of 20 operations each. Loop unrolled. */
-    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
-    R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
-    R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
-    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
-    R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
-    R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
-    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
-    R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
-    R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
-    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
-    R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
-    R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
-    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
-    R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
-    R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
-    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
-    R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
-    R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
-    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
-    R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
-    /* Add the working vars back into context.state[] */
-    state[0] += a;
-    state[1] += b;
-    state[2] += c;
-    state[3] += d;
-    state[4] += e;
-    /* Wipe variables */
-    a = b = c = d = e = 0;
-}
-
-
-/* SHA1Init - Initialize new context */
-
-void
-SHA1_Init(SHA1_CTX *context)
-{
-    /* SHA1 initialization constants */
-    context->state[0] = 0x67452301;
-    context->state[1] = 0xEFCDAB89;
-    context->state[2] = 0x98BADCFE;
-    context->state[3] = 0x10325476;
-    context->state[4] = 0xC3D2E1F0;
-    context->count[0] = context->count[1] = 0;
-}
-
-
-/* Run your data through this. */
-
-void
-SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
-{
-    unsigned int i, j;
-
-    j = (context->count[0] >> 3) & 63;
-    if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
-    context->count[1] += (len >> 29);
-    i = 64 - j;
-    while (len >= i) {
-       memcpy(&context->buffer[j], data, i);
-       SHA1_Transform(context->state, context->buffer);
-       data += i;
-       len -= i;
-       i = 64;
-       j = 0;
-    }
-
-    memcpy(&context->buffer[j], data, len);
-}
-
-
-/* Add padding and return the message digest. */
-
-void
-SHA1_Final(unsigned char digest[20], SHA1_CTX *context)
-{
-    u_int32_t i, j;
-    unsigned char finalcount[8];
-
-    for (i = 0; i < 8; i++) {
-        finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
-         >> ((3-(i & 3)) * 8) ) & 255);  /* Endian independent */
-    }
-    SHA1_Update(context, (unsigned char *) "\200", 1);
-    while ((context->count[0] & 504) != 448) {
-       SHA1_Update(context, (unsigned char *) "\0", 1);
-    }
-    SHA1_Update(context, finalcount, 8);  /* Should cause a SHA1Transform() */
-    for (i = 0; i < 20; i++) {
-       digest[i] = (unsigned char)
-                    ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
-    }
-    /* Wipe variables */
-    i = j = 0;
-    memset(context->buffer, 0, 64);
-    memset(context->state, 0, 20);
-    memset(context->count, 0, 8);
-    memset(&finalcount, 0, 8);
-#ifdef SHA1HANDSOFF  /* make SHA1Transform overwrite it's own static vars */
-    SHA1Transform(context->state, context->buffer);
-#endif
-}
-
diff --git a/pppd/sha1.h b/pppd/sha1.h
deleted file mode 100644 (file)
index 2325133..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* sha1.h */
-
-#ifndef PPP_SHA1_H
-#define PPP_SHA1_H
-
-#include "pppdconf.h"
-
-#ifndef USE_SHA
-#include <openssl/sha.h>
-
-#define SHA1_CTX SHA_CTX
-#define SHA1_SIGNATURE_SIZE SHA_DIGEST_LENGTH
-
-#else
-
-#ifndef SHA1_SIGNATURE_SIZE
-#ifdef SHA_DIGESTSIZE
-#define SHA1_SIGNATURE_SIZE SHA_DIGESTSIZE
-#else
-#define SHA1_SIGNATURE_SIZE 20
-#endif
-#endif
-
-typedef struct {
-    u_int32_t state[5];
-    u_int32_t count[2];
-    unsigned char buffer[64];
-} SHA1_CTX;
-
-extern void SHA1_Init(SHA1_CTX *);
-extern void SHA1_Update(SHA1_CTX *, const unsigned char *, unsigned int);
-extern void SHA1_Final(unsigned char[SHA1_SIGNATURE_SIZE], SHA1_CTX *);
-
-#endif /* USE_SHA */
-#endif /* PPP_SHA1_H */
index b36d2a84d8a49f839ee0d3a987be9ebf3a33814c..5835a4a7f4d85963f66d52bf918771c538519733 100644 (file)
@@ -1,3 +1,29 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   trivial database library 
+
+   Copyright (C) Anton Blanchard                   2001
+   
+     ** NOTE! The following LGPL license applies to the tdb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+   
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
 #ifndef PPP_SPINLOCK_H
 #define PPP_SPINLOCK_H
 
index 097281a2ca85ff7fbad728a8d0e61bd9d9587d6d..7564c08b947e4fec99d83fbfd374af8f364a074a 100644 (file)
@@ -1,5 +1,4 @@
 .\" manual page [] for srp-entry
-.\" $Id: srp-entry.8,v 1.2 2004/11/13 12:22:49 paulus Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
index ff3a249e81758ec042a6cd67991e6412532f8d1b..b94f3ecc7f7ccce8999a0b157a62184af35e8f23 100644 (file)
@@ -2,7 +2,7 @@
  * sys-linux.c - System-dependent procedures for setting up
  * PPP interfaces on Linux systems
  *
- * Copyright (c) 1994-2004 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <linux/if_link.h>
-/* Attempt at retaining compile-support with older than 4.7 kernels, or kernels
- * where RTM_NEWSTATS isn't defined for whatever reason.
- */
-#ifndef RTM_NEWSTATS
-#define RTM_NEWSTATS 92
-#define RTM_GETSTATS 94
-#define IFLA_STATS_LINK_64 1
-
 #include <linux/if_addr.h>
+
 /* glibc versions prior to 2.24 do not define SOL_NETLINK */
 #ifndef SOL_NETLINK
 #define SOL_NETLINK 270
 #ifndef NETLINK_CAP_ACK
 #define NETLINK_CAP_ACK 10
 #endif
+
+/* linux kernel versions prior to 4.7 do not define/support IFLA_PPP_DEV_FD */
+#ifndef IFLA_PPP_MAX
+/* IFLA_PPP_DEV_FD is declared as enum when IFLA_PPP_MAX is defined */
+#define IFLA_PPP_DEV_FD 1
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "ipcp.h"
 
 #include "eui64.h"
 #endif /* PPP_WITH_IPV6CP */
 
+#include "multilink.h"
+
 #ifdef PPP_WITH_FILTER
 #include <pcap-bpf.h>
 #include <linux/filter.h>
@@ -290,6 +287,147 @@ extern int dfl_route_metric;
     memset ((char *) &(addr), '\0', sizeof(addr));     \
     addr.sa_family = (family);
 
+
+/*
+ * rtnetlink_msg - send rtnetlink message, receive response
+ * and return received error code:
+ * 0              - success
+ * positive value - error during sending / receiving message
+ * negative value - rtnetlink responce error code
+ */
+static int rtnetlink_msg(const char *desc, int *shared_fd, void *nlreq, size_t nlreq_len, void *nlresp_data, size_t *nlresp_size, unsigned nlresp_type)
+{
+    struct nlresp_hdr {
+        struct nlmsghdr nlh;
+        struct nlmsgerr nlerr;
+    } nlresp_hdr;
+    struct sockaddr_nl nladdr;
+    struct iovec iov[2];
+    struct msghdr msg;
+    ssize_t nlresp_len;
+    int one;
+    int fd;
+
+    if (shared_fd && *shared_fd >= 0) {
+        fd = *shared_fd;
+    } else {
+        fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+        if (fd < 0) {
+            error("rtnetlink_msg: socket(NETLINK_ROUTE): %m (line %d)", __LINE__);
+            return 1;
+        }
+
+        /*
+         * Tell kernel to not send to us payload of acknowledgment error message.
+         * NETLINK_CAP_ACK option is supported since Linux kernel version 4.3 and
+         * older kernel versions always send full payload in acknowledgment netlink
+         * message. We ignore payload of this message as we need only error code,
+         * to check if our set remote peer address request succeeded or failed.
+         * So ignore return value from the following setsockopt() call as setting
+         * option NETLINK_CAP_ACK means for us just a kernel hint / optimization.
+         */
+        one = 1;
+        setsockopt(fd, SOL_NETLINK, NETLINK_CAP_ACK, &one, sizeof(one));
+
+        memset(&nladdr, 0, sizeof(nladdr));
+        nladdr.nl_family = AF_NETLINK;
+
+        if (bind(fd, (struct sockaddr *)&nladdr, sizeof(nladdr)) < 0) {
+            error("rtnetlink_msg: bind(AF_NETLINK): %m (line %d)", __LINE__);
+            close(fd);
+            return 1;
+        }
+
+        if (shared_fd)
+            *shared_fd = fd;
+    }
+
+    memset(&nladdr, 0, sizeof(nladdr));
+    nladdr.nl_family = AF_NETLINK;
+
+    memset(&iov[0], 0, sizeof(iov[0]));
+    iov[0].iov_base = nlreq;
+    iov[0].iov_len = nlreq_len;
+
+    memset(&msg, 0, sizeof(msg));
+    msg.msg_name = &nladdr;
+    msg.msg_namelen = sizeof(nladdr);
+    msg.msg_iov = &iov[0];
+    msg.msg_iovlen = 1;
+
+    if (sendmsg(fd, &msg, 0) < 0) {
+        error("rtnetlink_msg: sendmsg(%s): %m (line %d)", desc, __LINE__);
+        if (!shared_fd)
+            close(fd);
+        return 1;
+    }
+
+    memset(iov, 0, sizeof(iov));
+    iov[0].iov_base = &nlresp_hdr;
+    if (nlresp_size && *nlresp_size > sizeof(nlresp_hdr)) {
+        iov[0].iov_len = offsetof(struct nlresp_hdr, nlerr);
+        iov[1].iov_base = nlresp_data;
+        iov[1].iov_len = *nlresp_size;
+    } else {
+        iov[0].iov_len = sizeof(nlresp_hdr);
+    }
+
+    memset(&msg, 0, sizeof(msg));
+    msg.msg_name = &nladdr;
+    msg.msg_namelen = sizeof(nladdr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = (nlresp_size && *nlresp_size > sizeof(nlresp_hdr)) ? 2 : 1;
+
+    nlresp_len = recvmsg(fd, &msg, 0);
+
+    if (!shared_fd)
+        close(fd);
+
+    if (nlresp_len < 0) {
+        error("rtnetlink_msg: recvmsg(%s): %m (line %d)", desc, __LINE__);
+        return 1;
+    }
+
+    if (nladdr.nl_family != AF_NETLINK) {
+        error("rtnetlink_msg: recvmsg(%s): Not a netlink packet (line %d)", desc, __LINE__);
+        return 1;
+    }
+
+    if (!nlresp_size) {
+        if ((size_t)nlresp_len < sizeof(nlresp_hdr) || nlresp_hdr.nlh.nlmsg_len < sizeof(nlresp_hdr)) {
+            error("rtnetlink_msg: recvmsg(%s): Acknowledgment netlink packet too short (line %d)", desc, __LINE__);
+            return 1;
+        }
+
+        /* acknowledgment packet for NLM_F_ACK is NLMSG_ERROR */
+        if (nlresp_hdr.nlh.nlmsg_type != NLMSG_ERROR) {
+            error("rtnetlink_msg: recvmsg(%s): Not an acknowledgment netlink packet (line %d)", desc, __LINE__);
+            return 1;
+        }
+    }
+
+    if (nlresp_size) {
+        if (*nlresp_size > sizeof(nlresp_hdr))
+            memcpy((unsigned char *)&nlresp_hdr + offsetof(struct nlresp_hdr, nlerr), nlresp_data, sizeof(nlresp_hdr.nlerr));
+        else
+            memcpy(nlresp_data, (unsigned char *)&nlresp_hdr + offsetof(struct nlresp_hdr, nlerr), *nlresp_size);
+    }
+
+    /* error == 0 indicates success, negative value is errno code */
+    if (nlresp_hdr.nlh.nlmsg_type == NLMSG_ERROR && nlresp_hdr.nlerr.error)
+        return nlresp_hdr.nlerr.error;
+
+    if (nlresp_size) {
+        if (nlresp_hdr.nlh.nlmsg_type != nlresp_type) {
+            error("rtnetlink_msg: recvmsg(%s): Not a netlink packet of type 0x%x (line %d)", desc, nlresp_type, __LINE__);
+            return 1;
+        }
+        *nlresp_size = nlresp_len - offsetof(struct nlresp_hdr, nlerr);
+    }
+
+    return 0;
+}
+
 /*
  * Determine if the PPP connection should still be present.
  */
@@ -398,10 +536,10 @@ void sys_cleanup(void)
 
 /********************************************************************
  *
- * sys_close - Clean up in a child process before execing.
+ * ppp_sys_close - Clean up in a child process before execing.
  */
 void
-sys_close(void)
+ppp_sys_close(void)
 {
     if (new_style_driver && ppp_dev_fd >= 0)
        close(ppp_dev_fd);
@@ -465,7 +603,7 @@ int tty_establish_ppp (int tty_fd)
 #ifndef N_SYNC_PPP
 #define N_SYNC_PPP 14
 #endif
-    ppp_disc = (new_style_driver && sync_serial)? N_SYNC_PPP: N_PPP;
+    ppp_disc = (new_style_driver && ppp_sync_serial())? N_SYNC_PPP: N_PPP;
     if (ioctl(tty_fd, TIOCSETD, &ppp_disc) < 0) {
        if ( ! ok_error (errno) ) {
            error("Couldn't set tty to PPP discipline: %m");
@@ -473,7 +611,7 @@ int tty_establish_ppp (int tty_fd)
        }
     }
 
-    ret_fd = generic_establish_ppp(tty_fd);
+    ret_fd = ppp_generic_establish(tty_fd);
 
 #define SC_RCVB        (SC_RCV_B7_0 | SC_RCV_B7_1 | SC_RCV_EVNP | SC_RCV_ODDP)
 #define SC_LOGB        (SC_DEBUG | SC_LOG_INPKT | SC_LOG_OUTPKT | SC_LOG_RAWIN \
@@ -494,7 +632,7 @@ int tty_establish_ppp (int tty_fd)
  *
  * generic_establish_ppp - Turn the fd into a ppp interface.
  */
-int generic_establish_ppp (int fd)
+int ppp_generic_establish (int fd)
 {
     int x;
 
@@ -631,16 +769,16 @@ void tty_disestablish_ppp(int tty_fd)
 flushfailed:
     initfdflags = -1;
 
-    generic_disestablish_ppp(tty_fd);
+    ppp_generic_disestablish(tty_fd);
 }
 
 /********************************************************************
  *
- * generic_disestablish_ppp - Restore device components to normal
+ * ppp_generic_disestablish - Restore device components to normal
  * operation, and reconnect the ppp unit to the loopback if in demand
  * mode.  This shouldn't call die() because it's called from die().
  */
-void generic_disestablish_ppp(int dev_fd)
+void ppp_generic_disestablish(int dev_fd)
 {
     if (new_style_driver) {
        close(ppp_fd);
@@ -648,7 +786,7 @@ void generic_disestablish_ppp(int dev_fd)
        if (demand) {
            modify_flags(ppp_dev_fd, 0, SC_LOOP_TRAFFIC);
            looped = 1;
-       } else if (!doing_multilink && ppp_dev_fd >= 0) {
+       } else if (!mp_on() && ppp_dev_fd >= 0) {
            close(ppp_dev_fd);
            remove_fd(ppp_dev_fd);
            ppp_dev_fd = -1;
@@ -662,6 +800,84 @@ void generic_disestablish_ppp(int dev_fd)
     }
 }
 
+/*
+ * make_ppp_unit_rtnetlink - register a new ppp network interface for ppp_dev_fd
+ * with specified req_ifname via rtnetlink. Interface name req_ifname must not
+ * be empty. Custom ppp unit id req_unit is ignored and kernel choose some free.
+ */
+static int make_ppp_unit_rtnetlink(void)
+{
+    struct {
+        struct nlmsghdr nlh;
+        struct ifinfomsg ifm;
+        struct {
+            struct rtattr rta;
+            char ifname[IFNAMSIZ];
+        } ifn;
+        struct {
+            struct rtattr rta;
+            struct {
+                struct rtattr rta;
+                char ifkind[sizeof("ppp")];
+            } ifik;
+            struct {
+                struct rtattr rta;
+                struct {
+                    struct rtattr rta;
+                    union {
+                        int ppp_dev_fd;
+                    } ppp;
+                } ifdata[1];
+            } ifid;
+        } ifli;
+    } nlreq;
+    int resp;
+
+    memset(&nlreq, 0, sizeof(nlreq));
+    nlreq.nlh.nlmsg_len = sizeof(nlreq);
+    nlreq.nlh.nlmsg_type = RTM_NEWLINK;
+    nlreq.nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE;
+    nlreq.ifm.ifi_family = AF_UNSPEC;
+    nlreq.ifm.ifi_type = ARPHRD_NETROM;
+    nlreq.ifn.rta.rta_len = sizeof(nlreq.ifn);
+    nlreq.ifn.rta.rta_type = IFLA_IFNAME;
+    strlcpy(nlreq.ifn.ifname, req_ifname, sizeof(nlreq.ifn.ifname));
+    nlreq.ifli.rta.rta_len = sizeof(nlreq.ifli);
+    nlreq.ifli.rta.rta_type = IFLA_LINKINFO;
+    nlreq.ifli.ifik.rta.rta_len = sizeof(nlreq.ifli.ifik);
+    nlreq.ifli.ifik.rta.rta_type = IFLA_INFO_KIND;
+    strcpy(nlreq.ifli.ifik.ifkind, "ppp");
+    nlreq.ifli.ifid.rta.rta_len = sizeof(nlreq.ifli.ifid);
+    nlreq.ifli.ifid.rta.rta_type = IFLA_INFO_DATA;
+    nlreq.ifli.ifid.ifdata[0].rta.rta_len = sizeof(nlreq.ifli.ifid.ifdata[0]);
+    nlreq.ifli.ifid.ifdata[0].rta.rta_type = IFLA_PPP_DEV_FD;
+    nlreq.ifli.ifid.ifdata[0].ppp.ppp_dev_fd = ppp_dev_fd;
+
+    /*
+     * See kernel function ppp_nl_newlink(), which may return -EBUSY to prevent
+     * possible deadlock in kernel and ask userspace to retry request again.
+     */
+    do {
+        resp = rtnetlink_msg("RTM_NEWLINK/NLM_F_CREATE", NULL, &nlreq, sizeof(nlreq), NULL, NULL, 0);
+    } while (resp == -EBUSY);
+
+    if (resp) {
+        /*
+         * Linux kernel versions prior to 4.7 do not support creating ppp
+         * interfaces via rtnetlink API and therefore error response is
+         * expected. On older kernel versions do not show this error message.
+         * When error is different than EEXIST then pppd tries to fallback to
+         * the old ioctl method.
+         */
+        errno = (resp < 0) ? -resp : EINVAL;
+        if (kernel_version >= KVERSION(4,7,0))
+            error("Couldn't create ppp interface %s: %m", req_ifname);
+        return 0;
+    }
+
+    return 1;
+}
+
 /*
  * make_ppp_unit - make a new ppp unit for ppp_dev_fd.
  * Assumes new_style_driver.
@@ -682,6 +898,33 @@ static int make_ppp_unit(void)
            || fcntl(ppp_dev_fd, F_SETFL, flags | O_NONBLOCK) == -1)
                warn("Couldn't set /dev/ppp to nonblock: %m");
 
+       /*
+        * Via rtnetlink it is possible to create ppp network interface with
+        * custom ifname atomically. But it is not possible to specify custom
+        * ppp unit id.
+        *
+        * Tools like systemd, udev or NetworkManager are trying to query
+        * interface attributes based on interface name immediately when new
+        * network interface is created. And therefore immediate interface
+        * renaming is causing issues.
+        *
+        * So use rtnetlink API only when user requested custom ifname. It will
+        * avoid system issues with interface renaming.
+        */
+       if (req_unit == -1 && req_ifname[0] != '\0' && kernel_version >= KVERSION(2,1,16)) {
+           if (make_ppp_unit_rtnetlink()) {
+               if (ioctl(ppp_dev_fd, PPPIOCGUNIT, &ifunit))
+                   fatal("Couldn't retrieve PPP unit id: %m");
+               return 0;
+           }
+           /*
+            * If interface with requested name already exist return error
+            * otherwise fallback to old ioctl method.
+            */
+           if (errno == EEXIST)
+               return -1;
+       }
+
        ifunit = req_unit;
        x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
        if (x < 0 && req_unit >= 0 && errno == EEXIST) {
@@ -689,6 +932,11 @@ static int make_ppp_unit(void)
                ifunit = -1;
                x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
        }
+       if (x < 0 && errno == EEXIST) {
+               srand(time(NULL) * getpid());
+               ifunit = rand() % 10000;
+               x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
+       }
        if (x < 0)
                error("Couldn't create new ppp unit: %m");
 
@@ -1244,7 +1492,7 @@ int read_packet (unsigned char *buf)
            error("read /dev/ppp: %m");
        if (nr < 0 && errno == ENXIO)
            nr = 0;
-       if (nr == 0 && doing_multilink) {
+       if (nr == 0 && mp_on()) {
            remove_fd(ppp_dev_fd);
            bundle_eof = 1;
        }
@@ -1290,7 +1538,7 @@ get_loop_output(void)
  * netif_set_mtu - set the MTU on the PPP network interface.
  */
 void
-netif_set_mtu(int unit, int mtu)
+ppp_set_mtu(int unit, int mtu)
 {
     struct ifreq ifr;
 
@@ -1306,7 +1554,7 @@ netif_set_mtu(int unit, int mtu)
  * netif_get_mtu - get the MTU on the PPP network interface.
  */
 int
-netif_get_mtu(int unit)
+ppp_get_mtu(int unit)
 {
     struct ifreq ifr;
 
@@ -1341,7 +1589,7 @@ void tty_send_config(int mtu, u_int32_t asyncmap, int pcomp, int accomp)
        }
 
        x = (pcomp? SC_COMP_PROT: 0) | (accomp? SC_COMP_AC: 0)
-           | (sync_serial? SC_SYNC: 0);
+           | (ppp_sync_serial()? SC_SYNC: 0);
        modify_flags(ppp_fd, SC_COMP_PROT|SC_COMP_AC|SC_SYNC, x);
 }
 
@@ -1514,123 +1762,57 @@ get_ppp_stats_ioctl(int u, struct pppd_stats *stats)
 static int
 get_ppp_stats_rtnetlink(int u, struct pppd_stats *stats)
 {
-    static int rtnl_fd = -1;
+#ifdef RTM_NEWSTATS
+    static int fd = -1;
 
-    struct sockaddr_nl nladdr;
     struct {
         struct nlmsghdr nlh;
         struct if_stats_msg ifsm;
     } nlreq;
-    struct nlresp {
-        struct nlmsghdr nlh;
-       union {
-           struct {
-               struct nlmsgerr nlerr;
-               char __end_err[0];
-           };
-           struct {
-               struct rtmsg rth;
-               struct  {
-                   /* We only case about these first fields from rtnl_link_stats64 */
-                   uint64_t rx_packets;
-                   uint64_t tx_packets;
-                   uint64_t rx_bytes;
-                   uint64_t tx_bytes;
-               } stats;
-               char __end_stats[0];
-           };
-       };
-    } nlresp;
-    ssize_t nlresplen;
-    struct iovec iov;
-    struct msghdr msg;
-
-    memset(&nladdr, 0, sizeof(nladdr));
-    nladdr.nl_family = AF_NETLINK;
-
-    if (rtnl_fd < 0) {
-       rtnl_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-       if (rtnl_fd < 0) {
-           error("get_ppp_stats_rtnetlink: error creating NETLINK socket: %m (line %d)", __LINE__);
-           return 0;
-       }
-
-       if (bind(rtnl_fd, (struct sockaddr *)&nladdr, sizeof(nladdr)) < 0) {
-           error("get_ppp_stats_rtnetlink: bind(AF_NETLINK): %m (line %d)", __LINE__);
-           goto err;
-       }
-    }
+    struct {
+        struct rtmsg rth;
+        struct {
+            /* We only case about these first fields from rtnl_link_stats64 */
+            uint64_t rx_packets;
+            uint64_t tx_packets;
+            uint64_t rx_bytes;
+            uint64_t tx_bytes;
+        } stats;
+    } nlresp_data;
+    size_t nlresp_size;
+    int resp;
 
     memset(&nlreq, 0, sizeof(nlreq));
     nlreq.nlh.nlmsg_len = sizeof(nlreq);
     nlreq.nlh.nlmsg_type = RTM_GETSTATS;
     nlreq.nlh.nlmsg_flags = NLM_F_REQUEST;
-
     nlreq.ifsm.ifindex = if_nametoindex(ifname);
     nlreq.ifsm.filter_mask = IFLA_STATS_LINK_64;
 
-    memset(&iov, 0, sizeof(iov));
-    iov.iov_base = &nlreq;
-    iov.iov_len = sizeof(nlreq);
-
-    memset(&msg, 0, sizeof(msg));
-    msg.msg_name = &nladdr;
-    msg.msg_namelen = sizeof(nladdr);
-    msg.msg_iov = &iov;
-    msg.msg_iovlen = 1;
-
-    if (sendmsg(rtnl_fd, &msg, 0) < 0) {
-        error("get_ppp_stats_rtnetlink: sendmsg(RTM_GETSTATS): %m (line %d)", __LINE__);
-       goto err;
-    }
-
-    /* We just need to repoint to IOV ... everything else stays the same */
-    iov.iov_base = &nlresp;
-    iov.iov_len = sizeof(nlresp);
-
-    nlresplen = recvmsg(rtnl_fd, &msg, 0);
-
-    if (nlresplen < 0) {
-        error("get_ppp_stats_rtnetlink: recvmsg(RTM_GETSTATS): %m (line %d)", __LINE__);
-       goto err;
-    }
-
-    if (nlresplen < sizeof(nlresp.nlh)) {
-       error("get_ppp_stats_rtnetlink: Netlink response message was incomplete (line %d)", __LINE__);
-       goto err;
-    }
-
-    if (nlresp.nlh.nlmsg_type == NLMSG_ERROR) {
-       if (nlresplen < offsetof(struct nlresp, __end_err)) {
-           if (kernel_version >= KVERSION(4,7,0))
-               error("get_ppp_stats_rtnetlink: Netlink responded with error: %s (line %d)", strerror(-nlresp.nlerr.error), __LINE__);
-       } else {
-           error("get_ppp_stats_rtnetlink: Netlink responded with an error message, but the nlmsgerr structure is incomplete (line %d).",
-                   __LINE__);
-       }
-       goto err;
+    nlresp_size = sizeof(nlresp_data);
+    resp = rtnetlink_msg("RTM_GETSTATS/NLM_F_REQUEST", &fd, &nlreq, sizeof(nlreq), &nlresp_data, &nlresp_size, RTM_NEWSTATS);
+    if (resp) {
+        errno = (resp < 0) ? -resp : EINVAL;
+        if (kernel_version >= KVERSION(4,7,0))
+            error("get_ppp_stats_rtnetlink: %m (line %d)", __LINE__);
+        goto err;
     }
 
-    if (nlresp.nlh.nlmsg_type != RTM_NEWSTATS) {
-       error("get_ppp_stats_rtnetlink: Expected RTM_NEWSTATS response, found something else (mlmsg_type %d, line %d)",
-               nlresp.nlh.nlmsg_type, __LINE__);
-       goto err;
-    }
-
-    if (nlresplen < offsetof(struct nlresp, __end_stats)) {
+    if (nlresp_size < sizeof(nlresp_data)) {
        error("get_ppp_stats_rtnetlink: Obtained an insufficiently sized rtnl_link_stats64 struct from the kernel (line %d).", __LINE__);
        goto err;
     }
 
-    stats->bytes_in  = nlresp.stats.rx_bytes;
-    stats->bytes_out = nlresp.stats.tx_bytes;
-    stats->pkts_in   = nlresp.stats.rx_packets;
-    stats->pkts_out  = nlresp.stats.tx_packets;
+    stats->bytes_in  = nlresp_data.stats.rx_bytes;
+    stats->bytes_out = nlresp_data.stats.tx_bytes;
+    stats->pkts_in   = nlresp_data.stats.rx_packets;
+    stats->pkts_out  = nlresp_data.stats.tx_packets;
 
     return 1;
 err:
-    close(rtnl_fd);
-    rtnl_fd = -1;
+    close(fd);
+    fd = -1;
+#endif
     return 0;
 }
 
@@ -2007,11 +2189,27 @@ int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replac
         * - this is normally only the case the doing demand: */
        if (defaultroute_exists(&tmp_rt, -1))
            del_rt = &tmp_rt;
+    } else if (!replace) {
+       /*
+        * We don't want to replace an existing route.
+        * We may however add our route along an existing route with a different
+        * metric.
+        */
+       if (defaultroute_exists(&rt, dfl_route_metric) && strcmp(rt.rt_dev, ifname) != 0) {
+          if (rt.rt_flags & RTF_GATEWAY)
+              error("not replacing existing default route via %I with metric %d",
+                    SIN_ADDR(rt.rt_gateway), dfl_route_metric);
+          else
+              error("not replacing existing default route through %s with metric %d",
+                    rt.rt_dev, dfl_route_metric);
+          return 0;
+       }
     } else if (defaultroute_exists(&old_def_rt, -1           ) &&
                            strcmp( old_def_rt.rt_dev, ifname) != 0) {
        /*
-        * We did not yet replace an existing default route, let's
-        * check if we should save and replace a default route:
+        * We want to replace an existing route and did not replace an existing
+        * default route yet, let's check if we should save and replace an
+        * existing default route:
         */
        u_int32_t old_gateway = SIN_ADDR(old_def_rt.rt_gateway);
 
@@ -2077,8 +2275,6 @@ int cifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
     SET_SA_FAMILY (rt.rt_dst,     AF_INET);
     SET_SA_FAMILY (rt.rt_gateway, AF_INET);
 
-    rt.rt_dev = ifname;
-
     rt.rt_dev = ifname;
     rt.rt_metric = dfl_route_metric + 1; /* +1 for binary compatibility */
 
@@ -2666,11 +2862,11 @@ ppp_registered(void)
 
 /********************************************************************
  *
- * ppp_available - check whether the system has any ppp interfaces
+ * ppp_check_kernel_support - check whether the system has any ppp interfaces
  * (in fact we check whether we can do an ioctl on ppp0).
  */
 
-int ppp_available(void)
+int ppp_check_kernel_support(void)
 {
     int s, ok, fd;
     struct ifreq ifr;
@@ -3167,43 +3363,7 @@ static int sif6addr_rtnetlink(unsigned int iface, eui64_t our_eui64, eui64_t his
             struct in6_addr addr;
         } addrs[2];
     } nlreq;
-    struct {
-        struct nlmsghdr nlh;
-        struct nlmsgerr nlerr;
-    } nlresp;
-    struct sockaddr_nl nladdr;
-    struct iovec iov;
-    struct msghdr msg;
-    ssize_t nlresplen;
-    int one;
-    int fd;
-
-    fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-    if (fd < 0) {
-        error("sif6addr_rtnetlink: socket(NETLINK_ROUTE): %m (line %d)", __LINE__);
-        return 0;
-    }
-
-    /*
-     * Tell kernel to not send to us payload of acknowledgment error message.
-     * NETLINK_CAP_ACK option is supported since Linux kernel version 4.3 and
-     * older kernel versions always send full payload in acknowledgment netlink
-     * message. We ignore payload of this message as we need only error code,
-     * to check if our set remote peer address request succeeded or failed.
-     * So ignore return value from the following setsockopt() call as setting
-     * option NETLINK_CAP_ACK means for us just a kernel hint / optimization.
-     */
-    one = 1;
-    setsockopt(fd, SOL_NETLINK, NETLINK_CAP_ACK, &one, sizeof(one));
-
-    memset(&nladdr, 0, sizeof(nladdr));
-    nladdr.nl_family = AF_NETLINK;
-
-    if (bind(fd, (struct sockaddr *)&nladdr, sizeof(nladdr)) < 0) {
-        error("sif6addr_rtnetlink: bind(AF_NETLINK): %m (line %d)", __LINE__);
-        close(fd);
-        return 0;
-    }
+    int resp;
 
     memset(&nlreq, 0, sizeof(nlreq));
     nlreq.nlh.nlmsg_len = sizeof(nlreq);
@@ -3233,71 +3393,17 @@ static int sif6addr_rtnetlink(unsigned int iface, eui64_t our_eui64, eui64_t his
     else
         IN6_LLADDR_FROM_EUI64(nlreq.addrs[1].addr, our_eui64);
 
-    memset(&nladdr, 0, sizeof(nladdr));
-    nladdr.nl_family = AF_NETLINK;
-
-    memset(&iov, 0, sizeof(iov));
-    iov.iov_base = &nlreq;
-    iov.iov_len = sizeof(nlreq);
-
-    memset(&msg, 0, sizeof(msg));
-    msg.msg_name = &nladdr;
-    msg.msg_namelen = sizeof(nladdr);
-    msg.msg_iov = &iov;
-    msg.msg_iovlen = 1;
-
-    if (sendmsg(fd, &msg, 0) < 0) {
-        error("sif6addr_rtnetlink: sendmsg(RTM_NEWADDR/NLM_F_CREATE): %m (line %d)", __LINE__);
-        close(fd);
-        return 0;
-    }
-
-    memset(&iov, 0, sizeof(iov));
-    iov.iov_base = &nlresp;
-    iov.iov_len = sizeof(nlresp);
-
-    memset(&msg, 0, sizeof(msg));
-    msg.msg_name = &nladdr;
-    msg.msg_namelen = sizeof(nladdr);
-    msg.msg_iov = &iov;
-    msg.msg_iovlen = 1;
-
-    nlresplen = recvmsg(fd, &msg, 0);
-
-    if (nlresplen < 0) {
-        error("sif6addr_rtnetlink: recvmsg(NLM_F_ACK): %m (line %d)", __LINE__);
-        close(fd);
-        return 0;
-    }
-
-    close(fd);
-
-    if (nladdr.nl_family != AF_NETLINK) {
-        error("sif6addr_rtnetlink: recvmsg(NLM_F_ACK): Not a netlink packet (line %d)", __LINE__);
-        return 0;
-    }
-
-    if ((size_t)nlresplen != sizeof(nlresp) || nlresp.nlh.nlmsg_len < sizeof(nlresp)) {
-        error("sif6addr_rtnetlink: recvmsg(NLM_F_ACK): Acknowledgment netlink packet too short (line %d)", __LINE__);
-        return 0;
-    }
-
-    /* acknowledgment packet for NLM_F_ACK is NLMSG_ERROR */
-    if (nlresp.nlh.nlmsg_type != NLMSG_ERROR) {
-        error("sif6addr_rtnetlink: recvmsg(NLM_F_ACK): Not an acknowledgment netlink packet (line %d)", __LINE__);
-        return 0;
-    }
-
-    /* error == 0 indicates success, negative value is errno code */
-    if (nlresp.nlerr.error != 0) {
+    resp = rtnetlink_msg("RTM_NEWADDR/NLM_F_CREATE", NULL, &nlreq, sizeof(nlreq), NULL, NULL, 0);
+    if (resp) {
         /*
          * Linux kernel versions prior 3.11 do not support setting IPv6 peer
          * addresses and error response is expected. On older kernel versions
          * do not show this error message. On error pppd tries to fallback to
          * the old IOCTL method.
          */
+        errno = (resp < 0) ? -resp : EINVAL;
         if (kernel_version >= KVERSION(3,11,0))
-            error("sif6addr_rtnetlink: %s (line %d)", strerror(-nlresp.nlerr.error), __LINE__);
+            error("sif6addr_rtnetlink: %m (line %d)", __LINE__);
         return 0;
     }
 
@@ -3573,7 +3679,7 @@ int
 get_host_seed(void)
 {
     int h;
-    char *p = hostname;
+    const char *p;
 
     h = 407;
     for (p = hostname; *p != 0; ++p)
@@ -3590,7 +3696,7 @@ int
 sys_check_options(void)
 {
     if (demand && driver_is_old) {
-       option_error("demand dialling is not supported by kernel driver "
+       ppp_option_error("demand dialling is not supported by kernel driver "
                     "version %d.%d.%d", driver_version, driver_modification,
                     driver_patch);
        return 0;
@@ -3607,7 +3713,7 @@ sys_check_options(void)
  * get_time - Get current time, monotonic if possible.
  */
 int
-get_time(struct timeval *tv)
+ppp_get_time(struct timeval *tv)
 {
 /* Old glibc (< 2.3.4) does define CLOCK_MONOTONIC, but kernel may have it.
  * Runtime checking makes it safe. */
index d903721de9659b76653f1b57e29d16001de30677..e4421089981447f2b150cb097e42be891d19205e 100644 (file)
@@ -18,7 +18,7 @@
  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
  *
- * Copyright (c) 1995-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1995-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -99,9 +95,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <termios.h>
-#ifndef CRTSCTS
-#include <sys/termiox.h>
-#endif
 #include <signal.h>
 #include <utmpx.h>
 #include <stropts.h>
 #include <net/ppp_defs.h>
 #include <net/pppio.h>
 #include <netinet/in.h>
-#ifdef SOL2
 #include <sys/tihdr.h>
 #include <sys/tiuser.h>
 #include <inet/common.h>
 #include <inet/mib2.h>
 #include <sys/ethernet.h>
-#endif
 
 #ifdef PPP_WITH_FILTER
 #include <pcap.h>
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
 #include "lcp.h"
 #include "ipcp.h"
 #include "ccp.h"
-
-#ifdef PPP_WITH_IPV6CP
 #include "eui64.h"
-#endif
-
-#if !defined(PPP_DRV_NAME)
-#define PPP_DRV_NAME   "ppp"
-#endif /* !defined(PPP_DRV_NAME) */
 
 #if !defined(PPP_DEV_NAME)
 #define PPP_DEV_NAME   "/dev/" PPP_DRV_NAME
 #endif /* !defined(PPP_DEV_NAME) */
 
 #if !defined(AHDLC_MOD_NAME)
-#define AHDLC_MOD_NAME "ppp_ahdl"
+#define AHDLC_MOD_NAME "spppasyn"
 #endif /* !defined(AHDLC_MOD_NAME) */
 
 #if !defined(COMP_MOD_NAME)
-#define COMP_MOD_NAME  "ppp_comp"
+#define COMP_MOD_NAME  "spppcomp"
 #endif /* !defined(COMP_MOD_NAME) */
 
-#if !defined(IP_DEV_NAME)
-#define        IP_DEV_NAME     "/dev/ip"
-#endif /* !defined(IP_DEV_NAME) */
-
 #if !defined(IP_MOD_NAME)
 #define        IP_MOD_NAME     "ip"
 #endif /* !defined(IP_MOD_NAME) */
 
-#if !defined(UDP_DEV_NAME) && defined(SOL2)
 #define        UDP_DEV_NAME    "/dev/udp"
-#endif /* !defined(UDP_DEV_NAME) && defined(SOL2) */
-
-#if !defined(UDP6_DEV_NAME) && defined(SOL2)
 #define        UDP6_DEV_NAME   "/dev/udp6"
-#endif /* !defined(UDP6_DEV_NAME) && defined(SOL2) */
-
 
-#if defined(SOL2)
 /*
  * "/dev/udp" is used as a multiplexor to PLINK the interface stream
  * under. It is used in place of "/dev/ip" since STREAMS will not let
  * driver at the bottom of the tunneling interfaces stream.
  */
 static char *mux_dev_name = UDP_DEV_NAME;
-#else
-static char *mux_dev_name = IP_DEV_NAME;
-#endif
 static int     pppfd;
 static int     fdmuxid = -1;
 static int     ipfd;
 static int     ipmuxid = -1;
-
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
 static int     ip6fd;          /* IP file descriptor */
 static int     ip6muxid = -1;  /* Multiplexer file descriptor */
 static int     if6_is_up = 0;  /* IPv6 interface has been marked up */
@@ -228,18 +196,8 @@ static int if6_is_up = 0;  /* IPv6 interface has been marked up */
 #define IN6A_LLADDR_FROM_EUI64(s, eui64)  \
     _IN6A_LLX_FROM_EUI64(s, eui64, 0xfe800000)
 
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
-
-#if !defined(PPP_WITH_IPV6CP) || !defined(SOL2)
-#define MAXIFS         256                     /* Max # of interfaces */
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
-
 static int     restore_term;
 static struct termios inittermios;
-#ifndef CRTSCTS
-static struct termiox inittermiox;
-static int     termiox_ok;
-#endif
 static struct winsize wsinfo;  /* Initial window size info */
 static pid_t   tty_sid;        /* original session ID for terminal */
 
@@ -273,7 +231,6 @@ static int dlpi_info_req(int);
 static int dlpi_get_reply(int, union DL_primitives *, int, size_t);
 static int strioctl(int, int, void *, int, int);
 
-#ifdef SOL2
 /*
  * sifppa - Sets interface ppa
  *
@@ -299,14 +256,10 @@ sifppa(fd, ppa)
 {
     return (int)ioctl(fd, IF_UNITSEL, (char *)&ppa);
 }
-#endif /* SOL2 */
 
-#if defined(SOL2) && defined(PPP_WITH_IPV6CP)
 /*
  * get_first_ether_hwaddr - get the hardware address for the first
  * ethernet-style interface on this system.
- *
- * NOTE: This is the lifreq version (Solaris 8 and above)
  */
 int
 get_first_ether_hwaddr(u_char *addr)
@@ -395,95 +348,7 @@ get_first_ether_hwaddr(u_char *addr)
     else
        return -1;
 }
-#else
-/*
- * get_first_ether_hwaddr - get the hardware address for the first
- * ethernet-style interface on this system.
- *
- * NOTE: This is the ifreq version (before Solaris 8). 
- */
-int
-get_first_ether_hwaddr(u_char *addr)
-{
-    struct ifconf ifc;
-    struct ifreq *pifreq;
-    struct ifreq ifr;
-    int        fd, num_ifs, i, found;
-    uint_t fl, req_size;
-    char *req;
 
-    fd = socket(AF_INET, SOCK_DGRAM, 0);
-    if (fd < 0) {
-       return -1;
-    }
-
-    /*
-     * Find out how many interfaces are running
-     */
-    if (ioctl(fd, SIOCGIFNUM, (char *)&num_ifs) < 0) {
-       num_ifs = MAXIFS;
-    }
-
-    req_size = num_ifs * sizeof(struct ifreq);
-    req = malloc(req_size);
-    if (req == NULL) {
-       close(fd);
-       error("out of memory");
-       return -1;
-    }
-
-    /*
-     * Get interface configuration info for all interfaces
-     */
-    ifc.ifc_len = req_size;
-    ifc.ifc_buf = req;
-    if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
-       close(fd);
-       free(req);
-       error("SIOCGIFCONF: %m");
-       return -1;
-    }
-
-    /*
-     * And traverse each interface to look specifically for the first
-     * occurence of an Ethernet interface which has been marked up
-     */
-    pifreq = ifc.ifc_req;
-    found = 0;
-    for (i = ifc.ifc_len / sizeof(struct ifreq); i > 0; i--, pifreq++) {
-
-       if (strchr(pifreq->ifr_name, ':') != NULL)
-           continue;
-
-       memset(&ifr, 0, sizeof(ifr));
-       strncpy(ifr.ifr_name, pifreq->ifr_name, sizeof(ifr.ifr_name));
-       if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
-           error("SIOCGIFFLAGS: %m");
-           break;
-       }
-       fl = ifr.ifr_flags;
-
-       if ((fl & (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
-               != (IFF_UP | IFF_BROADCAST))
-           continue;
-
-       if (get_if_hwaddr(addr, ifr.ifr_name) < 0)
-           continue;
-
-       found = 1;
-       break;
-    }
-    free(req);
-    close(fd);
-
-    if (found)
-       return 0;
-    else
-       return -1;
-}
-#endif /* defined(SOL2) && defined(PPP_WITH_IPV6CP) */
-
-#if defined(SOL2)
 /*
  * get_if_hwaddr - get the hardware address for the specified
  * network interface device.
@@ -508,9 +373,7 @@ get_if_hwaddr(u_char *addr, char *if_name)
     memcpy(addr, eth_addr->ether_addr_octet, 6);
     return 1;
 }
-#endif /* SOL2 */
 
-#if defined(SOL2) && defined(PPP_WITH_IPV6CP)
 /*
  * slifname - Sets interface ppa and flags
  *
@@ -537,10 +400,7 @@ slifname(int fd, int ppa)
 
 slifname_done:
     return ret;
-
-
 }
-#endif /* defined(SOL2) && defined(PPP_WITH_IPV6CP) */
 
 /*
  * sys_init - System-dependent initialization.
@@ -550,26 +410,16 @@ sys_init(void)
 {
     int ifd, x;
     struct ifreq ifr;
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     int i6fd;
     struct lifreq lifr;
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
-#if !defined(SOL2)
-    struct {
-       union DL_primitives prim;
-       char space[64];
-    } reply;
-#endif /* !defined(SOL2) */
 
     ipfd = open(mux_dev_name, O_RDWR, 0);
     if (ipfd < 0)
        fatal("Couldn't open IP device: %m");
 
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     ip6fd = open(UDP6_DEV_NAME, O_RDWR, 0);
     if (ip6fd < 0)
        fatal("Couldn't open IP device (2): %m");
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
 
     if (default_device && !notty)
        tty_sid = getsid((pid_t)0);
@@ -586,7 +436,6 @@ sys_init(void)
     if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
        fatal("Can't create new PPP interface: %m");
 
-#if defined(SOL2)
     /*
      * Since sys_init() is called prior to ifname being set in main(),
      * we need to get the ifname now, otherwise slifname(), and others,
@@ -594,7 +443,7 @@ sys_init(void)
      * <adi.masputra@sun.com>
      */
     sprintf(ifname, PPP_DRV_NAME "%d", ifunit);
-#endif /* defined(SOL2) */
+
     /*
      * Open the ppp device again and link it under the ip multiplexor.
      * IP will assign a unit number which hopefully is the same as ifunit.
@@ -608,7 +457,6 @@ sys_init(void)
        strioctl(ifd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
 
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     i6fd = open(PPP_DEV_NAME, O_RDWR, 0);
     if (i6fd < 0) {
        close(ifd);
@@ -618,14 +466,10 @@ sys_init(void)
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(i6fd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
 
-#if defined(SOL2)
     if (ioctl(ifd, I_PUSH, IP_MOD_NAME) < 0) {
        close(ifd);
-#if defined(PPP_WITH_IPV6CP)
        close(i6fd);
-#endif /* defined(PPP_WITH_IPV6CP) */
        fatal("Can't push IP module: %m");
     }
 
@@ -635,13 +479,10 @@ sys_init(void)
      */
     if (sifppa(ifd, ifunit) < 0) {
         close (ifd);
-#if defined(PPP_WITH_IPV6CP)
        close(i6fd);
-#endif /* defined(PPP_WITH_IPV6CP) */
         fatal("Can't set ppa for unit %d: %m", ifunit);
     }
 
-#if defined(PPP_WITH_IPV6CP)
     /*
      * An IPv6 interface is created anyway, even when the user does not 
      * explicitly enable it. Note that the interface will be marked
@@ -663,14 +504,11 @@ sys_init(void)
        close(i6fd);
        fatal("Can't set ifname for unit %d: %m", ifunit);
     }
-#endif /* defined(PPP_WITH_IPV6CP) */
 
     ipmuxid = ioctl(ipfd, I_PLINK, ifd);
     close(ifd);
     if (ipmuxid < 0) {
-#if defined(PPP_WITH_IPV6CP)
        close(i6fd);
-#endif /* defined(PPP_WITH_IPV6CP) */
        fatal("Can't I_PLINK PPP device to IP: %m");
     }
 
@@ -687,27 +525,10 @@ sys_init(void)
      */
     if (ioctl(ipfd, SIOCSIFMUXID, &ifr) < 0) {
        ioctl(ipfd, I_PUNLINK, ipmuxid);
-#if defined(PPP_WITH_IPV6CP)
        close(i6fd);
-#endif /* defined(PPP_WITH_IPV6CP) */
        fatal("SIOCSIFMUXID: %m");
     }
 
-#else /* else if !defined(SOL2) */
-
-    if (dlpi_attach(ifd, ifunit) < 0 ||
-       dlpi_get_reply(ifd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0) {
-       close(ifd);
-       fatal("Can't attach to ppp%d: %m", ifunit);
-    }
-
-    ipmuxid = ioctl(ipfd, I_LINK, ifd);
-    close(ifd);
-    if (ipmuxid < 0)
-       fatal("Can't link PPP device to IP: %m");
-#endif /* defined(SOL2) */
-
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     ip6muxid = ioctl(ip6fd, I_PLINK, i6fd);
     close(i6fd);
     if (ip6muxid < 0) {
@@ -727,15 +548,6 @@ sys_init(void)
        ioctl(ip6fd, I_PUNLINK, ip6muxid);
        fatal("Can't link PPP device to IP (2): %m");
     }
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
-
-#if !defined(SOL2)
-    /* Set the interface name for the link. */
-    slprintf(ifr.ifr_name, sizeof(ifr.ifr_name), PPP_DRV_NAME "%d", ifunit);
-    ifr.ifr_metric = ipmuxid;
-    if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0)
-       fatal("Can't set interface name %s: %m", ifr.ifr_name);
-#endif /* !defined(SOL2) */
 
     n_pollfds = 0;
 }
@@ -748,17 +560,11 @@ sys_init(void)
 void
 sys_cleanup(void)
 {
-#if defined(SOL2)
     struct ifreq ifr;
-#if defined(PPP_WITH_IPV6CP)
     struct lifreq lifr;
-#endif /* defined(PPP_WITH_IPV6CP) */
-#endif /* defined(SOL2) */
 
-#if defined(SOL2) && defined(PPP_WITH_IPV6CP)
     if (if6_is_up)
        sif6down(0);
-#endif /* defined(SOL2) && defined(PPP_WITH_IPV6CP) */
     if (if_is_up)
        sifdown(0);
     if (default_route_gateway)
@@ -767,7 +573,7 @@ sys_cleanup(void)
        cif6defaultroute(0, default_route_gateway6, default_route_gateway6);
     if (proxy_arp_addr)
        cifproxyarp(0, proxy_arp_addr);
-#if defined(SOL2)
+
     /*
      * Make sure we ask ip what the muxid, because 'ifconfig modlist' will
      * unlink and re-link the modules, causing the muxid to change.
@@ -790,7 +596,7 @@ sys_cleanup(void)
        error("Can't I_PUNLINK PPP from IP: %m");
        return;
     }
-#if defined(PPP_WITH_IPV6CP)
+
     /*
      * Make sure we ask ip what the muxid, because 'ifconfig modlist' will
      * unlink and re-link the modules, causing the muxid to change.
@@ -812,20 +618,16 @@ sys_cleanup(void)
     if (ioctl(ip6fd, I_PUNLINK, ip6muxid) < 0) {
        error("Can't I_PUNLINK PPP from IP (2): %m");
     }
-#endif /* defined(PPP_WITH_IPV6CP) */
-#endif /* defined(SOL2) */
 }
 
 /*
  * sys_close - Clean up in a child process before execing.
  */
 void
-sys_close(void)
+ppp_sys_close(void)
 {
     close(ipfd);
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     close(ip6fd);
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
     if (pppfd >= 0)
        close(pppfd);
 }
@@ -839,36 +641,11 @@ sys_check_options(void)
     return 1;
 }
 
-#if 0
-/*
- * daemon - Detach us from controlling terminal session.
- */
-int
-daemon(int nochdir, int noclose)
-{
-    int pid;
-
-    if ((pid = fork()) < 0)
-       return -1;
-    if (pid != 0)
-       exit(0);                /* parent dies */
-    setsid();
-    if (!nochdir)
-       chdir("/");
-    if (!noclose) {
-       fclose(stdin);          /* don't need stdin, stdout, stderr */
-       fclose(stdout);
-       fclose(stderr);
-    }
-    return 0;
-}
-#endif
-
 /*
- * ppp_available - check whether the system has any ppp interfaces
+ * ppp_check_kernel_support - check whether the system has any ppp interfaces
  */
 int
-ppp_available(void)
+ppp_check_kernel_support(void)
 {
     struct stat buf;
 
@@ -915,7 +692,7 @@ tty_establish_ppp(int fd)
     /* Push the async hdlc module and the compressor module. */
     tty_npushed = 0;
 
-    if(!sync_serial) {
+    if(!ppp_sync_serial()) {
         if (ioctl(fd, I_PUSH, AHDLC_MOD_NAME) < 0) {
             error("Couldn't push PPP Async HDLC module: %m");
            return -1;
@@ -1156,46 +933,21 @@ set_up_tty(int fd, int local)
 {
     int speed;
     struct termios tios;
-#if !defined (CRTSCTS)
-    struct termiox tiox;
-#endif
 
-    if (!sync_serial && tcgetattr(fd, &tios) < 0)
+    if (!ppp_sync_serial() && tcgetattr(fd, &tios) < 0)
        fatal("tcgetattr: %m");
 
-#ifndef CRTSCTS
-    termiox_ok = 1;
-    if (!sync_serial && ioctl (fd, TCGETX, &tiox) < 0) {
-       termiox_ok = 0;
-       if (errno != ENOTTY)
-           error("TCGETX: %m");
-    }
-#endif
-
     if (!restore_term) {
        inittermios = tios;
-#ifndef CRTSCTS
-       inittermiox = tiox;
-#endif
-       if (!sync_serial)
+       if (!ppp_sync_serial())
            ioctl(fd, TIOCGWINSZ, &wsinfo);
     }
 
     tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
-#ifdef CRTSCTS
     if (crtscts > 0)
        tios.c_cflag |= CRTSCTS;
     else if (crtscts < 0)
        tios.c_cflag &= ~CRTSCTS;
-#else
-    if (crtscts != 0 && !termiox_ok) {
-       error("Can't set RTS/CTS flow control");
-    } else if (crtscts > 0) {
-       tiox.x_hflag |= RTSXOFF|CTSXON;
-    } else if (crtscts < 0) {
-       tiox.x_hflag &= ~(RTSXOFF|CTSXON);
-    }
-#endif
 
     if (stop_bits >= 2)
        tios.c_cflag |= CSTOPB;
@@ -1225,21 +977,15 @@ set_up_tty(int fd, int local)
         * We can't proceed if the serial port speed is 0,
         * since that implies that the serial port is disabled.
         */
-       if ((speed == B0) && !sync_serial)
+       if ((speed == B0) && !ppp_sync_serial())
            fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
 
-    if (!sync_serial && tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+    if (!ppp_sync_serial() && tcsetattr(fd, TCSAFLUSH, &tios) < 0)
        fatal("tcsetattr: %m");
 
-#ifndef CRTSCTS
-    if (!sync_serial && termiox_ok && ioctl (fd, TCSETXF, &tiox) < 0){
-       error("TCSETXF: %m");
-    }
-#endif
-
     baud_rate = inspeed = baud_rate_of(speed);
-    if (!sync_serial)
+    if (!ppp_sync_serial())
        restore_term = 1;
 }
 
@@ -1259,16 +1005,10 @@ restore_tty(int fd)
             */
            inittermios.c_lflag &= ~(ECHO | ECHONL);
        }
-       if (!sync_serial && tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
+       if (!ppp_sync_serial() && tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (!hungup && errno != ENXIO)
                warn("tcsetattr: %m");
-#ifndef CRTSCTS
-       if (!sync_serial && ioctl (fd, TCSETXF, &inittermiox) < 0){
-           if (!hungup && errno != ENXIO)
-               error("TCSETXF: %m");
-       }
-#endif
-       if (!sync_serial)
+       if (!ppp_sync_serial())
            ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = 0;
     }
@@ -1376,34 +1116,6 @@ void remove_fd(int fd)
     }
 }
 
-#if 0
-/*
- * wait_loop_output - wait until there is data available on the
- * loopback, for the length of time specified by *timo (indefinite
- * if timo is NULL).
- */
-void
-wait_loop_output(struct timeval *timo)
-{
-    wait_input(timo);
-}
-
-/*
- * wait_time - wait for a given length of time or until a
- * signal is received.
- */
-void
-wait_time(struct timeval *timo)
-{
-    int n;
-
-    n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR)
-       fatal("select: %m");
-}
-#endif
-
-
 /*
  * read_packet - get a PPP packet from the serial device.
  */
@@ -1434,7 +1146,7 @@ read_packet(u_char *buf)
         * Got a M_PROTO or M_PCPROTO message.  Interpret it
         * as a DLPI primitive??
         */
-       if (debug)
+       if (debug && ((union DL_primitives *)ctrlbuf)->dl_primitive != 0x53505050)
            dbglog("got dlpi prim 0x%x, len=%d",
                   ((union DL_primitives *)ctrlbuf)->dl_primitive, ctrl.len);
 
@@ -1460,16 +1172,14 @@ get_loop_output(void)
 }
 
 /*
- * netif_set_mtu - set the MTU on the PPP network interface.
+ * ppp_set_mtu - set the MTU on the PPP network interface.
  */
 void
-netif_set_mtu(int unit, int mtu)
+ppp_set_mtu(int unit, int mtu)
 {
     struct ifreq ifr;
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     struct lifreq lifr;
     int        fd;
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
 
     memset(&ifr, 0, sizeof(ifr));
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
@@ -1478,7 +1188,6 @@ netif_set_mtu(int unit, int mtu)
        error("Couldn't set IP MTU (%s): %m", ifr.ifr_name);
     }
 
-#if defined(PPP_WITH_IPV6CP) && defined(SOL2)
     fd = socket(AF_INET6, SOCK_DGRAM, 0);
     if (fd < 0)
        error("Couldn't open IPv6 socket: %m");
@@ -1491,16 +1200,15 @@ netif_set_mtu(int unit, int mtu)
        error("Couldn't set IPv6 MTU (%s): %m", ifr.ifr_name);
     }
     close(fd);
-#endif /* defined(PPP_WITH_IPV6CP) && defined(SOL2) */
 }
 
 
 
 /*
- * netif_get_mtu - get the MTU on the PPP network interface.
+ * ppp_get_mtu - get the MTU on the PPP network interface.
  */
 int
-netif_get_mtu(int unit)
+ppp_get_mtu(int unit)
 {
     struct ifreq ifr;
 
@@ -1532,7 +1240,7 @@ tty_send_config(int mtu, u_int32_t asyncmap, int pcomp, int accomp)
        error("Couldn't set MTU: %m");
     }
     if (fdmuxid >= 0) {
-       if (!sync_serial) {
+       if (!ppp_sync_serial()) {
            if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0)
                error("Couldn't set transmit ACCM: %m");
        }
@@ -1550,7 +1258,7 @@ tty_send_config(int mtu, u_int32_t asyncmap, int pcomp, int accomp)
 void
 tty_set_xaccm(ext_accm accm)
 {
-    if (sync_serial)
+    if (ppp_sync_serial())
        return;
 
     if (fdmuxid >= 0
@@ -1578,7 +1286,7 @@ tty_recv_config(int mru, u_int32_t asyncmap, int pcomp, int accomp)
        error("Couldn't set MRU: %m");
     }
     if (fdmuxid >= 0) {
-       if (!sync_serial) {
+       if (!ppp_sync_serial()) {
            if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0)
                error("Couldn't set receive ACCM: %m");
        }
@@ -1634,10 +1342,10 @@ get_idle_time(int u, struct ppp_idle *ip)
 int
 get_ppp_stats(int u, struct pppd_stats *stats)
 {
-    struct ppp_stats s;
+    struct ppp_stats64 s;
 
-    if (!sync_serial && 
-       strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) {
+    if (!ppp_sync_serial() &&
+       strioctl(pppfd, PPPIO_GETSTAT64, &s, 0, sizeof(s)) < 0) {
        error("Couldn't get link statistics: %m");
        return 0;
     }
@@ -1758,7 +1466,6 @@ sifnpmode(int u, int proto, enum NPmode mode)
     return 1;
 }
 
-#if defined(SOL2) && defined(PPP_WITH_IPV6CP)
 /*
  * sif6up - Config the IPv6 interface up and enable IPv6 packets to pass.
  */
@@ -1942,9 +1649,6 @@ cif6defaultroute(int u, eui64_t l, eui64_t g)
     return 1;
 }
 
-#endif /* defined(SOL2) && defined(PPP_WITH_IPV6CP) */
-
-
 #define INET_ADDR(x)   (((struct sockaddr_in *) &(x))->sin_addr.s_addr)
 
 /*
@@ -2136,9 +1840,7 @@ get_ether_addr(u_int32_t ipaddr, struct sockaddr *hwaddr)
     /*
      * Scan through the system's network interfaces.
      */
-#ifdef SIOCGIFNUM
     if (ioctl(ipfd, SIOCGIFNUM, &nif) < 0)
-#endif
        nif = MAX_IFS;
     ifc.ifc_len = nif * sizeof(struct ifreq);
     ifc.ifc_buf = (caddr_t) malloc(ifc.ifc_len);
@@ -2236,12 +1938,10 @@ get_hw_addr_dlpi(char *name, struct sockaddr *hwaddr)
     adrlen = reply.prim.info_ack.dl_addr_length;
     adrp = (unsigned char *)&reply + reply.prim.info_ack.dl_addr_offset;
 
-#if DL_CURRENT_VERSION >= 2
     if (reply.prim.info_ack.dl_sap_length < 0)
        adrlen += reply.prim.info_ack.dl_sap_length;
     else
        adrp += reply.prim.info_ack.dl_sap_length;
-#endif
 
     hwaddr->sa_family = AF_UNSPEC;
     memcpy(hwaddr->sa_data, adrp, adrlen);
@@ -2313,7 +2013,7 @@ dlpi_get_reply(int fd, union DL_primitives *reply, int expected_prim, size_t max
     pfd.events = POLLIN | POLLPRI;
     do {
        n = poll(&pfd, 1, 1000);
-    } while (n == -1 && errno == EINTR && !got_sigterm);
+    } while (n == -1 && errno == EINTR && !ppp_signaled(SIGTERM));
     if (n <= 0)
        return -1;
 
@@ -2481,85 +2181,6 @@ strioctl(int fd, int cmd, void *ptr, int ilen, int olen)
     return 0;
 }
 
-#if 0
-/*
- * lock - create a lock file for the named lock device
- */
-
-#define LOCK_PREFIX    "/var/spool/locks/LK."
-static char lock_file[40];     /* name of lock file created */
-
-int
-lock(char *dev)
-{
-    int n, fd, pid;
-    struct stat sbuf;
-    char ascii_pid[12];
-
-    if (stat(dev, &sbuf) < 0) {
-       error("Can't get device number for %s: %m", dev);
-       return -1;
-    }
-    if ((sbuf.st_mode & S_IFMT) != S_IFCHR) {
-       error("Can't lock %s: not a character device", dev);
-       return -1;
-    }
-    slprintf(lock_file, sizeof(lock_file), "%s%03d.%03d.%03d",
-            LOCK_PREFIX, major(sbuf.st_dev),
-            major(sbuf.st_rdev), minor(sbuf.st_rdev));
-
-    while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
-       if (errno == EEXIST
-           && (fd = open(lock_file, O_RDONLY, 0)) >= 0) {
-           /* Read the lock file to find out who has the device locked */
-           n = read(fd, ascii_pid, 11);
-           if (n <= 0) {
-               error("Can't read pid from lock file %s", lock_file);
-               close(fd);
-           } else {
-               ascii_pid[n] = 0;
-               pid = atoi(ascii_pid);
-               if (pid > 0 && kill(pid, 0) == -1 && errno == ESRCH) {
-                   /* pid no longer exists - remove the lock file */
-                   if (unlink(lock_file) == 0) {
-                       close(fd);
-                       notice("Removed stale lock on %s (pid %d)",
-                              dev, pid);
-                       continue;
-                   } else
-                       warn("Couldn't remove stale lock on %s",
-                              dev);
-               } else
-                   notice("Device %s is locked by pid %d",
-                          dev, pid);
-           }
-           close(fd);
-       } else
-           error("Can't create lock file %s: %m", lock_file);
-       lock_file[0] = 0;
-       return -1;
-    }
-
-    slprintf(ascii_pid, sizeof(ascii_pid), "%10d\n", getpid());
-    write(fd, ascii_pid, 11);
-
-    close(fd);
-    return 1;
-}
-
-/*
- * unlock - remove our lockfile
- */
-void
-unlock(void)
-{
-    if (lock_file[0]) {
-       unlink(lock_file);
-       lock_file[0] = 0;
-    }
-}
-#endif
-
 /*
  * cifroute - delete a route through the addresses given.
  */
@@ -2597,7 +2218,6 @@ cifroute(int u, u_int32_t our, u_int32_t his)
 int
 have_route_to(u_int32_t addr)
 {
-#ifdef SOL2
     int fd, r, flags, i;
     struct {
        struct T_optmgmt_req req;
@@ -2673,7 +2293,7 @@ have_route_to(u_int32_t addr)
            nroutes = dbuf.len / sizeof(mib2_ipRouteEntry_t);
            for (rp = routes, i = 0; i < nroutes; ++i, ++rp) {
                if (rp->ipRouteMask != ~0) {
-                   dbglog("have_route_to: dest=%x gw=%x mask=%x\n",
+                   dbglog("have_route_to: dest=%I gw=%I mask=%I",
                           rp->ipRouteDest, rp->ipRouteNextHop,
                           rp->ipRouteMask);
                    if (((addr ^ rp->ipRouteDest) & rp->ipRouteMask) == 0
@@ -2688,9 +2308,6 @@ have_route_to(u_int32_t addr)
     }
     close(fd);
     return 0;
-#else
-    return -1;
-#endif /* SOL2 */
 }
 
 /*
@@ -2744,7 +2361,7 @@ get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid)
  * get_time - Get current time, monotonic if possible.
  */
 int
-get_time(struct timeval *tv)
+ppp_get_time(struct timeval *tv)
 {
     return gettimeofday(tv, NULL);
 }
index 8a563f88b9a62b8aedc2ea504f8f8b22afdddb95..a124c236a1d4dd35dcd9d8b87d60a0cb6854ce18 100644 (file)
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <signal.h>
+
+#include "pppd-private.h"
 #include "tdb.h"
 #include "spinlock.h"
+#include "pathnames.h"
 
 #define TDB_MAGIC_FOOD "TDB file\n"
 #define TDB_VERSION (0x26011967 + 6)
@@ -185,18 +188,6 @@ struct list_struct {
        */
 };
 
-/***************************************************************
- Allow a caller to set a "alarm" flag that tdb can check to abort
- a blocking lock on SIGALRM.
-***************************************************************/
-
-static sig_atomic_t *palarm_fired;
-
-void tdb_set_lock_alarm(sig_atomic_t *palarm)
-{
-       palarm_fired = palarm;
-}
-
 /* a byte range locking function - return 0 on success
    this functions locks/unlocks 1 byte at the specified offset.
 
@@ -223,26 +214,15 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset,
 
        do {
                ret = fcntl(tdb->fd,lck_type,&fl);
-               if (ret == -1 && errno == EINTR && palarm_fired && *palarm_fired)
-                       break;
        } while (ret == -1 && errno == EINTR);
 
        if (ret == -1) {
                if (!probe && lck_type != F_SETLK) {
                        /* Ensure error code is set for log fun to examine. */
-                       if (errno == EINTR && palarm_fired && *palarm_fired)
-                               tdb->ecode = TDB_ERR_LOCK_TIMEOUT;
-                       else
-                               tdb->ecode = TDB_ERR_LOCK;
+                       tdb->ecode = TDB_ERR_LOCK;
                        TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n", 
                                 tdb->fd, offset, rw_type, lck_type));
                }
-               /* Was it an alarm timeout ? */
-               if (errno == EINTR && palarm_fired && *palarm_fired) {
-                       TDB_LOG((tdb, 5, "tdb_brlock timed out (fd=%d) at offset %d rw_type=%d lck_type=%d\n", 
-                                tdb->fd, offset, rw_type, lck_type));
-                       return TDB_ERRCODE(TDB_ERR_LOCK_TIMEOUT, -1);
-               }
                /* Otherwise - generic lock error. errno set by fcntl.
                 * EAGAIN is an expected return from non-blocking
                 * locks. */
@@ -503,107 +483,6 @@ static int update_tailer(TDB_CONTEXT *tdb, tdb_off offset,
                         &totalsize);
 }
 
-static tdb_off tdb_dump_record(TDB_CONTEXT *tdb, tdb_off offset)
-{
-       struct list_struct rec;
-       tdb_off tailer_ofs, tailer;
-
-       if (tdb_read(tdb, offset, (char *)&rec, sizeof(rec), DOCONV()) == -1) {
-               printf("ERROR: failed to read record at %u\n", offset);
-               return 0;
-       }
-
-       printf(" rec: offset=%u next=%d rec_len=%d key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
-              offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, rec.full_hash, rec.magic);
-
-       tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off);
-       if (ofs_read(tdb, tailer_ofs, &tailer) == -1) {
-               printf("ERROR: failed to read tailer at %u\n", tailer_ofs);
-               return rec.next;
-       }
-
-       if (tailer != rec.rec_len + sizeof(rec)) {
-               printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n",
-                               (unsigned)tailer, (unsigned)(rec.rec_len + sizeof(rec)));
-       }
-       return rec.next;
-}
-
-static int tdb_dump_chain(TDB_CONTEXT *tdb, int i)
-{
-       tdb_off rec_ptr, top;
-
-       top = TDB_HASH_TOP(i);
-
-       if (tdb_lock(tdb, i, F_WRLCK) != 0)
-               return -1;
-
-       if (ofs_read(tdb, top, &rec_ptr) == -1)
-               return tdb_unlock(tdb, i, F_WRLCK);
-
-       if (rec_ptr)
-               printf("hash=%d\n", i);
-
-       while (rec_ptr) {
-               rec_ptr = tdb_dump_record(tdb, rec_ptr);
-       }
-
-       return tdb_unlock(tdb, i, F_WRLCK);
-}
-
-void tdb_dump_all(TDB_CONTEXT *tdb)
-{
-       int i;
-       for (i=0;i<tdb->header.hash_size;i++) {
-               tdb_dump_chain(tdb, i);
-       }
-       printf("freelist:\n");
-       tdb_dump_chain(tdb, -1);
-}
-
-int tdb_printfreelist(TDB_CONTEXT *tdb)
-{
-       int ret;
-       long total_free = 0;
-       tdb_off offset, rec_ptr;
-       struct list_struct rec;
-
-       if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0)
-               return ret;
-
-       offset = FREELIST_TOP;
-
-       /* read in the freelist top */
-       if (ofs_read(tdb, offset, &rec_ptr) == -1) {
-               tdb_unlock(tdb, -1, F_WRLCK);
-               return 0;
-       }
-
-       printf("freelist top=[0x%08x]\n", rec_ptr );
-       while (rec_ptr) {
-               if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec), DOCONV()) == -1) {
-                       tdb_unlock(tdb, -1, F_WRLCK);
-                       return -1;
-               }
-
-               if (rec.magic != TDB_FREE_MAGIC) {
-                       printf("bad magic 0x%08x in free list\n", rec.magic);
-                       tdb_unlock(tdb, -1, F_WRLCK);
-                       return -1;
-               }
-
-               printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)]\n", rec.next, rec.rec_len, rec.rec_len );
-               total_free += rec.rec_len;
-
-               /* move to the next record */
-               rec_ptr = rec.next;
-       }
-       printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, 
-               (int)total_free);
-
-       return tdb_unlock(tdb, -1, F_WRLCK);
-}
-
 /* Remove an element from the freelist.  Must have alloc lock. */
 static int remove_from_freelist(TDB_CONTEXT *tdb, tdb_off off, tdb_off next)
 {
@@ -930,7 +809,7 @@ static int tdb_new_database(TDB_CONTEXT *tdb, int hash_size)
 
        /* We make it up in memory, then write it out if not internal */
        size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off);
-       if (!(newdb = calloc(size, 1)))
+       if (!(newdb = calloc(1, size)))
                return TDB_ERRCODE(TDB_ERR_OOM, -1);
 
        /* Fill in the header */
@@ -1117,12 +996,6 @@ static int tdb_exists_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash)
        return 1;
 }
 
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
-{
-       u32 hash = tdb->hash_fn(&key);
-       return tdb_exists_hash(tdb, key, hash);
-}
-
 /* record lock stops delete underneath */
 static int lock_record(TDB_CONTEXT *tdb, tdb_off off)
 {
@@ -1201,207 +1074,6 @@ static int do_delete(TDB_CONTEXT *tdb, tdb_off rec_ptr, struct list_struct*rec)
        return 0;
 }
 
-/* Uses traverse lock: 0 = finish, -1 = error, other = record offset */
-static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
-                        struct list_struct *rec)
-{
-       int want_next = (tlock->off != 0);
-
-       /* Lock each chain from the start one. */
-       for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
-               if (tdb_lock(tdb, tlock->hash, F_WRLCK) == -1)
-                       return -1;
-
-               /* No previous record?  Start at top of chain. */
-               if (!tlock->off) {
-                       if (ofs_read(tdb, TDB_HASH_TOP(tlock->hash),
-                                    &tlock->off) == -1)
-                               goto fail;
-               } else {
-                       /* Otherwise unlock the previous record. */
-                       if (unlock_record(tdb, tlock->off) != 0)
-                               goto fail;
-               }
-
-               if (want_next) {
-                       /* We have offset of old record: grab next */
-                       if (rec_read(tdb, tlock->off, rec) == -1)
-                               goto fail;
-                       tlock->off = rec->next;
-               }
-
-               /* Iterate through chain */
-               while( tlock->off) {
-                       tdb_off current;
-                       if (rec_read(tdb, tlock->off, rec) == -1)
-                               goto fail;
-                       if (!TDB_DEAD(rec)) {
-                               /* Woohoo: we found one! */
-                               if (lock_record(tdb, tlock->off) != 0)
-                                       goto fail;
-                               return tlock->off;
-                       }
-                       /* Try to clean dead ones from old traverses */
-                       current = tlock->off;
-                       tlock->off = rec->next;
-                       if (!tdb->read_only && 
-                           do_delete(tdb, current, rec) != 0)
-                               goto fail;
-               }
-               tdb_unlock(tdb, tlock->hash, F_WRLCK);
-               want_next = 0;
-       }
-       /* We finished iteration without finding anything */
-       return TDB_ERRCODE(TDB_SUCCESS, 0);
-
- fail:
-       tlock->off = 0;
-       if (tdb_unlock(tdb, tlock->hash, F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_next_lock: On error unlock failed!\n"));
-       return -1;
-}
-
-/* traverse the entire database - calling fn(tdb, key, data) on each element.
-   return -1 on error or the record count traversed
-   if fn is NULL then it is not called
-   a non-zero return value from fn() indicates that the traversal should stop
-  */
-int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *private)
-{
-       TDB_DATA key, dbuf;
-       struct list_struct rec;
-       struct tdb_traverse_lock tl = { NULL, 0, 0 };
-       int ret, count = 0;
-
-       /* This was in the initializaton, above, but the IRIX compiler
-        * did not like it.  crh
-        */
-       tl.next = tdb->travlocks.next;
-
-       /* fcntl locks don't stack: beware traverse inside traverse */
-       tdb->travlocks.next = &tl;
-
-       /* tdb_next_lock places locks on the record returned, and its chain */
-       while ((ret = tdb_next_lock(tdb, &tl, &rec)) > 0) {
-               count++;
-               /* now read the full record */
-               key.dptr = tdb_alloc_read(tdb, tl.off + sizeof(rec), 
-                                         rec.key_len + rec.data_len);
-               if (!key.dptr) {
-                       ret = -1;
-                       if (tdb_unlock(tdb, tl.hash, F_WRLCK) != 0)
-                               goto out;
-                       if (unlock_record(tdb, tl.off) != 0)
-                               TDB_LOG((tdb, 0, "tdb_traverse: key.dptr == NULL and unlock_record failed!\n"));
-                       goto out;
-               }
-               key.dsize = rec.key_len;
-               dbuf.dptr = key.dptr + rec.key_len;
-               dbuf.dsize = rec.data_len;
-
-               /* Drop chain lock, call out */
-               if (tdb_unlock(tdb, tl.hash, F_WRLCK) != 0) {
-                       ret = -1;
-                       goto out;
-               }
-               if (fn && fn(tdb, key, dbuf, private)) {
-                       /* They want us to terminate traversal */
-                       ret = count;
-                       if (unlock_record(tdb, tl.off) != 0) {
-                               TDB_LOG((tdb, 0, "tdb_traverse: unlock_record failed!\n"));;
-                               ret = -1;
-                       }
-                       tdb->travlocks.next = tl.next;
-                       SAFE_FREE(key.dptr);
-                       return count;
-               }
-               SAFE_FREE(key.dptr);
-       }
-out:
-       tdb->travlocks.next = tl.next;
-       if (ret < 0)
-               return -1;
-       else
-               return count;
-}
-
-/* find the first entry in the database and return its key */
-TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb)
-{
-       TDB_DATA key;
-       struct list_struct rec;
-
-       /* release any old lock */
-       if (unlock_record(tdb, tdb->travlocks.off) != 0)
-               return tdb_null;
-       tdb->travlocks.off = tdb->travlocks.hash = 0;
-
-       if (tdb_next_lock(tdb, &tdb->travlocks, &rec) <= 0)
-               return tdb_null;
-       /* now read the key */
-       key.dsize = rec.key_len;
-       key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize);
-       if (tdb_unlock(tdb, BUCKET(tdb->travlocks.hash), F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_firstkey: error occurred while tdb_unlocking!\n"));
-       return key;
-}
-
-/* find the next entry in the database, returning its key */
-TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA oldkey)
-{
-       u32 oldhash;
-       TDB_DATA key = tdb_null;
-       struct list_struct rec;
-       char *k = NULL;
-
-       /* Is locked key the old key?  If so, traverse will be reliable. */
-       if (tdb->travlocks.off) {
-               if (tdb_lock(tdb,tdb->travlocks.hash,F_WRLCK))
-                       return tdb_null;
-               if (rec_read(tdb, tdb->travlocks.off, &rec) == -1
-                   || !(k = tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),
-                                           rec.key_len))
-                   || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) {
-                       /* No, it wasn't: unlock it and start from scratch */
-                       if (unlock_record(tdb, tdb->travlocks.off) != 0)
-                               return tdb_null;
-                       if (tdb_unlock(tdb, tdb->travlocks.hash, F_WRLCK) != 0)
-                               return tdb_null;
-                       tdb->travlocks.off = 0;
-               }
-
-               SAFE_FREE(k);
-       }
-
-       if (!tdb->travlocks.off) {
-               /* No previous element: do normal find, and lock record */
-               tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb->hash_fn(&oldkey), F_WRLCK, &rec);
-               if (!tdb->travlocks.off)
-                       return tdb_null;
-               tdb->travlocks.hash = BUCKET(rec.full_hash);
-               if (lock_record(tdb, tdb->travlocks.off) != 0) {
-                       TDB_LOG((tdb, 0, "tdb_nextkey: lock_record failed (%s)!\n", strerror(errno)));
-                       return tdb_null;
-               }
-       }
-       oldhash = tdb->travlocks.hash;
-
-       /* Grab next record: locks chain and returned record,
-          unlocks old record */
-       if (tdb_next_lock(tdb, &tdb->travlocks, &rec) > 0) {
-               key.dsize = rec.key_len;
-               key.dptr = tdb_alloc_read(tdb, tdb->travlocks.off+sizeof(rec),
-                                         key.dsize);
-               /* Unlock the chain of this new record */
-               if (tdb_unlock(tdb, tdb->travlocks.hash, F_WRLCK) != 0)
-                       TDB_LOG((tdb, 0, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
-       }
-       /* Unlock the chain of old record */
-       if (tdb_unlock(tdb, BUCKET(oldhash), F_WRLCK) != 0)
-               TDB_LOG((tdb, 0, "tdb_nextkey: WARNING tdb_unlock failed!\n"));
-       return key;
-}
-
 /* delete an entry in the database given a key */
 static int tdb_delete_hash(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash)
 {
@@ -1508,131 +1180,6 @@ fail:
        goto out;
 }
 
-/* Attempt to append data to an entry in place - this only works if the new data size
-   is <= the old data size and the key exists.
-   on failure return -1. Record must be locked before calling.
-*/
-static int tdb_append_inplace(TDB_CONTEXT *tdb, TDB_DATA key, u32 hash, TDB_DATA new_dbuf)
-{
-       struct list_struct rec;
-       tdb_off rec_ptr;
-
-       /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec)))
-               return -1;
-
-       /* Append of 0 is always ok. */
-       if (new_dbuf.dsize == 0)
-               return 0;
-
-       /* must be long enough for key, old data + new data and tailer */
-       if (rec.rec_len < key.dsize + rec.data_len + new_dbuf.dsize + sizeof(tdb_off)) {
-               /* No room. */
-               tdb->ecode = TDB_SUCCESS; /* Not really an error */
-               return -1;
-       }
-
-       if (tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len + rec.data_len,
-                     new_dbuf.dptr, new_dbuf.dsize) == -1)
-               return -1;
-
-       /* update size */
-       rec.data_len += new_dbuf.dsize;
-       return rec_write(tdb, rec_ptr, &rec);
-}
-
-/* Append to an entry. Create if not exist. */
-
-int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf)
-{
-       struct list_struct rec;
-       u32 hash;
-       tdb_off rec_ptr;
-       char *p = NULL;
-       int ret = 0;
-       size_t new_data_size = 0;
-
-       /* find which hash bucket it is in */
-       hash = tdb->hash_fn(&key);
-       if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1)
-               return -1;
-
-       /* first try in-place. */
-       if (tdb_append_inplace(tdb, key, hash, new_dbuf) == 0)
-               goto out;
-
-       /* reset the error code potentially set by the tdb_append_inplace() */
-       tdb->ecode = TDB_SUCCESS;
-
-       /* find entry */
-       if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) {
-               if (tdb->ecode != TDB_ERR_NOEXIST)
-                       goto fail;
-
-               /* Not found - create. */
-
-               ret = tdb_store(tdb, key, new_dbuf, TDB_INSERT);
-               goto out;
-       }
-
-       new_data_size = rec.data_len + new_dbuf.dsize;
-
-       /* Copy key+old_value+value *before* allocating free space in case malloc
-          fails and we are left with a dead spot in the tdb. */
-
-       if (!(p = (char *)malloc(key.dsize + new_data_size))) {
-               tdb->ecode = TDB_ERR_OOM;
-               goto fail;
-       }
-
-       /* Copy the key in place. */
-       memcpy(p, key.dptr, key.dsize);
-
-       /* Now read the old data into place. */
-       if (rec.data_len &&
-               tdb_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, p + key.dsize, rec.data_len, 0) == -1)
-                       goto fail;
-
-       /* Finally append the new data. */
-       if (new_dbuf.dsize)
-               memcpy(p+key.dsize+rec.data_len, new_dbuf.dptr, new_dbuf.dsize);
-
-       /* delete any existing record - if it doesn't exist we don't
-           care.  Doing this first reduces fragmentation, and avoids
-           coalescing with `allocated' block before it's updated. */
-
-       tdb_delete_hash(tdb, key, hash);
-
-       if (!(rec_ptr = tdb_allocate(tdb, key.dsize + new_data_size, &rec)))
-               goto fail;
-
-       /* Read hash top into next ptr */
-       if (ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1)
-               goto fail;
-
-       rec.key_len = key.dsize;
-       rec.data_len = new_data_size;
-       rec.full_hash = hash;
-       rec.magic = TDB_MAGIC;
-
-       /* write out and point the top of the hash chain at it */
-       if (rec_write(tdb, rec_ptr, &rec) == -1
-           || tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+new_data_size)==-1
-           || ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) {
-               /* Need to tdb_unallocate() here */
-               goto fail;
-       }
-
- out:
-       SAFE_FREE(p); 
-       tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
-       return ret;
-
-fail:
-       ret = -1;
-       goto out;
-}
-
 static int tdb_already_open(dev_t device,
                            ino_t ino)
 {
@@ -1728,7 +1275,12 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
                goto internal;
        }
 
+again:
        if ((tdb->fd = open(name, open_flags, mode)) == -1) {
+               if ((open_flags & O_CREAT) && errno == ENOENT &&
+                       mkdir_recursive(PPP_PATH_VARRUN) == 0)
+                       goto again;
+
                TDB_LOG((tdb, 5, "tdb_open_ex: could not open file %s: %s\n",
                         name, strerror(errno)));
                goto fail;      /* errno set by open(2) */
@@ -1898,36 +1450,6 @@ int tdb_close(TDB_CONTEXT *tdb)
        return ret;
 }
 
-/* lock/unlock entire database */
-int tdb_lockall(TDB_CONTEXT *tdb)
-{
-       u32 i;
-
-       /* There are no locks on read-only dbs */
-       if (tdb->read_only)
-               return TDB_ERRCODE(TDB_ERR_LOCK, -1);
-       for (i = 0; i < tdb->header.hash_size; i++) 
-               if (tdb_lock(tdb, i, F_WRLCK))
-                       break;
-
-       /* If error, release locks we have... */
-       if (i < tdb->header.hash_size) {
-               u32 j;
-
-               for ( j = 0; j < i; j++)
-                       tdb_unlock(tdb, j, F_WRLCK);
-               return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
-       }
-
-       return 0;
-}
-void tdb_unlockall(TDB_CONTEXT *tdb)
-{
-       u32 i;
-       for (i=0; i < tdb->header.hash_size; i++)
-               tdb_unlock(tdb, i, F_WRLCK);
-}
-
 /* lock/unlock one hash chain. This is meant to be used to reduce
    contention - it cannot guarantee how many records will be locked */
 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key)
@@ -1939,75 +1461,3 @@ int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key)
 {
        return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
 }
-
-int tdb_chainlock_read(TDB_CONTEXT *tdb, TDB_DATA key)
-{
-       return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK);
-}
-
-int tdb_chainunlock_read(TDB_CONTEXT *tdb, TDB_DATA key)
-{
-       return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK);
-}
-
-
-/* register a loging function */
-void tdb_logging_function(TDB_CONTEXT *tdb, void (*fn)(TDB_CONTEXT *, int , const char *, ...))
-{
-       tdb->log_fn = fn;
-}
-
-/* reopen a tdb - this can be used after a fork to ensure that we have an independent
-   seek pointer from our parent and to re-establish locks */
-int tdb_reopen(TDB_CONTEXT *tdb)
-{
-       struct stat st;
-
-       if (tdb->flags & TDB_INTERNAL)
-               return 0; /* Nothing to do. */
-       if (tdb_munmap(tdb) != 0) {
-               TDB_LOG((tdb, 0, "tdb_reopen: munmap failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (close(tdb->fd) != 0)
-               TDB_LOG((tdb, 0, "tdb_reopen: WARNING closing tdb->fd failed!\n"));
-       tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0);
-       if (tdb->fd == -1) {
-               TDB_LOG((tdb, 0, "tdb_reopen: open failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (fstat(tdb->fd, &st) != 0) {
-               TDB_LOG((tdb, 0, "tdb_reopen: fstat failed (%s)\n", strerror(errno)));
-               goto fail;
-       }
-       if (st.st_ino != tdb->inode || st.st_dev != tdb->device) {
-               TDB_LOG((tdb, 0, "tdb_reopen: file dev/inode has changed!\n"));
-               goto fail;
-       }
-       tdb_mmap(tdb);
-       if ((tdb->flags & TDB_CLEAR_IF_FIRST) && (tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0) == -1)) {
-               TDB_LOG((tdb, 0, "tdb_reopen: failed to obtain active lock\n"));
-               goto fail;
-       }
-
-       return 0;
-
-fail:
-       tdb_close(tdb);
-       return -1;
-}
-
-/* reopen all tdb's */
-int tdb_reopen_all(void)
-{
-       TDB_CONTEXT *tdb;
-
-       for (tdb=tdbs; tdb; tdb = tdb->next) {
-               /* Ensure no clear-if-first. */
-               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
-               if (tdb_reopen(tdb) != 0)
-                       return -1;
-       }
-
-       return 0;
-}
index 1d7d7656238b8d2a8863d186b4ca725097c8ce8f..734ff85bf4853839601bebe54f64e337b1d2a7cd 100644 (file)
@@ -129,34 +129,19 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
                         tdb_log_func log_fn,
                         tdb_hash_func hash_fn);
 
-int tdb_reopen(TDB_CONTEXT *tdb);
-int tdb_reopen_all(void);
-void tdb_logging_function(TDB_CONTEXT *tdb, tdb_log_func);
 enum TDB_ERROR tdb_error(TDB_CONTEXT *tdb);
 const char *tdb_errorstr(TDB_CONTEXT *tdb);
 TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
-int tdb_append(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA new_dbuf);
 int tdb_close(TDB_CONTEXT *tdb);
-TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
-TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
-int tdb_traverse(TDB_CONTEXT *tdb, tdb_traverse_func fn, void *);
-int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_lockkeys(TDB_CONTEXT *tdb, u32 number, TDB_DATA keys[]);
 void tdb_unlockkeys(TDB_CONTEXT *tdb);
-int tdb_lockall(TDB_CONTEXT *tdb);
-void tdb_unlockall(TDB_CONTEXT *tdb);
 
 /* Low level locking functions: use with care */
-void tdb_set_lock_alarm(sig_atomic_t *palarm);
 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
 
-/* Debug functions. Not used in production. */
-void tdb_dump_all(TDB_CONTEXT *tdb);
-int tdb_printfreelist(TDB_CONTEXT *tdb);
-
 extern TDB_DATA tdb_null;
 
 #ifdef  __cplusplus
index 28c2e5793158163a4d7b1e3fc39b79c7cc843011..d57e434e734a7e9a0fd0fed38fc6cbe5ebf40d30 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <string.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 #include <openssl/x509v3.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "tls.h"
 
 /**
@@ -231,7 +235,7 @@ int tls_set_verify_info(SSL *ssl, const char *peer_name, const char *peer_cert,
         bool client, struct tls_info **out)
 {
     if (out != NULL) {
-        struct tls_info *tmp = calloc(sizeof(struct tls_info), 1);
+        struct tls_info *tmp = calloc(1, sizeof(struct tls_info));
         if (!tmp) {
             fatal("Allocation error");
         }
index ad743539ec806c8fcfa2b7cfc9ea95195c063bf8..2531ce1e39dbd129c5584bf454bc8037e6bac967 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * tty.c - code for handling serial ports in pppd.
  *
- * Copyright (C) 2000-2004 Paul Mackerras. All rights reserved.
+ * Copyright (C) 2000-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -95,7 +91,8 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "fsm.h"
 #include "lcp.h"
 
@@ -111,7 +108,7 @@ static int setdevname(char *, char **, int);
 static int setspeed(char *, char **, int);
 static int setxonxoff(char **);
 static int setescape(char **);
-static void printescape(option_t *, void (*)(void *, char *,...),void *);
+static void printescape(struct option *, void (*)(void *, char *,...),void *);
 static void finish_tty(void);
 static int start_charshunt(int, int);
 static void stop_charshunt(void *, int);
@@ -136,6 +133,8 @@ int locked;                 /* lock() has succeeded */
 struct stat devstat;           /* result of stat() on devnam */
 
 /* option variables */
+char   devnam[MAXPATHLEN];     /* Device name */
+char   ppp_devname[MAXPATHLEN];/* name of PPP tty (maybe ttypx) */
 int    crtscts = 0;            /* Use hardware flow control */
 int    stop_bits = 1;          /* Number of serial port stop bits */
 bool   modem = 1;              /* Use modem control lines */
@@ -164,7 +163,7 @@ extern int privopen;                /* don't lock, open device as root */
 u_int32_t xmit_accm[8];                /* extended transmit ACCM */
 
 /* option descriptors */
-option_t tty_options[] = {
+static struct option tty_options[] = {
     /* device name must be first, or change connect_tty() below! */
     { "device name", o_wild, (void *) &setdevname,
       "Serial port device name",
@@ -261,6 +260,61 @@ struct channel tty_channel = {
        &tty_close_fds
 };
 
+bool
+ppp_sync_serial()
+{
+    return sync_serial;
+}
+
+bool
+ppp_get_modem()
+{
+    return modem;
+}
+
+void
+ppp_set_modem(bool on)
+{
+    modem = on;
+}
+
+bool
+ppp_using_pty()
+{
+    return using_pty;
+}
+
+int
+ppp_set_pppdevnam(const char *name)
+{
+    if (name) {
+        return strlcpy(ppp_devname, name, sizeof(ppp_devname));
+    }
+    return -1;
+}
+
+const char *
+ppp_pppdevnam()
+{
+    return ppp_devname;
+}
+
+const char *
+ppp_devnam()
+{
+    return devnam;
+}
+
+int
+ppp_set_devnam(const char *name)
+{
+    if (name) {
+        return strlcpy(devnam, name, sizeof(devnam));
+    }
+    return -1;
+}
+
+
 /*
  * setspeed - Set the serial port baud rate.
  * If doit is 0, the call is to check whether this option is
@@ -309,12 +363,12 @@ setdevname(char *cp, char **argv, int doit)
        if (stat(cp, &statbuf) < 0) {
                if (!doit)
                        return errno != ENOENT;
-               option_error("Couldn't stat %s: %m", cp);
+               ppp_option_error("Couldn't stat %s: %m", cp);
                return 0;
        }
        if (!S_ISCHR(statbuf.st_mode)) {
                if (doit)
-                       option_error("%s is not a character device", cp);
+                       ppp_option_error("%s is not a character device", cp);
                return 0;
        }
 
@@ -351,16 +405,16 @@ setescape(char **argv)
     while (*p) {
        n = strtol(p, &endp, 16);
        if (p == endp) {
-           option_error("escape parameter contains invalid hex number '%s'",
+           ppp_option_error("escape parameter contains invalid hex number '%s'",
                         p);
            return 0;
        }
        p = endp;
        if (n < 0 || n == 0x5E || n > 0xFF) {
-           option_error("can't escape character 0x%x", n);
+           ppp_option_error("can't escape character 0x%x", n);
            ret = 0;
        } else
-           xmit_accm[n >> 5] |= 1 << (n & 0x1F);
+           xmit_accm[n >> 5] |= 1U << (n & 0x1F);
        while (*p == ',' || *p == ' ')
            ++p;
     }
@@ -369,7 +423,7 @@ setescape(char **argv)
 }
 
 static void
-printescape(option_t *opt, void (*printer)(void *, char *, ...), void *arg)
+printescape(struct option *opt, void (*printer)(void *, char *, ...), void *arg)
 {
        int n;
        int first = 1;
@@ -377,7 +431,7 @@ printescape(option_t *opt, void (*printer)(void *, char *, ...), void *arg)
        for (n = 0; n < 256; ++n) {
                if (n == 0x7d)
                        n += 2;         /* skip 7d, 7e */
-               if (xmit_accm[n >> 5] & (1 << (n & 0x1f))) {
+               if (xmit_accm[n >> 5] & (1U << (n & 0x1f))) {
                        if (!first)
                                printer(arg, ",");
                        else
@@ -394,9 +448,9 @@ printescape(option_t *opt, void (*printer)(void *, char *, ...), void *arg)
  */
 void tty_init(void)
 {
-    add_notifier(&pidchange, maybe_relock, 0);
+    ppp_add_notify(NF_PID_CHANGE, maybe_relock, 0);
     the_channel = &tty_channel;
-    xmit_accm[3] = 0x60000000;
+    xmit_accm[3] = 0x60000000U;
 }
 
 /*
@@ -411,7 +465,7 @@ void tty_process_extra_options(void)
        if (default_device) {
                char *p;
                if (!isatty(0) || (p = ttyname(0)) == NULL) {
-                       option_error("no device specified and stdin is not a tty");
+                       ppp_option_error("no device specified and stdin is not a tty");
                        exit(EXIT_OPTION_ERROR);
                }
                strlcpy(devnam, p, MAXPATHLEN);
@@ -441,12 +495,12 @@ tty_check_options(void)
        int fdflags;
 
        if (demand && notty) {
-               option_error("demand-dialling is incompatible with notty");
+               ppp_option_error("demand-dialling is incompatible with notty");
                exit(EXIT_OPTION_ERROR);
        }
        if (demand && connect_script == 0 && ptycommand == NULL
            && pty_socket == NULL) {
-               option_error("connect script is required for demand-dialling\n");
+               ppp_option_error("connect script is required for demand-dialling\n");
                exit(EXIT_OPTION_ERROR);
        }
        /* default holdoff to 0 if no connect script has been given */
@@ -455,16 +509,16 @@ tty_check_options(void)
 
        if (using_pty) {
                if (!default_device) {
-                       option_error("%s option precludes specifying device name",
+                       ppp_option_error("%s option precludes specifying device name",
                                     pty_socket? "socket": notty? "notty": "pty");
                        exit(EXIT_OPTION_ERROR);
                }
                if (ptycommand != NULL && notty) {
-                       option_error("pty option is incompatible with notty option");
+                       ppp_option_error("pty option is incompatible with notty option");
                        exit(EXIT_OPTION_ERROR);
                }
                if (pty_socket != NULL && (ptycommand != NULL || notty)) {
-                       option_error("socket option is incompatible with pty and notty");
+                       ppp_option_error("socket option is incompatible with pty and notty");
                        exit(EXIT_OPTION_ERROR);
                }
                default_device = notty;
@@ -518,14 +572,14 @@ int connect_tty(void)
         * Get a pty master/slave pair if the pty, notty, socket,
         * or record options were specified.
         */
-       strlcpy(ppp_devnam, devnam, MAXPATHLEN);
+       strlcpy(ppp_devname, devnam, MAXPATHLEN);
        pty_master = -1;
        pty_slave = -1;
        real_ttyfd = -1;
        if (using_pty || record_file != NULL) {
-               if (!get_pty(&pty_master, &pty_slave, ppp_devnam, uid)) {
+               if (!get_pty(&pty_master, &pty_slave, ppp_devname, uid)) {
                        error("Couldn't allocate pseudo-tty");
-                       status = EXIT_FATAL_ERROR;
+                       ppp_set_status(EXIT_FATAL_ERROR);
                        return -1;
                }
                set_up_tty(pty_slave, 1);
@@ -534,7 +588,7 @@ int connect_tty(void)
        /*
         * Lock the device if we've been asked to.
         */
-       status = EXIT_LOCK_FAILED;
+       ppp_set_status(EXIT_LOCK_FAILED);
        if (lockflag && !privopen) {
                if (lock(devnam) < 0)
                        goto errret;
@@ -560,7 +614,7 @@ int connect_tty(void)
                        if (prio < OPRIO_ROOT && seteuid(uid) == -1) {
                                error("Unable to drop privileges before opening %s: %m\n",
                                      devnam);
-                               status = EXIT_OPEN_FAILED;
+                               ppp_set_status(EXIT_OPEN_FAILED);
                                goto errret;
                        }
                        real_ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
@@ -572,7 +626,7 @@ int connect_tty(void)
                        errno = err;
                        if (err != EINTR) {
                                error("Failed to open %s: %m", devnam);
-                               status = EXIT_OPEN_FAILED;
+                               ppp_set_status(EXIT_OPEN_FAILED);
                        }
                        if (!persist || err != EINTR)
                                goto errret;
@@ -615,7 +669,7 @@ int connect_tty(void)
         * If the pty, socket, notty and/or record option was specified,
         * start up the character shunt now.
         */
-       status = EXIT_PTYCMD_FAILED;
+       ppp_set_status(EXIT_PTYCMD_FAILED);
        if (ptycommand != NULL) {
                if (record_file != NULL) {
                        int ipipe[2], opipe[2], ok;
@@ -681,7 +735,7 @@ int connect_tty(void)
                if (initializer && initializer[0]) {
                        if (device_script(initializer, ttyfd, ttyfd, 0) < 0) {
                                error("Initializer script failed");
-                               status = EXIT_INIT_FAILED;
+                               ppp_set_status(EXIT_INIT_FAILED);
                                goto errretf;
                        }
                        if (got_sigterm) {
@@ -694,7 +748,7 @@ int connect_tty(void)
                if (connector && connector[0]) {
                        if (device_script(connector, ttyfd, ttyfd, 0) < 0) {
                                error("Connect script failed");
-                               status = EXIT_CONNECT_FAILED;
+                               ppp_set_status(EXIT_CONNECT_FAILED);
                                goto errretf;
                        }
                        if (got_sigterm) {
@@ -721,7 +775,7 @@ int connect_tty(void)
                                break;
                        if (errno != EINTR) {
                                error("Failed to reopen %s: %m", devnam);
-                               status = EXIT_OPEN_FAILED;
+                               ppp_set_status(EXIT_OPEN_FAILED);
                        }
                        if (!persist || errno != EINTR || hungup || got_sigterm)
                                goto errret;
@@ -730,7 +784,7 @@ int connect_tty(void)
        }
 
        slprintf(numbuf, sizeof(numbuf), "%d", baud_rate);
-       script_setenv("SPEED", numbuf, 0);
+       ppp_script_setenv("SPEED", numbuf, 0);
 
        /* run welcome script, if any */
        if (welcomer && welcomer[0]) {
@@ -911,7 +965,7 @@ start_charshunt(int ifd, int ofd)
 {
     int cpid, ret;
 
-    cpid = safe_fork(ifd, ofd, (log_to_fd >= 0? log_to_fd: 2));
+    cpid = ppp_safe_fork(ifd, ofd, (log_to_fd >= 0? log_to_fd: 2));
     if (cpid == -1) {
        error("Can't fork process for character shunt: %m");
        return 0;
@@ -1054,7 +1108,7 @@ charshunt(int ifd, int ofd, char *record_file)
     pty_readable = stdin_readable = 1;
 
     ilevel = olevel = 0;
-    get_time(&levelt);
+    ppp_get_time(&levelt);
     if (max_data_rate) {
        max_level = max_data_rate / 10;
        if (max_level < 100)
@@ -1103,7 +1157,7 @@ charshunt(int ifd, int ofd, char *record_file)
            int nbt;
            struct timeval now;
 
-           get_time(&now);
+           ppp_get_time(&now);
            dt = (now.tv_sec - levelt.tv_sec
                  + (now.tv_usec - levelt.tv_usec) / 1e6);
            nbt = (int)(dt * max_data_rate);
index 1fcff0904b1d9961814db0a8341b4940e8001201..822fb0a1b7abbbadc9ddc2bb1361fef3742f600d 100644 (file)
@@ -51,7 +51,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "pppd.h"
+#include "pppd-private.h"
+#include "options.h"
 #include "upap.h"
 
 
@@ -60,7 +61,7 @@ static bool hide_password = 1;
 /*
  * Command-line options.
  */
-static option_t pap_option_list[] = {
+static struct option pap_option_list[] = {
     { "hide-password", o_bool, &hide_password,
       "Don't output passwords to log", OPT_PRIO | 1 },
     { "show-password", o_bool, &hide_password,
index af09cd914176225a76a1fd6ef28ff760660e84a0..c86e520195262af8bedb6b782fa87c4f9d891052 100644 (file)
@@ -1,5 +1,3 @@
-#include "pppdconf.h"
-
 /*
  * upap.h - User/Password Authentication Protocol definitions.
  *
 
 #include "pppdconf.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 /*
  * Packet header = Code, id, length.
  */
@@ -71,7 +74,7 @@ typedef struct upap_state {
     int us_passwdlen;          /* Password length */
     int us_clientstate;                /* Client state */
     int us_serverstate;                /* Server state */
-    u_char us_id;              /* Current id */
+    unsigned char us_id;               /* Current id */
     int us_timeouttime;                /* Timeout (seconds) for auth-req retrans. */
     int us_transmits;          /* Number of auth-reqs sent */
     int us_maxtransmits;       /* Maximum number of auth-reqs to send */
@@ -113,4 +116,41 @@ void upap_authpeer(int);
 
 extern struct protent pap_protent;
 
+typedef int  (pap_check_hook_fn)(void);
+typedef int  (pap_auth_hook_fn)(char *user, char *passwd, char **msgp,
+                struct wordlist **paddrs,
+                struct wordlist **popts);
+typedef void (pap_logout_hook_fn)(void);
+typedef int  (pap_passwd_hook_fn)(char *user, char *passwd);
+
+/*
+ * This function will return a value of 1 to indicate that a plugin intent to
+ *   supply a username or a password through the pap_auth_hook callback.
+ *
+ * A return value of > 0 will avoid parsing pap-secrets file.
+ */
+extern pap_check_hook_fn  *pap_check_hook;
+
+/*
+ * This hook is used to check if a username and password matches against the
+ *   PAP secrets.
+ */
+extern pap_auth_hook_fn   *pap_auth_hook;
+
+/*
+ * Hook for plugin to know about PAP user logout.
+ */
+extern pap_logout_hook_fn *pap_logout_hook;
+
+/*
+ * A plugin can chose to supply its own user and password overriding what
+ * previously has been configured. Hook is only valid when pppd is acting
+ * as a client
+ */
+extern pap_passwd_hook_fn *pap_passwd_hook;
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif // PPP_UPAP_H
index e75bb9c8eecd21279a999c18f8c0bc4f132ef1e3..c995e3c8117973357747729fe19aecf2aadb437f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * utils.c - various utility functions used in pppd.
  *
- * Copyright (c) 1999-2002 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
- * 2. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 3. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
  *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 #include <sys/mkdev.h>
 #endif
 
-#include "pppd.h"
+#include "pppd-private.h"
 #include "fsm.h"
 #include "lcp.h"
+#include "pathnames.h"
 
 
 #if defined(SUNOS4)
 extern char *strerror();
 #endif
 
-static void logit(int, char *, va_list);
+static void logit(int, const char *, va_list);
 static void log_write(int, char *);
 static void vslp_printer(void *, char *, ...);
 static void format_packet(u_char *, int, printer_func, void *);
@@ -119,7 +116,7 @@ strlcat(char *dest, const char *src, size_t len)
  * Returns the number of chars put into buf.
  */
 int
-slprintf(char *buf, int buflen, char *fmt, ...)
+slprintf(char *buf, int buflen, const char *fmt, ...)
 {
     va_list args;
     int n;
@@ -136,14 +133,15 @@ slprintf(char *buf, int buflen, char *fmt, ...)
 #define OUTCHAR(c)     (buflen > 0? (--buflen, *buf++ = (c)): 0)
 
 int
-vslprintf(char *buf, int buflen, char *fmt, va_list args)
+vslprintf(char *buf, int buflen, const char *fmt, va_list args)
 {
     int c, i, n;
     int width, prec, fillch;
     int base, len, neg, quoted;
-    long lval = 0;
-    unsigned long val = 0;
-    char *str, *f, *buf0;
+    long long lval = 0;
+    unsigned long long val = 0;
+    char *str, *buf0;
+    const char *f;
     unsigned char *p;
     char num[32];
     time_t t;
@@ -206,6 +204,30 @@ vslprintf(char *buf, int buflen, char *fmt, va_list args)
        case 'l':
            c = *fmt++;
            switch (c) {
+           case 'l':
+               c = *fmt++;
+               switch (c) {
+               case 'd':
+                   lval = va_arg(args, long long);
+                   if (lval < 0) {
+                       neg = 1;
+                       val = -lval;
+                   } else
+                       val = lval;
+                   base = 10;
+                   break;
+               case 'u':
+                   val = va_arg(args, unsigned long long);
+                   base = 10;
+                   break;
+               default:
+                   OUTCHAR('%');
+                   OUTCHAR('l');
+                   OUTCHAR('l');
+                   --fmt;              /* so %llz outputs %llz etc. */
+                   continue;
+               }
+               break;
            case 'd':
                lval = va_arg(args, long);
                if (lval < 0) {
@@ -599,7 +621,7 @@ print_string(char *p, int len, printer_func printer, void *arg)
  * logit - does the hard work for fatal et al.
  */
 static void
-logit(int level, char *fmt, va_list args)
+logit(int level, const char *fmt, va_list args)
 {
     char buf[1024];
 
@@ -634,7 +656,7 @@ log_write(int level, char *buf)
  * fatal - log an error message and die horribly.
  */
 void
-fatal(char *fmt, ...)
+fatal(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -654,7 +676,7 @@ fatal(char *fmt, ...)
  * error - log an error message.
  */
 void
-error(char *fmt, ...)
+error(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -669,7 +691,7 @@ error(char *fmt, ...)
  * warn - log a warning message.
  */
 void
-warn(char *fmt, ...)
+warn(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -683,7 +705,7 @@ warn(char *fmt, ...)
  * notice - log a notice-level message.
  */
 void
-notice(char *fmt, ...)
+notice(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -697,7 +719,7 @@ notice(char *fmt, ...)
  * info - log an informational message.
  */
 void
-info(char *fmt, ...)
+info(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -711,7 +733,7 @@ info(char *fmt, ...)
  * dbglog - log a debug message.
  */
 void
-dbglog(char *fmt, ...)
+dbglog(const char *fmt, ...)
 {
     va_list pvar;
 
@@ -767,7 +789,7 @@ complete_read(int fd, void *buf, size_t count)
        for (done = 0; done < count; ) {
                nb = read(fd, ptr, count - done);
                if (nb < 0) {
-                       if (errno == EINTR && !got_sigterm)
+                       if (errno == EINTR && !ppp_signaled(SIGTERM))
                                continue;
                        return -1;
                }
@@ -780,19 +802,89 @@ complete_read(int fd, void *buf, size_t count)
 }
 #endif
 
-/* Procedures for locking the serial device using a lock file. */
-#ifndef LOCK_DIR
-#ifdef __linux__
-#define LOCK_DIR       "/var/lock"
-#else
-#ifdef SVR4
-#define LOCK_DIR       "/var/spool/locks"
-#else
-#define LOCK_DIR       "/var/spool/lock"
-#endif
-#endif
-#endif /* LOCK_DIR */
+/*
+ * mkdir_check - helper for mkdir_recursive, creates a directory
+ * but do not error on EEXIST if and only if entry is a directory
+ * The caller must check for errno == ENOENT if appropriate.
+ */
+static int
+mkdir_check(const char *path)
+{
+    struct stat statbuf;
+
+    if (mkdir(path, 0755) >= 0)
+       return 0;
+
+    if (errno == EEXIST) {
+       if (stat(path, &statbuf) < 0)
+           /* got raced? */
+           return -1;
+
+       if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
+           return 0;
+
+       /* already exists but not a dir, treat as failure */
+       errno = EEXIST;
+       return -1;
+    }
+
+    return -1;
+}
 
+/*
+ * mkdir_parent - helper for mkdir_recursive, modifies the string in place
+ * Assumes mkdir(path) already failed, so it first creates the parent then
+ * full path again.
+ */
+static int
+mkdir_parent(char *path)
+{
+    char *slash;
+    int rc;
+
+    slash = strrchr(path, '/');
+    if (!slash)
+       return -1;
+
+    *slash = 0;
+    if (mkdir_check(path) < 0) {
+       if (errno != ENOENT) {
+           *slash = '/';
+           return -1;
+       }
+       if (mkdir_parent(path) < 0) {
+           *slash = '/';
+           return -1;
+       }
+    }
+    *slash = '/';
+
+    return mkdir_check(path);
+}
+
+/*
+ * mkdir_recursive - recursively create directory if it didn't exist
+ */
+int
+mkdir_recursive(const char *path)
+{
+    char *copy;
+    int rc;
+
+    // optimistically try on full path first to avoid allocation
+    if (mkdir_check(path) == 0)
+       return 0;
+
+    copy = strdup(path);
+    if (!copy)
+       return -1;
+
+    rc = mkdir_parent(copy);
+    free(copy);
+    return rc;
+}
+
+/* Procedures for locking the serial device using a lock file. */
 static char lock_file[MAXPATHLEN];
 
 /*
@@ -833,7 +925,7 @@ lock(char *dev)
        return -1;
     }
     slprintf(lock_file, sizeof(lock_file), "%s/LK.%03d.%03d.%03d",
-            LOCK_DIR, major(sbuf.st_dev),
+            PPP_PATH_LOCKDIR, major(sbuf.st_dev),
             major(sbuf.st_rdev), minor(sbuf.st_rdev));
 #else
     char *p;
@@ -851,7 +943,7 @@ lock(char *dev)
        if ((p = strrchr(dev, '/')) != NULL)
            dev = p + 1;
 
-    slprintf(lock_file, sizeof(lock_file), "%s/LCK..%s", LOCK_DIR, dev);
+    slprintf(lock_file, sizeof(lock_file), "%s/LCK..%s", PPP_PATH_LOCKDIR, dev);
 #endif
 
     while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
diff --git a/pppd/utils_utest.c b/pppd/utils_utest.c
new file mode 100644 (file)
index 0000000..cdca97e
--- /dev/null
@@ -0,0 +1,139 @@
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "pppd-private.h"
+
+/* globals used in test.c... */
+int debug = 1;
+int error_count;
+int unsuccess;
+
+/* check if path exists and returns its type */
+static int
+file_type(char *path)
+{
+    struct stat statbuf;
+
+    if (stat(path, &statbuf) < 0)
+       return -1;
+
+    return statbuf.st_mode & S_IFMT;
+}
+
+int
+test_simple() {
+    if (mkdir_recursive("dir"))
+       return -1;
+
+    if (file_type("dir") != S_IFDIR)
+       return -1;
+
+    rmdir("dir");
+    return 0;
+}
+
+int
+test_recurse() {
+    if (mkdir_recursive("dir/subdir/subsubdir"))
+       return -1;
+
+    if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+       return -1;
+
+    rmdir("dir/subdir/subsubdir");
+
+    /* try again with partial existence */
+    if (mkdir_recursive("dir/subdir/subsubdir"))
+       return -1;
+
+    if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+       return -1;
+
+    rmdir("dir/subdir/subsubdir");
+    rmdir("dir/subdir");
+    rmdir("dir");
+    return 0;
+}
+
+int
+test_recurse_multislash() {
+    if (mkdir_recursive("dir/subdir///subsubdir"))
+       return -1;
+
+    if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+       return -1;
+
+    rmdir("dir/subdir/subsubdir");
+    rmdir("dir/subdir");
+
+    /* try again with partial existence */
+    if (mkdir_recursive("dir/subdir/subsubdir///"))
+       return -1;
+
+    if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+       return -1;
+
+    rmdir("dir/subdir/subsubdir");
+    rmdir("dir/subdir");
+    rmdir("dir");
+    return 0;
+}
+
+int
+test_parent_notdir() {
+    int fd = open("file", O_CREAT, 0600);
+    if (fd < 0)
+       return -1;
+    close(fd);
+
+    if (mkdir_recursive("file") == 0)
+       return -1;
+    if (mkdir_recursive("file/dir") == 0)
+       return -1;
+
+    unlink("file");
+    return 0;
+}
+
+int
+main()
+{
+    char *base_dir = strdup("/tmp/ppp_utils_utest.XXXXXX");
+    int failure = 0;
+
+    if (mkdtemp(base_dir) == NULL) {
+       printf("Could not create test directory, aborting\n");
+       return 1;
+    }
+
+    if (chdir(base_dir) < 0) {
+       printf("Could not enter newly created test dir, aborting\n");
+       return 1;
+    }
+
+    if (test_simple()) {
+       printf("Could not create simple directory\n");
+       failure++;
+    }
+
+    if (test_recurse()) {
+       printf("Could not create recursive directory\n");
+       failure++;
+    }
+
+    if (test_recurse_multislash()) {
+       printf("Could not create recursive directory with multiple slashes\n");
+       failure++;
+    }
+
+    if (test_parent_notdir()) {
+       printf("Creating over a file appeared to work?\n");
+       failure++;
+    }
+
+    rmdir(base_dir);
+    free(base_dir);
+    return failure;
+}
index 186f34e00e259d7837a365d8bdd4372d2dcab802..113d11b85cbaa095f59ed970e46098ebe5737f95 100644 (file)
@@ -1,8 +1,4 @@
 sbin_PROGRAMS = pppdump
 dist_man8_MANS = pppdump.8
 
-pppdump_SOURCES = pppdump.c bsd-comp.c deflate.c zlib.c
-
-noinst_HEADERS = \
-    ppp-comp.h \
-    zlib.h
+pppdump_SOURCES = pppdump.c
diff --git a/pppdump/bsd-comp.c b/pppdump/bsd-comp.c
deleted file mode 100644 (file)
index 57f936c..0000000
+++ /dev/null
@@ -1,733 +0,0 @@
-/* Because this code is derived from the 4.3BSD compress source:
- *
- *
- * Copyright (c) 1985, 1986 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * James A. Woods, derived from original work by Spencer Thomas
- * and Joseph Orost.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * $Id: bsd-comp.c,v 1.4 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "ppp-comp.h"
-
-#if DO_BSD_COMPRESS
-
-/*
- * PPP "BSD compress" compression
- *  The differences between this compression and the classic BSD LZW
- *  source are obvious from the requirement that the classic code worked
- *  with files while this handles arbitrarily long streams that
- *  are broken into packets.  They are:
- *
- *     When the code size expands, a block of junk is not emitted by
- *         the compressor and not expected by the decompressor.
- *
- *     New codes are not necessarily assigned every time an old
- *         code is output by the compressor.  This is because a packet
- *         end forces a code to be emitted, but does not imply that a
- *         new sequence has been seen.
- *
- *     The compression ratio is checked at the first end of a packet
- *         after the appropriate gap.  Besides simplifying and speeding
- *         things up, this makes it more likely that the transmitter
- *         and receiver will agree when the dictionary is cleared when
- *         compression is not going well.
- */
-
-/*
- * A dictionary for doing BSD compress.
- */
-struct bsd_db {
-    int            totlen;                     /* length of this structure */
-    u_int   hsize;                     /* size of the hash table */
-    u_char  hshift;                    /* used in hash function */
-    u_char  n_bits;                    /* current bits/code */
-    u_char  maxbits;
-    u_char  debug;
-    u_char  unit;
-    u_short seqno;                     /* sequence number of next packet */
-    u_int   hdrlen;                    /* header length to preallocate */
-    u_int   mru;
-    u_int   maxmaxcode;                        /* largest valid code */
-    u_int   max_ent;                   /* largest code in use */
-    u_int   in_count;                  /* uncompressed bytes, aged */
-    u_int   bytes_out;                 /* compressed bytes, aged */
-    u_int   ratio;                     /* recent compression ratio */
-    u_int   checkpoint;                        /* when to next check the ratio */
-    u_int   clear_count;               /* times dictionary cleared */
-    u_int   incomp_count;              /* incompressible packets */
-    u_int   incomp_bytes;              /* incompressible bytes */
-    u_int   uncomp_count;              /* uncompressed packets */
-    u_int   uncomp_bytes;              /* uncompressed bytes */
-    u_int   comp_count;                        /* compressed packets */
-    u_int   comp_bytes;                        /* compressed bytes */
-    u_short *lens;                     /* array of lengths of codes */
-    struct bsd_dict {
-       union {                         /* hash value */
-           u_int32_t   fcode;
-           struct {
-#ifdef BSD_LITTLE_ENDIAN
-               u_short prefix;         /* preceding code */
-               u_char  suffix;         /* last character of new code */
-               u_char  pad;
-#else
-               u_char  pad;
-               u_char  suffix;         /* last character of new code */
-               u_short prefix;         /* preceding code */
-#endif
-           } hs;
-       } f;
-       u_short codem1;                 /* output of hash table -1 */
-       u_short cptr;                   /* map code to hash table entry */
-    } dict[1];
-};
-
-#define BSD_OVHD       2               /* BSD compress overhead/packet */
-#define BSD_INIT_BITS  BSD_MIN_BITS
-
-static void    *bsd_decomp_alloc(u_char *options, int opt_len);
-static void    bsd_free(void *state);
-static int     bsd_decomp_init(void *state, u_char *options, int opt_len,
-                               int unit, int hdrlen, int mru, int debug);
-static void    bsd_incomp(void *state, u_char *dmsg, int len);
-static int     bsd_decompress(void *state, u_char *cmp, int inlen,
-                              u_char *dmp, int *outlen);
-static void    bsd_reset(void *state);
-static void    bsd_comp_stats(void *state, struct compstat *stats);
-
-/*
- * Exported procedures.
- */
-struct compressor ppp_bsd_compress = {
-    CI_BSD_COMPRESS,           /* compress_proto */
-    bsd_decomp_alloc,          /* decomp_alloc */
-    bsd_free,                  /* decomp_free */
-    bsd_decomp_init,           /* decomp_init */
-    bsd_reset,                 /* decomp_reset */
-    bsd_decompress,            /* decompress */
-    bsd_incomp,                        /* incomp */
-    bsd_comp_stats,            /* decomp_stat */
-};
-
-/*
- * the next two codes should not be changed lightly, as they must not
- * lie within the contiguous general code space.
- */
-#define CLEAR  256                     /* table clear output code */
-#define FIRST  257                     /* first free entry */
-#define LAST   255
-
-#define MAXCODE(b)     ((1 << (b)) - 1)
-#define BADCODEM1      MAXCODE(BSD_MAX_BITS)
-
-#define BSD_HASH(prefix,suffix,hshift) ((((u_int32_t)(suffix)) << (hshift)) \
-                                        ^ (u_int32_t)(prefix))
-#define BSD_KEY(prefix,suffix)         ((((u_int32_t)(suffix)) << 16) \
-                                        + (u_int32_t)(prefix))
-
-#define CHECK_GAP      10000           /* Ratio check interval */
-
-#define RATIO_SCALE_LOG        8
-#define RATIO_SCALE    (1<<RATIO_SCALE_LOG)
-#define RATIO_MAX      (0x7fffffff>>RATIO_SCALE_LOG)
-
-/*
- * clear the dictionary
- */
-static void
-bsd_clear(struct bsd_db *db)
-{
-    db->clear_count++;
-    db->max_ent = FIRST-1;
-    db->n_bits = BSD_INIT_BITS;
-    db->ratio = 0;
-    db->bytes_out = 0;
-    db->in_count = 0;
-    db->checkpoint = CHECK_GAP;
-}
-
-/*
- * If the dictionary is full, then see if it is time to reset it.
- *
- * Compute the compression ratio using fixed-point arithmetic
- * with 8 fractional bits.
- *
- * Since we have an infinite stream instead of a single file,
- * watch only the local compression ratio.
- *
- * Since both peers must reset the dictionary at the same time even in
- * the absence of CLEAR codes (while packets are incompressible), they
- * must compute the same ratio.
- */
-static int                             /* 1=output CLEAR */
-bsd_check(struct bsd_db *db)
-{
-    u_int new_ratio;
-
-    if (db->in_count >= db->checkpoint) {
-       /* age the ratio by limiting the size of the counts */
-       if (db->in_count >= RATIO_MAX
-           || db->bytes_out >= RATIO_MAX) {
-           db->in_count -= db->in_count/4;
-           db->bytes_out -= db->bytes_out/4;
-       }
-
-       db->checkpoint = db->in_count + CHECK_GAP;
-
-       if (db->max_ent >= db->maxmaxcode) {
-           /* Reset the dictionary only if the ratio is worse,
-            * or if it looks as if it has been poisoned
-            * by incompressible data.
-            *
-            * This does not overflow, because
-            *  db->in_count <= RATIO_MAX.
-            */
-           new_ratio = db->in_count << RATIO_SCALE_LOG;
-           if (db->bytes_out != 0)
-               new_ratio /= db->bytes_out;
-
-           if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
-               bsd_clear(db);
-               return 1;
-           }
-           db->ratio = new_ratio;
-       }
-    }
-    return 0;
-}
-
-/*
- * Return statistics.
- */
-static void
-bsd_comp_stats(void *state, struct compstat *stats)
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int out;
-
-    stats->unc_bytes = db->uncomp_bytes;
-    stats->unc_packets = db->uncomp_count;
-    stats->comp_bytes = db->comp_bytes;
-    stats->comp_packets = db->comp_count;
-    stats->inc_bytes = db->incomp_bytes;
-    stats->inc_packets = db->incomp_count;
-
-    u_int ratio = db->in_count;
-    out = db->bytes_out;
-    if (ratio <= 0x7fffff)
-       ratio <<= 8;
-    else
-       out >>= 8;
-    if (out != 0)
-       stats->ratio = ratio / out;
-}
-
-/*
- * Reset state, as on a CCP ResetReq.
- */
-static void
-bsd_reset(void *state)
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-
-    db->seqno = 0;
-    bsd_clear(db);
-    db->clear_count = 0;
-}
-
-/*
- * Allocate space for a (de) compressor.
- */
-static void *
-bsd_alloc(u_char *options, int opt_len, int decomp)
-{
-    int bits;
-    u_int newlen, hsize, hshift, maxmaxcode;
-    struct bsd_db *db;
-
-    if (opt_len != 3 || options[0] != CI_BSD_COMPRESS || options[1] != 3
-       || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
-       return NULL;
-
-    bits = BSD_NBITS(options[2]);
-    switch (bits) {
-    case 9:                    /* needs 82152 for both directions */
-    case 10:                   /* needs 84144 */
-    case 11:                   /* needs 88240 */
-    case 12:                   /* needs 96432 */
-       hsize = 5003;
-       hshift = 4;
-       break;
-    case 13:                   /* needs 176784 */
-       hsize = 9001;
-       hshift = 5;
-       break;
-    case 14:                   /* needs 353744 */
-       hsize = 18013;
-       hshift = 6;
-       break;
-    case 15:                   /* needs 691440 */
-       hsize = 35023;
-       hshift = 7;
-       break;
-    case 16:                   /* needs 1366160--far too much, */
-       /* hsize = 69001; */    /* and 69001 is too big for cptr */
-       /* hshift = 8; */       /* in struct bsd_db */
-       /* break; */
-    default:
-       return NULL;
-    }
-
-    maxmaxcode = MAXCODE(bits);
-    newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
-    db = (struct bsd_db *) malloc(newlen);
-    if (!db)
-       return NULL;
-    memset(db, 0, sizeof(*db) - sizeof(db->dict));
-
-    if (!decomp) {
-       db->lens = NULL;
-    } else {
-       db->lens = (u_short *) malloc((maxmaxcode+1) * sizeof(db->lens[0]));
-       if (!db->lens) {
-           free(db);
-           return NULL;
-       }
-    }
-
-    db->totlen = newlen;
-    db->hsize = hsize;
-    db->hshift = hshift;
-    db->maxmaxcode = maxmaxcode;
-    db->maxbits = bits;
-
-    return (void *) db;
-}
-
-static void
-bsd_free(void *state)
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-
-    if (db->lens)
-       free(db->lens);
-    free(db);
-}
-
-static void *
-bsd_decomp_alloc(u_char *options, int opt_len)
-{
-    return bsd_alloc(options, opt_len, 1);
-}
-
-/*
- * Initialize the database.
- */
-static int
-bsd_init(struct bsd_db *db, u_char *options, int opt_len, int unit,
-        int hdrlen, int mru, int debug, int decomp)
-{
-    int i;
-
-    if (opt_len < CILEN_BSD_COMPRESS
-       || options[0] != CI_BSD_COMPRESS || options[1] != CILEN_BSD_COMPRESS
-       || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION
-       || BSD_NBITS(options[2]) != db->maxbits
-       || (decomp && db->lens == NULL))
-       return 0;
-
-    if (decomp) {
-       i = LAST+1;
-       while (i != 0)
-           db->lens[--i] = 1;
-    }
-    i = db->hsize;
-    while (i != 0) {
-       db->dict[--i].codem1 = BADCODEM1;
-       db->dict[i].cptr = 0;
-    }
-
-    db->unit = unit;
-    db->hdrlen = hdrlen;
-    db->mru = mru;
-    if (debug)
-       db->debug = 1;
-
-    bsd_reset(db);
-
-    return 1;
-}
-
-static int
-bsd_decomp_init(void *state, u_char *options, int opt_len,
-               int unit, int hdrlen, int mru, int debug)
-{
-    return bsd_init((struct bsd_db *) state, options, opt_len,
-                   unit, hdrlen, mru, debug, 1);
-}
-
-
-/*
- * Update the "BSD Compress" dictionary on the receiver for
- * incompressible data by pretending to compress the incoming data.
- */
-static void
-bsd_incomp(void *state, u_char *dmsg, int mlen)
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int hshift = db->hshift;
-    u_int max_ent = db->max_ent;
-    u_int n_bits = db->n_bits;
-    struct bsd_dict *dictp;
-    u_int32_t fcode;
-    u_char c;
-    long hval, disp;
-    int slen, ilen;
-    u_int bitno = 7;
-    u_char *rptr;
-    u_int ent;
-
-    rptr = dmsg;
-    ent = rptr[0];             /* get the protocol */
-    if (ent == 0) {
-       ++rptr;
-       --mlen;
-       ent = rptr[0];
-    }
-    if ((ent & 1) == 0 || ent < 0x21 || ent > 0xf9)
-       return;
-
-    db->seqno++;
-    ilen = 1;          /* count the protocol as 1 byte */
-    ++rptr;
-    slen = dmsg + mlen - rptr;
-    ilen += slen;
-    for (; slen > 0; --slen) {
-       c = *rptr++;
-       fcode = BSD_KEY(ent, c);
-       hval = BSD_HASH(ent, c, hshift);
-       dictp = &db->dict[hval];
-
-       /* validate and then check the entry */
-       if (dictp->codem1 >= max_ent)
-           goto nomatch;
-       if (dictp->f.fcode == fcode) {
-           ent = dictp->codem1+1;
-           continue;   /* found (prefix,suffix) */
-       }
-
-       /* continue probing until a match or invalid entry */
-       disp = (hval == 0) ? 1 : hval;
-       do {
-           hval += disp;
-           if (hval >= db->hsize)
-               hval -= db->hsize;
-           dictp = &db->dict[hval];
-           if (dictp->codem1 >= max_ent)
-               goto nomatch;
-       } while (dictp->f.fcode != fcode);
-       ent = dictp->codem1+1;
-       continue;       /* finally found (prefix,suffix) */
-
-    nomatch:           /* output (count) the prefix */
-       bitno += n_bits;
-
-       /* code -> hashtable */
-       if (max_ent < db->maxmaxcode) {
-           struct bsd_dict *dictp2;
-           /* expand code size if needed */
-           if (max_ent >= MAXCODE(n_bits))
-               db->n_bits = ++n_bits;
-
-           /* Invalidate previous hash table entry
-            * assigned this code, and then take it over.
-            */
-           dictp2 = &db->dict[max_ent+1];
-           if (db->dict[dictp2->cptr].codem1 == max_ent)
-               db->dict[dictp2->cptr].codem1 = BADCODEM1;
-           dictp2->cptr = hval;
-           dictp->codem1 = max_ent;
-           dictp->f.fcode = fcode;
-
-           db->max_ent = ++max_ent;
-           db->lens[max_ent] = db->lens[ent]+1;
-       }
-       ent = c;
-    }
-    bitno += n_bits;           /* output (count) the last code */
-    db->bytes_out += bitno/8;
-    db->in_count += ilen;
-    (void)bsd_check(db);
-
-    ++db->incomp_count;
-    db->incomp_bytes += ilen;
-    ++db->uncomp_count;
-    db->uncomp_bytes += ilen;
-
-    /* Increase code size if we would have without the packet
-     * boundary and as the decompressor will.
-     */
-    if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
-       db->n_bits++;
-}
-
-
-/*
- * Decompress "BSD Compress"
- *
- * Because of patent problems, we return DECOMP_ERROR for errors
- * found by inspecting the input data and for system problems, but
- * DECOMP_FATALERROR for any errors which could possibly be said to
- * be being detected "after" decompression.  For DECOMP_ERROR,
- * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
- * infringing a patent of Motorola's if we do, so we take CCP down
- * instead.
- *
- * Given that the frame has the correct sequence number and a good FCS,
- * errors such as invalid codes in the input most likely indicate a
- * bug, so we return DECOMP_FATALERROR for them in order to turn off
- * compression, even though they are detected by inspecting the input.
- */
-static int
-bsd_decompress(void *state, u_char *cmsg, int inlen, u_char *dmp, int *outlenp)
-{
-    struct bsd_db *db = (struct bsd_db *) state;
-    u_int max_ent = db->max_ent;
-    u_int32_t accm = 0;
-    u_int bitno = 32;          /* 1st valid bit in accm */
-    u_int n_bits = db->n_bits;
-    u_int tgtbitno = 32-n_bits;        /* bitno when we have a code */
-    struct bsd_dict *dictp;
-    int explen, seq, len;
-    u_int incode, oldcode, finchar;
-    u_char *p, *rptr, *wptr;
-    int ilen;
-    int codelen, extra;
-
-    rptr = cmsg;
-    if (*rptr == 0)
-       ++rptr;
-    ++rptr;                    /* skip protocol (assumed 0xfd) */
-    seq = (rptr[0] << 8) + rptr[1];
-    rptr += BSD_OVHD;
-    ilen = len = cmsg + inlen - rptr;
-
-    /*
-     * Check the sequence number and give up if it is not what we expect.
-     */
-    if (seq != db->seqno++) {
-       if (db->debug)
-           printf("bsd_decomp%d: bad sequence # %d, expected %d\n",
-                  db->unit, seq, db->seqno - 1);
-       return DECOMP_ERROR;
-    }
-
-    wptr = dmp + db->hdrlen;
-
-    oldcode = CLEAR;
-    explen = 0;
-    while (len > 0) {
-       /*
-        * Accumulate bytes until we have a complete code.
-        * Then get the next code, relying on the 32-bit,
-        * unsigned accm to mask the result.
-        */
-       bitno -= 8;
-       accm |= *rptr++ << bitno;
-       --len;
-       if (tgtbitno < bitno)
-           continue;
-       incode = accm >> tgtbitno;
-       accm <<= n_bits;
-       bitno += n_bits;
-
-       if (incode == CLEAR) {
-           /*
-            * The dictionary must only be cleared at
-            * the end of a packet.  But there could be an
-            * empty message block at the end.
-            */
-           if (len > 0) {
-               if (db->debug)
-                   printf("bsd_decomp%d: bad CLEAR\n", db->unit);
-               return DECOMP_FATALERROR;
-           }
-           bsd_clear(db);
-           explen = ilen = 0;
-           break;
-       }
-
-       if (incode > max_ent + 2 || incode > db->maxmaxcode
-           || (incode > max_ent && oldcode == CLEAR)) {
-           if (db->debug) {
-               printf("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
-                      db->unit, incode, oldcode);
-               printf("max_ent=0x%x seqno=%d\n",
-                      max_ent, db->seqno);
-           }
-           return DECOMP_FATALERROR;   /* probably a bug */
-       }
-
-       /* Special case for KwKwK string. */
-       if (incode > max_ent) {
-           finchar = oldcode;
-           extra = 1;
-       } else {
-           finchar = incode;
-           extra = 0;
-       }
-
-       codelen = db->lens[finchar];
-       explen += codelen + extra;
-       if (explen > db->mru + 1) {
-           if (db->debug)
-               printf("bsd_decomp%d: ran out of mru\n", db->unit);
-           return DECOMP_FATALERROR;
-       }
-
-       /*
-        * Decode this code and install it in the decompressed buffer.
-        */
-       p = (wptr += codelen);
-       while (finchar > LAST) {
-           dictp = &db->dict[db->dict[finchar].cptr];
-#ifdef DEBUG
-           --codelen;
-           if (codelen <= 0) {
-               printf("bsd_decomp%d: fell off end of chain ", db->unit);
-               printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
-                      incode, finchar, db->dict[finchar].cptr, max_ent);
-               return DECOMP_FATALERROR;
-           }
-           if (dictp->codem1 != finchar-1) {
-               printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ",
-                      db->unit, incode, finchar);
-               printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode,
-                      db->dict[finchar].cptr, dictp->codem1);
-               return DECOMP_FATALERROR;
-           }
-#endif
-           *--p = dictp->f.hs.suffix;
-           finchar = dictp->f.hs.prefix;
-       }
-       *--p = finchar;
-
-#ifdef DEBUG
-       if (--codelen != 0)
-           printf("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n",
-                  db->unit, codelen, incode, max_ent);
-#endif
-
-       if (extra)              /* the KwKwK case again */
-           *wptr++ = finchar;
-
-       /*
-        * If not first code in a packet, and
-        * if not out of code space, then allocate a new code.
-        *
-        * Keep the hash table correct so it can be used
-        * with uncompressed packets.
-        */
-       if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
-           struct bsd_dict *dictp2;
-           u_int32_t fcode;
-           int hval, disp;
-
-           fcode = BSD_KEY(oldcode,finchar);
-           hval = BSD_HASH(oldcode,finchar,db->hshift);
-           dictp = &db->dict[hval];
-
-           /* look for a free hash table entry */
-           if (dictp->codem1 < max_ent) {
-               disp = (hval == 0) ? 1 : hval;
-               do {
-                   hval += disp;
-                   if (hval >= db->hsize)
-                       hval -= db->hsize;
-                   dictp = &db->dict[hval];
-               } while (dictp->codem1 < max_ent);
-           }
-
-           /*
-            * Invalidate previous hash table entry
-            * assigned this code, and then take it over
-            */
-           dictp2 = &db->dict[max_ent+1];
-           if (db->dict[dictp2->cptr].codem1 == max_ent) {
-               db->dict[dictp2->cptr].codem1 = BADCODEM1;
-           }
-           dictp2->cptr = hval;
-           dictp->codem1 = max_ent;
-           dictp->f.fcode = fcode;
-
-           db->max_ent = ++max_ent;
-           db->lens[max_ent] = db->lens[oldcode]+1;
-
-           /* Expand code size if needed. */
-           if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
-               db->n_bits = ++n_bits;
-               tgtbitno = 32-n_bits;
-           }
-       }
-       oldcode = incode;
-    }
-    *outlenp = wptr - (dmp + db->hdrlen);
-
-    /*
-     * Keep the checkpoint right so that incompressible packets
-     * clear the dictionary at the right times.
-     */
-    db->bytes_out += ilen;
-    db->in_count += explen;
-    if (bsd_check(db) && db->debug) {
-       printf("bsd_decomp%d: peer should have cleared dictionary\n",
-              db->unit);
-    }
-
-    ++db->comp_count;
-    db->comp_bytes += ilen + BSD_OVHD;
-    ++db->uncomp_count;
-    db->uncomp_bytes += explen;
-
-    return DECOMP_OK;
-}
-#endif /* DO_BSD_COMPRESS */
diff --git a/pppdump/deflate.c b/pppdump/deflate.c
deleted file mode 100644 (file)
index ebc1692..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * ppp_deflate.c - interface the zlib procedures for Deflate compression
- * and decompression (as used by gzip) to the PPP code.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: deflate.c,v 1.5 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "ppp-comp.h"
-#include "zlib.h"
-
-#if DO_DEFLATE
-
-#define DEFLATE_DEBUG  1
-
-/*
- * State for a Deflate (de)compressor.
- */
-struct deflate_state {
-    int                seqno;
-    int                w_size;
-    int                unit;
-    int                hdrlen;
-    int                mru;
-    int                debug;
-    z_stream   strm;
-    struct compstat stats;
-};
-
-#define DEFLATE_OVHD   2               /* Deflate overhead/packet */
-
-static void    *z_alloc(void *, u_int items, u_int size);
-static void    z_free(void *, void *ptr, u_int nb);
-static void    *z_decomp_alloc(u_char *options, int opt_len);
-static void    z_decomp_free(void *state);
-static int     z_decomp_init(void *state, u_char *options, int opt_len,
-                             int unit, int hdrlen, int mru, int debug);
-static void    z_incomp(void *state, u_char *dmsg, int len);
-static int     z_decompress(void *state, u_char *cmp, int inlen,
-                            u_char *dmp, int *outlenp);
-static void    z_decomp_reset(void *state);
-static void    z_comp_stats(void *state, struct compstat *stats);
-
-/*
- * Procedures exported to if_ppp.c.
- */
-struct compressor ppp_deflate = {
-    CI_DEFLATE,                        /* compress_proto */
-    z_decomp_alloc,            /* decomp_alloc */
-    z_decomp_free,             /* decomp_free */
-    z_decomp_init,             /* decomp_init */
-    z_decomp_reset,            /* decomp_reset */
-    z_decompress,              /* decompress */
-    z_incomp,                  /* incomp */
-    z_comp_stats,              /* decomp_stat */
-};
-
-/*
- * Space allocation and freeing routines for use by zlib routines.
- */
-static void *
-z_alloc(void *notused, u_int items, u_int size)
-{
-    return malloc(items * size);
-}
-
-static void
-z_free(void *notused, void *ptr, u_int nbytes)
-{
-    free(ptr);
-}
-
-static void
-z_comp_stats(void *arg, struct compstat *stats)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_int out;
-
-    *stats = state->stats;
-    stats->ratio = stats->unc_bytes;
-    out = stats->comp_bytes + stats->unc_bytes;
-    u_int ratio = stats->ratio;
-    if (ratio <= 0x7ffffff)
-       ratio <<= 8;
-    else
-       out >>= 8;
-    if (out != 0)
-       stats->ratio = ratio / out;
-}
-
-/*
- * Allocate space for a decompressor.
- */
-static void *
-z_decomp_alloc(u_char *options, int opt_len)
-{
-    struct deflate_state *state;
-    int w_size;
-
-    if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return NULL;
-    w_size = DEFLATE_SIZE(options[2]);
-    if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
-       return NULL;
-
-    state = (struct deflate_state *) malloc(sizeof(*state));
-    if (state == NULL)
-       return NULL;
-
-    state->strm.next_out = NULL;
-    state->strm.zalloc = (alloc_func) z_alloc;
-    state->strm.zfree = (free_func) z_free;
-    if (inflateInit2(&state->strm, -w_size) != Z_OK) {
-       free(state);
-       return NULL;
-    }
-
-    state->w_size = w_size;
-    memset(&state->stats, 0, sizeof(state->stats));
-    return (void *) state;
-}
-
-static void
-z_decomp_free(void *arg)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    inflateEnd(&state->strm);
-    free(state);
-}
-
-static int
-z_decomp_init(void *arg, u_char *options, int opt_len,
-             int unit, int hdrlen, int mru, int debug)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
-       || options[1] != CILEN_DEFLATE
-       || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
-       || DEFLATE_SIZE(options[2]) != state->w_size
-       || options[3] != DEFLATE_CHK_SEQUENCE)
-       return 0;
-
-    state->seqno = 0;
-    state->unit = unit;
-    state->hdrlen = hdrlen;
-    state->debug = debug;
-    state->mru = mru;
-
-    inflateReset(&state->strm);
-
-    return 1;
-}
-
-static void
-z_decomp_reset(void *arg)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-
-    state->seqno = 0;
-    inflateReset(&state->strm);
-}
-
-/*
- * Decompress a Deflate-compressed packet.
- *
- * Because of patent problems, we return DECOMP_ERROR for errors
- * found by inspecting the input data and for system problems, but
- * DECOMP_FATALERROR for any errors which could possibly be said to
- * be being detected "after" decompression.  For DECOMP_ERROR,
- * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
- * infringing a patent of Motorola's if we do, so we take CCP down
- * instead.
- *
- * Given that the frame has the correct sequence number and a good FCS,
- * errors such as invalid codes in the input most likely indicate a
- * bug, so we return DECOMP_FATALERROR for them in order to turn off
- * compression, even though they are detected by inspecting the input.
- */
-static int
-z_decompress(void *arg, u_char *mi, int inlen, u_char *mo, int *outlenp)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_char *rptr, *wptr;
-    int rlen, olen;
-    int seq, r;
-
-    rptr = mi;
-    if (*rptr == 0)
-       ++rptr;
-    ++rptr;
-
-    /* Check the sequence number. */
-    seq = (rptr[0] << 8) + rptr[1];
-    rptr += 2;
-    if (seq != state->seqno) {
-#if !DEFLATE_DEBUG
-       if (state->debug)
-#endif
-           printf("z_decompress%d: bad seq # %d, expected %d\n",
-                  state->unit, seq, state->seqno);
-       return DECOMP_ERROR;
-    }
-    ++state->seqno;
-
-    /*
-     * Set up to call inflate.
-     */
-    wptr = mo;
-    state->strm.next_in = rptr;
-    state->strm.avail_in = mi + inlen - rptr;
-    rlen = state->strm.avail_in + PPP_HDRLEN + DEFLATE_OVHD;
-    state->strm.next_out = wptr;
-    state->strm.avail_out = state->mru + 2;
-
-    r = inflate(&state->strm, Z_PACKET_FLUSH);
-    if (r != Z_OK) {
-#if !DEFLATE_DEBUG
-       if (state->debug)
-#endif
-           printf("z_decompress%d: inflate returned %d (%s)\n",
-                  state->unit, r, (state->strm.msg? state->strm.msg: ""));
-       return DECOMP_FATALERROR;
-    }
-    olen = state->mru + 2 - state->strm.avail_out;
-    *outlenp = olen;
-
-    if ((wptr[0] & 1) != 0)
-       ++olen;                 /* for suppressed protocol high byte */
-    olen += 2;                 /* for address, control */
-
-#if DEFLATE_DEBUG
-    if (olen > state->mru + PPP_HDRLEN)
-       printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
-              state->unit, olen, state->mru + PPP_HDRLEN);
-#endif
-
-    state->stats.unc_bytes += olen;
-    state->stats.unc_packets++;
-    state->stats.comp_bytes += rlen;
-    state->stats.comp_packets++;
-
-    return DECOMP_OK;
-}
-
-/*
- * Incompressible data has arrived - add it to the history.
- */
-static void
-z_incomp(void *arg, u_char *mi, int mlen)
-{
-    struct deflate_state *state = (struct deflate_state *) arg;
-    u_char *rptr;
-    int rlen, proto, r;
-
-    /*
-     * Check that the protocol is one we handle.
-     */
-    rptr = mi;
-    proto = rptr[0];
-    if ((proto & 1) == 0)
-       proto = (proto << 8) + rptr[1];
-    if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
-       return;
-
-    ++state->seqno;
-
-    if (rptr[0] == 0)
-       ++rptr;
-    rlen = mi + mlen - rptr;
-    state->strm.next_in = rptr;
-    state->strm.avail_in = rlen;
-    r = inflateIncomp(&state->strm);
-    if (r != Z_OK) {
-       /* gak! */
-#if !DEFLATE_DEBUG
-       if (state->debug)
-#endif
-           printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
-                  state->unit, r, (state->strm.msg? state->strm.msg: ""));
-       return;
-    }
-
-    /*
-     * Update stats.
-     */
-    if (proto <= 0xff)
-       ++rlen;
-    rlen += 2;
-    state->stats.inc_bytes += rlen;
-    state->stats.inc_packets++;
-    state->stats.unc_bytes += rlen;
-    state->stats.unc_packets++;
-}
-
-#endif /* DO_DEFLATE */
diff --git a/pppdump/ppp-comp.h b/pppdump/ppp-comp.h
deleted file mode 100644 (file)
index 0199b5f..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ppp-comp.h - Definitions for doing PPP packet compression.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp-comp.h,v 1.2 2002/12/06 09:49:16 paulus Exp $
- */
-
-#ifndef _NET_PPP_COMP_H
-#define _NET_PPP_COMP_H
-
-/*
- * The following symbols control whether we include code for
- * various compression methods.
- */
-#ifndef DO_BSD_COMPRESS
-#define DO_BSD_COMPRESS        1       /* by default, include BSD-Compress */
-#endif
-#ifndef DO_DEFLATE
-#define DO_DEFLATE     1       /* by default, include Deflate */
-#endif
-#define DO_PREDICTOR_1 0
-#define DO_PREDICTOR_2 0
-
-#if defined(SOL2)
-#include <net/ppp_defs.h>
-#else
-#include <linux/ppp_defs.h>
-#endif
-
-/*
- * Structure giving methods for compression/decompression.
- */
-struct compressor {
-       int     compress_proto; /* CCP compression protocol number */
-
-       /* Allocate space for a decompressor (receive side) */
-       void    *(*decomp_alloc)(u_char *options, int opt_len);
-       /* Free space used by a decompressor */
-       void    (*decomp_free)(void *state);
-       /* Initialize a decompressor */
-       int     (*decomp_init)(void *state, u_char *options, int opt_len,
-                              int unit, int hdrlen, int mru, int debug);
-       /* Reset a decompressor */
-       void    (*decomp_reset)(void *state);
-       /* Decompress a packet. */
-       int     (*decompress)(void *state, u_char *mp, int inlen,
-                             u_char *dmp, int *outlen);
-       /* Update state for an incompressible packet received */
-       void    (*incomp)(void *state, u_char *mp, int len);
-       /* Return decompression statistics */
-       void    (*decomp_stat)(void *state, struct compstat *stats);
-};
-
-/*
- * Return values for decompress routine.
- * We need to make these distinctions so that we can disable certain
- * useful functionality, namely sending a CCP reset-request as a result
- * of an error detected after decompression.  This is to avoid infringing
- * a patent held by Motorola.
- * Don't you just lurve software patents.
- */
-#define DECOMP_OK              0       /* everything went OK */
-#define DECOMP_ERROR           1       /* error detected before decomp. */
-#define DECOMP_FATALERROR      2       /* error detected after decomp. */
-
-/*
- * CCP codes.
- */
-#define CCP_CONFREQ    1
-#define CCP_CONFACK    2
-#define CCP_CONFNAK    3
-#define CCP_CONFREJ    4
-#define CCP_TERMREQ    5
-#define CCP_TERMACK    6
-#define CCP_RESETREQ   14
-#define CCP_RESETACK   15
-
-/*
- * Max # bytes for a CCP option
- */
-#define CCP_MAX_OPTION_LENGTH  32
-
-/*
- * Parts of a CCP packet.
- */
-#define CCP_CODE(dp)           ((dp)[0])
-#define CCP_ID(dp)             ((dp)[1])
-#define CCP_LENGTH(dp)         (((dp)[2] << 8) + (dp)[3])
-#define CCP_HDRLEN             4
-
-#define CCP_OPT_CODE(dp)       ((dp)[0])
-#define CCP_OPT_LENGTH(dp)     ((dp)[1])
-#define CCP_OPT_MINLEN         2
-
-/*
- * Definitions for BSD-Compress.
- */
-#define CI_BSD_COMPRESS                21      /* config. option for BSD-Compress */
-#define CILEN_BSD_COMPRESS     3       /* length of config. option */
-
-/* Macros for handling the 3rd byte of the BSD-Compress config option. */
-#define BSD_NBITS(x)           ((x) & 0x1F)    /* number of bits requested */
-#define BSD_VERSION(x)         ((x) >> 5)      /* version of option format */
-#define BSD_CURRENT_VERSION    1               /* current version number */
-#define BSD_MAKE_OPT(v, n)     (((v) << 5) | (n))
-
-#define BSD_MIN_BITS           9       /* smallest code size supported */
-#define BSD_MAX_BITS           15      /* largest code size supported */
-
-/*
- * Definitions for Deflate.
- */
-#define CI_DEFLATE             26      /* config option for Deflate */
-#define CI_DEFLATE_DRAFT       24      /* value used in original draft RFC */
-#define CILEN_DEFLATE          4       /* length of its config option */
-
-#define DEFLATE_MIN_SIZE       8
-#define DEFLATE_MAX_SIZE       15
-#define DEFLATE_METHOD_VAL     8
-#define DEFLATE_SIZE(x)                (((x) >> 4) + DEFLATE_MIN_SIZE)
-#define DEFLATE_METHOD(x)      ((x) & 0x0F)
-#define DEFLATE_MAKE_OPT(w)    ((((w) - DEFLATE_MIN_SIZE) << 4) \
-                                + DEFLATE_METHOD_VAL)
-#define DEFLATE_CHK_SEQUENCE   0
-
-/*
- * Definitions for other, as yet unsupported, compression methods.
- */
-#define CI_PREDICTOR_1         1       /* config option for Predictor-1 */
-#define CILEN_PREDICTOR_1      2       /* length of its config option */
-#define CI_PREDICTOR_2         2       /* config option for Predictor-2 */
-#define CILEN_PREDICTOR_2      2       /* length of its config option */
-
-#endif /* _NET_PPP_COMP_H */
index 1116b85617c655ee72075eac0f5b6882fb12611f..c3f29f9c86c37557b79d82de7ee9c9f65a4df23c 100644 (file)
@@ -1,4 +1,3 @@
-.\"    @(#) $Id: pppdump.8,v 1.2 2004/11/13 12:22:49 paulus Exp $
 .TH PPPDUMP 8 "1 April 1999"
 .SH NAME
 pppdump \- convert PPP record file to readable format
index b85a86271edacafcbae3f7329bce4e08bf5b0b94..c24208af5fff98edc3e5634cade285d02005f8ab 100644 (file)
@@ -2,7 +2,7 @@
  * pppdump - print out the contents of a record file generated by
  * pppd in readable form.
  *
- * Copyright (c) 1999 Paul Mackerras. All rights reserved.
+ * Copyright (c) 1999-2024 Paul Mackerras. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 #include <time.h>
 #include <sys/types.h>
 
-#include "ppp-comp.h"
-
 int hexmode;
 int pppmode;
 int reverse;
-int decompress;
 int mru = 1500;
 int abs_times;
 time_t start_time;
@@ -57,7 +45,6 @@ extern char *optarg;
 void dumplog();
 void dumpppp();
 void show_time();
-void handle_ccp();
 
 int
 main(ac, av)
@@ -79,9 +66,6 @@ main(ac, av)
        case 'r':
            reverse = 1;
            break;
-       case 'd':
-           decompress = 1;
-           break;
        case 'm':
            mru = atoi(optarg);
            break;
@@ -235,6 +219,9 @@ static u_short fcstab[256] = {
 };
 #define PPP_FCS(fcs, c)        (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
 
+#define PPP_INITFCS    0xffff  /* Initial FCS value */
+#define PPP_GOODFCS    0xf0b8  /* Good final FCS value */
+
 struct pkt {
     int        cnt;
     int        esc;
@@ -327,51 +314,6 @@ dumpppp(f)
                        if (endp - r > mru)
                            printf("     ERROR: length (%zd) > MRU (%d)\n",
                                   endp - r, mru);
-                       if (decompress && fcs == PPP_GOODFCS) {
-                           /* See if this is a CCP or compressed packet */
-                           d = dbuf;
-                           r = p;
-                           if (r[0] == 0xff && r[1] == 3) {
-                               *d++ = *r++;
-                               *d++ = *r++;
-                           }
-                           proto = r[0];
-                           if ((proto & 1) == 0)
-                               proto = (proto << 8) + r[1];
-                           if (proto == PPP_CCP) {
-                               handle_ccp(pkt, r + 2, endp - r - 2);
-                           } else if (proto == PPP_COMP) {
-                               if ((pkt->flags & CCP_ISUP)
-                                   && (pkt->flags & CCP_DECOMP_RUN)
-                                   && pkt->state
-                                   && (pkt->flags & CCP_ERR) == 0) {
-                                   rv = pkt->comp->decompress(pkt->state, r,
-                                                       endp - r, d, &dn);
-                                   switch (rv) {
-                                   case DECOMP_OK:
-                                       p = dbuf;
-                                       nb = d + dn - p;
-                                       if ((d[0] & 1) == 0)
-                                           --dn;
-                                       --dn;
-                                       if (dn > mru)
-                                           printf("     ERROR: decompressed length (%d) > MRU (%d)\n", dn, mru);
-                                       break;
-                                   case DECOMP_ERROR:
-                                       printf("     DECOMPRESSION ERROR\n");
-                                       pkt->flags |= CCP_ERROR;
-                                       break;
-                                   case DECOMP_FATALERROR:
-                                       printf("     FATAL DECOMPRESSION ERROR\n");
-                                       pkt->flags |= CCP_FATALERROR;
-                                       break;
-                                   }
-                               }
-                           } else if (pkt->state
-                                      && (pkt->flags & CCP_DECOMP_RUN)) {
-                               pkt->comp->incomp(pkt->state, r, endp - r);
-                           }
-                       }
                        do {
                            nl = nb < 16? nb: 16;
                            printf("%s ", q);
@@ -432,75 +374,6 @@ dumpppp(f)
     }
 }
 
-extern struct compressor ppp_bsd_compress, ppp_deflate;
-
-struct compressor *compressors[] = {
-#if DO_BSD_COMPRESS
-    &ppp_bsd_compress,
-#endif
-#if DO_DEFLATE
-    &ppp_deflate,
-#endif
-    NULL
-};
-
-void
-handle_ccp(cp, dp, len)
-    struct pkt *cp;
-    u_char *dp;
-    int len;
-{
-    int clen;
-    struct compressor **comp;
-
-    if (len < CCP_HDRLEN)
-       return;
-    clen = CCP_LENGTH(dp);
-    if (clen > len)
-       return;
-
-    switch (CCP_CODE(dp)) {
-    case CCP_CONFACK:
-       cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP);
-       if (clen < CCP_HDRLEN + CCP_OPT_MINLEN
-           || clen < CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN))
-           break;
-       dp += CCP_HDRLEN;
-       clen -= CCP_HDRLEN;
-       for (comp = compressors; *comp != NULL; ++comp) {
-           if ((*comp)->compress_proto == dp[0]) {
-               if (cp->state != NULL) {
-                   (*cp->comp->decomp_free)(cp->state);
-                   cp->state = NULL;
-               }
-               cp->comp = *comp;
-               cp->state = (*comp)->decomp_alloc(dp, CCP_OPT_LENGTH(dp));
-               cp->flags |= CCP_ISUP;
-               if (cp->state != NULL
-                   && (*cp->comp->decomp_init)
-                       (cp->state, dp, clen, 0, 0, 8192, 1))
-                   cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
-               break;
-           }
-       }
-       break;
-
-    case CCP_CONFNAK:
-    case CCP_CONFREJ:
-       cp->flags &= ~(CCP_DECOMP_RUN | CCP_ISUP);
-       break;
-
-    case CCP_RESETACK:
-       if (cp->flags & CCP_ISUP) {
-           if (cp->state && (cp->flags & CCP_DECOMP_RUN)) {
-               (*cp->comp->decomp_reset)(cp->state);
-               cp->flags &= ~CCP_ERROR;
-           }
-       }
-       break;
-    }
-}
-
 void
 show_time(f, c)
     FILE *f;
diff --git a/pppdump/zlib.c b/pppdump/zlib.c
deleted file mode 100644 (file)
index c3c68f6..0000000
+++ /dev/null
@@ -1,4614 +0,0 @@
-/*
- * This file is derived from various .h and .c files from the zlib-0.95
- * distribution by Jean-loup Gailly and Mark Adler, with some additions
- * by Paul Mackerras to aid in implementing Deflate compression and
- * decompression for PPP packets.  See zlib.h for conditions of
- * distribution and use.
- *
- * Changes that have been made include:
- * - changed functions not used outside this file to "local"
- * - added minCompression parameter to deflateInit2
- * - added Z_PACKET_FLUSH (see zlib.h for details)
- * - added inflateIncomp
- *
- * $Id: zlib.c,v 1.2 1999/04/01 07:26:30 paulus Exp $
- */
-
-
-/*+++++*/
-/* zutil.h -- internal interface and configuration of the compression library
- * Copyright (C) 1995 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* From: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp */
-
-#define _Z_UTIL_H
-
-#include "zlib.h"
-
-#ifdef STDC
-#  include <string.h>
-#endif
-
-#ifndef local
-#  define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
-
-#define FAR
-
-typedef unsigned char  uch;
-typedef uch FAR uchf;
-typedef unsigned short ush;
-typedef ush FAR ushf;
-typedef unsigned long  ulg;
-
-extern char *z_errmsg[]; /* indexed by 1-zlib_error */
-
-#define ERR_RETURN(strm,err) return (strm->msg=z_errmsg[1-err], err)
-/* To be used only when the state is known to be valid */
-
-#ifndef NULL
-#define NULL   ((void *) 0)
-#endif
-
-        /* common constants */
-
-#define DEFLATED   8
-
-#ifndef DEF_WBITS
-#  define DEF_WBITS MAX_WBITS
-#endif
-/* default windowBits for decompression. MAX_WBITS is for compression only */
-
-#if MAX_MEM_LEVEL >= 8
-#  define DEF_MEM_LEVEL 8
-#else
-#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
-#endif
-/* default memLevel */
-
-#define STORED_BLOCK 0
-#define STATIC_TREES 1
-#define DYN_TREES    2
-/* The three kinds of block type */
-
-#define MIN_MATCH  3
-#define MAX_MATCH  258
-/* The minimum and maximum match lengths */
-
-         /* functions */
-
-#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
-#  define HAVE_MEMCPY
-#endif
-#ifdef HAVE_MEMCPY
-#  define zmemcpy memcpy
-#  define zmemzero(dest, len) memset(dest, 0, len)
-#else
-#  define zmemcpy(d, s, n)     bcopy((s), (d), (n))
-#  define zmemzero             bzero
-#endif
-
-/* Diagnostic functions */
-#ifdef DEBUG_ZLIB
-#  include <stdio.h>
-#  ifndef verbose
-#    define verbose 0
-#  endif
-#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
-#  define Trace(x) fprintf x
-#  define Tracev(x) {if (verbose) fprintf x ;}
-#  define Tracevv(x) {if (verbose>1) fprintf x ;}
-#  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
-#  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
-#else
-#  define Assert(cond,msg)
-#  define Trace(x)
-#  define Tracev(x)
-#  define Tracevv(x)
-#  define Tracec(c,x)
-#  define Tracecv(c,x)
-#endif
-
-
-typedef uLong (*check_func) OF((uLong check, Bytef *buf, uInt len));
-
-/* voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); */
-/* void   zcfree  OF((voidpf opaque, voidpf ptr)); */
-
-#define ZALLOC(strm, items, size) \
-           (*((strm)->zalloc))((strm)->opaque, (items), (size))
-#define ZFREE(strm, addr, size)        \
-          (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size))
-#define TRY_FREE(s, p, n) {if (p) ZFREE(s, p, n);}
-
-/* deflate.h -- internal compression state
- * Copyright (C) 1995 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-
-/*+++++*/
-/* From: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp */
-
-/* ===========================================================================
- * Internal compression state.
- */
-
-/* Data type */
-#define BINARY  0
-#define ASCII   1
-#define UNKNOWN 2
-
-#define LENGTH_CODES 29
-/* number of length codes, not counting the special END_BLOCK code */
-
-#define LITERALS  256
-/* number of literal bytes 0..255 */
-
-#define L_CODES (LITERALS+1+LENGTH_CODES)
-/* number of Literal or Length codes, including the END_BLOCK code */
-
-#define D_CODES   30
-/* number of distance codes */
-
-#define BL_CODES  19
-/* number of codes used to transfer the bit lengths */
-
-#define HEAP_SIZE (2*L_CODES+1)
-/* maximum heap size */
-
-#define MAX_BITS 15
-/* All codes must not exceed MAX_BITS bits */
-
-#define INIT_STATE    42
-#define BUSY_STATE   113
-#define FLUSH_STATE  124
-#define FINISH_STATE 666
-/* Stream status */
-
-
-/* Data structure describing a single value and its code string. */
-typedef struct ct_data_s {
-    union {
-        ush  freq;       /* frequency count */
-        ush  code;       /* bit string */
-    } fc;
-    union {
-        ush  dad;        /* father node in Huffman tree */
-        ush  len;        /* length of bit string */
-    } dl;
-} FAR ct_data;
-
-#define Freq fc.freq
-#define Code fc.code
-#define Dad  dl.dad
-#define Len  dl.len
-
-typedef struct static_tree_desc_s  static_tree_desc;
-
-typedef struct tree_desc_s {
-    ct_data *dyn_tree;           /* the dynamic tree */
-    int     max_code;            /* largest code with non zero frequency */
-    static_tree_desc *stat_desc; /* the corresponding static tree */
-} FAR tree_desc;
-
-typedef ush Pos;
-typedef Pos FAR Posf;
-typedef unsigned IPos;
-
-/* A Pos is an index in the character window. We use short instead of int to
- * save space in the various tables. IPos is used only for parameter passing.
- */
-
-typedef struct deflate_state {
-    z_stream *strm;      /* pointer back to this zlib stream */
-    int   status;        /* as the name implies */
-    Bytef *pending_buf;  /* output still pending */
-    Bytef *pending_out;  /* next pending byte to output to the stream */
-    int   pending;       /* nb of bytes in the pending buffer */
-    uLong adler;         /* adler32 of uncompressed data */
-    int   noheader;      /* suppress zlib header and adler32 */
-    Byte  data_type;     /* UNKNOWN, BINARY or ASCII */
-    Byte  method;        /* STORED (for zip only) or DEFLATED */
-    int          minCompr;      /* min size decrease for Z_FLUSH_NOSTORE */
-
-                /* used by deflate.c: */
-
-    uInt  w_size;        /* LZ77 window size (32K by default) */
-    uInt  w_bits;        /* log2(w_size)  (8..16) */
-    uInt  w_mask;        /* w_size - 1 */
-
-    Bytef *window;
-    /* Sliding window. Input bytes are read into the second half of the window,
-     * and move to the first half later to keep a dictionary of at least wSize
-     * bytes. With this organization, matches are limited to a distance of
-     * wSize-MAX_MATCH bytes, but this ensures that IO is always
-     * performed with a length multiple of the block size. Also, it limits
-     * the window size to 64K, which is quite useful on MSDOS.
-     * To do: use the user input buffer as sliding window.
-     */
-
-    ulg window_size;
-    /* Actual size of window: 2*wSize, except when the user input buffer
-     * is directly used as sliding window.
-     */
-
-    Posf *prev;
-    /* Link to older string with same hash index. To limit the size of this
-     * array to 64K, this link is maintained only for the last 32K strings.
-     * An index in this array is thus a window index modulo 32K.
-     */
-
-    Posf *head; /* Heads of the hash chains or NIL. */
-
-    uInt  ins_h;          /* hash index of string to be inserted */
-    uInt  hash_size;      /* number of elements in hash table */
-    uInt  hash_bits;      /* log2(hash_size) */
-    uInt  hash_mask;      /* hash_size-1 */
-
-    uInt  hash_shift;
-    /* Number of bits by which ins_h must be shifted at each input
-     * step. It must be such that after MIN_MATCH steps, the oldest
-     * byte no longer takes part in the hash key, that is:
-     *   hash_shift * MIN_MATCH >= hash_bits
-     */
-
-    long block_start;
-    /* Window position at the beginning of the current output block. Gets
-     * negative when the window is moved backwards.
-     */
-
-    uInt match_length;           /* length of best match */
-    IPos prev_match;             /* previous match */
-    int match_available;         /* set if previous match exists */
-    uInt strstart;               /* start of string to insert */
-    uInt match_start;            /* start of matching string */
-    uInt lookahead;              /* number of valid bytes ahead in window */
-
-    uInt prev_length;
-    /* Length of the best match at previous step. Matches not greater than this
-     * are discarded. This is used in the lazy match evaluation.
-     */
-
-    uInt max_chain_length;
-    /* To speed up deflation, hash chains are never searched beyond this
-     * length.  A higher limit improves compression ratio but degrades the
-     * speed.
-     */
-
-    uInt max_lazy_match;
-    /* Attempt to find a better match only when the current match is strictly
-     * smaller than this value. This mechanism is used only for compression
-     * levels >= 4.
-     */
-#   define max_insert_length  max_lazy_match
-    /* Insert new strings in the hash table only if the match length is not
-     * greater than this length. This saves time but degrades compression.
-     * max_insert_length is used only for compression levels <= 3.
-     */
-
-    int level;    /* compression level (1..9) */
-    int strategy; /* favor or force Huffman coding*/
-
-    uInt good_match;
-    /* Use a faster search when the previous match is longer than this */
-
-     int nice_match; /* Stop searching when current match exceeds this */
-
-                /* used by trees.c: */
-    /* Didn't use ct_data typedef below to supress compiler warning */
-    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
-    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
-    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
-
-    struct tree_desc_s l_desc;               /* desc. for literal tree */
-    struct tree_desc_s d_desc;               /* desc. for distance tree */
-    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
-
-    ush bl_count[MAX_BITS+1];
-    /* number of codes at each bit length for an optimal tree */
-
-    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
-    int heap_len;               /* number of elements in the heap */
-    int heap_max;               /* element of largest frequency */
-    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
-     * The same heap array is used to build all trees.
-     */
-
-    uch depth[2*L_CODES+1];
-    /* Depth of each subtree used as tie breaker for trees of equal frequency
-     */
-
-    uchf *l_buf;          /* buffer for literals or lengths */
-
-    uInt  lit_bufsize;
-    /* Size of match buffer for literals/lengths.  There are 4 reasons for
-     * limiting lit_bufsize to 64K:
-     *   - frequencies can be kept in 16 bit counters
-     *   - if compression is not successful for the first block, all input
-     *     data is still in the window so we can still emit a stored block even
-     *     when input comes from standard input.  (This can also be done for
-     *     all blocks if lit_bufsize is not greater than 32K.)
-     *   - if compression is not successful for a file smaller than 64K, we can
-     *     even emit a stored file instead of a stored block (saving 5 bytes).
-     *     This is applicable only for zip (not gzip or zlib).
-     *   - creating new Huffman trees less frequently may not provide fast
-     *     adaptation to changes in the input data statistics. (Take for
-     *     example a binary file with poorly compressible code followed by
-     *     a highly compressible string table.) Smaller buffer sizes give
-     *     fast adaptation but have of course the overhead of transmitting
-     *     trees more frequently.
-     *   - I can't count above 4
-     */
-
-    uInt last_lit;      /* running index in l_buf */
-
-    ushf *d_buf;
-    /* Buffer for distances. To simplify the code, d_buf and l_buf have
-     * the same number of elements. To use different lengths, an extra flag
-     * array would be necessary.
-     */
-
-    ulg opt_len;        /* bit length of current block with optimal trees */
-    ulg static_len;     /* bit length of current block with static trees */
-    ulg compressed_len; /* total bit length of compressed file */
-    uInt matches;       /* number of string matches in current block */
-    int last_eob_len;   /* bit length of EOB code for last block */
-
-#ifdef DEBUG_ZLIB
-    ulg bits_sent;      /* bit length of the compressed data */
-#endif
-
-    ush bi_buf;
-    /* Output buffer. bits are inserted starting at the bottom (least
-     * significant bits).
-     */
-    int bi_valid;
-    /* Number of valid bits in bi_buf.  All bits above the last valid bit
-     * are always zero.
-     */
-
-    uInt blocks_in_packet;
-    /* Number of blocks produced since the last time Z_PACKET_FLUSH
-     * was used.
-     */
-
-} FAR deflate_state;
-
-/* Output a byte on the stream.
- * IN assertion: there is enough room in pending_buf.
- */
-#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
-
-
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
-/* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
- */
-
-#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
-/* In order to simplify the code, particularly on 16 bit machines, match
- * distances are limited to MAX_DIST instead of WSIZE.
- */
-
-        /* in trees.c */
-local void ct_init       OF((deflate_state *s));
-local int  ct_tally      OF((deflate_state *s, int dist, int lc));
-local ulg ct_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
-                            int flush));
-local void ct_align      OF((deflate_state *s));
-local void ct_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
-                          int eof));
-local void ct_stored_type_only OF((deflate_state *s));
-
-
-/*+++++*/
-/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process depends on being able to identify portions
- *      of the input text which are identical to earlier input (within a
- *      sliding window trailing behind the input currently being processed).
- *
- *      The most straightforward technique turns out to be the fastest for
- *      most input files: try all possible matches and select the longest.
- *      The key feature of this algorithm is that insertions into the string
- *      dictionary are very simple and thus fast, and deletions are avoided
- *      completely. Insertions are performed at each input character, whereas
- *      string matches are performed only when the previous match ends. So it
- *      is preferable to spend more time in matches to allow very fast string
- *      insertions and avoid deletions. The matching algorithm for small
- *      strings is inspired from that of Rabin & Karp. A brute force approach
- *      is used to find longer strings when a small match has been found.
- *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
- *      (by Leonid Broukhis).
- *         A previous version of this file used a more sophisticated algorithm
- *      (by Fiala and Greene) which is guaranteed to run in linear amortized
- *      time, but has a larger average cost, uses more memory and is patented.
- *      However the F&G algorithm may be faster for some highly redundant
- *      files if the parameter max_chain_length (described below) is too large.
- *
- *  ACKNOWLEDGEMENTS
- *
- *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
- *      I found it in 'freeze' written by Leonid Broukhis.
- *      Thanks to many people for bug reports and testing.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
- *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
- *
- *      A description of the Rabin and Karp algorithm is given in the book
- *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
- *
- *      Fiala,E.R., and Greene,D.H.
- *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
- *
- */
-
-/* From: deflate.c,v 1.8 1995/05/03 17:27:08 jloup Exp */
-
-local char zlib_copyright[] = " deflate Copyright 1995 Jean-loup Gailly ";
-/*
-  If you use the zlib library in a product, an acknowledgment is welcome
-  in the documentation of your product. If for some reason you cannot
-  include such an acknowledgment, I would appreciate that you keep this
-  copyright string in the executable of your product.
- */
-
-#define NIL 0
-/* Tail of hash chains */
-
-#ifndef TOO_FAR
-#  define TOO_FAR 4096
-#endif
-/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
-
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
-/* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
- */
-
-/* Values for max_lazy_match, good_match and max_chain_length, depending on
- * the desired pack level (0..9). The values given below have been tuned to
- * exclude worst case performance for pathological files. Better values may be
- * found for specific files.
- */
-
-typedef struct config_s {
-   ush good_length; /* reduce lazy search above this match length */
-   ush max_lazy;    /* do not perform lazy search above this match length */
-   ush nice_length; /* quit search above this match length */
-   ush max_chain;
-} config;
-
-local config configuration_table[10] = {
-/*      good lazy nice chain */
-/* 0 */ {0,    0,  0,    0},  /* store only */
-/* 1 */ {4,    4,  8,    4},  /* maximum speed, no lazy matches */
-/* 2 */ {4,    5, 16,    8},
-/* 3 */ {4,    6, 32,   32},
-
-/* 4 */ {4,    4, 16,   16},  /* lazy matches */
-/* 5 */ {8,   16, 32,   32},
-/* 6 */ {8,   16, 128, 128},
-/* 7 */ {8,   32, 128, 256},
-/* 8 */ {32, 128, 258, 1024},
-/* 9 */ {32, 258, 258, 4096}}; /* maximum compression */
-
-/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
- * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
- * meaning.
- */
-
-#define EQUAL 0
-/* result of memcmp for equal strings */
-
-/* ===========================================================================
- *  Prototypes for local functions.
- */
-
-local void fill_window   OF((deflate_state *s));
-local int  deflate_fast  OF((deflate_state *s, int flush));
-local int  deflate_slow  OF((deflate_state *s, int flush));
-local void lm_init       OF((deflate_state *s));
-local int longest_match  OF((deflate_state *s, IPos cur_match));
-local void putShortMSB   OF((deflate_state *s, uInt b));
-local void flush_pending OF((z_stream *strm));
-local int read_buf       OF((z_stream *strm, charf *buf, unsigned size));
-#ifdef ASMV
-      void match_init OF((void)); /* asm code initialization */
-#endif
-
-#ifdef DEBUG_ZLIB
-local  void check_match OF((deflate_state *s, IPos start, IPos match,
-                            int length));
-#endif
-
-
-/* ===========================================================================
- * Update a hash value with the given input byte
- * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
- *    input characters, so that a running hash key can be computed from the
- *    previous key instead of complete recalculation each time.
- */
-#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
-
-
-/* ===========================================================================
- * Insert string str in the dictionary and set match_head to the previous head
- * of the hash chain (the most recent string with same hash key). Return
- * the previous length of the hash chain.
- * IN  assertion: all calls to to INSERT_STRING are made with consecutive
- *    input characters and the first MIN_MATCH bytes of str are valid
- *    (except for the last MIN_MATCH-1 bytes of the input file).
- */
-#define INSERT_STRING(s, str, match_head) \
-   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
-    s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
-    s->head[s->ins_h] = (str))
-
-/* ===========================================================================
- * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
- * prev[] will be initialized on the fly.
- */
-#define CLEAR_HASH(s) \
-    s->head[s->hash_size-1] = NIL; \
-    zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
-
-/* ========================================================================= */
-int deflateInit (strm, level)
-    z_stream *strm;
-    int level;
-{
-    return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
-                        0, 0);
-    /* To do: ignore strm->next_in if we use it as window */
-}
-
-/* ========================================================================= */
-int deflateInit2 (strm, level, method, windowBits, memLevel,
-                 strategy, minCompression)
-    z_stream *strm;
-    int  level;
-    int  method;
-    int  windowBits;
-    int  memLevel;
-    int  strategy;
-    int  minCompression;
-{
-    deflate_state *s;
-    int noheader = 0;
-
-    if (strm == Z_NULL) return Z_STREAM_ERROR;
-
-    strm->msg = Z_NULL;
-/*    if (strm->zalloc == Z_NULL) strm->zalloc = zcalloc; */
-/*    if (strm->zfree == Z_NULL) strm->zfree = zcfree; */
-
-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
-
-    if (windowBits < 0) { /* undocumented feature: suppress zlib header */
-        noheader = 1;
-        windowBits = -windowBits;
-    }
-    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != DEFLATED ||
-        windowBits < 8 || windowBits > 15 || level < 1 || level > 9) {
-        return Z_STREAM_ERROR;
-    }
-    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
-    if (s == Z_NULL) return Z_MEM_ERROR;
-    strm->state = (struct internal_state FAR *)s;
-    s->strm = strm;
-
-    s->noheader = noheader;
-    s->w_bits = windowBits;
-    s->w_size = 1 << s->w_bits;
-    s->w_mask = s->w_size - 1;
-
-    s->hash_bits = memLevel + 7;
-    s->hash_size = 1 << s->hash_bits;
-    s->hash_mask = s->hash_size - 1;
-    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
-
-    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
-    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
-    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
-
-    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
-
-    s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush));
-
-    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
-        s->pending_buf == Z_NULL) {
-        strm->msg = z_errmsg[1-Z_MEM_ERROR];
-        deflateEnd (strm);
-        return Z_MEM_ERROR;
-    }
-    s->d_buf = (ushf *) &(s->pending_buf[s->lit_bufsize]);
-    s->l_buf = (uchf *) &(s->pending_buf[3*s->lit_bufsize]);
-    /* We overlay pending_buf and d_buf+l_buf. This works since the average
-     * output size for (length,distance) codes is <= 32 bits (worst case
-     * is 15+15+13=33).
-     */
-
-    s->level = level;
-    s->strategy = strategy;
-    s->method = (Byte)method;
-    s->minCompr = minCompression;
-    s->blocks_in_packet = 0;
-
-    return deflateReset(strm);
-}
-
-/* ========================================================================= */
-int deflateReset (strm)
-    z_stream *strm;
-{
-    deflate_state *s;
-    
-    if (strm == Z_NULL || strm->state == Z_NULL ||
-        strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR;
-
-    strm->total_in = strm->total_out = 0;
-    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
-    strm->data_type = Z_UNKNOWN;
-
-    s = (deflate_state *)strm->state;
-    s->pending = 0;
-    s->pending_out = s->pending_buf;
-
-    if (s->noheader < 0) {
-        s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
-    }
-    s->status = s->noheader ? BUSY_STATE : INIT_STATE;
-    s->adler = 1;
-
-    ct_init(s);
-    lm_init(s);
-
-    return Z_OK;
-}
-
-/* =========================================================================
- * Put a short in the pending buffer. The 16-bit value is put in MSB order.
- * IN assertion: the stream state is correct and there is enough room in
- * pending_buf.
- */
-local void putShortMSB (s, b)
-    deflate_state *s;
-    uInt b;
-{
-    put_byte(s, (Byte)(b >> 8));
-    put_byte(s, (Byte)(b & 0xff));
-}   
-
-/* =========================================================================
- * Flush as much pending output as possible.
- */
-local void flush_pending(strm)
-    z_stream *strm;
-{
-    deflate_state *state = (deflate_state *) strm->state;
-    unsigned len = state->pending;
-
-    if (len > strm->avail_out) len = strm->avail_out;
-    if (len == 0) return;
-
-    if (strm->next_out != NULL) {
-       zmemcpy(strm->next_out, state->pending_out, len);
-       strm->next_out += len;
-    }
-    state->pending_out += len;
-    strm->total_out += len;
-    strm->avail_out -= len;
-    state->pending -= len;
-    if (state->pending == 0) {
-        state->pending_out = state->pending_buf;
-    }
-}
-
-/* ========================================================================= */
-int deflate (strm, flush)
-    z_stream *strm;
-    int flush;
-{
-    deflate_state *state = (deflate_state *) strm->state;
-
-    if (strm == Z_NULL || state == Z_NULL) return Z_STREAM_ERROR;
-    
-    if (strm->next_in == Z_NULL && strm->avail_in != 0) {
-        ERR_RETURN(strm, Z_STREAM_ERROR);
-    }
-    if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
-
-    state->strm = strm; /* just in case */
-
-    /* Write the zlib header */
-    if (state->status == INIT_STATE) {
-
-        uInt header = (DEFLATED + ((state->w_bits-8)<<4)) << 8;
-        uInt level_flags = (state->level-1) >> 1;
-
-        if (level_flags > 3) level_flags = 3;
-        header |= (level_flags << 6);
-        header += 31 - (header % 31);
-
-        state->status = BUSY_STATE;
-        putShortMSB(state, header);
-    }
-
-    /* Flush as much pending output as possible */
-    if (state->pending != 0) {
-        flush_pending(strm);
-        if (strm->avail_out == 0) return Z_OK;
-    }
-
-    /* If we came back in here to get the last output from
-     * a previous flush, we're done for now.
-     */
-    if (state->status == FLUSH_STATE) {
-       state->status = BUSY_STATE;
-       if (flush != Z_NO_FLUSH && flush != Z_FINISH)
-           return Z_OK;
-    }
-
-    /* User must not provide more input after the first FINISH: */
-    if (state->status == FINISH_STATE && strm->avail_in != 0) {
-        ERR_RETURN(strm, Z_BUF_ERROR);
-    }
-
-    /* Start a new block or continue the current one.
-     */
-    if (strm->avail_in != 0 || state->lookahead != 0 ||
-        (flush == Z_FINISH && state->status != FINISH_STATE)) {
-        int quit;
-
-        if (flush == Z_FINISH) {
-            state->status = FINISH_STATE;
-        }
-        if (state->level <= 3) {
-            quit = deflate_fast(state, flush);
-        } else {
-            quit = deflate_slow(state, flush);
-        }
-        if (quit || strm->avail_out == 0)
-           return Z_OK;
-        /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
-         * of deflate should use the same flush parameter to make sure
-         * that the flush is complete. So we don't have to output an
-         * empty block here, this will be done at next call. This also
-         * ensures that for a very small output buffer, we emit at most
-         * one empty block.
-         */
-    }
-
-    /* If a flush was requested, we have a little more to output now. */
-    if (flush != Z_NO_FLUSH && flush != Z_FINISH
-       && state->status != FINISH_STATE) {
-       switch (flush) {
-       case Z_PARTIAL_FLUSH:
-           ct_align(state);
-           break;
-       case Z_PACKET_FLUSH:
-           /* Output just the 3-bit `stored' block type value,
-              but not a zero length. */
-           ct_stored_type_only(state);
-           break;
-       default:
-           ct_stored_block(state, (char*)0, 0L, 0);
-           /* For a full flush, this empty block will be recognized
-            * as a special marker by inflate_sync().
-            */
-           if (flush == Z_FULL_FLUSH) {
-               CLEAR_HASH(state);             /* forget history */
-           }
-       }
-       flush_pending(strm);
-       if (strm->avail_out == 0) {
-           /* We'll have to come back to get the rest of the output;
-            * this ensures we don't output a second zero-length stored
-            * block (or whatever).
-            */
-           state->status = FLUSH_STATE;
-           return Z_OK;
-       }
-    }
-
-    Assert(strm->avail_out > 0, "bug2");
-
-    if (flush != Z_FINISH) return Z_OK;
-    if (state->noheader) return Z_STREAM_END;
-
-    /* Write the zlib trailer (adler32) */
-    putShortMSB(state, (uInt)(state->adler >> 16));
-    putShortMSB(state, (uInt)(state->adler & 0xffff));
-    flush_pending(strm);
-    /* If avail_out is zero, the application will call deflate again
-     * to flush the rest.
-     */
-    state->noheader = -1; /* write the trailer only once! */
-    return state->pending != 0 ? Z_OK : Z_STREAM_END;
-}
-
-/* ========================================================================= */
-int deflateEnd (strm)
-    z_stream *strm;
-{
-    deflate_state *state = (deflate_state *) strm->state;
-
-    if (strm == Z_NULL || state == Z_NULL) return Z_STREAM_ERROR;
-
-    TRY_FREE(strm, state->window, state->w_size * 2 * sizeof(Byte));
-    TRY_FREE(strm, state->prev, state->w_size * sizeof(Pos));
-    TRY_FREE(strm, state->head, state->hash_size * sizeof(Pos));
-    TRY_FREE(strm, state->pending_buf, state->lit_bufsize * 2 * sizeof(ush));
-
-    ZFREE(strm, state, sizeof(deflate_state));
-    strm->state = Z_NULL;
-
-    return Z_OK;
-}
-
-/* ===========================================================================
- * Read a new buffer from the current input stream, update the adler32
- * and total number of bytes read.
- */
-local int read_buf(strm, buf, size)
-    z_stream *strm;
-    charf *buf;
-    unsigned size;
-{
-    unsigned len = strm->avail_in;
-    deflate_state *state = (deflate_state *) strm->state;
-
-    if (len > size) len = size;
-    if (len == 0) return 0;
-
-    strm->avail_in  -= len;
-
-    if (!state->noheader) {
-        state->adler = adler32(state->adler, strm->next_in, len);
-    }
-    zmemcpy(buf, strm->next_in, len);
-    strm->next_in  += len;
-    strm->total_in += len;
-
-    return (int)len;
-}
-
-/* ===========================================================================
- * Initialize the "longest match" routines for a new zlib stream
- */
-local void lm_init (s)
-    deflate_state *s;
-{
-    s->window_size = (ulg)2L*s->w_size;
-
-    CLEAR_HASH(s);
-
-    /* Set the default configuration parameters:
-     */
-    s->max_lazy_match   = configuration_table[s->level].max_lazy;
-    s->good_match       = configuration_table[s->level].good_length;
-    s->nice_match       = configuration_table[s->level].nice_length;
-    s->max_chain_length = configuration_table[s->level].max_chain;
-
-    s->strstart = 0;
-    s->block_start = 0L;
-    s->lookahead = 0;
-    s->match_length = MIN_MATCH-1;
-    s->match_available = 0;
-    s->ins_h = 0;
-#ifdef ASMV
-    match_init(); /* initialize the asm code */
-#endif
-}
-
-/* ===========================================================================
- * Set match_start to the longest match starting at the given string and
- * return its length. Matches shorter or equal to prev_length are discarded,
- * in which case the result is equal to prev_length and match_start is
- * garbage.
- * IN assertions: cur_match is the head of the hash chain for the current
- *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
- */
-#ifndef ASMV
-/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
- * match.S. The code will be functionally equivalent.
- */
-local int longest_match(s, cur_match)
-    deflate_state *s;
-    IPos cur_match;                             /* current match */
-{
-    unsigned chain_length = s->max_chain_length;/* max hash chain length */
-    register Bytef *scan = s->window + s->strstart; /* current string */
-    register Bytef *match;                       /* matched string */
-    register int len;                           /* length of current match */
-    int best_len = s->prev_length;              /* best match length so far */
-    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
-        s->strstart - (IPos)MAX_DIST(s) : NIL;
-    /* Stop when cur_match becomes <= limit. To simplify the code,
-     * we prevent matches with the string of window index 0.
-     */
-    Posf *prev = s->prev;
-    uInt wmask = s->w_mask;
-
-#ifdef UNALIGNED_OK
-    /* Compare two bytes at a time. Note: this is not always beneficial.
-     * Try with and without -DUNALIGNED_OK to check.
-     */
-    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
-    register ush scan_start = *(ushf*)scan;
-    register ush scan_end   = *(ushf*)(scan+best_len-1);
-#else
-    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
-    register Byte scan_end1  = scan[best_len-1];
-    register Byte scan_end   = scan[best_len];
-#endif
-
-    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
-     * It is easy to get rid of this optimization if necessary.
-     */
-    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
-
-    /* Do not waste too much time if we already have a good match: */
-    if (s->prev_length >= s->good_match) {
-        chain_length >>= 2;
-    }
-    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
-
-    do {
-        Assert(cur_match < s->strstart, "no future");
-        match = s->window + cur_match;
-
-        /* Skip to next match if the match length cannot increase
-         * or if the match length is less than 2:
-         */
-#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
-        /* This code assumes sizeof(unsigned short) == 2. Do not use
-         * UNALIGNED_OK if your compiler uses a different size.
-         */
-        if (*(ushf*)(match+best_len-1) != scan_end ||
-            *(ushf*)match != scan_start) continue;
-
-        /* It is not necessary to compare scan[2] and match[2] since they are
-         * always equal when the other bytes match, given that the hash keys
-         * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
-         * strstart+3, +5, ... up to strstart+257. We check for insufficient
-         * lookahead only every 4th comparison; the 128th check will be made
-         * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
-         * necessary to put more guard bytes at the end of the window, or
-         * to check more often for insufficient lookahead.
-         */
-        Assert(scan[2] == match[2], "scan[2]?");
-        scan++, match++;
-        do {
-        } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
-                 scan < strend);
-        /* The funny "do {}" generates better code on most compilers */
-
-        /* Here, scan <= window+strstart+257 */
-        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-        if (*scan == *match) scan++;
-
-        len = (MAX_MATCH - 1) - (int)(strend-scan);
-        scan = strend - (MAX_MATCH-1);
-
-#else /* UNALIGNED_OK */
-
-        if (match[best_len]   != scan_end  ||
-            match[best_len-1] != scan_end1 ||
-            *match            != *scan     ||
-            *++match          != scan[1])      continue;
-
-        /* The check at best_len-1 can be removed because it will be made
-         * again later. (This heuristic is not always a win.)
-         * It is not necessary to compare scan[2] and match[2] since they
-         * are always equal when the other bytes match, given that
-         * the hash keys are equal and that HASH_BITS >= 8.
-         */
-        scan += 2, match++;
-        Assert(*scan == *match, "match[2]?");
-
-        /* We check for insufficient lookahead only every 8th comparison;
-         * the 256th check will be made at strstart+258.
-         */
-        do {
-        } while (*++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 *++scan == *++match && *++scan == *++match &&
-                 scan < strend);
-
-        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
-
-        len = MAX_MATCH - (int)(strend - scan);
-        scan = strend - MAX_MATCH;
-
-#endif /* UNALIGNED_OK */
-
-        if (len > best_len) {
-            s->match_start = cur_match;
-            best_len = len;
-            if (len >= s->nice_match) break;
-#ifdef UNALIGNED_OK
-            scan_end = *(ushf*)(scan+best_len-1);
-#else
-            scan_end1  = scan[best_len-1];
-            scan_end   = scan[best_len];
-#endif
-        }
-    } while ((cur_match = prev[cur_match & wmask]) > limit
-             && --chain_length != 0);
-
-    return best_len;
-}
-#endif /* ASMV */
-
-#ifdef DEBUG_ZLIB
-/* ===========================================================================
- * Check that the match at match_start is indeed a match.
- */
-local void check_match(s, start, match, length)
-    deflate_state *s;
-    IPos start, match;
-    int length;
-{
-    /* check that the match is indeed a match */
-    if (memcmp((charf *)s->window + match,
-                (charf *)s->window + start, length) != EQUAL) {
-        fprintf(stderr,
-            " start %u, match %u, length %d\n",
-            start, match, length);
-        do { fprintf(stderr, "%c%c", s->window[match++],
-                     s->window[start++]); } while (--length != 0);
-        z_error("invalid match");
-    }
-    if (verbose > 1) {
-        fprintf(stderr,"\\[%d,%d]", start-match, length);
-        do { putc(s->window[start++], stderr); } while (--length != 0);
-    }
-}
-#else
-#  define check_match(s, start, match, length)
-#endif
-
-/* ===========================================================================
- * Fill the window when the lookahead becomes insufficient.
- * Updates strstart and lookahead.
- *
- * IN assertion: lookahead < MIN_LOOKAHEAD
- * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
- *    At least one byte has been read, or avail_in == 0; reads are
- *    performed for at least two bytes (required for the zip translate_eol
- *    option -- not supported here).
- */
-local void fill_window(s)
-    deflate_state *s;
-{
-    register unsigned n, m;
-    register Posf *p;
-    unsigned more;    /* Amount of free space at the end of the window. */
-    uInt wsize = s->w_size;
-
-    do {
-        more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
-
-        /* Deal with !@#$% 64K limit: */
-        if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
-            more = wsize;
-        } else if (more == (unsigned)(-1)) {
-            /* Very unlikely, but possible on 16 bit machine if strstart == 0
-             * and lookahead == 1 (input done one byte at time)
-             */
-            more--;
-
-        /* If the window is almost full and there is insufficient lookahead,
-         * move the upper half to the lower one to make room in the upper half.
-         */
-        } else if (s->strstart >= wsize+MAX_DIST(s)) {
-
-            /* By the IN assertion, the window is not empty so we can't confuse
-             * more == 0 with more == 64K on a 16 bit machine.
-             */
-            zmemcpy((charf *)s->window, (charf *)s->window+wsize,
-                   (unsigned)wsize);
-            s->match_start -= wsize;
-            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
-
-            s->block_start -= (long) wsize;
-
-            /* Slide the hash table (could be avoided with 32 bit values
-               at the expense of memory usage):
-             */
-            n = s->hash_size;
-            p = &s->head[n];
-            do {
-                m = *--p;
-                *p = (Pos)(m >= wsize ? m-wsize : NIL);
-            } while (--n);
-
-            n = wsize;
-            p = &s->prev[n];
-            do {
-                m = *--p;
-                *p = (Pos)(m >= wsize ? m-wsize : NIL);
-                /* If n is not on any hash chain, prev[n] is garbage but
-                 * its value will never be used.
-                 */
-            } while (--n);
-
-            more += wsize;
-        }
-        if (s->strm->avail_in == 0) return;
-
-        /* If there was no sliding:
-         *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
-         *    more == window_size - lookahead - strstart
-         * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
-         * => more >= window_size - 2*WSIZE + 2
-         * In the BIG_MEM or MMAP case (not yet supported),
-         *   window_size == input_size + MIN_LOOKAHEAD  &&
-         *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
-         * Otherwise, window_size == 2*WSIZE so more >= 2.
-         * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
-         */
-        Assert(more >= 2, "more < 2");
-
-        n = read_buf(s->strm, (charf *)s->window + s->strstart + s->lookahead,
-                     more);
-        s->lookahead += n;
-
-        /* Initialize the hash value now that we have some input: */
-        if (s->lookahead >= MIN_MATCH) {
-            s->ins_h = s->window[s->strstart];
-            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
-#if MIN_MATCH != 3
-            Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-        }
-        /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
-         * but this is not important since only literal bytes will be emitted.
-         */
-
-    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
-}
-
-/* ===========================================================================
- * Flush the current block, with given end-of-file flag.
- * IN assertion: strstart is set to the end of the current match.
- */
-#define FLUSH_BLOCK_ONLY(s, flush) { \
-   ct_flush_block(s, (s->block_start >= 0L ? \
-           (charf *)&s->window[(unsigned)s->block_start] : \
-           (charf *)Z_NULL), (long)s->strstart - s->block_start, (flush)); \
-   s->block_start = s->strstart; \
-   flush_pending(s->strm); \
-   Tracev((stderr,"[FLUSH]")); \
-}
-
-/* Same but force premature exit if necessary. */
-#define FLUSH_BLOCK(s, flush) { \
-   FLUSH_BLOCK_ONLY(s, flush); \
-   if (s->strm->avail_out == 0) return 1; \
-}
-
-/* ===========================================================================
- * Compress as much as possible from the input stream, return true if
- * processing was terminated prematurely (no more input or output space).
- * This function does not perform lazy evaluationof matches and inserts
- * new strings in the dictionary only for unmatched strings or for short
- * matches. It is used only for the fast compression options.
- */
-local int deflate_fast(s, flush)
-    deflate_state *s;
-    int flush;
-{
-    IPos hash_head = NIL; /* head of the hash chain */
-    int bflush;     /* set if current block must be flushed */
-
-    s->prev_length = MIN_MATCH-1;
-
-    for (;;) {
-        /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
-         * string following the next match.
-         */
-        if (s->lookahead < MIN_LOOKAHEAD) {
-            fill_window(s);
-            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1;
-
-            if (s->lookahead == 0) break; /* flush the current block */
-        }
-
-        /* Insert the string window[strstart .. strstart+2] in the
-         * dictionary, and set hash_head to the head of the hash chain:
-         */
-        if (s->lookahead >= MIN_MATCH) {
-            INSERT_STRING(s, s->strstart, hash_head);
-        }
-
-        /* Find the longest match, discarding those <= prev_length.
-         * At this point we have always match_length < MIN_MATCH
-         */
-        if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
-            /* To simplify the code, we prevent matches with the string
-             * of window index 0 (in particular we have to avoid a match
-             * of the string with itself at the start of the input file).
-             */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
-                s->match_length = longest_match (s, hash_head);
-            }
-            /* longest_match() sets match_start */
-
-            if (s->match_length > s->lookahead) s->match_length = s->lookahead;
-        }
-        if (s->match_length >= MIN_MATCH) {
-            check_match(s, s->strstart, s->match_start, s->match_length);
-
-            bflush = ct_tally(s, s->strstart - s->match_start,
-                              s->match_length - MIN_MATCH);
-
-            s->lookahead -= s->match_length;
-
-            /* Insert new strings in the hash table only if the match length
-             * is not too large. This saves time but degrades compression.
-             */
-            if (s->match_length <= s->max_insert_length &&
-                s->lookahead >= MIN_MATCH) {
-                s->match_length--; /* string at strstart already in hash table */
-                do {
-                    s->strstart++;
-                    INSERT_STRING(s, s->strstart, hash_head);
-                    /* strstart never exceeds WSIZE-MAX_MATCH, so there are
-                     * always MIN_MATCH bytes ahead.
-                     */
-                } while (--s->match_length != 0);
-                s->strstart++; 
-            } else {
-                s->strstart += s->match_length;
-                s->match_length = 0;
-                s->ins_h = s->window[s->strstart];
-                UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
-#if MIN_MATCH != 3
-                Call UPDATE_HASH() MIN_MATCH-3 more times
-#endif
-                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
-                 * matter since it will be recomputed at next deflate call.
-                 */
-            }
-        } else {
-            /* No match, output a literal byte */
-            Tracevv((stderr,"%c", s->window[s->strstart]));
-            bflush = ct_tally (s, 0, s->window[s->strstart]);
-            s->lookahead--;
-            s->strstart++; 
-        }
-        if (bflush) FLUSH_BLOCK(s, Z_NO_FLUSH);
-    }
-    FLUSH_BLOCK(s, flush);
-    return 0; /* normal exit */
-}
-
-/* ===========================================================================
- * Same as above, but achieves better compression. We use a lazy
- * evaluation for matches: a match is finally adopted only if there is
- * no better match at the next window position.
- */
-local int deflate_slow(s, flush)
-    deflate_state *s;
-    int flush;
-{
-    IPos hash_head = NIL;    /* head of hash chain */
-    int bflush;              /* set if current block must be flushed */
-
-    /* Process the input block. */
-    for (;;) {
-        /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
-         * string following the next match.
-         */
-        if (s->lookahead < MIN_LOOKAHEAD) {
-            fill_window(s);
-            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) return 1;
-
-            if (s->lookahead == 0) break; /* flush the current block */
-        }
-
-        /* Insert the string window[strstart .. strstart+2] in the
-         * dictionary, and set hash_head to the head of the hash chain:
-         */
-        if (s->lookahead >= MIN_MATCH) {
-            INSERT_STRING(s, s->strstart, hash_head);
-        }
-
-        /* Find the longest match, discarding those <= prev_length.
-         */
-        s->prev_length = s->match_length, s->prev_match = s->match_start;
-        s->match_length = MIN_MATCH-1;
-
-        if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
-            s->strstart - hash_head <= MAX_DIST(s)) {
-            /* To simplify the code, we prevent matches with the string
-             * of window index 0 (in particular we have to avoid a match
-             * of the string with itself at the start of the input file).
-             */
-            if (s->strategy != Z_HUFFMAN_ONLY) {
-                s->match_length = longest_match (s, hash_head);
-            }
-            /* longest_match() sets match_start */
-            if (s->match_length > s->lookahead) s->match_length = s->lookahead;
-
-            if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
-                 (s->match_length == MIN_MATCH &&
-                  s->strstart - s->match_start > TOO_FAR))) {
-
-                /* If prev_match is also MIN_MATCH, match_start is garbage
-                 * but we will ignore the current match anyway.
-                 */
-                s->match_length = MIN_MATCH-1;
-            }
-        }
-        /* If there was a match at the previous step and the current
-         * match is not better, output the previous match:
-         */
-        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
-            uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
-            /* Do not insert strings in hash table beyond this. */
-
-            check_match(s, s->strstart-1, s->prev_match, s->prev_length);
-
-            bflush = ct_tally(s, s->strstart -1 - s->prev_match,
-                              s->prev_length - MIN_MATCH);
-
-            /* Insert in hash table all strings up to the end of the match.
-             * strstart-1 and strstart are already inserted. If there is not
-             * enough lookahead, the last two strings are not inserted in
-             * the hash table.
-             */
-            s->lookahead -= s->prev_length-1;
-            s->prev_length -= 2;
-            do {
-                if (++s->strstart <= max_insert) {
-                    INSERT_STRING(s, s->strstart, hash_head);
-                }
-            } while (--s->prev_length != 0);
-            s->match_available = 0;
-            s->match_length = MIN_MATCH-1;
-            s->strstart++;
-
-            if (bflush) FLUSH_BLOCK(s, Z_NO_FLUSH);
-
-        } else if (s->match_available) {
-            /* If there was no match at the previous position, output a
-             * single literal. If there was a match but the current match
-             * is longer, truncate the previous match to a single literal.
-             */
-            Tracevv((stderr,"%c", s->window[s->strstart-1]));
-            if (ct_tally (s, 0, s->window[s->strstart-1])) {
-                FLUSH_BLOCK_ONLY(s, Z_NO_FLUSH);
-            }
-            s->strstart++;
-            s->lookahead--;
-            if (s->strm->avail_out == 0) return 1;
-        } else {
-            /* There is no previous match to compare with, wait for
-             * the next step to decide.
-             */
-            s->match_available = 1;
-            s->strstart++;
-            s->lookahead--;
-        }
-    }
-    Assert (flush != Z_NO_FLUSH, "no flush?");
-    if (s->match_available) {
-        Tracevv((stderr,"%c", s->window[s->strstart-1]));
-        ct_tally (s, 0, s->window[s->strstart-1]);
-        s->match_available = 0;
-    }
-    FLUSH_BLOCK(s, flush);
-    return 0;
-}
-
-
-/*+++++*/
-/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/*
- *  ALGORITHM
- *
- *      The "deflation" process uses several Huffman trees. The more
- *      common source values are represented by shorter bit sequences.
- *
- *      Each code tree is stored in a compressed form which is itself
- * a Huffman encoding of the lengths of all the code strings (in
- * ascending order by source values).  The actual code strings are
- * reconstructed from the lengths in the inflate process, as described
- * in the deflate specification.
- *
- *  REFERENCES
- *
- *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
- *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
- *
- *      Storer, James A.
- *          Data Compression:  Methods and Theory, pp. 49-50.
- *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
- *
- *      Sedgewick, R.
- *          Algorithms, p290.
- *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
- */
-
-/* From: trees.c,v 1.5 1995/05/03 17:27:12 jloup Exp */
-
-#ifdef DEBUG_ZLIB
-#  include <ctype.h>
-#endif
-
-/* ===========================================================================
- * Constants
- */
-
-#define MAX_BL_BITS 7
-/* Bit length codes must not exceed MAX_BL_BITS bits */
-
-#define END_BLOCK 256
-/* end of block literal code */
-
-#define REP_3_6      16
-/* repeat previous bit length 3-6 times (2 bits of repeat count) */
-
-#define REPZ_3_10    17
-/* repeat a zero length 3-10 times  (3 bits of repeat count) */
-
-#define REPZ_11_138  18
-/* repeat a zero length 11-138 times  (7 bits of repeat count) */
-
-local int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
-   = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
-
-local int extra_dbits[D_CODES] /* extra bits for each distance code */
-   = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
-
-local int extra_blbits[BL_CODES]/* extra bits for each bit length code */
-   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
-
-local uch bl_order[BL_CODES]
-   = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
-/* The lengths of the bit length codes are sent in order of decreasing
- * probability, to avoid transmitting the lengths for unused bit length codes.
- */
-
-#define Buf_size (8 * 2*sizeof(char))
-/* Number of bits used within bi_buf. (bi_buf might be implemented on
- * more than 16 bits on some systems.)
- */
-
-/* ===========================================================================
- * Local data. These are initialized only once.
- * To do: initialize at compile time to be completely reentrant. ???
- */
-
-local ct_data static_ltree[L_CODES+2];
-/* The static literal tree. Since the bit lengths are imposed, there is no
- * need for the L_CODES extra codes used during heap construction. However
- * The codes 286 and 287 are needed to build a canonical tree (see ct_init
- * below).
- */
-
-local ct_data static_dtree[D_CODES];
-/* The static distance tree. (Actually a trivial tree since all codes use
- * 5 bits.)
- */
-
-local uch dist_code[512];
-/* distance codes. The first 256 values correspond to the distances
- * 3 .. 258, the last 256 values correspond to the top 8 bits of
- * the 15 bit distances.
- */
-
-local uch length_code[MAX_MATCH-MIN_MATCH+1];
-/* length code for each normalized match length (0 == MIN_MATCH) */
-
-local int base_length[LENGTH_CODES];
-/* First normalized length for each code (0 = MIN_MATCH) */
-
-local int base_dist[D_CODES];
-/* First normalized distance for each code (0 = distance of 1) */
-
-struct static_tree_desc_s {
-    ct_data *static_tree;        /* static tree or NULL */
-    intf    *extra_bits;         /* extra bits for each code or NULL */
-    int     extra_base;          /* base index for extra_bits */
-    int     elems;               /* max number of elements in the tree */
-    int     max_length;          /* max bit length for the codes */
-};
-
-local static_tree_desc  static_l_desc =
-{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
-
-local static_tree_desc  static_d_desc =
-{static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS};
-
-local static_tree_desc  static_bl_desc =
-{(ct_data *)0, extra_blbits, 0,      BL_CODES, MAX_BL_BITS};
-
-/* ===========================================================================
- * Local (static) routines in this file.
- */
-
-local void ct_static_init OF((void));
-local void init_block     OF((deflate_state *s));
-local void pqdownheap     OF((deflate_state *s, ct_data *tree, int k));
-local void gen_bitlen     OF((deflate_state *s, tree_desc *desc));
-local void gen_codes      OF((ct_data *tree, int max_code, ushf *bl_count));
-local void build_tree     OF((deflate_state *s, tree_desc *desc));
-local void scan_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
-local int  build_bl_tree  OF((deflate_state *s));
-local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
-                              int blcodes));
-local void compress_block OF((deflate_state *s, ct_data *ltree,
-                              ct_data *dtree));
-local void set_data_type  OF((deflate_state *s));
-local unsigned bi_reverse OF((unsigned value, int length));
-local void bi_windup      OF((deflate_state *s));
-local void bi_flush       OF((deflate_state *s));
-local void copy_block     OF((deflate_state *s, charf *buf, unsigned len,
-                              int header));
-
-#ifndef DEBUG_ZLIB
-#  define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
-   /* Send a code of the given tree. c and tree must not have side effects */
-
-#else /* DEBUG_ZLIB */
-#  define send_code(s, c, tree) \
-     { if (verbose>1) fprintf(stderr,"\ncd %3d ",(c)); \
-       send_bits(s, tree[c].Code, tree[c].Len); }
-#endif
-
-#define d_code(dist) \
-   ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)])
-/* Mapping from a distance to a distance code. dist is the distance - 1 and
- * must not have side effects. dist_code[256] and dist_code[257] are never
- * used.
- */
-
-/* ===========================================================================
- * Output a short LSB first on the stream.
- * IN assertion: there is enough room in pendingBuf.
- */
-#define put_short(s, w) { \
-    put_byte(s, (uch)((w) & 0xff)); \
-    put_byte(s, (uch)((ush)(w) >> 8)); \
-}
-
-/* ===========================================================================
- * Send a value on a given number of bits.
- * IN assertion: length <= 16 and value fits in length bits.
- */
-#ifdef DEBUG_ZLIB
-local void send_bits      OF((deflate_state *s, int value, int length));
-
-local void send_bits(s, value, length)
-    deflate_state *s;
-    int value;  /* value to send */
-    int length; /* number of bits */
-{
-    Tracev((stderr," l %2d v %4x ", length, value));
-    Assert(length > 0 && length <= 15, "invalid length");
-    s->bits_sent += (ulg)length;
-
-    /* If not enough room in bi_buf, use (valid) bits from bi_buf and
-     * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
-     * unused bits in value.
-     */
-    if (s->bi_valid > (int)Buf_size - length) {
-        s->bi_buf |= (value << s->bi_valid);
-        put_short(s, s->bi_buf);
-        s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
-        s->bi_valid += length - Buf_size;
-    } else {
-        s->bi_buf |= value << s->bi_valid;
-        s->bi_valid += length;
-    }
-}
-#else /* !DEBUG_ZLIB */
-
-#define send_bits(s, value, length) \
-{ int len = length;\
-  if (s->bi_valid > (int)Buf_size - len) {\
-    int val = value;\
-    s->bi_buf |= (val << s->bi_valid);\
-    put_short(s, s->bi_buf);\
-    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
-    s->bi_valid += len - Buf_size;\
-  } else {\
-    s->bi_buf |= (value) << s->bi_valid;\
-    s->bi_valid += len;\
-  }\
-}
-#endif /* DEBUG_ZLIB */
-
-
-#define MAX(a,b) (a >= b ? a : b)
-/* the arguments must not have side effects */
-
-/* ===========================================================================
- * Initialize the various 'constant' tables.
- * To do: do this at compile time.
- */
-local void ct_static_init()
-{
-    int n;        /* iterates over tree elements */
-    int bits;     /* bit counter */
-    int length;   /* length value */
-    int code;     /* code value */
-    int dist;     /* distance index */
-    ush bl_count[MAX_BITS+1];
-    /* number of codes at each bit length for an optimal tree */
-
-    /* Initialize the mapping length (0..255) -> length code (0..28) */
-    length = 0;
-    for (code = 0; code < LENGTH_CODES-1; code++) {
-        base_length[code] = length;
-        for (n = 0; n < (1<<extra_lbits[code]); n++) {
-            length_code[length++] = (uch)code;
-        }
-    }
-    Assert (length == 256, "ct_static_init: length != 256");
-    /* Note that the length 255 (match length 258) can be represented
-     * in two different ways: code 284 + 5 bits or code 285, so we
-     * overwrite length_code[255] to use the best encoding:
-     */
-    length_code[length-1] = (uch)code;
-
-    /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
-    dist = 0;
-    for (code = 0 ; code < 16; code++) {
-        base_dist[code] = dist;
-        for (n = 0; n < (1<<extra_dbits[code]); n++) {
-            dist_code[dist++] = (uch)code;
-        }
-    }
-    Assert (dist == 256, "ct_static_init: dist != 256");
-    dist >>= 7; /* from now on, all distances are divided by 128 */
-    for ( ; code < D_CODES; code++) {
-        base_dist[code] = dist << 7;
-        for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
-            dist_code[256 + dist++] = (uch)code;
-        }
-    }
-    Assert (dist == 256, "ct_static_init: 256+dist != 512");
-
-    /* Construct the codes of the static literal tree */
-    for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
-    n = 0;
-    while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
-    while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
-    while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
-    while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
-    /* Codes 286 and 287 do not exist, but we must include them in the
-     * tree construction to get a canonical Huffman tree (longest code
-     * all ones)
-     */
-    gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
-
-    /* The static distance tree is trivial: */
-    for (n = 0; n < D_CODES; n++) {
-        static_dtree[n].Len = 5;
-        static_dtree[n].Code = bi_reverse(n, 5);
-    }
-}
-
-/* ===========================================================================
- * Initialize the tree data structures for a new zlib stream.
- */
-local void ct_init(s)
-    deflate_state *s;
-{
-    if (static_dtree[0].Len == 0) {
-        ct_static_init();              /* To do: at compile time */
-    }
-
-    s->compressed_len = 0L;
-
-    s->l_desc.dyn_tree = s->dyn_ltree;
-    s->l_desc.stat_desc = &static_l_desc;
-
-    s->d_desc.dyn_tree = s->dyn_dtree;
-    s->d_desc.stat_desc = &static_d_desc;
-
-    s->bl_desc.dyn_tree = s->bl_tree;
-    s->bl_desc.stat_desc = &static_bl_desc;
-
-    s->bi_buf = 0;
-    s->bi_valid = 0;
-    s->last_eob_len = 8; /* enough lookahead for inflate */
-#ifdef DEBUG_ZLIB
-    s->bits_sent = 0L;
-#endif
-    s->blocks_in_packet = 0;
-
-    /* Initialize the first block of the first file: */
-    init_block(s);
-}
-
-/* ===========================================================================
- * Initialize a new block.
- */
-local void init_block(s)
-    deflate_state *s;
-{
-    int n; /* iterates over tree elements */
-
-    /* Initialize the trees. */
-    for (n = 0; n < L_CODES;  n++) s->dyn_ltree[n].Freq = 0;
-    for (n = 0; n < D_CODES;  n++) s->dyn_dtree[n].Freq = 0;
-    for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
-
-    s->dyn_ltree[END_BLOCK].Freq = 1;
-    s->opt_len = s->static_len = 0L;
-    s->last_lit = s->matches = 0;
-}
-
-#define SMALLEST 1
-/* Index within the heap array of least frequent node in the Huffman tree */
-
-
-/* ===========================================================================
- * Remove the smallest element from the heap and recreate the heap with
- * one less element. Updates heap and heap_len.
- */
-#define pqremove(s, tree, top) \
-{\
-    top = s->heap[SMALLEST]; \
-    s->heap[SMALLEST] = s->heap[s->heap_len--]; \
-    pqdownheap(s, tree, SMALLEST); \
-}
-
-/* ===========================================================================
- * Compares to subtrees, using the tree depth as tie breaker when
- * the subtrees have equal frequency. This minimizes the worst case length.
- */
-#define smaller(tree, n, m, depth) \
-   (tree[n].Freq < tree[m].Freq || \
-   (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
-
-/* ===========================================================================
- * Restore the heap property by moving down the tree starting at node k,
- * exchanging a node with the smallest of its two sons if necessary, stopping
- * when the heap property is re-established (each father smaller than its
- * two sons).
- */
-local void pqdownheap(s, tree, k)
-    deflate_state *s;
-    ct_data *tree;  /* the tree to restore */
-    int k;               /* node to move down */
-{
-    int v = s->heap[k];
-    int j = k << 1;  /* left son of k */
-    while (j <= s->heap_len) {
-        /* Set j to the smallest of the two sons: */
-        if (j < s->heap_len &&
-            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
-            j++;
-        }
-        /* Exit if v is smaller than both sons */
-        if (smaller(tree, v, s->heap[j], s->depth)) break;
-
-        /* Exchange v with the smallest son */
-        s->heap[k] = s->heap[j];  k = j;
-
-        /* And continue down the tree, setting j to the left son of k */
-        j <<= 1;
-    }
-    s->heap[k] = v;
-}
-
-/* ===========================================================================
- * Compute the optimal bit lengths for a tree and update the total bit length
- * for the current block.
- * IN assertion: the fields freq and dad are set, heap[heap_max] and
- *    above are the tree nodes sorted by increasing frequency.
- * OUT assertions: the field len is set to the optimal bit length, the
- *     array bl_count contains the frequencies for each bit length.
- *     The length opt_len is updated; static_len is also updated if stree is
- *     not null.
- */
-local void gen_bitlen(s, desc)
-    deflate_state *s;
-    tree_desc *desc;    /* the tree descriptor */
-{
-    ct_data *tree  = desc->dyn_tree;
-    int max_code   = desc->max_code;
-    ct_data *stree = desc->stat_desc->static_tree;
-    intf *extra    = desc->stat_desc->extra_bits;
-    int base       = desc->stat_desc->extra_base;
-    int max_length = desc->stat_desc->max_length;
-    int h;              /* heap index */
-    int n, m;           /* iterate over the tree elements */
-    int bits;           /* bit length */
-    int xbits;          /* extra bits */
-    ush f;              /* frequency */
-    int overflow = 0;   /* number of elements with bit length too large */
-
-    for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
-
-    /* In a first pass, compute the optimal bit lengths (which may
-     * overflow in the case of the bit length tree).
-     */
-    tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
-
-    for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
-        n = s->heap[h];
-        bits = tree[tree[n].Dad].Len + 1;
-        if (bits > max_length) bits = max_length, overflow++;
-        tree[n].Len = (ush)bits;
-        /* We overwrite tree[n].Dad which is no longer needed */
-
-        if (n > max_code) continue; /* not a leaf node */
-
-        s->bl_count[bits]++;
-        xbits = 0;
-        if (n >= base) xbits = extra[n-base];
-        f = tree[n].Freq;
-        s->opt_len += (ulg)f * (bits + xbits);
-        if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
-    }
-    if (overflow == 0) return;
-
-    Trace((stderr,"\nbit length overflow\n"));
-    /* This happens for example on obj2 and pic of the Calgary corpus */
-
-    /* Find the first bit length which could increase: */
-    do {
-        bits = max_length-1;
-        while (s->bl_count[bits] == 0) bits--;
-        s->bl_count[bits]--;      /* move one leaf down the tree */
-        s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
-        s->bl_count[max_length]--;
-        /* The brother of the overflow item also moves one step up,
-         * but this does not affect bl_count[max_length]
-         */
-        overflow -= 2;
-    } while (overflow > 0);
-
-    /* Now recompute all bit lengths, scanning in increasing frequency.
-     * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
-     * lengths instead of fixing only the wrong ones. This idea is taken
-     * from 'ar' written by Haruhiko Okumura.)
-     */
-    for (bits = max_length; bits != 0; bits--) {
-        n = s->bl_count[bits];
-        while (n != 0) {
-            m = s->heap[--h];
-            if (m > max_code) continue;
-            if (tree[m].Len != (unsigned) bits) {
-                Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
-                s->opt_len += ((long)bits - (long)tree[m].Len)
-                              *(long)tree[m].Freq;
-                tree[m].Len = (ush)bits;
-            }
-            n--;
-        }
-    }
-}
-
-/* ===========================================================================
- * Generate the codes for a given tree and bit counts (which need not be
- * optimal).
- * IN assertion: the array bl_count contains the bit length statistics for
- * the given tree and the field len is set for all tree elements.
- * OUT assertion: the field code is set for all tree elements of non
- *     zero code length.
- */
-local void gen_codes (tree, max_code, bl_count)
-    ct_data *tree;             /* the tree to decorate */
-    int max_code;              /* largest code with non zero frequency */
-    ushf *bl_count;            /* number of codes at each bit length */
-{
-    ush next_code[MAX_BITS+1]; /* next code value for each bit length */
-    ush code = 0;              /* running code value */
-    int bits;                  /* bit index */
-    int n;                     /* code index */
-
-    /* The distribution counts are first used to generate the code values
-     * without bit reversal.
-     */
-    for (bits = 1; bits <= MAX_BITS; bits++) {
-        next_code[bits] = code = (code + bl_count[bits-1]) << 1;
-    }
-    /* Check that the bit counts in bl_count are consistent. The last code
-     * must be all ones.
-     */
-    Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
-            "inconsistent bit counts");
-    Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
-
-    for (n = 0;  n <= max_code; n++) {
-        int len = tree[n].Len;
-        if (len == 0) continue;
-        /* Now reverse the bits */
-        tree[n].Code = bi_reverse(next_code[len]++, len);
-
-        Tracec(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
-             n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
-    }
-}
-
-/* ===========================================================================
- * Construct one Huffman tree and assigns the code bit strings and lengths.
- * Update the total bit length for the current block.
- * IN assertion: the field freq is set for all tree elements.
- * OUT assertions: the fields len and code are set to the optimal bit length
- *     and corresponding code. The length opt_len is updated; static_len is
- *     also updated if stree is not null. The field max_code is set.
- */
-local void build_tree(s, desc)
-    deflate_state *s;
-    tree_desc *desc; /* the tree descriptor */
-{
-    ct_data *tree   = desc->dyn_tree;
-    ct_data *stree  = desc->stat_desc->static_tree;
-    int elems       = desc->stat_desc->elems;
-    int n, m;          /* iterate over heap elements */
-    int max_code = -1; /* largest code with non zero frequency */
-    int node;          /* new node being created */
-
-    /* Construct the initial heap, with least frequent element in
-     * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
-     * heap[0] is not used.
-     */
-    s->heap_len = 0, s->heap_max = HEAP_SIZE;
-
-    for (n = 0; n < elems; n++) {
-        if (tree[n].Freq != 0) {
-            s->heap[++(s->heap_len)] = max_code = n;
-            s->depth[n] = 0;
-        } else {
-            tree[n].Len = 0;
-        }
-    }
-
-    /* The pkzip format requires that at least one distance code exists,
-     * and that at least one bit should be sent even if there is only one
-     * possible code. So to avoid special checks later on we force at least
-     * two codes of non zero frequency.
-     */
-    while (s->heap_len < 2) {
-        node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
-        tree[node].Freq = 1;
-        s->depth[node] = 0;
-        s->opt_len--; if (stree) s->static_len -= stree[node].Len;
-        /* node is 0 or 1 so it does not have extra bits */
-    }
-    desc->max_code = max_code;
-
-    /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
-     * establish sub-heaps of increasing lengths:
-     */
-    for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
-
-    /* Construct the Huffman tree by repeatedly combining the least two
-     * frequent nodes.
-     */
-    node = elems;              /* next internal node of the tree */
-    do {
-        pqremove(s, tree, n);  /* n = node of least frequency */
-        m = s->heap[SMALLEST]; /* m = node of next least frequency */
-
-        s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
-        s->heap[--(s->heap_max)] = m;
-
-        /* Create a new node father of n and m */
-        tree[node].Freq = tree[n].Freq + tree[m].Freq;
-        s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1);
-        tree[n].Dad = tree[m].Dad = (ush)node;
-#ifdef DUMP_BL_TREE
-        if (tree == s->bl_tree) {
-            fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
-                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
-        }
-#endif
-        /* and insert the new node in the heap */
-        s->heap[SMALLEST] = node++;
-        pqdownheap(s, tree, SMALLEST);
-
-    } while (s->heap_len >= 2);
-
-    s->heap[--(s->heap_max)] = s->heap[SMALLEST];
-
-    /* At this point, the fields freq and dad are set. We can now
-     * generate the bit lengths.
-     */
-    gen_bitlen(s, (tree_desc *)desc);
-
-    /* The field len is now set, we can generate the bit codes */
-    gen_codes ((ct_data *)tree, max_code, s->bl_count);
-}
-
-/* ===========================================================================
- * Scan a literal or distance tree to determine the frequencies of the codes
- * in the bit length tree.
- */
-local void scan_tree (s, tree, max_code)
-    deflate_state *s;
-    ct_data *tree;   /* the tree to be scanned */
-    int max_code;    /* and its largest code of non zero frequency */
-{
-    int n;                     /* iterates over all tree elements */
-    int prevlen = -1;          /* last emitted length */
-    int curlen;                /* length of current code */
-    int nextlen = tree[0].Len; /* length of next code */
-    int count = 0;             /* repeat count of the current code */
-    int max_count = 7;         /* max repeat count */
-    int min_count = 4;         /* min repeat count */
-
-    if (nextlen == 0) max_count = 138, min_count = 3;
-    tree[max_code+1].Len = (ush)0xffff; /* guard */
-
-    for (n = 0; n <= max_code; n++) {
-        curlen = nextlen; nextlen = tree[n+1].Len;
-        if (++count < max_count && curlen == nextlen) {
-            continue;
-        } else if (count < min_count) {
-            s->bl_tree[curlen].Freq += count;
-        } else if (curlen != 0) {
-            if (curlen != prevlen) s->bl_tree[curlen].Freq++;
-            s->bl_tree[REP_3_6].Freq++;
-        } else if (count <= 10) {
-            s->bl_tree[REPZ_3_10].Freq++;
-        } else {
-            s->bl_tree[REPZ_11_138].Freq++;
-        }
-        count = 0; prevlen = curlen;
-        if (nextlen == 0) {
-            max_count = 138, min_count = 3;
-        } else if (curlen == nextlen) {
-            max_count = 6, min_count = 3;
-        } else {
-            max_count = 7, min_count = 4;
-        }
-    }
-}
-
-/* ===========================================================================
- * Send a literal or distance tree in compressed form, using the codes in
- * bl_tree.
- */
-local void send_tree (s, tree, max_code)
-    deflate_state *s;
-    ct_data *tree; /* the tree to be scanned */
-    int max_code;       /* and its largest code of non zero frequency */
-{
-    int n;                     /* iterates over all tree elements */
-    int prevlen = -1;          /* last emitted length */
-    int curlen;                /* length of current code */
-    int nextlen = tree[0].Len; /* length of next code */
-    int count = 0;             /* repeat count of the current code */
-    int max_count = 7;         /* max repeat count */
-    int min_count = 4;         /* min repeat count */
-
-    /* tree[max_code+1].Len = -1; */  /* guard already set */
-    if (nextlen == 0) max_count = 138, min_count = 3;
-
-    for (n = 0; n <= max_code; n++) {
-        curlen = nextlen; nextlen = tree[n+1].Len;
-        if (++count < max_count && curlen == nextlen) {
-            continue;
-        } else if (count < min_count) {
-            do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
-
-        } else if (curlen != 0) {
-            if (curlen != prevlen) {
-                send_code(s, curlen, s->bl_tree); count--;
-            }
-            Assert(count >= 3 && count <= 6, " 3_6?");
-            send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
-
-        } else if (count <= 10) {
-            send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
-
-        } else {
-            send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
-        }
-        count = 0; prevlen = curlen;
-        if (nextlen == 0) {
-            max_count = 138, min_count = 3;
-        } else if (curlen == nextlen) {
-            max_count = 6, min_count = 3;
-        } else {
-            max_count = 7, min_count = 4;
-        }
-    }
-}
-
-/* ===========================================================================
- * Construct the Huffman tree for the bit lengths and return the index in
- * bl_order of the last bit length code to send.
- */
-local int build_bl_tree(s)
-    deflate_state *s;
-{
-    int max_blindex;  /* index of last bit length code of non zero freq */
-
-    /* Determine the bit length frequencies for literal and distance trees */
-    scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
-    scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
-
-    /* Build the bit length tree: */
-    build_tree(s, (tree_desc *)(&(s->bl_desc)));
-    /* opt_len now includes the length of the tree representations, except
-     * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
-     */
-
-    /* Determine the number of bit length codes to send. The pkzip format
-     * requires that at least 4 bit length codes be sent. (appnote.txt says
-     * 3 but the actual value used is 4.)
-     */
-    for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
-        if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
-    }
-    /* Update opt_len to include the bit length tree and counts */
-    s->opt_len += 3*(max_blindex+1) + 5+5+4;
-    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
-            s->opt_len, s->static_len));
-
-    return max_blindex;
-}
-
-/* ===========================================================================
- * Send the header for a block using dynamic Huffman trees: the counts, the
- * lengths of the bit length codes, the literal tree and the distance tree.
- * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
- */
-local void send_all_trees(s, lcodes, dcodes, blcodes)
-    deflate_state *s;
-    int lcodes, dcodes, blcodes; /* number of codes for each tree */
-{
-    int rank;                    /* index in bl_order */
-
-    Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
-    Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
-            "too many codes");
-    Tracev((stderr, "\nbl counts: "));
-    send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
-    send_bits(s, dcodes-1,   5);
-    send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
-    for (rank = 0; rank < blcodes; rank++) {
-        Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
-        send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
-    }
-    Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
-
-    send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
-    Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
-
-    send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
-    Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
-}
-
-/* ===========================================================================
- * Send a stored block
- */
-local void ct_stored_block(s, buf, stored_len, eof)
-    deflate_state *s;
-    charf *buf;       /* input block */
-    ulg stored_len;   /* length of input block */
-    int eof;          /* true if this is the last block for a file */
-{
-    send_bits(s, (STORED_BLOCK<<1)+eof, 3);  /* send block type */
-    s->compressed_len = (s->compressed_len + 3 + 7) & ~7L;
-    s->compressed_len += (stored_len + 4) << 3;
-
-    copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
-}
-
-/* Send just the `stored block' type code without any length bytes or data.
- */
-local void ct_stored_type_only(s)
-    deflate_state *s;
-{
-    send_bits(s, (STORED_BLOCK << 1), 3);
-    bi_windup(s);
-    s->compressed_len = (s->compressed_len + 3) & ~7L;
-}
-
-
-/* ===========================================================================
- * Send one empty static block to give enough lookahead for inflate.
- * This takes 10 bits, of which 7 may remain in the bit buffer.
- * The current inflate code requires 9 bits of lookahead. If the EOB
- * code for the previous block was coded on 5 bits or less, inflate
- * may have only 5+3 bits of lookahead to decode this EOB.
- * (There are no problems if the previous block is stored or fixed.)
- */
-local void ct_align(s)
-    deflate_state *s;
-{
-    send_bits(s, STATIC_TREES<<1, 3);
-    send_code(s, END_BLOCK, static_ltree);
-    s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
-    bi_flush(s);
-    /* Of the 10 bits for the empty block, we have already sent
-     * (10 - bi_valid) bits. The lookahead for the EOB of the previous
-     * block was thus its length plus what we have just sent.
-     */
-    if (s->last_eob_len + 10 - s->bi_valid < 9) {
-        send_bits(s, STATIC_TREES<<1, 3);
-        send_code(s, END_BLOCK, static_ltree);
-        s->compressed_len += 10L;
-        bi_flush(s);
-    }
-    s->last_eob_len = 7;
-}
-
-/* ===========================================================================
- * Determine the best encoding for the current block: dynamic trees, static
- * trees or store, and output the encoded block to the zip file. This function
- * returns the total compressed length for the file so far.
- */
-local ulg ct_flush_block(s, buf, stored_len, flush)
-    deflate_state *s;
-    charf *buf;       /* input block, or NULL if too old */
-    ulg stored_len;   /* length of input block */
-    int flush;        /* Z_FINISH if this is the last block for a file */
-{
-    ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
-    int max_blindex;  /* index of last bit length code of non zero freq */
-    int eof = flush == Z_FINISH;
-
-    ++s->blocks_in_packet;
-
-    /* Check if the file is ascii or binary */
-    if (s->data_type == UNKNOWN) set_data_type(s);
-
-    /* Construct the literal and distance trees */
-    build_tree(s, (tree_desc *)(&(s->l_desc)));
-    Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
-            s->static_len));
-
-    build_tree(s, (tree_desc *)(&(s->d_desc)));
-    Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
-            s->static_len));
-    /* At this point, opt_len and static_len are the total bit lengths of
-     * the compressed block data, excluding the tree representations.
-     */
-
-    /* Build the bit length tree for the above two trees, and get the index
-     * in bl_order of the last bit length code to send.
-     */
-    max_blindex = build_bl_tree(s);
-
-    /* Determine the best encoding. Compute first the block length in bytes */
-    opt_lenb = (s->opt_len+3+7)>>3;
-    static_lenb = (s->static_len+3+7)>>3;
-
-    Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
-            opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
-            s->last_lit));
-
-    if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
-
-    /* If compression failed and this is the first and last block,
-     * and if the .zip file can be seeked (to rewrite the local header),
-     * the whole file is transformed into a stored file:
-     */
-#ifdef STORED_FILE_OK
-#  ifdef FORCE_STORED_FILE
-    if (eof && compressed_len == 0L) /* force stored file */
-#  else
-    if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable())
-#  endif
-    {
-        /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
-        if (buf == (charf*)0) error ("block vanished");
-
-        copy_block(buf, (unsigned)stored_len, 0); /* without header */
-        s->compressed_len = stored_len << 3;
-        s->method = STORED;
-    } else
-#endif /* STORED_FILE_OK */
-
-    /* For Z_PACKET_FLUSH, if we don't achieve the required minimum
-     * compression, and this block contains all the data since the last
-     * time we used Z_PACKET_FLUSH, then just omit this block completely
-     * from the output.
-     */
-    if (flush == Z_PACKET_FLUSH && s->blocks_in_packet == 1
-       && opt_lenb > stored_len - s->minCompr) {
-       s->blocks_in_packet = 0;
-       /* output nothing */
-    } else
-
-#ifdef FORCE_STORED
-    if (buf != (char*)0) /* force stored block */
-#else
-    if (stored_len+4 <= opt_lenb && buf != (char*)0)
-                       /* 4: two words for the lengths */
-#endif
-    {
-        /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
-         * Otherwise we can't have processed more than WSIZE input bytes since
-         * the last block flush, because compression would have been
-         * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
-         * transform a block into a stored block.
-         */
-        ct_stored_block(s, buf, stored_len, eof);
-    } else
-
-#ifdef FORCE_STATIC
-    if (static_lenb >= 0) /* force static trees */
-#else
-    if (static_lenb == opt_lenb)
-#endif
-    {
-        send_bits(s, (STATIC_TREES<<1)+eof, 3);
-        compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
-        s->compressed_len += 3 + s->static_len;
-    } else {
-        send_bits(s, (DYN_TREES<<1)+eof, 3);
-        send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
-                       max_blindex+1);
-        compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
-        s->compressed_len += 3 + s->opt_len;
-    }
-    Assert (s->compressed_len == s->bits_sent, "bad compressed size");
-    init_block(s);
-
-    if (eof) {
-        bi_windup(s);
-        s->compressed_len += 7;  /* align on byte boundary */
-    }
-    Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
-           s->compressed_len-7*eof));
-
-    return s->compressed_len >> 3;
-}
-
-/* ===========================================================================
- * Save the match info and tally the frequency counts. Return true if
- * the current block must be flushed.
- */
-local int ct_tally (s, dist, lc)
-    deflate_state *s;
-    int dist;  /* distance of matched string */
-    int lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
-{
-    s->d_buf[s->last_lit] = (ush)dist;
-    s->l_buf[s->last_lit++] = (uch)lc;
-    if (dist == 0) {
-        /* lc is the unmatched char */
-        s->dyn_ltree[lc].Freq++;
-    } else {
-        s->matches++;
-        /* Here, lc is the match length - MIN_MATCH */
-        dist--;             /* dist = match distance - 1 */
-        Assert((ush)dist < (ush)MAX_DIST(s) &&
-               (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
-               (ush)d_code(dist) < (ush)D_CODES,  "ct_tally: bad match");
-
-        s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
-        s->dyn_dtree[d_code(dist)].Freq++;
-    }
-
-    /* Try to guess if it is profitable to stop the current block here */
-    if (s->level > 2 && (s->last_lit & 0xfff) == 0) {
-        /* Compute an upper bound for the compressed length */
-        ulg out_length = (ulg)s->last_lit*8L;
-        ulg in_length = (ulg)s->strstart - s->block_start;
-        int dcode;
-        for (dcode = 0; dcode < D_CODES; dcode++) {
-            out_length += (ulg)s->dyn_dtree[dcode].Freq *
-                (5L+extra_dbits[dcode]);
-        }
-        out_length >>= 3;
-        Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
-               s->last_lit, in_length, out_length,
-               100L - out_length*100L/in_length));
-        if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
-    }
-    return (s->last_lit == s->lit_bufsize-1);
-    /* We avoid equality with lit_bufsize because of wraparound at 64K
-     * on 16 bit machines and because stored blocks are restricted to
-     * 64K-1 bytes.
-     */
-}
-
-/* ===========================================================================
- * Send the block data compressed using the given Huffman trees
- */
-local void compress_block(s, ltree, dtree)
-    deflate_state *s;
-    ct_data *ltree; /* literal tree */
-    ct_data *dtree; /* distance tree */
-{
-    unsigned dist;      /* distance of matched string */
-    int lc;             /* match length or unmatched char (if dist == 0) */
-    unsigned lx = 0;    /* running index in l_buf */
-    unsigned code;      /* the code to send */
-    int extra;          /* number of extra bits to send */
-
-    if (s->last_lit != 0) do {
-        dist = s->d_buf[lx];
-        lc = s->l_buf[lx++];
-        if (dist == 0) {
-            send_code(s, lc, ltree); /* send a literal byte */
-            Tracecv(isgraph(lc), (stderr," '%c' ", lc));
-        } else {
-            /* Here, lc is the match length - MIN_MATCH */
-            code = length_code[lc];
-            send_code(s, code+LITERALS+1, ltree); /* send the length code */
-            extra = extra_lbits[code];
-            if (extra != 0) {
-                lc -= base_length[code];
-                send_bits(s, lc, extra);       /* send the extra length bits */
-            }
-            dist--; /* dist is now the match distance - 1 */
-            code = d_code(dist);
-            Assert (code < D_CODES, "bad d_code");
-
-            send_code(s, code, dtree);       /* send the distance code */
-            extra = extra_dbits[code];
-            if (extra != 0) {
-                dist -= base_dist[code];
-                send_bits(s, dist, extra);   /* send the extra distance bits */
-            }
-        } /* literal or match pair ? */
-
-        /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
-        Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
-
-    } while (lx < s->last_lit);
-
-    send_code(s, END_BLOCK, ltree);
-    s->last_eob_len = ltree[END_BLOCK].Len;
-}
-
-/* ===========================================================================
- * Set the data type to ASCII or BINARY, using a crude approximation:
- * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
- * IN assertion: the fields freq of dyn_ltree are set and the total of all
- * frequencies does not exceed 64K (to fit in an int on 16 bit machines).
- */
-local void set_data_type(s)
-    deflate_state *s;
-{
-    int n = 0;
-    unsigned ascii_freq = 0;
-    unsigned bin_freq = 0;
-    while (n < 7)        bin_freq += s->dyn_ltree[n++].Freq;
-    while (n < 128)    ascii_freq += s->dyn_ltree[n++].Freq;
-    while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq;
-    s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII);
-}
-
-/* ===========================================================================
- * Reverse the first len bits of a code, using straightforward code (a faster
- * method would use a table)
- * IN assertion: 1 <= len <= 15
- */
-local unsigned bi_reverse(code, len)
-    unsigned code; /* the value to invert */
-    int len;       /* its bit length */
-{
-    register unsigned res = 0;
-    do {
-        res |= code & 1;
-        code >>= 1, res <<= 1;
-    } while (--len > 0);
-    return res >> 1;
-}
-
-/* ===========================================================================
- * Flush the bit buffer, keeping at most 7 bits in it.
- */
-local void bi_flush(s)
-    deflate_state *s;
-{
-    if (s->bi_valid == 16) {
-        put_short(s, s->bi_buf);
-        s->bi_buf = 0;
-        s->bi_valid = 0;
-    } else if (s->bi_valid >= 8) {
-        put_byte(s, (Byte)s->bi_buf);
-        s->bi_buf >>= 8;
-        s->bi_valid -= 8;
-    }
-}
-
-/* ===========================================================================
- * Flush the bit buffer and align the output on a byte boundary
- */
-local void bi_windup(s)
-    deflate_state *s;
-{
-    if (s->bi_valid > 8) {
-        put_short(s, s->bi_buf);
-    } else if (s->bi_valid > 0) {
-        put_byte(s, (Byte)s->bi_buf);
-    }
-    s->bi_buf = 0;
-    s->bi_valid = 0;
-#ifdef DEBUG_ZLIB
-    s->bits_sent = (s->bits_sent+7) & ~7;
-#endif
-}
-
-/* ===========================================================================
- * Copy a stored block, storing first the length and its
- * one's complement if requested.
- */
-local void copy_block(s, buf, len, header)
-    deflate_state *s;
-    charf    *buf;    /* the input data */
-    unsigned len;     /* its length */
-    int      header;  /* true if block header must be written */
-{
-    bi_windup(s);        /* align on byte boundary */
-    s->last_eob_len = 8; /* enough lookahead for inflate */
-
-    if (header) {
-        put_short(s, (ush)len);   
-        put_short(s, (ush)~len);
-#ifdef DEBUG_ZLIB
-        s->bits_sent += 2*16;
-#endif
-    }
-#ifdef DEBUG_ZLIB
-    s->bits_sent += (ulg)len<<3;
-#endif
-    while (len--) {
-        put_byte(s, *buf++);
-    }
-}
-
-
-/*+++++*/
-/* infblock.h -- header to use infblock.c
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-struct inflate_blocks_state;
-typedef struct inflate_blocks_state FAR inflate_blocks_statef;
-
-local inflate_blocks_statef * inflate_blocks_new OF((
-    z_stream *z,
-    check_func c,               /* check function */
-    uInt w));                   /* window size */
-
-local int inflate_blocks OF((
-    inflate_blocks_statef *,
-    z_stream *,
-    int));                      /* initial return code */
-
-local void inflate_blocks_reset OF((
-    inflate_blocks_statef *,
-    z_stream *,
-    uLongf *));                  /* check value on output */
-
-local int inflate_blocks_free OF((
-    inflate_blocks_statef *,
-    z_stream *,
-    uLongf *));                  /* check value on output */
-
-local int inflate_addhistory OF((
-    inflate_blocks_statef *,
-    z_stream *));
-
-local int inflate_packet_flush OF((
-    inflate_blocks_statef *));
-
-/*+++++*/
-/* inftrees.h -- header to use inftrees.c
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* Huffman code lookup table entry--this entry is four bytes for machines
-   that have 16-bit pointers (e.g. PC's in the small or medium model). */
-
-typedef struct inflate_huft_s FAR inflate_huft;
-
-struct inflate_huft_s {
-  union {
-    struct {
-      Byte Exop;        /* number of extra bits or operation */
-      Byte Bits;        /* number of bits in this code or subcode */
-    } what;
-    uInt Nalloc;       /* number of these allocated here */
-    Bytef *pad;         /* pad structure to a power of 2 (4 bytes for */
-  } word;               /*  16-bit, 8 bytes for 32-bit machines) */
-  union {
-    uInt Base;          /* literal, length base, or distance base */
-    inflate_huft *Next; /* pointer to next level of table */
-  } more;
-};
-
-#ifdef DEBUG_ZLIB
-  local uInt inflate_hufts;
-#endif
-
-local int inflate_trees_bits OF((
-    uIntf *,                    /* 19 code lengths */
-    uIntf *,                    /* bits tree desired/actual depth */
-    inflate_huft * FAR *,       /* bits tree result */
-    z_stream *));               /* for zalloc, zfree functions */
-
-local int inflate_trees_dynamic OF((
-    uInt,                       /* number of literal/length codes */
-    uInt,                       /* number of distance codes */
-    uIntf *,                    /* that many (total) code lengths */
-    uIntf *,                    /* literal desired/actual bit depth */
-    uIntf *,                    /* distance desired/actual bit depth */
-    inflate_huft * FAR *,       /* literal/length tree result */
-    inflate_huft * FAR *,       /* distance tree result */
-    z_stream *));               /* for zalloc, zfree functions */
-
-local int inflate_trees_fixed OF((
-    uIntf *,                    /* literal desired/actual bit depth */
-    uIntf *,                    /* distance desired/actual bit depth */
-    inflate_huft * FAR *,       /* literal/length tree result */
-    inflate_huft * FAR *));     /* distance tree result */
-
-local int inflate_trees_free OF((
-    inflate_huft *,             /* tables to free */
-    z_stream *));               /* for zfree function */
-
-
-/*+++++*/
-/* infcodes.h -- header to use infcodes.c
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-struct inflate_codes_state;
-typedef struct inflate_codes_state FAR inflate_codes_statef;
-
-local inflate_codes_statef *inflate_codes_new OF((
-    uInt, uInt,
-    inflate_huft *, inflate_huft *,
-    z_stream *));
-
-local int inflate_codes OF((
-    inflate_blocks_statef *,
-    z_stream *,
-    int));
-
-local void inflate_codes_free OF((
-    inflate_codes_statef *,
-    z_stream *));
-
-
-/*+++++*/
-/* inflate.c -- zlib interface to inflate modules
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* inflate private state */
-struct internal_state {
-
-  /* mode */
-  enum {
-      METHOD,   /* waiting for method byte */
-      FLAG,     /* waiting for flag byte */
-      BLOCKS,   /* decompressing blocks */
-      CHECK4,   /* four check bytes to go */
-      CHECK3,   /* three check bytes to go */
-      CHECK2,   /* two check bytes to go */
-      CHECK1,   /* one check byte to go */
-      DONE,     /* finished check, done */
-      BAD}      /* got an error--stay here */
-    mode;               /* current inflate mode */
-
-  /* mode dependent information */
-  union {
-    uInt method;        /* if FLAGS, method byte */
-    struct {
-      uLong was;                /* computed check value */
-      uLong need;               /* stream check value */
-    } check;            /* if CHECK, check values to compare */
-    uInt marker;        /* if BAD, inflateSync's marker bytes count */
-  } sub;        /* submode */
-
-  /* mode independent information */
-  int  nowrap;          /* flag for no wrapper */
-  uInt wbits;           /* log2(window size)  (8..15, defaults to 15) */
-  inflate_blocks_statef 
-    *blocks;            /* current inflate_blocks state */
-
-};
-
-
-int inflateReset(z)
-z_stream *z;
-{
-  uLong c;
-
-  if (z == Z_NULL || z->state == Z_NULL)
-    return Z_STREAM_ERROR;
-  z->total_in = z->total_out = 0;
-  z->msg = Z_NULL;
-  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
-  inflate_blocks_reset(z->state->blocks, z, &c);
-  Trace((stderr, "inflate: reset\n"));
-  return Z_OK;
-}
-
-
-int inflateEnd(z)
-z_stream *z;
-{
-  uLong c;
-
-  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
-    return Z_STREAM_ERROR;
-  if (z->state->blocks != Z_NULL)
-    inflate_blocks_free(z->state->blocks, z, &c);
-  ZFREE(z, z->state, sizeof(struct internal_state));
-  z->state = Z_NULL;
-  Trace((stderr, "inflate: end\n"));
-  return Z_OK;
-}
-
-
-int inflateInit2(z, w)
-z_stream *z;
-int w;
-{
-  /* initialize state */
-  if (z == Z_NULL)
-    return Z_STREAM_ERROR;
-/*  if (z->zalloc == Z_NULL) z->zalloc = zcalloc; */
-/*  if (z->zfree == Z_NULL) z->zfree = zcfree; */
-  if ((z->state = (struct internal_state FAR *)
-       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
-    return Z_MEM_ERROR;
-  z->state->blocks = Z_NULL;
-
-  /* handle undocumented nowrap option (no zlib header or check) */
-  z->state->nowrap = 0;
-  if (w < 0)
-  {
-    w = - w;
-    z->state->nowrap = 1;
-  }
-
-  /* set window size */
-  if (w < 8 || w > 15)
-  {
-    inflateEnd(z);
-    return Z_STREAM_ERROR;
-  }
-  z->state->wbits = (uInt)w;
-
-  /* create inflate_blocks state */
-  if ((z->state->blocks =
-       inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, 1 << w))
-      == Z_NULL)
-  {
-    inflateEnd(z);
-    return Z_MEM_ERROR;
-  }
-  Trace((stderr, "inflate: allocated\n"));
-
-  /* reset state */
-  inflateReset(z);
-  return Z_OK;
-}
-
-
-int inflateInit(z)
-z_stream *z;
-{
-  return inflateInit2(z, DEF_WBITS);
-}
-
-
-#define NEEDBYTE {if(z->avail_in==0)goto empty;r=Z_OK;}
-#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
-
-int inflate(z, f)
-z_stream *z;
-int f;
-{
-  int r;
-  uInt b;
-
-  if (z == Z_NULL || z->next_in == Z_NULL)
-    return Z_STREAM_ERROR;
-  r = Z_BUF_ERROR;
-  while (1) switch (z->state->mode)
-  {
-    case METHOD:
-      NEEDBYTE
-      if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED)
-      {
-        z->state->mode = BAD;
-        z->msg = "unknown compression method";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
-      {
-        z->state->mode = BAD;
-        z->msg = "invalid window size";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      z->state->mode = FLAG;
-    case FLAG:
-      NEEDBYTE
-      if ((b = NEXTBYTE) & 0x20)
-      {
-        z->state->mode = BAD;
-        z->msg = "invalid reserved bit";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      if (((z->state->sub.method << 8) + b) % 31)
-      {
-        z->state->mode = BAD;
-        z->msg = "incorrect header check";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      Trace((stderr, "inflate: zlib header ok\n"));
-      z->state->mode = BLOCKS;
-    case BLOCKS:
-      r = inflate_blocks(z->state->blocks, z, r);
-      if (f == Z_PACKET_FLUSH && z->avail_in == 0 && z->avail_out != 0)
-         r = inflate_packet_flush(z->state->blocks);
-      if (r == Z_DATA_ERROR)
-      {
-        z->state->mode = BAD;
-        z->state->sub.marker = 0;       /* can try inflateSync */
-        break;
-      }
-      if (r != Z_STREAM_END)
-        return r;
-      r = Z_OK;
-      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
-      if (z->state->nowrap)
-      {
-        z->state->mode = DONE;
-        break;
-      }
-      z->state->mode = CHECK4;
-    case CHECK4:
-      NEEDBYTE
-      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
-      z->state->mode = CHECK3;
-    case CHECK3:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
-      z->state->mode = CHECK2;
-    case CHECK2:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
-      z->state->mode = CHECK1;
-    case CHECK1:
-      NEEDBYTE
-      z->state->sub.check.need += (uLong)NEXTBYTE;
-
-      if (z->state->sub.check.was != z->state->sub.check.need)
-      {
-        z->state->mode = BAD;
-        z->msg = "incorrect data check";
-        z->state->sub.marker = 5;       /* can't try inflateSync */
-        break;
-      }
-      Trace((stderr, "inflate: zlib check ok\n"));
-      z->state->mode = DONE;
-    case DONE:
-      return Z_STREAM_END;
-    case BAD:
-      return Z_DATA_ERROR;
-    default:
-      return Z_STREAM_ERROR;
-  }
-
- empty:
-  if (f != Z_PACKET_FLUSH)
-    return r;
-  z->state->mode = BAD;
-  z->state->sub.marker = 0;       /* can try inflateSync */
-  return Z_DATA_ERROR;
-}
-
-/*
- * This subroutine adds the data at next_in/avail_in to the output history
- * without performing any output.  The output buffer must be "caught up";
- * i.e. no pending output (hence s->read equals s->write), and the state must
- * be BLOCKS (i.e. we should be willing to see the start of a series of
- * BLOCKS).  On exit, the output will also be caught up, and the checksum
- * will have been updated if need be.
- */
-
-int inflateIncomp(z)
-z_stream *z;
-{
-    if (z->state->mode != BLOCKS)
-       return Z_DATA_ERROR;
-    return inflate_addhistory(z->state->blocks, z);
-}
-
-
-int inflateSync(z)
-z_stream *z;
-{
-  uInt n;       /* number of bytes to look at */
-  Bytef *p;     /* pointer to bytes */
-  uInt m;       /* number of marker bytes found in a row */
-  uLong r, w;   /* temporaries to save total_in and total_out */
-
-  /* set up */
-  if (z == Z_NULL || z->state == Z_NULL)
-    return Z_STREAM_ERROR;
-  if (z->state->mode != BAD)
-  {
-    z->state->mode = BAD;
-    z->state->sub.marker = 0;
-  }
-  if ((n = z->avail_in) == 0)
-    return Z_BUF_ERROR;
-  p = z->next_in;
-  m = z->state->sub.marker;
-
-  /* search */
-  while (n && m < 4)
-  {
-    if (*p == (Byte)(m < 2 ? 0 : 0xff))
-      m++;
-    else if (*p)
-      m = 0;
-    else
-      m = 4 - m;
-    p++, n--;
-  }
-
-  /* restore */
-  z->total_in += p - z->next_in;
-  z->next_in = p;
-  z->avail_in = n;
-  z->state->sub.marker = m;
-
-  /* return no joy or set up to restart on a new block */
-  if (m != 4)
-    return Z_DATA_ERROR;
-  r = z->total_in;  w = z->total_out;
-  inflateReset(z);
-  z->total_in = r;  z->total_out = w;
-  z->state->mode = BLOCKS;
-  return Z_OK;
-}
-
-#undef NEEDBYTE
-#undef NEXTBYTE
-
-/*+++++*/
-/* infutil.h -- types and macros common to blocks and codes
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-/* inflate blocks semi-private state */
-struct inflate_blocks_state {
-
-  /* mode */
-  enum {
-      TYPE,     /* get type bits (3, including end bit) */
-      LENS,     /* get lengths for stored */
-      STORED,   /* processing stored block */
-      TABLE,    /* get table lengths */
-      BTREE,    /* get bit lengths tree for a dynamic block */
-      DTREE,    /* get length, distance trees for a dynamic block */
-      CODES,    /* processing fixed or dynamic block */
-      DRY,      /* output remaining window bytes */
-      DONEB,     /* finished last block, done */
-      BADB}      /* got a data error--stuck here */
-    mode;               /* current inflate_block mode */
-
-  /* mode dependent information */
-  union {
-    uInt left;          /* if STORED, bytes left to copy */
-    struct {
-      uInt table;               /* table lengths (14 bits) */
-      uInt index;               /* index into blens (or border) */
-      uIntf *blens;             /* bit lengths of codes */
-      uInt bb;                  /* bit length tree depth */
-      inflate_huft *tb;         /* bit length decoding tree */
-      int nblens;              /* # elements allocated at blens */
-    } trees;            /* if DTREE, decoding info for trees */
-    struct {
-      inflate_huft *tl, *td;    /* trees to free */
-      inflate_codes_statef 
-         *codes;
-    } decode;           /* if CODES, current state */
-  } sub;                /* submode */
-  uInt last;            /* true if this block is the last block */
-
-  /* mode independent information */
-  uInt bitk;            /* bits in bit buffer */
-  uLong bitb;           /* bit buffer */
-  Bytef *window;        /* sliding window */
-  Bytef *end;           /* one byte after sliding window */
-  Bytef *read;          /* window read pointer */
-  Bytef *write;         /* window write pointer */
-  check_func checkfn;   /* check function */
-  uLong check;          /* check on output */
-
-};
-
-
-/* defines for inflate input/output */
-/*   update pointers and return */
-#define UPDBITS {s->bitb=b;s->bitk=k;}
-#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
-#define UPDOUT {s->write=q;}
-#define UPDATE {UPDBITS UPDIN UPDOUT}
-#define LEAVE {UPDATE return inflate_flush(s,z,r);}
-/*   get bytes and bits */
-#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
-#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
-#define NEXTBYTE (n--,*p++)
-#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
-#define DUMPBITS(j) {b>>=(j);k-=(j);}
-/*   output bytes */
-#define WAVAIL (q<s->read?s->read-q-1:s->end-q)
-#define LOADOUT {q=s->write;m=WAVAIL;}
-#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}}
-#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
-#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
-#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
-/*   load local pointers */
-#define LOAD {LOADIN LOADOUT}
-
-/* And'ing with mask[n] masks the lower n bits */
-local uInt inflate_mask[] = {
-    0x0000,
-    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
-    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
-};
-
-/* copy as much as possible from the sliding window to the output area */
-local int inflate_flush OF((
-    inflate_blocks_statef *,
-    z_stream *,
-    int));
-
-/*+++++*/
-/* inffast.h -- header to use inffast.c
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* WARNING: this file should *not* be used by applications. It is
-   part of the implementation of the compression library and is
-   subject to change. Applications should only use zlib.h.
- */
-
-local int inflate_fast OF((
-    uInt,
-    uInt,
-    inflate_huft *,
-    inflate_huft *,
-    inflate_blocks_statef *,
-    z_stream *));
-
-
-/*+++++*/
-/* infblock.c -- interpret and process block types to last block
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* Table for deflate from PKZIP's appnote.txt. */
-local uInt border[] = { /* Order of the bit length code lengths */
-        16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
-
-/*
-   Notes beyond the 1.93a appnote.txt:
-
-   1. Distance pointers never point before the beginning of the output
-      stream.
-   2. Distance pointers can point back across blocks, up to 32k away.
-   3. There is an implied maximum of 7 bits for the bit length table and
-      15 bits for the actual data.
-   4. If only one code exists, then it is encoded using one bit.  (Zero
-      would be more efficient, but perhaps a little confusing.)  If two
-      codes exist, they are coded using one bit each (0 and 1).
-   5. There is no way of sending zero distance codes--a dummy must be
-      sent if there are none.  (History: a pre 2.0 version of PKZIP would
-      store blocks with no distance codes, but this was discovered to be
-      too harsh a criterion.)  Valid only for 1.93a.  2.04c does allow
-      zero distance codes, which is sent as one code of zero bits in
-      length.
-   6. There are up to 286 literal/length codes.  Code 256 represents the
-      end-of-block.  Note however that the static length tree defines
-      288 codes just to fill out the Huffman codes.  Codes 286 and 287
-      cannot be used though, since there is no length base or extra bits
-      defined for them.  Similarily, there are up to 30 distance codes.
-      However, static trees define 32 codes (all 5 bits) to fill out the
-      Huffman codes, but the last two had better not show up in the data.
-   7. Unzip can check dynamic Huffman blocks for complete code sets.
-      The exception is that a single code would not be complete (see #4).
-   8. The five bits following the block type is really the number of
-      literal codes sent minus 257.
-   9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
-      (1+6+6).  Therefore, to output three times the length, you output
-      three codes (1+1+1), whereas to output four times the same length,
-      you only need two codes (1+3).  Hmm.
-  10. In the tree reconstruction algorithm, Code = Code + Increment
-      only if BitLength(i) is not zero.  (Pretty obvious.)
-  11. Correction: 4 Bits: # of Bit Length codes - 4     (4 - 19)
-  12. Note: length code 284 can represent 227-258, but length code 285
-      really is 258.  The last length deserves its own, short code
-      since it gets used a lot in very redundant files.  The length
-      258 is special since 258 - 3 (the min match length) is 255.
-  13. The literal/length and distance code bit lengths are read as a
-      single stream of lengths.  It is possible (and advantageous) for
-      a repeat code (16, 17, or 18) to go across the boundary between
-      the two sets of lengths.
- */
-
-
-local void inflate_blocks_reset(s, z, c)
-inflate_blocks_statef *s;
-z_stream *z;
-uLongf *c;
-{
-  if (s->checkfn != Z_NULL)
-    *c = s->check;
-  if (s->mode == BTREE || s->mode == DTREE)
-    ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
-  if (s->mode == CODES)
-  {
-    inflate_codes_free(s->sub.decode.codes, z);
-    inflate_trees_free(s->sub.decode.td, z);
-    inflate_trees_free(s->sub.decode.tl, z);
-  }
-  s->mode = TYPE;
-  s->bitk = 0;
-  s->bitb = 0;
-  s->read = s->write = s->window;
-  if (s->checkfn != Z_NULL)
-    s->check = (*s->checkfn)(0L, Z_NULL, 0);
-  Trace((stderr, "inflate:   blocks reset\n"));
-}
-
-
-local inflate_blocks_statef *inflate_blocks_new(z, c, w)
-z_stream *z;
-check_func c;
-uInt w;
-{
-  inflate_blocks_statef *s;
-
-  if ((s = (inflate_blocks_statef *)ZALLOC
-       (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
-    return s;
-  if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
-  {
-    ZFREE(z, s, sizeof(struct inflate_blocks_state));
-    return Z_NULL;
-  }
-  s->end = s->window + w;
-  s->checkfn = c;
-  s->mode = TYPE;
-  Trace((stderr, "inflate:   blocks allocated\n"));
-  inflate_blocks_reset(s, z, &s->check);
-  return s;
-}
-
-
-local int inflate_blocks(s, z, r)
-inflate_blocks_statef *s;
-z_stream *z;
-int r;
-{
-  uInt t;               /* temporary storage */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-
-  /* copy input/output information to locals (UPDATE macro restores) */
-  LOAD
-
-  /* process input based on current state */
-  while (1) switch (s->mode)
-  {
-    case TYPE:
-      NEEDBITS(3)
-      t = (uInt)b & 7;
-      s->last = t & 1;
-      switch (t >> 1)
-      {
-        case 0:                         /* stored */
-          Trace((stderr, "inflate:     stored block%s\n",
-                 s->last ? " (last)" : ""));
-          DUMPBITS(3)
-          t = k & 7;                    /* go to byte boundary */
-          DUMPBITS(t)
-          s->mode = LENS;               /* get length of stored block */
-          break;
-        case 1:                         /* fixed */
-          Trace((stderr, "inflate:     fixed codes block%s\n",
-                 s->last ? " (last)" : ""));
-          {
-            uInt bl, bd;
-            inflate_huft *tl, *td;
-
-            inflate_trees_fixed(&bl, &bd, &tl, &td);
-            s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
-            if (s->sub.decode.codes == Z_NULL)
-            {
-              r = Z_MEM_ERROR;
-              LEAVE
-            }
-            s->sub.decode.tl = Z_NULL;  /* don't try to free these */
-            s->sub.decode.td = Z_NULL;
-          }
-          DUMPBITS(3)
-          s->mode = CODES;
-          break;
-        case 2:                         /* dynamic */
-          Trace((stderr, "inflate:     dynamic codes block%s\n",
-                 s->last ? " (last)" : ""));
-          DUMPBITS(3)
-          s->mode = TABLE;
-          break;
-        case 3:                         /* illegal */
-          DUMPBITS(3)
-          s->mode = BADB;
-          z->msg = "invalid block type";
-          r = Z_DATA_ERROR;
-          LEAVE
-      }
-      break;
-    case LENS:
-      NEEDBITS(32)
-      if (((~b) >> 16) != (b & 0xffff))
-      {
-        s->mode = BADB;
-        z->msg = "invalid stored block lengths";
-        r = Z_DATA_ERROR;
-        LEAVE
-      }
-      s->sub.left = (uInt)b & 0xffff;
-      b = k = 0;                      /* dump bits */
-      Tracev((stderr, "inflate:       stored length %u\n", s->sub.left));
-      s->mode = s->sub.left ? STORED : TYPE;
-      break;
-    case STORED:
-      if (n == 0)
-        LEAVE
-      NEEDOUT
-      t = s->sub.left;
-      if (t > n) t = n;
-      if (t > m) t = m;
-      zmemcpy(q, p, t);
-      p += t;  n -= t;
-      q += t;  m -= t;
-      if ((s->sub.left -= t) != 0)
-        break;
-      Tracev((stderr, "inflate:       stored end, %lu total out\n",
-              z->total_out + (q >= s->read ? q - s->read :
-              (s->end - s->read) + (q - s->window))));
-      s->mode = s->last ? DRY : TYPE;
-      break;
-    case TABLE:
-      NEEDBITS(14)
-      s->sub.trees.table = t = (uInt)b & 0x3fff;
-#ifndef PKZIP_BUG_WORKAROUND
-      if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
-      {
-        s->mode = BADB;
-        z->msg = "too many length or distance symbols";
-        r = Z_DATA_ERROR;
-        LEAVE
-      }
-#endif
-      t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
-      if (t < 19)
-        t = 19;
-      if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
-      {
-        r = Z_MEM_ERROR;
-        LEAVE
-      }
-      s->sub.trees.nblens = t;
-      DUMPBITS(14)
-      s->sub.trees.index = 0;
-      Tracev((stderr, "inflate:       table sizes ok\n"));
-      s->mode = BTREE;
-    case BTREE:
-      while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
-      {
-        NEEDBITS(3)
-        s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
-        DUMPBITS(3)
-      }
-      while (s->sub.trees.index < 19)
-        s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
-      s->sub.trees.bb = 7;
-      t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
-                             &s->sub.trees.tb, z);
-      if (t != Z_OK)
-      {
-        r = t;
-        if (r == Z_DATA_ERROR)
-          s->mode = BADB;
-        LEAVE
-      }
-      s->sub.trees.index = 0;
-      Tracev((stderr, "inflate:       bits tree ok\n"));
-      s->mode = DTREE;
-    case DTREE:
-      while (t = s->sub.trees.table,
-             s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
-      {
-        inflate_huft *h;
-        uInt i, j, c;
-
-        t = s->sub.trees.bb;
-        NEEDBITS(t)
-        h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
-        t = h->word.what.Bits;
-        c = h->more.Base;
-        if (c < 16)
-        {
-          DUMPBITS(t)
-          s->sub.trees.blens[s->sub.trees.index++] = c;
-        }
-        else /* c == 16..18 */
-        {
-          i = c == 18 ? 7 : c - 14;
-          j = c == 18 ? 11 : 3;
-          NEEDBITS(t + i)
-          DUMPBITS(t)
-          j += (uInt)b & inflate_mask[i];
-          DUMPBITS(i)
-          i = s->sub.trees.index;
-          t = s->sub.trees.table;
-          if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
-              (c == 16 && i < 1))
-          {
-            s->mode = BADB;
-            z->msg = "invalid bit length repeat";
-            r = Z_DATA_ERROR;
-            LEAVE
-          }
-          c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
-          do {
-            s->sub.trees.blens[i++] = c;
-          } while (--j);
-          s->sub.trees.index = i;
-        }
-      }
-      inflate_trees_free(s->sub.trees.tb, z);
-      s->sub.trees.tb = Z_NULL;
-      {
-        uInt bl, bd;
-        inflate_huft *tl, *td;
-        inflate_codes_statef *c;
-
-        bl = 9;         /* must be <= 9 for lookahead assumptions */
-        bd = 6;         /* must be <= 9 for lookahead assumptions */
-        t = s->sub.trees.table;
-        t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
-                                  s->sub.trees.blens, &bl, &bd, &tl, &td, z);
-        if (t != Z_OK)
-        {
-          if (t == (uInt)Z_DATA_ERROR)
-            s->mode = BADB;
-          r = t;
-          LEAVE
-        }
-        Tracev((stderr, "inflate:       trees ok\n"));
-        if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
-        {
-          inflate_trees_free(td, z);
-          inflate_trees_free(tl, z);
-          r = Z_MEM_ERROR;
-          LEAVE
-        }
-        ZFREE(z, s->sub.trees.blens, s->sub.trees.nblens * sizeof(uInt));
-        s->sub.decode.codes = c;
-        s->sub.decode.tl = tl;
-        s->sub.decode.td = td;
-      }
-      s->mode = CODES;
-    case CODES:
-      UPDATE
-      if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
-        return inflate_flush(s, z, r);
-      r = Z_OK;
-      inflate_codes_free(s->sub.decode.codes, z);
-      inflate_trees_free(s->sub.decode.td, z);
-      inflate_trees_free(s->sub.decode.tl, z);
-      LOAD
-      Tracev((stderr, "inflate:       codes end, %lu total out\n",
-              z->total_out + (q >= s->read ? q - s->read :
-              (s->end - s->read) + (q - s->window))));
-      if (!s->last)
-      {
-        s->mode = TYPE;
-        break;
-      }
-      if (k > 7)              /* return unused byte, if any */
-      {
-        Assert(k < 16, "inflate_codes grabbed too many bytes")
-        k -= 8;
-        n++;
-        p--;                    /* can always return one */
-      }
-      s->mode = DRY;
-    case DRY:
-      FLUSH
-      if (s->read != s->write)
-        LEAVE
-      s->mode = DONEB;
-    case DONEB:
-      r = Z_STREAM_END;
-      LEAVE
-    case BADB:
-      r = Z_DATA_ERROR;
-      LEAVE
-    default:
-      r = Z_STREAM_ERROR;
-      LEAVE
-  }
-}
-
-
-local int inflate_blocks_free(s, z, c)
-inflate_blocks_statef *s;
-z_stream *z;
-uLongf *c;
-{
-  inflate_blocks_reset(s, z, c);
-  ZFREE(z, s->window, s->end - s->window);
-  ZFREE(z, s, sizeof(struct inflate_blocks_state));
-  Trace((stderr, "inflate:   blocks freed\n"));
-  return Z_OK;
-}
-
-/*
- * This subroutine adds the data at next_in/avail_in to the output history
- * without performing any output.  The output buffer must be "caught up";
- * i.e. no pending output (hence s->read equals s->write), and the state must
- * be BLOCKS (i.e. we should be willing to see the start of a series of
- * BLOCKS).  On exit, the output will also be caught up, and the checksum
- * will have been updated if need be.
- */
-local int inflate_addhistory(s, z)
-inflate_blocks_statef *s;
-z_stream *z;
-{
-    uLong b;              /* bit buffer */  /* NOT USED HERE */
-    uInt k;               /* bits in bit buffer */ /* NOT USED HERE */
-    uInt t;               /* temporary storage */
-    Bytef *p;             /* input data pointer */
-    uInt n;               /* bytes available there */
-    Bytef *q;             /* output window write pointer */
-    uInt m;               /* bytes to end of window or read pointer */
-
-    if (s->read != s->write)
-       return Z_STREAM_ERROR;
-    if (s->mode != TYPE)
-       return Z_DATA_ERROR;
-
-    /* we're ready to rock */
-    LOAD
-    /* while there is input ready, copy to output buffer, moving
-     * pointers as needed.
-     */
-    while (n) {
-       t = n;  /* how many to do */
-       /* is there room until end of buffer? */
-       if (t > m) t = m;
-       /* update check information */
-       if (s->checkfn != Z_NULL)
-           s->check = (*s->checkfn)(s->check, q, t);
-       zmemcpy(q, p, t);
-       q += t;
-       p += t;
-       n -= t;
-       z->total_out += t;
-       s->read = q;    /* drag read pointer forward */
-/*      WRAP  */       /* expand WRAP macro by hand to handle s->read */
-       if (q == s->end) {
-           s->read = q = s->window;
-           m = WAVAIL;
-       }
-    }
-    UPDATE
-    return Z_OK;
-}
-
-
-/*
- * At the end of a Deflate-compressed PPP packet, we expect to have seen
- * a `stored' block type value but not the (zero) length bytes.
- */
-local int inflate_packet_flush(s)
-    inflate_blocks_statef *s;
-{
-    if (s->mode != LENS)
-       return Z_DATA_ERROR;
-    s->mode = TYPE;
-    return Z_OK;
-}
-
-
-/*+++++*/
-/* inftrees.c -- generate Huffman trees for efficient decoding
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-
-local int huft_build OF((
-    uIntf *,            /* code lengths in bits */
-    uInt,               /* number of codes */
-    uInt,               /* number of "simple" codes */
-    uIntf *,            /* list of base values for non-simple codes */
-    uIntf *,            /* list of extra bits for non-simple codes */
-    inflate_huft * FAR*,/* result: starting table */
-    uIntf *,            /* maximum lookup bits (returns actual) */
-    z_stream *));       /* for zalloc function */
-
-local voidpf falloc OF((
-    voidpf,             /* opaque pointer (not used) */
-    uInt,               /* number of items */
-    uInt));             /* size of item */
-
-local void ffree OF((
-    voidpf q,           /* opaque pointer (not used) */
-    voidpf p,           /* what to free (not used) */
-    uInt n));          /* number of bytes (not used) */
-
-/* Tables for deflate from PKZIP's appnote.txt. */
-local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
-        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
-        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
-        /* actually lengths - 2; also see note #13 above about 258 */
-local uInt cplext[] = { /* Extra bits for literal codes 257..285 */
-        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
-        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */
-local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */
-        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
-        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
-        8193, 12289, 16385, 24577};
-local uInt cpdext[] = { /* Extra bits for distance codes */
-        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
-        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
-        12, 12, 13, 13};
-
-/*
-   Huffman code decoding is performed using a multi-level table lookup.
-   The fastest way to decode is to simply build a lookup table whose
-   size is determined by the longest code.  However, the time it takes
-   to build this table can also be a factor if the data being decoded
-   is not very long.  The most common codes are necessarily the
-   shortest codes, so those codes dominate the decoding time, and hence
-   the speed.  The idea is you can have a shorter table that decodes the
-   shorter, more probable codes, and then point to subsidiary tables for
-   the longer codes.  The time it costs to decode the longer codes is
-   then traded against the time it takes to make longer tables.
-
-   This results of this trade are in the variables lbits and dbits
-   below.  lbits is the number of bits the first level table for literal/
-   length codes can decode in one step, and dbits is the same thing for
-   the distance codes.  Subsequent tables are also less than or equal to
-   those sizes.  These values may be adjusted either when all of the
-   codes are shorter than that, in which case the longest code length in
-   bits is used, or when the shortest code is *longer* than the requested
-   table size, in which case the length of the shortest code in bits is
-   used.
-
-   There are two different values for the two tables, since they code a
-   different number of possibilities each.  The literal/length table
-   codes 286 possible values, or in a flat code, a little over eight
-   bits.  The distance table codes 30 possible values, or a little less
-   than five bits, flat.  The optimum values for speed end up being
-   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
-   The optimum values may differ though from machine to machine, and
-   possibly even between compilers.  Your mileage may vary.
- */
-
-
-/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
-#define BMAX 15         /* maximum bit length of any code */
-#define N_MAX 288       /* maximum number of codes in any set */
-
-#ifdef DEBUG_ZLIB
-  uInt inflate_hufts;
-#endif
-
-local int huft_build(b, n, s, d, e, t, m, zs)
-uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
-uInt n;                 /* number of codes (assumed <= N_MAX) */
-uInt s;                 /* number of simple-valued codes (0..s-1) */
-uIntf *d;               /* list of base values for non-simple codes */
-uIntf *e;               /* list of extra bits for non-simple codes */  
-inflate_huft * FAR *t;  /* result: starting table */
-uIntf *m;               /* maximum lookup bits, returns actual */
-z_stream *zs;           /* for zalloc function */
-/* Given a list of code lengths and a maximum table size, make a set of
-   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
-   if the given code set is incomplete (the tables are still built in this
-   case), Z_DATA_ERROR if the input is invalid (all zero length codes or an
-   over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */
-{
-
-  uInt a;                       /* counter for codes of length k */
-  uInt c[BMAX+1];               /* bit length count table */
-  uInt f;                       /* i repeats in table every f entries */
-  int g;                        /* maximum code length */
-  int h;                        /* table level */
-  register uInt i;              /* counter, current code */
-  register uInt j;              /* counter */
-  register int k;               /* number of bits in current code */
-  int l;                        /* bits per table (returned in m) */
-  register uIntf *p;            /* pointer into c[], b[], or v[] */
-  inflate_huft *q;              /* points to current table */
-  struct inflate_huft_s r;      /* table entry for structure assignment */
-  inflate_huft *u[BMAX];        /* table stack */
-  uInt v[N_MAX];                /* values in order of bit length */
-  register int w;               /* bits before this table == (l * h) */
-  uInt x[BMAX+1];               /* bit offsets, then code stack */
-  uIntf *xp;                    /* pointer into x */
-  int y;                        /* number of dummy codes added */
-  uInt z;                       /* number of entries in current table */
-
-
-  /* Generate counts for each bit length */
-  p = c;
-#define C0 *p++ = 0;
-#define C2 C0 C0 C0 C0
-#define C4 C2 C2 C2 C2
-  C4                            /* clear c[]--assume BMAX+1 is 16 */
-  p = b;  i = n;
-  do {
-    c[*p++]++;                  /* assume all entries <= BMAX */
-  } while (--i);
-  if (c[0] == n)                /* null input--all zero length codes */
-  {
-    *t = (inflate_huft *)Z_NULL;
-    *m = 0;
-    return Z_OK;
-  }
-
-
-  /* Find minimum and maximum length, bound *m by those */
-  l = *m;
-  for (j = 1; j <= BMAX; j++)
-    if (c[j])
-      break;
-  k = j;                        /* minimum code length */
-  if ((uInt)l < j)
-    l = j;
-  for (i = BMAX; i; i--)
-    if (c[i])
-      break;
-  g = i;                        /* maximum code length */
-  if ((uInt)l > i)
-    l = i;
-  *m = l;
-
-
-  /* Adjust last length count to fill out codes, if needed */
-  for (y = 1 << j; j < i; j++, y <<= 1)
-    if ((y -= c[j]) < 0)
-      return Z_DATA_ERROR;
-  if ((y -= c[i]) < 0)
-    return Z_DATA_ERROR;
-  c[i] += y;
-
-
-  /* Generate starting offsets into the value table for each length */
-  x[1] = j = 0;
-  p = c + 1;  xp = x + 2;
-  while (--i) {                 /* note that i == g from above */
-    *xp++ = (j += *p++);
-  }
-
-
-  /* Make a table of values in order of bit lengths */
-  p = b;  i = 0;
-  do {
-    if ((j = *p++) != 0)
-      v[x[j]++] = i;
-  } while (++i < n);
-
-
-  /* Generate the Huffman codes and for each, make the table entries */
-  x[0] = i = 0;                 /* first Huffman code is zero */
-  p = v;                        /* grab values in bit order */
-  h = -1;                       /* no tables yet--level -1 */
-  w = -l;                       /* bits decoded == (l * h) */
-  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
-  q = (inflate_huft *)Z_NULL;   /* ditto */
-  z = 0;                        /* ditto */
-
-  /* go through the bit lengths (k already is bits in shortest code) */
-  for (; k <= g; k++)
-  {
-    a = c[k];
-    while (a--)
-    {
-      /* here i is the Huffman code of length k bits for value *p */
-      /* make tables up to required level */
-      while (k > w + l)
-      {
-        h++;
-        w += l;                 /* previous table always l bits */
-
-        /* compute minimum size table less than or equal to l bits */
-        z = (z = g - w) > (uInt)l ? l : z;      /* table size upper limit */
-        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
-        {                       /* too few codes for k-w bit table */
-          f -= a + 1;           /* deduct codes from patterns left */
-          xp = c + k;
-          if (j < z)
-            while (++j < z)     /* try smaller tables up to z bits */
-            {
-              if ((f <<= 1) <= *++xp)
-                break;          /* enough codes to use up j bits */
-              f -= *xp;         /* else deduct codes from patterns */
-            }
-        }
-        z = 1 << j;             /* table entries for j-bit table */
-
-        /* allocate and link in new table */
-        if ((q = (inflate_huft *)ZALLOC
-             (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
-        {
-          if (h)
-            inflate_trees_free(u[0], zs);
-          return Z_MEM_ERROR;   /* not enough memory */
-        }
-       q->word.Nalloc = z + 1;
-#ifdef DEBUG_ZLIB
-        inflate_hufts += z + 1;
-#endif
-        *t = q + 1;             /* link to list for huft_free() */
-        *(t = &(q->next)) = Z_NULL;
-        u[h] = ++q;             /* table starts after link */
-
-        /* connect to last table, if there is one */
-        if (h)
-        {
-          x[h] = i;             /* save pattern for backing up */
-          r.bits = (Byte)l;     /* bits to dump before this table */
-          r.exop = (Byte)j;     /* bits in this table */
-          r.next = q;           /* pointer to this table */
-          j = i >> (w - l);     /* (get around Turbo C bug) */
-          u[h-1][j] = r;        /* connect to last table */
-        }
-      }
-
-      /* set up table entry in r */
-      r.bits = (Byte)(k - w);
-      if (p >= v + n)
-        r.exop = 128 + 64;      /* out of values--invalid code */
-      else if (*p < s)
-      {
-        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
-        r.base = *p++;          /* simple code is just the value */
-      }
-      else
-      {
-        r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */
-        r.base = d[*p++ - s];
-      }
-
-      /* fill code-like entries with r */
-      f = 1 << (k - w);
-      for (j = i >> w; j < z; j += f)
-        q[j] = r;
-
-      /* backwards increment the k-bit code i */
-      for (j = 1 << (k - 1); i & j; j >>= 1)
-        i ^= j;
-      i ^= j;
-
-      /* backup over finished tables */
-      while ((i & ((1 << w) - 1)) != x[h])
-      {
-        h--;                    /* don't need to update q */
-        w -= l;
-      }
-    }
-  }
-
-
-  /* Return Z_BUF_ERROR if we were given an incomplete table */
-  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
-}
-
-
-local int inflate_trees_bits(c, bb, tb, z)
-uIntf *c;               /* 19 code lengths */
-uIntf *bb;              /* bits tree desired/actual depth */
-inflate_huft * FAR *tb; /* bits tree result */
-z_stream *z;            /* for zfree function */
-{
-  int r;
-
-  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
-  if (r == Z_DATA_ERROR)
-    z->msg = "oversubscribed dynamic bit lengths tree";
-  else if (r == Z_BUF_ERROR)
-  {
-    inflate_trees_free(*tb, z);
-    z->msg = "incomplete dynamic bit lengths tree";
-    r = Z_DATA_ERROR;
-  }
-  return r;
-}
-
-
-local int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
-uInt nl;                /* number of literal/length codes */
-uInt nd;                /* number of distance codes */
-uIntf *c;               /* that many (total) code lengths */
-uIntf *bl;              /* literal desired/actual bit depth */
-uIntf *bd;              /* distance desired/actual bit depth */
-inflate_huft * FAR *tl; /* literal/length tree result */
-inflate_huft * FAR *td; /* distance tree result */
-z_stream *z;            /* for zfree function */
-{
-  int r;
-
-  /* build literal/length tree */
-  if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK)
-  {
-    if (r == Z_DATA_ERROR)
-      z->msg = "oversubscribed literal/length tree";
-    else if (r == Z_BUF_ERROR)
-    {
-      inflate_trees_free(*tl, z);
-      z->msg = "incomplete literal/length tree";
-      r = Z_DATA_ERROR;
-    }
-    return r;
-  }
-
-  /* build distance tree */
-  if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK)
-  {
-    if (r == Z_DATA_ERROR)
-      z->msg = "oversubscribed literal/length tree";
-    else if (r == Z_BUF_ERROR) {
-#ifdef PKZIP_BUG_WORKAROUND
-      r = Z_OK;
-    }
-#else
-      inflate_trees_free(*td, z);
-      z->msg = "incomplete literal/length tree";
-      r = Z_DATA_ERROR;
-    }
-    inflate_trees_free(*tl, z);
-    return r;
-#endif
-  }
-
-  /* done */
-  return Z_OK;
-}
-
-
-/* build fixed tables only once--keep them here */
-local int fixed_lock = 0;
-local int fixed_built = 0;
-#define FIXEDH 530      /* number of hufts used by fixed tables */
-local uInt fixed_left = FIXEDH;
-local inflate_huft fixed_mem[FIXEDH];
-local uInt fixed_bl;
-local uInt fixed_bd;
-local inflate_huft *fixed_tl;
-local inflate_huft *fixed_td;
-
-
-local voidpf falloc(q, n, s)
-voidpf q;        /* opaque pointer (not used) */
-uInt n;         /* number of items */
-uInt s;         /* size of item */
-{
-  Assert(s == sizeof(inflate_huft) && n <= fixed_left,
-         "inflate_trees falloc overflow");
-  if (q) s++; /* to make some compilers happy */
-  fixed_left -= n;
-  return (voidpf)(fixed_mem + fixed_left);
-}
-
-
-local void ffree(q, p, n)
-voidpf q;
-voidpf p;
-uInt n;
-{
-  Assert(0, "inflate_trees ffree called!");
-  if (q) q = p; /* to make some compilers happy */
-}
-
-
-local int inflate_trees_fixed(bl, bd, tl, td)
-uIntf *bl;               /* literal desired/actual bit depth */
-uIntf *bd;               /* distance desired/actual bit depth */
-inflate_huft * FAR *tl;  /* literal/length tree result */
-inflate_huft * FAR *td;  /* distance tree result */
-{
-  /* build fixed tables if not built already--lock out other instances */
-  while (++fixed_lock > 1)
-    fixed_lock--;
-  if (!fixed_built)
-  {
-    int k;              /* temporary variable */
-    unsigned c[288];    /* length list for huft_build */
-    z_stream z;         /* for falloc function */
-
-    /* set up fake z_stream for memory routines */
-    z.zalloc = falloc;
-    z.zfree = ffree;
-    z.opaque = Z_NULL;
-
-    /* literal table */
-    for (k = 0; k < 144; k++)
-      c[k] = 8;
-    for (; k < 256; k++)
-      c[k] = 9;
-    for (; k < 280; k++)
-      c[k] = 7;
-    for (; k < 288; k++)
-      c[k] = 8;
-    fixed_bl = 7;
-    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
-
-    /* distance table */
-    for (k = 0; k < 30; k++)
-      c[k] = 5;
-    fixed_bd = 5;
-    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
-
-    /* done */
-    fixed_built = 1;
-  }
-  fixed_lock--;
-  *bl = fixed_bl;
-  *bd = fixed_bd;
-  *tl = fixed_tl;
-  *td = fixed_td;
-  return Z_OK;
-}
-
-
-local int inflate_trees_free(t, z)
-inflate_huft *t;        /* table to free */
-z_stream *z;            /* for zfree function */
-/* Free the malloc'ed tables built by huft_build(), which makes a linked
-   list of the tables it made, with the links in a dummy first entry of
-   each table. */
-{
-  register inflate_huft *p, *q;
-
-  /* Go through linked list, freeing from the malloced (t[-1]) address. */
-  p = t;
-  while (p != Z_NULL)
-  {
-    q = (--p)->next;
-    ZFREE(z, p, p->word.Nalloc * sizeof(inflate_huft));
-    p = q;
-  } 
-  return Z_OK;
-}
-
-/*+++++*/
-/* infcodes.c -- process literals and length/distance pairs
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-/* inflate codes private state */
-struct inflate_codes_state {
-
-  /* mode */
-  enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
-      START,    /* x: set up for LEN */
-      LEN,      /* i: get length/literal/eob next */
-      LENEXT,   /* i: getting length extra (have base) */
-      DIST,     /* i: get distance next */
-      DISTEXT,  /* i: getting distance extra */
-      COPY,     /* o: copying bytes in window, waiting for space */
-      LIT,      /* o: got literal, waiting for output space */
-      WASH,     /* o: got eob, possibly still output waiting */
-      END,      /* x: got eob and all data flushed */
-      BADCODE}  /* x: got error */
-    mode;               /* current inflate_codes mode */
-
-  /* mode dependent information */
-  uInt len;
-  union {
-    struct {
-      inflate_huft *tree;       /* pointer into tree */
-      uInt need;                /* bits needed */
-    } code;             /* if LEN or DIST, where in tree */
-    uInt lit;           /* if LIT, literal */
-    struct {
-      uInt get;                 /* bits to get for extra */
-      uInt dist;                /* distance back to copy from */
-    } copy;             /* if EXT or COPY, where and how much */
-  } sub;                /* submode */
-
-  /* mode independent information */
-  Byte lbits;           /* ltree bits decoded per branch */
-  Byte dbits;           /* dtree bits decoder per branch */
-  inflate_huft *ltree;          /* literal/length/eob tree */
-  inflate_huft *dtree;          /* distance tree */
-
-};
-
-
-local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
-uInt bl, bd;
-inflate_huft *tl, *td;
-z_stream *z;
-{
-  inflate_codes_statef *c;
-
-  if ((c = (inflate_codes_statef *)
-       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
-  {
-    c->mode = START;
-    c->lbits = (Byte)bl;
-    c->dbits = (Byte)bd;
-    c->ltree = tl;
-    c->dtree = td;
-    Tracev((stderr, "inflate:       codes new\n"));
-  }
-  return c;
-}
-
-
-local int inflate_codes(s, z, r)
-inflate_blocks_statef *s;
-z_stream *z;
-int r;
-{
-  uInt j;               /* temporary storage */
-  inflate_huft *t;      /* temporary pointer */
-  uInt e;               /* extra bits or operation */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-  Bytef *f;             /* pointer to copy strings from */
-  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */
-
-  /* copy input/output information to locals (UPDATE macro restores) */
-  LOAD
-
-  /* process input and output based on current state */
-  while (1) switch (c->mode)
-  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
-    case START:         /* x: set up for LEN */
-#ifndef SLOW
-      if (m >= 258 && n >= 10)
-      {
-        UPDATE
-        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
-        LOAD
-        if (r != Z_OK)
-        {
-          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
-          break;
-        }
-      }
-#endif /* !SLOW */
-      c->sub.code.need = c->lbits;
-      c->sub.code.tree = c->ltree;
-      c->mode = LEN;
-    case LEN:           /* i: get length/literal/eob next */
-      j = c->sub.code.need;
-      NEEDBITS(j)
-      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
-      DUMPBITS(t->bits)
-      e = (uInt)(t->exop);
-      if (e == 0)               /* literal */
-      {
-        c->sub.lit = t->base;
-        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                 "inflate:         literal '%c'\n" :
-                 "inflate:         literal 0x%02x\n", t->base));
-        c->mode = LIT;
-        break;
-      }
-      if (e & 16)               /* length */
-      {
-        c->sub.copy.get = e & 15;
-        c->len = t->base;
-        c->mode = LENEXT;
-        break;
-      }
-      if ((e & 64) == 0)        /* next table */
-      {
-        c->sub.code.need = e;
-        c->sub.code.tree = t->next;
-        break;
-      }
-      if (e & 32)               /* end of block */
-      {
-        Tracevv((stderr, "inflate:         end of block\n"));
-        c->mode = WASH;
-        break;
-      }
-      c->mode = BADCODE;        /* invalid code */
-      z->msg = "invalid literal/length code";
-      r = Z_DATA_ERROR;
-      LEAVE
-    case LENEXT:        /* i: getting length extra (have base) */
-      j = c->sub.copy.get;
-      NEEDBITS(j)
-      c->len += (uInt)b & inflate_mask[j];
-      DUMPBITS(j)
-      c->sub.code.need = c->dbits;
-      c->sub.code.tree = c->dtree;
-      Tracevv((stderr, "inflate:         length %u\n", c->len));
-      c->mode = DIST;
-    case DIST:          /* i: get distance next */
-      j = c->sub.code.need;
-      NEEDBITS(j)
-      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
-      DUMPBITS(t->bits)
-      e = (uInt)(t->exop);
-      if (e & 16)               /* distance */
-      {
-        c->sub.copy.get = e & 15;
-        c->sub.copy.dist = t->base;
-        c->mode = DISTEXT;
-        break;
-      }
-      if ((e & 64) == 0)        /* next table */
-      {
-        c->sub.code.need = e;
-        c->sub.code.tree = t->next;
-        break;
-      }
-      c->mode = BADCODE;        /* invalid code */
-      z->msg = "invalid distance code";
-      r = Z_DATA_ERROR;
-      LEAVE
-    case DISTEXT:       /* i: getting distance extra */
-      j = c->sub.copy.get;
-      NEEDBITS(j)
-      c->sub.copy.dist += (uInt)b & inflate_mask[j];
-      DUMPBITS(j)
-      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
-      c->mode = COPY;
-    case COPY:          /* o: copying bytes in window, waiting for space */
-#ifndef __TURBOC__ /* Turbo C bug for following expression */
-      f = (uInt)(q - s->window) < c->sub.copy.dist ?
-          s->end - (c->sub.copy.dist - (q - s->window)) :
-          q - c->sub.copy.dist;
-#else
-      f = q - c->sub.copy.dist;
-      if ((uInt)(q - s->window) < c->sub.copy.dist)
-        f = s->end - (c->sub.copy.dist - (q - s->window));
-#endif
-      while (c->len)
-      {
-        NEEDOUT
-        OUTBYTE(*f++)
-        if (f == s->end)
-          f = s->window;
-        c->len--;
-      }
-      c->mode = START;
-      break;
-    case LIT:           /* o: got literal, waiting for output space */
-      NEEDOUT
-      OUTBYTE(c->sub.lit)
-      c->mode = START;
-      break;
-    case WASH:          /* o: got eob, possibly more output */
-      FLUSH
-      if (s->read != s->write)
-        LEAVE
-      c->mode = END;
-    case END:
-      r = Z_STREAM_END;
-      LEAVE
-    case BADCODE:       /* x: got error */
-      r = Z_DATA_ERROR;
-      LEAVE
-    default:
-      r = Z_STREAM_ERROR;
-      LEAVE
-  }
-}
-
-
-local void inflate_codes_free(c, z)
-inflate_codes_statef *c;
-z_stream *z;
-{
-  ZFREE(z, c, sizeof(struct inflate_codes_state));
-  Tracev((stderr, "inflate:       codes free\n"));
-}
-
-/*+++++*/
-/* inflate_util.c -- data and routines common to blocks and codes
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* copy as much as possible from the sliding window to the output area */
-local int inflate_flush(s, z, r)
-inflate_blocks_statef *s;
-z_stream *z;
-int r;
-{
-  uInt n;
-  Bytef *p, *q;
-
-  /* local copies of source and destination pointers */
-  p = z->next_out;
-  q = s->read;
-
-  /* compute number of bytes to copy as far as end of window */
-  n = (uInt)((q <= s->write ? s->write : s->end) - q);
-  if (n > z->avail_out) n = z->avail_out;
-  if (n && r == Z_BUF_ERROR) r = Z_OK;
-
-  /* update counters */
-  z->avail_out -= n;
-  z->total_out += n;
-
-  /* update check information */
-  if (s->checkfn != Z_NULL)
-    s->check = (*s->checkfn)(s->check, q, n);
-
-  /* copy as far as end of window */
-  if (p != NULL) {
-    zmemcpy(p, q, n);
-    p += n;
-  }
-  q += n;
-
-  /* see if more to copy at beginning of window */
-  if (q == s->end)
-  {
-    /* wrap pointers */
-    q = s->window;
-    if (s->write == s->end)
-      s->write = s->window;
-
-    /* compute bytes to copy */
-    n = (uInt)(s->write - q);
-    if (n > z->avail_out) n = z->avail_out;
-    if (n && r == Z_BUF_ERROR) r = Z_OK;
-
-    /* update counters */
-    z->avail_out -= n;
-    z->total_out += n;
-
-    /* update check information */
-    if (s->checkfn != Z_NULL)
-      s->check = (*s->checkfn)(s->check, q, n);
-
-    /* copy */
-    if (p != NULL) {
-      zmemcpy(p, q, n);
-      p += n;
-    }
-    q += n;
-  }
-
-  /* update pointers */
-  z->next_out = p;
-  s->read = q;
-
-  /* done */
-  return r;
-}
-
-
-/*+++++*/
-/* inffast.c -- process literals and length/distance pairs fast
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* simplify the use of the inflate_huft type with some defines */
-#define base more.Base
-#define next more.Next
-#define exop word.what.Exop
-#define bits word.what.Bits
-
-/* macros for bit input with no checking and for returning unused bytes */
-#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
-#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
-
-/* Called with number of bytes left to write in window at least 258
-   (the maximum string length) and number of input bytes available
-   at least ten.  The ten bytes are six bytes for the longest length/
-   distance pair plus four bytes for overloading the bit buffer. */
-
-local int inflate_fast(bl, bd, tl, td, s, z)
-uInt bl, bd;
-inflate_huft *tl, *td;
-inflate_blocks_statef *s;
-z_stream *z;
-{
-  inflate_huft *t;      /* temporary pointer */
-  uInt e;               /* extra bits or operation */
-  uLong b;              /* bit buffer */
-  uInt k;               /* bits in bit buffer */
-  Bytef *p;             /* input data pointer */
-  uInt n;               /* bytes available there */
-  Bytef *q;             /* output window write pointer */
-  uInt m;               /* bytes to end of window or read pointer */
-  uInt ml;              /* mask for literal/length tree */
-  uInt md;              /* mask for distance tree */
-  uInt c;               /* bytes to copy */
-  uInt d;               /* distance back to copy from */
-  Bytef *r;             /* copy source pointer */
-
-  /* load input, output, bit values */
-  LOAD
-
-  /* initialize masks */
-  ml = inflate_mask[bl];
-  md = inflate_mask[bd];
-
-  /* do until not enough input or output space for fast loop */
-  do {                          /* assume called with m >= 258 && n >= 10 */
-    /* get literal/length code */
-    GRABBITS(20)                /* max bits for literal/length code */
-    if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
-    {
-      DUMPBITS(t->bits)
-      Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                "inflate:         * literal '%c'\n" :
-                "inflate:         * literal 0x%02x\n", t->base));
-      *q++ = (Byte)t->base;
-      m--;
-      continue;
-    }
-    do {
-      DUMPBITS(t->bits)
-      if (e & 16)
-      {
-        /* get extra bits for length */
-        e &= 15;
-        c = t->base + ((uInt)b & inflate_mask[e]);
-        DUMPBITS(e)
-        Tracevv((stderr, "inflate:         * length %u\n", c));
-
-        /* decode distance base of block to copy */
-        GRABBITS(15);           /* max bits for distance code */
-        e = (t = td + ((uInt)b & md))->exop;
-        do {
-          DUMPBITS(t->bits)
-          if (e & 16)
-          {
-            /* get extra bits to add to distance base */
-            e &= 15;
-            GRABBITS(e)         /* get extra bits (up to 13) */
-            d = t->base + ((uInt)b & inflate_mask[e]);
-            DUMPBITS(e)
-            Tracevv((stderr, "inflate:         * distance %u\n", d));
-
-            /* do the copy */
-            m -= c;
-            if ((uInt)(q - s->window) >= d)     /* offset before dest */
-            {                                   /*  just copy */
-              r = q - d;
-              *q++ = *r++;  c--;        /* minimum count is three, */
-              *q++ = *r++;  c--;        /*  so unroll loop a little */
-            }
-            else                        /* else offset after destination */
-            {
-              e = d - (q - s->window);  /* bytes from offset to end */
-              r = s->end - e;           /* pointer to offset */
-              if (c > e)                /* if source crosses, */
-              {
-                c -= e;                 /* copy to end of window */
-                do {
-                  *q++ = *r++;
-                } while (--e);
-                r = s->window;          /* copy rest from start of window */
-              }
-            }
-            do {                        /* copy all or what's left */
-              *q++ = *r++;
-            } while (--c);
-            break;
-          }
-          else if ((e & 64) == 0)
-            e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
-          else
-          {
-            z->msg = "invalid distance code";
-            UNGRAB
-            UPDATE
-            return Z_DATA_ERROR;
-          }
-        } while (1);
-        break;
-      }
-      if ((e & 64) == 0)
-      {
-        if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
-        {
-          DUMPBITS(t->bits)
-          Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
-                    "inflate:         * literal '%c'\n" :
-                    "inflate:         * literal 0x%02x\n", t->base));
-          *q++ = (Byte)t->base;
-          m--;
-          break;
-        }
-      }
-      else if (e & 32)
-      {
-        Tracevv((stderr, "inflate:         * end of block\n"));
-        UNGRAB
-        UPDATE
-        return Z_STREAM_END;
-      }
-      else
-      {
-        z->msg = "invalid literal/length code";
-        UNGRAB
-        UPDATE
-        return Z_DATA_ERROR;
-      }
-    } while (1);
-  } while (m >= 258 && n >= 10);
-
-  /* not enough input or output--restore pointers and return */
-  UNGRAB
-  UPDATE
-  return Z_OK;
-}
-
-
-/*+++++*/
-/* zutil.c -- target dependent utility functions for the compression library
- * Copyright (C) 1995 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp */
-
-char *zlib_version = ZLIB_VERSION;
-
-char *z_errmsg[] = {
-"stream end",          /* Z_STREAM_END    1 */
-"",                    /* Z_OK            0 */
-"file error",          /* Z_ERRNO        (-1) */
-"stream error",        /* Z_STREAM_ERROR (-2) */
-"data error",          /* Z_DATA_ERROR   (-3) */
-"insufficient memory", /* Z_MEM_ERROR    (-4) */
-"buffer error",        /* Z_BUF_ERROR    (-5) */
-""};
-
-
-/*+++++*/
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp */
-
-#define BASE 65521L /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf)  {s1 += *buf++; s2 += s1;}
-#define DO2(buf)  DO1(buf); DO1(buf);
-#define DO4(buf)  DO2(buf); DO2(buf);
-#define DO8(buf)  DO4(buf); DO4(buf);
-#define DO16(buf) DO8(buf); DO8(buf);
-
-/* ========================================================================= */
-uLong adler32(adler, buf, len)
-    uLong adler;
-    Bytef *buf;
-    uInt len;
-{
-    unsigned long s1 = adler & 0xffff;
-    unsigned long s2 = (adler >> 16) & 0xffff;
-    int k;
-
-    if (buf == Z_NULL) return 1L;
-
-    while (len > 0) {
-        k = len < NMAX ? len : NMAX;
-        len -= k;
-        while (k >= 16) {
-            DO16(buf);
-            k -= 16;
-        }
-        if (k != 0) do {
-            DO1(buf);
-        } while (--k);
-        s1 %= BASE;
-        s2 %= BASE;
-    }
-    return (s2 << 16) | s1;
-}
diff --git a/pppdump/zlib.h b/pppdump/zlib.h
deleted file mode 100644 (file)
index 082f649..0000000
+++ /dev/null
@@ -1,631 +0,0 @@
-/*     $Id: zlib.h,v 1.1 1999/03/23 03:21:58 paulus Exp $      */
-
-/*
- * This file is derived from zlib.h and zconf.h from the zlib-0.95
- * distribution by Jean-loup Gailly and Mark Adler, with some additions
- * by Paul Mackerras to aid in implementing Deflate compression and
- * decompression for PPP packets.
- */
-
-/* zlib.h -- interface of the 'zlib' general purpose compression library
-  version 0.95, Aug 16th, 1995.
-
-  Copyright (C) 1995 Jean-loup Gailly and Mark Adler
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jean-loup Gailly        Mark Adler
-  gzip@prep.ai.mit.edu    madler@alumni.caltech.edu
- */
-
-#ifndef _ZLIB_H
-#define _ZLIB_H
-
-/* #include "zconf.h" */       /* included directly here */
-
-/* zconf.h -- configuration of the zlib compression library
- * Copyright (C) 1995 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h 
- */
-
-/* From: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp */
-
-/*
-     The library does not install any signal handler. It is recommended to
-  add at least a handler for SIGSEGV when decompressing; the library checks
-  the consistency of the input data whenever possible but may go nuts
-  for some forms of corrupted input.
- */
-
-/*
- * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
- * than 64k bytes at a time (needed on systems with 16-bit int).
- * Compile with -DUNALIGNED_OK if it is OK to access shorts or ints
- * at addresses which are not a multiple of their size.
- * Under DOS, -DFAR=far or -DFAR=__far may be needed.
- */
-
-#ifndef STDC
-#  if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
-#    define STDC
-#  endif
-#endif
-
-#ifdef __MWERKS__ /* Metrowerks CodeWarrior declares fileno() in unix.h */
-#  include <unix.h>
-#endif
-
-/* Maximum value for memLevel in deflateInit2 */
-#ifndef MAX_MEM_LEVEL
-#  ifdef MAXSEG_64K
-#    define MAX_MEM_LEVEL 8
-#  else
-#    define MAX_MEM_LEVEL 9
-#  endif
-#endif
-
-#ifndef FAR
-#  define FAR
-#endif
-
-/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
-#ifndef MAX_WBITS
-#  define MAX_WBITS   15 /* 32K LZ77 window */
-#endif
-
-/* The memory requirements for deflate are (in bytes):
-            1 << (windowBits+2)   +  1 << (memLevel+9)
- that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
- plus a few kilobytes for small objects. For example, if you want to reduce
- the default memory requirements from 256K to 128K, compile with
-     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
- Of course this will generally degrade compression (there's no free lunch).
-
-   The memory requirements for inflate are (in bytes) 1 << windowBits
- that is, 32K for windowBits=15 (default value) plus a few kilobytes
- for small objects.
-*/
-
-                        /* Type declarations */
-
-#ifndef OF /* function prototypes */
-#  ifdef STDC
-#    define OF(args)  args
-#  else
-#    define OF(args)  ()
-#  endif
-#endif
-
-typedef unsigned char  Byte;  /* 8 bits */
-typedef unsigned int   uInt;  /* 16 bits or more */
-typedef unsigned long  uLong; /* 32 bits or more */
-
-typedef Byte FAR Bytef;
-typedef char FAR charf;
-typedef int FAR intf;
-typedef uInt FAR uIntf;
-typedef uLong FAR uLongf;
-
-#ifdef STDC
-   typedef void FAR *voidpf;
-   typedef void     *voidp;
-#else
-   typedef Byte FAR *voidpf;
-   typedef Byte     *voidp;
-#endif
-
-/* end of original zconf.h */
-
-#define ZLIB_VERSION "0.95P"
-
-/* 
-     The 'zlib' compression library provides in-memory compression and
-  decompression functions, including integrity checks of the uncompressed
-  data.  This version of the library supports only one compression method
-  (deflation) but other algorithms may be added later and will have the same
-  stream interface.
-
-     For compression the application must provide the output buffer and
-  may optionally provide the input buffer for optimization. For decompression,
-  the application must provide the input buffer and may optionally provide
-  the output buffer for optimization.
-
-     Compression can be done in a single step if the buffers are large
-  enough (for example if an input file is mmap'ed), or can be done by
-  repeated calls of the compression function.  In the latter case, the
-  application must provide more input and/or consume the output
-  (providing more output space) before each call.
-*/
-
-typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-typedef void   (*free_func)  OF((voidpf opaque, voidpf address, uInt nbytes));
-
-struct internal_state;
-
-typedef struct z_stream_s {
-    Bytef    *next_in;  /* next input byte */
-    uInt     avail_in;  /* number of bytes available at next_in */
-    uLong    total_in;  /* total nb of input bytes read so far */
-
-    Bytef    *next_out; /* next output byte should be put there */
-    uInt     avail_out; /* remaining free space at next_out */
-    uLong    total_out; /* total nb of bytes output so far */
-
-    char     *msg;      /* last error message, NULL if no error */
-    struct internal_state FAR *state; /* not visible by applications */
-
-    alloc_func zalloc;  /* used to allocate the internal state */
-    free_func  zfree;   /* used to free the internal state */
-    voidp      opaque;  /* private data object passed to zalloc and zfree */
-
-    Byte     data_type; /* best guess about the data type: ascii or binary */
-
-} z_stream;
-
-/*
-   The application must update next_in and avail_in when avail_in has
-   dropped to zero. It must update next_out and avail_out when avail_out
-   has dropped to zero. The application must initialize zalloc, zfree and
-   opaque before calling the init function. All other fields are set by the
-   compression library and must not be updated by the application.
-
-   The opaque value provided by the application will be passed as the first
-   parameter for calls of zalloc and zfree. This can be useful for custom
-   memory management. The compression library attaches no meaning to the
-   opaque value.
-
-   zalloc must return Z_NULL if there is not enough memory for the object.
-   On 16-bit systems, the functions zalloc and zfree must be able to allocate
-   exactly 65536 bytes, but will not be required to allocate more than this
-   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
-   pointers returned by zalloc for objects of exactly 65536 bytes *must*
-   have their offset normalized to zero. The default allocation function
-   provided by this library ensures this (see zutil.c). To reduce memory
-   requirements and avoid any allocation of 64K objects, at the expense of
-   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
-
-   The fields total_in and total_out can be used for statistics or
-   progress reports. After compression, total_in holds the total size of
-   the uncompressed data and may be saved for use in the decompressor
-   (particularly if the decompressor wants to decompress everything in
-   a single step).
-*/
-
-                        /* constants */
-
-#define Z_NO_FLUSH      0
-#define Z_PARTIAL_FLUSH 1
-#define Z_FULL_FLUSH    2
-#define Z_SYNC_FLUSH    3 /* experimental: partial_flush + byte align */
-#define Z_FINISH        4
-#define Z_PACKET_FLUSH 5
-/* See deflate() below for the usage of these constants */
-
-#define Z_OK            0
-#define Z_STREAM_END    1
-#define Z_ERRNO        (-1)
-#define Z_STREAM_ERROR (-2)
-#define Z_DATA_ERROR   (-3)
-#define Z_MEM_ERROR    (-4)
-#define Z_BUF_ERROR    (-5)
-/* error codes for the compression/decompression functions */
-
-#define Z_BEST_SPEED             1
-#define Z_BEST_COMPRESSION       9
-#define Z_DEFAULT_COMPRESSION  (-1)
-/* compression levels */
-
-#define Z_FILTERED            1
-#define Z_HUFFMAN_ONLY        2
-#define Z_DEFAULT_STRATEGY    0
-
-#define Z_BINARY   0
-#define Z_ASCII    1
-#define Z_UNKNOWN  2
-/* Used to set the data_type field */
-
-#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
-
-extern char *zlib_version;
-/* The application can compare zlib_version and ZLIB_VERSION for consistency.
-   If the first character differs, the library code actually used is
-   not compatible with the zlib.h header file used by the application.
- */
-
-                        /* basic functions */
-
-extern int deflateInit OF((z_stream *strm, int level));
-/* 
-     Initializes the internal stream state for compression. The fields
-   zalloc, zfree and opaque must be initialized before by the caller.
-   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
-   use default allocation functions.
-
-     The compression level must be Z_DEFAULT_COMPRESSION, or between 1 and 9:
-   1 gives best speed, 9 gives best compression. Z_DEFAULT_COMPRESSION requests
-   a default compromise between speed and compression (currently equivalent
-   to level 6).
-
-     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_STREAM_ERROR if level is not a valid compression level.
-   msg is set to null if there is no error message.  deflateInit does not
-   perform any compression: this will be done by deflate().
-*/
-
-
-extern int deflate OF((z_stream *strm, int flush));
-/*
-  Performs one or both of the following actions:
-
-  - Compress more input starting at next_in and update next_in and avail_in
-    accordingly. If not all input can be processed (because there is not
-    enough room in the output buffer), next_in and avail_in are updated and
-    processing will resume at this point for the next call of deflate().
-
-  - Provide more output starting at next_out and update next_out and avail_out
-    accordingly. This action is forced if the parameter flush is non zero.
-    Forcing flush frequently degrades the compression ratio, so this parameter
-    should be set only when necessary (in interactive applications).
-    Some output may be provided even if flush is not set.
-
-  Before the call of deflate(), the application should ensure that at least
-  one of the actions is possible, by providing more input and/or consuming
-  more output, and updating avail_in or avail_out accordingly; avail_out
-  should never be zero before the call. The application can consume the
-  compressed output when it wants, for example when the output buffer is full
-  (avail_out == 0), or after each call of deflate().
-
-    If the parameter flush is set to Z_PARTIAL_FLUSH, the current compression
-  block is terminated and flushed to the output buffer so that the
-  decompressor can get all input data available so far. For method 9, a future
-  variant on method 8, the current block will be flushed but not terminated.
-  If flush is set to Z_FULL_FLUSH, the compression block is terminated, a
-  special marker is output and the compression dictionary is discarded; this
-  is useful to allow the decompressor to synchronize if one compressed block
-  has been damaged (see inflateSync below).  Flushing degrades compression and
-  so should be used only when necessary.  Using Z_FULL_FLUSH too often can
-  seriously degrade the compression. If deflate returns with avail_out == 0,
-  this function must be called again with the same value of the flush
-  parameter and more output space (updated avail_out), until the flush is
-  complete (deflate returns with non-zero avail_out).
-
-    If the parameter flush is set to Z_PACKET_FLUSH, the compression
-  block is terminated, and a zero-length stored block is output,
-  omitting the length bytes (the effect of this is that the 3-bit type
-  code 000 for a stored block is output, and the output is then
-  byte-aligned).  This is designed for use at the end of a PPP packet.
-  In addition, if the current compression block contains all the data
-  since the last Z_PACKET_FLUSH, it is never output as a stored block.
-  If the current compression block output as a static or dynamic block
-  would not be at least `minCompression' bytes smaller than the
-  original data, then nothing is output for that block.  (The type
-  code for the zero-length stored block is still output, resulting in
-  a single zero byte being output for the whole packet.)
-  `MinCompression' is a parameter to deflateInit2, or 0 if deflateInit
-  is used.
-
-    If the parameter flush is set to Z_FINISH, all pending input is processed,
-  all pending output is flushed and deflate returns with Z_STREAM_END if there
-  was enough output space; if deflate returns with Z_OK, this function must be
-  called again with Z_FINISH and more output space (updated avail_out) but no
-  more input data, until it returns with Z_STREAM_END or an error. After
-  deflate has returned Z_STREAM_END, the only possible operations on the
-  stream are deflateReset or deflateEnd.
-  
-    Z_FINISH can be used immediately after deflateInit if all the compression
-  is to be done in a single step. In this case, avail_out must be at least
-  0.1% larger than avail_in plus 12 bytes.  If deflate does not return
-  Z_STREAM_END, then it must be called again as described above.
-
-    deflate() may update data_type if it can make a good guess about
-  the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
-  binary. This field is only for information purposes and does not affect
-  the compression algorithm in any manner.
-
-    deflate() returns Z_OK if some progress has been made (more input
-  processed or more output produced), Z_STREAM_END if all input has been
-  consumed and all output has been produced (only when flush is set to
-  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
-  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible.
-*/
-
-
-extern int deflateEnd OF((z_stream *strm));
-/*
-     All dynamically allocated data structures for this stream are freed.
-   This function discards any unprocessed input and does not flush any
-   pending output.
-
-     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
-   stream state was inconsistent. In the error case, msg may be set
-   but then points to a static string (which must not be deallocated).
-*/
-
-
-extern int inflateInit OF((z_stream *strm));
-/* 
-     Initializes the internal stream state for decompression. The fields
-   zalloc and zfree must be initialized before by the caller.  If zalloc and
-   zfree are set to Z_NULL, inflateInit updates them to use default allocation
-   functions.
-
-     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory.  msg is set to null if there is no error message.
-   inflateInit does not perform any decompression: this will be done by
-   inflate().
-*/
-
-
-extern int inflate OF((z_stream *strm, int flush));
-/*
-  Performs one or both of the following actions:
-
-  - Decompress more input starting at next_in and update next_in and avail_in
-    accordingly. If not all input can be processed (because there is not
-    enough room in the output buffer), next_in is updated and processing
-    will resume at this point for the next call of inflate().
-
-  - Provide more output starting at next_out and update next_out and avail_out
-    accordingly.  inflate() always provides as much output as possible
-    (until there is no more input data or no more space in the output buffer).
-
-  Before the call of inflate(), the application should ensure that at least
-  one of the actions is possible, by providing more input and/or consuming
-  more output, and updating the next_* and avail_* values accordingly.
-  The application can consume the uncompressed output when it wants, for
-  example when the output buffer is full (avail_out == 0), or after each
-  call of inflate().
-
-    If the parameter flush is set to Z_PARTIAL_FLUSH or Z_PACKET_FLUSH,
-  inflate flushes as much output as possible to the output buffer. The
-  flushing behavior of inflate is not specified for values of the flush
-  parameter other than Z_PARTIAL_FLUSH, Z_PACKET_FLUSH or Z_FINISH, but the
-  current implementation actually flushes as much output as possible
-  anyway.  For Z_PACKET_FLUSH, inflate checks that once all the input data
-  has been consumed, it is expecting to see the length field of a stored
-  block; if not, it returns Z_DATA_ERROR.
-
-    inflate() should normally be called until it returns Z_STREAM_END or an
-  error. However if all decompression is to be performed in a single step
-  (a single call of inflate), the parameter flush should be set to
-  Z_FINISH. In this case all pending input is processed and all pending
-  output is flushed; avail_out must be large enough to hold all the
-  uncompressed data. (The size of the uncompressed data may have been saved
-  by the compressor for this purpose.) The next operation on this stream must
-  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
-  is never required, but can be used to inform inflate that a faster routine
-  may be used for the single inflate() call.
-
-    inflate() returns Z_OK if some progress has been made (more input
-  processed or more output produced), Z_STREAM_END if the end of the
-  compressed data has been reached and all uncompressed output has been
-  produced, Z_DATA_ERROR if the input data was corrupted, Z_STREAM_ERROR if
-  the stream structure was inconsistent (for example if next_in or next_out
-  was NULL), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if no
-  progress is possible or if there was not enough room in the output buffer
-  when Z_FINISH is used. In the Z_DATA_ERROR case, the application may then
-  call inflateSync to look for a good compression block.  */
-
-
-extern int inflateEnd OF((z_stream *strm));
-/*
-     All dynamically allocated data structures for this stream are freed.
-   This function discards any unprocessed input and does not flush any
-   pending output.
-
-     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
-   was inconsistent. In the error case, msg may be set but then points to a
-   static string (which must not be deallocated).
-*/
-
-                        /* advanced functions */
-
-/*
-    The following functions are needed only in some special applications.
-*/
-
-extern int deflateInit2 OF((z_stream *strm,
-                            int  level,
-                            int  method,
-                            int  windowBits,
-                            int  memLevel,
-                            int  strategy,
-                           int  minCompression));
-/*   
-     This is another version of deflateInit with more compression options. The
-   fields next_in, zalloc and zfree must be initialized before by the caller.
-
-     The method parameter is the compression method. It must be 8 in this
-   version of the library. (Method 9 will allow a 64K history buffer and
-   partial block flushes.)
-
-     The windowBits parameter is the base two logarithm of the window size
-   (the size of the history buffer).  It should be in the range 8..15 for this
-   version of the library (the value 16 will be allowed for method 9). Larger
-   values of this parameter result in better compression at the expense of
-   memory usage. The default value is 15 if deflateInit is used instead.
-
-    The memLevel parameter specifies how much memory should be allocated
-   for the internal compression state. memLevel=1 uses minimum memory but
-   is slow and reduces compression ratio; memLevel=9 uses maximum memory
-   for optimal speed. The default value is 8. See zconf.h for total memory
-   usage as a function of windowBits and memLevel.
-
-     The strategy parameter is used to tune the compression algorithm. Use
-   the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
-   produced by a filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman
-   encoding only (no string match).  Filtered data consists mostly of small
-   values with a somewhat random distribution. In this case, the
-   compression algorithm is tuned to compress them better. The strategy
-   parameter only affects the compression ratio but not the correctness of
-   the compressed output even if it is not set appropriately.
-
-     The minCompression parameter specifies the minimum reduction in size
-   required for a compressed block to be output when Z_PACKET_FLUSH is
-   used (see the description of deflate above).
-
-     If next_in is not null, the library will use this buffer to hold also
-   some history information; the buffer must either hold the entire input
-   data, or have at least 1<<(windowBits+1) bytes and be writable. If next_in
-   is null, the library will allocate its own history buffer (and leave next_in
-   null). next_out need not be provided here but must be provided by the
-   application for the next call of deflate().
-
-     If the history buffer is provided by the application, next_in must
-   must never be changed by the application since the compressor maintains
-   information inside this buffer from call to call; the application
-   must provide more input only by increasing avail_in. next_in is always
-   reset by the library in this case.
-
-      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
-   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
-   an invalid method). msg is set to null if there is no error message.
-   deflateInit2 does not perform any compression: this will be done by
-   deflate().
-*/
-                            
-extern int deflateCopy OF((z_stream *dest,
-                           z_stream *source));
-/*
-     Sets the destination stream as a complete copy of the source stream.  If
-   the source stream is using an application-supplied history buffer, a new
-   buffer is allocated for the destination stream.  The compressed output
-   buffer is always application-supplied. It's the responsibility of the
-   application to provide the correct values of next_out and avail_out for the
-   next call of deflate.
-
-     This function is useful when several compression strategies will be
-   tried, for example when there are several ways of pre-processing the input
-   data with a filter. The streams that will be discarded should then be freed
-   by calling deflateEnd.  Note that deflateCopy duplicates the internal
-   compression state which can be quite large, so this strategy is slow and
-   can consume lots of memory.
-
-      deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
-   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
-   (such as zalloc being NULL). msg is left unchanged in both source and
-   destination.
-*/
-
-extern int deflateReset OF((z_stream *strm));
-/*
-     This function is equivalent to deflateEnd followed by deflateInit,
-   but does not free and reallocate all the internal compression state.
-   The stream will keep the same compression level and any other attributes
-   that may have been set by deflateInit2.
-
-      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NULL).
-*/
-
-extern int inflateInit2 OF((z_stream *strm,
-                            int  windowBits));
-/*   
-     This is another version of inflateInit with more compression options. The
-   fields next_out, zalloc and zfree must be initialized before by the caller.
-
-     The windowBits parameter is the base two logarithm of the maximum window
-   size (the size of the history buffer).  It should be in the range 8..15 for
-   this version of the library (the value 16 will be allowed soon). The
-   default value is 15 if inflateInit is used instead. If a compressed stream
-   with a larger window size is given as input, inflate() will return with
-   the error code Z_DATA_ERROR instead of trying to allocate a larger window.
-
-     If next_out is not null, the library will use this buffer for the history
-   buffer; the buffer must either be large enough to hold the entire output
-   data, or have at least 1<<windowBits bytes.  If next_out is null, the
-   library will allocate its own buffer (and leave next_out null). next_in
-   need not be provided here but must be provided by the application for the
-   next call of inflate().
-
-     If the history buffer is provided by the application, next_out must
-   never be changed by the application since the decompressor maintains
-   history information inside this buffer from call to call; the application
-   can only reset next_out to the beginning of the history buffer when
-   avail_out is zero and all output has been consumed.
-
-      inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was
-   not enough memory, Z_STREAM_ERROR if a parameter is invalid (such as
-   windowBits < 8). msg is set to null if there is no error message.
-   inflateInit2 does not perform any decompression: this will be done by
-   inflate().
-*/
-
-extern int inflateSync OF((z_stream *strm));
-/* 
-    Skips invalid compressed data until the special marker (see deflate()
-  above) can be found, or until all available input is skipped. No output
-  is provided.
-
-    inflateSync returns Z_OK if the special marker has been found, Z_BUF_ERROR
-  if no more input was provided, Z_DATA_ERROR if no marker has been found,
-  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
-  case, the application may save the current current value of total_in which
-  indicates where valid compressed data was found. In the error case, the
-  application may repeatedly call inflateSync, providing more input each time,
-  until success or end of the input data.
-*/
-
-extern int inflateReset OF((z_stream *strm));
-/*
-     This function is equivalent to inflateEnd followed by inflateInit,
-   but does not free and reallocate all the internal decompression state.
-   The stream will keep attributes that may have been set by inflateInit2.
-
-      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
-   stream state was inconsistent (such as zalloc or state being NULL).
-*/
-
-extern int inflateIncomp OF((z_stream *strm));
-/*
-     This function adds the data at next_in (avail_in bytes) to the output
-   history without performing any output.  There must be no pending output,
-   and the decompressor must be expecting to see the start of a block.
-   Calling this function is equivalent to decompressing a stored block
-   containing the data at next_in (except that the data is not output).
-*/
-
-                        /* checksum functions */
-
-/*
-     This function is not related to compression but is exported
-   anyway because it might be useful in applications using the
-   compression library.
-*/
-
-extern uLong adler32 OF((uLong adler, Bytef *buf, uInt len));
-
-/*
-     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
-   return the updated checksum. If buf is NULL, this function returns
-   the required initial value for the checksum.
-   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
-   much faster. Usage example:
-
-     uLong adler = adler32(0L, Z_NULL, 0);
-
-     while (read_buffer(buffer, length) != EOF) {
-       adler = adler32(adler, buffer, length);
-     }
-     if (adler != original_adler) error();
-*/
-
-#ifndef _Z_UTIL_H
-    struct internal_state {int dummy;}; /* hack for buggy compilers */
-#endif
-
-#endif /* _ZLIB_H */
index cabf4d7ab3bbbae1e8c8e3a5aa9e4098561a0b92..94c6fc552c0f4d6c1a4f5c4112c047787957e19a 100644 (file)
@@ -1,4 +1,3 @@
-.\"    @(#) $Id: pppstats.8,v 1.4 2004/11/13 12:22:49 paulus Exp $
 .TH PPPSTATS 8 "26 June 1995"
 .SH NAME
 pppstats \- print PPP statistics
index 44a254d70154f5d00ff03727419ef87eb1693623..606ea51e31cfa3382a82fc973132a906fa9481e9 100644 (file)
 #define const
 #endif
 
-#ifndef lint
-static const char rcsid[] = "$Id: pppstats.c,v 1.29 2002/10/27 12:56:26 fcusack Exp $";
-#endif
-
 #include <stdio.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -72,7 +68,7 @@ static const char rcsid[] = "$Id: pppstats.c,v 1.29 2002/10/27 12:56:26 fcusack
 #include <linux/if.h>
 #endif
 #include <linux/ppp_defs.h>
-#include <linux/if_ppp.h>
+#include <linux/ppp-ioctl.h>
 
 #endif /* __linux__ */
 
diff --git a/sample/options.ttyXX b/sample/options.ttyXX
deleted file mode 100644 (file)
index d4202f5..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-# If you need to set up multiple serial lines then copy this file to
-# options.<ttyname> for each tty with a modem on it.
-#
-# The options.tty file will assign an IP address to each PPP connection
-# as it comes up. They must all be distinct!
-#
-# Example:
-# options.ttyS1                for com2 under DOS.
-#
-# Edit the following line so that the first IP address
-# mentioned is the ip address of the serial port while the second
-# is the IP address of your host
-#
-hostname-s1:hostname
index 0fadd48dc0b5c5ddece0cdb12d5c989e2c080886..65b15f9e345126e9b687ee5fb2a6b271d1450b04 100644 (file)
@@ -1,32 +1,13 @@
-EXTRA_CHATCHAT = \
-    chatchat/chatchat.c \
-    chatchat/README
-
 EXTRA_SCRIPTS = \
     autopppd \
-    callback \
-    chatchat \
-    ip-down.local.add \
-    ip-up.local.add \
     ipv6-down.sample \
     ipv6-up.sample \
-    options-rsh-loc \
-    options-rsh-rem \
-    options-ssh-loc \
-    options-ssh-rem \
     plog \
     poff \
     pon \
     pon.1 \
-    ppp-off \
-    ppp-on \
-    ppp-on-dialer \
-    ppp-on-rsh \
-    ppp-on-ssh \
-    README \
-    redialer \
-    secure-card
+    lcp_rtt_dump \
+    lcp_rtt_exporter
 
 EXTRA_DIST= \
-    $(EXTRA_CHATCHAT) \
     $(EXTRA_SCRIPTS)
diff --git a/scripts/README b/scripts/README
deleted file mode 100644 (file)
index 00e032c..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-This directory contains a set of scripts which have been used on Linux
-as well as Solaris 2.x systems to initiate or maintain a connection 
-with PPP.  The files in this directory were contributed by Al Longyear 
-(longyear@netcom.com) and Adi Masputra (adi.masputra@sun.com)
-
-------------------------------------------------------------------------
-
-1. README
-
-This file. You are reading it. It is just documentation.
-
-------------------------------------------------------------------------
-
-2. ppp-on
-
-This script will initiate a connection to the PPP system. It will run
-the chat program with the connection script as a parameter. This is a
-possible security hole. However, it is simple. It is meant to replace
-the previous version of ppp-on which was not very functional.
-
-The ppp-on script has entries for the account name, password, IP
-addresses, and telephone numbers. The parameters are passed to the
-pppd process and, then in turn, to the second part of the connect
-script, as a set of environment variables.
-
-Please make sure that you put the full path name to the ppp-on-dialer
-script in the reference to it in ppp-on.
-
-------------------------------------------------------------------------
-
-3. ppp-on-dialer
-
-This is the second part to the simple calling script, ppp-on.  It
-executes the chat program to connect the user with a standard UNIX
-style getty/login connection sequence.
-
-------------------------------------------------------------------------
-
-4. callback
-
-This script may be used in lieu of the ppp-on-dialer to permit the
-common modem callback sequence. You may need to make changes to the
-expected prompt string for the modem.
-
-The script works by disabling the system's detection of the DCD
-condition and working on the modem status message "NO CARRIER" which
-is generated when the modem disconnects.
-
-It is crude. It does work for my modem connection. Use as you see fit.
-
-------------------------------------------------------------------------
-
-5. redialer
-
-The redialer script is a replacement for the ppp-on-dialer script.  It
-will do 'attack dialing' or 'demon dialing' of one or more telephone
-numbers. The first number which responds will be used for a
-connection.
-
-There is a limit of ten attempts and a 15 second delay between dialing
-attempts. Both values are set in the script.
-
-------------------------------------------------------------------------
-
-6. ppp-off
-
-This is a script which will terminate the active ppp connection. Use
-as either "ppp-off" to terminate ppp0, or "ppp-off <device>" to
-terminate the connection on <device>. For example, "ppp-off ppp2" will
-terminate the ppp2 connection.
-
-------------------------------------------------------------------------
-
-7. secure-card
-
-This script was written by Jim Isaacson <jcisaac@crl.com>. It is a script
-for the 'expect' programming language used with Tcl. You need to have
-expect and Tcl installed before this script may be used.
-
-This script will operate with a device marketed under the name "SecureCARD".
-This little device is mated with its controller. On the credit card size
-device, there is a sequence number which changes on a random basis. In order
-for you to connect you need to enter a fixed portion of your account name
-and the number which is displayed on this card device. The number must match
-the value at the controller in order for the account name to be used.
-
-The problem is that chat uses fixed response strings. In addition, the
-timing for running the script may prevent the use of a script that reads the
-value before it starts the dial sequence. What was needed was a script which
-asked the user at the user's console at the time that it is needed.
-
-This led to the use of expect.
-
-------------------------------------------------------------------------
-
-8. ppp-on-rsh
-
-This script will initiate a PPP connection to a remote machine using rsh.
-This is implemented by creating a master/slave pseudo-tty with the slave 
-pointing to rsh, specifically with the 'pty' and 'notty' options of pppd. 
-It is assumed that the remote machine contains some sort of trust 
-mechanisms (such as ~/.rhosts, et al) to allow the local machine to 
-connect via rsh as root.
-
-------------------------------------------------------------------------
-
-9. ppp-on-ssh
-
-This script will initiate a PPP connection to a remote machine using the 
-secure shell, or ssh. I've only tested this on ssh 1.x, so those of you 
-who are running ssh 2.x mahy need to modify the ssh options slightly.
-This is implemented by creating a master/slave pseudo-ttyt with the slave 
-pointing to ssh, specifically with the 'pty' and 'notty' options of pppd. 
-It is assumed that the remote machine can accept the ssh connection from 
-the local host, in the sense that all ssh authentication mechanisms have 
-been properly configured, so that a remote root user can open a ssh 
-connection.
-
-------------------------------------------------------------------------
-
-10. options-rsh-loc & options-rsh-rem
-
-These options files accompany the ppp-on-rsh script mentioned above. In 
-theory, you'd want to copy the options-rsh-rem to the remote machine where 
-in.rshd is running. The only extra option required on the remote machine 
-options file is the 'notty' option. In addition, all ASCII control characters 
-[0x00 to 0x1f], plus 0xff, are escaped. This may need to be modified 
-depending on the rsh (or pseudo-tty) implementation which may differ across 
-platforms, for further optimizations.
-
-------------------------------------------------------------------------
-
-11. options-ssh-loc & options-ssh-rem
-
-These options files accompany the ppp-on-ssh script mentioned above. I've
-only tested this on ssh 1.x, so those of you who are running ssh 2.x need
-to modify the ssh options slightly. In theory, you'd want to copy the 
-options-ssh-rem to the remote machine where sshd daemon is running. The only 
-extra options required on the remote machine options file is the 'notty' 
-option. In addition, all ASCII control characters [0x00 to 0x1f], plus 0xff, 
-are escaped. This may need to be modified depending on the ssh (or 
-pseudo-tty) implementation which may differ across platforms, for further 
-optimizations.
index 0730ef6d7cc3a4858b89676e5777e0e78ef28a5d..5d8e5744b7ce175f4e4591a679668f8eca8197a2 100755 (executable)
@@ -134,7 +134,7 @@ while (1)
     syslog('err', "pppd returned: unknown error ($pppd_code), delayed retry");
     $pppd_fail = 1;
   }
-  # if it hasn't ran for at least an hour, then somthing went wrong
+  # if it hasn't ran for at least an hour, then something went wrong
   elsif ($pppd_run_time < toseconds("01:00:00")) {
     syslog('err',"pppd session didn't last 1 hour, delayed retry");
     $pppd_fail = 1;
diff --git a/scripts/callback b/scripts/callback
deleted file mode 100755 (executable)
index 1c3d3aa..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/sh
-###################################################################
-#
-# Script to dial the remote system, negotiate the connection, and send
-# it the id. Then wait for the modem to disconnect. Reset the modem
-# to answer mode and wait for the system to call back.
-#
-# The telephone number and modempass are used when establishing the
-# connection to the modem.
-#
-PHONE=555-1212
-MODEMPASS=modem_identifier
-#
-# Once the modem calls back, the account name and password are used for
-# a UNIX style login operation.
-#
-ACCOUNT=my_account_name
-PASSWORD=my_password
-
-###################################################################
-#
-# Step 1. Dial the modem and negotiate the initial dialog.
-#         note: the modem is configured to ignore loss of DCD at this point.
-#         it is important that this be performed because the loss of DCD
-#         will normally prevent system from working since 'modem' is used
-#         for pppd.
-#
-#         The script is terminated normally when the carrier is lost.
-#
-chat -v                                                        \
-       TIMEOUT         3                               \
-       ABORT           '\nBUSY\r'                      \
-       ABORT           '\nNO ANSWER\r'                 \
-       ABORT           '\nRINGING\r\n\r\nRINGING\r'    \
-       ''              AT                              \
-       'OK-+++\c-OK'   'AT&C0&D2S0=0H0'                \
-       TIMEOUT         30                              \
-       OK              ATDT$TELEPHONE                  \
-       CONNECT         ''                              \
-       assword:        $MODEMPASS                      \
-       "\nNO CARRIER\r"
-
-if [ "$?" = "0" ]; then
-
-###################################################################
-#
-# Step 2. Wait for the call back from the remote. This will wait for at most
-#         30 seconds for the call back should the first attempt fail or
-#         something happen with the callback logic at the remote.
-#
-#         note: when the callback occurs, the DCD setting is re-enabled.
-#
-# If some voice call should happen during this period, the system will
-# answer the telephone and then hang up on them. I realize that this is
-# rude, but there is little that this script can do.
-#
-  chat -v                                              \
-       TIMEOUT         30                              \
-       ABORT           '\nVOICE\r'                     \
-       '\nRING\r'      'AT&C1A'                        \
-       CONNECT         ''                              \
-       TIMEOUT         10                              \
-       ogin:--ogin:    $ACCOUNT                        \
-       TIMEOUT         45                              \
-       assword:        $PASSWORD
-
-  if [ "$?" = "0" ]; then
-    exit 0
-  fi
-fi
-
-###################################################################
-#
-# The script has failed. Terminate the connection mode.
-#
-chat -v TIMEOUT 3 "" AT 'OK-+++\c-OK' 'AT&C1&D2S0=0H0' OK
-exit 1
diff --git a/scripts/chat-callback b/scripts/chat-callback
deleted file mode 100644 (file)
index d014d6a..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-# =====================================================================================
-# Chat script to dial our Company PPP account.
-# They uses a call-back system to identify us and to reverse
-# charge the call cost.
-# =====================================================================================
-#
-ECHO OFF
-# All the usual abort strings
-ABORT "NO CARRIER"
-ABORT "VOICE"
-ABORT "BUSY"
-ABORT "NO DIALTONE"
-ABORT "NO ANSWER"
-#
-# If calling outside allowed time we get this:
-#
-ABORT "Access denied"
-#
-# Modem initialisation stuff
-#
-TIMEOUT 5
-SAY "Initialising modem ...\n"
-'' ATE1
-'OK\r\n' ATS0=1S11=60X4&K4S42.1=1
-#
-# Now dial our ISP and wait for connection
-#
-SAY "Dialling our ISP ...\n"
-'OK\r\n' ATDT09834657
-TIMEOUT 60
-CONNECT \c
-SAY "Connected ...\n"
-#
-# This is the first stage login, we identify ourself so that the remote
-# system will agree to call us back.
-#
-TIMEOUT 30
-SAY "Sending Callback login ID ...\n"
-name:-BREAK-name: callme
-#
-# From now on, we must assume no carrier is normal as well
-# as receiving a HANGUP signal because it will be the
-# case if our ISP clears the call to call us back.
-#
-CLR_ABORT "NO CARRIER"
-HANGUP OFF
-#
-ABORT "Invalid"
-#
-# Now send password and wait to see what happens
-#
-SAY "Sending Callback password ...\n"
-word:--word:  xvsgsgs
-"You will be" \c
-#
-# What can happen now is:
-#   either: we get "You will be called back..." which is the successful case
-#   or:     we get "Invalid login" and we abort (bad login ID or password)
-#   or:     we get "NO CARRIER" because of an error, this will not abort
-#           and we will time out after 30 seconds
-#   or:     we get nothing and we will time out after 30 seconds
-#
-#
-# We reach here if we got "You will be called back..."
-#
-CLR_ABORT "Invalid"
-SAY "Now waiting for Call back ...\n"
-#
-# The remote system will now hangup and we will get both "NO CARRIER"
-# and a hangup signal which are ignored. We now wait for a connection
-# for up to 120 seconds. What happens here if somebody else calls before
-# the remote system is a bit dangerous:
-#
-#   If a malicious user connects and says 'name:', he will see 'PPPuser'
-#   If he then says 'word:' he will see the passowrd 'blipblop'. I may not
-#   know to which systems these belong to, though. It is up to you to consider 
-#   that case and decide wether the risk is too big or not ....
-#
-TIMEOUT 120
-"CONNECT" \c
-#
-# We have been called, re-arm ABORT on NO CARRIER and normal hangup signal
-# behaviour
-#
-HANGUP ON
-ABORT "NO CARRIER"
-#
-# Second stage login in order to start PPP
-#
-SAY "Remote system called back, logging in ...\n"
-SAY "Sending login ID ...\n"
-name:-BREAK-name: PPPuser
-SAY "Sending password ...\n"
-word:--word:  blipblop
-SAY "Asking to start PPP ...\n"
-'CnetSrv' "ppp default"
-"Entering PPP mode" \c
-SAY "ISP PPP started ...\n"
diff --git a/scripts/chatchat/README b/scripts/chatchat/README
deleted file mode 100644 (file)
index 88a4c69..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-v 0.1 gpk@onramp.net 3/27/99
-
-I Intro
-
-   This document covers the use of the modified "chat" program and its 
-adjunct "chatchat" to login using the Security Dynamics SecurID card
-on a linux system.
-
-   This set of files comprises a modified version of the chat program
-(the one distributed with ppp-2.3.5) and a new program called chatchat
-that allows you to supply data from the keyboard to the chat program.
-
-   The SecurID card generates passwords that have a lifetime of one
-minute and are used as a first layer in dial up security. The only
-software I know of for this card is for windows, so I wrote my own. 
-This software allows you to type in the time-sensitive password right
-when your chat script is asked to supply the passcode by the remote
-system. 
-
-
-II How It Works
-
-   This version of chat his an additional command that can be put into
-its options that says "Don't reply with this string. Open this pipe,
-read the contents, and reply with that instead." Chatchat creates a
-pipe and lets you type your passcode into it, then chat picks that up
-and sends it out just as though the passcode was hardcoded into the
-options. 
-
-
-III Installation 
-
-  I've provided intel binaries and source code the the modified chat 
-program and the chatchat program. I'll recommend that you copy the 
-chat.c program into your ppp-2.3.5/chat directory (save your original 
-chat.c program first!) and re-make it using the Makefile that comes 
-with chat. Copy the new chat somewhere into your path. (On my system
-chat lives in /usr/sbin/chat, so I've copied the modified one into 
-/usr/sbin/chat.new and changed my dial in script to call chat.new
-instead of chat.
-
-  Second, compile chatchat.c and install it somewhere in your path:
-
- gcc -g -o chatchat chatchat.c
- cp chatchat /usr/sbin
-
- Third, modify your chat script to use the chatchat program. Mine
-looks something like this:
-
-
-                       --------------------
-
-#!/bin/sh
-#
-# This is part 2 of the ppp-on script. It will perform the connection
-# protocol for the desired connection.
-# use atm0 to turn down the speaker volume on my sportster x2 voice modem
-# gpk 11/2/97
-
-exec /usr/sbin/chat.new  -V -v                       \
-         ABORT           "BUSY"                     \
-     ABORT              "NO DIAL TONE"      \
-         ABORT           "NO ANSWER"                \
-         TIMEOUT         50                             \
-         ""             "atm0"                  \
-         OK              ATDT$TELEPHONE                  \
-        CONNECT         ''       \
-    name:           \\da0xxxxxx  \
-    word:           @/var/tmp/p \
-        compress.       ''
-
-
-                     -----------------------
-
- This is a standard chat script:
-
-* abort if the modem is busy, you don't get a dial tone, no one
-  answers, or 50 seconds elapses.
-
-* use atm0 to mute the modem
-
-* dial the modem, when it connects, wait to be asked for account name
-
-* when we see "name:" prompt, delay briefly then respond with your 
-  account name (fill in your account name)
-
-Now we get to the new stuff:
-
-* when we see "word:" in the password prompt, instead of responding
-  with "@/var/tmp/p", the modified chat program will open the pipe 
-  /var/tmp/p, read the passcode out of there, and send it
-
-* when we see "compress." (the last word before ppp starts), reply
-  with nothing. The script ends and we start ppp.
-
-Note:
-
-* Make sure there is some whitespace between the filename and the \.
-
-
-IV Usage
-
-   To use this install the modified chat and chatchat programs, and
-modify your chat script similar to the above. Before you dial in,
-start that chatchat program giving it the same pipe as in your config
-file. In the above case:
-
-chatchat /var/tmp/p
-
-   Wait until you have one or two tick marks left on your card's
-current number, then start your dial up process that eventually calls
-chat. When chat goes to open and read the pipe, chatchat will prompt:
-
-
-type PIN into SecurID card and 
- enter resulting passcode:
-
-   At that point, type your PIN number into your Securid card, press
-the diamond, and type the resulting numbers in as your passcode. If
-you've left the -V -v options on your chat command you'll see
-everything so out, otherwise it works silently.
-
-   If you type the number wrong or run out of time, the server will 
-respond with an authentication failure. In that case you will have to 
-hang up and start again. I don't know how to build a conditional script 
-that says either expect "compress" next, but if you see "name:" again, 
-do this instead. 
-
-
-V Additional Information
-
-  You can obtain additional information about chat and ppp from the
-man pages for chat and pppd, as well as the PPP-HOWTO.
-
diff --git a/scripts/chatchat/chatchat.c b/scripts/chatchat/chatchat.c
deleted file mode 100644 (file)
index 4534fb9..0000000
+++ /dev/null
@@ -1,409 +0,0 @@
-/* ************************************************************************* 
-* NAME: chatchat.c
-*
-* DESCRIPTION:
-*
-* This program creates a pipe for the chat process to read. The user
-* can supply information (like a password) that will be picked up
-* by chat and sent just like the regular contents of a chat script.
-*
-* Usage is:
-*
-* chatchat <filename>
-*
-*   where <filename> matches the option given in the chat script.
-*
-* for instance the chat script fragment:
-*
-*       ...
-*        name:           \\dmyname  \
-*        word:           @/var/tmp/p \
-*       ...
-*                                   ^
-*                    (note: leave some whitespace after the filename)
-*
-* expect "name:", reply with a delay followed by "myname"
-* expect "word:", reply with the data read from the pipe /var/tmp/p 
-*
-* the matching usage of chatchat would be:
-*
-* chatchat /var/tmp/p
-*
-* eg:
-*
-* $chatchat /var/tmp/p
-* ...
-*                           some other process eventually starts:
-*                           chat ...
-*                           chat parses the "@/var/tmp/p" option and opens
-*                              /var/tmp/p
-*  (chatchat prompts:)
-*
-* type PIN into SecurID card
-*   enter resulting passcode: [user inputs something]
-*
-*                           chat reads /var/tmp/p & gets what the
-*                              user typed at chatchat's "enter string" prompt
-*                           chat removes the pipe file
-*                           chat sends the user's input as a response in
-*                              place of "@/var/tmp/p"
-*                             
-* PROCESS:
-*
-* gcc -g -o chatchat chatchat.c
-*
-* 
-* GLOBALS: none
-*
-* REFERENCES:
-*
-* see the man pages and documentation that come with the 'chat' program
-* (part of the ppp package). you will need to use the modified chat
-* program that accepts the '@' operator.
-*
-* LIMITATIONS:
-*
-* REVISION HISTORY:
-*
-*   STR                Description                          Author
-*
-*   23-Mar-99          initial coding                        gpk
-*   12-May-99         unlink the pipe after closing         paulus
-*
-* TARGET: ANSI C
-* This program is in the public domain.
-* 
-*
-* ************************************************************************* */
-
-
-
-
-#include <sys/time.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-
-/* MAXINPUT - the data typed into chatchat must be fewer   */
-/* characters than this.                                 */
-
-#define MAXINPUT 80
-
-
-
-
-
-
-/* ************************************************************************* 
-
-
-   NAME:  main
-
-
-   USAGE: 
-
-   int argc;
-   char * argv[];
-
-   main(argc, argv[]);
-
-   returns: int
-
-   DESCRIPTION:
-                 if the pipe file name is given on the command line,
-                   create the pipe, prompt the user and put whatever
-                   is typed into the pipe.
-
-                returns -1 on error
-                    else # characters entered
-   REFERENCES:
-
-   LIMITATIONS:
-
-   GLOBAL VARIABLES:
-
-      accessed: none
-
-      modified: none
-
-   FUNCTIONS CALLED:
-
-   REVISION HISTORY:
-
-        STR                  Description of Revision                 Author
-
-     25-Mar-99               initial coding                           gpk
-
- ************************************************************************* */
-
-int main(int argc, char * argv[])
-{
-  int retval;
-  
-  int create_and_write_pipe(char * pipename);
-
-  if (argc != 2)
-    {
-      fprintf(stderr, "usage: %s pipename\n", argv[0]);
-      retval = -1;
-    }
-  else
-    {
-     retval =  create_and_write_pipe(argv[1]);
-    }
-  return (retval);
-}
-
-
-
-
-/* ************************************************************************* 
-
-
-   NAME:  create_and_write_pipe
-
-
-   USAGE: 
-
-   int some_int;
-   char * pipename;
-
-   some_int =  create_and_write_pipe(pipename);
-
-   returns: int
-
-   DESCRIPTION:
-                 given the pipename, create the pipe, open it,
-                prompt the user for a string to put into the
-                pipe, write the string, and close the pipe
-
-                on error, print out an error message and return -1
-                
-                returns -1 on error
-                  else #bytes written into the pipe
-   REFERENCES:
-
-   LIMITATIONS:
-
-   GLOBAL VARIABLES: 
-
-      accessed: none
-
-      modified: none
-
-   FUNCTIONS CALLED:
-
-   REVISION HISTORY:
-
-        STR                  Description of Revision                 Author
-
-     25-Mar-99               initial coding                           gpk
-     12-May-99              remove pipe after closing               paulus
-
- ************************************************************************* */
-
-int create_and_write_pipe(char * pipename)
-{
-  int retval, created, pipefd, nread, nwritten;
-  char input[MAXINPUT];
-  char errstring[180];
-  
-  int create_pipe(char * pipename);
-  int write_to_pipe(int pipefd, char * input, int nchar);
-
-  created = create_pipe(pipename);
-
-  if (-1 == created)
-    {
-      sprintf(errstring, "unable to create pipe '%s'", pipename);
-      perror(errstring);
-      retval = -1;
-    }
-  else
-    {
-
-      /* note: this open won't succeed until chat has the pipe  */
-      /* open and ready to read. this makes for nice timing.    */
-      
-      pipefd = open(pipename, O_WRONLY);
-
-      if (-1 == pipefd)
-       {
-         sprintf(errstring, "unable to open pipe '%s'", pipename);
-         perror(errstring);
-         retval =  -1;
-       }
-      else
-       {
-         fprintf(stderr, "%s \n %s",
-                 "type PIN into SecurID card and",
-                 "enter resulting passcode:");
-         nread = read(STDIN_FILENO, (void *)input, MAXINPUT);
-
-         
-         if (0 >= nread)
-           {
-             perror("unable to read from stdin");
-             retval = -1;
-           }
-         else
-           {
-             /* munch off the newline character, chat supplies  */
-             /* a return when it sends the string out.          */
-             input[nread -1] = 0;
-             nread--;
-             nwritten = write_to_pipe(pipefd, input, nread);
-             /* printf("wrote [%d]: '%s'\n", nwritten, input); */
-             retval = nwritten;
-           }
-         close(pipefd);
-
-         /* Now make the pipe go away.  It won't actually go away
-            completely until chat closes it. */
-         if (unlink(pipename) < 0)
-             perror("Warning: couldn't remove pipe");
-       }
-    }
-  return(retval);
-}
-
-
-
-
-
-
-
-/* ************************************************************************* 
-
-
-   NAME:  create_pipe
-
-
-   USAGE: 
-
-   int some_int;
-   char * pipename;
-   
-   some_int =  create_pipe(pipename);
-   
-   returns: int
-   
-   DESCRIPTION:
-                 create a pipe of the given name
-
-                if there is an error (like the pipe already exists)
-                   print an error message and return
-                   
-                return -1 on failure else success
-
-   REFERENCES:
-
-   LIMITATIONS:
-
-   GLOBAL VARIABLES:
-
-      accessed: none
-
-      modified: none
-
-   FUNCTIONS CALLED:
-
-   REVISION HISTORY:
-
-        STR                  Description of Revision                 Author
-
-     25-Mar-99               initial coding                           gpk
-
- ************************************************************************* */
-
-int create_pipe(char * pipename)
-{
-  mode_t old_umask;
-  int created;
-
-  /* hijack the umask temporarily to get the mode I want  */
-  /* on the pipe.                                         */
-  
-  old_umask = umask(000);
-
-  created = mknod(pipename, S_IFIFO | S_IRWXU | S_IWGRP | S_IWOTH,
-                 (dev_t)NULL);
-
-  /* now restore umask.  */
-  
-  (void)umask(old_umask);
-  
-  if (-1 == created)
-    {
-      perror("unable to create pipe");
-    }
-
-  return(created);
-}
-
-
-
-
-
-
-/* ************************************************************************* 
-
-
-   NAME:  write_to_pipe
-
-
-   USAGE: 
-
-   int some_int;
-   int pipefd;
-   char * input;
-   int nchar;
-
-   some_int =  write_to_pipe(pipefd, input, nchar);
-
-   returns: int
-
-   DESCRIPTION:
-                 write nchars of data from input to pipefd
-
-                on error print a message to stderr
-
-                return -1 on error, else # bytes written
-   REFERENCES:
-
-   LIMITATIONS:
-
-   GLOBAL VARIABLES:
-
-      accessed: none
-
-      modified: none
-
-   FUNCTIONS CALLED:
-
-   REVISION HISTORY:
-
-        STR                  Description of Revision                 Author
-
-     25-Mar-99               initial coding                           gpk
-     12-May-99              don't write count word first             paulus
-
- ************************************************************************* */
-
-int write_to_pipe(int pipefd, char * input, int nchar)
-{
-  int nwritten;
-
-  /* nwritten = write(pipefd, (void *)&nchar, sizeof(nchar)); */
-  nwritten = write(pipefd, (void *)input, nchar);
-
-  if (-1 == nwritten)
-    {
-      perror("unable to write to pipe");
-    }
-
-  return(nwritten);
-}
diff --git a/scripts/ip-down.local.add b/scripts/ip-down.local.add
deleted file mode 100644 (file)
index b93590e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-
-#
-# This sample code shows you one way to modify your setup to allow automatic
-# configuration of your resolv.conf for peer supplied DNS addresses when using
-# the `usepeerdns' option.
-#
-# In my case I just added this to my /etc/ppp/ip-down.local script. You may need to 
-# create an executable script if one does not exist.
-#
-# Nick Walker (nickwalker@email.com)
-#
-
-if [ -n "$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
-       if [ -f /etc/ppp/resolv.prev ]; then
-               cp -f /etc/ppp/resolv.prev /etc/resolv.conf
-       else
-               rm -f /etc/resolv.conf
-       fi
-fi
-
diff --git a/scripts/ip-up.local.add b/scripts/ip-up.local.add
deleted file mode 100644 (file)
index 8017209..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-
-#
-# This sample code shows you one way to modify your setup to allow automatic
-# configuration of your resolv.conf for peer supplied DNS addresses when using
-# the `usepeerdns' option.
-#
-# In my case I just added this to my /etc/ppp/ip-up.local script. You may need to 
-# create an executable script if one does not exist.
-#
-# Nick Walker (nickwalker@email.com)
-#
-
-if [ -n "$USEPEERDNS" -a -f /etc/ppp/resolv.conf ]; then
-       rm -f /etc/ppp/resolv.prev
-       if [ -f /etc/resolv.conf ]; then
-               cp /etc/resolv.conf /etc/ppp/resolv.prev
-               grep domain /etc/ppp/resolv.prev > /etc/resolv.conf
-               grep search /etc/ppp/resolv.prev >> /etc/resolv.conf
-               cat /etc/ppp/resolv.conf >> /etc/resolv.conf
-       else
-               cp /etc/ppp/resolv.conf /etc
-       fi
-fi
-
diff --git a/scripts/lcp_rtt_dump b/scripts/lcp_rtt_dump
new file mode 100755 (executable)
index 0000000..7898f08
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+# vim: shiftwidth=4 tabstop=4
+#
+# This program dumps to standard output the content of the file written
+# by pppd's lcp-rtt-file configuration option.
+#
+# Copyright (C) Marco d'Itri <md@linux.it>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+use v5.14;
+use warnings;
+use autodie;
+
+use POSIX qw(strftime);
+
+{
+       my $data = read_data($ARGV[0] || '/run/ppp-rtt.data');
+       die "The data file is invalid!\n" if not $data;
+       dump_data($data);
+}
+
+sub dump_data {
+       my ($s) = @_;
+
+       say "status:   $s->{status}";
+       say "interval: $s->{echo_interval}";
+       say "position: $s->{position}";
+       say 'elements: ' . scalar(@{ $s->{data} });
+       say '';
+
+       foreach (my $i= 0; $i < @{ $s->{data} }; $i++) {
+               my $date = strftime('%F %T', localtime($s->{data}->[$i]->[0]));
+               print "$i\t$date\t$s->{data}->[$i]->[1]\t$s->{data}->[$i]->[2]\n";
+       }
+}
+
+sub read_data {
+       my ($file) = @_;
+
+       my $data;
+       open(my $fh, '<', $file);
+       binmode($fh);
+       my $bytes_read;
+       do {
+               $bytes_read = sysread($fh, $data, 8192, length($data));
+       } while ($bytes_read == 8192);
+       close($fh);
+
+       my ($magic, $status, $position, $echo_interval, $rest)
+               = unpack('NNNN a*', $data);
+       return undef if $magic != 0x19450425;
+
+       # the position is relative to the C array, not to the logical entries
+       $position /= 2;
+
+       my @rawdata = unpack('(N C a3)*', $rest);
+       my @data;
+       while (my ($time, $loss, $rtt) = splice(@rawdata, 0, 3)) {
+               push(@data, [ $time, unpack('N', "\000$rtt"), $loss ]);
+       }
+
+       if (0) {
+       @data =
+               # skip any "empty" (null) entries
+               grep { $_->[0] }
+               # rearrange the list in chronological order
+               (@data[$position+1 .. $#data], @data[0 .. $position]);
+       }
+
+       return {
+               status                  => $status,
+               echo_interval   => $echo_interval,
+               position                => $position,
+               data                    => \@data,
+       };
+}
+
diff --git a/scripts/lcp_rtt_exporter b/scripts/lcp_rtt_exporter
new file mode 100644 (file)
index 0000000..4b57d2a
--- /dev/null
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+# vim: shiftwidth=4 tabstop=4
+#
+# This CGI program is a Prometheus exporter for pppd's lcp-rtt-file feature.
+#
+# Copyright (C) Marco d'Itri <md@linux.it>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+use v5.14;
+use warnings;
+use autodie;
+
+use List::Util qw(sum max min);
+
+{
+       my $data = read_data('/run/ppp-rtt.data');
+       my $stats = compute_statistics($data, 60);
+
+       my $s = metrics($stats);
+       my $length = length($s);
+
+       print "Content-type: text/plain\n";
+       print "Content-length: $length\n\n$s";
+       exit;
+}
+
+sub metrics {
+       my ($stats) = @_;
+
+       my $s = <<END;
+# TYPE lcp_rtt_status gauge
+# HELP LCP RTT status
+lcp_rtt_status $stats->{status}
+END
+       foreach (qw(average min max loss)) {
+               next if not exists $stats->{$_};
+               $s .= <<END;
+# TYPE lcp_rtt_$_ gauge
+# HELP LCP RTT $_
+lcp_rtt_$_ $stats->{$_}
+END
+       }
+
+       return $s;
+}
+
+sub compute_statistics {
+       my ($data, $length) = @_;
+
+       my $cutoff = time() - $length;
+       my @e = grep { $_->[0] >= $cutoff } @{ $data->{data} };
+       return { status => -1 } if not @e; # no data
+
+       my $average = (sum map { $_->[1] } @e) / scalar(@e);
+       my $min = min map { $_->[1] } @e;
+       my $max = max map { $_->[1] } @e;
+       my $loss = sum map { $_->[2] } @e;
+
+       return {
+               status  => $data->{status},
+               average => $average,
+               min             => $min,
+               max             => $max,
+               loss    => $loss,
+       };
+}
+
+sub read_data {
+       my ($file) = @_;
+
+       my $data;
+       open(my $fh, '<', $file);
+       binmode($fh);
+       my $bytes_read;
+       do {
+               $bytes_read = sysread($fh, $data, 8192, length($data));
+       } while ($bytes_read == 8192);
+       close($fh);
+
+       my ($magic, $status, $position, $echo_interval, $rest)
+               = unpack('NNNN a*', $data);
+       return undef if $magic != 0x19450425;
+
+       # the position is relative to the C array, not to the logical entries
+       $position /= 2;
+
+       my @rawdata = unpack('(N C a3)*', $rest);
+       my @data;
+       while (my ($time, $loss, $rtt) = splice(@rawdata, 0, 3)) {
+               push(@data, [ $time, unpack('N', "\000$rtt"), $loss ]);
+       }
+
+       @data =
+               # skip any "empty" (null) entries
+               grep { $_->[0] }
+               # rearrange the list in chronological order
+               (@data[$position+1 .. $#data], @data[0 .. $position]);
+
+       return {
+               status                  => $status,
+               echo_interval   => $echo_interval,
+               position                => $position,
+               data                    => \@data,
+       };
+}
+
diff --git a/scripts/options-rsh-loc b/scripts/options-rsh-loc
deleted file mode 100644 (file)
index b015b87..0000000
+++ /dev/null
@@ -1 +0,0 @@
-debug asyncmap FFFFFFFF escape FF kdebug 0 noipdefault nodefaultroute noauth mtu 1460
diff --git a/scripts/options-rsh-rem b/scripts/options-rsh-rem
deleted file mode 100644 (file)
index 4b10bb9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-notty debug asyncmap FFFFFFFF escape FF kdebug 0 noipdefault nodefaultroute noauth mtu 1460
diff --git a/scripts/options-ssh-loc b/scripts/options-ssh-loc
deleted file mode 100644 (file)
index add03d6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-debug asyncmap FFFFFFFF escape FF kdebug 0 noipdefault nodefaultroute noauth mtu 1400
diff --git a/scripts/options-ssh-rem b/scripts/options-ssh-rem
deleted file mode 100644 (file)
index d690722..0000000
+++ /dev/null
@@ -1 +0,0 @@
-notty debug asyncmap FFFFFFFF escape FF kdebug 0 noipdefault nodefaultroute noauth mtu 1400
index 5b45d98a2b6afea557772d07949d1615c12237dd..38b888b3c689afba7a106f6f5401a36ea0d14445 100644 (file)
@@ -1,6 +1,5 @@
 #!/bin/sh
 
-# $Id: poff,v 1.1 2002/11/24 23:30:44 etbe Exp $
 # Written by John Hasler <john@dhh.gt.org> and based on work 
 # by Phil Hands <phil@hands.com>.  Distributed under the GNU GPL
 
diff --git a/scripts/ppp-off b/scripts/ppp-off
deleted file mode 100755 (executable)
index a22b5ea..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-######################################################################
-#
-# Determine the device to be terminated.
-#
-if [ "$1" = "" ]; then
-       DEVICE=ppp0
-else
-       DEVICE=$1
-fi
-
-######################################################################
-#
-# If the ppp0 pid file is present then the program is running. Stop it.
-if [ -r /var/run/$DEVICE.pid ]; then
-        kill -INT `cat /var/run/$DEVICE.pid`
-#
-# If the kill did not work then there is no process running for this
-# pid. It may also mean that the lock file will be left. You may wish
-# to delete the lock file at the same time.
-        if [ ! "$?" = "0" ]; then
-                rm -f /var/run/$DEVICE.pid
-                echo "ERROR: Removed stale pid file"
-                exit 1
-        fi
-#
-# Success. Let pppd clean up its own junk.
-        echo "PPP link to $DEVICE terminated."
-        exit 0
-fi
-#
-# The ppp process is not running for ppp0
-echo "ERROR: PPP link is not active on $DEVICE"
-exit 1
diff --git a/scripts/ppp-on b/scripts/ppp-on
deleted file mode 100755 (executable)
index ab79db4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-#
-# Script to initiate a ppp connection. This is the first part of the
-# pair of scripts. This is not a secure pair of scripts as the codes
-# are visible with the 'ps' command.  However, it is simple.
-#
-# These are the parameters. Change as needed.
-TELEPHONE=555-1212     # The telephone number for the connection
-ACCOUNT=george         # The account name for logon (as in 'George Burns')
-PASSWORD=gracie                # The password for this account (and 'Gracie Allen')
-LOCAL_IP=0.0.0.0       # Local IP address if known. Dynamic = 0.0.0.0
-REMOTE_IP=0.0.0.0      # Remote IP address if desired. Normally 0.0.0.0
-NETMASK=255.255.255.0  # The proper netmask if needed
-#
-# Export them so that they will be available at 'ppp-on-dialer' time.
-export TELEPHONE ACCOUNT PASSWORD
-# 
-# This is the location of the script which dials the phone and logs
-# in.  Please use the absolute file name as the $PATH variable is not
-# used on the connect option.  (To do so on a 'root' account would be
-# a security hole so don't ask.)
-#
-DIALER_SCRIPT=/etc/ppp/ppp-on-dialer
-#
-# Initiate the connection
-# 
-# I put most of the common options on this command. Please, don't
-# forget the 'lock' option or some programs such as mgetty will not
-# work. The asyncmap and escape will permit the PPP link to work with
-# a telnet or rlogin connection. You are welcome to make any changes
-# as desired. Don't use the 'defaultroute' option if you currently
-# have a default route to an ethernet gateway.
-#
-exec /usr/sbin/pppd debug lock modem crtscts /dev/ttyS0 38400 \
-       asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \
-       noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT
diff --git a/scripts/ppp-on-dialer b/scripts/ppp-on-dialer
deleted file mode 100755 (executable)
index 7d66765..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-#
-# This is part 2 of the ppp-on script. It will perform the connection
-# protocol for the desired connection.
-#
-exec chat -v                                           \
-       TIMEOUT         3                               \
-       ABORT           '\nBUSY\r'                      \
-       ABORT           '\nNO ANSWER\r'                 \
-       ABORT           '\nRINGING\r\n\r\nRINGING\r'    \
-       ''              \rAT                            \
-       'OK-+++\c-OK'   ATH0                            \
-       TIMEOUT         30                              \
-       OK              ATDT$TELEPHONE                  \
-       CONNECT         ''                              \
-       ogin:--ogin:    $ACCOUNT                        \
-       assword:        $PASSWORD
diff --git a/scripts/ppp-on-rsh b/scripts/ppp-on-rsh
deleted file mode 100755 (executable)
index 30a50db..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/sh
-#
-# A sample script to establish PPP session(s) via rsh
-#
-# Adi Masputra <adi.masputra@sun.com>
-# Jan 24, 2000
-#
-
-#
-# You'd definitely want to change the following addresses to suit
-# your network configuration
-#
-LOC_IP=10.0.0.1
-REM_IP=10.0.0.2
-NETMASK=255.255.0.0
-
-export LOC_IP REM_IP
-
-#
-# This is the remote peer where in.rshd is running, either
-# its hostname or IP address
-#
-PPPD_RHOST=myremotehost
-
-#
-# For this example, we assume that pppd on both local and remote
-# machines reside in the same place, /usr/local/bin/pppd
-#
-PPPD_LOC=/usr/local/bin/pppd
-
-#
-# The location of local options file (where rsh client is running).
-# Note that the sample options file included in the distribution
-# may need further customizations, depending on your needs. The 'noauth'
-# option specified in the file is there to simplify the example. In
-# reality, you'd probably want to remove such option.
-#
-PPPD_LOC_OPT=/etc/ppp/options-rsh-loc
-
-#
-# The location of remote options file (where in.rshd daemon is running).
-# Note that the sample options file included in the distribution
-# may need further customizations, depending on your needs. The 'noauth'
-# option specified in the file is there to simplify the example. In
-# reality, you'd probably want to remove such option. Also note that
-# the remote options file need to include the 'notty' option for this
-# to work
-#
-PPPD_REM_OPT=/etc/ppp/options-rsh-rem
-
-#
-# The location of rsh client on the local machine
-#
-RSH_LOC=/bin/rsh
-
-export PPPD_LOC PPPD_LOC_OPT PPPD_REM_OPT PPPD_RHOST RSH_LOC
-
-#
-# Uncomment the following to enable IPv6, note that the IPv6 support 
-# needs to be enabled during compilation
-#
-# PPPD_IPV6='+ipv6 ipv6cp-use-ipaddr'
-export PPPD_IPV6
-
-#
-# And execute pppd with the pty option, specifying rsh client as the
-# slave side of the pseduo-tty master/slave pair.
-#
-exec $PPPD_LOC \
-        pty '$RSH_LOC $PPPD_RHOST $PPPD_LOC $REM_IP:$LOC_IP $PPPD_IPV6 file $PPPD_REM_OPT' \
-        $LOC_IP:$REM_IP netmask $NETMASK $PPPD_IPV6 file $PPPD_LOC_OPT
-
diff --git a/scripts/ppp-on-ssh b/scripts/ppp-on-ssh
deleted file mode 100755 (executable)
index 0e41aca..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-#
-# A sample script to establish PPP session(s) via SSH 1.x
-#
-# Adi Masputra <adi.masputra@sun.com>
-# Jan 24, 2000
-#
-
-#
-# You'd definitely want to change the following addresses to suit
-# your network configuration
-#
-LOC_IP=10.0.0.1
-REM_IP=10.0.0.2
-NETMASK=255.255.0.0
-
-export LOC_IP REM_IP
-
-#
-# This is the remote peer where sshd is running, either
-# its hostname or IP address
-#
-PPPD_RHOST=myremotehost
-
-#
-# For this example, we assume that pppd on both local and remote
-# machines reside in the same place, /usr/local/bin/pppd
-#
-PPPD_LOC=/usr/local/bin/pppd
-
-#
-# The location of local options file (where ssh client is running).
-# Note that the sample options file included in the distribution
-# may need further customizations, depending on your needs. The 'noauth'
-# option specified in the file is there to simplify the example, although
-# some may choose to have it there and rely on ssh authentication
-# instead.
-#
-PPPD_LOC_OPT=/etc/ppp/options-ssh-loc
-
-#
-# The location of remote options file (where sshd daemon is running)
-# Note that the sample options file included in the distribution
-# may need further customizations, depending on your needs. The 'noauth'
-# option specified in the file is there to simplify the example, although
-# some may choose to have it there and rely on ssh authentication
-# instead. Also note that the remote options file need to include the 'notty'
-# options for this to work.
-#
-PPPD_REM_OPT=/etc/ppp/options-ssh-rem
-
-#
-# The location of ssh client on the local machine
-#
-SSH_LOC=/usr/local/bin/ssh
-
-export PPPD_LOC PPPD_LOC_OPT PPPD_REM_OPT PPPD_RHOST SSH_LOC
-
-#
-# Uncomment the following to enable IPv6, note that the IPv6 support 
-# needs to be enabled during compilation
-#
-# PPPD_IPV6='+ipv6 ipv6cp-use-ipaddr'
-export PPPD_IPV6
-
-#
-# And execute pppd with the pty option, specifying ssh client as the
-# slave side of the pseudo-tty master/slave pair. Note that on this example,
-# ssh has been compiled to allow NULL encryption (thus the '-c none' option),
-# but in reality, you'd probably want to specify the encryption algorithm.
-# See the man page of ssh(1) for details.
-#
-exec $PPPD_LOC \
-        pty '$SSH_LOC -c none $PPPD_RHOST $PPPD_LOC $REM_IP:$LOC_IP $PPPD_IPV6 file $PPPD_REM_OPT' \
-        $LOC_IP:$REM_IP netmask $NETMASK $PPPD_IPV6 file $PPPD_LOC_OPT
-
diff --git a/scripts/redialer b/scripts/redialer
deleted file mode 100755 (executable)
index 5bbde4e..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/sh
-###################################################################
-#
-# These parameters control the attack dialing sequence.
-#
-# Maximum number of attempts to reach the telephone number(s)
-MAX_ATTEMPTS=10
-
-# Delay between each of the attempts. This is a parameter to sleep
-# so use "15s" for 15 seconds, "1m" for 1 minute, etc.
-SLEEP_DELAY=15s
-
-###################################################################
-#
-# This is a list of telephone numbers. Add new numbers if you wish
-# and see the function 'callall' below for the dial process.
-PHONE1=555-1212
-PHONE2=411
-
-###################################################################
-#
-# If you use the ppp-on script, then these are passed to this routine
-# automatically. There is no need to define them here. If not, then
-# you will need to set the values.
-#
-ACCOUNT=my_account_name
-PASSWORD=my_password
-
-###################################################################
-#
-# Function to initialize the modem and ensure that it is in command
-# state. This may not be needed, but it doesn't hurt.
-#
-function initialize
-{
-    chat -v TIMEOUT 3 '' AT 'OK-+++\c-OK'
-    return
-}
-
-###################################################################
-#
-# Script to dial a telephone
-#
-function callnumber
-{
-chat -v                                                        \
-       ABORT           '\nBUSY\r'                      \
-       ABORT           '\nNO ANSWER\r'                 \
-       ABORT           '\nRINGING\r\n\r\nRINGING\r'    \
-       ''              ATDT$1                          \
-       CONNECT         ''                              \
-       ogin:--ogin:    $ACCOUNT                        \
-       assword:        $PASSWORD
-#
-# If the connection was successful then end the whole script with a
-# success.
-#
-    if [ "$?" = "0" ]; then
-       exit 0
-    fi
-
-    return
-}
-
-###################################################################
-#
-# Script to dial any telephone number
-#
-function callall
-{
-#   echo "dialing attempt number: $1" >/dev/console
-    callnumber $PHONE1
-#    callnumber $PHONE2
-}
-
-###################################################################
-#
-# Initialize the modem to ensure that it is in the command state
-#
-initialize
-if [ ! "$?" = "0" ]; then
-   exit 1
-fi
-
-#
-# Dial telephone numbers until one answers
-#
-attempt=0
-while : ; do
-    attempt=`expr $attempt + 1`
-    callall $attempt
-    if [ "$attempt" = "$MAX_ATTEMPTS" ]; then
-       exit 1
-    fi 
-    sleep "$SLEEP_DELAY"
-done
diff --git a/scripts/secure-card b/scripts/secure-card
deleted file mode 100755 (executable)
index ae3ae50..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/expect -f
-#
-# This  script was  written  by  Jim Isaacson  <jcisaac@crl.com>.  It is
-# designed to work  as a script to use the  SecureCARD(tm) device.  This
-# little device is mated with a central controller. The number displayed
-# on this card changes every so often and  you need to enter  the number
-# along with your user account name in order to gain access.  Since chat
-# is based upon fixed strings this procedure will not work with chat.
-#
-# It is included by permission. An excellent reference for the expect
-# program used by this script is in the book:
-#
-# "Exploring Expect"
-# by Don Libes
-# Published by O'Rielly and Associates
-#
-
-send_user "hello, starting ppp\n"
-
-system "stty 19200 -echoe -echo raw < /dev/ttyS3 > /dev/ttyS3"
-
-#
-# These are the parameters for the program.
-#
-set user      Pxxxxxx
-set password  xxxxxxx 
-set modem     /dev/ttyS3
-set dialup    <put phone number here>
-set timeout   60
-
-spawn -noecho -open [open $modem "r+"]
-
-send "AT&F\r"
-expect "OK"
-
-send "ATe0v1x4&c1q0&d2&c1s2=128s0=0DT $dialup\r"
-set timeout 15
-set counter 0
-
-set still_connecting 1
-
-expect {
-       -re ".*CONNECT.*\n" {
-               set timeout 5
-               set still_connecting 0
-               continue -expect
-       }
-       -re ".*CONNECT.*\r" {
-               set timeout 5
-               set still_connecting 0
-               continue -expect
-       }
-        -re ".*NO.*CARRIER" {
-               send_user "Failed to Connect, exiting...\n"
-               exit
-        }
-        -re ".*NO.*DIAL.*TONE" {
-               send_user "Failed to Connect, exiting...\n"
-               exit
-        }
-        -re ".*VOICE" {
-               send_user "Failed to Connect, exiting...\n"
-               exit
-        }
-       -re ".*sscode:.*\n" {
-               continue -expect
-       }
-       -re ".*sscode:" {
-                set timeout -1
-               expect_user -re "(.*)\n"
-               send "$expect_out(1,string)\r"
-               set timeout 30
-               continue -expect
-       }
-       -re ".*Next.*:" {
-                set timeout -1
-               expect_user -re "(.*)\n"
-               send "$expect_out(1,string)\r"
-               set timeout 30
-               continue -expect
-       }
-       -re "Your.*" {
-               send "\r"
-               continue -expect
-       }
-       -re ".*in:" {
-               send "$user\r"
-               continue -expect
-       }
-       -re ".*word:" {
-               send "$password\r"
-       }
-
-       timeout {
-               if { $still_connecting > 0 } {
-                       continue -expect 
-                       }
-               set timeout 15
-               send "\r"
-               incr counter
-               if { $counter > 8 } {
-                       send_user "Cannot Connect\n"
-                       exit
-               } else {
-                       continue -expect
-               }
-       }
-}
-
-overlay -0 $spawn_id -1 $spawn_id pppd /dev/ttyS3 19200 192.111.187.215: \
-       crtscts modem defaultroute debug 
diff --git a/solaris/Makedefs b/solaris/Makedefs
deleted file mode 100644 (file)
index 967e292..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# defines common to several Makefiles
-#
-
-INSTALL= /usr/sbin/install
-
-BINDIR = @DESTDIR@/bin
-MANDIR = @DESTDIR@/man
-ETCDIR = @SYSCONF@/ppp
-
-CC = /opt/SUNWspro/bin/cc
-COPTS = -O -Xa
-
-LD = /usr/ccs/bin/ld
diff --git a/solaris/Makedefs.gcc b/solaris/Makedefs.gcc
deleted file mode 100644 (file)
index ba9ce01..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-# defines common to several Makefiles
-#
-
-INSTALL= /usr/sbin/install
-
-BINDIR = @DESTDIR@/bin
-MANDIR = @DESTDIR@/man
-ETCDIR = @SYSCONF@/ppp
-
-CC = gcc
-COPTS = -O2
-
-LD = /usr/ccs/bin/ld
diff --git a/solaris/Makedefs.sol2 b/solaris/Makedefs.sol2
deleted file mode 100644 (file)
index a0417bd..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Generic make definitions for Solaris 2
-#
-# $Id: Makedefs.sol2,v 1.2 2002/09/07 05:15:25 carlsonj Exp $
-#
-
-include ../Makedefs.com
-
-CPPFLAGS       = -D_KERNEL -DSVR4 -DSOL2 -DPRIOQ -DDEBUG -I../include
-CFLAGS         = $(CPPFLAGS) $(COPTS)
-
-# lint-specific variables
-LINT            = lint
-LINT_OPT_32     =
-LINT_OPT_64     = -Xarch=v9 -errchk=longptr64
-
-LINT_32        =
-LINT_32        += -erroff=E_BAD_PTR_CAST_ALIGN
-LINT_32        += -erroff=E_SUPPRESSION_DIRECTIVE_UNUSED
-LINT_32        += -erroff=E_SUSPICIOUS_COMPARISON
-LINT_32        += -erroff=E_CAST_UINT_TO_SIGNED_INT
-LINT_32        += -erroff=E_PASS_UINT_TO_SIGNED_INT
-LINT_32        += -erroff=E_INVALID_ANNOTATION_NAME
-LINT_32        += -erroff=E_FUNC_ARG_UNUSED
-# This might be needed, but zlib.c and vjcompress.c will squawk 
-# when not ignored
-LINT_32                += -erroff=E_CASE_FALLTHRU
-LINT_32                += -erroff=E_RET_INT_IMPLICITLY
-LINT_32                += -erroff=E_FUNC_NO_RET_VAL
-# Some STREAMS macros will be noisy too when this isn't ignored
-LINT_32                += -erroff=E_CONSTANT_CONDITION
-LINT_32                += -erroff=E_CONST_EXPR
-
-# Extra noise suppressant for 64-bit
-EXTRA_OFF      =
-EXTRA_OFF      += -erroff=E_CAST_INT_TO_SMALL_INT
-EXTRA_OFF      += -erroff=E_CAST_INT_CONST_TO_SMALL_INT
-EXTRA_OFF      += -erroff=E_CAST_TO_PTR_FROM_INT
-EXTRA_OFF      += -erroff=E_ASSIGN_INT_TO_SMALL_INT
-EXTRA_OFF      += -erroff=E_ASSIGN_INT_FROM_BIG_CONST
-EXTRA_OFF      += -erroff=E_CONST_PROMOTED_UNSIGNED_LL
-EXTRA_OFF      += -erroff=E_CONST_PROMOTED_LONG_LONG
-EXTRA_OFF      += -erroff=E_CONST_TRUNCATED_BY_ASSIGN
-EXTRA_OFF      += -erroff=E_PASS_INT_FROM_BIG_CONST
-EXTRA_OFF      += -erroff=E_COMP_INT_WITH_LARGE_INT
-EXTRA_OFF      += -erroff=E_ASSIGN_UINT_TO_SIGNED_INT
-EXTRA_OFF      += -erroff=E_ASSIGN_NARROW_CONV
-EXTRA_OFF      += -erroff=E_PASS_INT_TO_SMALL_INT
-EXTRA_OFF      += -erroff=E_PTR_CONV_LOSES_BITS
-
-LINT_64        = $(LINT_32)
-LINT_64        += $(EXTRA_OFF)
-
-LINTFLAGS64     = -Xa -nsxmuF -errtags=yes $(LINT_OPT_64) $(LINT_64)
-LINT64          = $(LINT) -c $(LINTFLAGS64) $(CPPFLAGS)
-
-LINTFLAGS32     = -Xa -nsxmuF -errtags=yes $(LINT_OPT_32) $(LINT_32)
-LINT32          = $(LINT) -c $(LINTFLAGS32) $(CPPFLAGS)
-
diff --git a/solaris/Makefile.sol2 b/solaris/Makefile.sol2
deleted file mode 100644 (file)
index c3b2577..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Makefile for STREAMS modules for Solaris 2.
-#
-# $Id: Makefile.sol2,v 1.3 2004/11/15 00:57:54 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-COPTS += -xO2 -xspace -W0,-Lt
-
-COMP_OBJS = ppp_comp.o bsd-comp.o deflate.o zlib.o vjcompress.o \
-       ppp_comp_mod.o
-
-all:   ppp ppp_ahdl ppp_comp
-
-ppp:   ppp.o ppp_mod.o
-       $(LD) -r -o $@ ppp.o ppp_mod.o
-       chmod +x $@
-
-ppp_ahdl: ppp_ahdlc.o ppp_ahdlc_mod.o
-       $(LD) -r -o $@ ppp_ahdlc.o ppp_ahdlc_mod.o
-       chmod +x $@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $@ $(COMP_OBJS)
-       chmod +x $@
-
-bsd-comp.o:    ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $?
-deflate.o:     ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $?
-ppp.o: ppp.c
-       $(CC) $(CFLAGS) -c $?
-ppp_mod.o:     ppp_mod.c
-       $(CC) $(CFLAGS) -c $?
-ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $?
-ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $?
-ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $?
-ppp_comp_mod.o:        ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $?
-vjcompress.o:  ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $?
-zlib.o:        ../common/zlib.c
-       $(CC) $(CFLAGS) -c $?
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT32) $(SRCS)
-
-clean:
-       rm -f ppp ppp_comp ppp_ahdl *.o *~ core
-       rm -f *.ln
diff --git a/solaris/Makefile.sol2-64 b/solaris/Makefile.sol2-64
deleted file mode 100644 (file)
index 9d614ae..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Makefile for 64-bit STREAMS modules for Solaris 2.
-#
-# $Id: Makefile.sol2-64,v 1.3 2004/11/15 00:57:54 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-# Sun's cc flag for LP64 compilation / linkage
-COPTS          += -xchip=ultra -xarch=v9 -Wc,-xcode=abs32 -Wc,-Qiselect-regsym=0 -xO3 -xspace -W0,-Lt
-
-# subdirectory where 64-bit objects / binaries will be placed
-LP64DIR                = sparcv9
-
-# Name of legacy Makefile (for 32-bit binaries)
-STD_MAKE       = Makefile.sol2
-
-COMP_OBJS      = $(LP64DIR)/ppp_comp.o $(LP64DIR)/bsd-comp.o \
-               $(LP64DIR)/deflate.o $(LP64DIR)/zlib.o $(LP64DIR)/vjcompress.o \
-               $(LP64DIR)/ppp_comp_mod.o
-
-all:   std_objs $(LP64DIR) ppp ppp_ahdl ppp_comp
-
-std_objs:
-       $(MAKE) -f $(STD_MAKE) all
-
-ppp:   $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_ahdl: $(LP64DIR)/ppp_ahdlc.o $(LP64DIR)/ppp_ahdlc_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp_ahdlc.o \
-               $(LP64DIR)/ppp_ahdlc_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $(LP64DIR)/$@ $(COMP_OBJS)
-       chmod +x $(LP64DIR)/$@
-
-$(LP64DIR)/bsd-comp.o: ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/deflate.o: ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp.o:      ppp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_mod.o:  ppp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp_mod.o: ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/vjcompress.o: ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/zlib.o:     ../common/zlib.c
-       $(CC) $(CFLAGS) -c $? -o $@
-
-$(LP64DIR):
-       mkdir -m 755 -p $@
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       cp $(LP64DIR)/ppp /kernel/drv/$(LP64DIR)
-       cp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl /kernel/strmod/$(LP64DIR)
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT64) $(SRCS)
-
-lint-32:
-       $(LINT32) $(SRCS)
-
-clean:
-       $(MAKE) -f $(STD_MAKE) clean
-       rm -f $(LP64DIR)/ppp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl $(LP64DIR)/*.o $(LP64DIR)/*~ $(LP64DIR)/core
diff --git a/solaris/Makefile.sol2-64x b/solaris/Makefile.sol2-64x
deleted file mode 100644 (file)
index afddcb9..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#
-# Makefile for 64-bit STREAMS modules for Solaris 2 on x64
-#
-# $Id: Makefile.sol2-64x,v 1.1 2005/06/26 23:53:17 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-# Sun's cc flag for LP64 compilation / linkage
-COPTS          += -errwarn -xtarget=opteron -m64 -xmodel=kernel \
-                  -Ui386 -U__i386 -D__amd64 -xO2
-
-# subdirectory where 64-bit objects / binaries will be placed
-LP64DIR                = amd64
-
-# Name of legacy Makefile (for 32-bit binaries)
-STD_MAKE       = Makefile.sol2
-
-COMP_OBJS      = $(LP64DIR)/ppp_comp.o $(LP64DIR)/bsd-comp.o \
-               $(LP64DIR)/deflate.o $(LP64DIR)/zlib.o $(LP64DIR)/vjcompress.o \
-               $(LP64DIR)/ppp_comp_mod.o
-
-all:   std_objs $(LP64DIR) ppp ppp_ahdl ppp_comp
-
-std_objs:
-       $(MAKE) -f $(STD_MAKE) all
-
-ppp:   $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_ahdl: $(LP64DIR)/ppp_ahdlc.o $(LP64DIR)/ppp_ahdlc_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp_ahdlc.o \
-               $(LP64DIR)/ppp_ahdlc_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $(LP64DIR)/$@ $(COMP_OBJS)
-       chmod +x $(LP64DIR)/$@
-
-$(LP64DIR)/bsd-comp.o: ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/deflate.o: ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp.o:      ppp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_mod.o:  ppp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp_mod.o: ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/vjcompress.o: ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/zlib.o:     ../common/zlib.c
-       $(CC) $(CFLAGS) -c $? -o $@
-
-$(LP64DIR):
-       mkdir -m 755 -p $@
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       cp $(LP64DIR)/ppp /kernel/drv/$(LP64DIR)
-       cp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl /kernel/strmod/$(LP64DIR)
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT64) $(SRCS)
-
-lint-32:
-       $(LINT32) $(SRCS)
-
-clean:
-       $(MAKE) -f $(STD_MAKE) clean
-       rm -f $(LP64DIR)/ppp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl $(LP64DIR)/*.o $(LP64DIR)/*~ $(LP64DIR)/core
diff --git a/solaris/Makefile.sol2gcc b/solaris/Makefile.sol2gcc
deleted file mode 100644 (file)
index 7d7c943..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# Makefile for STREAMS modules for Solaris 2.
-#
-# $Id: Makefile.sol2gcc,v 1.4 2004/11/15 00:57:54 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-COPTS += -fno-builtin
-
-COMP_OBJS = ppp_comp.o bsd-comp.o deflate.o zlib.o vjcompress.o \
-       ppp_comp_mod.o
-
-all:   ppp ppp_ahdl ppp_comp
-
-ppp:   ppp.o ppp_mod.o
-       $(LD) -r -o $@ ppp.o ppp_mod.o
-       chmod +x $@
-
-ppp_ahdl: ppp_ahdlc.o ppp_ahdlc_mod.o
-       $(LD) -r -o $@ ppp_ahdlc.o ppp_ahdlc_mod.o
-       chmod +x $@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $@ $(COMP_OBJS)
-       chmod +x $@
-
-bsd-comp.o:    ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $?
-deflate.o:     ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $?
-ppp.o: ppp.c
-       $(CC) $(CFLAGS) -c $?
-ppp_mod.o:     ppp_mod.c
-       $(CC) $(CFLAGS) -c $?
-ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $?
-ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $?
-ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $?
-ppp_comp_mod.o:        ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $?
-vjcompress.o:  ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $?
-zlib.o:        ../common/zlib.c
-       $(CC) $(CFLAGS) -c $?
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT32) $(SRCS)
-
-clean:
-       rm -f ppp ppp_comp ppp_ahdl *.o *~ core
-       rm -f *.ln
diff --git a/solaris/Makefile.sol2gcc-64 b/solaris/Makefile.sol2gcc-64
deleted file mode 100644 (file)
index 2844a0d..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-#
-# Makefile for 64-bit STREAMS modules for Solaris 2.
-#
-# $Id: Makefile.sol2gcc-64,v 1.3 2004/11/15 00:57:54 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-# gcc flags for LP64 compilation / linkage
-COPTS           += -mcpu=v9 -m64 -mcmodel=medlow -mstack-bias -fno-builtin
-
-# subdirectory where 64-bit objects / binaries will be placed
-LP64DIR                = sparcv9
-
-# Name of legacy Makefile (for 32-bit binaries)
-STD_MAKE       = Makefile.sol2gcc
-
-COMP_OBJS      = $(LP64DIR)/ppp_comp.o $(LP64DIR)/bsd-comp.o \
-               $(LP64DIR)/deflate.o $(LP64DIR)/zlib.o $(LP64DIR)/vjcompress.o \
-               $(LP64DIR)/ppp_comp_mod.o
-
-all:   std_objs $(LP64DIR) ppp ppp_ahdl ppp_comp
-
-std_objs:
-       $(MAKE) -f $(STD_MAKE) all
-
-ppp:   $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_ahdl: $(LP64DIR)/ppp_ahdlc.o $(LP64DIR)/ppp_ahdlc_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp_ahdlc.o \
-               $(LP64DIR)/ppp_ahdlc_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $(LP64DIR)/$@ $(COMP_OBJS)
-       chmod +x $(LP64DIR)/$@
-
-$(LP64DIR)/bsd-comp.o: ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/deflate.o: ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp.o:      ppp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_mod.o:  ppp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp_mod.o: ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/vjcompress.o: ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/zlib.o:     ../common/zlib.c
-       $(CC) $(CFLAGS) -c $? -o $@
-
-$(LP64DIR):
-       mkdir -m 755 -p $@
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       cp $(LP64DIR)/ppp /kernel/drv/$(LP64DIR)
-       cp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl /kernel/strmod/$(LP64DIR)
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT64) $(SRCS)
-
-lint-32:
-       $(LINT32) $(SRCS)
-
-clean:
-       $(MAKE) -f $(STD_MAKE) clean
-       rm -f $(LP64DIR)/ppp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl $(LP64DIR)/*.o $(LP64DIR)/*~ $(LP64DIR)/core
diff --git a/solaris/Makefile.sol2gcc-64x b/solaris/Makefile.sol2gcc-64x
deleted file mode 100644 (file)
index 0eaef7d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-#
-# Makefile for 64-bit STREAMS modules for Solaris 2 on x64 with gcc.
-#
-# $Id: Makefile.sol2gcc-64x,v 1.1 2005/06/26 23:53:17 carlsonj Exp $
-#
-
-include Makedefs.sol2
-
-# gcc flags for LP64 compilation / linkage
-COPTS           += -finline -fno-inline-functions -fno-builtin -fno-asm \
-                  -nodefaultlibs -D__sun -m64 -mtune=opteron -Ui386 \
-                  -U__i386 -fno-strict-aliasing -fno-unit-at-a-time \
-                  -fno-optimize-sibling-calls -O2 -D_ASM_INLINES \
-                  -ffreestanding -mcmodel=kernel -mno-red-zone -gdwarf-2 \
-                  -std=gnu89 -D_KERNEL -D_SYSCALL32 -D_SYSCALL32_IMPL \
-                  -D_ELF64 -Dsun -D__sun -D__SVR4
-
-# subdirectory where 64-bit objects / binaries will be placed
-LP64DIR                = amd64
-
-# Name of legacy Makefile (for 32-bit binaries)
-STD_MAKE       = Makefile.sol2gcc
-
-COMP_OBJS      = $(LP64DIR)/ppp_comp.o $(LP64DIR)/bsd-comp.o \
-               $(LP64DIR)/deflate.o $(LP64DIR)/zlib.o $(LP64DIR)/vjcompress.o \
-               $(LP64DIR)/ppp_comp_mod.o
-
-all:   std_objs $(LP64DIR) ppp ppp_ahdl ppp_comp
-
-std_objs:
-       $(MAKE) -f $(STD_MAKE) all
-
-ppp:   $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp.o $(LP64DIR)/ppp_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_ahdl: $(LP64DIR)/ppp_ahdlc.o $(LP64DIR)/ppp_ahdlc_mod.o
-       $(LD) -r -o $(LP64DIR)/$@ $(LP64DIR)/ppp_ahdlc.o \
-               $(LP64DIR)/ppp_ahdlc_mod.o
-       chmod +x $(LP64DIR)/$@
-
-ppp_comp: $(COMP_OBJS)
-       $(LD) -r -o $(LP64DIR)/$@ $(COMP_OBJS)
-       chmod +x $(LP64DIR)/$@
-
-$(LP64DIR)/bsd-comp.o: ../modules/bsd-comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/deflate.o: ../modules/deflate.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp.o:      ppp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_mod.o:  ppp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc_mod.o: ppp_ahdlc_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_ahdlc.o: ppp_ahdlc.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp.o: ppp_comp.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/ppp_comp_mod.o: ppp_comp_mod.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/vjcompress.o: ../modules/vjcompress.c
-       $(CC) $(CFLAGS) -c $? -o $@
-$(LP64DIR)/zlib.o:     ../common/zlib.c
-       $(CC) $(CFLAGS) -c $? -o $@
-
-$(LP64DIR):
-       mkdir -m 755 -p $@
-
-install:
-       /usr/sbin/modunload -i 0
-       cp ppp ppp.conf /kernel/drv
-       cp ppp_comp ppp_ahdl /kernel/strmod
-       cp $(LP64DIR)/ppp /kernel/drv/$(LP64DIR)
-       cp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl /kernel/strmod/$(LP64DIR)
-       if grep clone:ppp /etc/minor_perm; then :; else \
-         echo clone:ppp 0644 root sys >>/etc/minor_perm; fi
-       /usr/sbin/rem_drv ppp 2>/dev/null || true
-       /usr/sbin/modunload -i 0
-       /usr/sbin/add_drv ppp
-
-SRCS   = ppp.c ppp_mod.c ppp_ahdlc.c ppp_ahdlc_mod.c \
-       ppp_comp.c ../modules/bsd-comp.c ../modules/deflate.c \
-       ../common/zlib.c ../modules/vjcompress.c ppp_comp_mod.c
-
-lint:
-       $(LINT64) $(SRCS)
-
-lint-32:
-       $(LINT32) $(SRCS)
-
-clean:
-       $(MAKE) -f $(STD_MAKE) clean
-       rm -f $(LP64DIR)/ppp $(LP64DIR)/ppp_comp $(LP64DIR)/ppp_ahdl $(LP64DIR)/*.o $(LP64DIR)/*~ $(LP64DIR)/core
diff --git a/solaris/Makefile.top b/solaris/Makefile.top
deleted file mode 100644 (file)
index 73edccd..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# ppp top level makefile for SVR4 and Solaris 2
-#
-# $Id: Makefile.top,v 1.3 2004/11/01 09:31:07 paulus Exp $
-#
-
-include Makedefs.com
-
-all:
-       cd chat; $(MAKE) all
-       cd pppd; $(MAKE) all
-       cd pppstats; $(MAKE) all
-       cd pppdump; $(MAKE) all
-       cd solaris; $(MAKE) all
-
-install: $(BINDIR) $(MANDIR)/man8 install-progs
-
-install-progs:
-       cd chat; $(MAKE) install
-       cd pppd; $(MAKE) install
-       cd pppstats; $(MAKE) install
-       cd pppdump; $(MAKE) install
-
-install-etcppp: $(ETCDIR) $(ETCDIR)/options $(ETCDIR)/pap-secrets \
-       $(ETCDIR)/chap-secrets
-
-install-modules:
-       cd solaris; $(MAKE) install
-
-$(ETCDIR)/options:
-       cp etc.ppp/options $@
-       chmod go-w $@
-$(ETCDIR)/pap-secrets:
-       $(INSTALL) -f $(ETCDIR) -m 600 etc.ppp/pap-secrets
-$(ETCDIR)/chap-secrets:
-       $(INSTALL) -f $(ETCDIR) -m 600 etc.ppp/chap-secrets
-
-$(BINDIR):
-       mkdir -m 755 -p $@
-$(MANDIR)/man8:
-       mkdir -m 755 -p $@
-$(ETCDIR):
-       mkdir -m 755 -p $@
-
-clean:
-       rm -f *~
-       cd chat; $(MAKE) clean
-       cd pppd; $(MAKE) clean
-       cd pppstats; $(MAKE) clean
-       cd pppdump; $(MAKE) clean
-       cd solaris; $(MAKE) clean
-
-# no tests yet, one day...
-installcheck:
-       true
diff --git a/solaris/ppp.c b/solaris/ppp.c
deleted file mode 100644 (file)
index 98f4f91..0000000
+++ /dev/null
@@ -1,2511 +0,0 @@
-/*
- * ppp.c - STREAMS multiplexing pseudo-device driver for PPP.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * This file is used under Solaris 2, SVR4, SunOS 4, and Digital UNIX.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-#include <sys/errno.h>
-#ifdef __osf__
-#include <sys/ioctl.h>
-#include <sys/cmn_err.h>
-#define queclass(mp)   ((mp)->b_band & QPCTL)
-#else
-#include <sys/ioccom.h>
-#endif
-#include <sys/time.h>
-#ifdef SVR4
-#include <sys/cmn_err.h>
-#include <sys/conf.h>
-#include <sys/dlpi.h>
-#include <sys/ddi.h>
-#ifdef SOL2
-#include <sys/ksynch.h>
-#include <sys/kstat.h>
-#include <sys/sunddi.h>
-#include <sys/ethernet.h>
-#else
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#endif /* SOL2 */
-#else /* not SVR4 */
-#include <sys/user.h>
-#endif /* SVR4 */
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-/*
- * Modifications marked with #ifdef PRIOQ are for priority queueing of
- * interactive traffic, and are due to Marko Zec <zec@japa.tel.fer.hr>.
- */
-#ifdef PRIOQ
-#endif /* PRIOQ */
-
-#include <netinet/in.h>        /* leave this outside of PRIOQ for htons */
-
-/*
- * The IP module may use this SAP value for IP packets.
- */
-#ifndef ETHERTYPE_IP
-#define ETHERTYPE_IP   0x800
-#endif
-
-#if !defined(ETHERTYPE_IPV6) 
-#define ETHERTYPE_IPV6 0x86dd
-#endif /* !defined(ETHERTYPE_IPV6) */
-
-#if !defined(ETHERTYPE_ALLSAP) && defined(SOL2)
-#define ETHERTYPE_ALLSAP   0
-#endif /* !defined(ETHERTYPE_ALLSAP) && defined(SOL2) */
-
-#if !defined(PPP_ALLSAP) && defined(SOL2)
-#define PPP_ALLSAP  PPP_ALLSTATIONS
-#endif /* !defined(PPP_ALLSAP) && defined(SOL2) */
-
-extern time_t time;
-
-#ifdef SOL2
-/*
- * We use this reader-writer lock to ensure that the lower streams
- * stay connected to the upper streams while the lower-side put and
- * service procedures are running.  Essentially it is an existence
- * lock for the upper stream associated with each lower stream.
- */
-krwlock_t ppp_lower_lock;
-#define LOCK_LOWER_W   rw_enter(&ppp_lower_lock, RW_WRITER)
-#define LOCK_LOWER_R   rw_enter(&ppp_lower_lock, RW_READER)
-#define TRYLOCK_LOWER_R        rw_tryenter(&ppp_lower_lock, RW_READER)
-#define UNLOCK_LOWER   rw_exit(&ppp_lower_lock)
-
-#define MT_ENTER(x)    mutex_enter(x)
-#define MT_EXIT(x)     mutex_exit(x)
-
-/*
- * Notes on multithreaded implementation for Solaris 2:
- *
- * We use an inner perimeter around each queue pair and an outer
- * perimeter around the whole driver.  The inner perimeter is
- * entered exclusively for all entry points (open, close, put,
- * service).  The outer perimeter is entered exclusively for open
- * and close and shared for put and service.  This is all done for
- * us by the streams framework.
- *
- * I used to think that the perimeters were entered for the lower
- * streams' put and service routines as well as for the upper streams'.
- * Because of problems experienced by people, and after reading the
- * documentation more closely, I now don't think that is true.  So we
- * now use ppp_lower_lock to give us an existence guarantee on the
- * upper stream controlling each lower stream.
- *
- * Shared entry to the outer perimeter protects the existence of all
- * the upper streams and their upperstr_t structures, and guarantees
- * that the following fields of any upperstr_t won't change:
- * nextmn, next, nextppa.  It guarantees that the lowerq field of an
- * upperstr_t won't go from non-zero to zero, that the global `ppas'
- * won't change and that the no lower stream will get unlinked.
- *
- * Shared (reader) access to ppa_lower_lock guarantees that no lower
- * stream will be unlinked and that the lowerq field of all upperstr_t
- * structures won't change.
- */
-
-#else /* SOL2 */
-#define LOCK_LOWER_W   0
-#define LOCK_LOWER_R   0
-#define TRYLOCK_LOWER_R        1
-#define UNLOCK_LOWER   0
-#define MT_ENTER(x)    0
-#define MT_EXIT(x)     0
-
-#endif /* SOL2 */
-
-/*
- * Private information; one per upper stream.
- */
-typedef struct upperstr {
-    minor_t mn;                        /* minor device number */
-    struct upperstr *nextmn;   /* next minor device */
-    queue_t *q;                        /* read q associated with this upper stream */
-    int flags;                 /* flag bits, see below */
-    int state;                 /* current DLPI state */
-    int sap;                   /* service access point */
-    int req_sap;               /* which SAP the DLPI client requested */
-    struct upperstr *ppa;      /* control stream for our ppa */
-    struct upperstr *next;     /* next stream for this ppa */
-    uint ioc_id;               /* last ioctl ID for this stream */
-    enum NPmode npmode;                /* what to do with packets on this SAP */
-    unsigned char rblocked;    /* flow control has blocked upper read strm */
-       /* N.B. rblocked is only changed by control stream's put/srv procs */
-    /*
-     * There is exactly one control stream for each PPA.
-     * The following fields are only used for control streams.
-     */
-    int ppa_id;
-    queue_t *lowerq;           /* write queue attached below this PPA */
-    struct upperstr *nextppa;  /* next control stream */
-    int mru;
-    int mtu;
-    struct pppstat stats;      /* statistics */
-    time_t last_sent;          /* time last NP packet sent */
-    time_t last_recv;          /* time last NP packet rcvd */
-#ifdef SOL2
-    kmutex_t stats_lock;       /* lock for stats updates */
-    kstat_t *kstats;           /* stats for netstat */
-#endif /* SOL2 */
-#ifdef LACHTCP
-    int ifflags;
-    char ifname[IFNAMSIZ];
-    struct ifstats ifstats;
-#endif /* LACHTCP */
-} upperstr_t;
-
-/* Values for flags */
-#define US_PRIV                1       /* stream was opened by superuser */
-#define US_CONTROL     2       /* stream is a control stream */
-#define US_BLOCKED     4       /* flow ctrl has blocked lower write stream */
-#define US_LASTMOD     8       /* no PPP modules below us */
-#define US_DBGLOG      0x10    /* log various occurrences */
-#define US_RBLOCKED    0x20    /* flow ctrl has blocked upper read stream */
-
-#if defined(SOL2)
-#if DL_CURRENT_VERSION >= 2
-#define US_PROMISC     0x40    /* stream is promiscuous */
-#endif /* DL_CURRENT_VERSION >= 2 */
-#define US_RAWDATA     0x80    /* raw M_DATA, no DLPI header */
-#endif /* defined(SOL2) */
-
-#ifdef PRIOQ
-static u_char max_band=0;
-static u_char def_band=0;
-
-#define IPPORT_DEFAULT         65535
-
-/*
- * Port priority table
- * Highest priority ports are listed first, lowest are listed last.
- * ICMP & packets using unlisted ports will be treated as "default".
- * If IPPORT_DEFAULT is not listed here, "default" packets will be 
- * assigned lowest priority.
- * Each line should be terminated with "0".
- * Line containing only "0" marks the end of the list.
- */
-
-static u_short prioq_table[]= {
-    113, 53, 0,
-    22, 23, 513, 517, 518, 0,
-    514, 21, 79, 111, 0,
-    25, 109, 110, 0,
-    IPPORT_DEFAULT, 0,
-    20, 70, 80, 8001, 8008, 8080, 0, /* 8001,8008,8080 - common proxy ports */
-0 };
-
-#endif /* PRIOQ */
-
-
-static upperstr_t *minor_devs = NULL;
-static upperstr_t *ppas = NULL;
-
-#ifdef SVR4
-static int pppopen(queue_t *, dev_t *, int, int, cred_t *);
-static int pppclose(queue_t *, int, cred_t *);
-#else
-static int pppopen(queue_t *, int, int, int);
-static int pppclose(queue_t *, int);
-#endif /* SVR4 */
-static int pppurput(queue_t *, mblk_t *);
-static int pppuwput(queue_t *, mblk_t *);
-static int pppursrv(queue_t *);
-static int pppuwsrv(queue_t *);
-static int ppplrput(queue_t *, mblk_t *);
-static int ppplwput(queue_t *, mblk_t *);
-static int ppplrsrv(queue_t *);
-static int ppplwsrv(queue_t *);
-#ifndef NO_DLPI
-static void dlpi_request(queue_t *, mblk_t *, upperstr_t *);
-static void dlpi_error(queue_t *, upperstr_t *, int, int, int);
-static void dlpi_ok(queue_t *, int);
-#endif
-static int send_data(mblk_t *, upperstr_t *);
-static void new_ppa(queue_t *, mblk_t *);
-static void attach_ppa(queue_t *, mblk_t *);
-#ifndef NO_DLPI
-static void detach_ppa(queue_t *, mblk_t *);
-#endif
-static void detach_lower(queue_t *, mblk_t *);
-static void debug_dump(queue_t *, mblk_t *);
-static upperstr_t *find_dest(upperstr_t *, int);
-#if defined(SOL2)
-static upperstr_t *find_promisc(upperstr_t *, int);
-static mblk_t *prepend_ether(upperstr_t *, mblk_t *, int);
-static mblk_t *prepend_udind(upperstr_t *, mblk_t *, int);
-static void promisc_sendup(upperstr_t *, mblk_t *, int, int);
-#endif /* defined(SOL2) */
-static int putctl2(queue_t *, int, int, int);
-static int putctl4(queue_t *, int, int, int);
-static int pass_packet(upperstr_t *ppa, mblk_t *mp, int outbound);
-#ifdef FILTER_PACKETS
-static int ip_hard_filter(upperstr_t *ppa, mblk_t *mp, int outbound);
-#endif /* FILTER_PACKETS */
-
-#define PPP_ID 0xb1a6
-static struct module_info ppp_info = {
-#ifdef PRIOQ
-    PPP_ID, "ppp", 0, 512, 512, 384
-#else
-    PPP_ID, "ppp", 0, 512, 512, 128
-#endif /* PRIOQ */
-};
-
-static struct qinit pppurint = {
-    pppurput, pppursrv, pppopen, pppclose, NULL, &ppp_info, NULL
-};
-
-static struct qinit pppuwint = {
-    pppuwput, pppuwsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-static struct qinit ppplrint = {
-    ppplrput, ppplrsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-static struct qinit ppplwint = {
-    ppplwput, ppplwsrv, NULL, NULL, NULL, &ppp_info, NULL
-};
-
-#ifdef LACHTCP
-extern struct ifstats *ifstats;
-int pppdevflag = 0;
-#endif
-
-struct streamtab pppinfo = {
-    &pppurint, &pppuwint,
-    &ppplrint, &ppplwint
-};
-
-int ppp_count;
-
-/*
- * How we maintain statistics.
- */
-#ifdef SOL2
-#define INCR_IPACKETS(ppa)                             \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[0].value.ul++; \
-       }
-#define INCR_IERRORS(ppa)                              \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[1].value.ul++; \
-       }
-#define INCR_OPACKETS(ppa)                             \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[2].value.ul++; \
-       }
-#define INCR_OERRORS(ppa)                              \
-       if (ppa->kstats != 0) {                         \
-           KSTAT_NAMED_PTR(ppa->kstats)[3].value.ul++; \
-       }
-#endif
-
-#ifdef LACHTCP
-#define INCR_IPACKETS(ppa)     ppa->ifstats.ifs_ipackets++;
-#define INCR_IERRORS(ppa)      ppa->ifstats.ifs_ierrors++;
-#define INCR_OPACKETS(ppa)     ppa->ifstats.ifs_opackets++;
-#define INCR_OERRORS(ppa)      ppa->ifstats.ifs_oerrors++;
-#endif
-
-/*
- * STREAMS driver entry points.
- */
-static int
-#ifdef SVR4
-pppopen(q, devp, oflag, sflag, credp)
-    queue_t *q;
-    dev_t *devp;
-    int oflag, sflag;
-    cred_t *credp;
-#else
-pppopen(q, dev, oflag, sflag)
-    queue_t *q;
-    int dev;                   /* really dev_t */
-    int oflag, sflag;
-#endif
-{
-    upperstr_t *up;
-    upperstr_t **prevp;
-    minor_t mn;
-#ifdef PRIOQ
-    u_short *ptr;
-    u_char new_band;
-#endif /* PRIOQ */
-
-    if (q->q_ptr)
-       DRV_OPEN_OK(dev);       /* device is already open */
-
-#ifdef PRIOQ
-    /* Calculate max_bband & def_band from definitions in prioq.h
-       This colud be done at some more approtiate time (less often)
-       but this way it works well so I'll just leave it here */
-
-    max_band = 1;
-    def_band = 0;
-    ptr = prioq_table;
-    while (*ptr) {
-        new_band = 1;
-        while (*ptr)
-           if (*ptr++ == IPPORT_DEFAULT) {
-               new_band = 0;
-               def_band = max_band;
-           }
-        max_band += new_band;
-        ptr++;
-    }
-    if (def_band)
-        def_band = max_band - def_band;
-    --max_band;
-#endif /* PRIOQ */
-
-    if (sflag == CLONEOPEN) {
-       mn = 0;
-       for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
-           if (up->mn != mn)
-               break;
-           ++mn;
-       }
-    } else {
-#ifdef SVR4
-       mn = getminor(*devp);
-#else
-       mn = minor(dev);
-#endif
-       for (prevp = &minor_devs; (up = *prevp) != 0; prevp = &up->nextmn) {
-           if (up->mn >= mn)
-               break;
-       }
-       if (up->mn == mn) {
-           /* this can't happen */
-           q->q_ptr = WR(q)->q_ptr = (caddr_t) up;
-           DRV_OPEN_OK(dev);
-       }
-    }
-
-    /*
-     * Construct a new minor node.
-     */
-    up = (upperstr_t *) ALLOC_SLEEP(sizeof(upperstr_t));
-    bzero((caddr_t) up, sizeof(upperstr_t));
-    if (up == 0) {
-       DPRINT("pppopen: out of kernel memory\n");
-       OPEN_ERROR(ENXIO);
-    }
-    up->nextmn = *prevp;
-    *prevp = up;
-    up->mn = mn;
-#ifdef SVR4
-    *devp = makedevice(getmajor(*devp), mn);
-#endif
-    up->q = q;
-    if (NOTSUSER() == 0)
-       up->flags |= US_PRIV;
-#ifndef NO_DLPI
-    up->state = DL_UNATTACHED;
-#endif
-#ifdef LACHTCP
-    up->ifflags = IFF_UP | IFF_POINTOPOINT;
-#endif
-    up->sap = -1;
-    up->last_sent = up->last_recv = time;
-    up->npmode = NPMODE_DROP;
-    q->q_ptr = (caddr_t) up;
-    WR(q)->q_ptr = (caddr_t) up;
-    noenable(WR(q));
-#ifdef SOL2
-    mutex_init(&up->stats_lock, NULL, MUTEX_DRIVER, NULL);
-#endif
-    ++ppp_count;
-
-    qprocson(q);
-    DRV_OPEN_OK(makedev(major(dev), mn));
-}
-
-static int
-#ifdef SVR4
-pppclose(q, flag, credp)
-    queue_t *q;
-    int flag;
-    cred_t *credp;
-#else
-pppclose(q, flag)
-    queue_t *q;
-    int flag;
-#endif
-{
-    upperstr_t *up, **upp;
-    upperstr_t *as, *asnext;
-    upperstr_t **prevp;
-
-    qprocsoff(q);
-
-    up = (upperstr_t *) q->q_ptr;
-    if (up == 0) {
-       DPRINT("pppclose: q_ptr = 0\n");
-       return 0;
-    }
-    if (up->flags & US_DBGLOG)
-       DPRINT2("ppp/%d: close, flags=%x\n", up->mn, up->flags);
-    if (up->flags & US_CONTROL) {
-#ifdef LACHTCP
-       struct ifstats *ifp, *pifp;
-#endif
-       if (up->lowerq != 0) {
-           /* Gack! the lower stream should have be unlinked earlier! */
-           DPRINT1("ppp%d: lower stream still connected on close?\n",
-                   up->mn);
-           LOCK_LOWER_W;
-           up->lowerq->q_ptr = 0;
-           RD(up->lowerq)->q_ptr = 0;
-           up->lowerq = 0;
-           UNLOCK_LOWER;
-       }
-
-       /*
-        * This stream represents a PPA:
-        * For all streams attached to the PPA, clear their
-        * references to this PPA.
-        * Then remove this PPA from the list of PPAs.
-        */
-       for (as = up->next; as != 0; as = asnext) {
-           asnext = as->next;
-           as->next = 0;
-           as->ppa = 0;
-           if (as->flags & US_BLOCKED) {
-               as->flags &= ~US_BLOCKED;
-               flushq(WR(as->q), FLUSHDATA);
-           }
-       }
-       for (upp = &ppas; *upp != 0; upp = &(*upp)->nextppa)
-           if (*upp == up) {
-               *upp = up->nextppa;
-               break;
-           }
-#ifdef LACHTCP
-       /* Remove the statistics from the active list.  */
-       for (ifp = ifstats, pifp = 0; ifp; ifp = ifp->ifs_next) {
-           if (ifp == &up->ifstats) {
-               if (pifp)
-                   pifp->ifs_next = ifp->ifs_next;
-               else
-                   ifstats = ifp->ifs_next;
-               break;
-           }
-           pifp = ifp;
-       }
-#endif
-    } else {
-       /*
-        * If this stream is attached to a PPA,
-        * remove it from the PPA's list.
-        */
-       if ((as = up->ppa) != 0) {
-           for (; as->next != 0; as = as->next)
-               if (as->next == up) {
-                   as->next = up->next;
-                   break;
-               }
-       }
-    }
-
-#ifdef SOL2
-    if (up->kstats)
-       kstat_delete(up->kstats);
-    mutex_destroy(&up->stats_lock);
-#endif
-
-    q->q_ptr = NULL;
-    WR(q)->q_ptr = NULL;
-
-    for (prevp = &minor_devs; *prevp != 0; prevp = &(*prevp)->nextmn) {
-       if (*prevp == up) {
-           *prevp = up->nextmn;
-           break;
-       }
-    }
-    FREE(up, sizeof(upperstr_t));
-    --ppp_count;
-
-    return 0;
-}
-
-/*
- * A message from on high.  We do one of three things:
- *     - qreply()
- *     - put the message on the lower write stream
- *     - queue it for our service routine
- */
-static int
-pppuwput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *ppa, *nps;
-    struct iocblk *iop;
-    struct linkblk *lb;
-#ifdef LACHTCP
-    struct ifreq *ifr;
-    int i;
-#endif
-    queue_t *lq;
-    int error, n, sap;
-    mblk_t *mq;
-    struct ppp_idle *pip;
-#ifdef PRIOQ
-    queue_t *tlq;
-#endif /* PRIOQ */
-#ifdef NO_DLPI
-    upperstr_t *os;
-#endif
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppuwput: q_ptr = 0!\n");
-       return 0;
-    }
-    if (mp == 0) {
-       DPRINT1("pppuwput/%d: mp = 0!\n", us->mn);
-       return 0;
-    }
-    if (mp->b_datap == 0) {
-       DPRINT1("pppuwput/%d: mp->b_datap = 0!\n", us->mn);
-       return 0;
-    }
-    switch (mp->b_datap->db_type) {
-#ifndef NO_DLPI
-    case M_PCPROTO:
-    case M_PROTO:
-       dlpi_request(q, mp, us);
-       break;
-#endif /* NO_DLPI */
-
-    case M_DATA:
-       if (us->flags & US_DBGLOG)
-           DPRINT3("ppp/%d: uwput M_DATA len=%d flags=%x\n",
-                   us->mn, msgdsize(mp), us->flags);
-       if (us->ppa == 0 || msgdsize(mp) > us->ppa->mtu + PPP_HDRLEN
-#ifndef NO_DLPI
-           || (us->flags & US_CONTROL) == 0
-#endif /* NO_DLPI */
-           ) {
-           DPRINT1("pppuwput: junk data len=%d\n", msgdsize(mp));
-           freemsg(mp);
-           break;
-       }
-#ifdef NO_DLPI
-       /* pass_packet frees the packet on returning 0 */
-       if ((us->flags & US_CONTROL) == 0 && !pass_packet(us, mp, 1))
-           break;
-#endif
-       if (!send_data(mp, us) && !putq(q, mp))
-           freemsg(mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       if (us->flags & US_DBGLOG)
-           DPRINT3("ppp/%d: ioctl %x count=%d\n",
-                   us->mn, iop->ioc_cmd, iop->ioc_count);
-       switch (iop->ioc_cmd) {
-#if defined(SOL2)
-       case DLIOCRAW:      /* raw M_DATA mode */
-           us->flags |= US_RAWDATA;
-           error = 0;
-           break;
-#endif /* defined(SOL2) */
-       case I_LINK:
-           if ((us->flags & US_CONTROL) == 0 || us->lowerq != 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_LINK b_cont = 0!\n", us->mn);
-               break;
-           }
-           lb = (struct linkblk *) mp->b_cont->b_rptr;
-           lq = lb->l_qbot;
-           if (lq == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_LINK l_qbot = 0!\n", us->mn);
-               break;
-           }
-           LOCK_LOWER_W;
-           us->lowerq = lq;
-           lq->q_ptr = (caddr_t) q;
-           RD(lq)->q_ptr = (caddr_t) us->q;
-           UNLOCK_LOWER;
-           iop->ioc_count = 0;
-           error = 0;
-           us->flags &= ~US_LASTMOD;
-           /* Unblock upper streams which now feed this lower stream. */
-           qenable(q);
-           /* Send useful information down to the modules which
-              are now linked below us. */
-           putctl2(lq, M_CTL, PPPCTL_UNIT, us->ppa_id);
-           putctl4(lq, M_CTL, PPPCTL_MRU, us->mru);
-           putctl4(lq, M_CTL, PPPCTL_MTU, us->mtu);
-#ifdef PRIOQ
-            /* Lower tty driver's queue hiwat/lowat from default 4096/128
-               to 256/128 since we don't want queueing of data on
-               output to physical device */
-
-            freezestr(lq);
-            for (tlq = lq; tlq->q_next != NULL; tlq = tlq->q_next)
-               ;
-            strqset(tlq, QHIWAT, 0, 256);
-            strqset(tlq, QLOWAT, 0, 128);
-            unfreezestr(lq);
-#endif /* PRIOQ */
-           break;
-
-       case I_UNLINK:
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl I_UNLINK b_cont = 0!\n", us->mn);
-               break;
-           }
-           lb = (struct linkblk *) mp->b_cont->b_rptr;
-#if DEBUG
-           if (us->lowerq != lb->l_qbot) {
-               DPRINT2("ppp unlink: lowerq=%x qbot=%x\n",
-                       us->lowerq, lb->l_qbot);
-               break;
-           }
-#endif
-           iop->ioc_count = 0;
-           qwriter(q, mp, detach_lower, PERIM_OUTER);
-           /* mp is now gone */
-           error = -1;
-           break;
-
-       case PPPIO_NEWPPA:
-           if (us->flags & US_CONTROL)
-               break;
-           if ((us->flags & US_PRIV) == 0) {
-               error = EPERM;
-               break;
-           }
-           /* Arrange to return an int */
-           if ((mq = mp->b_cont) == 0
-               || mq->b_datap->db_lim - mq->b_rptr < sizeof(int)) {
-               mq = allocb(sizeof(int), BPRI_HI);
-               if (mq == 0) {
-                   error = ENOSR;
-                   break;
-               }
-               if (mp->b_cont != 0)
-                   freemsg(mp->b_cont);
-               mp->b_cont = mq;
-               mq->b_cont = 0;
-           }
-           iop->ioc_count = sizeof(int);
-           mq->b_wptr = mq->b_rptr + sizeof(int);
-           qwriter(q, mp, new_ppa, PERIM_OUTER);
-           /* mp is now gone */
-           error = -1;
-           break;
-
-       case PPPIO_ATTACH:
-           /* like dlpi_attach, for programs which can't write to
-              the stream (like pppstats) */
-           if (iop->ioc_count != sizeof(int) || us->ppa != 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_ATTACH b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
-               if (ppa->ppa_id == n)
-                   break;
-           if (ppa == 0)
-               break;
-           us->ppa = ppa;
-           iop->ioc_count = 0;
-           qwriter(q, mp, attach_ppa, PERIM_OUTER);
-           /* mp is now gone */
-           error = -1;
-           break;
-
-#ifdef NO_DLPI
-       case PPPIO_BIND:
-           /* Attach to a given SAP. */
-           if (iop->ioc_count != sizeof(int) || us->ppa == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_BIND b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           /* n must be a valid PPP network protocol number. */
-           if (n < 0x21 || n > 0x3fff || (n & 0x101) != 1)
-               break;
-           /* check that no other stream is bound to this sap already. */
-           for (os = us->ppa; os != 0; os = os->next)
-               if (os->sap == n)
-                   break;
-           if (os != 0)
-               break;
-           us->sap = n;
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-#endif /* NO_DLPI */
-
-       case PPPIO_MRU:
-           if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_MRU b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n <= 0 || n > PPP_MAXMRU)
-               break;
-           if (n < PPP_MRU)
-               n = PPP_MRU;
-           us->mru = n;
-           if (us->lowerq)
-               putctl4(us->lowerq, M_CTL, PPPCTL_MRU, n);
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_MTU:
-           if (iop->ioc_count != sizeof(int) || (us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_MTU b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n <= 0 || n > PPP_MAXMTU)
-               break;
-           us->mtu = n;
-#ifdef LACHTCP
-           /* The MTU reported in netstat, not used as IP max packet size! */
-           us->ifstats.ifs_mtu = n;
-#endif
-           if (us->lowerq)
-               putctl4(us->lowerq, M_CTL, PPPCTL_MTU, n);
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_LASTMOD:
-           us->flags |= US_LASTMOD;
-           error = 0;
-           break;
-
-       case PPPIO_DEBUG:
-           if (iop->ioc_count != sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_DEBUG b_cont = 0!\n", us->mn);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n == PPPDBG_DUMP + PPPDBG_DRIVER) {
-               qwriter(q, mp, debug_dump, PERIM_OUTER);
-               /* mp is now gone */
-               error = -1;
-           } else if (n == PPPDBG_LOG + PPPDBG_DRIVER) {
-               DPRINT1("ppp/%d: debug log enabled\n", us->mn);
-               us->flags |= US_DBGLOG;
-               iop->ioc_count = 0;
-               error = 0;
-           } else {
-               if (us->ppa == 0 || us->ppa->lowerq == 0)
-                   break;
-               putnext(us->ppa->lowerq, mp);
-               /* mp is now gone */
-               error = -1;
-           }
-           break;
-
-       case PPPIO_NPMODE:
-           if (iop->ioc_count != 2 * sizeof(int))
-               break;
-           if ((us->flags & US_CONTROL) == 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("pppuwput/%d: ioctl PPPIO_NPMODE b_cont = 0!\n", us->mn);
-               break;
-           }
-           sap = ((int *)mp->b_cont->b_rptr)[0];
-           for (nps = us->next; nps != 0; nps = nps->next) {
-               if (us->flags & US_DBGLOG)
-                   DPRINT2("us = 0x%x, us->next->sap = 0x%x\n", nps, nps->sap);
-               if (nps->sap == sap)
-                   break;
-           }
-           if (nps == 0) {
-               if (us->flags & US_DBGLOG)
-                   DPRINT2("ppp/%d: no stream for sap %x\n", us->mn, sap);
-               break;
-           }
-           /* XXX possibly should use qwriter here */
-           nps->npmode = (enum NPmode) ((int *)mp->b_cont->b_rptr)[1];
-           if (nps->npmode != NPMODE_QUEUE && (nps->flags & US_BLOCKED) != 0)
-               qenable(WR(nps->q));
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_GIDLE:
-           if ((ppa = us->ppa) == 0)
-               break;
-           mq = allocb(sizeof(struct ppp_idle), BPRI_HI);
-           if (mq == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = mq;
-           mq->b_cont = 0;
-           pip = (struct ppp_idle *) mq->b_wptr;
-           pip->xmit_idle = time - ppa->last_sent;
-           pip->recv_idle = time - ppa->last_recv;
-           mq->b_wptr += sizeof(struct ppp_idle);
-           iop->ioc_count = sizeof(struct ppp_idle);
-           error = 0;
-           break;
-
-#ifdef LACHTCP
-       case SIOCSIFNAME:
-           /* Sent from IP down to us.  Attach the ifstats structure.  */
-           if (iop->ioc_count != sizeof(struct ifreq) || us->ppa == 0)
-               break;
-           ifr = (struct ifreq *)mp->b_cont->b_rptr;
-           /* Find the unit number in the interface name.  */
-           for (i = 0; i < IFNAMSIZ; i++) {
-               if (ifr->ifr_name[i] == 0 ||
-                   (ifr->ifr_name[i] >= '0' &&
-                    ifr->ifr_name[i] <= '9'))
-                   break;
-               else
-                   us->ifname[i] = ifr->ifr_name[i];
-           }
-           us->ifname[i] = 0;
-
-           /* Convert the unit number to binary.  */
-           for (n = 0; i < IFNAMSIZ; i++) {
-               if (ifr->ifr_name[i] == 0) {
-                   break;
-               }
-               else {
-                   n = n * 10 + ifr->ifr_name[i] - '0';
-               }
-           }
-
-           /* Verify the ppa.  */
-           if (us->ppa->ppa_id != n)
-               break;
-           ppa = us->ppa;
-
-           /* Set up the netstat block.  */
-           strncpy (ppa->ifname, us->ifname, IFNAMSIZ);
-
-           ppa->ifstats.ifs_name = ppa->ifname;
-           ppa->ifstats.ifs_unit = n;
-           ppa->ifstats.ifs_active = us->state != DL_UNBOUND;
-           ppa->ifstats.ifs_mtu = ppa->mtu;
-
-           /* Link in statistics used by netstat.  */
-           ppa->ifstats.ifs_next = ifstats;
-           ifstats = &ppa->ifstats;
-
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case SIOCGIFFLAGS:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           ((struct iocblk_in *)iop)->ioc_ifflags = us->ifflags;
-           error = 0;
-           break;
-
-       case SIOCSIFFLAGS:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           us->ifflags = ((struct iocblk_in *)iop)->ioc_ifflags;
-           error = 0;
-           break;
-
-       case SIOCSIFADDR:
-           if (!(us->flags & US_CONTROL)) {
-               if (us->ppa)
-                   us = us->ppa;
-               else
-                   break;
-           }
-           us->ifflags |= IFF_RUNNING;
-           ((struct iocblk_in *)iop)->ioc_ifflags |= IFF_RUNNING;
-           error = 0;
-           break;
-
-       case SIOCSIFMTU:
-           /*
-            * Vanilla SVR4 systems don't handle SIOCSIFMTU, rather
-            * they take the MTU from the DL_INFO_ACK we sent in response
-            * to their DL_INFO_REQ.  Fortunately, they will update the
-            * MTU if we send an unsolicited DL_INFO_ACK up.
-            */
-           if ((mq = allocb(sizeof(dl_info_req_t), BPRI_HI)) == 0)
-               break;          /* should do bufcall */
-           ((union DL_primitives *)mq->b_rptr)->dl_primitive = DL_INFO_REQ;
-           mq->b_wptr = mq->b_rptr + sizeof(dl_info_req_t);
-           dlpi_request(q, mq, us);
-           /* mp is now gone */
-           error = -1;
-           break;
-
-       case SIOCGIFNETMASK:
-       case SIOCSIFNETMASK:
-       case SIOCGIFADDR:
-       case SIOCGIFDSTADDR:
-       case SIOCSIFDSTADDR:
-       case SIOCGIFMETRIC:
-           error = 0;
-           break;
-#endif /* LACHTCP */
-
-       default:
-           if (us->ppa == 0 || us->ppa->lowerq == 0)
-               break;
-           us->ioc_id = iop->ioc_id;
-           error = -1;
-           switch (iop->ioc_cmd) {
-           case PPPIO_GETSTAT:
-           case PPPIO_GETCSTAT:
-               if (us->flags & US_LASTMOD) {
-                   error = EINVAL;
-                   break;
-               }
-               putnext(us->ppa->lowerq, mp);
-               break;
-           default:
-               if (us->flags & US_PRIV)
-                   putnext(us->ppa->lowerq, mp);
-               else {
-                   DPRINT1("ppp ioctl %x rejected\n", iop->ioc_cmd);
-                   error = EPERM;
-               }
-               break;
-           }
-           break;
-       }
-
-       if (error > 0) {
-           iop->ioc_error = error;
-           mp->b_datap->db_type = M_IOCNAK;
-           qreply(q, mp);
-       } else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_FLUSH:
-       if (us->flags & US_DBGLOG)
-           DPRINT2("ppp/%d: flush %x\n", us->mn, *mp->b_rptr);
-       if (*mp->b_rptr & FLUSHW)
-           flushq(q, FLUSHDATA);
-       if (*mp->b_rptr & FLUSHR) {
-           *mp->b_rptr &= ~FLUSHW;
-           qreply(q, mp);
-       } else
-           freemsg(mp);
-       break;
-
-    default:
-       freemsg(mp);
-       break;
-    }
-    return 0;
-}
-
-#ifndef NO_DLPI
-static void
-dlpi_request(q, mp, us)
-    queue_t *q;
-    mblk_t *mp;
-    upperstr_t *us;
-{
-    union DL_primitives *d = (union DL_primitives *) mp->b_rptr;
-    int size = mp->b_wptr - mp->b_rptr;
-    mblk_t *reply, *np;
-    upperstr_t *ppa, *os;
-    int sap, len;
-    dl_info_ack_t *info;
-    dl_bind_ack_t *ackp;
-#if DL_CURRENT_VERSION >= 2
-    dl_phys_addr_ack_t *paddrack;
-    static struct ether_addr eaddr = {0};
-#endif
-
-    if (us->flags & US_DBGLOG)
-       DPRINT3("ppp/%d: dlpi prim %x len=%d\n", us->mn,
-               d->dl_primitive, size);
-    switch (d->dl_primitive) {
-    case DL_INFO_REQ:
-       if (size < sizeof(dl_info_req_t))
-           goto badprim;
-       if ((reply = allocb(sizeof(dl_info_ack_t), BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       reply->b_datap->db_type = M_PCPROTO;
-       info = (dl_info_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_info_ack_t);
-       bzero((caddr_t) info, sizeof(dl_info_ack_t));
-       info->dl_primitive = DL_INFO_ACK;
-       info->dl_max_sdu = us->ppa? us->ppa->mtu: PPP_MAXMTU;
-       info->dl_min_sdu = 1;
-       info->dl_addr_length = sizeof(uint);
-       info->dl_mac_type = DL_ETHER;   /* a bigger lie */
-       info->dl_current_state = us->state;
-       info->dl_service_mode = DL_CLDLS;
-       info->dl_provider_style = DL_STYLE2;
-#if DL_CURRENT_VERSION >= 2
-       info->dl_sap_length = sizeof(uint);
-       info->dl_version = DL_CURRENT_VERSION;
-#endif
-       qreply(q, reply);
-       break;
-
-    case DL_ATTACH_REQ:
-       if (size < sizeof(dl_attach_req_t))
-           goto badprim;
-       if (us->state != DL_UNATTACHED || us->ppa != 0) {
-           dlpi_error(q, us, DL_ATTACH_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       for (ppa = ppas; ppa != 0; ppa = ppa->nextppa)
-           if (ppa->ppa_id == d->attach_req.dl_ppa)
-               break;
-       if (ppa == 0) {
-           dlpi_error(q, us, DL_ATTACH_REQ, DL_BADPPA, 0);
-           break;
-       }
-       us->ppa = ppa;
-       qwriter(q, mp, attach_ppa, PERIM_OUTER);
-       return;
-
-    case DL_DETACH_REQ:
-       if (size < sizeof(dl_detach_req_t))
-           goto badprim;
-       if (us->state != DL_UNBOUND || us->ppa == 0) {
-           dlpi_error(q, us, DL_DETACH_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       qwriter(q, mp, detach_ppa, PERIM_OUTER);
-       return;
-
-    case DL_BIND_REQ:
-       if (size < sizeof(dl_bind_req_t))
-           goto badprim;
-       if (us->state != DL_UNBOUND || us->ppa == 0) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-#if 0
-       /* apparently this test fails (unnecessarily?) on some systems */
-       if (d->bind_req.dl_service_mode != DL_CLDLS) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_UNSUPPORTED, 0);
-           break;
-       }
-#endif
-
-       /* saps must be valid PPP network protocol numbers,
-          except that we accept ETHERTYPE_IP in place of PPP_IP. */
-       sap = d->bind_req.dl_sap;
-       us->req_sap = sap;
-
-#if defined(SOL2)
-       if (us->flags & US_DBGLOG)
-           DPRINT2("DL_BIND_REQ: ip gives sap = 0x%x, us = 0x%x", sap, us);
-
-       if (sap == ETHERTYPE_IP)            /* normal IFF_IPV4 */
-           sap = PPP_IP;
-       else if (sap == ETHERTYPE_IPV6)     /* when IFF_IPV6 is set */
-           sap = PPP_IPV6;
-       else if (sap == ETHERTYPE_ALLSAP)   /* snoop gives sap of 0 */
-           sap = PPP_ALLSAP;
-       else {
-           DPRINT2("DL_BIND_REQ: unrecognized sap = 0x%x, us = 0x%x", sap, us);
-           dlpi_error(q, us, DL_BIND_REQ, DL_BADADDR, 0);
-           break;
-       }
-#else
-       if (sap == ETHERTYPE_IP)
-           sap = PPP_IP;
-       if (sap < 0x21 || sap > 0x3fff || (sap & 0x101) != 1) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_BADADDR, 0);
-           break;
-       }
-#endif /* defined(SOL2) */
-
-       /* check that no other stream is bound to this sap already. */
-       for (os = us->ppa; os != 0; os = os->next)
-           if (os->sap == sap)
-               break;
-       if (os != 0) {
-           dlpi_error(q, us, DL_BIND_REQ, DL_NOADDR, 0);
-           break;
-       }
-
-       us->sap = sap;
-       us->state = DL_IDLE;
-
-       if ((reply = allocb(sizeof(dl_bind_ack_t) + sizeof(uint),
-                           BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       ackp = (dl_bind_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_bind_ack_t) + sizeof(uint);
-       reply->b_datap->db_type = M_PCPROTO;
-       bzero((caddr_t) ackp, sizeof(dl_bind_ack_t));
-       ackp->dl_primitive = DL_BIND_ACK;
-       ackp->dl_sap = sap;
-       ackp->dl_addr_length = sizeof(uint);
-       ackp->dl_addr_offset = sizeof(dl_bind_ack_t);
-       *(uint *)(ackp+1) = sap;
-       qreply(q, reply);
-       break;
-
-    case DL_UNBIND_REQ:
-       if (size < sizeof(dl_unbind_req_t))
-           goto badprim;
-       if (us->state != DL_IDLE) {
-           dlpi_error(q, us, DL_UNBIND_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       us->sap = -1;
-       us->state = DL_UNBOUND;
-#ifdef LACHTCP
-       us->ppa->ifstats.ifs_active = 0;
-#endif
-       dlpi_ok(q, DL_UNBIND_REQ);
-       break;
-
-    case DL_UNITDATA_REQ:
-       if (size < sizeof(dl_unitdata_req_t))
-           goto badprim;
-       if (us->state != DL_IDLE) {
-           dlpi_error(q, us, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
-           break;
-       }
-       if ((ppa = us->ppa) == 0) {
-           cmn_err(CE_CONT, "ppp: in state dl_idle but ppa == 0?\n");
-           break;
-       }
-       len = mp->b_cont == 0? 0: msgdsize(mp->b_cont);
-       if (len > ppa->mtu) {
-           DPRINT2("dlpi data too large (%d > %d)\n", len, ppa->mtu);
-           break;
-       }
-
-#if defined(SOL2)
-       /*
-        * Should there be any promiscuous stream(s), send the data
-        * up for each promiscuous stream that we recognize.
-        */
-       if (mp->b_cont)
-           promisc_sendup(ppa, mp->b_cont, us->sap, 0);
-#endif /* defined(SOL2) */
-
-       mp->b_band = 0;
-#ifdef PRIOQ
-        /* Extract s_port & d_port from IP-packet, the code is a bit
-           dirty here, but so am I, too... */
-        if (mp->b_datap->db_type == M_PROTO && us->sap == PPP_IP
-           && mp->b_cont != 0) {
-           u_char *bb, *tlh;
-           int iphlen, len;
-           u_short *ptr;
-           u_char band_unset, cur_band, syn;
-           u_short s_port, d_port;
-
-            bb = mp->b_cont->b_rptr; /* bb points to IP-header*/
-           len = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
-            syn = 0;
-           s_port = IPPORT_DEFAULT;
-           d_port = IPPORT_DEFAULT;
-           if (len >= 20) {    /* 20 = minimum length of IP header */
-               iphlen = (bb[0] & 0x0f) * 4;
-               tlh = bb + iphlen;
-               len -= iphlen;
-               switch (bb[9]) {
-               case IPPROTO_TCP:
-                   if (len >= 20) {          /* min length of TCP header */
-                       s_port = (tlh[0] << 8) + tlh[1];
-                       d_port = (tlh[2] << 8) + tlh[3];
-                       syn = tlh[13] & 0x02;
-                   }
-                   break;
-               case IPPROTO_UDP:
-                   if (len >= 8) {           /* min length of UDP header */
-                       s_port = (tlh[0] << 8) + tlh[1];
-                       d_port = (tlh[2] << 8) + tlh[3];
-                   }
-                   break;
-               }
-           }
-
-            /*
-            * Now calculate b_band for this packet from the
-            * port-priority table.
-            */
-            ptr = prioq_table;
-            cur_band = max_band;
-            band_unset = 1;
-            while (*ptr) {
-                while (*ptr && band_unset)
-                    if (s_port == *ptr || d_port == *ptr++) {
-                        mp->b_band = cur_band;
-                        band_unset = 0;
-                        break;
-                   }
-                ptr++;
-                cur_band--;
-           }
-            if (band_unset)
-               mp->b_band = def_band;
-            /* It may be usable to urge SYN packets a bit */
-            if (syn)
-               mp->b_band++;
-       }
-#endif /* PRIOQ */
-       /* this assumes PPP_HDRLEN <= sizeof(dl_unitdata_req_t) */
-       if (mp->b_datap->db_ref > 1) {
-           np = allocb(PPP_HDRLEN, BPRI_HI);
-           if (np == 0)
-               break;          /* gak! */
-           np->b_cont = mp->b_cont;
-           mp->b_cont = 0;
-           freeb(mp);
-           mp = np;
-       } else
-           mp->b_datap->db_type = M_DATA;
-       /* XXX should use dl_dest_addr_offset/length here,
-          but we would have to translate ETHERTYPE_IP -> PPP_IP */
-       mp->b_wptr = mp->b_rptr + PPP_HDRLEN;
-       mp->b_rptr[0] = PPP_ALLSTATIONS;
-       mp->b_rptr[1] = PPP_UI;
-       mp->b_rptr[2] = us->sap >> 8;
-       mp->b_rptr[3] = us->sap;
-       /* pass_packet frees the packet on returning 0 */
-       if (pass_packet(us, mp, 1)) {
-           if (!send_data(mp, us) && !putq(q, mp))
-               freemsg(mp);
-       }
-       return;
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_PHYS_ADDR_REQ:
-       if (size < sizeof(dl_phys_addr_req_t))
-           goto badprim;
-
-       /*
-        * Don't check state because ifconfig sends this one down too
-        */
-
-       if ((reply = allocb(sizeof(dl_phys_addr_ack_t)+ETHERADDRL, 
-                       BPRI_HI)) == 0)
-           break;              /* should do bufcall */
-       reply->b_datap->db_type = M_PCPROTO;
-       paddrack = (dl_phys_addr_ack_t *) reply->b_wptr;
-       reply->b_wptr += sizeof(dl_phys_addr_ack_t);
-       bzero((caddr_t) paddrack, sizeof(dl_phys_addr_ack_t)+ETHERADDRL);
-       paddrack->dl_primitive = DL_PHYS_ADDR_ACK;
-       paddrack->dl_addr_length = ETHERADDRL;
-       paddrack->dl_addr_offset = sizeof(dl_phys_addr_ack_t);
-       bcopy(&eaddr, reply->b_wptr, ETHERADDRL);
-       reply->b_wptr += ETHERADDRL;
-       qreply(q, reply);
-       break;
-
-#if defined(SOL2)
-    case DL_PROMISCON_REQ:
-       if (size < sizeof(dl_promiscon_req_t))
-           goto badprim;
-       us->flags |= US_PROMISC;
-       dlpi_ok(q, DL_PROMISCON_REQ);
-       break;
-
-    case DL_PROMISCOFF_REQ:
-       if (size < sizeof(dl_promiscoff_req_t))
-           goto badprim;
-       us->flags &= ~US_PROMISC;
-       dlpi_ok(q, DL_PROMISCOFF_REQ);
-       break;
-#else
-    case DL_PROMISCON_REQ:         /* fall thru */
-    case DL_PROMISCOFF_REQ:        /* fall thru */
-#endif /* defined(SOL2) */
-#endif /* DL_CURRENT_VERSION >= 2 */
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_SET_PHYS_ADDR_REQ:
-    case DL_SUBS_BIND_REQ:
-    case DL_SUBS_UNBIND_REQ:
-    case DL_ENABMULTI_REQ:
-    case DL_DISABMULTI_REQ:
-    case DL_XID_REQ:
-    case DL_TEST_REQ:
-    case DL_REPLY_UPDATE_REQ:
-    case DL_REPLY_REQ:
-    case DL_DATA_ACK_REQ:
-#endif
-    case DL_CONNECT_REQ:
-    case DL_TOKEN_REQ:
-       dlpi_error(q, us, d->dl_primitive, DL_NOTSUPPORTED, 0);
-       break;
-
-    case DL_CONNECT_RES:
-    case DL_DISCONNECT_REQ:
-    case DL_RESET_REQ:
-    case DL_RESET_RES:
-       dlpi_error(q, us, d->dl_primitive, DL_OUTSTATE, 0);
-       break;
-
-    case DL_UDQOS_REQ:
-       dlpi_error(q, us, d->dl_primitive, DL_BADQOSTYPE, 0);
-       break;
-
-#if DL_CURRENT_VERSION >= 2
-    case DL_TEST_RES:
-    case DL_XID_RES:
-       break;
-#endif
-
-    default:
-       if (us->flags & US_DBGLOG)
-           DPRINT1("ppp: unknown dlpi prim 0x%x\n", d->dl_primitive);
-       /* fall through */
-    badprim:
-       dlpi_error(q, us, d->dl_primitive, DL_BADPRIM, 0);
-       break;
-    }
-    freemsg(mp);
-}
-
-static void
-dlpi_error(q, us, prim, err, uerr)
-    queue_t *q;
-    upperstr_t *us;
-    int prim, err, uerr;
-{
-    mblk_t *reply;
-    dl_error_ack_t *errp;
-
-    if (us->flags & US_DBGLOG)
-        DPRINT3("ppp/%d: dlpi error, prim=%x, err=%x\n", us->mn, prim, err);
-    reply = allocb(sizeof(dl_error_ack_t), BPRI_HI);
-    if (reply == 0)
-       return;                 /* XXX should do bufcall */
-    reply->b_datap->db_type = M_PCPROTO;
-    errp = (dl_error_ack_t *) reply->b_wptr;
-    reply->b_wptr += sizeof(dl_error_ack_t);
-    errp->dl_primitive = DL_ERROR_ACK;
-    errp->dl_error_primitive = prim;
-    errp->dl_errno = err;
-    errp->dl_unix_errno = uerr;
-    qreply(q, reply);
-}
-
-static void
-dlpi_ok(q, prim)
-    queue_t *q;
-    int prim;
-{
-    mblk_t *reply;
-    dl_ok_ack_t *okp;
-
-    reply = allocb(sizeof(dl_ok_ack_t), BPRI_HI);
-    if (reply == 0)
-       return;                 /* XXX should do bufcall */
-    reply->b_datap->db_type = M_PCPROTO;
-    okp = (dl_ok_ack_t *) reply->b_wptr;
-    reply->b_wptr += sizeof(dl_ok_ack_t);
-    okp->dl_primitive = DL_OK_ACK;
-    okp->dl_correct_primitive = prim;
-    qreply(q, reply);
-}
-#endif /* NO_DLPI */
-
-/*
- * If return value is 0, then the packet has already been freed.
- */
-static int
-pass_packet(us, mp, outbound)
-    upperstr_t *us;
-    mblk_t *mp;
-    int outbound;
-{
-    int pass;
-    upperstr_t *ppa;
-
-    if ((ppa = us->ppa) == 0) {
-       freemsg(mp);
-       return 0;
-    }
-
-#ifdef FILTER_PACKETS
-    pass = ip_hard_filter(us, mp, outbound);
-#else
-    /*
-     * Here is where we might, in future, decide whether to pass
-     * or drop the packet, and whether it counts as link activity.
-     */
-    pass = 1;
-#endif /* FILTER_PACKETS */
-
-    if (pass < 0) {
-       /* pass only if link already up, and don't update time */
-       if (ppa->lowerq == 0) {
-           freemsg(mp);
-           return 0;
-       }
-       pass = 1;
-    } else if (pass) {
-       if (outbound)
-           ppa->last_sent = time;
-       else
-           ppa->last_recv = time;
-    }
-
-    return pass;
-}
-
-/*
- * We have some data to send down to the lower stream (or up the
- * control stream, if we don't have a lower stream attached).
- * Returns 1 if the message was dealt with, 0 if it wasn't able
- * to be sent on and should therefore be queued up.
- */
-static int
-send_data(mp, us)
-    mblk_t *mp;
-    upperstr_t *us;
-{
-    upperstr_t *ppa;
-
-    if ((us->flags & US_BLOCKED) || us->npmode == NPMODE_QUEUE)
-       return 0;
-    ppa = us->ppa;
-    if (ppa == 0 || us->npmode == NPMODE_DROP || us->npmode == NPMODE_ERROR) {
-       if (us->flags & US_DBGLOG)
-           DPRINT2("ppp/%d: dropping pkt (npmode=%d)\n", us->mn, us->npmode);
-       freemsg(mp);
-       return 1;
-    }
-    if (ppa->lowerq == 0) {
-       /* try to send it up the control stream */
-        if (bcanputnext(ppa->q, mp->b_band)) {
-           /*
-            * The message seems to get corrupted for some reason if
-            * we just send the message up as it is, so we send a copy.
-            */
-           mblk_t *np = copymsg(mp);
-           freemsg(mp);
-           if (np != 0)
-               putnext(ppa->q, np);
-           return 1;
-       }
-    } else {
-        if (bcanputnext(ppa->lowerq, mp->b_band)) {
-           MT_ENTER(&ppa->stats_lock);
-           ppa->stats.ppp_opackets++;
-           ppa->stats.ppp_obytes += msgdsize(mp);
-#ifdef INCR_OPACKETS
-           INCR_OPACKETS(ppa);
-#endif
-           MT_EXIT(&ppa->stats_lock);
-           /*
-            * The lower queue is only ever detached while holding an
-            * exclusive lock on the whole driver.  So we can be confident
-            * that the lower queue is still there.
-            */
-           putnext(ppa->lowerq, mp);
-           return 1;
-       }
-    }
-    us->flags |= US_BLOCKED;
-    return 0;
-}
-
-/*
- * Allocate a new PPA id and link this stream into the list of PPAs.
- * This procedure is called with an exclusive lock on all queues in
- * this driver.
- */
-static void
-new_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *up, **usp;
-    int ppa_id;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("new_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-    usp = &ppas;
-    ppa_id = 0;
-    while ((up = *usp) != 0 && ppa_id == up->ppa_id) {
-       ++ppa_id;
-       usp = &up->nextppa;
-    }
-    us->ppa_id = ppa_id;
-    us->ppa = us;
-    us->next = 0;
-    us->nextppa = *usp;
-    *usp = us;
-    us->flags |= US_CONTROL;
-    us->npmode = NPMODE_PASS;
-
-    us->mtu = PPP_MTU;
-    us->mru = PPP_MRU;
-
-#ifdef SOL2
-    /*
-     * Create a kstats record for our statistics, so netstat -i works.
-     */
-    if (us->kstats == 0) {
-       char unit[32];
-
-       sprintf(unit, "ppp%d", us->ppa->ppa_id);
-       us->kstats = kstat_create("ppp", us->ppa->ppa_id, unit,
-                                 "net", KSTAT_TYPE_NAMED, 4, 0);
-       if (us->kstats != 0) {
-           kstat_named_t *kn = KSTAT_NAMED_PTR(us->kstats);
-
-           strcpy(kn[0].name, "ipackets");
-           kn[0].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[1].name, "ierrors");
-           kn[1].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[2].name, "opackets");
-           kn[2].data_type = KSTAT_DATA_ULONG;
-           strcpy(kn[3].name, "oerrors");
-           kn[3].data_type = KSTAT_DATA_ULONG;
-           kstat_install(us->kstats);
-       }
-    }
-#endif /* SOL2 */
-
-    *(int *)mp->b_cont->b_rptr = ppa_id;
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-static void
-attach_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *t;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("attach_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-#ifndef NO_DLPI
-    us->state = DL_UNBOUND;
-#endif
-    for (t = us->ppa; t->next != 0; t = t->next)
-       ;
-    t->next = us;
-    us->next = 0;
-    if (mp->b_datap->db_type == M_IOCTL) {
-       mp->b_datap->db_type = M_IOCACK;
-       qreply(q, mp);
-    } else {
-#ifndef NO_DLPI
-       dlpi_ok(q, DL_ATTACH_REQ);
-#endif
-       freemsg(mp);
-    }
-}
-
-#ifndef NO_DLPI
-static void
-detach_ppa(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us, *t;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("detach_ppa: q_ptr = 0!\n");
-       return;
-    }
-
-    for (t = us->ppa; t->next != 0; t = t->next)
-       if (t->next == us) {
-           t->next = us->next;
-           break;
-       }
-    us->next = 0;
-    us->ppa = 0;
-    us->state = DL_UNATTACHED;
-    dlpi_ok(q, DL_DETACH_REQ);
-    freemsg(mp);
-}
-#endif
-
-/*
- * We call this with qwriter in order to give the upper queue procedures
- * the guarantee that the lower queue is not going to go away while
- * they are executing.
- */
-static void
-detach_lower(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("detach_lower: q_ptr = 0!\n");
-       return;
-    }
-
-    LOCK_LOWER_W;
-    us->lowerq->q_ptr = 0;
-    RD(us->lowerq)->q_ptr = 0;
-    us->lowerq = 0;
-    UNLOCK_LOWER;
-
-    /* Unblock streams which now feed back up the control stream. */
-    qenable(us->q);
-
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-static int
-pppuwsrv(q)
-    queue_t *q;
-{
-    upperstr_t *us, *as;
-    mblk_t *mp;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppuwsrv: q_ptr = 0!\n");
-       return 0;
-    }
-
-    /*
-     * If this is a control stream, then this service procedure
-     * probably got enabled because of flow control in the lower
-     * stream being enabled (or because of the lower stream going
-     * away).  Therefore we enable the service procedure of all
-     * attached upper streams.
-     */
-    if (us->flags & US_CONTROL) {
-       for (as = us->next; as != 0; as = as->next)
-           qenable(WR(as->q));
-    }
-
-    /* Try to send on any data queued here. */
-    us->flags &= ~US_BLOCKED;
-    while ((mp = getq(q)) != 0) {
-       if (!send_data(mp, us)) {
-           putbq(q, mp);
-           break;
-       }
-    }
-
-    return 0;
-}
-
-/* should never get called... */
-static int
-ppplwput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    putnext(q, mp);
-    return 0;
-}
-
-static int
-ppplwsrv(q)
-    queue_t *q;
-{
-    queue_t *uq;
-
-    /*
-     * Flow control has back-enabled this stream:
-     * enable the upper write service procedure for
-     * the upper control stream for this lower stream.
-     */
-    LOCK_LOWER_R;
-    uq = (queue_t *) q->q_ptr;
-    if (uq != 0)
-       qenable(uq);
-    UNLOCK_LOWER;
-    return 0;
-}
-
-/*
- * This should only get called for control streams.
- */
-static int
-pppurput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *ppa, *us;
-    int proto, len;
-    struct iocblk *iop;
-
-    ppa = (upperstr_t *) q->q_ptr;
-    if (ppa == 0) {
-       DPRINT("pppurput: q_ptr = 0!\n");
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_CTL:
-       MT_ENTER(&ppa->stats_lock);
-       switch (*mp->b_rptr) {
-       case PPPCTL_IERROR:
-#ifdef INCR_IERRORS
-           INCR_IERRORS(ppa);
-#endif
-           ppa->stats.ppp_ierrors++;
-           break;
-       case PPPCTL_OERROR:
-#ifdef INCR_OERRORS
-           INCR_OERRORS(ppa);
-#endif
-           ppa->stats.ppp_oerrors++;
-           break;
-       }
-       MT_EXIT(&ppa->stats_lock);
-       freemsg(mp);
-       break;
-
-    case M_IOCACK:
-    case M_IOCNAK:
-       /*
-        * Attempt to match up the response with the stream
-        * that the request came from.
-        */
-       iop = (struct iocblk *) mp->b_rptr;
-       for (us = ppa; us != 0; us = us->next)
-           if (us->ioc_id == iop->ioc_id)
-               break;
-       if (us == 0)
-           freemsg(mp);
-       else
-           putnext(us->q, mp);
-       break;
-
-    case M_HANGUP:
-       /*
-        * The serial device has hung up.  We don't want to send
-        * the M_HANGUP message up to pppd because that will stop
-        * us from using the control stream any more.  Instead we
-        * send a zero-length message as an end-of-file indication.
-        */
-       freemsg(mp);
-       mp = allocb(1, BPRI_HI);
-       if (mp == 0) {
-           DPRINT1("ppp/%d: couldn't allocate eof message!\n", ppa->mn);
-           break;
-       }
-       putnext(ppa->q, mp);
-       break;
-
-    case M_DATA:
-       len = msgdsize(mp);
-       if (mp->b_wptr - mp->b_rptr < PPP_HDRLEN) {
-           PULLUP(mp, PPP_HDRLEN);
-           if (mp == 0) {
-               DPRINT1("ppp_urput: msgpullup failed (len=%d)\n", len);
-               break;
-           }
-       }
-       MT_ENTER(&ppa->stats_lock);
-       ppa->stats.ppp_ipackets++;
-       ppa->stats.ppp_ibytes += len;
-#ifdef INCR_IPACKETS
-       INCR_IPACKETS(ppa);
-#endif
-       MT_EXIT(&ppa->stats_lock);
-
-       proto = PPP_PROTOCOL(mp->b_rptr);
-
-#if defined(SOL2)
-       /*
-        * Should there be any promiscuous stream(s), send the data
-        * up for each promiscuous stream that we recognize.
-        */
-       promisc_sendup(ppa, mp, proto, 1);
-#endif /* defined(SOL2) */
-
-       if (proto < 0x8000 && (us = find_dest(ppa, proto)) != 0) {
-           /*
-            * A data packet for some network protocol.
-            * Queue it on the upper stream for that protocol.
-            * XXX could we just putnext it?  (would require thought)
-            * The rblocked flag is there to ensure that we keep
-            * messages in order for each network protocol.
-            */
-           /* pass_packet frees the packet on returning 0 */
-           if (!pass_packet(us, mp, 0))
-               break;
-           if (!us->rblocked && !canput(us->q))
-               us->rblocked = 1;
-           if (!putq(us->rblocked ? q : us->q, mp))
-               freemsg(mp);
-           break;
-       }
-
-       /* FALLTHROUGH */
-
-   default:
-       /*
-        * A control frame, a frame for an unknown protocol,
-        * or some other message type.
-        * Send it up to pppd via the control stream.
-        */
-       if (queclass(mp) == QPCTL || canputnext(ppa->q))
-           putnext(ppa->q, mp);
-       else if (!putq(q, mp))
-           freemsg(mp);
-       break;
-    }
-
-    return 0;
-}
-
-static int
-pppursrv(q)
-    queue_t *q;
-{
-    upperstr_t *us, *as;
-    mblk_t *mp, *hdr;
-#ifndef NO_DLPI
-    dl_unitdata_ind_t *ud;
-#endif
-    int proto;
-
-    us = (upperstr_t *) q->q_ptr;
-    if (us == 0) {
-       DPRINT("pppursrv: q_ptr = 0!\n");
-       return 0;
-    }
-
-    if (us->flags & US_CONTROL) {
-       /*
-        * A control stream.
-        * If there is no lower queue attached, run the write service
-        * routines of other upper streams attached to this PPA.
-        */
-       if (us->lowerq == 0) {
-           as = us;
-           do {
-               if (as->flags & US_BLOCKED)
-                   qenable(WR(as->q));
-               as = as->next;
-           } while (as != 0);
-       }
-
-       /*
-        * Messages get queued on this stream's read queue if they
-        * can't be queued on the read queue of the attached stream
-        * that they are destined for.  This is for flow control -
-        * when this queue fills up, the lower read put procedure will
-        * queue messages there and the flow control will propagate
-        * down from there.
-        */
-       while ((mp = getq(q)) != 0) {
-           proto = PPP_PROTOCOL(mp->b_rptr);
-           if (proto < 0x8000 && (as = find_dest(us, proto)) != 0) {
-               if (!canput(as->q))
-                   break;
-               if (!putq(as->q, mp))
-                   freemsg(mp);
-           } else {
-               if (!canputnext(q))
-                   break;
-               putnext(q, mp);
-           }
-       }
-       if (mp) {
-           putbq(q, mp);
-       } else {
-           /* can now put stuff directly on network protocol streams again */
-           for (as = us->next; as != 0; as = as->next)
-               as->rblocked = 0;
-       }
-
-       /*
-        * If this stream has a lower stream attached,
-        * enable the read queue's service routine.
-        * XXX we should really only do this if the queue length
-        * has dropped below the low-water mark.
-        */
-       if (us->lowerq != 0)
-           qenable(RD(us->lowerq));
-               
-    } else {
-       /*
-        * A network protocol stream.  Put a DLPI header on each
-        * packet and send it on.
-        * (Actually, it seems that the IP module will happily
-        * accept M_DATA messages without the DL_UNITDATA_IND header.)
-        */
-       while ((mp = getq(q)) != 0) {
-           if (!canputnext(q)) {
-               putbq(q, mp);
-               break;
-           }
-#ifndef NO_DLPI
-           proto = PPP_PROTOCOL(mp->b_rptr);
-           mp->b_rptr += PPP_HDRLEN;
-           hdr = allocb(sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint),
-                        BPRI_MED);
-           if (hdr == 0) {
-               /* XXX should put it back and use bufcall */
-               freemsg(mp);
-               continue;
-           }
-           hdr->b_datap->db_type = M_PROTO;
-           ud = (dl_unitdata_ind_t *) hdr->b_wptr;
-           hdr->b_wptr += sizeof(dl_unitdata_ind_t) + 2 * sizeof(uint);
-           hdr->b_cont = mp;
-           ud->dl_primitive = DL_UNITDATA_IND;
-           ud->dl_dest_addr_length = sizeof(uint);
-           ud->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
-           ud->dl_src_addr_length = sizeof(uint);
-           ud->dl_src_addr_offset = ud->dl_dest_addr_offset + sizeof(uint);
-#if DL_CURRENT_VERSION >= 2
-           ud->dl_group_address = 0;
-#endif
-           /* Send the DLPI client the data with the SAP they requested,
-              (e.g. ETHERTYPE_IP) rather than the PPP protocol number
-              (e.g. PPP_IP) */
-           ((uint *)(ud + 1))[0] = us->req_sap;        /* dest SAP */
-           ((uint *)(ud + 1))[1] = us->req_sap;        /* src SAP */
-           putnext(q, hdr);
-#else /* NO_DLPI */
-           putnext(q, mp);
-#endif /* NO_DLPI */
-       }
-       /*
-        * Now that we have consumed some packets from this queue,
-        * enable the control stream's read service routine so that we
-        * can process any packets for us that might have got queued
-        * there for flow control reasons.
-        */
-       if (us->ppa)
-           qenable(us->ppa->q);
-    }
-
-    return 0;
-}
-
-static upperstr_t *
-find_dest(ppa, proto)
-    upperstr_t *ppa;
-    int proto;
-{
-    upperstr_t *us;
-
-    for (us = ppa->next; us != 0; us = us->next)
-       if (proto == us->sap)
-           break;
-    return us;
-}
-
-#if defined (SOL2)
-/*
- * Test upstream promiscuous conditions. As of now, only pass IPv4 and
- * Ipv6 packets upstream (let PPP packets be decoded elsewhere).
- */
-static upperstr_t *
-find_promisc(us, proto)
-    upperstr_t *us;
-    int proto;
-{
-
-    if ((proto != PPP_IP) && (proto != PPP_IPV6))
-       return (upperstr_t *)0;
-
-    for ( ; us; us = us->next) {
-       if ((us->flags & US_PROMISC) && (us->state == DL_IDLE))
-           return us;
-    }
-
-    return (upperstr_t *)0;
-}
-
-/*
- * Prepend an empty Ethernet header to msg for snoop, et al.
- */
-static mblk_t *
-prepend_ether(us, mp, proto)
-    upperstr_t *us;
-    mblk_t *mp;
-    int proto;
-{
-    mblk_t *eh;
-    int type;
-
-    if ((eh = allocb(sizeof(struct ether_header), BPRI_HI)) == 0) {
-       freemsg(mp);
-       return (mblk_t *)0;
-    }
-
-    if (proto == PPP_IP)
-       type = ETHERTYPE_IP;
-    else if (proto == PPP_IPV6)
-       type = ETHERTYPE_IPV6;
-    else 
-       type = proto;       /* What else? Let decoder decide */
-
-    eh->b_wptr += sizeof(struct ether_header);
-    bzero((caddr_t)eh->b_rptr, sizeof(struct ether_header));
-    ((struct ether_header *)eh->b_rptr)->ether_type = htons((short)type);
-    eh->b_cont = mp;
-    return (eh);
-}
-
-/*
- * Prepend DL_UNITDATA_IND mblk to msg
- */
-static mblk_t *
-prepend_udind(us, mp, proto)
-    upperstr_t *us;
-    mblk_t *mp;
-    int proto;
-{
-    dl_unitdata_ind_t *dlu;
-    mblk_t *dh;
-    size_t size;
-
-    size = sizeof(dl_unitdata_ind_t);
-    if ((dh = allocb(size, BPRI_MED)) == 0) {
-       freemsg(mp);
-       return (mblk_t *)0;
-    }
-
-    dh->b_datap->db_type = M_PROTO;
-    dh->b_wptr = dh->b_datap->db_lim;
-    dh->b_rptr = dh->b_wptr - size;
-
-    dlu = (dl_unitdata_ind_t *)dh->b_rptr;
-    dlu->dl_primitive = DL_UNITDATA_IND;
-    dlu->dl_dest_addr_length = 0;
-    dlu->dl_dest_addr_offset = sizeof(dl_unitdata_ind_t);
-    dlu->dl_src_addr_length = 0;
-    dlu->dl_src_addr_offset = sizeof(dl_unitdata_ind_t);
-    dlu->dl_group_address = 0;
-
-    dh->b_cont = mp;
-    return (dh);
-}
-
-/*
- * For any recognized promiscuous streams, send data upstream
- */
-static void
-promisc_sendup(ppa, mp, proto, skip)
-    upperstr_t *ppa;
-    mblk_t *mp;
-    int proto, skip;
-{
-    mblk_t *dup_mp, *dup_dup_mp;
-    upperstr_t *prus, *nprus;
-
-    if ((prus = find_promisc(ppa, proto)) != 0) {
-       if (dup_mp = dupmsg(mp)) {
-
-           if (skip)
-               dup_mp->b_rptr += PPP_HDRLEN;
-
-           for ( ; nprus = find_promisc(prus->next, proto); 
-                   prus = nprus) {
-
-               if (dup_dup_mp = dupmsg(dup_mp)) {
-                   if (canputnext(prus->q)) {
-                       if (prus->flags & US_RAWDATA) {
-                           dup_dup_mp = prepend_ether(prus, dup_dup_mp, proto);
-                       } else {
-                           dup_dup_mp = prepend_udind(prus, dup_dup_mp, proto);
-                       }
-                       if (dup_dup_mp == 0)
-                           continue;
-                       putnext(prus->q, dup_dup_mp);
-                   } else {
-                       DPRINT("ppp_urput: data to promisc q dropped\n");
-                       freemsg(dup_dup_mp);
-                   }
-               }
-           }
-
-           if (canputnext(prus->q)) {
-               if (prus->flags & US_RAWDATA) {
-                   dup_mp = prepend_ether(prus, dup_mp, proto);
-               } else {
-                   dup_mp = prepend_udind(prus, dup_mp, proto);
-               }
-               if (dup_mp != 0)
-                   putnext(prus->q, dup_mp);
-           } else {
-               DPRINT("ppp_urput: data to promisc q dropped\n");
-               freemsg(dup_mp);
-           }
-       }
-    }
-}
-#endif /* defined(SOL2) */
-
-/*
- * We simply put the message on to the associated upper control stream
- * (either here or in ppplrsrv).  That way we enter the perimeters
- * before looking through the list of attached streams to decide which
- * stream it should go up.
- */
-static int
-ppplrput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    queue_t *uq;
-    struct iocblk *iop;
-
-    switch (mp->b_datap->db_type) {
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       iop->ioc_error = EINVAL;
-       mp->b_datap->db_type = M_IOCNAK;
-       qreply(q, mp);
-       return 0;
-    case M_FLUSH:
-       if (*mp->b_rptr & FLUSHR)
-           flushq(q, FLUSHDATA);
-       if (*mp->b_rptr & FLUSHW) {
-           *mp->b_rptr &= ~FLUSHR;
-           qreply(q, mp);
-       } else
-           freemsg(mp);
-       return 0;
-    }
-
-    /*
-     * If we can't get the lower lock straight away, queue this one
-     * rather than blocking, to avoid the possibility of deadlock.
-     */
-    if (!TRYLOCK_LOWER_R) {
-       if (!putq(q, mp))
-           freemsg(mp);
-       return 0;
-    }
-
-    /*
-     * Check that we're still connected to the driver.
-     */
-    uq = (queue_t *) q->q_ptr;
-    if (uq == 0) {
-       UNLOCK_LOWER;
-       DPRINT1("ppplrput: q = %x, uq = 0??\n", q);
-       freemsg(mp);
-       return 0;
-    }
-
-    /*
-     * Try to forward the message to the put routine for the upper
-     * control stream for this lower stream.
-     * If there are already messages queued here, queue this one so
-     * they don't get out of order.
-     */
-    if (queclass(mp) == QPCTL || (qsize(q) == 0 && canput(uq)))
-       put(uq, mp);
-    else if (!putq(q, mp))
-       freemsg(mp);
-
-    UNLOCK_LOWER;
-    return 0;
-}
-
-static int
-ppplrsrv(q)
-    queue_t *q;
-{
-    mblk_t *mp;
-    queue_t *uq;
-
-    /*
-     * Packets get queued here for flow control reasons
-     * or if the lrput routine couldn't get the lower lock
-     * without blocking.
-     */
-    LOCK_LOWER_R;
-    uq = (queue_t *) q->q_ptr;
-    if (uq == 0) {
-       UNLOCK_LOWER;
-       flushq(q, FLUSHALL);
-       DPRINT1("ppplrsrv: q = %x, uq = 0??\n", q);
-       return 0;
-    }
-    while ((mp = getq(q)) != 0) {
-       if (queclass(mp) == QPCTL || canput(uq))
-           put(uq, mp);
-       else {
-           putbq(q, mp);
-           break;
-       }
-    }
-    UNLOCK_LOWER;
-    return 0;
-}
-
-static int
-putctl2(q, type, code, val)
-    queue_t *q;
-    int type, code, val;
-{
-    mblk_t *mp;
-
-    mp = allocb(2, BPRI_HI);
-    if (mp == 0)
-       return 0;
-    mp->b_datap->db_type = type;
-    mp->b_wptr[0] = code;
-    mp->b_wptr[1] = val;
-    mp->b_wptr += 2;
-    putnext(q, mp);
-    return 1;
-}
-
-static int
-putctl4(q, type, code, val)
-    queue_t *q;
-    int type, code, val;
-{
-    mblk_t *mp;
-
-    mp = allocb(4, BPRI_HI);
-    if (mp == 0)
-       return 0;
-    mp->b_datap->db_type = type;
-    mp->b_wptr[0] = code;
-    ((short *)mp->b_wptr)[1] = val;
-    mp->b_wptr += 4;
-    putnext(q, mp);
-    return 1;
-}
-
-static void
-debug_dump(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    upperstr_t *us;
-    queue_t *uq, *lq;
-
-    DPRINT("ppp upper streams:\n");
-    for (us = minor_devs; us != 0; us = us->nextmn) {
-       uq = us->q;
-       DPRINT3(" %d: q=%x rlev=%d",
-               us->mn, uq, (uq? qsize(uq): 0));
-       DPRINT3(" wlev=%d flags=0x%b", (uq? qsize(WR(uq)): 0),
-               us->flags, "\020\1priv\2control\3blocked\4last");
-       DPRINT3(" state=%x sap=%x req_sap=%x", us->state, us->sap,
-               us->req_sap);
-       if (us->ppa == 0)
-           DPRINT(" ppa=?\n");
-       else
-           DPRINT1(" ppa=%d\n", us->ppa->ppa_id);
-       if (us->flags & US_CONTROL) {
-           lq = us->lowerq;
-           DPRINT3("    control for %d lq=%x rlev=%d",
-                   us->ppa_id, lq, (lq? qsize(RD(lq)): 0));
-           DPRINT3(" wlev=%d mru=%d mtu=%d\n",
-                   (lq? qsize(lq): 0), us->mru, us->mtu);
-       }
-    }
-    mp->b_datap->db_type = M_IOCACK;
-    qreply(q, mp);
-}
-
-#ifdef FILTER_PACKETS
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-
-#define MAX_IPHDR    128     /* max TCP/IP header size */
-
-
-/* The following table contains a hard-coded list of protocol/port pairs.
- * Any matching packets are either discarded unconditionally, or, 
- * if ok_if_link_up is non-zero when a connection does not currently exist
- * (i.e., they go through if the connection is present, but never initiate
- * a dial-out).
- * This idea came from a post by dm@garage.uun.org (David Mazieres)
- */
-static struct pktfilt_tab { 
-       int proto; 
-       u_short port; 
-       u_short ok_if_link_up; 
-} pktfilt_tab[] = {
-       { IPPROTO_UDP,  520,    1 },    /* RIP, ok to pass if link is up */
-       { IPPROTO_UDP,  123,    1 },    /* NTP, don't keep up the link for it */
-       { -1,           0,      0 }     /* terminator entry has port == -1 */
-};
-
-
-/*
- * Packet has already been freed if return value is 0.
- */
-static int
-ip_hard_filter(us, mp, outbound)
-    upperstr_t *us;
-    mblk_t *mp;
-    int outbound;
-{
-    struct ip *ip;
-    struct pktfilt_tab *pft;
-    mblk_t *temp_mp;
-    int proto;
-    int len, hlen;
-
-
-    /* Note, the PPP header has already been pulled up in all cases */
-    proto = PPP_PROTOCOL(mp->b_rptr);
-    if (us->flags & US_DBGLOG)
-        DPRINT3("ppp/%d: filter, proto=0x%x, out=%d\n", us->mn, proto, outbound);
-
-    switch (proto)
-    {
-    case PPP_IP:
-       if ((mp->b_wptr - mp->b_rptr) == PPP_HDRLEN && mp->b_cont != 0) {
-           temp_mp = mp->b_cont;
-           len = msgdsize(temp_mp);
-           hlen = (len < MAX_IPHDR) ? len : MAX_IPHDR;
-           PULLUP(temp_mp, hlen);
-           if (temp_mp == 0) {
-               DPRINT2("ppp/%d: filter, pullup next failed, len=%d\n", 
-                       us->mn, hlen);
-               mp->b_cont = 0;         /* PULLUP() freed the rest */
-               freemsg(mp);
-               return 0;
-           }
-           ip = (struct ip *)mp->b_cont->b_rptr;
-       }
-       else {
-           len = msgdsize(mp);
-           hlen = (len < (PPP_HDRLEN+MAX_IPHDR)) ? len : (PPP_HDRLEN+MAX_IPHDR);
-           PULLUP(mp, hlen);
-           if (mp == 0) {
-               DPRINT2("ppp/%d: filter, pullup failed, len=%d\n", 
-                       us->mn, hlen);
-               return 0;
-           }
-           ip = (struct ip *)(mp->b_rptr + PPP_HDRLEN);
-       }
-
-       /* For IP traffic, certain packets (e.g., RIP) may be either
-        *   1.  ignored - dropped completely
-        *   2.  will not initiate a connection, but
-        *       will be passed if a connection is currently up.
-        */
-       for (pft=pktfilt_tab; pft->proto != -1; pft++) {
-           if (ip->ip_p == pft->proto) {
-               switch(pft->proto) {
-               case IPPROTO_UDP:
-                   if (((struct udphdr *) &((int *)ip)[ip->ip_hl])->uh_dport
-                               == htons(pft->port)) goto endfor;
-                   break;
-               case IPPROTO_TCP:
-                   if (((struct tcphdr *) &((int *)ip)[ip->ip_hl])->th_dport
-                               == htons(pft->port)) goto endfor;
-                   break;
-               }       
-           }
-       }
-       endfor:
-       if (pft->proto != -1) {
-           if (us->flags & US_DBGLOG)
-               DPRINT3("ppp/%d: found IP pkt, proto=0x%x (%d)\n", 
-                               us->mn, pft->proto, pft->port);
-           /* Discard if not connected, or if not pass_with_link_up */
-           /* else, if link is up let go by, but don't update time */
-           if (pft->ok_if_link_up)
-               return -1;
-           freemsg(mp);
-           return 0;
-       }
-        break;
-    } /* end switch (proto) */
-
-    return 1;
-}
-#endif /* FILTER_PACKETS */
-
diff --git a/solaris/ppp.conf b/solaris/ppp.conf
deleted file mode 100644 (file)
index e443a7a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-name="ppp" parent="pseudo" instance=0;
diff --git a/solaris/ppp_ahdlc.c b/solaris/ppp_ahdlc.c
deleted file mode 100644 (file)
index 21b8c54..0000000
+++ /dev/null
@@ -1,833 +0,0 @@
-/*
- * ppp_ahdlc.c - STREAMS module for doing PPP asynchronous HDLC.
- *
- * Re-written by Adi Masputra <adi.masputra@sun.com>, based on 
- * the original ppp_ahdlc.c
- *
- * Copyright (c) 2000 by Sun Microsystems, Inc.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation is hereby granted, provided that the above copyright
- * notice appears in all copies.  
- *
- * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp_ahdlc.c,v 1.5 2005/06/27 00:59:57 carlsonj Exp $
- */
-
-/*
- * This file is used under Solaris 2, SVR4, SunOS 4, and Digital UNIX.
- */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stream.h>
-#include <sys/stropts.h>
-#include <sys/errno.h>
-
-#ifdef SVR4
-#include <sys/conf.h>
-#include <sys/kmem.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#else
-#include <sys/user.h>
-#ifdef __osf__
-#include <sys/cmn_err.h>
-#endif
-#endif /* SVR4 */
-
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-/*
- * Right now, mutex is only enabled for Solaris 2.x
- */
-#if defined(SOL2)
-#define USE_MUTEX
-#endif /* SOL2 */
-
-#ifdef USE_MUTEX
-#define        MUTEX_ENTER(x)  mutex_enter(x)
-#define        MUTEX_EXIT(x)   mutex_exit(x)
-#else
-#define        MUTEX_ENTER(x)
-#define        MUTEX_EXIT(x)
-#endif
-
-/*
- * intpointer_t and uintpointer_t are signed and unsigned integer types 
- * large enough to hold any data pointer; that is, data pointers can be 
- * assigned into or from these integer types without losing precision.
- * On recent Solaris releases, these types are defined in sys/int_types.h,
- * but not on SunOS 4.x or the earlier Solaris versions.
- */
-#if defined(_LP64) || defined(_I32LPx)
-typedef long                    intpointer_t;
-typedef unsigned long           uintpointer_t;
-#else
-typedef int                     intpointer_t;
-typedef unsigned int            uintpointer_t;
-#endif
-
-MOD_OPEN_DECL(ahdlc_open);
-MOD_CLOSE_DECL(ahdlc_close);
-static int ahdlc_wput(queue_t *, mblk_t *);
-static int ahdlc_rput(queue_t *, mblk_t *);
-static void ahdlc_encode(queue_t *, mblk_t *);
-static void ahdlc_decode(queue_t *, mblk_t *);
-static int msg_byte(mblk_t *, unsigned int);
-
-#if defined(SOL2)
-/*
- * Don't send HDLC start flag is last transmit is within 1.5 seconds -
- * FLAG_TIME is defined is microseconds
- */
-#define FLAG_TIME   1500
-#define ABS(x)     (x >= 0 ? x : (-x))
-#endif /* SOL2 */
-
-/*
- * Extract byte i of message mp 
- */
-#define MSG_BYTE(mp, i)        ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
-                        msg_byte((mp), (i)))
-
-/* 
- * Is this LCP packet one we have to transmit using LCP defaults? 
- */
-#define LCP_USE_DFLT(mp)       (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
-
-/*
- * Standard STREAMS declarations
- */
-static struct module_info minfo = {
-    0x7d23, "ppp_ahdl", 0, INFPSZ, 32768, 512
-};
-
-static struct qinit rinit = {
-    ahdlc_rput, NULL, ahdlc_open, ahdlc_close, NULL, &minfo, NULL
-};
-
-static struct qinit winit = {
-    ahdlc_wput, NULL, NULL, NULL, NULL, &minfo, NULL
-};
-
-#if defined(SVR4) && !defined(SOL2)
-int phdldevflag = 0;
-#define ppp_ahdlcinfo phdlinfo
-#endif /* defined(SVR4) && !defined(SOL2) */
-
-struct streamtab ppp_ahdlcinfo = {
-    &rinit,                        /* ptr to st_rdinit */
-    &winit,                        /* ptr to st_wrinit */
-    NULL,                          /* ptr to st_muxrinit */
-    NULL,                          /* ptr to st_muxwinit */
-#if defined(SUNOS4)
-    NULL                           /* ptr to ptr to st_modlist */
-#endif /* SUNOS4 */
-};
-
-#if defined(SUNOS4)
-int ppp_ahdlc_count = 0;           /* open counter */
-#endif /* SUNOS4 */
-
-/*
- * Per-stream state structure
- */
-typedef struct ahdlc_state {
-#if defined(USE_MUTEX)
-    kmutex_t       lock;                   /* lock for this structure */
-#endif /* USE_MUTEX */
-    int                    flags;                  /* link flags */
-    mblk_t         *rx_buf;                /* ptr to receive buffer */
-    int                    rx_buf_size;            /* receive buffer size */
-    ushort_t       infcs;                  /* calculated rx HDLC FCS */
-    u_int32_t      xaccm[8];               /* 256-bit xmit ACCM */
-    u_int32_t      raccm;                  /* 32-bit rcv ACCM */
-    int                    mtu;                    /* interface MTU */
-    int                    mru;                    /* link MRU */
-    int                    unit;                   /* current PPP unit number */
-    struct pppstat  stats;                 /* statistic structure */
-#if defined(SOL2)
-    clock_t        flag_time;              /* time in usec between flags */
-    clock_t        lbolt;                  /* last updated lbolt */
-#endif /* SOL2 */
-} ahdlc_state_t;
-
-/*
- * Values for flags 
- */
-#define ESCAPED                0x100   /* last saw escape char on input */
-#define IFLUSH         0x200   /* flushing input due to error */
-
-/* 
- * RCV_B7_1, etc., defined in net/pppio.h, are stored in flags also. 
- */
-#define RCV_FLAGS      (RCV_B7_1|RCV_B7_0|RCV_ODDP|RCV_EVNP)
-
-/*
- * FCS lookup table as calculated by genfcstab.
- */
-static u_short fcstab[256] = {
-       0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
-       0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
-       0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
-       0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
-       0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
-       0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
-       0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
-       0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
-       0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
-       0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
-       0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
-       0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
-       0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
-       0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
-       0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
-       0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
-       0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
-       0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
-       0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
-       0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
-       0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
-       0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
-       0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
-       0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
-       0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
-       0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
-       0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
-       0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
-       0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
-       0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
-       0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
-       0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
-};
-
-static u_int32_t paritytab[8] =
-{
-       0x96696996, 0x69969669, 0x69969669, 0x96696996,
-       0x69969669, 0x96696996, 0x96696996, 0x69969669
-};
-
-/*
- * STREAMS module open (entry) point
- */
-MOD_OPEN(ahdlc_open)
-{
-    ahdlc_state_t   *state;
-    mblk_t *mp;
-
-    /*
-     * Return if it's already opened
-     */
-    if (q->q_ptr) {
-       return 0;
-    }
-
-    /*
-     * This can only be opened as a module
-     */
-    if (sflag != MODOPEN) {
-       OPEN_ERROR(EINVAL);
-    }
-
-    state = (ahdlc_state_t *) ALLOC_NOSLEEP(sizeof(ahdlc_state_t));
-    if (state == 0)
-       OPEN_ERROR(ENOSR);
-    bzero((caddr_t) state, sizeof(ahdlc_state_t));
-
-    q->q_ptr    = (caddr_t) state;
-    WR(q)->q_ptr = (caddr_t) state;
-
-#if defined(USE_MUTEX)
-    mutex_init(&state->lock, NULL, MUTEX_DEFAULT, NULL);
-#endif /* USE_MUTEX */
-
-    state->xaccm[0] = ~0;          /* escape 0x00 through 0x1f */
-    state->xaccm[3] = 0x60000000;   /* escape 0x7d and 0x7e */
-    state->mru     = PPP_MRU;      /* default of 1500 bytes */
-#if defined(SOL2)
-    state->flag_time = drv_usectohz(FLAG_TIME);
-#endif /* SOL2 */
-
-#if defined(SUNOS4)
-    ppp_ahdlc_count++;
-#endif /* SUNOS4 */
-
-    qprocson(q);
-
-    if ((mp = allocb(1, BPRI_HI)) != NULL) {
-           mp->b_datap->db_type = M_FLUSH;
-           *mp->b_wptr++ = FLUSHR;
-           putnext(q, mp);
-    }
-
-    return 0;
-}
-
-/*
- * STREAMS module close (exit) point
- */
-MOD_CLOSE(ahdlc_close)
-{
-    ahdlc_state_t   *state;
-
-    qprocsoff(q);
-
-    state = (ahdlc_state_t *) q->q_ptr;
-
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_close\n");
-       return 0;
-    }
-
-    if (state->rx_buf != 0) {
-       freemsg(state->rx_buf);
-       state->rx_buf = 0;
-    }
-
-#if defined(USE_MUTEX)
-    mutex_destroy(&state->lock);
-#endif /* USE_MUTEX */
-
-    FREE(q->q_ptr, sizeof(ahdlc_state_t));
-    q->q_ptr        = NULL;
-    OTHERQ(q)->q_ptr = NULL;
-
-#if defined(SUNOS4)
-    if (ppp_ahdlc_count)
-       ppp_ahdlc_count--;
-#endif /* SUNOS4 */
-    
-    return 0;
-}
-
-/*
- * Write side put routine
- */
-static int
-ahdlc_wput(q, mp)
-    queue_t    *q;
-    mblk_t     *mp;
-{
-    ahdlc_state_t      *state;
-    struct iocblk      *iop;
-    int                        error;
-    mblk_t             *np;
-    struct ppp_stats   *psp;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_wput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       /*
-        * A data packet - do character-stuffing and FCS, and
-        * send it onwards.
-        */
-       ahdlc_encode(q, mp);
-       freemsg(mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       switch (iop->ioc_cmd) {
-       case PPPIO_XACCM:
-           if ((iop->ioc_count < sizeof(u_int32_t)) || 
-               (iop->ioc_count > sizeof(ext_accm))) {
-               break;
-           }
-           if (mp->b_cont == 0) {
-               DPRINT1("ahdlc_wput/%d: PPPIO_XACCM b_cont = 0!\n", state->unit);
-               break;
-           }
-           MUTEX_ENTER(&state->lock);
-           bcopy((caddr_t)mp->b_cont->b_rptr, (caddr_t)state->xaccm,
-                 iop->ioc_count);
-           state->xaccm[2] &= ~0x40000000;     /* don't escape 0x5e */
-           state->xaccm[3] |= 0x60000000;      /* do escape 0x7d, 0x7e */
-           MUTEX_EXIT(&state->lock);
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_RACCM:
-           if (iop->ioc_count != sizeof(u_int32_t))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ahdlc_wput/%d: PPPIO_RACCM b_cont = 0!\n", state->unit);
-               break;
-           }
-           MUTEX_ENTER(&state->lock);
-           bcopy((caddr_t)mp->b_cont->b_rptr, (caddr_t)&state->raccm,
-                 sizeof(u_int32_t));
-           MUTEX_EXIT(&state->lock);
-           iop->ioc_count = 0;
-           error = 0;
-           break;
-
-       case PPPIO_GCLEAN:
-           np = allocb(sizeof(int), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           MUTEX_ENTER(&state->lock);
-           *(int *)np->b_wptr = state->flags & RCV_FLAGS;
-           MUTEX_EXIT(&state->lock);
-           np->b_wptr += sizeof(int);
-           iop->ioc_count = sizeof(int);
-           error = 0;
-           break;
-
-       case PPPIO_GETSTAT:
-           np = allocb(sizeof(struct ppp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           psp = (struct ppp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_stats);
-           bzero((caddr_t)psp, sizeof(struct ppp_stats));
-           psp->p = state->stats;
-           iop->ioc_count = sizeof(struct ppp_stats);
-           error = 0;
-           break;
-
-       case PPPIO_LASTMOD:
-           /* we knew this anyway */
-           error = 0;
-           break;
-
-       default:
-           error = -1;
-           break;
-       }
-
-       if (error < 0)
-           putnext(q, mp);
-       else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       } else {
-           mp->b_datap->db_type = M_IOCNAK;
-           iop->ioc_count = 0;
-           iop->ioc_error = error;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_CTL:
-       switch (*mp->b_rptr) {
-       case PPPCTL_MTU:
-           MUTEX_ENTER(&state->lock);
-           state->mtu = ((unsigned short *)mp->b_rptr)[1];
-           MUTEX_EXIT(&state->lock);
-           break;
-       case PPPCTL_MRU:
-           MUTEX_ENTER(&state->lock);
-           state->mru = ((unsigned short *)mp->b_rptr)[1];
-           MUTEX_EXIT(&state->lock);
-           break;
-       case PPPCTL_UNIT:
-           MUTEX_ENTER(&state->lock);
-           state->unit = mp->b_rptr[1];
-           MUTEX_EXIT(&state->lock);
-           break;
-       default:
-           putnext(q, mp);
-           return 0;
-       }
-       freemsg(mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-/*
- * Read side put routine
- */
-static int
-ahdlc_rput(q, mp)
-    queue_t *q;
-    mblk_t  *mp;
-{
-    ahdlc_state_t *state;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-    if (state == 0) {
-       DPRINT("state == 0 in ahdlc_rput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-    case M_DATA:
-       ahdlc_decode(q, mp);
-       break;
-
-    case M_HANGUP:
-       MUTEX_ENTER(&state->lock);
-       if (state->rx_buf != 0) {
-           /* XXX would like to send this up for debugging */
-           freemsg(state->rx_buf);
-           state->rx_buf = 0;
-       }
-       state->flags = IFLUSH;
-       MUTEX_EXIT(&state->lock);
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-    return 0;
-}
-
-/*
- * Extract bit c from map m, to determine if c needs to be escaped
- */
-#define IN_TX_MAP(c, m)        ((m)[(c) >> 5] & (1 << ((c) & 0x1f)))
-
-static void
-ahdlc_encode(q, mp)
-    queue_t    *q;
-    mblk_t     *mp;
-{
-    ahdlc_state_t      *state;
-    u_int32_t          *xaccm, loc_xaccm[8];
-    ushort_t           fcs;
-    size_t             outmp_len;
-    mblk_t             *outmp, *tmp;
-    uchar_t            *dp, fcs_val;
-    int                        is_lcp, code;
-#if defined(SOL2)
-    clock_t            lbolt;
-#endif /* SOL2 */
-
-    if (msgdsize(mp) < 4) {
-       return;
-    }
-
-    state = (ahdlc_state_t *)q->q_ptr;
-    MUTEX_ENTER(&state->lock);
-
-    /*
-     * Allocate an output buffer large enough to handle a case where all
-     * characters need to be escaped
-     */
-    outmp_len = (msgdsize(mp)   << 1) +                /* input block x 2 */
-               (sizeof(fcs)     << 2) +                /* HDLC FCS x 4 */
-               (sizeof(uchar_t) << 1);                 /* HDLC flags x 2 */
-
-    outmp = allocb(outmp_len, BPRI_MED);
-    if (outmp == NULL) {
-       state->stats.ppp_oerrors++;
-       MUTEX_EXIT(&state->lock);
-       putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-       return;
-    }
-
-#if defined(SOL2)
-    /*
-     * Check if our last transmit happenned within flag_time, using
-     * the system's LBOLT value in clock ticks
-     */
-    if (drv_getparm(LBOLT, &lbolt) != -1) {
-       if (ABS((clock_t)lbolt - state->lbolt) > state->flag_time) {
-           *outmp->b_wptr++ = PPP_FLAG;
-       } 
-       state->lbolt = lbolt;
-    } else {
-       *outmp->b_wptr++ = PPP_FLAG;
-    }
-#else
-    /*
-     * If the driver below still has a message to process, skip the
-     * HDLC flag, otherwise, put one in the beginning
-     */
-    if (qsize(q->q_next) == 0) {
-       *outmp->b_wptr++ = PPP_FLAG;
-    }
-#endif
-
-    /*
-     * All control characters must be escaped for LCP packets with code
-     * values between 1 (Conf-Req) and 7 (Code-Rej).
-     */
-    is_lcp = ((MSG_BYTE(mp, 0) == PPP_ALLSTATIONS) && 
-             (MSG_BYTE(mp, 1) == PPP_UI) && 
-             (MSG_BYTE(mp, 2) == (PPP_LCP >> 8)) &&
-             (MSG_BYTE(mp, 3) == (PPP_LCP & 0xff)) &&
-             LCP_USE_DFLT(mp));
-
-    xaccm = state->xaccm;
-    if (is_lcp) {
-       bcopy((caddr_t)state->xaccm, (caddr_t)loc_xaccm, sizeof(loc_xaccm));
-       loc_xaccm[0] = ~0;      /* force escape on 0x00 through 0x1f */
-       xaccm = loc_xaccm;
-    }
-
-    fcs = PPP_INITFCS;         /* Initial FCS is 0xffff */
-
-    /*
-     * Process this block and the rest (if any) attached to the this one
-     */
-    for (tmp = mp; tmp; tmp = tmp->b_cont) {
-       if (tmp->b_datap->db_type == M_DATA) {
-           for (dp = tmp->b_rptr; dp < tmp->b_wptr; dp++) {
-               fcs = PPP_FCS(fcs, *dp);
-               if (IN_TX_MAP(*dp, xaccm)) {
-                   *outmp->b_wptr++ = PPP_ESCAPE;
-                   *outmp->b_wptr++ = *dp ^ PPP_TRANS;
-               } else {
-                   *outmp->b_wptr++ = *dp;
-               }
-           }
-       } else {
-           continue;   /* skip if db_type is something other than M_DATA */
-       }
-    }
-
-    /*
-     * Append the HDLC FCS, making sure that escaping is done on any
-     * necessary bytes
-     */
-    fcs_val = (fcs ^ 0xffff) & 0xff;
-    if (IN_TX_MAP(fcs_val, xaccm)) {
-       *outmp->b_wptr++ = PPP_ESCAPE;
-       *outmp->b_wptr++ = fcs_val ^ PPP_TRANS;
-    } else {
-       *outmp->b_wptr++ = fcs_val;
-    }
-
-    fcs_val = ((fcs ^ 0xffff) >> 8) & 0xff;
-    if (IN_TX_MAP(fcs_val, xaccm)) {
-       *outmp->b_wptr++ = PPP_ESCAPE;
-       *outmp->b_wptr++ = fcs_val ^ PPP_TRANS;
-    } else {
-       *outmp->b_wptr++ = fcs_val;
-    }
-
-    /*
-     * And finally, append the HDLC flag, and send it away
-     */
-    *outmp->b_wptr++ = PPP_FLAG;
-
-    state->stats.ppp_obytes += msgdsize(outmp);
-    state->stats.ppp_opackets++;
-
-    MUTEX_EXIT(&state->lock);
-
-    putnext(q, outmp);
-}
-
-/*
- * Checks the 32-bit receive ACCM to see if the byte needs un-escaping
- */
-#define IN_RX_MAP(c, m)        ((((unsigned int) (uchar_t) (c)) < 0x20) && \
-                       (m) & (1 << (c)))
-
-
-/*
- * Process received characters.
- */
-static void
-ahdlc_decode(q, mp)
-    queue_t *q;
-    mblk_t  *mp;
-{
-    ahdlc_state_t   *state;
-    mblk_t         *om;
-    uchar_t        *dp;
-
-    state = (ahdlc_state_t *) q->q_ptr;
-
-    MUTEX_ENTER(&state->lock);
-
-    state->stats.ppp_ibytes += msgdsize(mp);
-
-    for (; mp != 0; om = mp->b_cont, freeb(mp), mp = om)
-    for (dp = mp->b_rptr; dp < mp->b_wptr; dp++) {
-
-       /*
-        * This should detect the lack of 8-bit communication channel
-        * which is necessary for PPP to work. In addition, it also
-        * checks on the parity.
-        */
-       if (*dp & 0x80)
-           state->flags |= RCV_B7_1;
-       else
-           state->flags |= RCV_B7_0;
-
-       if (paritytab[*dp >> 5] & (1 << (*dp & 0x1f)))
-           state->flags |= RCV_ODDP;
-       else
-           state->flags |= RCV_EVNP;
-
-       /*
-        * So we have a HDLC flag ...
-        */
-       if (*dp == PPP_FLAG) {
-
-           /*
-            * If we think that it marks the beginning of the frame,
-            * then continue to process the next octects
-            */
-           if ((state->flags & IFLUSH) ||
-               (state->rx_buf == 0) ||
-               (msgdsize(state->rx_buf) == 0)) {
-
-               state->flags &= ~IFLUSH;
-               continue;
-           }
-
-           /*
-            * We get here because the above condition isn't true,
-            * in which case the HDLC flag was there to mark the end
-            * of the frame (or so we think)
-            */
-           om = state->rx_buf;
-
-           if (state->infcs == PPP_GOODFCS) {
-               state->stats.ppp_ipackets++;
-               adjmsg(om, -PPP_FCSLEN);
-               putnext(q, om);
-           } else {
-               DPRINT2("ppp%d: bad fcs (len=%d)\n",
-                    state->unit, msgdsize(state->rx_buf));
-               freemsg(state->rx_buf);
-               state->flags &= ~(IFLUSH | ESCAPED);
-               state->stats.ppp_ierrors++;
-               putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-           }
-
-           state->rx_buf = 0;
-           continue;
-       }
-
-       if (state->flags & IFLUSH) {
-           continue;
-       }
-
-       /*
-        * Allocate a receive buffer, large enough to store a frame (after
-        * un-escaping) of at least 1500 octets. If MRU is negotiated to
-        * be more than the default, then allocate that much. In addition,
-        * we add an extra 32-bytes for a fudge factor
-        */ 
-       if (state->rx_buf == 0) {
-           state->rx_buf_size  = (state->mru < PPP_MRU ? PPP_MRU : state->mru);
-           state->rx_buf_size += (sizeof(u_int32_t) << 3);
-           state->rx_buf = allocb(state->rx_buf_size, BPRI_MED);
-
-           /*
-            * If allocation fails, try again on the next frame
-            */
-           if (state->rx_buf == 0) {
-               state->flags |= IFLUSH;
-               continue;
-           }
-           state->flags &= ~(IFLUSH | ESCAPED);
-           state->infcs  = PPP_INITFCS;
-       }
-
-       if (*dp == PPP_ESCAPE) {
-           state->flags |= ESCAPED;
-           continue;
-       }
-
-       /*
-        * Make sure we un-escape the necessary characters, as well as the
-        * ones in our receive async control character map
-        */
-       if (state->flags & ESCAPED) {
-           *dp ^= PPP_TRANS;
-           state->flags &= ~ESCAPED;
-       } else if (IN_RX_MAP(*dp, state->raccm)) 
-           continue;
-
-       /*
-        * Unless the peer lied to us about the negotiated MRU, we should
-        * never get a frame which is too long. If it happens, toss it away
-        * and grab the next incoming one
-        */
-       if (msgdsize(state->rx_buf) < state->rx_buf_size) {
-           state->infcs = PPP_FCS(state->infcs, *dp);
-           *state->rx_buf->b_wptr++ = *dp;
-       } else {
-           DPRINT2("ppp%d: frame too long (%d)\n",
-               state->unit, msgdsize(state->rx_buf));
-           freemsg(state->rx_buf);
-           state->rx_buf     = 0;
-           state->flags     |= IFLUSH;
-       }
-    }
-
-    MUTEX_EXIT(&state->lock);
-}
-
-static int
-msg_byte(mp, i)
-    mblk_t *mp;
-    unsigned int i;
-{
-    while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
-       mp = mp->b_cont;
-    if (mp == 0)
-       return -1;
-    return mp->b_rptr[i];
-}
diff --git a/solaris/ppp_ahdlc_mod.c b/solaris/ppp_ahdlc_mod.c
deleted file mode 100644 (file)
index f81be8a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/conf.h>
-#include <sys/modctl.h>
-#include <sys/sunddi.h>
-
-extern struct streamtab ppp_ahdlcinfo;
-
-static struct fmodsw fsw = {
-    "ppp_ahdl",
-    &ppp_ahdlcinfo,
-    D_NEW | D_MP | D_MTQPAIR
-};
-
-extern struct mod_ops mod_strmodops;
-
-static struct modlstrmod modlstrmod = {
-    &mod_strmodops,
-    "PPP async HDLC module",
-    &fsw
-};
-
-static struct modlinkage modlinkage = {
-    MODREV_1,
-    (void *) &modlstrmod,
-    NULL
-};
-
-/*
- * Entry points for modloading.
- */
-int
-_init(void)
-{
-    return mod_install(&modlinkage);
-}
-
-int
-_fini(void)
-{
-    return mod_remove(&modlinkage);
-}
-
-int
-_info(mip)
-    struct modinfo *mip;
-{
-    return mod_info(&modlinkage, mip);
-}
diff --git a/solaris/ppp_comp.c b/solaris/ppp_comp.c
deleted file mode 100644 (file)
index cda8ddf..0000000
+++ /dev/null
@@ -1,1134 +0,0 @@
-/*
- * ppp_comp.c - STREAMS module for kernel-level compression and CCP support.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp_comp.c,v 1.3 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-/*
- * This file is used under SVR4, Solaris 2, SunOS 4, and Digital UNIX.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/stream.h>
-
-#ifdef SVR4
-#include <sys/conf.h>
-#include <sys/cmn_err.h>
-#include <sys/ddi.h>
-#else
-#include <sys/user.h>
-#ifdef __osf__
-#include <sys/cmn_err.h>
-#endif
-#endif /* SVR4 */
-
-#include <net/ppp_defs.h>
-#include <net/pppio.h>
-#include "ppp_mod.h"
-
-#ifdef __osf__
-#include <sys/mbuf.h>
-#include <sys/protosw.h>
-#endif
-
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <net/vjcompress.h>
-
-#define PACKETPTR      mblk_t *
-#include <net/ppp-comp.h>
-
-MOD_OPEN_DECL(ppp_comp_open);
-MOD_CLOSE_DECL(ppp_comp_close);
-static int ppp_comp_rput(queue_t *, mblk_t *);
-static int ppp_comp_rsrv(queue_t *);
-static int ppp_comp_wput(queue_t *, mblk_t *);
-static int ppp_comp_wsrv(queue_t *);
-static void ppp_comp_ccp(queue_t *, mblk_t *, int);
-static int msg_byte(mblk_t *, unsigned int);
-
-/* Extract byte i of message mp. */
-#define MSG_BYTE(mp, i)        ((i) < (mp)->b_wptr - (mp)->b_rptr? (mp)->b_rptr[i]: \
-                        msg_byte((mp), (i)))
-
-/* Is this LCP packet one we have to transmit using LCP defaults? */
-#define LCP_USE_DFLT(mp)       (1 <= (code = MSG_BYTE((mp), 4)) && code <= 7)
-
-#define PPP_COMP_ID 0xbadf
-static struct module_info minfo = {
-#ifdef PRIOQ
-    PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16512, 16384,
-#else
-    PPP_COMP_ID, "ppp_comp", 0, INFPSZ, 16384, 4096,
-#endif
-};
-
-static struct qinit r_init = {
-    ppp_comp_rput, ppp_comp_rsrv, ppp_comp_open, ppp_comp_close,
-    NULL, &minfo, NULL
-};
-
-static struct qinit w_init = {
-    ppp_comp_wput, ppp_comp_wsrv, NULL, NULL, NULL, &minfo, NULL
-};
-
-#if defined(SVR4) && !defined(SOL2)
-int pcmpdevflag = 0;
-#define ppp_compinfo pcmpinfo
-#endif
-struct streamtab ppp_compinfo = {
-    &r_init, &w_init, NULL, NULL
-};
-
-int ppp_comp_count;            /* number of module instances in use */
-
-#ifdef __osf__
-
-static void ppp_comp_alloc(comp_state_t *);
-typedef struct memreq {
-    unsigned char comp_opts[20];
-    int cmd;
-    int thread_status;
-    char *returned_mem;
-} memreq_t;
-
-#endif
-
-typedef struct comp_state {
-    int                flags;
-    int                mru;
-    int                mtu;
-    int                unit;
-    struct compressor *xcomp;
-    void       *xstate;
-    struct compressor *rcomp;
-    void       *rstate;
-    struct vjcompress vj_comp;
-    int                vj_last_ierrors;
-    struct pppstat stats;
-#ifdef __osf__
-    memreq_t   memreq;
-    thread_t   thread;
-#endif
-} comp_state_t;
-
-
-#ifdef __osf__
-extern task_t first_task;
-#endif
-
-/* Bits in flags are as defined in pppio.h. */
-#define CCP_ERR                (CCP_ERROR | CCP_FATALERROR)
-#define LAST_MOD       0x1000000       /* no ppp modules below us */
-#define DBGLOG         0x2000000       /* log debugging stuff */
-
-#define MAX_IPHDR      128     /* max TCP/IP header size */
-#define MAX_VJHDR      20      /* max VJ compressed header size (?) */
-
-#undef MIN             /* just in case */
-#define MIN(a, b)      ((a) < (b)? (a): (b))
-
-/*
- * List of compressors we know about.
- */
-
-#if DO_BSD_COMPRESS
-extern struct compressor ppp_bsd_compress;
-#endif
-#if DO_DEFLATE
-extern struct compressor ppp_deflate, ppp_deflate_draft;
-#endif
-
-struct compressor *ppp_compressors[] = {
-#if DO_BSD_COMPRESS
-    &ppp_bsd_compress,
-#endif
-#if DO_DEFLATE
-    &ppp_deflate,
-    &ppp_deflate_draft,
-#endif
-    NULL
-};
-
-/*
- * STREAMS module entry points.
- */
-MOD_OPEN(ppp_comp_open)
-{
-    comp_state_t *cp;
-#ifdef __osf__
-    thread_t thread;
-#endif
-
-    if (q->q_ptr == NULL) {
-       cp = (comp_state_t *) ALLOC_SLEEP(sizeof(comp_state_t));
-       if (cp == NULL)
-           OPEN_ERROR(ENOSR);
-       bzero((caddr_t)cp, sizeof(comp_state_t));
-       WR(q)->q_ptr = q->q_ptr = (caddr_t) cp;
-       cp->mru = PPP_MRU;
-       cp->mtu = PPP_MTU;
-       cp->xstate = NULL;
-       cp->rstate = NULL;
-       vj_compress_init(&cp->vj_comp, -1);
-#ifdef __osf__
-       if (!(thread = kernel_thread_w_arg(first_task, ppp_comp_alloc, (void *)cp)))
-               OPEN_ERROR(ENOSR);
-       cp->thread = thread;
-#endif
-       ++ppp_comp_count;
-       qprocson(q);
-    }
-    return 0;
-}
-
-MOD_CLOSE(ppp_comp_close)
-{
-    comp_state_t *cp;
-
-    qprocsoff(q);
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp != NULL) {
-       if (cp->xstate != NULL)
-           (*cp->xcomp->comp_free)(cp->xstate);
-       if (cp->rstate != NULL)
-           (*cp->rcomp->decomp_free)(cp->rstate);
-#ifdef __osf__
-       if (!cp->thread)
-           printf("ppp_comp_close: NULL thread!\n");
-       else
-           thread_terminate(cp->thread);
-#endif
-       FREE(cp, sizeof(comp_state_t));
-       q->q_ptr = NULL;
-       OTHERQ(q)->q_ptr = NULL;
-       --ppp_comp_count;
-    }
-    return 0;
-}
-
-#ifdef __osf__
-
-/* thread for calling back to a compressor's memory allocator
- * Needed for Digital UNIX since it's VM can't handle requests
- * for large amounts of memory without blocking.  The thread
- * provides a context in which we can call a memory allocator
- * that may block.
- */
-static void
-ppp_comp_alloc(comp_state_t *cp)
-{
-    int len, cmd;
-    unsigned char *compressor_options;
-    thread_t thread;
-    void *(*comp_allocator)();
-
-
-#if defined(MAJOR_VERSION) && (MAJOR_VERSION <= 2)
-
-    /* In 2.x and earlier the argument gets passed
-     * in the thread structure itself.  Yuck.
-     */
-    thread = current_thread();
-    cp = thread->reply_port;
-    thread->reply_port = PORT_NULL;
-
-#endif
-
-    for (;;) {
-       assert_wait((vm_offset_t)&cp->memreq.thread_status, TRUE);
-       thread_block();
-
-       if (thread_should_halt(current_thread()))
-           thread_halt_self();
-       cmd = cp->memreq.cmd;
-       compressor_options = &cp->memreq.comp_opts[0];
-       len = compressor_options[1];
-       if (cmd == PPPIO_XCOMP) {
-           cp->memreq.returned_mem = cp->xcomp->comp_alloc(compressor_options, len);
-           if (!cp->memreq.returned_mem) {
-               cp->memreq.thread_status = ENOSR;
-           } else {
-               cp->memreq.thread_status = 0;
-           }
-       } else {
-           cp->memreq.returned_mem = cp->rcomp->decomp_alloc(compressor_options, len);
-           if (!cp->memreq.returned_mem) {
-               cp->memreq.thread_status = ENOSR;
-           } else {
-               cp->memreq.thread_status = 0;
-           }
-       }
-    }
-}
-
-#endif /* __osf__ */
-
-/* here's the deal with memory allocation under Digital UNIX.
- * Some other may also benefit from this...
- * We can't ask for huge chunks of memory in a context where
- * the caller can't be put to sleep (like, here.)  The alloc
- * is likely to fail.  Instead we do this: the first time we
- * get called, kick off a thread to do the allocation.  Return
- * immediately to the caller with EAGAIN, as an indication that
- * they should send down the ioctl again.  By the time the
- * second call comes in it's likely that the memory allocation
- * thread will have returned with the requested memory.  We will
- * continue to return EAGAIN however until the thread has completed.
- * When it has, we return zero (and the memory) if the allocator
- * was successful and ENOSR otherwise.
- *
- * Callers of the RCOMP and XCOMP ioctls are encouraged (but not
- * required) to loop for some number of iterations with a small
- * delay in the loop body (for instance a 1/10-th second "sleep"
- * via select.)
- */
-static int
-ppp_comp_wput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    struct iocblk *iop;
-    comp_state_t *cp;
-    int error, len, n;
-    int flags, mask;
-    mblk_t *np;
-    struct compressor **comp;
-    struct ppp_stats *psp;
-    struct ppp_comp_stats *csp;
-    unsigned char *opt_data;
-    int nxslots, nrslots;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_wput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-
-    case M_DATA:
-       putq(q, mp);
-       break;
-
-    case M_IOCTL:
-       iop = (struct iocblk *) mp->b_rptr;
-       error = EINVAL;
-       switch (iop->ioc_cmd) {
-
-       case PPPIO_CFLAGS:
-           /* set/get CCP state */
-           if (iop->ioc_count != 2 * sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_CFLAGS b_cont = 0!\n", cp->unit);
-               break;
-           }
-           flags = ((int *) mp->b_cont->b_rptr)[0];
-           mask = ((int *) mp->b_cont->b_rptr)[1];
-           cp->flags = (cp->flags & ~mask) | (flags & mask);
-           if ((mask & CCP_ISOPEN) && (flags & CCP_ISOPEN) == 0) {
-               if (cp->xstate != NULL) {
-                   (*cp->xcomp->comp_free)(cp->xstate);
-                   cp->xstate = NULL;
-               }
-               if (cp->rstate != NULL) {
-                   (*cp->rcomp->decomp_free)(cp->rstate);
-                   cp->rstate = NULL;
-               }
-               cp->flags &= ~CCP_ISUP;
-           }
-           error = 0;
-           iop->ioc_count = sizeof(int);
-           ((int *) mp->b_cont->b_rptr)[0] = cp->flags;
-           mp->b_cont->b_wptr = mp->b_cont->b_rptr + sizeof(int);
-           break;
-
-       case PPPIO_VJINIT:
-           /*
-            * Initialize VJ compressor/decompressor
-            */
-           if (iop->ioc_count != 2)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_VJINIT b_cont = 0!\n", cp->unit);
-               break;
-           }
-           nxslots = mp->b_cont->b_rptr[0] + 1;
-           nrslots = mp->b_cont->b_rptr[1] + 1;
-           if (nxslots > MAX_STATES || nrslots > MAX_STATES)
-               break;
-           vj_compress_init(&cp->vj_comp, nxslots);
-           cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-           error = 0;
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_XCOMP:
-       case PPPIO_RCOMP:
-           if (iop->ioc_count <= 0)
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_[XR]COMP b_cont = 0!\n", cp->unit);
-               break;
-           }
-           opt_data = mp->b_cont->b_rptr;
-           len = mp->b_cont->b_wptr - opt_data;
-           if (len > iop->ioc_count)
-               len = iop->ioc_count;
-           if (opt_data[1] < 2 || opt_data[1] > len)
-               break;
-           for (comp = ppp_compressors; *comp != NULL; ++comp)
-               if ((*comp)->compress_proto == opt_data[0]) {
-                   /* here's the handler! */
-                   error = 0;
-#ifndef __osf__
-                   if (iop->ioc_cmd == PPPIO_XCOMP) {
-                       /* A previous call may have fetched memory for a compressor
-                        * that's now being retired or reset.  Free it using it's
-                        * mechanism for freeing stuff.
-                        */
-                       if (cp->xstate != NULL) {
-                           (*cp->xcomp->comp_free)(cp->xstate);
-                           cp->xstate = NULL;
-                       }
-                       cp->xcomp = *comp;
-                       cp->xstate = (*comp)->comp_alloc(opt_data, len);
-                       if (cp->xstate == NULL)
-                           error = ENOSR;
-                   } else {
-                       if (cp->rstate != NULL) {
-                           (*cp->rcomp->decomp_free)(cp->rstate);
-                           cp->rstate = NULL;
-                       }
-                       cp->rcomp = *comp;
-                       cp->rstate = (*comp)->decomp_alloc(opt_data, len);
-                       if (cp->rstate == NULL)
-                           error = ENOSR;
-                   }
-#else
-                   if ((error = cp->memreq.thread_status) != EAGAIN)
-                   if (iop->ioc_cmd == PPPIO_XCOMP) {
-                       if (cp->xstate) {
-                           (*cp->xcomp->comp_free)(cp->xstate);
-                           cp->xstate = 0;
-                       }
-                       /* sanity check for compressor options
-                        */
-                       if (sizeof (cp->memreq.comp_opts) < len) {
-                           printf("can't handle options for compressor %d (%d)\n", opt_data[0],
-                               opt_data[1]);
-                           cp->memreq.thread_status = ENOSR;
-                           cp->memreq.returned_mem = 0;
-                       }
-                       /* fill in request for the thread and kick it off
-                        */
-                       if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
-                           bcopy(opt_data, cp->memreq.comp_opts, len);
-                           cp->memreq.cmd = PPPIO_XCOMP;
-                           cp->xcomp = *comp;
-                           error = cp->memreq.thread_status = EAGAIN;
-                           thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
-                       } else {
-                           cp->xstate = cp->memreq.returned_mem;
-                           cp->memreq.returned_mem = 0;
-                           cp->memreq.thread_status = 0;
-                       }
-                   } else {
-                       if (cp->rstate) {
-                           (*cp->rcomp->decomp_free)(cp->rstate);
-                           cp->rstate = NULL;
-                       }
-                       if (sizeof (cp->memreq.comp_opts) < len) {
-                           printf("can't handle options for compressor %d (%d)\n", opt_data[0],
-                               opt_data[1]);
-                           cp->memreq.thread_status = ENOSR;
-                           cp->memreq.returned_mem = 0;
-                       }
-                       if (cp->memreq.thread_status == 0 && !cp->memreq.returned_mem) {
-                           bcopy(opt_data, cp->memreq.comp_opts, len);
-                           cp->memreq.cmd = PPPIO_RCOMP;
-                           cp->rcomp = *comp;
-                           error = cp->memreq.thread_status = EAGAIN;
-                           thread_wakeup((vm_offset_t)&cp->memreq.thread_status);
-                       } else {
-                           cp->rstate = cp->memreq.returned_mem;
-                           cp->memreq.returned_mem = 0;
-                           cp->memreq.thread_status = 0;
-                       }
-                   }
-#endif
-                   break;
-               }
-           iop->ioc_count = 0;
-           break;
-
-       case PPPIO_GETSTAT:
-           if ((cp->flags & LAST_MOD) == 0) {
-               error = -1;     /* let the ppp_ahdl module handle it */
-               break;
-           }
-           np = allocb(sizeof(struct ppp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           psp = (struct ppp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_stats);
-           iop->ioc_count = sizeof(struct ppp_stats);
-           psp->p = cp->stats;
-           psp->vj = cp->vj_comp.stats;
-           error = 0;
-           break;
-
-       case PPPIO_GETCSTAT:
-           np = allocb(sizeof(struct ppp_comp_stats), BPRI_HI);
-           if (np == 0) {
-               error = ENOSR;
-               break;
-           }
-           if (mp->b_cont != 0)
-               freemsg(mp->b_cont);
-           mp->b_cont = np;
-           csp = (struct ppp_comp_stats *) np->b_wptr;
-           np->b_wptr += sizeof(struct ppp_comp_stats);
-           iop->ioc_count = sizeof(struct ppp_comp_stats);
-           bzero((caddr_t)csp, sizeof(struct ppp_comp_stats));
-           if (cp->xstate != 0)
-               (*cp->xcomp->comp_stat)(cp->xstate, &csp->c);
-           if (cp->rstate != 0)
-               (*cp->rcomp->decomp_stat)(cp->rstate, &csp->d);
-           error = 0;
-           break;
-
-       case PPPIO_DEBUG:
-           if (iop->ioc_count != sizeof(int))
-               break;
-           if (mp->b_cont == 0) {
-               DPRINT1("ppp_comp_wput/%d: PPPIO_DEBUG b_cont = 0!\n", cp->unit);
-               break;
-           }
-           n = *(int *)mp->b_cont->b_rptr;
-           if (n == PPPDBG_LOG + PPPDBG_COMP) {
-               DPRINT1("ppp_comp%d: debug log enabled\n", cp->unit);
-               cp->flags |= DBGLOG;
-               error = 0;
-               iop->ioc_count = 0;
-           } else {
-               error = -1;
-           }
-           break;
-
-       case PPPIO_LASTMOD:
-           cp->flags |= LAST_MOD;
-           error = 0;
-           break;
-
-       default:
-           error = -1;
-           break;
-       }
-
-       if (error < 0)
-           putnext(q, mp);
-       else if (error == 0) {
-           mp->b_datap->db_type = M_IOCACK;
-           qreply(q, mp);
-       } else {
-           mp->b_datap->db_type = M_IOCNAK;
-           iop->ioc_error = error;
-           iop->ioc_count = 0;
-           qreply(q, mp);
-       }
-       break;
-
-    case M_CTL:
-       switch (*mp->b_rptr) {
-       case PPPCTL_MTU:
-           cp->mtu = ((unsigned short *)mp->b_rptr)[1];
-           break;
-       case PPPCTL_MRU:
-           cp->mru = ((unsigned short *)mp->b_rptr)[1];
-           break;
-       case PPPCTL_UNIT:
-           cp->unit = mp->b_rptr[1];
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_wsrv(q)
-    queue_t *q;
-{
-    mblk_t *mp, *cmp = NULL;
-    comp_state_t *cp;
-    int len, proto, type, hlen, code;
-    struct ip *ip;
-    unsigned char *vjhdr, *dp;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_wsrv\n");
-       return 0;
-    }
-
-    while ((mp = getq(q)) != 0) {
-       /* assert(mp->b_datap->db_type == M_DATA) */
-#ifdef PRIOQ
-        if (!bcanputnext(q,mp->b_band))
-#else
-        if (!canputnext(q))
-#endif /* PRIOQ */
-       {
-           putbq(q, mp);
-           break;
-       }
-
-       /*
-        * First check the packet length and work out what the protocol is.
-        */
-       len = msgdsize(mp);
-       if (len < PPP_HDRLEN) {
-           DPRINT1("ppp_comp_wsrv: bogus short packet (%d)\n", len);
-           freemsg(mp);
-           cp->stats.ppp_oerrors++;
-           putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-           continue;
-       }
-       proto = (MSG_BYTE(mp, 2) << 8) + MSG_BYTE(mp, 3);
-
-       /*
-        * Make sure we've got enough data in the first mblk
-        * and that we are its only user.
-        */
-       if (proto == PPP_CCP)
-           hlen = len;
-       else if (proto == PPP_IP)
-           hlen = PPP_HDRLEN + MAX_IPHDR;
-       else
-           hlen = PPP_HDRLEN;
-       if (hlen > len)
-           hlen = len;
-       if (mp->b_wptr < mp->b_rptr + hlen || mp->b_datap->db_ref > 1) {
-           PULLUP(mp, hlen);
-           if (mp == 0) {
-               DPRINT1("ppp_comp_wsrv: pullup failed (%d)\n", hlen);
-               cp->stats.ppp_oerrors++;
-               putctl1(RD(q)->q_next, M_CTL, PPPCTL_OERROR);
-               continue;
-           }
-       }
-
-       /*
-        * Do VJ compression if requested.
-        */
-       if (proto == PPP_IP && (cp->flags & COMP_VJC)) {
-           ip = (struct ip *) (mp->b_rptr + PPP_HDRLEN);
-           if (ip->ip_p == IPPROTO_TCP) {
-               type = vj_compress_tcp(ip, len - PPP_HDRLEN, &cp->vj_comp,
-                                      (cp->flags & COMP_VJCCID), &vjhdr);
-               switch (type) {
-               case TYPE_UNCOMPRESSED_TCP:
-                   mp->b_rptr[3] = proto = PPP_VJC_UNCOMP;
-                   break;
-               case TYPE_COMPRESSED_TCP:
-                   dp = vjhdr - PPP_HDRLEN;
-                   dp[1] = mp->b_rptr[1]; /* copy control field */
-                   dp[0] = mp->b_rptr[0]; /* copy address field */
-                   dp[2] = 0;             /* set protocol field */
-                   dp[3] = proto = PPP_VJC_COMP;
-                   mp->b_rptr = dp;
-                   break;
-               }
-           }
-       }
-
-       /*
-        * Do packet compression if enabled.
-        */
-       if (proto == PPP_CCP)
-           ppp_comp_ccp(q, mp, 0);
-       else if (proto != PPP_LCP && (cp->flags & CCP_COMP_RUN)
-                && cp->xstate != NULL) {
-           len = msgdsize(mp);
-           (*cp->xcomp->compress)(cp->xstate, &cmp, mp, len,
-                       (cp->flags & CCP_ISUP? cp->mtu + PPP_HDRLEN: 0));
-           if (cmp != NULL) {
-#ifdef PRIOQ
-               cmp->b_band=mp->b_band;
-#endif /* PRIOQ */
-               freemsg(mp);
-               mp = cmp;
-           }
-       }
-
-       /*
-        * Do address/control and protocol compression if enabled.
-        */
-       if ((cp->flags & COMP_AC)
-           && !(proto == PPP_LCP && LCP_USE_DFLT(mp))) {
-           mp->b_rptr += 2;    /* drop the address & ctrl fields */
-           if (proto < 0x100 && (cp->flags & COMP_PROT))
-               ++mp->b_rptr;   /* drop the high protocol byte */
-       } else if (proto < 0x100 && (cp->flags & COMP_PROT)) {
-           /* shuffle up the address & ctrl fields */
-           mp->b_rptr[2] = mp->b_rptr[1];
-           mp->b_rptr[1] = mp->b_rptr[0];
-           ++mp->b_rptr;
-       }
-
-       cp->stats.ppp_opackets++;
-       cp->stats.ppp_obytes += msgdsize(mp);
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_rput(q, mp)
-    queue_t *q;
-    mblk_t *mp;
-{
-    comp_state_t *cp;
-    struct iocblk *iop;
-    struct ppp_stats *psp;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_rput\n");
-       freemsg(mp);
-       return 0;
-    }
-
-    switch (mp->b_datap->db_type) {
-
-    case M_DATA:
-       putq(q, mp);
-       break;
-
-    case M_IOCACK:
-       iop = (struct iocblk *) mp->b_rptr;
-       switch (iop->ioc_cmd) {
-       case PPPIO_GETSTAT:
-           /*
-            * Catch this on the way back from the ppp_ahdl module
-            * so we can fill in the VJ stats.
-            */
-           if (mp->b_cont == 0 || iop->ioc_count != sizeof(struct ppp_stats))
-               break;
-           psp = (struct ppp_stats *) mp->b_cont->b_rptr;
-           psp->vj = cp->vj_comp.stats;
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    case M_CTL:
-       switch (mp->b_rptr[0]) {
-       case PPPCTL_IERROR:
-           ++cp->stats.ppp_ierrors;
-           break;
-       case PPPCTL_OERROR:
-           ++cp->stats.ppp_oerrors;
-           break;
-       }
-       putnext(q, mp);
-       break;
-
-    default:
-       putnext(q, mp);
-    }
-
-    return 0;
-}
-
-static int
-ppp_comp_rsrv(q)
-    queue_t *q;
-{
-    int proto, rv, i;
-    mblk_t *mp, *dmp = NULL, *np;
-    uchar_t *dp, *iphdr;
-    comp_state_t *cp;
-    int len, hlen, vjlen;
-    u_int iphlen;
-
-    cp = (comp_state_t *) q->q_ptr;
-    if (cp == 0) {
-       DPRINT("cp == 0 in ppp_comp_rsrv\n");
-       return 0;
-    }
-
-    while ((mp = getq(q)) != 0) {
-       /* assert(mp->b_datap->db_type == M_DATA) */
-       if (!canputnext(q)) {
-           putbq(q, mp);
-           break;
-       }
-
-       len = msgdsize(mp);
-       cp->stats.ppp_ibytes += len;
-       cp->stats.ppp_ipackets++;
-
-       /*
-        * First work out the protocol and where the PPP header ends.
-        */
-       i = 0;
-       proto = MSG_BYTE(mp, 0);
-       if (proto == PPP_ALLSTATIONS) {
-           i = 2;
-           proto = MSG_BYTE(mp, 2);
-       }
-       if ((proto & 1) == 0) {
-           ++i;
-           proto = (proto << 8) + MSG_BYTE(mp, i);
-       }
-       hlen = i + 1;
-
-       /*
-        * Now reconstruct a complete, contiguous PPP header at the
-        * start of the packet.
-        */
-       if (hlen < ((cp->flags & DECOMP_AC)? 0: 2)
-                  + ((cp->flags & DECOMP_PROT)? 1: 2)) {
-           /* count these? */
-           goto bad;
-       }
-       if (mp->b_rptr + hlen > mp->b_wptr) {
-           adjmsg(mp, hlen);   /* XXX check this call */
-           hlen = 0;
-       }
-       if (hlen != PPP_HDRLEN) {
-           /*
-            * We need to put some bytes on the front of the packet
-            * to make a full-length PPP header.
-            * If we can put them in *mp, we do, otherwise we
-            * tack another mblk on the front.
-            * XXX we really shouldn't need to carry around
-            * the address and control at this stage.
-            */
-           dp = mp->b_rptr + hlen - PPP_HDRLEN;
-           if (dp < mp->b_datap->db_base || mp->b_datap->db_ref > 1) {
-               np = allocb(PPP_HDRLEN, BPRI_MED);
-               if (np == 0)
-                   goto bad;
-               np->b_cont = mp;
-               mp->b_rptr += hlen;
-               mp = np;
-               dp = mp->b_wptr;
-               mp->b_wptr += PPP_HDRLEN;
-           } else
-               mp->b_rptr = dp;
-
-           dp[0] = PPP_ALLSTATIONS;
-           dp[1] = PPP_UI;
-           dp[2] = proto >> 8;
-           dp[3] = proto;
-       }
-
-       /*
-        * Now see if we have a compressed packet to decompress,
-        * or a CCP packet to take notice of.
-        */
-       proto = PPP_PROTOCOL(mp->b_rptr);
-       if (proto == PPP_CCP) {
-           len = msgdsize(mp);
-           if (mp->b_wptr < mp->b_rptr + len) {
-               PULLUP(mp, len);
-               if (mp == 0)
-                   goto bad;
-           }
-           ppp_comp_ccp(q, mp, 1);
-       } else if (proto == PPP_COMP) {
-           if ((cp->flags & CCP_ISUP)
-               && (cp->flags & CCP_DECOMP_RUN) && cp->rstate
-               && (cp->flags & CCP_ERR) == 0) {
-               rv = (*cp->rcomp->decompress)(cp->rstate, mp, &dmp);
-               switch (rv) {
-               case DECOMP_OK:
-                   freemsg(mp);
-                   mp = dmp;
-                   if (mp == NULL) {
-                       /* no error, but no packet returned either. */
-                       continue;
-                   }
-                   break;
-               case DECOMP_ERROR:
-                   cp->flags |= CCP_ERROR;
-                   ++cp->stats.ppp_ierrors;
-                   putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-                   break;
-               case DECOMP_FATALERROR:
-                   cp->flags |= CCP_FATALERROR;
-                   ++cp->stats.ppp_ierrors;
-                   putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-                   break;
-               }
-           }
-       } else if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
-           (*cp->rcomp->incomp)(cp->rstate, mp);
-       }
-
-       /*
-        * Now do VJ decompression.
-        */
-       proto = PPP_PROTOCOL(mp->b_rptr);
-       if (proto == PPP_VJC_COMP || proto == PPP_VJC_UNCOMP) {
-           len = msgdsize(mp) - PPP_HDRLEN;
-           if ((cp->flags & DECOMP_VJC) == 0 || len <= 0)
-               goto bad;
-
-           /*
-            * Advance past the ppp header.
-            * Here we assume that the whole PPP header is in the first mblk.
-            */
-           np = mp;
-           dp = np->b_rptr + PPP_HDRLEN;
-           if (dp >= mp->b_wptr) {
-               np = np->b_cont;
-               dp = np->b_rptr;
-           }
-
-           /*
-            * Make sure we have sufficient contiguous data at this point.
-            */
-           hlen = (proto == PPP_VJC_COMP)? MAX_VJHDR: MAX_IPHDR;
-           if (hlen > len)
-               hlen = len;
-           if (np->b_wptr < dp + hlen || np->b_datap->db_ref > 1) {
-               PULLUP(mp, hlen + PPP_HDRLEN);
-               if (mp == 0)
-                   goto bad;
-               np = mp;
-               dp = np->b_rptr + PPP_HDRLEN;
-           }
-
-           if (proto == PPP_VJC_COMP) {
-               /*
-                * Decompress VJ-compressed packet.
-                * First reset compressor if an input error has occurred.
-                */
-               if (cp->stats.ppp_ierrors != cp->vj_last_ierrors) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT1("ppp%d: resetting VJ\n", cp->unit);
-                   vj_uncompress_err(&cp->vj_comp);
-                   cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-               }
-
-               vjlen = vj_uncompress_tcp(dp, np->b_wptr - dp, len,
-                                         &cp->vj_comp, &iphdr, &iphlen);
-               if (vjlen < 0) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT2("ppp%d: vj_uncomp_tcp failed, pkt len %d\n",
-                               cp->unit, len);
-                   ++cp->vj_last_ierrors;  /* so we don't reset next time */
-                   goto bad;
-               }
-
-               /* drop ppp and vj headers off */
-               if (mp != np) {
-                   freeb(mp);
-                   mp = np;
-               }
-               mp->b_rptr = dp + vjlen;
-
-               /* allocate a new mblk for the ppp and ip headers */
-               if ((np = allocb(iphlen + PPP_HDRLEN + 4, BPRI_MED)) == 0)
-                   goto bad;
-               dp = np->b_rptr;        /* prepend mblk with TCP/IP hdr */
-               dp[0] = PPP_ALLSTATIONS; /* reconstruct PPP header */
-               dp[1] = PPP_UI;
-               dp[2] = PPP_IP >> 8;
-               dp[3] = PPP_IP;
-               bcopy((caddr_t)iphdr, (caddr_t)dp + PPP_HDRLEN, iphlen);
-               np->b_wptr = dp + iphlen + PPP_HDRLEN;
-               np->b_cont = mp;
-
-               /* XXX there seems to be a bug which causes panics in strread
-                  if we make an mbuf with only the IP header in it :-( */
-               if (mp->b_wptr - mp->b_rptr > 4) {
-                   bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr, 4);
-                   mp->b_rptr += 4;
-                   np->b_wptr += 4;
-               } else {
-                   bcopy((caddr_t)mp->b_rptr, (caddr_t)np->b_wptr,
-                         mp->b_wptr - mp->b_rptr);
-                   np->b_wptr += mp->b_wptr - mp->b_rptr;
-                   np->b_cont = mp->b_cont;
-                   freeb(mp);
-               }
-
-               mp = np;
-
-           } else {
-               /*
-                * "Decompress" a VJ-uncompressed packet.
-                */
-               cp->vj_last_ierrors = cp->stats.ppp_ierrors;
-               if (!vj_uncompress_uncomp(dp, hlen, &cp->vj_comp)) {
-                   if (cp->flags & DBGLOG)
-                       DPRINT2("ppp%d: vj_uncomp_uncomp failed, pkt len %d\n",
-                               cp->unit, len);
-                   ++cp->vj_last_ierrors;  /* don't need to reset next time */
-                   goto bad;
-               }
-               mp->b_rptr[3] = PPP_IP; /* fix up the PPP protocol field */
-           }
-       }
-
-       putnext(q, mp);
-       continue;
-
-    bad:
-       if (mp != 0)
-           freemsg(mp);
-       cp->stats.ppp_ierrors++;
-       putctl1(q->q_next, M_CTL, PPPCTL_IERROR);
-    }
-
-    return 0;
-}
-
-/*
- * Handle a CCP packet being sent or received.
- * Here all the data in the packet is in a single mbuf.
- */
-static void
-ppp_comp_ccp(q, mp, rcvd)
-    queue_t *q;
-    mblk_t *mp;
-    int rcvd;
-{
-    int len, clen;
-    comp_state_t *cp;
-    unsigned char *dp;
-
-    len = msgdsize(mp);
-    if (len < PPP_HDRLEN + CCP_HDRLEN)
-       return;
-
-    cp = (comp_state_t *) q->q_ptr;
-    dp = mp->b_rptr + PPP_HDRLEN;
-    len -= PPP_HDRLEN;
-    clen = CCP_LENGTH(dp);
-    if (clen > len)
-       return;
-
-    switch (CCP_CODE(dp)) {
-    case CCP_CONFREQ:
-    case CCP_TERMREQ:
-    case CCP_TERMACK:
-       cp->flags &= ~CCP_ISUP;
-       break;
-
-    case CCP_CONFACK:
-       if ((cp->flags & (CCP_ISOPEN | CCP_ISUP)) == CCP_ISOPEN
-           && clen >= CCP_HDRLEN + CCP_OPT_MINLEN
-           && clen >= CCP_HDRLEN + CCP_OPT_LENGTH(dp + CCP_HDRLEN)) {
-           if (!rcvd) {
-               if (cp->xstate != NULL
-                   && (*cp->xcomp->comp_init)
-                       (cp->xstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
-                        cp->unit, 0, ((cp->flags & DBGLOG) != 0)))
-                   cp->flags |= CCP_COMP_RUN;
-           } else {
-               if (cp->rstate != NULL
-                   && (*cp->rcomp->decomp_init)
-                       (cp->rstate, dp + CCP_HDRLEN, clen - CCP_HDRLEN,
-                        cp->unit, 0, cp->mru, ((cp->flags & DBGLOG) != 0)))
-                   cp->flags = (cp->flags & ~CCP_ERR) | CCP_DECOMP_RUN;
-           }
-       }
-       break;
-
-    case CCP_RESETACK:
-       if (cp->flags & CCP_ISUP) {
-           if (!rcvd) {
-               if (cp->xstate && (cp->flags & CCP_COMP_RUN))
-                   (*cp->xcomp->comp_reset)(cp->xstate);
-           } else {
-               if (cp->rstate && (cp->flags & CCP_DECOMP_RUN)) {
-                   (*cp->rcomp->decomp_reset)(cp->rstate);
-                   cp->flags &= ~CCP_ERROR;
-               }
-           }
-       }
-       break;
-    }
-}
-
-#if 0
-dump_msg(mp)
-    mblk_t *mp;
-{
-    dblk_t *db;
-
-    while (mp != 0) {
-       db = mp->b_datap;
-       DPRINT2("mp=%x cont=%x ", mp, mp->b_cont);
-       DPRINT3("rptr=%x wptr=%x datap=%x\n", mp->b_rptr, mp->b_wptr, db);
-       DPRINT2("  base=%x lim=%x", db->db_base, db->db_lim);
-       DPRINT2(" ref=%d type=%d\n", db->db_ref, db->db_type);
-       mp = mp->b_cont;
-    }
-}
-#endif
-
-static int
-msg_byte(mp, i)
-    mblk_t *mp;
-    unsigned int i;
-{
-    while (mp != 0 && i >= mp->b_wptr - mp->b_rptr)
-       mp = mp->b_cont;
-    if (mp == 0)
-       return -1;
-    return mp->b_rptr[i];
-}
diff --git a/solaris/ppp_comp_mod.c b/solaris/ppp_comp_mod.c
deleted file mode 100644 (file)
index 21ad9ae..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ppp_comp_mod.c - modload support for PPP compression STREAMS module.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp_comp_mod.c,v 1.2 2002/12/06 09:49:16 paulus Exp $
- */
-
-/*
- * This file is used under Solaris 2.
- */
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/conf.h>
-#include <sys/modctl.h>
-#include <sys/sunddi.h>
-
-extern struct streamtab ppp_compinfo;
-
-static struct fmodsw fsw = {
-    "ppp_comp",
-    &ppp_compinfo,
-    D_NEW | D_MP | D_MTQPAIR
-};
-
-extern struct mod_ops mod_strmodops;
-
-static struct modlstrmod modlstrmod = {
-    &mod_strmodops,
-    "PPP compression module",
-    &fsw
-};
-
-static struct modlinkage modlinkage = {
-    MODREV_1,
-    (void *) &modlstrmod,
-    NULL
-};
-
-/*
- * Entry points for modloading.
- */
-int
-_init(void)
-{
-    return mod_install(&modlinkage);
-}
-
-int
-_fini(void)
-{
-    return mod_remove(&modlinkage);
-}
-
-int
-_info(mip)
-    struct modinfo *mip;
-{
-    return mod_info(&modlinkage, mip);
-}
diff --git a/solaris/ppp_mod.c b/solaris/ppp_mod.c
deleted file mode 100644 (file)
index d1bf025..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * ppp_mod.c - modload support for PPP pseudo-device driver.
- *
- * Copyright (c) 1994 Paul Mackerras. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The name(s) of the authors of this software must not be used to
- *    endorse or promote products derived from this software without
- *    prior written permission.
- *
- * 4. Redistributions of any form whatsoever must retain the following
- *    acknowledgment:
- *    "This product includes software developed by Paul Mackerras
- *     <paulus@samba.org>".
- *
- * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * $Id: ppp_mod.c,v 1.3 2004/01/17 05:47:55 carlsonj Exp $
- */
-
-/*
- * This file is used under Solaris 2.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/conf.h>
-#include <sys/modctl.h>
-#include <sys/sunddi.h>
-#include <sys/ksynch.h>
-
-static int ppp_identify(dev_info_t *);
-static int ppp_attach(dev_info_t *, ddi_attach_cmd_t);
-static int ppp_detach(dev_info_t *, ddi_detach_cmd_t);
-static int ppp_devinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
-
-extern struct streamtab pppinfo;
-extern krwlock_t ppp_lower_lock;
-
-static dev_info_t *ppp_dip;
-
-static struct cb_ops cb_ppp_ops = {
-    nulldev, nulldev, nodev, nodev,    /* cb_open, ... */
-    nodev, nodev, nodev, nodev,                /* cb_dump, ... */
-    nodev, nodev, nodev, nochpoll,     /* cb_devmap, ... */
-    ddi_prop_op,                       /* cb_prop_op */
-    &pppinfo,                          /* cb_stream */
-    D_NEW|D_MP|D_MTQPAIR|D_MTOUTPERIM|D_MTOCEXCL       /* cb_flag */
-};
-
-static struct dev_ops ppp_ops = {
-    DEVO_REV,                          /* devo_rev */
-    0,                                 /* devo_refcnt */
-    ppp_devinfo,                       /* devo_getinfo */
-    ppp_identify,                      /* devo_identify */
-    nulldev,                           /* devo_probe */
-    ppp_attach,                                /* devo_attach */
-    ppp_detach,                                /* devo_detach */
-    nodev,                             /* devo_reset */
-    &cb_ppp_ops,                       /* devo_cb_ops */
-    NULL                               /* devo_bus_ops */
-};
-
-/*
- * Module linkage information
- */
-
-static struct modldrv modldrv = {
-    &mod_driverops,                    /* says this is a pseudo driver */
-    "PPP-2.4.7 multiplexing driver",
-    &ppp_ops                           /* driver ops */
-};
-
-static struct modlinkage modlinkage = {
-    MODREV_1,
-    (void *) &modldrv,
-    NULL
-};
-
-int
-_init(void)
-{
-    return mod_install(&modlinkage);
-}
-
-int
-_fini(void)
-{
-    return mod_remove(&modlinkage);
-}
-
-int
-_info(mip)
-    struct modinfo *mip;
-{
-    return mod_info(&modlinkage, mip);
-}
-
-static int
-ppp_identify(dip)
-    dev_info_t *dip;
-{
-    /* This entry point is not used as of Solaris 10 */
-#ifdef DDI_IDENTIFIED
-    return strcmp(ddi_get_name(dip), "ppp") == 0? DDI_IDENTIFIED:
-       DDI_NOT_IDENTIFIED;
-#else
-    return 0;
-#endif
-}
-
-static int
-ppp_attach(dip, cmd)
-    dev_info_t *dip;
-    ddi_attach_cmd_t cmd;
-{
-
-    if (cmd != DDI_ATTACH)
-       return DDI_FAILURE;
-    if (ddi_create_minor_node(dip, "ppp", S_IFCHR, 0, DDI_PSEUDO, CLONE_DEV)
-       == DDI_FAILURE) {
-       ddi_remove_minor_node(dip, NULL);
-       return DDI_FAILURE;
-    }
-    rw_init(&ppp_lower_lock, NULL, RW_DRIVER, NULL);
-    return DDI_SUCCESS;
-}
-
-static int
-ppp_detach(dip, cmd)
-    dev_info_t *dip;
-    ddi_detach_cmd_t cmd;
-{
-    rw_destroy(&ppp_lower_lock);
-    ddi_remove_minor_node(dip, NULL);
-    return DDI_SUCCESS;
-}
-
-static int
-ppp_devinfo(dip, cmd, arg, result)
-    dev_info_t *dip;
-    ddi_info_cmd_t cmd;
-    void *arg;
-    void **result;
-{
-    int error;
-
-    error = DDI_SUCCESS;
-    switch (cmd) {
-    case DDI_INFO_DEVT2DEVINFO:
-       if (ppp_dip == NULL)
-           error = DDI_FAILURE;
-       else
-           *result = (void *) ppp_dip;
-       break;
-    case DDI_INFO_DEVT2INSTANCE:
-       *result = NULL;
-       break;
-    default:
-       error = DDI_FAILURE;
-    }
-    return error;
-}
diff --git a/solaris/ppp_mod.h b/solaris/ppp_mod.h
deleted file mode 100644 (file)
index 792c4d4..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Miscellaneous definitions for PPP STREAMS modules.
- */
-
-/*
- * Macros for allocating and freeing kernel memory.
- */
-#ifdef SVR4                    /* SVR4, including Solaris 2 */
-#include <sys/kmem.h>
-#define ALLOC_SLEEP(n)         kmem_alloc((n), KM_SLEEP)
-#define ALLOC_NOSLEEP(n)       kmem_alloc((n), KM_NOSLEEP)
-#define FREE(p, n)             kmem_free((p), (n))
-#endif
-
-#ifdef SUNOS4
-#include <sys/kmem_alloc.h>    /* SunOS 4.x */
-#define ALLOC_SLEEP(n)         kmem_alloc((n), KMEM_SLEEP)
-#define ALLOC_NOSLEEP(n)       kmem_alloc((n), KMEM_NOSLEEP)
-#define FREE(p, n)             kmem_free((p), (n))
-#define NOTSUSER()             (suser()? 0: EPERM)
-#define bcanputnext(q, band)   canputnext((q))
-#endif /* SunOS 4 */
-
-#ifdef __osf__
-#include <sys/malloc.h>
-
-/* caution: this mirrors macros in sys/malloc.h, and uses interfaces
- * which are subject to change.
- * The problems are that:
- *     - the official MALLOC macro wants the lhs of the assignment as an argument,
- *      and it takes care of the assignment itself (yuck.)
- *     - PPP insists on using "FREE" which conflicts with a macro of the same name.
- *
- */
-#ifdef BUCKETINDX /* V2.0 */
-#define ALLOC_SLEEP(n)         (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_WAITOK)
-#define ALLOC_NOSLEEP(n)       (void *)malloc((u_long)(n), BUCKETP(n), M_DEVBUF, M_NOWAIT)
-#else
-#define ALLOC_SLEEP(n)         (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_WAITOK)
-#define ALLOC_NOSLEEP(n)       (void *)malloc((u_long)(n), BUCKETINDEX(n), M_DEVBUF, M_NOWAIT)
-#endif
-
-#define bcanputnext(q, band)   canputnext((q))
-
-#ifdef FREE
-#undef FREE
-#endif
-#define FREE(p, n)             free((void *)(p), M_DEVBUF)
-
-#define NO_DLPI 1
-
-#ifndef IFT_PPP
-#define IFT_PPP 0x17
-#endif
-
-#include <sys/proc.h>
-#define NOTSUSER()             (suser(u.u_procp->p_rcred, &u.u_acflag) ? EPERM : 0)
-
-/* #include "ppp_osf.h" */
-
-#endif /* __osf__ */
-
-#ifdef AIX4
-#define ALLOC_SLEEP(n)         xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
-#define ALLOC_NOSLEEP(n)       xmalloc((n), 0, pinned_heap)    /* AIX V4.x */
-#define FREE(p, n)             xmfree((p), pinned_heap)
-#define NOTSUSER()             (suser()? 0: EPERM)
-#endif /* AIX */
-
-/*
- * Macros for printing debugging stuff.
- */
-#ifdef DEBUG
-#if defined(SVR4) || defined(__osf__)
-#if defined(SNI)
-#include <sys/strlog.h>
-#define STRLOG_ID              4712
-#define DPRINT(f)              strlog(STRLOG_ID, 0, 0, SL_TRACE, f)
-#define DPRINT1(f, a1)         strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1)
-#define DPRINT2(f, a1, a2)     strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) strlog(STRLOG_ID, 0, 0, SL_TRACE, f, a1, a2, a3)
-#else
-#define DPRINT(f)              cmn_err(CE_CONT, f)
-#define DPRINT1(f, a1)         cmn_err(CE_CONT, f, a1)
-#define DPRINT2(f, a1, a2)     cmn_err(CE_CONT, f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) cmn_err(CE_CONT, f, a1, a2, a3)
-#endif /* SNI */
-#else
-#define DPRINT(f)              printf(f)
-#define DPRINT1(f, a1)         printf(f, a1)
-#define DPRINT2(f, a1, a2)     printf(f, a1, a2)
-#define DPRINT3(f, a1, a2, a3) printf(f, a1, a2, a3)
-#endif /* SVR4 or OSF */
-
-#else
-#define DPRINT(f)              0
-#define DPRINT1(f, a1)         0
-#define DPRINT2(f, a1, a2)     0
-#define DPRINT3(f, a1, a2, a3) 0
-#endif /* DEBUG */
-
-#ifndef SVR4
-typedef unsigned char uchar_t;
-typedef unsigned short ushort_t;
-#ifndef __osf__
-typedef int minor_t;
-#endif
-#endif
-
-/*
- * If we don't have multithreading support, define substitutes.
- */
-#ifndef D_MP
-# define qprocson(q)
-# define qprocsoff(q)
-# define put(q, mp)    ((*(q)->q_qinfo->qi_putp)((q), (mp)))
-# define canputnext(q) canput((q)->q_next)
-# define qwriter(q, mp, func, scope)   (func)((q), (mp))
-#endif
-
-#ifdef D_MP
-/* Use msgpullup if we have other multithreading support. */
-#define PULLUP(mp, len)                                \
-    do {                                       \
-       mblk_t *np = msgpullup((mp), (len));    \
-       freemsg((mp));                          \
-       mp = np;                                \
-    } while (0)
-
-#else
-/* Use pullupmsg if we don't have any multithreading support. */
-#define PULLUP(mp, len)                        \
-    do {                               \
-       if (!pullupmsg((mp), (len))) {  \
-           freemsg((mp));              \
-           mp = 0;                     \
-       }                               \
-    } while (0)
-#endif
-
-/*
- * How to declare the open and close procedures for a module.
- */
-#ifdef SVR4
-#define MOD_OPEN_DECL(name)    \
-static int name(queue_t *, dev_t *, int, int, cred_t *)
-
-#define MOD_CLOSE_DECL(name)   \
-static int name(queue_t *, int, cred_t *)
-
-#define MOD_OPEN(name)                         \
-static int name(q, devp, flag, sflag, credp)   \
-    queue_t *q;                                        \
-    dev_t *devp;                               \
-    int flag, sflag;                           \
-    cred_t *credp;
-
-#define MOD_CLOSE(name)                \
-static int name(q, flag, credp)        \
-    queue_t *q;                        \
-    int flag;                  \
-    cred_t *credp;
-
-#define OPEN_ERROR(x)          return (x)
-#define DRV_OPEN_OK(dev)       return 0
-
-#define NOTSUSER()             (drv_priv(credp))
-
-#else  /* not SVR4 */
-#define MOD_OPEN_DECL(name)    \
-static int name(queue_t *, int, int, int)
-
-#define MOD_CLOSE_DECL(name)   \
-static int name(queue_t *, int)
-
-#define MOD_OPEN(name)         \
-static int name(q, dev, flag, sflag)   \
-    queue_t *q;                                \
-    int dev;                           \
-    int flag, sflag;
-
-#define MOD_CLOSE(name)                \
-static int name(q, flag)       \
-    queue_t *q;                        \
-    int flag;
-
-#define OPEN_ERROR(x)          { u.u_error = (x); return OPENFAIL; }
-#define DRV_OPEN_OK(dev)       return (dev)
-
-#endif /* SVR4 */