2 * Copyright (c) 1998-2007 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * The SFLOW protocol as per http://www.sflow.org/developers/specifications.php
17 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
19 * Expansion and refactoring by Rick Jones <rick.jones2@hp.com>
26 #include <tcpdump-stdinc.h>
28 #include "interface.h"
30 #include "addrtoname.h"
36 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Sflow version (2,4,5) |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | IP version (1 for IPv4 | 2 for IPv6) |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | IP Address AGENT (4 or 16 bytes) |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Datagram sequence number |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Switch uptime in ms |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | num samples in datagram |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 struct sflow_datagram_t
{
57 uint8_t ip_version
[4];
65 struct sflow_sample_header
{
70 #define SFLOW_FLOW_SAMPLE 1
71 #define SFLOW_COUNTER_SAMPLE 2
72 #define SFLOW_EXPANDED_FLOW_SAMPLE 3
73 #define SFLOW_EXPANDED_COUNTER_SAMPLE 4
75 static const struct tok sflow_format_values
[] = {
76 { SFLOW_FLOW_SAMPLE
, "flow sample" },
77 { SFLOW_COUNTER_SAMPLE
, "counter sample" },
78 { SFLOW_EXPANDED_FLOW_SAMPLE
, "expanded flow sample" },
79 { SFLOW_EXPANDED_COUNTER_SAMPLE
, "expanded counter sample" },
83 struct sflow_flow_sample_t
{
85 uint8_t typesource
[4];
89 uint8_t in_interface
[4];
90 uint8_t out_interface
[4];
95 struct sflow_expanded_flow_sample_t
{
102 uint8_t in_interface_format
[4];
103 uint8_t in_interface_value
[4];
104 uint8_t out_interface_format
[4];
105 uint8_t out_interface_value
[4];
109 #define SFLOW_FLOW_RAW_PACKET 1
110 #define SFLOW_FLOW_ETHERNET_FRAME 2
111 #define SFLOW_FLOW_IPV4_DATA 3
112 #define SFLOW_FLOW_IPV6_DATA 4
113 #define SFLOW_FLOW_EXTENDED_SWITCH_DATA 1001
114 #define SFLOW_FLOW_EXTENDED_ROUTER_DATA 1002
115 #define SFLOW_FLOW_EXTENDED_GATEWAY_DATA 1003
116 #define SFLOW_FLOW_EXTENDED_USER_DATA 1004
117 #define SFLOW_FLOW_EXTENDED_URL_DATA 1005
118 #define SFLOW_FLOW_EXTENDED_MPLS_DATA 1006
119 #define SFLOW_FLOW_EXTENDED_NAT_DATA 1007
120 #define SFLOW_FLOW_EXTENDED_MPLS_TUNNEL 1008
121 #define SFLOW_FLOW_EXTENDED_MPLS_VC 1009
122 #define SFLOW_FLOW_EXTENDED_MPLS_FEC 1010
123 #define SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC 1011
124 #define SFLOW_FLOW_EXTENDED_VLAN_TUNNEL 1012
126 static const struct tok sflow_flow_type_values
[] = {
127 { SFLOW_FLOW_RAW_PACKET
, "Raw packet"},
128 { SFLOW_FLOW_ETHERNET_FRAME
, "Ethernet frame"},
129 { SFLOW_FLOW_IPV4_DATA
, "IPv4 Data"},
130 { SFLOW_FLOW_IPV6_DATA
, "IPv6 Data"},
131 { SFLOW_FLOW_EXTENDED_SWITCH_DATA
, "Extended Switch data"},
132 { SFLOW_FLOW_EXTENDED_ROUTER_DATA
, "Extended Router data"},
133 { SFLOW_FLOW_EXTENDED_GATEWAY_DATA
, "Extended Gateway data"},
134 { SFLOW_FLOW_EXTENDED_USER_DATA
, "Extended User data"},
135 { SFLOW_FLOW_EXTENDED_URL_DATA
, "Extended URL data"},
136 { SFLOW_FLOW_EXTENDED_MPLS_DATA
, "Extended MPLS data"},
137 { SFLOW_FLOW_EXTENDED_NAT_DATA
, "Extended NAT data"},
138 { SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
, "Extended MPLS tunnel"},
139 { SFLOW_FLOW_EXTENDED_MPLS_VC
, "Extended MPLS VC"},
140 { SFLOW_FLOW_EXTENDED_MPLS_FEC
, "Extended MPLS FEC"},
141 { SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
, "Extended MPLS LVP FEC"},
142 { SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
, "Extended VLAN Tunnel"},
146 #define SFLOW_HEADER_PROTOCOL_ETHERNET 1
147 #define SFLOW_HEADER_PROTOCOL_IPV4 11
148 #define SFLOW_HEADER_PROTOCOL_IPV6 12
150 static const struct tok sflow_flow_raw_protocol_values
[] = {
151 { SFLOW_HEADER_PROTOCOL_ETHERNET
, "Ethernet"},
152 { SFLOW_HEADER_PROTOCOL_IPV4
, "IPv4"},
153 { SFLOW_HEADER_PROTOCOL_IPV6
, "IPv6"},
157 struct sflow_expanded_flow_raw_t
{
160 uint8_t stripped_bytes
[4];
161 uint8_t header_size
[4];
164 struct sflow_ethernet_frame_t
{
171 struct sflow_extended_switch_data_t
{
178 struct sflow_counter_record_t
{
183 struct sflow_flow_record_t
{
188 struct sflow_counter_sample_t
{
190 uint8_t typesource
[4];
194 struct sflow_expanded_counter_sample_t
{
201 #define SFLOW_COUNTER_GENERIC 1
202 #define SFLOW_COUNTER_ETHERNET 2
203 #define SFLOW_COUNTER_TOKEN_RING 3
204 #define SFLOW_COUNTER_BASEVG 4
205 #define SFLOW_COUNTER_VLAN 5
206 #define SFLOW_COUNTER_PROCESSOR 1001
208 static const struct tok sflow_counter_type_values
[] = {
209 { SFLOW_COUNTER_GENERIC
, "Generic counter"},
210 { SFLOW_COUNTER_ETHERNET
, "Ethernet counter"},
211 { SFLOW_COUNTER_TOKEN_RING
, "Token ring counter"},
212 { SFLOW_COUNTER_BASEVG
, "100 BaseVG counter"},
213 { SFLOW_COUNTER_VLAN
, "Vlan counter"},
214 { SFLOW_COUNTER_PROCESSOR
, "Processor counter"},
218 #define SFLOW_IFACE_DIRECTION_UNKNOWN 0
219 #define SFLOW_IFACE_DIRECTION_FULLDUPLEX 1
220 #define SFLOW_IFACE_DIRECTION_HALFDUPLEX 2
221 #define SFLOW_IFACE_DIRECTION_IN 3
222 #define SFLOW_IFACE_DIRECTION_OUT 4
224 static const struct tok sflow_iface_direction_values
[] = {
225 { SFLOW_IFACE_DIRECTION_UNKNOWN
, "unknown"},
226 { SFLOW_IFACE_DIRECTION_FULLDUPLEX
, "full-duplex"},
227 { SFLOW_IFACE_DIRECTION_HALFDUPLEX
, "half-duplex"},
228 { SFLOW_IFACE_DIRECTION_IN
, "in"},
229 { SFLOW_IFACE_DIRECTION_OUT
, "out"},
233 struct sflow_generic_counter_t
{
237 uint8_t ifdirection
[4];
239 uint8_t ifinoctets
[8];
240 uint8_t ifinunicastpkts
[4];
241 uint8_t ifinmulticastpkts
[4];
242 uint8_t ifinbroadcastpkts
[4];
243 uint8_t ifindiscards
[4];
244 uint8_t ifinerrors
[4];
245 uint8_t ifinunkownprotos
[4];
246 uint8_t ifoutoctets
[8];
247 uint8_t ifoutunicastpkts
[4];
248 uint8_t ifoutmulticastpkts
[4];
249 uint8_t ifoutbroadcastpkts
[4];
250 uint8_t ifoutdiscards
[4];
251 uint8_t ifouterrors
[4];
252 uint8_t ifpromiscmode
[4];
255 struct sflow_ethernet_counter_t
{
256 uint8_t alignerrors
[4];
257 uint8_t fcserrors
[4];
258 uint8_t single_collision_frames
[4];
259 uint8_t multiple_collision_frames
[4];
260 uint8_t test_errors
[4];
261 uint8_t deferred_transmissions
[4];
262 uint8_t late_collisions
[4];
263 uint8_t excessive_collisions
[4];
264 uint8_t mac_transmit_errors
[4];
265 uint8_t carrier_sense_errors
[4];
266 uint8_t frame_too_longs
[4];
267 uint8_t mac_receive_errors
[4];
268 uint8_t symbol_errors
[4];
271 struct sflow_100basevg_counter_t
{
272 uint8_t in_highpriority_frames
[4];
273 uint8_t in_highpriority_octets
[8];
274 uint8_t in_normpriority_frames
[4];
275 uint8_t in_normpriority_octets
[8];
276 uint8_t in_ipmerrors
[4];
277 uint8_t in_oversized
[4];
278 uint8_t in_data_errors
[4];
279 uint8_t in_null_addressed_frames
[4];
280 uint8_t out_highpriority_frames
[4];
281 uint8_t out_highpriority_octets
[8];
282 uint8_t transitioninto_frames
[4];
283 uint8_t hc_in_highpriority_octets
[8];
284 uint8_t hc_in_normpriority_octets
[8];
285 uint8_t hc_out_highpriority_octets
[8];
288 struct sflow_vlan_counter_t
{
291 uint8_t unicast_pkt
[4];
292 uint8_t multicast_pkt
[4];
293 uint8_t broadcast_pkt
[4];
298 print_sflow_counter_generic(netdissect_options
*ndo
,
299 const u_char
*pointer
, u_int len
)
301 const struct sflow_generic_counter_t
*sflow_gen_counter
;
303 if (len
< sizeof(struct sflow_generic_counter_t
))
307 sflow_gen_counter
= (const struct sflow_generic_counter_t
*)pointer
;
308 ND_PRINT((ndo
, "\n\t ifindex %u, iftype %u, ifspeed %" PRIu64
", ifdirection %u (%s)",
309 EXTRACT_32BITS(sflow_gen_counter
->ifindex
),
310 EXTRACT_32BITS(sflow_gen_counter
->iftype
),
311 EXTRACT_64BITS(sflow_gen_counter
->ifspeed
),
312 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
),
313 tok2str(sflow_iface_direction_values
, "Unknown",
314 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
))));
315 ND_PRINT((ndo
, "\n\t ifstatus %u, adminstatus: %s, operstatus: %s",
316 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
),
317 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)&1 ? "up" : "down",
318 (EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)>>1)&1 ? "up" : "down"));
319 ND_PRINT((ndo
, "\n\t In octets %" PRIu64
320 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
321 EXTRACT_64BITS(sflow_gen_counter
->ifinoctets
),
322 EXTRACT_32BITS(sflow_gen_counter
->ifinunicastpkts
),
323 EXTRACT_32BITS(sflow_gen_counter
->ifinmulticastpkts
),
324 EXTRACT_32BITS(sflow_gen_counter
->ifinbroadcastpkts
),
325 EXTRACT_32BITS(sflow_gen_counter
->ifindiscards
)));
326 ND_PRINT((ndo
, "\n\t In errors %u, unknown protos %u",
327 EXTRACT_32BITS(sflow_gen_counter
->ifinerrors
),
328 EXTRACT_32BITS(sflow_gen_counter
->ifinunkownprotos
)));
329 ND_PRINT((ndo
, "\n\t Out octets %" PRIu64
330 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
331 EXTRACT_64BITS(sflow_gen_counter
->ifoutoctets
),
332 EXTRACT_32BITS(sflow_gen_counter
->ifoutunicastpkts
),
333 EXTRACT_32BITS(sflow_gen_counter
->ifoutmulticastpkts
),
334 EXTRACT_32BITS(sflow_gen_counter
->ifoutbroadcastpkts
),
335 EXTRACT_32BITS(sflow_gen_counter
->ifoutdiscards
)));
336 ND_PRINT((ndo
, "\n\t Out errors %u, promisc mode %u",
337 EXTRACT_32BITS(sflow_gen_counter
->ifouterrors
),
338 EXTRACT_32BITS(sflow_gen_counter
->ifpromiscmode
)));
344 print_sflow_counter_ethernet(netdissect_options
*ndo
,
345 const u_char
*pointer
, u_int len
)
347 const struct sflow_ethernet_counter_t
*sflow_eth_counter
;
349 if (len
< sizeof(struct sflow_ethernet_counter_t
))
352 sflow_eth_counter
= (const struct sflow_ethernet_counter_t
*)pointer
;
353 ND_PRINT((ndo
, "\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u",
354 EXTRACT_32BITS(sflow_eth_counter
->alignerrors
),
355 EXTRACT_32BITS(sflow_eth_counter
->fcserrors
),
356 EXTRACT_32BITS(sflow_eth_counter
->single_collision_frames
),
357 EXTRACT_32BITS(sflow_eth_counter
->multiple_collision_frames
),
358 EXTRACT_32BITS(sflow_eth_counter
->test_errors
)));
359 ND_PRINT((ndo
, "\n\t deferred %u, late collision %u, excessive collision %u, mac trans error %u",
360 EXTRACT_32BITS(sflow_eth_counter
->deferred_transmissions
),
361 EXTRACT_32BITS(sflow_eth_counter
->late_collisions
),
362 EXTRACT_32BITS(sflow_eth_counter
->excessive_collisions
),
363 EXTRACT_32BITS(sflow_eth_counter
->mac_transmit_errors
)));
364 ND_PRINT((ndo
, "\n\t carrier error %u, frames too long %u, mac receive errors %u, symbol errors %u",
365 EXTRACT_32BITS(sflow_eth_counter
->carrier_sense_errors
),
366 EXTRACT_32BITS(sflow_eth_counter
->frame_too_longs
),
367 EXTRACT_32BITS(sflow_eth_counter
->mac_receive_errors
),
368 EXTRACT_32BITS(sflow_eth_counter
->symbol_errors
)));
374 print_sflow_counter_token_ring(netdissect_options
*ndo _U_
,
375 const u_char
*pointer _U_
, u_int len _U_
)
381 print_sflow_counter_basevg(netdissect_options
*ndo
,
382 const u_char
*pointer
, u_int len
)
384 const struct sflow_100basevg_counter_t
*sflow_100basevg_counter
;
386 if (len
< sizeof(struct sflow_100basevg_counter_t
))
389 sflow_100basevg_counter
= (const struct sflow_100basevg_counter_t
*)pointer
;
390 ND_PRINT((ndo
, "\n\t in high prio frames %u, in high prio octets %" PRIu64
,
391 EXTRACT_32BITS(sflow_100basevg_counter
->in_highpriority_frames
),
392 EXTRACT_64BITS(sflow_100basevg_counter
->in_highpriority_octets
)));
393 ND_PRINT((ndo
, "\n\t in norm prio frames %u, in norm prio octets %" PRIu64
,
394 EXTRACT_32BITS(sflow_100basevg_counter
->in_normpriority_frames
),
395 EXTRACT_64BITS(sflow_100basevg_counter
->in_normpriority_octets
)));
396 ND_PRINT((ndo
, "\n\t in ipm errors %u, oversized %u, in data errors %u, null addressed frames %u",
397 EXTRACT_32BITS(sflow_100basevg_counter
->in_ipmerrors
),
398 EXTRACT_32BITS(sflow_100basevg_counter
->in_oversized
),
399 EXTRACT_32BITS(sflow_100basevg_counter
->in_data_errors
),
400 EXTRACT_32BITS(sflow_100basevg_counter
->in_null_addressed_frames
)));
401 ND_PRINT((ndo
, "\n\t out high prio frames %u, out high prio octets %" PRIu64
402 ", trans into frames %u",
403 EXTRACT_32BITS(sflow_100basevg_counter
->out_highpriority_frames
),
404 EXTRACT_64BITS(sflow_100basevg_counter
->out_highpriority_octets
),
405 EXTRACT_32BITS(sflow_100basevg_counter
->transitioninto_frames
)));
406 ND_PRINT((ndo
, "\n\t in hc high prio octets %" PRIu64
407 ", in hc norm prio octets %" PRIu64
408 ", out hc high prio octets %" PRIu64
,
409 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_highpriority_octets
),
410 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_normpriority_octets
),
411 EXTRACT_64BITS(sflow_100basevg_counter
->hc_out_highpriority_octets
)));
417 print_sflow_counter_vlan(netdissect_options
*ndo
,
418 const u_char
*pointer
, u_int len
)
420 const struct sflow_vlan_counter_t
*sflow_vlan_counter
;
422 if (len
< sizeof(struct sflow_vlan_counter_t
))
425 sflow_vlan_counter
= (const struct sflow_vlan_counter_t
*)pointer
;
426 ND_PRINT((ndo
, "\n\t vlan_id %u, octets %" PRIu64
427 ", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u",
428 EXTRACT_32BITS(sflow_vlan_counter
->vlan_id
),
429 EXTRACT_64BITS(sflow_vlan_counter
->octets
),
430 EXTRACT_32BITS(sflow_vlan_counter
->unicast_pkt
),
431 EXTRACT_32BITS(sflow_vlan_counter
->multicast_pkt
),
432 EXTRACT_32BITS(sflow_vlan_counter
->broadcast_pkt
),
433 EXTRACT_32BITS(sflow_vlan_counter
->discards
)));
438 struct sflow_processor_counter_t
{
439 uint8_t five_sec_util
[4];
440 uint8_t one_min_util
[4];
441 uint8_t five_min_util
[4];
442 uint8_t total_memory
[8];
443 uint8_t free_memory
[8];
447 print_sflow_counter_processor(netdissect_options
*ndo
,
448 const u_char
*pointer
, u_int len
)
450 const struct sflow_processor_counter_t
*sflow_processor_counter
;
452 if (len
< sizeof(struct sflow_processor_counter_t
))
455 sflow_processor_counter
= (const struct sflow_processor_counter_t
*)pointer
;
456 ND_PRINT((ndo
, "\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64
457 ", total_mem %" PRIu64
,
458 EXTRACT_32BITS(sflow_processor_counter
->five_sec_util
),
459 EXTRACT_32BITS(sflow_processor_counter
->one_min_util
),
460 EXTRACT_32BITS(sflow_processor_counter
->five_min_util
),
461 EXTRACT_64BITS(sflow_processor_counter
->total_memory
),
462 EXTRACT_64BITS(sflow_processor_counter
->free_memory
)));
468 sflow_print_counter_records(netdissect_options
*ndo
,
469 const u_char
*pointer
, u_int len
, u_int records
)
477 const struct sflow_counter_record_t
*sflow_counter_record
;
483 while (nrecords
> 0) {
484 /* do we have the "header?" */
485 if (tlen
< sizeof(struct sflow_counter_record_t
))
487 sflow_counter_record
= (const struct sflow_counter_record_t
*)tptr
;
489 enterprise
= EXTRACT_32BITS(sflow_counter_record
->format
);
490 counter_type
= enterprise
& 0x0FFF;
491 enterprise
= enterprise
>> 20;
492 counter_len
= EXTRACT_32BITS(sflow_counter_record
->length
);
493 ND_PRINT((ndo
, "\n\t enterprise %u, %s (%u) length %u",
495 (enterprise
== 0) ? tok2str(sflow_counter_type_values
,"Unknown",counter_type
) : "Unknown",
499 tptr
+= sizeof(struct sflow_counter_record_t
);
500 tlen
-= sizeof(struct sflow_counter_record_t
);
502 if (tlen
< counter_len
)
504 if (enterprise
== 0) {
505 switch (counter_type
) {
506 case SFLOW_COUNTER_GENERIC
:
507 if (print_sflow_counter_generic(ndo
, tptr
, tlen
))
510 case SFLOW_COUNTER_ETHERNET
:
511 if (print_sflow_counter_ethernet(ndo
, tptr
, tlen
))
514 case SFLOW_COUNTER_TOKEN_RING
:
515 if (print_sflow_counter_token_ring(ndo
, tptr
,tlen
))
518 case SFLOW_COUNTER_BASEVG
:
519 if (print_sflow_counter_basevg(ndo
, tptr
, tlen
))
522 case SFLOW_COUNTER_VLAN
:
523 if (print_sflow_counter_vlan(ndo
, tptr
, tlen
))
526 case SFLOW_COUNTER_PROCESSOR
:
527 if (print_sflow_counter_processor(ndo
, tptr
, tlen
))
531 if (ndo
->ndo_vflag
<= 1)
532 print_unknown_data(ndo
, tptr
, "\n\t\t", counter_len
);
546 sflow_print_counter_sample(netdissect_options
*ndo
,
547 const u_char
*pointer
, u_int len
)
549 const struct sflow_counter_sample_t
*sflow_counter_sample
;
556 if (len
< sizeof(struct sflow_counter_sample_t
))
559 sflow_counter_sample
= (const struct sflow_counter_sample_t
*)pointer
;
561 typesource
= EXTRACT_32BITS(sflow_counter_sample
->typesource
);
562 nrecords
= EXTRACT_32BITS(sflow_counter_sample
->records
);
563 type
= typesource
>> 24;
564 index
= typesource
& 0x0FFF;
566 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
567 EXTRACT_32BITS(sflow_counter_sample
->seqnum
),
572 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_counter_sample_t
),
573 len
- sizeof(struct sflow_counter_sample_t
),
579 sflow_print_expanded_counter_sample(netdissect_options
*ndo
,
580 const u_char
*pointer
, u_int len
)
582 const struct sflow_expanded_counter_sample_t
*sflow_expanded_counter_sample
;
586 if (len
< sizeof(struct sflow_expanded_counter_sample_t
))
589 sflow_expanded_counter_sample
= (const struct sflow_expanded_counter_sample_t
*)pointer
;
591 nrecords
= EXTRACT_32BITS(sflow_expanded_counter_sample
->records
);
593 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
594 EXTRACT_32BITS(sflow_expanded_counter_sample
->seqnum
),
595 EXTRACT_32BITS(sflow_expanded_counter_sample
->type
),
596 EXTRACT_32BITS(sflow_expanded_counter_sample
->index
),
599 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_expanded_counter_sample_t
),
600 len
- sizeof(struct sflow_expanded_counter_sample_t
),
606 print_sflow_raw_packet(netdissect_options
*ndo
,
607 const u_char
*pointer
, u_int len
)
609 const struct sflow_expanded_flow_raw_t
*sflow_flow_raw
;
611 if (len
< sizeof(struct sflow_expanded_flow_raw_t
))
614 sflow_flow_raw
= (const struct sflow_expanded_flow_raw_t
*)pointer
;
615 ND_PRINT((ndo
, "\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u",
616 tok2str(sflow_flow_raw_protocol_values
,"Unknown",EXTRACT_32BITS(sflow_flow_raw
->protocol
)),
617 EXTRACT_32BITS(sflow_flow_raw
->protocol
),
618 EXTRACT_32BITS(sflow_flow_raw
->length
),
619 EXTRACT_32BITS(sflow_flow_raw
->stripped_bytes
),
620 EXTRACT_32BITS(sflow_flow_raw
->header_size
)));
622 /* QUESTION - should we attempt to print the raw header itself?
623 assuming of course there is wnough data present to do so... */
629 print_sflow_ethernet_frame(netdissect_options
*ndo
,
630 const u_char
*pointer
, u_int len
)
632 const struct sflow_ethernet_frame_t
*sflow_ethernet_frame
;
634 if (len
< sizeof(struct sflow_ethernet_frame_t
))
637 sflow_ethernet_frame
= (const struct sflow_ethernet_frame_t
*)pointer
;
639 ND_PRINT((ndo
, "\n\t frame len %u, type %u",
640 EXTRACT_32BITS(sflow_ethernet_frame
->length
),
641 EXTRACT_32BITS(sflow_ethernet_frame
->type
)));
647 print_sflow_extended_switch_data(netdissect_options
*ndo
,
648 const u_char
*pointer
, u_int len
)
650 const struct sflow_extended_switch_data_t
*sflow_extended_sw_data
;
652 if (len
< sizeof(struct sflow_extended_switch_data_t
))
655 sflow_extended_sw_data
= (const struct sflow_extended_switch_data_t
*)pointer
;
656 ND_PRINT((ndo
, "\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u",
657 EXTRACT_32BITS(sflow_extended_sw_data
->src_vlan
),
658 EXTRACT_32BITS(sflow_extended_sw_data
->src_pri
),
659 EXTRACT_32BITS(sflow_extended_sw_data
->dst_vlan
),
660 EXTRACT_32BITS(sflow_extended_sw_data
->dst_pri
)));
666 sflow_print_flow_records(netdissect_options
*ndo
,
667 const u_char
*pointer
, u_int len
, u_int records
)
675 const struct sflow_flow_record_t
*sflow_flow_record
;
681 while (nrecords
> 0) {
682 /* do we have the "header?" */
683 if (tlen
< sizeof(struct sflow_flow_record_t
))
686 sflow_flow_record
= (const struct sflow_flow_record_t
*)tptr
;
688 /* so, the funky encoding means we cannot blythly mask-off
689 bits, we must also check the enterprise. */
691 enterprise
= EXTRACT_32BITS(sflow_flow_record
->format
);
692 flow_type
= enterprise
& 0x0FFF;
693 enterprise
= enterprise
>> 12;
694 flow_len
= EXTRACT_32BITS(sflow_flow_record
->length
);
695 ND_PRINT((ndo
, "\n\t enterprise %u %s (%u) length %u",
697 (enterprise
== 0) ? tok2str(sflow_flow_type_values
,"Unknown",flow_type
) : "Unknown",
701 tptr
+= sizeof(struct sflow_flow_record_t
);
702 tlen
-= sizeof(struct sflow_flow_record_t
);
707 if (enterprise
== 0) {
709 case SFLOW_FLOW_RAW_PACKET
:
710 if (print_sflow_raw_packet(ndo
, tptr
, tlen
))
713 case SFLOW_FLOW_EXTENDED_SWITCH_DATA
:
714 if (print_sflow_extended_switch_data(ndo
, tptr
, tlen
))
717 case SFLOW_FLOW_ETHERNET_FRAME
:
718 if (print_sflow_ethernet_frame(ndo
, tptr
, tlen
))
721 /* FIXME these need a decoder */
722 case SFLOW_FLOW_IPV4_DATA
:
723 case SFLOW_FLOW_IPV6_DATA
:
724 case SFLOW_FLOW_EXTENDED_ROUTER_DATA
:
725 case SFLOW_FLOW_EXTENDED_GATEWAY_DATA
:
726 case SFLOW_FLOW_EXTENDED_USER_DATA
:
727 case SFLOW_FLOW_EXTENDED_URL_DATA
:
728 case SFLOW_FLOW_EXTENDED_MPLS_DATA
:
729 case SFLOW_FLOW_EXTENDED_NAT_DATA
:
730 case SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
:
731 case SFLOW_FLOW_EXTENDED_MPLS_VC
:
732 case SFLOW_FLOW_EXTENDED_MPLS_FEC
:
733 case SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
:
734 case SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
:
737 if (ndo
->ndo_vflag
<= 1)
738 print_unknown_data(ndo
, tptr
, "\n\t\t", flow_len
);
752 sflow_print_flow_sample(netdissect_options
*ndo
,
753 const u_char
*pointer
, u_int len
)
755 const struct sflow_flow_sample_t
*sflow_flow_sample
;
761 if (len
< sizeof(struct sflow_flow_sample_t
))
764 sflow_flow_sample
= (const struct sflow_flow_sample_t
*)pointer
;
766 typesource
= EXTRACT_32BITS(sflow_flow_sample
->typesource
);
767 nrecords
= EXTRACT_32BITS(sflow_flow_sample
->records
);
768 type
= typesource
>> 24;
769 index
= typesource
& 0x0FFF;
771 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, input %u output %u records %u",
772 EXTRACT_32BITS(sflow_flow_sample
->seqnum
),
775 EXTRACT_32BITS(sflow_flow_sample
->rate
),
776 EXTRACT_32BITS(sflow_flow_sample
->pool
),
777 EXTRACT_32BITS(sflow_flow_sample
->drops
),
778 EXTRACT_32BITS(sflow_flow_sample
->in_interface
),
779 EXTRACT_32BITS(sflow_flow_sample
->out_interface
),
782 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_flow_sample_t
),
783 len
- sizeof(struct sflow_flow_sample_t
),
789 sflow_print_expanded_flow_sample(netdissect_options
*ndo
,
790 const u_char
*pointer
, u_int len
)
792 const struct sflow_expanded_flow_sample_t
*sflow_expanded_flow_sample
;
795 if (len
< sizeof(struct sflow_expanded_flow_sample_t
))
798 sflow_expanded_flow_sample
= (const struct sflow_expanded_flow_sample_t
*)pointer
;
800 nrecords
= EXTRACT_32BITS(sflow_expanded_flow_sample
->records
);
802 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, records %u",
803 EXTRACT_32BITS(sflow_expanded_flow_sample
->seqnum
),
804 EXTRACT_32BITS(sflow_expanded_flow_sample
->type
),
805 EXTRACT_32BITS(sflow_expanded_flow_sample
->index
),
806 EXTRACT_32BITS(sflow_expanded_flow_sample
->rate
),
807 EXTRACT_32BITS(sflow_expanded_flow_sample
->pool
),
808 EXTRACT_32BITS(sflow_expanded_flow_sample
->drops
),
809 EXTRACT_32BITS(sflow_expanded_flow_sample
->records
)));
811 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_expanded_flow_sample_t
),
812 len
- sizeof(struct sflow_expanded_flow_sample_t
),
818 sflow_print(netdissect_options
*ndo
,
819 const u_char
*pptr
, u_int len
)
821 const struct sflow_datagram_t
*sflow_datagram
;
822 const struct sflow_sample_header
*sflow_sample
;
826 uint32_t sflow_sample_type
, sflow_sample_len
;
832 sflow_datagram
= (const struct sflow_datagram_t
*)pptr
;
833 ND_TCHECK(*sflow_datagram
);
836 * Sanity checking of the header.
838 if (EXTRACT_32BITS(sflow_datagram
->version
) != 5) {
839 ND_PRINT((ndo
, "sFlow version %u packet not supported",
840 EXTRACT_32BITS(sflow_datagram
->version
)));
844 if (ndo
->ndo_vflag
< 1) {
845 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, length %u",
846 EXTRACT_32BITS(sflow_datagram
->version
),
847 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
848 ipaddr_string(ndo
, sflow_datagram
->agent
),
849 EXTRACT_32BITS(sflow_datagram
->agent_id
),
854 /* ok they seem to want to know everything - lets fully decode it */
855 nsamples
=EXTRACT_32BITS(sflow_datagram
->samples
);
856 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
857 EXTRACT_32BITS(sflow_datagram
->version
),
858 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
859 ipaddr_string(ndo
, sflow_datagram
->agent
),
860 EXTRACT_32BITS(sflow_datagram
->agent_id
),
861 EXTRACT_32BITS(sflow_datagram
->seqnum
),
862 EXTRACT_32BITS(sflow_datagram
->uptime
),
866 /* skip Common header */
867 tptr
+= sizeof(const struct sflow_datagram_t
);
868 tlen
-= sizeof(const struct sflow_datagram_t
);
870 while (nsamples
> 0 && tlen
> 0) {
871 sflow_sample
= (const struct sflow_sample_header
*)tptr
;
872 ND_TCHECK(*sflow_sample
);
874 sflow_sample_type
= (EXTRACT_32BITS(sflow_sample
->format
)&0x0FFF);
875 sflow_sample_len
= EXTRACT_32BITS(sflow_sample
->len
);
877 if (tlen
< sizeof(struct sflow_sample_header
))
880 tptr
+= sizeof(struct sflow_sample_header
);
881 tlen
-= sizeof(struct sflow_sample_header
);
883 ND_PRINT((ndo
, "\n\t%s (%u), length %u,",
884 tok2str(sflow_format_values
, "Unknown", sflow_sample_type
),
888 /* basic sanity check */
889 if (sflow_sample_type
== 0 || sflow_sample_len
==0) {
893 if (tlen
< sflow_sample_len
)
896 /* did we capture enough for fully decoding the sample ? */
897 ND_TCHECK2(*tptr
, sflow_sample_len
);
899 switch(sflow_sample_type
) {
900 case SFLOW_FLOW_SAMPLE
:
901 if (sflow_print_flow_sample(ndo
, tptr
, tlen
))
905 case SFLOW_COUNTER_SAMPLE
:
906 if (sflow_print_counter_sample(ndo
, tptr
,tlen
))
910 case SFLOW_EXPANDED_FLOW_SAMPLE
:
911 if (sflow_print_expanded_flow_sample(ndo
, tptr
, tlen
))
915 case SFLOW_EXPANDED_COUNTER_SAMPLE
:
916 if (sflow_print_expanded_counter_sample(ndo
, tptr
,tlen
))
921 if (ndo
->ndo_vflag
<= 1)
922 print_unknown_data(ndo
, tptr
, "\n\t ", sflow_sample_len
);
925 tptr
+= sflow_sample_len
;
926 tlen
-= sflow_sample_len
;
932 ND_PRINT((ndo
, "[|SFLOW]"));
937 * c-style: whitesmith