Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-zebra.c
1 /* packet-zebra.c
2  * Routines for zebra packet disassembly
3  *
4  * Jochen Friedrich <jochen@scram.de>
5  *
6  * $Id: packet-zebra.c,v 1.22 2002/08/02 23:36:05 jmayer Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  * 
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.
16  * 
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.
21  * 
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.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <string.h>
32 #include <ctype.h>
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
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;
65
66 static gint ett_zebra = -1;
67 static gint ett_zebra_request = -1;
68 static gint ett_message = -1;
69
70 #define TCP_PORT_ZEBRA                  2600
71
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
89
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" },
107         { 0,                                    NULL },
108 };
109
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
120
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" },
131         { 0,                                    NULL },
132 };
133
134 /* Zebra's family types. */
135 #define ZEBRA_FAMILY_IPV4                1
136 #define ZEBRA_FAMILY_IPV6                2
137
138 static const value_string families[] = {
139         { ZEBRA_FAMILY_IPV4,                    "IPv4" },
140         { ZEBRA_FAMILY_IPV6,                    "IPv6" },
141         { 0,                                    NULL },
142 };
143
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
149
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" },
155         { 0,                                    NULL },
156 };
157
158 /* Zebra message flags */
159 #define ZEBRA_FLAG_INTERNAL           0x01
160 #define ZEBRA_FLAG_SELFROUTE          0x02
161 #define ZEBRA_FLAG_BLACKHOLE          0x04
162
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
168
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" },
174         { 0,                                    NULL },
175 };
176
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
182
183 #define INTERFACE_NAMSIZ      20
184
185 #define PSIZE(a) (((a) + 7) / (8))
186
187 static void
188 dissect_zebra_request(proto_tree *tree, gboolean request, tvbuff_t *tvb,
189         int offset, guint16 len, guint8 command)
190 {
191         guint32 prefix4;
192         guint16 i;
193         guint8  buffer6[16], prefixlen, message;
194         proto_item *ti;
195         proto_tree *msg_tree;
196
197         proto_tree_add_uint(tree, hf_zebra_len, tvb, offset, 2, len);
198         offset += 2;
199         proto_tree_add_uint(tree, hf_zebra_command, tvb, offset, 1,
200                 command);
201         offset += 1;
202         switch(command) {
203                 case ZEBRA_INTERFACE_ADD:
204                 case ZEBRA_INTERFACE_UP:
205                 case ZEBRA_INTERFACE_DOWN:
206                         if (request) break;
207                         /* Request just subscribes to messages */
208
209                         proto_tree_add_item(tree, hf_zebra_interface, 
210                                 tvb, offset, INTERFACE_NAMSIZ, FALSE);
211                         offset += INTERFACE_NAMSIZ;
212
213                         proto_tree_add_item(tree, hf_zebra_index, tvb,
214                                  offset, 4, FALSE);
215                         offset += 4;
216
217                         proto_tree_add_item(tree, hf_zebra_intflags, tvb,
218                                  offset, 4, FALSE);
219                         offset += 4;
220                         
221                         proto_tree_add_item(tree, hf_zebra_metric, tvb,
222                                  offset, 4, FALSE);
223                         offset += 4;
224
225                         proto_tree_add_item(tree, hf_zebra_mtu, tvb,
226                                  offset, 4, FALSE);
227                         offset += 4;
228
229                         proto_tree_add_item(tree, hf_zebra_bandwidth, tvb,
230                                  offset, 4, FALSE);
231                         offset += 4;
232
233                         break;
234                 case ZEBRA_INTERFACE_DELETE:
235                         proto_tree_add_item(tree, hf_zebra_interface,
236                                 tvb, offset, INTERFACE_NAMSIZ, FALSE);
237                         offset += INTERFACE_NAMSIZ;
238
239                         proto_tree_add_item(tree, hf_zebra_index, tvb,
240                                  offset, 4, FALSE);
241                         offset += 4;
242                         break;
243                 case ZEBRA_INTERFACE_ADDRESS_ADD:
244                 case ZEBRA_INTERFACE_ADDRESS_DELETE:
245                         proto_tree_add_item(tree, hf_zebra_index, tvb,
246                                  offset, 4, FALSE);
247                         offset += 4;
248
249                         proto_tree_add_item(tree, hf_zebra_family, tvb,
250                                  offset, 1, FALSE);
251                         offset += 1;
252
253                         if (len == 17) { /* IPv4 */
254                                 proto_tree_add_item(tree, hf_zebra_prefix4,
255                                         tvb, offset, 4, FALSE);
256                                 offset += 4;
257                         }
258                         else if (len == 41) { /* IPv6 */
259                                 proto_tree_add_item(tree, hf_zebra_prefix6,
260                                         tvb, offset, 16, FALSE);
261                                 offset += 16;
262                         }
263                         else break;
264
265                         proto_tree_add_item(tree, hf_zebra_prefixlen, tvb,
266                                  offset, 1, FALSE);
267                         offset += 1;
268
269                         if (len == 17) { /* IPv4 */
270                                 proto_tree_add_item(tree, hf_zebra_dest4,
271                                         tvb, offset, 4, FALSE);
272                                 offset += 4;
273                         }
274                         else if (len == 41) { /* IPv6 */
275                                 proto_tree_add_item(tree, hf_zebra_dest6,
276                                         tvb, offset, 16, FALSE);
277                                 offset += 16;
278                         }
279                         break;
280
281                 case ZEBRA_IPV4_ROUTE_ADD:
282                 case ZEBRA_IPV4_ROUTE_DELETE:
283                         proto_tree_add_item(tree, hf_zebra_type, tvb,
284                                  offset, 1, FALSE);
285                         offset += 1;
286
287                         proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
288                                  offset, 1, FALSE);
289                         offset += 1;
290
291                         message = tvb_get_guint8(tvb, offset);
292                         ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
293                                  offset, 1, message);
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);
303                         offset += 1;
304
305                         prefixlen = tvb_get_guint8(tvb, offset);
306                         proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
307                                  offset, 1, prefixlen);
308                         offset += 1;
309
310                         prefix4 = 0;
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);
316
317                         if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
318                                 i = tvb_get_guint8(tvb, offset);
319                                 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
320                                         tvb, offset, 1, i);
321                                 offset += 1;
322
323                                 if (i>len) break; /* Sanity */
324
325                                 while (i--) {
326                                         proto_tree_add_item(tree,
327                                                 hf_zebra_nexthop4, tvb,
328                                                 offset, 4, FALSE);
329                                         offset += 4;
330                                 }
331                         }
332                         if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
333                                 i = tvb_get_guint8(tvb, offset);
334                                 proto_tree_add_uint(tree, hf_zebra_indexnum,
335                                         tvb, offset, 1, i);
336                                 offset += 1;
337
338                                 if (i>len) break; /* Sanity */
339
340                                 while (i--) {
341                                         proto_tree_add_item(tree,
342                                                 hf_zebra_index, tvb,
343                                                 offset, 4, FALSE);
344                                         offset += 4;
345                                 }
346                         }
347                         if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
348                                 proto_tree_add_item(tree, hf_zebra_distance,
349                                         tvb, offset, 1, FALSE);
350                                 offset += 1;
351                         }
352                         if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
353                                 proto_tree_add_item(tree, hf_zebra_metric,
354                                         tvb, offset, 4, FALSE);
355                                 offset += 4;
356                         }
357                         break;
358                 case ZEBRA_IPV6_ROUTE_ADD:
359                 case ZEBRA_IPV6_ROUTE_DELETE:
360                         proto_tree_add_item(tree, hf_zebra_type, tvb,
361                                  offset, 1, FALSE);
362                         offset += 1;
363
364                         proto_tree_add_item(tree, hf_zebra_rtflags, tvb,
365                                  offset, 1, FALSE);
366                         offset += 1;
367
368                         message = tvb_get_guint8(tvb, offset);
369                         ti = proto_tree_add_uint(tree, hf_zebra_message, tvb,
370                                  offset, 1, message);
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);
380                         offset += 1;
381
382                         prefixlen = tvb_get_guint8(tvb, offset);
383                         proto_tree_add_uint(tree, hf_zebra_prefixlen, tvb,
384                                  offset, 1, prefixlen);
385                         offset += 1;
386
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);
393
394                         if (message & ZEBRA_ZAPI_MESSAGE_NEXTHOP) {
395                                 i = tvb_get_guint8(tvb, offset);
396                                 proto_tree_add_uint(tree, hf_zebra_nexthopnum,
397                                         tvb, offset, 1, i);
398                                 offset += 1;
399
400                                 if (i>len) break; /* Sanity */
401
402                                 while (i--) {
403                                         proto_tree_add_item(tree,
404                                                 hf_zebra_nexthop6, tvb,
405                                                 offset, 16, FALSE);
406                                         offset += 16;
407                                 }
408                         }
409                         if (message & ZEBRA_ZAPI_MESSAGE_IFINDEX) {
410                                 i = tvb_get_guint8(tvb, offset);
411                                 proto_tree_add_uint(tree, hf_zebra_indexnum,
412                                         tvb, offset, 1, i);
413                                 offset += 1;
414
415                                 if (i>len) break; /* Sanity */
416
417                                 while (i--) {
418                                         proto_tree_add_item(tree,
419                                                 hf_zebra_index, tvb,
420                                                 offset, 4, FALSE);
421                                         offset += 4;
422                                 }
423                         }
424                         if (message & ZEBRA_ZAPI_MESSAGE_DISTANCE) {
425                                 proto_tree_add_item(tree, hf_zebra_distance,
426                                         tvb, offset, 1, FALSE);
427                                 offset += 1;
428                         }
429                         if (message & ZEBRA_ZAPI_MESSAGE_METRIC) {
430                                 proto_tree_add_item(tree, hf_zebra_metric,
431                                         tvb, offset, 4, FALSE);
432                                 offset += 4;
433                         }
434                         break;
435                 case ZEBRA_REDISTRIBUTE_ADD:
436                 case ZEBRA_REDISTRIBUTE_DELETE:
437                         proto_tree_add_item(tree, hf_zebra_type, tvb,
438                                  offset, 1, FALSE);
439                         offset += 1;
440                         break;
441                 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
442                 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
443                         break;
444                 case ZEBRA_IPV4_NEXTHOP_LOOKUP:
445                         proto_tree_add_item(tree, hf_zebra_nexthop4,
446                                 tvb, offset, 4, FALSE);
447                         offset += 4;
448
449                         proto_tree_add_item(tree, hf_zebra_metric,
450                                 tvb, offset, 4, FALSE);
451                         offset += 4;
452                         break;
453                 case ZEBRA_IPV6_NEXTHOP_LOOKUP:
454                         /* Not yet implemeted in ZEBRA */
455                         break;
456         }
457 }
458                 
459 static void
460 dissect_zebra(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
461 {
462         proto_item      *ti;
463         proto_tree      *zebra_tree;
464         gboolean        request;
465         int             left, offset;
466
467         if (check_col(pinfo->cinfo, COL_PROTOCOL))
468                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZEBRA");
469
470         request = (pinfo->destport == pinfo->match_port);
471         left = tvb_reported_length(tvb);
472         offset = 0;
473
474         if (check_col(pinfo->cinfo, COL_INFO)) {
475                 col_set_str(pinfo->cinfo, COL_INFO, 
476                         request? "ZEBRA Request" : "ZEBRA Reply");
477         }
478         if (tree) {
479                 ti = proto_tree_add_item(tree, proto_zebra, tvb, offset, -1,
480                         FALSE);
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);
484
485                 for (;;) {
486                         guint8          command;
487                         guint16         len;
488                         proto_tree      *zebra_request_tree;
489                         
490                         if (left < 3) break;
491
492                         len = tvb_get_ntohs(tvb, offset);
493                         if (len < 3) break;
494
495                         command = tvb_get_guint8(tvb, offset+2);
496
497                         ti = proto_tree_add_uint(zebra_tree,
498                                 hf_zebra_command, tvb, offset, len,
499                                 command);
500                         zebra_request_tree = proto_item_add_subtree(ti,
501                                 ett_zebra_request);
502                         dissect_zebra_request(zebra_request_tree, request, tvb,
503                                 offset, len, command);
504
505                         offset += len;
506                         left -= len;
507                 }
508         }
509 }
510
511 void
512 proto_register_zebra(void)
513 {
514
515   static hf_register_info hf[] = {
516     { &hf_zebra_len,
517       { "Length",               "zebra.len",
518         FT_UINT16, BASE_DEC, NULL, 0x0,
519         "Length of ZEBRA request", HFILL }},
520     { &hf_zebra_request,
521       { "Request",              "zebra.request",
522         FT_BOOLEAN, BASE_NONE, NULL, 0x0,
523         "TRUE if ZEBRA request", HFILL }},
524     { &hf_zebra_command,
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 }},
532     { &hf_zebra_index,
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 }},
544     { &hf_zebra_rtflags,
545       { "Flags",                "zebra.rtflags",
546         FT_UINT8, BASE_DEC, NULL, 0x0,
547         "Flags of route", HFILL }},
548     { &hf_zebra_message,
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 }},
568     { &hf_zebra_type,
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 }},
576     { &hf_zebra_metric,
577       { "Metric",               "zebra.metric",
578         FT_UINT32, BASE_DEC, NULL, 0x0,
579         "Metric of interface or route", HFILL }},
580     { &hf_zebra_mtu,
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 }},
588     { &hf_zebra_family,
589       { "Family",               "zebra.family",
590         FT_UINT32, BASE_DEC, NULL, 0x0,
591         "Family of IP address", HFILL }},
592     { &hf_zebra_dest4,
593       { "Destination",          "zebra.dest4",
594         FT_IPv4, BASE_NONE, NULL, 0x0,
595         "Destination IPv4 field", HFILL }},
596     { &hf_zebra_dest6,
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 }},
616     { &hf_zebra_prefix4,
617       { "Prefix",               "zebra.prefix4",
618         FT_IPv4, BASE_NONE, NULL, 0x0,
619         "Prefix IPv4", HFILL }},
620     { &hf_zebra_prefix6,
621       { "Prefix",               "zebra.prefix6",
622         FT_IPv6, BASE_NONE, NULL, 0x0,
623         "Prefix IPv6", HFILL }},
624   };
625
626   static gint *ett[] = {
627     &ett_zebra,
628     &ett_zebra_request,
629     &ett_message,
630   };
631
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));
635 }
636
637 void
638 proto_reg_handoff_zebra(void)
639 {
640   dissector_handle_t zebra_handle;
641
642   zebra_handle = create_dissector_handle(dissect_zebra, proto_zebra);
643   dissector_add("tcp.port", TCP_PORT_ZEBRA, zebra_handle);
644 }