1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
typedef struct PPP PPP;
typedef struct Pstate Pstate;
typedef struct Lcpmsg Lcpmsg;
typedef struct Lcpopt Lcpopt;
typedef struct Qualpkt Qualpkt;
typedef struct Qualstats Qualstats;
typedef struct Tcpc Tcpc;
typedef uchar Ipaddr[IPaddrlen];
enum
{
HDLC_frame= 0x7e,
HDLC_esc= 0x7d,
/* PPP frame fields */
PPP_addr= 0xff,
PPP_ctl= 0x3,
PPP_initfcs= 0xffff,
PPP_goodfcs= 0xf0b8,
/* PPP phases */
Pdead= 0,
Plink, /* doing LCP */
Pauth, /* doing chap */
Pnet, /* doing IPCP, CCP */
Pterm, /* closing down */
/* PPP protocol types */
Pip= 0x21, /* internet */
Pvjctcp= 0x2d, /* compressing van jacobson tcp */
Pvjutcp= 0x2f, /* uncompressing van jacobson tcp */
Pcdata= 0xfd, /* compressed datagram */
Pipcp= 0x8021, /* ip control */
Pecp= 0x8053, /* encryption control */
Pccp= 0x80fd, /* compressed datagram control */
Plcp= 0xc021, /* link control */
Ppap= 0xc023, /* password auth. protocol */
Plqm= 0xc025, /* link quality monitoring */
Pchap= 0xc223, /* challenge/response */
/* LCP codes */
Lconfreq= 1,
Lconfack= 2,
Lconfnak= 3,
Lconfrej= 4,
Ltermreq= 5,
Ltermack= 6,
Lcoderej= 7,
Lprotorej= 8,
Lechoreq= 9,
Lechoack= 10,
Ldiscard= 11,
/* Lcp configure options */
Omtu= 1,
Octlmap= 2,
Oauth= 3,
Oquality= 4,
Omagic= 5,
Opc= 7,
Oac= 8,
Obad= 12, /* for testing */
/* authentication protocols */
APmd5= 5,
/* lcp flags */
Fmtu= 1<<Omtu,
Fctlmap= 1<<Octlmap,
Fauth= 1<<Oauth,
Fquality= 1<<Oquality,
Fmagic= 1<<Omagic,
Fpc= 1<<Opc,
Fac= 1<<Oac,
Fbad= 1<<Obad,
/* Chap codes */
Cchallenge= 1,
Cresponse= 2,
Csuccess= 3,
Cfailure= 4,
/* Pap codes */
Cpapreq= 1,
Cpapack= 2,
Cpapnak= 3,
/* link states */
Sclosed= 0,
Sclosing,
Sreqsent,
Sackrcvd,
Sacksent,
Sopened,
/* ccp configure options */
Ocoui= 0, /* proprietary compression */
Ocstac= 17, /* stac electronics LZS */
Ocmppc= 18, /* microsoft ppc */
/* ccp flags */
Fcoui= 1<<Ocoui,
Fcstac= 1<<Ocstac,
Fcmppc= 1<<Ocmppc,
/* ecp configure options */
Oeoui= 0, /* proprietary compression */
Oedese= 1, /* DES */
/* ecp flags */
Feoui= 1<<Oeoui,
Fedese= 1<<Oedese,
/* ipcp configure options */
Oipaddrs= 1,
Oipcompress= 2,
Oipaddr= 3,
Oipdns= 129,
Oipwins= 130,
Oipdns2= 131,
Oipwins2= 132,
/* ipcp flags */
Fipaddrs= 1<<Oipaddrs,
Fipcompress= 1<<Oipcompress,
Fipaddr= 1<<Oipaddr,
Period= 3*1000, /* period of retransmit process (in ms) */
Timeout= 10, /* xmit timeout (in Periods) */
MAX_STATES = 16, /* van jacobson compression states */
Defmtu= 1450, /* default that we will ask for */
Minmtu= 128, /* minimum that we will accept */
Maxmtu= 2000, /* maximum that we will accept */
};
struct Pstate
{
int proto; /* protocol type */
int timeout; /* for current state */
int rxtimeout; /* for current retransmit */
ulong flags; /* options received */
uchar id; /* id of current message */
uchar confid; /* id of current config message */
uchar termid; /* id of current termination message */
uchar rcvdconfid; /* id of last conf message received */
uchar state; /* PPP link state */
ulong optmask; /* which options to request */
int echoack; /* recieved echo ack */
int echotimeout; /* echo timeout */
};
struct Qualstats
{
ulong reports;
ulong packets;
ulong bytes;
ulong discards;
ulong errors;
};
struct PPP
{
QLock;
Chan* dchan; /* serial line */
Chan* cchan; /* serial line control */
int framing; /* non-zero to use framing characters */
Ipaddr local;
int localfrozen;
Ipaddr remote;
int remotefrozen;
int pppup;
Fs *f; /* file system we belong to */
Ipifc* ifc;
Proc* readp; /* reading process */
Proc* timep; /* timer process */
Block* inbuf; /* input buffer */
Block* outbuf; /* output buffer */
QLock outlock; /* and its lock */
ulong magic; /* magic number to detect loop backs */
ulong rctlmap; /* map of chars to ignore in rcvr */
ulong xctlmap; /* map of chars to excape in xmit */
int phase; /* PPP phase */
Pstate* lcp; /* lcp state */
Pstate* ipcp; /* ipcp state */
char secret[256]; /* md5 key */
char chapname[256]; /* chap system name */
Tcpc* ctcp;
ulong mtu; /* maximum xmit size */
ulong mru; /* maximum recv size */
int baud;
int usepap; /* authentication is PAP in every sense, not CHAP */
int papid;
int usechap;
/* rfc */
int usedns;
Ipaddr dns1;
Ipaddr dns2;
/* link quality monitoring */
int period; /* lqm period */
int timeout; /* time to next lqm packet */
Qualstats in; /* local */
Qualstats out;
Qualstats pin; /* peer */
Qualstats pout;
Qualstats sin; /* saved */
};
PPP* pppopen(PPP*, char*, Ipaddr, Ipaddr, int, int, char*, char*);
Block* pppread(PPP*);
int pppwrite(PPP*, Block*);
void pppclose(PPP*);
struct Lcpmsg
{
uchar code;
uchar id;
uchar len[2];
uchar data[1];
};
struct Lcpopt
{
uchar type;
uchar len;
uchar data[1];
};
struct Qualpkt
{
uchar magic[4];
uchar lastoutreports[4];
uchar lastoutpackets[4];
uchar lastoutbytes[4];
uchar peerinreports[4];
uchar peerinpackets[4];
uchar peerindiscards[4];
uchar peerinerrors[4];
uchar peerinbytes[4];
uchar peeroutreports[4];
uchar peeroutpackets[4];
uchar peeroutbytes[4];
};
ushort compress(Tcpc*, Block*, Fs*);
Tcpc* compress_init(Tcpc*);
int compress_negotiate(Tcpc*, uchar*);
ushort tcpcompress(Tcpc*, Block*, Fs*);
Block* tcpuncompress(Tcpc*, Block*, ushort, Fs*);
|