ppp.h 8.1 KB

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