diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 9b17144b..d96ab99f 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -126,7 +126,9 @@ #include "cbcp.h" #endif +#if 0 /* UNUSED */ #include "session.h" +#endif /* UNUSED */ #if 0 /* UNUSED */ /* Bits in scan_authfile return value */ @@ -1001,7 +1003,12 @@ continue_networks(unit) */ for (i = 0; (protp = protocols[i]) != NULL; ++i) if (protp->protocol < 0xC000 - && protp->protocol != PPP_CCP && protp->protocol != PPP_ECP +#if CCP_SUPPORT + && protp->protocol != PPP_CCP +#endif /* CCP_SUPPORT */ +#if ECP_SUPPORT + && protp->protocol != PPP_ECP +#endif /* ECP_SUPPORT */ && protp->enabled_flag && protp->open != NULL) { (*protp->open)(0); ++num_np_open; diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index e3520bb6..c92ab19d 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -40,7 +40,10 @@ #include "ppp.h" +#if 0 /* UNUSED */ #include "session.h" +#endif /* UNUSED */ + #include "chap-new.h" #include "chap-md5.h" diff --git a/src/netif/ppp/linux/if_ppp.h b/src/netif/ppp/linux/if_ppp.h deleted file mode 100644 index 1101fc78..00000000 --- a/src/netif/ppp/linux/if_ppp.h +++ /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_ */ diff --git a/src/netif/ppp/linux/if_pppol2tp.h b/src/netif/ppp/linux/if_pppol2tp.h deleted file mode 100644 index 7ee86b24..00000000 --- a/src/netif/ppp/linux/if_pppol2tp.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Linux PPP over L2TP (PPPoL2TP) Socket Implementation (RFC 2661) - * - * This file supplies definitions required by the PPP over L2TP driver - * (l2tp_ppp.c). All version information wrt this file is located in l2tp_ppp.c - * - * License: - * 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. - * - */ - -#ifndef __LINUX_IF_PPPOL2TP_H -#define __LINUX_IF_PPPOL2TP_H - -#include - - -/* Structure used to connect() the socket to a particular tunnel UDP - * socket. - */ -struct pppol2tp_addr { - __kernel_pid_t pid; /* pid that owns the fd. - * 0 => current */ - int fd; /* FD of UDP socket to use */ - - struct sockaddr_in addr; /* IP address and port to send to */ - - __u16 s_tunnel, s_session; /* For matching incoming packets */ - __u16 d_tunnel, d_session; /* For sending outgoing packets */ -}; - -/* The L2TPv3 protocol changes tunnel and session ids from 16 to 32 - * bits. So we need a different sockaddr structure. - */ -struct pppol2tpv3_addr { - pid_t pid; /* pid that owns the fd. - * 0 => current */ - int fd; /* FD of UDP or IP socket to use */ - - struct sockaddr_in addr; /* IP address and port to send to */ - - __u32 s_tunnel, s_session; /* For matching incoming packets */ - __u32 d_tunnel, d_session; /* For sending outgoing packets */ -}; - -/* Socket options: - * DEBUG - bitmask of debug message categories - * SENDSEQ - 0 => don't send packets with sequence numbers - * 1 => send packets with sequence numbers - * RECVSEQ - 0 => receive packet sequence numbers are optional - * 1 => drop receive packets without sequence numbers - * LNSMODE - 0 => act as LAC. - * 1 => act as LNS. - * REORDERTO - reorder timeout (in millisecs). If 0, don't try to reorder. - */ -enum { - PPPOL2TP_SO_DEBUG = 1, - PPPOL2TP_SO_RECVSEQ = 2, - PPPOL2TP_SO_SENDSEQ = 3, - PPPOL2TP_SO_LNSMODE = 4, - PPPOL2TP_SO_REORDERTO = 5, -}; - -/* Debug message categories for the DEBUG socket option */ -enum { - PPPOL2TP_MSG_DEBUG = (1 << 0), /* verbose debug (if - * compiled in) */ - PPPOL2TP_MSG_CONTROL = (1 << 1), /* userspace - kernel - * interface */ - PPPOL2TP_MSG_SEQ = (1 << 2), /* sequence numbers */ - PPPOL2TP_MSG_DATA = (1 << 3), /* data packets */ -}; - - - -#endif diff --git a/src/netif/ppp/linux/ppp-comp.h b/src/netif/ppp/linux/ppp-comp.h deleted file mode 100644 index d30cacbd..00000000 --- a/src/netif/ppp/linux/ppp-comp.h +++ /dev/null @@ -1,213 +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 - * ". - * - * 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.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 -#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. - */ - -struct compressor { - int compress_proto; /* CCP compression protocol number */ - - /* Allocate space for a compressor (transmit side) */ - void *(*comp_alloc) (unsigned char *options, int opt_len); - - /* Free space used by a compressor */ - void (*comp_free) (void *state); - - /* Initialize a compressor */ - int (*comp_init) (void *state, unsigned char *options, - int opt_len, int unit, int opthdr, int debug); - - /* Reset a compressor */ - void (*comp_reset) (void *state); - - /* Compress a packet */ - int (*compress) (void *state, unsigned char *rptr, - unsigned char *obuf, int isize, int osize); - - /* Return compression statistics */ - void (*comp_stat) (void *state, struct compstat *stats); - - /* Allocate space for a decompressor (receive side) */ - void *(*decomp_alloc) (unsigned char *options, int opt_len); - - /* Free space used by a decompressor */ - void (*decomp_free) (void *state); - - /* Initialize a decompressor */ - int (*decomp_init) (void *state, unsigned char *options, - int opt_len, int unit, int opthdr, int mru, - int debug); - - /* Reset a decompressor */ - void (*decomp_reset) (void *state); - - /* Decompress a packet. */ - int (*decompress) (void *state, unsigned char *ibuf, int isize, - unsigned char *obuf, int osize); - - /* Update state for an incompressible packet received */ - void (*incomp) (void *state, unsigned char *ibuf, int icnt); - - /* Return decompression statistics */ - void (*decomp_stat) (void *state, struct compstat *stats); -}; - -/* - * The return value from decompress routine is the length of the - * decompressed packet if successful, otherwise DECOMP_ERROR - * or DECOMP_FATALERROR if an error occurred. - * - * We need to make this distinction 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_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/src/netif/ppp/linux/ppp_defs.h b/src/netif/ppp/linux/ppp_defs.h deleted file mode 100644 index 314339e9..00000000 --- a/src/netif/ppp/linux/ppp_defs.h +++ /dev/null @@ -1,195 +0,0 @@ -/* $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. - * - * 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 - * ". - * - * 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. - */ - -/* - * ==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_ - -/* - * The basic PPP frame. - */ -#define PPP_HDRLEN 4 /* octets for standard ppp header */ -#define PPP_FCSLEN 2 /* octets for FCS */ -#define PPP_MRU 1500 /* default MRU = max length of info field */ - -#define PPP_ADDRESS(p) (((__u8 *)(p))[0]) -#define PPP_CONTROL(p) (((__u8 *)(p))[1]) -#define PPP_PROTOCOL(p) ((((__u8 *)(p))[2] << 8) + ((__u8 *)(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_MP 0x3d /* Multilink protocol */ -#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ -#define PPP_COMPFRAG 0xfb /* fragment compressed below bundle */ -#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_CCPFRAG 0x80fb /* CCP at link level (below MP bundle) */ -#define PPP_CCP 0x80fd /* Compression Control Protocol */ -#define PPP_ECPFRAG 0x8055 /* ECP at link level (below MP bundle) */ -#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 */ - -/* - * 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]) - -/* - * Extended asyncmap - allows any character to be escaped. - */ - -typedef __u32 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 for LQRP and pppstats - */ -struct pppstat { - __u32 ppp_discards; /* # frames discarded */ - - __u32 ppp_ibytes; /* bytes received */ - __u32 ppp_ioctects; /* bytes received not in error */ - __u32 ppp_ipackets; /* packets received */ - __u32 ppp_ierrors; /* receive errors */ - __u32 ppp_ilqrs; /* # LQR frames received */ - - __u32 ppp_obytes; /* raw bytes sent */ - __u32 ppp_ooctects; /* frame bytes sent */ - __u32 ppp_opackets; /* packets sent */ - __u32 ppp_oerrors; /* transmit errors */ - __u32 ppp_olqrs; /* # LQR frames sent */ -}; - -struct vjstat { - __u32 vjs_packets; /* outbound packets */ - __u32 vjs_compressed; /* outbound compressed packets */ - __u32 vjs_searches; /* searches for connection state */ - __u32 vjs_misses; /* times couldn't find conn. state */ - __u32 vjs_uncompressedin; /* inbound uncompressed packets */ - __u32 vjs_compressedin; /* inbound compressed packets */ - __u32 vjs_errorin; /* inbound unknown type packets */ - __u32 vjs_tossed; /* inbound packets tossed because of error */ -}; - -struct compstat { - __u32 unc_bytes; /* total uncompressed bytes */ - __u32 unc_packets; /* total uncompressed packets */ - __u32 comp_bytes; /* compressed bytes */ - __u32 comp_packets; /* compressed packets */ - __u32 inc_bytes; /* incompressible bytes */ - __u32 inc_packets; /* incompressible packets */ - - /* the compression ratio is defined as in_count / bytes_out */ - __u32 in_count; /* Bytes received */ - __u32 bytes_out; /* Bytes transmitted */ - - double ratio; /* not computed in kernel. */ -}; - -struct ppp_stats { - struct pppstat p; /* basic PPP statistics */ - struct vjstat vj; /* VJ header compression statistics */ -}; - -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 */ -}; - -#ifndef __P -#ifdef __STDC__ -#define __P(x) x -#else -#define __P(x) () -#endif -#endif - -#endif /* _PPP_DEFS_H_ */ diff --git a/src/netif/ppp/net/if_ppp.h b/src/netif/ppp/net/if_ppp.h deleted file mode 100644 index bfec6064..00000000 --- a/src/netif/ppp/net/if_ppp.h +++ /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_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_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 __P((void)); -void pppintr __P((void)); -#endif -#endif /* _IF_PPP_H_ */ diff --git a/src/netif/ppp/net/ppp-comp.h b/src/netif/ppp/net/ppp-comp.h deleted file mode 100644 index 088c73e9..00000000 --- a/src/netif/ppp/net/ppp-comp.h +++ /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 - * ". - * - * 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) __P((u_char *options, int opt_len)); - /* Free space used by a compressor */ - void (*comp_free) __P((void *state)); - /* Initialize a compressor */ - int (*comp_init) __P((void *state, u_char *options, int opt_len, - int unit, int hdrlen, int debug)); - /* Reset a compressor */ - void (*comp_reset) __P((void *state)); - /* Compress a packet */ - int (*compress) __P((void *state, PACKETPTR *mret, - PACKETPTR mp, int orig_len, int max_len)); - /* Return compression statistics */ - void (*comp_stat) __P((void *state, struct compstat *stats)); - - /* Allocate space for a decompressor (receive side) */ - void *(*decomp_alloc) __P((u_char *options, int opt_len)); - /* Free space used by a decompressor */ - void (*decomp_free) __P((void *state)); - /* Initialize a decompressor */ - int (*decomp_init) __P((void *state, u_char *options, int opt_len, - int unit, int hdrlen, int mru, int debug)); - /* Reset a decompressor */ - void (*decomp_reset) __P((void *state)); - /* Decompress a packet. */ - int (*decompress) __P((void *state, PACKETPTR mp, - PACKETPTR *dmpp)); - /* Update state for an incompressible packet received */ - void (*incomp) __P((void *state, PACKETPTR mp)); - /* Return decompression statistics */ - void (*decomp_stat) __P((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/src/netif/ppp/net/ppp_defs.h b/src/netif/ppp/net/ppp_defs.h deleted file mode 100644 index 2baf70a6..00000000 --- a/src/netif/ppp/net/ppp_defs.h +++ /dev/null @@ -1,197 +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 - * ". - * - * 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) - */ -#if 0 /* defined in opt.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 -#endif - -#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 */ -}; - -#ifndef __P -#ifdef __STDC__ -#define __P(x) x -#else -#define __P(x) () -#endif -#endif - -#endif /* _PPP_DEFS_H_ */ diff --git a/src/netif/ppp/net/pppio.h b/src/netif/ppp/net/pppio.h deleted file mode 100644 index 54cfe445..00000000 --- a/src/netif/ppp/net/pppio.h +++ /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 - * ". - * - * 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/src/netif/ppp/net/slcompress.h b/src/netif/ppp/net/slcompress.h deleted file mode 100644 index d887dfc2..00000000 --- a/src/netif/ppp/net/slcompress.h +++ /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 __P((struct slcompress *)); -void sl_compress_setup __P((struct slcompress *, int)); -u_int sl_compress_tcp __P((struct mbuf *, - struct ip *, struct slcompress *, int)); -int sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *)); -int sl_uncompress_tcp_core __P((u_char *, int, int, u_int, - struct slcompress *, u_char **, u_int *)); - -#endif /* _SLCOMPRESS_H_ */ diff --git a/src/netif/ppp/net/vjcompress.h b/src/netif/ppp/net/vjcompress.h deleted file mode 100644 index 03a33bf7..00000000 --- a/src/netif/ppp/net/vjcompress.h +++ /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 __P((struct vjcompress *comp, int max_state)); -extern u_int vj_compress_tcp __P((struct ip *ip, u_int mlen, - struct vjcompress *comp, int compress_cid_flag, - u_char **vjhdrp)); -extern void vj_uncompress_err __P((struct vjcompress *comp)); -extern int vj_uncompress_uncomp __P((u_char *buf, int buflen, - struct vjcompress *comp)); -extern int vj_uncompress_tcp __P((u_char *buf, int buflen, int total_len, - struct vjcompress *comp, u_char **hdrp, - u_int *hlenp)); - -#endif /* _VJCOMPRESS_H_ */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index ee8912c1..a3331037 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -510,8 +510,9 @@ static void ppp_input(void *arg) { /* FIXME: should we write protent to do that ? */ switch(protocol) { - case PPP_VJC_COMP: /* VJ compressed TCP */ + #if PPPOS_SUPPORT && VJ_SUPPORT + case PPP_VJC_COMP: /* VJ compressed TCP */ PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_comp in pbuf len=%d\n", pd, nb->len)); /* * Clip off the VJ header and prepend the rebuilt TCP/IP header and @@ -523,14 +524,9 @@ static void ppp_input(void *arg) { } /* Something's wrong so drop it. */ PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ compressed\n", pd)); -#else /* PPPOS_SUPPORT && VJ_SUPPORT */ - /* No handler for this protocol so drop the packet. */ - PPPDEBUG(LOG_INFO, ("pppInput[%d]: drop VJ Comp in %d\n", pd, nb->len)); -#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ break; case PPP_VJC_UNCOMP: /* VJ uncompressed TCP */ -#if PPPOS_SUPPORT && VJ_SUPPORT PPPDEBUG(LOG_INFO, ("pppInput[%d]: vj_un in pbuf len=%d\n", pd, nb->len)); /* * Process the TCP/IP header for VJ header compression and then pass @@ -542,13 +538,8 @@ static void ppp_input(void *arg) { } /* Something's wrong so drop it. */ PPPDEBUG(LOG_WARNING, ("pppInput[%d]: Dropping VJ uncompressed\n", pd)); -#else /* PPPOS_SUPPORT && VJ_SUPPORT */ - /* No handler for this protocol so drop the packet. */ - PPPDEBUG(LOG_INFO, - ("pppInput[%d]: drop VJ UnComp in %d\n", - pd, nb->len)); -#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ break; +#endif /* PPPOS_SUPPORT && VJ_SUPPORT */ case PPP_IP: /* Internet Protocol */ PPPDEBUG(LOG_INFO, ("pppInput[%d]: ip in pbuf len=%d\n", pd, nb->len)); @@ -614,7 +605,7 @@ out: pbuf_free(nb); return; - #if 0 +#if 0 /* * Toss all non-LCP packets unless LCP is OPEN. * Until we get past the authentication phase, toss all packets @@ -1351,7 +1342,7 @@ int sifvjcomp (int u, int vjcomp, int cidcomp, int maxcid) { * get_idle_time - return how long the link has been idle. */ int get_idle_time(int u, struct ppp_idle *ip) { - /* FIXME: add idle time support */ + /* FIXME: add idle time support and make it optional */ return 1; } diff --git a/src/netif/ppp/ppp.h b/src/netif/ppp/ppp.h index 09a49ff1..5e18d6b7 100644 --- a/src/netif/ppp/ppp.h +++ b/src/netif/ppp/ppp.h @@ -22,12 +22,23 @@ #define volatile #endif +#ifndef __P +#ifdef __STDC__ +#define __P(x) x +#else +#define __P(x) () +#endif +#endif + +#ifndef bool +typedef unsigned char bool; +#endif + #include "lwip/netif.h" #include "lwip/def.h" #include "lwip/timers.h" #include "pppdebug.h" -#include "net/ppp_defs.h" /* FIXME: merge linux/ppp_defs.h content here */ #ifdef INET6 #include "eui64.h" @@ -36,16 +47,177 @@ /* * 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 */ -#ifndef bool -typedef unsigned char bool; + +/* + * The basic PPP frame. + */ +#define PPP_HDRLEN 4 /* octets for standard ppp header */ +#define PPP_FCSLEN 2 /* octets for FCS */ + +#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 */ +#if 0 /* UNUSED */ +#define PPP_AT 0x29 /* AppleTalk Protocol */ +#define PPP_IPX 0x2b /* IPX protocol */ +#endif /* UNUSED */ +#if VJ_SUPPORT +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#endif /* VJ_SUPPORT */ +#ifdef INET6 +#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ +#endif /* INET6 */ +#if CCP_SUPPORT +#define PPP_COMP 0xfd /* compressed packet */ +#endif /* CCP_SUPPORT */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#if 0 /* UNUSED */ +#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ +#define PPP_IPXCP 0x802b /* IPX Control Protocol */ +#endif /* UNUSED */ +#ifdef INET6 +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#endif /* INET6 */ +#if CCP_SUPPORT +#define PPP_CCP 0x80fd /* Compression Control Protocol */ +#endif /* CCP_SUPPORT */ +#if ECP_SUPPORT +#define PPP_ECP 0x8053 /* Encryption Control Protocol */ +#endif /* ECP_SUPPORT */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#if PAP_SUPPORT +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#endif /* PAP_SUPPORT */ +/* FIXME: make LQR support optional, anyway, there is no LQR support at all in pppd */ +#define PPP_LQR 0xc025 /* Link Quality Report protocol */ +#if CHAP_SUPPORT +#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ +#endif /* CHAP_SUPPORT */ +#if CBCP_SUPPORT +#define PPP_CBCP 0xc029 /* Callback Control Protocol */ +#endif /* CBCP_SUPPORT */ +#if EAP_SUPPORT +#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ +#endif /* EAP_SUPPORT */ + +/* + * 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. + */ +#if PPP_STATS_SUPPORT +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 */ +}; + +#if VJ_SUPPORT +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 */ +}; +#endif /* VJ_SUPPORT */ + +struct ppp_stats { + struct pppstat p; /* basic PPP statistics */ +#if VJ_SUPPORT + struct vjstat vj; /* VJ header compression statistics */ +#endif /* VJ_SUPPORT */ +}; + +#if CCP_SUPPORT +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 */ +}; +#endif /* CCP_SUPPORT */ + +#endif /* PPP_STATS_SUPPORT */ + +/* + * The following structure records the time in seconds since + * the last NP packet was sent or received. + */ +/* FIXME: add idle time support and make it optional */ +struct ppp_idle { + time_t xmit_idle; /* time since last NP packet sent */ + time_t recv_idle; /* time since last NP packet received */ +}; /* FIXME: make endpoint discriminator optional */ diff --git a/src/netif/ppp/session.c b/src/netif/ppp/session.c deleted file mode 100644 index 3885a759..00000000 --- a/src/netif/ppp/session.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - * session.c - PPP session control. - * - * Copyright (c) 2007 Diego Rivera. 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 - * ". - * - * 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. - * - * Derived from auth.c, which is: - * - * 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. - */ - -#if 0 /* UNUSED */ - -#include "lwip/opt.h" - -#include -#include -#include -#include -#include -#ifdef HAS_SHADOW -#include -#endif -#include -#include -#include -#include - -#include "ppp.h" - -#include "session.h" - -#ifdef USE_PAM -#include -#endif /* #ifdef USE_PAM */ - -#define SET_MSG(var, msg) if (var != NULL) { var[0] = msg; } -#define COPY_STRING(s) ((s) ? strdup(s) : NULL) - -#define SUCCESS_MSG "Session started successfully" -#define ABORT_MSG "Session can't be started without a username" -#define SERVICE_NAME "ppp" - -#define SESSION_FAILED 0 -#define SESSION_OK 1 - -/* We have successfully started a session */ -static bool logged_in = 0; - -#ifdef USE_PAM -/* - * Static variables used to communicate between the conversation function - * and the server_login function - */ -static const char *PAM_username; -static const char *PAM_password; -static int PAM_session = 0; -static pam_handle_t *pamh = NULL; - -/* PAM conversation function - * Here we assume (for now, at least) that echo on means login name, and - * echo off means password. - */ - -static int conversation (int num_msg, -#ifndef SOL2 - const -#endif - struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) -{ - int replies = 0; - struct pam_response *reply = NULL; - - reply = malloc(sizeof(struct pam_response) * num_msg); - if (!reply) return PAM_CONV_ERR; - - for (replies = 0; replies < num_msg; replies++) { - switch (msg[replies]->msg_style) { - case PAM_PROMPT_ECHO_ON: - reply[replies].resp_retcode = PAM_SUCCESS; - reply[replies].resp = COPY_STRING(PAM_username); - /* PAM frees resp */ - break; - case PAM_PROMPT_ECHO_OFF: - reply[replies].resp_retcode = PAM_SUCCESS; - reply[replies].resp = COPY_STRING(PAM_password); - /* PAM frees resp */ - break; - case PAM_TEXT_INFO: - /* fall through */ - case PAM_ERROR_MSG: - /* ignore it, but pam still wants a NULL response... */ - reply[replies].resp_retcode = PAM_SUCCESS; - reply[replies].resp = NULL; - break; - default: - /* Must be an error of some sort... */ - free (reply); - return PAM_CONV_ERR; - } - } - *resp = reply; - return PAM_SUCCESS; -} - -static struct pam_conv pam_conv_data = { - &conversation, - NULL -}; -#endif /* #ifdef USE_PAM */ - -int -session_start(flags, user, passwd, ttyName, msg) - const int flags; - const char *user; - const char *passwd; - const char *ttyName; - char **msg; -{ -#ifdef USE_PAM - bool ok = 1; - const char *usr; - int pam_error; - bool try_session = 0; -#else /* #ifdef USE_PAM */ - struct passwd *pw; -#ifdef HAS_SHADOW - struct spwd *spwd; - struct spwd *getspnam(); - long now = 0; -#endif /* #ifdef HAS_SHADOW */ -#endif /* #ifdef USE_PAM */ - - SET_MSG(msg, SUCCESS_MSG); - - /* If no verification is requested, then simply return an OK */ - if (!(SESS_ALL & flags)) { - return SESSION_OK; - } - - if (user == NULL) { - SET_MSG(msg, ABORT_MSG); - return SESSION_FAILED; - } - -#ifdef USE_PAM - /* Find the '\\' in the username */ - /* This needs to be fixed to support different username schemes */ - if ((usr = strchr(user, '\\')) == NULL) - usr = user; - else - usr++; - - PAM_session = 0; - PAM_username = usr; - PAM_password = passwd; - - dbglog("Initializing PAM (%d) for user %s", flags, usr); - pam_error = pam_start (SERVICE_NAME, usr, &pam_conv_data, &pamh); - dbglog("---> PAM INIT Result = %d", pam_error); - ok = (pam_error == PAM_SUCCESS); - - if (ok) { - ok = (pam_set_item(pamh, PAM_TTY, ttyName) == PAM_SUCCESS) && - (pam_set_item(pamh, PAM_RHOST, ifname) == PAM_SUCCESS); - } - - if (ok && (SESS_AUTH & flags)) { - dbglog("Attempting PAM authentication"); - pam_error = pam_authenticate (pamh, PAM_SILENT); - if (pam_error == PAM_SUCCESS) { - /* PAM auth was OK */ - dbglog("PAM Authentication OK for %s", user); - } else { - /* No matter the reason, we fail because we're authenticating */ - ok = 0; - if (pam_error == PAM_USER_UNKNOWN) { - dbglog("User unknown, failing PAM authentication"); - SET_MSG(msg, "User unknown - cannot authenticate via PAM"); - } else { - /* Any other error means authentication was bad */ - dbglog("PAM Authentication failed: %d: %s", pam_error, - pam_strerror(pamh, pam_error)); - SET_MSG(msg, (char *) pam_strerror (pamh, pam_error)); - } - } - } - - if (ok && (SESS_ACCT & flags)) { - dbglog("Attempting PAM account checks"); - pam_error = pam_acct_mgmt (pamh, PAM_SILENT); - if (pam_error == PAM_SUCCESS) { - /* - * PAM account was OK, set the flag which indicates that we should - * try to perform the session checks. - */ - try_session = 1; - dbglog("PAM Account OK for %s", user); - } else { - /* - * If the account checks fail, then we should not try to perform - * the session check, because they don't make sense. - */ - try_session = 0; - if (pam_error == PAM_USER_UNKNOWN) { - /* - * We're checking the account, so it's ok to not have one - * because the user might come from the secrets files, or some - * other plugin. - */ - dbglog("User unknown, ignoring PAM restrictions"); - SET_MSG(msg, "User unknown - ignoring PAM restrictions"); - } else { - /* Any other error means session is rejected */ - ok = 0; - dbglog("PAM Account checks failed: %d: %s", pam_error, - pam_strerror(pamh, pam_error)); - SET_MSG(msg, (char *) pam_strerror (pamh, pam_error)); - } - } - } - - if (ok && try_session && (SESS_ACCT & flags)) { - /* Only open a session if the user's account was found */ - pam_error = pam_open_session (pamh, PAM_SILENT); - if (pam_error == PAM_SUCCESS) { - dbglog("PAM Session opened for user %s", user); - PAM_session = 1; - } else { - dbglog("PAM Session denied for user %s", user); - SET_MSG(msg, (char *) pam_strerror (pamh, pam_error)); - ok = 0; - } - } - - /* This is needed because apparently the PAM stuff closes the log */ - reopen_log(); - - /* If our PAM checks have already failed, then we must return a failure */ - if (!ok) return SESSION_FAILED; - -#else /* #ifdef USE_PAM */ - -/* - * Use the non-PAM methods directly. 'pw' will remain NULL if the user - * has not been authenticated using local UNIX system services. - */ - - pw = NULL; - if ((SESS_AUTH & flags)) { - pw = getpwnam(user); - - endpwent(); - /* - * Here, we bail if we have no user account, because there is nothing - * to verify against. - */ - if (pw == NULL) - return SESSION_FAILED; - -#ifdef HAS_SHADOW - - spwd = getspnam(user); - endspent(); - - /* - * If there is no shadow entry for the user, then we can't verify the - * account. - */ - if (spwd == NULL) - return SESSION_FAILED; - - /* - * We check validity all the time, because if the password has expired, - * then clearly we should not authenticate against it (if we're being - * called for authentication only). Thus, in this particular instance, - * there is no real difference between using the AUTH, SESS or ACCT - * flags, or combinations thereof. - */ - now = time(NULL) / 86400L; - if ((spwd->sp_expire > 0 && now >= spwd->sp_expire) - || ((spwd->sp_max >= 0 && spwd->sp_max < 10000) - && spwd->sp_lstchg >= 0 - && now >= spwd->sp_lstchg + spwd->sp_max)) { - warn("Password for %s has expired", user); - return SESSION_FAILED; - } - - /* We have a valid shadow entry, keep the password */ - pw->pw_passwd = spwd->sp_pwdp; - -#endif /* #ifdef HAS_SHADOW */ - -#if 0 - /* - * If no passwd, don't let them login if we're authenticating. - */ - if (pw->pw_passwd == NULL || strlen(pw->pw_passwd) < 2 - || strcmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd) != 0) - return SESSION_FAILED; -#endif - } - -#endif /* #ifdef USE_PAM */ - - /* - * Write a wtmp entry for this user. - */ - - if (SESS_ACCT & flags) { - if (strncmp(ttyName, "/dev/", 5) == 0) - ttyName += 5; - logwtmp(ttyName, user, ifname); /* Add wtmp login entry */ - logged_in = 1; - -#if defined(_PATH_LASTLOG) && !defined(USE_PAM) - /* - * Enter the user in lastlog only if he has been authenticated using - * local system services. If he has not, then we don't know what his - * UID might be, and lastlog is indexed by UID. - */ - if (pw != NULL) { - struct lastlog ll; - int fd; - time_t tnow; - - if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { - (void)lseek(fd, (off_t)(pw->pw_uid * sizeof(ll)), SEEK_SET); - memset((void *)&ll, 0, sizeof(ll)); - (void)time(&tnow); - ll.ll_time = tnow; - (void)strncpy(ll.ll_line, ttyName, sizeof(ll.ll_line)); - (void)strncpy(ll.ll_host, ifname, sizeof(ll.ll_host)); - (void)write(fd, (char *)&ll, sizeof(ll)); - (void)close(fd); - } - } -#endif /* _PATH_LASTLOG and not USE_PAM */ - info("user %s logged in on tty %s intf %s", user, ttyName, ifname); - } - - return SESSION_OK; -} - -/* - * session_end - Logout the user. - */ -void -session_end(const char* ttyName) -{ -#ifdef USE_PAM - int pam_error = PAM_SUCCESS; - - if (pamh != NULL) { - if (PAM_session) pam_error = pam_close_session (pamh, PAM_SILENT); - PAM_session = 0; - pam_end (pamh, pam_error); - pamh = NULL; - /* Apparently the pam stuff does closelog(). */ - reopen_log(); - } -#endif - if (logged_in) { - if (strncmp(ttyName, "/dev/", 5) == 0) - ttyName += 5; - logwtmp(ttyName, "", ""); /* Wipe out utmp logout entry */ - logged_in = 0; - } -} - -#endif /* UNUSED */ diff --git a/src/netif/ppp/session.h b/src/netif/ppp/session.h deleted file mode 100644 index cfdbdfac..00000000 --- a/src/netif/ppp/session.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * session.c - PPP session control. - * - * Copyright (c) 2007 Diego Rivera. 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 - * ". - * - * 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. - */ - -#if 0 /* UNUSED */ - -#ifndef __SESSION_H -#define __SESSION_H - -#define SESS_AUTH 1 /* Check User Authentication */ -#define SESS_ACCT 2 /* Check Account Validity */ - -/* Convenience parameter to do the whole enchilada */ -#define SESS_ALL (SESS_AUTH | SESS_ACCT) - -/* - * int session_start(...) - * - * Start a session, performing any necessary validations. - * - * Parameters: - * const int flags : - * Any combination of the SESS_XXX flags, to indicate what the function - * should do as part of its checks - * - * const char* user : - * The username to validate. May safely be null. - * - * const char* passwd : - * The password to validate the user with. May safely be null. - * - * const char* tty : - * The TTY the user is connected on. May safely be null. - * - * char** msg : - * A char* to return an error or success message. This message will be returned - * regardless of the result. May safely be null. - * - * Return Value: - * Zero value for failure, non-zero value for successful session verification. - */ -int -session_start(const int flags, const char* user, const char* passwd, const char* tty, char** msg); - -/* Added these macros for convenience... */ -#define session_auth(user, pass, tty, msg) \ - session_start(SESS_AUTH, user, pass, tty, msg) - -#define session_check(user, pass, tty, msg) \ - session_start(SESS_ACCT, user, pass, tty, msg) - -#define session_full(user, pass, tty, msg) \ - session_start(SESS_ALL, user, pass, tty, msg) - -/* - * void session_end(...) - * - * End a previously-started session. - * - * Parameters: - * const char* tty : - * The TTY the user is connected on. May safely be null. - */ -void -session_end(const char* tty); - -#endif - -#endif /* UNUSED */ diff --git a/src/netif/ppp/tty.c b/src/netif/ppp/tty.c deleted file mode 100644 index 53941c6e..00000000 --- a/src/netif/ppp/tty.c +++ /dev/null @@ -1,1290 +0,0 @@ -/* - * tty.c - code for handling serial ports in pppd. - * - * Copyright (C) 2000-2004 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 - * ". - * - * 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. - * - * Portions derived from main.c, which is: - * - * 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. - */ - -#if 0 /* NEED OUR OWN PORT */ - -#define RCSID "$Id: tty.c,v 1.27 2008/07/01 12:27:56 paulus Exp $" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ppp.h" - -#include "fsm.h" -#include "lcp.h" - -void tty_process_extra_options __P((void)); -void tty_check_options __P((void)); -int connect_tty __P((void)); -void disconnect_tty __P((void)); -void tty_close_fds __P((void)); -void cleanup_tty __P((void)); -void tty_do_send_config __P((int, u_int32_t, int, int)); - -static int setdevname __P((char *, char **, int)); -static int setspeed __P((char *, char **, int)); -static int setxonxoff __P((char **)); -static int setescape __P((char **)); -#if 0 /* UNUSED */ -static void printescape __P((option_t *, void (*)(void *, char *,...),void *)); -#endif /* UNUSED */ -static void finish_tty __P((void)); -static int start_charshunt __P((int, int)); -static void stop_charshunt __P((void *, int)); -static void charshunt_done __P((void *)); -static void charshunt __P((int, int, char *)); -static int record_write __P((FILE *, int code, u_char *buf, int nb, - struct timeval *)); -static int open_socket __P((char *)); - -#if 0 -static void maybe_relock __P((void *, int)); -#endif - -static int pty_master; /* fd for master side of pty */ -static int pty_slave; /* fd for slave side of pty */ -static int real_ttyfd; /* fd for actual serial port (not pty) */ -static int ttyfd; /* Serial port file descriptor */ -static char speed_str[16]; /* Serial port speed as string */ - -mode_t tty_mode = (mode_t)-1; /* Original access permissions to tty */ -int baud_rate; /* Actual bits/second for serial device */ -char *callback_script; /* script for doing callback */ -int charshunt_pid; /* Process ID for charshunt */ -int locked; /* lock() has succeeded */ -struct stat devstat; /* result of stat() on devnam */ - -/* option variables */ -int crtscts = 0; /* Use hardware flow control */ -bool modem = 1; /* Use modem control lines */ -int inspeed = 0; /* Input/Output speed requested */ -bool lockflag = 0; /* Create lock file to lock the serial dev */ -char *initializer = NULL; /* Script to initialize physical link */ -char *connect_script = NULL; /* Script to establish physical link */ -char *disconnect_script = NULL; /* Script to disestablish physical link */ -char *welcomer = NULL; /* Script to run after phys link estab. */ -char *ptycommand = NULL; /* Command to run on other side of pty */ -bool notty = 0; /* Stdin/out is not a tty */ -char *record_file = NULL; /* File to record chars sent/received */ -int max_data_rate; /* max bytes/sec through charshunt */ -bool sync_serial = 0; /* Device is synchronous serial device */ -char *pty_socket = NULL; /* Socket to connect to pty */ -int using_pty = 0; /* we're allocating a pty as the device */ - -extern uid_t uid; -#if 0 /* UNUSED */ -extern int kill_link; -#endif /* UNUSED */ -extern int asked_to_quit; -extern int got_sigterm; - -/* XXX */ -extern int privopen; /* don't lock, open device as root */ - -u_int32_t xmit_accm[8]; /* extended transmit ACCM */ - -#if 0 /* UNUSED */ -/* option descriptors */ -option_t tty_options[] = { - /* device name must be first, or change connect_tty() below! */ - { "device name", o_wild, (void *) &setdevname, - "Serial port device name", - OPT_DEVNAM | OPT_PRIVFIX | OPT_NOARG | OPT_A2STRVAL | OPT_STATIC, - devnam}, - - { "tty speed", o_wild, (void *) &setspeed, - "Baud rate for serial port", - OPT_PRIO | OPT_NOARG | OPT_A2STRVAL | OPT_STATIC, speed_str }, - - { "lock", o_bool, &lockflag, - "Lock serial device with UUCP-style lock file", OPT_PRIO | 1 }, - { "nolock", o_bool, &lockflag, - "Don't lock serial device", OPT_PRIOSUB | OPT_PRIV }, - - { "init", o_string, &initializer, - "A program to initialize the device", OPT_PRIO | OPT_PRIVFIX }, - - { "connect", o_string, &connect_script, - "A program to set up a connection", OPT_PRIO | OPT_PRIVFIX }, - - { "disconnect", o_string, &disconnect_script, - "Program to disconnect serial device", OPT_PRIO | OPT_PRIVFIX }, - - { "welcome", o_string, &welcomer, - "Script to welcome client", OPT_PRIO | OPT_PRIVFIX }, - - { "pty", o_string, &ptycommand, - "Script to run on pseudo-tty master side", - OPT_PRIO | OPT_PRIVFIX | OPT_DEVNAM }, - - { "notty", o_bool, ¬ty, - "Input/output is not a tty", OPT_DEVNAM | 1 }, - - { "socket", o_string, &pty_socket, - "Send and receive over socket, arg is host:port", - OPT_PRIO | OPT_DEVNAM }, - - { "record", o_string, &record_file, - "Record characters sent/received to file", OPT_PRIO }, - - { "crtscts", o_int, &crtscts, - "Set hardware (RTS/CTS) flow control", - OPT_PRIO | OPT_NOARG | OPT_VAL(1) }, - { "cdtrcts", o_int, &crtscts, - "Set alternate hardware (DTR/CTS) flow control", - OPT_PRIOSUB | OPT_NOARG | OPT_VAL(2) }, - { "nocrtscts", o_int, &crtscts, - "Disable hardware flow control", - OPT_PRIOSUB | OPT_NOARG | OPT_VAL(-1) }, - { "-crtscts", o_int, &crtscts, - "Disable hardware flow control", - OPT_PRIOSUB | OPT_ALIAS | OPT_NOARG | OPT_VAL(-1) }, - { "nocdtrcts", o_int, &crtscts, - "Disable hardware flow control", - OPT_PRIOSUB | OPT_ALIAS | OPT_NOARG | OPT_VAL(-1) }, - { "xonxoff", o_special_noarg, (void *)setxonxoff, - "Set software (XON/XOFF) flow control", OPT_PRIOSUB }, - - { "modem", o_bool, &modem, - "Use modem control lines", OPT_PRIO | 1 }, - { "local", o_bool, &modem, - "Don't use modem control lines", OPT_PRIOSUB | 0 }, - - { "sync", o_bool, &sync_serial, - "Use synchronous HDLC serial encoding", 1 }, - - { "datarate", o_int, &max_data_rate, - "Maximum data rate in bytes/sec (with pty, notty or record option)", - OPT_PRIO }, - - { "escape", o_special, (void *)setescape, - "List of character codes to escape on transmission", - OPT_A2PRINTER, (void *)printescape }, - - { NULL } -}; - -#endif /* UNUSED */ - -struct channel tty_channel = { -#if PPP_OPTIONS - tty_options, - &tty_process_extra_options, - &tty_check_options, - &connect_tty, -#endif /* UNUSED */ - &disconnect_tty, - &tty_establish_ppp, - &tty_disestablish_ppp, - &tty_do_send_config, - &tty_recv_config, - &cleanup_tty, - &tty_close_fds -}; - -/* - * setspeed - Set the serial port baud rate. - * If doit is 0, the call is to check whether this option is - * potentially a speed value. - */ -static int -setspeed(arg, argv, doit) - char *arg; - char **argv; - int doit; -{ - char *ptr; - int spd; - - spd = strtol(arg, &ptr, 0); - if (ptr == arg || *ptr != 0 || spd == 0) - return 0; - if (doit) { - inspeed = spd; - slprintf(speed_str, sizeof(speed_str), "%d", spd); - } - return 1; -} - - -/* - * setdevname - Set the device name. - * If doit is 0, the call is to check whether this option is - * potentially a device name. - */ -static int -setdevname(cp, argv, doit) - char *cp; - char **argv; - int doit; -{ - struct stat statbuf; - char dev[MAXPATHLEN]; - - if (*cp == 0) - return 0; - - if (*cp != '/') { - strlcpy(dev, "/dev/", sizeof(dev)); - strlcat(dev, cp, sizeof(dev)); - cp = dev; - } - - /* - * Check if there is a character device by this name. - */ - if (stat(cp, &statbuf) < 0) { - if (!doit) - return errno != ENOENT; - 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); - return 0; - } - - if (doit) { - strlcpy(devnam, cp, sizeof(devnam)); - devstat = statbuf; - default_device = 0; - } - - return 1; -} - -static int -setxonxoff(argv) - char **argv; -{ - lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */ - lcp_wantoptions[0].neg_asyncmap = 1; - - crtscts = -2; - return 1; -} - -/* - * setescape - add chars to the set we escape on transmission. - */ -static int -setescape(argv) - char **argv; -{ - int n, ret; - char *p, *endp; - - p = *argv; - ret = 1; - while (*p) { - n = strtol(p, &endp, 16); - if (p == endp) { - 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); - ret = 0; - } else - xmit_accm[n >> 5] |= 1 << (n & 0x1F); - while (*p == ',' || *p == ' ') - ++p; - } - lcp_allowoptions[0].asyncmap = xmit_accm[0]; - return ret; -} - -#if 0 /* UNUSED */ -static void -printescape(opt, printer, arg) - option_t *opt; - void (*printer) __P((void *, char *, ...)); - void *arg; -{ - int n; - int first = 1; - - for (n = 0; n < 256; ++n) { - if (n == 0x7d) - n += 2; /* skip 7d, 7e */ - if (xmit_accm[n >> 5] & (1 << (n & 0x1f))) { - if (!first) - printer(arg, ","); - else - first = 0; - printer(arg, "%x", n); - } - } - if (first) - printer(arg, "oops # nothing escaped"); -} -#endif /* UNUSED */ - -#if 0 -/* - * tty_init - do various tty-related initializations. - */ -void tty_init() -{ - add_notifier(&pidchange, maybe_relock, 0); - the_channel = &tty_channel; - xmit_accm[3] = 0x60000000; -} -#endif - -/* - * tty_process_extra_options - work out which tty device we are using - * and read its options file. - */ -void tty_process_extra_options() -{ - using_pty = notty || ptycommand != NULL || pty_socket != NULL; - if (using_pty) - return; - if (default_device) { - char *p; - if (!isatty(0) || (p = ttyname(0)) == NULL) { - option_error("no device specified and stdin is not a tty"); - exit(EXIT_OPTION_ERROR); - } - strlcpy(devnam, p, sizeof(devnam)); - if (stat(devnam, &devstat) < 0) - fatal("Couldn't stat default device %s: %m", devnam); - } - -#if PPP_OPTIONS - /* - * Parse the tty options file. - * The per-tty options file should not change - * ptycommand, pty_socket, notty or devnam. - * options_for_tty doesn't override options set on the command line, - * except for some privileged options. - */ - if (!options_for_tty()) - exit(EXIT_OPTION_ERROR); -#endif /* PPP_OPTIONS */ -} - -#if 0 /* UNUSED */ -/* - * tty_check_options - do consistency checks on the options we were given. - */ -void -tty_check_options() -{ - struct stat statbuf; - int fdflags; - - if (demand && notty) { - 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"); - exit(EXIT_OPTION_ERROR); - } - /* default holdoff to 0 if no connect script has been given */ - if (connect_script == 0 && !holdoff_specified) - holdoff = 0; - - if (using_pty) { - if (!default_device) { - 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"); - exit(EXIT_OPTION_ERROR); - } - if (pty_socket != NULL && (ptycommand != NULL || notty)) { - option_error("socket option is incompatible with pty and notty"); - exit(EXIT_OPTION_ERROR); - } - default_device = notty; - lockflag = 0; - modem = 0; - if (notty && log_to_fd <= 1) - log_to_fd = -1; - } else { - /* - * If the user has specified a device which is the same as - * the one on stdin, pretend they didn't specify any. - * If the device is already open read/write on stdin, - * we assume we don't need to lock it, and we can open it - * as root. - */ - if (fstat(0, &statbuf) >= 0 && S_ISCHR(statbuf.st_mode) - && statbuf.st_rdev == devstat.st_rdev) { - default_device = 1; - fdflags = fcntl(0, F_GETFL); - if (fdflags != -1 && (fdflags & O_ACCMODE) == O_RDWR) - privopen = 1; - } - } - if (default_device) - nodetach = 1; - - /* - * Don't send log messages to the serial port, it tends to - * confuse the peer. :-) - */ - if (log_to_fd >= 0 && fstat(log_to_fd, &statbuf) >= 0 - && S_ISCHR(statbuf.st_mode) && statbuf.st_rdev == devstat.st_rdev) - log_to_fd = -1; -} -#endif /* UNUSED */ - -#if 0 /* UNUSED */ -/* - * connect_tty - get the serial port ready to start doing PPP. - * That is, open the serial port, set its speed and mode, and run - * the connector and/or welcomer. - */ -int connect_tty() -{ - char *connector; - int fdflags; -#ifndef __linux__ - struct stat statbuf; -#endif - char numbuf[16]; - - /* - * Get a pty master/slave pair if the pty, notty, socket, - * or record options were specified. - */ - strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam)); - 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)) { - error("Couldn't allocate pseudo-tty"); - status = EXIT_FATAL_ERROR; - return -1; - } - set_up_tty(pty_slave, 1); - } - - /* - * Lock the device if we've been asked to. - */ - status = EXIT_LOCK_FAILED; - if (lockflag && !privopen) { - if (lock(devnam) < 0) - goto errret; - locked = 1; - } - - /* - * Open the serial device and set it up to be the ppp interface. - * First we open it in non-blocking mode so we can set the - * various termios flags appropriately. If we aren't dialling - * out and we want to use the modem lines, we reopen it later - * in order to wait for the carrier detect signal from the modem. - */ - got_sigterm = 0; - connector = doing_callback? callback_script: connect_script; - if (devnam[0] != 0) { - for (;;) { - /* If the user specified the device name, become the - user before opening it. */ - int err, prio; - - prio = privopen? OPRIO_ROOT: tty_options[0].priority; - if (prio < OPRIO_ROOT && seteuid(uid) == -1) { - error("Unable to drop privileges before opening %s: %m\n", - devnam); - status = EXIT_OPEN_FAILED; - goto errret; - } - real_ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0); - err = errno; - if (prio < OPRIO_ROOT && seteuid(0) == -1) - fatal("Unable to regain privileges"); - if (real_ttyfd >= 0) - break; - errno = err; - if (err != EINTR) { - error("Failed to open %s: %m", devnam); - status = EXIT_OPEN_FAILED; - } - if (!persist || err != EINTR) - goto errret; - } - ttyfd = real_ttyfd; - if ((fdflags = fcntl(ttyfd, F_GETFL)) == -1 - || fcntl(ttyfd, F_SETFL, fdflags & ~O_NONBLOCK) < 0) - warn("Couldn't reset non-blocking mode on device: %m"); - -#ifndef __linux__ - /* - * Linux 2.4 and above blocks normal writes to the tty - * when it is in PPP line discipline, so this isn't needed. - */ - /* - * Do the equivalent of `mesg n' to stop broadcast messages. - */ - if (fstat(ttyfd, &statbuf) < 0 - || fchmod(ttyfd, statbuf.st_mode & ~(S_IWGRP | S_IWOTH)) < 0) { - warn("Couldn't restrict write permissions to %s: %m", devnam); - } else - tty_mode = statbuf.st_mode; -#endif /* __linux__ */ - - /* - * Set line speed, flow control, etc. - * If we have a non-null connection or initializer script, - * on most systems we set CLOCAL for now so that we can talk - * to the modem before carrier comes up. But this has the - * side effect that we might miss it if CD drops before we - * get to clear CLOCAL below. On systems where we can talk - * successfully to the modem with CLOCAL clear and CD down, - * we could clear CLOCAL at this point. - */ - set_up_tty(ttyfd, ((connector != NULL && connector[0] != 0) - || initializer != NULL)); - } - - /* - * If the pty, socket, notty and/or record option was specified, - * start up the character shunt now. - */ - status = EXIT_PTYCMD_FAILED; - if (ptycommand != NULL) { - if (record_file != NULL) { - int ipipe[2], opipe[2], ok; - - if (pipe(ipipe) < 0 || pipe(opipe) < 0) - fatal("Couldn't create pipes for record option: %m"); - - /* don't leak these to the ptycommand */ - (void) fcntl(ipipe[0], F_SETFD, FD_CLOEXEC); - (void) fcntl(opipe[1], F_SETFD, FD_CLOEXEC); - - ok = device_script(ptycommand, opipe[0], ipipe[1], 1) == 0 - && start_charshunt(ipipe[0], opipe[1]); - close(ipipe[0]); - close(ipipe[1]); - close(opipe[0]); - close(opipe[1]); - if (!ok) - goto errret; - } else { - if (device_script(ptycommand, pty_master, pty_master, 1) < 0) - goto errret; - } - } else if (pty_socket != NULL) { - int fd = open_socket(pty_socket); - if (fd < 0) - goto errret; - if (!start_charshunt(fd, fd)) - goto errret; - close(fd); - } else if (notty) { - if (!start_charshunt(0, 1)) - goto errret; - dup2(fd_devnull, 0); - dup2(fd_devnull, 1); - if (log_to_fd == 1) - log_to_fd = -1; - if (log_to_fd != 2) - dup2(fd_devnull, 2); - } else if (record_file != NULL) { - int fd = dup(ttyfd); - if (!start_charshunt(fd, fd)) - goto errret; - } - - if (using_pty || record_file != NULL) { - ttyfd = pty_slave; - close(pty_master); - pty_master = -1; - } - - /* run connection script */ - if ((connector && connector[0]) || initializer) { - if (real_ttyfd != -1) { - /* XXX do this if doing_callback == CALLBACK_DIALIN? */ - if (!default_device && modem) { - setdtr(real_ttyfd, 0); /* in case modem is off hook */ - sleep(1); - setdtr(real_ttyfd, 1); - } - } - - if (initializer && initializer[0]) { - if (device_script(initializer, ttyfd, ttyfd, 0) < 0) { - error("Initializer script failed"); - status = EXIT_INIT_FAILED; - goto errretf; - } - if (got_sigterm) { - disconnect_tty(); - goto errretf; - } - info("Serial port initialized."); - } - - if (connector && connector[0]) { - if (device_script(connector, ttyfd, ttyfd, 0) < 0) { - error("Connect script failed"); - status = EXIT_CONNECT_FAILED; - goto errretf; - } - if (got_sigterm) { - disconnect_tty(); - goto errretf; - } - info("Serial connection established."); - } - - /* set line speed, flow control, etc.; - clear CLOCAL if modem option */ - if (real_ttyfd != -1) - set_up_tty(real_ttyfd, 0); - - if (doing_callback == CALLBACK_DIALIN) - connector = NULL; - } - - /* reopen tty if necessary to wait for carrier */ - if (connector == NULL && modem && devnam[0] != 0) { - int i; - for (;;) { - if ((i = open(devnam, O_RDWR)) >= 0) - break; - if (errno != EINTR) { - error("Failed to reopen %s: %m", devnam); - status = EXIT_OPEN_FAILED; - } - if (!persist || errno != EINTR || hungup || got_sigterm) - goto errret; - } - close(i); - } - - slprintf(numbuf, sizeof(numbuf), "%d", baud_rate); - script_setenv("SPEED", numbuf, 0); - - /* run welcome script, if any */ - if (welcomer && welcomer[0]) { - if (device_script(welcomer, ttyfd, ttyfd, 0) < 0) - warn("Welcome script failed"); - } - - /* - * If we are initiating this connection, wait for a short - * time for something from the peer. This can avoid bouncing - * our packets off his tty before he has it set up. - */ - if (connector != NULL || ptycommand != NULL || pty_socket != NULL) - listen_time = connect_delay; - - return ttyfd; - - errretf: - if (real_ttyfd >= 0) - tcflush(real_ttyfd, TCIOFLUSH); - errret: - if (pty_master >= 0) { - close(pty_master); - pty_master = -1; - } - ttyfd = -1; - if (got_sigterm) - asked_to_quit = 1; - return -1; -} -#endif /* UNUSED */ - -void disconnect_tty() -{ - if (disconnect_script == NULL || hungup) - return; - if (real_ttyfd >= 0) - set_up_tty(real_ttyfd, 1); - if (device_script(disconnect_script, ttyfd, ttyfd, 0) < 0) { - warn("disconnect script failed"); - } else { - info("Serial link disconnected."); - } - stop_charshunt(NULL, 0); -} - -void tty_close_fds() -{ - if (pty_slave >= 0) - close(pty_slave); - if (real_ttyfd >= 0) { - close(real_ttyfd); - real_ttyfd = -1; - } - /* N.B. ttyfd will == either pty_slave or real_ttyfd */ -} - -void cleanup_tty() -{ - if (real_ttyfd >= 0) - finish_tty(); - tty_close_fds(); -#if 0 - if (locked) { - unlock(); - locked = 0; - } -#endif -} - -/* - * tty_do_send_config - set transmit-side PPP configuration. - * We set the extended transmit ACCM here as well. - */ -void -tty_do_send_config(mtu, accm, pcomp, accomp) - int mtu; - u_int32_t accm; - int pcomp, accomp; -{ - tty_set_xaccm(xmit_accm); - tty_send_config(mtu, accm, pcomp, accomp); -} - -/* - * finish_tty - restore the terminal device to its original settings - */ -static void -finish_tty() -{ - /* drop dtr to hang up */ - if (!default_device && modem) { - setdtr(real_ttyfd, 0); - /* - * This sleep is in case the serial port has CLOCAL set by default, - * and consequently will reassert DTR when we close the device. - */ - sleep(1); - } - - restore_tty(real_ttyfd); - -#ifndef __linux__ - if (tty_mode != (mode_t) -1) { - if (fchmod(real_ttyfd, tty_mode) != 0) - error("Couldn't restore tty permissions"); - } -#endif /* __linux__ */ - - close(real_ttyfd); - real_ttyfd = -1; -} - -#if 0 -/* - * maybe_relock - our PID has changed, maybe update the lock file. - */ -static void -maybe_relock(arg, pid) - void *arg; - int pid; -{ - if (locked) - relock(pid); -} -#endif - -/* - * open_socket - establish a stream socket connection to the nominated - * host and port. - */ -static int -open_socket(dest) - char *dest; -{ - char *sep, *endp = NULL; - int sock, port = -1; - u_int32_t host; - struct hostent *hent; - struct sockaddr_in sad; - - /* parse host:port and resolve host to an IP address */ - sep = strchr(dest, ':'); - if (sep != NULL) - port = strtol(sep+1, &endp, 10); - if (port < 0 || endp == sep+1 || sep == dest) { - error("Can't parse host:port for socket destination"); - return -1; - } - *sep = 0; - host = inet_addr(dest); - if (host == (u_int32_t) -1) { - hent = gethostbyname(dest); - if (hent == NULL) { - error("%s: unknown host in socket option", dest); - *sep = ':'; - return -1; - } - host = *(u_int32_t *)(hent->h_addr_list[0]); - } - *sep = ':'; - - /* get a socket and connect it to the other end */ - sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock < 0) { - error("Can't create socket: %m"); - return -1; - } - memset(&sad, 0, sizeof(sad)); - sad.sin_family = AF_INET; - sad.sin_port = htons(port); - sad.sin_addr.s_addr = host; - if (connect(sock, (struct sockaddr *)&sad, sizeof(sad)) < 0) { - error("Can't connect to %s: %m", dest); - close(sock); - return -1; - } - - return sock; -} - - -/* - * start_charshunt - create a child process to run the character shunt. - */ -static int -start_charshunt(ifd, ofd) - int ifd, ofd; -{ - int cpid; - - cpid = -1; /* 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; - } - if (cpid == 0) { - /* child */ - reopen_log(); - if (!nodetach) - log_to_fd = -1; - else if (log_to_fd >= 0) - log_to_fd = 2; - setgid(getgid()); - setuid(uid); - if (getuid() != uid) - fatal("setuid failed"); - charshunt(0, 1, record_file); - exit(0); - } - charshunt_pid = cpid; - record_child(cpid, "pppd (charshunt)", charshunt_done, NULL, 1); - return 1; -} - -static void -charshunt_done(arg) - void *arg; -{ - charshunt_pid = 0; -} - -static void -stop_charshunt(arg, sig) - void *arg; - int sig; -{ - if (charshunt_pid) - kill(charshunt_pid, (sig == SIGINT? sig: SIGTERM)); -} - -/* - * charshunt - the character shunt, which passes characters between - * the pty master side and the serial port (or stdin/stdout). - * This runs as the user (not as root). - * (We assume ofd >= ifd which is true the way this gets called. :-). - */ -static void -charshunt(ifd, ofd, record_file) - int ifd, ofd; - char *record_file; -{ - int n, nfds; - fd_set ready, writey; - u_char *ibufp, *obufp; - int nibuf, nobuf; - int flags; - int pty_readable, stdin_readable; - struct timeval lasttime; - FILE *recordf = NULL; - int ilevel, olevel, max_level; - struct timeval levelt, tout, *top; - extern u_char inpacket_buf[]; - - /* - * Reset signal handlers. - */ - signal(SIGHUP, SIG_IGN); /* Hangup */ - signal(SIGINT, SIG_DFL); /* Interrupt */ - signal(SIGTERM, SIG_DFL); /* Terminate */ - signal(SIGCHLD, SIG_DFL); - signal(SIGUSR1, SIG_DFL); - signal(SIGUSR2, SIG_DFL); - signal(SIGABRT, SIG_DFL); - signal(SIGALRM, SIG_DFL); - signal(SIGFPE, SIG_DFL); - signal(SIGILL, SIG_DFL); - signal(SIGPIPE, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGSEGV, SIG_DFL); -#ifdef SIGBUS - signal(SIGBUS, SIG_DFL); -#endif -#ifdef SIGEMT - signal(SIGEMT, SIG_DFL); -#endif -#ifdef SIGPOLL - signal(SIGPOLL, SIG_DFL); -#endif -#ifdef SIGPROF - signal(SIGPROF, SIG_DFL); -#endif -#ifdef SIGSYS - signal(SIGSYS, SIG_DFL); -#endif -#ifdef SIGTRAP - signal(SIGTRAP, SIG_DFL); -#endif -#ifdef SIGVTALRM - signal(SIGVTALRM, SIG_DFL); -#endif -#ifdef SIGXCPU - signal(SIGXCPU, SIG_DFL); -#endif -#ifdef SIGXFSZ - signal(SIGXFSZ, SIG_DFL); -#endif - - /* - * Check that the fds won't overrun the fd_sets - */ - if (ifd >= FD_SETSIZE || ofd >= FD_SETSIZE || pty_master >= FD_SETSIZE) - fatal("internal error: file descriptor too large (%d, %d, %d)", - ifd, ofd, pty_master); - - /* - * Open the record file if required. - */ - if (record_file != NULL) { - recordf = fopen(record_file, "a"); - if (recordf == NULL) - error("Couldn't create record file %s: %m", record_file); - } - - /* set all the fds to non-blocking mode */ - flags = fcntl(pty_master, F_GETFL); - if (flags == -1 - || fcntl(pty_master, F_SETFL, flags | O_NONBLOCK) == -1) - warn("couldn't set pty master to nonblock: %m"); - flags = fcntl(ifd, F_GETFL); - if (flags == -1 - || fcntl(ifd, F_SETFL, flags | O_NONBLOCK) == -1) - warn("couldn't set %s to nonblock: %m", (ifd==0? "stdin": "tty")); - if (ofd != ifd) { - flags = fcntl(ofd, F_GETFL); - if (flags == -1 - || fcntl(ofd, F_SETFL, flags | O_NONBLOCK) == -1) - warn("couldn't set stdout to nonblock: %m"); - } - - nibuf = nobuf = 0; - ibufp = obufp = NULL; - pty_readable = stdin_readable = 1; - - ilevel = olevel = 0; - gettimeofday(&levelt, NULL); - if (max_data_rate) { - max_level = max_data_rate / 10; - if (max_level < 100) - max_level = 100; - } else - max_level = PPP_MRU + PPP_HDRLEN + 1; - - nfds = (ofd > pty_master? ofd: pty_master) + 1; - if (recordf != NULL) { - gettimeofday(&lasttime, NULL); - putc(7, recordf); /* put start marker */ - putc(lasttime.tv_sec >> 24, recordf); - putc(lasttime.tv_sec >> 16, recordf); - putc(lasttime.tv_sec >> 8, recordf); - putc(lasttime.tv_sec, recordf); - lasttime.tv_usec = 0; - } - - while (nibuf != 0 || nobuf != 0 || pty_readable || stdin_readable) { - top = 0; - tout.tv_sec = 0; - tout.tv_usec = 10000; - FD_ZERO(&ready); - FD_ZERO(&writey); - if (nibuf != 0) { - if (ilevel >= max_level) - top = &tout; - else - FD_SET(pty_master, &writey); - } else if (stdin_readable) - FD_SET(ifd, &ready); - if (nobuf != 0) { - if (olevel >= max_level) - top = &tout; - else - FD_SET(ofd, &writey); - } else if (pty_readable) - FD_SET(pty_master, &ready); - if (select(nfds, &ready, &writey, NULL, top) < 0) { - if (errno != EINTR) - fatal("select"); - continue; - } - if (max_data_rate) { - double dt; - int nbt; - struct timeval now; - - gettimeofday(&now, NULL); - dt = (now.tv_sec - levelt.tv_sec - + (now.tv_usec - levelt.tv_usec) / 1e6); - nbt = (int)(dt * max_data_rate); - ilevel = (nbt < 0 || nbt > ilevel)? 0: ilevel - nbt; - olevel = (nbt < 0 || nbt > olevel)? 0: olevel - nbt; - levelt = now; - } else - ilevel = olevel = 0; - if (FD_ISSET(ifd, &ready)) { - ibufp = inpacket_buf; - nibuf = read(ifd, ibufp, PPP_MRU + PPP_HDRLEN); - if (nibuf < 0 && errno == EIO) - nibuf = 0; - if (nibuf < 0) { - if (!(errno == EINTR || errno == EAGAIN)) { - error("Error reading standard input: %m"); - break; - } - nibuf = 0; - } else if (nibuf == 0) { - /* end of file from stdin */ - stdin_readable = 0; - if (recordf) - if (!record_write(recordf, 4, NULL, 0, &lasttime)) - recordf = NULL; - } else { - FD_SET(pty_master, &writey); - if (recordf) - if (!record_write(recordf, 2, ibufp, nibuf, &lasttime)) - recordf = NULL; - } - } - if (FD_ISSET(pty_master, &ready)) { - obufp = outpacket_buf; - nobuf = read(pty_master, obufp, PPP_MRU + PPP_HDRLEN); - if (nobuf < 0 && errno == EIO) - nobuf = 0; - if (nobuf < 0) { - if (!(errno == EINTR || errno == EAGAIN)) { - error("Error reading pseudo-tty master: %m"); - break; - } - nobuf = 0; - } else if (nobuf == 0) { - /* end of file from the pty - slave side has closed */ - pty_readable = 0; - stdin_readable = 0; /* pty is not writable now */ - nibuf = 0; - close(ofd); - if (recordf) - if (!record_write(recordf, 3, NULL, 0, &lasttime)) - recordf = NULL; - } else { - FD_SET(ofd, &writey); - if (recordf) - if (!record_write(recordf, 1, obufp, nobuf, &lasttime)) - recordf = NULL; - } - } else if (!stdin_readable) - pty_readable = 0; - if (FD_ISSET(ofd, &writey)) { - n = nobuf; - if (olevel + n > max_level) - n = max_level - olevel; - n = write(ofd, obufp, n); - if (n < 0) { - if (errno == EIO) { - pty_readable = 0; - nobuf = 0; - } else if (errno != EAGAIN && errno != EINTR) { - error("Error writing standard output: %m"); - break; - } - } else { - obufp += n; - nobuf -= n; - olevel += n; - } - } - if (FD_ISSET(pty_master, &writey)) { - n = nibuf; - if (ilevel + n > max_level) - n = max_level - ilevel; - n = write(pty_master, ibufp, n); - if (n < 0) { - if (errno == EIO) { - stdin_readable = 0; - nibuf = 0; - } else if (errno != EAGAIN && errno != EINTR) { - error("Error writing pseudo-tty master: %m"); - break; - } - } else { - ibufp += n; - nibuf -= n; - ilevel += n; - } - } - } - exit(0); -} - -static int -record_write(f, code, buf, nb, tp) - FILE *f; - int code; - u_char *buf; - int nb; - struct timeval *tp; -{ - struct timeval now; - int diff; - - gettimeofday(&now, NULL); - now.tv_usec /= 100000; /* actually 1/10 s, not usec now */ - diff = (now.tv_sec - tp->tv_sec) * 10 + (now.tv_usec - tp->tv_usec); - if (diff > 0) { - if (diff > 255) { - putc(5, f); - putc(diff >> 24, f); - putc(diff >> 16, f); - putc(diff >> 8, f); - putc(diff, f); - } else { - putc(6, f); - putc(diff, f); - } - *tp = now; - } - putc(code, f); - if (buf != NULL) { - putc(nb >> 8, f); - putc(nb, f); - fwrite(buf, nb, 1, f); - } - fflush(f); - if (ferror(f)) { - error("Error writing record file: %m"); - return 0; - } - return 1; -} - -#endif /* NEED OUR OWN PORT */