1 | /************************************************************************** |
---|
2 | * |
---|
3 | * Copyright (c) 2013 Alcatel-Lucent |
---|
4 | * |
---|
5 | * Alcatel Lucent licenses this file to You under the Apache License, |
---|
6 | * Version 2.0 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. A copy of the License is contained the |
---|
8 | * file LICENSE at the top level of this repository. |
---|
9 | * You may also obtain a copy of the License at: |
---|
10 | * |
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
12 | * |
---|
13 | * Unless required by applicable law or agreed to in writing, software |
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
16 | * See the License for the specific language governing permissions and |
---|
17 | * limitations under the License. |
---|
18 | * |
---|
19 | ************************************************************************** |
---|
20 | * |
---|
21 | * ether.h: |
---|
22 | * |
---|
23 | * This file is a single "contains-all" header file to support different |
---|
24 | * components of ethernet/IP along with the peer and upper layer protocols |
---|
25 | * like ICMP, UDP, TFTP, DHCP etc... |
---|
26 | * |
---|
27 | * Original author: Ed Sutter (ed.sutter@alcatel-lucent.com) |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef _ETHER_H_ |
---|
32 | #define _ETHER_H_ |
---|
33 | |
---|
34 | #define __PACKED__ __attribute__ ((packed)) |
---|
35 | |
---|
36 | #ifndef INCLUDE_MONCMD |
---|
37 | #define INCLUDE_MONCMD INCLUDE_ETHERNET |
---|
38 | #endif |
---|
39 | |
---|
40 | #ifndef INCLUDE_ETHERVERBOSE |
---|
41 | #define INCLUDE_ETHERVERBOSE INCLUDE_ETHERNET |
---|
42 | #endif |
---|
43 | |
---|
44 | #ifndef INCLUDE_RARPIPASSIGN |
---|
45 | #define INCLUDE_RARPIPASSIGN INCLUDE_ETHERNET |
---|
46 | #endif |
---|
47 | |
---|
48 | /************************************************************************ |
---|
49 | * |
---|
50 | * Default MAC & IP addresses... |
---|
51 | * |
---|
52 | */ |
---|
53 | |
---|
54 | #ifndef DEFAULT_ETHERADD |
---|
55 | #define DEFAULT_ETHERADD "00:00:00:00:00:00" |
---|
56 | #endif |
---|
57 | |
---|
58 | #ifndef DEFAULT_IPADD |
---|
59 | #define DEFAULT_IPADD "0.0.0.0" |
---|
60 | #endif |
---|
61 | |
---|
62 | /************************************************************************ |
---|
63 | * |
---|
64 | * Retransmission delay stuff... |
---|
65 | * |
---|
66 | */ |
---|
67 | |
---|
68 | #define DELAY_INIT_ARP 1 |
---|
69 | #define DELAY_INIT_DHCP 2 |
---|
70 | #define DELAY_INIT_TFTP 3 |
---|
71 | #define DELAY_INCREMENT 4 |
---|
72 | #define DELAY_RETURN 5 |
---|
73 | #define DELAY_OR_TIMEOUT_RETURN 6 |
---|
74 | #define RETRANSMISSION_TIMEOUT -1 |
---|
75 | #define RETRANSMISSION_ACTIVE 1 |
---|
76 | |
---|
77 | /************************************************************************ |
---|
78 | * |
---|
79 | * Ethernet stuff... |
---|
80 | * |
---|
81 | */ |
---|
82 | |
---|
83 | struct ether_addr { |
---|
84 | unsigned char ether_addr_octet[6]; |
---|
85 | } __PACKED__ ; |
---|
86 | |
---|
87 | struct ether_header { |
---|
88 | struct ether_addr ether_dhost; |
---|
89 | struct ether_addr ether_shost; |
---|
90 | unsigned short ether_type; |
---|
91 | } __PACKED__ ; |
---|
92 | #define ETHERSIZE sizeof(struct ether_header) |
---|
93 | |
---|
94 | #define ETHERTYPE_PUP 0x0200 /* PUP protocol */ |
---|
95 | #define ETHERTYPE_IP 0x0800 /* IP protocol */ |
---|
96 | #define ETHERTYPE_ARP 0x0806 /* Addr resolution protocol */ |
---|
97 | #define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */ |
---|
98 | |
---|
99 | #define ETHER_MINPKT 64 |
---|
100 | |
---|
101 | /************************************************************************ |
---|
102 | * |
---|
103 | * ARP/RARP stuff... |
---|
104 | * |
---|
105 | */ |
---|
106 | |
---|
107 | #define SIZEOFARPCACHE 8 |
---|
108 | |
---|
109 | #define ARPSIZE (sizeof(struct ether_header) + sizeof(struct arphdr)) |
---|
110 | |
---|
111 | struct arphdr { |
---|
112 | unsigned short hardware; /* 1 for ethernet */ |
---|
113 | unsigned short protocol; |
---|
114 | unsigned char hlen; |
---|
115 | unsigned char plen; |
---|
116 | unsigned short operation; |
---|
117 | unsigned char senderha[6]; |
---|
118 | unsigned char senderia[4]; |
---|
119 | unsigned char targetha[6]; |
---|
120 | unsigned char targetia[4]; |
---|
121 | } __PACKED__ ; |
---|
122 | |
---|
123 | /* ARP/RARP operations:. */ |
---|
124 | #define ARP_REQUEST 1 |
---|
125 | #define ARP_RESPONSE 2 |
---|
126 | #define RARP_REQUEST 3 |
---|
127 | #define RARP_RESPONSE 4 |
---|
128 | |
---|
129 | /************************************************************************ |
---|
130 | * |
---|
131 | * IP stuff... |
---|
132 | * |
---|
133 | */ |
---|
134 | |
---|
135 | struct in_addr { |
---|
136 | unsigned long s_addr; |
---|
137 | } __PACKED__ ; |
---|
138 | |
---|
139 | #define getIP_V(x) ((x)>>4) |
---|
140 | #define getIP_HL(x) ((x)&0xf) |
---|
141 | #define IP_DONTFRAG 0x4000 /* dont fragment flag */ |
---|
142 | #define IP_MOREFRAGS 0x2000 /* more fragments flag */ |
---|
143 | #define IP_VER 0x4 |
---|
144 | #define IP_HDR_LEN (sizeof(struct ip)>>2) |
---|
145 | #define IP_HDR_VER_LEN ((IP_VER<<4)|IP_HDR_LEN) |
---|
146 | #define IP_HLEN(ihdr) ((ihdr->ip_vhl&0x0f)<<2) |
---|
147 | |
---|
148 | struct ip { |
---|
149 | unsigned char ip_vhl; /* version & header length */ |
---|
150 | unsigned char ip_tos; /* type of service */ |
---|
151 | short ip_len; /* total length */ |
---|
152 | unsigned short ip_id; /* identification */ |
---|
153 | short ip_off; /* fragment offset field */ |
---|
154 | unsigned char ip_ttl; /* time to live */ |
---|
155 | unsigned char ip_p; /* protocol */ |
---|
156 | unsigned short ip_sum; /* checksum */ |
---|
157 | struct in_addr ip_src; /* source address */ |
---|
158 | struct in_addr ip_dst; /* dest address */ |
---|
159 | } __PACKED__ ; |
---|
160 | #define IPSIZE sizeof(struct ip) |
---|
161 | |
---|
162 | /* ip protocols */ |
---|
163 | #define IP_IP 0 |
---|
164 | #define IP_ICMP 1 |
---|
165 | #define IP_IGMP 2 |
---|
166 | #define IP_GGP 3 |
---|
167 | #define IP_TCP 6 |
---|
168 | #define IP_PUP 12 |
---|
169 | #define IP_UDP 17 |
---|
170 | |
---|
171 | #define IP1(a) ((a & 0xff000000) >> 24) |
---|
172 | #define IP2(a) ((a & 0xff0000) >> 16) |
---|
173 | #define IP3(a) ((a & 0xff00) >> 8) |
---|
174 | #define IP4(a) (a & 0xff) |
---|
175 | |
---|
176 | #define IP2LONG(a,b,c,d) ((a << 24) | (b << 16) | (c << 8) | d) |
---|
177 | |
---|
178 | /************************************************************************ |
---|
179 | * |
---|
180 | * ICMP stuff... |
---|
181 | * |
---|
182 | */ |
---|
183 | |
---|
184 | #define ICMP_UNREACHABLESIZE (sizeof(struct ether_header) + \ |
---|
185 | sizeof(struct ip) + sizeof(struct icmp_unreachable_hdr) + datalen) |
---|
186 | #define ICMP_TIMERQSTSIZE (sizeof(struct ether_header) + \ |
---|
187 | sizeof(struct ip) + sizeof(struct icmp_time_hdr)) |
---|
188 | #define ICMP_ECHORQSTSIZE (sizeof(struct ether_header) + \ |
---|
189 | sizeof(struct ip) + sizeof(struct icmp_echo_hdr)) |
---|
190 | |
---|
191 | #define INVALID_TIMESTAMP 0xffffffff |
---|
192 | #define NONSTANDARD_TIMESTAMP 0x80000000 |
---|
193 | |
---|
194 | /* ICMP protocol header. |
---|
195 | */ |
---|
196 | struct icmp_hdr { |
---|
197 | unsigned char type; /* type of message */ |
---|
198 | unsigned char code; /* type subcode */ |
---|
199 | unsigned short cksum; /* ones complement cksum of struct */ |
---|
200 | } __PACKED__ ; |
---|
201 | |
---|
202 | /* ICMP time request. |
---|
203 | */ |
---|
204 | struct icmp_time_hdr { |
---|
205 | unsigned char type; /* type of message */ |
---|
206 | unsigned char code; /* type subcode */ |
---|
207 | unsigned short cksum; /* ones complement cksum of struct */ |
---|
208 | unsigned short id; /* identifier */ |
---|
209 | unsigned short seq; /* sequence number */ |
---|
210 | unsigned long orig; /* originate timestamp */ |
---|
211 | unsigned long recv; /* receive timestamp */ |
---|
212 | unsigned long xmit; /* transmit timestamp */ |
---|
213 | } __PACKED__ ; |
---|
214 | |
---|
215 | /* ICMP echo reply. |
---|
216 | */ |
---|
217 | struct icmp_echo_hdr { |
---|
218 | unsigned char type; /* type of message */ |
---|
219 | unsigned char code; /* type subcode */ |
---|
220 | unsigned short cksum; /* ones complement cksum of struct */ |
---|
221 | unsigned short id; /* identifier */ |
---|
222 | unsigned short seq; /* sequence number */ |
---|
223 | } __PACKED__ ; |
---|
224 | |
---|
225 | struct icmp_unreachable_hdr { |
---|
226 | unsigned char type; /* type of message */ |
---|
227 | unsigned char code; /* type subcode */ |
---|
228 | unsigned short cksum; /* ones complement cksum of struct */ |
---|
229 | unsigned short unused1; /* Is alway zero */ |
---|
230 | unsigned short unused2; /* Is alway zero */ |
---|
231 | } __PACKED__ ; |
---|
232 | |
---|
233 | /* ICMP types |
---|
234 | */ |
---|
235 | #define ICMP_ECHOREPLY 0 |
---|
236 | #define ICMP_DESTUNREACHABLE 3 |
---|
237 | #define ICMP_SOURCEQUENCH 4 |
---|
238 | #define ICMP_REDIRECT 5 |
---|
239 | #define ICMP_ECHOREQUEST 8 |
---|
240 | #define ICMP_TIMEEXCEEDED 11 |
---|
241 | #define ICMP_PARAMPROBLEM 12 |
---|
242 | #define ICMP_TIMEREQUEST 13 |
---|
243 | #define ICMP_TIMEREPLY 14 |
---|
244 | #define ICMP_INFOREQUEST 15 |
---|
245 | #define ICMP_INFOREPLY 16 |
---|
246 | #define ICMP_ADDRMASKREQUEST 17 |
---|
247 | #define ICMP_ADDRMASKREPLY 18 |
---|
248 | |
---|
249 | /* A few unreachable codes. |
---|
250 | */ |
---|
251 | #define ICMP_UNREACHABLE_PROTOCOL 2 |
---|
252 | #define ICMP_UNREACHABLE_PORT 3 |
---|
253 | #define ICMP_DEST_UNREACHABLE_MAX_CODE 12 |
---|
254 | |
---|
255 | /************************************************************************ |
---|
256 | * |
---|
257 | * UDP stuff... |
---|
258 | * |
---|
259 | */ |
---|
260 | |
---|
261 | /* UDP protocol header. |
---|
262 | */ |
---|
263 | struct Udphdr { |
---|
264 | unsigned short uh_sport; /* source port */ |
---|
265 | unsigned short uh_dport; /* destination port */ |
---|
266 | unsigned short uh_ulen; /* udp length */ |
---|
267 | unsigned short uh_sum; /* udp checksum */ |
---|
268 | } __PACKED__ ; |
---|
269 | #define UDPSIZE sizeof(struct Udphdr) |
---|
270 | |
---|
271 | /* UDP pseudo header. |
---|
272 | */ |
---|
273 | struct UdpPseudohdr { |
---|
274 | struct in_addr ip_src; /* source address */ |
---|
275 | struct in_addr ip_dst; /* dest address */ |
---|
276 | unsigned char zero; /* fixed to zero */ |
---|
277 | unsigned char proto; /* protocol */ |
---|
278 | unsigned short ulen; /* udp length */ |
---|
279 | } __PACKED__ ; |
---|
280 | |
---|
281 | #define UDP_OPEN 2 |
---|
282 | #define UDP_DATA 3 |
---|
283 | #define UDP_ACK 4 |
---|
284 | #define UDP_TTL 0x3c |
---|
285 | |
---|
286 | /************************************************************************ |
---|
287 | * |
---|
288 | * IGMP stuff... |
---|
289 | * |
---|
290 | */ |
---|
291 | |
---|
292 | /* IGMP protocol header. |
---|
293 | */ |
---|
294 | struct Igmphdr { |
---|
295 | unsigned char type; /* IGMP message type */ |
---|
296 | unsigned char mrt; /* Max response time */ |
---|
297 | unsigned short csum; /* Checksum of IGMP header */ |
---|
298 | unsigned long group; /* Multicast group ip */ |
---|
299 | } __PACKED__ ; |
---|
300 | |
---|
301 | #define IGMPSIZE sizeof(struct Igmphdr) |
---|
302 | |
---|
303 | #define IGMPTYPE_QUERY 0x11 |
---|
304 | #define IGMPTYPE_REPORTV1 0x12 |
---|
305 | #define IGMPTYPE_REPORTV2 0x16 |
---|
306 | #define IGMPTYPE_JOIN IGMPTYPE_REPORTV2 |
---|
307 | #define IGMPTYPE_LEAVE 0x17 |
---|
308 | |
---|
309 | #define ALL_HOSTS 0xe0000001 /* 224.0.0.1 */ |
---|
310 | #define ALL_MULTICAST_ROUTERS 0xe0000002 /* 224.0.0.2 */ |
---|
311 | |
---|
312 | #define IGMP_JOINRQSTSIZE (sizeof(struct ether_header) + \ |
---|
313 | sizeof(struct ip) + sizeof(long) + sizeof(struct Igmphdr)) |
---|
314 | |
---|
315 | /************************************************************************ |
---|
316 | * |
---|
317 | * TFTP stuff... |
---|
318 | * |
---|
319 | */ |
---|
320 | |
---|
321 | /* TFTP state values: |
---|
322 | */ |
---|
323 | #define TFTPOFF 0 |
---|
324 | #define TFTPIDLE 1 |
---|
325 | #define TFTPACTIVE 2 |
---|
326 | #define TFTPERROR 3 |
---|
327 | #define TFTPSENTRRQ 4 |
---|
328 | #define TFTPTIMEOUT 5 |
---|
329 | #define TFTPHOSTERROR 6 |
---|
330 | #define TFTPSENTWRQ 7 |
---|
331 | |
---|
332 | /* TFTP opcode superset (see Stevens pg 466) |
---|
333 | */ |
---|
334 | #define TFTP_RRQ 1 |
---|
335 | #define TFTP_WRQ 2 |
---|
336 | #define TFTP_DAT 3 |
---|
337 | #define TFTP_ACK 4 |
---|
338 | #define TFTP_ERR 5 |
---|
339 | #define TFTP_OACK 6 /* RFC2347: Option Acknowledgement opcode. */ |
---|
340 | |
---|
341 | /* TFTP is UDP port 69... (see Stevens pg 206) |
---|
342 | */ |
---|
343 | #define IPPORT_TFTP 69 |
---|
344 | #define IPPORT_TFTPSRC 8888 |
---|
345 | |
---|
346 | #define TFTP_NETASCII_WRQ 1 |
---|
347 | #define TFTP_NETASCII_RRQ 2 |
---|
348 | #define TFTP_OCTET_WRQ 3 |
---|
349 | #define TFTP_OCTET_RRQ 4 |
---|
350 | #define TFTP_DATAMAX 512 |
---|
351 | #define TFTP_PKTOVERHEAD (ETHERSIZE + IPSIZE + UDPSIZE) |
---|
352 | #define TFTPACKSIZE (TFTP_PKTOVERHEAD + 4) |
---|
353 | |
---|
354 | /************************************************************************ |
---|
355 | * |
---|
356 | * DHCP stuff... |
---|
357 | * See RFCs 2131 & 2132 for more details. |
---|
358 | * Note that the values used for dhcpstate enum are based on the state |
---|
359 | * diagram in 3rd Edition Comer pg 375. Plus a few more so that I can |
---|
360 | * used the same enum for DHCP and BOOTP. |
---|
361 | * |
---|
362 | */ |
---|
363 | |
---|
364 | #define BOOTPSIZE (sizeof(struct ether_header) + sizeof(struct ip) + \ |
---|
365 | sizeof(struct Udphdr) + sizeof(struct bootphdr)) |
---|
366 | |
---|
367 | #define DHCPSIZE (sizeof(struct ether_header) + sizeof(struct ip) + \ |
---|
368 | sizeof(struct Udphdr) + sizeof(struct dhcphdr)) |
---|
369 | |
---|
370 | #define IPPORT_DHCP_SERVER 67 |
---|
371 | #define IPPORT_DHCP_CLIENT 68 |
---|
372 | |
---|
373 | #define DHCPBOOTP_REQUEST 1 |
---|
374 | #define DHCPBOOTP_REPLY 2 |
---|
375 | |
---|
376 | #define USE_NULL 0 |
---|
377 | #define USE_DHCP 1 |
---|
378 | #define USE_BOOTP 2 |
---|
379 | |
---|
380 | #define DHCP_VERBOSE (SHOW_DHCP|SHOW_INCOMING|SHOW_OUTGOING|SHOW_BROADCAST) |
---|
381 | |
---|
382 | /* DHCP Message types: |
---|
383 | */ |
---|
384 | #define DHCPDISCOVER 1 |
---|
385 | #define DHCPOFFER 2 |
---|
386 | #define DHCPREQUEST 3 |
---|
387 | #define DHCPDECLINE 4 |
---|
388 | #define DHCPACK 5 |
---|
389 | #define DHCPNACK 6 |
---|
390 | #define DHCPRELEASE 7 |
---|
391 | #define DHCPINFORM 8 |
---|
392 | #define DHCPFORCERENEW 9 |
---|
393 | #define DHCPLEASEQUERY 10 |
---|
394 | #define DHCPLEASEUNASSIGNED 11 |
---|
395 | #define DHCPLEASEUNKNOWN 12 |
---|
396 | #define DHCPLEASEACTIVE 13 |
---|
397 | #define DHCPUNKNOWN 99 |
---|
398 | |
---|
399 | /* DHCPState (short) values: (upper bit set = bootp) |
---|
400 | */ |
---|
401 | #define DHCPSTATE_INITIALIZE 0x0001 |
---|
402 | #define DHCPSTATE_INITDELAY 0x0002 |
---|
403 | #define DHCPSTATE_SELECT 0x0003 |
---|
404 | #define DHCPSTATE_REQUEST 0x0004 |
---|
405 | #define DHCPSTATE_BOUND 0x0005 |
---|
406 | #define DHCPSTATE_RENEW 0x0006 |
---|
407 | #define DHCPSTATE_REBIND 0x0007 |
---|
408 | #define DHCPSTATE_NOTUSED 0x0008 |
---|
409 | #define DHCPSTATE_RESTART 0x0009 |
---|
410 | #define BOOTP_MODE 0x8000 |
---|
411 | #define BOOTPSTATE_INITIALIZE 0x8001 |
---|
412 | #define BOOTPSTATE_INITDELAY 0x8002 |
---|
413 | #define BOOTPSTATE_REQUEST 0x8003 |
---|
414 | #define BOOTPSTATE_RESTART 0x8004 |
---|
415 | #define BOOTPSTATE_COMPLETE 0x8005 |
---|
416 | |
---|
417 | /* DHCP Options |
---|
418 | */ |
---|
419 | #define DHCPOPT_SUBNETMASK 1 |
---|
420 | #define DHCPOPT_ROUTER 3 |
---|
421 | #define DHCPOPT_HOSTNAME 12 |
---|
422 | #define DHCPOPT_ROOTPATH 17 |
---|
423 | #define DHCPOPT_BROADCASTADDRESS 28 |
---|
424 | #define DHCPOPT_VENDORSPECIFICINFO 43 |
---|
425 | #define DHCPOPT_REQUESTEDIP 50 |
---|
426 | #define DHCPOPT_LEASETIME 51 |
---|
427 | #define DHCPOPT_MESSAGETYPE 53 |
---|
428 | #define DHCPOPT_SERVERID 54 |
---|
429 | #define DHCPOPT_PARMRQSTLIST 55 |
---|
430 | #define DHCPOPT_CLASSID 60 |
---|
431 | #define DHCPOPT_CLIENTID 61 |
---|
432 | #define DHCPOPT_NISDOMAINNAME 64 |
---|
433 | #define DHCPOPT_NISSERVER 65 |
---|
434 | |
---|
435 | #define STANDARD_MAGIC_COOKIE 0x63825363 /* 99.130.83.99 */ |
---|
436 | |
---|
437 | struct dhcphdr { |
---|
438 | unsigned char op; |
---|
439 | unsigned char htype; |
---|
440 | unsigned char hlen; |
---|
441 | unsigned char hops; |
---|
442 | unsigned long transaction_id; |
---|
443 | unsigned short seconds; |
---|
444 | unsigned short flags; |
---|
445 | unsigned long client_ip; |
---|
446 | unsigned long your_ip; |
---|
447 | unsigned long server_ip; |
---|
448 | unsigned long router_ip; |
---|
449 | unsigned char client_macaddr[16]; |
---|
450 | unsigned char server_hostname[64]; |
---|
451 | unsigned char bootfile[128]; |
---|
452 | unsigned long magic_cookie; |
---|
453 | /* Dhcp options would start here */ |
---|
454 | } __PACKED__ ; |
---|
455 | |
---|
456 | struct bootphdr { |
---|
457 | unsigned char op; |
---|
458 | unsigned char htype; |
---|
459 | unsigned char hlen; |
---|
460 | unsigned char hops; |
---|
461 | unsigned long transaction_id; |
---|
462 | unsigned short seconds; |
---|
463 | unsigned short unused; |
---|
464 | unsigned long client_ip; |
---|
465 | unsigned long your_ip; |
---|
466 | unsigned long server_ip; |
---|
467 | unsigned long router_ip; |
---|
468 | unsigned char client_macaddr[16]; |
---|
469 | unsigned char server_hostname[64]; |
---|
470 | unsigned char bootfile[128]; |
---|
471 | unsigned char vsa[64]; |
---|
472 | } __PACKED__ ; |
---|
473 | |
---|
474 | unsigned char *DhcpGetOption(unsigned char, unsigned char *); |
---|
475 | |
---|
476 | /************************************************************************ |
---|
477 | * |
---|
478 | * DNS stuff... |
---|
479 | * |
---|
480 | * The area of the dnshdr structure beginning with the question array |
---|
481 | * is actually a variable sized area for four sections: |
---|
482 | * question, answer, authority and additional information. |
---|
483 | * For the monitor's implementation of DNS, it is simplified to need |
---|
484 | * only the question section because we are only using this to do |
---|
485 | * a standard DNS query (give a domain name to a server and wait for |
---|
486 | * a response that has the IP address). |
---|
487 | * So, for the sake of building a fixed size structure, we allocate a |
---|
488 | * 64 byte question section and assume that no single domain name request |
---|
489 | * will exceed that length. |
---|
490 | * Note: first byte of domain name is the size. |
---|
491 | * |
---|
492 | * For MulticastDNS information I used... |
---|
493 | * http://files.multicastdns.org/draft-cheshire-dnsext-multicastdns.txt |
---|
494 | */ |
---|
495 | #define MAX_DOMAIN_NAME_SIZE 63 |
---|
496 | |
---|
497 | struct dnshdr { |
---|
498 | unsigned short id; |
---|
499 | unsigned short param; |
---|
500 | unsigned short num_questions; |
---|
501 | unsigned short num_answers; |
---|
502 | unsigned short num_authority; |
---|
503 | unsigned short num_additional; |
---|
504 | unsigned char question[MAX_DOMAIN_NAME_SIZE+1]; |
---|
505 | } __PACKED__ ; |
---|
506 | |
---|
507 | #define IPPORT_DNS 53 |
---|
508 | #define TYPE_A 1 |
---|
509 | #define TYPE_CNAME 5 |
---|
510 | #define CLASS_IN 1 |
---|
511 | |
---|
512 | /* DNS Error codes: |
---|
513 | */ |
---|
514 | #define DNSERR_NULL 0 |
---|
515 | #define DNSERR_COMPLETE 1 |
---|
516 | #define DNSERR_NOSRVR 2 |
---|
517 | #define DNSERR_SOCKETFAIL 3 |
---|
518 | #define DNSERR_FORMATERR 4 |
---|
519 | #define DNSERR_SRVRFAILURE 5 |
---|
520 | #define DNSERR_NAMENOEXIST 6 |
---|
521 | #define DNSERR_BADRESPTYPE 7 |
---|
522 | #define DNSERR_BADQSTNCOUNT 8 |
---|
523 | #define DNSERR_BADANSWRCOUNT 9 |
---|
524 | #define DNSERR_NOTARESPONSE 10 |
---|
525 | #define DNSERR_BADRESPID 11 |
---|
526 | |
---|
527 | #define DNSMCAST_IP IP2LONG(224,0,0,251) |
---|
528 | #define DNSMCAST_PORT 5353 |
---|
529 | |
---|
530 | /* DNS Buffer sizes: |
---|
531 | */ |
---|
532 | #define MAX_CACHED_HOSTNAMES 32 |
---|
533 | #define MAX_HOSTNAME_SIZE 255 |
---|
534 | |
---|
535 | #define DNS_RETRY_MAX 5 |
---|
536 | #define DNS_PKTBUF_SIZE 512 |
---|
537 | |
---|
538 | struct dnserr { |
---|
539 | int errno; |
---|
540 | char *errstr; |
---|
541 | }; |
---|
542 | |
---|
543 | struct dnscache { |
---|
544 | int idx; |
---|
545 | unsigned long addr; |
---|
546 | char name[MAX_HOSTNAME_SIZE+1]; |
---|
547 | }; |
---|
548 | |
---|
549 | extern const char mDNSIp[]; |
---|
550 | |
---|
551 | /************************************************************************ |
---|
552 | * |
---|
553 | * TCP stuff... |
---|
554 | * |
---|
555 | */ |
---|
556 | |
---|
557 | struct tcphdr { |
---|
558 | unsigned short sport; /* Source port */ |
---|
559 | unsigned short dport; /* Source port */ |
---|
560 | unsigned long seqno; /* Sequence number */ |
---|
561 | unsigned long ackno; /* Acknowledgment number */ |
---|
562 | unsigned short flags; /* Flags (lower 6 bits) */ |
---|
563 | unsigned short windowsize; /* Window size */ |
---|
564 | unsigned short tcpcsum; /* TCP checksum */ |
---|
565 | unsigned short urgentptr; /* Urgent pointer */ |
---|
566 | /* options (if any) & data (if any) follow */ |
---|
567 | } __PACKED__ ; |
---|
568 | |
---|
569 | /* Masks for flags (made up of flag bits, reserved bits & header length): |
---|
570 | */ |
---|
571 | #define TCP_FLAGMASK 0x003F |
---|
572 | #define TCP_RSVDMASK 0x0FC0 |
---|
573 | #define TCP_HDRLENMASK 0xF000 |
---|
574 | #define TCP_HLEN(tp) (((tp)->flags & TCP_HDRLENMASK) >> 10) |
---|
575 | |
---|
576 | /* Masks for flag bits within flags member: |
---|
577 | */ |
---|
578 | #define TCP_FINISH 0x0001 |
---|
579 | #define TCP_SYNC 0x0002 |
---|
580 | #define TCP_RESET 0x0004 |
---|
581 | #define TCP_PUSH 0x0008 |
---|
582 | #define TCP_ACK 0x0010 |
---|
583 | #define TCP_URGENT 0x0020 |
---|
584 | |
---|
585 | |
---|
586 | /************************************************************************ |
---|
587 | * |
---|
588 | * Miscellaneous... |
---|
589 | * |
---|
590 | */ |
---|
591 | |
---|
592 | /* Port that is used to issue monitor commands through ethernet. |
---|
593 | */ |
---|
594 | #define MONRESPSIZE (sizeof(struct ether_header) + sizeof(struct ip) + \ |
---|
595 | sizeof(struct Udphdr) + idx) |
---|
596 | #define IPPORT_MONCMD 777 |
---|
597 | #define IPPORT_GDB 1234 |
---|
598 | |
---|
599 | /* Verbosity levels used by various ethernet layers: |
---|
600 | */ |
---|
601 | #define SHOW_INCOMING 0x00000001 |
---|
602 | #define SHOW_OUTGOING 0x00000002 |
---|
603 | #define SHOW_HEX 0x00000004 |
---|
604 | #define SHOW_BROADCAST 0x00000008 |
---|
605 | #define SHOW_TFTP_TICKER 0x00000010 |
---|
606 | #define SHOW_DHCP 0x00000020 |
---|
607 | #define SHOW_ARP 0x00000040 |
---|
608 | #define SHOW_ASCII 0x00000080 |
---|
609 | #define SHOW_BADCSUM 0x00000100 |
---|
610 | #define SHOW_BADCSUMV 0x00000200 |
---|
611 | #define SHOW_PHY 0x00000400 |
---|
612 | #define SHOW_GDB 0x00000800 |
---|
613 | #define SHOW_TFTP_STATE 0x00001000 |
---|
614 | #define SHOW_DRIVER_DEBUG 0x00002000 |
---|
615 | #define SHOW_ALL 0xffffffff |
---|
616 | |
---|
617 | #define ENET_DEBUG_ENABLED() (EtherVerbose & SHOW_DRIVER_DEBUG) |
---|
618 | |
---|
619 | #define ETHER_INCOMING 1 |
---|
620 | #define ETHER_OUTGOING 2 |
---|
621 | |
---|
622 | extern char *Etheradd, *IPadd; |
---|
623 | extern unsigned char etheraddr[], ipaddr[]; |
---|
624 | extern unsigned short MoncmdPort, TftpPort, TftpSrcPort; |
---|
625 | extern unsigned short DhcpClientPort, DhcpServerPort, DHCPState; |
---|
626 | extern int EtherVerbose, IPMonCmdActive, EtherIsActive, EtherPollingOff; |
---|
627 | extern unsigned char BinEnetAddr[], BinIpAddr[]; |
---|
628 | extern unsigned char AllZeroAddr[], BroadcastAddr[]; |
---|
629 | extern int EtherXFRAMECnt, EtherRFRAMECnt, EtherIPERRCnt, EtherUDPERRCnt; |
---|
630 | |
---|
631 | extern int getAddresses(void); |
---|
632 | extern int IpToBin(char *,unsigned char *); |
---|
633 | extern int EtherToBin(char *,unsigned char *); |
---|
634 | extern char *extGetIpAdd(void), *extGetEtherAdd(void); |
---|
635 | extern char *IpToString(unsigned long, char *); |
---|
636 | extern char *EtherToString(unsigned char *,char *); |
---|
637 | extern unsigned short ipId(void); |
---|
638 | extern unsigned char *ArpEther(unsigned char *,unsigned char *,int); |
---|
639 | extern unsigned char *getXmitBuffer(void); |
---|
640 | extern unsigned char *EtherFromCache(unsigned char *); |
---|
641 | extern void ipChksum(struct ip *), udpChksum(struct ip *); |
---|
642 | extern void tcpChksum(struct ip *); |
---|
643 | #if INCLUDE_ETHERVERBOSE |
---|
644 | extern void printPkt(struct ether_header *,int,int); |
---|
645 | #else |
---|
646 | #define printPkt(a,b,c) |
---|
647 | #endif |
---|
648 | extern void DhcpBootpDone(int, struct dhcphdr *,int); |
---|
649 | extern void DhcpVendorSpecific(struct dhcphdr *); |
---|
650 | extern int sendBuffer(int); |
---|
651 | extern struct ether_header *EtherCopy(struct ether_header *); |
---|
652 | extern int ValidDHCPOffer(struct dhcphdr *); |
---|
653 | extern int buildDhcpHdr(struct dhcphdr *); |
---|
654 | extern int printDhcpVSopt(int,int,char *); |
---|
655 | extern int RetransmitDelay(int); |
---|
656 | extern int tftpGet(unsigned long,char *,char *,char *,char *,char *,char *); |
---|
657 | extern void printDhcp(struct Udphdr *); |
---|
658 | extern int printIp(struct ip*); |
---|
659 | extern int printUdp(struct Udphdr *,char *); |
---|
660 | extern int printIgmp(struct Igmphdr *,char *); |
---|
661 | extern void processPACKET(struct ether_header *,unsigned short); |
---|
662 | extern void processTCP(struct ether_header *,unsigned short); |
---|
663 | extern int processTFTP(struct ether_header *,unsigned short); |
---|
664 | extern int processICMP(struct ether_header *,unsigned short); |
---|
665 | extern char *processARP(struct ether_header *,unsigned short); |
---|
666 | extern int processDHCP(struct ether_header *,unsigned short); |
---|
667 | extern int processRARP(struct ether_header *,unsigned short); |
---|
668 | extern int processGDB(struct ether_header *,unsigned short); |
---|
669 | extern int processDNS(struct ether_header *,unsigned short); |
---|
670 | extern int processMCASTDNS(struct ether_header *,unsigned short); |
---|
671 | extern int SendICMPUnreachable(struct ether_header *,unsigned char); |
---|
672 | extern void enresetmmu(void), enreset(void); |
---|
673 | extern void ShowEtherdevStats(void), ShowTftpStats(void), ShowDhcpStats(void); |
---|
674 | extern void enablePromiscuousReception(void); |
---|
675 | extern void disablePromiscuousReception(void); |
---|
676 | extern int enselftest(int), polletherdev(void), EtherdevStartup(int); |
---|
677 | extern void DisableEtherdev(void); |
---|
678 | extern void tftpStateCheck(void), dhcpStateCheck(void); |
---|
679 | extern int DhcpIPCheck(char *); |
---|
680 | extern void dhcpDisable(void); |
---|
681 | extern void tftpInit(void); |
---|
682 | extern void disableBroadcastReception(void); |
---|
683 | extern void enableBroadcastReception(void); |
---|
684 | extern void sendGratuitousArp(void); |
---|
685 | |
---|
686 | extern unsigned long getHostAddr(char *); |
---|
687 | extern int dnsCacheDelName(char *); |
---|
688 | extern void dnsCacheInit(void); |
---|
689 | extern int dnsCacheAdd(char *, unsigned long); |
---|
690 | extern int dnsCacheDelAddr(unsigned long); |
---|
691 | extern short DnsPort; |
---|
692 | |
---|
693 | #if INCLUDE_ETHERNET |
---|
694 | extern int pollethernet(void); |
---|
695 | extern int EthernetStartup(int,int); |
---|
696 | #else |
---|
697 | #define pollethernet() |
---|
698 | #define EthernetStartup(a,b) |
---|
699 | #endif |
---|
700 | |
---|
701 | #if INCLUDE_MONCMD |
---|
702 | extern int SendIPMonChar(unsigned char,int); |
---|
703 | #else |
---|
704 | #define SendIPMonChar(a,b) |
---|
705 | #endif |
---|
706 | |
---|
707 | extern int DisableEthernet(void); |
---|
708 | extern void storeMac(int); |
---|
709 | extern void GetBinNetMask(unsigned char *binnetmask); |
---|
710 | extern int monSendEnetPkt(char *pkt, int cnt); |
---|
711 | extern int monRecvEnetPkt(char *pkt, int cnt); |
---|
712 | extern void AppPrintPkt(char *buf, int size, int incoming); |
---|
713 | |
---|
714 | #endif |
---|