summaryrefslogtreecommitdiffstats
path: root/src/plugins/cdp/cdp.h
blob: d3abb07fa016862d2979319059341a3869646fd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Sym
/*
 * cdp.h - cdp protocol plug-in
 *
 * Copyright (c) 2011-2018 by Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __included_cdp_h__
#define __included_cdp_h__

#include <vlib/vlib.h>
#include <vlib/unix/unix.h>

#include <vnet/snap/snap.h>
#include <vnet/hdlc/hdlc.h>
#include <vnet/hdlc/packet.h>

#include <vppinfra/format.h>
#include <vppinfra/hash.h>

#include "cdp_protocol.h"

typedef enum
{
  CDP_PACKET_TEMPLATE_ETHERNET,
  CDP_PACKET_TEMPLATE_HDLC,
  CDP_PACKET_TEMPLATE_SRP,
  CDP_N_PACKET_TEMPLATES,
} cdp_packet_template_id_t;

typedef struct
{
  /* neighbor's vlib software interface index */
  u32 sw_if_index;

  /* Timers */
  f64 last_heard;
  f64 last_sent;

  /* Neighbor time-to-live (usually 180s) */
  u8 ttl_in_seconds;

  /* "no cdp run" or similar */
  u8 disabled;

  /* tx packet template id for this neighbor */
  u8 packet_template_index;

  /* Jenkins hash optimization: avoid tlv scan, send short keepalive msg */
  u8 last_packet_signature_valid;
  uword last_packet_signature;

  /* Info we actually keep about each neighbor */
  u8 *device_name;
  u8 *version;
  u8 *port_id;
  u8 *platform;

  /* last received packet, for the J-hash optimization */
  u8 *last_rx_pkt;
} cdp_neighbor_t;

#define foreach_neighbor_string_field           \
_(device_name)                                  \
_(version)                                      \
_(port_id)                                      \
_(platform)

typedef struct
{
  /* pool of cdp neighbors */
  cdp_neighbor_t *neighbors;

  /* plugin message id base */
  u16 msg_id_base;

  /* tx pcap debug enable */
  u8 tx_pcap_debug;

  /* rapidly find a neighbor by vlib software interface index */
  uword *neighbor_by_sw_if_index;

  /* Background process node index */
  u32 cdp_process_node_index;

  /* top-level state */
  int enabled;
  int cdp_protocol_registered;

  /* Packet templates for different encap types */
  vlib_packet_template_t packet_templates[CDP_N_PACKET_TEMPLATES];

  /* convenience variables */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;
} cdp_main_t;

extern cdp_main_t cdp_main;
extern vlib_node_registration_t cdp_process_node;

/* Packet counters */
#define foreach_cdp_error                                       \
_ (NONE, "good cdp packets (processed)")	                \
_ (CACHE_HIT, "good cdp packets (cache hit)")			\
_ (BAD_TLV, "cdp packets with bad TLVs")                        \
_ (PROTOCOL_VERSION, "cdp packets with bad protocol versions")  \
_ (CHECKSUM, "cdp packets with bad checksums")                  \
_ (DISABLED, "cdp packets received on disabled interfaces")

typedef enum
{
#define _(sym,str) CDP_ERROR_##sym,
  foreach_cdp_error
#undef _
    CDP_N_ERROR,
} cdp_error_t;

/* cdp packet trace capture */
typedef struct
{
  u32 len;
  u8 data[400];
} cdp_input_trace_t;

typedef enum
{
  CDP_EVENT_ENABLE,
  CDP_EVENT_DISABLE,
} cdp_process_event_t;

cdp_error_t cdp_input (vlib_main_t * vm, vlib_buffer_t * b0, u32 bi0);
void cdp_periodic (vlib_main_t * vm);
void cdp_keepalive (cdp_main_t * cm, cdp_neighbor_t * n);
u16 cdp_checksum (void *p, int count);
u8 *cdp_input_format_trace (u8 * s, va_list * args);
void vnet_cdp_create_periodic_process (cdp_main_t * cmp);

#endif /* __included_cdp_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */