FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
lisp_gpe_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * lisp_gpe_api.c - lisp_gpe api
4  *
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:
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 <vnet/lisp-gpe/lisp_gpe.h>
30 
31 #include <vnet/vnet_msg_enum.h>
32 
33 #define vl_api_gpe_locator_pair_t_endian vl_noop_handler
34 #define vl_api_gpe_locator_pair_t_print vl_noop_handler
35 #define vl_api_gpe_add_del_fwd_entry_t_endian vl_noop_handler
36 #define vl_api_gpe_add_del_fwd_entry_t_print vl_noop_handler
37 
38 #define vl_typedefs /* define message structures */
39 #include <vnet/vnet_all_api_h.h>
40 #undef vl_typedefs
41 
42 #define vl_endianfun /* define message structures */
43 #include <vnet/vnet_all_api_h.h>
44 #undef vl_endianfun
45 
46 /* instantiate all the print functions we know about */
47 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
48 #define vl_printfun
49 #include <vnet/vnet_all_api_h.h>
50 #undef vl_printfun
51 
53 
54 #define foreach_vpe_api_msg \
55 _(GPE_ADD_DEL_FWD_ENTRY, gpe_add_del_fwd_entry) \
56 _(GPE_FWD_ENTRIES_GET, gpe_fwd_entries_get) \
57 _(GPE_FWD_ENTRY_PATH_DUMP, gpe_fwd_entry_path_dump) \
58 _(GPE_ENABLE_DISABLE, gpe_enable_disable) \
59 _(GPE_ADD_DEL_IFACE, gpe_add_del_iface) \
60 _(GPE_SET_ENCAP_MODE, gpe_set_encap_mode) \
61 _(GPE_GET_ENCAP_MODE, gpe_get_encap_mode)
62 
63 static locator_pair_t *
64 unformat_gpe_loc_pairs (void *locs, u32 rloc_num)
65 {
66  u32 i;
67  locator_pair_t *pairs = 0, pair, *p;
69 
70  for (i = 0; i < rloc_num; i++)
71  {
72  /* local locator */
73  r = &((vl_api_gpe_locator_t *) locs)[i];
74  memset (&pair, 0, sizeof (pair));
75  ip_address_set (&pair.lcl_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
76 
77  pair.weight = r->weight;
78  vec_add1 (pairs, pair);
79  }
80 
81  for (i = rloc_num; i < rloc_num * 2; i++)
82  {
83  /* remote locators */
84  r = &((vl_api_gpe_locator_t *) locs)[i];
85  p = &pairs[i - rloc_num];
86  ip_address_set (&p->rmt_loc, &r->addr, r->is_ip4 ? IP4 : IP6);
87  }
88  return pairs;
89 }
90 
91 static int
92 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
93  u8 len)
94 {
95  switch (type)
96  {
97  case 0: /* ipv4 */
99  gid_address_ip_set (dst, src, IP4);
100  gid_address_ippref_len (dst) = len;
102  break;
103  case 1: /* ipv6 */
105  gid_address_ip_set (dst, src, IP6);
106  gid_address_ippref_len (dst) = len;
108  break;
109  case 2: /* l2 mac */
111  clib_memcpy (&gid_address_mac (dst), src, 6);
112  break;
113  default:
114  /* unknown type */
115  return VNET_API_ERROR_INVALID_VALUE;
116  }
117 
118  gid_address_vni (dst) = vni;
119 
120  return 0;
121 }
122 
123 static void
126 {
127  mp->fwd_entry_index = clib_net_to_host_u32 (mp->fwd_entry_index);
128 }
129 
130 static void
132  const ip_address_t * addr, u8 weight)
133 {
134  loc->weight = weight;
135  if (IP4 == ip_addr_version (addr))
136  {
137  loc->is_ip4 = 1;
138  memcpy (loc->addr, addr, 4);
139  }
140  else
141  {
142  loc->is_ip4 = 0;
143  memcpy (loc->addr, addr, 16);
144  }
145 }
146 
147 static void
150 {
151  lisp_fwd_path_t *path;
156 
158 
160  if (q == 0)
161  return;
162 
164  return;
165 
167 
169  return;
170 
171  vec_foreach (path, lfe->paths)
172  {
173  rmp = vl_msg_api_alloc (sizeof (*rmp));
174  memset (rmp, 0, sizeof (*rmp));
175  const lisp_gpe_tunnel_t *lgt;
176 
177  rmp->_vl_msg_id =
178  clib_host_to_net_u16 (VL_API_GPE_FWD_ENTRY_PATH_DETAILS);
179 
180  const lisp_gpe_adjacency_t *ladj =
182  lisp_api_set_locator (&rmp->rmt_loc, &ladj->remote_rloc, path->weight);
183  lgt = lisp_gpe_tunnel_get (ladj->tunnel_index);
184  lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight);
185 
186  rmp->context = mp->context;
187  vl_msg_api_send_shmem (q, (u8 *) & rmp);
188  }
189 }
190 
191 static void
194 {
196  u32 i = 0;
197 
198  vec_foreach (e, src)
199  {
200  memset (dst, 0, sizeof (*dst));
201  dst[i].dp_table = src->dp_table;
202  dst[i].fwd_entry_index = src->fwd_entry_index;
203  switch (fid_addr_type (&e->leid))
204  {
205  case FID_ADDR_IP_PREF:
206  if (IP4 == ip_prefix_version (&fid_addr_ippref (&e->leid)))
207  {
208  memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 4);
209  memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 4);
210  dst[i].eid_type = 0;
211  }
212  else
213  {
214  memcpy (&dst[i].leid, &fid_addr_ippref (&e->leid), 16);
215  memcpy (&dst[i].reid, &fid_addr_ippref (&e->reid), 16);
216  dst[i].eid_type = 1;
217  }
220  break;
221  case FID_ADDR_MAC:
222  memcpy (&dst[i].leid, fid_addr_mac (&e->leid), 6);
223  memcpy (&dst[i].reid, fid_addr_mac (&e->reid), 6);
224  dst[i].eid_type = 2;
225  break;
226  default:
227  clib_warning ("unknown fid type %d!", fid_addr_type (&e->leid));
228  break;
229  }
230  i++;
231  }
232 }
233 
234 static void
236 {
237  mp->vni = clib_net_to_host_u32 (mp->vni);
238 }
239 
240 static void
242 {
243  e->fwd_entry_index = clib_host_to_net_u32 (e->fwd_entry_index);
244  e->dp_table = clib_host_to_net_u32 (e->dp_table);
245 }
246 
247 static void
250 {
251  u32 i;
253 
254  for (i = 0; i < mp->count; i++)
255  {
256  e = &mp->entries[i];
258  }
259  mp->count = clib_host_to_net_u32 (mp->count);
260 }
261 
262 static void
264 {
267  u32 size = 0;
268  int rv = 0;
269 
271 
273  size = vec_len (e) * sizeof (vl_api_gpe_fwd_entry_t);
274 
275  /* *INDENT-OFF* */
276  REPLY_MACRO4 (VL_API_GPE_FWD_ENTRIES_GET_REPLY, size,
277  {
278  rmp->count = vec_len (e);
279  gpe_fwd_entries_copy (rmp->entries, e);
281  });
282  /* *INDENT-ON* */
283 
284  vec_free (e);
285 }
286 
287 static void
289 {
290  mp->vni = clib_net_to_host_u32 (mp->vni);
291  mp->dp_table = clib_net_to_host_u32 (mp->dp_table);
292  mp->loc_num = clib_net_to_host_u32 (mp->loc_num);
293 }
294 
295 static void
297 {
300  locator_pair_t *pairs = 0;
301  int rv = 0;
302 
304  memset (a, 0, sizeof (a[0]));
305 
306  rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, mp->eid_type,
307  mp->rmt_eid, mp->rmt_len);
308  rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, mp->eid_type,
309  mp->lcl_eid, mp->lcl_len);
310 
311  if (mp->loc_num % 2 != 0)
312  {
313  rv = -1;
314  goto send_reply;
315  }
316  pairs = unformat_gpe_loc_pairs (mp->locs, mp->loc_num / 2);
317 
318  if (rv || 0 == pairs)
319  goto send_reply;
320 
321  a->is_add = mp->is_add;
322  a->locator_pairs = pairs;
323  a->dp_table = mp->dp_table;
324  a->vni = mp->vni;
325  a->action = mp->action;
326 
328  vec_free (pairs);
329 send_reply:
330  REPLY_MACRO (VL_API_GPE_ADD_DEL_FWD_ENTRY_REPLY);
331 }
332 
333 static void
335 {
337  int rv = 0;
339 
340  a->is_en = mp->is_en;
342 
343  REPLY_MACRO (VL_API_GPE_ENABLE_DISABLE_REPLY);
344 }
345 
346 static void
348 {
350  int rv = 0;
351 
352  if (mp->is_l2)
353  {
354  if (mp->is_add)
355  {
356  if (~0 ==
358  rv = 1;
359  }
360  else
362  }
363  else
364  {
365  if (mp->is_add)
366  {
367  if (~0 ==
369  rv = 1;
370  }
371  else
373  }
374 
375  REPLY_MACRO (VL_API_GPE_ADD_DEL_IFACE_REPLY);
376 }
377 
378 static void
380 {
382  int rv = 0;
383 
384  rv = vnet_gpe_set_encap_mode (mp->mode);
385  REPLY_MACRO (VL_API_GPE_SET_ENCAP_MODE_REPLY);
386 }
387 
388 static void
390 {
392  int rv = 0;
393 
394  /* *INDENT-OFF* */
395  REPLY_MACRO2 (VL_API_GPE_GET_ENCAP_MODE_REPLY,
396  ({
398  }));
399  /* *INDENT-ON* */
400 }
401 
402 /*
403  * gpe_api_hookup
404  * Add vpe's API message handlers to the table.
405  * vlib has alread mapped shared memory and
406  * added the client registration handlers.
407  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
408  */
409 #define vl_msg_name_crc_list
410 #include <vnet/vnet_all_api_h.h>
411 #undef vl_msg_name_crc_list
412 
413 static void
415 {
416 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
417  foreach_vl_msg_name_crc_lisp_gpe;
418 #undef _
419 }
420 
421 static clib_error_t *
423 {
424  api_main_t *am = &api_main;
425 
426 #define _(N,n) \
427  vl_msg_api_set_handlers(VL_API_##N, #n, \
428  vl_api_##n##_t_handler, \
429  vl_noop_handler, \
430  vl_api_##n##_t_endian, \
431  vl_api_##n##_t_print, \
432  sizeof(vl_api_##n##_t), 1);
434 #undef _
435 
436  /*
437  * Set up the (msg_name, crc, message-id) table
438  */
440 
441  return 0;
442 }
443 
445 
446 /*
447  * fd.io coding-style-patch-verification: ON
448  *
449  * Local Variables:
450  * eval: (c-set-style "gnu")
451  * End:
452  */
u32 fwd_entry_index
Definition: lisp_gpe.h:271
void lisp_gpe_tenant_l2_iface_unlock(u32 vni)
Release the lock held on the tenant&#39;s L3 interface.
vl_api_gpe_locator_t lcl_loc
Definition: lisp_gpe.api:157
const lisp_gpe_tunnel_t * lisp_gpe_tunnel_get(index_t lgti)
add or delete gpe_iface
Definition: lisp_gpe.api:100
Set GPE encapsulation mode.
Definition: lisp_gpe.api:166
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
#define gid_address_type(_a)
Definition: lisp_types.h:241
u8 eid_type
Definition: lisp_gpe.api:51
a
Definition: bitmap.h:516
Reply for gpe_iface add/del.
Definition: lisp_gpe.api:114
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
Reply for gpe enable/disable.
Definition: lisp_gpe.api:89
#define REPLY_MACRO4(t, n, body)
static void gpe_fwd_entry_path_dump_t_net_to_host(vl_api_gpe_fwd_entry_path_dump_t *mp)
Definition: lisp_gpe_api.c:125
void lisp_gpe_tenant_l3_iface_unlock(u32 vni)
Release the lock held on the tenant&#39;s L3 interface.
GPE locator structure.
Definition: lisp_gpe.api:21
#define REPLY_MACRO2(t, body)
clib_error_t * vnet_lisp_gpe_enable_disable(vnet_lisp_gpe_enable_disable_args_t *a)
Enable/disable LISP-GPE.
Definition: lisp_gpe.c:190
#define NULL
Definition: clib.h:55
LISP-GPE global state.
Definition: lisp_gpe.h:118
#define ip_prefix_len(_a)
Definition: lisp_types.h:73
u32 dp_table
Definition: lisp_gpe.api:57
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
LISP-GPE definitions.
static void vl_api_gpe_add_del_iface_t_handler(vl_api_gpe_add_del_iface_t *mp)
Definition: lisp_gpe_api.c:347
vl_api_gpe_fwd_entry_t entries[count]
Definition: lisp_gpe.api:143
void ip_address_set(ip_address_t *dst, const void *src, u8 version)
Definition: lisp_types.c:843
u8 is_add
Definition: lisp_gpe.api:50
#define ip_prefix_version(_a)
Definition: lisp_types.h:72
#define fid_addr_mac(_a)
Definition: lisp_types.h:131
u8 eid_type
Definition: lisp_gpe.api:131
u8 reid_prefix_len
Definition: lisp_gpe.api:133
api_main_t api_main
Definition: api_shared.c:35
Reply for set_encap_mode.
Definition: lisp_gpe.api:177
static void setup_message_id_table(api_main_t *am)
Definition: lisp_gpe_api.c:414
static void vl_api_gpe_add_del_fwd_entry_t_handler(vl_api_gpe_add_del_fwd_entry_t *mp)
Definition: lisp_gpe_api.c:296
u8 is_add
Definition: lisp_gpe.h:226
u8 rmt_eid[16]
Definition: lisp_gpe.api:52
lisp_gpe_fwd_entry_type_t type
The forwarding entry type.
static void vl_api_gpe_get_encap_mode_t_handler(vl_api_gpe_get_encap_mode_t *mp)
Definition: lisp_gpe_api.c:389
u8 leid_prefix_len
Definition: lisp_gpe.api:132
u32 lisp_gpe_tenant_l2_iface_add_or_lock(u32 vni, u32 bd_id)
Add/create and lock a new or find and lock the existing L2 interface for the tenant.
Definition: lisp_gpe.h:222
#define ip_addr_version(_a)
Definition: lisp_types.h:56
Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels.
lisp_api_gpe_fwd_entry_t * vnet_lisp_gpe_fwd_entries_get_by_vni(u32 vni)
u8 action
Definition: lisp_gpe.api:58
#define gid_address_mac(_a)
Definition: lisp_types.h:247
u32 context
Definition: lisp_gpe.api:156
u32 context
Definition: lisp_gpe.api:149
Reply for set_encap_mode.
Definition: lisp_gpe.api:199
u8 lcl_eid[16]
Definition: lisp_gpe.api:53
u32 loc_num
Definition: lisp_gpe.api:59
vl_api_gpe_locator_t locs[loc_num]
Definition: lisp_gpe.api:60
static void vl_api_gpe_set_encap_mode_t_handler(vl_api_gpe_set_encap_mode_t *mp)
Definition: lisp_gpe_api.c:379
#define REPLY_MACRO(t)
const lisp_gpe_adjacency_t * lisp_gpe_adjacency_get(index_t lai)
Definition: lisp_gpe.api:127
u32 vni
Definition: lisp_gpe.api:56
void ip_prefix_normalize(ip_prefix_t *a)
Definition: lisp_types.c:923
Definition: lisp_gpe.h:269
#define gid_address_ippref(_a)
Definition: lisp_types.h:242
vl_api_gpe_locator_t rmt_loc
Definition: lisp_gpe.api:158
get GPE encapsulation mode
Definition: lisp_gpe.api:188
static void lisp_api_set_locator(vl_api_gpe_locator_t *loc, const ip_address_t *addr, u8 weight)
Definition: lisp_gpe_api.c:131
static void gpe_fwd_entries_copy(vl_api_gpe_fwd_entry_t *dst, lisp_api_gpe_fwd_entry_t *src)
Definition: lisp_gpe_api.c:192
u32 vni
VNI/tenant id in HOST byte order.
Definition: lisp_gpe.h:253
void * vl_msg_api_alloc(int nbytes)
u32 fwd_entry_index
Definition: lisp_gpe.api:129
vlib_main_t * vm
Definition: buffer.c:276
void gid_address_ip_set(gid_address_t *dst, void *src, u8 version)
Definition: lisp_types.c:1465
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
dp_address_t reid
Definition: lisp_gpe.h:275
#define gid_address_ippref_len(_a)
Definition: lisp_types.h:243
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:69
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:238
lisp_gpe_main_t lisp_gpe_main
LISP-GPE global state.
Definition: lisp_gpe.c:27
lisp_gpe_tunnel_key_t * key
RLOC pair and rloc fib_index.
#define fid_addr_ippref(_a)
Definition: lisp_types.h:128
int vnet_lisp_gpe_add_del_fwd_entry(vnet_lisp_gpe_add_del_fwd_entry_args_t *a, u32 *hw_if_indexp)
Forwarding entry create/remove dispatcher.
struct _gid_address_t gid_address_t
gpe_encap_mode_t vnet_gpe_get_encap_mode(void)
Definition: lisp_gpe.c:436
#define fid_addr_type(_a)
Definition: lisp_types.h:133
u32 client_index
Definition: lisp_gpe.api:148
unsigned int u32
Definition: types.h:88
u8 rmt_len
Definition: lisp_gpe.api:54
A path on which to forward lisp traffic.
u8 weight
[UE]CMP weigt for the path
Definition: lisp_gpe.api:153
u64 size
Definition: vhost-user.h:77
static void gpe_entry_t_host_to_net(vl_api_gpe_fwd_entry_t *e)
Definition: lisp_gpe_api.c:241
static clib_error_t * gpe_api_hookup(vlib_main_t *vm)
Definition: lisp_gpe_api.c:422
int vnet_gpe_set_encap_mode(gpe_encap_mode_t mode)
Set GPE encapsulation mode.
Definition: lisp_gpe.c:214
gid_address_t rmt_eid
remote eid
Definition: lisp_gpe.h:238
static void vl_api_gpe_fwd_entry_path_dump_t_handler(vl_api_gpe_fwd_entry_path_dump_t *mp)
Definition: lisp_gpe_api.c:149
#define foreach_vpe_api_msg
Definition: lisp_gpe_api.c:54
u32 dp_table
Definition: lisp_gpe.api:130
negative_fwd_actions_e action
action for negative mappings
Definition: lisp_gpe.h:232
A LISP GPE Adjacency.
#define gid_address_vni(_a)
Definition: lisp_types.h:249
struct lisp_gpe_fwd_entry_t_ * lisp_fwd_entry_pool
A Pool of all LISP forwarding entries.
Definition: lisp_gpe.h:129
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
add or delete GPE tunnel
Definition: lisp_gpe.api:46
u32 tunnel_index
The index of the LISP GPE tunnel that provides the transport in the underlay.
u32 dp_table
generic access
Definition: lisp_gpe.h:265
static void gpe_fwd_entries_get_t_net_to_host(vl_api_gpe_fwd_entries_get_t *mp)
Definition: lisp_gpe_api.c:235
locator_pair_t * locator_pairs
vector of locator pairs
Definition: lisp_gpe.h:241
Definition: lisp_types.h:37
lisp_fwd_path_t * paths
When the type is &#39;normal&#39; The RLOC pair that form the route&#39;s paths.
u8 lcl_len
Definition: lisp_gpe.api:55
Reply for gpe_fwd_entry add/del.
Definition: lisp_gpe.api:67
#define vec_foreach(var, vec)
Vector iterator.
dp_address_t leid
Definition: lisp_gpe.h:274
static void vl_api_gpe_fwd_entries_get_t_handler(vl_api_gpe_fwd_entries_get_t *mp)
Definition: lisp_gpe_api.c:263
u32 fwd_entry_index
Definition: lisp_gpe.api:150
vhost_vring_addr_t addr
Definition: vhost-user.h:84
static void vl_api_gpe_enable_disable_t_handler(vl_api_gpe_enable_disable_t *mp)
Definition: lisp_gpe_api.c:334
Definition: lisp_types.h:38
VLIB_API_INIT_FUNCTION(gpe_api_hookup)
gid_address_t lcl_eid
local eid
Definition: lisp_gpe.h:235
static int unformat_lisp_eid_api(gid_address_t *dst, u32 vni, u8 type, void *src, u8 len)
Definition: lisp_gpe_api.c:92
static locator_pair_t * unformat_gpe_loc_pairs(void *locs, u32 rloc_num)
Definition: lisp_gpe_api.c:64
u32 lisp_gpe_tenant_l3_iface_add_or_lock(u32 vni, u32 table_id)
Add/create and lock a new or find and lock the existing L3 interface for the tenant.
ip_address_t remote_rloc
remote RLOC.
A LISP GPE Tunnel.
LISP-GPE definitions.
static void gpe_add_del_fwd_entry_t_net_to_host(vl_api_gpe_add_del_fwd_entry_t *mp)
Definition: lisp_gpe_api.c:288
enable or disable gpe protocol
Definition: lisp_gpe.api:78
static void gpe_fwd_entries_get_reply_t_host_to_net(vl_api_gpe_fwd_entries_get_reply_t *mp)
Definition: lisp_gpe_api.c:249
struct _unix_shared_memory_queue unix_shared_memory_queue_t
index_t lisp_adj
The adjacency constructed for the locator pair.
A LISP Forwarding Entry.
Definition: lisp_gpe.api:146
u32 dp_table
Definition: lisp_gpe.h:272