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 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
17 * Expansion and refactoring by Rick Jones <rick.jones2@hp.com>
20 /* \summary: sFlow protocol printer */
22 /* specification: https://sflow.org/developers/specifications.php */
28 #include "netdissect-stdinc.h"
30 #define ND_LONGJMP_FROM_TCHECK
31 #include "netdissect.h"
33 #include "addrtoname.h"
39 * 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
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Sflow version (2,4,5) |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | IP version (1 for IPv4 | 2 for IPv6) |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | IP Address AGENT (4 or 16 bytes) |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | Datagram sequence number |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | Switch uptime in ms |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * | num samples in datagram |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 struct sflow_datagram_t
{
60 nd_uint32_t ip_version
;
68 struct sflow_v6_datagram_t
{
70 nd_uint32_t ip_version
;
78 struct sflow_sample_header
{
83 #define SFLOW_FLOW_SAMPLE 1
84 #define SFLOW_COUNTER_SAMPLE 2
85 #define SFLOW_EXPANDED_FLOW_SAMPLE 3
86 #define SFLOW_EXPANDED_COUNTER_SAMPLE 4
88 static const struct tok sflow_format_values
[] = {
89 { SFLOW_FLOW_SAMPLE
, "flow sample" },
90 { SFLOW_COUNTER_SAMPLE
, "counter sample" },
91 { SFLOW_EXPANDED_FLOW_SAMPLE
, "expanded flow sample" },
92 { SFLOW_EXPANDED_COUNTER_SAMPLE
, "expanded counter sample" },
96 struct sflow_flow_sample_t
{
103 nd_uint32_t in_interface
;
104 nd_uint32_t out_interface
;
109 struct sflow_expanded_flow_sample_t
{
116 nd_uint32_t in_interface_format
;
117 nd_uint32_t in_interface_value
;
118 nd_uint32_t out_interface_format
;
119 nd_uint32_t out_interface_value
;
123 #define SFLOW_FLOW_RAW_PACKET 1
124 #define SFLOW_FLOW_ETHERNET_FRAME 2
125 #define SFLOW_FLOW_IPV4_DATA 3
126 #define SFLOW_FLOW_IPV6_DATA 4
127 #define SFLOW_FLOW_EXTENDED_SWITCH_DATA 1001
128 #define SFLOW_FLOW_EXTENDED_ROUTER_DATA 1002
129 #define SFLOW_FLOW_EXTENDED_GATEWAY_DATA 1003
130 #define SFLOW_FLOW_EXTENDED_USER_DATA 1004
131 #define SFLOW_FLOW_EXTENDED_URL_DATA 1005
132 #define SFLOW_FLOW_EXTENDED_MPLS_DATA 1006
133 #define SFLOW_FLOW_EXTENDED_NAT_DATA 1007
134 #define SFLOW_FLOW_EXTENDED_MPLS_TUNNEL 1008
135 #define SFLOW_FLOW_EXTENDED_MPLS_VC 1009
136 #define SFLOW_FLOW_EXTENDED_MPLS_FEC 1010
137 #define SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC 1011
138 #define SFLOW_FLOW_EXTENDED_VLAN_TUNNEL 1012
140 static const struct tok sflow_flow_type_values
[] = {
141 { SFLOW_FLOW_RAW_PACKET
, "Raw packet"},
142 { SFLOW_FLOW_ETHERNET_FRAME
, "Ethernet frame"},
143 { SFLOW_FLOW_IPV4_DATA
, "IPv4 Data"},
144 { SFLOW_FLOW_IPV6_DATA
, "IPv6 Data"},
145 { SFLOW_FLOW_EXTENDED_SWITCH_DATA
, "Extended Switch data"},
146 { SFLOW_FLOW_EXTENDED_ROUTER_DATA
, "Extended Router data"},
147 { SFLOW_FLOW_EXTENDED_GATEWAY_DATA
, "Extended Gateway data"},
148 { SFLOW_FLOW_EXTENDED_USER_DATA
, "Extended User data"},
149 { SFLOW_FLOW_EXTENDED_URL_DATA
, "Extended URL data"},
150 { SFLOW_FLOW_EXTENDED_MPLS_DATA
, "Extended MPLS data"},
151 { SFLOW_FLOW_EXTENDED_NAT_DATA
, "Extended NAT data"},
152 { SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
, "Extended MPLS tunnel"},
153 { SFLOW_FLOW_EXTENDED_MPLS_VC
, "Extended MPLS VC"},
154 { SFLOW_FLOW_EXTENDED_MPLS_FEC
, "Extended MPLS FEC"},
155 { SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
, "Extended MPLS LVP FEC"},
156 { SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
, "Extended VLAN Tunnel"},
160 #define SFLOW_HEADER_PROTOCOL_ETHERNET 1
161 #define SFLOW_HEADER_PROTOCOL_IPV4 11
162 #define SFLOW_HEADER_PROTOCOL_IPV6 12
164 static const struct tok sflow_flow_raw_protocol_values
[] = {
165 { SFLOW_HEADER_PROTOCOL_ETHERNET
, "Ethernet"},
166 { SFLOW_HEADER_PROTOCOL_IPV4
, "IPv4"},
167 { SFLOW_HEADER_PROTOCOL_IPV6
, "IPv6"},
171 struct sflow_expanded_flow_raw_t
{
172 nd_uint32_t protocol
;
174 nd_uint32_t stripped_bytes
;
175 nd_uint32_t header_size
;
178 struct sflow_ethernet_frame_t
{
185 struct sflow_extended_switch_data_t
{
186 nd_uint32_t src_vlan
;
188 nd_uint32_t dst_vlan
;
192 struct sflow_counter_record_t
{
197 struct sflow_flow_record_t
{
202 struct sflow_counter_sample_t
{
209 struct sflow_expanded_counter_sample_t
{
216 #define SFLOW_COUNTER_GENERIC 1
217 #define SFLOW_COUNTER_ETHERNET 2
218 #define SFLOW_COUNTER_TOKEN_RING 3
219 #define SFLOW_COUNTER_BASEVG 4
220 #define SFLOW_COUNTER_VLAN 5
221 #define SFLOW_COUNTER_PROCESSOR 1001
223 static const struct tok sflow_counter_type_values
[] = {
224 { SFLOW_COUNTER_GENERIC
, "Generic counter"},
225 { SFLOW_COUNTER_ETHERNET
, "Ethernet counter"},
226 { SFLOW_COUNTER_TOKEN_RING
, "Token ring counter"},
227 { SFLOW_COUNTER_BASEVG
, "100 BaseVG counter"},
228 { SFLOW_COUNTER_VLAN
, "Vlan counter"},
229 { SFLOW_COUNTER_PROCESSOR
, "Processor counter"},
233 #define SFLOW_IFACE_DIRECTION_UNKNOWN 0
234 #define SFLOW_IFACE_DIRECTION_FULLDUPLEX 1
235 #define SFLOW_IFACE_DIRECTION_HALFDUPLEX 2
236 #define SFLOW_IFACE_DIRECTION_IN 3
237 #define SFLOW_IFACE_DIRECTION_OUT 4
239 static const struct tok sflow_iface_direction_values
[] = {
240 { SFLOW_IFACE_DIRECTION_UNKNOWN
, "unknown"},
241 { SFLOW_IFACE_DIRECTION_FULLDUPLEX
, "full-duplex"},
242 { SFLOW_IFACE_DIRECTION_HALFDUPLEX
, "half-duplex"},
243 { SFLOW_IFACE_DIRECTION_IN
, "in"},
244 { SFLOW_IFACE_DIRECTION_OUT
, "out"},
248 struct sflow_generic_counter_t
{
252 nd_uint32_t ifdirection
;
253 nd_uint32_t ifstatus
;
254 nd_uint64_t ifinoctets
;
255 nd_uint32_t ifinunicastpkts
;
256 nd_uint32_t ifinmulticastpkts
;
257 nd_uint32_t ifinbroadcastpkts
;
258 nd_uint32_t ifindiscards
;
259 nd_uint32_t ifinerrors
;
260 nd_uint32_t ifinunkownprotos
;
261 nd_uint64_t ifoutoctets
;
262 nd_uint32_t ifoutunicastpkts
;
263 nd_uint32_t ifoutmulticastpkts
;
264 nd_uint32_t ifoutbroadcastpkts
;
265 nd_uint32_t ifoutdiscards
;
266 nd_uint32_t ifouterrors
;
267 nd_uint32_t ifpromiscmode
;
270 struct sflow_ethernet_counter_t
{
271 nd_uint32_t alignerrors
;
272 nd_uint32_t fcserrors
;
273 nd_uint32_t single_collision_frames
;
274 nd_uint32_t multiple_collision_frames
;
275 nd_uint32_t test_errors
;
276 nd_uint32_t deferred_transmissions
;
277 nd_uint32_t late_collisions
;
278 nd_uint32_t excessive_collisions
;
279 nd_uint32_t mac_transmit_errors
;
280 nd_uint32_t carrier_sense_errors
;
281 nd_uint32_t frame_too_longs
;
282 nd_uint32_t mac_receive_errors
;
283 nd_uint32_t symbol_errors
;
286 struct sflow_100basevg_counter_t
{
287 nd_uint32_t in_highpriority_frames
;
288 nd_uint64_t in_highpriority_octets
;
289 nd_uint32_t in_normpriority_frames
;
290 nd_uint64_t in_normpriority_octets
;
291 nd_uint32_t in_ipmerrors
;
292 nd_uint32_t in_oversized
;
293 nd_uint32_t in_data_errors
;
294 nd_uint32_t in_null_addressed_frames
;
295 nd_uint32_t out_highpriority_frames
;
296 nd_uint64_t out_highpriority_octets
;
297 nd_uint32_t transitioninto_frames
;
298 nd_uint64_t hc_in_highpriority_octets
;
299 nd_uint64_t hc_in_normpriority_octets
;
300 nd_uint64_t hc_out_highpriority_octets
;
303 struct sflow_vlan_counter_t
{
306 nd_uint32_t unicast_pkt
;
307 nd_uint32_t multicast_pkt
;
308 nd_uint32_t broadcast_pkt
;
309 nd_uint32_t discards
;
313 print_sflow_counter_generic(netdissect_options
*ndo
,
314 const u_char
*pointer
, u_int len
)
316 const struct sflow_generic_counter_t
*sflow_gen_counter
;
318 if (len
< sizeof(struct sflow_generic_counter_t
))
321 sflow_gen_counter
= (const struct sflow_generic_counter_t
*)pointer
;
322 ND_PRINT("\n\t ifindex %u, iftype %u, ifspeed %" PRIu64
", ifdirection %u (%s)",
323 GET_BE_U_4(sflow_gen_counter
->ifindex
),
324 GET_BE_U_4(sflow_gen_counter
->iftype
),
325 GET_BE_U_8(sflow_gen_counter
->ifspeed
),
326 GET_BE_U_4(sflow_gen_counter
->ifdirection
),
327 tok2str(sflow_iface_direction_values
, "Unknown",
328 GET_BE_U_4(sflow_gen_counter
->ifdirection
)));
329 ND_PRINT("\n\t ifstatus %u, adminstatus: %s, operstatus: %s",
330 GET_BE_U_4(sflow_gen_counter
->ifstatus
),
331 GET_BE_U_4(sflow_gen_counter
->ifstatus
)&1 ? "up" : "down",
332 (GET_BE_U_4(sflow_gen_counter
->ifstatus
)>>1)&1 ? "up" : "down");
333 ND_PRINT("\n\t In octets %" PRIu64
334 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
335 GET_BE_U_8(sflow_gen_counter
->ifinoctets
),
336 GET_BE_U_4(sflow_gen_counter
->ifinunicastpkts
),
337 GET_BE_U_4(sflow_gen_counter
->ifinmulticastpkts
),
338 GET_BE_U_4(sflow_gen_counter
->ifinbroadcastpkts
),
339 GET_BE_U_4(sflow_gen_counter
->ifindiscards
));
340 ND_PRINT("\n\t In errors %u, unknown protos %u",
341 GET_BE_U_4(sflow_gen_counter
->ifinerrors
),
342 GET_BE_U_4(sflow_gen_counter
->ifinunkownprotos
));
343 ND_PRINT("\n\t Out octets %" PRIu64
344 ", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
345 GET_BE_U_8(sflow_gen_counter
->ifoutoctets
),
346 GET_BE_U_4(sflow_gen_counter
->ifoutunicastpkts
),
347 GET_BE_U_4(sflow_gen_counter
->ifoutmulticastpkts
),
348 GET_BE_U_4(sflow_gen_counter
->ifoutbroadcastpkts
),
349 GET_BE_U_4(sflow_gen_counter
->ifoutdiscards
));
350 ND_PRINT("\n\t Out errors %u, promisc mode %u",
351 GET_BE_U_4(sflow_gen_counter
->ifouterrors
),
352 GET_BE_U_4(sflow_gen_counter
->ifpromiscmode
));
358 print_sflow_counter_ethernet(netdissect_options
*ndo
,
359 const u_char
*pointer
, u_int len
)
361 const struct sflow_ethernet_counter_t
*sflow_eth_counter
;
363 if (len
< sizeof(struct sflow_ethernet_counter_t
))
366 sflow_eth_counter
= (const struct sflow_ethernet_counter_t
*)pointer
;
367 ND_PRINT("\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u",
368 GET_BE_U_4(sflow_eth_counter
->alignerrors
),
369 GET_BE_U_4(sflow_eth_counter
->fcserrors
),
370 GET_BE_U_4(sflow_eth_counter
->single_collision_frames
),
371 GET_BE_U_4(sflow_eth_counter
->multiple_collision_frames
),
372 GET_BE_U_4(sflow_eth_counter
->test_errors
));
373 ND_PRINT("\n\t deferred %u, late collision %u, excessive collision %u, mac trans error %u",
374 GET_BE_U_4(sflow_eth_counter
->deferred_transmissions
),
375 GET_BE_U_4(sflow_eth_counter
->late_collisions
),
376 GET_BE_U_4(sflow_eth_counter
->excessive_collisions
),
377 GET_BE_U_4(sflow_eth_counter
->mac_transmit_errors
));
378 ND_PRINT("\n\t carrier error %u, frames too long %u, mac receive errors %u, symbol errors %u",
379 GET_BE_U_4(sflow_eth_counter
->carrier_sense_errors
),
380 GET_BE_U_4(sflow_eth_counter
->frame_too_longs
),
381 GET_BE_U_4(sflow_eth_counter
->mac_receive_errors
),
382 GET_BE_U_4(sflow_eth_counter
->symbol_errors
));
388 print_sflow_counter_token_ring(netdissect_options
*ndo _U_
,
389 const u_char
*pointer _U_
, u_int len _U_
)
395 print_sflow_counter_basevg(netdissect_options
*ndo
,
396 const u_char
*pointer
, u_int len
)
398 const struct sflow_100basevg_counter_t
*sflow_100basevg_counter
;
400 if (len
< sizeof(struct sflow_100basevg_counter_t
))
403 sflow_100basevg_counter
= (const struct sflow_100basevg_counter_t
*)pointer
;
404 ND_PRINT("\n\t in high prio frames %u, in high prio octets %" PRIu64
,
405 GET_BE_U_4(sflow_100basevg_counter
->in_highpriority_frames
),
406 GET_BE_U_8(sflow_100basevg_counter
->in_highpriority_octets
));
407 ND_PRINT("\n\t in norm prio frames %u, in norm prio octets %" PRIu64
,
408 GET_BE_U_4(sflow_100basevg_counter
->in_normpriority_frames
),
409 GET_BE_U_8(sflow_100basevg_counter
->in_normpriority_octets
));
410 ND_PRINT("\n\t in ipm errors %u, oversized %u, in data errors %u, null addressed frames %u",
411 GET_BE_U_4(sflow_100basevg_counter
->in_ipmerrors
),
412 GET_BE_U_4(sflow_100basevg_counter
->in_oversized
),
413 GET_BE_U_4(sflow_100basevg_counter
->in_data_errors
),
414 GET_BE_U_4(sflow_100basevg_counter
->in_null_addressed_frames
));
415 ND_PRINT("\n\t out high prio frames %u, out high prio octets %" PRIu64
416 ", trans into frames %u",
417 GET_BE_U_4(sflow_100basevg_counter
->out_highpriority_frames
),
418 GET_BE_U_8(sflow_100basevg_counter
->out_highpriority_octets
),
419 GET_BE_U_4(sflow_100basevg_counter
->transitioninto_frames
));
420 ND_PRINT("\n\t in hc high prio octets %" PRIu64
421 ", in hc norm prio octets %" PRIu64
422 ", out hc high prio octets %" PRIu64
,
423 GET_BE_U_8(sflow_100basevg_counter
->hc_in_highpriority_octets
),
424 GET_BE_U_8(sflow_100basevg_counter
->hc_in_normpriority_octets
),
425 GET_BE_U_8(sflow_100basevg_counter
->hc_out_highpriority_octets
));
431 print_sflow_counter_vlan(netdissect_options
*ndo
,
432 const u_char
*pointer
, u_int len
)
434 const struct sflow_vlan_counter_t
*sflow_vlan_counter
;
436 if (len
< sizeof(struct sflow_vlan_counter_t
))
439 sflow_vlan_counter
= (const struct sflow_vlan_counter_t
*)pointer
;
440 ND_PRINT("\n\t vlan_id %u, octets %" PRIu64
441 ", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u",
442 GET_BE_U_4(sflow_vlan_counter
->vlan_id
),
443 GET_BE_U_8(sflow_vlan_counter
->octets
),
444 GET_BE_U_4(sflow_vlan_counter
->unicast_pkt
),
445 GET_BE_U_4(sflow_vlan_counter
->multicast_pkt
),
446 GET_BE_U_4(sflow_vlan_counter
->broadcast_pkt
),
447 GET_BE_U_4(sflow_vlan_counter
->discards
));
452 struct sflow_processor_counter_t
{
453 nd_uint32_t five_sec_util
;
454 nd_uint32_t one_min_util
;
455 nd_uint32_t five_min_util
;
456 nd_uint64_t total_memory
;
457 nd_uint64_t free_memory
;
461 print_sflow_counter_processor(netdissect_options
*ndo
,
462 const u_char
*pointer
, u_int len
)
464 const struct sflow_processor_counter_t
*sflow_processor_counter
;
466 if (len
< sizeof(struct sflow_processor_counter_t
))
469 sflow_processor_counter
= (const struct sflow_processor_counter_t
*)pointer
;
470 ND_PRINT("\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64
471 ", total_mem %" PRIu64
,
472 GET_BE_U_4(sflow_processor_counter
->five_sec_util
),
473 GET_BE_U_4(sflow_processor_counter
->one_min_util
),
474 GET_BE_U_4(sflow_processor_counter
->five_min_util
),
475 GET_BE_U_8(sflow_processor_counter
->total_memory
),
476 GET_BE_U_8(sflow_processor_counter
->free_memory
));
482 sflow_print_counter_records(netdissect_options
*ndo
,
483 const u_char
*pointer
, u_int len
, u_int records
)
491 const struct sflow_counter_record_t
*sflow_counter_record
;
497 while (nrecords
> 0) {
498 /* do we have the "header?" */
499 if (tlen
< sizeof(struct sflow_counter_record_t
))
501 sflow_counter_record
= (const struct sflow_counter_record_t
*)tptr
;
503 enterprise
= GET_BE_U_4(sflow_counter_record
->format
);
504 counter_type
= enterprise
& 0x0FFF;
505 enterprise
= enterprise
>> 20;
506 counter_len
= GET_BE_U_4(sflow_counter_record
->length
);
507 ND_PRINT("\n\t enterprise %u, %s (%u) length %u",
509 (enterprise
== 0) ? tok2str(sflow_counter_type_values
,"Unknown",counter_type
) : "Unknown",
513 tptr
+= sizeof(struct sflow_counter_record_t
);
514 tlen
-= sizeof(struct sflow_counter_record_t
);
516 if (tlen
< counter_len
)
518 if (enterprise
== 0) {
519 switch (counter_type
) {
520 case SFLOW_COUNTER_GENERIC
:
521 if (print_sflow_counter_generic(ndo
, tptr
, tlen
))
524 case SFLOW_COUNTER_ETHERNET
:
525 if (print_sflow_counter_ethernet(ndo
, tptr
, tlen
))
528 case SFLOW_COUNTER_TOKEN_RING
:
529 if (print_sflow_counter_token_ring(ndo
, tptr
,tlen
))
532 case SFLOW_COUNTER_BASEVG
:
533 if (print_sflow_counter_basevg(ndo
, tptr
, tlen
))
536 case SFLOW_COUNTER_VLAN
:
537 if (print_sflow_counter_vlan(ndo
, tptr
, tlen
))
540 case SFLOW_COUNTER_PROCESSOR
:
541 if (print_sflow_counter_processor(ndo
, tptr
, tlen
))
545 if (ndo
->ndo_vflag
<= 1)
546 print_unknown_data(ndo
, tptr
, "\n\t\t", counter_len
);
560 sflow_print_counter_sample(netdissect_options
*ndo
,
561 const u_char
*pointer
, u_int len
)
563 const struct sflow_counter_sample_t
*sflow_counter_sample
;
566 if (len
< sizeof(struct sflow_counter_sample_t
))
569 sflow_counter_sample
= (const struct sflow_counter_sample_t
*)pointer
;
571 nrecords
= GET_BE_U_4(sflow_counter_sample
->records
);
573 ND_PRINT(" seqnum %u, type %u, idx %u, records %u",
574 GET_BE_U_4(sflow_counter_sample
->seqnum
),
575 GET_U_1(sflow_counter_sample
->type
),
576 GET_BE_U_3(sflow_counter_sample
->index
),
579 return sflow_print_counter_records(ndo
, pointer
+ sizeof(struct sflow_counter_sample_t
),
580 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
= GET_BE_U_4(sflow_expanded_counter_sample
->records
);
599 ND_PRINT(" seqnum %u, type %u, idx %u, records %u",
600 GET_BE_U_4(sflow_expanded_counter_sample
->seqnum
),
601 GET_BE_U_4(sflow_expanded_counter_sample
->type
),
602 GET_BE_U_4(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
),
611 print_sflow_raw_packet(netdissect_options
*ndo
,
612 const u_char
*pointer
, u_int len
)
614 const struct sflow_expanded_flow_raw_t
*sflow_flow_raw
;
616 if (len
< sizeof(struct sflow_expanded_flow_raw_t
))
619 sflow_flow_raw
= (const struct sflow_expanded_flow_raw_t
*)pointer
;
620 ND_PRINT("\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u",
621 tok2str(sflow_flow_raw_protocol_values
,"Unknown",GET_BE_U_4(sflow_flow_raw
->protocol
)),
622 GET_BE_U_4(sflow_flow_raw
->protocol
),
623 GET_BE_U_4(sflow_flow_raw
->length
),
624 GET_BE_U_4(sflow_flow_raw
->stripped_bytes
),
625 GET_BE_U_4(sflow_flow_raw
->header_size
));
627 /* QUESTION - should we attempt to print the raw header itself?
628 assuming of course there is enough data present to do so... */
634 print_sflow_ethernet_frame(netdissect_options
*ndo
,
635 const u_char
*pointer
, u_int len
)
637 const struct sflow_ethernet_frame_t
*sflow_ethernet_frame
;
639 if (len
< sizeof(struct sflow_ethernet_frame_t
))
642 sflow_ethernet_frame
= (const struct sflow_ethernet_frame_t
*)pointer
;
644 ND_PRINT("\n\t frame len %u, type %u",
645 GET_BE_U_4(sflow_ethernet_frame
->length
),
646 GET_BE_U_4(sflow_ethernet_frame
->type
));
652 print_sflow_extended_switch_data(netdissect_options
*ndo
,
653 const u_char
*pointer
, u_int len
)
655 const struct sflow_extended_switch_data_t
*sflow_extended_sw_data
;
657 if (len
< sizeof(struct sflow_extended_switch_data_t
))
660 sflow_extended_sw_data
= (const struct sflow_extended_switch_data_t
*)pointer
;
661 ND_PRINT("\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u",
662 GET_BE_U_4(sflow_extended_sw_data
->src_vlan
),
663 GET_BE_U_4(sflow_extended_sw_data
->src_pri
),
664 GET_BE_U_4(sflow_extended_sw_data
->dst_vlan
),
665 GET_BE_U_4(sflow_extended_sw_data
->dst_pri
));
671 sflow_print_flow_records(netdissect_options
*ndo
,
672 const u_char
*pointer
, u_int len
, u_int records
)
680 const struct sflow_flow_record_t
*sflow_flow_record
;
686 while (nrecords
> 0) {
687 /* do we have the "header?" */
688 if (tlen
< sizeof(struct sflow_flow_record_t
))
691 sflow_flow_record
= (const struct sflow_flow_record_t
*)tptr
;
693 /* so, the funky encoding means we cannot blythly mask-off
694 bits, we must also check the enterprise. */
696 enterprise
= GET_BE_U_4(sflow_flow_record
->format
);
697 flow_type
= enterprise
& 0x0FFF;
698 enterprise
= enterprise
>> 12;
699 flow_len
= GET_BE_U_4(sflow_flow_record
->length
);
700 ND_PRINT("\n\t enterprise %u %s (%u) length %u",
702 (enterprise
== 0) ? tok2str(sflow_flow_type_values
,"Unknown",flow_type
) : "Unknown",
706 tptr
+= sizeof(struct sflow_flow_record_t
);
707 tlen
-= sizeof(struct sflow_flow_record_t
);
712 if (enterprise
== 0) {
714 case SFLOW_FLOW_RAW_PACKET
:
715 if (print_sflow_raw_packet(ndo
, tptr
, tlen
))
718 case SFLOW_FLOW_EXTENDED_SWITCH_DATA
:
719 if (print_sflow_extended_switch_data(ndo
, tptr
, tlen
))
722 case SFLOW_FLOW_ETHERNET_FRAME
:
723 if (print_sflow_ethernet_frame(ndo
, tptr
, tlen
))
726 /* FIXME these need a decoder */
727 case SFLOW_FLOW_IPV4_DATA
:
728 case SFLOW_FLOW_IPV6_DATA
:
729 case SFLOW_FLOW_EXTENDED_ROUTER_DATA
:
730 case SFLOW_FLOW_EXTENDED_GATEWAY_DATA
:
731 case SFLOW_FLOW_EXTENDED_USER_DATA
:
732 case SFLOW_FLOW_EXTENDED_URL_DATA
:
733 case SFLOW_FLOW_EXTENDED_MPLS_DATA
:
734 case SFLOW_FLOW_EXTENDED_NAT_DATA
:
735 case SFLOW_FLOW_EXTENDED_MPLS_TUNNEL
:
736 case SFLOW_FLOW_EXTENDED_MPLS_VC
:
737 case SFLOW_FLOW_EXTENDED_MPLS_FEC
:
738 case SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC
:
739 case SFLOW_FLOW_EXTENDED_VLAN_TUNNEL
:
742 if (ndo
->ndo_vflag
<= 1)
743 print_unknown_data(ndo
, tptr
, "\n\t\t", flow_len
);
757 sflow_print_flow_sample(netdissect_options
*ndo
,
758 const u_char
*pointer
, u_int len
)
760 const struct sflow_flow_sample_t
*sflow_flow_sample
;
763 if (len
< sizeof(struct sflow_flow_sample_t
))
766 sflow_flow_sample
= (const struct sflow_flow_sample_t
*)pointer
;
768 nrecords
= GET_BE_U_4(sflow_flow_sample
->records
);
770 ND_PRINT(" seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, input %u output %u records %u",
771 GET_BE_U_4(sflow_flow_sample
->seqnum
),
772 GET_U_1(sflow_flow_sample
->type
),
773 GET_BE_U_3(sflow_flow_sample
->index
),
774 GET_BE_U_4(sflow_flow_sample
->rate
),
775 GET_BE_U_4(sflow_flow_sample
->pool
),
776 GET_BE_U_4(sflow_flow_sample
->drops
),
777 GET_BE_U_4(sflow_flow_sample
->in_interface
),
778 GET_BE_U_4(sflow_flow_sample
->out_interface
),
781 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_flow_sample_t
),
782 len
- sizeof(struct sflow_flow_sample_t
),
787 sflow_print_expanded_flow_sample(netdissect_options
*ndo
,
788 const u_char
*pointer
, u_int len
)
790 const struct sflow_expanded_flow_sample_t
*sflow_expanded_flow_sample
;
793 if (len
< sizeof(struct sflow_expanded_flow_sample_t
))
796 sflow_expanded_flow_sample
= (const struct sflow_expanded_flow_sample_t
*)pointer
;
798 nrecords
= GET_BE_U_4(sflow_expanded_flow_sample
->records
);
800 ND_PRINT(" seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, records %u",
801 GET_BE_U_4(sflow_expanded_flow_sample
->seqnum
),
802 GET_BE_U_4(sflow_expanded_flow_sample
->type
),
803 GET_BE_U_4(sflow_expanded_flow_sample
->index
),
804 GET_BE_U_4(sflow_expanded_flow_sample
->rate
),
805 GET_BE_U_4(sflow_expanded_flow_sample
->pool
),
806 GET_BE_U_4(sflow_expanded_flow_sample
->drops
),
809 return sflow_print_flow_records(ndo
, pointer
+ sizeof(struct sflow_expanded_flow_sample_t
),
810 len
- sizeof(struct sflow_expanded_flow_sample_t
),
815 sflow_print(netdissect_options
*ndo
,
816 const u_char
*pptr
, u_int len
)
818 const struct sflow_datagram_t
*sflow_datagram
;
819 const struct sflow_v6_datagram_t
*sflow_v6_datagram
;
820 const struct sflow_sample_header
*sflow_sample
;
824 uint32_t sflow_sample_type
, sflow_sample_len
;
828 ndo
->ndo_protocol
= "sflow";
831 sflow_datagram
= (const struct sflow_datagram_t
*)pptr
;
832 sflow_v6_datagram
= (const struct sflow_v6_datagram_t
*)pptr
;
833 ip_version
= GET_BE_U_4(sflow_datagram
->ip_version
);
835 if ((len
< sizeof(struct sflow_datagram_t
) && (ip_version
== 1)) ||
836 (len
< sizeof(struct sflow_v6_datagram_t
) && (ip_version
== 2))) {
837 ND_PRINT("sFlowv%u", GET_BE_U_4(sflow_datagram
->version
));
838 ND_PRINT(" [length %u < %zu]", len
, sizeof(struct sflow_datagram_t
));
839 nd_print_invalid(ndo
);
842 ND_TCHECK_SIZE(sflow_datagram
);
845 * Sanity checking of the header.
847 if (GET_BE_U_4(sflow_datagram
->version
) != 5) {
848 ND_PRINT("sFlow version %u packet not supported",
849 GET_BE_U_4(sflow_datagram
->version
));
853 if (ndo
->ndo_vflag
< 1) {
854 ND_PRINT("sFlowv%u, %s agent %s, agent-id %u, length %u",
855 GET_BE_U_4(sflow_datagram
->version
),
856 ip_version
== 1 ? "IPv4" : "IPv6",
857 ip_version
== 1 ? GET_IPADDR_STRING(sflow_datagram
->agent
) :
858 GET_IP6ADDR_STRING( sflow_v6_datagram
->agent
),
859 ip_version
== 1 ? GET_BE_U_4(sflow_datagram
->agent_id
) :
860 GET_BE_U_4(sflow_v6_datagram
->agent_id
),
865 /* ok they seem to want to know everything - lets fully decode it */
866 if (ip_version
== 1) {
867 nsamples
= GET_BE_U_4(sflow_datagram
->samples
);
868 ND_PRINT("sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
869 GET_BE_U_4(sflow_datagram
->version
),
871 GET_IPADDR_STRING(sflow_datagram
->agent
),
872 GET_BE_U_4(sflow_datagram
->agent_id
),
873 GET_BE_U_4(sflow_datagram
->seqnum
),
874 GET_BE_U_4(sflow_datagram
->uptime
),
878 /* skip Common header */
879 tptr
+= sizeof(struct sflow_datagram_t
);
880 tlen
-= sizeof(struct sflow_datagram_t
);
882 nsamples
= GET_BE_U_4(sflow_v6_datagram
->samples
);
883 ND_PRINT("sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
884 GET_BE_U_4(sflow_v6_datagram
->version
),
886 GET_IP6ADDR_STRING(sflow_v6_datagram
->agent
),
887 GET_BE_U_4(sflow_v6_datagram
->agent_id
),
888 GET_BE_U_4(sflow_v6_datagram
->seqnum
),
889 GET_BE_U_4(sflow_v6_datagram
->uptime
),
893 /* skip Common header */
894 ND_ICHECK_ZU(tlen
, <, sizeof(struct sflow_v6_datagram_t
));
895 tptr
+= sizeof(struct sflow_v6_datagram_t
);
896 tlen
-= sizeof(struct sflow_v6_datagram_t
);
898 while (nsamples
> 0 && tlen
> 0) {
899 sflow_sample
= (const struct sflow_sample_header
*)tptr
;
901 sflow_sample_type
= (GET_BE_U_4(sflow_sample
->format
)&0x0FFF);
902 sflow_sample_len
= GET_BE_U_4(sflow_sample
->len
);
904 if (tlen
< sizeof(struct sflow_sample_header
))
907 tptr
+= sizeof(struct sflow_sample_header
);
908 tlen
-= sizeof(struct sflow_sample_header
);
910 ND_PRINT("\n\t%s (%u), length %u,",
911 tok2str(sflow_format_values
, "Unknown", sflow_sample_type
),
915 /* basic sanity check */
916 if (sflow_sample_type
== 0 || sflow_sample_len
== 0) {
920 if (tlen
< sflow_sample_len
)
923 /* did we capture enough for fully decoding the sample ? */
924 ND_TCHECK_LEN(tptr
, sflow_sample_len
);
926 switch(sflow_sample_type
) {
927 case SFLOW_FLOW_SAMPLE
:
928 if (sflow_print_flow_sample(ndo
, tptr
, tlen
))
932 case SFLOW_COUNTER_SAMPLE
:
933 if (sflow_print_counter_sample(ndo
, tptr
,tlen
))
937 case SFLOW_EXPANDED_FLOW_SAMPLE
:
938 if (sflow_print_expanded_flow_sample(ndo
, tptr
, tlen
))
942 case SFLOW_EXPANDED_COUNTER_SAMPLE
:
943 if (sflow_print_expanded_counter_sample(ndo
, tptr
,tlen
))
948 if (ndo
->ndo_vflag
<= 1)
949 print_unknown_data(ndo
, tptr
, "\n\t ", sflow_sample_len
);
952 tptr
+= sflow_sample_len
;
953 tlen
-= sflow_sample_len
;
959 nd_print_invalid(ndo
);
960 ND_TCHECK_LEN(tptr
, tlen
);