FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
lisp_gpe.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file
17  * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels.
18  *
19  */
20 
21 #include <vnet/lisp-gpe/lisp_gpe.h>
25 
26 /** LISP-GPE global state */
28 
29 
30 /** CLI command to add/del forwarding entry. */
31 static clib_error_t *
33  unformat_input_t * input,
34  vlib_cli_command_t * cmd)
35 {
36  unformat_input_t _line_input, *line_input = &_line_input;
37  u8 is_add = 1;
38  ip_address_t lloc, rloc;
39  clib_error_t *error = 0;
40  gid_address_t _reid, *reid = &_reid, _leid, *leid = &_leid;
41  u8 reid_set = 0, leid_set = 0, is_negative = 0, vrf_set = 0, vni_set = 0;
42  u32 vni, vrf, action = ~0, p, w;
43  locator_pair_t pair, *pairs = 0;
44  int rv;
45 
46  /* Get a line of input. */
47  if (!unformat_user (input, unformat_line_input, line_input))
48  return 0;
49 
50  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
51  {
52  if (unformat (line_input, "del"))
53  is_add = 0;
54  else if (unformat (line_input, "add"))
55  is_add = 1;
56  else if (unformat (line_input, "leid %U", unformat_gid_address, leid))
57  {
58  leid_set = 1;
59  }
60  else if (unformat (line_input, "reid %U", unformat_gid_address, reid))
61  {
62  reid_set = 1;
63  }
64  else if (unformat (line_input, "vni %u", &vni))
65  {
66  gid_address_vni (leid) = vni;
67  gid_address_vni (reid) = vni;
68  vni_set = 1;
69  }
70  else if (unformat (line_input, "vrf %u", &vrf))
71  {
72  vrf_set = 1;
73  }
74  else if (unformat (line_input, "bd %u", &vrf))
75  {
76  vrf_set = 1;
77  }
78  else if (unformat (line_input, "negative action %U",
80  {
81  is_negative = 1;
82  }
83  else if (unformat (line_input, "loc-pair %U %U p %d w %d",
84  unformat_ip_address, &lloc,
85  unformat_ip_address, &rloc, &p, &w))
86  {
87  pair.lcl_loc = lloc;
88  pair.rmt_loc = rloc;
89  pair.priority = p;
90  pair.weight = w;
91  vec_add1 (pairs, pair);
92  }
93  else
94  {
95  error = unformat_parse_error (line_input);
96  goto done;
97  }
98  }
99  unformat_free (line_input);
100 
101  if (!vni_set || !vrf_set)
102  {
103  error = clib_error_return (0, "vni and vrf must be set!");
104  goto done;
105  }
106 
107  if (!reid_set)
108  {
109  error = clib_error_return (0, "remote eid must be set!");
110  goto done;
111  }
112 
113  if (is_negative)
114  {
115  if (~0 == action)
116  {
117  error = clib_error_return (0, "no action set for negative tunnel!");
118  goto done;
119  }
120  }
121  else
122  {
123  if (vec_len (pairs) == 0)
124  {
125  error = clib_error_return (0, "expected ip4/ip6 locators.");
126  goto done;
127  }
128  }
129 
130  if (!leid_set)
131  {
132  /* if leid not set, make sure it's the same AFI like reid */
133  gid_address_type (leid) = gid_address_type (reid);
134  if (GID_ADDR_IP_PREFIX == gid_address_type (reid))
136  }
137 
138  /* add fwd entry */
140  memset (a, 0, sizeof (a[0]));
141 
142  a->is_add = is_add;
143  a->is_negative = is_negative;
144  a->vni = vni;
145  a->table_id = vrf;
146  gid_address_copy (&a->lcl_eid, leid);
147  gid_address_copy (&a->rmt_eid, reid);
148  a->locator_pairs = pairs;
149 
151  if (0 != rv)
152  {
153  error = clib_error_return (0, "failed to %s gpe tunnel!",
154  is_add ? "add" : "delete");
155  }
156 
157 done:
158  vec_free (pairs);
159  return error;
160 }
161 
162 /* *INDENT-OFF* */
163 VLIB_CLI_COMMAND (lisp_gpe_add_del_fwd_entry_command, static) = {
164  .path = "lisp gpe entry",
165  .short_help = "lisp gpe entry add/del vni <vni> vrf <vrf> [leid <leid>]"
166  "reid <reid> [loc-pair <lloc> <rloc> p <priority> w <weight>] "
167  "[negative action <action>]",
169 };
170 /* *INDENT-ON* */
171 
172 /** Check if LISP-GPE is enabled. */
173 u8
175 {
177 
178  return lgm->is_en;
179 }
180 
181 /** Enable/disable LISP-GPE. */
182 clib_error_t *
184 {
186 
187  if (a->is_en)
188  {
189  lgm->is_en = 1;
190  }
191  else
192  {
193  /* remove all entries */
195 
196  /* disable all l3 ifaces */
198 
199  lgm->is_en = 0;
200  }
201 
202  return 0;
203 }
204 
205 /** CLI command to enable/disable LISP-GPE. */
206 static clib_error_t *
208  unformat_input_t * input,
209  vlib_cli_command_t * cmd)
210 {
211  unformat_input_t _line_input, *line_input = &_line_input;
212  u8 is_en = 1;
214 
215  /* Get a line of input. */
216  if (!unformat_user (input, unformat_line_input, line_input))
217  return 0;
218 
219  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
220  {
221  if (unformat (line_input, "enable"))
222  is_en = 1;
223  else if (unformat (line_input, "disable"))
224  is_en = 0;
225  else
226  {
227  return clib_error_return (0, "parse error: '%U'",
228  format_unformat_error, line_input);
229  }
230  }
231  a->is_en = is_en;
232  return vnet_lisp_gpe_enable_disable (a);
233 }
234 
235 /* *INDENT-OFF* */
236 VLIB_CLI_COMMAND (enable_disable_lisp_gpe_command, static) = {
237  .path = "lisp gpe",
238  .short_help = "lisp gpe [enable|disable]",
240 };
241 /* *INDENT-ON* */
242 
243 /** CLI command to show LISP-GPE interfaces. */
244 static clib_error_t *
246  unformat_input_t * input,
247  vlib_cli_command_t * cmd)
248 {
250  hash_pair_t *p;
251 
252  vlib_cli_output (vm, "%=10s%=12s", "vrf", "hw_if_index");
253 
254  /* *INDENT-OFF* */
256  vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
257  }));
258  /* *INDENT-ON* */
259 
260  if (0 != lgm->l2_ifaces.hw_if_index_by_dp_table)
261  {
262  vlib_cli_output (vm, "%=10s%=12s", "bd_id", "hw_if_index");
263  /* *INDENT-OFF* */
265  vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
266  }));
267  /* *INDENT-ON* */
268  }
269  return 0;
270 }
271 
272 /* *INDENT-OFF* */
273 VLIB_CLI_COMMAND (lisp_show_iface_command) = {
274  .path = "show lisp gpe interface",
275  .short_help = "show lisp gpe interface",
276  .function = lisp_show_iface_command_fn,
277 };
278 /* *INDENT-ON* */
279 
280 /** Format LISP-GPE status. */
281 u8 *
282 format_vnet_lisp_gpe_status (u8 * s, va_list * args)
283 {
285  return format (s, "%s", lgm->is_en ? "enabled" : "disabled");
286 }
287 
288 
289 /** LISP-GPE init function. */
290 clib_error_t *
292 {
294  clib_error_t *error = 0;
295 
296  if ((error = vlib_call_init_function (vm, ip_main_init)))
297  return error;
298 
299  if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
300  return error;
301 
302  lgm->vnet_main = vnet_get_main ();
303  lgm->vlib_main = vm;
304  lgm->im4 = &ip4_main;
305  lgm->im6 = &ip6_main;
306  lgm->lm4 = &ip4_main.lookup_main;
307  lgm->lm6 = &ip6_main.lookup_main;
308 
309  lgm->lisp_gpe_fwd_entries =
310  hash_create_mem (0, sizeof (lisp_gpe_fwd_entry_key_t), sizeof (uword));
311 
312  udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe,
313  lisp_gpe_ip4_input_node.index, 1 /* is_ip4 */ );
314  udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe6,
315  lisp_gpe_ip6_input_node.index, 0 /* is_ip4 */ );
316  return 0;
317 }
318 
320 
321 /*
322  * fd.io coding-style-patch-verification: ON
323  *
324  * Local Variables:
325  * eval: (c-set-style "gnu")
326  * End:
327  */
#define gid_address_ip_version(_a)
Definition: lisp_types.h:232
vlib_node_registration_t lisp_gpe_ip4_input_node
(constructor) VLIB_REGISTER_NODE (lisp_gpe_ip4_input_node)
Definition: decap.c:452
#define gid_address_type(_a)
Definition: lisp_types.h:228
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
a
Definition: bitmap.h:516
u8 vnet_lisp_gpe_enable_disable_status(void)
Check if LISP-GPE is enabled.
Definition: lisp_gpe.c:174
void vnet_lisp_gpe_fwd_entry_flush(void)
Flush all the forwrding entries.
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
clib_error_t * vnet_lisp_gpe_enable_disable(vnet_lisp_gpe_enable_disable_args_t *a)
Enable/disable LISP-GPE.
Definition: lisp_gpe.c:183
LISP-GPE global state.
Definition: lisp_gpe.h:89
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:147
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
LISP-GPE definitions.
ip_lookup_main_t lookup_main
Definition: ip4.h:97
vlib_main_t * vlib_main
convenience
Definition: lisp_gpe.h:123
uword unformat_negative_mapping_action(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:333
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
ip6_main_t * im6
Definition: lisp_gpe.h:126
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
LISP-GPE fwd entry key.
u8 is_add
Definition: lisp_gpe.h:180
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
uword * lisp_gpe_fwd_entries
DB of all forwarding entries.
Definition: lisp_gpe.h:95
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
#define vlib_call_init_function(vm, x)
Definition: init.h:161
Definition: lisp_gpe.h:178
Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys.
vlib_node_registration_t lisp_gpe_ip6_input_node
(constructor) VLIB_REGISTER_NODE (lisp_gpe_ip6_input_node)
Definition: decap.c:474
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:637
u32 table_id
table (vrf) id
Definition: lisp_gpe.h:213
#define unformat_parse_error(input)
Definition: format.h:267
uword unformat_gid_address(unformat_input_t *input, va_list *args)
Definition: lisp_types.c:298
ip_address_t lcl_loc
Definition: lisp_types.h:334
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:576
u8 is_negative
type of mapping
Definition: lisp_gpe.h:183
u32 vni
VNI/tenant id in HOST byte order.
Definition: lisp_gpe.h:207
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
static clib_error_t * lisp_show_iface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI command to show LISP-GPE interfaces.
Definition: lisp_gpe.c:245
tunnel_lookup_t l2_ifaces
Definition: lisp_gpe.h:117
vnet_main_t * vnet_main
Definition: lisp_gpe.h:124
void lisp_gpe_tenant_flush(void)
Flush/delete ALL the tenants.
lisp_gpe_main_t lisp_gpe_main
LISP-GPE global state.
Definition: lisp_gpe.c:27
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
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
u8 * format_vnet_lisp_gpe_status(u8 *s, va_list *args)
Format LISP-GPE status.
Definition: lisp_gpe.c:282
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip6_main_t ip6_main
Definition: ip6_forward.c:2828
ip_lookup_main_t lookup_main
Definition: ip6.h:135
clib_error_t * lisp_gpe_init(vlib_main_t *vm)
LISP-GPE init function.
Definition: lisp_gpe.c:291
uword * hw_if_index_by_dp_table
Lookup lisp-gpe interfaces by dp table (eg.
Definition: lisp_gpe.h:79
gid_address_t rmt_eid
remote eid
Definition: lisp_gpe.h:192
clib_error_t * ip4_lookup_init(vlib_main_t *vm)
Definition: ip4_forward.c:1102
u64 uword
Definition: types.h:112
#define gid_address_vni(_a)
Definition: lisp_types.h:235
static clib_error_t * lisp_gpe_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI command to enable/disable LISP-GPE.
Definition: lisp_gpe.c:207
ip_lookup_main_t * lm4
Definition: lisp_gpe.h:127
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
tunnel_lookup_t l3_ifaces
Definition: lisp_gpe.h:109
ip4_main_t * im4
Definition: lisp_gpe.h:125
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
Definition: hash.h:349
locator_pair_t * locator_pairs
vector of locator pairs
Definition: lisp_gpe.h:195
void gid_address_copy(gid_address_t *dst, gid_address_t *src)
Definition: lisp_types.c:1295
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1099
ip_address_t rmt_loc
Definition: lisp_types.h:335
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:495
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
ip_lookup_main_t * lm6
Definition: lisp_gpe.h:128
gid_address_t lcl_eid
local eid
Definition: lisp_gpe.h:189
unformat_function_t unformat_line_input
Definition: format.h:281
LISP-GPE definitions.
static clib_error_t * lisp_gpe_add_del_fwd_entry_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI command to add/del forwarding entry.
Definition: lisp_gpe.c:32