if_sppp.h revision 139365
14910Swollman/*
2139365Srik * Defines for synchronous PPP/Cisco/Frame Relay link level subroutines.
34910Swollman *
4139365Srik * Copyright (C) 1994-2000 Cronyx Engineering.
525944Sjoerg * Author: Serge Vakulenko, <vak@cronyx.ru>
64910Swollman *
725944Sjoerg * Heavily revamped to conform to RFC 1661.
825944Sjoerg * Copyright (C) 1997, Joerg Wunsch.
925944Sjoerg *
104910Swollman * This software is distributed with NO WARRANTIES, not even the implied
114910Swollman * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
124910Swollman *
1313765Smpp * Authors grant any other persons or organizations permission to use
144910Swollman * or modify this software as long as this message is kept with the software,
154910Swollman * all derivative works or modified versions.
164910Swollman *
1730300Sjoerg * From: Version 2.0, Fri Oct  6 20:39:21 MSK 1995
1825944Sjoerg *
1950477Speter * $FreeBSD: head/sys/net/if_sppp.h 139365 2004-12-28 00:07:57Z rik $
204910Swollman */
214910Swollman
2241687Sphk#ifndef _NET_IF_SPPP_H_
2341687Sphk#define _NET_IF_SPPP_H_ 1
244910Swollman
2525944Sjoerg#define IDX_LCP 0		/* idx into state table */
2625944Sjoerg
274910Swollmanstruct slcp {
2825944Sjoerg	u_long	opts;		/* LCP options to send (bitfield) */
294910Swollman	u_long  magic;          /* local magic number */
3025944Sjoerg	u_long	mru;		/* our max receive unit */
3125944Sjoerg	u_long	their_mru;	/* their max receive unit */
3225944Sjoerg	u_long	protos;		/* bitmask of protos that are started */
3311189Sjkh	u_char  echoid;         /* id of last keepalive echo request */
3425944Sjoerg	/* restart max values, see RFC 1661 */
3525944Sjoerg	int	timeout;
3625944Sjoerg	int	max_terminate;
3725944Sjoerg	int	max_configure;
3825944Sjoerg	int	max_failure;
394910Swollman};
404910Swollman
4125944Sjoerg#define IDX_IPCP 1		/* idx into state table */
4278064Sume#define IDX_IPV6CP 2		/* idx into state table */
4325944Sjoerg
444910Swollmanstruct sipcp {
4525944Sjoerg	u_long	opts;		/* IPCP options to send (bitfield) */
4625944Sjoerg	u_int	flags;
4725944Sjoerg#define IPCP_HISADDR_SEEN 1	/* have seen his address already */
4825944Sjoerg#define IPCP_MYADDR_DYN   2	/* my address is dynamically assigned */
4942104Sphk#define IPCP_MYADDR_SEEN  4	/* have seen his address already */
5078064Sume#ifdef notdef
5188507Sjoerg#define IPV6CP_MYIFID_DYN 8	/* my ifid is dynamically assigned */
5278064Sume#endif
5388507Sjoerg#define IPV6CP_MYIFID_SEEN 0x10	/* have seen his ifid already */
5488534Sjoerg#define IPCP_VJ		0x20	/* can use VJ compression */
5588534Sjoerg	int	max_state;	/* VJ: Max-Slot-Id */
5688534Sjoerg	int	compress_cid;	/* VJ: Comp-Slot-Id */
574910Swollman};
584910Swollman
5988711Sjoerg#define AUTHNAMELEN	64
6030300Sjoerg#define AUTHKEYLEN	16
6125944Sjoerg
6230300Sjoergstruct sauth {
6330300Sjoerg	u_short	proto;			/* authentication protocol to use */
6430300Sjoerg	u_short	flags;
6530300Sjoerg#define AUTHFLAG_NOCALLOUT	1	/* do not require authentication on */
6630300Sjoerg					/* callouts */
6730300Sjoerg#define AUTHFLAG_NORECHALLENGE	2	/* do not re-challenge CHAP */
6830300Sjoerg	u_char	name[AUTHNAMELEN];	/* system identification name */
6930300Sjoerg	u_char	secret[AUTHKEYLEN];	/* secret password */
7030300Sjoerg	u_char	challenge[AUTHKEYLEN];	/* random challenge */
7130300Sjoerg};
7230300Sjoerg
7378064Sume#define IDX_PAP		3
7478064Sume#define IDX_CHAP	4
7530300Sjoerg
7630300Sjoerg#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
7730300Sjoerg
7825944Sjoerg/*
7925944Sjoerg * Don't change the order of this.  Ordering the phases this way allows
8025944Sjoerg * for a comparision of ``pp_phase >= PHASE_AUTHENTICATE'' in order to
8125944Sjoerg * know whether LCP is up.
8225944Sjoerg */
8325944Sjoergenum ppp_phase {
8425944Sjoerg	PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE,
8525944Sjoerg	PHASE_AUTHENTICATE, PHASE_NETWORK
8625944Sjoerg};
8725944Sjoerg
8888558Sjoerg#define PP_MTU          1500    /* default/minimal MRU */
8988558Sjoerg#define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
9088558Sjoerg
9188558Sjoerg/*
9288558Sjoerg * This is a cut down struct sppp (see below) that can easily be
9388558Sjoerg * exported to/ imported from userland without the need to include
9488558Sjoerg * dozens of kernel-internal header files.  It is used by the
9588558Sjoerg * SPPPIO[GS]DEFS ioctl commands below.
9688558Sjoerg */
9788558Sjoergstruct sppp_parms {
9888558Sjoerg	enum ppp_phase pp_phase;	/* phase we're currently in */
9988558Sjoerg	int	enable_vj;		/* VJ header compression enabled */
10088723Sjoerg	int	enable_ipv6;		/*
10188723Sjoerg					 * Enable IPv6 negotiations -- only
10288723Sjoerg					 * needed since each IPv4 i/f auto-
10388723Sjoerg					 * matically gets an IPv6 address
10488723Sjoerg					 * assigned, so we can't use this as
10588723Sjoerg					 * a decision.
10688723Sjoerg					 */
10788558Sjoerg	struct slcp lcp;		/* LCP params */
10888558Sjoerg	struct sipcp ipcp;		/* IPCP params */
10988558Sjoerg	struct sipcp ipv6cp;		/* IPv6CP params */
11088558Sjoerg	struct sauth myauth;		/* auth params, i'm peer */
11188558Sjoerg	struct sauth hisauth;		/* auth params, i'm authenticator */
11288558Sjoerg};
11388558Sjoerg
11488558Sjoerg/*
11588558Sjoerg * Definitions to pass struct sppp_parms data down into the kernel
11688558Sjoerg * using the SIOC[SG]IFGENERIC ioctl interface.
11788558Sjoerg *
11888558Sjoerg * In order to use this, create a struct spppreq, fill in the cmd
11988558Sjoerg * field with SPPPIOGDEFS, and put the address of this structure into
12088558Sjoerg * the ifr_data portion of a struct ifreq.  Pass this struct to a
12188558Sjoerg * SIOCGIFGENERIC ioctl.  Then replace the cmd field by SPPPIOSDEFS,
12288558Sjoerg * modify the defs field as desired, and pass the struct ifreq now
12388558Sjoerg * to a SIOCSIFGENERIC ioctl.
12488558Sjoerg */
12588558Sjoerg
12688558Sjoerg#define SPPPIOGDEFS  ((caddr_t)(('S' << 24) + (1 << 16) +\
12788558Sjoerg	sizeof(struct sppp_parms)))
12888558Sjoerg#define SPPPIOSDEFS  ((caddr_t)(('S' << 24) + (2 << 16) +\
12988558Sjoerg	sizeof(struct sppp_parms)))
13088558Sjoerg
13188558Sjoergstruct spppreq {
13288558Sjoerg	int	cmd;
13388558Sjoerg	struct sppp_parms defs;
13488558Sjoerg};
13588558Sjoerg
13688558Sjoerg#ifdef _KERNEL
1374910Swollmanstruct sppp {
13825944Sjoerg	/* NB: pp_if _must_ be first */
1394910Swollman	struct  ifnet pp_if;    /* network interface data */
1404910Swollman	struct  ifqueue pp_fastq; /* fast output queue */
14126018Sjoerg	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
1424910Swollman	struct  sppp *pp_next;  /* next interface in keepalive list */
14345152Sphk	u_int   pp_mode;        /* major protocol modes (cisco/ppp/...) */
14445152Sphk	u_int   pp_flags;       /* sub modes */
1454910Swollman	u_short pp_alivecnt;    /* keepalive packets counter */
1464910Swollman	u_short pp_loopcnt;     /* loopback detection counter */
14778064Sume	u_long  pp_seq[IDX_COUNT];	/* local sequence number */
14878064Sume	u_long  pp_rseq[IDX_COUNT];	/* remote sequence number */
14925944Sjoerg	enum ppp_phase pp_phase;	/* phase we're currently in */
15025944Sjoerg	int	state[IDX_COUNT];	/* state machine */
15125944Sjoerg	u_char  confid[IDX_COUNT];	/* id of last configuration request */
15225944Sjoerg	int	rst_counter[IDX_COUNT];	/* restart counter */
15325944Sjoerg	int	fail_counter[IDX_COUNT]; /* negotiation failure counter */
15488723Sjoerg	int	confflags;	/* administrative configuration flags */
15588723Sjoerg#define CONF_ENABLE_VJ    0x01	/* VJ header compression enabled */
15688723Sjoerg#define CONF_ENABLE_IPV6  0x02	/* IPv6 administratively enabled */
15788577Sjoerg	time_t	pp_last_recv;	/* time last packet has been received */
15888577Sjoerg	time_t	pp_last_sent;	/* time last packet has been sent */
159138745Srik	struct callout ch[IDX_COUNT];	/* per-proto and if callouts */
160138745Srik	struct callout pap_my_to_ch;	/* PAP needs one more... */
161138745Srik	struct callout keepalive_callout; /* keepalive callout */
16230300Sjoerg	struct slcp lcp;		/* LCP params */
16330300Sjoerg	struct sipcp ipcp;		/* IPCP params */
16478064Sume	struct sipcp ipv6cp;		/* IPv6CP params */
16530300Sjoerg	struct sauth myauth;		/* auth params, i'm peer */
16630300Sjoerg	struct sauth hisauth;		/* auth params, i'm authenticator */
16788599Sjoerg	struct slcompress *pp_comp;	/* for VJ compression */
168139365Srik	u_short fr_dlci;		/* Frame Relay DLCI number, 16..1023 */
169139365Srik	u_char fr_status;		/* PVC status, active/new/delete */
17025944Sjoerg	/*
17125944Sjoerg	 * These functions are filled in by sppp_attach(), and are
17225944Sjoerg	 * expected to be used by the lower layer (hardware) drivers
17325944Sjoerg	 * in order to communicate the (un)availability of the
17425944Sjoerg	 * communication link.  Lower layer drivers that are always
17525944Sjoerg	 * ready to communicate (like hardware HDLC) can shortcut
17625944Sjoerg	 * pp_up from pp_tls, and pp_down from pp_tlf.
17725944Sjoerg	 */
17825944Sjoerg	void	(*pp_up)(struct sppp *sp);
17925944Sjoerg	void	(*pp_down)(struct sppp *sp);
18025944Sjoerg	/*
18125944Sjoerg	 * These functions need to be filled in by the lower layer
18225944Sjoerg	 * (hardware) drivers if they request notification from the
18325944Sjoerg	 * PPP layer whether the link is actually required.  They
18425944Sjoerg	 * correspond to the tls and tlf actions.
18525944Sjoerg	 */
18625944Sjoerg	void	(*pp_tls)(struct sppp *sp);
18725944Sjoerg	void	(*pp_tlf)(struct sppp *sp);
18842104Sphk	/*
18942104Sphk	 * These (optional) functions may be filled by the hardware
19042104Sphk	 * driver if any notification of established connections
19142104Sphk	 * (currently: IPCP up) is desired (pp_con) or any internal
19242104Sphk	 * state change of the interface state machine should be
19342104Sphk	 * signaled for monitoring purposes (pp_chg).
19442104Sphk	 */
19542104Sphk	void	(*pp_con)(struct sppp *sp);
19642104Sphk	void	(*pp_chg)(struct sppp *sp, int new_state);
19741963Sphk	/* These two fields are for use by the lower layer */
19841963Sphk	void    *pp_lowerp;
19941963Sphk	int     pp_loweri;
200138745Srik	/* Lock */
201138745Srik	struct mtx	mtx;
202138745Srik	/* if_start () wrapper */
203138745Srik	void	(*if_start) (struct ifnet *);
204138745Srik	struct callout ifstart_callout; /* if_start () scheduler */
2054910Swollman};
2064910Swollman
20788558Sjoerg/* bits for pp_flags */
2084910Swollman#define PP_KEEPALIVE    0x01    /* use keepalive protocol */
209139365Srik#define PP_FR		0x04	/* use Frame Relay protocol instead of PPP */
21030300Sjoerg				/* 0x04 was PP_TIMO */
21130300Sjoerg#define PP_CALLIN	0x08	/* we are being called */
21230300Sjoerg#define PP_NEEDAUTH	0x10	/* remote requested authentication */
2134910Swollman
2144910Swollmanvoid sppp_attach (struct ifnet *ifp);
2154910Swollmanvoid sppp_detach (struct ifnet *ifp);
2164910Swollmanvoid sppp_input (struct ifnet *ifp, struct mbuf *m);
21738343Sbdeint sppp_ioctl (struct ifnet *ifp, u_long cmd, void *data);
2184910Swollmanstruct mbuf *sppp_dequeue (struct ifnet *ifp);
21930300Sjoergstruct mbuf *sppp_pick(struct ifnet *ifp);
22011189Sjkhint sppp_isempty (struct ifnet *ifp);
2214910Swollmanvoid sppp_flush (struct ifnet *ifp);
222139365Srik
223139365Srik/* Internal functions */
224139365Srikvoid sppp_fr_input (struct sppp *sp, struct mbuf *m);
225139365Srikstruct mbuf *sppp_fr_header (struct sppp *sp, struct mbuf *m, int fam);
226139365Srikvoid sppp_fr_keepalive (struct sppp *sp);
227139365Srikvoid sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst,
228139365Srik		       u_long *srcmask);
229139365Srik
2304910Swollman#endif
2314910Swollman
23241687Sphk#endif /* _NET_IF_SPPP_H_ */
233