epan/dissectors/pidl/ C99 drsuapi
[wireshark-sm.git] / epan / dissectors / packet-lisp-tcp.c
blobdea8e00cda963567ca12c6eb64f2bdcb9d00eaf9
1 /* packet-lisp-tcp.c
2 * Routines for Locator/ID Separation Protocol (LISP) TCP Control Message dissection
3 * Copyright 2014, 2018 Lorand Jakab <ljakab@ac.upc.edu>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
13 #include "packet-tcp.h"
14 #include "packet-lisp.h"
16 #include <epan/to_str.h>
17 #include <epan/afn.h>
18 #include <epan/expert.h>
19 #include <epan/tfs.h>
20 #include <wsutil/array.h>
22 void proto_register_lisp_tcp(void);
23 void proto_reg_handoff_lisp_tcp(void);
26 * See draft-kouvelas-lisp-map-server-reliable-transport-04 "LISP Map
27 * Server Reliable Transport", and draft-kouvelas-lisp-rloc-membership-01
28 * "LISP RLOC Membership Distribution" for packet format and protocol
29 * information.
32 #define LISP_MSG_HEADER_LEN 4
33 #define LISP_MSG_END_MARKER 0x9FACADE9
35 /* LISP Map Server Reliable Transport message types */
36 #define TRANSPORT_BASE 16
37 /* LISP RLOC Membership Distribution message types */
38 #define MEMBERSHIP_BASE 22
40 /* Registration refresh message flags */
41 #define REFRESH_FLAG_R 0x8000
43 static bool lisp_tcp_desegment = true;
45 /* Initialize the protocol and registered fields */
46 static int proto_lisp_tcp;
47 static int hf_lisp_tcp_message_type;
48 static int hf_lisp_tcp_message_length;
49 static int hf_lisp_tcp_message_id;
50 static int hf_lisp_tcp_message_data;
51 static int hf_lisp_tcp_message_eid_afi;
52 static int hf_lisp_tcp_message_iid;
53 static int hf_lisp_tcp_message_sid;
54 static int hf_lisp_tcp_message_err;
55 static int hf_lisp_tcp_message_err_code;
56 static int hf_lisp_tcp_message_err_reserved;
57 static int hf_lisp_tcp_message_err_offending_msg_type;
58 static int hf_lisp_tcp_message_err_offending_msg_len;
59 static int hf_lisp_tcp_message_err_offending_msg_id;
60 static int hf_lisp_tcp_message_err_offending_msg_data;
61 static int hf_lisp_tcp_message_registration_reject_reason;
62 static int hf_lisp_tcp_message_registration_reject_res;
63 static int hf_lisp_tcp_message_registration_refresh_scope;
64 static int hf_lisp_tcp_message_registration_refresh_flags_rejected;
65 static int hf_lisp_tcp_message_registration_refresh_res;
66 static int hf_lisp_tcp_message_xtr_id;
67 static int hf_lisp_tcp_message_site_id;
68 static int hf_lisp_tcp_message_eid_prefix_length;
69 static int hf_lisp_tcp_message_eid_prefix_afi;
70 static int hf_lisp_tcp_message_eid_ipv4;
71 static int hf_lisp_tcp_message_eid_ipv6;
72 static int hf_lisp_tcp_message_eid_mac;
73 static int hf_lisp_tcp_message_eid_dn;
74 static int hf_lisp_tcp_message_rloc_afi;
75 static int hf_lisp_tcp_message_rloc_ipv4;
76 static int hf_lisp_tcp_message_rloc_ipv6;
77 static int hf_lisp_tcp_message_rid;
78 static int hf_lisp_tcp_message_end_marker;
80 /* Initialize the subtree pointers */
81 static int ett_lisp_tcp;
82 static int ett_lisp_tcp_lcaf;
83 static int ett_lisp_tcp_eid_prefix;
84 static int ett_lisp_tcp_map_register;
86 /* Initialize expert fields */
87 static expert_field ei_lisp_tcp_undecoded;
88 static expert_field ei_lisp_tcp_invalid_length;
89 static expert_field ei_lisp_tcp_invalid_marker;
90 static expert_field ei_lisp_tcp_unexpected_afi;
92 static dissector_handle_t lisp_tcp_handle;
94 static const value_string lisp_tcp_typevals[] = {
95 { TRANSPORT_BASE, "Error Notification" },
96 { TRANSPORT_BASE + 1, "Registration" },
97 { TRANSPORT_BASE + 2, "Registration ACK" },
98 { TRANSPORT_BASE + 3, "Registration NACK" },
99 { TRANSPORT_BASE + 4, "Registration Refresh" },
100 { TRANSPORT_BASE + 5, "Mapping Notification" },
101 { MEMBERSHIP_BASE, "RLOC Membership Subscribe" },
102 { MEMBERSHIP_BASE + 1, "RLOC Membership Subscribe ACK" },
103 { MEMBERSHIP_BASE + 2, "RLOC Membership Subscribe NACK" },
104 { MEMBERSHIP_BASE + 3, "RLOC Membership Unsubscribe" },
105 { MEMBERSHIP_BASE + 4, "RLOC Membership Element Add" },
106 { MEMBERSHIP_BASE + 5, "RLOC Membership Element Remove" },
107 { MEMBERSHIP_BASE + 6, "RLOC Membership Refresh Request" },
108 { MEMBERSHIP_BASE + 7, "RLOC Membership Refresh Begin" },
109 { MEMBERSHIP_BASE + 8, "RLOC Membership Refresh End" },
110 { 0, NULL}
113 static const value_string lisp_tcp_membership_subscribe_errors[] = {
114 { 0, "Undefined" },
115 { 1, "Instance not found" },
116 { 2, "Distribution not enabled" },
117 { 3, "Not Authorized" },
118 { 0, NULL}
121 static const value_string lisp_tcp_registration_reject_reason[] = {
122 { 1, "Not a valid site EID prefix" },
123 { 2, "Authentication failure" },
124 { 3, "Locator set not allowed" },
125 { 4, "Reason not defined" },
126 { 0, NULL}
129 static const value_string lisp_tcp_registration_refresh_scope[] = {
130 { 0, "All prefixes under all address families under all EID instances" },
131 { 1, "All prefixes under all address families under a single EID instance" },
132 { 2, "All prefixes under a single address family under a single EID instance" },
133 { 3, "All prefixes covered by a specific EID prefix in a single EID instance" },
134 { 4, "A specific EID prefix in a single EID instance" },
135 { 0, NULL}
139 * Dissector for EID prefixes
142 static unsigned
143 dissect_lisp_tcp_message_eid_prefix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *message_tree,
144 unsigned offset, proto_item *tim)
146 proto_tree *prefix_tree, *lcaf_tree;
147 int str_len;
148 uint8_t prefix_length;
149 uint16_t prefix_afi, addr_len = 0;
150 const char *prefix;
152 prefix_length = tvb_get_uint8(tvb, offset);
153 prefix_afi = tvb_get_ntohs(tvb, offset + 1);
155 prefix = get_addr_str(tvb, pinfo, offset + 3, prefix_afi, &addr_len);
157 if (prefix == NULL) {
158 expert_add_info_format(pinfo, message_tree, &ei_lisp_tcp_unexpected_afi,
159 "Unexpected EID prefix AFI (%d), cannot decode", prefix_afi);
160 return offset + addr_len;
163 proto_item_append_text(tim, " for %s/%d", prefix, prefix_length);
164 prefix_tree = proto_tree_add_subtree_format(message_tree, tvb, offset, 3 + addr_len, ett_lisp_tcp_eid_prefix,
165 NULL, "EID Prefix: %s/%d", prefix, prefix_length);
167 /* Prefix-Length (1 byte) */
168 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_prefix_length, tvb, offset, 1, ENC_BIG_ENDIAN);
169 offset += 1;
171 /* EID-Prefix-AFI (2 bytes) */
172 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_prefix_afi, tvb, offset, 2, ENC_BIG_ENDIAN);
173 offset += 2;
175 /* EID-Prefix */
176 switch(prefix_afi) {
177 case AFNUM_INET:
178 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_ipv4, tvb, offset, INET_ADDRLEN, ENC_BIG_ENDIAN);
179 offset += INET_ADDRLEN;
180 break;
181 case AFNUM_INET6:
182 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_ipv6, tvb, offset, INET6_ADDRLEN, ENC_NA);
183 offset += INET6_ADDRLEN;
184 break;
185 case AFNUM_LCAF:
186 lcaf_tree = proto_tree_add_subtree_format(prefix_tree, tvb, offset, addr_len, ett_lisp_tcp_lcaf, NULL, "Address: %s", prefix);
187 dissect_lcaf(tvb, pinfo, lcaf_tree, offset, NULL);
188 offset += addr_len;
189 break;
190 case AFNUM_802:
191 case AFNUM_EUI48:
192 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_mac, tvb, offset, EUI48_ADDRLEN, ENC_NA);
193 offset += EUI48_ADDRLEN;
194 break;
195 case AFNUM_DISTNAME:
196 str_len = tvb_strsize(tvb, offset);
197 proto_tree_add_item(prefix_tree, hf_lisp_tcp_message_eid_dn, tvb, offset, str_len, ENC_ASCII);
198 offset += str_len;
199 break;
201 return offset;
206 * Dissector for Reliable Transport messages
209 static unsigned
210 dissect_lisp_tcp_reliable_transport_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *message_tree,
211 unsigned offset, uint16_t type, uint16_t data_len, proto_item *tim)
213 unsigned initial_offset = offset;
214 proto_tree *map_register_tree;
215 uint8_t reject_reason, scope, err;
216 uint16_t refresh_flags, offending_msg_type;
218 switch (type) {
220 /* Error Notification */
221 case TRANSPORT_BASE:
222 /* Error code (1 byte) */
223 err = tvb_get_uint8(tvb, offset);
224 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_code, tvb, offset, 1, ENC_BIG_ENDIAN);
225 offset += 1;
226 data_len -= 1;
227 proto_item_append_text(tim, ", Code: %d", err);
229 /* Reserved (3 bytes) */
230 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_reserved, tvb, offset, 3, ENC_BIG_ENDIAN);
231 offset += 3;
232 data_len -= 3;
234 /* Offending message type (2 bytes) */
235 offending_msg_type = tvb_get_ntohs(tvb, offset);
236 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_offending_msg_type, tvb, offset, 2, ENC_BIG_ENDIAN);
237 offset += 2;
238 data_len -= 2;
239 proto_item_append_text(tim, ", Offending message type: %s",
240 val_to_str(offending_msg_type, lisp_tcp_typevals, "Unknown type (%u)"));
242 /* Offending message length (2 bytes) */
243 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_offending_msg_len, tvb, offset, 2, ENC_BIG_ENDIAN);
244 offset += 2;
245 data_len -= 2;
247 /* Offending message ID (4 bytes) */
248 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_offending_msg_id, tvb, offset, 4, ENC_BIG_ENDIAN);
249 offset += 4;
250 data_len -= 4;
252 /* Offending message data */
253 if (data_len) {
254 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err_offending_msg_data, tvb, offset, data_len, ENC_NA);
255 offset += data_len;
257 return offset;
259 /* Registration */
260 case TRANSPORT_BASE + 1:
261 /* Map-Register */
262 map_register_tree = proto_tree_add_subtree(message_tree, tvb, offset, data_len,
263 ett_lisp_tcp_map_register, NULL, "Map-Register");
264 offset = dissect_lisp_map_register(tvb, pinfo, map_register_tree, offset, tim, false);
265 data_len -= offset - initial_offset;
266 break;
268 /* Registration ACK */
269 case TRANSPORT_BASE + 2:
270 /* EID */
271 offset = dissect_lisp_tcp_message_eid_prefix(tvb, pinfo, message_tree, offset, tim);
272 data_len -= offset - initial_offset;
273 break;
275 /* Registration Reject */
276 case TRANSPORT_BASE + 3:
277 /* Reason (1 byte) */
278 reject_reason = tvb_get_uint8(tvb, offset);
279 proto_tree_add_item(message_tree, hf_lisp_tcp_message_registration_reject_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
280 offset += 1;
281 proto_item_append_text(tim, ", Reason: %s",
282 val_to_str(reject_reason, lisp_tcp_registration_reject_reason, "Unknown reason code (%u)"));
284 /* Reserved (2 bytes) */
285 proto_tree_add_item(message_tree, hf_lisp_tcp_message_registration_reject_res, tvb, offset, 2, ENC_BIG_ENDIAN);
286 offset += 2;
288 /* EID */
289 offset = dissect_lisp_tcp_message_eid_prefix(tvb, pinfo, message_tree, offset, tim);
290 data_len -= offset - initial_offset;
291 break;
293 /* Registration Refresh */
294 case TRANSPORT_BASE + 4:
295 /* Reason (1 byte) */
296 scope = tvb_get_uint8(tvb, offset);
297 proto_tree_add_item(message_tree, hf_lisp_tcp_message_registration_refresh_scope, tvb, offset, 1, ENC_BIG_ENDIAN);
298 offset += 1;
299 proto_item_append_text(tim, ", Scope: %s",
300 val_to_str(scope, lisp_tcp_registration_refresh_scope, "Unknown scope code (%u)"));
301 col_append_fstr(pinfo->cinfo, COL_INFO, ", Scope: %d", scope);
303 /* Rejected only flag (1 bit) */
304 refresh_flags = tvb_get_ntohs(tvb, offset);
305 proto_tree_add_item(message_tree, hf_lisp_tcp_message_registration_refresh_flags_rejected, tvb, offset, 2, ENC_BIG_ENDIAN);
306 if (refresh_flags & REFRESH_FLAG_R) {
307 proto_item_append_text(tim, " (rejected only)");
308 col_append_str(pinfo->cinfo, COL_INFO, " (rejected only)");
311 /* Reserved (15 bits) */
312 proto_tree_add_item(message_tree, hf_lisp_tcp_message_registration_refresh_res, tvb, offset, 2, ENC_BIG_ENDIAN);
313 offset += 2;
315 if (scope == 0) {
316 data_len -= 3;
317 break;
320 /* EID */
321 offset = dissect_lisp_tcp_message_eid_prefix(tvb, pinfo, message_tree, offset, tim);
322 data_len -= offset - initial_offset;
323 break;
325 /* Mapping Notification */
326 case TRANSPORT_BASE + 5:
327 /* xTR-ID (16 bytes) */
328 proto_tree_add_item(message_tree, hf_lisp_tcp_message_xtr_id, tvb, offset, LISP_XTRID_LEN, ENC_NA);
329 offset += LISP_XTRID_LEN;
331 /* Site-ID (8 bytes) */
332 proto_tree_add_item(message_tree, hf_lisp_tcp_message_site_id, tvb, offset, LISP_SITEID_LEN, ENC_NA);
333 offset += LISP_SITEID_LEN;
335 /* Mapping Record */
336 offset = dissect_lisp_mapping(tvb, pinfo, message_tree, 0, 1, false, offset, tim);
337 data_len -= offset - initial_offset;
338 break;
341 if (data_len) {
342 proto_tree_add_item(message_tree, hf_lisp_tcp_message_data, tvb, offset, data_len, ENC_NA);
343 offset += data_len;
344 expert_add_info_format(pinfo, message_tree, &ei_lisp_tcp_undecoded, "Work-in-progress");
347 return offset;
352 * Dissector for Membership messages
355 static unsigned
356 dissect_lisp_tcp_membership_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *message_tree,
357 unsigned offset, uint16_t type, uint16_t data_len, proto_item *tim)
359 uint32_t iid, sid, rid;
360 uint8_t err;
361 uint64_t siteid;
362 uint16_t afi;
364 /* EID AFI (2 bytes) */
365 proto_tree_add_item(message_tree, hf_lisp_tcp_message_eid_afi, tvb, offset, 2, ENC_BIG_ENDIAN);
366 offset += 2;
367 data_len -= 2;
369 /* Instance ID (4 bytes) */
370 iid = tvb_get_ntohl(tvb, offset);
371 proto_tree_add_item(message_tree, hf_lisp_tcp_message_iid, tvb, offset, 4, ENC_BIG_ENDIAN);
372 offset += 4;
373 data_len -= 4;
374 proto_item_append_text(tim, ", IID: %u", iid);
376 switch (type) {
377 case MEMBERSHIP_BASE + 1:
378 case MEMBERSHIP_BASE + 2:
379 /* Subscribe ID (4 bytes) */
380 sid = tvb_get_ntohl(tvb, offset);
381 proto_tree_add_item(message_tree, hf_lisp_tcp_message_sid, tvb, offset, 4, ENC_BIG_ENDIAN);
382 offset += 4;
383 data_len -= 4;
384 col_append_fstr(pinfo->cinfo, COL_INFO, ", Sub ID: %u", sid);
385 proto_item_append_text(tim, ", Sub ID: %u", sid);
387 if (type == MEMBERSHIP_BASE + 2) {
388 /* Error code (1 byte) */
389 err = tvb_get_uint8(tvb, offset);
390 proto_tree_add_item(message_tree, hf_lisp_tcp_message_err, tvb, offset, 1, ENC_BIG_ENDIAN);
391 offset += 1;
392 data_len -= 1;
393 proto_item_append_text(tim, ", Error code: %s",
394 val_to_str(err, lisp_tcp_membership_subscribe_errors, "Unknown error code (%u)"));
397 break;
399 case MEMBERSHIP_BASE + 4:
400 case MEMBERSHIP_BASE + 5:
401 /* Site ID (8 bytes) */
402 siteid = tvb_get_ntoh64(tvb, offset);
403 proto_tree_add_item(message_tree, hf_lisp_tcp_message_site_id, tvb, offset, LISP_SITEID_LEN, ENC_NA);
404 offset += 8;
405 data_len -= 8;
406 proto_item_append_text(tim, ", Site-ID: %"PRIu64, siteid);
408 /* RLOC AFI (2 bytes) */
409 afi = tvb_get_ntohs(tvb, offset);
410 proto_tree_add_item(message_tree, hf_lisp_tcp_message_rloc_afi, tvb, offset, 2, ENC_BIG_ENDIAN);
411 offset += 2;
412 data_len -= 2;
414 switch (afi) {
415 case AFNUM_INET:
416 proto_tree_add_item(message_tree, hf_lisp_tcp_message_rloc_ipv4, tvb, offset, INET_ADDRLEN, ENC_NA);
417 proto_item_append_text(tim, ", RLOC: %s", tvb_ip_to_str(pinfo->pool, tvb, offset));
418 col_append_fstr(pinfo->cinfo, COL_INFO, " [%u] %s", iid, tvb_ip_to_str(pinfo->pool, tvb, offset));
419 offset += INET_ADDRLEN;
420 data_len -= INET_ADDRLEN;
421 break;
422 case AFNUM_INET6:
423 proto_tree_add_item(message_tree, hf_lisp_tcp_message_rloc_ipv6, tvb, offset, INET6_ADDRLEN, ENC_NA);
424 proto_item_append_text(tim, ", RLOC: %s", tvb_ip6_to_str(pinfo->pool, tvb, offset));
425 col_append_fstr(pinfo->cinfo, COL_INFO, " [%u] %s", iid, tvb_ip6_to_str(pinfo->pool, tvb, offset));
426 offset += INET6_ADDRLEN;
427 data_len -= INET6_ADDRLEN;
428 break;
431 break;
433 case MEMBERSHIP_BASE + 7:
434 case MEMBERSHIP_BASE + 8:
435 /* Request ID (4 bytes) */
436 rid = tvb_get_ntohl(tvb, offset);
437 proto_tree_add_item(message_tree, hf_lisp_tcp_message_rid, tvb, offset, 4, ENC_BIG_ENDIAN);
438 offset += 4;
439 data_len -= 4;
440 proto_item_append_text(tim, ", Req ID: %u", rid);
441 break;
444 if (data_len) {
445 proto_tree_add_item(message_tree, hf_lisp_tcp_message_data, tvb, offset, data_len, ENC_NA);
446 offset += data_len;
447 expert_add_info_format(pinfo, message_tree, &ei_lisp_tcp_undecoded, "Work-in-progress");
450 return offset;
455 * Dissector for individual messages
458 static int
459 dissect_lisp_tcp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
461 unsigned offset = 0;
462 uint16_t type, len, data_len;
463 uint32_t id, marker;
464 proto_item *tim, *til, *tiem;
465 proto_tree *message_tree;
467 tim = proto_tree_add_item(tree, proto_lisp_tcp, tvb, offset, -1, ENC_NA);
468 message_tree = proto_item_add_subtree(tim, ett_lisp_tcp);
470 /* Message type (2 bytes) */
471 type = tvb_get_ntohs(tvb, offset);
472 proto_tree_add_item(message_tree, hf_lisp_tcp_message_type, tvb, offset, 2, ENC_BIG_ENDIAN);
473 offset += 2;
475 /* Message length (2 bytes) */
476 len = tvb_get_ntohs(tvb, offset);
477 til = proto_tree_add_item(message_tree, hf_lisp_tcp_message_length, tvb, offset, 2, ENC_BIG_ENDIAN);
478 offset += 2;
480 if (len < 8) {
481 expert_add_info_format(pinfo, til, &ei_lisp_tcp_invalid_length,
482 "Invalid message length (%u < 8)", len);
483 } else if (len > 8) {
484 /* Message ID (4 bytes) */
485 id = tvb_get_ntohl(tvb, offset);
486 proto_tree_add_item(message_tree, hf_lisp_tcp_message_id, tvb, offset, 4, ENC_BIG_ENDIAN);
487 offset += 4;
488 col_append_sep_fstr(pinfo->cinfo, COL_INFO, "; ", "Msg: %u, %s", id, val_to_str(type, lisp_tcp_typevals,
489 "Unknown type (%u)"));
490 proto_item_append_text(tim, ", Msg: %u, %s", id, val_to_str(type, lisp_tcp_typevals,
491 "Unknown type (%u)"));
492 proto_item_set_len(tim, len);
494 data_len = len - 12;
495 if (type >= TRANSPORT_BASE && type <= TRANSPORT_BASE + 5) {
496 /* Map Server reliable transport message types */
497 offset = dissect_lisp_tcp_reliable_transport_message(tvb, pinfo, message_tree, offset, type, data_len, tim);
498 } else if (type >= MEMBERSHIP_BASE && type <= MEMBERSHIP_BASE + 8) {
499 /* EID instance membership message types */
500 offset = dissect_lisp_tcp_membership_message(tvb, pinfo, message_tree, offset, type, data_len, tim);
501 } else {
502 /* Message Data (variable length) */
503 proto_tree_add_item(message_tree, hf_lisp_tcp_message_data, tvb, offset, data_len, ENC_NA);
504 offset += data_len;
508 /* Message End Marker (4 bytes) */
509 marker = tvb_get_ntohl(tvb, offset);
510 tiem = proto_tree_add_item(message_tree, hf_lisp_tcp_message_end_marker, tvb, offset, 4, ENC_BIG_ENDIAN);
511 offset += 4;
513 if (marker != LISP_MSG_END_MARKER) {
514 expert_add_info_format(pinfo, tiem, &ei_lisp_tcp_invalid_marker,
515 "Invalid message end marker (0x%08x)", marker);
516 } else {
517 proto_item_append_text(tiem, " (correct)");
520 return offset;
525 * Get message length, needed by tcp_dissect_pdus()
528 static unsigned
529 get_lisp_tcp_message_len(packet_info *pinfo _U_, tvbuff_t *tvb,
530 int offset, void *data _U_)
532 uint16_t mlen;
534 /* Get length of membership message */
535 mlen = tvb_get_ntohs(tvb, offset + 2);
537 return mlen;
542 * Main dissector code
545 static int
546 dissect_lisp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
548 /* Clear Info column before fetching data in case an exception is thrown */
549 col_clear(pinfo->cinfo, COL_INFO);
551 /* Make entries in Protocol column and Info column on summary display */
552 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LISP");
554 /* Reassemble and dissect PDUs */
555 tcp_dissect_pdus(tvb, pinfo, tree, lisp_tcp_desegment, LISP_MSG_HEADER_LEN,
556 get_lisp_tcp_message_len, dissect_lisp_tcp_message, data);
558 /* Return the amount of data this dissector was able to dissect */
559 return tvb_reported_length(tvb);
564 * Register the LISP protocol with Wireshark
567 void
568 proto_register_lisp_tcp(void)
570 /* Setup list of header fields */
571 static hf_register_info hf[] = {
572 { &hf_lisp_tcp_message_type,
573 { "Type", "lisp-tcp.message.type",
574 FT_UINT16, BASE_DEC, VALS(lisp_tcp_typevals), 0x0, "TLV Message Type", HFILL }},
575 { &hf_lisp_tcp_message_length,
576 { "Length", "lisp-tcp.message.length",
577 FT_UINT16, BASE_DEC, NULL, 0x0, "TLV Message Length", HFILL }},
578 { &hf_lisp_tcp_message_id,
579 { "Message ID", "lisp-tcp.message.id",
580 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
581 { &hf_lisp_tcp_message_data,
582 { "Message Data", "lisp-tcp.message.data",
583 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
584 { &hf_lisp_tcp_message_eid_afi,
585 { "EID AFI", "lisp-tcp.message.eid.afi",
586 FT_UINT16, BASE_DEC, VALS(afn_vals), 0x0, NULL, HFILL }},
587 { &hf_lisp_tcp_message_iid,
588 { "Instance ID", "lisp-tcp.message.iid",
589 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
590 { &hf_lisp_tcp_message_sid,
591 { "Subscribe Message ID", "lisp-tcp.message.sid",
592 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
593 { &hf_lisp_tcp_message_err,
594 { "Error code", "lisp-tcp.message.err",
595 FT_UINT8, BASE_DEC, VALS(lisp_tcp_membership_subscribe_errors), 0x0, NULL, HFILL }},
596 { &hf_lisp_tcp_message_err_code,
597 { "Error code", "lisp-tcp.message.err.code",
598 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
599 { &hf_lisp_tcp_message_err_reserved,
600 { "Error code", "lisp-tcp.message.err.reserved",
601 FT_UINT24, BASE_HEX, NULL, 0x0, "Must be zero", HFILL }},
602 { &hf_lisp_tcp_message_err_offending_msg_type,
603 { "Offending message type", "lisp-tcp.message.err.offending_msg.type",
604 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
605 { &hf_lisp_tcp_message_err_offending_msg_len,
606 { "Offending message length", "lisp-tcp.message.err.offending_msg.len",
607 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
608 { &hf_lisp_tcp_message_err_offending_msg_id,
609 { "Offending message ID", "lisp-tcp.message.err.offending_msg.id",
610 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
611 { &hf_lisp_tcp_message_err_offending_msg_data,
612 { "Offending message data", "lisp-tcp.message.err.offending_msg.data",
613 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
614 { &hf_lisp_tcp_message_registration_reject_reason,
615 { "Registration reject reason", "lisp-tcp.message.registration_reject.reason",
616 FT_UINT8, BASE_DEC, VALS(lisp_tcp_registration_reject_reason), 0x0, NULL, HFILL }},
617 { &hf_lisp_tcp_message_registration_reject_res,
618 { "Reserved bits", "lisp-tcp.message.registration_reject.res",
619 FT_UINT16, BASE_HEX, NULL, 0x0, "Must be zero", HFILL }},
620 { &hf_lisp_tcp_message_registration_refresh_scope,
621 { "Registration refresh scope", "lisp-tcp.message.registration_refresh.scope",
622 FT_UINT8, BASE_DEC, VALS(lisp_tcp_registration_refresh_scope), 0x0, NULL, HFILL }},
623 { &hf_lisp_tcp_message_registration_refresh_flags_rejected,
624 { "Rejected only", "lisp-tcp.message.registration_refresh.flags.rejected",
625 FT_BOOLEAN, 16, TFS(&tfs_set_notset), REFRESH_FLAG_R, NULL, HFILL }},
626 { &hf_lisp_tcp_message_registration_refresh_res,
627 { "Reserved", "lisp-tcp.message.registration_refresh.res",
628 FT_UINT16, BASE_HEX, NULL, 0x7FFF, "Must be zero", HFILL }},
629 { &hf_lisp_tcp_message_xtr_id,
630 { "xTR-ID", "lisp-tcp.message.xtrid",
631 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
632 { &hf_lisp_tcp_message_site_id,
633 { "Site-ID", "lisp-tcp.message.siteid",
634 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
635 { &hf_lisp_tcp_message_eid_prefix_length,
636 { "Prefix Length", "lisp-tcp.message.eid.prefix.length",
637 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
638 { &hf_lisp_tcp_message_eid_prefix_afi,
639 { "Prefix AFI", "lisp-tcp.message.eid.prefix.afi",
640 FT_UINT16, BASE_DEC, VALS(afn_vals), 0x0, NULL, HFILL }},
641 { &hf_lisp_tcp_message_eid_ipv4,
642 { "Address", "lisp-tcp.message.eid.ipv4",
643 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
644 { &hf_lisp_tcp_message_eid_ipv6,
645 { "Address", "lisp-tcp.message.eid.ipv6",
646 FT_IPv6, BASE_NONE, NULL, 0x0, NULL, HFILL }},
647 { &hf_lisp_tcp_message_eid_mac,
648 { "Address", "lisp-tcp.message.eid.mac",
649 FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
650 { &hf_lisp_tcp_message_eid_dn,
651 { "Address", "lisp-tcp.message.eid.dn",
652 FT_STRINGZ, BASE_NONE, NULL, 0x0, NULL, HFILL }},
653 { &hf_lisp_tcp_message_rloc_afi,
654 { "RLOC AFI", "lisp-tcp.message.rloc.afi",
655 FT_UINT16, BASE_DEC, VALS(afn_vals), 0x0, NULL, HFILL }},
656 { &hf_lisp_tcp_message_rloc_ipv4,
657 { "RLOC", "lisp-tcp.message.rloc.ipv4",
658 FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
659 { &hf_lisp_tcp_message_rloc_ipv6,
660 { "RLOC", "lisp-tcp.message.rloc.ipv6",
661 FT_IPv6, BASE_NONE, NULL, 0x0, NULL, HFILL }},
662 { &hf_lisp_tcp_message_rid,
663 { "Request Message ID", "lisp-tcp.message.rid",
664 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
665 { &hf_lisp_tcp_message_end_marker,
666 { "Message End Marker", "lisp-tcp.message.end_marker",
667 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
670 /* Setup protocol subtree array */
671 static int *ett[] = {
672 &ett_lisp_tcp,
673 &ett_lisp_tcp_lcaf,
674 &ett_lisp_tcp_eid_prefix,
675 &ett_lisp_tcp_map_register
678 static ei_register_info ei[] = {
679 { &ei_lisp_tcp_undecoded, { "lisp-tcp.undecoded", PI_UNDECODED, PI_WARN, "Not dissected yet (report to wireshark.org)", EXPFILL }},
680 { &ei_lisp_tcp_invalid_length, { "lisp-tcp.invalid_length", PI_PROTOCOL, PI_ERROR, "Invalid message length", EXPFILL }},
681 { &ei_lisp_tcp_invalid_marker, { "lisp-tcp.invalid_marker", PI_PROTOCOL, PI_ERROR, "Invalid message end marker", EXPFILL }},
682 { &ei_lisp_tcp_unexpected_afi, { "lisp-tcp.unexpected_afi", PI_PROTOCOL, PI_ERROR, "Unexpected AFI", EXPFILL }},
685 expert_module_t* expert_lisp_tcp;
687 /* Register the protocol name and description */
688 proto_lisp_tcp = proto_register_protocol("Locator/ID Separation Protocol (Reliable Transport)",
689 "LISP Reliable Transport", "lisp-tcp");
691 /* Required function calls to register the header fields and subtrees used */
692 proto_register_field_array(proto_lisp_tcp, hf, array_length(hf));
693 proto_register_subtree_array(ett, array_length(ett));
694 expert_lisp_tcp = expert_register_protocol(proto_lisp_tcp);
695 expert_register_field_array(expert_lisp_tcp, ei, array_length(ei));
697 /* Register dissector so that other dissectors can call it */
698 lisp_tcp_handle = register_dissector("lisp-tcp", dissect_lisp_tcp, proto_lisp_tcp);
703 * Simple form of proto_reg_handoff_lisp_tcp which can be used if there are
704 * no prefs-dependent registration function calls.
707 void
708 proto_reg_handoff_lisp_tcp(void)
710 dissector_add_uint_with_preference("tcp.port", LISP_CONTROL_PORT, lisp_tcp_handle);
714 * Editor modelines - https://www.wireshark.org/tools/modelines.html
716 * Local variables:
717 * c-basic-offset: 4
718 * tab-width: 8
719 * indent-tabs-mode: nil
720 * End:
722 * vi: set shiftwidth=4 tabstop=8 expandtab:
723 * :indentSize=4:tabSize=8:noTabs=true: