14910Swollman/*
2139365Srik * Defines for synchronous PPP/Cisco/Frame Relay link level subroutines.
3139823Simp */
4139823Simp/*-
5139365Srik * Copyright (C) 1994-2000 Cronyx Engineering.
625944Sjoerg * Author: Serge Vakulenko, <vak@cronyx.ru>
74910Swollman *
825944Sjoerg * Heavily revamped to conform to RFC 1661.
925944Sjoerg * Copyright (C) 1997, Joerg Wunsch.
1025944Sjoerg *
114910Swollman * This software is distributed with NO WARRANTIES, not even the implied
124910Swollman * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
134910Swollman *
1413765Smpp * Authors grant any other persons or organizations permission to use
154910Swollman * or modify this software as long as this message is kept with the software,
164910Swollman * all derivative works or modified versions.
174910Swollman *
1830300Sjoerg * From: Version 2.0, Fri Oct  6 20:39:21 MSK 1995
1925944Sjoerg *
2050477Speter * $FreeBSD$
214910Swollman */
224910Swollman
2341687Sphk#ifndef _NET_IF_SPPP_H_
2441687Sphk#define _NET_IF_SPPP_H_ 1
254910Swollman
2625944Sjoerg#define IDX_LCP 0		/* idx into state table */
2725944Sjoerg
284910Swollmanstruct slcp {
2925944Sjoerg	u_long	opts;		/* LCP options to send (bitfield) */
304910Swollman	u_long  magic;          /* local magic number */
3125944Sjoerg	u_long	mru;		/* our max receive unit */
3225944Sjoerg	u_long	their_mru;	/* their max receive unit */
3325944Sjoerg	u_long	protos;		/* bitmask of protos that are started */
3411189Sjkh	u_char  echoid;         /* id of last keepalive echo request */
3525944Sjoerg	/* restart max values, see RFC 1661 */
3625944Sjoerg	int	timeout;
3725944Sjoerg	int	max_terminate;
3825944Sjoerg	int	max_configure;
3925944Sjoerg	int	max_failure;
404910Swollman};
414910Swollman
4225944Sjoerg#define IDX_IPCP 1		/* idx into state table */
4378064Sume#define IDX_IPV6CP 2		/* idx into state table */
4425944Sjoerg
454910Swollmanstruct sipcp {
4625944Sjoerg	u_long	opts;		/* IPCP options to send (bitfield) */
4725944Sjoerg	u_int	flags;
4825944Sjoerg#define IPCP_HISADDR_SEEN 1	/* have seen his address already */
4925944Sjoerg#define IPCP_MYADDR_DYN   2	/* my address is dynamically assigned */
5042104Sphk#define IPCP_MYADDR_SEEN  4	/* have seen his address already */
5178064Sume#ifdef notdef
5288507Sjoerg#define IPV6CP_MYIFID_DYN 8	/* my ifid is dynamically assigned */
5378064Sume#endif
5488507Sjoerg#define IPV6CP_MYIFID_SEEN 0x10	/* have seen his ifid already */
5588534Sjoerg#define IPCP_VJ		0x20	/* can use VJ compression */
5688534Sjoerg	int	max_state;	/* VJ: Max-Slot-Id */
5788534Sjoerg	int	compress_cid;	/* VJ: Comp-Slot-Id */
584910Swollman};
594910Swollman
6088711Sjoerg#define AUTHNAMELEN	64
6130300Sjoerg#define AUTHKEYLEN	16
6225944Sjoerg
6330300Sjoergstruct sauth {
6430300Sjoerg	u_short	proto;			/* authentication protocol to use */
6530300Sjoerg	u_short	flags;
6630300Sjoerg#define AUTHFLAG_NOCALLOUT	1	/* do not require authentication on */
6730300Sjoerg					/* callouts */
6830300Sjoerg#define AUTHFLAG_NORECHALLENGE	2	/* do not re-challenge CHAP */
6930300Sjoerg	u_char	name[AUTHNAMELEN];	/* system identification name */
7030300Sjoerg	u_char	secret[AUTHKEYLEN];	/* secret password */
7130300Sjoerg	u_char	challenge[AUTHKEYLEN];	/* random challenge */
7230300Sjoerg};
7330300Sjoerg
7478064Sume#define IDX_PAP		3
7578064Sume#define IDX_CHAP	4
7630300Sjoerg
7730300Sjoerg#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
7830300Sjoerg
7925944Sjoerg/*
8025944Sjoerg * Don't change the order of this.  Ordering the phases this way allows
81298995Spfg * for a comparison of ``pp_phase >= PHASE_AUTHENTICATE'' in order to
8225944Sjoerg * know whether LCP is up.
8325944Sjoerg */
8425944Sjoergenum ppp_phase {
8525944Sjoerg	PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE,
8625944Sjoerg	PHASE_AUTHENTICATE, PHASE_NETWORK
8725944Sjoerg};
8825944Sjoerg
8988558Sjoerg#define PP_MTU          1500    /* default/minimal MRU */
9088558Sjoerg#define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
9188558Sjoerg
9288558Sjoerg/*
9388558Sjoerg * This is a cut down struct sppp (see below) that can easily be
9488558Sjoerg * exported to/ imported from userland without the need to include
9588558Sjoerg * dozens of kernel-internal header files.  It is used by the
9688558Sjoerg * SPPPIO[GS]DEFS ioctl commands below.
9788558Sjoerg */
9888558Sjoergstruct sppp_parms {
9988558Sjoerg	enum ppp_phase pp_phase;	/* phase we're currently in */
10088558Sjoerg	int	enable_vj;		/* VJ header compression enabled */
10188723Sjoerg	int	enable_ipv6;		/*
10288723Sjoerg					 * Enable IPv6 negotiations -- only
10388723Sjoerg					 * needed since each IPv4 i/f auto-
10488723Sjoerg					 * matically gets an IPv6 address
10588723Sjoerg					 * assigned, so we can't use this as
10688723Sjoerg					 * a decision.
10788723Sjoerg					 */
10888558Sjoerg	struct slcp lcp;		/* LCP params */
10988558Sjoerg	struct sipcp ipcp;		/* IPCP params */
11088558Sjoerg	struct sipcp ipv6cp;		/* IPv6CP params */
11188558Sjoerg	struct sauth myauth;		/* auth params, i'm peer */
11288558Sjoerg	struct sauth hisauth;		/* auth params, i'm authenticator */
11388558Sjoerg};
11488558Sjoerg
11588558Sjoerg/*
11688558Sjoerg * Definitions to pass struct sppp_parms data down into the kernel
11788558Sjoerg * using the SIOC[SG]IFGENERIC ioctl interface.
11888558Sjoerg *
11988558Sjoerg * In order to use this, create a struct spppreq, fill in the cmd
12088558Sjoerg * field with SPPPIOGDEFS, and put the address of this structure into
12188558Sjoerg * the ifr_data portion of a struct ifreq.  Pass this struct to a
12288558Sjoerg * SIOCGIFGENERIC ioctl.  Then replace the cmd field by SPPPIOSDEFS,
12388558Sjoerg * modify the defs field as desired, and pass the struct ifreq now
12488558Sjoerg * to a SIOCSIFGENERIC ioctl.
12588558Sjoerg */
12688558Sjoerg
12788558Sjoerg#define SPPPIOGDEFS  ((caddr_t)(('S' << 24) + (1 << 16) +\
12888558Sjoerg	sizeof(struct sppp_parms)))
12988558Sjoerg#define SPPPIOSDEFS  ((caddr_t)(('S' << 24) + (2 << 16) +\
13088558Sjoerg	sizeof(struct sppp_parms)))
13188558Sjoerg
13288558Sjoergstruct spppreq {
13388558Sjoerg	int	cmd;
13488558Sjoerg	struct sppp_parms defs;
13588558Sjoerg};
13688558Sjoerg
13788558Sjoerg#ifdef _KERNEL
1384910Swollmanstruct sppp {
139147256Sbrooks	struct  ifnet *pp_ifp;    /* 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};
206147256Sbrooks#define IFP2SP(ifp)	((struct sppp *)(ifp)->if_l2com)
207147256Sbrooks#define SP2IFP(sp)	((sp)->pp_ifp)
2084910Swollman
20988558Sjoerg/* bits for pp_flags */
2104910Swollman#define PP_KEEPALIVE    0x01    /* use keepalive protocol */
211139365Srik#define PP_FR		0x04	/* use Frame Relay protocol instead of PPP */
21230300Sjoerg				/* 0x04 was PP_TIMO */
21330300Sjoerg#define PP_CALLIN	0x08	/* we are being called */
21430300Sjoerg#define PP_NEEDAUTH	0x10	/* remote requested authentication */
2154910Swollman
2164910Swollmanvoid sppp_attach (struct ifnet *ifp);
2174910Swollmanvoid sppp_detach (struct ifnet *ifp);
2184910Swollmanvoid sppp_input (struct ifnet *ifp, struct mbuf *m);
21938343Sbdeint sppp_ioctl (struct ifnet *ifp, u_long cmd, void *data);
2204910Swollmanstruct mbuf *sppp_dequeue (struct ifnet *ifp);
22130300Sjoergstruct mbuf *sppp_pick(struct ifnet *ifp);
22211189Sjkhint sppp_isempty (struct ifnet *ifp);
2234910Swollmanvoid sppp_flush (struct ifnet *ifp);
224139365Srik
225139365Srik/* Internal functions */
226139365Srikvoid sppp_fr_input (struct sppp *sp, struct mbuf *m);
227139365Srikstruct mbuf *sppp_fr_header (struct sppp *sp, struct mbuf *m, int fam);
228139365Srikvoid sppp_fr_keepalive (struct sppp *sp);
229139365Srikvoid sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst,
230139365Srik		       u_long *srcmask);
231139365Srik
2324910Swollman#endif
2334910Swollman
23441687Sphk#endif /* _NET_IF_SPPP_H_ */
235