FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_ext_itf.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
19 #include <plugins/gbp/gbp_itf.h>
20 
21 /**
22  * Pool of GBP ext_itfs
23  */
25 
26 /**
27  * external interface configs keyed by sw_if_index
28  */
30 
31 #define GBP_EXT_ITF_ID 0x00000080
32 
33 /**
34  * logger
35  */
37 
38 #define GBP_EXT_ITF_DBG(...) \
39  vlib_log_debug (gx_logger, __VA_ARGS__);
40 
41 u8 *
42 format_gbp_ext_itf (u8 * s, va_list * args)
43 {
44  gbp_ext_itf_t *gx = va_arg (*args, gbp_ext_itf_t *);
45 
46  return (format (s, "%U%s in %U",
48  (gx->gx_flags & GBP_EXT_ITF_F_ANON) ? " [anon]" : "",
50 }
51 
52 int
54 {
55  gbp_ext_itf_t *gx;
56  index_t gxi;
57 
59 
61 
62  if (INDEX_INVALID == gxi)
63  {
65  fib_protocol_t fproto;
66  index_t gbi, gri;
67 
69 
70  if (INDEX_INVALID == gbi)
71  return (VNET_API_ERROR_NO_SUCH_ENTRY);
72 
74 
75  if (INDEX_INVALID == gri)
76  {
78  return (VNET_API_ERROR_NO_SUCH_ENTRY);
79  }
80 
82  gxi = gx - gbp_ext_itf_pool;
83 
84  gr = gbp_route_domain_get (gri);
85 
86  gx->gx_bd = gbi;
87  gx->gx_rd = gri;
89 
91  {
92  gx->gx_fib_index[fproto] =
93  gr->grd_fib_index[fib_proto_to_dpo (fproto)];
94  }
95 
97  {
98  /* add interface to the BD */
100 
101  /* setup GBP L2 features on this interface */
103  L2INPUT_FEAT_GBP_LPM_ANON_CLASSIFY |
104  L2INPUT_FEAT_LEARN);
106  L2OUTPUT_FEAT_GBP_POLICY_LPM);
107  }
108 
109  gx->gx_flags = flags;
110 
112 
113  GBP_EXT_ITF_DBG ("add: %U", format_gbp_ext_itf, gx);
114 
115  return (0);
116  }
117 
118  return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
119 }
120 
121 int
123 {
124  gbp_ext_itf_t *gx;
125  index_t gxi;
126 
128  return (VNET_API_ERROR_INVALID_SW_IF_INDEX);
129 
131 
132  if (INDEX_INVALID != gxi)
133  {
135 
136  GBP_EXT_ITF_DBG ("del: %U", format_gbp_ext_itf, gx);
137 
138  gbp_itf_unlock (&gx->gx_itf);
141 
144 
145  return (0);
146  }
147  return (VNET_API_ERROR_NO_SUCH_ENTRY);
148 }
149 
150 static clib_error_t *
152  unformat_input_t * input, vlib_cli_command_t * cmd)
153 {
154  unformat_input_t _line_input, *line_input = &_line_input;
155  u32 sw_if_index = ~0, bd_id = ~0, rd_id = ~0, flags = 0;
156  int add = 1;
157  int rv;
158 
159  /* Get a line of input. */
160  if (!unformat_user (input, unformat_line_input, line_input))
161  return 0;
162 
163  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
164  {
165  if (unformat (line_input, "del"))
166  add = 0;
167  else
168  if (unformat
169  (line_input, "%U", unformat_vnet_sw_interface, vnet_get_main (),
170  &sw_if_index))
171  ;
172  else if (unformat (line_input, "bd %d", &bd_id))
173  ;
174  else if (unformat (line_input, "rd %d", &rd_id))
175  ;
176  else if (unformat (line_input, "anon-l3-out"))
178  else
179  return clib_error_return (0, "unknown input `%U'",
180  format_unformat_error, line_input);
181  }
182  unformat_free (line_input);
183 
184  if (~0 == sw_if_index)
185  return clib_error_return (0, "interface must be specified");
186 
187  if (add)
188  {
189  if (~0 == bd_id)
190  return clib_error_return (0, "BD-ID must be specified");
191  if (~0 == rd_id)
192  return clib_error_return (0, "RD-ID must be specified");
194  }
195  else
197 
198  switch (rv)
199  {
200  case 0:
201  return 0;
202  case VNET_API_ERROR_ENTRY_ALREADY_EXISTS:
203  return clib_error_return (0, "interface already exists");
204  case VNET_API_ERROR_NO_SUCH_ENTRY: /* fallthrough */
205  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
206  return clib_error_return (0, "unknown interface");
207  default:
208  return clib_error_return (0, "error %d", rv);
209  }
210 
211  /* never reached */
212  return 0;
213 }
214 
215 /*?
216  * Add Group Based Interface as anonymous L3out interface
217  *
218  * @cliexpar
219  * @cliexstart{gbp interface [del] anon-l3out <interface> bd <ID>}
220  * @cliexend
221  ?*/
222 /* *INDENT-OFF* */
224  .path = "gbp ext-itf",
225  .short_help = "gbp ext-itf [del] <interface> bd <ID> rd <ID> [anon-l3-out]\n",
226  .function = gbp_ext_itf_add_del_cli,
227 };
228 /* *INDENT-ON* */
229 
230 void
232 {
233  gbp_ext_itf_t *ge;
234 
235  /* *INDENT-OFF* */
237  {
238  if (!cb(ge, ctx))
239  break;
240  }
241  /* *INDENT-ON* */
242 }
243 
244 static walk_rc_t
246 {
247  vlib_cli_output (ctx, " %U", format_gbp_ext_itf, gx);
248 
249  return (WALK_CONTINUE);
250 }
251 
252 static clib_error_t *
254  unformat_input_t * input, vlib_cli_command_t * cmd)
255 {
256  vlib_cli_output (vm, "External-Interfaces:");
258 
259  return (NULL);
260 }
261 
262 /*?
263  * Show Group Based Policy external interface and derived information
264  *
265  * @cliexpar
266  * @cliexstart{show gbp ext-itf}
267  * @cliexend
268  ?*/
269 /* *INDENT-OFF* */
271  .path = "show gbp ext-itf",
272  .short_help = "show gbp ext-itf\n",
273  .function = gbp_ext_itf_show,
274 };
275 /* *INDENT-ON* */
276 
277 static clib_error_t *
279 {
280  gx_logger = vlib_log_register_class ("gbp", "ext-itf");
281 
282  return (NULL);
283 }
284 
286 
287 /*
288  * fd.io coding-style-patch-verification: ON
289  *
290  * Local Variables:
291  * eval: (c-set-style "gnu")
292  * End:
293  */
gbp_ext_itf_walk
void gbp_ext_itf_walk(gbp_ext_itf_cb_t cb, void *ctx)
Definition: gbp_ext_itf.c:231
gpb_ext_itf_t_::gx_fib_index
u32 gx_fib_index[DPO_PROTO_NUM]
cached FIB indices from the RD
Definition: gbp_ext_itf.h:53
gbp_itf_l2_set_input_feature
void gbp_itf_l2_set_input_feature(gbp_itf_hdl_t gh, l2input_feat_masks_t feats)
Definition: gbp_itf.c:384
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
FOR_EACH_FIB_IP_PROTOCOL
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:69
gbp_ext_itf_add
int gbp_ext_itf_add(u32 sw_if_index, u32 bd_id, u32 rd_id, u32 flags)
Definition: gbp_ext_itf.c:53
gpb_route_domain_t_::grd_fib_index
u32 grd_fib_index[FIB_PROTOCOL_IP_MAX]
Definition: gbp_route_domain.h:36
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
vlib_log_register_class
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:339
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
gbp_ext_itf_pool
gbp_ext_itf_t * gbp_ext_itf_pool
Pool of GBP ext_itfs.
Definition: gbp_ext_itf.c:24
format_gbp_bridge_domain
u8 * format_gbp_bridge_domain(u8 *s, va_list *args)
Definition: gbp_bridge_domain.c:168
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
gpb_route_domain_t_
A route Domain Representation.
Definition: gbp_route_domain.h:29
gbp_ext_itf_show_one
static walk_rc_t gbp_ext_itf_show_one(gbp_ext_itf_t *gx, void *ctx)
Definition: gbp_ext_itf.c:245
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
gbp_ext_itf_show
static clib_error_t * gbp_ext_itf_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gbp_ext_itf.c:253
gpb_ext_itf_t_::gx_flags
u32 gx_flags
The associated flags.
Definition: gbp_ext_itf.h:58
unformat_input_t
struct _unformat_input_t unformat_input_t
gbp_ext_itf_add_del_cli
static clib_error_t * gbp_ext_itf_add_del_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gbp_ext_itf.c:151
gbp_ext_itf_cb_t
walk_rc_t(* gbp_ext_itf_cb_t)(gbp_ext_itf_t *gbpe, void *ctx)
Definition: gbp_ext_itf.h:68
gbp_itf_anon_l3out_add_del_node
static vlib_cli_command_t gbp_itf_anon_l3out_add_del_node
(constructor) VLIB_CLI_COMMAND (gbp_itf_anon_l3out_add_del_node)
Definition: gbp_ext_itf.c:223
gbp_itf_l2_set_output_feature
void gbp_itf_l2_set_output_feature(gbp_itf_hdl_t gh, l2output_feat_masks_t feats)
Definition: gbp_itf.c:430
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
gbp_ext_itf_show_node
static vlib_cli_command_t gbp_ext_itf_show_node
(constructor) VLIB_CLI_COMMAND (gbp_ext_itf_show_node)
Definition: gbp_ext_itf.c:270
gbp_ext_itf.h
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
gbp_itf_hdl_reset
void gbp_itf_hdl_reset(gbp_itf_hdl_t *gh)
Definition: gbp_itf.c:110
gbp_ext_itf_init
static clib_error_t * gbp_ext_itf_init(vlib_main_t *vm)
Definition: gbp_ext_itf.c:278
bd_id
u32 bd_id
Definition: gbp.api:188
gx_logger
vlib_log_class_t gx_logger
logger
Definition: gbp_ext_itf.c:36
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
format_gbp_itf_hdl
u8 * format_gbp_itf_hdl(u8 *s, va_list *args)
Definition: gbp_itf.c:522
gpb_ext_itf_t_::gx_rd
index_t gx_rd
The RD this external interface is a member of.
Definition: gbp_ext_itf.h:48
gbp_itf.h
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
ge
u8 ge
Definition: ip_types.api:160
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
gbp_ext_itf_delete
int gbp_ext_itf_delete(u32 sw_if_index)
Definition: gbp_ext_itf.c:122
gbp_bridge_domain.h
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
fib_proto_to_dpo
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:343
GBP_EXT_ITF_DBG
#define GBP_EXT_ITF_DBG(...)
Definition: gbp_ext_itf.c:38
rd_id
u32 rd_id
Definition: gbp.api:35
gpb_ext_itf_t_::gx_bd
index_t gx_bd
The BD this external interface is a member of.
Definition: gbp_ext_itf.h:43
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
format
description fragment has unexpected format
Definition: map.api:433
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
gbp_itf_l2_add_and_lock
gbp_itf_hdl_t gbp_itf_l2_add_and_lock(u32 sw_if_index, index_t gbi)
Definition: gbp_itf.c:198
gbp_route_domain_get
gbp_route_domain_t * gbp_route_domain_get(index_t i)
Definition: gbp_route_domain.c:72
gbp_bridge_domain_find_and_lock
index_t gbp_bridge_domain_find_and_lock(u32 bd_id)
Definition: gbp_bridge_domain.c:91
gbp_route_domain_find_and_lock
index_t gbp_route_domain_find_and_lock(u32 rd_id)
Definition: gbp_route_domain.c:100
format_gbp_ext_itf
u8 * format_gbp_ext_itf(u8 *s, va_list *args)
Definition: gbp_ext_itf.c:42
vlib_main_t
Definition: main.h:102
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
gpb_ext_itf_t_::gx_itf
gbp_itf_hdl_t gx_itf
The interface.
Definition: gbp_ext_itf.h:38
gpb_ext_itf_t_
An external interface maps directly to an oflex L3ExternalInterface.
Definition: gbp_ext_itf.h:33
rv
int __clib_unused rv
Definition: application.c:491
gbp_route_domain.h
vlib_cli_command_t
Definition: cli.h:92
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
gbp_ext_itf_db
index_t * gbp_ext_itf_db
external interface configs keyed by sw_if_index
Definition: gbp_ext_itf.c:29
GBP_EXT_ITF_F_ANON
@ GBP_EXT_ITF_F_ANON
Definition: gbp_ext_itf.h:24
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
gbp_route_domain_unlock
void gbp_route_domain_unlock(index_t index)
Definition: gbp_route_domain.c:208
gbp_itf_unlock
void gbp_itf_unlock(gbp_itf_hdl_t *gh)
Definition: gbp_itf.c:288
gbp_bridge_domain_unlock
void gbp_bridge_domain_unlock(index_t gbdi)
Definition: gbp_bridge_domain.c:312
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105