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