From 7ac8b97895e14f360cab0c1bbaca50c5ba7fd812 Mon Sep 17 00:00:00 2001 From: David Underhill Date: Fri, 11 Jul 2008 20:16:21 -0700 Subject: [PATCH] Added Packet In dissector. -- Sub-dissects the the data portion with the Ethernet dissector! -- cleaned up var decls by putting cases in stmt blocks --- .../openflow/packet-openflow.c | 123 +++++++++++++----- 1 file changed, 93 insertions(+), 30 deletions(-) diff --git a/utilities/wireshark_dissectors/openflow/packet-openflow.c b/utilities/wireshark_dissectors/openflow/packet-openflow.c index f59cb61..d04f31f 100644 --- a/utilities/wireshark_dissectors/openflow/packet-openflow.c +++ b/utilities/wireshark_dissectors/openflow/packet-openflow.c @@ -35,6 +35,9 @@ static void dissect_openflow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree #define TCP_PORT_FILTER "tcp.port" static int global_openflow_proto = OPENFLOW_DST_TCP_PORT; +/* try to find the ethernet dissector to dissect encapsulated Ethernet data */ +static dissector_handle_t data_ethernet; + /* AM=Async message, CSM=Control/Switch Message */ /** names to bind to various values in the type field */ static const value_string names_ofp_type[] = { @@ -316,12 +319,12 @@ static gint ofp_packet_out_data = -1; /* Asynchronous Messages */ static gint ofp_packet_in = -1; -static gint ofp_packet_buffer_id = -1; -static gint ofp_packet_total_len = -1; -static gint ofp_packet_in_port = -1; -static gint ofp_packet_reason = -1; -static gint ofp_packet_pad = -1; -static gint ofp_packet_data = -1; +static gint ofp_packet_in_buffer_id = -1; +static gint ofp_packet_in_total_len = -1; +static gint ofp_packet_in_in_port = -1; +static gint ofp_packet_in_reason = -1; +static gint ofp_packet_in_pad = -1; +static gint ofp_packet_in_data_hdr = -1; static gint ofp_flow_expired = -1; /* field: ofp_match */ @@ -378,6 +381,7 @@ static gint ett_ofp_packet_out = -1; /* Asynchronous Messages */ static gint ett_ofp_packet_in = -1; +static gint ett_ofp_packet_in_data_hdr = -1; static gint ett_ofp_flow_expired = -1; static gint ett_ofp_port_status = -1; static gint ett_ofp_error_msg = -1; @@ -402,6 +406,8 @@ static inline char* indent( char* str ) { void proto_register_openflow() { + data_ethernet = find_dissector("eth"); + /* initialize uninitialized header fields */ int i; for( i=0; i 0 ) { @@ -869,6 +898,7 @@ static void dissect_openflow_message(tvbuff_t *tvb, packet_info *pinfo, proto_tr add_child_str(sf_port_tree, ofp_switch_features_ports_warn, tvb, &offset, 0, str); } break; + } case OFPT_GET_CONFIG_REQUEST: @@ -882,9 +912,42 @@ static void dissect_openflow_message(tvbuff_t *tvb, packet_info *pinfo, proto_tr break; - case OFPT_PACKET_IN: + case OFPT_PACKET_IN: { + type_item = proto_tree_add_item(ofp_tree, ofp_packet_in, tvb, offset, -1, FALSE); + type_tree = proto_item_add_subtree(type_item, ett_ofp_packet_in); + + add_child(type_tree, ofp_packet_in_buffer_id, tvb, &offset, 4); + + /* specially process total length to remove the 2 fake bytes at the + start of the data (so we show the REAL Ethernet frame length) */ + guint16 total_len = tvb_get_ntohs( tvb, offset ); + proto_tree_add_uint(type_tree, ofp_packet_in_total_len, tvb, offset, 2, total_len); + offset += 2; + + add_child(type_tree, ofp_packet_in_in_port, tvb, &offset, 2); + add_child(type_tree, ofp_packet_in_reason, tvb, &offset, 1); + add_child(type_tree, ofp_packet_in_pad, tvb, &offset, 1); + + /* continue the dissection with the Ethernet dissector */ + if( data_ethernet ) { + proto_item *data_item = proto_tree_add_item(type_tree, ofp_packet_in_data_hdr, tvb, offset, -1, FALSE); + proto_tree *data_tree = proto_item_add_subtree(data_item, ett_ofp_packet_in_data_hdr); + tvbuff_t *next_tvb = tvb_new_subset(tvb, offset, -1, total_len); + if (check_col(pinfo->cinfo, COL_PROTOCOL)) + col_append_str( pinfo->cinfo, COL_PROTOCOL, "+" ); + if(check_col(pinfo->cinfo,COL_INFO)) + col_append_str( pinfo->cinfo, COL_INFO, " => " ); + col_set_fence(pinfo->cinfo, COL_PROTOCOL); + col_set_fence(pinfo->cinfo, COL_INFO); + call_dissector(data_ethernet, next_tvb, pinfo, data_tree); + } + else { + /* if we couldn't load the ethernet dissector, just display the bytes */ + add_child(type_tree, ofp_packet_in_data_hdr, tvb, &offset, total_len); + } break; + } case OFPT_PACKET_OUT: