1 1.42 yamaguch /* $NetBSD: if_spppvar.h,v 1.42 2021/06/01 04:59:50 yamaguchi Exp $ */ 2 1.11 elad 3 1.11 elad #ifndef _NET_IF_SPPPVAR_H_ 4 1.11 elad #define _NET_IF_SPPPVAR_H_ 5 1.1 martin 6 1.1 martin /* 7 1.1 martin * Defines for synchronous PPP/Cisco link level subroutines. 8 1.1 martin * 9 1.1 martin * Copyright (C) 1994 Cronyx Ltd. 10 1.1 martin * Author: Serge Vakulenko, <vak (at) cronyx.ru> 11 1.1 martin * 12 1.1 martin * Heavily revamped to conform to RFC 1661. 13 1.1 martin * Copyright (C) 1997, Joerg Wunsch. 14 1.1 martin * 15 1.1 martin * This software is distributed with NO WARRANTIES, not even the implied 16 1.1 martin * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 1.1 martin * 18 1.1 martin * Authors grant any other persons or organizations permission to use 19 1.1 martin * or modify this software as long as this message is kept with the software, 20 1.1 martin * all derivative works or modified versions. 21 1.1 martin * 22 1.1 martin * From: Version 2.0, Fri Oct 6 20:39:21 MSK 1995 23 1.1 martin * 24 1.1 martin * From: if_sppp.h,v 1.8 1997/10/11 11:25:20 joerg Exp 25 1.1 martin * 26 1.1 martin * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp 27 1.1 martin */ 28 1.1 martin 29 1.18 knakahar #include <sys/workqueue.h> 30 1.19 knakahar #include <sys/pcq.h> 31 1.27 yamaguch struct sppp; 32 1.27 yamaguch 33 1.27 yamaguch struct sppp_work { 34 1.27 yamaguch struct work work; 35 1.27 yamaguch void *arg; 36 1.27 yamaguch void (*func)(struct sppp *, void *); 37 1.27 yamaguch unsigned int state; 38 1.27 yamaguch #define SPPP_WK_FREE 0 39 1.27 yamaguch #define SPPP_WK_BUSY 1 40 1.27 yamaguch #define SPPP_WK_UNAVAIL 2 41 1.27 yamaguch }; 42 1.18 knakahar 43 1.15 martin #define IDX_LCP 0 /* idx into state table */ 44 1.1 martin 45 1.1 martin struct slcp { 46 1.1 martin u_long opts; /* LCP options to send (bitfield) */ 47 1.1 martin u_long magic; /* local magic number */ 48 1.1 martin u_long mru; /* our max receive unit */ 49 1.1 martin u_long their_mru; /* their max receive unit */ 50 1.1 martin u_long protos; /* bitmask of protos that are started */ 51 1.1 martin u_char echoid; /* id of last keepalive echo request */ 52 1.1 martin /* restart max values, see RFC 1661 */ 53 1.1 martin int timeout; 54 1.1 martin int max_terminate; 55 1.1 martin int max_configure; 56 1.1 martin int max_failure; 57 1.23 is /* multilink variables */ 58 1.23 is u_long mrru; /* our max received reconstructed unit */ 59 1.23 is u_long their_mrru; /* their max receive dreconstructed unit */ 60 1.27 yamaguch bool reestablish; /* reestablish after the next down event */ 61 1.31 yamaguch bool tlf_sent; /* call lower layer's tlf before a down event */ 62 1.1 martin }; 63 1.1 martin 64 1.15 martin #define IDX_IPCP 1 /* idx into state table */ 65 1.15 martin #define IDX_IPV6CP 2 /* idx into state table */ 66 1.15 martin 67 1.1 martin struct sipcp { 68 1.1 martin u_long opts; /* IPCP options to send (bitfield) */ 69 1.1 martin u_int flags; 70 1.1 martin #define IPCP_HISADDR_SEEN 1 /* have seen his address already */ 71 1.1 martin #define IPCP_MYADDR_SEEN 2 /* have a local address assigned already */ 72 1.1 martin #define IPCP_MYADDR_DYN 4 /* my address is dynamically assigned */ 73 1.1 martin #define IPCP_HISADDR_DYN 8 /* his address is dynamically assigned */ 74 1.1 martin #ifdef notdef 75 1.1 martin #define IPV6CP_MYIFID_DYN 2 /* my ifid is dynamically assigned */ 76 1.1 martin #endif 77 1.1 martin #define IPV6CP_MYIFID_SEEN 4 /* have seen his ifid already */ 78 1.12 matt uint32_t saved_hisaddr;/* if hisaddr (IPv4) is dynamic, save original one here, in network byte order */ 79 1.12 matt uint32_t req_hisaddr; /* remote address requested */ 80 1.12 matt uint32_t req_myaddr; /* local address requested */ 81 1.32 yamaguch 82 1.32 yamaguch uint8_t my_ifid[8]; /* IPv6CP my ifid*/ 83 1.32 yamaguch uint8_t his_ifid[8]; /* IPv6CP his ifid*/ 84 1.1 martin }; 85 1.1 martin 86 1.1 martin struct sauth { 87 1.1 martin u_short proto; /* authentication protocol to use */ 88 1.1 martin u_short flags; 89 1.1 martin char *name; /* system identification name */ 90 1.1 martin char *secret; /* secret password */ 91 1.5 christos u_char name_len; /* no need to have a bigger size */ 92 1.5 christos u_char secret_len; /* because proto gives size in a byte */ 93 1.29 yamaguch }; 94 1.29 yamaguch 95 1.29 yamaguch struct schap { 96 1.29 yamaguch char challenge[16]; /* random challenge 97 1.29 yamaguch [don't change size! it's really hardcoded!] */ 98 1.29 yamaguch char digest[16]; 99 1.29 yamaguch u_char digest_len; 100 1.29 yamaguch bool rechallenging; /* sent challenge after open */ 101 1.29 yamaguch bool response_rcvd; /* receive response, stop sending challenge */ 102 1.29 yamaguch 103 1.29 yamaguch struct sppp_work work_challenge_rcvd; 104 1.1 martin }; 105 1.1 martin 106 1.15 martin #define IDX_PAP 3 107 1.15 martin #define IDX_CHAP 4 108 1.15 martin 109 1.15 martin #define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */ 110 1.1 martin 111 1.25 yamaguch struct sppp_cp { 112 1.25 yamaguch u_long seq; /* local sequence number */ 113 1.25 yamaguch u_long rseq; /* remote sequence number */ 114 1.25 yamaguch int state; /* state machine */ 115 1.26 yamaguch u_char confid; /* local id of last configuration request */ 116 1.26 yamaguch u_char rconfid; /* remote id of last configuration request */ 117 1.25 yamaguch int rst_counter; /* restart counter */ 118 1.25 yamaguch int fail_counter; /* negotiation failure counter */ 119 1.25 yamaguch struct callout ch; /* per-proto and if callouts */ 120 1.34 yamaguch u_char rcr_type; /* parsing result of conf-req */ 121 1.34 yamaguch struct mbuf *mbuf_confreq; /* received conf-req */ 122 1.34 yamaguch struct mbuf *mbuf_confnak; /* received conf-nak or conf-rej */ 123 1.27 yamaguch 124 1.27 yamaguch struct sppp_work work_up; 125 1.27 yamaguch struct sppp_work work_down; 126 1.27 yamaguch struct sppp_work work_open; 127 1.27 yamaguch struct sppp_work work_close; 128 1.27 yamaguch struct sppp_work work_to; 129 1.27 yamaguch struct sppp_work work_rcr; 130 1.27 yamaguch struct sppp_work work_rca; 131 1.27 yamaguch struct sppp_work work_rcn; 132 1.27 yamaguch struct sppp_work work_rtr; 133 1.27 yamaguch struct sppp_work work_rta; 134 1.27 yamaguch struct sppp_work work_rxj; 135 1.25 yamaguch }; 136 1.25 yamaguch 137 1.1 martin struct sppp { 138 1.1 martin /* NB: pp_if _must_ be first */ 139 1.1 martin struct ifnet pp_if; /* network interface data */ 140 1.1 martin struct ifqueue pp_fastq; /* fast output queue */ 141 1.1 martin struct ifqueue pp_cpq; /* PPP control protocol queue */ 142 1.1 martin struct sppp *pp_next; /* next interface in keepalive list */ 143 1.1 martin u_int pp_flags; /* use Cisco protocol instead of PPP */ 144 1.37 yamaguch u_int pp_ncpflags; /* enable or disable each NCP */ 145 1.1 martin u_int pp_framebytes; /* number of bytes added by (hardware) framing */ 146 1.10 martin u_int pp_alivecnt; /* keepalive packets counter */ 147 1.38 yamaguch u_int pp_alive_interval; /* keepalive interval */ 148 1.10 martin u_int pp_loopcnt; /* loopback detection counter */ 149 1.10 martin u_int pp_maxalive; /* number or echo req. w/o reply */ 150 1.16 dyoung uint64_t pp_saved_mtu; /* saved MTU value */ 151 1.10 martin time_t pp_last_receive; /* peer's last "sign of life" */ 152 1.10 martin time_t pp_max_noreceive; /* seconds since last receive before 153 1.10 martin we start to worry and send echo 154 1.10 martin requests */ 155 1.2 martin time_t pp_last_activity; /* second of last payload data s/r */ 156 1.2 martin time_t pp_idle_timeout; /* idle seconds before auto-disconnect, 157 1.2 martin * 0 = disabled */ 158 1.3 martin int pp_auth_failures; /* authorization failures */ 159 1.3 martin int pp_max_auth_fail; /* max. allowed authorization failures */ 160 1.1 martin int pp_phase; /* phase we're currently in */ 161 1.21 knakahar krwlock_t pp_lock; /* lock for sppp structure */ 162 1.4 martin int query_dns; /* 1 if we want to know the dns addresses */ 163 1.12 matt uint32_t dns_addrs[2]; 164 1.1 martin #if defined(__FreeBSD__) && __FreeBSD__ >= 3 165 1.1 martin struct callout_handle ch[IDX_COUNT]; /* per-proto and if callouts */ 166 1.1 martin struct callout_handle pap_my_to_ch; /* PAP needs one more... */ 167 1.1 martin #endif 168 1.27 yamaguch struct workqueue *wq_cp; 169 1.28 yamaguch struct sppp_work work_ifdown; 170 1.25 yamaguch struct sppp_cp scp[IDX_COUNT]; 171 1.1 martin struct slcp lcp; /* LCP params */ 172 1.1 martin struct sipcp ipcp; /* IPCP params */ 173 1.1 martin struct sipcp ipv6cp; /* IPv6CP params */ 174 1.1 martin struct sauth myauth; /* auth params, i'm peer */ 175 1.1 martin struct sauth hisauth; /* auth params, i'm authenticator */ 176 1.29 yamaguch struct schap chap; /* CHAP params */ 177 1.1 martin /* 178 1.1 martin * These functions are filled in by sppp_attach(), and are 179 1.1 martin * expected to be used by the lower layer (hardware) drivers 180 1.1 martin * in order to communicate the (un)availability of the 181 1.1 martin * communication link. Lower layer drivers that are always 182 1.1 martin * ready to communicate (like hardware HDLC) can shortcut 183 1.1 martin * pp_up from pp_tls, and pp_down from pp_tlf. 184 1.1 martin */ 185 1.8 itojun void (*pp_up)(struct sppp *); 186 1.8 itojun void (*pp_down)(struct sppp *); 187 1.1 martin /* 188 1.1 martin * These functions need to be filled in by the lower layer 189 1.1 martin * (hardware) drivers if they request notification from the 190 1.1 martin * PPP layer whether the link is actually required. They 191 1.1 martin * correspond to the tls and tlf actions. 192 1.1 martin */ 193 1.8 itojun void (*pp_tls)(struct sppp *); 194 1.8 itojun void (*pp_tlf)(struct sppp *); 195 1.1 martin /* 196 1.1 martin * These (optional) functions may be filled by the hardware 197 1.1 martin * driver if any notification of established connections 198 1.1 martin * (currently: IPCP up) is desired (pp_con) or any internal 199 1.1 martin * state change of the interface state machine should be 200 1.1 martin * signaled for monitoring purposes (pp_chg). 201 1.1 martin */ 202 1.8 itojun void (*pp_con)(struct sppp *); 203 1.8 itojun void (*pp_chg)(struct sppp *, int); 204 1.1 martin }; 205 1.1 martin 206 1.40 yamaguch #define PP_KEEPALIVE 0x01 /* use keepalive protocol */ 207 1.41 yamaguch /* 0x02 was PP_CISCO */ 208 1.40 yamaguch /* 0x04 was PP_TIMO */ 209 1.40 yamaguch #define PP_CALLIN 0x08 /* we are being called */ 210 1.40 yamaguch #define PP_NEEDAUTH 0x10 /* remote requested authentication */ 211 1.40 yamaguch #define PP_NOFRAMING 0x20 /* do not add/expect encapsulation 212 1.40 yamaguch around PPP frames (i.e. the serial 213 1.40 yamaguch HDLC like encapsulation, RFC1662) */ 214 1.40 yamaguch #define PP_LOOPBACK 0x40 /* in line loopback mode */ 215 1.40 yamaguch #define PP_LOOPBACK_IFDOWN 0x80 /* if_down() when loopback detected */ 216 1.40 yamaguch #define PP_KEEPALIVE_IFDOWN 0x100 /* if_down() when no ECHO_REPLY received */ 217 1.42 yamaguch #define PP_ADMIN_UP 0x200 /* the interface is up */ 218 1.1 martin 219 1.1 martin 220 1.1 martin #define PP_MTU 1500 /* default/minimal MRU */ 221 1.1 martin #define PP_MAX_MRU 2048 /* maximal MRU we want to negotiate */ 222 1.1 martin 223 1.1 martin #ifdef _KERNEL 224 1.8 itojun void sppp_attach (struct ifnet *); 225 1.8 itojun void sppp_detach (struct ifnet *); 226 1.8 itojun void sppp_input (struct ifnet *, struct mbuf *); 227 1.8 itojun int sppp_ioctl(struct ifnet *, u_long, void *); 228 1.8 itojun struct mbuf *sppp_dequeue (struct ifnet *); 229 1.8 itojun int sppp_isempty (struct ifnet *); 230 1.8 itojun void sppp_flush (struct ifnet *); 231 1.1 martin #endif 232 1.22 knakahar 233 1.22 knakahar /* 234 1.22 knakahar * Locking notes: 235 1.22 knakahar * + spppq is protected by spppq_lock (an adaptive mutex) 236 1.22 knakahar * spppq is a list of all struct sppps, and it is used for 237 1.22 knakahar * sending keepalive packets. 238 1.22 knakahar * + struct sppp is protected by sppp->pp_lock (an rwlock) 239 1.22 knakahar * sppp holds configuration parameters for line, 240 1.22 knakahar * authentication and addresses. It also has pointers 241 1.22 knakahar * of functions to notify events to lower layer. 242 1.22 knakahar * When notify events, sppp->pp_lock must be released. 243 1.22 knakahar * Because the event handler implemented in a lower 244 1.22 knakahar * layer often call functions implemented in 245 1.22 knakahar * if_spppsubr.c. 246 1.22 knakahar * 247 1.22 knakahar * Locking order: 248 1.33 yamaguch * - IFNET_LOCK => spppq_lock => struct sppp->pp_lock 249 1.22 knakahar * 250 1.22 knakahar * NOTICE 251 1.22 knakahar * - Lower layers must not acquire sppp->pp_lock 252 1.22 knakahar */ 253 1.11 elad #endif /* !_NET_IF_SPPPVAR_H_ */ 254