summaryrefslogtreecommitdiff
path: root/print-slow.c
diff options
context:
space:
mode:
authorDenis Ovsienko <infrastation@yandex.ru>2014-03-17 19:17:57 +0400
committerDenis Ovsienko <infrastation@yandex.ru>2014-03-17 19:18:47 +0400
commit5663cdab5ec8730ade9938c1ace64a4859d9ef7b (patch)
treeac7f9778113a528ed1336f916538c7c4e908247b /print-slow.c
parentae2020e84203389ef8c06a00543304b7414e0018 (diff)
downloadtcpdump-5663cdab5ec8730ade9938c1ace64a4859d9ef7b.tar.gz
NDOize OpenFlow, IEEE slow and telnet decoders
Diffstat (limited to 'print-slow.c')
-rw-r--r--print-slow.c144
1 files changed, 73 insertions, 71 deletions
diff --git a/print-slow.c b/print-slow.c
index 7462ab81..aa26d3e9 100644
--- a/print-slow.c
+++ b/print-slow.c
@@ -18,16 +18,13 @@
* Original code by Hannes Gredler (hannes@juniper.net)
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "interface.h"
#include "extract.h"
#include "addrtoname.h"
@@ -245,18 +242,19 @@ struct lacp_marker_tlv_terminator_t {
u_int8_t pad[50];
};
-void slow_marker_lacp_print(register const u_char *, register u_int);
-void slow_oam_print(register const u_char *, register u_int);
+static void slow_marker_lacp_print(netdissect_options *, register const u_char *, register u_int);
+static void slow_oam_print(netdissect_options *, register const u_char *, register u_int);
const struct slow_common_header_t *slow_com_header;
void
-slow_print(register const u_char *pptr, register u_int len) {
+slow_print(netdissect_options *ndo,
+ register const u_char *pptr, register u_int len) {
int print_version;
slow_com_header = (const struct slow_common_header_t *)pptr;
- TCHECK(*slow_com_header);
+ ND_TCHECK(*slow_com_header);
/*
* Sanity checking of the header.
@@ -264,7 +262,7 @@ slow_print(register const u_char *pptr, register u_int len) {
switch (slow_com_header->proto_subtype) {
case SLOW_PROTO_LACP:
if (slow_com_header->version != LACP_VERSION) {
- printf("LACP version %u packet not supported",slow_com_header->version);
+ ND_PRINT((ndo, "LACP version %u packet not supported",slow_com_header->version));
return;
}
print_version = 1;
@@ -272,7 +270,7 @@ slow_print(register const u_char *pptr, register u_int len) {
case SLOW_PROTO_MARKER:
if (slow_com_header->version != MARKER_VERSION) {
- printf("MARKER version %u packet not supported",slow_com_header->version);
+ ND_PRINT((ndo, "MARKER version %u packet not supported",slow_com_header->version));
return;
}
print_version = 1;
@@ -289,24 +287,24 @@ slow_print(register const u_char *pptr, register u_int len) {
}
if (print_version) {
- printf("%sv%u, length %u",
+ ND_PRINT((ndo, "%sv%u, length %u",
tok2str(slow_proto_values, "unknown (%u)",slow_com_header->proto_subtype),
slow_com_header->version,
- len);
+ len));
} else {
/* some slow protos don't have a version number in the header */
- printf("%s, length %u",
+ ND_PRINT((ndo, "%s, length %u",
tok2str(slow_proto_values, "unknown (%u)",slow_com_header->proto_subtype),
- len);
+ len));
}
/* unrecognized subtype */
if (print_version == -1) {
- print_unknown_data(gndo,pptr, "\n\t", len);
+ print_unknown_data(ndo, pptr, "\n\t", len);
return;
}
- if (!vflag)
+ if (!ndo->ndo_vflag)
return;
switch (slow_com_header->proto_subtype) {
@@ -315,7 +313,7 @@ slow_print(register const u_char *pptr, register u_int len) {
case SLOW_PROTO_OAM:
/* skip proto_subtype */
- slow_oam_print(pptr+1, len-1);
+ slow_oam_print(ndo, pptr+1, len-1);
break;
case SLOW_PROTO_LACP: /* LACP and MARKER share the same semantics */
@@ -323,16 +321,18 @@ slow_print(register const u_char *pptr, register u_int len) {
/* skip slow_common_header */
len -= sizeof(const struct slow_common_header_t);
pptr += sizeof(const struct slow_common_header_t);
- slow_marker_lacp_print(pptr, len);
+ slow_marker_lacp_print(ndo, pptr, len);
break;
}
return;
trunc:
- printf("\n\t\t packet exceeded snapshot");
+ ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
}
-void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
+static void
+slow_marker_lacp_print(netdissect_options *ndo,
+ register const u_char *tptr, register u_int tlen) {
const struct tlv_header_t *tlv_header;
const u_char *tlv_tptr;
@@ -347,23 +347,23 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
while(tlen>0) {
/* did we capture enough for fully decoding the tlv header ? */
- TCHECK2(*tptr, sizeof(struct tlv_header_t));
+ ND_TCHECK2(*tptr, sizeof(struct tlv_header_t));
tlv_header = (const struct tlv_header_t *)tptr;
tlv_len = tlv_header->length;
- printf("\n\t%s TLV (0x%02x), length %u",
+ ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
tok2str(slow_tlv_values,
"Unknown",
(slow_com_header->proto_subtype << 8) + tlv_header->type),
tlv_header->type,
- tlv_len);
+ tlv_len));
if ((tlv_len < sizeof(struct tlv_header_t) ||
tlv_len > tlen) &&
tlv_header->type != LACP_TLV_TERMINATOR &&
tlv_header->type != MARKER_TLV_TERMINATOR) {
- printf("\n\t-----trailing data-----");
- print_unknown_data(gndo,tptr+sizeof(struct tlv_header_t),"\n\t ",tlen);
+ ND_PRINT((ndo, "\n\t-----trailing data-----"));
+ print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ", tlen);
return;
}
@@ -371,7 +371,7 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
/* did we capture enough for fully decoding the tlv ? */
- TCHECK2(*tptr, tlv_len);
+ ND_TCHECK2(*tptr, tlv_len);
switch((slow_com_header->proto_subtype << 8) + tlv_header->type) {
@@ -380,7 +380,7 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
- printf("\n\t System %s, System Priority %u, Key %u" \
+ ND_PRINT((ndo, "\n\t System %s, System Priority %u, Key %u" \
", Port %u, Port Priority %u\n\t State Flags [%s]",
etheraddr_string(tlv_ptr.lacp_tlv_actor_partner_info->sys),
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
@@ -389,25 +389,25 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
bittok2str(lacp_tlv_actor_partner_info_state_values,
"none",
- tlv_ptr.lacp_tlv_actor_partner_info->state));
+ tlv_ptr.lacp_tlv_actor_partner_info->state)));
break;
case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
- printf("\n\t Max Delay %u",
- EXTRACT_16BITS(tlv_ptr.lacp_tlv_collector_info->max_delay));
+ ND_PRINT((ndo, "\n\t Max Delay %u",
+ EXTRACT_16BITS(tlv_ptr.lacp_tlv_collector_info->max_delay)));
break;
case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
- printf("\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
+ ND_PRINT((ndo, "\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
etheraddr_string(tlv_ptr.marker_tlv_marker_info->req_sys),
EXTRACT_16BITS(tlv_ptr.marker_tlv_marker_info->req_port),
- EXTRACT_32BITS(tlv_ptr.marker_tlv_marker_info->req_trans_id));
+ EXTRACT_32BITS(tlv_ptr.marker_tlv_marker_info->req_trans_id)));
break;
@@ -419,24 +419,24 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
tlv_len = sizeof(tlv_ptr.lacp_marker_tlv_terminator->pad) +
sizeof(struct tlv_header_t);
/* tell the user that we modified the length field */
- if (vflag>1)
- printf(" (=%u)",tlv_len);
+ if (ndo->ndo_vflag>1)
+ ND_PRINT((ndo, " (=%u)", tlv_len));
/* we have messed around with the length field - now we need to check
* again if there are enough bytes on the wire for the hexdump */
- TCHECK2(tlv_ptr.lacp_marker_tlv_terminator->pad[0],
+ ND_TCHECK2(tlv_ptr.lacp_marker_tlv_terminator->pad[0],
sizeof(tlv_ptr.lacp_marker_tlv_terminator->pad));
}
break;
default:
- if (vflag <= 1)
- print_unknown_data(gndo,tlv_tptr,"\n\t ",tlv_tlen);
+ if (ndo->ndo_vflag <= 1)
+ print_unknown_data(ndo, tlv_tptr, "\n\t ", tlv_tlen);
break;
}
/* do we want to see an additional hexdump ? */
- if (vflag > 1) {
- print_unknown_data(gndo,tptr+sizeof(struct tlv_header_t),"\n\t ",
+ if (ndo->ndo_vflag > 1) {
+ print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ",
tlv_len-sizeof(struct tlv_header_t));
}
@@ -445,10 +445,12 @@ void slow_marker_lacp_print(register const u_char *tptr, register u_int tlen) {
}
return;
trunc:
- printf("\n\t\t packet exceeded snapshot");
+ ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
}
-void slow_oam_print(register const u_char *tptr, register u_int tlen) {
+static void
+slow_oam_print(netdissect_options *ndo,
+ register const u_char *tptr, register u_int tlen) {
u_int hexdump;
@@ -479,27 +481,27 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
tptr += sizeof(struct slow_oam_common_header_t);
tlen -= sizeof(struct slow_oam_common_header_t);
- printf("\n\tCode %s OAM PDU, Flags [%s]",
+ ND_PRINT((ndo, "\n\tCode %s OAM PDU, Flags [%s]",
tok2str(slow_oam_code_values, "Unknown (%u)", ptr.slow_oam_common_header->code),
bittok2str(slow_oam_flag_values,
"none",
- EXTRACT_16BITS(&ptr.slow_oam_common_header->flags)));
+ EXTRACT_16BITS(&ptr.slow_oam_common_header->flags))));
switch (ptr.slow_oam_common_header->code) {
case SLOW_OAM_CODE_INFO:
while (tlen > 0) {
ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
- printf("\n\t %s Information Type (%u), length %u",
+ ND_PRINT((ndo, "\n\t %s Information Type (%u), length %u",
tok2str(slow_oam_info_type_values, "Reserved",
ptr.slow_oam_tlv_header->type),
ptr.slow_oam_tlv_header->type,
- ptr.slow_oam_tlv_header->length);
+ ptr.slow_oam_tlv_header->length));
hexdump = FALSE;
switch (ptr.slow_oam_tlv_header->type) {
case SLOW_OAM_INFO_TYPE_END_OF_TLV:
if (ptr.slow_oam_tlv_header->length != 0) {
- printf("\n\t ERROR: illegal length - should be 0");
+ ND_PRINT((ndo, "\n\t ERROR: illegal length - should be 0"));
}
return;
@@ -509,30 +511,30 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
if (tlv.slow_oam_info->info_length !=
sizeof(struct slow_oam_info_t)) {
- printf("\n\t ERROR: illegal length - should be %lu",
- (unsigned long) sizeof(struct slow_oam_info_t));
+ ND_PRINT((ndo, "\n\t ERROR: illegal length - should be %lu",
+ (unsigned long) sizeof(struct slow_oam_info_t)));
return;
}
- printf("\n\t OAM-Version %u, Revision %u",
+ ND_PRINT((ndo, "\n\t OAM-Version %u, Revision %u",
tlv.slow_oam_info->oam_version,
- EXTRACT_16BITS(&tlv.slow_oam_info->revision));
+ EXTRACT_16BITS(&tlv.slow_oam_info->revision)));
- printf("\n\t State-Parser-Action %s, State-MUX-Action %s",
+ ND_PRINT((ndo, "\n\t State-Parser-Action %s, State-MUX-Action %s",
tok2str(slow_oam_info_type_state_parser_values, "Reserved",
tlv.slow_oam_info->state & OAM_INFO_TYPE_PARSER_MASK),
tok2str(slow_oam_info_type_state_mux_values, "Reserved",
- tlv.slow_oam_info->state & OAM_INFO_TYPE_MUX_MASK));
- printf("\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
+ tlv.slow_oam_info->state & OAM_INFO_TYPE_MUX_MASK)));
+ ND_PRINT((ndo, "\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
bittok2str(slow_oam_info_type_oam_config_values, "none",
tlv.slow_oam_info->oam_config),
EXTRACT_16BITS(&tlv.slow_oam_info->oam_pdu_config) &
- OAM_INFO_TYPE_PDU_SIZE_MASK);
- printf("\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
+ OAM_INFO_TYPE_PDU_SIZE_MASK));
+ ND_PRINT((ndo, "\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
tok2str(oui_values, "Unknown",
EXTRACT_24BITS(&tlv.slow_oam_info->oui)),
EXTRACT_24BITS(&tlv.slow_oam_info->oui),
- EXTRACT_32BITS(&tlv.slow_oam_info->vendor_private));
+ EXTRACT_32BITS(&tlv.slow_oam_info->vendor_private)));
break;
case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
@@ -550,8 +552,8 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
}
/* do we also want to see a hex dump ? */
- if (vflag > 1 || hexdump==TRUE) {
- print_unknown_data(gndo,tptr,"\n\t ",
+ if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
+ print_unknown_data(ndo, tptr, "\n\t ",
ptr.slow_oam_tlv_header->length);
}
@@ -563,17 +565,17 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
case SLOW_OAM_CODE_EVENT_NOTIF:
while (tlen > 0) {
ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
- printf("\n\t %s Link Event Type (%u), length %u",
+ ND_PRINT((ndo, "\n\t %s Link Event Type (%u), length %u",
tok2str(slow_oam_link_event_values, "Reserved",
ptr.slow_oam_tlv_header->type),
ptr.slow_oam_tlv_header->type,
- ptr.slow_oam_tlv_header->length);
+ ptr.slow_oam_tlv_header->length));
hexdump = FALSE;
switch (ptr.slow_oam_tlv_header->type) {
case SLOW_OAM_LINK_EVENT_END_OF_TLV:
if (ptr.slow_oam_tlv_header->length != 0) {
- printf("\n\t ERROR: illegal length - should be 0");
+ ND_PRINT((ndo, "\n\t ERROR: illegal length - should be 0"));
}
return;
@@ -585,12 +587,12 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
if (tlv.slow_oam_link_event->event_length !=
sizeof(struct slow_oam_link_event_t)) {
- printf("\n\t ERROR: illegal length - should be %lu",
- (unsigned long) sizeof(struct slow_oam_link_event_t));
+ ND_PRINT((ndo, "\n\t ERROR: illegal length - should be %lu",
+ (unsigned long) sizeof(struct slow_oam_link_event_t)));
return;
}
- printf("\n\t Timestamp %u ms, Errored Window %" PRIu64
+ ND_PRINT((ndo, "\n\t Timestamp %u ms, Errored Window %" PRIu64
"\n\t Errored Threshold %" PRIu64
"\n\t Errors %" PRIu64
"\n\t Error Running Total %" PRIu64
@@ -600,7 +602,7 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
EXTRACT_64BITS(&tlv.slow_oam_link_event->threshold),
EXTRACT_64BITS(&tlv.slow_oam_link_event->errors),
EXTRACT_64BITS(&tlv.slow_oam_link_event->errors_running_total),
- EXTRACT_32BITS(&tlv.slow_oam_link_event->event_running_total));
+ EXTRACT_32BITS(&tlv.slow_oam_link_event->event_running_total)));
break;
case SLOW_OAM_LINK_EVENT_ORG_SPECIFIC:
@@ -618,8 +620,8 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
}
/* do we also want to see a hex dump ? */
- if (vflag > 1 || hexdump==TRUE) {
- print_unknown_data(gndo,tptr,"\n\t ",
+ if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
+ print_unknown_data(ndo, tptr, "\n\t ",
ptr.slow_oam_tlv_header->length);
}
@@ -630,11 +632,11 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
case SLOW_OAM_CODE_LOOPBACK_CTRL:
tlv.slow_oam_loopbackctrl = (const struct slow_oam_loopbackctrl_t *)tptr;
- printf("\n\t Command %s (%u)",
+ ND_PRINT((ndo, "\n\t Command %s (%u)",
tok2str(slow_oam_loopbackctrl_cmd_values,
"Unknown",
tlv.slow_oam_loopbackctrl->command),
- tlv.slow_oam_loopbackctrl->command);
+ tlv.slow_oam_loopbackctrl->command));
tptr ++;
tlen --;
break;
@@ -647,8 +649,8 @@ void slow_oam_print(register const u_char *tptr, register u_int tlen) {
case SLOW_OAM_CODE_VAR_RESPONSE:
case SLOW_OAM_CODE_PRIVATE:
default:
- if (vflag <= 1) {
- print_unknown_data(gndo,tptr,"\n\t ", tlen);
+ if (ndo->ndo_vflag <= 1) {
+ print_unknown_data(ndo, tptr, "\n\t ", tlen);
}
break;
}