00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00075 #ifndef _YAF_DECODE_H_
00076 #define _YAF_DECODE_H_
00077
00078 #include <yaf/autoinc.h>
00079 #include <yaf/yafcore.h>
00080
00082 typedef struct yfIPFragInfo_st {
00084 uint32_t ipid;
00086 uint16_t offset;
00088 uint16_t iphlen;
00093 uint16_t l4hlen;
00098 uint8_t frag;
00102 uint8_t more;
00103 } yfIPFragInfo_t;
00104
00106 #define YF_MPLS_LABEL_COUNT_MAX 10
00107
00109 typedef struct yfL2Info_st {
00111 uint8_t smac[6];
00113 uint8_t dmac[6];
00115 uint16_t l2hlen;
00117 uint16_t vlan_tag;
00119 uint32_t mpls_count;
00121 uint32_t mpls_label[YF_MPLS_LABEL_COUNT_MAX];
00122 } yfL2Info_t;
00123
00125 typedef struct yfTCPInfo_st {
00127 uint32_t seq;
00129 uint8_t flags;
00130 } yfTCPInfo_t;
00131
00133 typedef struct yfPBuf_st {
00135 uint64_t ptime;
00137 yfFlowKey_t key;
00139 size_t allHeaderLen;
00141 struct pcap_pkthdr pcap_hdr;
00143 pcap_t *pcapt;
00145 uint64_t pcap_offset;
00147 uint16_t pcap_caplist;
00149 uint16_t iplen;
00151 uint16_t ifnum;
00153 yfTCPInfo_t tcpinfo;
00155 yfL2Info_t l2info;
00156 # if defined(YAF_ENABLE_P0F) || defined(YAF_ENABLE_FPEXPORT)
00157
00158 size_t headerLen;
00160 uint8_t headerVal[YFP_IPTCPHEADER_SIZE];
00161 # endif
00162
00163 size_t paylen;
00167 uint8_t payload[1];
00168 } yfPBuf_t;
00169
00171 #define YF_PBUFLEN_NOL2INFO offsetof(yfPBuf_t, l2info)
00172
00174 #define YF_PBUFLEN_NOPAYLOAD offsetof(yfPBuf_t, paylen)
00175
00177 #define YF_PBUFLEN_BASE offsetof(yfPBuf_t, payload)
00178
00179 struct yfDecodeCtx_st;
00181 typedef struct yfDecodeCtx_st yfDecodeCtx_t;
00182
00184 #define YF_TYPE_IPv4 0x0800
00185
00186 #define YF_TYPE_IPv6 0x86DD
00187
00191 #define YF_TYPE_IPANY 0x0000
00192
00194 #define YF_PROTO_IP6_HOP 0
00195
00196 #define YF_PROTO_ICMP 1
00197
00198 #define YF_PROTO_TCP 6
00199
00200 #define YF_PROTO_UDP 17
00201
00202 #define YF_PROTO_IP6_ROUTE 43
00203
00204 #define YF_PROTO_IP6_FRAG 44
00205
00206 #define YF_PROTO_GRE 47
00207
00208 #define YF_PROTO_ICMP6 58
00209
00210 #define YF_PROTO_IP6_NONEXT 59
00211
00212 #define YF_PROTO_IP6_DOPT 60
00213
00215 #define YF_TF_FIN 0x01
00216
00217 #define YF_TF_SYN 0x02
00218
00219 #define YF_TF_RST 0x04
00220
00221 #define YF_TF_PSH 0x08
00222
00223 #define YF_TF_ACK 0x10
00224
00225 #define YF_TF_URG 0x20
00226
00227 #define YF_TF_ECE 0x40
00228
00229 #define YF_TF_CWR 0x80
00230
00249 yfDecodeCtx_t *yfDecodeCtxAlloc(
00250 int datalink,
00251 uint16_t reqtype,
00252 gboolean gremode);
00253
00259 void yfDecodeCtxFree(
00260 yfDecodeCtx_t *ctx);
00261
00297 gboolean yfDecodeToPBuf(
00298 yfDecodeCtx_t *ctx,
00299 uint64_t ptime,
00300 size_t caplen,
00301 const uint8_t *pkt,
00302 yfIPFragInfo_t *fraginfo,
00303 size_t pbuflen,
00304 yfPBuf_t *pbuf);
00305
00314 uint64_t yfDecodeTimeval(
00315 const struct timeval *tv);
00316
00325 uint64_t yfDecodeTimeNTP(
00326 uint64_t ntp);
00327
00335 void yfDecodeDumpStats(
00336 yfDecodeCtx_t *ctx,
00337 uint64_t packetTotal);
00338
00345 void yfDecodeResetOffset(
00346 yfDecodeCtx_t *ctx);
00347
00354 uint32_t yfGetDecodeStats(
00355 yfDecodeCtx_t *ctx);
00356
00357
00371 gboolean yfDefragTCP(
00372 uint8_t *pkt,
00373 size_t *caplen,
00374 yfFlowKey_t *key,
00375 yfIPFragInfo_t *fraginfo,
00376 yfTCPInfo_t *tcpinfo,
00377 size_t *payoff);
00378
00379
00380 #endif