ip.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. typedef struct Enpkt Enpkt;
  2. typedef struct Arppkt Arppkt;
  3. typedef struct Ippkt Ippkt;
  4. typedef struct Ilpkt Ilpkt;
  5. typedef struct Udppkt Udppkt;
  6. typedef struct Icmppkt Icmppkt;
  7. typedef struct Ifc Ifc;
  8. enum
  9. {
  10. Easize = 6, /* Ether address size */
  11. Pasize = 4, /* IP protocol address size */
  12. };
  13. enum
  14. {
  15. Nqt= 8,
  16. };
  17. typedef
  18. struct Ilp
  19. {
  20. Queue* reply; /* ethernet output */
  21. uchar iphis[Pasize]; /* his ip address (index) */
  22. uchar ipgate[Pasize]; /* his ip/gateway address */
  23. Chan* chan; /* list of il channels */
  24. int alloc; /* 1 means allocated */
  25. int srcp; /* source port (index) */
  26. int dstp; /* dest port (index) */
  27. int state; /* connection state */
  28. Lock;
  29. Msgbuf* unacked;
  30. Msgbuf* unackedtail;
  31. Msgbuf* outoforder;
  32. ulong next; /* id of next to send */
  33. ulong recvd; /* last packet received */
  34. ulong start; /* local start id */
  35. ulong rstart; /* remote start id */
  36. ulong acksent; /* Last packet acked */
  37. ulong lastxmit; /* time of last xmit */
  38. ulong lastrecv; /* time of last recv */
  39. ulong timeout; /* time out counter */
  40. ulong acktime; /* acknowledge timer */
  41. ulong querytime; /* Query timer */
  42. ulong delay; /* Average of the fixed rtt delay */
  43. ulong rate; /* Average byte rate */
  44. ulong mdev; /* Mean deviation of predicted to real rtt */
  45. ulong maxrtt; /* largest rtt seen */
  46. ulong rttack; /* The ack we are waiting for */
  47. int rttlen; /* Length of rttack packet */
  48. ulong rttstart; /* Time we issued rttack packet */
  49. ulong unackedbytes;
  50. int rexmit; /* number of rexmits of *unacked */
  51. ulong qt[Nqt+1]; /* state table for query messages */
  52. int qtx; /* ... index into qt */
  53. int window; /* maximum receive window */
  54. Rendez syn; /* connect hang out */
  55. } Ilp;
  56. /*
  57. * Ethernet header
  58. */
  59. enum
  60. {
  61. ETHERMINTU = 60, /* minimum transmit size */
  62. ETHERMAXTU = 1514, /* maximum transmit size */
  63. Arptype = 0x0806,
  64. Iptype = 0x0800,
  65. Icmpproto = 1,
  66. Igmpproto = 2,
  67. Tcpproto = 6,
  68. Udpproto = 17,
  69. Ilproto = 40,
  70. Nqueue = 20,
  71. Nfrag = 6, /* max number of non-contig ip fragments */
  72. Nrock = 20, /* number of partial ip assembly stations */
  73. Nb = 211, /* number of arp hash buckets */
  74. Ne = 10, /* number of entries in each arp hash bucket */
  75. Ensize = 14, /* ether header size */
  76. Ipsize = 20, /* ip header size -- doesnt include Ensize */
  77. Arpsize = 28, /* arp header size -- doesnt include Ensize */
  78. Ilsize = 18, /* il header size -- doesnt include Ipsize/Ensize */
  79. Udpsize = 8, /* il header size -- doesnt include Ipsize/Ensize */
  80. Udpphsize = 12, /* udp pseudo ip header size */
  81. IP_VER = 0x40, /* Using IP version 4 */
  82. IP_HLEN = Ipsize/4, /* Header length in longs */
  83. IP_DF = 0x4000, /* Don't fragment */
  84. IP_MF = 0x2000, /* More fragments */
  85. Arprequest = 1,
  86. Arpreply,
  87. Ilfsport = 17008,
  88. Ilauthport = 17020,
  89. Ilfsout = 5000,
  90. SNTP = 123,
  91. SNTP_LOCAL = 6001,
  92. };
  93. struct Enpkt
  94. {
  95. uchar d[Easize]; /* destination address */
  96. uchar s[Easize]; /* source address */
  97. uchar type[2]; /* packet type */
  98. uchar data[ETHERMAXTU-(6+6+2)];
  99. uchar crc[4];
  100. };
  101. struct Arppkt
  102. {
  103. uchar d[Easize]; /* ether header */
  104. uchar s[Easize];
  105. uchar type[2];
  106. uchar hrd[2]; /* hardware type, must be ether==1 */
  107. uchar pro[2]; /* protocol, must be ip */
  108. uchar hln; /* hardware address len, must be Easize */
  109. uchar pln; /* protocol address len, must be Pasize */
  110. uchar op[2];
  111. uchar sha[Easize];
  112. uchar spa[Pasize];
  113. uchar tha[Easize];
  114. uchar tpa[Pasize];
  115. };
  116. struct Ippkt
  117. {
  118. uchar d[Easize]; /* ether header */
  119. uchar s[Easize];
  120. uchar type[2];
  121. uchar vihl; /* Version and header length */
  122. uchar tos; /* Type of service */
  123. uchar length[2]; /* packet length */
  124. uchar id[2]; /* Identification */
  125. uchar frag[2]; /* Fragment information */
  126. uchar ttl; /* Time to live */
  127. uchar proto; /* Protocol */
  128. uchar cksum[2]; /* Header checksum */
  129. uchar src[Pasize]; /* Ip source */
  130. uchar dst[Pasize]; /* Ip destination */
  131. };
  132. struct Ilpkt
  133. {
  134. uchar d[Easize]; /* ether header */
  135. uchar s[Easize];
  136. uchar type[2];
  137. uchar vihl; /* ip header */
  138. uchar tos;
  139. uchar length[2];
  140. uchar id[2];
  141. uchar frag[2];
  142. uchar ttl;
  143. uchar proto;
  144. uchar cksum[2];
  145. uchar src[Pasize];
  146. uchar dst[Pasize];
  147. uchar ilsum[2]; /* Checksum including header */
  148. uchar illen[2]; /* Packet length */
  149. uchar iltype; /* Packet type */
  150. uchar ilspec; /* Special */
  151. uchar ilsrc[2]; /* Src port */
  152. uchar ildst[2]; /* Dst port */
  153. uchar ilid[4]; /* Sequence id */
  154. uchar ilack[4]; /* Acked sequence */
  155. };
  156. struct Udppkt
  157. {
  158. uchar d[Easize]; /* ether header */
  159. uchar s[Easize];
  160. uchar type[2];
  161. uchar vihl; /* ip header */
  162. uchar tos;
  163. uchar length[2];
  164. uchar id[2];
  165. uchar frag[2];
  166. uchar ttl;
  167. uchar proto;
  168. uchar cksum[2];
  169. uchar src[Pasize];
  170. uchar dst[Pasize];
  171. uchar udpsrc[2]; /* Src port */
  172. uchar udpdst[2]; /* Dst port */
  173. uchar udplen[2]; /* Packet length */
  174. uchar udpsum[2]; /* Checksum including header */
  175. };
  176. struct Icmppkt
  177. {
  178. uchar d[Easize]; /* ether header */
  179. uchar s[Easize];
  180. uchar type[2];
  181. uchar vihl; /* ip header */
  182. uchar tos;
  183. uchar length[2];
  184. uchar id[2];
  185. uchar frag[2];
  186. uchar ttl;
  187. uchar proto;
  188. uchar cksum[2];
  189. uchar src[Pasize];
  190. uchar dst[Pasize];
  191. uchar icmptype; /* Src port */
  192. uchar icmpcode; /* Dst port */
  193. uchar icmpsum[2]; /* Checksum including header */
  194. uchar icmpbody[10]; /* Depends on type */
  195. };
  196. struct Ifc
  197. {
  198. Lock;
  199. Queue* reply;
  200. Filter work[3];
  201. Filter rate[3];
  202. ulong rcverr;
  203. ulong txerr;
  204. ulong sumerr;
  205. ulong rxpkt;
  206. ulong txpkt;
  207. uchar ea[Easize]; /* my ether address */
  208. uchar ipa[Pasize]; /* my ip address, pulled from netdb */
  209. uchar netgate[Pasize]; /* my ip gateway, pulled from netdb */
  210. ulong ipaddr;
  211. ulong mask;
  212. ulong cmask;
  213. Ifc *next; /* List of configured interfaces */
  214. };
  215. Ifc* enets; /* List of configured interfaces */
  216. void riprecv(Msgbuf*, Ifc*);
  217. void sntprecv(Msgbuf *mb, Ifc *ifc);
  218. void arpreceive(Enpkt*, int, Ifc*);
  219. void ipreceive(Enpkt*, int, Ifc*);
  220. void ilrecv(Msgbuf*, Ifc*);
  221. void udprecv(Msgbuf*, Ifc*);
  222. void ilrecv(Msgbuf*, Ifc*);
  223. void icmprecv(Msgbuf*, Ifc*);
  224. void igmprecv(Msgbuf*, Ifc*);
  225. void tcprecv(Msgbuf*, Ifc*);
  226. void iprouteinit(void);
  227. long ipclassmask(uchar*);
  228. void iproute(uchar*, uchar*, uchar*);
  229. void getipa(Ifc*, int);
  230. int ipforme(uchar*, Ifc*);
  231. int ipcsum(uchar*);
  232. int ptclcsum(uchar*, int);
  233. void ipsend(Msgbuf*);
  234. void ipsend1(Msgbuf*, Ifc*, uchar*);
  235. uchar authip[Pasize]; /* ip address of server - from config block */
  236. uchar sntpip[Pasize]; /* ip address of sntp server */
  237. struct
  238. {
  239. uchar sysip[Pasize]; /* my ip - from config block */
  240. uchar defmask[Pasize];/* ip mask - from config block */
  241. uchar defgwip[Pasize];/* gateway ip - from config block */
  242. } ipaddr[10];