ccp.h revision 94894
1111072Sjake/*-
2111072Sjake * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3111072Sjake *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4111072Sjake *                           Internet Initiative Japan, Inc (IIJ)
5111072Sjake * All rights reserved.
6111072Sjake *
7111072Sjake * Redistribution and use in source and binary forms, with or without
8111072Sjake * modification, are permitted provided that the following conditions
9111072Sjake * are met:
10111072Sjake * 1. Redistributions of source code must retain the above copyright
11111072Sjake *    notice, this list of conditions and the following disclaimer.
12111072Sjake * 2. Redistributions in binary form must reproduce the above copyright
13111072Sjake *    notice, this list of conditions and the following disclaimer in the
14111072Sjake *    documentation and/or other materials provided with the distribution.
15111072Sjake *
16111072Sjake * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17111072Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18111072Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19111072Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20111072Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21111072Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22111072Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23111072Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24111072Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25111072Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26111072Sjake * SUCH DAMAGE.
27111072Sjake *
28111072Sjake * $FreeBSD: head/usr.sbin/ppp/ccp.h 94894 2002-04-16 23:57:09Z brian $
29111072Sjake */
30111072Sjake
31111072Sjake#define	CCP_MAXCODE	CODE_RESETACK
32111072Sjake
33111072Sjake#define	TY_OUI		0	/* OUI */
34111123Sjake#define	TY_PRED1	1	/* Predictor type 1 */
35111072Sjake#define	TY_PRED2	2	/* Predictor type 2 */
36111072Sjake#define	TY_PUDDLE	3	/* Puddle Jumper */
37111072Sjake#define	TY_HWPPC	16	/* Hewlett-Packard PPC */
38111072Sjake#define	TY_STAC		17	/* Stac Electronics LZS */
39111072Sjake#define	TY_MSPPC	18	/* Microsoft PPC */
40111072Sjake#define	TY_MPPE		18	/* Microsoft PPE */
41111072Sjake#define	TY_GAND		19	/* Gandalf FZA */
42111072Sjake#define	TY_V42BIS	20	/* V.42bis compression */
43111072Sjake#define	TY_BSD		21	/* BSD LZW Compress */
44111072Sjake#define	TY_PPPD_DEFLATE	24	/* Deflate (gzip) - (mis) numbered by pppd */
45111072Sjake#define	TY_DEFLATE	26	/* Deflate (gzip) - rfc 1979 */
46111072Sjake
47111072Sjake#define CCP_NEG_DEFLATE		0
48111072Sjake#define CCP_NEG_PRED1		1
49111072Sjake#define CCP_NEG_DEFLATE24	2
50111123Sjake#ifndef NODES
51111123Sjake#define CCP_NEG_MPPE		3
52111123Sjake#define CCP_NEG_TOTAL		4
53111123Sjake#else
54111123Sjake#define CCP_NEG_TOTAL		3
55111123Sjake#endif
56111123Sjake
57111123Sjake#ifndef NODES
58111072Sjakeenum mppe_negstate {
59111072Sjake  MPPE_ANYSTATE,
60111072Sjake  MPPE_STATELESS,
61111072Sjake  MPPE_STATEFUL
62111072Sjake};
63111072Sjake#endif
64111072Sjake
65111123Sjakestruct mbuf;
66111123Sjakestruct link;
67111072Sjake
68111072Sjakestruct ccp_config {
69111072Sjake  struct {
70111072Sjake    struct {
71111072Sjake      int winsize;
72111072Sjake    } in, out;
73111072Sjake  } deflate;
74111072Sjake#ifndef NODES
75111072Sjake  struct {
76111072Sjake    int keybits;
77111072Sjake    enum mppe_negstate state;
78111072Sjake    unsigned required : 1;
79111072Sjake  } mppe;
80111072Sjake#endif
81111072Sjake  struct fsm_retry fsm;	/* How often/frequently to resend requests */
82111072Sjake  unsigned neg[CCP_NEG_TOTAL];
83111072Sjake};
84111072Sjake
85111123Sjakestruct ccp_opt {
86111072Sjake  struct ccp_opt *next;
87111072Sjake  int algorithm;
88111072Sjake  struct fsm_opt val;
89111072Sjake};
90111072Sjake
91111072Sjakestruct ccp {
92111072Sjake  struct fsm fsm;		/* The finite state machine */
93111072Sjake
94111072Sjake  int his_proto;		/* peer's compression protocol */
95111123Sjake  int my_proto;			/* our compression protocol */
96111072Sjake
97111072Sjake  int reset_sent;		/* If != -1, ignore compressed 'till ack */
98111123Sjake  int last_reset;		/* We can receive more (dups) w/ this id */
99111123Sjake
100111123Sjake  struct {
101111123Sjake    int algorithm;		/* Algorithm in use */
102111123Sjake    void *state;		/* Returned by implementations Init() */
103111123Sjake    struct fsm_opt opt;		/* Set by implementation's OptInit() */
104111123Sjake  } in;
105111123Sjake
106111123Sjake  struct {
107111123Sjake    int algorithm;		/* Algorithm in use */
108111123Sjake    void *state;		/* Returned by implementations Init() */
109111123Sjake    struct ccp_opt *opt;	/* Set by implementation's OptInit() */
110111123Sjake  } out;
111111123Sjake
112111123Sjake  u_int32_t his_reject;		/* Request codes rejected by peer */
113111123Sjake  u_int32_t my_reject;		/* Request codes I have rejected */
114111072Sjake
115111072Sjake  u_long uncompout, compout;	/* Outgoing bytes before/after compression */
116111072Sjake  u_long uncompin, compin;	/* Incoming bytes after/before decompression */
117111072Sjake
118111072Sjake  struct ccp_config cfg;
119111072Sjake};
120111072Sjake
121111072Sjake#define fsm2ccp(fp) (fp->proto == PROTO_CCP ? (struct ccp *)fp : NULL)
122111072Sjake
123111072Sjakestruct ccp_algorithm {
124111072Sjake  int id;
125111072Sjake  int Neg;					/* ccp_config neg array item */
126111072Sjake  const char *(*Disp)(struct fsm_opt *);	/* Use result immediately !  */
127111072Sjake  int (*Usable)(struct fsm *);			/* Ok to negotiate ? */
128111072Sjake  int (*Required)(struct fsm *);		/* Must negotiate ? */
129111072Sjake  struct {
130111072Sjake    int (*Set)(struct fsm_opt *, const struct ccp_config *);
131111072Sjake    void *(*Init)(struct fsm_opt *);
132111072Sjake    void (*Term)(void *);
133111072Sjake    void (*Reset)(void *);
134111072Sjake    struct mbuf *(*Read)(void *, struct ccp *, u_short *, struct mbuf *);
135111072Sjake    void (*DictSetup)(void *, struct ccp *, u_short, struct mbuf *);
136111072Sjake  } i;
137111072Sjake  struct {
138111072Sjake    int MTUOverhead;
139111072Sjake    void (*OptInit)(struct fsm_opt *, const struct ccp_config *);
140111072Sjake    int (*Set)(struct fsm_opt *, const struct ccp_config *);
141111072Sjake    void *(*Init)(struct fsm_opt *);
142111072Sjake    void (*Term)(void *);
143111072Sjake    int (*Reset)(void *);
144111072Sjake    struct mbuf *(*Write)(void *, struct ccp *, struct link *, int, u_short *,
145111072Sjake                          struct mbuf *);
146111072Sjake  } o;
147111072Sjake};
148111072Sjake
149111072Sjakeextern void ccp_Init(struct ccp *, struct bundle *, struct link *,
150111072Sjake                     const struct fsm_parent *);
151111072Sjakeextern void ccp_Setup(struct ccp *);
152111072Sjakeextern int ccp_Required(struct ccp *);
153111072Sjakeextern int ccp_MTUOverhead(struct ccp *);
154111072Sjake
155111072Sjakeextern void ccp_SendResetReq(struct fsm *);
156111072Sjakeextern struct mbuf *ccp_Input(struct bundle *, struct link *, struct mbuf *);
157111072Sjakeextern int ccp_ReportStatus(struct cmdargs const *);
158111072Sjakeextern u_short ccp_Proto(struct ccp *);
159111072Sjakeextern void ccp_SetupCallbacks(struct ccp *);
160111072Sjakeextern int ccp_SetOpenMode(struct ccp *);
161111072Sjakeextern int ccp_DefaultUsable(struct fsm *);
162111072Sjakeextern int ccp_DefaultRequired(struct fsm *);
163111072Sjake
164111072Sjakeextern struct layer ccplayer;
165111072Sjake