FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
lldp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * lldp_api.c - lldp api
4  *
5  * Copyright (c) 2017 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <lldp/lldp.h>
26 
27 #include <vnet/ip/ip4_packet.h>
28 #include <vnet/ip/ip6_packet.h>
29 #include <vnet/ip/ip_types_api.h>
30 
31 /* define message IDs */
32 #include <vnet/format_fns.h>
33 #include <lldp/lldp.api_enum.h>
34 #include <lldp/lldp.api_types.h>
35 
36 /**
37  * Base message ID fot the plugin
38  */
40 #define REPLY_MSG_ID_BASE lldp_base_msg_id
41 
43 
44 static void
46 {
47  vl_api_lldp_config_reply_t *rmp;
48  int rv = 0;
49  u8 *sys_name = 0;
50 
51  sys_name = vl_api_from_api_to_new_vec (mp, &mp->system_name);
52 
53  if (lldp_cfg_set (&sys_name, ntohl (mp->tx_hold), ntohl (mp->tx_interval))
54  != lldp_ok)
55  {
56  vec_free (sys_name);
57  rv = VNET_API_ERROR_INVALID_VALUE;
58  }
59 
60  REPLY_MACRO (VL_API_LLDP_CONFIG_REPLY);
61 }
62 
63 static void
65 {
66  vl_api_sw_interface_set_lldp_reply_t *rmp;
67  int rv = 0;
68  u8 *mgmt_oid = 0, *mgmt_ip4 = 0, *mgmt_ip6 = 0;
69  char *port_desc = 0;
70  u8 no_data[128] = { 0 };
72  ip6_address_t ip6;
73 
74  if (vl_api_string_len (&mp->port_desc) > 0)
75  {
76  port_desc = vl_api_from_api_to_new_c_string (&mp->port_desc);
77  }
78 
80 
81  if (ip4.as_u32 != 0)
82  {
83  vec_validate (mgmt_ip4, sizeof (ip4_address_t) - 1);
84  clib_memcpy (mgmt_ip4, &ip4, vec_len (mgmt_ip4));
85  }
86 
88 
89  if (!ip6_address_is_zero (&ip6))
90  {
91  vec_validate (mgmt_ip6, sizeof (ip6_address_t) - 1);
92  clib_memcpy (mgmt_ip6, &ip6, vec_len (mgmt_ip6));
93  }
94 
95  if (memcmp (mp->mgmt_oid, no_data, strlen ((char *) mp->mgmt_oid)) != 0)
96  {
97  vec_validate (mgmt_oid, strlen ((char *) mp->mgmt_oid) - 1);
98  strncpy ((char *) mgmt_oid, (char *) mp->mgmt_oid, vec_len (mgmt_oid));
99  }
100 
102 
103  if (lldp_cfg_intf_set (ntohl (mp->sw_if_index), (u8 **) & port_desc,
104  &mgmt_ip4, &mgmt_ip6, &mgmt_oid,
105  mp->enable) != lldp_ok)
106  {
107  vec_free (port_desc);
108  vec_free (mgmt_ip4);
109  vec_free (mgmt_ip6);
110  vec_free (mgmt_oid);
111  rv = VNET_API_ERROR_INVALID_VALUE;
112  }
113 
115 
116  REPLY_MACRO (VL_API_SW_INTERFACE_SET_LLDP_REPLY);
117 }
118 
119 
120 /*
121  * * lldp_api_hookup
122  * * Add vpe's API message handlers to the table.
123  * * vlib has already mapped shared memory and
124  * * added the client registration handlers.
125  * * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
126  * */
127 #include <lldp/lldp.api.c>
128 
129 static clib_error_t *
131 {
132  /*
133  * Set up the (msg_name, crc, message-id) table
134  */
136 
137  return 0;
138 }
139 
141 
142 #include <vlib/unix/plugin.h>
143 #include <vpp/app/version.h>
144 
145 /* *INDENT-OFF* */
147  .version = VPP_BUILD_VER,
148  .description = "Link Layer Discovery Protocol (LLDP)",
149 };
150 /* *INDENT-ON* */
151 
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(lldp_api_hookup)
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
lldp_cfg_set
lldp_cfg_err_t lldp_cfg_set(u8 **host, int hold_time, int tx_interval)
Definition: lldp_cli.c:202
vl_api_sw_interface_set_lldp_t::mgmt_ip6
vl_api_ip6_address_t mgmt_ip6
Definition: lldp.api:54
ip4_address_decode
void ip4_address_decode(const vl_api_ip4_address_t in, ip4_address_t *out)
Definition: ip_types_api.c:155
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
vl_api_sw_interface_set_lldp_t::mgmt_oid
u8 mgmt_oid[128]
Definition: lldp.api:55
ip6_address_decode
void ip6_address_decode(const vl_api_ip6_address_t in, ip6_address_t *out)
Definition: ip_types_api.c:143
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
plugin.h
ip6_packet.h
vl_api_sw_interface_set_lldp_t_handler
static void vl_api_sw_interface_set_lldp_t_handler(vl_api_sw_interface_set_lldp_t *mp)
Definition: lldp_api.c:64
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
vl_api_lldp_config_t::tx_interval
u32 tx_interval
Definition: lldp.api:34
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
lldp_cfg_intf_set
lldp_cfg_err_t lldp_cfg_intf_set(u32 hw_if_index, u8 **port_desc, u8 **mgmt_ip4, u8 **mgmt_ip6, u8 **mgmt_oid, int enable)
Definition: lldp_cli.c:49
vl_api_sw_interface_set_lldp_t::enable
bool enable[default=true]
Definition: lldp.api:56
interface.h
vl_api_lldp_config_t_handler
static void vl_api_lldp_config_t_handler(vl_api_lldp_config_t *mp)
Definition: lldp_api.c:45
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
ip4_address_t
Definition: ip4_packet.h:50
vl_api_string_len
u32 vl_api_string_len(vl_api_string_t *astr)
Definition: api_shared.c:1184
vl_api_sw_interface_set_lldp_t::port_desc
string port_desc[]
Definition: lldp.api:57
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
ip4_packet.h
vl_api_sw_interface_set_lldp_t
Interface set LLDP request.
Definition: lldp.api:48
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
format_fns.h
vl_api_sw_interface_set_lldp_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: lldp.api:52
u32
unsigned int u32
Definition: types.h:88
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
api_helper_macros.h
vl_api_from_api_to_new_vec
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
Definition: api_shared.c:1202
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
lldp_ok
@ lldp_ok
Definition: lldp.h:24
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
lldp_base_msg_id
static u32 lldp_base_msg_id
Base message ID fot the plugin.
Definition: lldp_api.c:39
rv
int __clib_unused rv
Definition: application.c:491
ip6_address_is_zero
static uword ip6_address_is_zero(const ip6_address_t *a)
Definition: ip6_packet.h:226
lldp.h
LLDP external definition.
vnet.h
api_errno.h
vl_api_lldp_config_t::system_name
string system_name[]
Definition: lldp.api:35
vl_api_lldp_config_t
configure global parameter for LLDP
Definition: lldp.api:29
vl_api_lldp_config_t::tx_hold
u32 tx_hold
Definition: lldp.api:33
ip_types_api.h
vl_api_from_api_to_new_c_string
char * vl_api_from_api_to_new_c_string(vl_api_string_t *astr)
Definition: api_shared.c:1218
vl_api_sw_interface_set_lldp_t::mgmt_ip4
vl_api_ip4_address_t mgmt_ip4
Definition: lldp.api:53
lldp_api_hookup
static clib_error_t * lldp_api_hookup(vlib_main_t *vm)
Definition: lldp_api.c:130