19 #define DEBUG_TLV_DUMP 0 41 sum += *(
char *) data;
45 sum = (sum & 0xFFFF) + (sum >> 16);
67 cdp_tlv_t *t = va_arg (*va, cdp_tlv_t *);
79 #if DEBUG_TLV_DUMP > 0 83 return CDP_ERROR_NONE;
90 cdp_tlv_t *t = va_arg (*va, cdp_tlv_t *);
98 for (i = 0; i < (t->l -
sizeof (*t)); i++)
106 #if DEBUG_TLV_DUMP == 0 117 #if DEBUG_TLV_DUMP > 0 121 return CDP_ERROR_NONE;
125 #define format_unused_tlv format_generic_tlv 126 #define format_device_name_tlv format_text_tlv 127 #define format_address_tlv format_generic_tlv 128 #define format_port_id_tlv format_text_tlv 129 #define format_capabilities_tlv format_generic_tlv 130 #define format_version_tlv format_text_tlv 131 #define format_platform_tlv format_text_tlv 132 #define format_ipprefix_tlv format_generic_tlv 133 #define format_hello_tlv format_generic_tlv 134 #define format_vtp_domain_tlv format_generic_tlv 135 #define format_native_vlan_tlv format_generic_tlv 136 #define format_duplex_tlv format_generic_tlv 137 #define format_appl_vlan_tlv format_generic_tlv 138 #define format_trigger_tlv format_generic_tlv 139 #define format_power_tlv format_generic_tlv 140 #define format_mtu_tlv format_generic_tlv 141 #define format_trust_tlv format_generic_tlv 142 #define format_cos_tlv format_generic_tlv 143 #define format_sysname_tlv format_generic_tlv 144 #define format_sysobject_tlv format_generic_tlv 145 #define format_mgmt_addr_tlv format_generic_tlv 146 #define format_physical_loc_tlv format_generic_tlv 147 #define format_mgmt_addr2_tlv format_generic_tlv 148 #define format_power_requested_tlv format_generic_tlv 149 #define format_power_available_tlv format_generic_tlv 150 #define format_port_unidirectional_tlv format_generic_tlv 151 #define format_unknown_28_tlv format_generic_tlv 152 #define format_energywise_tlv format_generic_tlv 153 #define format_unknown_30_tlv format_generic_tlv 154 #define format_spare_poe_tlv format_generic_tlv 160 return CDP_ERROR_BAD_TLV;
164 #define foreach_text_to_struct_tlv \ 165 _(device_name,DEBUG_TLV_DUMP) \ 166 _(version,DEBUG_TLV_DUMP) \ 167 _(platform,DEBUG_TLV_DUMP) \ 168 _(port_id,DEBUG_TLV_DUMP) 172 cdp_error_t process_##z##_tlv (cdp_main_t *cm, cdp_neighbor_t *n, \ 177 fformat(stdout, "%U\n", format_text_tlv, t); \ 180 _vec_len(n->z) = 0; \ 182 for (i = 0; i < (t->l - sizeof (*t)); i++) \ 183 vec_add1(n->z, t->v[i]); \ 187 return CDP_ERROR_NONE; \ 192 #define process_address_tlv process_generic_tlv 193 #define process_capabilities_tlv process_generic_tlv 194 #define process_ipprefix_tlv process_generic_tlv 195 #define process_hello_tlv process_generic_tlv 196 #define process_vtp_domain_tlv process_generic_tlv 197 #define process_native_vlan_tlv process_generic_tlv 198 #define process_duplex_tlv process_generic_tlv 199 #define process_appl_vlan_tlv process_generic_tlv 200 #define process_trigger_tlv process_generic_tlv 201 #define process_power_tlv process_generic_tlv 202 #define process_mtu_tlv process_generic_tlv 203 #define process_trust_tlv process_generic_tlv 204 #define process_cos_tlv process_generic_tlv 205 #define process_sysname_tlv process_generic_tlv 206 #define process_sysobject_tlv process_generic_tlv 207 #define process_mgmt_addr_tlv process_generic_tlv 208 #define process_physical_loc_tlv process_generic_tlv 209 #define process_mgmt_addr2_tlv process_generic_tlv 210 #define process_power_requested_tlv process_generic_tlv 211 #define process_power_available_tlv process_generic_tlv 212 #define process_port_unidirectional_tlv process_generic_tlv 213 #define process_unknown_28_tlv process_generic_tlv 214 #define process_energywise_tlv process_generic_tlv 215 #define process_unknown_30_tlv process_generic_tlv 216 #define process_spare_poe_tlv process_generic_tlv 218 #define _(a) {#a, CDP_TLV_##a, format_##a##_tlv, process_##a##_tlv}, 223 #if DEBUG_TLV_DUMP == 0 230 cdp_hdr_t *
h = va_arg (*va, cdp_hdr_t *);
232 s =
format (s,
"version %d, ttl %d(secs), cksum 0x%04x\n",
233 h->version, h->ttl, h->checksum);
240 #if DEBUG_TLV_DUMP > 0 244 if (h->version != 1 && h->version != 2)
245 return CDP_ERROR_PROTOCOL_VERSION;
249 return CDP_ERROR_NONE;
262 u16 computed_checksum;
266 if (computed_checksum)
267 return CDP_ERROR_CHECKSUM;
269 h = (cdp_hdr_t *) cur;
277 return CDP_ERROR_BAD_TLV;
279 cur = (
u8 *) (h + 1);
283 while (cur + 3 <= end)
285 tlv = (cdp_tlv_t *) cur;
286 tlv->t = ntohs (tlv->t);
287 tlv->l = ntohs (tlv->l);
292 return CDP_ERROR_BAD_TLV;
296 return CDP_ERROR_BAD_TLV;
304 handler = &tlv_handlers[tlv->t];
306 e = (*fp) (cm, n, tlv);
313 if ((cur - 1) != end)
314 return CDP_ERROR_BAD_TLV;
316 return CDP_ERROR_NONE;
329 uword last_packet_signature;
361 return CDP_ERROR_DISABLED;
381 last_packet_signature =
387 e = CDP_ERROR_CACHE_HIT;
397 if (e == CDP_ERROR_NONE)
440 "%=25s %=25s %=25s %=10s\n",
441 "Our Port",
"Peer System",
"Peer Port",
"Last Heard");
446 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
448 if (n->disabled == 0)
449 s = format (s,
"%=25s %=25s %=25s %=10.1f\n",
450 hw->name, n->device_name, n->port_id,
474 .short_help =
"Show cdp command",
495 u8 *(*fp) (cdp_tlv_t *);
499 h = (cdp_hdr_t *) cur;
502 cur = (
u8 *) (h + 1);
504 while (cur < t->data + t->
len)
506 tlv = (cdp_tlv_t *) cur;
507 tlv->t = ntohs (tlv->t);
508 tlv->l = ntohs (tlv->l);
511 s =
format (s,
"BAD_TLV\n");
514 handler = &tlv_handlers[tlv->t];
516 s =
format (s,
" %U", fp, tlv);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define hash_set(h, key, value)
vnet_main_t * vnet_get_main(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
uword * neighbor_by_sw_if_index
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
u8 last_packet_signature_valid
#define vlib_call_init_function(vm, x)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
cdp_neighbor_t * neighbors
uword last_packet_signature
static uword vlib_buffer_contents(vlib_main_t *vm, u32 buffer_index, u8 *contents)
Copy buffer contents to memory.
void vnet_cdp_node_reference(void)
static clib_error_t * cdp_periodic_init(vlib_main_t *vm)
#define VLIB_CLI_COMMAND(x,...)
#define hash_create(elts, value_bytes)
uword hash_memory(void *p, word n_bytes, uword state)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)