2 * Routines for zebra packet disassembly
4 * Jochen Friedrich <jochen@scram.de>
6 * $Id: packet-zebra.c,v 1.22 2002/08/02 23:36:05 jmayer 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.
35 #include <epan/packet.h>
37 static int proto_zebra = -1;
38 static int hf_zebra_len = -1;
39 static int hf_zebra_command = -1;
40 static int hf_zebra_request = -1;
41 static int hf_zebra_interface = -1;
42 static int hf_zebra_index = -1;
43 static int hf_zebra_indexnum = -1;
44 static int hf_zebra_type = -1;
45 static int hf_zebra_intflags = -1;
46 static int hf_zebra_rtflags = -1;
47 static int hf_zebra_distance = -1;
48 static int hf_zebra_metric = -1;
49 static int hf_zebra_mtu = -1;
50 static int hf_zebra_bandwidth = -1;
51 static int hf_zebra_family = -1;
52 static int hf_zebra_message = -1;
53 static int hf_zebra_msg_nexthop = -1;
54 static int hf_zebra_msg_index = -1;
55 static int hf_zebra_msg_distance = -1;
56 static int hf_zebra_msg_metric = -1;
57 static int hf_zebra_nexthopnum = -1;
58 static int hf_zebra_nexthop4 = -1;
59 static int hf_zebra_nexthop6 = -1;
60 static int hf_zebra_dest4 = -1;
61 static int hf_zebra_dest6 = -1;
62 static int hf_zebra_prefixlen = -1;
63 static int hf_zebra_prefix4 = -1;
64 static int hf_zebra_prefix6 = -1;
66 static gint ett_zebra = -1;
67 static gint ett_zebra_request = -1;
68 static gint ett_message = -1;
70 #define TCP_PORT_ZEBRA 2600
72 /* Zebra message types. */
73 #define ZEBRA_INTERFACE_ADD 1
74 #define ZEBRA_INTERFACE_DELETE 2
75 #define ZEBRA_INTERFACE_ADDRESS_ADD 3
76 #define ZEBRA_INTERFACE_ADDRESS_DELETE 4
77 #define ZEBRA_INTERFACE_UP 5
78 #define ZEBRA_INTERFACE_DOWN 6
79 #define ZEBRA_IPV4_ROUTE_ADD 7
80 #define ZEBRA_IPV4_ROUTE_DELETE 8
81 #define ZEBRA_IPV6_ROUTE_ADD 9
82 #define ZEBRA_IPV6_ROUTE_DELETE 10
83 #define ZEBRA_REDISTRIBUTE_ADD 11
84 #define ZEBRA_REDISTRIBUTE_DELETE 12
85 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
86 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
87 #define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
88 #define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
90 static const value_string messages[] = {
91 { ZEBRA_INTERFACE_ADD, "Add Interface" },
92 { ZEBRA_INTERFACE_DELETE, "Delete Interface" },
93 { ZEBRA_INTERFACE_ADDRESS_ADD, "Add Interface Address" },
94 { ZEBRA_INTERFACE_ADDRESS_DELETE, "Delete Interface Address" },
95 { ZEBRA_INTERFACE_UP, "Interface Up" },
96 { ZEBRA_INTERFACE_DOWN, "Interface Down" },
97 { ZEBRA_IPV4_ROUTE_ADD, "Add IPv4 Route" },
98 { ZEBRA_IPV4_ROUTE_DELETE, "Delete IPv4 Route" },
99 { ZEBRA_IPV6_ROUTE_ADD, "Add IPv6 Route" },
100 { ZEBRA_IPV6_ROUTE_DELETE, "Delete IPv6 Route" },
101 { ZEBRA_REDISTRIBUTE_ADD, "Add Redistribute" },
102 { ZEBRA_REDISTRIBUTE_DELETE, "Delete Redistribute" },
103 { ZEBRA_REDISTRIBUTE_DEFAULT_ADD, "Add Default Redistribute" },
104 { ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, "Delete Default Redistribute" },
105 { ZEBRA_IPV4_NEXTHOP_LOOKUP, "IPv4 Nexthop Lookup" },
106 { ZEBRA_IPV6_NEXTHOP_LOOKUP, "IPv6 Nexthop Lookup" },
110 /* Zebra route's types. */
111 #define ZEBRA_ROUTE_SYSTEM 0
112 #define ZEBRA_ROUTE_KERNEL 1
113 #define ZEBRA_ROUTE_CONNECT 2
114 #define ZEBRA_ROUTE_STATIC 3
115 #define ZEBRA_ROUTE_RIP 4
116 #define ZEBRA_ROUTE_RIPNG 5
117 #define ZEBRA_ROUTE_OSPF 6
118 #define ZEBRA_ROUTE_OSPF6 7
119 #define ZEBRA_ROUTE_BGP 8
121 static const value_string routes[] = {
122 { ZEBRA_ROUTE_SYSTEM, "System Route" },
123 { ZEBRA_ROUTE_KERNEL, "Kernel Route" },
124 { ZEBRA_ROUTE_CONNECT, "Connected Route" },
125 { ZEBRA_ROUTE_STATIC, "Static Route" },
126 { ZEBRA_ROUTE_RIP, "RIP Route" },
127 { ZEBRA_ROUTE_RIPNG, "RIPnG Route" },
128 { ZEBRA_ROUTE_OSPF, "OSPF Route" },
129 { ZEBRA_ROUTE_OSPF6, "OSPF6 Route" },
130 { ZEBRA_ROUTE_BGP, "BGP Route" },
134 /* Zebra's family types. */
135 #define ZEBRA_FAMILY_IPV4 1
136 #define ZEBRA_FAMILY_IPV6 2
138 static const value_string families[] = {
139 { ZEBRA_FAMILY_IPV4, "IPv4" },
140 { ZEBRA_FAMILY_IPV6, "IPv6" },
144 /* Error codes of zebra. */
145 #define ZEBRA_ERR_RTEXIST 1
146 #define ZEBRA_ERR_RTUNREACH 2
147 #define ZEBRA_ERR_EPERM 3
148 #define ZEBRA_ERR_RTNOEXIST 4
150 static const value_string errors[] = {
151 { ZEBRA_ERR_RTEXIST, "Route Exists" },
152 { ZEBRA_ERR_RTUNREACH, "Route Unreachable" },
153 { ZEBRA_ERR_EPERM, "Permission Denied" },
154 { ZEBRA_ERR_RTNOEXIST, "Route Does Not Exist" },
158 /* Zebra message flags */
159 #define ZEBRA_FLAG_INTERNAL 0x01
160 #define ZEBRA_FLAG_SELFROUTE 0x02
161 #define ZEBRA_FLAG_BLACKHOLE 0x04
163 /* Subsequent Address Family Identifier. */
164 #define ZEBRA_SAFI_UNICAST 1
165 #define ZEBRA_SAFI_MULTICAST 2
166 #define ZEBRA_SAFI_UNICAST_MULTICAST 3
167 #define ZEBRA_SAFI_MPLS_VPN 4
169 static const value_string safis[] = {
170 { ZEBRA_SAFI_UNICAST, "Unicast" },
171 { ZEBRA_SAFI_MULTICAST, "Multicast" },
172 { ZEBRA_SAFI_UNICAST_MULTICAST, "Unicast And Multicast" },
173 { ZEBRA_SAFI_MPLS_VPN, "MPLS VPN" },
177 /* Zebra API message flag. */
178 #define ZEBRA_ZAPI_MESSAGE_NEXTHOP 0x01
179 #define ZEBRA_ZAPI_MESSAGE_IFINDEX 0x02
180 #define ZEBRA_ZAPI_MESSAGE_DISTANCE 0x04
181 #define ZEBRA_ZAPI_MESSAGE_METRIC 0x08
183 #define INTERFACE_NAMSIZ 20
185 #define PSIZE(a) (((a) + 7) / (8))
188 dissect_zebra_request(proto_tree *tree, gboolean request, tvbuff_t *tvb,
189 int offset, guint16 len, guint8 command)
193 guint8 buffer6[16], prefixlen, message;
195 proto_tree *msg_tree;
197 proto_tree_add_uint(tree, hf_zebra_len, tvb, offset, 2, len);
199 proto_tree_add_uint(tree, hf_zebra_command, tvb, offset, 1,
203 case ZEBRA_INTERFACE_ADD:
204 case ZEBRA_INTERFACE_UP:
205 case ZEBRA_INTERFACE_DOWN:
207 /* Request just subscribes to messages */
209 proto_tree_add_item(tree, hf_zebra_interface,
210 tvb, offset, INTERFACE_NAMSIZ, FALSE);
211 offset += INTERFACE_NAMSIZ;
213 proto_tree_add_item(tree, hf_zebra_index, tvb,
217 proto_tree_add_item(tree, hf_zebra_intflags, tvb,
221 proto_tree_add_item(tree, hf_zebra_metric, tvb,
225 proto_tree_add_item(tree, hf_zebra_mtu, tvb,
229 proto_tree_add_item(tree, hf_zebra_bandwidth, tvb,
234 case ZEBRA_INTERFACE_DELETE:
235 proto_tree_add_item(tree, hf_zebra_interface,
236 tvb, offset, INTERFACE_NAMSIZ, FALSE);
237 offset += INTERFACE_NAMSIZ;
239 proto_tree_add_item(tree, hf_zebra_index, tvb,
243 case ZEBRA_INTERFACE_ADDRESS_ADD:
244 case ZEBRA_INTERFACE_ADDRESS_DELETE:
245 proto_tree_add_item(tree, hf_zebra_index, tvb,
249 proto_tree_add_item(tree, hf_zebra_family, tvb,
253 if (len == 17) { /* IPv4 */
254 proto_tree_add_item(tree, hf_zebra_prefix4,
255 tvb, offset, 4, FALSE);
258 else if (len == 41) { /* IPv6 */
259 proto_tree_add_item(tree, hf_zebra_prefix6,
260 tvb, offset, 16, FALSE);
265 proto_tree_add_item(tree, hf_zebra_prefixlen, tvb,
269 if (len == 17) { /* IPv4 */
270 proto_tree_add_item(tree, hf_zebra_dest4,
271 tvb, offset, 4, FALSE);
274 else if (len == 41) { /* IPv6 */
275 proto_tree_add_item(tree, hf_zebra_dest6,
276 tvb, offset, 16, FALSE);
281 case ZEBRA_IPV4_ROUTE_ADD:
282 case ZEBRA_IPV4_ROUTE_DELETE:
283 proto_tree_add_item(tree, hf_zebra_type, tvb,
287 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
291 message = tvb_get_guint8(tvb, offset);
292 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
294 msg_tree = proto_item_add_subtree(ti, ett_message);
295 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
296 tvb, offset, 1, message);
297 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
298 tvb, offset, 1, message);
299 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
300 tvb, offset, 1, message);
301 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
302 tvb, offset, 1, message);
305 prefixlen = tvb_get_guint8(tvb, offset);
306 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
307 offset, 1, prefixlen);
311 tvb_memcpy(tvb, (guint8 *)&prefix4, offset,
312 MIN((unsigned) PSIZE(prefixlen), sizeof prefix4));
313 proto_tree_add_ipv4(tree, hf_zebra_prefix4,
314 tvb, offset, PSIZE(prefixlen), prefix4);
315 offset += PSIZE(prefixlen);
317 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
318 i = tvb_get_guint8(tvb, offset);
319 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
323 if (i>len) break; /* Sanity */
326 proto_tree_add_item(tree,
327 hf_zebra_nexthop4, tvb,
332 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
333 i = tvb_get_guint8(tvb, offset);
334 proto_tree_add_uint(tree, hf_zebra_indexnum,
338 if (i>len) break; /* Sanity */
341 proto_tree_add_item(tree,
347 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
348 proto_tree_add_item(tree, hf_zebra_distance,
349 tvb, offset, 1, FALSE);
352 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
353 proto_tree_add_item(tree, hf_zebra_metric,
354 tvb, offset, 4, FALSE);
358 case ZEBRA_IPV6_ROUTE_ADD:
359 case ZEBRA_IPV6_ROUTE_DELETE:
360 proto_tree_add_item(tree, hf_zebra_type, tvb,
364 proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
368 message = tvb_get_guint8(tvb, offset);
369 ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
371 msg_tree = proto_item_add_subtree(ti, ett_message);
372 proto_tree_add_boolean(msg_tree, hf_zebra_msg_nexthop,
373 tvb, offset, 1, message);
374 proto_tree_add_boolean(msg_tree, hf_zebra_msg_index,
375 tvb, offset, 1, message);
376 proto_tree_add_boolean(msg_tree, hf_zebra_msg_distance,
377 tvb, offset, 1, message);
378 proto_tree_add_boolean(msg_tree, hf_zebra_msg_metric,
379 tvb, offset, 1, message);
382 prefixlen = tvb_get_guint8(tvb, offset);
383 proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
384 offset, 1, prefixlen);
387 memset(buffer6, '\0', sizeof buffer6);
388 tvb_memcpy(tvb, buffer6, offset,
389 MIN((unsigned) PSIZE(prefixlen), sizeof buffer6));
390 proto_tree_add_ipv6(tree, hf_zebra_prefix6,
391 tvb, offset, PSIZE(prefixlen), buffer6);
392 offset += PSIZE(prefixlen);
394 if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
395 i = tvb_get_guint8(tvb, offset);
396 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
400 if (i>len) break; /* Sanity */
403 proto_tree_add_item(tree,
404 hf_zebra_nexthop6, tvb,
409 if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
410 i = tvb_get_guint8(tvb, offset);
411 proto_tree_add_uint(tree, hf_zebra_indexnum,
415 if (i>len) break; /* Sanity */
418 proto_tree_add_item(tree,
424 if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
425 proto_tree_add_item(tree, hf_zebra_distance,
426 tvb, offset, 1, FALSE);
429 if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
430 proto_tree_add_item(tree, hf_zebra_metric,
431 tvb, offset, 4, FALSE);
435 case ZEBRA_REDISTRIBUTE_ADD:
436 case ZEBRA_REDISTRIBUTE_DELETE:
437 proto_tree_add_item(tree, hf_zebra_type, tvb,
441 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
442 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
444 case ZEBRA_IPV4_NEXTHOP_LOOKUP:
445 proto_tree_add_item(tree, hf_zebra_nexthop4,
446 tvb, offset, 4, FALSE);
449 proto_tree_add_item(tree, hf_zebra_metric,
450 tvb, offset, 4, FALSE);
453 case ZEBRA_IPV6_NEXTHOP_LOOKUP:
454 /* Not yet implemeted in ZEBRA */
460 dissect_zebra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
463 proto_tree *zebra_tree;
467 if (check_col(pinfo->cinfo, COL_PROTOCOL))
468 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZEBRA");
470 request = (pinfo->destport == pinfo->match_port);
471 left = tvb_reported_length(tvb);
474 if (check_col(pinfo->cinfo, COL_INFO)) {
475 col_set_str(pinfo->cinfo, COL_INFO,
476 request? "ZEBRA Request" : "ZEBRA Reply");
479 ti = proto_tree_add_item(tree, proto_zebra, tvb, offset, -1,
481 zebra_tree = proto_item_add_subtree(ti, ett_zebra);
482 proto_tree_add_boolean_hidden(zebra_tree, hf_zebra_request,
483 tvb, offset, 0, request);
488 proto_tree *zebra_request_tree;
492 len = tvb_get_ntohs(tvb, offset);
495 command = tvb_get_guint8(tvb, offset+2);
497 ti = proto_tree_add_uint(zebra_tree,
498 hf_zebra_command, tvb, offset, len,
500 zebra_request_tree = proto_item_add_subtree(ti,
502 dissect_zebra_request(zebra_request_tree, request, tvb,
503 offset, len, command);
512 proto_register_zebra(void)
515 static hf_register_info hf[] = {
517 { "Length", "zebra.len",
518 FT_UINT16, BASE_DEC, NULL, 0x0,
519 "Length of ZEBRA request", HFILL }},
521 { "Request", "zebra.request",
522 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
523 "TRUE if ZEBRA request", HFILL }},
525 { "Command", "zebra.command",
526 FT_UINT8, BASE_DEC, VALS(messages), 0x0,
527 "ZEBRA command", HFILL }},
528 { &hf_zebra_interface,
529 { "Interface", "zebra.interface",
530 FT_STRING, BASE_NONE, NULL, 0x0,
531 "Interface name of ZEBRA request", HFILL }},
533 { "Index", "zebra.index",
534 FT_UINT32, BASE_DEC, NULL, 0x0,
535 "Index of interface", HFILL }},
536 { &hf_zebra_indexnum,
537 { "Index Number", "zebra.indexnum",
538 FT_UINT8, BASE_DEC, NULL, 0x0,
539 "Number of indices for route", HFILL }},
540 { &hf_zebra_intflags,
541 { "Flags", "zebra.intflags",
542 FT_UINT32, BASE_DEC, NULL, 0x0,
543 "Flags of interface", HFILL }},
545 { "Flags", "zebra.rtflags",
546 FT_UINT8, BASE_DEC, NULL, 0x0,
547 "Flags of route", HFILL }},
549 { "Message", "zebra.message",
550 FT_UINT8, BASE_DEC, NULL, 0x0,
551 "Message type of route", HFILL }},
552 { &hf_zebra_msg_nexthop,
553 { "Message Nexthop", "zebra.message.nexthop",
554 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_NEXTHOP,
555 "Message contains nexthop", HFILL }},
556 { &hf_zebra_msg_index,
557 { "Message Index", "zebra.message.index",
558 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_IFINDEX,
559 "Message contains index", HFILL }},
560 { &hf_zebra_msg_distance,
561 { "Message Distance", "zebra.message.distance",
562 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_DISTANCE,
563 "Message contains distance", HFILL }},
564 { &hf_zebra_msg_metric,
565 { "Message Metric", "zebra.message.metric",
566 FT_BOOLEAN, 8, NULL, ZEBRA_ZAPI_MESSAGE_METRIC,
567 "Message contains metric", HFILL }},
569 { "Type", "zebra.type",
570 FT_UINT8, BASE_DEC, VALS(routes), 0x0,
571 "Type of route", HFILL }},
572 { &hf_zebra_distance,
573 { "Distance", "zebra.distance",
574 FT_UINT8, BASE_DEC, NULL, 0x0,
575 "Distance of route", HFILL }},
577 { "Metric", "zebra.metric",
578 FT_UINT32, BASE_DEC, NULL, 0x0,
579 "Metric of interface or route", HFILL }},
581 { "MTU", "zebra.mtu",
582 FT_UINT32, BASE_DEC, NULL, 0x0,
583 "MTU of interface", HFILL }},
584 { &hf_zebra_bandwidth,
585 { "Bandwidth", "zebra.bandwidth",
586 FT_UINT32, BASE_DEC, NULL, 0x0,
587 "Bandwidth of interface", HFILL }},
589 { "Family", "zebra.family",
590 FT_UINT32, BASE_DEC, NULL, 0x0,
591 "Family of IP address", HFILL }},
593 { "Destination", "zebra.dest4",
594 FT_IPv4, BASE_NONE, NULL, 0x0,
595 "Destination IPv4 field", HFILL }},
597 { "Destination", "zebra.dest6",
598 FT_IPv6, BASE_NONE, NULL, 0x0,
599 "Destination IPv6 field", HFILL }},
600 { &hf_zebra_nexthopnum,
601 { "Nexthop Number", "zebra.nexthopnum",
602 FT_UINT8, BASE_DEC, NULL, 0x0,
603 "Number of nexthops in route", HFILL }},
604 { &hf_zebra_nexthop4,
605 { "Nexthop", "zebra.nexthop4",
606 FT_IPv4, BASE_NONE, NULL, 0x0,
607 "Nethop IPv4 field of route", HFILL }},
608 { &hf_zebra_nexthop6,
609 { "Nexthop", "zebra.nexthop6",
610 FT_IPv6, BASE_NONE, NULL, 0x0,
611 "Nethop IPv6 field of route", HFILL }},
612 { &hf_zebra_prefixlen,
613 { "Prefix length", "zebra.prefixlen",
614 FT_UINT32, BASE_DEC, NULL, 0x0,
615 "Prefix length", HFILL }},
617 { "Prefix", "zebra.prefix4",
618 FT_IPv4, BASE_NONE, NULL, 0x0,
619 "Prefix IPv4", HFILL }},
621 { "Prefix", "zebra.prefix6",
622 FT_IPv6, BASE_NONE, NULL, 0x0,
623 "Prefix IPv6", HFILL }},
626 static gint *ett[] = {
632 proto_zebra = proto_register_protocol("Zebra Protocol", "ZEBRA", "zebra");
633 proto_register_field_array(proto_zebra, hf, array_length(hf));
634 proto_register_subtree_array(ett, array_length(ett));
638 proto_reg_handoff_zebra(void)
640 dissector_handle_t zebra_handle;
642 zebra_handle = create_dissector_handle(dissect_zebra, proto_zebra);
643 dissector_add("tcp.port", TCP_PORT_ZEBRA, zebra_handle);