JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1998-2007 The TCPDUMP project |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that: (1) source code |
| 6 | * distributions retain the above copyright notice and this paragraph |
| 7 | * in its entirety, and (2) distributions including binary code include |
| 8 | * the above copyright notice and this paragraph in its entirety in |
| 9 | * the documentation or other materials provided with the distribution. |
| 10 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
| 11 | * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
| 12 | * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 13 | * FOR A PARTICULAR PURPOSE. |
| 14 | * |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 15 | * Original code by Carles Kishimoto <carles.kishimoto@gmail.com> |
| 16 | */ |
| 17 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 18 | /* \summary: Dynamic Trunking Protocol (DTP) printer */ |
| 19 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 21 | #include <config.h> |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 22 | #endif |
| 23 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 24 | #include "netdissect-stdinc.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 26 | #define ND_LONGJMP_FROM_TCHECK |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 27 | #include "netdissect.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 28 | #include "addrtoname.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 29 | #include "extract.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 30 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 31 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 32 | #define DTP_HEADER_LEN 1 |
| 33 | #define DTP_DOMAIN_TLV 0x0001 |
| 34 | #define DTP_STATUS_TLV 0x0002 |
| 35 | #define DTP_DTP_TYPE_TLV 0x0003 |
| 36 | #define DTP_NEIGHBOR_TLV 0x0004 |
| 37 | |
| 38 | static const struct tok dtp_tlv_values[] = { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 39 | { DTP_DOMAIN_TLV, "Domain" }, |
| 40 | { DTP_STATUS_TLV, "Status" }, |
| 41 | { DTP_DTP_TYPE_TLV, "DTP type" }, |
| 42 | { DTP_NEIGHBOR_TLV, "Neighbor" }, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 43 | { 0, NULL} |
| 44 | }; |
| 45 | |
| 46 | void |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 47 | dtp_print(netdissect_options *ndo, const u_char *tptr, u_int length) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 48 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 49 | ndo->ndo_protocol = "dtp"; |
| 50 | if (length < DTP_HEADER_LEN) { |
| 51 | ND_PRINT("[zero packet length]"); |
| 52 | goto invalid; |
| 53 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 54 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 55 | ND_PRINT("DTPv%u, length %u", |
| 56 | GET_U_1(tptr), |
| 57 | length); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * In non-verbose mode, just print version. |
| 61 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 62 | if (ndo->ndo_vflag < 1) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
| 66 | tptr += DTP_HEADER_LEN; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 67 | length -= DTP_HEADER_LEN; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 68 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 69 | while (length) { |
| 70 | uint16_t type, len; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 71 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 72 | if (length < 4) { |
| 73 | ND_PRINT("[%u bytes remaining]", length); |
| 74 | goto invalid; |
| 75 | } |
| 76 | type = GET_BE_U_2(tptr); |
| 77 | len = GET_BE_U_2(tptr + 2); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 78 | /* XXX: should not be but sometimes it is, see the test captures */ |
| 79 | if (type == 0) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 80 | return; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 81 | ND_PRINT("\n\t%s (0x%04x) TLV, length %u", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 82 | tok2str(dtp_tlv_values, "Unknown", type), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 83 | type, len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 84 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 85 | /* infinite loop check */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 86 | if (len < 4 || len > length) { |
| 87 | ND_PRINT("[invalid TLV length %u]", len); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 88 | goto invalid; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 89 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 90 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 91 | switch (type) { |
| 92 | case DTP_DOMAIN_TLV: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 93 | ND_PRINT(", "); |
| 94 | nd_printjnp(ndo, tptr+4, len-4); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 95 | break; |
| 96 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 97 | case DTP_STATUS_TLV: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 98 | case DTP_DTP_TYPE_TLV: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 99 | if (len != 5) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 100 | goto invalid; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 101 | ND_PRINT(", 0x%x", GET_U_1(tptr + 4)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 102 | break; |
| 103 | |
| 104 | case DTP_NEIGHBOR_TLV: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 105 | if (len != 10) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 106 | goto invalid; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 107 | ND_PRINT(", %s", GET_ETHERADDR_STRING(tptr+4)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 108 | break; |
| 109 | |
| 110 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 111 | ND_TCHECK_LEN(tptr, len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 112 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 113 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 114 | tptr += len; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 115 | length -= len; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 116 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 117 | return; |
| 118 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 119 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 120 | nd_print_invalid(ndo); |
| 121 | ND_TCHECK_LEN(tptr, length); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 122 | } |