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