FD.io VPP  v21.01.1
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 
79  ip4_address_decode (mp->mgmt_ip4, &ip4);
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 
87  ip6_address_decode (mp->mgmt_ip6, &ip6);
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  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
Definition: lldp.h:24
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
void ip6_address_decode(const vl_api_ip6_address_t in, ip6_address_t *out)
Definition: ip_types_api.c:143
vlib_main_t * vm
Definition: in2out_ed.c:1580
unsigned char u8
Definition: types.h:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
vl_api_ip6_address_t mgmt_ip6
Definition: lldp.api:54
vl_api_interface_index_t sw_if_index
Definition: lldp.api:52
vl_api_ip6_address_t ip6
Definition: one.api:424
string system_name[]
Definition: lldp.api:35
unsigned int u32
Definition: types.h:88
VLIB_API_INIT_FUNCTION(lldp_api_hookup)
#define REPLY_MACRO(t)
vl_api_ip4_address_t ip4
Definition: one.api:376
u32 vl_api_string_len(vl_api_string_t *astr)
Definition: api_shared.c:1170
LLDP external definition.
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:409
#define BAD_SW_IF_INDEX_LABEL
static void vl_api_lldp_config_t_handler(vl_api_lldp_config_t *mp)
Definition: lldp_api.c:45
vl_api_ip4_address_t mgmt_ip4
Definition: lldp.api:53
static uword ip6_address_is_zero(const ip6_address_t *a)
Definition: ip6_packet.h:226
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
char * vl_api_from_api_to_new_c_string(vl_api_string_t *astr)
Definition: api_shared.c:1204
static u32 lldp_base_msg_id
Base message ID fot the plugin.
Definition: lldp_api.c:39
static void vl_api_sw_interface_set_lldp_t_handler(vl_api_sw_interface_set_lldp_t *mp)
Definition: lldp_api.c:64
VLIB_PLUGIN_REGISTER()
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void ip4_address_decode(const vl_api_ip4_address_t in, ip4_address_t *out)
Definition: ip_types_api.c:155
Interface set LLDP request.
Definition: lldp.api:48
bool enable[default=true]
Definition: lldp.api:56
configure global parameter for LLDP
Definition: lldp.api:29
lldp_cfg_err_t lldp_cfg_set(u8 **host, int hold_time, int tx_interval)
Definition: lldp_cli.c:202
static clib_error_t * lldp_api_hookup(vlib_main_t *vm)
Definition: lldp_api.c:130
u8 * vl_api_from_api_to_new_vec(void *mp, vl_api_string_t *astr)
Definition: api_shared.c:1188
#define VALIDATE_SW_IF_INDEX(mp)