19 #define DEBUG_TLV_DUMP 0 45 sum += *(
char *) data;
49 sum = (sum & 0xFFFF) + (sum >> 16);
71 cdp_tlv_t *t = va_arg (*va, cdp_tlv_t *);
83 #if DEBUG_TLV_DUMP > 0 87 return CDP_ERROR_NONE;
94 cdp_tlv_t *t = va_arg (*va, cdp_tlv_t *);
100 for (i = 0; i < (t->l -
sizeof (*t)); i++)
107 #if DEBUG_TLV_DUMP == 0 118 #if DEBUG_TLV_DUMP > 0 122 return CDP_ERROR_NONE;
126 #define format_unused_tlv format_generic_tlv 127 #define format_device_name_tlv format_text_tlv 128 #define format_address_tlv format_generic_tlv 129 #define format_port_id_tlv format_text_tlv 130 #define format_capabilities_tlv format_generic_tlv 131 #define format_version_tlv format_text_tlv 132 #define format_platform_tlv format_text_tlv 133 #define format_ipprefix_tlv format_generic_tlv 134 #define format_hello_tlv format_generic_tlv 135 #define format_vtp_domain_tlv format_generic_tlv 136 #define format_native_vlan_tlv format_generic_tlv 137 #define format_duplex_tlv format_generic_tlv 138 #define format_appl_vlan_tlv format_generic_tlv 139 #define format_trigger_tlv format_generic_tlv 140 #define format_power_tlv format_generic_tlv 141 #define format_mtu_tlv format_generic_tlv 142 #define format_trust_tlv format_generic_tlv 143 #define format_cos_tlv format_generic_tlv 144 #define format_sysname_tlv format_generic_tlv 145 #define format_sysobject_tlv format_generic_tlv 146 #define format_mgmt_addr_tlv format_generic_tlv 147 #define format_physical_loc_tlv format_generic_tlv 148 #define format_mgmt_addr2_tlv format_generic_tlv 149 #define format_power_requested_tlv format_generic_tlv 150 #define format_power_available_tlv format_generic_tlv 151 #define format_port_unidirectional_tlv format_generic_tlv 152 #define format_unknown_28_tlv format_generic_tlv 153 #define format_energywise_tlv format_generic_tlv 154 #define format_unknown_30_tlv format_generic_tlv 155 #define format_spare_poe_tlv format_generic_tlv 161 return CDP_ERROR_BAD_TLV;
165 #define foreach_text_to_struct_tlv \ 166 _(device_name,DEBUG_TLV_DUMP) \ 167 _(version,DEBUG_TLV_DUMP) \ 168 _(platform,DEBUG_TLV_DUMP) \ 169 _(port_id,DEBUG_TLV_DUMP) 173 cdp_error_t process_##z##_tlv (cdp_main_t *cm, cdp_neighbor_t *n, \ 178 fformat(stdout, "%U\n", format_text_tlv, t); \ 181 _vec_len(n->z) = 0; \ 183 for (i = 0; i < (t->l - sizeof (*t)); i++) \ 184 vec_add1(n->z, t->v[i]); \ 188 return CDP_ERROR_NONE; \ 193 #define process_address_tlv process_generic_tlv 194 #define process_capabilities_tlv process_generic_tlv 195 #define process_ipprefix_tlv process_generic_tlv 196 #define process_hello_tlv process_generic_tlv 197 #define process_vtp_domain_tlv process_generic_tlv 198 #define process_native_vlan_tlv process_generic_tlv 199 #define process_duplex_tlv process_generic_tlv 200 #define process_appl_vlan_tlv process_generic_tlv 201 #define process_trigger_tlv process_generic_tlv 202 #define process_power_tlv process_generic_tlv 203 #define process_mtu_tlv process_generic_tlv 204 #define process_trust_tlv process_generic_tlv 205 #define process_cos_tlv process_generic_tlv 206 #define process_sysname_tlv process_generic_tlv 207 #define process_sysobject_tlv process_generic_tlv 208 #define process_mgmt_addr_tlv process_generic_tlv 209 #define process_physical_loc_tlv process_generic_tlv 210 #define process_mgmt_addr2_tlv process_generic_tlv 211 #define process_power_requested_tlv process_generic_tlv 212 #define process_power_available_tlv process_generic_tlv 213 #define process_port_unidirectional_tlv process_generic_tlv 214 #define process_unknown_28_tlv process_generic_tlv 215 #define process_energywise_tlv process_generic_tlv 216 #define process_unknown_30_tlv process_generic_tlv 217 #define process_spare_poe_tlv process_generic_tlv 219 #define _(a) {#a, CDP_TLV_##a, format_##a##_tlv, process_##a##_tlv}, 224 #if DEBUG_TLV_DUMP == 0 231 cdp_hdr_t *
h = va_arg (*va, cdp_hdr_t *);
233 s =
format (s,
"version %d, ttl %d(secs), cksum 0x%04x\n",
234 h->version, h->ttl, h->checksum);
241 #if DEBUG_TLV_DUMP > 0 245 if (h->version != 1 && h->version != 2)
246 return CDP_ERROR_PROTOCOL_VERSION;
250 return CDP_ERROR_NONE;
263 u16 computed_checksum;
267 if (computed_checksum)
268 return CDP_ERROR_CHECKSUM;
270 h = (cdp_hdr_t *) cur;
276 cur = (
u8 *) (h + 1);
280 tlv = (cdp_tlv_t *) cur;
281 tlv->t = ntohs (tlv->t);
282 tlv->l = ntohs (tlv->l);
284 return CDP_ERROR_BAD_TLV;
285 handler = &tlv_handlers[tlv->t];
287 e = (*fp) (cm, n, tlv);
294 return CDP_ERROR_NONE;
307 uword last_packet_signature;
317 memset (n, 0,
sizeof (*n));
339 return CDP_ERROR_DISABLED;
359 last_packet_signature =
365 e = CDP_ERROR_CACHE_HIT;
375 if (e == CDP_ERROR_NONE)
418 "%=25s %=15s %=25s %=10s\n",
419 "Our Port",
"Peer System",
"Peer Port",
"Last Heard");
424 hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
426 if (n->disabled == 0)
427 s = format (s,
"%=25s %=15s %=25s %=10.1f\n",
428 hw->name, n->device_name, n->port_id,
450 .short_help =
"Show cdp command",
471 u8 *(*fp) (cdp_tlv_t *);
475 h = (cdp_hdr_t *) cur;
478 cur = (
u8 *) (h + 1);
480 while (cur < t->data + t->
len)
482 tlv = (cdp_tlv_t *) cur;
483 tlv->t = ntohs (tlv->t);
484 tlv->l = ntohs (tlv->l);
487 s =
format (s,
"BAD_TLV\n");
490 handler = &tlv_handlers[tlv->t];
492 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)
sll srl srl sll sra u16x4 i
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
#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)
struct _mc_serialize_msg mc_serialize_msg_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)