/src/wireshark/epan/dissectors/packet-ripng.c
Line | Count | Source |
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 |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * Enhance RIPng by Alexis La Goutte |
11 | | * |
12 | | * SPDX-License-Identifier: GPL-2.0-or-later |
13 | | * |
14 | | * References: |
15 | | * RFC2080: RIPng for IPv6 |
16 | | */ |
17 | | |
18 | | #include "config.h" |
19 | | |
20 | | #include <epan/packet.h> |
21 | | #include <epan/to_str.h> |
22 | | |
23 | | void proto_register_ripng(void); |
24 | | void proto_reg_handoff_ripng(void); |
25 | | |
26 | | static dissector_handle_t ripng_handle; |
27 | | |
28 | | static int proto_ripng; |
29 | | static int hf_ripng_cmd; |
30 | | static int hf_ripng_version; |
31 | | static int hf_ripng_reserved; |
32 | | |
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; |
38 | | |
39 | | static int ett_ripng; |
40 | | static int ett_ripng_rte; |
41 | | |
42 | 16 | #define UDP_PORT_RIPNG 521 |
43 | | |
44 | | #define RIP6_REQUEST 1 |
45 | | #define RIP6_RESPONSE 2 |
46 | | |
47 | | static const value_string cmdvals[] = { |
48 | | { RIP6_REQUEST, "Request" }, |
49 | | { RIP6_RESPONSE, "Response" }, |
50 | | { 0, NULL }, |
51 | | }; |
52 | | |
53 | | static int |
54 | 0 | dissect_ripng(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) { |
55 | 0 | unsigned offset = 0; |
56 | 0 | proto_tree *ripng_tree = NULL, *rte_tree = NULL; |
57 | 0 | proto_item *ti, *rte_ti; |
58 | |
|
59 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "RIPng"); |
60 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO," Command %s, Version %u", |
61 | 0 | val_to_str(pinfo->pool, tvb_get_uint8(tvb, offset), cmdvals, "Unknown (%u)"), |
62 | 0 | tvb_get_uint8(tvb, offset +1)); |
63 | |
|
64 | 0 | if (tree) { |
65 | 0 | ti = proto_tree_add_item(tree, proto_ripng, tvb, offset, -1, ENC_NA); |
66 | 0 | ripng_tree = proto_item_add_subtree(ti, ett_ripng); |
67 | | |
68 | | /* Command */ |
69 | 0 | proto_tree_add_item(ripng_tree, hf_ripng_cmd, tvb, offset, 1, ENC_BIG_ENDIAN); |
70 | 0 | offset += 1; |
71 | | |
72 | | /* Version */ |
73 | 0 | proto_tree_add_item(ripng_tree, hf_ripng_version, tvb, offset, 1, ENC_BIG_ENDIAN); |
74 | 0 | offset += 1; |
75 | | |
76 | | /* Reserved */ |
77 | 0 | proto_tree_add_item(ripng_tree, hf_ripng_reserved, tvb, offset, 2, ENC_NA); |
78 | 0 | offset += 2; |
79 | | |
80 | | /* Route Table Entry */ |
81 | 0 | while (tvb_reported_length_remaining(tvb, offset) > 0) { |
82 | |
|
83 | 0 | rte_ti = proto_tree_add_item(ripng_tree, hf_ripng_rte, tvb, offset, 16 + 2 + 1 + 1, ENC_NA); |
84 | 0 | rte_tree = proto_item_add_subtree(rte_ti, ett_ripng_rte); |
85 | | |
86 | | /* IPv6 Prefix */ |
87 | 0 | proto_tree_add_item(rte_tree, hf_ripng_rte_ipv6_prefix, tvb, offset, 16, ENC_NA); |
88 | 0 | proto_item_append_text(rte_ti, ": IPv6 Prefix: %s", tvb_ip6_to_str(pinfo->pool, tvb, offset)); |
89 | 0 | offset += 16; |
90 | | |
91 | | /* Route Tag */ |
92 | 0 | proto_tree_add_item(rte_tree, hf_ripng_rte_route_tag, tvb, offset, 2, ENC_BIG_ENDIAN); |
93 | 0 | offset += 2; |
94 | | |
95 | | /* Prefix Length */ |
96 | 0 | proto_tree_add_item(rte_tree, hf_ripng_rte_prefix_length, tvb, offset, 1, ENC_BIG_ENDIAN); |
97 | 0 | proto_item_append_text(rte_ti, "/%u", tvb_get_uint8(tvb, offset)); |
98 | 0 | offset += 1; |
99 | | |
100 | | /* Metric */ |
101 | 0 | proto_tree_add_item(rte_tree, hf_ripng_rte_metric, tvb, offset, 1, ENC_BIG_ENDIAN); |
102 | 0 | proto_item_append_text(rte_ti, " Metric: %u", tvb_get_uint8(tvb, offset)); |
103 | 0 | offset += 1; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | return tvb_captured_length(tvb); |
107 | 0 | } |
108 | | |
109 | | void |
110 | | proto_register_ripng(void) |
111 | 16 | { |
112 | 16 | static hf_register_info hf[] = { |
113 | 16 | { &hf_ripng_cmd, |
114 | 16 | { "Command", "ripng.cmd", |
115 | 16 | FT_UINT8, BASE_DEC, VALS(cmdvals), 0x0, |
116 | 16 | "Used to specify the purpose of this message", HFILL }}, |
117 | 16 | { &hf_ripng_version, |
118 | 16 | { "Version", "ripng.version", |
119 | 16 | FT_UINT8, BASE_DEC, NULL, 0x0, |
120 | 16 | "Version of RIPng", HFILL }}, |
121 | 16 | { &hf_ripng_reserved, |
122 | 16 | { "Reserved", "ripng.reserved", |
123 | 16 | FT_BYTES, BASE_NONE, NULL, 0x0, |
124 | 16 | "Must be Zero", HFILL }}, |
125 | 16 | { &hf_ripng_rte, |
126 | 16 | { "Route Table Entry", "ripng.rte", |
127 | 16 | FT_NONE, BASE_NONE, NULL, 0x0, |
128 | 16 | NULL, HFILL }}, |
129 | 16 | { &hf_ripng_rte_ipv6_prefix, |
130 | 16 | { "IPv6 Prefix", "ripng.rte.ipv6_prefix", |
131 | 16 | FT_IPv6, BASE_NONE, NULL, 0x0, |
132 | 16 | "Destination", HFILL }}, |
133 | 16 | { &hf_ripng_rte_route_tag, |
134 | 16 | { "Route Tag", "ripng.rte.route_tag", |
135 | 16 | FT_UINT16, BASE_HEX, NULL, 0x0, |
136 | 16 | "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 }}, |
137 | | |
138 | 16 | { &hf_ripng_rte_prefix_length, |
139 | 16 | { "Prefix Length", "ripng.rte.prefix_length", |
140 | 16 | FT_UINT8, BASE_DEC, NULL, 0x0, |
141 | 16 | "The length in bits of the significant part of the prefix starting from the left of the prefix", HFILL }}, |
142 | | |
143 | 16 | { &hf_ripng_rte_metric, |
144 | 16 | { "Metric", "ripng.rte.metric", |
145 | 16 | FT_UINT8, BASE_DEC, NULL, 0x0, |
146 | 16 | "The current metric for the destination; the value 16 (infinity) indicates that the destination is not reachable", HFILL }}, |
147 | 16 | }; |
148 | | |
149 | 16 | static int *ett[] = { |
150 | 16 | &ett_ripng, |
151 | 16 | &ett_ripng_rte, |
152 | 16 | }; |
153 | | |
154 | 16 | proto_ripng = proto_register_protocol("RIPng", "RIPng", "ripng"); |
155 | 16 | proto_register_field_array(proto_ripng, hf, array_length(hf)); |
156 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
157 | | |
158 | 16 | ripng_handle = register_dissector("ripng", dissect_ripng, proto_ripng); |
159 | 16 | } |
160 | | |
161 | | void |
162 | | proto_reg_handoff_ripng(void) |
163 | 16 | { |
164 | 16 | dissector_add_uint_with_preference("udp.port", UDP_PORT_RIPNG, ripng_handle); |
165 | 16 | } |
166 | | |
167 | | /* |
168 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
169 | | * |
170 | | * Local variables: |
171 | | * c-basic-offset: 4 |
172 | | * tab-width: 8 |
173 | | * indent-tabs-mode: nil |
174 | | * End: |
175 | | * |
176 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
177 | | * :indentSize=4:tabSize=8:noTabs=true: |
178 | | */ |