2007-08-09 01:20:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998-2007 The TCPDUMP project
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code
|
|
|
|
* distributions retain the above copyright notice and this paragraph
|
|
|
|
* in its entirety, and (2) distributions including binary code include
|
|
|
|
* the above copyright notice and this paragraph in its entirety in
|
|
|
|
* the documentation or other materials provided with the distribution.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
|
|
|
|
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
|
|
|
|
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
|
2011-04-15 02:32:08 +08:00
|
|
|
*
|
|
|
|
* Expansion and refactoring by Rick Jones <rick.jones2@hp.com>
|
2007-08-09 01:20:58 +08:00
|
|
|
*/
|
|
|
|
|
2016-08-15 21:27:28 +08:00
|
|
|
/* \summary: sFlow protocol printer */
|
|
|
|
|
2019-08-05 21:11:50 +08:00
|
|
|
/* specification: https://sflow.org/developers/specifications.php */
|
2016-08-15 21:27:28 +08:00
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2007-08-09 01:20:58 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2007-08-09 01:20:58 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2007-08-09 01:20:58 +08:00
|
|
|
#include "extract.h"
|
|
|
|
#include "addrtoname.h"
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
/*
|
2007-08-09 01:20:58 +08:00
|
|
|
* sFlow datagram
|
2014-01-02 10:27:54 +08:00
|
|
|
*
|
2007-08-09 01:20:58 +08:00
|
|
|
* 0 1 2 3
|
|
|
|
* 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
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Sflow version (2,4,5) |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | IP version (1 for IPv4 | 2 for IPv6) |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | IP Address AGENT (4 or 16 bytes) |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Sub agent ID |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Datagram sequence number |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Switch uptime in ms |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | num samples in datagram |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-01-02 10:27:54 +08:00
|
|
|
*
|
2007-08-09 01:20:58 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct sflow_datagram_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t version;
|
|
|
|
nd_uint32_t ip_version;
|
|
|
|
nd_ipv4 agent;
|
|
|
|
nd_uint32_t agent_id;
|
|
|
|
nd_uint32_t seqnum;
|
|
|
|
nd_uint32_t uptime;
|
|
|
|
nd_uint32_t samples;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_sample_header {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t format;
|
|
|
|
nd_uint32_t len;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SFLOW_FLOW_SAMPLE 1
|
|
|
|
#define SFLOW_COUNTER_SAMPLE 2
|
|
|
|
#define SFLOW_EXPANDED_FLOW_SAMPLE 3
|
|
|
|
#define SFLOW_EXPANDED_COUNTER_SAMPLE 4
|
|
|
|
|
|
|
|
static const struct tok sflow_format_values[] = {
|
|
|
|
{ SFLOW_FLOW_SAMPLE, "flow sample" },
|
|
|
|
{ SFLOW_COUNTER_SAMPLE, "counter sample" },
|
|
|
|
{ SFLOW_EXPANDED_FLOW_SAMPLE, "expanded flow sample" },
|
|
|
|
{ SFLOW_EXPANDED_COUNTER_SAMPLE, "expanded counter sample" },
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
struct sflow_flow_sample_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t seqnum;
|
2017-12-31 18:04:12 +08:00
|
|
|
nd_uint8_t type;
|
|
|
|
nd_uint24_t index;
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t rate;
|
|
|
|
nd_uint32_t pool;
|
|
|
|
nd_uint32_t drops;
|
|
|
|
nd_uint32_t in_interface;
|
|
|
|
nd_uint32_t out_interface;
|
|
|
|
nd_uint32_t records;
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
struct sflow_expanded_flow_sample_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t seqnum;
|
|
|
|
nd_uint32_t type;
|
|
|
|
nd_uint32_t index;
|
|
|
|
nd_uint32_t rate;
|
|
|
|
nd_uint32_t pool;
|
|
|
|
nd_uint32_t drops;
|
|
|
|
nd_uint32_t in_interface_format;
|
|
|
|
nd_uint32_t in_interface_value;
|
|
|
|
nd_uint32_t out_interface_format;
|
|
|
|
nd_uint32_t out_interface_value;
|
|
|
|
nd_uint32_t records;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SFLOW_FLOW_RAW_PACKET 1
|
|
|
|
#define SFLOW_FLOW_ETHERNET_FRAME 2
|
|
|
|
#define SFLOW_FLOW_IPV4_DATA 3
|
|
|
|
#define SFLOW_FLOW_IPV6_DATA 4
|
|
|
|
#define SFLOW_FLOW_EXTENDED_SWITCH_DATA 1001
|
|
|
|
#define SFLOW_FLOW_EXTENDED_ROUTER_DATA 1002
|
|
|
|
#define SFLOW_FLOW_EXTENDED_GATEWAY_DATA 1003
|
|
|
|
#define SFLOW_FLOW_EXTENDED_USER_DATA 1004
|
|
|
|
#define SFLOW_FLOW_EXTENDED_URL_DATA 1005
|
|
|
|
#define SFLOW_FLOW_EXTENDED_MPLS_DATA 1006
|
|
|
|
#define SFLOW_FLOW_EXTENDED_NAT_DATA 1007
|
|
|
|
#define SFLOW_FLOW_EXTENDED_MPLS_TUNNEL 1008
|
|
|
|
#define SFLOW_FLOW_EXTENDED_MPLS_VC 1009
|
|
|
|
#define SFLOW_FLOW_EXTENDED_MPLS_FEC 1010
|
|
|
|
#define SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC 1011
|
|
|
|
#define SFLOW_FLOW_EXTENDED_VLAN_TUNNEL 1012
|
|
|
|
|
|
|
|
static const struct tok sflow_flow_type_values[] = {
|
|
|
|
{ SFLOW_FLOW_RAW_PACKET, "Raw packet"},
|
|
|
|
{ SFLOW_FLOW_ETHERNET_FRAME, "Ethernet frame"},
|
|
|
|
{ SFLOW_FLOW_IPV4_DATA, "IPv4 Data"},
|
|
|
|
{ SFLOW_FLOW_IPV6_DATA, "IPv6 Data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_SWITCH_DATA, "Extended Switch data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_ROUTER_DATA, "Extended Router data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_GATEWAY_DATA, "Extended Gateway data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_USER_DATA, "Extended User data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_URL_DATA, "Extended URL data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_MPLS_DATA, "Extended MPLS data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_NAT_DATA, "Extended NAT data"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_MPLS_TUNNEL, "Extended MPLS tunnel"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_MPLS_VC, "Extended MPLS VC"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_MPLS_FEC, "Extended MPLS FEC"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC, "Extended MPLS LVP FEC"},
|
|
|
|
{ SFLOW_FLOW_EXTENDED_VLAN_TUNNEL, "Extended VLAN Tunnel"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SFLOW_HEADER_PROTOCOL_ETHERNET 1
|
|
|
|
#define SFLOW_HEADER_PROTOCOL_IPV4 11
|
|
|
|
#define SFLOW_HEADER_PROTOCOL_IPV6 12
|
|
|
|
|
|
|
|
static const struct tok sflow_flow_raw_protocol_values[] = {
|
|
|
|
{ SFLOW_HEADER_PROTOCOL_ETHERNET, "Ethernet"},
|
|
|
|
{ SFLOW_HEADER_PROTOCOL_IPV4, "IPv4"},
|
|
|
|
{ SFLOW_HEADER_PROTOCOL_IPV6, "IPv6"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
struct sflow_expanded_flow_raw_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t protocol;
|
|
|
|
nd_uint32_t length;
|
|
|
|
nd_uint32_t stripped_bytes;
|
|
|
|
nd_uint32_t header_size;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
2011-04-16 01:01:02 +08:00
|
|
|
struct sflow_ethernet_frame_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t length;
|
|
|
|
nd_byte src_mac[8];
|
|
|
|
nd_byte dst_mac[8];
|
|
|
|
nd_uint32_t type;
|
2011-04-16 01:01:02 +08:00
|
|
|
};
|
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
struct sflow_extended_switch_data_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t src_vlan;
|
|
|
|
nd_uint32_t src_pri;
|
|
|
|
nd_uint32_t dst_vlan;
|
|
|
|
nd_uint32_t dst_pri;
|
2011-04-15 02:32:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_counter_record_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t format;
|
|
|
|
nd_uint32_t length;
|
2011-04-15 02:32:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_flow_record_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t format;
|
|
|
|
nd_uint32_t length;
|
2011-04-15 02:32:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_counter_sample_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t seqnum;
|
2017-12-31 18:04:12 +08:00
|
|
|
nd_uint8_t type;
|
|
|
|
nd_uint24_t index;
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t records;
|
2011-04-15 02:32:08 +08:00
|
|
|
};
|
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
struct sflow_expanded_counter_sample_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t seqnum;
|
|
|
|
nd_uint32_t type;
|
|
|
|
nd_uint32_t index;
|
|
|
|
nd_uint32_t records;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SFLOW_COUNTER_GENERIC 1
|
|
|
|
#define SFLOW_COUNTER_ETHERNET 2
|
|
|
|
#define SFLOW_COUNTER_TOKEN_RING 3
|
|
|
|
#define SFLOW_COUNTER_BASEVG 4
|
|
|
|
#define SFLOW_COUNTER_VLAN 5
|
|
|
|
#define SFLOW_COUNTER_PROCESSOR 1001
|
|
|
|
|
|
|
|
static const struct tok sflow_counter_type_values[] = {
|
|
|
|
{ SFLOW_COUNTER_GENERIC, "Generic counter"},
|
|
|
|
{ SFLOW_COUNTER_ETHERNET, "Ethernet counter"},
|
|
|
|
{ SFLOW_COUNTER_TOKEN_RING, "Token ring counter"},
|
|
|
|
{ SFLOW_COUNTER_BASEVG, "100 BaseVG counter"},
|
|
|
|
{ SFLOW_COUNTER_VLAN, "Vlan counter"},
|
|
|
|
{ SFLOW_COUNTER_PROCESSOR, "Processor counter"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SFLOW_IFACE_DIRECTION_UNKNOWN 0
|
|
|
|
#define SFLOW_IFACE_DIRECTION_FULLDUPLEX 1
|
|
|
|
#define SFLOW_IFACE_DIRECTION_HALFDUPLEX 2
|
|
|
|
#define SFLOW_IFACE_DIRECTION_IN 3
|
|
|
|
#define SFLOW_IFACE_DIRECTION_OUT 4
|
|
|
|
|
|
|
|
static const struct tok sflow_iface_direction_values[] = {
|
|
|
|
{ SFLOW_IFACE_DIRECTION_UNKNOWN, "unknown"},
|
|
|
|
{ SFLOW_IFACE_DIRECTION_FULLDUPLEX, "full-duplex"},
|
|
|
|
{ SFLOW_IFACE_DIRECTION_HALFDUPLEX, "half-duplex"},
|
|
|
|
{ SFLOW_IFACE_DIRECTION_IN, "in"},
|
|
|
|
{ SFLOW_IFACE_DIRECTION_OUT, "out"},
|
|
|
|
{ 0, NULL}
|
2014-01-02 10:27:54 +08:00
|
|
|
};
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
struct sflow_generic_counter_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t ifindex;
|
|
|
|
nd_uint32_t iftype;
|
|
|
|
nd_uint64_t ifspeed;
|
|
|
|
nd_uint32_t ifdirection;
|
|
|
|
nd_uint32_t ifstatus;
|
|
|
|
nd_uint64_t ifinoctets;
|
|
|
|
nd_uint32_t ifinunicastpkts;
|
|
|
|
nd_uint32_t ifinmulticastpkts;
|
|
|
|
nd_uint32_t ifinbroadcastpkts;
|
|
|
|
nd_uint32_t ifindiscards;
|
|
|
|
nd_uint32_t ifinerrors;
|
|
|
|
nd_uint32_t ifinunkownprotos;
|
|
|
|
nd_uint64_t ifoutoctets;
|
|
|
|
nd_uint32_t ifoutunicastpkts;
|
|
|
|
nd_uint32_t ifoutmulticastpkts;
|
|
|
|
nd_uint32_t ifoutbroadcastpkts;
|
|
|
|
nd_uint32_t ifoutdiscards;
|
|
|
|
nd_uint32_t ifouterrors;
|
|
|
|
nd_uint32_t ifpromiscmode;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_ethernet_counter_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t alignerrors;
|
|
|
|
nd_uint32_t fcserrors;
|
|
|
|
nd_uint32_t single_collision_frames;
|
|
|
|
nd_uint32_t multiple_collision_frames;
|
|
|
|
nd_uint32_t test_errors;
|
|
|
|
nd_uint32_t deferred_transmissions;
|
|
|
|
nd_uint32_t late_collisions;
|
|
|
|
nd_uint32_t excessive_collisions;
|
|
|
|
nd_uint32_t mac_transmit_errors;
|
|
|
|
nd_uint32_t carrier_sense_errors;
|
|
|
|
nd_uint32_t frame_too_longs;
|
|
|
|
nd_uint32_t mac_receive_errors;
|
|
|
|
nd_uint32_t symbol_errors;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_100basevg_counter_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t in_highpriority_frames;
|
|
|
|
nd_uint64_t in_highpriority_octets;
|
|
|
|
nd_uint32_t in_normpriority_frames;
|
|
|
|
nd_uint64_t in_normpriority_octets;
|
|
|
|
nd_uint32_t in_ipmerrors;
|
|
|
|
nd_uint32_t in_oversized;
|
|
|
|
nd_uint32_t in_data_errors;
|
|
|
|
nd_uint32_t in_null_addressed_frames;
|
|
|
|
nd_uint32_t out_highpriority_frames;
|
|
|
|
nd_uint64_t out_highpriority_octets;
|
|
|
|
nd_uint32_t transitioninto_frames;
|
|
|
|
nd_uint64_t hc_in_highpriority_octets;
|
|
|
|
nd_uint64_t hc_in_normpriority_octets;
|
|
|
|
nd_uint64_t hc_out_highpriority_octets;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sflow_vlan_counter_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t vlan_id;
|
|
|
|
nd_uint64_t octets;
|
|
|
|
nd_uint32_t unicast_pkt;
|
|
|
|
nd_uint32_t multicast_pkt;
|
|
|
|
nd_uint32_t broadcast_pkt;
|
|
|
|
nd_uint32_t discards;
|
2007-08-09 01:20:58 +08:00
|
|
|
};
|
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_generic(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2007-08-09 01:20:58 +08:00
|
|
|
const struct sflow_generic_counter_t *sflow_gen_counter;
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_generic_counter_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_gen_counter = (const struct sflow_generic_counter_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_gen_counter);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t ifindex %u, iftype %u, ifspeed %" PRIu64 ", ifdirection %u (%s)",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_gen_counter->ifindex),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->iftype),
|
|
|
|
GET_BE_U_8(sflow_gen_counter->ifspeed),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifdirection),
|
2011-04-15 02:32:08 +08:00
|
|
|
tok2str(sflow_iface_direction_values, "Unknown",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_gen_counter->ifdirection)));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t ifstatus %u, adminstatus: %s, operstatus: %s",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_gen_counter->ifstatus),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifstatus)&1 ? "up" : "down",
|
|
|
|
(GET_BE_U_4(sflow_gen_counter->ifstatus)>>1)&1 ? "up" : "down");
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t In octets %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_8(sflow_gen_counter->ifinoctets),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifinunicastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifinmulticastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifinbroadcastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifindiscards));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t In errors %u, unknown protos %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_gen_counter->ifinerrors),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifinunkownprotos));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t Out octets %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", unicast pkts %u, multicast pkts %u, broadcast pkts %u, discards %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_8(sflow_gen_counter->ifoutoctets),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifoutunicastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifoutmulticastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifoutbroadcastpkts),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifoutdiscards));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t Out errors %u, promisc mode %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_gen_counter->ifouterrors),
|
|
|
|
GET_BE_U_4(sflow_gen_counter->ifpromiscmode));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_ethernet(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2007-08-09 01:20:58 +08:00
|
|
|
const struct sflow_ethernet_counter_t *sflow_eth_counter;
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_ethernet_counter_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_eth_counter = (const struct sflow_ethernet_counter_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_eth_counter);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_eth_counter->alignerrors),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->fcserrors),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->single_collision_frames),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->multiple_collision_frames),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->test_errors));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t deferred %u, late collision %u, excessive collision %u, mac trans error %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_eth_counter->deferred_transmissions),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->late_collisions),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->excessive_collisions),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->mac_transmit_errors));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t carrier error %u, frames too long %u, mac receive errors %u, symbol errors %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_eth_counter->carrier_sense_errors),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->frame_too_longs),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->mac_receive_errors),
|
|
|
|
GET_BE_U_4(sflow_eth_counter->symbol_errors));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_token_ring(netdissect_options *ndo _U_,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer _U_, u_int len _U_)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_basevg(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2007-08-09 01:20:58 +08:00
|
|
|
const struct sflow_100basevg_counter_t *sflow_100basevg_counter;
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_100basevg_counter_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_100basevg_counter = (const struct sflow_100basevg_counter_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_100basevg_counter);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t in high prio frames %u, in high prio octets %" PRIu64,
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_highpriority_frames),
|
|
|
|
GET_BE_U_8(sflow_100basevg_counter->in_highpriority_octets));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t in norm prio frames %u, in norm prio octets %" PRIu64,
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_normpriority_frames),
|
|
|
|
GET_BE_U_8(sflow_100basevg_counter->in_normpriority_octets));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t in ipm errors %u, oversized %u, in data errors %u, null addressed frames %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_ipmerrors),
|
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_oversized),
|
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_data_errors),
|
|
|
|
GET_BE_U_4(sflow_100basevg_counter->in_null_addressed_frames));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t out high prio frames %u, out high prio octets %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", trans into frames %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_100basevg_counter->out_highpriority_frames),
|
|
|
|
GET_BE_U_8(sflow_100basevg_counter->out_highpriority_octets),
|
|
|
|
GET_BE_U_4(sflow_100basevg_counter->transitioninto_frames));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t in hc high prio octets %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", in hc norm prio octets %" PRIu64
|
|
|
|
", out hc high prio octets %" PRIu64,
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_8(sflow_100basevg_counter->hc_in_highpriority_octets),
|
|
|
|
GET_BE_U_8(sflow_100basevg_counter->hc_in_normpriority_octets),
|
|
|
|
GET_BE_U_8(sflow_100basevg_counter->hc_out_highpriority_octets));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_vlan(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2007-08-09 01:20:58 +08:00
|
|
|
const struct sflow_vlan_counter_t *sflow_vlan_counter;
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
if (len < sizeof(struct sflow_vlan_counter_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_vlan_counter = (const struct sflow_vlan_counter_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_vlan_counter);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t vlan_id %u, octets %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_vlan_counter->vlan_id),
|
|
|
|
GET_BE_U_8(sflow_vlan_counter->octets),
|
|
|
|
GET_BE_U_4(sflow_vlan_counter->unicast_pkt),
|
|
|
|
GET_BE_U_4(sflow_vlan_counter->multicast_pkt),
|
|
|
|
GET_BE_U_4(sflow_vlan_counter->broadcast_pkt),
|
|
|
|
GET_BE_U_4(sflow_vlan_counter->discards));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sflow_processor_counter_t {
|
2017-12-31 10:32:47 +08:00
|
|
|
nd_uint32_t five_sec_util;
|
|
|
|
nd_uint32_t one_min_util;
|
|
|
|
nd_uint32_t five_min_util;
|
|
|
|
nd_uint64_t total_memory;
|
|
|
|
nd_uint64_t free_memory;
|
2011-04-15 02:32:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_counter_processor(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_processor_counter_t *sflow_processor_counter;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_processor_counter_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_processor_counter = (const struct sflow_processor_counter_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_processor_counter);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64
|
2011-04-15 02:32:08 +08:00
|
|
|
", total_mem %" PRIu64,
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_processor_counter->five_sec_util),
|
|
|
|
GET_BE_U_4(sflow_processor_counter->one_min_util),
|
|
|
|
GET_BE_U_4(sflow_processor_counter->five_min_util),
|
|
|
|
GET_BE_U_8(sflow_processor_counter->total_memory),
|
|
|
|
GET_BE_U_8(sflow_processor_counter->free_memory));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_counter_records(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len, u_int records)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
u_int nrecords;
|
|
|
|
const u_char *tptr;
|
|
|
|
u_int tlen;
|
|
|
|
u_int counter_type;
|
|
|
|
u_int counter_len;
|
2011-04-16 01:01:02 +08:00
|
|
|
u_int enterprise;
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_counter_record_t *sflow_counter_record;
|
|
|
|
|
|
|
|
nrecords = records;
|
|
|
|
tptr = pointer;
|
|
|
|
tlen = len;
|
|
|
|
|
|
|
|
while (nrecords > 0) {
|
|
|
|
/* do we have the "header?" */
|
|
|
|
if (tlen < sizeof(struct sflow_counter_record_t))
|
|
|
|
return 1;
|
|
|
|
sflow_counter_record = (const struct sflow_counter_record_t *)tptr;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_counter_record);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
enterprise = GET_BE_U_4(sflow_counter_record->format);
|
2011-04-16 01:01:02 +08:00
|
|
|
counter_type = enterprise & 0x0FFF;
|
|
|
|
enterprise = enterprise >> 20;
|
2018-06-16 23:23:21 +08:00
|
|
|
counter_len = GET_BE_U_4(sflow_counter_record->length);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t enterprise %u, %s (%u) length %u",
|
2011-04-16 01:01:02 +08:00
|
|
|
enterprise,
|
|
|
|
(enterprise == 0) ? tok2str(sflow_counter_type_values,"Unknown",counter_type) : "Unknown",
|
2011-04-15 02:32:08 +08:00
|
|
|
counter_type,
|
2018-01-07 18:47:30 +08:00
|
|
|
counter_len);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
tptr += sizeof(struct sflow_counter_record_t);
|
|
|
|
tlen -= sizeof(struct sflow_counter_record_t);
|
|
|
|
|
|
|
|
if (tlen < counter_len)
|
|
|
|
return 1;
|
2011-04-16 01:01:02 +08:00
|
|
|
if (enterprise == 0) {
|
|
|
|
switch (counter_type) {
|
|
|
|
case SFLOW_COUNTER_GENERIC:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_generic(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_COUNTER_ETHERNET:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_ethernet(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_COUNTER_TOKEN_RING:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_token_ring(ndo, tptr,tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_COUNTER_BASEVG:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_basevg(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_COUNTER_VLAN:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_vlan(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_COUNTER_PROCESSOR:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_counter_processor(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag <= 1)
|
|
|
|
print_unknown_data(ndo, tptr, "\n\t\t", counter_len);
|
2011-04-16 01:01:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
tptr += counter_len;
|
|
|
|
tlen -= counter_len;
|
|
|
|
nrecords--;
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_counter_sample(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_counter_sample_t *sflow_counter_sample;
|
|
|
|
u_int nrecords;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_counter_sample_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_counter_sample = (const struct sflow_counter_sample_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_counter_sample);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
nrecords = GET_BE_U_4(sflow_counter_sample->records);
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" seqnum %u, type %u, idx %u, records %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_counter_sample->seqnum),
|
|
|
|
GET_U_1(sflow_counter_sample->type),
|
|
|
|
GET_BE_U_3(sflow_counter_sample->index),
|
2018-01-07 18:47:30 +08:00
|
|
|
nrecords);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
return sflow_print_counter_records(ndo, pointer + sizeof(struct sflow_counter_sample_t),
|
2011-04-15 02:32:08 +08:00
|
|
|
len - sizeof(struct sflow_counter_sample_t),
|
|
|
|
nrecords);
|
|
|
|
|
2015-05-07 23:54:32 +08:00
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_expanded_counter_sample(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_expanded_counter_sample_t *sflow_expanded_counter_sample;
|
|
|
|
u_int nrecords;
|
|
|
|
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_expanded_counter_sample_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_expanded_counter_sample = (const struct sflow_expanded_counter_sample_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_expanded_counter_sample);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
nrecords = GET_BE_U_4(sflow_expanded_counter_sample->records);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" seqnum %u, type %u, idx %u, records %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_expanded_counter_sample->seqnum),
|
|
|
|
GET_BE_U_4(sflow_expanded_counter_sample->type),
|
|
|
|
GET_BE_U_4(sflow_expanded_counter_sample->index),
|
2018-01-07 18:47:30 +08:00
|
|
|
nrecords);
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
return sflow_print_counter_records(ndo, pointer + sizeof(struct sflow_expanded_counter_sample_t),
|
2011-04-15 02:32:08 +08:00
|
|
|
len - sizeof(struct sflow_expanded_counter_sample_t),
|
|
|
|
nrecords);
|
|
|
|
|
2015-05-07 23:54:32 +08:00
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_raw_packet(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_expanded_flow_raw_t *sflow_flow_raw;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_expanded_flow_raw_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_flow_raw = (const struct sflow_expanded_flow_raw_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_flow_raw);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
tok2str(sflow_flow_raw_protocol_values,"Unknown",GET_BE_U_4(sflow_flow_raw->protocol)),
|
|
|
|
GET_BE_U_4(sflow_flow_raw->protocol),
|
|
|
|
GET_BE_U_4(sflow_flow_raw->length),
|
|
|
|
GET_BE_U_4(sflow_flow_raw->stripped_bytes),
|
|
|
|
GET_BE_U_4(sflow_flow_raw->header_size));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
/* QUESTION - should we attempt to print the raw header itself?
|
|
|
|
assuming of course there is wnough data present to do so... */
|
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
2011-04-16 01:01:02 +08:00
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_ethernet_frame(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-16 01:01:02 +08:00
|
|
|
const struct sflow_ethernet_frame_t *sflow_ethernet_frame;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_ethernet_frame_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_ethernet_frame = (const struct sflow_ethernet_frame_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_ethernet_frame);
|
2011-04-16 01:01:02 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t frame len %u, type %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_ethernet_frame->length),
|
|
|
|
GET_BE_U_4(sflow_ethernet_frame->type));
|
2011-04-16 01:01:02 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-16 01:01:02 +08:00
|
|
|
}
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
print_sflow_extended_switch_data(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_extended_switch_data_t *sflow_extended_sw_data;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_extended_switch_data_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_extended_sw_data = (const struct sflow_extended_switch_data_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_extended_sw_data);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_extended_sw_data->src_vlan),
|
|
|
|
GET_BE_U_4(sflow_extended_sw_data->src_pri),
|
|
|
|
GET_BE_U_4(sflow_extended_sw_data->dst_vlan),
|
|
|
|
GET_BE_U_4(sflow_extended_sw_data->dst_pri));
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_flow_records(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len, u_int records)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
u_int nrecords;
|
2007-08-09 01:20:58 +08:00
|
|
|
const u_char *tptr;
|
2011-04-15 02:32:08 +08:00
|
|
|
u_int tlen;
|
|
|
|
u_int flow_type;
|
2011-04-16 01:01:02 +08:00
|
|
|
u_int enterprise;
|
2011-04-15 02:32:08 +08:00
|
|
|
u_int flow_len;
|
|
|
|
const struct sflow_flow_record_t *sflow_flow_record;
|
|
|
|
|
|
|
|
nrecords = records;
|
|
|
|
tptr = pointer;
|
|
|
|
tlen = len;
|
|
|
|
|
|
|
|
while (nrecords > 0) {
|
|
|
|
/* do we have the "header?" */
|
|
|
|
if (tlen < sizeof(struct sflow_flow_record_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_flow_record = (const struct sflow_flow_record_t *)tptr;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_flow_record);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2011-04-16 01:01:02 +08:00
|
|
|
/* so, the funky encoding means we cannot blythly mask-off
|
|
|
|
bits, we must also check the enterprise. */
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
enterprise = GET_BE_U_4(sflow_flow_record->format);
|
2011-04-16 01:01:02 +08:00
|
|
|
flow_type = enterprise & 0x0FFF;
|
|
|
|
enterprise = enterprise >> 12;
|
2018-06-16 23:23:21 +08:00
|
|
|
flow_len = GET_BE_U_4(sflow_flow_record->length);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t enterprise %u %s (%u) length %u",
|
2011-04-16 01:01:02 +08:00
|
|
|
enterprise,
|
|
|
|
(enterprise == 0) ? tok2str(sflow_flow_type_values,"Unknown",flow_type) : "Unknown",
|
2011-04-15 02:32:08 +08:00
|
|
|
flow_type,
|
2018-01-07 18:47:30 +08:00
|
|
|
flow_len);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
|
|
|
tptr += sizeof(struct sflow_flow_record_t);
|
|
|
|
tlen -= sizeof(struct sflow_flow_record_t);
|
|
|
|
|
|
|
|
if (tlen < flow_len)
|
|
|
|
return 1;
|
|
|
|
|
2011-04-16 01:01:02 +08:00
|
|
|
if (enterprise == 0) {
|
|
|
|
switch (flow_type) {
|
|
|
|
case SFLOW_FLOW_RAW_PACKET:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_raw_packet(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_FLOW_EXTENDED_SWITCH_DATA:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_extended_switch_data(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case SFLOW_FLOW_ETHERNET_FRAME:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (print_sflow_ethernet_frame(ndo, tptr, tlen))
|
2011-04-16 01:01:02 +08:00
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
/* FIXME these need a decoder */
|
|
|
|
case SFLOW_FLOW_IPV4_DATA:
|
|
|
|
case SFLOW_FLOW_IPV6_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_ROUTER_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_GATEWAY_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_USER_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_URL_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_MPLS_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_NAT_DATA:
|
|
|
|
case SFLOW_FLOW_EXTENDED_MPLS_TUNNEL:
|
|
|
|
case SFLOW_FLOW_EXTENDED_MPLS_VC:
|
|
|
|
case SFLOW_FLOW_EXTENDED_MPLS_FEC:
|
|
|
|
case SFLOW_FLOW_EXTENDED_MPLS_LVP_FEC:
|
|
|
|
case SFLOW_FLOW_EXTENDED_VLAN_TUNNEL:
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag <= 1)
|
|
|
|
print_unknown_data(ndo, tptr, "\n\t\t", flow_len);
|
2011-04-16 01:01:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
tptr += flow_len;
|
|
|
|
tlen -= flow_len;
|
|
|
|
nrecords--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-05-07 23:54:32 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_flow_sample(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_flow_sample_t *sflow_flow_sample;
|
|
|
|
u_int nrecords;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_flow_sample_t))
|
|
|
|
return 1;
|
|
|
|
|
2015-04-27 08:24:42 +08:00
|
|
|
sflow_flow_sample = (const struct sflow_flow_sample_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_flow_sample);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
nrecords = GET_BE_U_4(sflow_flow_sample->records);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, input %u output %u records %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_flow_sample->seqnum),
|
|
|
|
GET_U_1(sflow_flow_sample->type),
|
|
|
|
GET_BE_U_3(sflow_flow_sample->index),
|
|
|
|
GET_BE_U_4(sflow_flow_sample->rate),
|
|
|
|
GET_BE_U_4(sflow_flow_sample->pool),
|
|
|
|
GET_BE_U_4(sflow_flow_sample->drops),
|
|
|
|
GET_BE_U_4(sflow_flow_sample->in_interface),
|
|
|
|
GET_BE_U_4(sflow_flow_sample->out_interface),
|
2018-01-07 18:47:30 +08:00
|
|
|
nrecords);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
return sflow_print_flow_records(ndo, pointer + sizeof(struct sflow_flow_sample_t),
|
2011-04-15 02:32:08 +08:00
|
|
|
len - sizeof(struct sflow_flow_sample_t),
|
|
|
|
nrecords);
|
|
|
|
|
2015-05-07 23:54:32 +08:00
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print_expanded_flow_sample(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pointer, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_expanded_flow_sample_t *sflow_expanded_flow_sample;
|
|
|
|
u_int nrecords;
|
|
|
|
|
|
|
|
if (len < sizeof(struct sflow_expanded_flow_sample_t))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sflow_expanded_flow_sample = (const struct sflow_expanded_flow_sample_t *)pointer;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_expanded_flow_sample);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
nrecords = GET_BE_U_4(sflow_expanded_flow_sample->records);
|
2011-04-15 02:32:08 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" seqnum %u, type %u, idx %u, rate %u, pool %u, drops %u, records %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->seqnum),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->type),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->index),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->rate),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->pool),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->drops),
|
|
|
|
GET_BE_U_4(sflow_expanded_flow_sample->records));
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
return sflow_print_flow_records(ndo, pointer + sizeof(struct sflow_expanded_flow_sample_t),
|
2011-04-15 02:32:08 +08:00
|
|
|
len - sizeof(struct sflow_expanded_flow_sample_t),
|
|
|
|
nrecords);
|
|
|
|
|
2015-05-07 23:54:32 +08:00
|
|
|
trunc:
|
|
|
|
return 1;
|
2011-04-15 02:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-25 19:05:59 +08:00
|
|
|
sflow_print(netdissect_options *ndo,
|
2015-03-05 18:33:43 +08:00
|
|
|
const u_char *pptr, u_int len)
|
|
|
|
{
|
2011-04-15 02:32:08 +08:00
|
|
|
const struct sflow_datagram_t *sflow_datagram;
|
|
|
|
const struct sflow_sample_header *sflow_sample;
|
|
|
|
|
|
|
|
const u_char *tptr;
|
|
|
|
u_int tlen;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t sflow_sample_type, sflow_sample_len;
|
|
|
|
uint32_t nsamples;
|
2007-08-09 01:20:58 +08:00
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "sflow";
|
2011-04-15 02:32:08 +08:00
|
|
|
tptr = pptr;
|
2007-08-09 01:20:58 +08:00
|
|
|
tlen = len;
|
|
|
|
sflow_datagram = (const struct sflow_datagram_t *)pptr;
|
2019-08-03 16:16:20 +08:00
|
|
|
if (len < sizeof(struct sflow_datagram_t)) {
|
|
|
|
ND_PRINT("sFlowv%u", GET_BE_U_4(sflow_datagram->version));
|
2019-08-07 17:59:11 +08:00
|
|
|
ND_PRINT(" [length %u < %zu]", len, sizeof(struct sflow_datagram_t));
|
2019-08-03 16:16:20 +08:00
|
|
|
nd_print_invalid(ndo);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_datagram);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity checking of the header.
|
|
|
|
*/
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_BE_U_4(sflow_datagram->version) != 5) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("sFlow version %u packet not supported",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_datagram->version));
|
2007-08-09 01:20:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag < 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("sFlowv%u, %s agent %s, agent-id %u, length %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_datagram->version),
|
|
|
|
GET_BE_U_4(sflow_datagram->ip_version) == 1 ? "IPv4" : "IPv6",
|
2020-01-20 11:55:38 +08:00
|
|
|
GET_IPADDR_STRING(sflow_datagram->agent),
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_datagram->agent_id),
|
2018-01-07 18:47:30 +08:00
|
|
|
len);
|
2007-08-09 01:20:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ok they seem to want to know everything - lets fully decode it */
|
2018-06-16 23:23:21 +08:00
|
|
|
nsamples=GET_BE_U_4(sflow_datagram->samples);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("sFlowv%u, %s agent %s, agent-id %u, seqnum %u, uptime %u, samples %u, length %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_datagram->version),
|
|
|
|
GET_BE_U_4(sflow_datagram->ip_version) == 1 ? "IPv4" : "IPv6",
|
2020-01-20 11:55:38 +08:00
|
|
|
GET_IPADDR_STRING(sflow_datagram->agent),
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_4(sflow_datagram->agent_id),
|
|
|
|
GET_BE_U_4(sflow_datagram->seqnum),
|
|
|
|
GET_BE_U_4(sflow_datagram->uptime),
|
2007-08-09 01:20:58 +08:00
|
|
|
nsamples,
|
2018-01-07 18:47:30 +08:00
|
|
|
len);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
/* skip Common header */
|
2017-09-13 20:26:02 +08:00
|
|
|
tptr += sizeof(struct sflow_datagram_t);
|
|
|
|
tlen -= sizeof(struct sflow_datagram_t);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
while (nsamples > 0 && tlen > 0) {
|
|
|
|
sflow_sample = (const struct sflow_sample_header *)tptr;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(sflow_sample);
|
2011-04-05 10:03:56 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
sflow_sample_type = (GET_BE_U_4(sflow_sample->format)&0x0FFF);
|
|
|
|
sflow_sample_len = GET_BE_U_4(sflow_sample->len);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
if (tlen < sizeof(struct sflow_sample_header))
|
|
|
|
goto trunc;
|
|
|
|
|
2011-04-05 10:03:56 +08:00
|
|
|
tptr += sizeof(struct sflow_sample_header);
|
|
|
|
tlen -= sizeof(struct sflow_sample_header);
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t%s (%u), length %u,",
|
2007-08-09 01:20:58 +08:00
|
|
|
tok2str(sflow_format_values, "Unknown", sflow_sample_type),
|
|
|
|
sflow_sample_type,
|
2018-01-07 18:47:30 +08:00
|
|
|
sflow_sample_len);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
/* basic sanity check */
|
|
|
|
if (sflow_sample_type == 0 || sflow_sample_len ==0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
if (tlen < sflow_sample_len)
|
|
|
|
goto trunc;
|
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
/* did we capture enough for fully decoding the sample ? */
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, sflow_sample_len);
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
switch(sflow_sample_type) {
|
2011-04-15 02:32:08 +08:00
|
|
|
case SFLOW_FLOW_SAMPLE:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (sflow_print_flow_sample(ndo, tptr, tlen))
|
2011-04-15 02:32:08 +08:00
|
|
|
goto trunc;
|
2007-08-09 01:20:58 +08:00
|
|
|
break;
|
|
|
|
|
2011-04-15 02:32:08 +08:00
|
|
|
case SFLOW_COUNTER_SAMPLE:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (sflow_print_counter_sample(ndo, tptr,tlen))
|
2011-04-15 02:32:08 +08:00
|
|
|
goto trunc;
|
2007-08-09 01:20:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFLOW_EXPANDED_FLOW_SAMPLE:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (sflow_print_expanded_flow_sample(ndo, tptr, tlen))
|
2011-04-15 02:32:08 +08:00
|
|
|
goto trunc;
|
|
|
|
break;
|
2007-08-09 01:20:58 +08:00
|
|
|
|
|
|
|
case SFLOW_EXPANDED_COUNTER_SAMPLE:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (sflow_print_expanded_counter_sample(ndo, tptr,tlen))
|
2011-04-15 02:32:08 +08:00
|
|
|
goto trunc;
|
|
|
|
break;
|
2011-04-05 10:03:56 +08:00
|
|
|
|
2007-08-09 01:20:58 +08:00
|
|
|
default:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag <= 1)
|
|
|
|
print_unknown_data(ndo, tptr, "\n\t ", sflow_sample_len);
|
2007-08-09 01:20:58 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tptr += sflow_sample_len;
|
|
|
|
tlen -= sflow_sample_len;
|
|
|
|
nsamples--;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2018-05-06 16:33:07 +08:00
|
|
|
nd_print_trunc(ndo);
|
2007-08-09 01:20:58 +08:00
|
|
|
}
|