2 * Routines for zebra packet disassembly
4 * Jochen Friedrich <jochen@scram.de>
6 * $Id: packet-zebra.c,v 1.8 2001/01/09 06:31:45 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
44 static int proto_zebra = -1;
45 static int hf_zebra_len = -1;
46 static int hf_zebra_command = -1;
47 static int hf_zebra_request = -1;
48 static int hf_zebra_interface = -1;
49 static int hf_zebra_index = -1;
50 static int hf_zebra_indexnum = -1;
51 static int hf_zebra_type = -1;
52 static int hf_zebra_intflags = -1;
53 static int hf_zebra_rtflags = -1;
54 static int hf_zebra_distance = -1;
55 static int hf_zebra_metric = -1;
56 static int hf_zebra_mtu = -1;
57 static int hf_zebra_bandwidth = -1;
58 static int hf_zebra_family = -1;
59 static int hf_zebra_message = -1;
60 static int hf_zebra_msg_nexthop = -1;
61 static int hf_zebra_msg_index = -1;
62 static int hf_zebra_msg_distance = -1;
63 static int hf_zebra_msg_metric = -1;
64 static int hf_zebra_nexthopnum = -1;
65 static int hf_zebra_nexthop4 = -1;
66 static int hf_zebra_nexthop6 = -1;
67 static int hf_zebra_dest4 = -1;
68 static int hf_zebra_dest6 = -1;
69 static int hf_zebra_prefixlen = -1;
70 static int hf_zebra_prefix4 = -1;
71 static int hf_zebra_prefix6 = -1;
73 static gint ett_zebra = -1;
74 static gint ett_zebra_request = -1;
75 static gint ett_message = -1;
77 #define TCP_PORT_ZEBRA 2600
79 /* Zebra message types. */
80 #define ZEBRA_INTERFACE_ADD 1
81 #define ZEBRA_INTERFACE_DELETE 2
82 #define ZEBRA_INTERFACE_ADDRESS_ADD 3
83 #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
84 #define ZEBRA_INTERFACE_UP 5
85 #define ZEBRA_INTERFACE_DOWN 6
86 #define ZEBRA_IPV4_ROUTE_ADD 7
87 #define ZEBRA_IPV4_ROUTE_DELETE 8
88 #define ZEBRA_IPV6_ROUTE_ADD 9
89 #define ZEBRA_IPV6_ROUTE_DELETE 10
90 #define ZEBRA_REDISTRIBUTE_ADD 11
91 #define ZEBRA_REDISTRIBUTE_DELETE 12
92 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
93 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
94 #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
95 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
97 static const value_string messages[] = {
98 { ZEBRA_INTERFACE_ADD, "Add Interface" },
99 { ZEBRA_INTERFACE_DELETE, "Delete Interface" },
100 { ZEBRA_INTERFACE_ADDRESS_ADD, "Add Interface Address" },
101 { ZEBRA_INTERFACE_ADDRESS_DELETE, "Delete Interface Address" },
102 { ZEBRA_INTERFACE_UP, "Interface Up" },
103 { ZEBRA_INTERFACE_DOWN, "Interface Down" },
104 { ZEBRA_IPV4_ROUTE_ADD, "Add IPv4 Route" },
105 { ZEBRA_IPV4_ROUTE_DELETE, "Delete IPv4 Route" },
106 { ZEBRA_IPV6_ROUTE_ADD, "Add IPv6 Route" },
107 { ZEBRA_IPV6_ROUTE_DELETE, "Delete IPv6 Route" },
108 { ZEBRA_REDISTRIBUTE_ADD, "Add Redistribute" },
109 { ZEBRA_REDISTRIBUTE_DELETE, "Delete Redistribute" },
110 { ZEBRA_REDISTRIBUTE_DEFAULT_ADD, "Add Default Redistribute" },
111 { ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, "Delete Default Redistribute" },
112 { ZEBRA_IPV4_NEXTHOP_LOOKUP, "IPv4 Nexthop Lookup" },
113 { ZEBRA_IPV6_NEXTHOP_LOOKUP, "IPv6 Nexthop Lookup" },
117 /* Zebra route's types. */
118 #define ZEBRA_ROUTE_SYSTEM 0
119 #define ZEBRA_ROUTE_KERNEL 1
120 #define ZEBRA_ROUTE_CONNECT 2
121 #define ZEBRA_ROUTE_STATIC 3
122 #define ZEBRA_ROUTE_RIP 4
123 #define ZEBRA_ROUTE_RIPNG 5
124 #define ZEBRA_ROUTE_OSPF 6
125 #define ZEBRA_ROUTE_OSPF6 7
126 #define ZEBRA_ROUTE_BGP 8
128 static const value_string routes[] = {
129 { ZEBRA_ROUTE_SYSTEM, "System Route" },
130 { ZEBRA_ROUTE_KERNEL, "Kernel Route" },
131 { ZEBRA_ROUTE_CONNECT, "Connected Route" },
132 { ZEBRA_ROUTE_STATIC, "Static Route" },
133 { ZEBRA_ROUTE_RIP, "RIP Route" },
134 { ZEBRA_ROUTE_RIPNG, "RIPnG Route" },
135 { ZEBRA_ROUTE_OSPF, "OSPF Route" },
136 { ZEBRA_ROUTE_OSPF6, "OSPF6 Route" },
137 { ZEBRA_ROUTE_BGP, "BGP Route" },
141 /* Zebra's family types. */
142 #define ZEBRA_FAMILY_IPV4 1
143 #define ZEBRA_FAMILY_IPV6 2
145 static const value_string families[] = {
146 { ZEBRA_FAMILY_IPV4, "IPv4" },
147 { ZEBRA_FAMILY_IPV6, "IPv6" },
151 /* Error codes of zebra. */
152 #define ZEBRA_ERR_RTEXIST 1
153 #define ZEBRA_ERR_RTUNREACH 2
154 #define ZEBRA_ERR_EPERM 3
155 #define ZEBRA_ERR_RTNOEXIST 4
157 static const value_string errors[] = {
158 { ZEBRA_ERR_RTEXIST, "Route Exists" },
159 { ZEBRA_ERR_RTUNREACH, "Route Unreachable" },
160 { ZEBRA_ERR_EPERM, "Permission Denied" },
161 { ZEBRA_ERR_RTNOEXIST, "Route Does Not Exist" },
165 /* Zebra message flags */
166 #define ZEBRA_FLAG_INTERNAL 0x01
167 #define ZEBRA_FLAG_SELFROUTE 0x02
168 #define ZEBRA_FLAG_BLACKHOLE 0x04
170 /* Subsequent Address Family Identifier. */
171 #define ZEBRA_SAFI_UNICAST 1
172 #define ZEBRA_SAFI_MULTICAST 2
173 #define ZEBRA_SAFI_UNICAST_MULTICAST 3
174 #define ZEBRA_SAFI_MPLS_VPN 4
176 static const value_string safis[] = {
177 { ZEBRA_SAFI_UNICAST, "Unicast" },
178 { ZEBRA_SAFI_MULTICAST, "Multicast" },
179 { ZEBRA_SAFI_UNICAST_MULTICAST, "Unicast And Multicast" },
180 { ZEBRA_SAFI_MPLS_VPN, "MPLS VPN" },
184 /* Zebra API message flag. */
185 #define ZEBRA_ZAPI_MESSAGE_NEXTHOP 0x01
186 #define ZEBRA_ZAPI_MESSAGE_IFINDEX 0x02
187 #define ZEBRA_ZAPI_MESSAGE_DISTANCE 0x04
188 #define ZEBRA_ZAPI_MESSAGE_METRIC 0x08
190 #define INTERFACE_NAMSIZ 20
192 #define PSIZE(a) (((a) + 7) / (8))
195 dissect_zebra_request(proto_tree *tree, gboolean request, tvbuff_t *tvb,
196 int offset, guint16 len, guint8 command)
200 guint8 buffer6[16], prefixlen, message;
203 proto_tree *msg_tree;
205 proto_tree_add_uint(tree, hf_zebra_len, tvb, offset, 2, len);
207 proto_tree_add_uint(tree, hf_zebra_command, tvb, offset, 1,
211 case ZEBRA_INTERFACE_ADD:
212 case ZEBRA_INTERFACE_UP:
213 case ZEBRA_INTERFACE_DOWN:
215 /* Request just subscribes to messages */
217 proto_tree_add_string(tree, hf_zebra_interface,
218 tvb, offset, INTERFACE_NAMSIZ,
219 tvb_get_ptr(tvb, offset, INTERFACE_NAMSIZ));
220 offset += INTERFACE_NAMSIZ;
222 proto_tree_add_item(tree, hf_zebra_index, tvb,
226 proto_tree_add_item(tree, hf_zebra_intflags, tvb,
230 proto_tree_add_item(tree, hf_zebra_metric, tvb,
234 proto_tree_add_item(tree, hf_zebra_mtu, tvb,
238 proto_tree_add_item(tree, hf_zebra_bandwidth, tvb,
243 case ZEBRA_INTERFACE_DELETE:
244 proto_tree_add_string(tree, hf_zebra_interface,
245 tvb, offset, INTERFACE_NAMSIZ,
246 tvb_get_ptr(tvb, offset, INTERFACE_NAMSIZ));
247 offset += INTERFACE_NAMSIZ;
249 proto_tree_add_item(tree, hf_zebra_index, tvb,
253 case ZEBRA_INTERFACE_ADDRESS_ADD:
254 case ZEBRA_INTERFACE_ADDRESS_DELETE:
255 proto_tree_add_item(tree, hf_zebra_index, tvb,
259 proto_tree_add_item(tree, hf_zebra_family, tvb,
263 if (len == 17) { /* IPv4 */
264 proto_tree_add_item(tree, hf_zebra_prefix4,
265 tvb, offset, 4, FALSE);
268 else if (len == 41) { /* IPv6 */
269 proto_tree_add_item(tree, hf_zebra_prefix6,
270 tvb, offset, 16, FALSE);
275 proto_tree_add_item(tree, hf_zebra_prefixlen, tvb,
279 if (len == 17) { /* IPv4 */
280 proto_tree_add_item(tree, hf_zebra_dest4,
281 tvb, offset, 4, FALSE);
284 else if (len == 41) { /* IPv6 */
285 proto_tree_add_item(tree, hf_zebra_dest6,
286 tvb, offset, 16, FALSE);
291 case ZEBRA_IPV4_ROUTE_ADD:
292 case ZEBRA_IPV4_ROUTE_DELETE:
293 proto_tree_add_item(tree, hf_zebra_type, tvb,
297 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
301 message = tvb_get_guint8(tvb, offset);
302 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
304 msg_tree = proto_item_add_subtree(ti, ett_message);
305 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
306 tvb, offset, 1, message);
307 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
308 tvb, offset, 1, message);
309 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
310 tvb, offset, 1, message);
311 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
312 tvb, offset, 1, message);
315 prefixlen = tvb_get_guint8(tvb, offset);
316 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
317 offset, 1, prefixlen);
320 prefix = tvb_get_ptr(tvb, offset, PSIZE(prefixlen));
322 memcpy(&prefix4, prefix,
323 MIN(PSIZE(prefixlen), sizeof prefix4));
324 proto_tree_add_ipv4(tree, hf_zebra_prefix4,
325 tvb, offset, PSIZE(prefixlen), prefix4);
326 offset += PSIZE(prefixlen);
328 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
329 i = tvb_get_guint8(tvb, offset);
330 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
334 if (i>len) break; /* Sanity */
337 proto_tree_add_item(tree,
338 hf_zebra_nexthop4, tvb,
343 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
344 i = tvb_get_guint8(tvb, offset);
345 proto_tree_add_uint(tree, hf_zebra_indexnum,
349 if (i>len) break; /* Sanity */
352 proto_tree_add_item(tree,
358 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
359 proto_tree_add_item(tree, hf_zebra_distance,
360 tvb, offset, 1, FALSE);
363 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
364 proto_tree_add_item(tree, hf_zebra_metric,
365 tvb, offset, 4, FALSE);
369 case ZEBRA_IPV6_ROUTE_ADD:
370 case ZEBRA_IPV6_ROUTE_DELETE:
371 proto_tree_add_item(tree, hf_zebra_type, tvb,
375 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
379 message = tvb_get_guint8(tvb, offset);
380 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
382 msg_tree = proto_item_add_subtree(ti, ett_message);
383 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
384 tvb, offset, 1, message);
385 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
386 tvb, offset, 1, message);
387 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
388 tvb, offset, 1, message);
389 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
390 tvb, offset, 1, message);
393 prefixlen = tvb_get_guint8(tvb, offset);
394 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
395 offset, 1, prefixlen);
398 prefix = tvb_get_ptr(tvb, offset, PSIZE(prefixlen));
399 memset(buffer6, '\0', sizeof buffer6);
400 memcpy(buffer6, prefix,
401 MIN(PSIZE(prefixlen), sizeof buffer6));
402 proto_tree_add_ipv6(tree, hf_zebra_prefix6,
403 tvb, offset, PSIZE(prefixlen), buffer6);
404 offset += PSIZE(prefixlen);
406 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
407 i = tvb_get_guint8(tvb, offset);
408 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
412 if (i>len) break; /* Sanity */
415 proto_tree_add_item(tree,
416 hf_zebra_nexthop6, tvb,
421 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
422 i = tvb_get_guint8(tvb, offset);
423 proto_tree_add_uint(tree, hf_zebra_indexnum,
427 if (i>len) break; /* Sanity */
430 proto_tree_add_item(tree,
436 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
437 proto_tree_add_item(tree, hf_zebra_distance,
438 tvb, offset, 1, FALSE);
441 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
442 proto_tree_add_item(tree, hf_zebra_metric,
443 tvb, offset, 4, FALSE);
447 case ZEBRA_REDISTRIBUTE_ADD:
448 case ZEBRA_REDISTRIBUTE_DELETE:
449 proto_tree_add_item(tree, hf_zebra_type, tvb,
453 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
454 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
456 case ZEBRA_IPV4_NEXTHOP_LOOKUP:
457 proto_tree_add_item(tree, hf_zebra_nexthop4,
458 tvb, offset, 4, FALSE);
461 proto_tree_add_item(tree, hf_zebra_metric,
462 tvb, offset, 4, FALSE);
465 case ZEBRA_IPV6_NEXTHOP_LOOKUP:
466 /* Not yet implemeted in ZEBRA */
472 dissect_zebra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
475 proto_tree *zebra_tree;
479 CHECK_DISPLAY_AS_DATA(proto_zebra, tvb, pinfo, tree);
481 pinfo->current_proto = "ZEBRA";
483 if (check_col(pinfo->fd, COL_PROTOCOL))
484 col_set_str(pinfo->fd, COL_PROTOCOL, "ZEBRA");
486 request = (pi.destport == TCP_PORT_ZEBRA);
487 left = tvb_reported_length(tvb);
490 if (check_col(pinfo->fd, COL_INFO)) {
491 col_add_str(pinfo->fd, COL_INFO,
492 request? "ZEBRA Request" : "ZEBRA Reply");
495 ti = proto_tree_add_item(tree, proto_zebra, tvb, offset,
496 END_OF_FRAME, FALSE);
497 zebra_tree = proto_item_add_subtree(ti, ett_zebra);
498 proto_tree_add_boolean_hidden(zebra_tree, hf_zebra_request,
499 tvb, offset, END_OF_FRAME, request);
504 proto_tree *zebra_request_tree;
508 len = tvb_get_ntohs(tvb, offset);
511 command = tvb_get_guint8(tvb, offset+2);
513 ti = proto_tree_add_uint(zebra_tree,
514 hf_zebra_command, tvb, offset, len,
516 zebra_request_tree = proto_item_add_subtree(ti,
518 dissect_zebra_request(zebra_request_tree, request, tvb,
519 offset, len, command);
528 proto_register_zebra(void)
531 static hf_register_info hf[] = {
533 { "Length", "zebra.len",
534 FT_UINT16, BASE_DEC, NULL, 0x0,
535 "Length of ZEBRA request" }},
537 { "Request", "zebra.request",
538 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
539 "TRUE if ZEBRA request" }},
541 { "Command", "zebra.command",
542 FT_UINT8, BASE_DEC, VALS(messages), 0x0,
544 { &hf_zebra_interface,
545 { "Interface", "zebra.interface",
546 FT_STRING, BASE_NONE, NULL, 0x0,
547 "Interface name of ZEBRA request" }},
549 { "Index", "zebra.index",
550 FT_UINT32, BASE_DEC, NULL, 0x0,
551 "Index of interface" }},
552 { &hf_zebra_indexnum,
553 { "Index Number", "zebra.indexnum",
554 FT_UINT8, BASE_DEC, NULL, 0x0,
555 "Number of indices for route" }},
556 { &hf_zebra_intflags,
557 { "Flags", "zebra.intflags",
558 FT_UINT32, BASE_DEC, NULL, 0x0,
559 "Flags of interface" }},
561 { "Flags", "zebra.rtflags",
562 FT_UINT8, BASE_DEC, NULL, 0x0,
565 { "Message", "zebra.message",
566 FT_UINT8, BASE_DEC, NULL, 0x0,
567 "Message type of route" }},
568 { &hf_zebra_msg_nexthop,
569 { "Message Nexthop", "zebra.message.nexthop",
570 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_NEXTHOP,
571 "Message contains nexthop" }},
572 { &hf_zebra_msg_index,
573 { "Message Index", "zebra.message.index",
574 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_IFINDEX,
575 "Message contains index" }},
576 { &hf_zebra_msg_distance,
577 { "Message Distance", "zebra.message.distance",
578 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_DISTANCE,
579 "Message contains distance" }},
580 { &hf_zebra_msg_metric,
581 { "Message Metric", "zebra.message.metric",
582 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_METRIC,
583 "Message contains metric" }},
585 { "Type", "zebra.type",
586 FT_UINT8, BASE_DEC, VALS(routes), 0x0,
588 { &hf_zebra_distance,
589 { "Distance", "zebra.distance",
590 FT_UINT8, BASE_DEC, NULL, 0x0,
591 "Distance of route" }},
593 { "Metric", "zebra.metric",
594 FT_UINT32, BASE_DEC, NULL, 0x0,
595 "Metric of interface or route" }},
597 { "MTU", "zebra.mtu",
598 FT_UINT32, BASE_DEC, NULL, 0x0,
599 "MTU of interface" }},
600 { &hf_zebra_bandwidth,
601 { "Bandwidth", "zebra.bandwidth",
602 FT_UINT32, BASE_DEC, NULL, 0x0,
603 "Bandwidth of interface" }},
605 { "Family", "zebra.family",
606 FT_UINT32, BASE_DEC, NULL, 0x0,
607 "Family of IP address" }},
609 { "Destination", "zebra.dest4",
610 FT_IPv4, BASE_NONE, NULL, 0x0,
611 "Destination IPv4 field" }},
613 { "Destination", "zebra.dest6",
614 FT_IPv6, BASE_NONE, NULL, 0x0,
615 "Destination IPv6 field" }},
616 { &hf_zebra_nexthopnum,
617 { "Nexthop Number", "zebra.nexthopnum",
618 FT_UINT8, BASE_NONE, NULL, 0x0,
619 "Number of nexthops in route" }},
620 { &hf_zebra_nexthop4,
621 { "Nexthop", "zebra.nexthop4",
622 FT_IPv4, BASE_NONE, NULL, 0x0,
623 "Nethop IPv4 field of route" }},
624 { &hf_zebra_nexthop6,
625 { "Nexthop", "zebra.nexthop6",
626 FT_IPv6, BASE_NONE, NULL, 0x0,
627 "Nethop IPv6 field of route" }},
628 { &hf_zebra_prefixlen,
629 { "Prefix length", "zebra.prefixlen",
630 FT_UINT32, BASE_DEC, NULL, 0x0,
633 { "Prefix", "zebra.prefix4",
634 FT_IPv4, BASE_NONE, NULL, 0x0,
637 { "Prefix", "zebra.prefix6",
638 FT_IPv6, BASE_NONE, NULL, 0x0,
642 static gint *ett[] = {
648 proto_zebra = proto_register_protocol("Zebra Protocol", "ZEBRA", "zebra");
649 proto_register_field_array(proto_zebra, hf, array_length(hf));
650 proto_register_subtree_array(ett, array_length(ett));
654 proto_reg_handoff_zebra(void)
656 dissector_add("tcp.port", TCP_PORT_ZEBRA, dissect_zebra, proto_zebra);