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