/src/wireshark/epan/dissectors/packet-tsp.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* packet-tsp.c |
2 | | * Routines for Time Synchronization Protocol (TSP) packet dissection |
3 | | * |
4 | | * Uwe Girlich <Uwe.Girlich@philosys.de> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * Copied from packet-quake.c |
11 | | * |
12 | | * SPDX-License-Identifier: GPL-2.0-or-later |
13 | | */ |
14 | | |
15 | | #include "config.h" |
16 | | |
17 | | #include <epan/packet.h> |
18 | | |
19 | | /* |
20 | | * For a full documentation of the Time Synchronization Protocol (TSP) see: |
21 | | * http://docs.freebsd.org/44doc/smm/12.timed/paper.pdf |
22 | | */ |
23 | | void proto_register_tsp(void); |
24 | | void proto_reg_handoff_tsp(void); |
25 | | |
26 | | static dissector_handle_t tsp_handle; |
27 | | |
28 | | static int proto_tsp; |
29 | | static int hf_tsp_type; |
30 | | static int hf_tsp_vers; |
31 | | static int hf_tsp_seq; |
32 | | static int hf_tsp_hopcnt; |
33 | | static int hf_tsp_time_sec; |
34 | | static int hf_tsp_time_usec; |
35 | | static int hf_tsp_name; |
36 | | |
37 | | static int ett_tsp; |
38 | | |
39 | | /* timed port from /etc/services */ |
40 | 14 | #define UDP_PORT_TIMED 525 |
41 | | |
42 | | |
43 | | static const value_string names_tsp_type[] = { |
44 | | #define TSP_ANY 0 /* match any types */ |
45 | | { TSP_ANY, "any" }, |
46 | 0 | #define TSP_ADJTIME 1 /* send adjtime */ |
47 | | { TSP_ADJTIME, "adjtime" }, |
48 | | #define TSP_ACK 2 /* generic acknowledgement */ |
49 | | { TSP_ACK, "ack" }, |
50 | | #define TSP_MASTERREQ 3 /* ask for master's name */ |
51 | | { TSP_MASTERREQ, "masterreq" }, |
52 | | #define TSP_MASTERACK 4 /* acknowledge master request */ |
53 | | { TSP_MASTERACK, "masterack" }, |
54 | 0 | #define TSP_SETTIME 5 /* send network time */ |
55 | | { TSP_SETTIME, "settime" }, |
56 | | #define TSP_MASTERUP 6 /* inform slaves that master is up */ |
57 | | { TSP_MASTERUP, "masterup" }, |
58 | | #define TSP_SLAVEUP 7 /* slave is up but not polled */ |
59 | | { TSP_SLAVEUP, "slaveup" }, |
60 | | #define TSP_ELECTION 8 /* advance candidature for master */ |
61 | | { TSP_ELECTION, "election" }, |
62 | | #define TSP_ACCEPT 9 /* support candidature of master */ |
63 | | { TSP_ACCEPT, "accept" }, |
64 | | #define TSP_REFUSE 10 /* reject candidature of master */ |
65 | | { TSP_REFUSE, "refuse" }, |
66 | | #define TSP_CONFLICT 11 /* two or more masters present */ |
67 | | { TSP_CONFLICT, "conflict" }, |
68 | | #define TSP_RESOLVE 12 /* masters' conflict resolution */ |
69 | | { TSP_RESOLVE, "resolve" }, |
70 | | #define TSP_QUIT 13 /* reject candidature if master is up */ |
71 | | { TSP_QUIT, "quit" }, |
72 | | #define TSP_DATE 14 /* reset the time (date command) */ |
73 | | { TSP_DATE, "date" }, |
74 | | #define TSP_DATEREQ 15 /* remote request to reset the time */ |
75 | | { TSP_DATEREQ, "datereq" }, |
76 | | #define TSP_DATEACK 16 /* acknowledge time setting */ |
77 | | { TSP_DATEACK, "dateack" }, |
78 | | #define TSP_TRACEON 17 /* turn tracing on */ |
79 | | { TSP_TRACEON, "traceon" }, |
80 | | #define TSP_TRACEOFF 18 /* turn tracing off */ |
81 | | { TSP_TRACEOFF, "traceoff" }, |
82 | | #define TSP_MSITE 19 /* find out master's site */ |
83 | | { TSP_MSITE, "msite" }, |
84 | | #define TSP_MSITEREQ 20 /* remote master's site request */ |
85 | | { TSP_MSITEREQ, "msitereq" }, |
86 | | #define TSP_TEST 21 /* for testing election algo */ |
87 | | { TSP_TEST, "test" }, |
88 | 0 | #define TSP_SETDATE 22 /* New from date command */ |
89 | | { TSP_SETDATE, "setdate" }, |
90 | 0 | #define TSP_SETDATEREQ 23 /* New remote for above */ |
91 | | { TSP_SETDATEREQ, "setdatereq" }, |
92 | 0 | #define TSP_LOOP 24 /* loop detection packet */ |
93 | | { TSP_LOOP, "loop" }, |
94 | | { 0, NULL } |
95 | | }; |
96 | | |
97 | | |
98 | | static int |
99 | | dissect_tsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
100 | 1 | { |
101 | 1 | proto_tree *tsp_tree; |
102 | 1 | proto_item *tsp_item; |
103 | | |
104 | 1 | uint8_t tsp_type; |
105 | | |
106 | 1 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "TSP"); |
107 | 1 | col_clear(pinfo->cinfo, COL_INFO); |
108 | | |
109 | 1 | tsp_type = tvb_get_uint8(tvb, 0); |
110 | 1 | col_add_str(pinfo->cinfo, COL_INFO, |
111 | 1 | val_to_str(tsp_type, names_tsp_type, "Unknown message type (%u)")); |
112 | | |
113 | 1 | tsp_item = proto_tree_add_item(tree, proto_tsp, |
114 | 1 | tvb, 0, -1, ENC_NA); |
115 | 1 | tsp_tree = proto_item_add_subtree(tsp_item, ett_tsp); |
116 | | |
117 | 1 | if (tsp_tree) { |
118 | 1 | proto_tree_add_uint(tsp_tree, hf_tsp_type, |
119 | 1 | tvb, 0, 1, tsp_type); |
120 | 1 | proto_tree_add_item(tsp_tree, hf_tsp_vers, |
121 | 1 | tvb, 1, 1, ENC_BIG_ENDIAN); |
122 | 1 | proto_tree_add_item(tsp_tree, hf_tsp_seq, |
123 | 1 | tvb, 2, 2, ENC_BIG_ENDIAN); |
124 | 1 | } |
125 | | |
126 | 1 | switch (tsp_type) { |
127 | | |
128 | 0 | case TSP_LOOP: |
129 | 0 | if (tsp_tree) |
130 | 0 | proto_tree_add_item(tsp_tree, hf_tsp_hopcnt, |
131 | 0 | tvb, 4, 1, ENC_BIG_ENDIAN); |
132 | 0 | break; |
133 | | |
134 | 0 | case TSP_SETTIME: |
135 | 0 | case TSP_ADJTIME: |
136 | 0 | case TSP_SETDATE: |
137 | 0 | case TSP_SETDATEREQ: |
138 | 0 | if (tsp_tree) { |
139 | 0 | proto_tree_add_item(tsp_tree, hf_tsp_time_sec, |
140 | 0 | tvb, 4, 4, ENC_BIG_ENDIAN); |
141 | 0 | proto_tree_add_item(tsp_tree, hf_tsp_time_usec, |
142 | 0 | tvb, 8, 4, ENC_BIG_ENDIAN); |
143 | 0 | } |
144 | 0 | break; |
145 | 1 | } |
146 | | |
147 | 1 | if (tsp_tree) { |
148 | 1 | proto_tree_add_item(tsp_tree, hf_tsp_name, tvb, 12, |
149 | 1 | -1, ENC_ASCII); |
150 | 1 | } |
151 | 1 | return tvb_captured_length(tvb); |
152 | 1 | } |
153 | | |
154 | | |
155 | | void |
156 | | proto_reg_handoff_tsp(void) |
157 | 14 | { |
158 | 14 | dissector_add_uint_with_preference("udp.port", UDP_PORT_TIMED, tsp_handle); |
159 | 14 | } |
160 | | |
161 | | |
162 | | void |
163 | | proto_register_tsp(void) |
164 | 14 | { |
165 | 14 | static hf_register_info hf[] = { |
166 | 14 | { &hf_tsp_type, |
167 | 14 | { "Type", "tsp.type", |
168 | 14 | FT_UINT8, BASE_DEC, VALS(names_tsp_type), 0x0, |
169 | 14 | "Packet Type", HFILL }}, |
170 | 14 | { &hf_tsp_vers, |
171 | 14 | { "Version", "tsp.version", |
172 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
173 | 14 | "Protocol Version Number", HFILL }}, |
174 | 14 | { &hf_tsp_seq, |
175 | 14 | { "Sequence", "tsp.sequence", |
176 | 14 | FT_UINT16, BASE_DEC, NULL, 0x0, |
177 | 14 | "Sequence Number", HFILL }}, |
178 | 14 | { &hf_tsp_hopcnt, |
179 | 14 | { "Hop Count", "tsp.hopcnt", |
180 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
181 | 14 | NULL, HFILL }}, |
182 | 14 | { &hf_tsp_time_sec, |
183 | 14 | { "Seconds", "tsp.sec", |
184 | 14 | FT_UINT32, BASE_DEC, NULL, 0x0, |
185 | 14 | NULL, HFILL }}, |
186 | 14 | { &hf_tsp_time_usec, |
187 | 14 | { "Microseconds", "tsp.usec", |
188 | 14 | FT_UINT32, BASE_DEC, NULL, 0x0, |
189 | 14 | NULL, HFILL }}, |
190 | 14 | { &hf_tsp_name, |
191 | 14 | { "Machine Name", "tsp.name", |
192 | 14 | FT_STRINGZ, BASE_NONE, NULL, 0x0, |
193 | 14 | "Sender Machine Name", HFILL }} |
194 | 14 | }; |
195 | 14 | static int *ett[] = { |
196 | 14 | &ett_tsp |
197 | 14 | }; |
198 | | |
199 | 14 | proto_tsp = proto_register_protocol("Time Synchronization Protocol", |
200 | 14 | "TSP", "tsp"); |
201 | 14 | proto_register_field_array(proto_tsp, hf, array_length(hf)); |
202 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
203 | 14 | tsp_handle = register_dissector("tsp", dissect_tsp, proto_tsp); |
204 | 14 | } |
205 | | |
206 | | /* |
207 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
208 | | * |
209 | | * Local variables: |
210 | | * c-basic-offset: 8 |
211 | | * tab-width: 8 |
212 | | * indent-tabs-mode: t |
213 | | * End: |
214 | | * |
215 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
216 | | * :indentSize=8:tabSize=8:noTabs=false: |
217 | | */ |