xref: /freebsd/usr.sbin/ppp/ccp.h (revision c30797873f663df5fc45ba0db943393f611bd24e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5  *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6  *                           Internet Initiative Japan, Inc (IIJ)
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #define	CCP_MAXCODE	CODE_RESETACK
34 
35 #define	TY_OUI		0	/* OUI */
36 #define	TY_PRED1	1	/* Predictor type 1 */
37 #define	TY_PRED2	2	/* Predictor type 2 */
38 #define	TY_PUDDLE	3	/* Puddle Jumper */
39 #define	TY_HWPPC	16	/* Hewlett-Packard PPC */
40 #define	TY_STAC		17	/* Stac Electronics LZS */
41 #define	TY_MSPPC	18	/* Microsoft PPC */
42 #define	TY_MPPE		18	/* Microsoft PPE */
43 #define	TY_GAND		19	/* Gandalf FZA */
44 #define	TY_V42BIS	20	/* V.42bis compression */
45 #define	TY_BSD		21	/* BSD LZW Compress */
46 #define	TY_PPPD_DEFLATE	24	/* Deflate (gzip) - (mis) numbered by pppd */
47 #define	TY_DEFLATE	26	/* Deflate (gzip) - rfc 1979 */
48 
49 #define CCP_NEG_DEFLATE		0
50 #define CCP_NEG_PRED1		1
51 #define CCP_NEG_DEFLATE24	2
52 #ifndef NODES
53 #define CCP_NEG_MPPE		3
54 #define CCP_NEG_TOTAL		4
55 #else
56 #define CCP_NEG_TOTAL		3
57 #endif
58 
59 #ifndef NODES
60 enum mppe_negstate {
61   MPPE_ANYSTATE,
62   MPPE_STATELESS,
63   MPPE_STATEFUL
64 };
65 #endif
66 
67 struct mbuf;
68 struct link;
69 
70 struct ccp_config {
71   struct {
72     struct {
73       int winsize;
74     } in, out;
75   } deflate;
76 #ifndef NODES
77   struct {
78     int keybits;
79     enum mppe_negstate state;
80     unsigned required : 1;
81   } mppe;
82 #endif
83   struct fsm_retry fsm;	/* How often/frequently to resend requests */
84   unsigned neg[CCP_NEG_TOTAL];
85 };
86 
87 struct ccp_opt {
88   struct ccp_opt *next;
89   int algorithm;
90   struct fsm_opt val;
91 };
92 
93 struct ccp {
94   struct fsm fsm;		/* The finite state machine */
95 
96   int his_proto;		/* peer's compression protocol */
97   int my_proto;			/* our compression protocol */
98 
99   int reset_sent;		/* If != -1, ignore compressed 'till ack */
100   int last_reset;		/* We can receive more (dups) w/ this id */
101 
102   struct {
103     int algorithm;		/* Algorithm in use */
104     void *state;		/* Returned by implementations Init() */
105     struct fsm_opt opt;		/* Set by implementation's OptInit() */
106   } in;
107 
108   struct {
109     int algorithm;		/* Algorithm in use */
110     void *state;		/* Returned by implementations Init() */
111     struct ccp_opt *opt;	/* Set by implementation's OptInit() */
112   } out;
113 
114   u_int32_t his_reject;		/* Request codes rejected by peer */
115   u_int32_t my_reject;		/* Request codes I have rejected */
116 
117   u_long uncompout, compout;	/* Outgoing bytes before/after compression */
118   u_long uncompin, compin;	/* Incoming bytes after/before decompression */
119 
120   struct ccp_config cfg;
121 };
122 
123 #define fsm2ccp(fp) (fp->proto == PROTO_CCP ? (struct ccp *)fp : NULL)
124 
125 struct ccp_algorithm {
126   int id;
127   int Neg;					/* ccp_config neg array item */
128   const char *(*Disp)(struct fsm_opt *);	/* Use result immediately !  */
129   int (*Usable)(struct fsm *);			/* Ok to negotiate ? */
130   int (*Required)(struct fsm *);		/* Must negotiate ? */
131   struct {
132     int (*Set)(struct bundle *, struct fsm_opt *, const struct ccp_config *);
133     void *(*Init)(struct bundle *, struct fsm_opt *);
134     void (*Term)(void *);
135     void (*Reset)(void *);
136     struct mbuf *(*Read)(void *, struct ccp *, u_short *, struct mbuf *);
137     void (*DictSetup)(void *, struct ccp *, u_short, struct mbuf *);
138   } i;
139   struct {
140     int MTUOverhead;
141     void (*OptInit)(struct bundle *, struct fsm_opt *,
142                     const struct ccp_config *);
143     int (*Set)(struct bundle *, struct fsm_opt *, const struct ccp_config *);
144     void *(*Init)(struct bundle *, struct fsm_opt *);
145     void (*Term)(void *);
146     int (*Reset)(void *);
147     struct mbuf *(*Write)(void *, struct ccp *, struct link *, int, u_short *,
148                           struct mbuf *);
149   } o;
150 };
151 
152 extern void ccp_Init(struct ccp *, struct bundle *, struct link *,
153                      const struct fsm_parent *);
154 extern void ccp_Setup(struct ccp *);
155 extern int ccp_Required(struct ccp *);
156 extern int ccp_MTUOverhead(struct ccp *);
157 
158 extern void ccp_SendResetReq(struct fsm *);
159 extern struct mbuf *ccp_Input(struct bundle *, struct link *, struct mbuf *);
160 extern int ccp_ReportStatus(struct cmdargs const *);
161 extern u_short ccp_Proto(struct ccp *);
162 extern void ccp_SetupCallbacks(struct ccp *);
163 extern int ccp_SetOpenMode(struct ccp *);
164 extern int ccp_DefaultUsable(struct fsm *);
165 extern int ccp_DefaultRequired(struct fsm *);
166 
167 extern struct layer ccplayer;
168