aboutsummaryrefslogtreecommitdiff
path: root/contrib/tcpdump/print-cfm.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tcpdump/print-cfm.c')
-rw-r--r--contrib/tcpdump/print-cfm.c231
1 files changed, 111 insertions, 120 deletions
diff --git a/contrib/tcpdump/print-cfm.c b/contrib/tcpdump/print-cfm.c
index fb0476f5584c..e6aec0b91f38 100644
--- a/contrib/tcpdump/print-cfm.c
+++ b/contrib/tcpdump/print-cfm.c
@@ -17,11 +17,7 @@
* Original code by Hannes Gredler (hannes@juniper.net)
*/
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-cfm.c,v 1.5 2007-07-24 16:01:42 hannes Exp $";
-#endif
-
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -29,8 +25,6 @@ static const char rcsid[] _U_ =
#include <tcpdump-stdinc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "interface.h"
#include "extract.h"
@@ -39,17 +33,11 @@ static const char rcsid[] _U_ =
#include "oui.h"
#include "af.h"
-/*
- * Prototypes
- */
-const char * cfm_egress_id_string(register const u_char *);
-int cfm_mgmt_addr_print(register const u_char *);
-
struct cfm_common_header_t {
- u_int8_t mdlevel_version;
- u_int8_t opcode;
- u_int8_t flags;
- u_int8_t first_tlv_offset;
+ uint8_t mdlevel_version;
+ uint8_t opcode;
+ uint8_t flags;
+ uint8_t first_tlv_offset;
};
#define CFM_VERSION 0
@@ -75,13 +63,13 @@ static const struct tok cfm_opcode_values[] = {
* Message Formats.
*/
struct cfm_ccm_t {
- u_int8_t sequence[4];
- u_int8_t ma_epi[2];
- u_int8_t md_nameformat;
- u_int8_t md_namelength;
- u_int8_t md_name[46]; /* md name and short ma name */
- u_int8_t reserved_itu[16];
- u_int8_t reserved[6];
+ uint8_t sequence[4];
+ uint8_t ma_epi[2];
+ uint8_t md_nameformat;
+ uint8_t md_namelength;
+ uint8_t md_name[46]; /* md name and short ma name */
+ uint8_t reserved_itu[16];
+ uint8_t reserved[6];
};
/*
@@ -126,17 +114,17 @@ static const struct tok cfm_ma_nameformat_values[] = {
};
struct cfm_lbm_t {
- u_int8_t transaction_id[4];
- u_int8_t reserved[4];
+ uint8_t transaction_id[4];
+ uint8_t reserved[4];
};
struct cfm_ltm_t {
- u_int8_t transaction_id[4];
- u_int8_t egress_id[8];
- u_int8_t ttl;
- u_int8_t original_mac[ETHER_ADDR_LEN];
- u_int8_t target_mac[ETHER_ADDR_LEN];
- u_int8_t reserved[3];
+ uint8_t transaction_id[4];
+ uint8_t egress_id[8];
+ uint8_t ttl;
+ uint8_t original_mac[ETHER_ADDR_LEN];
+ uint8_t target_mac[ETHER_ADDR_LEN];
+ uint8_t reserved[3];
};
static const struct tok cfm_ltm_flag_values[] = {
@@ -145,17 +133,18 @@ static const struct tok cfm_ltm_flag_values[] = {
};
struct cfm_ltr_t {
- u_int8_t transaction_id[4];
- u_int8_t last_egress_id[8];
- u_int8_t next_egress_id[8];
- u_int8_t ttl;
- u_int8_t replay_action;
- u_int8_t reserved[6];
+ uint8_t transaction_id[4];
+ uint8_t last_egress_id[8];
+ uint8_t next_egress_id[8];
+ uint8_t ttl;
+ uint8_t replay_action;
+ uint8_t reserved[6];
};
static const struct tok cfm_ltr_flag_values[] = {
- { 0x80, "Forwarded"},
- { 0x40, "Terminal MEP"},
+ { 0x80, "UseFDB Only"},
+ { 0x40, "FwdYes"},
+ { 0x20, "Terminal MEP"},
{ 0, NULL}
};
@@ -193,8 +182,8 @@ static const struct tok cfm_tlv_values[] = {
*/
struct cfm_tlv_header_t {
- u_int8_t type;
- u_int8_t length[2];
+ uint8_t type;
+ uint8_t length[2];
};
/* FIXME define TLV formats */
@@ -236,8 +225,9 @@ static const struct tok cfm_tlv_senderid_chassisid_values[] = {
};
-int
-cfm_mgmt_addr_print(register const u_char *tptr) {
+static int
+cfm_mgmt_addr_print(netdissect_options *ndo,
+ register const u_char *tptr) {
u_int mgmt_addr_type;
u_int hexdump = FALSE;
@@ -248,21 +238,21 @@ cfm_mgmt_addr_print(register const u_char *tptr) {
* is only once octet
*/
mgmt_addr_type = *tptr;
- printf("\n\t Management Address Type %s (%u)",
+ ND_PRINT((ndo, "\n\t Management Address Type %s (%u)",
tok2str(af_values, "Unknown", mgmt_addr_type),
- mgmt_addr_type);
+ mgmt_addr_type));
/*
* Resolve the passed in Address.
*/
switch(mgmt_addr_type) {
case AFNUM_INET:
- printf(", %s", ipaddr_string(tptr + 1));
+ ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1)));
break;
#ifdef INET6
case AFNUM_INET6:
- printf(", %s", ip6addr_string(tptr + 1));
+ ND_PRINT((ndo, ", %s", ip6addr_string(ndo, tptr + 1)));
break;
#endif
@@ -277,24 +267,25 @@ cfm_mgmt_addr_print(register const u_char *tptr) {
/*
* The egress-ID string is a 16-Bit string plus a MAC address.
*/
-const char *
-cfm_egress_id_string(register const u_char *tptr) {
+static const char *
+cfm_egress_id_string(netdissect_options *ndo, register const u_char *tptr) {
static char egress_id_buffer[80];
-
+
snprintf(egress_id_buffer, sizeof(egress_id_buffer),
- "MAC %0x4x-%s",
+ "MAC 0x%4x-%s",
EXTRACT_16BITS(tptr),
- etheraddr_string(tptr+2));
+ etheraddr_string(ndo, tptr+2));
return egress_id_buffer;
}
void
-cfm_print(register const u_char *pptr, register u_int length) {
+cfm_print(netdissect_options *ndo,
+ register const u_char *pptr, register u_int length) {
const struct cfm_common_header_t *cfm_common_header;
const struct cfm_tlv_header_t *cfm_tlv_header;
- const u_int8_t *tptr, *tlv_ptr, *ma_name, *ma_nameformat, *ma_namelength;
+ const uint8_t *tptr, *tlv_ptr, *ma_name, *ma_nameformat, *ma_namelength;
u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
@@ -307,31 +298,31 @@ cfm_print(register const u_char *pptr, register u_int length) {
tptr=pptr;
cfm_common_header = (const struct cfm_common_header_t *)pptr;
- TCHECK(*cfm_common_header);
+ ND_TCHECK(*cfm_common_header);
/*
* Sanity checking of the header.
*/
if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
- printf("CFMv%u not supported, length %u",
- CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length);
+ ND_PRINT((ndo, "CFMv%u not supported, length %u",
+ CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length));
return;
}
- printf("CFMv%u %s, MD Level %u, length %u",
+ ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u",
CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
- length);
+ length));
/*
* In non-verbose mode just print the opcode and md-level.
*/
- if (vflag < 1) {
+ if (ndo->ndo_vflag < 1) {
return;
}
- printf("\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset);
+ ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset));
tptr += sizeof(const struct cfm_common_header_t);
tlen = length - sizeof(struct cfm_common_header_t);
@@ -341,53 +332,53 @@ cfm_print(register const u_char *pptr, register u_int length) {
msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
- printf(", Flags [CCM Interval %u%s]",
+ ND_PRINT((ndo, ", Flags [CCM Interval %u%s]",
ccm_interval,
cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
- ", RDI" : "");
+ ", RDI" : ""));
/*
* Resolve the CCM interval field.
*/
if (ccm_interval) {
- printf("\n\t CCM Interval %.3fs"
+ ND_PRINT((ndo, "\n\t CCM Interval %.3fs"
", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
ccm_interval_base[ccm_interval],
ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
- ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER);
+ ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER));
}
- printf("\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
+ ND_PRINT((ndo, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
EXTRACT_32BITS(msg_ptr.cfm_ccm->sequence),
- EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi));
+ EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi)));
/*
* Resolve the MD fields.
*/
- printf("\n\t MD Name Format %s (%u), MD Name length %u",
+ ND_PRINT((ndo, "\n\t MD Name Format %s (%u), MD Name length %u",
tok2str(cfm_md_nameformat_values, "Unknown",
msg_ptr.cfm_ccm->md_nameformat),
msg_ptr.cfm_ccm->md_nameformat,
- msg_ptr.cfm_ccm->md_namelength);
+ msg_ptr.cfm_ccm->md_namelength));
if (msg_ptr.cfm_ccm->md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
- printf("\n\t MD Name: ");
+ ND_PRINT((ndo, "\n\t MD Name: "));
switch (msg_ptr.cfm_ccm->md_nameformat) {
case CFM_CCM_MD_FORMAT_DNS:
case CFM_CCM_MD_FORMAT_CHAR:
- safeputs((const char *)msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength);
+ safeputs(ndo, msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength);
break;
case CFM_CCM_MD_FORMAT_MAC:
- printf("\n\t MAC %s", etheraddr_string(
- msg_ptr.cfm_ccm->md_name));
+ ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo,
+ msg_ptr.cfm_ccm->md_name)));
break;
/* FIXME add printers for those MD formats - hexdump for now */
case CFM_CCM_MA_FORMAT_8021:
default:
- print_unknown_data(msg_ptr.cfm_ccm->md_name, "\n\t ",
+ print_unknown_data(ndo, msg_ptr.cfm_ccm->md_name, "\n\t ",
msg_ptr.cfm_ccm->md_namelength);
}
}
@@ -400,16 +391,16 @@ cfm_print(register const u_char *pptr, register u_int length) {
ma_namelength = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 1;
ma_name = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 2;
- printf("\n\t MA Name-Format %s (%u), MA name length %u",
+ ND_PRINT((ndo, "\n\t MA Name-Format %s (%u), MA name length %u",
tok2str(cfm_ma_nameformat_values, "Unknown",
*ma_nameformat),
*ma_nameformat,
- *ma_namelength);
+ *ma_namelength));
- printf("\n\t MA Name: ");
+ ND_PRINT((ndo, "\n\t MA Name: "));
switch (*ma_nameformat) {
case CFM_CCM_MA_FORMAT_CHAR:
- safeputs((const char *)ma_name, *ma_namelength);
+ safeputs(ndo, ma_name, *ma_namelength);
break;
/* FIXME add printers for those MA formats - hexdump for now */
@@ -418,45 +409,45 @@ cfm_print(register const u_char *pptr, register u_int length) {
case CFM_CCM_MA_FORMAT_INT:
case CFM_CCM_MA_FORMAT_VPN:
default:
- print_unknown_data(ma_name, "\n\t ", *ma_namelength);
+ print_unknown_data(ndo, ma_name, "\n\t ", *ma_namelength);
}
break;
case CFM_OPCODE_LTM:
msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
- printf(", Flags [%s]",
- bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags));
+ ND_PRINT((ndo, ", Flags [%s]",
+ bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags)));
- printf("\n\t Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
+ ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
EXTRACT_32BITS(msg_ptr.cfm_ltm->transaction_id),
- cfm_egress_id_string(msg_ptr.cfm_ltm->egress_id),
- msg_ptr.cfm_ltm->ttl);
+ cfm_egress_id_string(ndo, msg_ptr.cfm_ltm->egress_id),
+ msg_ptr.cfm_ltm->ttl));
- printf("\n\t Original-MAC %s, Target-MAC %s",
- etheraddr_string(msg_ptr.cfm_ltm->original_mac),
- etheraddr_string(msg_ptr.cfm_ltm->target_mac));
+ ND_PRINT((ndo, "\n\t Original-MAC %s, Target-MAC %s",
+ etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
+ etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac)));
break;
case CFM_OPCODE_LTR:
msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
- printf(", Flags [%s]",
- bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags));
+ ND_PRINT((ndo, ", Flags [%s]",
+ bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags)));
- printf("\n\t Transaction-ID 0x%08x, Last-Egress-ID %s",
+ ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, Last-Egress-ID %s",
EXTRACT_32BITS(msg_ptr.cfm_ltr->transaction_id),
- cfm_egress_id_string(msg_ptr.cfm_ltr->last_egress_id));
+ cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->last_egress_id)));
- printf("\n\t Next-Egress-ID %s, ttl %u",
- cfm_egress_id_string(msg_ptr.cfm_ltr->next_egress_id),
- msg_ptr.cfm_ltr->ttl);
+ ND_PRINT((ndo, "\n\t Next-Egress-ID %s, ttl %u",
+ cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->next_egress_id),
+ msg_ptr.cfm_ltr->ttl));
- printf("\n\t Replay-Action %s (%u)",
+ ND_PRINT((ndo, "\n\t Replay-Action %s (%u)",
tok2str(cfm_ltr_replay_action_values,
"Unknown",
msg_ptr.cfm_ltr->replay_action),
- msg_ptr.cfm_ltr->replay_action);
+ msg_ptr.cfm_ltr->replay_action));
break;
/*
@@ -467,7 +458,7 @@ cfm_print(register const u_char *pptr, register u_int length) {
case CFM_OPCODE_LBM:
default:
if (tlen > cfm_common_header->first_tlv_offset) {
- print_unknown_data(tptr, "\n\t ",
+ print_unknown_data(ndo, tptr, "\n\t ",
tlen - cfm_common_header->first_tlv_offset);
}
break;
@@ -482,32 +473,32 @@ cfm_print(register const u_char *pptr, register u_int length) {
tptr += cfm_common_header->first_tlv_offset;
tlen -= cfm_common_header->first_tlv_offset;
-
+
while (tlen > 0) {
cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
/* Enough to read the tlv type ? */
- TCHECK2(*tptr, 1);
+ ND_TCHECK2(*tptr, 1);
cfm_tlv_type=cfm_tlv_header->type;
if (cfm_tlv_type != CFM_TLV_END) {
/* did we capture enough for fully decoding the object header ? */
- TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
+ ND_TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
cfm_tlv_len=EXTRACT_16BITS(&cfm_tlv_header->length);
} else {
cfm_tlv_len = 0;
}
- printf("\n\t%s TLV (0x%02x), length %u",
+ ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
cfm_tlv_type,
- cfm_tlv_len);
+ cfm_tlv_len));
/* sanity check for not walking off and infinite loop check. */
if ((cfm_tlv_type != CFM_TLV_END) &&
((cfm_tlv_len + sizeof(struct cfm_tlv_header_t) > tlen) ||
(!cfm_tlv_len))) {
- print_unknown_data(tptr,"\n\t ",tlen);
+ print_unknown_data(ndo, tptr, "\n\t ", tlen);
return;
}
@@ -517,7 +508,7 @@ cfm_print(register const u_char *pptr, register u_int length) {
/* did we capture enough for fully decoding the object ? */
if (cfm_tlv_type != CFM_TLV_END) {
- TCHECK2(*tptr, cfm_tlv_len);
+ ND_TCHECK2(*tptr, cfm_tlv_len);
}
hexdump = FALSE;
@@ -527,22 +518,22 @@ cfm_print(register const u_char *pptr, register u_int length) {
return;
case CFM_TLV_PORT_STATUS:
- printf(", Status: %s (%u)",
+ ND_PRINT((ndo, ", Status: %s (%u)",
tok2str(cfm_tlv_port_status_values, "Unknown", *tptr),
- *tptr);
+ *tptr));
break;
case CFM_TLV_INTERFACE_STATUS:
- printf(", Status: %s (%u)",
+ ND_PRINT((ndo, ", Status: %s (%u)",
tok2str(cfm_tlv_interface_status_values, "Unknown", *tptr),
- *tptr);
+ *tptr));
break;
case CFM_TLV_PRIVATE:
- printf(", Vendor: %s (%u), Sub-Type %u",
+ ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u",
tok2str(oui_values,"Unknown", EXTRACT_24BITS(tptr)),
EXTRACT_24BITS(tptr),
- *(tptr+3));
+ *(tptr + 3)));
hexdump = TRUE;
break;
@@ -565,20 +556,20 @@ cfm_print(register const u_char *pptr, register u_int length) {
if (chassis_id_length) {
chassis_id_type = *tptr;
- printf("\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
+ ND_PRINT((ndo, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
tok2str(cfm_tlv_senderid_chassisid_values,
"Unknown",
chassis_id_type),
chassis_id_type,
- chassis_id_length);
+ chassis_id_length));
switch (chassis_id_type) {
case CFM_CHASSIS_ID_MAC_ADDRESS:
- printf("\n\t MAC %s", etheraddr_string(tptr+1));
+ ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo, tptr + 1)));
break;
case CFM_CHASSIS_ID_NETWORK_ADDRESS:
- hexdump |= cfm_mgmt_addr_print(tptr);
+ hexdump |= cfm_mgmt_addr_print(ndo, tptr);
break;
case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
@@ -586,7 +577,7 @@ cfm_print(register const u_char *pptr, register u_int length) {
case CFM_CHASSIS_ID_LOCAL:
case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
case CFM_CHASSIS_ID_PORT_COMPONENT:
- safeputs((const char *)tptr+1, chassis_id_length);
+ safeputs(ndo, tptr + 1, chassis_id_length);
break;
default:
@@ -611,7 +602,7 @@ cfm_print(register const u_char *pptr, register u_int length) {
tlen--;
if (mgmt_addr_length) {
- hexdump |= cfm_mgmt_addr_print(tptr);
+ hexdump |= cfm_mgmt_addr_print(ndo, tptr);
}
tptr += mgmt_addr_length;
@@ -633,13 +624,13 @@ cfm_print(register const u_char *pptr, register u_int length) {
break;
}
/* do we want to see an additional hexdump ? */
- if (hexdump || vflag > 1)
- print_unknown_data(tlv_ptr, "\n\t ", cfm_tlv_len);
+ if (hexdump || ndo->ndo_vflag > 1)
+ print_unknown_data(ndo, tlv_ptr, "\n\t ", cfm_tlv_len);
tptr+=cfm_tlv_len;
tlen-=cfm_tlv_len;
}
return;
trunc:
- printf("\n\t\t packet exceeded snapshot");
+ ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
}