-
Notifications
You must be signed in to change notification settings - Fork 31
/
ipfix.h
161 lines (148 loc) · 5.28 KB
/
ipfix.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright 2019 Hitoshi Irino <[email protected]> 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.
*/
#ifndef _IPFIX_H
#define _IPFIX_H
#include "softflowd.h"
#define IPFIX_TEMPLATE_SET_ID 2
#define IPFIX_OPTION_TEMPLATE_SET_ID 3
#define IPFIX_MIN_RECORD_SET_ID 256
/* Flowset record ies the we care about */
#define IPFIX_octetDeltaCount 1
#define IPFIX_packetDeltaCount 2
/* ... */
#define IPFIX_protocolIdentifier 4
#define IPFIX_ipClassOfService 5
/* ... */
#define IPFIX_tcpControlBits 6
#define IPFIX_sourceTransportPort 7
#define IPFIX_sourceIPv4Address 8
/* ... */
#define IPFIX_ingressInterface 10
#define IPFIX_destinationTransportPort 11
#define IPFIX_destinationIPv4Address 12
/* ... */
#define IPFIX_egressInterface 14
/* ... */
#define IPFIX_flowEndSysUpTime 21
#define IPFIX_flowStartSysUpTime 22
/* ... */
#define IPFIX_sourceIPv6Address 27
#define IPFIX_destinationIPv6Address 28
/* ... */
#define IPFIX_icmpTypeCodeIPv4 32
/* ... */
#define IPFIX_sourceMacAddress 56
#define IPFIX_postDestinationMacAddress 57
#define IPFIX_vlanId 58
#define IPFIX_postVlanId 59
#define IPFIX_ipVersion 60
#define IPFIX_flowDirection 61
#define IPFIX_mplsTopLabelStackSection 70
/* ... */
#define IPFIX_interfaceName 82
/* ... */
#define IPFIX_exporterIPv4Address 130
#define IPFIX_exporterIPv6Address 131
/* ... */
#define IPFIX_flowEndReason 136
/* ... */
#define IPFIX_icmpTypeCodeIPv6 139
/* ... */
#define IPFIX_meteringProcessId 143
/* ... */
#define IPFIX_flowStartSeconds 150
#define IPFIX_flowEndSeconds 151
#define IPFIX_flowStartMilliSeconds 152
#define IPFIX_flowEndMilliSeconds 153
#define IPFIX_flowStartMicroSeconds 154
#define IPFIX_flowEndMicroSeconds 155
#define IPFIX_flowStartNanoSeconds 156
#define IPFIX_flowEndNanoSeconds 157
/* ... */
#define IPFIX_systemInitTimeMilliseconds 160
/* ... */
#define IPFIX_originalExporterIPv4Address 403
#define IPFIX_originalExporterIPv6Address 404
/* ... */
// flow end reason for ipfix ie 136
#define IPFIX_flowEndReason_idleTimeout 0x01
#define IPFIX_flowEndReason_activeTimeout 0x02
#define IPFIX_flowEndReason_endOfFlow 0x03
#define IPFIX_flowEndReason_forceEnd 0x04
#define IPFIX_flowEndReason_lackOfResource 0x05
#define IPFIX_SOFTFLOWD_MAX_PACKET_SIZE 1428
#define IPFIX_mplsLabelStackSection_SIZE 3
struct IPFIX_HEADER {
u_int16_t version, length;
u_int32_t export_time; /* in seconds */
u_int32_t sequence, od_id;
} __packed;
struct IPFIX_SET_HEADER {
u_int16_t set_id, length;
} __packed;
struct IPFIX_TEMPLATE_RECORD_HEADER {
u_int16_t template_id, count;
} __packed;
struct IPFIX_TEMPLATE_SET_HEADER {
struct IPFIX_SET_HEADER c;
struct IPFIX_TEMPLATE_RECORD_HEADER r;
} __packed;
struct IPFIX_FIELD_SPECIFIER {
u_int16_t ie, length;
} __packed;
struct IPFIX_OPTION_TEMPLATE_SET_HEADER {
struct IPFIX_SET_HEADER c;
union {
struct {
struct IPFIX_TEMPLATE_RECORD_HEADER r;
u_int16_t scope_count;
} i;
struct {
u_int16_t template_id;
u_int16_t scope_length;
u_int16_t option_length;
} n;
} u;
} __packed;
struct IPFIX_VENDOR_FIELD_SPECIFIER {
u_int16_t ie, length;
u_int32_t pen;
} __packed;
#define REVERSE_PEN 29305
struct ntp_time_t {
uint32_t second;
uint32_t fraction;
};
/* Prototypes for functions to send NetFlow packets */
int send_nflow9 (struct SENDPARAMETER sp);
int send_ipfix (struct SENDPARAMETER sp);
int send_ipfix_bi (struct SENDPARAMETER sp);
/* 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);
#endif /* _IPFIX_H */