FreeBSD kernel netgraph code
netflow_v9.h
Go to the documentation of this file.
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
*
4
* Copyright (c) 2010 Alexander V. Chernikov <melifaro@ipfw.ru>
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
* SUCH DAMAGE.
27
*
28
* $FreeBSD$
29
*/
30
31
#ifndef _NETFLOW_V9_H_
32
#define _NETFLOW_V9_H_
33
34
#ifdef COUNTERS_64
35
#define CNTR uint64_t
36
#define CNTR_MAX UINT64_MAX
37
#else
38
#define CNTR uint32_t
39
#define CNTR_MAX UINT_MAX
40
#endif
41
42
struct
netflow_v9_template
43
{
44
int
field_id
;
45
int
field_length
;
46
};
47
48
/* Template ID for tcp/udp v4 streams ID:257 (0x100 + NETFLOW_V9_FLOW_V4_L4) */
49
struct
netflow_v9_record_ipv4_tcp
50
{
51
uint32_t
src_addr
;
/* Source IPv4 address (IPV4_SRC_ADDR) */
52
uint32_t
dst_addr
;
/* Destination IPv4 address (IPV4_DST_ADDR) */
53
uint32_t
next_hop
;
/* Next hop IPv4 address (IPV4_NEXT_HOP) */
54
uint16_t
i_ifx
;
/* Source interface index (INPUT_SNMP) */
55
uint16_t
o_ifx
;
/* Destination interface index (OUTPUT_SNMP) */
56
CNTR
i_packets
;
/* Number of incoming packets in a flow (IN_PKTS) */
57
CNTR
i_octets
;
/* Number of incoming octets in a flow (IN_BYTES) */
58
CNTR
o_packets
;
/* Number of outgoing packets in a flow (OUT_PKTS) */
59
CNTR
o_octets
;
/* Number of outgoing octets in a flow (OUT_BYTES) */
60
uint32_t
first
;
/* System uptime at start of a flow (FIRST_SWITCHED) */
61
uint32_t
last
;
/* System uptime at end of a flow (LAST_SWITCHED) */
62
uint16_t
s_port
;
/* Source port (L4_SRC_PORT) */
63
uint16_t
d_port
;
/* Destination port (L4_DST_PORT) */
64
uint8_t
flags
;
/* Cumulative OR of tcp flags (TCP_FLAGS) */
65
uint8_t
prot
;
/* IP protocol */
66
uint8_t
tos
;
/* IP type of service IN (or OUT) (TOS) */
67
uint32_t
src_as
;
/* Src peer/origin Autonomous System (SRC_AS) */
68
uint32_t
dst_as
;
/* Dst peer/origin Autonomous System (DST_AS) */
69
uint8_t
src_mask
;
/* Source route's mask bits (SRC_MASK) */
70
uint8_t
dst_mask
;
/* Destination route's mask bits (DST_MASK) */
71
}
__attribute__
((__packed__));
72
73
/* Template ID for tcp/udp v6 streams ID: 260 (0x100 + NETFLOW_V9_FLOW_V6_L4) */
74
struct
netflow_v9_record_ipv6_tcp
75
{
76
struct
in6_addr
src_addr
;
/* Source IPv6 address (IPV6_SRC_ADDR) */
77
struct
in6_addr
dst_addr
;
/* Destination IPv6 address (IPV6_DST_ADDR) */
78
struct
in6_addr
next_hop
;
/* Next hop IPv6 address (IPV6_NEXT_HOP) */
79
uint16_t
i_ifx
;
/* Source interface index (INPUT_SNMP) */
80
uint16_t
o_ifx
;
/* Destination interface index (OUTPUT_SNMP) */
81
CNTR
i_packets
;
/* Number of incoming packets in a flow (IN_PKTS) */
82
CNTR
i_octets
;
/* Number of incoming octets in a flow (IN_BYTES) */
83
CNTR
o_packets
;
/* Number of outgoing packets in a flow (OUT_PKTS) */
84
CNTR
o_octets
;
/* Number of outgoing octets in a flow (OUT_BYTES) */
85
uint32_t
first
;
/* System uptime at start of a flow (FIRST_SWITCHED) */
86
uint32_t
last
;
/* System uptime at end of a flow (LAST_SWITCHED) */
87
uint16_t
s_port
;
/* Source port (L4_SRC_PORT) */
88
uint16_t
d_port
;
/* Destination port (L4_DST_PORT) */
89
uint8_t
flags
;
/* Cumulative OR of tcp flags (TCP_FLAGS) */
90
uint8_t
prot
;
/* IP protocol */
91
uint8_t
tos
;
/* IP type of service IN (or OUT) (TOS) */
92
uint32_t
src_as
;
/* Src peer/origin Autonomous System (SRC_AS) */
93
uint32_t
dst_as
;
/* Dst peer/origin Autonomous System (DST_AS) */
94
uint8_t
src_mask
;
/* Source route's mask bits (SRC_MASK) */
95
uint8_t
dst_mask
;
/* Destination route's mask bits (DST_MASK) */
96
}
__attribute__
((__packed__));
97
98
/* Used in export9_add to determine max record size */
99
struct
netflow_v9_record_general
100
{
101
union
{
102
struct
netflow_v9_record_ipv4_tcp
v4_tcp
;
103
struct
netflow_v9_record_ipv6_tcp
v6_tcp
;
104
}
rec
;
105
};
106
107
#define BASE_MTU 1500
108
#define MIN_MTU sizeof(struct netflow_v5_header)
109
#define MAX_MTU 16384
110
#define NETFLOW_V9_MAX_SIZE _NETFLOW_V9_MAX_SIZE(BASE_MTU)
111
/* Decrease MSS by 16 since there can be some IPv[46] header options */
112
#define _NETFLOW_V9_MAX_SIZE(x) (x) - sizeof(struct ip6_hdr) - sizeof(struct udphdr) - 16
113
114
/* #define NETFLOW_V9_MAX_FLOWSETS 2 */
115
116
#define NETFLOW_V9_MAX_RECORD_SIZE sizeof(struct netflow_v9_record_ipv6_tcp)
117
#define NETFLOW_V9_MAX_PACKETS_TEMPL 500
/* Send data templates every ... packets */
118
#define NETFLOW_V9_MAX_TIME_TEMPL 600
/* Send data templates every ... seconds */
119
#define NETFLOW_V9_MAX_TEMPLATES 16
/* Not a real value */
120
#define _NETFLOW_V9_TEMPLATE_SIZE(x) (sizeof(x) / sizeof(struct netflow_v9_template)) * 4
121
//#define _NETFLOW_V9_TEMPLATE_SIZE(x) ((x) + 1) * 4
122
123
/* Flow Templates */
124
#define NETFLOW_V9_FLOW_V4_L4 1
/* IPv4 TCP/UDP packet */
125
#define NETFLOW_V9_FLOW_V4_ICMP 2
/* IPv4 ICMP packet, currently unused */
126
#define NETFLOW_V9_FLOW_V4_L3 3
/* IPv4 IP packet */
127
#define NETFLOW_V9_FLOW_V6_L4 4
/* IPv6 TCP/UDP packet */
128
#define NETFLOW_V9_FLOW_V6_ICMP 5
/* IPv6 ICMP packet, currently unused */
129
#define NETFLOW_V9_FLOW_V6_L3 6
/* IPv6 IP packet */
130
131
#define NETFLOW_V9_FLOW_FAKE 65535
/* Not uset used in real flowsets! */
132
133
struct
netflow_v9_export_dgram
{
134
struct
netflow_v9_header
header
;
135
char
*
data
;
/* MTU can change, record length is dynamic */
136
};
137
138
struct
netflow_v9_flowset_header
{
139
uint16_t
id
;
/* FlowSet id */
140
uint16_t
length
;
/* FlowSet length */
141
}
__attribute__
((__packed__));
142
143
struct
netflow_v9_packet_opt
{
144
uint16_t
length
;
/* current packet length */
145
uint16_t
count
;
/* current records count */
146
uint16_t
mtu
;
/* max MTU shapshot */
147
uint16_t
flow_type
;
/* current flowset */
148
uint16_t
flow_header
;
/* offset pointing to current flow header */
149
};
150
#endif
CNTR
#define CNTR
Definition:
netflow_v9.h:38
__attribute__
struct netflow_v9_record_general __attribute__
netflow_v9_export_dgram
Definition:
netflow_v9.h:133
netflow_v9_export_dgram::header
struct netflow_v9_header header
Definition:
netflow_v9.h:134
netflow_v9_export_dgram::data
char * data
Definition:
netflow_v9.h:135
netflow_v9_flowset_header
Definition:
netflow_v9.h:138
netflow_v9_flowset_header::length
uint16_t length
Definition:
netflow_v9.h:140
netflow_v9_flowset_header::id
uint16_t id
Definition:
netflow_v9.h:139
netflow_v9_header
Definition:
netflow.h:80
netflow_v9_packet_opt
Definition:
netflow_v9.h:143
netflow_v9_packet_opt::flow_type
uint16_t flow_type
Definition:
netflow_v9.h:147
netflow_v9_packet_opt::mtu
uint16_t mtu
Definition:
netflow_v9.h:146
netflow_v9_packet_opt::flow_header
uint16_t flow_header
Definition:
netflow_v9.h:148
netflow_v9_packet_opt::count
uint16_t count
Definition:
netflow_v9.h:145
netflow_v9_packet_opt::length
uint16_t length
Definition:
netflow_v9.h:144
netflow_v9_record_general
Definition:
netflow_v9.h:100
netflow_v9_record_general::rec
union netflow_v9_record_general::@10 rec
netflow_v9_record_general::v6_tcp
struct netflow_v9_record_ipv6_tcp v6_tcp
Definition:
netflow_v9.h:103
netflow_v9_record_general::v4_tcp
struct netflow_v9_record_ipv4_tcp v4_tcp
Definition:
netflow_v9.h:102
netflow_v9_record_ipv4_tcp
Definition:
netflow_v9.h:50
netflow_v9_record_ipv4_tcp::dst_addr
uint32_t dst_addr
Definition:
netflow_v9.h:52
netflow_v9_record_ipv4_tcp::d_port
uint16_t d_port
Definition:
netflow_v9.h:63
netflow_v9_record_ipv4_tcp::prot
uint8_t prot
Definition:
netflow_v9.h:65
netflow_v9_record_ipv4_tcp::o_octets
CNTR o_octets
Definition:
netflow_v9.h:59
netflow_v9_record_ipv4_tcp::flags
uint8_t flags
Definition:
netflow_v9.h:64
netflow_v9_record_ipv4_tcp::i_ifx
uint16_t i_ifx
Definition:
netflow_v9.h:54
netflow_v9_record_ipv4_tcp::next_hop
uint32_t next_hop
Definition:
netflow_v9.h:53
netflow_v9_record_ipv4_tcp::dst_mask
uint8_t dst_mask
Definition:
netflow_v9.h:70
netflow_v9_record_ipv4_tcp::i_octets
CNTR i_octets
Definition:
netflow_v9.h:57
netflow_v9_record_ipv4_tcp::o_packets
CNTR o_packets
Definition:
netflow_v9.h:58
netflow_v9_record_ipv4_tcp::src_mask
uint8_t src_mask
Definition:
netflow_v9.h:69
netflow_v9_record_ipv4_tcp::first
uint32_t first
Definition:
netflow_v9.h:60
netflow_v9_record_ipv4_tcp::o_ifx
uint16_t o_ifx
Definition:
netflow_v9.h:55
netflow_v9_record_ipv4_tcp::src_as
uint32_t src_as
Definition:
netflow_v9.h:67
netflow_v9_record_ipv4_tcp::src_addr
uint32_t src_addr
Definition:
netflow_v9.h:51
netflow_v9_record_ipv4_tcp::last
uint32_t last
Definition:
netflow_v9.h:61
netflow_v9_record_ipv4_tcp::tos
uint8_t tos
Definition:
netflow_v9.h:66
netflow_v9_record_ipv4_tcp::i_packets
CNTR i_packets
Definition:
netflow_v9.h:56
netflow_v9_record_ipv4_tcp::dst_as
uint32_t dst_as
Definition:
netflow_v9.h:68
netflow_v9_record_ipv4_tcp::s_port
uint16_t s_port
Definition:
netflow_v9.h:62
netflow_v9_record_ipv6_tcp
Definition:
netflow_v9.h:75
netflow_v9_record_ipv6_tcp::src_mask
uint8_t src_mask
Definition:
netflow_v9.h:94
netflow_v9_record_ipv6_tcp::s_port
uint16_t s_port
Definition:
netflow_v9.h:87
netflow_v9_record_ipv6_tcp::i_packets
CNTR i_packets
Definition:
netflow_v9.h:81
netflow_v9_record_ipv6_tcp::i_ifx
uint16_t i_ifx
Definition:
netflow_v9.h:79
netflow_v9_record_ipv6_tcp::o_octets
CNTR o_octets
Definition:
netflow_v9.h:84
netflow_v9_record_ipv6_tcp::flags
uint8_t flags
Definition:
netflow_v9.h:89
netflow_v9_record_ipv6_tcp::o_ifx
uint16_t o_ifx
Definition:
netflow_v9.h:80
netflow_v9_record_ipv6_tcp::next_hop
struct in6_addr next_hop
Definition:
netflow_v9.h:78
netflow_v9_record_ipv6_tcp::first
uint32_t first
Definition:
netflow_v9.h:85
netflow_v9_record_ipv6_tcp::dst_mask
uint8_t dst_mask
Definition:
netflow_v9.h:95
netflow_v9_record_ipv6_tcp::d_port
uint16_t d_port
Definition:
netflow_v9.h:88
netflow_v9_record_ipv6_tcp::prot
uint8_t prot
Definition:
netflow_v9.h:90
netflow_v9_record_ipv6_tcp::o_packets
CNTR o_packets
Definition:
netflow_v9.h:83
netflow_v9_record_ipv6_tcp::src_addr
struct in6_addr src_addr
Definition:
netflow_v9.h:76
netflow_v9_record_ipv6_tcp::src_as
uint32_t src_as
Definition:
netflow_v9.h:92
netflow_v9_record_ipv6_tcp::last
uint32_t last
Definition:
netflow_v9.h:86
netflow_v9_record_ipv6_tcp::i_octets
CNTR i_octets
Definition:
netflow_v9.h:82
netflow_v9_record_ipv6_tcp::tos
uint8_t tos
Definition:
netflow_v9.h:91
netflow_v9_record_ipv6_tcp::dst_addr
struct in6_addr dst_addr
Definition:
netflow_v9.h:77
netflow_v9_record_ipv6_tcp::dst_as
uint32_t dst_as
Definition:
netflow_v9.h:93
netflow_v9_template
Definition:
netflow_v9.h:43
netflow_v9_template::field_id
int field_id
Definition:
netflow_v9.h:44
netflow_v9_template::field_length
int field_length
Definition:
netflow_v9.h:45
netgraph
netflow
netflow_v9.h
Generated by
1.9.3