1 /* 2 * Defines for synchronous PPP/Cisco/Frame Relay link level subroutines. 3 */ 4 /*- 5 * Copyright (C) 1994-2000 Cronyx Engineering. 6 * Author: Serge Vakulenko, <vak@cronyx.ru> 7 * 8 * Heavily revamped to conform to RFC 1661. 9 * Copyright (C) 1997, Joerg Wunsch. 10 * 11 * This software is distributed with NO WARRANTIES, not even the implied 12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * 14 * Authors grant any other persons or organizations permission to use 15 * or modify this software as long as this message is kept with the software, 16 * all derivative works or modified versions. 17 * 18 * From: Version 2.0, Fri Oct 6 20:39:21 MSK 1995 19 */ 20 21 #ifndef _NET_IF_SPPP_H_ 22 #define _NET_IF_SPPP_H_ 1 23 24 #define IDX_LCP 0 /* idx into state table */ 25 26 struct slcp { 27 u_long opts; /* LCP options to send (bitfield) */ 28 u_long magic; /* local magic number */ 29 u_long mru; /* our max receive unit */ 30 u_long their_mru; /* their max receive unit */ 31 u_long protos; /* bitmask of protos that are started */ 32 u_char echoid; /* id of last keepalive echo request */ 33 /* restart max values, see RFC 1661 */ 34 int timeout; 35 int max_terminate; 36 int max_configure; 37 int max_failure; 38 }; 39 40 #define IDX_IPCP 1 /* idx into state table */ 41 #define IDX_IPV6CP 2 /* idx into state table */ 42 43 struct sipcp { 44 u_long opts; /* IPCP options to send (bitfield) */ 45 u_int flags; 46 #define IPCP_HISADDR_SEEN 1 /* have seen his address already */ 47 #define IPCP_MYADDR_DYN 2 /* my address is dynamically assigned */ 48 #define IPCP_MYADDR_SEEN 4 /* have seen his address already */ 49 #ifdef notdef 50 #define IPV6CP_MYIFID_DYN 8 /* my ifid is dynamically assigned */ 51 #endif 52 #define IPV6CP_MYIFID_SEEN 0x10 /* have seen his ifid already */ 53 #define IPCP_VJ 0x20 /* can use VJ compression */ 54 int max_state; /* VJ: Max-Slot-Id */ 55 int compress_cid; /* VJ: Comp-Slot-Id */ 56 }; 57 58 #define AUTHNAMELEN 64 59 #define AUTHKEYLEN 16 60 61 struct sauth { 62 u_short proto; /* authentication protocol to use */ 63 u_short flags; 64 #define AUTHFLAG_NOCALLOUT 1 /* do not require authentication on */ 65 /* callouts */ 66 #define AUTHFLAG_NORECHALLENGE 2 /* do not re-challenge CHAP */ 67 u_char name[AUTHNAMELEN]; /* system identification name */ 68 u_char secret[AUTHKEYLEN]; /* secret password */ 69 u_char challenge[AUTHKEYLEN]; /* random challenge */ 70 }; 71 72 #define IDX_PAP 3 73 #define IDX_CHAP 4 74 75 #define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */ 76 77 /* 78 * Don't change the order of this. Ordering the phases this way allows 79 * for a comparison of ``pp_phase >= PHASE_AUTHENTICATE'' in order to 80 * know whether LCP is up. 81 */ 82 enum ppp_phase { 83 PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE, 84 PHASE_AUTHENTICATE, PHASE_NETWORK 85 }; 86 87 #define PP_MTU 1500 /* default/minimal MRU */ 88 #define PP_MAX_MRU 2048 /* maximal MRU we want to negotiate */ 89 90 /* 91 * This is a cut down struct sppp (see below) that can easily be 92 * exported to/ imported from userland without the need to include 93 * dozens of kernel-internal header files. It is used by the 94 * SPPPIO[GS]DEFS ioctl commands below. 95 */ 96 struct sppp_parms { 97 enum ppp_phase pp_phase; /* phase we're currently in */ 98 int enable_vj; /* VJ header compression enabled */ 99 int enable_ipv6; /* 100 * Enable IPv6 negotiations -- only 101 * needed since each IPv4 i/f auto- 102 * matically gets an IPv6 address 103 * assigned, so we can't use this as 104 * a decision. 105 */ 106 struct slcp lcp; /* LCP params */ 107 struct sipcp ipcp; /* IPCP params */ 108 struct sipcp ipv6cp; /* IPv6CP params */ 109 struct sauth myauth; /* auth params, i'm peer */ 110 struct sauth hisauth; /* auth params, i'm authenticator */ 111 }; 112 113 /* 114 * Definitions to pass struct sppp_parms data down into the kernel 115 * using the SIOC[SG]IFGENERIC ioctl interface. 116 * 117 * In order to use this, create a struct spppreq, fill in the cmd 118 * field with SPPPIOGDEFS, and put the address of this structure into 119 * the ifr_data portion of a struct ifreq. Pass this struct to a 120 * SIOCGIFGENERIC ioctl. Then replace the cmd field by SPPPIOSDEFS, 121 * modify the defs field as desired, and pass the struct ifreq now 122 * to a SIOCSIFGENERIC ioctl. 123 */ 124 125 #define SPPPIOGDEFS ((caddr_t)(('S' << 24) + (1 << 16) +\ 126 sizeof(struct sppp_parms))) 127 #define SPPPIOSDEFS ((caddr_t)(('S' << 24) + (2 << 16) +\ 128 sizeof(struct sppp_parms))) 129 130 struct spppreq { 131 int cmd; 132 struct sppp_parms defs; 133 }; 134 135 #ifdef _KERNEL 136 struct sppp { 137 struct ifnet *pp_ifp; /* network interface data */ 138 struct ifqueue pp_fastq; /* fast output queue */ 139 struct ifqueue pp_cpq; /* PPP control protocol queue */ 140 struct sppp *pp_next; /* next interface in keepalive list */ 141 u_int pp_mode; /* major protocol modes (cisco/ppp/...) */ 142 u_int pp_flags; /* sub modes */ 143 u_short pp_alivecnt; /* keepalive packets counter */ 144 u_short pp_loopcnt; /* loopback detection counter */ 145 u_long pp_seq[IDX_COUNT]; /* local sequence number */ 146 u_long pp_rseq[IDX_COUNT]; /* remote sequence number */ 147 enum ppp_phase pp_phase; /* phase we're currently in */ 148 int state[IDX_COUNT]; /* state machine */ 149 u_char confid[IDX_COUNT]; /* id of last configuration request */ 150 int rst_counter[IDX_COUNT]; /* restart counter */ 151 int fail_counter[IDX_COUNT]; /* negotiation failure counter */ 152 int confflags; /* administrative configuration flags */ 153 #define CONF_ENABLE_VJ 0x01 /* VJ header compression enabled */ 154 #define CONF_ENABLE_IPV6 0x02 /* IPv6 administratively enabled */ 155 time_t pp_last_recv; /* time last packet has been received */ 156 time_t pp_last_sent; /* time last packet has been sent */ 157 struct callout ch[IDX_COUNT]; /* per-proto and if callouts */ 158 struct callout pap_my_to_ch; /* PAP needs one more... */ 159 struct callout keepalive_callout; /* keepalive callout */ 160 struct slcp lcp; /* LCP params */ 161 struct sipcp ipcp; /* IPCP params */ 162 struct sipcp ipv6cp; /* IPv6CP params */ 163 struct sauth myauth; /* auth params, i'm peer */ 164 struct sauth hisauth; /* auth params, i'm authenticator */ 165 struct slcompress *pp_comp; /* for VJ compression */ 166 u_short fr_dlci; /* Frame Relay DLCI number, 16..1023 */ 167 u_char fr_status; /* PVC status, active/new/delete */ 168 /* 169 * These functions are filled in by sppp_attach(), and are 170 * expected to be used by the lower layer (hardware) drivers 171 * in order to communicate the (un)availability of the 172 * communication link. Lower layer drivers that are always 173 * ready to communicate (like hardware HDLC) can shortcut 174 * pp_up from pp_tls, and pp_down from pp_tlf. 175 */ 176 void (*pp_up)(struct sppp *sp); 177 void (*pp_down)(struct sppp *sp); 178 /* 179 * These functions need to be filled in by the lower layer 180 * (hardware) drivers if they request notification from the 181 * PPP layer whether the link is actually required. They 182 * correspond to the tls and tlf actions. 183 */ 184 void (*pp_tls)(struct sppp *sp); 185 void (*pp_tlf)(struct sppp *sp); 186 /* 187 * These (optional) functions may be filled by the hardware 188 * driver if any notification of established connections 189 * (currently: IPCP up) is desired (pp_con) or any internal 190 * state change of the interface state machine should be 191 * signaled for monitoring purposes (pp_chg). 192 */ 193 void (*pp_con)(struct sppp *sp); 194 void (*pp_chg)(struct sppp *sp, int new_state); 195 /* These two fields are for use by the lower layer */ 196 void *pp_lowerp; 197 int pp_loweri; 198 /* Lock */ 199 struct mtx mtx; 200 /* if_start () wrapper */ 201 void (*if_start) (struct ifnet *); 202 struct callout ifstart_callout; /* if_start () scheduler */ 203 }; 204 #define IFP2SP(ifp) ((struct sppp *)(ifp)->if_l2com) 205 #define SP2IFP(sp) ((sp)->pp_ifp) 206 207 /* bits for pp_flags */ 208 #define PP_KEEPALIVE 0x01 /* use keepalive protocol */ 209 #define PP_FR 0x04 /* use Frame Relay protocol instead of PPP */ 210 /* 0x04 was PP_TIMO */ 211 #define PP_CALLIN 0x08 /* we are being called */ 212 #define PP_NEEDAUTH 0x10 /* remote requested authentication */ 213 214 void sppp_attach (struct ifnet *ifp); 215 void sppp_detach (struct ifnet *ifp); 216 void sppp_input (struct ifnet *ifp, struct mbuf *m); 217 int sppp_ioctl (struct ifnet *ifp, u_long cmd, void *data); 218 struct mbuf *sppp_dequeue (struct ifnet *ifp); 219 struct mbuf *sppp_pick(struct ifnet *ifp); 220 int sppp_isempty (struct ifnet *ifp); 221 void sppp_flush (struct ifnet *ifp); 222 223 /* Internal functions */ 224 void sppp_fr_input (struct sppp *sp, struct mbuf *m); 225 struct mbuf *sppp_fr_header (struct sppp *sp, struct mbuf *m, int fam); 226 void sppp_fr_keepalive (struct sppp *sp); 227 void sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, 228 u_long *srcmask); 229 230 #endif 231 232 #endif /* _NET_IF_SPPP_H_ */ 233