2 *------------------------------------------------------------------
3 * lisp_gpe_api.c - lisp_gpe api
5 * Copyright (c) 2016 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/lisp-gpe/lisp_gpe.h>
26 #include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
27 #include <vnet/lisp-gpe/lisp_gpe_tenant.h>
29 #include <vnet/vnet_msg_enum.h>
31 #define vl_api_lisp_gpe_locator_pair_t_endian vl_noop_handler
32 #define vl_api_lisp_gpe_locator_pair_t_print vl_noop_handler
33 #define vl_api_lisp_gpe_add_del_fwd_entry_t_endian vl_noop_handler
34 #define vl_api_lisp_gpe_add_del_fwd_entry_t_print vl_noop_handler
36 #define vl_typedefs /* define message structures */
37 #include <vnet/vnet_all_api_h.h>
40 #define vl_endianfun /* define message structures */
41 #include <vnet/vnet_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #include <vnet/vnet_all_api_h.h>
50 #include <vlibapi/api_helper_macros.h>
52 #define foreach_vpe_api_msg \
53 _(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry) \
54 _(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable) \
55 _(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface)
57 static locator_pair_t *
58 unformat_lisp_loc_pairs (void *locs, u32 rloc_num)
61 locator_pair_t *pairs = 0, pair, *p;
62 vl_api_lisp_gpe_locator_t *r;
64 for (i = 0; i < rloc_num; i++)
67 r = &((vl_api_lisp_gpe_locator_t *) locs)[i];
68 memset (&pair, 0, sizeof (pair));
69 ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
71 pair.weight = r->weight;
72 vec_add1 (pairs, pair);
75 for (i = rloc_num; i < rloc_num * 2; i++)
78 r = &((vl_api_lisp_gpe_locator_t *) locs)[i];
79 p = &pairs[i - rloc_num];
80 ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
86 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
92 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
93 gid_address_ip_set (dst, src, IP4);
94 gid_address_ippref_len (dst) = len;
95 ip_prefix_normalize (&gid_address_ippref (dst));
98 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
99 gid_address_ip_set (dst, src, IP6);
100 gid_address_ippref_len (dst) = len;
101 ip_prefix_normalize (&gid_address_ippref (dst));
104 gid_address_type (dst) = GID_ADDR_MAC;
105 clib_memcpy (&gid_address_mac (dst), src, 6);
109 return VNET_API_ERROR_INVALID_VALUE;
112 gid_address_vni (dst) = vni;
118 lisp_gpe_add_del_fwd_entry_t_net_to_host
119 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
121 mp->vni = clib_net_to_host_u32 (mp->vni);
122 mp->dp_table = clib_net_to_host_u32 (mp->dp_table);
123 mp->loc_num = clib_net_to_host_u32 (mp->loc_num);
127 vl_api_lisp_gpe_add_del_fwd_entry_t_handler
128 (vl_api_lisp_gpe_add_del_fwd_entry_t * mp)
130 vl_api_lisp_gpe_add_del_fwd_entry_reply_t *rmp;
131 vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a;
132 locator_pair_t *pairs = 0;
135 lisp_gpe_add_del_fwd_entry_t_net_to_host (mp);
136 memset (a, 0, sizeof (a[0]));
138 rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
139 mp->rmt_eid, mp->rmt_len);
140 rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
141 mp->lcl_eid, mp->lcl_len);
143 if (mp->loc_num % 2 != 0)
148 pairs = unformat_lisp_loc_pairs (mp->locs, mp->loc_num / 2);
150 if (rv || 0 == pairs)
153 a->is_add = mp->is_add;
154 a->locator_pairs = pairs;
155 a->dp_table = mp->dp_table;
157 a->action = mp->action;
159 rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
162 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY);
166 vl_api_lisp_gpe_enable_disable_t_handler (vl_api_lisp_gpe_enable_disable_t *
169 vl_api_lisp_gpe_enable_disable_reply_t *rmp;
171 vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a;
173 a->is_en = mp->is_en;
174 vnet_lisp_gpe_enable_disable (a);
176 REPLY_MACRO (VL_API_LISP_GPE_ENABLE_DISABLE_REPLY);
180 vl_api_lisp_gpe_add_del_iface_t_handler (vl_api_lisp_gpe_add_del_iface_t * mp)
182 vl_api_lisp_gpe_add_del_iface_reply_t *rmp;
190 lisp_gpe_tenant_l2_iface_add_or_lock (mp->vni, mp->dp_table))
194 lisp_gpe_tenant_l2_iface_unlock (mp->vni);
201 lisp_gpe_tenant_l3_iface_add_or_lock (mp->vni, mp->dp_table))
205 lisp_gpe_tenant_l3_iface_unlock (mp->vni);
208 REPLY_MACRO (VL_API_LISP_GPE_ADD_DEL_IFACE_REPLY);
212 * lisp_gpe_api_hookup
213 * Add vpe's API message handlers to the table.
214 * vlib has alread mapped shared memory and
215 * added the client registration handlers.
216 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
218 #define vl_msg_name_crc_list
219 #include <vnet/vnet_all_api_h.h>
220 #undef vl_msg_name_crc_list
223 setup_message_id_table (api_main_t * am)
225 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
226 foreach_vl_msg_name_crc_lisp_gpe;
230 static clib_error_t *
231 lisp_gpe_api_hookup (vlib_main_t * vm)
233 api_main_t *am = &api_main;
236 vl_msg_api_set_handlers(VL_API_##N, #n, \
237 vl_api_##n##_t_handler, \
239 vl_api_##n##_t_endian, \
240 vl_api_##n##_t_print, \
241 sizeof(vl_api_##n##_t), 1);
246 * Set up the (msg_name, crc, message-id) table
248 setup_message_id_table (am);
253 VLIB_API_INIT_FUNCTION (lisp_gpe_api_hookup);
256 * fd.io coding-style-patch-verification: ON
259 * eval: (c-set-style "gnu")