if_sppp.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* $OpenBSD: if_sppp.h,v 1.20 2013/11/20 08:21:33 stsp Exp $ */
  2. /* $NetBSD: if_sppp.h,v 1.2.2.1 1999/04/04 06:57:39 explorer Exp $ */
  3. /*
  4. * Defines for synchronous PPP/Cisco link level subroutines.
  5. *
  6. * Copyright (C) 1994 Cronyx Ltd.
  7. * Author: Serge Vakulenko, <vak@cronyx.ru>
  8. *
  9. * Heavily revamped to conform to RFC 1661.
  10. * Copyright (C) 1997, Joerg Wunsch.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * 1. Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY
  21. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE
  24. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * From: Version 2.0, Fri Oct 6 20:39:21 MSK 1995
  33. *
  34. * From: if_sppp.h,v 1.8 1997/10/11 11:25:20 joerg Exp
  35. *
  36. * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp
  37. */
  38. #ifndef _NET_IF_SPPP_H_
  39. #define _NET_IF_SPPP_H_
  40. #define AUTHFLAG_NOCALLOUT 1 /* don't require authentication on callouts */
  41. #define AUTHFLAG_NORECHALLENGE 2 /* don't re-challenge CHAP */
  42. /*
  43. * Don't change the order of this. Ordering the phases this way allows
  44. * for a comparision of ``pp_phase >= PHASE_AUTHENTICATE'' in order to
  45. * know whether LCP is up.
  46. */
  47. enum ppp_phase {
  48. PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE,
  49. PHASE_AUTHENTICATE, PHASE_NETWORK
  50. };
  51. #define AUTHMAXLEN 256 /* including terminating '\0' */
  52. #define AUTHCHALEN 16 /* length of the challenge we send */
  53. /*
  54. * Definitions to pass struct sppp data down into the kernel using the
  55. * SIOC[SG]IFGENERIC ioctl interface.
  56. *
  57. * In order to use this, create a struct spppreq, fill in the cmd
  58. * field with SPPPIOGDEFS, and put the address of this structure into
  59. * the ifr_data portion of a struct ifreq. Pass this struct to a
  60. * SIOCGIFGENERIC ioctl. Then replace the cmd field by SPPPIOSDEFS,
  61. * modify the defs field as desired, and pass the struct ifreq now
  62. * to a SIOCSIFGENERIC ioctl.
  63. */
  64. struct sauthreq {
  65. int cmd;
  66. u_short proto; /* authentication protocol to use */
  67. u_short flags;
  68. u_char name[AUTHMAXLEN]; /* system identification name */
  69. u_char secret[AUTHMAXLEN]; /* secret password */
  70. };
  71. struct spppreq {
  72. int cmd;
  73. enum ppp_phase phase; /* phase we're currently in */
  74. };
  75. #define SPPPIOGDEFS ((int)(('S' << 24) + (1 << 16) + sizeof(struct spppreq)))
  76. #define SPPPIOSDEFS ((int)(('S' << 24) + (2 << 16) + sizeof(struct spppreq)))
  77. #define SPPPIOGMAUTH ((int)(('S' << 24) + (3 << 16) + sizeof(struct sauthreq)))
  78. #define SPPPIOSMAUTH ((int)(('S' << 24) + (4 << 16) + sizeof(struct sauthreq)))
  79. #define SPPPIOGHAUTH ((int)(('S' << 24) + (5 << 16) + sizeof(struct sauthreq)))
  80. #define SPPPIOSHAUTH ((int)(('S' << 24) + (6 << 16) + sizeof(struct sauthreq)))
  81. #ifdef _KERNEL
  82. #include <sys/timeout.h>
  83. #include <sys/task.h>
  84. #ifdef INET6
  85. #include <netinet/in.h>
  86. #include <netinet6/in6_var.h>
  87. #endif
  88. #define IDX_LCP 0 /* idx into state table */
  89. struct slcp {
  90. u_long opts; /* LCP options to send (bitfield) */
  91. u_long magic; /* local magic number */
  92. u_long mru; /* our max receive unit */
  93. u_long their_mru; /* their max receive unit */
  94. u_long protos; /* bitmask of protos that are started */
  95. u_char echoid; /* id of last keepalive echo request */
  96. /* restart max values, see RFC 1661 */
  97. int timeout;
  98. int max_terminate;
  99. int max_configure;
  100. int max_failure;
  101. };
  102. #define IDX_IPCP 1 /* idx into state table */
  103. #define IDX_IPV6CP 2
  104. struct sipcp {
  105. u_long opts; /* IPCP options to send (bitfield) */
  106. u_int flags;
  107. #define IPCP_HISADDR_SEEN 1 /* have seen his address already */
  108. #define IPCP_MYADDR_DYN 2 /* my address is dynamically assigned */
  109. #define IPCP_MYADDR_SEEN 4 /* have seen my address already */
  110. #define IPCP_HISADDR_DYN 8 /* his address is dynamically assigned */
  111. #define IPV6CP_MYIFID_DYN 1 /* my ifid is dynamically assigned */
  112. #define IPV6CP_MYIFID_SEEN 2 /* have seen my suggested ifid */
  113. u_int32_t saved_hisaddr; /* if hisaddr (IPv4) is dynamic, save
  114. * original one here, in network byte order */
  115. u_int32_t req_hisaddr; /* remote address requested (IPv4) */
  116. u_int32_t req_myaddr; /* local address requested (IPv4) */
  117. #ifdef INET6
  118. struct in6_aliasreq req_ifid; /* local ifid requested (IPv6) */
  119. #endif
  120. struct task set_addr_task; /* set address from process context */
  121. struct task clear_addr_task; /* clear address from process context */
  122. };
  123. struct sauth {
  124. u_short proto; /* authentication protocol to use */
  125. u_short flags;
  126. u_char *name; /* system identification name */
  127. u_char *secret; /* secret password */
  128. };
  129. #define IDX_PAP 3
  130. #define IDX_CHAP 4
  131. #define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
  132. struct sppp {
  133. /* NB: pp_if _must_ be first */
  134. struct ifnet pp_if; /* network interface data */
  135. struct ifqueue pp_cpq; /* PPP control protocol queue */
  136. struct sppp *pp_next; /* next interface in keepalive list */
  137. u_int pp_flags; /* use Cisco protocol instead of PPP */
  138. u_int pp_framebytes; /* number of bytes added by hardware framing */
  139. u_short pp_alivecnt; /* keepalive packets counter */
  140. u_short pp_loopcnt; /* loopback detection counter */
  141. u_int32_t pp_seq; /* local sequence number */
  142. u_int32_t pp_rseq; /* remote sequence number */
  143. time_t pp_last_receive; /* peer's last "sign of life" */
  144. time_t pp_last_activity; /* second of last payload data s/r */
  145. enum ppp_phase pp_phase; /* phase we're currently in */
  146. int state[IDX_COUNT]; /* state machine */
  147. u_char confid[IDX_COUNT]; /* id of last configuration request */
  148. int rst_counter[IDX_COUNT]; /* restart counter */
  149. int fail_counter[IDX_COUNT]; /* negotiation failure counter */
  150. struct timeout ch[IDX_COUNT];
  151. struct timeout pap_my_to_ch;
  152. struct slcp lcp; /* LCP params */
  153. struct sipcp ipcp; /* IPCP params */
  154. struct sipcp ipv6cp; /* IPV6CP params */
  155. struct sauth myauth; /* auth params, i'm peer */
  156. struct sauth hisauth; /* auth params, i'm authenticator */
  157. u_char chap_challenge[AUTHCHALEN]; /* random challenge used by CHAP */
  158. /*
  159. * These functions are filled in by sppp_attach(), and are
  160. * expected to be used by the lower layer (hardware) drivers
  161. * in order to communicate the (un)availability of the
  162. * communication link. Lower layer drivers that are always
  163. * ready to communicate (like hardware HDLC) can shortcut
  164. * pp_up from pp_tls, and pp_down from pp_tlf.
  165. */
  166. void (*pp_up)(struct sppp *sp);
  167. void (*pp_down)(struct sppp *sp);
  168. /*
  169. * These functions need to be filled in by the lower layer
  170. * (hardware) drivers if they request notification from the
  171. * PPP layer whether the link is actually required. They
  172. * correspond to the tls and tlf actions.
  173. */
  174. void (*pp_tls)(struct sppp *sp);
  175. void (*pp_tlf)(struct sppp *sp);
  176. /*
  177. * These (optional) functions may be filled by the hardware
  178. * driver if any notification of established connections
  179. * (currently: IPCP up) is desired (pp_con) or any internal
  180. * state change of the interface state machine should be
  181. * signaled for monitoring purposes (pp_chg).
  182. */
  183. void (*pp_con)(struct sppp *sp);
  184. void (*pp_chg)(struct sppp *sp, int new_state);
  185. };
  186. #define PP_KEEPALIVE 0x01 /* use keepalive protocol */
  187. #define PP_CISCO 0x02 /* use Cisco protocol instead of PPP */
  188. /* 0x04 was PP_TIMO */
  189. #define PP_CALLIN 0x08 /* we are being called */
  190. #define PP_NEEDAUTH 0x10 /* remote requested authentication */
  191. #define PP_NOFRAMING 0x20 /* do not add/expect encapsulation
  192. around PPP frames (i.e. the serial
  193. HDLC like encapsulation, RFC1662) */
  194. #define PP_MIN_MRU IP_MSS /* minimal MRU */
  195. #define PP_MTU 1500 /* default MTU */
  196. #define PP_MAX_MRU 2048 /* maximal MRU we want to negotiate */
  197. void sppp_attach (struct ifnet *ifp);
  198. void sppp_detach (struct ifnet *ifp);
  199. void sppp_input (struct ifnet *ifp, struct mbuf *m);
  200. /* Workaround */
  201. void spppattach (struct ifnet *ifp);
  202. int sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data);
  203. struct mbuf *sppp_dequeue (struct ifnet *ifp);
  204. struct mbuf *sppp_pick(struct ifnet *ifp);
  205. int sppp_isempty (struct ifnet *ifp);
  206. void sppp_flush (struct ifnet *ifp);
  207. #endif /* _KERNEL */
  208. #endif /* _NET_IF_SPPP_H_ */