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 *);
96 for (i = 0; i < (t->l -
sizeof (*t)); i++)
103 #if DEBUG_TLV_DUMP == 0 114 #if DEBUG_TLV_DUMP > 0 118 return CDP_ERROR_NONE;
122 #define format_unused_tlv format_generic_tlv 123 #define format_device_name_tlv format_text_tlv 124 #define format_address_tlv format_generic_tlv 125 #define format_port_id_tlv format_text_tlv 126 #define format_capabilities_tlv format_generic_tlv 127 #define format_version_tlv format_text_tlv 128 #define format_platform_tlv format_text_tlv 129 #define format_ipprefix_tlv format_generic_tlv 130 #define format_hello_tlv format_generic_tlv 131 #define format_vtp_domain_tlv format_generic_tlv 132 #define format_native_vlan_tlv format_generic_tlv 133 #define format_duplex_tlv format_generic_tlv 134 #define format_appl_vlan_tlv format_generic_tlv 135 #define format_trigger_tlv format_generic_tlv 136 #define format_power_tlv format_generic_tlv 137 #define format_mtu_tlv format_generic_tlv 138 #define format_trust_tlv format_generic_tlv 139 #define format_cos_tlv format_generic_tlv 140 #define format_sysname_tlv format_generic_tlv 141 #define format_sysobject_tlv format_generic_tlv 142 #define format_mgmt_addr_tlv format_generic_tlv 143 #define format_physical_loc_tlv format_generic_tlv 144 #define format_mgmt_addr2_tlv format_generic_tlv 145 #define format_power_requested_tlv format_generic_tlv 146 #define format_power_available_tlv format_generic_tlv 147 #define format_port_unidirectional_tlv format_generic_tlv 148 #define format_unknown_28_tlv format_generic_tlv 149 #define format_energywise_tlv format_generic_tlv 150 #define format_unknown_30_tlv format_generic_tlv 151 #define format_spare_poe_tlv format_generic_tlv 157 return CDP_ERROR_BAD_TLV;
161 #define foreach_text_to_struct_tlv \ 162 _(device_name,DEBUG_TLV_DUMP) \ 163 _(version,DEBUG_TLV_DUMP) \ 164 _(platform,DEBUG_TLV_DUMP) \ 165 _(port_id,DEBUG_TLV_DUMP) 169 cdp_error_t process_##z##_tlv (cdp_main_t *cm, cdp_neighbor_t *n, \ 174 fformat(stdout, "%U\n", format_text_tlv, t); \ 177 _vec_len(n->z) = 0; \ 179 for (i = 0; i < (t->l - sizeof (*t)); i++) \ 180 vec_add1(n->z, t->v[i]); \ 184 return CDP_ERROR_NONE; \ 189 #define process_address_tlv process_generic_tlv 190 #define process_capabilities_tlv process_generic_tlv 191 #define process_ipprefix_tlv process_generic_tlv 192 #define process_hello_tlv process_generic_tlv 193 #define process_vtp_domain_tlv process_generic_tlv 194 #define process_native_vlan_tlv process_generic_tlv 195 #define process_duplex_tlv process_generic_tlv 196 #define process_appl_vlan_tlv process_generic_tlv 197 #define process_trigger_tlv process_generic_tlv 198 #define process_power_tlv process_generic_tlv 199 #define process_mtu_tlv process_generic_tlv 200 #define process_trust_tlv process_generic_tlv 201 #define process_cos_tlv process_generic_tlv 202 #define process_sysname_tlv process_generic_tlv 203 #define process_sysobject_tlv process_generic_tlv 204 #define process_mgmt_addr_tlv process_generic_tlv 205 #define process_physical_loc_tlv process_generic_tlv 206 #define process_mgmt_addr2_tlv process_generic_tlv 207 #define process_power_requested_tlv process_generic_tlv 208 #define process_power_available_tlv process_generic_tlv 209 #define process_port_unidirectional_tlv process_generic_tlv 210 #define process_unknown_28_tlv process_generic_tlv 211 #define process_energywise_tlv process_generic_tlv 212 #define process_unknown_30_tlv process_generic_tlv 213 #define process_spare_poe_tlv process_generic_tlv 215 #define _(a) {#a, CDP_TLV_##a, format_##a##_tlv, process_##a##_tlv}, 220 #if DEBUG_TLV_DUMP == 0 227 cdp_hdr_t *
h = va_arg (*va, cdp_hdr_t *);
229 s =
format (s,
"version %d, ttl %d(secs), cksum 0x%04x\n",
230 h->version, h->ttl, h->checksum);
237 #if DEBUG_TLV_DUMP > 0 241 if (h->version != 1 && h->version != 2)
242 return CDP_ERROR_PROTOCOL_VERSION;
246 return CDP_ERROR_NONE;
259 u16 computed_checksum;
263 if (computed_checksum)
264 return CDP_ERROR_CHECKSUM;
266 h = (cdp_hdr_t *) cur;
272 cur = (
u8 *) (h + 1);
276 tlv = (cdp_tlv_t *) cur;
277 tlv->t = ntohs (tlv->t);
278 tlv->l = ntohs (tlv->l);
285 handler = &tlv_handlers[tlv->t];
287 e = (*fp) (cm, n, tlv);
295 return CDP_ERROR_NONE;
308 uword last_packet_signature;
318 memset (n, 0,
sizeof (*n));
340 return CDP_ERROR_DISABLED;
360 last_packet_signature =
366 e = CDP_ERROR_CACHE_HIT;
376 if (e == CDP_ERROR_NONE)
419 "%=25s %=15s %=25s %=10s\n",
420 "Our Port",
"Peer System",
"Peer Port",
"Last Heard");
425 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
427 if (n->disabled == 0)
428 s = format (s,
"%=25s %=15s %=25s %=10.1f\n",
429 hw->name, n->device_name, n->port_id,
453 .short_help =
"Show cdp command",
474 u8 *(*fp) (cdp_tlv_t *);
478 h = (cdp_hdr_t *) cur;
481 cur = (
u8 *) (h + 1);
483 while (cur < t->data + t->
len)
485 tlv = (cdp_tlv_t *) cur;
486 tlv->t = ntohs (tlv->t);
487 tlv->l = ntohs (tlv->l);
490 s =
format (s,
"BAD_TLV\n");
493 handler = &tlv_handlers[tlv->t];
495 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)
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
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#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,...)