2 *------------------------------------------------------------------
3 * lldp_api.c - lldp api
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/lldp/lldp.h>
27 #include <vnet/ip/ip4_packet.h>
28 #include <vnet/ip/ip6_packet.h>
29 #include <vnet/ip/ip_types_api.h>
31 #include <vnet/vnet_msg_enum.h>
33 #define vl_typedefs /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
37 #define vl_endianfun /* define message structures */
38 #include <vnet/vnet_all_api_h.h>
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
44 #include <vnet/vnet_all_api_h.h>
47 #include <vlibapi/api_helper_macros.h>
49 #define foreach_vpe_api_msg \
50 _(LLDP_CONFIG, lldp_config) \
51 _(SW_INTERFACE_SET_LLDP, sw_interface_set_lldp)
54 vl_api_lldp_config_t_handler (vl_api_lldp_config_t * mp)
56 vl_api_lldp_config_reply_t *rmp;
60 sys_name = vl_api_from_api_to_new_vec (&mp->system_name);
62 if (lldp_cfg_set (&sys_name, ntohl (mp->tx_hold), ntohl (mp->tx_interval))
66 rv = VNET_API_ERROR_INVALID_VALUE;
69 REPLY_MACRO (VL_API_LLDP_CONFIG_REPLY);
73 vl_api_sw_interface_set_lldp_t_handler (vl_api_sw_interface_set_lldp_t * mp)
75 vl_api_sw_interface_set_lldp_reply_t *rmp;
77 u8 *mgmt_oid = 0, *mgmt_ip4 = 0, *mgmt_ip6 = 0;
79 u8 no_data[128] = { 0 };
83 if (vl_api_string_len (&mp->port_desc) > 0)
85 port_desc = vl_api_from_api_to_new_c_string (&mp->port_desc);
88 ip4_address_decode (mp->mgmt_ip4, &ip4);
92 vec_validate (mgmt_ip4, sizeof (ip4_address_t) - 1);
93 clib_memcpy (mgmt_ip4, &ip4, vec_len (mgmt_ip4));
96 ip6_address_decode (mp->mgmt_ip6, &ip6);
98 if (!ip6_address_is_zero (&ip6))
100 vec_validate (mgmt_ip6, sizeof (ip6_address_t) - 1);
101 clib_memcpy (mgmt_ip6, &ip6, vec_len (mgmt_ip6));
104 if (memcmp (mp->mgmt_oid, no_data, strlen ((char *) mp->mgmt_oid)) != 0)
106 vec_validate (mgmt_oid, strlen ((char *) mp->mgmt_oid) - 1);
107 strncpy ((char *) mgmt_oid, (char *) mp->mgmt_oid, vec_len (mgmt_oid));
110 VALIDATE_SW_IF_INDEX (mp);
112 if (lldp_cfg_intf_set (ntohl (mp->sw_if_index), (u8 **) & port_desc,
113 &mgmt_ip4, &mgmt_ip6, &mgmt_oid,
114 mp->enable) != lldp_ok)
116 vec_free (port_desc);
120 rv = VNET_API_ERROR_INVALID_VALUE;
123 BAD_SW_IF_INDEX_LABEL;
125 REPLY_MACRO (VL_API_SW_INTERFACE_SET_LLDP_REPLY);
131 * * Add vpe's API message handlers to the table.
132 * * vlib has already mapped shared memory and
133 * * added the client registration handlers.
134 * * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
136 #define vl_msg_name_crc_list
137 #include <vnet/vnet_all_api_h.h>
138 #undef vl_msg_name_crc_list
141 setup_message_id_table (api_main_t * am)
143 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
144 foreach_vl_msg_name_crc_lldp;
148 static clib_error_t *
149 lldp_api_hookup (vlib_main_t * vm)
151 api_main_t *am = vlibapi_get_main ();
154 vl_msg_api_set_handlers(VL_API_##N, #n, \
155 vl_api_##n##_t_handler, \
157 vl_api_##n##_t_endian, \
158 vl_api_##n##_t_print, \
159 sizeof(vl_api_##n##_t), 1);
164 * * Set up the (msg_name, crc, message-id) table
166 setup_message_id_table (am);
171 VLIB_API_INIT_FUNCTION (lldp_api_hookup);
174 * fd.io coding-style-patch-verification: ON
177 * eval: (c-set-style "gnu")