suricata
decode-ipv6.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2022 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 */
23
24#ifndef SURICATA_DECODE_IPV6_H
25#define SURICATA_DECODE_IPV6_H
26
27#define IPV6_HEADER_LEN 40
28#define IPV6_MAXPACKET 65535 /* maximum packet size */
29#define IPV6_MAX_OPT 40
30
31typedef struct IPV6Hdr_
32{
33 union {
34 struct ip6_un1_ {
35 uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
36 uint16_t ip6_un1_plen; /* payload length */
37 uint8_t ip6_un1_nxt; /* next header */
38 uint8_t ip6_un1_hlim; /* hop limit */
40 uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
42
43 union {
44 struct {
45 uint32_t ip6_src[4];
46 uint32_t ip6_dst[4];
48 uint16_t ip6_addrs[16];
51
52#define s_ip6_src ip6_hdrun2.ip6_un2.ip6_src
53#define s_ip6_dst ip6_hdrun2.ip6_un2.ip6_dst
54#define s_ip6_addrs ip6_hdrun2.ip6_addrs
55
56#define s_ip6_vfc ip6_hdrun.ip6_un2_vfc
57#define s_ip6_flow ip6_hdrun.ip6_un1.ip6_un1_flow
58#define s_ip6_plen ip6_hdrun.ip6_un1.ip6_un1_plen
59#define s_ip6_nxt ip6_hdrun.ip6_un1.ip6_un1_nxt
60#define s_ip6_hlim ip6_hdrun.ip6_un1.ip6_un1_hlim
61
62#define IPV6_GET_RAW_VER(ip6h) (((ip6h)->s_ip6_vfc & 0xf0) >> 4)
63#define IPV6_GET_RAW_CLASS(ip6h) ((SCNtohl((ip6h)->s_ip6_flow) & 0x0FF00000) >> 20)
64#define IPV6_GET_RAW_FLOW(ip6h) (SCNtohl((ip6h)->s_ip6_flow) & 0x000FFFFF)
65#define IPV6_GET_RAW_NH(ip6h) ((ip6h)->s_ip6_nxt)
66#define IPV6_GET_RAW_PLEN(ip6h) (SCNtohs((ip6h)->s_ip6_plen))
67#define IPV6_GET_RAW_HLIM(ip6h) ((ip6h)->s_ip6_hlim)
68
69#define IPV6_SET_RAW_VER(ip6h, value) ((ip6h)->s_ip6_vfc = (((ip6h)->s_ip6_vfc & 0x0f) | (value << 4)))
70#define IPV6_SET_RAW_NH(ip6h, value) ((ip6h)->s_ip6_nxt = (value))
71
72#define IPV6_SET_L4PROTO(p, proto) (p)->l3.vars.ip6.v.l4proto = (proto)
73#define IPV6_SET_EXTHDRS_LEN(p, len) (p)->l3.vars.ip6.v.exthdrs_len = (len)
74
75#define IPV6_GET_L4PROTO(p) ((p)->l3.vars.ip6.v.l4proto)
76#define IPV6_GET_EXTHDRS_LEN(p) ((p)->l3.vars.ip6.v.exthdrs_len)
77
78/** \brief get the highest proto/next header field we know */
79//#define IPV6_GET_UPPER_PROTO(p) (p)->ip6eh.ip6_exthdrs_cnt ?
80// (p)->ip6eh.ip6_exthdrs[(p)->ip6eh.ip6_exthdrs_cnt - 1].next : IPV6_GET_NH((p))
81
82/* helper structure with parsed ipv6 info */
83typedef struct IPV6Vars_
84{
85 uint8_t l4proto; /**< the proto after the extension headers
86 * store while decoding so we don't have
87 * to loop through the exthdrs all the time */
88 uint16_t exthdrs_len; /**< length of the exthdrs */
90
91/* Fragment header */
92typedef struct IPV6FragHdr_
93{
94 uint8_t ip6fh_nxt; /* next header */
95 uint8_t ip6fh_reserved; /* reserved field */
96 uint16_t ip6fh_offlg; /* offset, reserved, and flag */
97 uint32_t ip6fh_ident; /* identification */
98} __attribute__((__packed__)) IPV6FragHdr;
99
100#define IPV6_EXTHDR_GET_FH_NH(p) (p)->l3.vars.ip6.eh.fh_nh
101#define IPV6_EXTHDR_GET_FH_OFFSET(p) (p)->l3.vars.ip6.eh.fh_offset
102#define IPV6_EXTHDR_GET_FH_FLAG(p) (p)->l3.vars.ip6.eh.fh_more_frags_set
103#define IPV6_EXTHDR_GET_FH_ID(p) (p)->l3.vars.ip6.eh.fh_id
104
105/* rfc 1826 */
106typedef struct IPV6AuthHdr_
107{
108 uint8_t ip6ah_nxt; /* next header */
109 uint8_t ip6ah_len; /* header length in units of 8 bytes, not
110 including first 8 bytes. */
111 uint16_t ip6ah_reserved; /* reserved for future use */
112 uint32_t ip6ah_spi; /* SECURITY PARAMETERS INDEX (SPI) */
113 uint32_t ip6ah_seq; /* sequence number */
114} __attribute__((__packed__)) IPV6AuthHdr;
115
116/* Hop-by-Hop header and Destination Options header use options that are
117 * defined here. */
118
119#define IPV6OPT_PAD1 0x00
120#define IPV6OPT_PADN 0x01
121#define IPV6OPT_RA 0x05
122#define IPV6OPT_JUMBO 0xC2
123#define IPV6OPT_HAO 0xC9
124
125/* Home Address Option */
126typedef struct IPV6OptHAO_
127{
128 uint8_t ip6hao_type; /* Option type */
129 uint8_t ip6hao_len; /* Option Data len (excludes type and len) */
130 struct in6_addr ip6hao_hoa; /* Home address. */
132
133/* Router Alert Option */
134typedef struct IPV6OptRA_
135{
136 uint8_t ip6ra_type; /* Option type */
137 uint8_t ip6ra_len; /* Option Data len (excludes type and len) */
138 uint16_t ip6ra_value; /* Router Alert value */
140
141/* Jumbo Option */
142typedef struct IPV6OptJumbo_
143{
144 uint8_t ip6j_type; /* Option type */
145 uint8_t ip6j_len; /* Option Data len (excludes type and len) */
146 uint32_t ip6j_payload_len; /* Jumbo Payload Length */
148
149typedef struct IPV6ExtHdrs_
150{
151 bool rh_set;
152 uint8_t rh_type;
153
154 bool fh_set;
156 uint8_t fh_nh;
157
158 uint8_t fh_prev_nh;
160
163 uint16_t fh_data_len;
164
165 /* In fh_offset we store the offset of this extension into the packet past
166 * the ipv6 header. We use it in defrag for creating a defragmented packet
167 * without the frag header */
168 uint16_t fh_offset;
169 uint32_t fh_id;
170
172
173#define IPV6_EXTHDR_SET_FH(p) (p)->l3.vars.ip6.eh.fh_set = true
174#define IPV6_EXTHDR_ISSET_FH(p) (p)->l3.vars.ip6.eh.fh_set
175#define IPV6_EXTHDR_SET_RH(p) (p)->l3.vars.ip6.eh.rh_set = true
176#define IPV6_EXTHDR_ISSET_RH(p) (p)->l3.vars.ip6.eh.rh_set
177
178void DecodeIPV6RegisterTests(void);
179
180#endif /* SURICATA_DECODE_IPV6_H */
void DecodeIPV6RegisterTests(void)
this function registers unit tests for IPV6 decoder
struct IPV6ExtHdrs_ IPV6ExtHdrs
struct IPV6OptRA_ IPV6OptRA
struct IPV6OptJumbo_ IPV6OptJumbo
struct IPV6Hdr_ IPV6Hdr
struct IPV6Vars_ IPV6Vars
get the highest proto/next header field we know
struct IPV6OptHAO_ IPV6OptHAO
struct PrefilterEngineFlowbits __attribute__
DNP3 application header.
uint8_t ip6ah_nxt
uint8_t ip6ah_len
uint32_t ip6ah_seq
uint16_t ip6ah_reserved
uint32_t ip6ah_spi
uint16_t fh_data_len
uint16_t fh_header_offset
uint16_t fh_offset
uint8_t rh_type
uint16_t fh_data_offset
uint8_t fh_prev_nh
uint8_t fh_nh
bool fh_more_frags_set
uint32_t fh_id
uint16_t fh_prev_hdr_offset
uint16_t ip6fh_offlg
Definition decode-ipv6.h:96
uint32_t ip6fh_ident
Definition decode-ipv6.h:97
uint8_t ip6fh_nxt
Definition decode-ipv6.h:94
uint8_t ip6fh_reserved
Definition decode-ipv6.h:95
uint8_t ip6_un1_hlim
Definition decode-ipv6.h:38
uint32_t ip6_dst[4]
Definition decode-ipv6.h:46
uint32_t ip6_un1_flow
Definition decode-ipv6.h:35
struct IPV6Hdr_::@28::@29 ip6_un2
uint32_t ip6_src[4]
Definition decode-ipv6.h:45
union IPV6Hdr_::@27 ip6_hdrun
uint8_t ip6_un1_nxt
Definition decode-ipv6.h:37
union IPV6Hdr_::@28 ip6_hdrun2
uint8_t ip6_un2_vfc
Definition decode-ipv6.h:40
uint16_t ip6_un1_plen
Definition decode-ipv6.h:36
uint16_t ip6_addrs[16]
Definition decode-ipv6.h:48
struct IPV6Hdr_::@27::ip6_un1_ ip6_un1
uint8_t ip6hao_len
struct in6_addr ip6hao_hoa
uint8_t ip6hao_type
uint8_t ip6j_len
uint32_t ip6j_payload_len
uint8_t ip6j_type
uint8_t ip6ra_len
uint8_t ip6ra_type
uint16_t ip6ra_value
get the highest proto/next header field we know
Definition decode-ipv6.h:84
uint16_t exthdrs_len
Definition decode-ipv6.h:88
uint8_t l4proto
Definition decode-ipv6.h:85