Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __included_cdp_protocol_h__ |
| 16 | #define __included_cdp_protocol_h__ |
| 17 | |
| 18 | #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */ |
| 19 | #include <vnet/llc/llc.h> |
| 20 | #include <vnet/snap/snap.h> |
| 21 | #include <vnet/srp/packet.h> |
| 22 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 23 | typedef CLIB_PACKED (struct |
| 24 | { |
| 25 | u8 version; |
| 26 | u8 ttl; |
| 27 | u16 checksum; /* 1's complement of the 1's complement sum */ |
| 28 | u8 data[0]; |
| 29 | }) cdp_hdr_t; |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 30 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 31 | typedef struct |
| 32 | { |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 33 | u8 dst_address[6]; |
| 34 | u8 src_address[6]; |
| 35 | u16 len; |
| 36 | } ethernet_802_3_header_t; |
| 37 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 38 | typedef CLIB_PACKED (struct |
| 39 | { |
| 40 | ethernet_802_3_header_t ethernet; |
| 41 | llc_header_t llc; snap_header_t snap; cdp_hdr_t cdp; |
| 42 | }) ethernet_llc_snap_and_cdp_header_t; |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 43 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 44 | typedef CLIB_PACKED (struct |
| 45 | { |
| 46 | hdlc_header_t hdlc; cdp_hdr_t cdp; |
| 47 | }) hdlc_and_cdp_header_t; |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 48 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 49 | typedef CLIB_PACKED (struct |
| 50 | { |
| 51 | srp_header_t srp; |
| 52 | ethernet_header_t ethernet; cdp_hdr_t cdp; |
| 53 | }) srp_and_cdp_header_t; |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 54 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 55 | typedef CLIB_PACKED (struct |
| 56 | { |
| 57 | u16 t; |
| 58 | u16 l; |
| 59 | u8 v[0]; |
| 60 | }) cdp_tlv_t; |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 61 | |
| 62 | /* |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 63 | * TLV codes. |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 64 | */ |
| 65 | #define foreach_cdp_tlv_type \ |
| 66 | _(unused) \ |
| 67 | _(device_name) /* uniquely identifies the device */ \ |
| 68 | _(address) /* list of addresses this device has */ \ |
| 69 | _(port_id) /* port CDP packet was sent out on */ \ |
| 70 | _(capabilities) /* funct. capabilities of the device */ \ |
| 71 | _(version) /* version */ \ |
| 72 | _(platform) /* hardware platform of this device */ \ |
| 73 | _(ipprefix) /* An IP network prefix */ \ |
| 74 | _(hello) /* Pprotocol piggyback hello msg */ \ |
| 75 | _(vtp_domain) /* VTP management domain */ \ |
| 76 | _(native_vlan) /* Native VLAN number */ \ |
| 77 | _(duplex) /* The interface duplex mode */ \ |
| 78 | _(appl_vlan) /* Appliance VLAN-ID TLV */ \ |
| 79 | _(trigger) /* For sending trigger TLV msgs. */ \ |
| 80 | _(power) /* Power consumption of that device */ \ |
| 81 | _(mtu) /* MTU defined for sending intf. */ \ |
| 82 | _(trust) /* Extended trust TLV */ \ |
| 83 | _(cos) /* COS for Untrusted Port TLV */ \ |
| 84 | _(sysname) /* System name (FQDN of device) */ \ |
| 85 | _(sysobject) /* OID of sysObjectID MIB object */ \ |
| 86 | _(mgmt_addr) /* SNMP manageable addrs. of device */ \ |
| 87 | _(physical_loc) /* Physical Location of the device */ \ |
| 88 | _(mgmt_addr2) /* External Port-ID */ \ |
| 89 | _(power_requested) \ |
| 90 | _(power_available) \ |
| 91 | _(port_unidirectional) \ |
| 92 | _(unknown_28) \ |
| 93 | _(energywise) \ |
| 94 | _(unknown_30) \ |
| 95 | _(spare_poe) |
| 96 | |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 97 | typedef enum |
| 98 | { |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 99 | #define _(t) CDP_TLV_##t, |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 100 | foreach_cdp_tlv_type |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 101 | #undef _ |
| 102 | } cdp_tlv_code_t; |
| 103 | |
| 104 | /* |
| 105 | The address TLV looks as follows: |
| 106 | |
| 107 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 108 | | Number of addresses | |
| 109 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 110 | | IDRP encoded address | |
| 111 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 112 | |
| 113 | An address is encoded in IDRP format: |
| 114 | |
| 115 | 0 1 2 3 |
| 116 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 117 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 118 | | PT | PT Length | Protocol (variable) ... |
| 119 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 120 | | Address length | Address (variable) ... |
| 121 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 122 | |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 123 | PT: Protocol type |
| 124 | 1 = NLPID format |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 125 | 2 = 802.2 format |
| 126 | |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 127 | PT Length: |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 128 | Length of protocol field, 1 for PT = 1, and either 3 or 8 for |
| 129 | 802.2 format depending if SNAP is used for PT = 2. |
| 130 | |
| 131 | The encodings for the other protocols have the following format: |
| 132 | |
| 133 | field: <SSAP><DSAP><CTRL><-------OUI------><protocl_TYPE> |
| 134 | | | | | | | | | | |
| 135 | bytes: 0 1 2 3 4 5 6 7 8 |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 136 | |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 137 | where the first 3 bytes are 0xAAAA03 for SNAP encoded addresses. |
| 138 | The OUI is 000000 for ethernet and <protocl_TYPE> |
| 139 | is the assigned Ethernet type code for the particular protocol. |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 140 | e.g. for DECnet the encoding is AAAA03 000000 6003. |
Dave Barach | ced48e7 | 2016-02-08 15:57:35 -0500 | [diff] [blame] | 141 | for IPv6 the encoding is AAAA03 000000 86DD |
| 142 | */ |
| 143 | |
| 144 | /* |
| 145 | * Capabilities. |
| 146 | */ |
| 147 | |
| 148 | #define CDP_ROUTER_DEVICE 0x0001 |
| 149 | #define CDP_TB_DEVICE 0x0002 |
| 150 | #define CDP_SRB_DEVICE 0x0004 |
| 151 | #define CDP_SWITCH_DEVICE 0x0008 |
| 152 | #define CDP_HOST_DEVICE 0x0010 |
| 153 | #define CDP_IGMP_DEVICE 0x0020 |
| 154 | #define CDP_REPEATER_DEVICE 0x0040 |
| 155 | |
| 156 | /* |
| 157 | The protocol-hello TLV looks as follows: |
| 158 | |
| 159 | 0 1 2 3 |
| 160 | 012345678901234567890123456789012345678 |
| 161 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 162 | | Type | Length | |
| 163 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 164 | | OUI | |
| 165 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 166 | | Protocol ID | |
| 167 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 168 | | up to 27 bytes of message | |
| 169 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 170 | */ |
| 171 | |
| 172 | /* |
| 173 | * These macros define the valid values for the Duplex TLV. |
| 174 | */ |
| 175 | #define CDP_DUPLEX_TLV_HALF 0x0 |
| 176 | #define CDP_DUPLEX_TLV_FULL 0x1 |
| 177 | |
| 178 | #endif /* __included_cdp_protocol_h__ */ |
Dave Barach | 861bd21 | 2016-08-09 08:55:49 -0400 | [diff] [blame] | 179 | |
| 180 | /* |
| 181 | * fd.io coding-style-patch-verification: ON |
| 182 | * |
| 183 | * Local Variables: |
| 184 | * eval: (c-set-style "gnu") |
| 185 | * End: |
| 186 | */ |