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>
22 #include <sys/cdefs.h>
24 __RCSID("$NetBSD: print-sflow.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
27 #define NETDISSECT_REWORKED
32 #include <tcpdump-stdinc.h>
34 #include "interface.h"
36 #include "addrtoname.h"
42 * 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
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Sflow version (2,4,5) |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | IP version (1 for IPv4 | 2 for IPv6) |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | IP Address AGENT (4 or 16 bytes) |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | Datagram sequence number |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * | Switch uptime in ms |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | num samples in datagram |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 struct sflow_datagram_t
{
63 uint8_t ip_version
[4];
71 struct sflow_sample_header
{
76 #define SFLOW_FLOW_SAMPLE 1
77 #define SFLOW_COUNTER_SAMPLE 2
78 #define SFLOW_EXPANDED_FLOW_SAMPLE 3
79 #define SFLOW_EXPANDED_COUNTER_SAMPLE 4
81 static const struct tok sflow_format_values
[] = {
82 { SFLOW_FLOW_SAMPLE
, "flow sample" },
83 { SFLOW_COUNTER_SAMPLE
, "counter sample" },
84 { SFLOW_EXPANDED_FLOW_SAMPLE
, "expanded flow sample" },
85 { SFLOW_EXPANDED_COUNTER_SAMPLE
, "expanded counter sample" },
89 struct sflow_flow_sample_t
{
91 uint8_t typesource
[4];
95 uint8_t in_interface
[4];
96 uint8_t out_interface
[4];
101 struct sflow_expanded_flow_sample_t
{
108 uint8_t in_interface_format
[4];
109 uint8_t in_interface_value
[4];
110 uint8_t out_interface_format
[4];
111 uint8_t out_interface_value
[4];
115 #define SFLOW_FLOW_RAW_PACKET 1
116 #define SFLOW_FLOW_ETHERNET_FRAME 2
117 #define SFLOW_FLOW_IPV4_DATA 3
118 #define SFLOW_FLOW_IPV6_DATA 4
119 #define SFLOW_FLOW_EXTENDED_SWITCH_DATA 1001
120 #define SFLOW_FLOW_EXTENDED_ROUTER_DATA 1002
121 #define SFLOW_FLOW_EXTENDED_GATEWAY_DATA 1003
122 #define SFLOW_FLOW_EXTENDED_USER_DATA 1004
123 #define SFLOW_FLOW_EXTENDED_URL_DATA 1005
124 #define SFLOW_FLOW_EXTENDED_MPLS_DATA 1006
125 #define SFLOW_FLOW_EXTENDED_NAT_DATA 1007
126 #define SFLOW_FLOW_EXTENDED_MPLS_TUNNEL 1008
127 #define SFLOW_FLOW_EXTENDED_MPLS_VC 1009
128 #define SFLOW_FLOW_EXTENDED_MPLS_FEC 1010
129 #define SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC 1011
130 #define SFLOW_FLOW_EXTENDED_VLAN_TUNNEL 1012
132 static const struct tok sflow_flow_type_values
[] = {
133 { SFLOW_FLOW_RAW_PACKET
, "Raw packet"},
134 { SFLOW_FLOW_ETHERNET_FRAME
, "Ethernet frame"},
135 { SFLOW_FLOW_IPV4_DATA
, "IPv4 Data"},
136 { SFLOW_FLOW_IPV6_DATA
, "IPv6 Data"},
137 { SFLOW_FLOW_EXTENDED_SWITCH_DATA
, "Extended Switch data"},
138 { SFLOW_FLOW_EXTENDED_ROUTER_DATA
, "Extended Router data"},
139 { SFLOW_FLOW_EXTENDED_GATEWAY_DATA
, "Extended Gateway data"},
140 { SFLOW_FLOW_EXTENDED_USER_DATA
, "Extended User data"},
141 { SFLOW_FLOW_EXTENDED_URL_DATA
, "Extended URL data"},
142 { SFLOW_FLOW_EXTENDED_MPLS_DATA
, "Extended MPLS data"},
143 { SFLOW_FLOW_EXTENDED_NAT_DATA
, "Extended NAT data"},
144 { SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
, "Extended MPLS tunnel"},
145 { SFLOW_FLOW_EXTENDED_MPLS_VC
, "Extended MPLS VC"},
146 { SFLOW_FLOW_EXTENDED_MPLS_FEC
, "Extended MPLS FEC"},
147 { SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
, "Extended MPLS LVP FEC"},
148 { SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
, "Extended VLAN Tunnel"},
152 #define SFLOW_HEADER_PROTOCOL_ETHERNET 1
153 #define SFLOW_HEADER_PROTOCOL_IPV4 11
154 #define SFLOW_HEADER_PROTOCOL_IPV6 12
156 static const struct tok sflow_flow_raw_protocol_values
[] = {
157 { SFLOW_HEADER_PROTOCOL_ETHERNET
, "Ethernet"},
158 { SFLOW_HEADER_PROTOCOL_IPV4
, "IPv4"},
159 { SFLOW_HEADER_PROTOCOL_IPV6
, "IPv6"},
163 struct sflow_expanded_flow_raw_t
{
166 uint8_t stripped_bytes
[4];
167 uint8_t header_size
[4];
170 struct sflow_ethernet_frame_t
{
177 struct sflow_extended_switch_data_t
{
184 struct sflow_counter_record_t
{
189 struct sflow_flow_record_t
{
194 struct sflow_counter_sample_t
{
196 uint8_t typesource
[4];
200 struct sflow_expanded_counter_sample_t
{
207 #define SFLOW_COUNTER_GENERIC 1
208 #define SFLOW_COUNTER_ETHERNET 2
209 #define SFLOW_COUNTER_TOKEN_RING 3
210 #define SFLOW_COUNTER_BASEVG 4
211 #define SFLOW_COUNTER_VLAN 5
212 #define SFLOW_COUNTER_PROCESSOR 1001
214 static const struct tok sflow_counter_type_values
[] = {
215 { SFLOW_COUNTER_GENERIC
, "Generic counter"},
216 { SFLOW_COUNTER_ETHERNET
, "Ethernet counter"},
217 { SFLOW_COUNTER_TOKEN_RING
, "Token ring counter"},
218 { SFLOW_COUNTER_BASEVG
, "100 BaseVG counter"},
219 { SFLOW_COUNTER_VLAN
, "Vlan counter"},
220 { SFLOW_COUNTER_PROCESSOR
, "Processor counter"},
224 #define SFLOW_IFACE_DIRECTION_UNKNOWN 0
225 #define SFLOW_IFACE_DIRECTION_FULLDUPLEX 1
226 #define SFLOW_IFACE_DIRECTION_HALFDUPLEX 2
227 #define SFLOW_IFACE_DIRECTION_IN 3
228 #define SFLOW_IFACE_DIRECTION_OUT 4
230 static const struct tok sflow_iface_direction_values
[] = {
231 { SFLOW_IFACE_DIRECTION_UNKNOWN
, "unknown"},
232 { SFLOW_IFACE_DIRECTION_FULLDUPLEX
, "full-duplex"},
233 { SFLOW_IFACE_DIRECTION_HALFDUPLEX
, "half-duplex"},
234 { SFLOW_IFACE_DIRECTION_IN
, "in"},
235 { SFLOW_IFACE_DIRECTION_OUT
, "out"},
239 struct sflow_generic_counter_t
{
243 uint8_t ifdirection
[4];
245 uint8_t ifinoctets
[8];
246 uint8_t ifinunicastpkts
[4];
247 uint8_t ifinmulticastpkts
[4];
248 uint8_t ifinbroadcastpkts
[4];
249 uint8_t ifindiscards
[4];
250 uint8_t ifinerrors
[4];
251 uint8_t ifinunkownprotos
[4];
252 uint8_t ifoutoctets
[8];
253 uint8_t ifoutunicastpkts
[4];
254 uint8_t ifoutmulticastpkts
[4];
255 uint8_t ifoutbroadcastpkts
[4];
256 uint8_t ifoutdiscards
[4];
257 uint8_t ifouterrors
[4];
258 uint8_t ifpromiscmode
[4];
261 struct sflow_ethernet_counter_t
{
262 uint8_t alignerrors
[4];
263 uint8_t fcserrors
[4];
264 uint8_t single_collision_frames
[4];
265 uint8_t multiple_collision_frames
[4];
266 uint8_t test_errors
[4];
267 uint8_t deferred_transmissions
[4];
268 uint8_t late_collisions
[4];
269 uint8_t excessive_collisions
[4];
270 uint8_t mac_transmit_errors
[4];
271 uint8_t carrier_sense_errors
[4];
272 uint8_t frame_too_longs
[4];
273 uint8_t mac_receive_errors
[4];
274 uint8_t symbol_errors
[4];
277 struct sflow_100basevg_counter_t
{
278 uint8_t in_highpriority_frames
[4];
279 uint8_t in_highpriority_octets
[8];
280 uint8_t in_normpriority_frames
[4];
281 uint8_t in_normpriority_octets
[8];
282 uint8_t in_ipmerrors
[4];
283 uint8_t in_oversized
[4];
284 uint8_t in_data_errors
[4];
285 uint8_t in_null_addressed_frames
[4];
286 uint8_t out_highpriority_frames
[4];
287 uint8_t out_highpriority_octets
[8];
288 uint8_t transitioninto_frames
[4];
289 uint8_t hc_in_highpriority_octets
[8];
290 uint8_t hc_in_normpriority_octets
[8];
291 uint8_t hc_out_highpriority_octets
[8];
294 struct sflow_vlan_counter_t
{
297 uint8_t unicast_pkt
[4];
298 uint8_t multicast_pkt
[4];
299 uint8_t broadcast_pkt
[4];
304 print_sflow_counter_generic(netdissect_options
*ndo
,
305 const u_char
*pointer
, u_int len
)
307 const struct sflow_generic_counter_t
*sflow_gen_counter
;
309 if (len
< sizeof(struct sflow_generic_counter_t
))
313 sflow_gen_counter
= (const struct sflow_generic_counter_t
*)pointer
;
314 ND_PRINT((ndo
, "\n\t ifindex %u, iftype %u, ifspeed %" PRIu64
", ifdirection %u (%s)",
315 EXTRACT_32BITS(sflow_gen_counter
->ifindex
),
316 EXTRACT_32BITS(sflow_gen_counter
->iftype
),
317 EXTRACT_64BITS(sflow_gen_counter
->ifspeed
),
318 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
),
319 tok2str(sflow_iface_direction_values
, "Unknown",
320 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
))));
321 ND_PRINT((ndo
, "\n\t ifstatus %u, adminstatus: %s, operstatus: %s",
322 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
),
323 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)&1 ? "up" : "down",
324 (EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)>>1)&1 ? "up" : "down"));
325 ND_PRINT((ndo
, "\n\t In octets %" PRIu64
326 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
327 EXTRACT_64BITS(sflow_gen_counter
->ifinoctets
),
328 EXTRACT_32BITS(sflow_gen_counter
->ifinunicastpkts
),
329 EXTRACT_32BITS(sflow_gen_counter
->ifinmulticastpkts
),
330 EXTRACT_32BITS(sflow_gen_counter
->ifinbroadcastpkts
),
331 EXTRACT_32BITS(sflow_gen_counter
->ifindiscards
)));
332 ND_PRINT((ndo
, "\n\t In errors %u, unknown protos %u",
333 EXTRACT_32BITS(sflow_gen_counter
->ifinerrors
),
334 EXTRACT_32BITS(sflow_gen_counter
->ifinunkownprotos
)));
335 ND_PRINT((ndo
, "\n\t Out octets %" PRIu64
336 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
337 EXTRACT_64BITS(sflow_gen_counter
->ifoutoctets
),
338 EXTRACT_32BITS(sflow_gen_counter
->ifoutunicastpkts
),
339 EXTRACT_32BITS(sflow_gen_counter
->ifoutmulticastpkts
),
340 EXTRACT_32BITS(sflow_gen_counter
->ifoutbroadcastpkts
),
341 EXTRACT_32BITS(sflow_gen_counter
->ifoutdiscards
)));
342 ND_PRINT((ndo
, "\n\t Out errors %u, promisc mode %u",
343 EXTRACT_32BITS(sflow_gen_counter
->ifouterrors
),
344 EXTRACT_32BITS(sflow_gen_counter
->ifpromiscmode
)));
350 print_sflow_counter_ethernet(netdissect_options
*ndo
,
351 const u_char
*pointer
, u_int len
)
353 const struct sflow_ethernet_counter_t
*sflow_eth_counter
;
355 if (len
< sizeof(struct sflow_ethernet_counter_t
))
358 sflow_eth_counter
= (const struct sflow_ethernet_counter_t
*)pointer
;
359 ND_PRINT((ndo
, "\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u",
360 EXTRACT_32BITS(sflow_eth_counter
->alignerrors
),
361 EXTRACT_32BITS(sflow_eth_counter
->fcserrors
),
362 EXTRACT_32BITS(sflow_eth_counter
->single_collision_frames
),
363 EXTRACT_32BITS(sflow_eth_counter
->multiple_collision_frames
),
364 EXTRACT_32BITS(sflow_eth_counter
->test_errors
)));
365 ND_PRINT((ndo
, "\n\t deferred %u, late collision %u, excessive collision %u, mac trans error %u",
366 EXTRACT_32BITS(sflow_eth_counter
->deferred_transmissions
),
367 EXTRACT_32BITS(sflow_eth_counter
->late_collisions
),
368 EXTRACT_32BITS(sflow_eth_counter
->excessive_collisions
),
369 EXTRACT_32BITS(sflow_eth_counter
->mac_transmit_errors
)));
370 ND_PRINT((ndo
, "\n\t carrier error %u, frames too long %u, mac receive errors %u, symbol errors %u",
371 EXTRACT_32BITS(sflow_eth_counter
->carrier_sense_errors
),
372 EXTRACT_32BITS(sflow_eth_counter
->frame_too_longs
),
373 EXTRACT_32BITS(sflow_eth_counter
->mac_receive_errors
),
374 EXTRACT_32BITS(sflow_eth_counter
->symbol_errors
)));
380 print_sflow_counter_token_ring(netdissect_options
*ndo _U_
,
381 const u_char
*pointer _U_
, u_int len _U_
)
387 print_sflow_counter_basevg(netdissect_options
*ndo
,
388 const u_char
*pointer
, u_int len
)
390 const struct sflow_100basevg_counter_t
*sflow_100basevg_counter
;
392 if (len
< sizeof(struct sflow_100basevg_counter_t
))
395 sflow_100basevg_counter
= (const struct sflow_100basevg_counter_t
*)pointer
;
396 ND_PRINT((ndo
, "\n\t in high prio frames %u, in high prio octets %" PRIu64
,
397 EXTRACT_32BITS(sflow_100basevg_counter
->in_highpriority_frames
),
398 EXTRACT_64BITS(sflow_100basevg_counter
->in_highpriority_octets
)));
399 ND_PRINT((ndo
, "\n\t in norm prio frames %u, in norm prio octets %" PRIu64
,
400 EXTRACT_32BITS(sflow_100basevg_counter
->in_normpriority_frames
),
401 EXTRACT_64BITS(sflow_100basevg_counter
->in_normpriority_octets
)));
402 ND_PRINT((ndo
, "\n\t in ipm errors %u, oversized %u, in data errors %u, null addressed frames %u",
403 EXTRACT_32BITS(sflow_100basevg_counter
->in_ipmerrors
),
404 EXTRACT_32BITS(sflow_100basevg_counter
->in_oversized
),
405 EXTRACT_32BITS(sflow_100basevg_counter
->in_data_errors
),
406 EXTRACT_32BITS(sflow_100basevg_counter
->in_null_addressed_frames
)));
407 ND_PRINT((ndo
, "\n\t out high prio frames %u, out high prio octets %" PRIu64
408 ", trans into frames %u",
409 EXTRACT_32BITS(sflow_100basevg_counter
->out_highpriority_frames
),
410 EXTRACT_64BITS(sflow_100basevg_counter
->out_highpriority_octets
),
411 EXTRACT_32BITS(sflow_100basevg_counter
->transitioninto_frames
)));
412 ND_PRINT((ndo
, "\n\t in hc high prio octets %" PRIu64
413 ", in hc norm prio octets %" PRIu64
414 ", out hc high prio octets %" PRIu64
,
415 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_highpriority_octets
),
416 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_normpriority_octets
),
417 EXTRACT_64BITS(sflow_100basevg_counter
->hc_out_highpriority_octets
)));
423 print_sflow_counter_vlan(netdissect_options
*ndo
,
424 const u_char
*pointer
, u_int len
)
426 const struct sflow_vlan_counter_t
*sflow_vlan_counter
;
428 if (len
< sizeof(struct sflow_vlan_counter_t
))
431 sflow_vlan_counter
= (const struct sflow_vlan_counter_t
*)pointer
;
432 ND_PRINT((ndo
, "\n\t vlan_id %u, octets %" PRIu64
433 ", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u",
434 EXTRACT_32BITS(sflow_vlan_counter
->vlan_id
),
435 EXTRACT_64BITS(sflow_vlan_counter
->octets
),
436 EXTRACT_32BITS(sflow_vlan_counter
->unicast_pkt
),
437 EXTRACT_32BITS(sflow_vlan_counter
->multicast_pkt
),
438 EXTRACT_32BITS(sflow_vlan_counter
->broadcast_pkt
),
439 EXTRACT_32BITS(sflow_vlan_counter
->discards
)));
444 struct sflow_processor_counter_t
{
445 uint8_t five_sec_util
[4];
446 uint8_t one_min_util
[4];
447 uint8_t five_min_util
[4];
448 uint8_t total_memory
[8];
449 uint8_t free_memory
[8];
453 print_sflow_counter_processor(netdissect_options
*ndo
,
454 const u_char
*pointer
, u_int len
)
456 const struct sflow_processor_counter_t
*sflow_processor_counter
;
458 if (len
< sizeof(struct sflow_processor_counter_t
))
461 sflow_processor_counter
= (const struct sflow_processor_counter_t
*)pointer
;
462 ND_PRINT((ndo
, "\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64
463 ", total_mem %" PRIu64
,
464 EXTRACT_32BITS(sflow_processor_counter
->five_sec_util
),
465 EXTRACT_32BITS(sflow_processor_counter
->one_min_util
),
466 EXTRACT_32BITS(sflow_processor_counter
->five_min_util
),
467 EXTRACT_64BITS(sflow_processor_counter
->total_memory
),
468 EXTRACT_64BITS(sflow_processor_counter
->free_memory
)));
474 sflow_print_counter_records(netdissect_options
*ndo
,
475 const u_char
*pointer
, u_int len
, u_int records
)
483 const struct sflow_counter_record_t
*sflow_counter_record
;
489 while (nrecords
> 0) {
490 /* do we have the "header?" */
491 if (tlen
< sizeof(struct sflow_counter_record_t
))
493 sflow_counter_record
= (const struct sflow_counter_record_t
*)tptr
;
495 enterprise
= EXTRACT_32BITS(sflow_counter_record
->format
);
496 counter_type
= enterprise
& 0x0FFF;
497 enterprise
= enterprise
>> 20;
498 counter_len
= EXTRACT_32BITS(sflow_counter_record
->length
);
499 ND_PRINT((ndo
, "\n\t enterprise %u, %s (%u) length %u",
501 (enterprise
== 0) ? tok2str(sflow_counter_type_values
,"Unknown",counter_type
) : "Unknown",
505 tptr
+= sizeof(struct sflow_counter_record_t
);
506 tlen
-= sizeof(struct sflow_counter_record_t
);
508 if (tlen
< counter_len
)
510 if (enterprise
== 0) {
511 switch (counter_type
) {
512 case SFLOW_COUNTER_GENERIC
:
513 if (print_sflow_counter_generic(ndo
, tptr
, tlen
))
516 case SFLOW_COUNTER_ETHERNET
:
517 if (print_sflow_counter_ethernet(ndo
, tptr
, tlen
))
520 case SFLOW_COUNTER_TOKEN_RING
:
521 if (print_sflow_counter_token_ring(ndo
, tptr
,tlen
))
524 case SFLOW_COUNTER_BASEVG
:
525 if (print_sflow_counter_basevg(ndo
, tptr
, tlen
))
528 case SFLOW_COUNTER_VLAN
:
529 if (print_sflow_counter_vlan(ndo
, tptr
, tlen
))
532 case SFLOW_COUNTER_PROCESSOR
:
533 if (print_sflow_counter_processor(ndo
, tptr
, tlen
))
537 if (ndo
->ndo_vflag
<= 1)
538 print_unknown_data(ndo
, tptr
, "\n\t\t", counter_len
);
552 sflow_print_counter_sample(netdissect_options
*ndo
,
553 const u_char
*pointer
, u_int len
)
555 const struct sflow_counter_sample_t
*sflow_counter_sample
;
562 if (len
< sizeof(struct sflow_counter_sample_t
))
565 sflow_counter_sample
= (const struct sflow_counter_sample_t
*)pointer
;
567 typesource
= EXTRACT_32BITS(sflow_counter_sample
->typesource
);
568 nrecords
= EXTRACT_32BITS(sflow_counter_sample
->records
);
569 type
= typesource
>> 24;
570 index
= typesource
& 0x0FFF;
572 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
573 EXTRACT_32BITS(sflow_counter_sample
->seqnum
),
578 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_counter_sample_t
),
579 len
- sizeof(struct sflow_counter_sample_t
),
585 sflow_print_expanded_counter_sample(netdissect_options
*ndo
,
586 const u_char
*pointer
, u_int len
)
588 const struct sflow_expanded_counter_sample_t
*sflow_expanded_counter_sample
;
592 if (len
< sizeof(struct sflow_expanded_counter_sample_t
))
595 sflow_expanded_counter_sample
= (const struct sflow_expanded_counter_sample_t
*)pointer
;
597 nrecords
= EXTRACT_32BITS(sflow_expanded_counter_sample
->records
);
599 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
600 EXTRACT_32BITS(sflow_expanded_counter_sample
->seqnum
),
601 EXTRACT_32BITS(sflow_expanded_counter_sample
->type
),
602 EXTRACT_32BITS(sflow_expanded_counter_sample
->index
),
605 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_expanded_counter_sample_t
),
606 len
- sizeof(struct sflow_expanded_counter_sample_t
),
612 print_sflow_raw_packet(netdissect_options
*ndo
,
613 const u_char
*pointer
, u_int len
)
615 const struct sflow_expanded_flow_raw_t
*sflow_flow_raw
;
617 if (len
< sizeof(struct sflow_expanded_flow_raw_t
))
620 sflow_flow_raw
= (const struct sflow_expanded_flow_raw_t
*)pointer
;
621 ND_PRINT((ndo
, "\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u",
622 tok2str(sflow_flow_raw_protocol_values
,"Unknown",EXTRACT_32BITS(sflow_flow_raw
->protocol
)),
623 EXTRACT_32BITS(sflow_flow_raw
->protocol
),
624 EXTRACT_32BITS(sflow_flow_raw
->length
),
625 EXTRACT_32BITS(sflow_flow_raw
->stripped_bytes
),
626 EXTRACT_32BITS(sflow_flow_raw
->header_size
)));
628 /* QUESTION - should we attempt to print the raw header itself?
629 assuming of course there is wnough data present to do so... */
635 print_sflow_ethernet_frame(netdissect_options
*ndo
,
636 const u_char
*pointer
, u_int len
)
638 const struct sflow_ethernet_frame_t
*sflow_ethernet_frame
;
640 if (len
< sizeof(struct sflow_ethernet_frame_t
))
643 sflow_ethernet_frame
= (const struct sflow_ethernet_frame_t
*)pointer
;
645 ND_PRINT((ndo
, "\n\t frame len %u, type %u",
646 EXTRACT_32BITS(sflow_ethernet_frame
->length
),
647 EXTRACT_32BITS(sflow_ethernet_frame
->type
)));
653 print_sflow_extended_switch_data(netdissect_options
*ndo
,
654 const u_char
*pointer
, u_int len
)
656 const struct sflow_extended_switch_data_t
*sflow_extended_sw_data
;
658 if (len
< sizeof(struct sflow_extended_switch_data_t
))
661 sflow_extended_sw_data
= (const struct sflow_extended_switch_data_t
*)pointer
;
662 ND_PRINT((ndo
, "\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u",
663 EXTRACT_32BITS(sflow_extended_sw_data
->src_vlan
),
664 EXTRACT_32BITS(sflow_extended_sw_data
->src_pri
),
665 EXTRACT_32BITS(sflow_extended_sw_data
->dst_vlan
),
666 EXTRACT_32BITS(sflow_extended_sw_data
->dst_pri
)));
672 sflow_print_flow_records(netdissect_options
*ndo
,
673 const u_char
*pointer
, u_int len
, u_int records
)
681 const struct sflow_flow_record_t
*sflow_flow_record
;
687 while (nrecords
> 0) {
688 /* do we have the "header?" */
689 if (tlen
< sizeof(struct sflow_flow_record_t
))
692 sflow_flow_record
= (const struct sflow_flow_record_t
*)tptr
;
694 /* so, the funky encoding means we cannot blythly mask-off
695 bits, we must also check the enterprise. */
697 enterprise
= EXTRACT_32BITS(sflow_flow_record
->format
);
698 flow_type
= enterprise
& 0x0FFF;
699 enterprise
= enterprise
>> 12;
700 flow_len
= EXTRACT_32BITS(sflow_flow_record
->length
);
701 ND_PRINT((ndo
, "\n\t enterprise %u %s (%u) length %u",
703 (enterprise
== 0) ? tok2str(sflow_flow_type_values
,"Unknown",flow_type
) : "Unknown",
707 tptr
+= sizeof(struct sflow_flow_record_t
);
708 tlen
-= sizeof(struct sflow_flow_record_t
);
713 if (enterprise
== 0) {
715 case SFLOW_FLOW_RAW_PACKET
:
716 if (print_sflow_raw_packet(ndo
, tptr
, tlen
))
719 case SFLOW_FLOW_EXTENDED_SWITCH_DATA
:
720 if (print_sflow_extended_switch_data(ndo
, tptr
, tlen
))
723 case SFLOW_FLOW_ETHERNET_FRAME
:
724 if (print_sflow_ethernet_frame(ndo
, tptr
, tlen
))
727 /* FIXME these need a decoder */
728 case SFLOW_FLOW_IPV4_DATA
:
729 case SFLOW_FLOW_IPV6_DATA
:
730 case SFLOW_FLOW_EXTENDED_ROUTER_DATA
:
731 case SFLOW_FLOW_EXTENDED_GATEWAY_DATA
:
732 case SFLOW_FLOW_EXTENDED_USER_DATA
:
733 case SFLOW_FLOW_EXTENDED_URL_DATA
:
734 case SFLOW_FLOW_EXTENDED_MPLS_DATA
:
735 case SFLOW_FLOW_EXTENDED_NAT_DATA
:
736 case SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
:
737 case SFLOW_FLOW_EXTENDED_MPLS_VC
:
738 case SFLOW_FLOW_EXTENDED_MPLS_FEC
:
739 case SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
:
740 case SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
:
743 if (ndo
->ndo_vflag
<= 1)
744 print_unknown_data(ndo
, tptr
, "\n\t\t", flow_len
);
758 sflow_print_flow_sample(netdissect_options
*ndo
,
759 const u_char
*pointer
, u_int len
)
761 const struct sflow_flow_sample_t
*sflow_flow_sample
;
767 if (len
< sizeof(struct sflow_flow_sample_t
))
770 sflow_flow_sample
= (struct sflow_flow_sample_t
*)pointer
;
772 typesource
= EXTRACT_32BITS(sflow_flow_sample
->typesource
);
773 nrecords
= EXTRACT_32BITS(sflow_flow_sample
->records
);
774 type
= typesource
>> 24;
775 index
= typesource
& 0x0FFF;
777 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, input %u output %u records %u",
778 EXTRACT_32BITS(sflow_flow_sample
->seqnum
),
781 EXTRACT_32BITS(sflow_flow_sample
->rate
),
782 EXTRACT_32BITS(sflow_flow_sample
->pool
),
783 EXTRACT_32BITS(sflow_flow_sample
->drops
),
784 EXTRACT_32BITS(sflow_flow_sample
->in_interface
),
785 EXTRACT_32BITS(sflow_flow_sample
->out_interface
),
788 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_flow_sample_t
),
789 len
- sizeof(struct sflow_flow_sample_t
),
795 sflow_print_expanded_flow_sample(netdissect_options
*ndo
,
796 const u_char
*pointer
, u_int len
)
798 const struct sflow_expanded_flow_sample_t
*sflow_expanded_flow_sample
;
801 if (len
< sizeof(struct sflow_expanded_flow_sample_t
))
804 sflow_expanded_flow_sample
= (const struct sflow_expanded_flow_sample_t
*)pointer
;
806 nrecords
= EXTRACT_32BITS(sflow_expanded_flow_sample
->records
);
808 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, records %u",
809 EXTRACT_32BITS(sflow_expanded_flow_sample
->seqnum
),
810 EXTRACT_32BITS(sflow_expanded_flow_sample
->type
),
811 EXTRACT_32BITS(sflow_expanded_flow_sample
->index
),
812 EXTRACT_32BITS(sflow_expanded_flow_sample
->rate
),
813 EXTRACT_32BITS(sflow_expanded_flow_sample
->pool
),
814 EXTRACT_32BITS(sflow_expanded_flow_sample
->drops
),
815 EXTRACT_32BITS(sflow_expanded_flow_sample
->records
)));
817 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_expanded_flow_sample_t
),
818 len
- sizeof(struct sflow_expanded_flow_sample_t
),
824 sflow_print(netdissect_options
*ndo
,
825 const u_char
*pptr
, u_int len
)
827 const struct sflow_datagram_t
*sflow_datagram
;
828 const struct sflow_sample_header
*sflow_sample
;
832 uint32_t sflow_sample_type
, sflow_sample_len
;
838 sflow_datagram
= (const struct sflow_datagram_t
*)pptr
;
839 ND_TCHECK(*sflow_datagram
);
842 * Sanity checking of the header.
844 if (EXTRACT_32BITS(sflow_datagram
->version
) != 5) {
845 ND_PRINT((ndo
, "sFlow version %u packet not supported",
846 EXTRACT_32BITS(sflow_datagram
->version
)));
850 if (ndo
->ndo_vflag
< 1) {
851 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, length %u",
852 EXTRACT_32BITS(sflow_datagram
->version
),
853 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
854 ipaddr_string(ndo
, sflow_datagram
->agent
),
855 EXTRACT_32BITS(sflow_datagram
->agent_id
),
860 /* ok they seem to want to know everything - lets fully decode it */
861 nsamples
=EXTRACT_32BITS(sflow_datagram
->samples
);
862 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
863 EXTRACT_32BITS(sflow_datagram
->version
),
864 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
865 ipaddr_string(ndo
, sflow_datagram
->agent
),
866 EXTRACT_32BITS(sflow_datagram
->agent_id
),
867 EXTRACT_32BITS(sflow_datagram
->seqnum
),
868 EXTRACT_32BITS(sflow_datagram
->uptime
),
872 /* skip Common header */
873 tptr
+= sizeof(const struct sflow_datagram_t
);
874 tlen
-= sizeof(const struct sflow_datagram_t
);
876 while (nsamples
> 0 && tlen
> 0) {
877 sflow_sample
= (const struct sflow_sample_header
*)tptr
;
878 ND_TCHECK(*sflow_sample
);
880 sflow_sample_type
= (EXTRACT_32BITS(sflow_sample
->format
)&0x0FFF);
881 sflow_sample_len
= EXTRACT_32BITS(sflow_sample
->len
);
883 if (tlen
< sizeof(struct sflow_sample_header
))
886 tptr
+= sizeof(struct sflow_sample_header
);
887 tlen
-= sizeof(struct sflow_sample_header
);
889 ND_PRINT((ndo
, "\n\t%s (%u), length %u,",
890 tok2str(sflow_format_values
, "Unknown", sflow_sample_type
),
894 /* basic sanity check */
895 if (sflow_sample_type
== 0 || sflow_sample_len
==0) {
899 if (tlen
< sflow_sample_len
)
902 /* did we capture enough for fully decoding the sample ? */
903 ND_TCHECK2(*tptr
, sflow_sample_len
);
905 switch(sflow_sample_type
) {
906 case SFLOW_FLOW_SAMPLE
:
907 if (sflow_print_flow_sample(ndo
, tptr
, tlen
))
911 case SFLOW_COUNTER_SAMPLE
:
912 if (sflow_print_counter_sample(ndo
, tptr
,tlen
))
916 case SFLOW_EXPANDED_FLOW_SAMPLE
:
917 if (sflow_print_expanded_flow_sample(ndo
, tptr
, tlen
))
921 case SFLOW_EXPANDED_COUNTER_SAMPLE
:
922 if (sflow_print_expanded_counter_sample(ndo
, tptr
,tlen
))
927 if (ndo
->ndo_vflag
<= 1)
928 print_unknown_data(ndo
, tptr
, "\n\t ", sflow_sample_len
);
931 tptr
+= sflow_sample_len
;
932 tlen
-= sflow_sample_len
;
938 ND_PRINT((ndo
, "[|SFLOW]"));
943 * c-style: whitesmith