4ede900867fbdce6c4e554011887550312bba074
[fprobe-ulog.git] / src / netflow.c
1 /*
2         Copyright (C) Slava Astashonok <sla@0n.ru>
3
4         This program is free software; you can redistribute it and/or
5         modify it under the terms of the GNU General Public License.
6
7         $Id: netflow.c,v 1.2.2.4 2004/02/02 08:06:24 sla Exp $
8 */
9
10 #include <common.h>
11
12 #include <netflow.h>
13
14 static uint16_t NetFlow1_Header[] = {
15         NETFLOW_VERSION,
16         NETFLOW_COUNT,
17         NETFLOW_UPTIME,
18         NETFLOW_UNIX_SECS,
19         NETFLOW_UNIX_NSECS
20 };
21
22 static uint16_t NetFlow1_Flow[] = {
23         NETFLOW_IPV4_SRC_ADDR,
24         NETFLOW_IPV4_DST_ADDR,
25         NETFLOW_IPV4_NEXT_HOP,
26         NETFLOW_INPUT_SNMP,
27         NETFLOW_OUTPUT_SNMP,
28         NETFLOW_PKTS_32,
29         NETFLOW_BYTES_32,
30         NETFLOW_FIRST_SWITCHED,
31         NETFLOW_LAST_SWITCHED,
32         NETFLOW_L4_SRC_PORT,
33         NETFLOW_L4_DST_PORT,
34         NETFLOW_PAD16,
35         NETFLOW_PROT,
36         NETFLOW_SRC_TOS,
37         NETFLOW_TCP_FLAGS,
38         NETFLOW_PAD8, NETFLOW_PAD8, NETFLOW_PAD8,
39         NETFLOW_PAD32
40 };
41
42 static uint16_t NetFlow5_Header[] = {
43         NETFLOW_VERSION,
44         NETFLOW_COUNT,
45         NETFLOW_UPTIME,
46         NETFLOW_UNIX_SECS,
47         NETFLOW_UNIX_NSECS,
48         NETFLOW_FLOW_SEQUENCE,
49         NETFLOW_ENGINE_TYPE,
50         NETFLOW_ENGINE_ID,
51         NETFLOW_PAD16
52 };
53
54 static uint16_t NetFlow5_Flow[] = {
55         NETFLOW_IPV4_SRC_ADDR,
56         NETFLOW_IPV4_DST_ADDR,
57         NETFLOW_IPV4_NEXT_HOP,
58         NETFLOW_INPUT_SNMP,
59         NETFLOW_OUTPUT_SNMP,
60         NETFLOW_PKTS_32,
61         NETFLOW_BYTES_32,
62         NETFLOW_FIRST_SWITCHED,
63         NETFLOW_LAST_SWITCHED,
64         NETFLOW_L4_SRC_PORT,
65         NETFLOW_L4_DST_PORT,
66         NETFLOW_PAD8,
67         NETFLOW_TCP_FLAGS,
68         NETFLOW_PROT,
69         NETFLOW_SRC_TOS,
70         NETFLOW_SRC_AS,
71         NETFLOW_DST_AS,
72         NETFLOW_XID
73         /*
74          * Who needs the src and dst masks... Or deal
75          * with this later - Sapan
76         NETFLOW_SRC_MASK,
77         NETFLOW_DST_MASK,
78         NETFLOW_PAD16 */
79 };
80
81 static uint16_t NetFlow7_Header[] = {
82         NETFLOW_VERSION,
83         NETFLOW_COUNT,
84         NETFLOW_UPTIME,
85         NETFLOW_UNIX_SECS,
86         NETFLOW_UNIX_NSECS,
87         NETFLOW_FLOW_SEQUENCE,
88         NETFLOW_PAD32
89 };
90
91 static uint16_t NetFlow7_Flow[] = {
92         NETFLOW_IPV4_SRC_ADDR,
93         NETFLOW_IPV4_DST_ADDR,
94         NETFLOW_IPV4_NEXT_HOP,
95         NETFLOW_INPUT_SNMP,
96         NETFLOW_OUTPUT_SNMP,
97         NETFLOW_PKTS_32,
98         NETFLOW_BYTES_32,
99         NETFLOW_FIRST_SWITCHED,
100         NETFLOW_LAST_SWITCHED,
101         NETFLOW_L4_SRC_PORT,
102         NETFLOW_L4_DST_PORT,
103         NETFLOW_FLAGS7_1,
104         NETFLOW_TCP_FLAGS,
105         NETFLOW_PROT,
106         NETFLOW_SRC_TOS,
107         NETFLOW_SRC_AS,
108         NETFLOW_DST_AS,
109         NETFLOW_SRC_MASK,
110         NETFLOW_DST_MASK,
111         NETFLOW_FLAGS7_2,
112         NETFLOW_ROUTER_SC
113 };
114
115 struct NetFlow NetFlow1 = {
116         NETFLOW1_VERSION,
117         NETFLOW1_HEADER_SIZE,
118         NETFLOW1_MAX_FLOWS,
119         NETFLOW1_FLOW_SIZE,
120         NETFLOW1_SEQ_OFFSET,
121         sizeof(NetFlow1_Header) / sizeof(uint16_t),
122         NetFlow1_Header,
123         sizeof(NetFlow1_Flow) / sizeof(uint16_t),
124         NetFlow1_Flow
125 };
126
127 struct NetFlow NetFlow5 = {
128         NETFLOW5_VERSION,
129         NETFLOW5_HEADER_SIZE,
130         NETFLOW5_MAX_FLOWS,
131         NETFLOW5_FLOW_SIZE,
132         NETFLOW5_SEQ_OFFSET,
133         sizeof(NetFlow5_Header) / sizeof(uint16_t),
134         NetFlow5_Header,
135         sizeof(NetFlow5_Flow) / sizeof(uint16_t),
136         NetFlow5_Flow
137 };
138
139 struct NetFlow NetFlow7 = {
140         NETFLOW7_VERSION,
141         NETFLOW7_HEADER_SIZE,
142         NETFLOW7_MAX_FLOWS,
143         NETFLOW7_FLOW_SIZE,
144         NETFLOW7_SEQ_OFFSET,
145         sizeof(NetFlow7_Header) / sizeof(uint16_t),
146         NetFlow7_Header,
147         sizeof(NetFlow7_Flow) / sizeof(uint16_t),
148         NetFlow7_Flow
149 };