diff options
author | Chidambaram Arunachalam <carunach@cisco.com> | 2016-02-01 00:01:11 -0500 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-02-05 05:30:48 +0000 |
commit | 179b733d375f65e482afb84cb54c24d1c6466d21 (patch) | |
tree | e5f52630e8138206fca0a0cb28f0ce1d39ba96ae | |
parent | 005f44c222c96c56e7742af9afefe44bd296f528 (diff) |
Network Service Header Dissector for Ethernet & GRE encapsulation
draft-ietf-sfc-nsh-01.txt
Bug: 11490
Change-Id: I95adb1e0b1e42ba8c75e82145a756e2836a9a989
Reviewed-on: https://code.wireshark.org/review/13633
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | epan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/dissectors/Makefile.common | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-gre.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-nsh.c | 382 | ||||
-rw-r--r-- | epan/etypes.h | 4 |
6 files changed, 390 insertions, 0 deletions
@@ -3924,6 +3924,7 @@ Robert Jongbloed <robertj[AT]voxlucida.com.au> Pavel Moravec <pmoravec[AT]redhat.com> Robert Long <rlong[AT]sandia.gov> James Lynch <lynch007[AT]gmail.com> +Chidambaram Arunachalam <carunach[AT]cisco.com> Dan Lasley <dlasley[AT]promus.com> gave permission for his dumpit() hex-dump routine to be used. diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index e53db404f8..407313003b 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1077,6 +1077,7 @@ set(DISSECTOR_SRC dissectors/packet-nntp.c dissectors/packet-noe.c dissectors/packet-nsip.c + dissectors/packet-nsh.c dissectors/packet-nsrp.c dissectors/packet-nstrace.c dissectors/packet-nt-oui.c diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index abac28b253..88faa07f13 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -996,6 +996,7 @@ DISSECTOR_SRC = \ packet-nntp.c \ packet-noe.c \ packet-nsip.c \ + packet-nsh.c \ packet-nsrp.c \ packet-nstrace.c \ packet-nt-oui.c \ diff --git a/epan/dissectors/packet-gre.c b/epan/dissectors/packet-gre.c index 03de868d18..6c44314627 100644 --- a/epan/dissectors/packet-gre.c +++ b/epan/dissectors/packet-gre.c @@ -133,6 +133,7 @@ const value_string gre_typevals[] = { { ETHERTYPE_RAW_FR, "Frame Relay"}, { ETHERTYPE_IPv6, "IPv6" }, { ETHERTYPE_MPLS, "MPLS label switched packet" }, + { ETHERTYPE_NSH, "Network Service Header" }, { ETHERTYPE_CDMA2000_A10_UBS,"CDMA2000 A10 Unstructured byte stream" }, { ETHERTYPE_3GPP2, "CDMA2000 A10 3GPP2 Packet" }, { GRE_ARUBA_8200, "ARUBA WLAN" }, diff --git a/epan/dissectors/packet-nsh.c b/epan/dissectors/packet-nsh.c new file mode 100644 index 0000000000..16ba3761f7 --- /dev/null +++ b/epan/dissectors/packet-nsh.c @@ -0,0 +1,382 @@ +/*Routines for Network Service Header + *draft-ietf-sfc-nsh-01 + *Author: Chidambaram Arunachalam <carunach@cisco.com> + *Copyright 2016, ciscoSystems Inc. + * + * + *Wireshark - Network traffic analyzer + *By Gerald Combs <gerald@wireshark.org> + *Copyright 1998 Gerald Combs + * + *This program is free software; you can redistribute it and/or + *modify it under the terms of the GNU General Public License + *as published by the Free Software Foundation; either version 2 + *of the License, or (at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include <epan/packet.h> +#include <epan/expert.h> +#include <epan/ppptypes.h> +#include <epan/etypes.h> +#include <epan/prefs.h> +#include <epan/ipproto.h> +#include <epan/decode_as.h> + +#define MD_TYPE_1 1 +#define MD_TYPE_2 2 + +/* Prototypes */ +void proto_reg_handoff_nsh(void); +void proto_register_nsh(void); + +/*Network Service Header (NSH) Next Protocol field values */ + +enum { + NSH_IPV4 = 1, + NSH_IPV6, + NSH_ETHERNET, + NSH_EXPERIMENTAL +}; + +static const value_string nsh_next_protocols[] = { + { NSH_IPV4, "IPv4" }, + { NSH_IPV6, "IPv6" }, + { NSH_ETHERNET, "Ethernet" }, + { NSH_EXPERIMENTAL, "Experimental" }, + { 0, NULL } +}; + + +static int proto_nsh = -1; +static int hf_nsh_version = -1; +static int hf_nsh_oam = -1; +static int hf_nsh_critical_metadata = -1; +static int hf_nsh_reservedbits = -1; +static int hf_nsh_length = -1; +static int hf_nsh_md_type = -1; +static int hf_nsh_next_proto = -1; +static int hf_nsh_service_pathID = -1; +static int hf_nsh_service_index = -1; +static int hf_nsh_context_header = -1; +static int hf_nsh_metadata_class = -1; +static int hf_nsh_metadata_type = -1; +static int hf_nsh_metadata_reservedbits = -1; +static int hf_nsh_metadata_length = -1; +static int hf_nsh_metadata = -1; + +static gint ett_nsh = -1; +static dissector_handle_t dissector_ipv6; +static dissector_handle_t dissector_ip; +static dissector_handle_t dissector_eth; + +/* + *Dissect Fixed Length Context headers + * + */ +static void +dissect_nsh_md_type_1(tvbuff_t *tvb, proto_tree *nsh_tree, int offset) +{ + + proto_tree_add_item(nsh_tree, hf_nsh_context_header, tvb, offset, 4, ENC_NA); + proto_tree_add_item(nsh_tree, hf_nsh_context_header, tvb, offset + 4, 4, ENC_NA); + proto_tree_add_item(nsh_tree, hf_nsh_context_header, tvb, offset + 8, 4, ENC_NA); + proto_tree_add_item(nsh_tree, hf_nsh_context_header, tvb, offset + 12, 4, ENC_NA); + + +} + +/* + *Dissect Variable Length Context headers + * + */ + +static void +dissect_nsh_md_type_2(tvbuff_t *tvb, proto_tree *nsh_tree, int offset, int nsh_bytes_len) +{ + + int type2_metadata_len = 0; + + while (offset < nsh_bytes_len) { + + proto_tree_add_item(nsh_tree, hf_nsh_metadata_class, tvb, offset, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(nsh_tree, hf_nsh_metadata_type, tvb, offset + 2, 1, ENC_BIG_ENDIAN); + + /* Bits 24 - 26 are reserved */ + proto_tree_add_item(nsh_tree, hf_nsh_metadata_reservedbits, tvb, offset + 3, 1, ENC_BIG_ENDIAN); + + /*Bits 27-31 represent length in 4 bytes words*/ + proto_tree_add_item(nsh_tree, hf_nsh_metadata_length, tvb, offset + 3, 1, ENC_BIG_ENDIAN); + type2_metadata_len = 4 * tvb_get_bits8(tvb, ((offset + 3) * 8) + 3, 5); + + if (type2_metadata_len >= 4) + proto_tree_add_item(nsh_tree, hf_nsh_metadata, tvb, offset + 4, type2_metadata_len, ENC_NA); + + offset = offset + 4 + type2_metadata_len; + + } + + +} + + +/* + *Dissect Network Service Header + * + */ + +static int +dissect_nsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) +{ + + int offset = 0; + int md_type = -1; + int nsh_bytes_len = 0; + int nsh_next_proto = -1; + int captured_length; + tvbuff_t *next_tvb; + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "NSH"); + col_set_str(pinfo->cinfo, COL_INFO, "Network Service Header"); + + captured_length = tvb_captured_length(tvb); + + + if (tree) { + proto_item *ti; + proto_tree *nsh_tree; + + /* Bits 10 - 15 contain length value */ + nsh_bytes_len = 4 * tvb_get_bits8(tvb, 10, 6); + + ti = proto_tree_add_item(tree, proto_nsh, tvb, offset, nsh_bytes_len, ENC_NA); + nsh_tree = proto_item_add_subtree(ti, ett_nsh); + + /*NSH Base Header*/ + + proto_tree_add_item(nsh_tree, hf_nsh_version, tvb, offset, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(nsh_tree, hf_nsh_oam, tvb, offset, 1, ENC_BIG_ENDIAN); + proto_tree_add_item(nsh_tree, hf_nsh_critical_metadata, tvb, offset, 1, ENC_BIG_ENDIAN); + + + /* Bits 4 - 9 are reserved */ + proto_tree_add_item(nsh_tree, hf_nsh_reservedbits, tvb, offset, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(nsh_tree, hf_nsh_length, tvb, offset + 1, 1, ENC_BIG_ENDIAN); + + + md_type = tvb_get_guint8(tvb, offset + 2); + proto_tree_add_item(nsh_tree, hf_nsh_md_type, tvb, offset + 2, 1, ENC_BIG_ENDIAN); + + nsh_next_proto = tvb_get_guint8(tvb, offset + 3); + proto_tree_add_item(nsh_tree, hf_nsh_next_proto, tvb, offset + 3, 1, ENC_BIG_ENDIAN); + + /*NSH Service Path Header */ + offset = offset + 4; + proto_tree_add_item(nsh_tree, hf_nsh_service_pathID, tvb, offset, 3, ENC_BIG_ENDIAN); + proto_tree_add_item(nsh_tree, hf_nsh_service_index, tvb, offset + 3, 1, ENC_BIG_ENDIAN); + + /* Decode Context Headers */ + offset = offset + 4; + switch (md_type) { + + case MD_TYPE_1: + dissect_nsh_md_type_1(tvb, nsh_tree, offset); + break; + + case MD_TYPE_2: + + /* MD Type 2 indicates ZERO or more Variable Length Context headers*/ + if (nsh_bytes_len > 8) + dissect_nsh_md_type_2(tvb, nsh_tree, offset, nsh_bytes_len); + break; + + } + + /*Decode next protocol payload */ + + if (captured_length > (nsh_bytes_len)) { + + next_tvb = tvb_new_subset_remaining(tvb, nsh_bytes_len); + switch (nsh_next_proto) { + + case NSH_IPV4: + call_dissector(dissector_ip, next_tvb, pinfo, tree); + break; + + case NSH_IPV6: + call_dissector(dissector_ipv6, next_tvb, pinfo, tree); + break; + + case NSH_ETHERNET: + call_dissector(dissector_eth, next_tvb, pinfo, tree); + break; + + } + } + } + + return tvb_captured_length(tvb); + +} + +void +proto_register_nsh(void) +{ + static hf_register_info nsh_info[] = { + + /* Network Service Header fields */ + { &hf_nsh_version, + { "Version", "nsh.version", + FT_UINT16, BASE_DEC_HEX, NULL, 0xC000, + NULL, HFILL } + }, + + { &hf_nsh_oam, + { "O Bit", "nsh.Obit", + FT_UINT16, BASE_DEC, NULL, 0x2000, + "OAM Bit", HFILL } + }, + + + { &hf_nsh_critical_metadata, + { "C Bit", "nsh.CBit", + FT_UINT16, BASE_DEC, NULL, 0x1000, + "Critical Metadata Bit", HFILL } + }, + + + { &hf_nsh_reservedbits, + { "Reserved Bits", "nsh.reservedbits", + FT_UINT16, BASE_HEX, NULL, 0x0FC0, + "Reserved bits within NSH Base Header", HFILL } + }, + + + { &hf_nsh_length, + { "Length", "nsh.length", + FT_UINT16, BASE_DEC_HEX, NULL, 0x003F, + "Total length, in 4-byte words, of NSH including Base, Service Path headers and optional variable TLVs", HFILL } + }, + + + { &hf_nsh_md_type, + { "MD Type", "nsh.mdtype", + FT_UINT8, BASE_DEC_HEX, NULL, 0x00, + "Metadata Type defines the format of the metadata being carried", HFILL } + }, + + + { &hf_nsh_next_proto, + { "Next Protocol", "nsh.nextproto", + FT_UINT8, BASE_DEC_HEX, VALS(nsh_next_protocols), 0x00, + "Protocol type of the original packet", HFILL } + }, + + + { &hf_nsh_service_pathID, + { "SPI", "nsh.spi", + FT_UINT24, BASE_DEC_HEX, NULL, 0x00, + "Service Path Identifier", HFILL } + }, + + + { &hf_nsh_service_index, + { "SI", "nsh.si", + FT_UINT8, BASE_DEC_HEX, NULL, 0x00, + "Service Index", HFILL } + }, + + + + { &hf_nsh_context_header, + { "Context Header", "nsh.contextheader", + FT_BYTES, BASE_NONE, NULL, 0x00, + "Manadatory Context Header", HFILL } + }, + + + { &hf_nsh_metadata_class, + { "TLV Class", "nsh.metadataclass", + FT_UINT16, BASE_DEC_HEX, NULL, 0x00, + "TLV class describes the scope of the metadata type field", HFILL } + }, + + + { &hf_nsh_metadata_type, + { "Type", "nsh.metadatatype", + FT_UINT8, BASE_DEC_HEX, NULL, 0x00, + "Type of metadata", HFILL } + }, + + + { &hf_nsh_metadata_reservedbits, + { "Reserved Bits", "nsh.metadatareservedbits", + FT_UINT8, BASE_HEX, NULL, 0xE0, + "Reserved Bits within Variable Length Metadata header", HFILL } + }, + + + { &hf_nsh_metadata_length, + { "Length", "nsh.metadatalen", + FT_UINT8, BASE_HEX, NULL, 0x1F, + "Length of the variable metadata in 4-byte words", HFILL } + }, + + + { &hf_nsh_metadata, + { "Variable Metadata", "nsh.metadata", + FT_BYTES, BASE_NONE, NULL, 0x00, + "Variable length metadata", HFILL } + }, + + }; + + + static gint *ett[] = { + &ett_nsh, + }; + + proto_nsh = proto_register_protocol("Network Service Header", + "NSH", "nsh"); + proto_register_field_array(proto_nsh, nsh_info, array_length(nsh_info)); + proto_register_subtree_array(ett, array_length(ett)); + +} + +void +proto_reg_handoff_nsh(void) +{ + + dissector_handle_t nsh_handle; + + nsh_handle = create_dissector_handle(dissect_nsh, proto_nsh); + dissector_add_uint("gre.proto", ETHERTYPE_NSH, nsh_handle); + + dissector_ip = find_dissector("ip"); + dissector_ipv6 = find_dissector("ipv6"); + dissector_eth = find_dissector("eth"); + + +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/etypes.h b/epan/etypes.h index 5af30e5101..1e0b2694a1 100644 --- a/epan/etypes.h +++ b/epan/etypes.h @@ -538,6 +538,10 @@ extern "C" { #define ETHERTYPE_HSR 0x892F /* High-availability Seamless Redundancy (IEC62439 Part 3) */ #endif +#ifndef ETHERTYPE_NSH +#define ETHERTYPE_NSH 0x894F /* Network Service Header (draft-ietf-sfc-nsh-01.txt) */ +#endif + #ifndef ETHERTYPE_LOOP #define ETHERTYPE_LOOP 0x9000 /* used for layer 2 testing (do i see my own frames on the wire) */ #endif |