X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ed85e20e4d6a27d5405f37366dd34b64c10a9211..refs/pull/482/head:/print-sflow.c diff --git a/print-sflow.c b/print-sflow.c index da72848d..7eecf0a0 100644 --- a/print-sflow.c +++ b/print-sflow.c @@ -19,14 +19,13 @@ * Expansion and refactoring by Rick Jones */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -297,15 +296,15 @@ struct sflow_vlan_counter_t { static int print_sflow_counter_generic(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_generic_counter_t *sflow_gen_counter; if (len < sizeof(struct sflow_generic_counter_t)) return 1; - sflow_gen_counter = (const struct sflow_generic_counter_t *)pointer; + ND_TCHECK(*sflow_gen_counter); ND_PRINT((ndo, "\n\t ifindex %u, iftype %u, ifspeed %" PRIu64 ", ifdirection %u (%s)", EXTRACT_32BITS(sflow_gen_counter->ifindex), EXTRACT_32BITS(sflow_gen_counter->iftype), @@ -339,18 +338,22 @@ print_sflow_counter_generic(netdissect_options *ndo, EXTRACT_32BITS(sflow_gen_counter->ifpromiscmode))); return 0; + +trunc: + return 1; } static int print_sflow_counter_ethernet(netdissect_options *ndo, - const u_char *pointer, u_int len){ - + const u_char *pointer, u_int len) +{ const struct sflow_ethernet_counter_t *sflow_eth_counter; if (len < sizeof(struct sflow_ethernet_counter_t)) return 1; sflow_eth_counter = (const struct sflow_ethernet_counter_t *)pointer; + ND_TCHECK(*sflow_eth_counter); ND_PRINT((ndo, "\n\t align errors %u, fcs errors %u, single collision %u, multiple collision %u, test error %u", EXTRACT_32BITS(sflow_eth_counter->alignerrors), EXTRACT_32BITS(sflow_eth_counter->fcserrors), @@ -369,25 +372,29 @@ print_sflow_counter_ethernet(netdissect_options *ndo, EXTRACT_32BITS(sflow_eth_counter->symbol_errors))); return 0; + +trunc: + return 1; } static int print_sflow_counter_token_ring(netdissect_options *ndo _U_, - const u_char *pointer _U_, u_int len _U_) { - + const u_char *pointer _U_, u_int len _U_) +{ return 0; } static int print_sflow_counter_basevg(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_100basevg_counter_t *sflow_100basevg_counter; if (len < sizeof(struct sflow_100basevg_counter_t)) return 1; sflow_100basevg_counter = (const struct sflow_100basevg_counter_t *)pointer; + ND_TCHECK(*sflow_100basevg_counter); ND_PRINT((ndo, "\n\t in high prio frames %u, in high prio octets %" PRIu64, EXTRACT_32BITS(sflow_100basevg_counter->in_highpriority_frames), EXTRACT_64BITS(sflow_100basevg_counter->in_highpriority_octets))); @@ -412,18 +419,22 @@ print_sflow_counter_basevg(netdissect_options *ndo, EXTRACT_64BITS(sflow_100basevg_counter->hc_out_highpriority_octets))); return 0; + +trunc: + return 1; } static int print_sflow_counter_vlan(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_vlan_counter_t *sflow_vlan_counter; if (len < sizeof(struct sflow_vlan_counter_t)) return 1; sflow_vlan_counter = (const struct sflow_vlan_counter_t *)pointer; + ND_TCHECK(*sflow_vlan_counter); ND_PRINT((ndo, "\n\t vlan_id %u, octets %" PRIu64 ", unicast_pkt %u, multicast_pkt %u, broadcast_pkt %u, discards %u", EXTRACT_32BITS(sflow_vlan_counter->vlan_id), @@ -434,6 +445,9 @@ print_sflow_counter_vlan(netdissect_options *ndo, EXTRACT_32BITS(sflow_vlan_counter->discards))); return 0; + +trunc: + return 1; } struct sflow_processor_counter_t { @@ -446,14 +460,15 @@ struct sflow_processor_counter_t { static int print_sflow_counter_processor(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ 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; + ND_TCHECK(*sflow_processor_counter); ND_PRINT((ndo, "\n\t 5sec %u, 1min %u, 5min %u, total_mem %" PRIu64 ", total_mem %" PRIu64, EXTRACT_32BITS(sflow_processor_counter->five_sec_util), @@ -463,12 +478,15 @@ print_sflow_counter_processor(netdissect_options *ndo, EXTRACT_64BITS(sflow_processor_counter->free_memory))); return 0; + +trunc: + return 1; } static int sflow_print_counter_records(netdissect_options *ndo, - const u_char *pointer, u_int len, u_int records) { - + const u_char *pointer, u_int len, u_int records) +{ u_int nrecords; const u_char *tptr; u_int tlen; @@ -486,6 +504,7 @@ sflow_print_counter_records(netdissect_options *ndo, if (tlen < sizeof(struct sflow_counter_record_t)) return 1; sflow_counter_record = (const struct sflow_counter_record_t *)tptr; + ND_TCHECK(*sflow_counter_record); enterprise = EXTRACT_32BITS(sflow_counter_record->format); counter_type = enterprise & 0x0FFF; @@ -541,24 +560,26 @@ sflow_print_counter_records(netdissect_options *ndo, } return 0; -} +trunc: + return 1; +} static int sflow_print_counter_sample(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_counter_sample_t *sflow_counter_sample; u_int nrecords; u_int typesource; u_int type; u_int index; - if (len < sizeof(struct sflow_counter_sample_t)) return 1; sflow_counter_sample = (const struct sflow_counter_sample_t *)pointer; + ND_TCHECK(*sflow_counter_sample); typesource = EXTRACT_32BITS(sflow_counter_sample->typesource); nrecords = EXTRACT_32BITS(sflow_counter_sample->records); @@ -575,12 +596,14 @@ sflow_print_counter_sample(netdissect_options *ndo, len - sizeof(struct sflow_counter_sample_t), nrecords); +trunc: + return 1; } static int sflow_print_expanded_counter_sample(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_expanded_counter_sample_t *sflow_expanded_counter_sample; u_int nrecords; @@ -589,6 +612,7 @@ sflow_print_expanded_counter_sample(netdissect_options *ndo, return 1; sflow_expanded_counter_sample = (const struct sflow_expanded_counter_sample_t *)pointer; + ND_TCHECK(*sflow_expanded_counter_sample); nrecords = EXTRACT_32BITS(sflow_expanded_counter_sample->records); @@ -602,18 +626,21 @@ sflow_print_expanded_counter_sample(netdissect_options *ndo, len - sizeof(struct sflow_expanded_counter_sample_t), nrecords); +trunc: + return 1; } static int print_sflow_raw_packet(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ 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; + ND_TCHECK(*sflow_flow_raw); ND_PRINT((ndo, "\n\t protocol %s (%u), length %u, stripped bytes %u, header_size %u", tok2str(sflow_flow_raw_protocol_values,"Unknown",EXTRACT_32BITS(sflow_flow_raw->protocol)), EXTRACT_32BITS(sflow_flow_raw->protocol), @@ -625,36 +652,44 @@ print_sflow_raw_packet(netdissect_options *ndo, assuming of course there is wnough data present to do so... */ return 0; + +trunc: + return 1; } static int print_sflow_ethernet_frame(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ 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; + ND_TCHECK(*sflow_ethernet_frame); ND_PRINT((ndo, "\n\t frame len %u, type %u", EXTRACT_32BITS(sflow_ethernet_frame->length), EXTRACT_32BITS(sflow_ethernet_frame->type))); return 0; + +trunc: + return 1; } static int print_sflow_extended_switch_data(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ 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; + ND_TCHECK(*sflow_extended_sw_data); ND_PRINT((ndo, "\n\t src vlan %u, src pri %u, dst vlan %u, dst pri %u", EXTRACT_32BITS(sflow_extended_sw_data->src_vlan), EXTRACT_32BITS(sflow_extended_sw_data->src_pri), @@ -662,12 +697,15 @@ print_sflow_extended_switch_data(netdissect_options *ndo, EXTRACT_32BITS(sflow_extended_sw_data->dst_pri))); return 0; + +trunc: + return 1; } static int sflow_print_flow_records(netdissect_options *ndo, - const u_char *pointer, u_int len, u_int records) { - + const u_char *pointer, u_int len, u_int records) +{ u_int nrecords; const u_char *tptr; u_int tlen; @@ -686,6 +724,7 @@ sflow_print_flow_records(netdissect_options *ndo, return 1; sflow_flow_record = (const struct sflow_flow_record_t *)tptr; + ND_TCHECK(*sflow_flow_record); /* so, the funky encoding means we cannot blythly mask-off bits, we must also check the enterprise. */ @@ -748,12 +787,15 @@ sflow_print_flow_records(netdissect_options *ndo, } return 0; + +trunc: + return 1; } static int sflow_print_flow_sample(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_flow_sample_t *sflow_flow_sample; u_int nrecords; u_int typesource; @@ -763,7 +805,8 @@ sflow_print_flow_sample(netdissect_options *ndo, if (len < sizeof(struct sflow_flow_sample_t)) return 1; - sflow_flow_sample = (struct sflow_flow_sample_t *)pointer; + sflow_flow_sample = (const struct sflow_flow_sample_t *)pointer; + ND_TCHECK(*sflow_flow_sample); typesource = EXTRACT_32BITS(sflow_flow_sample->typesource); nrecords = EXTRACT_32BITS(sflow_flow_sample->records); @@ -785,12 +828,14 @@ sflow_print_flow_sample(netdissect_options *ndo, len - sizeof(struct sflow_flow_sample_t), nrecords); +trunc: + return 1; } static int sflow_print_expanded_flow_sample(netdissect_options *ndo, - const u_char *pointer, u_int len) { - + const u_char *pointer, u_int len) +{ const struct sflow_expanded_flow_sample_t *sflow_expanded_flow_sample; u_int nrecords; @@ -798,6 +843,7 @@ sflow_print_expanded_flow_sample(netdissect_options *ndo, return 1; sflow_expanded_flow_sample = (const struct sflow_expanded_flow_sample_t *)pointer; + ND_TCHECK(*sflow_expanded_flow_sample); nrecords = EXTRACT_32BITS(sflow_expanded_flow_sample->records); @@ -814,12 +860,14 @@ sflow_print_expanded_flow_sample(netdissect_options *ndo, len - sizeof(struct sflow_expanded_flow_sample_t), nrecords); +trunc: + return 1; } void sflow_print(netdissect_options *ndo, - const u_char *pptr, u_int len) { - + const u_char *pptr, u_int len) +{ const struct sflow_datagram_t *sflow_datagram; const struct sflow_sample_header *sflow_sample; @@ -828,7 +876,6 @@ sflow_print(netdissect_options *ndo, uint32_t sflow_sample_type, sflow_sample_len; uint32_t nsamples; - tptr = pptr; tlen = len; sflow_datagram = (const struct sflow_datagram_t *)pptr;