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.
36 #include <epan/packet.h>
37 #include <epan/etypes.h>
38 #include <epan/llcsaps.h>
39 #include <epan/ppptypes.h>
40 #include <epan/address.h>
41 #include <epan/addr_resolv.h>
43 /* Offsets of fields within a PagP PDU */
45 #define PAGP_VERSION_NUMBER 0
48 #define PAGP_LOCAL_DEVICE_ID 2
49 #define PAGP_LOCAL_LEARN_CAP 8
50 #define PAGP_LOCAL_PORT_PRIORITY 9
51 #define PAGP_LOCAL_SENT_PORT_IFINDEX 10
52 #define PAGP_LOCAL_GROUP_CAPABILITY 14
53 #define PAGP_LOCAL_GROUP_IFINDEX 18
54 #define PAGP_PARTNER_DEVICE_ID 22
55 #define PAGP_PARTNER_LEARN_CAP 28
56 #define PAGP_PARTNER_PORT_PRIORITY 29
57 #define PAGP_PARTNER_SENT_PORT_IFINDEX 30
58 #define PAGP_PARTNER_GROUP_CAPABILITY 34
59 #define PAGP_PARTNER_GROUP_IFINDEX 38
60 #define PAGP_PARTNER_COUNT 42
61 #define PAGP_NUM_TLVS 44
62 #define PAGP_FIRST_TLV 46
64 #define PAGP_FLUSH_LOCAL_DEVICE_ID 2
65 #define PAGP_FLUSH_PARTNER_DEVICE_ID 8
66 #define PAGP_FLUSH_TRANSACTION_ID 14
70 #define PAGP_INFO_PDU 1
71 #define PAGP_FLUSH_PDU 2
75 #define PAGP_FLAGS_SLOW_HELLO 0x01
76 #define PAGP_FLAGS_AUTO_MODE 0x02
77 #define PAGP_FLAGS_CONSISTENT_STATE 0x04
82 #define PAGP_TLV_DEVICE_NAME 1
83 #define PAGP_TLV_PORT_NAME 2
84 #define PAGP_TLV_AGPORT_MAC 3
85 #define PAGP_TLV_RESERVED 4
87 /* Initialise the protocol and registered fields */
89 static int proto_pagp = -1;
91 static int hf_pagp_version_number = -1;
93 static int hf_pagp_flags = -1;
94 static int hf_pagp_flags_slow_hello = -1;
95 static int hf_pagp_flags_auto_mode = -1;
96 static int hf_pagp_flags_consistent_state = -1;
97 static int hf_pagp_local_device_id = -1;
98 static int hf_pagp_local_learn_cap = -1;
99 static int hf_pagp_local_port_priority = -1;
100 static int hf_pagp_local_sent_port_ifindex = -1;
101 static int hf_pagp_local_group_capability = -1;
102 static int hf_pagp_local_group_ifindex = -1;
103 static int hf_pagp_partner_device_id = -1;
104 static int hf_pagp_partner_learn_cap = -1;
105 static int hf_pagp_partner_port_priority = -1;
106 static int hf_pagp_partner_sent_port_ifindex = -1;
107 static int hf_pagp_partner_group_capability = -1;
108 static int hf_pagp_partner_group_ifindex = -1;
109 static int hf_pagp_partner_count = -1;
110 static int hf_pagp_num_tlvs = -1;
111 static int hf_pagp_tlv = -1;
112 static int hf_pagp_tlv_device_name = -1;
113 static int hf_pagp_tlv_port_name = -1;
114 static int hf_pagp_tlv_agport_mac = -1;
116 static int hf_pagp_flush_local_device_id = -1;
117 static int hf_pagp_flush_partner_device_id = -1;
118 static int hf_pagp_flush_transaction_id = -1;
120 /* Initialise the subtree pointers */
122 static gint ett_pagp = -1;
123 static gint ett_pagp_flags = -1;
124 static gint ett_pagp_tlvs = -1;
126 /* General declarations and macros */
128 static const char initial_sep[] = " (";
129 static const char cont_sep[] = ", ";
131 static const value_string pdu_vers[] = {
137 static const value_string learn_cap[] = {
138 { 1, "Source-based Distribution" },
139 { 2, "Arbitrary Distribution" },
143 static const value_string tlv_types[] = {
144 { 1, "Device Name TLV" },
145 { 2, "Physical Port Name TLV" },
146 { 3, "Agport MAC Address" },
151 static const true_false_string automode = {
156 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
159 proto_item_append_text(item, string, sep); \
163 /* Code to actually dissect the PAGP packets */
165 dissect_pagp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
168 guint16 raw_half_word;
173 guint16 offset = PAGP_FIRST_TLV;
178 struct _address device_id;
184 proto_tree *pagp_tree = NULL;
185 proto_item *pagp_item;
186 proto_tree *flags_tree;
187 proto_item *flags_item;
188 proto_tree *tlv_tree;
189 proto_item *tlv_item;
195 device_id.type = AT_ETHER;
198 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PAGP"); /* PAGP Protocol */
200 col_clear(pinfo->cinfo, COL_INFO);
202 pinfo->current_proto = "PAGP";
204 raw_octet = tvb_get_guint8(tvb, PAGP_VERSION_NUMBER);
206 pagp_item = proto_tree_add_protocol_format(tree, proto_pagp, tvb,
207 0, -1, "Port Aggregation Protocol");
208 pagp_tree = proto_item_add_subtree(pagp_item, ett_pagp);
209 proto_tree_add_uint(pagp_tree, hf_pagp_version_number, tvb,
210 PAGP_VERSION_NUMBER, 1, raw_octet);
212 if (check_col(pinfo->cinfo, COL_INFO)) {
213 col_append_str(pinfo->cinfo, COL_INFO,
214 val_to_str(raw_octet, pdu_vers, "Unknown PDU version"));
217 if (raw_octet == PAGP_FLUSH_PDU) {
219 device_id.data = tvb_get_ptr(tvb, PAGP_FLUSH_LOCAL_DEVICE_ID, 6);
220 if (check_col(pinfo->cinfo, COL_INFO)) {
221 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
222 ep_address_to_str(&device_id));
225 proto_tree_add_ether(pagp_tree, hf_pagp_flush_local_device_id, tvb,
226 PAGP_FLUSH_LOCAL_DEVICE_ID, 6, device_id.data);
229 device_id.data = tvb_get_ptr(tvb, PAGP_FLUSH_PARTNER_DEVICE_ID, 6);
230 if (check_col(pinfo->cinfo, COL_INFO)) {
231 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
232 ep_address_to_str(&device_id));
235 proto_tree_add_ether(pagp_tree, hf_pagp_flush_partner_device_id, tvb,
236 PAGP_FLUSH_PARTNER_DEVICE_ID, 6, device_id.data);
239 raw_word = tvb_get_ntohl(tvb, PAGP_FLUSH_TRANSACTION_ID);
240 if (check_col(pinfo->cinfo, COL_INFO)) {
241 col_append_fstr(pinfo->cinfo, COL_INFO,
242 "; Transaction ID: 0x%x ", raw_word);
245 proto_tree_add_uint(pagp_tree, hf_pagp_flush_transaction_id, tvb,
246 PAGP_FLUSH_TRANSACTION_ID, 4, raw_word);
253 flags = tvb_get_guint8(tvb, PAGP_FLAGS);
254 if (check_col(pinfo->cinfo, COL_INFO)) {
255 col_append_fstr(pinfo->cinfo, COL_INFO, "; Flags 0x%x", flags);
259 flags_item = proto_tree_add_uint(pagp_tree, hf_pagp_flags, tvb,
260 PAGP_FLAGS, 1, flags);
261 flags_tree = proto_item_add_subtree(flags_item, ett_pagp_flags);
265 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_SLOW_HELLO, flags_item, "%sSlow Hello");
266 proto_tree_add_boolean(flags_tree, hf_pagp_flags_slow_hello, tvb,
267 PAGP_FLAGS, 1, flags);
269 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_AUTO_MODE, flags_item, "%sAuto Mode");
270 proto_tree_add_boolean(flags_tree, hf_pagp_flags_auto_mode, tvb,
271 PAGP_FLAGS, 1, flags);
273 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_CONSISTENT_STATE, flags_item,
274 "%sConsistent State");
275 proto_tree_add_boolean(flags_tree, hf_pagp_flags_consistent_state, tvb,
276 PAGP_FLAGS, 1, flags);
279 if (sep != initial_sep) {
280 /* We put something in; put in the terminating ")" */
281 proto_item_append_text(flags_item, ")");
285 device_id.data = tvb_get_ptr(tvb, PAGP_LOCAL_DEVICE_ID, 6);
286 if (check_col(pinfo->cinfo, COL_INFO)) {
287 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
288 ep_address_to_str(&device_id));
291 proto_tree_add_ether(pagp_tree, hf_pagp_local_device_id, tvb,
292 PAGP_LOCAL_DEVICE_ID, 6, device_id.data);
296 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_LEARN_CAP);
297 proto_tree_add_uint(pagp_tree, hf_pagp_local_learn_cap, tvb,
298 PAGP_LOCAL_LEARN_CAP, 1, raw_octet);
300 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_PORT_PRIORITY);
301 proto_tree_add_uint(pagp_tree, hf_pagp_local_port_priority, tvb,
302 PAGP_LOCAL_PORT_PRIORITY, 1, raw_octet);
304 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_SENT_PORT_IFINDEX);
305 proto_tree_add_uint(pagp_tree, hf_pagp_local_sent_port_ifindex, tvb,
306 PAGP_LOCAL_SENT_PORT_IFINDEX, 4, raw_word);
308 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_CAPABILITY);
309 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_capability, tvb,
310 PAGP_LOCAL_GROUP_CAPABILITY, 4, raw_word);
312 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_IFINDEX);
313 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_ifindex, tvb,
314 PAGP_LOCAL_GROUP_IFINDEX, 4, raw_word);
317 device_id.data = tvb_get_ptr(tvb, PAGP_PARTNER_DEVICE_ID, 6);
318 if (check_col(pinfo->cinfo, COL_INFO)) {
319 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
320 ep_address_to_str(&device_id));
323 proto_tree_add_ether(pagp_tree, hf_pagp_partner_device_id, tvb,
324 PAGP_PARTNER_DEVICE_ID, 6, device_id.data);
328 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_LEARN_CAP);
329 proto_tree_add_uint(pagp_tree, hf_pagp_partner_learn_cap, tvb,
330 PAGP_PARTNER_LEARN_CAP, 1, raw_octet);
332 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_PORT_PRIORITY);
333 proto_tree_add_uint(pagp_tree, hf_pagp_partner_port_priority, tvb,
334 PAGP_PARTNER_PORT_PRIORITY, 1, raw_octet);
336 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_SENT_PORT_IFINDEX);
337 proto_tree_add_uint(pagp_tree, hf_pagp_partner_sent_port_ifindex, tvb,
338 PAGP_PARTNER_SENT_PORT_IFINDEX, 4, raw_word);
340 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_CAPABILITY);
341 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_capability, tvb,
342 PAGP_PARTNER_GROUP_CAPABILITY, 4, raw_word);
344 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_IFINDEX);
345 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_ifindex, tvb,
346 PAGP_PARTNER_GROUP_IFINDEX, 4, raw_word);
348 raw_half_word = tvb_get_ntohs(tvb, PAGP_PARTNER_COUNT);
349 proto_tree_add_uint(pagp_tree, hf_pagp_partner_count, tvb,
350 PAGP_PARTNER_COUNT, 2, raw_half_word);
352 num_tlvs = tvb_get_ntohs(tvb, PAGP_NUM_TLVS);
353 proto_tree_add_uint(pagp_tree, hf_pagp_num_tlvs, tvb,
354 PAGP_NUM_TLVS, 2, num_tlvs);
356 /* dump TLV entries */
358 for ( i = 1; i <= num_tlvs; i++ ) {
360 tlv = tvb_get_ntohs(tvb, offset);
361 len = tvb_get_ntohs(tvb, offset + 2);
363 proto_tree_add_text(pagp_tree, tvb, offset, -1,
364 "Unknown data - TLV len=0");
368 tlv_item = proto_tree_add_text (pagp_tree, tvb, offset, len,
371 tlv_tree = proto_item_add_subtree (tlv_item, ett_pagp_tlvs);
372 proto_tree_add_uint_format (tlv_tree, hf_pagp_tlv, tvb,
373 offset,2,tlv,"Type = %d (%s)", tlv,
374 val_to_str(tlv,tlv_types, "Unknown")) ;
375 proto_tree_add_text (tlv_tree, tvb, offset+2, 2,
376 "Length = %u bytes (includes Type and Length)", len) ;
377 if ( tvb_reported_length_remaining(tvb, offset) < len ) {
378 proto_tree_add_text(tlv_tree, tvb, offset, -1,
379 "TLV length too large");
384 case PAGP_TLV_DEVICE_NAME:
385 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
386 proto_tree_add_string(tlv_tree, hf_pagp_tlv_device_name,
387 tvb, offset+4, len-4, ch);
389 case PAGP_TLV_PORT_NAME:
390 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
391 proto_tree_add_string(tlv_tree, hf_pagp_tlv_port_name,
392 tvb, offset+4, len-4, ch);
394 case PAGP_TLV_AGPORT_MAC:
395 p_sys = tvb_get_ptr(tvb, offset+4, 6);
396 proto_tree_add_ether(tlv_tree, hf_pagp_tlv_agport_mac,
397 tvb, offset+4, 6, p_sys);
399 case PAGP_TLV_RESERVED:
410 /* Register the protocol with Wireshark */
413 proto_register_pagp(void)
415 /* Setup list of header fields */
417 static hf_register_info hf[] = {
419 { &hf_pagp_version_number,
420 { "Version", "pagp.version",
421 FT_UINT8, BASE_HEX, VALS(pdu_vers), 0x0,
422 "Identifies the PAgP PDU version: 1 = Info, 2 = Flush", HFILL }},
425 { "Flags", "pagp.flags",
426 FT_UINT8, BASE_HEX, NULL, 0x0,
427 "Information flags", HFILL }},
429 { &hf_pagp_flags_slow_hello,
430 { "Slow Hello", "pagp.flags.slowhello",
431 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PAGP_FLAGS_SLOW_HELLO,
432 "1 = using Slow Hello, 0 = Slow Hello disabled", HFILL }},
434 { &hf_pagp_flags_auto_mode,
435 { "Auto Mode", "pagp.flags.automode",
436 FT_BOOLEAN, 8, TFS(&automode), PAGP_FLAGS_AUTO_MODE,
437 "1 = Auto Mode enabled, 0 = Desirable Mode", HFILL }},
439 { &hf_pagp_flags_consistent_state,
440 { "Consistent State", "pagp.flags.state",
441 FT_BOOLEAN, 8, NULL, PAGP_FLAGS_CONSISTENT_STATE,
442 "1 = Consistent State, 0 = Not Ready", HFILL }},
444 { &hf_pagp_local_device_id,
445 { "Local Device ID", "pagp.localdevid",
446 FT_ETHER, BASE_NONE, NULL, 0x0,
447 "Local device ID", HFILL }},
449 { &hf_pagp_local_learn_cap,
450 { "Local Learn Capability", "pagp.localearncap",
451 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
452 "Local learn capability", HFILL }},
454 { &hf_pagp_local_port_priority,
455 { "Local Port Hot Standby Priority", "pagp.localportpri",
456 FT_UINT8, BASE_DEC, NULL, 0x0,
457 "The local hot standby priority assigned to this port", HFILL }},
459 { &hf_pagp_local_sent_port_ifindex,
460 { "Local Sent Port ifindex", "pagp.localsentportifindex",
461 FT_UINT32, BASE_DEC, NULL, 0x0,
462 "The interface index of the local port used to send PDU", HFILL }},
464 { &hf_pagp_local_group_capability,
465 { "Local Group Capability", "pagp.localgroupcap",
466 FT_UINT32, BASE_HEX, NULL, 0x0,
467 "The local group capability", HFILL }},
469 { &hf_pagp_local_group_ifindex,
470 { "Local Group ifindex", "pagp.localgroupifindex",
471 FT_UINT32, BASE_DEC, NULL, 0x0,
472 "The local group interface index", HFILL }},
474 { &hf_pagp_partner_device_id,
475 { "Partner Device ID", "pagp.partnerdevid",
476 FT_ETHER, BASE_NONE, NULL, 0x0,
477 "Remote Device ID (MAC)", HFILL }},
479 { &hf_pagp_partner_learn_cap,
480 { "Partner Learn Capability", "pagp.partnerlearncap",
481 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
482 "Remote learn capability", HFILL }},
484 { &hf_pagp_partner_port_priority,
485 { "Partner Port Hot Standby Priority", "pagp.partnerportpri",
486 FT_UINT8, BASE_DEC, NULL, 0x0,
487 "Remote port priority", HFILL }},
489 { &hf_pagp_partner_sent_port_ifindex,
490 { "Partner Sent Port ifindex", "pagp.partnersentportifindex",
491 FT_UINT32, BASE_DEC, NULL, 0x0,
492 "Remote port interface index sent", HFILL }},
494 { &hf_pagp_partner_group_capability,
495 { "Partner Group Capability", "pagp.partnergroupcap",
496 FT_UINT32, BASE_HEX, NULL, 0x0,
497 "Remote group capability", HFILL }},
499 { &hf_pagp_partner_group_ifindex,
500 { "Partner Group ifindex", "pagp.partnergroupifindex",
501 FT_UINT32, BASE_DEC, NULL, 0x0,
502 "Remote group interface index", HFILL }},
504 { &hf_pagp_partner_count,
505 { "Partner Count", "pagp.partnercount",
506 FT_UINT16, BASE_DEC, NULL, 0x0,
507 "Partner count", HFILL }},
510 { "Number of TLVs", "pagp.numtlvs",
511 FT_UINT16, BASE_DEC, NULL, 0x0,
512 "Number of TLVs following", HFILL }},
515 { "Entry", "pagp.tlv",
516 FT_UINT16, BASE_DEC, NULL, 0x0,
517 "Type/Length/Value", HFILL }},
519 { &hf_pagp_tlv_device_name,
520 { "Device Name", "pagp.tlvdevname",
521 FT_STRING, BASE_NONE, NULL, 0x0,
522 "sysName of device", HFILL }},
524 { &hf_pagp_tlv_port_name,
525 { "Physical Port Name", "pagp.tlvportname",
526 FT_STRING, BASE_NONE, NULL, 0x0,
527 "Name of port used to send PDU", HFILL }},
529 { &hf_pagp_tlv_agport_mac,
530 { "Agport MAC Address", "pagp.tlvagportmac",
531 FT_ETHER, BASE_NONE, NULL, 0x0,
532 "Source MAC on frames for this aggregate", HFILL }},
534 { &hf_pagp_flush_local_device_id,
535 { "Flush Local Device ID", "pagp.flushlocaldevid",
536 FT_ETHER, BASE_NONE, NULL, 0x0,
537 "Flush local device ID", HFILL }},
539 { &hf_pagp_flush_partner_device_id,
540 { "Flush Partner Device ID", "pagp.flushpartnerdevid",
541 FT_ETHER, BASE_NONE, NULL, 0x0,
542 "Flush remote device ID", HFILL }},
544 { &hf_pagp_flush_transaction_id,
545 { "Transaction ID", "pagp.transid",
546 FT_UINT32, BASE_HEX, NULL, 0x0,
547 "Flush transaction ID", HFILL }},
551 /* Setup protocol subtree array */
553 static gint *ett[] = {
559 /* Register the protocol name and description */
561 proto_pagp = proto_register_protocol("Port Aggregation Protocol", "PAGP", "pagp");
563 /* Required function calls to register the header fields and subtrees used */
565 proto_register_field_array(proto_pagp, hf, array_length(hf));
566 proto_register_subtree_array(ett, array_length(ett));
572 proto_reg_handoff_pagp(void)
574 dissector_handle_t pagp_handle;
576 pagp_handle = create_dissector_handle(dissect_pagp, proto_pagp);
577 dissector_add("llc.cisco_pid", 0x0104, pagp_handle);