if_sppp.h revision 139365
11541Srgrimes/*
21541Srgrimes * Defines for synchronous PPP/Cisco/Frame Relay link level subroutines.
31541Srgrimes *
41541Srgrimes * Copyright (C) 1994-2000 Cronyx Engineering.
51541Srgrimes * Author: Serge Vakulenko, <vak@cronyx.ru>
61541Srgrimes *
71541Srgrimes * Heavily revamped to conform to RFC 1661.
81541Srgrimes * Copyright (C) 1997, Joerg Wunsch.
91541Srgrimes *
101541Srgrimes * This software is distributed with NO WARRANTIES, not even the implied
111541Srgrimes * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
121541Srgrimes *
131541Srgrimes * Authors grant any other persons or organizations permission to use
141541Srgrimes * or modify this software as long as this message is kept with the software,
151541Srgrimes * all derivative works or modified versions.
161541Srgrimes *
171541Srgrimes * From: Version 2.0, Fri Oct  6 20:39:21 MSK 1995
181541Srgrimes *
191541Srgrimes * $FreeBSD: head/sys/net/if_sppp.h 139365 2004-12-28 00:07:57Z rik $
201541Srgrimes */
211541Srgrimes
221541Srgrimes#ifndef _NET_IF_SPPP_H_
231541Srgrimes#define _NET_IF_SPPP_H_ 1
241541Srgrimes
251541Srgrimes#define IDX_LCP 0		/* idx into state table */
261541Srgrimes
271541Srgrimesstruct slcp {
281541Srgrimes	u_long	opts;		/* LCP options to send (bitfield) */
291541Srgrimes	u_long  magic;          /* local magic number */
301541Srgrimes	u_long	mru;		/* our max receive unit */
311541Srgrimes	u_long	their_mru;	/* their max receive unit */
321541Srgrimes	u_long	protos;		/* bitmask of protos that are started */
331541Srgrimes	u_char  echoid;         /* id of last keepalive echo request */
341541Srgrimes	/* restart max values, see RFC 1661 */
351541Srgrimes	int	timeout;
361541Srgrimes	int	max_terminate;
371541Srgrimes	int	max_configure;
381541Srgrimes	int	max_failure;
3946017Sphk};
401541Srgrimes
411541Srgrimes#define IDX_IPCP 1		/* idx into state table */
422165Spaul#define IDX_IPV6CP 2		/* idx into state table */
432165Spaul
442165Spaulstruct sipcp {
451541Srgrimes	u_long	opts;		/* IPCP options to send (bitfield) */
4617649Speter	u_int	flags;
4717649Speter#define IPCP_HISADDR_SEEN 1	/* have seen his address already */
4817649Speter#define IPCP_MYADDR_DYN   2	/* my address is dynamically assigned */
4917649Speter#define IPCP_MYADDR_SEEN  4	/* have seen his address already */
5013545Sjulian#ifdef notdef
511541Srgrimes#define IPV6CP_MYIFID_DYN 8	/* my ifid is dynamically assigned */
521541Srgrimes#endif
531541Srgrimes#define IPV6CP_MYIFID_SEEN 0x10	/* have seen his ifid already */
541541Srgrimes#define IPCP_VJ		0x20	/* can use VJ compression */
551541Srgrimes	int	max_state;	/* VJ: Max-Slot-Id */
561541Srgrimes	int	compress_cid;	/* VJ: Comp-Slot-Id */
571541Srgrimes};
581541Srgrimes
591541Srgrimes#define AUTHNAMELEN	64
601541Srgrimes#define AUTHKEYLEN	16
611541Srgrimes
621541Srgrimesstruct sauth {
631541Srgrimes	u_short	proto;			/* authentication protocol to use */
641541Srgrimes	u_short	flags;
651541Srgrimes#define AUTHFLAG_NOCALLOUT	1	/* do not require authentication on */
661541Srgrimes					/* callouts */
671541Srgrimes#define AUTHFLAG_NORECHALLENGE	2	/* do not re-challenge CHAP */
681541Srgrimes	u_char	name[AUTHNAMELEN];	/* system identification name */
691541Srgrimes	u_char	secret[AUTHKEYLEN];	/* secret password */
701541Srgrimes	u_char	challenge[AUTHKEYLEN];	/* random challenge */
711541Srgrimes};
721541Srgrimes
731541Srgrimes#define IDX_PAP		3
741541Srgrimes#define IDX_CHAP	4
751541Srgrimes
761541Srgrimes#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
771541Srgrimes
781541Srgrimes/*
791541Srgrimes * Don't change the order of this.  Ordering the phases this way allows
801541Srgrimes * for a comparision of ``pp_phase >= PHASE_AUTHENTICATE'' in order to
811541Srgrimes * know whether LCP is up.
821541Srgrimes */
831541Srgrimesenum ppp_phase {
841541Srgrimes	PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE,
851541Srgrimes	PHASE_AUTHENTICATE, PHASE_NETWORK
861541Srgrimes};
871541Srgrimes
881541Srgrimes#define PP_MTU          1500    /* default/minimal MRU */
891541Srgrimes#define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
901541Srgrimes
911541Srgrimes/*
921541Srgrimes * This is a cut down struct sppp (see below) that can easily be
931541Srgrimes * exported to/ imported from userland without the need to include
941541Srgrimes * dozens of kernel-internal header files.  It is used by the
951541Srgrimes * SPPPIO[GS]DEFS ioctl commands below.
961541Srgrimes */
971541Srgrimesstruct sppp_parms {
981541Srgrimes	enum ppp_phase pp_phase;	/* phase we're currently in */
991541Srgrimes	int	enable_vj;		/* VJ header compression enabled */
1001541Srgrimes	int	enable_ipv6;		/*
1011541Srgrimes					 * Enable IPv6 negotiations -- only
1021541Srgrimes					 * needed since each IPv4 i/f auto-
1031541Srgrimes					 * matically gets an IPv6 address
1041541Srgrimes					 * assigned, so we can't use this as
1051541Srgrimes					 * a decision.
1061541Srgrimes					 */
1071541Srgrimes	struct slcp lcp;		/* LCP params */
1081541Srgrimes	struct sipcp ipcp;		/* IPCP params */
1091541Srgrimes	struct sipcp ipv6cp;		/* IPv6CP params */
1101541Srgrimes	struct sauth myauth;		/* auth params, i'm peer */
1111541Srgrimes	struct sauth hisauth;		/* auth params, i'm authenticator */
1121541Srgrimes};
1131541Srgrimes
1141541Srgrimes/*
1151541Srgrimes * Definitions to pass struct sppp_parms data down into the kernel
1161541Srgrimes * using the SIOC[SG]IFGENERIC ioctl interface.
1171541Srgrimes *
1181541Srgrimes * In order to use this, create a struct spppreq, fill in the cmd
1191541Srgrimes * field with SPPPIOGDEFS, and put the address of this structure into
1201541Srgrimes * the ifr_data portion of a struct ifreq.  Pass this struct to a
1211541Srgrimes * SIOCGIFGENERIC ioctl.  Then replace the cmd field by SPPPIOSDEFS,
1221541Srgrimes * modify the defs field as desired, and pass the struct ifreq now
1231541Srgrimes * to a SIOCSIFGENERIC ioctl.
1241541Srgrimes */
1251541Srgrimes
1261541Srgrimes#define SPPPIOGDEFS  ((caddr_t)(('S' << 24) + (1 << 16) +\
1271541Srgrimes	sizeof(struct sppp_parms)))
1281541Srgrimes#define SPPPIOSDEFS  ((caddr_t)(('S' << 24) + (2 << 16) +\
1291541Srgrimes	sizeof(struct sppp_parms)))
1301541Srgrimes
1311541Srgrimesstruct spppreq {
1321541Srgrimes	int	cmd;
1331541Srgrimes	struct sppp_parms defs;
1341541Srgrimes};
1351541Srgrimes
1361541Srgrimes#ifdef _KERNEL
1371541Srgrimesstruct sppp {
1381541Srgrimes	/* NB: pp_if _must_ be first */
1391541Srgrimes	struct  ifnet pp_if;    /* network interface data */
1401541Srgrimes	struct  ifqueue pp_fastq; /* fast output queue */
1411541Srgrimes	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
1421541Srgrimes	struct  sppp *pp_next;  /* next interface in keepalive list */
1431541Srgrimes	u_int   pp_mode;        /* major protocol modes (cisco/ppp/...) */
1441541Srgrimes	u_int   pp_flags;       /* sub modes */
1451541Srgrimes	u_short pp_alivecnt;    /* keepalive packets counter */
1461541Srgrimes	u_short pp_loopcnt;     /* loopback detection counter */
1471541Srgrimes	u_long  pp_seq[IDX_COUNT];	/* local sequence number */
1481541Srgrimes	u_long  pp_rseq[IDX_COUNT];	/* remote sequence number */
1491541Srgrimes	enum ppp_phase pp_phase;	/* phase we're currently in */
1501541Srgrimes	int	state[IDX_COUNT];	/* state machine */
1511541Srgrimes	u_char  confid[IDX_COUNT];	/* id of last configuration request */
1521541Srgrimes	int	rst_counter[IDX_COUNT];	/* restart counter */
1531541Srgrimes	int	fail_counter[IDX_COUNT]; /* negotiation failure counter */
1541541Srgrimes	int	confflags;	/* administrative configuration flags */
1551541Srgrimes#define CONF_ENABLE_VJ    0x01	/* VJ header compression enabled */
1561541Srgrimes#define CONF_ENABLE_IPV6  0x02	/* IPv6 administratively enabled */
1571541Srgrimes	time_t	pp_last_recv;	/* time last packet has been received */
1581541Srgrimes	time_t	pp_last_sent;	/* time last packet has been sent */
1591541Srgrimes	struct callout ch[IDX_COUNT];	/* per-proto and if callouts */
1601541Srgrimes	struct callout pap_my_to_ch;	/* PAP needs one more... */
1611541Srgrimes	struct callout keepalive_callout; /* keepalive callout */
1621541Srgrimes	struct slcp lcp;		/* LCP params */
1631541Srgrimes	struct sipcp ipcp;		/* IPCP params */
16441796Sdt	struct sipcp ipv6cp;		/* IPv6CP params */
16541796Sdt	struct sauth myauth;		/* auth params, i'm peer */
16646017Sphk	struct sauth hisauth;		/* auth params, i'm authenticator */
16741796Sdt	struct slcompress *pp_comp;	/* for VJ compression */
16841796Sdt	u_short fr_dlci;		/* Frame Relay DLCI number, 16..1023 */
16941796Sdt	u_char fr_status;		/* PVC status, active/new/delete */
17035175Ssos	/*
1711541Srgrimes	 * These functions are filled in by sppp_attach(), and are
1721541Srgrimes	 * expected to be used by the lower layer (hardware) drivers
1731541Srgrimes	 * in order to communicate the (un)availability of the
1741541Srgrimes	 * communication link.  Lower layer drivers that are always
17531575Sbde	 * ready to communicate (like hardware HDLC) can shortcut
17631575Sbde	 * pp_up from pp_tls, and pp_down from pp_tlf.
17731575Sbde	 */
1781541Srgrimes	void	(*pp_up)(struct sppp *sp);
1792165Spaul	void	(*pp_down)(struct sppp *sp);
1802165Spaul	/*
181	 * These functions need to be filled in by the lower layer
182	 * (hardware) drivers if they request notification from the
183	 * PPP layer whether the link is actually required.  They
184	 * correspond to the tls and tlf actions.
185	 */
186	void	(*pp_tls)(struct sppp *sp);
187	void	(*pp_tlf)(struct sppp *sp);
188	/*
189	 * These (optional) functions may be filled by the hardware
190	 * driver if any notification of established connections
191	 * (currently: IPCP up) is desired (pp_con) or any internal
192	 * state change of the interface state machine should be
193	 * signaled for monitoring purposes (pp_chg).
194	 */
195	void	(*pp_con)(struct sppp *sp);
196	void	(*pp_chg)(struct sppp *sp, int new_state);
197	/* These two fields are for use by the lower layer */
198	void    *pp_lowerp;
199	int     pp_loweri;
200	/* Lock */
201	struct mtx	mtx;
202	/* if_start () wrapper */
203	void	(*if_start) (struct ifnet *);
204	struct callout ifstart_callout; /* if_start () scheduler */
205};
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
214void sppp_attach (struct ifnet *ifp);
215void sppp_detach (struct ifnet *ifp);
216void sppp_input (struct ifnet *ifp, struct mbuf *m);
217int sppp_ioctl (struct ifnet *ifp, u_long cmd, void *data);
218struct mbuf *sppp_dequeue (struct ifnet *ifp);
219struct mbuf *sppp_pick(struct ifnet *ifp);
220int sppp_isempty (struct ifnet *ifp);
221void sppp_flush (struct ifnet *ifp);
222
223/* Internal functions */
224void sppp_fr_input (struct sppp *sp, struct mbuf *m);
225struct mbuf *sppp_fr_header (struct sppp *sp, struct mbuf *m, int fam);
226void sppp_fr_keepalive (struct sppp *sp);
227void 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