Repository navigation
Expand file tree
/
Copy pathexport_common.h
More file actions
125 lines (112 loc) · 4.83 KB
/
Copy pathexport_common.h
File metadata and controls
125 lines (112 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright 2026 Hitoshi Irino <irino@sfc.wide.ad.jp> All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file export_common.h
* @brief Declarations shared by the NetFlow v9 and IPFIX exporters: template IDs,
* the template re-send interval and the conversion of time to NTP.
*/
#ifndef _EXPORT_COMMON_H
#define _EXPORT_COMMON_H
/*
* Definitions of softflowd shared by the exporters: the code common to them
* (export_common.c), the encoder-based exporter (export.c, export_fixed.c and
* export_template.c) and the fixed-format exporters (the files in compat/). The values defined by the RFCs are in
* ipfix.h.
*/
#include "ipfix.h"
#include "softflowd.h"
/** bi_flag: export each direction of a flow as a flow of its own. */
#define IPFIX_BIFLAG_OFF 0
/** bi_flag: export both directions of a flow as one Biflow (RFC 5103). */
#define IPFIX_BIFLAG_ON 1
/* Template IDs and template re-send interval (packets); shared with NetFlow v9
*/
/** Template ID of the IPv4 flow template. */
#define IPFIX_SOFTFLOWD_V4_TEMPLATE_ID 1024
/** Template ID of the ICMPv4 flow template. */
#define IPFIX_SOFTFLOWD_ICMPV4_TEMPLATE_ID 1025
/** Template ID of the IPv6 flow template. */
#define IPFIX_SOFTFLOWD_V6_TEMPLATE_ID 2048
/** Template ID of the ICMPv6 flow template. */
#define IPFIX_SOFTFLOWD_ICMPV6_TEMPLATE_ID 2049
/** Template ID of the options template. */
#define IPFIX_SOFTFLOWD_OPTION_TEMPLATE_ID 256
/** Number of packets after which the templates are sent again. */
#define IPFIX_DEFAULT_TEMPLATE_INTERVAL 16
/**
* Largest size in octets of an IPFIX or NetFlow v9 packet that softflowd
* builds.
*/
#define IPFIX_SOFTFLOWD_MAX_PACKET_SIZE 1428
/** @brief A time as a 64-bit NTP timestamp. */
struct ntp_time_t {
uint32_t second; /**< Seconds since 1900-01-01 */
uint32_t fraction; /**< Fraction of a second, in units of 2^-32 */
};
/* Force a resend of the flow template. */
void
ipfix_resend_template (void);
int
ipfix_init_fields (struct IPFIX_FIELD_SPECIFIER *dst, u_int *index,
const struct IPFIX_FIELD_SPECIFIER *src,
u_int field_number);
void
conv_unix_to_ntp (struct timeval tv, struct ntp_time_t *ntp);
void
conv_ntp_to_unix (struct ntp_time_t ntp, struct timeval *tv);
/* Determines flow template (v4/icmpv4/v6/icmpv6) index;
* used to select from their TMPLMAX template arrays. */
enum { TMPLV4,
TMPLICMPV4,
TMPLV6,
TMPLICMPV6,
TMPLMAX };
/* Functions shared by the exporters in export.c, export_template.c and
* compat/ipfix.c. */
u_int8_t
ipfix_flow_direction (const struct FLOW *flow, int i,
const struct FLOWTRACKPARAMETERS *param);
u_int
ipfix_flow_to_template_index (const struct FLOW *flow);
/* Hooks called by send_ipfix_flows() in export_common.c; each exporter
* (encoder-based in export_template.c, fixed-format in compat/ipfix.c)
* implements them. */
void
ipfix_init_exporter (const struct SENDPARAMETER *sp, u_int8_t bi_flag,
u_int16_t version);
void
ipfix_put_templates (u_char *packet, u_int *offset, u_int8_t bi_flag,
u_int16_t version, const struct SENDPARAMETER *sp);
int
ipfix_flow_to_flowset (const struct FLOW *flow, u_char *packet, u_int len,
const struct SENDPARAMETER *sp, u_int *len_used,
u_int8_t bi_flag, u_int16_t version);
u_int16_t
ipfix_template_set_id (u_int tmplindex);
/* Writes the export packet header; returns its size. Also used by the
* encoder-based exporter in export_fixed.c. */
u_int
export_build_flow_header (u_char *packet, u_int16_t version,
const struct FLOWTRACKPARAMETERS *param);
#endif /* _EXPORT_COMMON_H */