Add a missing header file dependancy.
[dragonfly/vkernel-mp.git] / usr.sbin / ppp / fsm.h
blob96e0fd27b9947be8ddd4df38287743ea979ad8e7
1 /*-
2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4 * Internet Initiative Japan, Inc (IIJ)
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $FreeBSD: src/usr.sbin/ppp/fsm.h,v 1.23.2.3 2002/09/01 02:12:27 brian Exp $
29 * $DragonFly: src/usr.sbin/ppp/fsm.h,v 1.2 2003/06/17 06:30:00 dillon Exp $
33 * State of machine
35 #define ST_INITIAL 0
36 #define ST_STARTING 1
37 #define ST_CLOSED 2
38 #define ST_STOPPED 3
39 #define ST_CLOSING 4
40 #define ST_STOPPING 5
41 #define ST_REQSENT 6
42 #define ST_ACKRCVD 7
43 #define ST_ACKSENT 8
44 #define ST_OPENED 9
46 #define ST_MAX 10
47 #define ST_UNDEF -1
49 #define MODE_REQ 0
50 #define MODE_NAK 1
51 #define MODE_REJ 2
52 #define MODE_NOP 3
53 #define MODE_ACK 4 /* pseudo mode for ccp negotiations */
55 #define OPEN_PASSIVE -1
57 #define FSM_REQ_TIMER 1
58 #define FSM_TRM_TIMER 2
60 #define FSM_OPTLEN 100
62 struct fsm;
64 struct fsm_retry {
65 u_int timeout; /* FSM retry frequency */
66 u_int maxreq; /* Max Config REQ retries */
67 u_int maxtrm; /* Max Term REQ retries */
70 struct fsm_decode {
71 u_char ack[FSM_OPTLEN], *ackend;
72 u_char nak[FSM_OPTLEN], *nakend;
73 u_char rej[FSM_OPTLEN], *rejend;
76 struct fsm_callbacks {
77 int (*LayerUp)(struct fsm *); /* Layer is now up (tlu) */
78 void (*LayerDown)(struct fsm *); /* About to come down (tld) */
79 void (*LayerStart)(struct fsm *); /* Layer about to start (tls) */
80 void (*LayerFinish)(struct fsm *); /* Layer now down (tlf) */
81 void (*InitRestartCounter)(struct fsm *, int);/* Set fsm timer load */
82 void (*SendConfigReq)(struct fsm *); /* Send REQ please */
83 void (*SentTerminateReq)(struct fsm *); /* Term REQ just sent */
84 void (*SendTerminateAck)(struct fsm *, u_char); /* Send Term ACK please */
85 void (*DecodeConfig)(struct fsm *, u_char *, u_char *, int,
86 struct fsm_decode *); /* Deal with incoming data */
87 int (*RecvResetReq)(struct fsm *fp); /* Reset output */
88 void (*RecvResetAck)(struct fsm *fp, u_char); /* Reset input */
91 struct fsm_parent {
92 void (*LayerStart) (void *, struct fsm *); /* tls */
93 void (*LayerUp) (void *, struct fsm *); /* tlu */
94 void (*LayerDown) (void *, struct fsm *); /* tld */
95 void (*LayerFinish) (void *, struct fsm *); /* tlf */
96 void *object;
99 struct link;
100 struct bundle;
102 struct fsm {
103 const char *name; /* Name of protocol */
104 u_short proto; /* Protocol number */
105 u_short min_code;
106 u_short max_code;
107 int open_mode; /* Delay before config REQ (-1 forever) */
108 int state; /* State of the machine */
109 u_char reqid; /* Next request id */
110 int restart; /* Restart counter value */
112 struct {
113 int reqs; /* Max config REQs before a close() */
114 int naks; /* Max config NAKs before a close() */
115 int rejs; /* Max config REJs before a close() */
116 } more;
118 struct pppTimer FsmTimer; /* Restart Timer */
119 struct pppTimer OpenTimer; /* Delay before opening */
122 * This timer times the ST_STOPPED state out after the given value
123 * (specified via "set stopped ..."). Although this isn't specified in the
124 * rfc, the rfc *does* say that "the application may use higher level
125 * timers to avoid deadlock". The StoppedTimer takes effect when the other
126 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
127 * causing ppp to time out and drop into ST_STOPPED. At this point,
128 * nothing will change this state :-(
130 struct pppTimer StoppedTimer;
131 int LogLevel;
133 /* The link layer active with this FSM (may be our bundle below) */
134 struct link *link;
136 /* Our high-level link */
137 struct bundle *bundle;
139 const struct fsm_parent *parent;
140 const struct fsm_callbacks *fn;
143 struct fsmheader {
144 u_char code; /* Request code */
145 u_char id; /* Identification */
146 u_short length; /* Length of packet */
149 #define CODE_CONFIGREQ 1
150 #define CODE_CONFIGACK 2
151 #define CODE_CONFIGNAK 3
152 #define CODE_CONFIGREJ 4
153 #define CODE_TERMREQ 5
154 #define CODE_TERMACK 6
155 #define CODE_CODEREJ 7
156 #define CODE_PROTOREJ 8
157 #define CODE_ECHOREQ 9 /* Used in LCP */
158 #define CODE_ECHOREP 10 /* Used in LCP */
159 #define CODE_DISCREQ 11
160 #define CODE_IDENT 12 /* Used in LCP Extension */
161 #define CODE_TIMEREM 13 /* Used in LCP Extension */
162 #define CODE_RESETREQ 14 /* Used in CCP */
163 #define CODE_RESETACK 15 /* Used in CCP */
165 struct fsm_opt_hdr {
166 u_char id;
167 u_char len;
170 #define MAX_FSM_OPT_LEN 52
171 struct fsm_opt {
172 struct fsm_opt_hdr hdr;
173 u_char data[MAX_FSM_OPT_LEN-2];
176 #define INC_FSM_OPT(ty, length, o) \
177 do { \
178 (o)->hdr.id = (ty); \
179 (o)->hdr.len = (length); \
180 (o) = (struct fsm_opt *)((u_char *)(o) + (length)); \
181 } while (0)
184 extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
185 struct bundle *, struct link *, const struct fsm_parent *,
186 struct fsm_callbacks *, const char * const [3]);
187 extern void fsm_Output(struct fsm *, u_int, u_int, u_char *, int, int);
188 extern void fsm_Open(struct fsm *);
189 extern void fsm_Up(struct fsm *);
190 extern void fsm_Down(struct fsm *);
191 extern void fsm_Input(struct fsm *, struct mbuf *);
192 extern void fsm_Close(struct fsm *);
193 extern int fsm_NullRecvResetReq(struct fsm *);
194 extern void fsm_NullRecvResetAck(struct fsm *, u_char);
195 extern void fsm_Reopen(struct fsm *);
196 extern void fsm2initial(struct fsm *);
197 extern const char *State2Nam(u_int);
198 extern struct fsm_opt *fsm_readopt(u_char **);
199 extern void fsm_rej(struct fsm_decode *, const struct fsm_opt *);
200 extern void fsm_ack(struct fsm_decode *, const struct fsm_opt *);
201 extern void fsm_nak(struct fsm_decode *, const struct fsm_opt *);
202 extern void fsm_opt_normalise(struct fsm_decode *);