2 * Routines for zebra packet disassembly
4 * Jochen Friedrich <jochen@scram.de>
6 * $Id: packet-zebra.c,v 1.21 2002/04/02 01:32:11 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
39 #include <epan/packet.h>
41 static int proto_zebra = -1;
42 static int hf_zebra_len = -1;
43 static int hf_zebra_command = -1;
44 static int hf_zebra_request = -1;
45 static int hf_zebra_interface = -1;
46 static int hf_zebra_index = -1;
47 static int hf_zebra_indexnum = -1;
48 static int hf_zebra_type = -1;
49 static int hf_zebra_intflags = -1;
50 static int hf_zebra_rtflags = -1;
51 static int hf_zebra_distance = -1;
52 static int hf_zebra_metric = -1;
53 static int hf_zebra_mtu = -1;
54 static int hf_zebra_bandwidth = -1;
55 static int hf_zebra_family = -1;
56 static int hf_zebra_message = -1;
57 static int hf_zebra_msg_nexthop = -1;
58 static int hf_zebra_msg_index = -1;
59 static int hf_zebra_msg_distance = -1;
60 static int hf_zebra_msg_metric = -1;
61 static int hf_zebra_nexthopnum = -1;
62 static int hf_zebra_nexthop4 = -1;
63 static int hf_zebra_nexthop6 = -1;
64 static int hf_zebra_dest4 = -1;
65 static int hf_zebra_dest6 = -1;
66 static int hf_zebra_prefixlen = -1;
67 static int hf_zebra_prefix4 = -1;
68 static int hf_zebra_prefix6 = -1;
70 static gint ett_zebra = -1;
71 static gint ett_zebra_request = -1;
72 static gint ett_message = -1;
74 #define TCP_PORT_ZEBRA 2600
76 /* Zebra message types. */
77 #define ZEBRA_INTERFACE_ADD 1
78 #define ZEBRA_INTERFACE_DELETE 2
79 #define ZEBRA_INTERFACE_ADDRESS_ADD 3
80 #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
81 #define ZEBRA_INTERFACE_UP 5
82 #define ZEBRA_INTERFACE_DOWN 6
83 #define ZEBRA_IPV4_ROUTE_ADD 7
84 #define ZEBRA_IPV4_ROUTE_DELETE 8
85 #define ZEBRA_IPV6_ROUTE_ADD 9
86 #define ZEBRA_IPV6_ROUTE_DELETE 10
87 #define ZEBRA_REDISTRIBUTE_ADD 11
88 #define ZEBRA_REDISTRIBUTE_DELETE 12
89 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
90 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
91 #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
92 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
94 static const value_string messages[] = {
95 { ZEBRA_INTERFACE_ADD, "Add Interface" },
96 { ZEBRA_INTERFACE_DELETE, "Delete Interface" },
97 { ZEBRA_INTERFACE_ADDRESS_ADD, "Add Interface Address" },
98 { ZEBRA_INTERFACE_ADDRESS_DELETE, "Delete Interface Address" },
99 { ZEBRA_INTERFACE_UP, "Interface Up" },
100 { ZEBRA_INTERFACE_DOWN, "Interface Down" },
101 { ZEBRA_IPV4_ROUTE_ADD, "Add IPv4 Route" },
102 { ZEBRA_IPV4_ROUTE_DELETE, "Delete IPv4 Route" },
103 { ZEBRA_IPV6_ROUTE_ADD, "Add IPv6 Route" },
104 { ZEBRA_IPV6_ROUTE_DELETE, "Delete IPv6 Route" },
105 { ZEBRA_REDISTRIBUTE_ADD, "Add Redistribute" },
106 { ZEBRA_REDISTRIBUTE_DELETE, "Delete Redistribute" },
107 { ZEBRA_REDISTRIBUTE_DEFAULT_ADD, "Add Default Redistribute" },
108 { ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, "Delete Default Redistribute" },
109 { ZEBRA_IPV4_NEXTHOP_LOOKUP, "IPv4 Nexthop Lookup" },
110 { ZEBRA_IPV6_NEXTHOP_LOOKUP, "IPv6 Nexthop Lookup" },
114 /* Zebra route's types. */
115 #define ZEBRA_ROUTE_SYSTEM 0
116 #define ZEBRA_ROUTE_KERNEL 1
117 #define ZEBRA_ROUTE_CONNECT 2
118 #define ZEBRA_ROUTE_STATIC 3
119 #define ZEBRA_ROUTE_RIP 4
120 #define ZEBRA_ROUTE_RIPNG 5
121 #define ZEBRA_ROUTE_OSPF 6
122 #define ZEBRA_ROUTE_OSPF6 7
123 #define ZEBRA_ROUTE_BGP 8
125 static const value_string routes[] = {
126 { ZEBRA_ROUTE_SYSTEM, "System Route" },
127 { ZEBRA_ROUTE_KERNEL, "Kernel Route" },
128 { ZEBRA_ROUTE_CONNECT, "Connected Route" },
129 { ZEBRA_ROUTE_STATIC, "Static Route" },
130 { ZEBRA_ROUTE_RIP, "RIP Route" },
131 { ZEBRA_ROUTE_RIPNG, "RIPnG Route" },
132 { ZEBRA_ROUTE_OSPF, "OSPF Route" },
133 { ZEBRA_ROUTE_OSPF6, "OSPF6 Route" },
134 { ZEBRA_ROUTE_BGP, "BGP Route" },
138 /* Zebra's family types. */
139 #define ZEBRA_FAMILY_IPV4 1
140 #define ZEBRA_FAMILY_IPV6 2
142 static const value_string families[] = {
143 { ZEBRA_FAMILY_IPV4, "IPv4" },
144 { ZEBRA_FAMILY_IPV6, "IPv6" },
148 /* Error codes of zebra. */
149 #define ZEBRA_ERR_RTEXIST 1
150 #define ZEBRA_ERR_RTUNREACH 2
151 #define ZEBRA_ERR_EPERM 3
152 #define ZEBRA_ERR_RTNOEXIST 4
154 static const value_string errors[] = {
155 { ZEBRA_ERR_RTEXIST, "Route Exists" },
156 { ZEBRA_ERR_RTUNREACH, "Route Unreachable" },
157 { ZEBRA_ERR_EPERM, "Permission Denied" },
158 { ZEBRA_ERR_RTNOEXIST, "Route Does Not Exist" },
162 /* Zebra message flags */
163 #define ZEBRA_FLAG_INTERNAL 0x01
164 #define ZEBRA_FLAG_SELFROUTE 0x02
165 #define ZEBRA_FLAG_BLACKHOLE 0x04
167 /* Subsequent Address Family Identifier. */
168 #define ZEBRA_SAFI_UNICAST 1
169 #define ZEBRA_SAFI_MULTICAST 2
170 #define ZEBRA_SAFI_UNICAST_MULTICAST 3
171 #define ZEBRA_SAFI_MPLS_VPN 4
173 static const value_string safis[] = {
174 { ZEBRA_SAFI_UNICAST, "Unicast" },
175 { ZEBRA_SAFI_MULTICAST, "Multicast" },
176 { ZEBRA_SAFI_UNICAST_MULTICAST, "Unicast And Multicast" },
177 { ZEBRA_SAFI_MPLS_VPN, "MPLS VPN" },
181 /* Zebra API message flag. */
182 #define ZEBRA_ZAPI_MESSAGE_NEXTHOP 0x01
183 #define ZEBRA_ZAPI_MESSAGE_IFINDEX 0x02
184 #define ZEBRA_ZAPI_MESSAGE_DISTANCE 0x04
185 #define ZEBRA_ZAPI_MESSAGE_METRIC 0x08
187 #define INTERFACE_NAMSIZ 20
189 #define PSIZE(a) (((a) + 7) / (8))
192 dissect_zebra_request(proto_tree *tree, gboolean request, tvbuff_t *tvb,
193 int offset, guint16 len, guint8 command)
197 guint8 buffer6[16], prefixlen, message;
199 proto_tree *msg_tree;
201 proto_tree_add_uint(tree, hf_zebra_len, tvb, offset, 2, len);
203 proto_tree_add_uint(tree, hf_zebra_command, tvb, offset, 1,
207 case ZEBRA_INTERFACE_ADD:
208 case ZEBRA_INTERFACE_UP:
209 case ZEBRA_INTERFACE_DOWN:
211 /* Request just subscribes to messages */
213 proto_tree_add_item(tree, hf_zebra_interface,
214 tvb, offset, INTERFACE_NAMSIZ, FALSE);
215 offset += INTERFACE_NAMSIZ;
217 proto_tree_add_item(tree, hf_zebra_index, tvb,
221 proto_tree_add_item(tree, hf_zebra_intflags, tvb,
225 proto_tree_add_item(tree, hf_zebra_metric, tvb,
229 proto_tree_add_item(tree, hf_zebra_mtu, tvb,
233 proto_tree_add_item(tree, hf_zebra_bandwidth, tvb,
238 case ZEBRA_INTERFACE_DELETE:
239 proto_tree_add_item(tree, hf_zebra_interface,
240 tvb, offset, INTERFACE_NAMSIZ, FALSE);
241 offset += INTERFACE_NAMSIZ;
243 proto_tree_add_item(tree, hf_zebra_index, tvb,
247 case ZEBRA_INTERFACE_ADDRESS_ADD:
248 case ZEBRA_INTERFACE_ADDRESS_DELETE:
249 proto_tree_add_item(tree, hf_zebra_index, tvb,
253 proto_tree_add_item(tree, hf_zebra_family, tvb,
257 if (len == 17) { /* IPv4 */
258 proto_tree_add_item(tree, hf_zebra_prefix4,
259 tvb, offset, 4, FALSE);
262 else if (len == 41) { /* IPv6 */
263 proto_tree_add_item(tree, hf_zebra_prefix6,
264 tvb, offset, 16, FALSE);
269 proto_tree_add_item(tree, hf_zebra_prefixlen, tvb,
273 if (len == 17) { /* IPv4 */
274 proto_tree_add_item(tree, hf_zebra_dest4,
275 tvb, offset, 4, FALSE);
278 else if (len == 41) { /* IPv6 */
279 proto_tree_add_item(tree, hf_zebra_dest6,
280 tvb, offset, 16, FALSE);
285 case ZEBRA_IPV4_ROUTE_ADD:
286 case ZEBRA_IPV4_ROUTE_DELETE:
287 proto_tree_add_item(tree, hf_zebra_type, tvb,
291 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
295 message = tvb_get_guint8(tvb, offset);
296 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
298 msg_tree = proto_item_add_subtree(ti, ett_message);
299 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
300 tvb, offset, 1, message);
301 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
302 tvb, offset, 1, message);
303 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
304 tvb, offset, 1, message);
305 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
306 tvb, offset, 1, message);
309 prefixlen = tvb_get_guint8(tvb, offset);
310 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
311 offset, 1, prefixlen);
315 tvb_memcpy(tvb, (guint8 *)&prefix4, offset,
316 MIN((unsigned) PSIZE(prefixlen), sizeof prefix4));
317 proto_tree_add_ipv4(tree, hf_zebra_prefix4,
318 tvb, offset, PSIZE(prefixlen), prefix4);
319 offset += PSIZE(prefixlen);
321 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
322 i = tvb_get_guint8(tvb, offset);
323 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
327 if (i>len) break; /* Sanity */
330 proto_tree_add_item(tree,
331 hf_zebra_nexthop4, tvb,
336 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
337 i = tvb_get_guint8(tvb, offset);
338 proto_tree_add_uint(tree, hf_zebra_indexnum,
342 if (i>len) break; /* Sanity */
345 proto_tree_add_item(tree,
351 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
352 proto_tree_add_item(tree, hf_zebra_distance,
353 tvb, offset, 1, FALSE);
356 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
357 proto_tree_add_item(tree, hf_zebra_metric,
358 tvb, offset, 4, FALSE);
362 case ZEBRA_IPV6_ROUTE_ADD:
363 case ZEBRA_IPV6_ROUTE_DELETE:
364 proto_tree_add_item(tree, hf_zebra_type, tvb,
368 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
372 message = tvb_get_guint8(tvb, offset);
373 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
375 msg_tree = proto_item_add_subtree(ti, ett_message);
376 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
377 tvb, offset, 1, message);
378 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
379 tvb, offset, 1, message);
380 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
381 tvb, offset, 1, message);
382 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
383 tvb, offset, 1, message);
386 prefixlen = tvb_get_guint8(tvb, offset);
387 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
388 offset, 1, prefixlen);
391 memset(buffer6, '\0', sizeof buffer6);
392 tvb_memcpy(tvb, buffer6, offset,
393 MIN((unsigned) PSIZE(prefixlen), sizeof buffer6));
394 proto_tree_add_ipv6(tree, hf_zebra_prefix6,
395 tvb, offset, PSIZE(prefixlen), buffer6);
396 offset += PSIZE(prefixlen);
398 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
399 i = tvb_get_guint8(tvb, offset);
400 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
404 if (i>len) break; /* Sanity */
407 proto_tree_add_item(tree,
408 hf_zebra_nexthop6, tvb,
413 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
414 i = tvb_get_guint8(tvb, offset);
415 proto_tree_add_uint(tree, hf_zebra_indexnum,
419 if (i>len) break; /* Sanity */
422 proto_tree_add_item(tree,
428 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
429 proto_tree_add_item(tree, hf_zebra_distance,
430 tvb, offset, 1, FALSE);
433 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
434 proto_tree_add_item(tree, hf_zebra_metric,
435 tvb, offset, 4, FALSE);
439 case ZEBRA_REDISTRIBUTE_ADD:
440 case ZEBRA_REDISTRIBUTE_DELETE:
441 proto_tree_add_item(tree, hf_zebra_type, tvb,
445 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
446 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
448 case ZEBRA_IPV4_NEXTHOP_LOOKUP:
449 proto_tree_add_item(tree, hf_zebra_nexthop4,
450 tvb, offset, 4, FALSE);
453 proto_tree_add_item(tree, hf_zebra_metric,
454 tvb, offset, 4, FALSE);
457 case ZEBRA_IPV6_NEXTHOP_LOOKUP:
458 /* Not yet implemeted in ZEBRA */
464 dissect_zebra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
467 proto_tree *zebra_tree;
471 if (check_col(pinfo->cinfo, COL_PROTOCOL))
472 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZEBRA");
474 request = (pinfo->destport == pinfo->match_port);
475 left = tvb_reported_length(tvb);
478 if (check_col(pinfo->cinfo, COL_INFO)) {
479 col_set_str(pinfo->cinfo, COL_INFO,
480 request? "ZEBRA Request" : "ZEBRA Reply");
483 ti = proto_tree_add_item(tree, proto_zebra, tvb, offset, -1,
485 zebra_tree = proto_item_add_subtree(ti, ett_zebra);
486 proto_tree_add_boolean_hidden(zebra_tree, hf_zebra_request,
487 tvb, offset, 0, request);
492 proto_tree *zebra_request_tree;
496 len = tvb_get_ntohs(tvb, offset);
499 command = tvb_get_guint8(tvb, offset+2);
501 ti = proto_tree_add_uint(zebra_tree,
502 hf_zebra_command, tvb, offset, len,
504 zebra_request_tree = proto_item_add_subtree(ti,
506 dissect_zebra_request(zebra_request_tree, request, tvb,
507 offset, len, command);
516 proto_register_zebra(void)
519 static hf_register_info hf[] = {
521 { "Length", "zebra.len",
522 FT_UINT16, BASE_DEC, NULL, 0x0,
523 "Length of ZEBRA request", HFILL }},
525 { "Request", "zebra.request",
526 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
527 "TRUE if ZEBRA request", HFILL }},
529 { "Command", "zebra.command",
530 FT_UINT8, BASE_DEC, VALS(messages), 0x0,
531 "ZEBRA command", HFILL }},
532 { &hf_zebra_interface,
533 { "Interface", "zebra.interface",
534 FT_STRING, BASE_NONE, NULL, 0x0,
535 "Interface name of ZEBRA request", HFILL }},
537 { "Index", "zebra.index",
538 FT_UINT32, BASE_DEC, NULL, 0x0,
539 "Index of interface", HFILL }},
540 { &hf_zebra_indexnum,
541 { "Index Number", "zebra.indexnum",
542 FT_UINT8, BASE_DEC, NULL, 0x0,
543 "Number of indices for route", HFILL }},
544 { &hf_zebra_intflags,
545 { "Flags", "zebra.intflags",
546 FT_UINT32, BASE_DEC, NULL, 0x0,
547 "Flags of interface", HFILL }},
549 { "Flags", "zebra.rtflags",
550 FT_UINT8, BASE_DEC, NULL, 0x0,
551 "Flags of route", HFILL }},
553 { "Message", "zebra.message",
554 FT_UINT8, BASE_DEC, NULL, 0x0,
555 "Message type of route", HFILL }},
556 { &hf_zebra_msg_nexthop,
557 { "Message Nexthop", "zebra.message.nexthop",
558 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_NEXTHOP,
559 "Message contains nexthop", HFILL }},
560 { &hf_zebra_msg_index,
561 { "Message Index", "zebra.message.index",
562 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_IFINDEX,
563 "Message contains index", HFILL }},
564 { &hf_zebra_msg_distance,
565 { "Message Distance", "zebra.message.distance",
566 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_DISTANCE,
567 "Message contains distance", HFILL }},
568 { &hf_zebra_msg_metric,
569 { "Message Metric", "zebra.message.metric",
570 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_METRIC,
571 "Message contains metric", HFILL }},
573 { "Type", "zebra.type",
574 FT_UINT8, BASE_DEC, VALS(routes), 0x0,
575 "Type of route", HFILL }},
576 { &hf_zebra_distance,
577 { "Distance", "zebra.distance",
578 FT_UINT8, BASE_DEC, NULL, 0x0,
579 "Distance of route", HFILL }},
581 { "Metric", "zebra.metric",
582 FT_UINT32, BASE_DEC, NULL, 0x0,
583 "Metric of interface or route", HFILL }},
585 { "MTU", "zebra.mtu",
586 FT_UINT32, BASE_DEC, NULL, 0x0,
587 "MTU of interface", HFILL }},
588 { &hf_zebra_bandwidth,
589 { "Bandwidth", "zebra.bandwidth",
590 FT_UINT32, BASE_DEC, NULL, 0x0,
591 "Bandwidth of interface", HFILL }},
593 { "Family", "zebra.family",
594 FT_UINT32, BASE_DEC, NULL, 0x0,
595 "Family of IP address", HFILL }},
597 { "Destination", "zebra.dest4",
598 FT_IPv4, BASE_NONE, NULL, 0x0,
599 "Destination IPv4 field", HFILL }},
601 { "Destination", "zebra.dest6",
602 FT_IPv6, BASE_NONE, NULL, 0x0,
603 "Destination IPv6 field", HFILL }},
604 { &hf_zebra_nexthopnum,
605 { "Nexthop Number", "zebra.nexthopnum",
606 FT_UINT8, BASE_DEC, NULL, 0x0,
607 "Number of nexthops in route", HFILL }},
608 { &hf_zebra_nexthop4,
609 { "Nexthop", "zebra.nexthop4",
610 FT_IPv4, BASE_NONE, NULL, 0x0,
611 "Nethop IPv4 field of route", HFILL }},
612 { &hf_zebra_nexthop6,
613 { "Nexthop", "zebra.nexthop6",
614 FT_IPv6, BASE_NONE, NULL, 0x0,
615 "Nethop IPv6 field of route", HFILL }},
616 { &hf_zebra_prefixlen,
617 { "Prefix length", "zebra.prefixlen",
618 FT_UINT32, BASE_DEC, NULL, 0x0,
619 "Prefix length", HFILL }},
621 { "Prefix", "zebra.prefix4",
622 FT_IPv4, BASE_NONE, NULL, 0x0,
623 "Prefix IPv4", HFILL }},
625 { "Prefix", "zebra.prefix6",
626 FT_IPv6, BASE_NONE, NULL, 0x0,
627 "Prefix IPv6", HFILL }},
630 static gint *ett[] = {
636 proto_zebra = proto_register_protocol("Zebra Protocol", "ZEBRA", "zebra");
637 proto_register_field_array(proto_zebra, hf, array_length(hf));
638 proto_register_subtree_array(ett, array_length(ett));
642 proto_reg_handoff_zebra(void)
644 dissector_handle_t zebra_handle;
646 zebra_handle = create_dissector_handle(dissect_zebra, proto_zebra);
647 dissector_add("tcp.port", TCP_PORT_ZEBRA, zebra_handle);