X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/aa944dd81d30c51e2577691c1a2baad1b4b596ef..d08b4abef4de825b3aecbb7c7e7601ac010806fc:/print-openflow-1.0.c diff --git a/print-openflow-1.0.c b/print-openflow-1.0.c index f4bd977b..73a9fd88 100644 --- a/print-openflow-1.0.c +++ b/print-openflow-1.0.c @@ -8,6 +8,13 @@ * * [OF10] http://www.openflow.org/documents/openflow-spec-v1.0.0.pdf * + * Decoding of Ethernet frames nested in OFPT_PACKET_IN and OFPT_PACKET_OUT + * messages is done only when the verbosity level set by command-line argument + * is "-vvv" or higher. In that case the verbosity level is temporarily + * decremented by 3 during the nested frame decoding. For example, running + * tcpdump with "-vvvv" will do full decoding of OpenFlow and "-v" decoding of + * the nested frames. + * * * Copyright (c) 2013 The TCPDUMP project * All rights reserved. @@ -44,10 +51,14 @@ #include "interface.h" #include "extract.h" #include "addrtoname.h" +#include "ether.h" #include "ethertype.h" #include "ipproto.h" #include "openflow.h" +static const char tstr[] = " [|openflow]"; +static const char cstr[] = " (corrupt)"; + #define OFPT_HELLO 0x00 #define OFPT_ERROR 0x01 #define OFPT_ECHO_REQUEST 0x02 @@ -566,7 +577,6 @@ static const struct tok empty_str[] = { #define OFP_MAX_PORT_NAME_LEN 16 #define DESC_STR_LEN 256 #define SERIAL_NUM_LEN 32 -#define OFP_ETH_ALEN 6 #define OFP_VLAN_NONE 0xffff static const char * @@ -616,7 +626,7 @@ of10_data_print(const u_char *cp, const u_char *ep, const u_int len) { return cp + len; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -633,11 +643,31 @@ of10_vendor_data_print(const u_char *cp, const u_char *ep, const u_int len) { return of10_data_print(cp, ep, len - 4); corrupt: /* skip the undersized data */ - printf(" (corrupt)"); + printf("%s", cstr); + TCHECK2(*cp, len); + return cp + len; +trunc: + printf("%s", tstr); + return ep; +} + +static const u_char * +of10_packet_data_print(const u_char *cp, const u_char *ep, const u_int len) { + if (len == 0) + return cp; + /* data */ + printf("\n\t data (%u octets)", len); + if (vflag < 3) + return cp + len; TCHECK2(*cp, len); + vflag -= 3; + printf(", frame decoding below\n"); + ether_print(gndo, cp, len, snapend - cp, NULL, NULL); + vflag += 3; return cp + len; + trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -655,9 +685,9 @@ of10_phy_ports_print(const u_char *cp, const u_char *ep, u_int len) { printf("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))); cp += 2; /* hw_addr */ - TCHECK2(*cp, OFP_ETH_ALEN); + TCHECK2(*cp, ETHER_ADDR_LEN); printf(", hw_addr %s", etheraddr_string(cp)); - cp += OFP_ETH_ALEN; + cp += ETHER_ADDR_LEN; /* name */ TCHECK2(*cp, OFP_MAX_PORT_NAME_LEN); printf(", name '"); @@ -706,11 +736,11 @@ next_port: return cp; corrupt: /* skip the undersized trailing data */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -780,11 +810,11 @@ next_property: return cp; corrupt: /* skip the rest of queue properties */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -826,11 +856,11 @@ next_queue: return cp; corrupt: /* skip the rest of queues */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -855,15 +885,15 @@ of10_match_print(const char *pfx, const u_char *cp, const u_char *ep) { printf("%smatch in_port %s", pfx, tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))); cp += 2; /* dl_src */ - TCHECK2(*cp, OFP_ETH_ALEN); + TCHECK2(*cp, ETHER_ADDR_LEN); if (! (wildcards & OFPFW_DL_SRC)) printf("%smatch dl_src %s", pfx, etheraddr_string(cp)); - cp += OFP_ETH_ALEN; + cp += ETHER_ADDR_LEN; /* dl_dst */ - TCHECK2(*cp, OFP_ETH_ALEN); + TCHECK2(*cp, ETHER_ADDR_LEN); if (! (wildcards & OFPFW_DL_DST)) printf("%smatch dl_dst %s", pfx, etheraddr_string(cp)); - cp += OFP_ETH_ALEN; + cp += ETHER_ADDR_LEN; /* dl_vlan */ TCHECK2(*cp, 2); if (! (wildcards & OFPFW_DL_VLAN)) @@ -932,7 +962,7 @@ of10_match_print(const char *pfx, const u_char *cp, const u_char *ep) { return cp + 2; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1031,9 +1061,9 @@ of10_actions_print(const char *pfx, const u_char *cp, const u_char *ep, case OFPAT_SET_DL_SRC: case OFPAT_SET_DL_DST: /* dl_addr */ - TCHECK2(*cp, OFP_ETH_ALEN); + TCHECK2(*cp, ETHER_ADDR_LEN); printf(", dl_addr %s", etheraddr_string(cp)); - cp += OFP_ETH_ALEN; + cp += ETHER_ADDR_LEN; /* pad */ TCHECK2(*cp, 6); cp += 6; @@ -1093,11 +1123,11 @@ next_action: return cp; corrupt: /* skip the rest of actions */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1133,7 +1163,7 @@ of10_features_reply_print(const u_char *cp, const u_char *ep, const u_int len) { return of10_phy_ports_print(cp, ep, len - OF_SWITCH_FEATURES_LEN); trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1189,7 +1219,7 @@ of10_flow_mod_print(const u_char *cp, const u_char *ep, const u_int len) { return of10_actions_print("\n\t ", cp, ep, len - OF_FLOW_MOD_LEN); trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1201,9 +1231,9 @@ of10_port_mod_print(const u_char *cp, const u_char *ep) { printf("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))); cp += 2; /* hw_addr */ - TCHECK2(*cp, OFP_ETH_ALEN); + TCHECK2(*cp, ETHER_ADDR_LEN); printf(", hw_addr %s", etheraddr_string(cp)); - cp += OFP_ETH_ALEN; + cp += ETHER_ADDR_LEN; /* config */ TCHECK2(*cp, 4); printf("\n\t config 0x%08x", EXTRACT_32BITS(cp)); @@ -1224,7 +1254,7 @@ of10_port_mod_print(const u_char *cp, const u_char *ep) { return cp + 4; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1302,11 +1332,11 @@ of10_stats_request_print(const u_char *cp, const u_char *ep, u_int len) { return cp; corrupt: /* skip the message body */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1347,11 +1377,11 @@ of10_desc_stats_reply_print(const u_char *cp, const u_char *ep, const u_int len) return cp + DESC_STR_LEN; corrupt: /* skip the message body */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp, len); return cp + len; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1426,11 +1456,11 @@ of10_flow_stats_reply_print(const u_char *cp, const u_char *ep, u_int len) { return cp; corrupt: /* skip the rest of flow statistics entries */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1457,11 +1487,11 @@ of10_aggregate_stats_reply_print(const u_char *cp, const u_char *ep, return cp + 4; corrupt: /* skip the message body */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp, len); return cp + len; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1514,11 +1544,11 @@ of10_table_stats_reply_print(const u_char *cp, const u_char *ep, u_int len) { return cp; corrupt: /* skip the undersized trailing data */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1597,11 +1627,11 @@ next_port: return cp; corrupt: /* skip the undersized trailing data */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1643,11 +1673,11 @@ of10_queue_stats_reply_print(const u_char *cp, const u_char *ep, u_int len) { return cp; corrupt: /* skip the undersized trailing data */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1685,7 +1715,7 @@ of10_stats_reply_print(const u_char *cp, const u_char *ep, const u_int len) { return cp0 + len; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1714,14 +1744,14 @@ of10_packet_out_print(const u_char *cp, const u_char *ep, const u_int len) { if (ep == (cp = of10_actions_print("\n\t ", cp, ep, actions_len))) return ep; /* end of snapshot */ /* data */ - return of10_data_print(cp, ep, len - OF_PACKET_OUT_LEN - actions_len); + return of10_packet_data_print(cp, ep, len - OF_PACKET_OUT_LEN - actions_len); corrupt: /* skip the rest of the message body */ - printf(" (corrupt)"); + printf("%s", cstr); TCHECK2(*cp0, len0); return cp0 + len0; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1749,10 +1779,10 @@ of10_packet_in_print(const u_char *cp, const u_char *ep, const u_int len) { cp += 1; /* data */ /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */ - return of10_data_print(cp, ep, len - (OF_PACKET_IN_LEN - 2)); + return of10_packet_data_print(cp, ep, len - (OF_PACKET_IN_LEN - 2)); trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1804,7 +1834,7 @@ of10_flow_removed_print(const u_char *cp, const u_char *ep) { return cp + 8; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -1835,7 +1865,7 @@ of10_error_print(const u_char *cp, const u_char *ep, const u_int len) { return of10_data_print(cp, ep, len - OF_ERROR_MSG_LEN); trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; } @@ -2012,11 +2042,11 @@ of10_header_body_print(const u_char *cp, const u_char *ep, const uint8_t type, goto next_message; corrupt: /* skip the message body */ - printf(" (corrupt)"); + printf("%s", cstr); next_message: TCHECK2(*cp0, len0 - OF_HEADER_LEN); return cp0 + len0 - OF_HEADER_LEN; trunc: - printf(" [|openflow]"); + printf("%s", tstr); return ep; }