home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / SUN / PPP / SUNOS_OL / DDP_PPP.TAR / ppp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-03  |  8.4 KB  |  314 lines

  1. /*
  2.  * ppp.h - PPP global declarations.
  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. /*
  21.  * TODO:
  22.  */
  23.  
  24. #define NPPP    1        /* One PPP interface supported (per process) */
  25.  
  26. extern int debug;        /* Debug flag */
  27. extern int fsm_debug;        /* FSM debug flag */
  28. extern int lcp_debug;        /* LCP debug flag */
  29. extern int ipcp_debug;        /* IPCP debug flag */
  30. extern int upap_debug;        /* UPAP debug flag */
  31. extern char ifname[];        /* Interface name */
  32. extern int fd;            /* Device file descriptor */
  33. extern int s;            /* Socket file descriptor */
  34.  
  35. void quit();            /* Cleanup and exit */
  36. void timeout();            /* Look-alike of kernel's timeout() */
  37. void untimeout();        /* Look-alike of kernel's untimeout() */
  38. void output();            /* Output a PPP packet */
  39. void demuxprotrej();        /* Demultiplex a Protocol-Reject */
  40. u_char login();            /* Login user */
  41. void logout();            /* Logout user */
  42.  
  43. extern int errno;
  44.  
  45.  
  46. /*
  47.  * Inline versions of get/put char/short/long.
  48.  * Pointer is advanced; we assume that both arguments
  49.  * are lvalues and will already be in registers.
  50.  * cp MUST be u_char *.
  51.  */
  52. #define GETCHAR(c, cp) { \
  53.     (c) = *(cp)++; \
  54. }
  55. #define PUTCHAR(c, cp) { \
  56.     *(cp)++ = (c); \
  57. }
  58.  
  59.  
  60. #define GETSHORT(s, cp) { \
  61.     (s) = *(cp)++ << 8; \
  62.     (s) |= *(cp)++; \
  63. }
  64. #define PUTSHORT(s, cp) { \
  65.     *(cp)++ = (s) >> 8; \
  66.     *(cp)++ = (s); \
  67. }
  68.  
  69. #define GETLONG(l, cp) { \
  70.     (l) = *(cp)++ << 8; \
  71.     (l) |= *(cp)++; (l) <<= 8; \
  72.     (l) |= *(cp)++; (l) <<= 8; \
  73.     (l) |= *(cp)++; \
  74. }
  75. #define PUTLONG(l, cp) { \
  76.     *(cp)++ = (l) >> 24; \
  77.     *(cp)++ = (l) >> 16; \
  78.     *(cp)++ = (l) >> 8; \
  79.     *(cp)++ = (l); \
  80. }
  81.  
  82. #define INCPTR(n, cp)    ((cp) += (n))
  83. #define DECPTR(n, cp)    ((cp) -= (n))
  84.  
  85.  
  86. /*
  87.  * Data Link Layer header = Address, Control, Protocol.
  88.  */
  89. #define ALLSTATIONS    0xff    /* All-Stations Address */
  90. #define UI        0x03    /* Unnumbered Information */
  91. #define LCP        0xc021    /* Link Control Protocol */
  92. #define IPCP        0x8021    /* IP Control Protocol */
  93. #define UPAP        0xc023    /* User/Password Authentication Protocol */
  94. #define DLLHEADERLEN    (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
  95. #define MTU        1500    /* Default MTU */
  96.  
  97.  
  98. /*
  99.  * System dependent definitions for user-level 4.3BSD UNIX implementation.
  100.  */
  101. #define PACKET        u_char
  102. #define PACKET_DATA(p)    (p)
  103. #define PACKET_FREE(p)    (free((p) - DLLHEADERLEN))
  104. #define PACKET_ALLOC(s)    ((u_char *) malloc((s)+DLLHEADERLEN) + DLLHEADERLEN)
  105.  
  106. #define DEMUXPROTREJ(u, p) demuxprotrej(u, p)
  107.  
  108. #define TIMEOUT(r, f, t) timeout((r), (f), (t))
  109. #define UNTIMEOUT(r, f)    untimeout((r), (f))
  110.  
  111. #define BCOPY(s, d, l)    bcopy(s, d, l)
  112. #define EXIT(u)        quit()
  113.  
  114. #define GETUSERPASSWD(u)
  115. #define LOGIN(n, u, ul, p, pl, m, ml) login(u, ul, p, pl, m, ml);
  116. #define LOGOUT(n)    logout()
  117.  
  118. #define PRINTMSG(m, l)    { m[l] = '\0'; printf("%s\n", m); }
  119.  
  120.  
  121. /*
  122.  * OUTPUT - Output a PACKET.
  123.  */
  124. #define OUTPUT(u, p, l, t) { \
  125.     p -= DLLHEADERLEN; \
  126.     PUTCHAR(ALLSTATIONS, p); \
  127.     PUTCHAR(UI, p); \
  128.     PUTSHORT(t, p); \
  129.     output(u, p - DLLHEADERLEN, l + DLLHEADERLEN); }
  130.  
  131. /*
  132.  * SIFUP - Config the interface up.
  133.  */
  134. #define SIFUP(u)    { \
  135.     struct ifreq ifr; \
  136.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  137.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  138.     perror("ppp: ioctl (SIOCGIFFLAGS)"); \
  139.     quit(); \
  140.     } \
  141.     ifr.ifr_flags |= IFF_UP; \
  142.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  143.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  144.     quit(); \
  145.     } }
  146.  
  147. /*
  148.  * SIFDOWN - Config the interface down.
  149.  */
  150. #define SIFDOWN(u)    { \
  151.     struct ifreq ifr; \
  152.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  153.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  154.     perror("ppp: ioctl (SIOCGIFFLAGS)"); \
  155.     quit(); \
  156.     } \
  157.     ifr.ifr_flags &= ~IFF_UP; \
  158.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  159.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  160.     quit(); \
  161.     } }
  162.  
  163. /*
  164.  * SIFMTU - Config the interface MTU.
  165.  */
  166. #define SIFMTU(u, m)    { \
  167.     struct ifreq ifr; \
  168.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  169.     ifr.ifr_mtu = m; \
  170.     if (ioctl(s, SIOCSIFMTU, (caddr_t) &ifr) < 0) { \
  171.     perror("ppp: ioctl(SIOCSIFMTU)"); \
  172.     quit(); \
  173.     } }
  174.  
  175. /*
  176.  * SIFASYNCMAP - Config the interface async map.
  177.  */
  178. #define SIFASYNCMAP(u, a)    { \
  179.     struct ifreq ifr; \
  180.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  181.     ifr.ifr_asyncmap = a; \
  182.     if (ioctl(s, SIOCSIFASYNCMAP, (caddr_t) &ifr) < 0) { \
  183.     perror("ppp: ioctl(SIOCSIFASYNCMAP)"); \
  184.     quit(); \
  185.     } }
  186.  
  187. /*
  188.  * SIFPCOMPRESSION - Config the interface for protocol compression.
  189.  */
  190. #define SIFPCOMPRESSION(u)    { \
  191.     struct ifreq ifr; \
  192.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  193.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  194.     perror("ppp: ioctl (SIOCGIFFLAGS)"); \
  195.     quit(); \
  196.     } \
  197.     ifr.ifr_flags |= IFF_COMPPROT; \
  198.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  199.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  200.     quit(); \
  201.     } }
  202.  
  203. /*
  204.  * CIFPCOMPRESSION - Config the interface for no protocol compression.
  205.  */
  206. #define CIFPCOMPRESSION(u)    { \
  207.     struct ifreq ifr; \
  208.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  209.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  210.     perror("ppp: ioctl(SIOCGIFFLAGS)"); \
  211.     quit(); \
  212.     } \
  213.     ifr.ifr_flags &= ~IFF_COMPPROT; \
  214.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  215.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  216.     quit(); \
  217.     } }
  218.  
  219. /*
  220.  * SIFACCOMPRESSION - Config the interface for address/control compression.
  221.  */
  222. #define SIFACCOMPRESSION(u)    { \
  223.     struct ifreq ifr; \
  224.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  225.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  226.     perror("ppp: ioctl (SIOCGIFFLAGS)"); \
  227.     quit(); \
  228.     } \
  229.     ifr.ifr_flags |= IFF_COMPAC; \
  230.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  231.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  232.     quit(); \
  233.     } }
  234.  
  235. /*
  236.  * CIFACCOMPRESSION - Config the interface for no address/control compression.
  237.  */
  238. #define CIFACCOMPRESSION(u)    { \
  239.     struct ifreq ifr; \
  240.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  241.     if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { \
  242.     perror("ppp: ioctl (SIOCGIFFLAGS)"); \
  243.     quit(); \
  244.     } \
  245.     ifr.ifr_flags &= ~IFF_COMPAC; \
  246.     if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { \
  247.     perror("ppp: ioctl(SIOCSIFFLAGS)"); \
  248.     quit(); \
  249.     } }
  250.  
  251. /*
  252.  * SIFADDR - Config the interface IP addresses.
  253.  */
  254. #define SIFADDR(u, o, h)    { \
  255.     struct ifreq ifr; \
  256.     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); \
  257.     bzero((char *) &ifr.ifr_addr, sizeof(ifr.ifr_addr));  \
  258.     ifr.ifr_addr.sa_family = AF_INET; \
  259.     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o; \
  260.     if (ioctl(s, SIOCSIFADDR, (caddr_t) &ifr) < 0) { \
  261.     perror("ppp: ioctl(SIOCSIFADDR)"); \
  262.     } \
  263.     ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h; \
  264.     if (ioctl(s, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) { \
  265.     perror("ppp: ioctl(SIOCSIFDSTADDR)"); \
  266.     quit(); \
  267.     } }
  268.  
  269. /*
  270.  * CIFADDR - Clear the interface IP addresses.
  271.  */
  272. #define CIFADDR(u, o, h)    { \
  273.     struct rtentry rt; \
  274.     bzero((char *) &rt.rt_dst, sizeof(rt.rt_dst));  \
  275.     rt.rt_dst.sa_family = AF_INET; \
  276.     ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h; \
  277.     bzero((char *) &rt.rt_gateway, sizeof(rt.rt_gateway));  \
  278.     rt.rt_gateway.sa_family = AF_INET; \
  279.     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o; \
  280.     rt.rt_flags |= RTF_HOST; \
  281.     if (ioctl(s, SIOCDELRT, (caddr_t) &rt) < 0) { \
  282.     perror("ppp: ioctl(SIOCDELRT)"); \
  283.     quit(); \
  284.     } }
  285.  
  286.  
  287. #ifdef DEBUGFSM
  288. extern fsm_debug;
  289. #define FSMDEBUG(x)    if (fsm_debug) fprintf x;
  290. #else
  291. #define FSMDEBUG(x)
  292. #endif
  293.  
  294. #ifdef DEBUGLCP
  295. extern lcp_debug;
  296. #define LCPDEBUG(x)    if (lcp_debug) fprintf x;
  297. #else
  298. #define LCPDEBUG(x)
  299. #endif
  300.  
  301. #ifdef DEBUGIPCP
  302. extern ipcp_debug;
  303. #define IPCPDEBUG(x)    if (ipcp_debug) fprintf x;
  304. #else
  305. #define IPCPDEBUG(x)
  306. #endif
  307.  
  308. #ifdef DEBUGUPAP
  309. extern upap_debug;
  310. #define UPAPDEBUG(x)    if (upap_debug) fprintf x;
  311. #else
  312. #define UPAPDEBUG(x)
  313. #endif
  314.