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