if_sppp.h revision 88723
1295373Sdteske/*
2295373Sdteske * Defines for synchronous PPP/Cisco link level subroutines.
3295373Sdteske *
4295373Sdteske * Copyright (C) 1994 Cronyx Ltd.
5295373Sdteske * Author: Serge Vakulenko, <vak@cronyx.ru>
6295373Sdteske *
7295373Sdteske * Heavily revamped to conform to RFC 1661.
8295373Sdteske * Copyright (C) 1997, Joerg Wunsch.
9295373Sdteske *
10295373Sdteske * This software is distributed with NO WARRANTIES, not even the implied
11295373Sdteske * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12295373Sdteske *
13295373Sdteske * Authors grant any other persons or organizations permission to use
14295373Sdteske * or modify this software as long as this message is kept with the software,
15295373Sdteske * all derivative works or modified versions.
16295373Sdteske *
17295373Sdteske * From: Version 2.0, Fri Oct  6 20:39:21 MSK 1995
18295373Sdteske *
19295373Sdteske * $FreeBSD: head/sys/net/if_sppp.h 88723 2001-12-30 20:42:29Z joerg $
20295373Sdteske */
21295373Sdteske
22295373Sdteske#ifndef _NET_IF_SPPP_H_
23295373Sdteske#define _NET_IF_SPPP_H_ 1
24295373Sdteske
25295373Sdteske#define IDX_LCP 0		/* idx into state table */
26295373Sdteske
27295373Sdteskestruct slcp {
28295373Sdteske	u_long	opts;		/* LCP options to send (bitfield) */
29295373Sdteske	u_long  magic;          /* local magic number */
30295373Sdteske	u_long	mru;		/* our max receive unit */
31295373Sdteske	u_long	their_mru;	/* their max receive unit */
32295373Sdteske	u_long	protos;		/* bitmask of protos that are started */
33295373Sdteske	u_char  echoid;         /* id of last keepalive echo request */
34295373Sdteske	/* restart max values, see RFC 1661 */
35295373Sdteske	int	timeout;
36295400Sdteske	int	max_terminate;
37295400Sdteske	int	max_configure;
38295400Sdteske	int	max_failure;
39295373Sdteske};
40295400Sdteske
41295400Sdteske#define IDX_IPCP 1		/* idx into state table */
42295373Sdteske#define IDX_IPV6CP 2		/* idx into state table */
43295373Sdteske
44295373Sdteskestruct sipcp {
45295373Sdteske	u_long	opts;		/* IPCP options to send (bitfield) */
46295373Sdteske	u_int	flags;
47295373Sdteske#define IPCP_HISADDR_SEEN 1	/* have seen his address already */
48295373Sdteske#define IPCP_MYADDR_DYN   2	/* my address is dynamically assigned */
49295373Sdteske#define IPCP_MYADDR_SEEN  4	/* have seen his address already */
50295373Sdteske#ifdef notdef
51295373Sdteske#define IPV6CP_MYIFID_DYN 8	/* my ifid is dynamically assigned */
52295373Sdteske#endif
53295373Sdteske#define IPV6CP_MYIFID_SEEN 0x10	/* have seen his ifid already */
54295373Sdteske#define IPCP_VJ		0x20	/* can use VJ compression */
55295373Sdteske	int	max_state;	/* VJ: Max-Slot-Id */
56295373Sdteske	int	compress_cid;	/* VJ: Comp-Slot-Id */
57295373Sdteske};
58295373Sdteske
59295373Sdteske#define AUTHNAMELEN	64
60295373Sdteske#define AUTHKEYLEN	16
61295373Sdteske
62295373Sdteskestruct sauth {
63295373Sdteske	u_short	proto;			/* authentication protocol to use */
64295373Sdteske	u_short	flags;
65295373Sdteske#define AUTHFLAG_NOCALLOUT	1	/* do not require authentication on */
66295373Sdteske					/* callouts */
67295373Sdteske#define AUTHFLAG_NORECHALLENGE	2	/* do not re-challenge CHAP */
68295373Sdteske	u_char	name[AUTHNAMELEN];	/* system identification name */
69295373Sdteske	u_char	secret[AUTHKEYLEN];	/* secret password */
70295373Sdteske	u_char	challenge[AUTHKEYLEN];	/* random challenge */
71295373Sdteske};
72295373Sdteske
73295373Sdteske#define IDX_PAP		3
74295373Sdteske#define IDX_CHAP	4
75295373Sdteske
76295373Sdteske#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */
77295373Sdteske
78295373Sdteske/*
79295373Sdteske * Don't change the order of this.  Ordering the phases this way allows
80295373Sdteske * for a comparision of ``pp_phase >= PHASE_AUTHENTICATE'' in order to
81295373Sdteske * know whether LCP is up.
82295373Sdteske */
83295373Sdteskeenum ppp_phase {
84295373Sdteske	PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE,
85295373Sdteske	PHASE_AUTHENTICATE, PHASE_NETWORK
86295373Sdteske};
87295373Sdteske
88295373Sdteske#define PP_MTU          1500    /* default/minimal MRU */
89295373Sdteske#define PP_MAX_MRU	2048	/* maximal MRU we want to negotiate */
90295373Sdteske
91295373Sdteske/*
92295373Sdteske * This is a cut down struct sppp (see below) that can easily be
93295373Sdteske * exported to/ imported from userland without the need to include
94295373Sdteske * dozens of kernel-internal header files.  It is used by the
95295373Sdteske * SPPPIO[GS]DEFS ioctl commands below.
96295373Sdteske */
97295373Sdteskestruct sppp_parms {
98295373Sdteske	enum ppp_phase pp_phase;	/* phase we're currently in */
99295373Sdteske	int	enable_vj;		/* VJ header compression enabled */
100295373Sdteske	int	enable_ipv6;		/*
101295373Sdteske					 * Enable IPv6 negotiations -- only
102295373Sdteske					 * needed since each IPv4 i/f auto-
103295373Sdteske					 * matically gets an IPv6 address
104295373Sdteske					 * assigned, so we can't use this as
105295373Sdteske					 * a decision.
106295373Sdteske					 */
107295373Sdteske	struct slcp lcp;		/* LCP params */
108295373Sdteske	struct sipcp ipcp;		/* IPCP params */
109295373Sdteske	struct sipcp ipv6cp;		/* IPv6CP params */
110295373Sdteske	struct sauth myauth;		/* auth params, i'm peer */
111295373Sdteske	struct sauth hisauth;		/* auth params, i'm authenticator */
112295373Sdteske};
113295373Sdteske
114295373Sdteske/*
115295373Sdteske * Definitions to pass struct sppp_parms data down into the kernel
116295373Sdteske * using the SIOC[SG]IFGENERIC ioctl interface.
117295373Sdteske *
118295373Sdteske * In order to use this, create a struct spppreq, fill in the cmd
119295373Sdteske * field with SPPPIOGDEFS, and put the address of this structure into
120295373Sdteske * the ifr_data portion of a struct ifreq.  Pass this struct to a
121295373Sdteske * SIOCGIFGENERIC ioctl.  Then replace the cmd field by SPPPIOSDEFS,
122295373Sdteske * modify the defs field as desired, and pass the struct ifreq now
123295373Sdteske * to a SIOCSIFGENERIC ioctl.
124295373Sdteske */
125295441Sdteske
126295373Sdteske#define SPPPIOGDEFS  ((caddr_t)(('S' << 24) + (1 << 16) +\
127295373Sdteske	sizeof(struct sppp_parms)))
128295373Sdteske#define SPPPIOSDEFS  ((caddr_t)(('S' << 24) + (2 << 16) +\
129295373Sdteske	sizeof(struct sppp_parms)))
130295373Sdteske
131295373Sdteskestruct spppreq {
132295373Sdteske	int	cmd;
133295373Sdteske	struct sppp_parms defs;
134295373Sdteske};
135295373Sdteske
136295373Sdteske#ifdef _KERNEL
137295373Sdteskestruct sppp {
138295373Sdteske	/* NB: pp_if _must_ be first */
139295373Sdteske	struct  ifnet pp_if;    /* network interface data */
140295373Sdteske	struct  ifqueue pp_fastq; /* fast output queue */
141295373Sdteske	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
142295373Sdteske	struct  sppp *pp_next;  /* next interface in keepalive list */
143295373Sdteske	u_int   pp_mode;        /* major protocol modes (cisco/ppp/...) */
144295373Sdteske	u_int   pp_flags;       /* sub modes */
145295373Sdteske	u_short pp_alivecnt;    /* keepalive packets counter */
146295373Sdteske	u_short pp_loopcnt;     /* loopback detection counter */
147295373Sdteske	u_long  pp_seq[IDX_COUNT];	/* local sequence number */
148295373Sdteske	u_long  pp_rseq[IDX_COUNT];	/* remote sequence number */
149295373Sdteske	enum ppp_phase pp_phase;	/* phase we're currently in */
150295373Sdteske	int	state[IDX_COUNT];	/* state machine */
151295373Sdteske	u_char  confid[IDX_COUNT];	/* id of last configuration request */
152295373Sdteske	int	rst_counter[IDX_COUNT];	/* restart counter */
153295373Sdteske	int	fail_counter[IDX_COUNT]; /* negotiation failure counter */
154295373Sdteske	int	confflags;	/* administrative configuration flags */
155295373Sdteske#define CONF_ENABLE_VJ    0x01	/* VJ header compression enabled */
156295373Sdteske#define CONF_ENABLE_IPV6  0x02	/* IPv6 administratively enabled */
157295460Sdteske	time_t	pp_last_recv;	/* time last packet has been received */
158295373Sdteske	time_t	pp_last_sent;	/* time last packet has been sent */
159295373Sdteske	struct callout_handle ch[IDX_COUNT]; /* per-proto and if callouts */
160295373Sdteske	struct callout_handle pap_my_to_ch; /* PAP needs one more... */
161295373Sdteske	struct slcp lcp;		/* LCP params */
162295373Sdteske	struct sipcp ipcp;		/* IPCP params */
163295373Sdteske	struct sipcp ipv6cp;		/* IPv6CP params */
164295373Sdteske	struct sauth myauth;		/* auth params, i'm peer */
165295373Sdteske	struct sauth hisauth;		/* auth params, i'm authenticator */
166295373Sdteske	struct slcompress *pp_comp;	/* for VJ compression */
167295373Sdteske	/*
168295373Sdteske	 * These functions are filled in by sppp_attach(), and are
169295587Sdteske	 * expected to be used by the lower layer (hardware) drivers
170295373Sdteske	 * in order to communicate the (un)availability of the
171295373Sdteske	 * communication link.  Lower layer drivers that are always
172295587Sdteske	 * ready to communicate (like hardware HDLC) can shortcut
173295587Sdteske	 * pp_up from pp_tls, and pp_down from pp_tlf.
174295373Sdteske	 */
175295373Sdteske	void	(*pp_up)(struct sppp *sp);
176295373Sdteske	void	(*pp_down)(struct sppp *sp);
177295546Sdteske	/*
178295546Sdteske	 * These functions need to be filled in by the lower layer
179295546Sdteske	 * (hardware) drivers if they request notification from the
180295546Sdteske	 * PPP layer whether the link is actually required.  They
181295546Sdteske	 * correspond to the tls and tlf actions.
182295546Sdteske	 */
183295546Sdteske	void	(*pp_tls)(struct sppp *sp);
184295546Sdteske	void	(*pp_tlf)(struct sppp *sp);
185295546Sdteske	/*
186295546Sdteske	 * These (optional) functions may be filled by the hardware
187295546Sdteske	 * driver if any notification of established connections
188295546Sdteske	 * (currently: IPCP up) is desired (pp_con) or any internal
189295546Sdteske	 * state change of the interface state machine should be
190295546Sdteske	 * signaled for monitoring purposes (pp_chg).
191295546Sdteske	 */
192295546Sdteske	void	(*pp_con)(struct sppp *sp);
193295546Sdteske	void	(*pp_chg)(struct sppp *sp, int new_state);
194295546Sdteske	/* These two fields are for use by the lower layer */
195295546Sdteske	void    *pp_lowerp;
196295546Sdteske	int     pp_loweri;
197295546Sdteske};
198295546Sdteske
199295546Sdteske/* bits for pp_flags */
200295546Sdteske#define PP_KEEPALIVE    0x01    /* use keepalive protocol */
201295546Sdteske				/* 0x04 was PP_TIMO */
202295546Sdteske#define PP_CALLIN	0x08	/* we are being called */
203295546Sdteske#define PP_NEEDAUTH	0x10	/* remote requested authentication */
204295546Sdteske
205295546Sdteskevoid sppp_attach (struct ifnet *ifp);
206295546Sdteskevoid sppp_detach (struct ifnet *ifp);
207295546Sdteskevoid sppp_input (struct ifnet *ifp, struct mbuf *m);
208295546Sdteskeint sppp_ioctl (struct ifnet *ifp, u_long cmd, void *data);
209295546Sdteskestruct mbuf *sppp_dequeue (struct ifnet *ifp);
210295546Sdteskestruct mbuf *sppp_pick(struct ifnet *ifp);
211295546Sdteskeint sppp_isempty (struct ifnet *ifp);
212295546Sdteskevoid sppp_flush (struct ifnet *ifp);
213295546Sdteske#endif
214295546Sdteske
215295546Sdteske#endif /* _NET_IF_SPPP_H_ */
216295546Sdteske