2 * Routines for PAgP (Port Aggregation Protocol - aka FEC) dissection
3 * Original Author Mark C. Brown <mbrown@hp.com>
4 * Copyright (C) 2004 Hewlett-Packard Development Company, L.P.
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-slowprotocols.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
35 #include <epan/etypes.h>
36 #include <epan/llcsaps.h>
37 #include <epan/ppptypes.h>
38 #include <epan/address.h>
39 #include <epan/addr_resolv.h>
41 /* Offsets of fields within a PagP PDU */
43 #define PAGP_VERSION_NUMBER 0
46 #define PAGP_LOCAL_DEVICE_ID 2
47 #define PAGP_LOCAL_LEARN_CAP 8
48 #define PAGP_LOCAL_PORT_PRIORITY 9
49 #define PAGP_LOCAL_SENT_PORT_IFINDEX 10
50 #define PAGP_LOCAL_GROUP_CAPABILITY 14
51 #define PAGP_LOCAL_GROUP_IFINDEX 18
52 #define PAGP_PARTNER_DEVICE_ID 22
53 #define PAGP_PARTNER_LEARN_CAP 28
54 #define PAGP_PARTNER_PORT_PRIORITY 29
55 #define PAGP_PARTNER_SENT_PORT_IFINDEX 30
56 #define PAGP_PARTNER_GROUP_CAPABILITY 34
57 #define PAGP_PARTNER_GROUP_IFINDEX 38
58 #define PAGP_PARTNER_COUNT 42
59 #define PAGP_NUM_TLVS 44
60 #define PAGP_FIRST_TLV 46
62 #define PAGP_FLUSH_LOCAL_DEVICE_ID 2
63 #define PAGP_FLUSH_PARTNER_DEVICE_ID 8
64 #define PAGP_FLUSH_TRANSACTION_ID 14
68 #define PAGP_INFO_PDU 1
69 #define PAGP_FLUSH_PDU 2
73 #define PAGP_FLAGS_SLOW_HELLO 0x01
74 #define PAGP_FLAGS_AUTO_MODE 0x02
75 #define PAGP_FLAGS_CONSISTENT_STATE 0x04
80 #define PAGP_TLV_DEVICE_NAME 1
81 #define PAGP_TLV_PORT_NAME 2
82 #define PAGP_TLV_AGPORT_MAC 3
83 #define PAGP_TLV_RESERVED 4
85 /* Initialise the protocol and registered fields */
87 static int proto_pagp = -1;
89 static int hf_pagp_version_number = -1;
91 static int hf_pagp_flags = -1;
92 static int hf_pagp_flags_slow_hello = -1;
93 static int hf_pagp_flags_auto_mode = -1;
94 static int hf_pagp_flags_consistent_state = -1;
95 static int hf_pagp_local_device_id = -1;
96 static int hf_pagp_local_learn_cap = -1;
97 static int hf_pagp_local_port_priority = -1;
98 static int hf_pagp_local_sent_port_ifindex = -1;
99 static int hf_pagp_local_group_capability = -1;
100 static int hf_pagp_local_group_ifindex = -1;
101 static int hf_pagp_partner_device_id = -1;
102 static int hf_pagp_partner_learn_cap = -1;
103 static int hf_pagp_partner_port_priority = -1;
104 static int hf_pagp_partner_sent_port_ifindex = -1;
105 static int hf_pagp_partner_group_capability = -1;
106 static int hf_pagp_partner_group_ifindex = -1;
107 static int hf_pagp_partner_count = -1;
108 static int hf_pagp_num_tlvs = -1;
109 static int hf_pagp_tlv = -1;
110 static int hf_pagp_tlv_device_name = -1;
111 static int hf_pagp_tlv_port_name = -1;
112 static int hf_pagp_tlv_agport_mac = -1;
114 static int hf_pagp_flush_local_device_id = -1;
115 static int hf_pagp_flush_partner_device_id = -1;
116 static int hf_pagp_flush_transaction_id = -1;
118 /* Initialise the subtree pointers */
120 static gint ett_pagp = -1;
121 static gint ett_pagp_flags = -1;
122 static gint ett_pagp_tlvs = -1;
124 /* General declarations and macros */
126 static const char initial_sep[] = " (";
127 static const char cont_sep[] = ", ";
129 static const value_string pdu_vers[] = {
135 static const value_string learn_cap[] = {
136 { 1, "Source-based Distribution" },
137 { 2, "Arbitrary Distribution" },
141 static const value_string tlv_types[] = {
142 { 1, "Device Name TLV" },
143 { 2, "Physical Port Name TLV" },
144 { 3, "Agport MAC Address" },
149 static const true_false_string automode = {
154 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
157 proto_item_append_text(item, string, sep); \
161 /* Code to actually dissect the PAGP packets */
163 dissect_pagp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
166 guint16 raw_half_word;
171 guint16 offset = PAGP_FIRST_TLV;
176 struct _address device_id;
182 proto_tree *pagp_tree = NULL;
183 proto_item *pagp_item;
184 proto_tree *flags_tree;
185 proto_item *flags_item;
186 proto_tree *tlv_tree;
187 proto_item *tlv_item;
193 device_id.type = AT_ETHER;
196 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PAGP"); /* PAGP Protocol */
198 col_clear(pinfo->cinfo, COL_INFO);
200 pinfo->current_proto = "PAGP";
202 raw_octet = tvb_get_guint8(tvb, PAGP_VERSION_NUMBER);
204 pagp_item = proto_tree_add_protocol_format(tree, proto_pagp, tvb,
205 0, -1, "Port Aggregation Protocol");
206 pagp_tree = proto_item_add_subtree(pagp_item, ett_pagp);
207 proto_tree_add_uint(pagp_tree, hf_pagp_version_number, tvb,
208 PAGP_VERSION_NUMBER, 1, raw_octet);
210 if (check_col(pinfo->cinfo, COL_INFO)) {
211 col_append_str(pinfo->cinfo, COL_INFO,
212 val_to_str(raw_octet, pdu_vers, "Unknown PDU version"));
215 if (raw_octet == PAGP_FLUSH_PDU) {
217 device_id.data = tvb_get_ptr(tvb, PAGP_FLUSH_LOCAL_DEVICE_ID, 6);
218 if (check_col(pinfo->cinfo, COL_INFO)) {
219 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
220 ep_address_to_str(&device_id));
223 proto_tree_add_ether(pagp_tree, hf_pagp_flush_local_device_id, tvb,
224 PAGP_FLUSH_LOCAL_DEVICE_ID, 6, device_id.data);
227 device_id.data = tvb_get_ptr(tvb, PAGP_FLUSH_PARTNER_DEVICE_ID, 6);
228 if (check_col(pinfo->cinfo, COL_INFO)) {
229 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
230 ep_address_to_str(&device_id));
233 proto_tree_add_ether(pagp_tree, hf_pagp_flush_partner_device_id, tvb,
234 PAGP_FLUSH_PARTNER_DEVICE_ID, 6, device_id.data);
237 raw_word = tvb_get_ntohl(tvb, PAGP_FLUSH_TRANSACTION_ID);
238 if (check_col(pinfo->cinfo, COL_INFO)) {
239 col_append_fstr(pinfo->cinfo, COL_INFO,
240 "; Transaction ID: 0x%x ", raw_word);
243 proto_tree_add_uint(pagp_tree, hf_pagp_flush_transaction_id, tvb,
244 PAGP_FLUSH_TRANSACTION_ID, 4, raw_word);
251 flags = tvb_get_guint8(tvb, PAGP_FLAGS);
252 if (check_col(pinfo->cinfo, COL_INFO)) {
253 col_append_fstr(pinfo->cinfo, COL_INFO, "; Flags 0x%x", flags);
257 flags_item = proto_tree_add_uint(pagp_tree, hf_pagp_flags, tvb,
258 PAGP_FLAGS, 1, flags);
259 flags_tree = proto_item_add_subtree(flags_item, ett_pagp_flags);
263 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_SLOW_HELLO, flags_item, "%sSlow Hello");
264 proto_tree_add_boolean(flags_tree, hf_pagp_flags_slow_hello, tvb,
265 PAGP_FLAGS, 1, flags);
267 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_AUTO_MODE, flags_item, "%sAuto Mode");
268 proto_tree_add_boolean(flags_tree, hf_pagp_flags_auto_mode, tvb,
269 PAGP_FLAGS, 1, flags);
271 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_CONSISTENT_STATE, flags_item,
272 "%sConsistent State");
273 proto_tree_add_boolean(flags_tree, hf_pagp_flags_consistent_state, tvb,
274 PAGP_FLAGS, 1, flags);
277 if (sep != initial_sep) {
278 /* We put something in; put in the terminating ")" */
279 proto_item_append_text(flags_item, ")");
283 device_id.data = tvb_get_ptr(tvb, PAGP_LOCAL_DEVICE_ID, 6);
284 if (check_col(pinfo->cinfo, COL_INFO)) {
285 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
286 ep_address_to_str(&device_id));
289 proto_tree_add_ether(pagp_tree, hf_pagp_local_device_id, tvb,
290 PAGP_LOCAL_DEVICE_ID, 6, device_id.data);
294 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_LEARN_CAP);
295 proto_tree_add_uint(pagp_tree, hf_pagp_local_learn_cap, tvb,
296 PAGP_LOCAL_LEARN_CAP, 1, raw_octet);
298 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_PORT_PRIORITY);
299 proto_tree_add_uint(pagp_tree, hf_pagp_local_port_priority, tvb,
300 PAGP_LOCAL_PORT_PRIORITY, 1, raw_octet);
302 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_SENT_PORT_IFINDEX);
303 proto_tree_add_uint(pagp_tree, hf_pagp_local_sent_port_ifindex, tvb,
304 PAGP_LOCAL_SENT_PORT_IFINDEX, 4, raw_word);
306 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_CAPABILITY);
307 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_capability, tvb,
308 PAGP_LOCAL_GROUP_CAPABILITY, 4, raw_word);
310 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_IFINDEX);
311 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_ifindex, tvb,
312 PAGP_LOCAL_GROUP_IFINDEX, 4, raw_word);
315 device_id.data = tvb_get_ptr(tvb, PAGP_PARTNER_DEVICE_ID, 6);
316 if (check_col(pinfo->cinfo, COL_INFO)) {
317 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
318 ep_address_to_str(&device_id));
321 proto_tree_add_ether(pagp_tree, hf_pagp_partner_device_id, tvb,
322 PAGP_PARTNER_DEVICE_ID, 6, device_id.data);
326 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_LEARN_CAP);
327 proto_tree_add_uint(pagp_tree, hf_pagp_partner_learn_cap, tvb,
328 PAGP_PARTNER_LEARN_CAP, 1, raw_octet);
330 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_PORT_PRIORITY);
331 proto_tree_add_uint(pagp_tree, hf_pagp_partner_port_priority, tvb,
332 PAGP_PARTNER_PORT_PRIORITY, 1, raw_octet);
334 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_SENT_PORT_IFINDEX);
335 proto_tree_add_uint(pagp_tree, hf_pagp_partner_sent_port_ifindex, tvb,
336 PAGP_PARTNER_SENT_PORT_IFINDEX, 4, raw_word);
338 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_CAPABILITY);
339 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_capability, tvb,
340 PAGP_PARTNER_GROUP_CAPABILITY, 4, raw_word);
342 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_IFINDEX);
343 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_ifindex, tvb,
344 PAGP_PARTNER_GROUP_IFINDEX, 4, raw_word);
346 raw_half_word = tvb_get_ntohs(tvb, PAGP_PARTNER_COUNT);
347 proto_tree_add_uint(pagp_tree, hf_pagp_partner_count, tvb,
348 PAGP_PARTNER_COUNT, 2, raw_half_word);
350 num_tlvs = tvb_get_ntohs(tvb, PAGP_NUM_TLVS);
351 proto_tree_add_uint(pagp_tree, hf_pagp_num_tlvs, tvb,
352 PAGP_NUM_TLVS, 2, num_tlvs);
354 /* dump TLV entries */
356 for ( i = 1; i <= num_tlvs; i++ ) {
358 tlv = tvb_get_ntohs(tvb, offset);
359 len = tvb_get_ntohs(tvb, offset + 2);
361 proto_tree_add_text(pagp_tree, tvb, offset, -1,
362 "Unknown data - TLV len=0");
366 tlv_item = proto_tree_add_text (pagp_tree, tvb, offset, len,
369 tlv_tree = proto_item_add_subtree (tlv_item, ett_pagp_tlvs);
370 proto_tree_add_uint_format (tlv_tree, hf_pagp_tlv, tvb,
371 offset,2,tlv,"Type = %d (%s)", tlv,
372 val_to_str(tlv,tlv_types, "Unknown")) ;
373 proto_tree_add_text (tlv_tree, tvb, offset+2, 2,
374 "Length = %u bytes (includes Type and Length)", len) ;
375 if ( tvb_reported_length_remaining(tvb, offset) < len ) {
376 proto_tree_add_text(tlv_tree, tvb, offset, -1,
377 "TLV length too large");
382 case PAGP_TLV_DEVICE_NAME:
383 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
384 proto_tree_add_string(tlv_tree, hf_pagp_tlv_device_name,
385 tvb, offset+4, len-4, ch);
387 case PAGP_TLV_PORT_NAME:
388 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
389 proto_tree_add_string(tlv_tree, hf_pagp_tlv_port_name,
390 tvb, offset+4, len-4, ch);
392 case PAGP_TLV_AGPORT_MAC:
393 p_sys = tvb_get_ptr(tvb, offset+4, 6);
394 proto_tree_add_ether(tlv_tree, hf_pagp_tlv_agport_mac,
395 tvb, offset+4, 6, p_sys);
397 case PAGP_TLV_RESERVED:
408 /* Register the protocol with Wireshark */
411 proto_register_pagp(void)
413 /* Setup list of header fields */
415 static hf_register_info hf[] = {
417 { &hf_pagp_version_number,
418 { "Version", "pagp.version",
419 FT_UINT8, BASE_HEX, VALS(pdu_vers), 0x0,
420 "Identifies the PAgP PDU version: 1 = Info, 2 = Flush", HFILL }},
423 { "Flags", "pagp.flags",
424 FT_UINT8, BASE_HEX, NULL, 0x0,
425 "Information flags", HFILL }},
427 { &hf_pagp_flags_slow_hello,
428 { "Slow Hello", "pagp.flags.slowhello",
429 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PAGP_FLAGS_SLOW_HELLO,
430 "1 = using Slow Hello, 0 = Slow Hello disabled", HFILL }},
432 { &hf_pagp_flags_auto_mode,
433 { "Auto Mode", "pagp.flags.automode",
434 FT_BOOLEAN, 8, TFS(&automode), PAGP_FLAGS_AUTO_MODE,
435 "1 = Auto Mode enabled, 0 = Desirable Mode", HFILL }},
437 { &hf_pagp_flags_consistent_state,
438 { "Consistent State", "pagp.flags.state",
439 FT_BOOLEAN, 8, NULL, PAGP_FLAGS_CONSISTENT_STATE,
440 "1 = Consistent State, 0 = Not Ready", HFILL }},
442 { &hf_pagp_local_device_id,
443 { "Local Device ID", "pagp.localdevid",
444 FT_ETHER, BASE_NONE, NULL, 0x0,
445 "Local device ID", HFILL }},
447 { &hf_pagp_local_learn_cap,
448 { "Local Learn Capability", "pagp.localearncap",
449 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
450 "Local learn capability", HFILL }},
452 { &hf_pagp_local_port_priority,
453 { "Local Port Hot Standby Priority", "pagp.localportpri",
454 FT_UINT8, BASE_DEC, NULL, 0x0,
455 "The local hot standby priority assigned to this port", HFILL }},
457 { &hf_pagp_local_sent_port_ifindex,
458 { "Local Sent Port ifindex", "pagp.localsentportifindex",
459 FT_UINT32, BASE_DEC, NULL, 0x0,
460 "The interface index of the local port used to send PDU", HFILL }},
462 { &hf_pagp_local_group_capability,
463 { "Local Group Capability", "pagp.localgroupcap",
464 FT_UINT32, BASE_HEX, NULL, 0x0,
465 "The local group capability", HFILL }},
467 { &hf_pagp_local_group_ifindex,
468 { "Local Group ifindex", "pagp.localgroupifindex",
469 FT_UINT32, BASE_DEC, NULL, 0x0,
470 "The local group interface index", HFILL }},
472 { &hf_pagp_partner_device_id,
473 { "Partner Device ID", "pagp.partnerdevid",
474 FT_ETHER, BASE_NONE, NULL, 0x0,
475 "Remote Device ID (MAC)", HFILL }},
477 { &hf_pagp_partner_learn_cap,
478 { "Partner Learn Capability", "pagp.partnerlearncap",
479 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
480 "Remote learn capability", HFILL }},
482 { &hf_pagp_partner_port_priority,
483 { "Partner Port Hot Standby Priority", "pagp.partnerportpri",
484 FT_UINT8, BASE_DEC, NULL, 0x0,
485 "Remote port priority", HFILL }},
487 { &hf_pagp_partner_sent_port_ifindex,
488 { "Partner Sent Port ifindex", "pagp.partnersentportifindex",
489 FT_UINT32, BASE_DEC, NULL, 0x0,
490 "Remote port interface index sent", HFILL }},
492 { &hf_pagp_partner_group_capability,
493 { "Partner Group Capability", "pagp.partnergroupcap",
494 FT_UINT32, BASE_HEX, NULL, 0x0,
495 "Remote group capability", HFILL }},
497 { &hf_pagp_partner_group_ifindex,
498 { "Partner Group ifindex", "pagp.partnergroupifindex",
499 FT_UINT32, BASE_DEC, NULL, 0x0,
500 "Remote group interface index", HFILL }},
502 { &hf_pagp_partner_count,
503 { "Partner Count", "pagp.partnercount",
504 FT_UINT16, BASE_DEC, NULL, 0x0,
505 "Partner count", HFILL }},
508 { "Number of TLVs", "pagp.numtlvs",
509 FT_UINT16, BASE_DEC, NULL, 0x0,
510 "Number of TLVs following", HFILL }},
513 { "Entry", "pagp.tlv",
514 FT_UINT16, BASE_DEC, NULL, 0x0,
515 "Type/Length/Value", HFILL }},
517 { &hf_pagp_tlv_device_name,
518 { "Device Name", "pagp.tlvdevname",
519 FT_STRING, BASE_NONE, NULL, 0x0,
520 "sysName of device", HFILL }},
522 { &hf_pagp_tlv_port_name,
523 { "Physical Port Name", "pagp.tlvportname",
524 FT_STRING, BASE_NONE, NULL, 0x0,
525 "Name of port used to send PDU", HFILL }},
527 { &hf_pagp_tlv_agport_mac,
528 { "Agport MAC Address", "pagp.tlvagportmac",
529 FT_ETHER, BASE_NONE, NULL, 0x0,
530 "Source MAC on frames for this aggregate", HFILL }},
532 { &hf_pagp_flush_local_device_id,
533 { "Flush Local Device ID", "pagp.flushlocaldevid",
534 FT_ETHER, BASE_NONE, NULL, 0x0,
535 "Flush local device ID", HFILL }},
537 { &hf_pagp_flush_partner_device_id,
538 { "Flush Partner Device ID", "pagp.flushpartnerdevid",
539 FT_ETHER, BASE_NONE, NULL, 0x0,
540 "Flush remote device ID", HFILL }},
542 { &hf_pagp_flush_transaction_id,
543 { "Transaction ID", "pagp.transid",
544 FT_UINT32, BASE_HEX, NULL, 0x0,
545 "Flush transaction ID", HFILL }},
549 /* Setup protocol subtree array */
551 static gint *ett[] = {
557 /* Register the protocol name and description */
559 proto_pagp = proto_register_protocol("Port Aggregation Protocol", "PAGP", "pagp");
561 /* Required function calls to register the header fields and subtrees used */
563 proto_register_field_array(proto_pagp, hf, array_length(hf));
564 proto_register_subtree_array(ett, array_length(ett));
570 proto_reg_handoff_pagp(void)
572 dissector_handle_t pagp_handle;
574 pagp_handle = create_dissector_handle(dissect_pagp, proto_pagp);
575 dissector_add("llc.cisco_pid", 0x0104, pagp_handle);