decode.h
1/*
2 * Copyright 2007-2023 Carnegie Mellon University
3 * See license information in LICENSE.txt.
4 */
5/*
6 * decode.h
7 * YAF Layer 2 and Layer 3 decode routines
8 *
9 * ------------------------------------------------------------------------
10 * Authors: Brian Trammell
11 * ------------------------------------------------------------------------
12 * @DISTRIBUTION_STATEMENT_BEGIN@
13 * YAF 2.15.0
14 *
15 * Copyright 2023 Carnegie Mellon University.
16 *
17 * NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
18 * INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
19 * UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
20 * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
21 * PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
22 * THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
23 * ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
24 * INFRINGEMENT.
25 *
26 * Licensed under a GNU GPL 2.0-style license, please see LICENSE.txt or
27 * contact permission@sei.cmu.edu for full terms.
28 *
29 * [DISTRIBUTION STATEMENT A] This material has been approved for public
30 * release and unlimited distribution. Please see Copyright notice for
31 * non-US Government use and distribution.
32 *
33 * GOVERNMENT PURPOSE RIGHTS - Software and Software Documentation
34 * Contract No.: FA8702-15-D-0002
35 * Contractor Name: Carnegie Mellon University
36 * Contractor Address: 4500 Fifth Avenue, Pittsburgh, PA 15213
37 *
38 * The Government's rights to use, modify, reproduce, release, perform,
39 * display, or disclose this software are restricted by paragraph (b)(2) of
40 * the Rights in Noncommercial Computer Software and Noncommercial Computer
41 * Software Documentation clause contained in the above identified
42 * contract. No restrictions apply after the expiration date shown
43 * above. Any reproduction of the software or portions thereof marked with
44 * this legend must also reproduce the markings.
45 *
46 * This Software includes and/or makes use of Third-Party Software each
47 * subject to its own license.
48 *
49 * DM23-2313
50 * @DISTRIBUTION_STATEMENT_END@
51 * ------------------------------------------------------------------------
52 */
53
72#ifndef _YAF_DECODE_H_
73#define _YAF_DECODE_H_
74
75#include <yaf/autoinc.h>
76#include <yaf/yafcore.h>
77
79typedef struct yfIPFragInfo_st {
81 uint32_t ipid;
83 uint16_t offset;
85 uint16_t iphlen;
90 uint16_t l4hlen;
95 uint8_t frag;
99 uint8_t more;
101
103#define YF_MPLS_LABEL_COUNT_MAX 3
104
106typedef struct yfL2Info_st {
108 uint8_t smac[6];
110 uint8_t dmac[6];
112 uint16_t l2hlen;
114 uint16_t vlan_tag;
116 uint32_t mpls_count;
118 uint32_t mpls_label[YF_MPLS_LABEL_COUNT_MAX];
119} yfL2Info_t;
120
122typedef struct yfMPTCPInfo_st {
124 uint64_t idsn;
126 uint32_t token;
128 uint16_t mss;
130 uint8_t flags;
131 /* address id */
132 uint8_t addrid;
134
136typedef struct yfTCPInfo_st {
138 uint32_t seq;
140 uint8_t flags;
144
146typedef struct yfPBuf_st {
148 uint64_t ptime;
154 struct pcap_pkthdr pcap_hdr;
156 pcap_t *pcapt;
158 uint64_t pcap_offset;
160 uint16_t pcap_caplist;
162 uint32_t iplen;
164 uint16_t ifnum;
167 uint8_t frag;
172#if defined(YAF_ENABLE_P0F) || defined(YAF_ENABLE_FPEXPORT)
174 size_t headerLen;
176 uint8_t headerVal[YFP_IPTCPHEADER_SIZE];
177#endif /* if defined(YAF_ENABLE_P0F) || defined(YAF_ENABLE_FPEXPORT) */
179 size_t paylen;
183 uint8_t payload[1];
184} yfPBuf_t;
185
187#define YF_PBUFLEN_NOL2INFO offsetof(yfPBuf_t, l2info)
188
190#define YF_PBUFLEN_NOPAYLOAD offsetof(yfPBuf_t, paylen)
191
193#define YF_PBUFLEN_BASE offsetof(yfPBuf_t, payload)
194
195struct yfDecodeCtx_st;
197typedef struct yfDecodeCtx_st yfDecodeCtx_t;
198
200#define YF_TYPE_IPv4 0x0800
202#define YF_TYPE_IPv6 0x86DD
207#define YF_TYPE_IPANY 0x0000
208
210#define YF_PROTO_IP6_HOP 0
212#define YF_PROTO_ICMP 1
214#define YF_PROTO_TCP 6
216#define YF_PROTO_UDP 17
218#define YF_PROTO_IP6_ROUTE 43
220#define YF_PROTO_IP6_FRAG 44
222#define YF_PROTO_GRE 47
224#define YF_PROTO_ICMP6 58
226#define YF_PROTO_IP6_NONEXT 59
228#define YF_PROTO_IP6_DOPT 60
229
231#define YF_TF_FIN 0x01
233#define YF_TF_SYN 0x02
235#define YF_TF_RST 0x04
237#define YF_TF_PSH 0x08
239#define YF_TF_ACK 0x10
241#define YF_TF_URG 0x20
243#define YF_TF_ECE 0x40
245#define YF_TF_CWR 0x80
246
248#define YF_MF_PRIO_CHANGE 0x01
250#define YF_MF_PRIORITY 0x02
252#define YF_MF_FAIL 0x04
254#define YF_MF_FASTCLOSE 0x08
255
277yfDecodeCtx_t *
278yfDecodeCtxAlloc(
279 int datalink,
280 uint16_t reqtype,
281 gboolean gremode,
282 GArray *vxlanports,
283 GArray *geneveports);
284
290void
291yfDecodeCtxFree(
292 yfDecodeCtx_t *ctx);
293
328gboolean
329yfDecodeToPBuf(
330 yfDecodeCtx_t *ctx,
331 uint64_t ptime,
332 size_t caplen,
333 const uint8_t *pkt,
334 yfIPFragInfo_t *fraginfo,
335 size_t pbuflen,
336 yfPBuf_t *pbuf);
337
345uint64_t
346yfDecodeTimeval(
347 const struct timeval *tv);
348
355void
356yfDecodeDumpStats(
357 yfDecodeCtx_t *ctx,
358 uint64_t packetTotal);
359
366void
367yfDecodeResetOffset(
368 yfDecodeCtx_t *ctx);
369
376uint32_t
377yfGetDecodeStats(
378 yfDecodeCtx_t *ctx);
379
380
394gboolean
395yfDefragTCP(
396 uint8_t *pkt,
397 size_t *caplen,
398 yfFlowKey_t *key,
399 yfIPFragInfo_t *fraginfo,
400 yfTCPInfo_t *tcpinfo,
401 size_t *payoff);
402
403#endif /* ifndef _YAF_DECODE_H_ */
A YAF flow key.
Definition yafcore.h:212
Fragmentation information structure.
Definition decode.h:79
uint16_t offset
Fragment offset within the reassembled datagram.
Definition decode.h:83
uint16_t l4hlen
Decoded header length.
Definition decode.h:90
uint8_t more
More fragments flag.
Definition decode.h:99
uint32_t ipid
Fragment ID.
Definition decode.h:81
uint16_t iphlen
IP header length.
Definition decode.h:85
uint8_t frag
Fragmented packet flag.
Definition decode.h:95
Datalink layer information structure.
Definition decode.h:106
uint16_t vlan_tag
VLAN tag.
Definition decode.h:114
uint32_t mpls_label[YF_MPLS_LABEL_COUNT_MAX]
MPLS label stack.
Definition decode.h:118
uint32_t mpls_count
MPLS label count.
Definition decode.h:116
uint8_t dmac[6]
Destination MAC address.
Definition decode.h:110
uint16_t l2hlen
Layer 2 Header Length.
Definition decode.h:112
uint8_t smac[6]
Source MAC address.
Definition decode.h:108
MPTCP information structure.
Definition decode.h:122
uint32_t token
token
Definition decode.h:126
uint8_t flags
flags
Definition decode.h:130
uint64_t idsn
initial dsn
Definition decode.h:124
uint16_t mss
maximum segment size
Definition decode.h:128
Full packet information structure.
Definition decode.h:146
uint64_t pcap_offset
offset into pcap
Definition decode.h:158
uint64_t ptime
Packet timestamp in epoch milliseconds.
Definition decode.h:148
yfTCPInfo_t tcpinfo
TCP information structure.
Definition decode.h:169
uint32_t iplen
Packet IP length.
Definition decode.h:162
yfL2Info_t l2info
Decoded layer 2 information.
Definition decode.h:171
pcap_t * pcapt
pcap struct
Definition decode.h:156
uint16_t ifnum
Interface number packet was decoded from.
Definition decode.h:164
uint16_t pcap_caplist
caplist
Definition decode.h:160
size_t paylen
Length of payload available in captured payload buffer.
Definition decode.h:179
size_t allHeaderLen
Length of all headers, L2, L3, L4.
Definition decode.h:152
struct pcap_pkthdr pcap_hdr
pcap header
Definition decode.h:154
yfFlowKey_t key
Flow key containing decoded IP and transport headers.
Definition decode.h:150
uint8_t frag
flag for determining if the packet was fragmented 0-no, 1-yes, 2-not fully assembled
Definition decode.h:167
uint8_t payload[1]
Captured payload buffer.
Definition decode.h:183
TCP information structure.
Definition decode.h:136
uint32_t seq
TCP sequence number.
Definition decode.h:138
uint8_t flags
TCP flags.
Definition decode.h:140
yfMPTCPInfo_t mptcp
MPTCP Info.
Definition decode.h:142
YAF Core Library.
#define YFP_IPTCPHEADER_SIZE
This is the size of the packet to store away for use primarily in passive OS fingerprinting,...
Definition yafcore.h:185