Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

decode.h

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 /* $Id$ */
00020 
00021 
00022 #ifndef __DECODE_H__
00023 #define __DECODE_H__
00024 
00025 
00026 /*  I N C L U D E S  **********************************************************/
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include "config.h"
00030 #endif
00031 
00032 #include <sys/types.h>
00033 #include <pcap.h>
00034 
00035 #ifndef WIN32
00036 #include <sys/socket.h>
00037 #include <netinet/in.h>
00038 #include <net/if.h>
00039 #else /* !WIN32 */
00040 #include <netinet/in_systm.h>
00041 #include "libnet/IPExport.h"
00042 #ifndef IFNAMSIZ
00043 #define IFNAMESIZ MAX_ADAPTER_NAME
00044 #endif /* !IFNAMSIZ */
00045 #endif /* !WIN32 */
00046 //#include "ubi_SplayTree.h"
00047 #include "stream.h"
00048 
00049 
00050 /*  D E F I N E S  ************************************************************/
00051 #define ETHERNET_MTU                  1500
00052 #define ETHERNET_TYPE_IP              0x0800
00053 #define ETHERNET_TYPE_ARP             0x0806
00054 #define ETHERNET_TYPE_REVARP          0x8035
00055 #define ETHERNET_TYPE_EAPOL           0x888e
00056 #define ETHERNET_TYPE_IPV6            0x86dd
00057 #define ETHERNET_TYPE_IPX             0x8137
00058 #define ETHERNET_TYPE_PPPoE_DISC      0x8863 /* discovery stage */
00059 #define ETHERNET_TYPE_PPPoE_SESS      0x8864 /* session stage */
00060 #define ETHERNET_TYPE_8021Q           0x8100
00061 #define ETHERNET_TYPE_LOOP            0x9000
00062 
00063 #define ETH_DSAP_SNA                  0x08    /* SNA */
00064 #define ETH_SSAP_SNA                  0x00    /* SNA */
00065 #define ETH_DSAP_STP                  0x42    /* Spanning Tree Protocol */
00066 #define ETH_SSAP_STP                  0x42    /* Spanning Tree Protocol */
00067 #define ETH_DSAP_IP                   0xaa    /* IP */
00068 #define ETH_SSAP_IP                   0xaa    /* IP */
00069 
00070 #define ETH_ORG_CODE_ETHR              0x000000    /* Encapsulated Ethernet */
00071 #define ETH_ORG_CODE_CDP               0x00000c    /* Cisco Discovery Proto */
00072 
00073 #define ETHERNET_HEADER_LEN             14
00074 #define ETHERNET_MAX_LEN_ENCAP          1518    /* 802.3 (+LLC) or ether II ? */
00075 #define PPPOE_HEADER_LEN                20    /* ETHERNET_HEADER_LEN + 6 */
00076 #define MINIMAL_TOKENRING_HEADER_LEN    22
00077 #define MINIMAL_IEEE80211_HEADER_LEN    10    /* Ack frames and others */
00078 #define IEEE802_11_DATA_HDR_LEN         24    /* Header for data packets */
00079 #define TR_HLEN                         MINIMAL_TOKENRING_HEADER_LEN
00080 #define TOKENRING_LLC_LEN                8
00081 #define SLIP_HEADER_LEN                 16
00082 
00083 /* Frame type/subype combinations with version = 0 */
00084         /*** FRAME TYPE *****  HEX ****  SUBTYPE TYPE  DESCRIPT ********/
00085 #define WLAN_TYPE_MGMT_ASREQ   0x0      /* 0000    00  Association Req */
00086 #define WLAN_TYPE_MGMT_ASRES   0x10     /* 0001    00  Assocaition Res */
00087 #define WLAN_TYPE_MGMT_REREQ   0x20     /* 0010    00  Reassoc. Req.   */
00088 #define WLAN_TYPE_MGMT_RERES   0x30     /* 0011    00  Reassoc. Resp.  */
00089 #define WLAN_TYPE_MGMT_PRREQ   0x40     /* 0100    00  Probe Request   */
00090 #define WLAN_TYPE_MGMT_PRRES   0x50     /* 0101    00  Probe Response  */ 
00091 #define WLAN_TYPE_MGMT_BEACON  0x80     /* 1000    00  Beacon          */
00092 #define WLAN_TYPE_MGMT_ATIM    0x90     /* 1001    00  ATIM message    */
00093 #define WLAN_TYPE_MGMT_DIS     0xa0     /* 1010    00  Disassociation  */
00094 #define WLAN_TYPE_MGMT_AUTH    0xb0     /* 1011    00  Authentication  */
00095 #define WLAN_TYPE_MGMT_DEAUTH  0xc0     /* 1100    00  Deauthentication*/
00096 
00097 #define WLAN_TYPE_CONT_PS      0xa4     /* 1010    01  Power Save      */
00098 #define WLAN_TYPE_CONT_RTS     0xb4     /* 1011    01  Request to send */
00099 #define WLAN_TYPE_CONT_CTS     0xc4     /* 1100    01  Clear to sene   */
00100 #define WLAN_TYPE_CONT_ACK     0xd4     /* 1101    01  Acknowledgement */
00101 #define WLAN_TYPE_CONT_CFE     0xe4     /* 1110    01  Cont. Free end  */
00102 #define WLAN_TYPE_CONT_CFACK   0xf4     /* 1111    01  CF-End + CF-Ack */
00103 
00104 #define WLAN_TYPE_DATA_DATA    0x08     /* 0000    10  Data            */
00105 #define WLAN_TYPE_DATA_DTCFACK 0x18     /* 0001    10  Data + CF-Ack   */
00106 #define WLAN_TYPE_DATA_DTCFPL  0x28     /* 0010    10  Data + CF-Poll  */
00107 #define WLAN_TYPE_DATA_DTACKPL 0x38     /* 0011    10  Data+CF-Ack+CF-Pl */
00108 #define WLAN_TYPE_DATA_NULL    0x48     /* 0100    10  Null (no data)  */
00109 #define WLAN_TYPE_DATA_CFACK   0x58     /* 0101    10  CF-Ack (no data)*/
00110 #define WLAN_TYPE_DATA_CFPL    0x68     /* 0110    10  CF-Poll (no data)*/
00111 #define WLAN_TYPE_DATA_ACKPL   0x78     /* 0111    10  CF-Ack+CF-Poll  */
00112 
00113 /*** Flags for IEEE 802.11 Frame Control ***/
00114 /* The following are designed to be bitwise-AND-d in an 8-bit u_char */
00115 #define WLAN_FLAG_TODS      0x0100    /* To DS Flag   10000000 */
00116 #define WLAN_FLAG_FROMDS    0x0200    /* From DS Flag 01000000 */
00117 #define WLAN_FLAG_FRAG      0x0400    /* More Frag    00100000 */
00118 #define WLAN_FLAG_RETRY     0x0800    /* Retry Flag   00010000 */
00119 #define WLAN_FLAG_PWRMGMT   0x1000    /* Power Mgmt.  00001000 */
00120 #define WLAN_FLAG_MOREDAT   0x2000    /* More Data    00000100 */
00121 #define WLAN_FLAG_WEP       0x4000    /* Wep Enabled  00000010 */
00122 #define WLAN_FLAG_ORDER     0x8000    /* Strict Order 00000001 */
00123 
00124 /* IEEE 802.1x eapol types */
00125 #define EAPOL_TYPE_EAP      0x00      /* EAP packet */
00126 #define EAPOL_TYPE_START    0x01      /* EAPOL start */
00127 #define EAPOL_TYPE_LOGOFF   0x02      /* EAPOL Logoff */
00128 #define EAPOL_TYPE_KEY      0x03      /* EAPOL Key */
00129 #define EAPOL_TYPE_ASF      0x04      /* EAPOL Encapsulated ASF-Alert */
00130 
00131 /* Extensible Authentication Protocol Codes RFC 2284*/
00132 #define EAP_CODE_REQUEST    0x01   
00133 #define EAP_CODE_RESPONSE   0x02
00134 #define EAP_CODE_SUCCESS    0x03
00135 #define EAP_CODE_FAILURE    0x04
00136 /* EAP Types */
00137 #define EAP_TYPE_IDENTITY   0x01
00138 #define EAP_TYPE_NOTIFY     0x02
00139 #define EAP_TYPE_NAK        0x03
00140 #define EAP_TYPE_MD5        0x04
00141 #define EAP_TYPE_OTP        0x05
00142 #define EAP_TYPE_GTC        0x06
00143 #define EAP_TYPE_TLS        0x0d
00144 
00145 /* Cisco HDLC header values */
00146 #define CHDLC_HEADER_LEN        4
00147 #define CHDLC_ADDR_UNICAST      0x0f
00148 #define CHDLC_ADDR_MULTICAST    0x8f
00149 #define CHDLC_ADDR_BROADCAST    0xff
00150 #define CHDLC_CTRL_UNNUMBERED   0x03
00151 
00152 /* ppp header structure
00153  *
00154  * Actually, this is the header for RFC1332 Section 3
00155  * IPCP Configuration Options for sending IP datagrams over a PPP link
00156  *
00157  */
00158 struct ppp_header {
00159     unsigned char  address;
00160     unsigned char  control;
00161     unsigned short protocol;
00162 };
00163 
00164 #ifndef PPP_HDRLEN
00165     #define PPP_HDRLEN          sizeof(struct ppp_header)
00166 #endif
00167 
00168 #define PPP_IP         0x0021        /* Internet Protocol */
00169 #define PPP_VJ_COMP    0x002d        /* VJ compressed TCP/IP */
00170 #define PPP_VJ_UCOMP   0x002f        /* VJ uncompressed TCP/IP */
00171 #define PPP_IPX        0x002b        /* Novell IPX Protocol */
00172 
00173 /* otherwise defined in /usr/include/ppp_defs.h */
00174 #ifndef PPP_MTU
00175     #define PPP_MTU                 1500
00176 #endif
00177 
00178 /* NULL aka LoopBack interfaces */
00179 #define NULL_HDRLEN             4
00180 
00181 /* enc interface */
00182 struct enc_header {
00183     u_int32_t af;
00184     u_int32_t spi;
00185     u_int32_t flags;
00186 };
00187 #define ENC_HEADER_LEN          12
00188 
00189 /* otherwise defined in /usr/include/ppp_defs.h */
00190 #define IP_HEADER_LEN           20
00191 #define TCP_HEADER_LEN          20
00192 #define UDP_HEADER_LEN          8
00193 #define ICMP_HEADER_LEN         4
00194 
00195 #define IP_OPTMAX               40
00196 #define TCP_OPTLENMAX           40 /* (((2^4) - 1) * 4  - TCP_HEADER_LEN) */
00197 
00198 #ifndef IP_MAXPACKET
00199 #define IP_MAXPACKET    65535        /* maximum packet size */
00200 #endif /* IP_MAXPACKET */
00201 
00202 #define TH_FIN  0x01
00203 #define TH_SYN  0x02
00204 #define TH_RST  0x04
00205 #define TH_PUSH 0x08
00206 #define TH_ACK  0x10
00207 #define TH_URG  0x20
00208 #define TH_RES2 0x40
00209 #define TH_RES1 0x80
00210 #define TH_NORESERVED (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG)
00211 
00212 /* http://www.iana.org/assignments/tcp-parameters
00213  *
00214  * tcp options stuff. used to be in <netinet/tcp.h> but it breaks
00215  * things on AIX
00216  */
00217 #define TCPOPT_EOL              0   /* End of Option List [RFC793] */
00218 #define TCPOLEN_EOL             1   /* Always one byte */
00219 
00220 #define TCPOPT_NOP              1   /* No-Option [RFC793] */
00221 #define TCPOLEN_NOP             1   /* Always one byte */
00222 
00223 #define TCPOPT_MAXSEG           2   /* Maximum Segment Size [RFC793] */
00224 #define TCPOLEN_MAXSEG          4   /* Always 4 bytes */
00225 
00226 #define TCPOPT_WSCALE           3   /* Window scaling option [RFC1323] */
00227 #define TCPOLEN_WSCALE          3   /* 1 byte with logarithmic values */
00228 
00229 #define TCPOPT_SACKOK           4    /* Experimental [RFC2018]*/
00230 #define TCPOLEN_SACKOK          2
00231 
00232 #define TCPOPT_SACK             5    /* Experimental [RFC2018] variable length */
00233 
00234 #define TCPOPT_ECHO             6    /* Echo (obsoleted by option 8)      [RFC1072] */
00235 #define TCPOLEN_ECHO            6    /* 6 bytes  */
00236 
00237 #define TCPOPT_ECHOREPLY        7    /* Echo Reply (obsoleted by option 8)[RFC1072] */
00238 #define TCPOLEN_ECHOREPLY       6    /* 6 bytes  */
00239 
00240 #define TCPOPT_TIMESTAMP        8   /* Timestamp [RFC1323], 10 bytes */
00241 #define TCPOLEN_TIMESTAMP       10
00242 
00243 #define TCPOPT_PARTIAL_PERM     9   /* Partial Order Permitted/ Experimental [RFC1693] */
00244 #define TCPOLEN_PARTIAL_PERM    2   /* Partial Order Permitted/ Experimental [RFC1693] */
00245 
00246 #define TCPOPT_PARTIAL_SVC      10  /*  Partial Order Profile [RFC1693] */
00247 #define TCPOLEN_PARTIAL_SVC     3   /*  3 bytes long -- Experimental */
00248 
00249 /* atleast decode T/TCP options... */
00250 #define TCPOPT_CC               11  /*  T/TCP Connection count  [RFC1644] */
00251 #define TCPOPT_CC_NEW           12  /*  CC.NEW [RFC1644] */
00252 #define TCPOPT_CC_ECHO          13  /*  CC.ECHO [RFC1644] */
00253 #define TCPOLEN_CC             6  /* page 17 of rfc1644 */
00254 #define TCPOLEN_CC_NEW         6  /* page 17 of rfc1644 */
00255 #define TCPOLEN_CC_ECHO        6  /* page 17 of rfc1644 */
00256 
00257 #define TCPOPT_ALTCSUM          15  /* TCP Alternate Checksum Data [RFC1146], variable length */
00258 #define TCPOPT_SKEETER          16  /* Skeeter [Knowles] */
00259 #define TCPOPT_BUBBA            17  /* Bubba   [Knowles] */
00260 
00261 #define TCPOPT_TRAILER_CSUM     18  /* Trailer Checksum Option [Subbu & Monroe] */
00262 #define TCPOLEN_TRAILER_CSUM  3  
00263 
00264 #define TCPOPT_MD5SIG           19  /* MD5 Signature Option [RFC2385] */
00265 #define TCPOLEN_MD5SIG        18
00266 
00267 /* Space Communications Protocol Standardization */
00268 #define TCPOPT_SCPS             20  /* Capabilities [Scott] */
00269 #define TCPOPT_SELNEGACK        21  /* Selective Negative Acknowledgements [Scott] */
00270 #define TCPOPT_RECORDBOUND         22  /* Record Boundaries [Scott] */
00271 #define TCPOPT_CORRUPTION          23  /* Corruption experienced [Scott] */
00272 
00273 #define TCPOPT_SNAP                24  /* SNAP [Sukonnik] -- anyone have info?*/
00274 #define TCPOPT_UNASSIGNED          25  /* Unassigned (released 12/18/00) */
00275 #define TCPOPT_COMPRESSION         26  /* TCP Compression Filter [Bellovin] */
00276 /* http://www.research.att.com/~smb/papers/draft-bellovin-tcpcomp-00.txt*/
00277 
00278 #define TCP_OPT_TRUNC -1
00279 #define TCP_OPT_BADLEN -2
00280 
00281 /* Why are these lil buggers here? Never Used. -- cmg */
00282 #define TCPOLEN_TSTAMP_APPA     (TCPOLEN_TIMESTAMP+2)    /* appendix A / rfc 1323 */
00283 #define TCPOPT_TSTAMP_HDR    \
00284     (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
00285 
00286 /*
00287  * Default maximum segment size for TCP.
00288  * With an IP MSS of 576, this is 536,
00289  * but 512 is probably more convenient.
00290  * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
00291  */
00292 
00293 #ifndef TCP_MSS
00294     #define    TCP_MSS      512
00295 #endif
00296 
00297 #ifndef TCP_MAXWIN
00298     #define    TCP_MAXWIN   65535    /* largest value for (unscaled) window */
00299 #endif
00300 
00301 #ifndef TCP_MAX_WINSHIFT 
00302     #define TCP_MAX_WINSHIFT    14    /* maximum window shift */
00303 #endif
00304 
00305 /*
00306  * User-settable options (used with setsockopt).
00307  */
00308 #ifndef TCP_NODELAY
00309     #define    TCP_NODELAY   0x01    /* don't delay send to coalesce packets */
00310 #endif
00311 
00312 #ifndef TCP_MAXSEG
00313     #define    TCP_MAXSEG    0x02    /* set maximum segment size */
00314 #endif
00315 
00316 #define SOL_TCP        6    /* TCP level */
00317 
00318 
00319 
00320 #define L2TP_PORT           1701
00321 #define DHCP_CLIENT_PORT    68
00322 #define DHCP_SERVER_PORT    67
00323 
00324 /* IRIX 6.2 hack! */
00325 #ifndef IRIX
00326     #define SNAPLEN         1514
00327 #else
00328     #define SNAPLEN         1500
00329 #endif
00330 
00331 #define MIN_SNAPLEN         68
00332 #define PROMISC             1
00333 #define READ_TIMEOUT        500
00334 
00335 /* Start Token Ring */
00336 #define TR_ALEN             6        /* octets in an Ethernet header */
00337 #define IPARP_SAP           0xaa
00338 
00339 #define AC                  0x10
00340 #define LLC_FRAME           0x40
00341 
00342 #define TRMTU                      2000    /* 2000 bytes            */
00343 #define TR_RII                     0x80
00344 #define TR_RCF_DIR_BIT             0x80
00345 #define TR_RCF_LEN_MASK            0x1f00
00346 #define TR_RCF_BROADCAST           0x8000    /* all-routes broadcast   */
00347 #define TR_RCF_LIMITED_BROADCAST   0xC000    /* single-route broadcast */
00348 #define TR_RCF_FRAME2K             0x20
00349 #define TR_RCF_BROADCAST_MASK      0xC000
00350 /* End Token Ring */
00351 
00352 /* Start FDDI */
00353 #define FDDI_ALLC_LEN                   13
00354 #define FDDI_ALEN                       6
00355 #define FDDI_MIN_HLEN                   (FDDI_ALLC_LEN + 3)
00356 
00357 #define FDDI_DSAP_SNA                   0x08    /* SNA */
00358 #define FDDI_SSAP_SNA                   0x00    /* SNA */
00359 #define FDDI_DSAP_STP                   0x42    /* Spanning Tree Protocol */
00360 #define FDDI_SSAP_STP                   0x42    /* Spanning Tree Protocol */
00361 #define FDDI_DSAP_IP                    0xaa    /* IP */
00362 #define FDDI_SSAP_IP                    0xaa    /* IP */
00363 
00364 #define FDDI_ORG_CODE_ETHR              0x000000    /* Encapsulated Ethernet */
00365 #define FDDI_ORG_CODE_CDP               0x00000c    /* Cisco Discovery
00366                              * Proto(?) */
00367 
00368 #define ETHERNET_TYPE_CDP               0x2000    /* Cisco Discovery Protocol */
00369 /* End FDDI */
00370 
00371 #define ARPOP_REQUEST   1    /* ARP request                  */
00372 #define ARPOP_REPLY     2    /* ARP reply                    */
00373 #define ARPOP_RREQUEST  3    /* RARP request                 */
00374 #define ARPOP_RREPLY    4    /* RARP reply                   */
00375 
00376 /* PPPoE types */
00377 #define PPPoE_CODE_SESS 0x00 /* PPPoE session */
00378 #define PPPoE_CODE_PADI 0x09 /* PPPoE Active Discovery Initiation */
00379 #define PPPoE_CODE_PADO 0x07 /* PPPoE Active Discovery Offer */
00380 #define PPPoE_CODE_PADR 0x19 /* PPPoE Active Discovery Request */
00381 #define PPPoE_CODE_PADS 0x65 /* PPPoE Active Discovery Session-confirmation */
00382 #define PPPoE_CODE_PADT 0xa7 /* PPPoE Active Discovery Terminate */
00383 
00384 /* PPPoE tag types */
00385 #define PPPoE_TAG_END_OF_LIST        0x0000
00386 #define PPPoE_TAG_SERVICE_NAME       0x0101
00387 #define PPPoE_TAG_AC_NAME            0x0102
00388 #define PPPoE_TAG_HOST_UNIQ          0x0103
00389 #define PPPoE_TAG_AC_COOKIE          0x0104
00390 #define PPPoE_TAG_VENDOR_SPECIFIC    0x0105
00391 #define PPPoE_TAG_RELAY_SESSION_ID   0x0110
00392 #define PPPoE_TAG_SERVICE_NAME_ERROR 0x0201
00393 #define PPPoE_TAG_AC_SYSTEM_ERROR    0x0202
00394 #define PPPoE_TAG_GENERIC_ERROR      0x0203
00395 
00396 
00397 #define ICMP_ECHOREPLY          0    /* Echo Reply                   */
00398 #define ICMP_DEST_UNREACH       3    /* Destination Unreachable      */
00399 #define ICMP_SOURCE_QUENCH      4    /* Source Quench                */
00400 #define ICMP_REDIRECT           5    /* Redirect (change route)      */
00401 #define ICMP_ECHO               8    /* Echo Request                 */
00402 #define ICMP_ROUTER_ADVERTISE   9    /* Router Advertisement         */
00403 #define ICMP_ROUTER_SOLICIT     10    /* Router Solicitation          */
00404 #define ICMP_TIME_EXCEEDED      11    /* Time Exceeded                */
00405 #define ICMP_PARAMETERPROB      12    /* Parameter Problem            */
00406 #define ICMP_TIMESTAMP          13    /* Timestamp Request            */
00407 #define ICMP_TIMESTAMPREPLY     14    /* Timestamp Reply              */
00408 #define ICMP_INFO_REQUEST       15    /* Information Request          */
00409 #define ICMP_INFO_REPLY         16    /* Information Reply            */
00410 #define ICMP_ADDRESS            17    /* Address Mask Request         */
00411 #define ICMP_ADDRESSREPLY       18    /* Address Mask Reply           */
00412 #define NR_ICMP_TYPES           18
00413 
00414 /* Codes for ICMP UNREACHABLES */
00415 #define ICMP_NET_UNREACH        0    /* Network Unreachable          */
00416 #define ICMP_HOST_UNREACH       1    /* Host Unreachable             */
00417 #define ICMP_PROT_UNREACH       2    /* Protocol Unreachable         */
00418 #define ICMP_PORT_UNREACH       3    /* Port Unreachable             */
00419 #define ICMP_FRAG_NEEDED        4    /* Fragmentation Needed/DF set  */
00420 #define ICMP_SR_FAILED          5    /* Source Route failed          */
00421 #define ICMP_NET_UNKNOWN        6
00422 #define ICMP_HOST_UNKNOWN       7
00423 #define ICMP_HOST_ISOLATED      8
00424 #define ICMP_PKT_FILTERED_NET   9
00425 #define ICMP_PKT_FILTERED_HOST  10
00426 #define ICMP_NET_UNR_TOS        11
00427 #define ICMP_HOST_UNR_TOS       12
00428 #define ICMP_PKT_FILTERED       13    /* Packet filtered */
00429 #define ICMP_PREC_VIOLATION     14    /* Precedence violation */
00430 #define ICMP_PREC_CUTOFF        15    /* Precedence cut off */
00431 #define NR_ICMP_UNREACH         15    /* instead of hardcoding immediate
00432                                        * value */
00433 
00434 #define ICMP_REDIR_NET          0
00435 #define ICMP_REDIR_HOST         1
00436 #define ICMP_REDIR_TOS_NET      2
00437 #define ICMP_REDIR_TOS_HOST     3
00438 
00439 #define ICMP_TIMEOUT_TRANSIT    0
00440 #define ICMP_TIMEOUT_REASSY     1
00441 
00442 #define ICMP_PARAM_BADIPHDR     0
00443 #define ICMP_PARAM_OPTMISSING   1
00444 #define ICMP_PARAM_BAD_LENGTH   2
00445 
00446 /* ip option type codes */
00447 #ifndef IPOPT_EOL
00448     #define IPOPT_EOL            0x00
00449 #endif
00450 
00451 #ifndef IPOPT_NOP
00452     #define IPOPT_NOP            0x01
00453 #endif
00454 
00455 #ifndef IPOPT_RR
00456     #define IPOPT_RR             0x07
00457 #endif
00458 
00459 #ifndef IPOPT_RTRALT
00460     #define IPOPT_RTRALT         0x14
00461 #endif
00462 
00463 #ifndef IPOPT_TS
00464     #define IPOPT_TS             0x44
00465 #endif
00466 
00467 #ifndef IPOPT_SECURITY
00468     #define IPOPT_SECURITY       0x82
00469 #endif
00470 
00471 #ifndef IPOPT_LSRR
00472     #define IPOPT_LSRR           0x83
00473 #endif
00474 
00475 #ifndef IPOPT_LSRR_E
00476     #define IPOPT_LSRR_E         0x84
00477 #endif
00478 
00479 #ifndef IPOPT_SATID
00480     #define IPOPT_SATID          0x88
00481 #endif
00482 
00483 #ifndef IPOPT_SSRR
00484     #define IPOPT_SSRR           0x89
00485 #endif
00486 
00487 
00488 
00489 /* tcp option codes */
00490 #define TOPT_EOL                0x00
00491 #define TOPT_NOP                0x01
00492 #define TOPT_MSS                0x02
00493 #define TOPT_WS                 0x03
00494 #define TOPT_TS                 0x08
00495 #ifndef TCPOPT_WSCALE
00496     #define TCPOPT_WSCALE           3     /* window scale factor (rfc1072) */
00497 #endif
00498 #ifndef TCPOPT_SACKOK
00499     #define    TCPOPT_SACKOK        4     /* selective ack ok (rfc1072) */
00500 #endif
00501 #ifndef TCPOPT_SACK
00502     #define    TCPOPT_SACK          5     /* selective ack (rfc1072) */
00503 #endif
00504 #ifndef TCPOPT_ECHO
00505     #define TCPOPT_ECHO             6     /* echo (rfc1072) */
00506 #endif
00507 #ifndef TCPOPT_ECHOREPLY
00508     #define TCPOPT_ECHOREPLY        7     /* echo (rfc1072) */
00509 #endif
00510 #ifndef TCPOPT_TIMESTAMP
00511     #define TCPOPT_TIMESTAMP        8     /* timestamps (rfc1323) */
00512 #endif
00513 #ifndef TCPOPT_CC
00514     #define TCPOPT_CC               11    /* T/TCP CC options (rfc1644) */
00515 #endif
00516 #ifndef TCPOPT_CCNEW
00517     #define TCPOPT_CCNEW            12    /* T/TCP CC options (rfc1644) */
00518 #endif
00519 #ifndef TCPOPT_CCECHO
00520     #define TCPOPT_CCECHO           13    /* T/TCP CC options (rfc1644) */
00521 #endif
00522 
00523 #define EXTRACT_16BITS(p) ((u_short) ntohs (*(u_short *)(p)))
00524 
00525 #ifdef WORDS_MUSTALIGN
00526 
00527 #if defined(__GNUC__)
00528 /* force word-aligned ntohl parameter */
00529     #define EXTRACT_32BITS(p)  ({ u_int32_t __tmp; memmove(&__tmp, (p), sizeof(u_int32_t)); (u_int32_t) ntohl(__tmp);})
00530 #endif /* __GNUC__ */
00531 
00532 #else
00533 
00534 /* allows unaligned ntohl parameter - dies w/SIGBUS on SPARCs */
00535     #define EXTRACT_32BITS(p) ((u_int32_t) ntohl (*(u_int32_t *)(p)))
00536 
00537 #endif                /* WORDS_MUSTALIGN */
00538 
00539 /* packet status flags */
00540 #define PKT_REBUILT_FRAG     0x00000001  /* is a rebuilt fragment */
00541 #define PKT_REBUILT_STREAM   0x00000002  /* is a rebuilt stream */
00542 #define PKT_STREAM_UNEST_UNI 0x00000004  /* is from an unestablished stream and
00543                                           * we've only seen traffic in one
00544                                           * direction
00545                                           */
00546 #define PKT_STREAM_UNEST_BI  0x00000008  /* is from an unestablished stream and
00547                                           * we've seen traffic in both 
00548                                           * directions
00549                                           */
00550 #define PKT_STREAM_EST       0x00000010  /* is from an established stream */
00551 #define PKT_ECN              0x00000020  /* this is ECN traffic */
00552 #define PKT_FROM_SERVER      0x00000040  /* this packet came from the server
00553                                             side of a connection (TCP) */
00554 #define PKT_FROM_CLIENT      0x00000080  /* this packet came from the client
00555                                             side of a connection (TCP) */
00556 #define PKT_HTTP_DECODE      0x00000100  /* this packet has normalized http */
00557 #define PKT_FRAG_ALERTED     0x00000200  /* this packet has been alerted by 
00558                                             defrag */
00559 #define PKT_STREAM_INSERT    0x00000400  /* this packet has been inserted into stream4 */
00560 #define PKT_ALT_DECODE       0x00000800  /* this packet has been normalized by telnet
00561                                              (only set when we must look at an alernative buffer)
00562                                          */
00563 #define PKT_STREAM_TWH       0x00001000
00564 #define PKT_IGNORE_PORT      0x00002000  /* this packet should be ignored, based on port */
00565 #define PKT_INLINE_DROP      0x20000000
00566 #define PKT_OBFUSCATED       0x40000000  /* this packet has been obfuscated */
00567 #define PKT_LOGGED           0x80000000  /* this packet has been logged */
00568 /*  D A T A  S T R U C T U R E S  *********************************************/
00569 
00570 /* Start Token Ring Data Structures */
00571 
00572 
00573 #ifdef _MSC_VER
00574     /* Visual C++ pragma to disable warning messages about nonstandard bit field type */
00575     #pragma warning( disable : 4214 )  
00576 #endif
00577 
00578 /* LLC structure */
00579 typedef struct _Trh_llc
00580 {
00581     u_int8_t dsap;
00582     u_int8_t ssap;
00583     u_int8_t protid[3];
00584     u_int16_t ethertype;
00585 }        Trh_llc;
00586 
00587 /* RIF structure
00588  * Linux/tcpdump patch defines tokenring header in dump way, since not
00589  * every tokenring header with have RIF data... we define it separately, and
00590  * a bit more split up
00591  */
00592 
00593 #ifdef _MSC_VER
00594   /* Visual C++ pragma to disable warning messages about nonstandard bit field type */
00595   #pragma warning( disable : 4214 )  
00596 #endif
00597 
00598 
00599 /* These are macros to use the bitlevel accesses in the Trh_Mr header
00600 
00601    they haven't been tested and they aren't used much so here is a
00602    listing of what used to be there
00603 
00604    #if defined(WORDS_BIGENDIAN)
00605       u_int16_t bcast:3, len:5, dir:1, lf:3, res:4;
00606    #else
00607       u_int16_t len:5,         length of RIF field, including RC itself
00608       bcast:3,       broadcast indicator 
00609       res:4,         reserved 
00610       lf:3,      largest frame size 
00611       dir:1;         direction
00612 */
00613 
00614 #define TRH_MR_BCAST(trhmr)  ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0xe000) >> 13)
00615 #define TRH_MR_LEN(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x1F00) >> 8)
00616 #define TRH_MR_DIR(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0080) >> 8)
00617 #define TRH_MR_LF(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0070) >> 7)
00618 #define TRH_MR_RES(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x000F))
00619 
00620 typedef struct _Trh_mr
00621 {
00622     u_int16_t bcast_len_dir_lf_res; /* broadcast/res/framesize/direction */
00623     u_int16_t rseg[8];
00624 }       Trh_mr;
00625 #ifdef _MSC_VER
00626   /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
00627   #pragma warning( default : 4214 )
00628 #endif
00629 
00630 
00631 typedef struct _Trh_hdr
00632 {
00633     u_int8_t ac;        /* access control field */
00634     u_int8_t fc;        /* frame control field */
00635     u_int8_t daddr[TR_ALEN];    /* src address */
00636     u_int8_t saddr[TR_ALEN];    /* dst address */
00637 }        Trh_hdr;
00638 
00639 #ifdef WIN32
00640     /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
00641     #pragma warning( default : 4214 )
00642 #endif
00643 /* End Token Ring Data Structures */
00644 
00645 
00646 /* Start FDDI Data Structures */
00647 
00648 /* FDDI header is always this: -worm5er */
00649 typedef struct _Fddi_hdr
00650 {
00651     u_int8_t fc;        /* frame control field */
00652     u_int8_t daddr[FDDI_ALEN];  /* src address */
00653     u_int8_t saddr[FDDI_ALEN];  /* dst address */
00654 }         Fddi_hdr;
00655 
00656 /* splitting the llc up because of variable lengths of the LLC -worm5er */
00657 typedef struct _Fddi_llc_saps
00658 {
00659     u_int8_t dsap;
00660     u_int8_t ssap;
00661 }              Fddi_llc_saps;
00662 
00663 /* I've found sna frames have two addition bytes after the llc saps -worm5er */
00664 typedef struct _Fddi_llc_sna
00665 {
00666     u_int8_t ctrl_fld[2];
00667 }             Fddi_llc_sna;
00668 
00669 /* I've also found other frames that seem to have only one byte...  We're only
00670 really intersted in the IP data so, until we want other, I'm going to say
00671 the data is one byte beyond this frame...  -worm5er */
00672 typedef struct _Fddi_llc_other
00673 {
00674     u_int8_t ctrl_fld[1];
00675 }               Fddi_llc_other;
00676 
00677 /* Just like TR the ip/arp data is setup as such: -worm5er */
00678 typedef struct _Fddi_llc_iparp
00679 {
00680     u_int8_t ctrl_fld;
00681     u_int8_t protid[3];
00682     u_int16_t ethertype;
00683 }               Fddi_llc_iparp;
00684 
00685 /* End FDDI Data Structures */
00686 
00687 
00688 /* 'Linux cooked captures' data
00689  * (taken from tcpdump source).
00690  */
00691 
00692 #define SLL_HDR_LEN     16              /* total header length */
00693 #define SLL_ADDRLEN     8               /* length of address field */
00694 typedef struct _SLLHdr {
00695         u_int16_t       sll_pkttype;    /* packet type */
00696         u_int16_t       sll_hatype;     /* link-layer address type */
00697         u_int16_t       sll_halen;      /* link-layer address length */
00698         u_int8_t        sll_addr[SLL_ADDRLEN];  /* link-layer address */
00699         u_int16_t       sll_protocol;   /* protocol */
00700 } SLLHdr;
00701 
00702 
00703 /* Old OpenBSD pf firewall pflog0 header
00704  * (information from pf source in kernel)
00705  * the rule, reason, and action codes tell why the firewall dropped it -fleck
00706  */
00707 
00708 typedef struct _OldPflog_hdr
00709 {
00710     u_int32_t af;
00711     char intf[IFNAMSIZ];
00712     short rule;
00713     u_short reason;
00714     u_short action;
00715     u_short dir;
00716 } OldPflogHdr;
00717 
00718 #define OLDPFLOG_HDRLEN    sizeof(struct _OldPflog_hdr)
00719 
00720 /* OpenBSD pf firewall pflog0 header
00721  * (information from pf source in kernel)
00722  * the rule, reason, and action codes tell why the firewall dropped it -fleck
00723  */
00724 
00725 typedef struct _Pflog_hdr
00726 {
00727         int8_t          length;
00728         sa_family_t     af;
00729         u_int8_t        action;
00730         u_int8_t        reason;
00731         char            ifname[IFNAMSIZ];
00732         char            ruleset[16];
00733         u_int32_t       rulenr;
00734         u_int32_t       subrulenr;
00735         u_int8_t        dir;
00736         u_int8_t        pad[3];
00737 } PflogHdr;
00738 
00739 #define PFLOG_HDRLEN    sizeof(struct _Pflog_hdr)
00740 
00741 /*
00742  * ssl_pkttype values.
00743  */
00744 
00745 #define LINUX_SLL_HOST          0
00746 #define LINUX_SLL_BROADCAST     1
00747 #define LINUX_SLL_MULTICAST     2
00748 #define LINUX_SLL_OTHERHOST     3
00749 #define LINUX_SLL_OUTGOING      4
00750 
00751 /* ssl protocol values */
00752 
00753 #define LINUX_SLL_P_802_3       0x0001  /* Novell 802.3 frames without 802.2 LLC header */
00754 #define LINUX_SLL_P_802_2       0x0004  /* 802.2 frames (not D/I/X Ethernet) */
00755 
00756 
00757 #ifdef _MSC_VER
00758   /* Visual C++ pragma to disable warning messages 
00759    * about nonstandard bit field type 
00760    */
00761   #pragma warning( disable : 4214 )  
00762 #endif
00763 
00764 #define VTH_PRIORITY(vh)  ((ntohs((vh)->vth_pri_cfi_vlan) & 0xe000) >> 13)
00765 #define VTH_CFI(vh)       ((ntohs((vh)->vth_pri_cfi_vlan) & 0x0100) >> 12)
00766 #define VTH_VLAN(vh)      ((ntohs((vh)->vth_pri_cfi_vlan) & 0x0FFF))
00767 
00768 typedef struct _VlanTagHdr
00769 {
00770     u_int16_t vth_pri_cfi_vlan;
00771     u_int16_t vth_proto;  /* protocol field... */
00772 } VlanTagHdr;
00773 #ifdef _MSC_VER
00774   /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
00775   #pragma warning( default : 4214 )
00776 #endif
00777 
00778 
00779 typedef struct _EthLlc
00780 {
00781     u_int8_t dsap;
00782     u_int8_t ssap;
00783 } EthLlc;
00784 
00785 typedef struct _EthLlcOther
00786 {
00787     u_int8_t ctrl;
00788     u_int8_t org_code[3];
00789     u_int16_t proto_id;
00790 } EthLlcOther;
00791 
00792 
00793 /* 
00794  * Ethernet header
00795  */
00796 
00797 typedef struct _EtherHdr
00798 {
00799     u_int8_t ether_dst[6];
00800     u_int8_t ether_src[6];
00801     u_int16_t ether_type;
00802 
00803 }         EtherHdr;
00804 
00805 
00806 /*
00807  *  Wireless Header (IEEE 802.11)
00808  */
00809 typedef struct _WifiHdr
00810 {
00811   u_int16_t frame_control;
00812   u_int16_t duration_id;
00813   u_int8_t  addr1[6];
00814   u_int8_t  addr2[6];
00815   u_int8_t  addr3[6];
00816   u_int16_t seq_control;
00817   u_int8_t  addr4[6];
00818 } WifiHdr;
00819 
00820 
00821 /* Can't add any fields not in the real header here 
00822    because of how the decoder uses structure overlaying */
00823 #ifdef _MSC_VER
00824   /* Visual C++ pragma to disable warning messages 
00825    * about nonstandard bit field type 
00826    */
00827   #pragma warning( disable : 4214 )  
00828 #endif
00829 
00830 /* tcpdump shows us the way to cross platform compatibility */
00831 #define IP_VER(iph)    (((iph)->ip_verhl & 0xf0) >> 4)
00832 #define IP_HLEN(iph)   ((iph)->ip_verhl & 0x0f)
00833 
00834 /* we need to change them as well as get them */
00835 #define SET_IP_VER(iph, value)  ((iph)->ip_verhl = (((iph)->ip_verhl & 0x0f) | (value << 4)))
00836 #define SET_IP_HLEN(iph, value)  ((iph)->ip_verhl = (((iph)->ip_verhl & 0xf0) | (value & 0x0f)))
00837 
00838 typedef struct _IPHdr
00839 {
00840     u_int8_t ip_verhl;      /* version & header length */
00841     u_int8_t ip_tos;        /* type of service */
00842     u_int16_t ip_len;       /* datagram length */
00843     u_int16_t ip_id;        /* identification  */
00844     u_int16_t ip_off;       /* fragment offset */
00845     u_int8_t ip_ttl;        /* time to live field */
00846     u_int8_t ip_proto;      /* datagram protocol */
00847     u_int16_t ip_csum;      /* checksum */
00848     struct in_addr ip_src;  /* source IP */
00849     struct in_addr ip_dst;  /* dest IP */
00850 }      IPHdr;
00851 #ifdef _MSC_VER
00852   /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
00853   #pragma warning( default : 4214 )
00854 #endif
00855 
00856 
00857 /* Can't add any fields not in the real header here 
00858    because of how the decoder uses structure overlaying */
00859 #ifdef _MSC_VER
00860   /* Visual C++ pragma to disable warning 
00861    * messages about nonstandard bit field type 
00862    */
00863   #pragma warning( disable : 4214 )  
00864 #endif
00865 
00866 
00867 /* more macros for TCP offset */
00868 #define TCP_OFFSET(tcph)        (((tcph)->th_offx2 & 0xf0) >> 4)
00869 #define TCP_X2(tcph)            ((tcph)->th_offx2 & 0x0f)
00870 
00871 /* we need to change them as well as get them */
00872 #define SET_TCP_OFFSET(tcph, value)  ((tcph)->th_offx2 = (((tcph)->th_offx2 & 0x0f) | (value << 4)))
00873 #define SET_TCP_X2(tcph, value)  ((tcph)->th_offx2 = (((tcph)->th_offx2 & 0xf0) | (value & 0x0f)))
00874 
00875 typedef struct _TCPHdr
00876 {
00877     u_int16_t th_sport;     /* source port */
00878     u_int16_t th_dport;     /* destination port */
00879     u_int32_t th_seq;       /* sequence number */
00880     u_int32_t th_ack;       /* acknowledgement number */
00881     u_int8_t th_offx2;     /* offset and reserved */
00882     u_int8_t th_flags;
00883     u_int16_t th_win;       /* window */
00884     u_int16_t th_sum;       /* checksum */
00885     u_int16_t th_urp;       /* urgent pointer */
00886 
00887 }       TCPHdr;
00888 #ifdef _MSC_VER
00889   /* Visual C++ pragma to enable warning messages 
00890    * about nonstandard bit field type 
00891    */
00892   #pragma warning( default : 4214 )
00893 #endif
00894 
00895 
00896 typedef struct _UDPHdr
00897 {
00898     u_int16_t uh_sport;
00899     u_int16_t uh_dport;
00900     u_int16_t uh_len;
00901     u_int16_t uh_chk;
00902 
00903 }       UDPHdr;
00904 
00905 
00906 typedef struct _ICMPHdr
00907 {
00908     u_int8_t type;
00909     u_int8_t code;
00910     u_int16_t csum;
00911     union
00912     {
00913         u_int8_t pptr;
00914 
00915         struct in_addr gwaddr;
00916 
00917         struct idseq
00918         {
00919             u_int16_t id;
00920             u_int16_t seq;
00921         } idseq;
00922 
00923         int sih_void;
00924 
00925         struct pmtu 
00926         {
00927             u_int16_t ipm_void;
00928             u_int16_t nextmtu;
00929         } pmtu;
00930 
00931         struct rtradv 
00932         {
00933             u_int8_t num_addrs;
00934             u_int8_t wpa;
00935             u_int16_t lifetime;
00936         } rtradv;
00937     } icmp_hun;
00938 
00939 #define s_icmp_pptr       icmp_hun.pptr
00940 #define s_icmp_gwaddr     icmp_hun.gwaddr
00941 #define s_icmp_id         icmp_hun.idseq.id
00942 #define s_icmp_seq        icmp_hun.idseq.seq
00943 #define s_icmp_void       icmp_hun.sih_void
00944 #define s_icmp_pmvoid     icmp_hun.pmtu.ipm_void
00945 #define s_icmp_nextmtu    icmp_hun.pmtu.nextmtu
00946 #define s_icmp_num_addrs  icmp_hun.rtradv.num_addrs
00947 #define s_icmp_wpa        icmp_hun.rtradv.wpa
00948 #define s_icmp_lifetime   icmp_hun.rtradv.lifetime
00949 
00950     union 
00951     {
00952         /* timestamp */
00953         struct ts 
00954         {
00955             u_int32_t otime;
00956             u_int32_t rtime;
00957             u_int32_t ttime;
00958         } ts;
00959         
00960         /* IP header for unreach */
00961         struct ih_ip  
00962         {
00963             IPHdr *ip;
00964             /* options and then 64 bits of data */
00965         } ip;
00966         
00967         struct ra_addr 
00968         {
00969             u_int32_t addr;
00970             u_int32_t preference;
00971         } radv;
00972 
00973         u_int32_t mask;
00974 
00975         char    data[1];
00976 
00977     } icmp_dun;
00978 #define s_icmp_otime      icmp_dun.ts.otime
00979 #define s_icmp_rtime      icmp_dun.ts.rtime
00980 #define s_icmp_ttime      icmp_dun.ts.ttime
00981 #define s_icmp_ip         icmp_dun.ih_ip
00982 #define s_icmp_radv       icmp_dun.radv
00983 #define s_icmp_mask       icmp_dun.mask
00984 #define s_icmp_data       icmp_dun.data
00985 
00986 }        ICMPHdr;
00987 
00988 
00989 typedef struct _ARPHdr
00990 {
00991     u_int16_t ar_hrd;       /* format of hardware address   */
00992     u_int16_t ar_pro;       /* format of protocol address   */
00993     u_int8_t ar_hln;        /* length of hardware address   */
00994     u_int8_t ar_pln;        /* length of protocol address   */
00995     u_int16_t ar_op;        /* ARP opcode (command)         */
00996 }       ARPHdr;
00997 
00998 
00999 
01000 typedef struct _EtherARP
01001 {
01002     ARPHdr ea_hdr;      /* fixed-size header */
01003     u_int8_t arp_sha[6];    /* sender hardware address */
01004     u_int8_t arp_spa[4];    /* sender protocol address */
01005     u_int8_t arp_tha[6];    /* target hardware address */
01006     u_int8_t arp_tpa[4];    /* target protocol address */
01007 }         EtherARP;
01008 
01009 
01010 typedef struct _EtherEapol
01011 {
01012     u_int8_t  version;  /* EAPOL proto version */
01013     u_int8_t  eaptype;  /* EAPOL Packet type */
01014     u_int16_t len;  /* Packet body length */
01015 }         EtherEapol;
01016 
01017 typedef struct _EAPHdr
01018 {
01019     u_int8_t code;
01020     u_int8_t id;
01021     u_int16_t len;
01022 }         EAPHdr;
01023 
01024 typedef struct _EapolKey
01025 {
01026   u_int8_t type;
01027   u_int8_t length[2];
01028   u_int8_t counter[8];
01029   u_int8_t iv[16];
01030   u_int8_t index;
01031   u_int8_t sig[16];
01032 }       EapolKey;
01033 
01034 typedef struct _Options
01035 {
01036     u_int8_t code;
01037     u_int8_t len; /* length of the data section */
01038     u_int8_t *data;
01039 }        Options;
01040 
01041 /* PPPoEHdr Header; EtherHdr plus the PPPoE Header */
01042 typedef struct _PPPoEHdr
01043 {
01044     EtherHdr ethhdr;            /* ethernet header */
01045     unsigned char ver_type;     /* pppoe version/type */
01046     unsigned char code;         /* pppoe code CODE_* */
01047     unsigned short session;     /* session id */
01048     unsigned short length;      /* payload length */
01049                                 /* payload follows */
01050 } PPPoEHdr;
01051 
01052 /* PPPoE tag; the payload is a sequence of these */
01053 typedef struct _PPPoE_Tag
01054 {
01055     unsigned short type;    /* tag type TAG_* */
01056     unsigned short length;    /* tag length */
01057                             /* payload follows */
01058 } PPPoE_Tag;
01059 
01060 #define DECODE_BLEN 65535
01061 
01062 /* Max Number of HTTP/1.1 requests in a single segment */
01063 #define URI_COUNT        5
01064 
01065 #define HTTPURI_PIPELINE_REQ 0x01
01066 typedef struct _HttpUri
01067 {
01068     u_int8_t *uri;  /* static buffer for uri length */
01069     u_int16_t length;
01070     u_int32_t decode_flags; 
01071 } HttpUri;
01072 
01073 typedef struct _Packet
01074 {
01075     struct pcap_pkthdr *pkth;   /* BPF data */
01076     u_int8_t *pkt;              /* base pointer to the raw packet data */
01077 
01078     Fddi_hdr *fddihdr;          /* FDDI support headers */
01079     Fddi_llc_saps *fddisaps;
01080     Fddi_llc_sna *fddisna;
01081     Fddi_llc_iparp *fddiiparp;    
01082     Fddi_llc_other *fddiother;
01083 
01084     Trh_hdr *trh;               /* Token Ring support headers */
01085     Trh_llc *trhllc;
01086     Trh_mr *trhmr;
01087 
01088     SLLHdr *sllh;               /* Linux cooked sockets header */
01089 
01090     PflogHdr *pfh;              /* OpenBSD pflog interface header */
01091 
01092     OldPflogHdr *opfh;          /* Old OpenBSD pflog interface header */
01093 
01094     EtherHdr *eh;               /* standard TCP/IP/Ethernet/ARP headers */
01095     VlanTagHdr *vh;
01096     EthLlc   *ehllc;
01097     EthLlcOther *ehllcother;
01098     
01099     WifiHdr *wifih;         /* wireless LAN header */
01100 
01101     EtherARP *ah;
01102 
01103     EtherEapol *eplh;       /* 802.1x EAPOL header */
01104     EAPHdr *eaph;
01105     u_int8_t *eaptype;
01106     EapolKey *eapolk;
01107 
01108     PPPoEHdr *pppoeh;        /* Encapsulated PPP of Ether header */
01109 
01110     IPHdr *iph, *orig_iph;   /* and orig. headers for ICMP_*_UNREACH family */
01111     u_int32_t ip_options_len;
01112     u_int8_t *ip_options_data;
01113 
01114     TCPHdr *tcph, *orig_tcph;
01115     u_int32_t tcp_options_len;
01116     u_int8_t *tcp_options_data;
01117 
01118     UDPHdr *udph, *orig_udph;
01119     ICMPHdr *icmph, *orig_icmph;
01120 
01121     u_int8_t *data;         /* packet payload pointer */
01122     u_int16_t dsize;        /* packet payload size */
01123     u_int16_t alt_dsize;    /* the dsize of a packet before munging (used for log)*/
01124 
01125     u_int16_t actual_ip_len;/* for logging truncated packets (usually by a small snaplen) */
01126 
01127     u_int8_t frag_flag;     /* flag to indicate a fragmented packet */
01128     u_int16_t frag_offset;  /* fragment offset number */
01129     u_int8_t mf;            /* more fragments flag */
01130     u_int8_t df;            /* don't fragment flag */
01131     u_int8_t rf;                  /* IP reserved bit */
01132 
01133     u_int16_t sp;           /* source port (TCP/UDP) */
01134     u_int16_t dp;           /* dest port (TCP/UDP) */
01135     u_int16_t orig_sp;      /* source port (TCP/UDP) of original datagram */
01136     u_int16_t orig_dp;      /* dest port (TCP/UDP) of original datagram */
01137     u_int32_t caplen;
01138 
01139     u_int8_t uri_count;     /* number of URIs in this packet */
01140 
01141     void *ssnptr;           /* for tcp session tracking info... */
01142     void *fragtracker;      /* for ip fragmentation tracking info... */
01143     void *flow;             /* for flow info */
01144     void *streamptr;        /* for tcp pkt dump */
01145     
01146     Options ip_options[IP_OPTMAX]; /* ip options decode structure */
01147     u_int32_t ip_option_count;  /* number of options in this packet */
01148     u_char ip_lastopt_bad;  /* flag to indicate that option decoding was
01149                                halted due to a bad option */
01150     Options tcp_options[TCP_OPTLENMAX];    /* tcp options decode struct */
01151     u_int32_t tcp_option_count;
01152     u_char tcp_lastopt_bad;  /* flag to indicate that option decoding was
01153                                 halted due to a bad option */
01154 
01155     u_int8_t csum_flags;        /* checksum flags */
01156     u_int32_t packet_flags;     /* special flags for the packet */
01157     u_int32_t bytes_to_inspect; /* Number of bytes to check against rules */
01158     int preprocessors;          /* flags for preprocessors to check */
01159 } Packet;
01160 
01161 typedef struct s_pseudoheader
01162 {
01163     u_int32_t sip, dip; 
01164     u_int8_t  zero;     
01165     u_int8_t  protocol; 
01166     u_int16_t len; 
01167 
01168 } PSEUDO_HDR;
01169 
01170 /* Default classification for decoder alerts */
01171 #define DECODE_CLASS 25 
01172 
01173 typedef struct _DecoderFlags
01174 {
01175     char decode_alerts;   /* if decode.c alerts are going to be enabled */
01176     char drop_alerts;     /* drop alerts from decoder */
01177     char tcpopt_experiment;  /* TcpOptions Decoder */
01178     char drop_tcpopt_experiment; /* Drop alerts from TcpOptions Decoder */
01179     char tcpopt_obsolete;    /* Alert on obsolete TCP options */
01180     char drop_tcpopt_obsolete; /* Drop on alerts from obsolete TCP options */
01181     char tcpopt_ttcp;        /* Alert on T/TCP options */
01182     char drop_tcpopt_ttcp;   /* Drop on alerts from T/TCP options */
01183     char tcpopt_decode;      /* alert on decoder inconsistencies */
01184     char drop_tcpopt_decode; /* Drop on alerts from decoder inconsistencies */
01185     char ipopt_decode;      /* alert on decoder inconsistencies */
01186     char drop_ipopt_decode; /* Drop on alerts from decoder inconsistencies */
01187 } DecoderFlags;
01188 
01189 #define        ALERTMSG_LENGTH 256
01190 
01191 
01192 /*  P R O T O T Y P E S  ******************************************************/
01193 void InitDecoderFlags(void);
01194 void DecodeTRPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01195 void DecodeFDDIPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01196 void DecodeLinuxSLLPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01197 void DecodeEthPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01198 void DecodeIEEE80211Pkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01199 void DecodeVlan(u_int8_t *, const u_int32_t, Packet *);
01200 void DecodePppPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01201 void DecodePppSerialPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01202 void DecodePppPktEncapsulated(Packet *, const u_int32_t, u_int8_t *);
01203 void DecodeSlipPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01204 void DecodeNullPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01205 void DecodeRawPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01206 void DecodeI4LRawIPPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01207 void DecodeI4LCiscoIPPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01208 void DecodeChdlcPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01209 void DecodePflog(Packet *, struct pcap_pkthdr *, u_int8_t *);
01210 void DecodeOldPflog(Packet *, struct pcap_pkthdr *, u_int8_t *);
01211 void DecodeIP(u_int8_t *, const u_int32_t, Packet *);
01212 void DecodeARP(u_int8_t *, u_int32_t, Packet *);
01213 void DecodeEapol(u_int8_t *, u_int32_t, Packet *);
01214 void DecodeEapolKey(u_int8_t *, u_int32_t, Packet *);
01215 void DecodeIPV6(u_int8_t *, u_int32_t);
01216 void DecodeIPX(u_int8_t *, u_int32_t);
01217 void DecodeEthLoopback(u_int8_t *, u_int32_t);
01218 void DecodeTCP(u_int8_t *, const u_int32_t, Packet *);
01219 void DecodeUDP(u_int8_t *, const u_int32_t, Packet *);
01220 void DecodeEAP(u_int8_t *, const u_int32_t, Packet *);
01221 void DecodeICMP(u_int8_t *, const u_int32_t, Packet *);
01222 void DecodeIPOptions(u_int8_t *, u_int32_t, Packet *);
01223 void DecodeTCPOptions(u_int8_t *, u_int32_t, Packet *);
01224 void DecodeIPOptions(u_int8_t *, u_int32_t, Packet *);
01225 void DecodePPPoEPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01226 void DecodeEncPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01227 #ifdef GIDS
01228 #ifndef IPFW
01229 void DecodeIptablesPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01230 #else
01231 void DecodeIpfwPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01232 #endif /* IPFW */
01233 #endif /* GIDS */
01234 
01235 #if defined(WORDS_MUSTALIGN) && !defined(__GNUC__)
01236 u_int32_t EXTRACT_32BITS (u_char *);
01237 #endif /* WORDS_MUSTALIGN && !__GNUC__ */
01238 
01239 /* XXX not sure where this guy needs to live at the moment */
01240 typedef struct _PortList
01241 {
01242     int ports[32];   /* 32 is kind of arbitrary */
01243 
01244     int num_entries;
01245 
01246 } PortList;
01247 
01248 #endif                /* __DECODE_H__ */

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2