]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/ip/ppp/ppp.h
merge
[plan9front.git] / sys / src / cmd / ip / ppp / ppp.h
1 typedef struct Tcpc Tcpc;
2 typedef struct Pstate Pstate;
3 typedef struct Chap Chap;
4 typedef struct Qualstats Qualstats;
5 typedef struct Comptype Comptype;
6 typedef struct Uncomptype Uncomptype;
7 typedef struct PPP PPP;
8 typedef struct Lcpmsg Lcpmsg;
9 typedef struct Lcpopt Lcpopt;
10 typedef struct Qualpkt Qualpkt;
11 typedef struct Block Block;
12
13 typedef uchar Ipaddr[IPaddrlen];        
14
15 #pragma incomplete Tcpc
16
17 /*
18  *  data blocks
19  */
20 struct Block
21 {
22         Block   *next;
23         Block   *flist;
24         Block   *list;                  /* chain of block lists */
25         uchar   *rptr;                  /* first unconsumed uchar */
26         uchar   *wptr;                  /* first empty uchar */
27         uchar   *lim;                   /* 1 past the end of the buffer */
28         uchar   *base;                  /* start of the buffer */
29         uchar   flags;
30         void    *flow;
31         ulong   pc;
32         ulong   bsz;
33 };
34 #define BLEN(b) ((b)->wptr-(b)->rptr)
35
36 enum
37 {
38         /* block flags */
39         S_DELIM         = (1<<0),
40         S_HANGUP        = (1<<1),
41         S_RHANGUP       = (1<<2),
42
43         /* queue states */
44         QHUNGUP         = (1<<0),
45         QFLOW           = (1<<1),       /* queue is flow controlled */
46 };
47
48 Block*  allocb(int);
49 void    freeb(Block*);
50 Block*  concat(Block*);
51 int     blen(Block*);
52 Block*  pullup(Block*, int);
53 Block*  padb(Block*, int);
54 Block*  btrim(Block*, int, int);
55 Block*  copyb(Block*, int);
56 int     pullb(Block**, int);
57
58 enum {
59         HDLC_frame=     0x7e,
60         HDLC_esc=       0x7d,
61
62         /* PPP frame fields */
63         PPP_addr=       0xff,
64         PPP_ctl=        0x3,
65         PPP_initfcs=    0xffff,
66         PPP_goodfcs=    0xf0b8,
67
68         /* PPP phases */
69         Pdead=          0,      
70         Plink,                          /* doing LCP */
71         Pauth,                          /* doing chap */
72         Pnet,                           /* doing IPCP, CCP */
73         Pterm,                          /* closing down */
74
75         /* PPP protocol types */
76         Pip=            0x21,           /* ip v4 */
77         Pipv6=          0x57,           /* ip v6 */
78         Pvjctcp=        0x2d,           /* compressing van jacobson tcp */
79         Pvjutcp=        0x2f,           /* uncompressing van jacobson tcp */
80         Pcdata=         0xfd,           /* compressed datagram */
81         Pipcp=          0x8021,         /* ip control */
82         Pecp=           0x8053,         /* encryption control */
83         Pccp=           0x80fd,         /* compressed datagram control */
84         Plcp=           0xc021,         /* link control */
85         Ppasswd=        0xc023,         /* passwd authentication */
86         Plqm=           0xc025,         /* link quality monitoring */
87         Pchap=          0xc223,         /* challenge/response */
88
89         /* LCP codes */
90         Lconfreq=       1,
91         Lconfack=       2,
92         Lconfnak=       3,
93         Lconfrej=       4,
94         Ltermreq=       5,
95         Ltermack=       6,
96         Lcoderej=       7,
97         Lprotorej=      8,
98         Lechoreq=       9,
99         Lechoack=       10,
100         Ldiscard=       11,
101         Lresetreq=      14,
102         Lresetack=      15,
103
104         /* Lcp configure options */
105         Omtu=           1,
106         Octlmap=        2,
107         Oauth=          3,
108         Oquality=       4,
109         Omagic=         5,
110         Opc=            7,
111         Oac=            8,
112
113         /* authentication protocols */
114         APmd5=          5,
115         APmschap=       128,
116         APpasswd=       Ppasswd,                /* use Pap, not Chap */
117
118         /* lcp flags */
119         Fmtu=           1<<Omtu,
120         Fctlmap=        1<<Octlmap,
121         Fauth=          1<<Oauth,
122         Fquality=       1<<Oquality,
123         Fmagic=         1<<Omagic,
124         Fpc=            1<<Opc,
125         Fac=            1<<Oac,
126
127         /* Chap codes */
128         Cchallenge=     1,
129         Cresponse=      2,
130         Csuccess=       3,
131         Cfailure=       4,
132
133         /* Pap codes */
134         Pauthreq=       1,
135         Pauthack=       2,
136         Pauthnak=       3,
137
138         /* Chap state */
139         Cunauth=        0,
140         Cchalsent,
141         Cauthfail,
142         Cauthok,
143
144         /* link states */
145         Sclosed=        0,
146         Sclosing,
147         Sreqsent,
148         Sackrcvd,
149         Sacksent,
150         Sopened,
151
152         /* ccp configure options */
153         Ocoui=          0,      /* proprietary compression */
154         Ocstac=         17,     /* stac electronics LZS */
155         Ocmppc=         18,     /* microsoft ppc */
156         Octhwack=       31,     /* thwack; unofficial */
157
158         /* ccp flags */
159         Fcoui=          1<<Ocoui,
160         Fcstac=         1<<Ocstac,
161         Fcmppc=         1<<Ocmppc,
162         Fcthwack=       1<<Octhwack,
163
164         /* ecp configure options */
165         Oeoui=          0,      /* proprietary compression */
166         Oedese=         1,      /* DES */
167
168         /* ecp flags */
169         Feoui=          1<<Oeoui,
170         Fedese=         1<<Oedese,
171
172         /* ipcp configure options */
173         Oipaddrs=       1,
174         Oipcompress=    2,
175         Oipaddr=        3,
176         Oipdns=         129,
177         Oipwins=        130,
178         Oipdns2=        131,
179         Oipwins2=       132,
180
181         /* ipcp flags */
182         Fipaddrs=       1<<Oipaddrs,
183         Fipcompress=    1<<Oipcompress,
184         Fipaddr=        1<<Oipaddr,
185         Fipdns=         1<<8,   // Oipdns,
186         Fipwins=        1<<9,   // Oipwins,
187         Fipdns2=        1<<10,  // Oipdns2,
188         Fipwins2=       1<<11,  // Oipwins2,
189
190         Period=         5*1000, /* period of retransmit process (in ms) */
191         Timeout=        20,     /* xmit timeout (in Periods) */
192         Buflen=         4096,
193
194         MAX_STATES=     16,             /* van jacobson compression states */
195         Defmtu=         1450,           /* default that we will ask for */
196         Minmtu=         128,            /* minimum that we will accept */
197         Maxmtu=         2000,           /* maximum that we will accept */
198 };
199
200
201 struct Pstate
202 {
203         int     proto;          /* protocol type */
204         int     timeout;        /* for current state */
205         int     rxtimeout;      /* for current retransmit */
206         ulong   flags;          /* options received */
207         uchar   id;             /* id of current message */
208         uchar   confid;         /* id of current config message */
209         uchar   termid;         /* id of current termination message */
210         uchar   rcvdconfid;     /* id of last conf message received */
211         uchar   state;          /* PPP link state */
212         ulong   optmask;        /* which options to request */
213         int     echoack;        /* recieved echo ack */
214         int     echotimeout;    /* echo timeout */
215 };
216
217 /* server chap state */
218 struct Chap
219 {
220         int     proto;          /* chap proto */
221         int     state;          /* chap state */
222         uchar   id;             /* id of current message */
223         int     timeout;        /* for current state */
224         Chalstate *cs;
225 };
226
227 struct Qualstats
228 {
229         ulong   reports;
230         ulong   packets;
231         ulong   uchars;
232         ulong   discards;
233         ulong   errors;
234 };
235
236 struct Comptype
237 {
238         void*           (*init)(PPP*);
239         Block*          (*compress)(PPP*, ushort, Block*, int*);
240         Block*          (*resetreq)(void*, Block*);
241         void            (*fini)(void*);
242 };
243
244 struct Uncomptype
245 {
246         void*           (*init)(PPP*);
247         Block*          (*uncompress)(PPP*, Block*, int*, Block**);
248         void            (*resetack)(void*, Block*);
249         void            (*fini)(void*);
250 };
251
252 struct PPP
253 {
254         QLock;
255
256         int             ipfd;           /* fd to ip stack */
257         int             ipcfd;          /* fd to control channel of ip stack */
258         int             mediain;        /* fd to media */
259         int             mediaout;       /* fd to media */
260         char            *net;           /* ip stack to use */
261         int             framing;        /* non-zero to use framing characters */
262         Ipaddr          local;
263         Ipaddr          curlocal;
264         int             localfrozen;
265         Ipaddr          remote;
266         Ipaddr          curremote;
267         int             remotefrozen;
268
269         Ipaddr          dns[2];         /* dns servers */
270         Ipaddr          wins[2];        /* wins servers */
271
272         Block*          inbuf;          /* input buffer */
273         Block*          outbuf;         /* output buffer */
274         QLock           outlock;        /*  and its lock */
275         ulong           magic;          /* magic number to detect loop backs */
276         ulong           rctlmap;        /* map of chars to ignore in rcvr */
277         ulong           xctlmap;        /* map of chars to excape in xmit */
278         int             phase;          /* PPP phase */
279         Pstate*         lcp;            /* lcp state */
280         Pstate*         ccp;            /* ccp state */
281         Pstate*         ipcp;           /* ipcp state */
282         Chap*           chap;           /* chap state */
283         Tcpc*           ctcp;           /* tcp compression state */
284         ulong           mtu;            /* maximum xmit size */
285         ulong           mru;            /* maximum recv size */
286
287         /* data compression */
288         int             ctries;         /* number of negotiation tries */
289         Comptype        *ctype;         /* compression virtual table */
290         void            *cstate;        /* compression state */
291         Uncomptype      *unctype;       /* uncompression virtual table */
292         void            *uncstate;      /* uncompression state */
293         
294         /* encryption key */
295         uchar           key[16];
296         int             sendencrypted;
297
298         /* authentication */
299         char            secret[256];    /* md5 key */
300         char            chapname[256];  /* chap system name */
301
302         /* link quality monitoring */
303         int             period; /* lqm period */
304         int             timeout; /* time to next lqm packet */
305         Qualstats       in;     /* local */
306         Qualstats       out;
307         Qualstats       pin;    /* peer */
308         Qualstats       pout;
309         Qualstats       sin;    /* saved */
310
311         struct {
312                 ulong   ipsend;
313                 ulong   iprecv;
314                 ulong   iprecvbadsrc;
315                 ulong   iprecvnotup;
316                 ulong   comp;
317                 ulong   compin;
318                 ulong   compout;
319                 ulong   compreset;
320                 ulong   uncomp;
321                 ulong   uncompin;
322                 ulong   uncompout;
323                 ulong   uncompreset;
324                 ulong   vjin;
325                 ulong   vjout;
326                 ulong   vjfail;
327         } stat;
328 };
329
330 extern Block*   pppread(PPP*);
331 extern int      pppwrite(PPP*, Block*);
332 extern void     pppopen(PPP*, int, int, char*, Ipaddr, Ipaddr, int, int);
333
334 struct Lcpmsg
335 {
336         uchar   code;
337         uchar   id;
338         uchar   len[2];
339         uchar   data[1];
340 };
341
342 struct Lcpopt
343 {
344         uchar   type;
345         uchar   len;
346         uchar   data[1];
347 };
348
349 struct Qualpkt
350 {
351         uchar   magic[4];
352
353         uchar   lastoutreports[4];
354         uchar   lastoutpackets[4];
355         uchar   lastoutuchars[4];
356         uchar   peerinreports[4];
357         uchar   peerinpackets[4];
358         uchar   peerindiscards[4];
359         uchar   peerinerrors[4];
360         uchar   peerinuchars[4];
361         uchar   peeroutreports[4];
362         uchar   peeroutpackets[4];
363         uchar   peeroutuchars[4];
364 };
365
366 extern Block*   compress(Tcpc*, Block*, int*);
367 extern void     compress_error(Tcpc*);
368 extern Tcpc*    compress_init(Tcpc*);
369 extern int      compress_negotiate(Tcpc*, uchar*);
370 extern Block*   tcpcompress(Tcpc*, Block*, int*);
371 extern Block*   tcpuncompress(Tcpc*, Block*, int);
372 extern Block*   alloclcp(int, int, int, Lcpmsg**);
373 extern ushort   ptclcsum(Block*, int, int);
374 extern ushort   ptclbsum(uchar*, int);
375 extern ushort   ipcsum(uchar*);
376
377 extern  Comptype        cmppc;
378 extern  Uncomptype      uncmppc;
379
380 extern  Comptype        cthwack;
381 extern  Uncomptype      uncthwack;
382
383 extern void     netlog(char*, ...);
384 #pragma varargck        argpos  netlog  1
385
386 extern char     *LOG;