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