From cfcb33e8b78d4c9e28cc5fa65f3b799c78f53ced Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 21 Nov 2022 20:42:53 +0800 Subject: [PATCH] MCTP: Add NCSI (and ethernet) over MCTP dissection This change adds support for trivially-encapsulated MCTP protocols, starting with NCSI-over-MCTP. We need to handle this slightly different from the existing MCTP-based protocols (MCTP control protocol and NVMe-MI), as the inner protocol is unaware of the type byte and (optional) checksum tailer. So, add a new dissector table, "mctp.encap-type" for these, meaning we can just hook into the raw NC-SI dissector. We also add the type definition for MCTP-over-ethernet, as defined in the NCSI-over-MCTP specification. Signed-off-by: Jeremy Kerr --- epan/dissectors/packet-eth.c | 2 ++ epan/dissectors/packet-mctp.c | 35 +++++++++++++++++++++++++++++++++-- epan/dissectors/packet-ncsi.c | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 2be4473566..9f3deff915 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -35,6 +35,7 @@ #include "packet-vxlan.h" #include "packet-nsh.h" #include "packet-acdr.h" +#include "packet-mctp.h" #include #include @@ -1197,6 +1198,7 @@ proto_reg_handoff_eth(void) dissector_add_uint("acdr.media_type", ACDR_Control, eth_withoutfcs_handle); dissector_add_uint("acdr.media_type", ACDR_DSP_SNIFFER, eth_withoutfcs_handle); + dissector_add_uint("mctp.encap-type", MCTP_TYPE_ETHERNET, eth_withoutfcs_handle); /* * This is to handle the output for the Cisco CMTS "cable intercept" diff --git a/epan/dissectors/packet-mctp.c b/epan/dissectors/packet-mctp.c index 6baac3dfa3..9c3a3ca35c 100644 --- a/epan/dissectors/packet-mctp.c +++ b/epan/dissectors/packet-mctp.c @@ -95,6 +95,7 @@ static const value_string flag_vals[] = { }; static dissector_table_t mctp_dissector_table; +static dissector_table_t mctp_encap_dissector_table; static reassembly_table mctp_reassembly_table; static int @@ -208,9 +209,17 @@ dissect_mctp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } if (next_tvb) { + int rc; + type = tvb_get_guint8(next_tvb, 0); - dissector_try_uint_new(mctp_dissector_table, type & 0x7f, next_tvb, - pinfo, tree, true, NULL); + rc = dissector_try_uint_new(mctp_dissector_table, type & 0x7f, + next_tvb, pinfo, tree, true, NULL); + + if (!rc && !(type & 0x80)) { + tvbuff_t *encap_tvb = tvb_new_subset_remaining(next_tvb, 1); + dissector_try_uint_new(mctp_encap_dissector_table, type, + encap_tvb, pinfo, tree, true, NULL); + } } pinfo->fragmented = save_fragmented; @@ -330,9 +339,31 @@ proto_register_mctp(void) proto_register_field_array(proto_mctp, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); + /* We have two dissector tables here, both keyed off the type byte, but + * with different decode semantics: + * + * mctp.type: for protocols that are "MCTP-aware" - they perform their + * own decoding of the type byte, including the IC bit, and possibly the + * message integrity check (which is type-specific!). For example, + * NVMe-MI, which includes the type byte in packet specifications + * + * mctp.encap-type: for procotols that are trivially encapsulated in a + * MCTP message, and do not handle the type byte themselves. For + * example, NC-SI over MCTP, which just wraps a NC-SI packet within + * a MCTP message. + * + * it doesn't make sense to allow encap-type decoders to also have the IC + * bit set, as there is no specification for what format the message + * integrity check is in. So, we disallow the IC bit in the type field + * for those dissectors. + */ mctp_dissector_table = register_dissector_table("mctp.type", "MCTP type", proto_mctp, FT_UINT8, BASE_HEX); + mctp_encap_dissector_table = register_dissector_table("mctp.encap-type", + "MCTP encapsulated type", + proto_mctp, FT_UINT8, + BASE_HEX); reassembly_table_register(&mctp_reassembly_table, &addresses_reassembly_table_functions); diff --git a/epan/dissectors/packet-ncsi.c b/epan/dissectors/packet-ncsi.c index 61b69252b2..3756d5f7dd 100644 --- a/epan/dissectors/packet-ncsi.c +++ b/epan/dissectors/packet-ncsi.c @@ -26,6 +26,7 @@ #include #include #include +#include void proto_reg_handoff_ncsi(void); void proto_register_ncsi(void); @@ -1670,6 +1671,7 @@ void proto_reg_handoff_ncsi(void) { dissector_add_uint("ethertype", ETHERTYPE_NCSI, ncsi_handle); + dissector_add_uint("mctp.encap-type", MCTP_TYPE_NCSI, ncsi_handle); } /*