pppd.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:12k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* pppd.h - PPP daemon header */
  2. /* Copyright 1995 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1989 Carnegie Mellon University.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms are permitted
  8.  * provided that the above copyright notice and this paragraph are
  9.  * duplicated in all such forms and that any documentation,
  10.  * advertising materials, and other materials related to such
  11.  * distribution and use acknowledge that the software was developed
  12.  * by Carnegie Mellon University.  The name of the
  13.  * University may not be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19. /*
  20. modification history
  21. --------------------
  22. 01l,29oct01,gls  removed definition of sleep()
  23. 01k,05aug96,vin  included if_types.h.
  24. 01j,22jun95,dzb  changed [un]timeout() to ppp_[un]timeout().
  25.                  removed usehostname option.
  26. 01i,12jun95,dzb  added SNMP MIBII counters to ppp_task_vars.
  27.                  header file consolidation.  changed to ppp_auth.h.
  28.  moved PPP_OPTIONS and options flags to options.h.
  29.  removed device_script() prototype.
  30.  changed [dis[connect strings to global hook routines.
  31.  changed [UN]TIMEOUT macros to PPP_[UN]TIMEOUT. 
  32. 01h,22may95,dzb  Added OPT_REQUIRE_PAP and OPT_REQUIRE_CHAP.
  33. 01g,16may95,dzb  Added uselogin and OPT_LOGIN for login option.
  34.                  removed logged_in and attempts fields from PPP_TASK_VARS.
  35. 01f,05may95,dzb  added pap_passwd field to ppp_options structure.
  36. 01e,07mar95,dzb  moved pppInit() and pppDelete() prototypes to pppLib.h.
  37. 01d,09feb95,dab  removed lcp_echo_fails_reached, uselogin, and OPT_LOGIN.
  38. 01c,24jan95,dzb  renamed protoype params for pppInit() and ppp_task().
  39. 01b,16jan95,dzb  moved in ARGS macro from args.h.
  40.  moved in callout from callout.h.
  41.  moved in patch level macros from patchlevel.h.
  42. 01a,13jan95,dab  VxWorks port - first WRS version.
  43.    +dzb  added: path for ppp header files, WRS copyright.  WRS-ize.
  44. */
  45. #ifndef __INCpppdh
  46. #define __INCpppdh
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. #ifndef __ARGS
  51. #ifdef __STDC__
  52. #define __ARGS(x)       x
  53. #else
  54. #define __ARGS(x)       ()
  55. #endif
  56. #endif
  57. /* includes */
  58. #include "wdLib.h"
  59. #include "semLib.h"
  60. #include "remLib.h"
  61. #include "net/if.h"
  62. #include "net/if_types.h"
  63. #include "time.h"
  64. #include "netinet/ppp/ppp.h"
  65. #include "netinet/ppp/ppp_auth.h"
  66. #include "netinet/ppp/chap.h"
  67. #include "netinet/ppp/fsm.h"
  68. #include "netinet/ppp/if_ppp.h"
  69. #include "netinet/ppp/ipcp.h"
  70. #include "netinet/ppp/lcp.h"
  71. #include "netinet/ppp/magic.h"
  72. #include "netinet/ppp/md5.h"
  73. #include "netinet/ppp/options.h"
  74. #include "netinet/ppp/ppp_vxworks.h"
  75. #include "netinet/ppp/random.h"
  76. #include "netinet/ppp/upap.h"
  77. /* defines */
  78. /*
  79.  * Patch level
  80.  */
  81. #define PATCHLEVEL      2
  82. #define VERSION "2.1"
  83. #define DATE "9 June 94"
  84. /*
  85.  * Limits.
  86.  */
  87. #define MAXWORDLEN      1024    /* max length of word in file (incl null) */
  88. #define MAXARGS         1       /* max # args to a command */
  89. #define MAXNAMELEN      256     /* max length of hostname or name for auth */
  90. #define MAXSECRETLEN    256     /* max length of password or secret */
  91. #define MAXPATHLEN     1024    /* max length of password or secret */
  92. /*
  93.  * Values for phase.
  94.  */
  95. #define PHASE_DEAD              0
  96. #define PHASE_ESTABLISH         1
  97. #define PHASE_AUTHENTICATE      2
  98. #define PHASE_NETWORK           3
  99. #define PHASE_TERMINATE         4
  100. #ifndef SIOCSIFMTU
  101. #define SIOCSIFMTU      _IOW('i', 140, int)
  102. #endif /* SIOCSIFMTU */
  103. #ifndef SIOCGIFMTU
  104. #define SIOCGIFMTU      _IOR('i', 141, int)
  105. #endif /* SIOCGIFMTU */
  106. /* Used for storing a sequence of words.  Usually malloced. */
  107. struct wordlist {
  108. struct wordlist *next;
  109. char word[1];
  110. };
  111. /*
  112.  * This is a copy of /usr/include/sys/callout.h with the c_func
  113.  * member of struct callout changed from a pointer to a function of type int
  114.  * to a pointer to a function of type void (generic pointer) as per ANSI C
  115.  */
  116. struct  callout {
  117.         int     c_time;         /* incremental time */
  118.         caddr_t c_arg;          /* argument to routine */
  119.         void    (*c_func)();    /* routine (changed to void (*)() */
  120.         struct  callout *c_next;
  121. };
  122. /* PPP task variables structure */
  123. typedef struct ppp_task_vars
  124. {
  125. PPP_OPTIONS *options; /* Configuration options */
  126. int task_id; /* Task id of pppd task */
  127. /* interface varibles */
  128. char ifname[IFNAMSIZ]; /* Interface name */
  129. int ifunit; /* Interface unit number */
  130. /* descriptors */
  131. int fd; /* Device descriptor */
  132. int s; /* Socket descriptor */
  133. /* timer variables */
  134. struct callout *callout; /* Callout list */
  135. timer_t timer_id; /* Id of alarm timer */
  136. time_t schedtime; /* Time last timeout was set */
  137. /* configured variables */
  138. int debug; /* Debug flag */
  139. int inspeed;                    /* Input/Output speed requested */
  140. u_long netmask;                 /* Netmask to use on PPP interface */
  141. int auth_required;              /* Require peer to authenticate */
  142. int defaultroute;               /* Assign default rte through interf */
  143. int proxyarp;                   /* Set entry in arp table */
  144. int uselogin;                   /* Check PAP info against login table */
  145. int phase;                      /* Where the link is at */
  146. int baud_rate;                  /* Bits/sec currently used */
  147. char user[MAXNAMELEN]; /* User name */
  148. char passwd[MAXSECRETLEN];      /* Password for PAP */
  149. int disable_defaultip; /* Use hostname IP address */
  150. int kdebugflag; /* Enable driver debug */
  151. char hostname[MAXNAMELEN]; /* Our host name */
  152. char our_name[MAXNAMELEN]; /* Authentication host name */
  153. char remote_name[MAXNAMELEN]; /* Remote host name */
  154. char devname[MAXPATHLEN]; /* Device name */
  155. int ttystate; /* Initial TTY state */
  156. int restore_term;         /* 1 => we've munged the terminal */
  157. /* Buffer for outgoing packet */
  158. u_char outpacket_buf[MTU + DLLHEADERLEN];
  159. /* Buffer for incoming packet */
  160. u_char inpacket_buf[MTU + DLLHEADERLEN];
  161. int hungup;                     /* Terminal has been hung up */
  162. int peer_mru; /* Peer MRU */
  163. /* Records which authentication operations haven't completed yet. */
  164. int auth_pending; /* Authentication state */
  165. struct wordlist *addresses; /* List of acceptable IP addresses */
  166. /* lcp echo variables */
  167. u_long lcp_echos_pending; /* Number of outstanding echo msgs */
  168. u_long lcp_echo_number;     /* ID number of next echo frame */
  169. u_long lcp_echo_timer_running; /* TRUE if a timer running */
  170. u_long lcp_echo_interval; /* Seconds between intervals */
  171. u_long lcp_echo_fails; /* Number of echo failures */
  172. /* chap variables */
  173. chap_state chap; /* CHAP structure */
  174.         /* ipcp variables */
  175. ipcp_options ipcp_wantoptions; /* Options we want to request */
  176. ipcp_options ipcp_gotoptions;  /* Options that peer ack'd */
  177. ipcp_options ipcp_allowoptions; /* Options we allow peer to request */
  178. ipcp_options ipcp_hisoptions; /* Options that we ack'd */
  179. fsm ipcp_fsm;             /* IPCP fsm structure */
  180. int cis_received;           /* # Conf-Reqs received */
  181. /* lcp variables */
  182. lcp_options lcp_wantoptions; /* Options that we want to request */
  183. lcp_options lcp_gotoptions; /* Options that peer ack'd */
  184. lcp_options lcp_allowoptions; /* Options we allow peer to request */
  185. lcp_options lcp_hisoptions; /* Options that we ack'd */
  186. u_long xmit_accm[8]; /* extended transmit ACCM */
  187. fsm lcp_fsm; /* LCP fsm structure */
  188. /* upap variables */
  189. upap_state upap; /* UPAP state; one for each unit */
  190. /* SNMP MIBII counters */
  191. u_long unknownProto; /* MIBII: ifInUnknownProtos */
  192. } PPP_TASK_VARS;
  193. /* 
  194.  * Externals
  195.  */
  196. extern int ppp_unit;
  197. extern PPP_TASK_VARS *ppp_if[];
  198. extern void syslog(int, char *, ...);
  199. extern FUNCPTR pppConnectHook; /* user connect hook routine */ 
  200. extern FUNCPTR pppDisconnectHook; /* user disconnect hook routine */ 
  201. /*
  202.  * Inline versions of get/put char/short/long.
  203.  * Pointer is advanced; we assume that both arguments
  204.  * are lvalues and will already be in registers.
  205.  * cp MUST be u_char *.
  206.  */
  207. #define GETCHAR(c, cp) { 
  208. (c) = *(cp)++; 
  209. }
  210. #define PUTCHAR(c, cp) { 
  211. *(cp)++ = (u_char) (c); 
  212. }
  213. #define GETSHORT(s, cp) { 
  214. (s) = *(cp)++ << 8; 
  215. (s) |= *(cp)++; 
  216. }
  217. #define PUTSHORT(s, cp) { 
  218. *(cp)++ = (u_char) ((s) >> 8); 
  219. *(cp)++ = (u_char) (s); 
  220. }
  221. #define GETLONG(l, cp) { 
  222. (l) = *(cp)++ << 8; 
  223. (l) |= *(cp)++; (l) <<= 8; 
  224. (l) |= *(cp)++; (l) <<= 8; 
  225. (l) |= *(cp)++; 
  226. }
  227. #define PUTLONG(l, cp) { 
  228. *(cp)++ = (u_char) ((l) >> 24); 
  229. *(cp)++ = (u_char) ((l) >> 16); 
  230. *(cp)++ = (u_char) ((l) >> 8); 
  231. *(cp)++ = (u_char) ((l)); 
  232. }
  233. #define INCPTR(n, cp) ((cp) += (n))
  234. #define DECPTR(n, cp) ((cp) -= (n))
  235. /*
  236.  * System dependent definitions for user-level 4.3BSD UNIX implementation.
  237.  */
  238. #define DEMUXPROTREJ(u, p)  demuxprotrej(u, p)
  239. #define PPP_TIMEOUT(r, f, t)  ppp_timeout((r), (f), (t))
  240. #define PPP_UNTIMEOUT(r, f) ppp_untimeout((r), (f))
  241. #define BCOPY(s, d, l) bcopy((char *) s, (char *) d, (int) l)
  242. #define BZERO(s, n)             bzero(s, n)
  243. #define EXIT(u) die(u, 0)
  244. #define PRINTMSG(m, l) { m[l] = ''; syslog(LOG_INFO, "Remote message: %s", m); }
  245. /*
  246.  * MAKEHEADER - Add Header fields to a packet.
  247.  */
  248. #define MAKEHEADER(p, t) { 
  249.     PUTCHAR(ALLSTATIONS, p); 
  250.     PUTCHAR(UI, p); 
  251.     PUTSHORT(t, p); }
  252. #ifdef DEBUGALL
  253. #define DEBUGMAIN       1
  254. #define DEBUGFSM        1
  255. #define DEBUGLCP        1
  256. #define DEBUGIPCP       1
  257. #define DEBUGUPAP       1
  258. #define DEBUGCHAP       1
  259. #endif
  260. #ifndef LOG_PPP /* we use LOG_LOCAL2 for syslog by default */
  261. #if defined(DEBUGMAIN) || defined(DEBUGFSM) || defined(DEBUG) 
  262.   || defined(DEBUGLCP) || defined(DEBUGIPCP) || defined(DEBUGUPAP) 
  263.   || defined(DEBUGCHAP) 
  264. #define LOG_PPP LOG_LOCAL2
  265. #else
  266. #define LOG_PPP LOG_DAEMON
  267. #endif
  268. #endif /* LOG_PPP */
  269. #ifdef DEBUGMAIN
  270. #define MAINDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  271. #else
  272. #define MAINDEBUG(x)
  273. #endif
  274. #ifdef DEBUGFSM
  275. #define FSMDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  276. #else
  277. #define FSMDEBUG(x)
  278. #endif
  279. #ifdef DEBUGLCP
  280. #define LCPDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  281. #else
  282. #define LCPDEBUG(x)
  283. #endif
  284. #ifdef DEBUGIPCP
  285. #define IPCPDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  286. #else
  287. #define IPCPDEBUG(x)
  288. #endif
  289. #ifdef DEBUGUPAP
  290. #define UPAPDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  291. #else
  292. #define UPAPDEBUG(x)
  293. #endif
  294. #ifdef DEBUGCHAP
  295. #define CHAPDEBUG(x) if (ppp_if[ppp_unit]->debug) syslog x;
  296. #else
  297. #define CHAPDEBUG(x)
  298. #endif
  299. #ifndef SIGTYPE
  300. #if defined(sun) || defined(SYSV) || defined(POSIX_SOURCE)
  301. #define SIGTYPE void
  302. #else
  303. #define SIGTYPE int
  304. #endif /* defined(sun) || defined(SYSV) || defined(POSIX_SOURCE) */
  305. #endif /* SIGTYPE */
  306. #ifndef MIN
  307. #define MIN(a, b)       ((a) < (b)? (a): (b))
  308. #endif
  309. #ifndef MAX
  310. #define MAX(a, b)       ((a) > (b)? (a): (b))
  311. #endif
  312. #undef  LOG_WARNING
  313. #undef  LOG_ERR
  314. #undef  LOG_INFO
  315. #undef  LOG_NOTICE
  316. #undef  LOG_DEBUG
  317. #undef  LOG_UPTO
  318. #define LOG_WARNING 0
  319. #define LOG_ERR 1
  320. #define LOG_INFO 2
  321. #define LOG_NOTICE 3
  322. #define LOG_DEBUG 4
  323. #define LOG_UPTO 5
  324. #ifndef DEBUGALL
  325. #define _assert(ex)    {if (!(ex)){(void)syslog(LOG_ERR,"Assertion failed: file "%s", line %dn", __FILE__, __LINE__);die(ppp_unit, 1);}}
  326. #define assert(ex)     _assert(ex)
  327. #else
  328. #define _assert(ex)
  329. #define assert(ex)
  330. #endif
  331. void format_packet __ARGS((u_char *, int,
  332.    void (*) (void *, char *, ...), void *));
  333. /* function declarations */
  334. #if defined(__STDC__) || defined(__cplusplus)
  335. extern void ppp_task (int unit, char *devname, char *local_addr,
  336.     char *remote_addr, int baud, PPP_OPTIONS *pOptions,
  337.     char *fOptions);
  338. extern void die (int unit, int status);
  339. extern void ppp_timeout (void (*func) (), caddr_t arg, int seconds);
  340. extern void ppp_untimeout (void (*func) (), caddr_t arg);
  341. extern void adjtimeout (void);
  342. extern void demuxprotrej (int unit, u_short protocol);
  343. extern void log_packet (u_char *p, int len, char *prefix);
  344. extern void print_string (char *p, int len, void (*printer)
  345.                     (void *, char *, ...), void *arg);
  346. extern void pr_log (void *arg, char *fmt, ...);
  347. extern void format_packet (u_char *p, int len,
  348.    void (*printer) (void *, char *, ...), void *arg);
  349. extern void novm (char *msg);
  350. #else /* __STDC__ */
  351.  
  352. extern int ppp_task ();
  353. extern void die ();
  354. extern void ppp_timeout ();
  355. extern void ppp_untimeout ();
  356. extern void adjtimeout ();
  357. extern void demuxprotrej ();
  358. extern void log_packet ();
  359. extern void print_string ();
  360. extern void pr_log ();
  361. extern void format_packet ();
  362. extern void novm ();
  363. #endif /* __STDC__ */
  364.   
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368. #endif /* __INCpppdh */