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 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
29 #include "interface.h"
31 #include "addrtoname.h"
37 * 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
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Sflow version (2,4,5) |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | IP version (1 for IPv4 | 2 for IPv6) |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | IP Address AGENT (4 or 16 bytes) |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Datagram sequence number |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | Switch uptime in ms |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | num samples in datagram |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 struct sflow_datagram_t
{
58 uint8_t ip_version
[4];
66 struct sflow_sample_header
{
71 #define SFLOW_FLOW_SAMPLE 1
72 #define SFLOW_COUNTER_SAMPLE 2
73 #define SFLOW_EXPANDED_FLOW_SAMPLE 3
74 #define SFLOW_EXPANDED_COUNTER_SAMPLE 4
76 static const struct tok sflow_format_values
[] = {
77 { SFLOW_FLOW_SAMPLE
, "flow sample" },
78 { SFLOW_COUNTER_SAMPLE
, "counter sample" },
79 { SFLOW_EXPANDED_FLOW_SAMPLE
, "expanded flow sample" },
80 { SFLOW_EXPANDED_COUNTER_SAMPLE
, "expanded counter sample" },
84 struct sflow_flow_sample_t
{
86 uint8_t typesource
[4];
90 uint8_t in_interface
[4];
91 uint8_t out_interface
[4];
96 struct sflow_expanded_flow_sample_t
{
103 uint8_t in_interface_format
[4];
104 uint8_t in_interface_value
[4];
105 uint8_t out_interface_format
[4];
106 uint8_t out_interface_value
[4];
110 #define SFLOW_FLOW_RAW_PACKET 1
111 #define SFLOW_FLOW_ETHERNET_FRAME 2
112 #define SFLOW_FLOW_IPV4_DATA 3
113 #define SFLOW_FLOW_IPV6_DATA 4
114 #define SFLOW_FLOW_EXTENDED_SWITCH_DATA 1001
115 #define SFLOW_FLOW_EXTENDED_ROUTER_DATA 1002
116 #define SFLOW_FLOW_EXTENDED_GATEWAY_DATA 1003
117 #define SFLOW_FLOW_EXTENDED_USER_DATA 1004
118 #define SFLOW_FLOW_EXTENDED_URL_DATA 1005
119 #define SFLOW_FLOW_EXTENDED_MPLS_DATA 1006
120 #define SFLOW_FLOW_EXTENDED_NAT_DATA 1007
121 #define SFLOW_FLOW_EXTENDED_MPLS_TUNNEL 1008
122 #define SFLOW_FLOW_EXTENDED_MPLS_VC 1009
123 #define SFLOW_FLOW_EXTENDED_MPLS_FEC 1010
124 #define SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC 1011
125 #define SFLOW_FLOW_EXTENDED_VLAN_TUNNEL 1012
127 static const struct tok sflow_flow_type_values
[] = {
128 { SFLOW_FLOW_RAW_PACKET
, "Raw packet"},
129 { SFLOW_FLOW_ETHERNET_FRAME
, "Ethernet frame"},
130 { SFLOW_FLOW_IPV4_DATA
, "IPv4 Data"},
131 { SFLOW_FLOW_IPV6_DATA
, "IPv6 Data"},
132 { SFLOW_FLOW_EXTENDED_SWITCH_DATA
, "Extended Switch data"},
133 { SFLOW_FLOW_EXTENDED_ROUTER_DATA
, "Extended Router data"},
134 { SFLOW_FLOW_EXTENDED_GATEWAY_DATA
, "Extended Gateway data"},
135 { SFLOW_FLOW_EXTENDED_USER_DATA
, "Extended User data"},
136 { SFLOW_FLOW_EXTENDED_URL_DATA
, "Extended URL data"},
137 { SFLOW_FLOW_EXTENDED_MPLS_DATA
, "Extended MPLS data"},
138 { SFLOW_FLOW_EXTENDED_NAT_DATA
, "Extended NAT data"},
139 { SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
, "Extended MPLS tunnel"},
140 { SFLOW_FLOW_EXTENDED_MPLS_VC
, "Extended MPLS VC"},
141 { SFLOW_FLOW_EXTENDED_MPLS_FEC
, "Extended MPLS FEC"},
142 { SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
, "Extended MPLS LVP FEC"},
143 { SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
, "Extended VLAN Tunnel"},
147 #define SFLOW_HEADER_PROTOCOL_ETHERNET 1
148 #define SFLOW_HEADER_PROTOCOL_IPV4 11
149 #define SFLOW_HEADER_PROTOCOL_IPV6 12
151 static const struct tok sflow_flow_raw_protocol_values
[] = {
152 { SFLOW_HEADER_PROTOCOL_ETHERNET
, "Ethernet"},
153 { SFLOW_HEADER_PROTOCOL_IPV4
, "IPv4"},
154 { SFLOW_HEADER_PROTOCOL_IPV6
, "IPv6"},
158 struct sflow_expanded_flow_raw_t
{
161 uint8_t stripped_bytes
[4];
162 uint8_t header_size
[4];
165 struct sflow_ethernet_frame_t
{
172 struct sflow_extended_switch_data_t
{
179 struct sflow_counter_record_t
{
184 struct sflow_flow_record_t
{
189 struct sflow_counter_sample_t
{
191 uint8_t typesource
[4];
195 struct sflow_expanded_counter_sample_t
{
202 #define SFLOW_COUNTER_GENERIC 1
203 #define SFLOW_COUNTER_ETHERNET 2
204 #define SFLOW_COUNTER_TOKEN_RING 3
205 #define SFLOW_COUNTER_BASEVG 4
206 #define SFLOW_COUNTER_VLAN 5
207 #define SFLOW_COUNTER_PROCESSOR 1001
209 static const struct tok sflow_counter_type_values
[] = {
210 { SFLOW_COUNTER_GENERIC
, "Generic counter"},
211 { SFLOW_COUNTER_ETHERNET
, "Ethernet counter"},
212 { SFLOW_COUNTER_TOKEN_RING
, "Token ring counter"},
213 { SFLOW_COUNTER_BASEVG
, "100 BaseVG counter"},
214 { SFLOW_COUNTER_VLAN
, "Vlan counter"},
215 { SFLOW_COUNTER_PROCESSOR
, "Processor counter"},
219 #define SFLOW_IFACE_DIRECTION_UNKNOWN 0
220 #define SFLOW_IFACE_DIRECTION_FULLDUPLEX 1
221 #define SFLOW_IFACE_DIRECTION_HALFDUPLEX 2
222 #define SFLOW_IFACE_DIRECTION_IN 3
223 #define SFLOW_IFACE_DIRECTION_OUT 4
225 static const struct tok sflow_iface_direction_values
[] = {
226 { SFLOW_IFACE_DIRECTION_UNKNOWN
, "unknown"},
227 { SFLOW_IFACE_DIRECTION_FULLDUPLEX
, "full-duplex"},
228 { SFLOW_IFACE_DIRECTION_HALFDUPLEX
, "half-duplex"},
229 { SFLOW_IFACE_DIRECTION_IN
, "in"},
230 { SFLOW_IFACE_DIRECTION_OUT
, "out"},
234 struct sflow_generic_counter_t
{
238 uint8_t ifdirection
[4];
240 uint8_t ifinoctets
[8];
241 uint8_t ifinunicastpkts
[4];
242 uint8_t ifinmulticastpkts
[4];
243 uint8_t ifinbroadcastpkts
[4];
244 uint8_t ifindiscards
[4];
245 uint8_t ifinerrors
[4];
246 uint8_t ifinunkownprotos
[4];
247 uint8_t ifoutoctets
[8];
248 uint8_t ifoutunicastpkts
[4];
249 uint8_t ifoutmulticastpkts
[4];
250 uint8_t ifoutbroadcastpkts
[4];
251 uint8_t ifoutdiscards
[4];
252 uint8_t ifouterrors
[4];
253 uint8_t ifpromiscmode
[4];
256 struct sflow_ethernet_counter_t
{
257 uint8_t alignerrors
[4];
258 uint8_t fcserrors
[4];
259 uint8_t single_collision_frames
[4];
260 uint8_t multiple_collision_frames
[4];
261 uint8_t test_errors
[4];
262 uint8_t deferred_transmissions
[4];
263 uint8_t late_collisions
[4];
264 uint8_t excessive_collisions
[4];
265 uint8_t mac_transmit_errors
[4];
266 uint8_t carrier_sense_errors
[4];
267 uint8_t frame_too_longs
[4];
268 uint8_t mac_receive_errors
[4];
269 uint8_t symbol_errors
[4];
272 struct sflow_100basevg_counter_t
{
273 uint8_t in_highpriority_frames
[4];
274 uint8_t in_highpriority_octets
[8];
275 uint8_t in_normpriority_frames
[4];
276 uint8_t in_normpriority_octets
[8];
277 uint8_t in_ipmerrors
[4];
278 uint8_t in_oversized
[4];
279 uint8_t in_data_errors
[4];
280 uint8_t in_null_addressed_frames
[4];
281 uint8_t out_highpriority_frames
[4];
282 uint8_t out_highpriority_octets
[8];
283 uint8_t transitioninto_frames
[4];
284 uint8_t hc_in_highpriority_octets
[8];
285 uint8_t hc_in_normpriority_octets
[8];
286 uint8_t hc_out_highpriority_octets
[8];
289 struct sflow_vlan_counter_t
{
292 uint8_t unicast_pkt
[4];
293 uint8_t multicast_pkt
[4];
294 uint8_t broadcast_pkt
[4];
299 print_sflow_counter_generic(netdissect_options
*ndo
,
300 const u_char
*pointer
, u_int len
)
302 const struct sflow_generic_counter_t
*sflow_gen_counter
;
304 if (len
< sizeof(struct sflow_generic_counter_t
))
307 sflow_gen_counter
= (const struct sflow_generic_counter_t
*)pointer
;
308 ND_TCHECK(*sflow_gen_counter
);
309 ND_PRINT((ndo
, "\n\t ifindex %u, iftype %u, ifspeed %" PRIu64
", ifdirection %u (%s)",
310 EXTRACT_32BITS(sflow_gen_counter
->ifindex
),
311 EXTRACT_32BITS(sflow_gen_counter
->iftype
),
312 EXTRACT_64BITS(sflow_gen_counter
->ifspeed
),
313 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
),
314 tok2str(sflow_iface_direction_values
, "Unknown",
315 EXTRACT_32BITS(sflow_gen_counter
->ifdirection
))));
316 ND_PRINT((ndo
, "\n\t ifstatus %u, adminstatus: %s, operstatus: %s",
317 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
),
318 EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)&1 ? "up" : "down",
319 (EXTRACT_32BITS(sflow_gen_counter
->ifstatus
)>>1)&1 ? "up" : "down"));
320 ND_PRINT((ndo
, "\n\t In octets %" PRIu64
321 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
322 EXTRACT_64BITS(sflow_gen_counter
->ifinoctets
),
323 EXTRACT_32BITS(sflow_gen_counter
->ifinunicastpkts
),
324 EXTRACT_32BITS(sflow_gen_counter
->ifinmulticastpkts
),
325 EXTRACT_32BITS(sflow_gen_counter
->ifinbroadcastpkts
),
326 EXTRACT_32BITS(sflow_gen_counter
->ifindiscards
)));
327 ND_PRINT((ndo
, "\n\t In errors %u, unknown protos %u",
328 EXTRACT_32BITS(sflow_gen_counter
->ifinerrors
),
329 EXTRACT_32BITS(sflow_gen_counter
->ifinunkownprotos
)));
330 ND_PRINT((ndo
, "\n\t Out octets %" PRIu64
331 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
332 EXTRACT_64BITS(sflow_gen_counter
->ifoutoctets
),
333 EXTRACT_32BITS(sflow_gen_counter
->ifoutunicastpkts
),
334 EXTRACT_32BITS(sflow_gen_counter
->ifoutmulticastpkts
),
335 EXTRACT_32BITS(sflow_gen_counter
->ifoutbroadcastpkts
),
336 EXTRACT_32BITS(sflow_gen_counter
->ifoutdiscards
)));
337 ND_PRINT((ndo
, "\n\t Out errors %u, promisc mode %u",
338 EXTRACT_32BITS(sflow_gen_counter
->ifouterrors
),
339 EXTRACT_32BITS(sflow_gen_counter
->ifpromiscmode
)));
348 print_sflow_counter_ethernet(netdissect_options
*ndo
,
349 const u_char
*pointer
, u_int len
)
351 const struct sflow_ethernet_counter_t
*sflow_eth_counter
;
353 if (len
< sizeof(struct sflow_ethernet_counter_t
))
356 sflow_eth_counter
= (const struct sflow_ethernet_counter_t
*)pointer
;
357 ND_TCHECK(*sflow_eth_counter
);
358 ND_PRINT((ndo
, "\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u",
359 EXTRACT_32BITS(sflow_eth_counter
->alignerrors
),
360 EXTRACT_32BITS(sflow_eth_counter
->fcserrors
),
361 EXTRACT_32BITS(sflow_eth_counter
->single_collision_frames
),
362 EXTRACT_32BITS(sflow_eth_counter
->multiple_collision_frames
),
363 EXTRACT_32BITS(sflow_eth_counter
->test_errors
)));
364 ND_PRINT((ndo
, "\n\t deferred %u, late collision %u, excessive collision %u, mac trans error %u",
365 EXTRACT_32BITS(sflow_eth_counter
->deferred_transmissions
),
366 EXTRACT_32BITS(sflow_eth_counter
->late_collisions
),
367 EXTRACT_32BITS(sflow_eth_counter
->excessive_collisions
),
368 EXTRACT_32BITS(sflow_eth_counter
->mac_transmit_errors
)));
369 ND_PRINT((ndo
, "\n\t carrier error %u, frames too long %u, mac receive errors %u, symbol errors %u",
370 EXTRACT_32BITS(sflow_eth_counter
->carrier_sense_errors
),
371 EXTRACT_32BITS(sflow_eth_counter
->frame_too_longs
),
372 EXTRACT_32BITS(sflow_eth_counter
->mac_receive_errors
),
373 EXTRACT_32BITS(sflow_eth_counter
->symbol_errors
)));
382 print_sflow_counter_token_ring(netdissect_options
*ndo _U_
,
383 const u_char
*pointer _U_
, u_int len _U_
)
389 print_sflow_counter_basevg(netdissect_options
*ndo
,
390 const u_char
*pointer
, u_int len
)
392 const struct sflow_100basevg_counter_t
*sflow_100basevg_counter
;
394 if (len
< sizeof(struct sflow_100basevg_counter_t
))
397 sflow_100basevg_counter
= (const struct sflow_100basevg_counter_t
*)pointer
;
398 ND_TCHECK(*sflow_100basevg_counter
);
399 ND_PRINT((ndo
, "\n\t in high prio frames %u, in high prio octets %" PRIu64
,
400 EXTRACT_32BITS(sflow_100basevg_counter
->in_highpriority_frames
),
401 EXTRACT_64BITS(sflow_100basevg_counter
->in_highpriority_octets
)));
402 ND_PRINT((ndo
, "\n\t in norm prio frames %u, in norm prio octets %" PRIu64
,
403 EXTRACT_32BITS(sflow_100basevg_counter
->in_normpriority_frames
),
404 EXTRACT_64BITS(sflow_100basevg_counter
->in_normpriority_octets
)));
405 ND_PRINT((ndo
, "\n\t in ipm errors %u, oversized %u, in data errors %u, null addressed frames %u",
406 EXTRACT_32BITS(sflow_100basevg_counter
->in_ipmerrors
),
407 EXTRACT_32BITS(sflow_100basevg_counter
->in_oversized
),
408 EXTRACT_32BITS(sflow_100basevg_counter
->in_data_errors
),
409 EXTRACT_32BITS(sflow_100basevg_counter
->in_null_addressed_frames
)));
410 ND_PRINT((ndo
, "\n\t out high prio frames %u, out high prio octets %" PRIu64
411 ", trans into frames %u",
412 EXTRACT_32BITS(sflow_100basevg_counter
->out_highpriority_frames
),
413 EXTRACT_64BITS(sflow_100basevg_counter
->out_highpriority_octets
),
414 EXTRACT_32BITS(sflow_100basevg_counter
->transitioninto_frames
)));
415 ND_PRINT((ndo
, "\n\t in hc high prio octets %" PRIu64
416 ", in hc norm prio octets %" PRIu64
417 ", out hc high prio octets %" PRIu64
,
418 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_highpriority_octets
),
419 EXTRACT_64BITS(sflow_100basevg_counter
->hc_in_normpriority_octets
),
420 EXTRACT_64BITS(sflow_100basevg_counter
->hc_out_highpriority_octets
)));
429 print_sflow_counter_vlan(netdissect_options
*ndo
,
430 const u_char
*pointer
, u_int len
)
432 const struct sflow_vlan_counter_t
*sflow_vlan_counter
;
434 if (len
< sizeof(struct sflow_vlan_counter_t
))
437 sflow_vlan_counter
= (const struct sflow_vlan_counter_t
*)pointer
;
438 ND_TCHECK(*sflow_vlan_counter
);
439 ND_PRINT((ndo
, "\n\t vlan_id %u, octets %" PRIu64
440 ", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u",
441 EXTRACT_32BITS(sflow_vlan_counter
->vlan_id
),
442 EXTRACT_64BITS(sflow_vlan_counter
->octets
),
443 EXTRACT_32BITS(sflow_vlan_counter
->unicast_pkt
),
444 EXTRACT_32BITS(sflow_vlan_counter
->multicast_pkt
),
445 EXTRACT_32BITS(sflow_vlan_counter
->broadcast_pkt
),
446 EXTRACT_32BITS(sflow_vlan_counter
->discards
)));
454 struct sflow_processor_counter_t
{
455 uint8_t five_sec_util
[4];
456 uint8_t one_min_util
[4];
457 uint8_t five_min_util
[4];
458 uint8_t total_memory
[8];
459 uint8_t free_memory
[8];
463 print_sflow_counter_processor(netdissect_options
*ndo
,
464 const u_char
*pointer
, u_int len
)
466 const struct sflow_processor_counter_t
*sflow_processor_counter
;
468 if (len
< sizeof(struct sflow_processor_counter_t
))
471 sflow_processor_counter
= (const struct sflow_processor_counter_t
*)pointer
;
472 ND_TCHECK(*sflow_processor_counter
);
473 ND_PRINT((ndo
, "\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64
474 ", total_mem %" PRIu64
,
475 EXTRACT_32BITS(sflow_processor_counter
->five_sec_util
),
476 EXTRACT_32BITS(sflow_processor_counter
->one_min_util
),
477 EXTRACT_32BITS(sflow_processor_counter
->five_min_util
),
478 EXTRACT_64BITS(sflow_processor_counter
->total_memory
),
479 EXTRACT_64BITS(sflow_processor_counter
->free_memory
)));
488 sflow_print_counter_records(netdissect_options
*ndo
,
489 const u_char
*pointer
, u_int len
, u_int records
)
497 const struct sflow_counter_record_t
*sflow_counter_record
;
503 while (nrecords
> 0) {
504 /* do we have the "header?" */
505 if (tlen
< sizeof(struct sflow_counter_record_t
))
507 sflow_counter_record
= (const struct sflow_counter_record_t
*)tptr
;
508 ND_TCHECK(*sflow_counter_record
);
510 enterprise
= EXTRACT_32BITS(sflow_counter_record
->format
);
511 counter_type
= enterprise
& 0x0FFF;
512 enterprise
= enterprise
>> 20;
513 counter_len
= EXTRACT_32BITS(sflow_counter_record
->length
);
514 ND_PRINT((ndo
, "\n\t enterprise %u, %s (%u) length %u",
516 (enterprise
== 0) ? tok2str(sflow_counter_type_values
,"Unknown",counter_type
) : "Unknown",
520 tptr
+= sizeof(struct sflow_counter_record_t
);
521 tlen
-= sizeof(struct sflow_counter_record_t
);
523 if (tlen
< counter_len
)
525 if (enterprise
== 0) {
526 switch (counter_type
) {
527 case SFLOW_COUNTER_GENERIC
:
528 if (print_sflow_counter_generic(ndo
, tptr
, tlen
))
531 case SFLOW_COUNTER_ETHERNET
:
532 if (print_sflow_counter_ethernet(ndo
, tptr
, tlen
))
535 case SFLOW_COUNTER_TOKEN_RING
:
536 if (print_sflow_counter_token_ring(ndo
, tptr
,tlen
))
539 case SFLOW_COUNTER_BASEVG
:
540 if (print_sflow_counter_basevg(ndo
, tptr
, tlen
))
543 case SFLOW_COUNTER_VLAN
:
544 if (print_sflow_counter_vlan(ndo
, tptr
, tlen
))
547 case SFLOW_COUNTER_PROCESSOR
:
548 if (print_sflow_counter_processor(ndo
, tptr
, tlen
))
552 if (ndo
->ndo_vflag
<= 1)
553 print_unknown_data(ndo
, tptr
, "\n\t\t", counter_len
);
570 sflow_print_counter_sample(netdissect_options
*ndo
,
571 const u_char
*pointer
, u_int len
)
573 const struct sflow_counter_sample_t
*sflow_counter_sample
;
579 if (len
< sizeof(struct sflow_counter_sample_t
))
582 sflow_counter_sample
= (const struct sflow_counter_sample_t
*)pointer
;
583 ND_TCHECK(*sflow_counter_sample
);
585 typesource
= EXTRACT_32BITS(sflow_counter_sample
->typesource
);
586 nrecords
= EXTRACT_32BITS(sflow_counter_sample
->records
);
587 type
= typesource
>> 24;
588 index
= typesource
& 0x0FFF;
590 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
591 EXTRACT_32BITS(sflow_counter_sample
->seqnum
),
596 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_counter_sample_t
),
597 len
- sizeof(struct sflow_counter_sample_t
),
605 sflow_print_expanded_counter_sample(netdissect_options
*ndo
,
606 const u_char
*pointer
, u_int len
)
608 const struct sflow_expanded_counter_sample_t
*sflow_expanded_counter_sample
;
612 if (len
< sizeof(struct sflow_expanded_counter_sample_t
))
615 sflow_expanded_counter_sample
= (const struct sflow_expanded_counter_sample_t
*)pointer
;
616 ND_TCHECK(*sflow_expanded_counter_sample
);
618 nrecords
= EXTRACT_32BITS(sflow_expanded_counter_sample
->records
);
620 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, records %u",
621 EXTRACT_32BITS(sflow_expanded_counter_sample
->seqnum
),
622 EXTRACT_32BITS(sflow_expanded_counter_sample
->type
),
623 EXTRACT_32BITS(sflow_expanded_counter_sample
->index
),
626 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_expanded_counter_sample_t
),
627 len
- sizeof(struct sflow_expanded_counter_sample_t
),
635 print_sflow_raw_packet(netdissect_options
*ndo
,
636 const u_char
*pointer
, u_int len
)
638 const struct sflow_expanded_flow_raw_t
*sflow_flow_raw
;
640 if (len
< sizeof(struct sflow_expanded_flow_raw_t
))
643 sflow_flow_raw
= (const struct sflow_expanded_flow_raw_t
*)pointer
;
644 ND_TCHECK(*sflow_flow_raw
);
645 ND_PRINT((ndo
, "\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u",
646 tok2str(sflow_flow_raw_protocol_values
,"Unknown",EXTRACT_32BITS(sflow_flow_raw
->protocol
)),
647 EXTRACT_32BITS(sflow_flow_raw
->protocol
),
648 EXTRACT_32BITS(sflow_flow_raw
->length
),
649 EXTRACT_32BITS(sflow_flow_raw
->stripped_bytes
),
650 EXTRACT_32BITS(sflow_flow_raw
->header_size
)));
652 /* QUESTION - should we attempt to print the raw header itself?
653 assuming of course there is wnough data present to do so... */
662 print_sflow_ethernet_frame(netdissect_options
*ndo
,
663 const u_char
*pointer
, u_int len
)
665 const struct sflow_ethernet_frame_t
*sflow_ethernet_frame
;
667 if (len
< sizeof(struct sflow_ethernet_frame_t
))
670 sflow_ethernet_frame
= (const struct sflow_ethernet_frame_t
*)pointer
;
671 ND_TCHECK(*sflow_ethernet_frame
);
673 ND_PRINT((ndo
, "\n\t frame len %u, type %u",
674 EXTRACT_32BITS(sflow_ethernet_frame
->length
),
675 EXTRACT_32BITS(sflow_ethernet_frame
->type
)));
684 print_sflow_extended_switch_data(netdissect_options
*ndo
,
685 const u_char
*pointer
, u_int len
)
687 const struct sflow_extended_switch_data_t
*sflow_extended_sw_data
;
689 if (len
< sizeof(struct sflow_extended_switch_data_t
))
692 sflow_extended_sw_data
= (const struct sflow_extended_switch_data_t
*)pointer
;
693 ND_TCHECK(*sflow_extended_sw_data
);
694 ND_PRINT((ndo
, "\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u",
695 EXTRACT_32BITS(sflow_extended_sw_data
->src_vlan
),
696 EXTRACT_32BITS(sflow_extended_sw_data
->src_pri
),
697 EXTRACT_32BITS(sflow_extended_sw_data
->dst_vlan
),
698 EXTRACT_32BITS(sflow_extended_sw_data
->dst_pri
)));
707 sflow_print_flow_records(netdissect_options
*ndo
,
708 const u_char
*pointer
, u_int len
, u_int records
)
716 const struct sflow_flow_record_t
*sflow_flow_record
;
722 while (nrecords
> 0) {
723 /* do we have the "header?" */
724 if (tlen
< sizeof(struct sflow_flow_record_t
))
727 sflow_flow_record
= (const struct sflow_flow_record_t
*)tptr
;
728 ND_TCHECK(*sflow_flow_record
);
730 /* so, the funky encoding means we cannot blythly mask-off
731 bits, we must also check the enterprise. */
733 enterprise
= EXTRACT_32BITS(sflow_flow_record
->format
);
734 flow_type
= enterprise
& 0x0FFF;
735 enterprise
= enterprise
>> 12;
736 flow_len
= EXTRACT_32BITS(sflow_flow_record
->length
);
737 ND_PRINT((ndo
, "\n\t enterprise %u %s (%u) length %u",
739 (enterprise
== 0) ? tok2str(sflow_flow_type_values
,"Unknown",flow_type
) : "Unknown",
743 tptr
+= sizeof(struct sflow_flow_record_t
);
744 tlen
-= sizeof(struct sflow_flow_record_t
);
749 if (enterprise
== 0) {
751 case SFLOW_FLOW_RAW_PACKET
:
752 if (print_sflow_raw_packet(ndo
, tptr
, tlen
))
755 case SFLOW_FLOW_EXTENDED_SWITCH_DATA
:
756 if (print_sflow_extended_switch_data(ndo
, tptr
, tlen
))
759 case SFLOW_FLOW_ETHERNET_FRAME
:
760 if (print_sflow_ethernet_frame(ndo
, tptr
, tlen
))
763 /* FIXME these need a decoder */
764 case SFLOW_FLOW_IPV4_DATA
:
765 case SFLOW_FLOW_IPV6_DATA
:
766 case SFLOW_FLOW_EXTENDED_ROUTER_DATA
:
767 case SFLOW_FLOW_EXTENDED_GATEWAY_DATA
:
768 case SFLOW_FLOW_EXTENDED_USER_DATA
:
769 case SFLOW_FLOW_EXTENDED_URL_DATA
:
770 case SFLOW_FLOW_EXTENDED_MPLS_DATA
:
771 case SFLOW_FLOW_EXTENDED_NAT_DATA
:
772 case SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
:
773 case SFLOW_FLOW_EXTENDED_MPLS_VC
:
774 case SFLOW_FLOW_EXTENDED_MPLS_FEC
:
775 case SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
:
776 case SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
:
779 if (ndo
->ndo_vflag
<= 1)
780 print_unknown_data(ndo
, tptr
, "\n\t\t", flow_len
);
797 sflow_print_flow_sample(netdissect_options
*ndo
,
798 const u_char
*pointer
, u_int len
)
800 const struct sflow_flow_sample_t
*sflow_flow_sample
;
806 if (len
< sizeof(struct sflow_flow_sample_t
))
809 sflow_flow_sample
= (struct sflow_flow_sample_t
*)pointer
;
810 ND_TCHECK(*sflow_flow_sample
);
812 typesource
= EXTRACT_32BITS(sflow_flow_sample
->typesource
);
813 nrecords
= EXTRACT_32BITS(sflow_flow_sample
->records
);
814 type
= typesource
>> 24;
815 index
= typesource
& 0x0FFF;
817 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, input %u output %u records %u",
818 EXTRACT_32BITS(sflow_flow_sample
->seqnum
),
821 EXTRACT_32BITS(sflow_flow_sample
->rate
),
822 EXTRACT_32BITS(sflow_flow_sample
->pool
),
823 EXTRACT_32BITS(sflow_flow_sample
->drops
),
824 EXTRACT_32BITS(sflow_flow_sample
->in_interface
),
825 EXTRACT_32BITS(sflow_flow_sample
->out_interface
),
828 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_flow_sample_t
),
829 len
- sizeof(struct sflow_flow_sample_t
),
837 sflow_print_expanded_flow_sample(netdissect_options
*ndo
,
838 const u_char
*pointer
, u_int len
)
840 const struct sflow_expanded_flow_sample_t
*sflow_expanded_flow_sample
;
843 if (len
< sizeof(struct sflow_expanded_flow_sample_t
))
846 sflow_expanded_flow_sample
= (const struct sflow_expanded_flow_sample_t
*)pointer
;
847 ND_TCHECK(*sflow_expanded_flow_sample
);
849 nrecords
= EXTRACT_32BITS(sflow_expanded_flow_sample
->records
);
851 ND_PRINT((ndo
, " seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, records %u",
852 EXTRACT_32BITS(sflow_expanded_flow_sample
->seqnum
),
853 EXTRACT_32BITS(sflow_expanded_flow_sample
->type
),
854 EXTRACT_32BITS(sflow_expanded_flow_sample
->index
),
855 EXTRACT_32BITS(sflow_expanded_flow_sample
->rate
),
856 EXTRACT_32BITS(sflow_expanded_flow_sample
->pool
),
857 EXTRACT_32BITS(sflow_expanded_flow_sample
->drops
),
858 EXTRACT_32BITS(sflow_expanded_flow_sample
->records
)));
860 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_expanded_flow_sample_t
),
861 len
- sizeof(struct sflow_expanded_flow_sample_t
),
869 sflow_print(netdissect_options
*ndo
,
870 const u_char
*pptr
, u_int len
)
872 const struct sflow_datagram_t
*sflow_datagram
;
873 const struct sflow_sample_header
*sflow_sample
;
877 uint32_t sflow_sample_type
, sflow_sample_len
;
882 sflow_datagram
= (const struct sflow_datagram_t
*)pptr
;
883 ND_TCHECK(*sflow_datagram
);
886 * Sanity checking of the header.
888 if (EXTRACT_32BITS(sflow_datagram
->version
) != 5) {
889 ND_PRINT((ndo
, "sFlow version %u packet not supported",
890 EXTRACT_32BITS(sflow_datagram
->version
)));
894 if (ndo
->ndo_vflag
< 1) {
895 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, length %u",
896 EXTRACT_32BITS(sflow_datagram
->version
),
897 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
898 ipaddr_string(ndo
, sflow_datagram
->agent
),
899 EXTRACT_32BITS(sflow_datagram
->agent_id
),
904 /* ok they seem to want to know everything - lets fully decode it */
905 nsamples
=EXTRACT_32BITS(sflow_datagram
->samples
);
906 ND_PRINT((ndo
, "sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
907 EXTRACT_32BITS(sflow_datagram
->version
),
908 EXTRACT_32BITS(sflow_datagram
->ip_version
) == 1 ? "IPv4" : "IPv6",
909 ipaddr_string(ndo
, sflow_datagram
->agent
),
910 EXTRACT_32BITS(sflow_datagram
->agent_id
),
911 EXTRACT_32BITS(sflow_datagram
->seqnum
),
912 EXTRACT_32BITS(sflow_datagram
->uptime
),
916 /* skip Common header */
917 tptr
+= sizeof(const struct sflow_datagram_t
);
918 tlen
-= sizeof(const struct sflow_datagram_t
);
920 while (nsamples
> 0 && tlen
> 0) {
921 sflow_sample
= (const struct sflow_sample_header
*)tptr
;
922 ND_TCHECK(*sflow_sample
);
924 sflow_sample_type
= (EXTRACT_32BITS(sflow_sample
->format
)&0x0FFF);
925 sflow_sample_len
= EXTRACT_32BITS(sflow_sample
->len
);
927 if (tlen
< sizeof(struct sflow_sample_header
))
930 tptr
+= sizeof(struct sflow_sample_header
);
931 tlen
-= sizeof(struct sflow_sample_header
);
933 ND_PRINT((ndo
, "\n\t%s (%u), length %u,",
934 tok2str(sflow_format_values
, "Unknown", sflow_sample_type
),
938 /* basic sanity check */
939 if (sflow_sample_type
== 0 || sflow_sample_len
==0) {
943 if (tlen
< sflow_sample_len
)
946 /* did we capture enough for fully decoding the sample ? */
947 ND_TCHECK2(*tptr
, sflow_sample_len
);
949 switch(sflow_sample_type
) {
950 case SFLOW_FLOW_SAMPLE
:
951 if (sflow_print_flow_sample(ndo
, tptr
, tlen
))
955 case SFLOW_COUNTER_SAMPLE
:
956 if (sflow_print_counter_sample(ndo
, tptr
,tlen
))
960 case SFLOW_EXPANDED_FLOW_SAMPLE
:
961 if (sflow_print_expanded_flow_sample(ndo
, tptr
, tlen
))
965 case SFLOW_EXPANDED_COUNTER_SAMPLE
:
966 if (sflow_print_expanded_counter_sample(ndo
, tptr
,tlen
))
971 if (ndo
->ndo_vflag
<= 1)
972 print_unknown_data(ndo
, tptr
, "\n\t ", sflow_sample_len
);
975 tptr
+= sflow_sample_len
;
976 tlen
-= sflow_sample_len
;
982 ND_PRINT((ndo
, "[|SFLOW]"));
987 * c-style: whitesmith