File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / ppp.h
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:39:23 2021 UTC (4 years ago) by misho
Branches: mpd, MAIN
CVS tags: v5_9p16, v5_9, HEAD
mpd 5.9

    1: 
    2: /*
    3:  * ppp.h
    4:  *
    5:  * Written by Archie Cobbs <archie@freebsd.org>
    6:  * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
    7:  * See ``COPYRIGHT.whistle''
    8:  */
    9: 
   10: #ifndef _PPP_H_
   11: #define _PPP_H_
   12: 
   13: /* Keep source files simple */
   14: 
   15: #include <sys/types.h>
   16: #include <sys/param.h>
   17: #include <sys/socket.h>
   18: #include <sys/ioctl.h>
   19: #include <poll.h>
   20: #include <sys/time.h>
   21: #include <sys/uio.h>
   22: #include <sys/queue.h>
   23: #include <stdio.h>
   24: #include <stdlib.h>
   25: #include <limits.h>
   26: #include <stddef.h>
   27: #include <stdarg.h>
   28: #include <string.h>
   29: #include <signal.h>
   30: #include <ctype.h>
   31: #include <unistd.h>
   32: #include <errno.h>
   33: #include <err.h>
   34: #include <netdb.h>
   35: #include <fcntl.h>
   36: #include <machine/endian.h>
   37: #include <net/ppp_defs.h>
   38: #include <netinet/in.h>
   39: #include <arpa/inet.h>
   40: 
   41: #include <pthread.h>
   42: #ifdef NOLIBPDEL
   43: #include "contrib/libpdel/structs/structs.h"
   44: #include "contrib/libpdel/structs/type/array.h"
   45: #include "contrib/libpdel/util/typed_mem.h"
   46: #include "contrib/libpdel/util/pevent.h"
   47: #include "contrib/libpdel/util/paction.h"
   48: #include "contrib/libpdel/util/ghash.h"
   49: #else
   50: #include <pdel/structs/structs.h>
   51: #include <pdel/structs/type/array.h>
   52: #include <pdel/util/typed_mem.h>
   53: #include <pdel/util/pevent.h>
   54: #include <pdel/util/paction.h>
   55: #include <pdel/util/ghash.h>
   56: #endif
   57: 
   58: #include <netgraph/ng_message.h>
   59: #include <netgraph/ng_ppp.h>
   60: 
   61: #include "defs.h"
   62: #include "msg.h"
   63: 
   64: /*
   65:  * DEFINITIONS
   66:  */
   67: 
   68:   /* Do our own version of assert() so it shows up in the logs */
   69:   #define assert(e)	((e) ? (void)0 : DoAssert(__FILE__, __LINE__, #e))
   70: 
   71: #ifdef __clang__
   72: 
   73: #ifndef THREAD_ANNOTATION_ATTRIBUTE__
   74:   #define THREAD_ANNOTATION_ATTRIBUTE__(x)   __attribute__((x))
   75: #else
   76:   #define THREAD_ANNOTATION_ATTRIBUTE__(x)
   77: #endif
   78: 
   79: #ifndef NO_THREAD_SAFETY_ANALYSIS
   80:   #define NO_THREAD_SAFETY_ANALYSIS \
   81: 	THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
   82: #else
   83:   #define NO_THREAD_SAFETY_ANALYSIS
   84: #endif
   85: 
   86: #endif /* __clang__ */
   87: 
   88:   /* Giant Mutex handling */
   89:   #define GIANT_MUTEX_LOCK()	assert(pthread_mutex_lock(&gGiantMutex) == 0)
   90:   #define GIANT_MUTEX_UNLOCK()	assert(pthread_mutex_unlock(&gGiantMutex) == 0)
   91: 
   92:   #define MUTEX_LOCK(m)		assert(pthread_mutex_lock(&m) == 0)
   93:   #define MUTEX_UNLOCK(m)	assert(pthread_mutex_unlock(&m) == 0)
   94: 
   95:   #define RWLOCK_RDLOCK(m)	assert(pthread_rwlock_rdlock(&m) == 0)
   96:   #define RWLOCK_WRLOCK(m)	assert(pthread_rwlock_wrlock(&m) == 0)
   97:   #define RWLOCK_UNLOCK(m)	assert(pthread_rwlock_unlock(&m) == 0)
   98: 
   99:   #define SETOVERLOAD(q)						\
  100: 	do {								\
  101: 		int t = (q);						\
  102: 		if (t > gQThresMax) {					\
  103: 			gOverload = 100;				\
  104: 		} else if (t > gQThresMin) {				\
  105: 			gOverload = (t - gQThresMin) * 100/gQThresDiff;	\
  106: 		} else {						\
  107: 			gOverload = 0;					\
  108: 		}							\
  109: 	} while (0)
  110: 
  111:   #define OVERLOAD()		(gOverload > (random() % 100))
  112:   
  113:   #define REF(p)		do {					\
  114: 				    (p)->refs++;			\
  115: 				} while (0)
  116: 
  117:   #define UNREF(p)		do {					\
  118: 				    if ((--(p)->refs) == 0)		\
  119: 					Freee(p);			\
  120: 				} while (0)
  121: 
  122:   #define RESETREF(v, p)	do {					\
  123: 				    if (v) UNREF(v);			\
  124: 				    (v) = (p);				\
  125: 				    if (v) REF(v);			\
  126: 				} while (0)
  127: 
  128:   #define ADLG_WAN_AUTHORIZATION_FAILURE	0
  129:   #define ADLG_WAN_CONNECTED			1
  130:   #define ADLG_WAN_CONNECTING			2
  131:   #define ADLG_WAN_CONNECT_FAILURE		3
  132:   #define ADLG_WAN_DISABLED			4
  133:   #define ADLG_WAN_MESSAGE			5
  134:   #define ADLG_WAN_NEGOTIATION_FAILURE		6
  135:   #define ADLG_WAN_WAIT_FOR_DEMAND		7
  136: 
  137: #ifndef NG_PPP_STATS64
  138:   /* internal 64 bit counters as workaround for the 32 bit 
  139:    * limitation for ng_ppp_link_stat
  140:    */
  141:   struct ng_ppp_link_stat64 {
  142: 	u_int64_t 	xmitFrames;	/* xmit frames on link */
  143: 	u_int64_t 	xmitOctets;	/* xmit octets on link */
  144: 	u_int64_t 	recvFrames;	/* recv frames on link */
  145: 	u_int64_t	recvOctets;	/* recv octets on link */
  146: 	u_int64_t 	badProtos;	/* frames rec'd with bogus protocol */
  147: 	u_int64_t 	runts;		/* Too short MP fragments */
  148: 	u_int64_t 	dupFragments;	/* MP frames with duplicate seq # */
  149: 	u_int64_t	dropFragments;	/* MP fragments we had to drop */
  150:   };
  151: #endif
  152: 
  153: #if defined(USE_NG_BPF) || defined(USE_IPFW)
  154:   /* max. length of acl rule */
  155:   #define ACL_LEN	256
  156:   #define ACL_NAME_LEN	16
  157:   /* max. number of acl_filters */
  158:   #define ACL_FILTERS	16
  159:   /* There are two directions for acl_limits */
  160:   #define ACL_DIRS	2
  161: #endif
  162: 
  163: #ifdef USE_NG_BPF
  164:   struct svcssrc {
  165:     int				type;
  166:   #define SSSS_IN	1
  167:   #define SSSS_MATCH	2
  168:   #define SSSS_NOMATCH	3
  169:   #define SSSS_OUT	4
  170:     char			hook[NG_HOOKSIZ];
  171:     SLIST_ENTRY(svcssrc)	next;
  172:   };
  173: 
  174:   struct svcs {
  175:     char 			name[ACL_NAME_LEN]; 	/* Name of ACL */
  176:     SLIST_HEAD(, svcssrc)	src;
  177:     SLIST_ENTRY(svcs)		next;
  178:   };
  179: 
  180:   struct svcstatrec {
  181:     char			name[ACL_NAME_LEN]; 	/* Name of ACL */
  182:     u_int64_t			Packets;
  183:     u_int64_t			Octets;
  184:     SLIST_ENTRY(svcstatrec)	next;
  185:   };
  186:   
  187:   struct svcstat {
  188:     SLIST_HEAD(, svcstatrec)	stat[ACL_DIRS];
  189:   };
  190: #endif /* USE_NG_BPF */
  191: 
  192: #include "bund.h"
  193: #include "link.h"
  194: #include "rep.h"
  195: #include "phys.h"
  196: #include "msgdef.h"
  197: 
  198: /*
  199:  * VARIABLES
  200:  */
  201: 
  202:   extern Rep		*gReps;			/* Repeaters */
  203:   extern Link		*gLinks;		/* Links */
  204:   extern Bund		*gBundles;		/* Bundles */
  205: 
  206:   extern int		gNumReps;		/* Total number of repeaters */
  207:   extern int		gNumLinks;		/* Total number of links */
  208:   extern int		gNumBundles;		/* Total number of bundles */
  209:   extern struct console	gConsole;
  210:   extern struct web	gWeb;
  211:   extern struct radsrv	gRadsrv;
  212:   extern int		gBackground;
  213:   extern int		gShutdownInProgress;
  214:   extern int		gOverload;
  215:   extern pid_t		gPid;
  216:   extern int		gRouteSeq;
  217: 
  218: #ifdef PHYSTYPE_PPTP
  219:   extern int		gPPTPto;
  220:   extern unsigned	gPPTPtunlimit;
  221: #endif
  222: #ifdef PHYSTYPE_L2TP
  223:   extern int		gL2TPto;
  224:   extern unsigned	gL2TPtunlimit;
  225: #endif
  226:   extern int		gChildren;
  227:   extern int		gMaxChildren;
  228: 
  229:   extern struct globalconf	gGlobalConf;	/* Global config settings */
  230: 
  231: #if defined(USE_NG_BPF) && !defined(RADSRV)
  232:   extern struct acl		*acl_filters[ACL_FILTERS]; /* mpd's internal bpf filters */
  233: #endif
  234: 
  235: #ifdef USE_PAM
  236:   extern char			gPamService[32];
  237: #endif
  238: 
  239:   extern struct pevent_ctx	*gPeventCtx;
  240:   extern pthread_mutex_t	gGiantMutex;	/* Giant Mutex */
  241: 
  242:   extern const char	*gVersion;		/* Program version string */
  243:   extern const char	*gConfigFile;		/* Main config file */
  244:   extern const char	*gConfDirectory;	/* Where the files are */
  245: 
  246: /*
  247:  * FUNCTIONS
  248:  */
  249: 
  250:   extern void		Greetings(void);
  251:   extern void		SendSignal(int sig);
  252:   extern void		DoExit(int code) __dead2;
  253:   extern void		DoAssert(const char *file, int line, const char *x) __dead2;
  254:   extern void		CheckOneShot(void);
  255: 
  256: #endif
  257: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>