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