decode.h
1/*
2 * Copyright 2007-2026 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.19
14 *
15 * Copyright 2026 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 * This Software includes and/or makes use of Third-Party Software each
34 * subject to its own license.
35 *
36 * DM26-0194
37 * @DISTRIBUTION_STATEMENT_END@
38 * ------------------------------------------------------------------------
39 */
40
58
59#ifndef _YAF_DECODE_H_
60#define _YAF_DECODE_H_
61
62#include <yaf/autoinc.h>
63#include <yaf/yafcore.h>
64
66typedef struct yfIPFragInfo_st {
68 uint32_t ipid;
70 uint16_t offset;
72 uint16_t iphlen;
77 uint16_t l4hlen;
82 uint8_t frag;
86 uint8_t more;
87} yfIPFragInfo_t;
88
90#define YF_MPLS_LABEL_COUNT_MAX 3
91
93typedef struct yfL2Info_st {
95 uint8_t smac[6];
97 uint8_t dmac[6];
99 uint16_t l2hlen;
101 uint16_t vlan_tag;
103 uint32_t mpls_count;
105 uint32_t mpls_label[YF_MPLS_LABEL_COUNT_MAX];
106} yfL2Info_t;
107
109typedef struct yfMPTCPInfo_st {
111 uint64_t idsn;
113 uint32_t token;
115 uint16_t mss;
117 uint8_t flags;
118 /* address id */
119 uint8_t addrid;
120} yfMPTCPInfo_t;
121
123typedef struct yfTCPInfo_st {
125 uint32_t seq;
127 uint8_t flags;
129 yfMPTCPInfo_t mptcp;
130} yfTCPInfo_t;
131
133typedef struct yfPBuf_st {
135 yfTime_t ptime;
141 struct pcap_pkthdr pcap_hdr;
143 pcap_t *pcapt;
145 uint64_t pcap_offset;
147 uint32_t iplen;
149 uint16_t pcap_caplist;
150#if 0
152 uint16_t ifnum;
153#endif
156 uint8_t frag;
158 yfTCPInfo_t tcpinfo;
160 yfL2Info_t l2info;
161#if defined(YAF_ENABLE_P0F) || defined(YAF_ENABLE_FPEXPORT)
163 size_t headerLen;
165 uint8_t headerVal[YFP_IPTCPHEADER_SIZE];
166#endif /* if defined(YAF_ENABLE_P0F) || defined(YAF_ENABLE_FPEXPORT) */
168 size_t paylen;
172 uint8_t payload[1];
173} yfPBuf_t;
174
176#define YF_PBUFLEN_NOL2INFO offsetof(yfPBuf_t, l2info)
177
179#define YF_PBUFLEN_NOPAYLOAD offsetof(yfPBuf_t, paylen)
180
182#define YF_PBUFLEN_BASE offsetof(yfPBuf_t, payload)
183
184struct yfDecodeCtx_st;
186typedef struct yfDecodeCtx_st yfDecodeCtx_t;
187
189#define YF_TYPE_IPv4 0x0800
191#define YF_TYPE_IPv6 0x86DD
196#define YF_TYPE_IPANY 0x0000
197
199#define YF_PROTO_IP6_HOP 0
201#define YF_PROTO_ICMP 1
203#define YF_PROTO_TCP 6
205#define YF_PROTO_UDP 17
207#define YF_PROTO_IP6_ROUTE 43
209#define YF_PROTO_IP6_FRAG 44
211#define YF_PROTO_GRE 47
213#define YF_PROTO_ICMP6 58
215#define YF_PROTO_IP6_NONEXT 59
217#define YF_PROTO_IP6_DOPT 60
218
220#define YF_TF_FIN 0x01
222#define YF_TF_SYN 0x02
224#define YF_TF_RST 0x04
226#define YF_TF_PSH 0x08
228#define YF_TF_ACK 0x10
230#define YF_TF_URG 0x20
232#define YF_TF_ECE 0x40
234#define YF_TF_CWR 0x80
235
237#define YF_MF_PRIO_CHANGE 0x01
239#define YF_MF_PRIORITY 0x02
241#define YF_MF_FAIL 0x04
243#define YF_MF_FASTCLOSE 0x08
244
266yfDecodeCtx_t *
267yfDecodeCtxAlloc(
268 int datalink,
269 uint16_t reqtype,
270 gboolean gremode,
271 GArray *vxlanports,
272 GArray *geneveports);
273
279void
280yfDecodeCtxFree(
281 yfDecodeCtx_t *ctx);
282
314gboolean
315yfDecodeToPBuf(
316 yfDecodeCtx_t *ctx,
317 const yfTime_t *ptime,
318 size_t caplen,
319 const uint8_t *pkt,
320 yfIPFragInfo_t *fraginfo,
321 size_t pbuflen,
322 yfPBuf_t *pbuf);
323
331uint64_t
332yfDecodeTimeval(
333 const struct timeval *tv);
334
341void
342yfDecodeDumpStats(
343 yfDecodeCtx_t *ctx,
344 uint64_t packetTotal);
345
352void
353yfDecodeResetOffset(
354 yfDecodeCtx_t *ctx);
355
362uint32_t
363yfGetDecodeStats(
364 yfDecodeCtx_t *ctx);
365
366
380gboolean
381yfDefragTCP(
382 uint8_t *pkt,
383 size_t *caplen,
384 yfFlowKey_t *key,
385 yfIPFragInfo_t *fraginfo,
386 yfTCPInfo_t *tcpinfo,
387 size_t *payoff);
388
389#endif /* ifndef _YAF_DECODE_H_ */
Fragmentation information structure.
Definition decode.h:66
uint16_t offset
Fragment offset within the reassembled datagram.
Definition decode.h:70
uint16_t l4hlen
Decoded header length.
Definition decode.h:77
uint8_t more
More fragments flag.
Definition decode.h:86
uint32_t ipid
Fragment ID.
Definition decode.h:68
uint16_t iphlen
IP header length.
Definition decode.h:72
uint8_t frag
Fragmented packet flag.
Definition decode.h:82
Datalink layer information structure.
Definition decode.h:93
uint16_t vlan_tag
VLAN tag.
Definition decode.h:101
uint32_t mpls_label[YF_MPLS_LABEL_COUNT_MAX]
MPLS label stack.
Definition decode.h:105
uint32_t mpls_count
MPLS label count.
Definition decode.h:103
uint8_t dmac[6]
Destination MAC address.
Definition decode.h:97
uint16_t l2hlen
Layer 2 Header Length.
Definition decode.h:99
uint8_t smac[6]
Source MAC address.
Definition decode.h:95
MPTCP information structure.
Definition decode.h:109
uint32_t token
token
Definition decode.h:113
uint8_t flags
flags
Definition decode.h:117
uint64_t idsn
initial dsn
Definition decode.h:111
uint16_t mss
maximum segment size
Definition decode.h:115
Full packet information structure.
Definition decode.h:133
uint64_t pcap_offset
offset into pcap
Definition decode.h:145
yfTCPInfo_t tcpinfo
TCP information structure.
Definition decode.h:158
yfTime_t ptime
Packet timestamp.
Definition decode.h:135
uint32_t iplen
Packet IP length.
Definition decode.h:147
yfL2Info_t l2info
Decoded layer 2 information.
Definition decode.h:160
pcap_t * pcapt
pcap struct
Definition decode.h:143
uint16_t pcap_caplist
file number within the caplist
Definition decode.h:149
size_t paylen
Length of payload available in captured payload buffer.
Definition decode.h:168
size_t allHeaderLen
Length of all headers, L2, L3, L4.
Definition decode.h:139
struct pcap_pkthdr pcap_hdr
pcap header
Definition decode.h:141
yfFlowKey_t key
Flow key containing decoded IP and transport headers.
Definition decode.h:137
uint8_t frag
flag for determining if the packet was fragmented 0-no, 1-yes, 2-not fully assembled (FIXME: Is value...
Definition decode.h:156
uint8_t payload[1]
Captured payload buffer.
Definition decode.h:172
TCP information structure.
Definition decode.h:123
uint32_t seq
TCP sequence number.
Definition decode.h:125
uint8_t flags
TCP flags.
Definition decode.h:127
yfMPTCPInfo_t mptcp
MPTCP Info.
Definition decode.h:129
YAF Core Library.
struct yfFlowKey_st yfFlowKey_t
A YAF flow key.
#define YFP_IPTCPHEADER_SIZE
This is the size of the packet to store away for use primarily in passive OS fingerprinting,...
Definition yafcore.h:180