diff options
author | Michael Mann <mmann78@netscape.net> | 2017-04-17 08:52:57 -0400 |
---|---|---|
committer | Martin Kaiser <wireshark@kaiser.cx> | 2017-04-17 20:22:45 +0000 |
commit | 2273cf0e7b2dedc20430594a4ee840d640203ab3 (patch) | |
tree | bb0da493cb545c590fa329fd1c9b6fefe94f3ecb | |
parent | 25382fd638a7152d0262b994b1b1b38e9e1ae283 (diff) |
packet-nsh.c: Create dissector table for next protocol
Change-Id: Id8be2a37f99f4ac9d531a694273c7d5d3f843cc1
Reviewed-on: https://code.wireshark.org/review/21163
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
-rw-r--r-- | epan/dissectors/Makefile.am | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-eth.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-ip.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-ipv6.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-mpls.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-nsh.c | 100 | ||||
-rw-r--r-- | epan/dissectors/packet-nsh.h | 38 |
7 files changed, 76 insertions, 71 deletions
diff --git a/epan/dissectors/Makefile.am b/epan/dissectors/Makefile.am index 4e34fa0bef..b74e9c3789 100644 --- a/epan/dissectors/Makefile.am +++ b/epan/dissectors/Makefile.am @@ -1657,6 +1657,7 @@ DISSECTOR_INCLUDES = \ packet-nfs.h \ packet-nisplus.h \ packet-nlm.h \ + packet-nsh.h \ packet-ntlmssp.h \ packet-ntp.h \ packet-nvme.h \ diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 30cfc9f64c..83657bffd5 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -43,6 +43,7 @@ #include "packet-sflow.h" #include "packet-l2tp.h" #include "packet-vxlan.h" +#include "packet-nsh.h" #include <epan/crc32-tvb.h> #include <wiretap/erf.h> @@ -1025,6 +1026,7 @@ proto_reg_handoff_eth(void) dissector_add_uint("l2tp.pw_type", L2TPv3_PROTOCOL_ETH, eth_withoutfcs_handle); dissector_add_uint("vxlan.next_proto", VXLAN_ETHERNET, eth_withoutfcs_handle); dissector_add_uint("sll.ltype", LINUX_SLL_P_ETHERNET, eth_withoutfcs_handle); + dissector_add_uint("nsh.next_proto", NSH_ETHERNET, eth_withoutfcs_handle); /* * This is to handle the output for the Cisco CMTS "cable intercept" diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index b50428e516..6841abe3b7 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -58,6 +58,7 @@ #include "packet-l2tp.h" #include "packet-vxlan.h" #include "packet-mpls.h" +#include "packet-nsh.h" #ifdef HAVE_GEOIP #include <GeoIP.h> @@ -3062,6 +3063,7 @@ proto_reg_handoff_ip(void) dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP4, ip_handle); dissector_add_uint("enc", BSD_AF_INET, ip_handle); dissector_add_uint("vxlan.next_proto", VXLAN_IPV4, ip_handle); + dissector_add_uint("nsh.next_proto", NSH_IPV4, ip_handle); heur_dissector_add("tipc", dissect_ip_heur, "IP over TIPC", "ip_tipc", proto_ip, HEURISTIC_ENABLE); diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c index 15e9de71e5..0ae0f711df 100644 --- a/epan/dissectors/packet-ipv6.c +++ b/epan/dissectors/packet-ipv6.c @@ -53,6 +53,7 @@ #include "packet-sflow.h" #include "packet-vxlan.h" #include "packet-mpls.h" +#include "packet-nsh.h" #ifdef HAVE_GEOIP_V6 #include <GeoIP.h> @@ -3555,6 +3556,7 @@ proto_reg_handoff_ipv6(void) dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP6, ipv6_handle); dissector_add_uint("enc", BSD_AF_INET6_BSD, ipv6_handle); dissector_add_uint("vxlan.next_proto", VXLAN_IPV6, ipv6_handle); + dissector_add_uint("nsh.next_proto", NSH_IPV6, ipv6_handle); dissector_add_for_decode_as_with_preference("udp.port", ipv6_handle); diff --git a/epan/dissectors/packet-mpls.c b/epan/dissectors/packet-mpls.c index 4ea63e589e..bfe167fa0e 100644 --- a/epan/dissectors/packet-mpls.c +++ b/epan/dissectors/packet-mpls.c @@ -68,6 +68,7 @@ #include "packet-sflow.h" #include "packet-l2tp.h" #include "packet-vxlan.h" +#include "packet-nsh.h" void proto_register_mpls(void); void proto_reg_handoff_mpls(void); @@ -687,6 +688,7 @@ proto_reg_handoff_mpls(void) dissector_add_uint("l2tp.pw_type", L2TPv3_PROTOCOL_MPLS, mpls_handle); dissector_add_uint_with_preference("udp.port", UDP_PORT_MPLS_OVER_UDP, mpls_handle); dissector_add_uint("vxlan.next_proto", VXLAN_MPLS, mpls_handle); + dissector_add_uint("nsh.next_proto", NSH_MPLS, mpls_handle); dissector_add_uint( "mpls.label", MPLS_LABEL_INVALID, mpls_pwcw_handle ); diff --git a/epan/dissectors/packet-nsh.c b/epan/dissectors/packet-nsh.c index 6be15fc7c1..801915876e 100644 --- a/epan/dissectors/packet-nsh.c +++ b/epan/dissectors/packet-nsh.c @@ -1,39 +1,35 @@ -/*Routines for Network Service Header - *draft-ietf-sfc-nsh-01 - *Author: Chidambaram Arunachalam <carunach@cisco.com> - *Copyright 2016, ciscoSystems Inc. +/* packet-nsh.c + * Routines for Network Service Header + * draft-ietf-sfc-nsh-01 + * Author: Chidambaram Arunachalam <carunach@cisco.com> + * Copyright 2016, ciscoSystems Inc. * + * (c) Copyright 2016, Sumit Kumar Jha <sjha3@ncsu.edu> + * Support for VXLAN GPE encapsulation * - *Wireshark - Network traffic analyzer - *By Gerald Combs <gerald@wireshark.org> - *Copyright 1998 Gerald Combs + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs * - *(c) Copyright 2016, Sumit Kumar Jha <sjha3@ncsu.edu> - *Support for VXLAN GPE encapsulation + * 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 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. * - *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. + * 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> +#include "packet-nsh.h" #include "packet-vxlan.h" #define MD_TYPE_1 1 @@ -43,18 +39,6 @@ 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_NSH, - NSH_MPLS, - NSH_EXPERIMENT_1 = 254, - NSH_EXPERIMENT_2, -}; - static const value_string nsh_next_protocols[] = { { NSH_IPV4, "IPv4" }, { NSH_IPV6, "IPv6" }, @@ -86,11 +70,7 @@ static int hf_nsh_metadata = -1; static gint ett_nsh = -1; -static dissector_handle_t nsh_handle; -static dissector_handle_t dissector_ipv6; -static dissector_handle_t dissector_ip; -static dissector_handle_t dissector_eth; -static dissector_handle_t dissector_mpls; +static dissector_table_t subdissector_table; /* *Dissect Fixed Length Context headers @@ -219,28 +199,8 @@ dissect_nsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) 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; - - case NSH_NSH: - call_dissector(nsh_handle, next_tvb, pinfo, tree); - break; - - case NSH_MPLS: - call_dissector(dissector_mpls, next_tvb, pinfo, tree); - break; - + if (!dissector_try_uint(subdissector_table, nsh_next_proto, tvb, pinfo, tree)) { + call_data_dissector(next_tvb, pinfo, tree); } } } @@ -370,22 +330,20 @@ proto_register_nsh(void) proto_register_field_array(proto_nsh, nsh_info, array_length(nsh_info)); proto_register_subtree_array(ett, array_length(ett)); + subdissector_table = register_dissector_table("nsh.next_proto", "NSH Next Protocol", proto_nsh, FT_UINT32, BASE_DEC); + } void proto_reg_handoff_nsh(void) { + static dissector_handle_t nsh_handle; nsh_handle = create_dissector_handle(dissect_nsh, proto_nsh); dissector_add_uint("ethertype", ETHERTYPE_NSH, nsh_handle); dissector_add_uint("gre.proto", ETHERTYPE_NSH, nsh_handle); dissector_add_uint("vxlan.next_proto", VXLAN_NSH, nsh_handle); - - dissector_ip = find_dissector_add_dependency("ip", proto_nsh); - dissector_ipv6 = find_dissector_add_dependency("ipv6", proto_nsh); - dissector_eth = find_dissector_add_dependency("eth_maybefcs", proto_nsh); - dissector_mpls = find_dissector_add_dependency("mpls", proto_nsh); - + dissector_add_uint("nsh.next_proto", NSH_NSH, nsh_handle); } diff --git a/epan/dissectors/packet-nsh.h b/epan/dissectors/packet-nsh.h new file mode 100644 index 0000000000..5e44dfaff9 --- /dev/null +++ b/epan/dissectors/packet-nsh.h @@ -0,0 +1,38 @@ +/* packet-nsh.h + * + * Routines for Network Service Header + * draft-ietf-sfc-nsh-01 + * + * 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. + */ + +#ifndef __PACKET_NSH_H__ +#define __PACKET_NSH_H__ + +/*Network Service Header (NSH) Next Protocol field values */ + +#define NSH_IPV4 1 +#define NSH_IPV6 2 +#define NSH_ETHERNET 3 +#define NSH_NSH 4 +#define NSH_MPLS 5 +#define NSH_EXPERIMENT_1 254 +#define NSH_EXPERIMENT_2 255 + +#endif /* __PACKET_NSH_H__ */ |