summaryrefslogtreecommitdiff
path: root/2005/flow-accounting-lt2005/flow-accounting-lt2005.mgp
blob: 601eb889e4feae549cecd75c199f0a653896585a (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
%include "default.mgp"
%default 1 bgrad
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
%nodefault
%back "blue"

%center
%size 7


Flow-based network accounting with Linux
OLS 2005 (July 22, 2005)

%center
%size 4
by

Harald Welte <hwelte@hmw-consulting.de>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
Contents

	Introduction
	Network Acounting
	Existing Tools
	ip_conntrack_acct
	ctnetlink / conntrack tool
	ulogd2

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page 
Flow-based network accounting with Linux
Introduction

	Who is speaking to you?
		an independent Free Software developer
		who earns his living off Free Software since 1997
		who is one of the authors of the linux kernel firewall system called netfilter/iptables
		who has recently given lots of non-technical presentations about GPL enforcement
		who is happy to again speak about a technical subject today


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
Network Accounting


	Counting of metadata of network traffic
	Optionally Summarizing
	Kind of metadate dependant on application
		number of packets
		number of bytes
	Scope
		per timeframe
		per connection
		per flow


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
Network Accounting


	Reasons for network accounting
		volume or bandwith based billing
		monitoring of network utilization / disstribution
		research on network usage patterns, ...


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
Existing accounting solutions


	Existing accounting solutions for Linux
		nacctd (net-acct)
		ipt_LOG based
		ipt_ULOG based
		iptables-based (ipac-ng)
		ipt_ACCOUNT
		ntop


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
nacctd / net-acct


	nacctd
		Oldest tool available, at least since 1995
		Originally developed by Ulrich Callmeier
		Later unmaintained, multiple forks
		Principle of operation:
			Capture all packets using libpcap (AF_PACKET)
			try to aggregate packets into flows
			log to ASCII file (some branches provide SQL backends)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ipt_LOG based


	ipt_LOG
		iptables "LOG" target, available in all 2.4.x and 2.6.x kernels
		Designed to log policy violations, not accounting data
		Not intended for logging of high data volumes
		Principle of Operation
			Iptables rule with "LOG" target for to-be-logged packets
			syslogd writes one line for each packet
			Perl scripts (or similar) used to parse syslog files
		Summary
			Doesn't scale since it abuses ipt_LOG for unintended purpose

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ipt_ULOG based


	ipt_ULOG
		iptables "ULOG" target, available in almost all 2.4.x and 2.6.x kernels
		Designed to efficiently log policy violations, not accounting data
		Principle of Operation
			Copy header of packets into buffer
			Flush buffer to userspace
			Have a daemon parse packet headers in buffer
			Write information to some form of storage
		Summary
			Scales way better than ipt_LOG
			I still abusing an interface for a different purpose
			Still needs to transfer all packets to userspace

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_tables counter based


	Accounting based on ip_tables
		Every ip_tables ruleset has per-rule packet and byte counters
		A number of ready-built tools exist to parse and summarize
		Most commonly used is "ipac-ng", supports storage in SQL DB
		Principle of Operation
			Careful placement of fallthrough-rules
			Executing "iptables -L -vn" or "iptables-save -c" displays counters
			Counters can be reset by "iptables -Z"
		Summary
			Scales well with high traffic
			Scales badly for lots of different accounting groups (which require lots of rules)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ipt_ACCOUNT


	ipt_ACCOUNT
		http://www.intra2net.com/opensource/ipt_account/
		A special purpose iptables target, requires kernel patch
		Principle of Operation
			Keeps byte counters per IP address in a given subnet (/24, eg.)
			Counters can be read by special "iptaccount" commandline tool
		Summary
			Is limited to networks up to /8
			Granularity only down to per-ip level
			Highly optimized, but special-purpose

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


	ip_conntrack based accounting
		The netfilter connection tracking subsystem runs on almost any firewall
		Accounting is usually done at the edge of a network, where a firewall is placed
		ip_conntrack already maintains some ~ 350 bytes of state per connection
		Principle of Operation
			Add per-connection, per-direction packet and byte counters
			Read the counters from userspace (/proc/net/ip_conntrack or ctnetlink-based)
		Summary
			adds little extra overhead if ip_conntrack is used already
			Not recommended for non-firewall systems


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


Userpace interfaces
	/proc/net/ip_conntrack
		shows one line per connection
		if CONFIG_IP_NF_CT_ACCT is enabled, "packets=5749 bytes=423453" is added for each direction
		Pro:
			Easy to use
		Con:
			Not always accurate
			No way to reset counters
			Inefficient

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


	ctnetlink based interface
		What is ctnetlink?
			it's a netlink-based interface to ip_conntrack
			allows reading/deleting/updating/creating conntrack entries from usrspace
			exists as out-of-kernel patch for many years
		Extending ctnetlink with ip_conntrack_acct
			Simple: Add counter information to TLV's passed from kernel to userspace
		Additional features
			Add new IPCTNL_MSG_CT_GET_CTRZERO command request for atomic get-counters-and-zero


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


Possible ctnetlink based implementations
	polling-based
		use GET_CTRZERO in a regular sampling interval
		add up counters with every call
		Pro: configurable granularity
		Con: overhead increases with short samling interval
	event-based
		listen for ctnetlink DELETE event messages
		store flow-based information only once at the end of every connection
		Pro: Very easy to implement
		Con: Data only available after connection finishes

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


Programs to use ip_conntrack_acct
	'conntrack' tool
		http://svn.netfilter.org/trunk/conntrack
		Try "conntrack -E conntrack" for event-based output
		Try "conntrack -L conntrack" for polling
		Try "conntrack -L conntrack -z" for poll with zeroing counters

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
ip_conntrack_acct


Programs to use ip_conntrack_acct
	ulogd2
		http://svn.netfilter.org/branches/ulogd2
		next-gerneration of 'ulogd'
		can log per-packet and per-flow information
		can aggregate per-packet to per-flow information
		can run multiple 'plugin stacks' for multiple outputs
		can export per-flow data in IPFIX format
		is not fully implemented yet, but pretty far ahead

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%page
Flow-based network accounting with Linux
Thanks

	Thanks to
		Alan Cox, Alexey Kuznetsov, David Miller, Andi Kleen
			for implementing (one of?) the world's best TCP/IP stacks
		Paul 'Rusty' Russell
			for starting the netfilter/iptables project
			for trusting me to maintain it today
		Astaro AG
			for sponsoring parts of my netfilter work
		Free Software Foundation
			for the GNU Project 
			for the GNU General Public License
%size 3
	http://gnumonks.org/
%size 3
	http://netfilter.org/
%size 3
	http://svn.netfilter.org/

personal git repositories of Harald Welte. Your mileage may vary