Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ripng.c
blob3b15cf86b02edf2c0c2159039e5c5765cca2761c
1 /* packet-ripng.c
2 * Routines for RIPng disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
4 * derived from packet-rip.c
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Enhance RIPng by Alexis La Goutte
12 * SPDX-License-Identifier: GPL-2.0-or-later
14 * References:
15 * RFC2080: RIPng for IPv6
18 #include "config.h"
20 #include <epan/packet.h>
21 #include <epan/to_str.h>
23 void proto_register_ripng(void);
24 void proto_reg_handoff_ripng(void);
26 static dissector_handle_t ripng_handle;
28 static int proto_ripng;
29 static int hf_ripng_cmd;
30 static int hf_ripng_version;
31 static int hf_ripng_reserved;
33 static int hf_ripng_rte;
34 static int hf_ripng_rte_ipv6_prefix;
35 static int hf_ripng_rte_route_tag;
36 static int hf_ripng_rte_prefix_length;
37 static int hf_ripng_rte_metric;
39 static int ett_ripng;
40 static int ett_ripng_rte;
42 #define UDP_PORT_RIPNG 521
44 #define RIP6_REQUEST 1
45 #define RIP6_RESPONSE 2
47 static const value_string cmdvals[] = {
48 { RIP6_REQUEST, "Request" },
49 { RIP6_RESPONSE, "Response" },
50 { 0, NULL },
53 static int
54 dissect_ripng(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
55 int offset = 0;
56 proto_tree *ripng_tree = NULL, *rte_tree = NULL;
57 proto_item *ti, *rte_ti;
59 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIPng");
60 col_add_fstr(pinfo->cinfo, COL_INFO," Command %s, Version %u",
61 val_to_str(tvb_get_uint8(tvb, offset), cmdvals, "Unknown (%u)"),
62 tvb_get_uint8(tvb, offset +1));
64 if (tree) {
65 ti = proto_tree_add_item(tree, proto_ripng, tvb, offset, -1, ENC_NA);
66 ripng_tree = proto_item_add_subtree(ti, ett_ripng);
68 /* Command */
69 proto_tree_add_item(ripng_tree, hf_ripng_cmd, tvb, offset, 1, ENC_BIG_ENDIAN);
70 offset += 1;
72 /* Version */
73 proto_tree_add_item(ripng_tree, hf_ripng_version, tvb, offset, 1, ENC_BIG_ENDIAN);
74 offset += 1;
76 /* Reserved */
77 proto_tree_add_item(ripng_tree, hf_ripng_reserved, tvb, offset, 2, ENC_NA);
78 offset += 2;
80 /* Route Table Entry */
81 while (tvb_reported_length_remaining(tvb, offset) > 0) {
83 rte_ti = proto_tree_add_item(ripng_tree, hf_ripng_rte, tvb, offset, 16 + 2 + 1 + 1, ENC_NA);
84 rte_tree = proto_item_add_subtree(rte_ti, ett_ripng_rte);
86 /* IPv6 Prefix */
87 proto_tree_add_item(rte_tree, hf_ripng_rte_ipv6_prefix, tvb, offset, 16, ENC_NA);
88 proto_item_append_text(rte_ti, ": IPv6 Prefix: %s", tvb_ip6_to_str(pinfo->pool, tvb, offset));
89 offset += 16;
91 /* Route Tag */
92 proto_tree_add_item(rte_tree, hf_ripng_rte_route_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
93 offset += 2;
95 /* Prefix Length */
96 proto_tree_add_item(rte_tree, hf_ripng_rte_prefix_length, tvb, offset, 1, ENC_BIG_ENDIAN);
97 proto_item_append_text(rte_ti, "/%u", tvb_get_uint8(tvb, offset));
98 offset += 1;
100 /* Metric */
101 proto_tree_add_item(rte_tree, hf_ripng_rte_metric, tvb, offset, 1, ENC_BIG_ENDIAN);
102 proto_item_append_text(rte_ti, " Metric: %u", tvb_get_uint8(tvb, offset));
103 offset += 1;
106 return tvb_captured_length(tvb);
109 void
110 proto_register_ripng(void)
112 static hf_register_info hf[] = {
113 { &hf_ripng_cmd,
114 { "Command", "ripng.cmd",
115 FT_UINT8, BASE_DEC, VALS(cmdvals), 0x0,
116 "Used to specify the purpose of this message", HFILL }},
117 { &hf_ripng_version,
118 { "Version", "ripng.version",
119 FT_UINT8, BASE_DEC, NULL, 0x0,
120 "Version of RIPng", HFILL }},
121 { &hf_ripng_reserved,
122 { "Reserved", "ripng.reserved",
123 FT_BYTES, BASE_NONE, NULL, 0x0,
124 "Must be Zero", HFILL }},
125 { &hf_ripng_rte,
126 { "Route Table Entry", "ripng.rte",
127 FT_NONE, BASE_NONE, NULL, 0x0,
128 NULL, HFILL }},
129 { &hf_ripng_rte_ipv6_prefix,
130 { "IPv6 Prefix", "ripng.rte.ipv6_prefix",
131 FT_IPv6, BASE_NONE, NULL, 0x0,
132 "Destination", HFILL }},
133 { &hf_ripng_rte_route_tag,
134 { "Route Tag", "ripng.rte.route_tag",
135 FT_UINT16, BASE_HEX, NULL, 0x0,
136 "Provides a method of separating internal RIPng routes (routes for networks within the RIPng routing domain) from external RIPng routes, which may have been imported from an EGP or another IGP", HFILL }},
138 { &hf_ripng_rte_prefix_length,
139 { "Prefix Length", "ripng.rte.prefix_length",
140 FT_UINT8, BASE_DEC, NULL, 0x0,
141 "The length in bits of the significant part of the prefix starting from the left of the prefix", HFILL }},
143 { &hf_ripng_rte_metric,
144 { "Metric", "ripng.rte.metric",
145 FT_UINT8, BASE_DEC, NULL, 0x0,
146 "The current metric for the destination; the value 16 (infinity) indicates that the destination is not reachable", HFILL }},
149 static int *ett[] = {
150 &ett_ripng,
151 &ett_ripng_rte,
154 proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng");
155 proto_register_field_array(proto_ripng, hf, array_length(hf));
156 proto_register_subtree_array(ett, array_length(ett));
158 ripng_handle = register_dissector("ripng", dissect_ripng, proto_ripng);
161 void
162 proto_reg_handoff_ripng(void)
164 dissector_add_uint_with_preference("udp.port", UDP_PORT_RIPNG, ripng_handle);
168 * Editor modelines - https://www.wireshark.org/tools/modelines.html
170 * Local variables:
171 * c-basic-offset: 4
172 * tab-width: 8
173 * indent-tabs-mode: nil
174 * End:
176 * vi: set shiftwidth=4 tabstop=8 expandtab:
177 * :indentSize=4:tabSize=8:noTabs=true: