FD.io VPP  v19.01.3-6-g70449b9b9
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 in %U",
49 }
50 
51 int
53 {
54  gbp_ext_itf_t *gx;
55  index_t gxi;
56 
58 
60 
61  if (INDEX_INVALID == gxi)
62  {
65  fib_protocol_t fproto;
66  index_t gbi, gri;
67 
68  gbi = gbp_bridge_domain_find_and_lock (bd_id);
69 
70  if (INDEX_INVALID == gbi)
71  return (VNET_API_ERROR_NO_SUCH_ENTRY);
72 
73  gri = gbp_route_domain_find_and_lock (rd_id);
74 
75  if (INDEX_INVALID == gri)
76  {
78  return (VNET_API_ERROR_NO_SUCH_ENTRY);
79  }
80 
81  pool_get_zero (gbp_ext_itf_pool, gx);
82  gxi = gx - gbp_ext_itf_pool;
83 
84  gb = gbp_bridge_domain_get (gbi);
85  gr = gbp_route_domain_get (gri);
86 
87  gx->gx_bd = gbi;
88  gx->gx_rd = gri;
89 
91  {
92  gx->gx_fib_index[fproto] =
93  gr->grd_fib_index[fib_proto_to_dpo (fproto)];
94  }
95 
96  gx->gx_itf = gbp_itf_add_and_lock (sw_if_index, gb->gb_bd_index);
98  L2INPUT_FEAT_GBP_LPM_CLASSIFY);
99 
101 
102  GBP_EXT_ITF_DBG ("add: %U", format_gbp_ext_itf, gx);
103 
104  return (0);
105  }
106 
107  return (VNET_API_ERROR_ENTRY_ALREADY_EXISTS);
108 }
109 
110 int
112 {
113  gbp_ext_itf_t *gx;
114  index_t gxi;
115 
116  if (vec_len (gbp_ext_itf_db) <= sw_if_index)
117  return (VNET_API_ERROR_INVALID_SW_IF_INDEX);
118 
120 
121  if (INDEX_INVALID != gxi)
122  {
123  gx = pool_elt_at_index (gbp_ext_itf_pool, gxi);
124 
125  GBP_EXT_ITF_DBG ("del: %U", format_gbp_ext_itf, gx);
126 
128  (gxi | GBP_EXT_ITF_ID),
130  gbp_itf_unlock (gx->gx_itf);
131 
134 
136  pool_put (gbp_ext_itf_pool, gx);
137 
138  return (0);
139  }
140  return (VNET_API_ERROR_NO_SUCH_ENTRY);
141 }
142 
143 void
145 {
146  gbp_ext_itf_t *ge;
147 
148  /* *INDENT-OFF* */
149  pool_foreach(ge, gbp_ext_itf_pool,
150  {
151  if (!cb(ge, ctx))
152  break;
153  });
154  /* *INDENT-ON* */
155 }
156 
157 static walk_rc_t
159 {
160  vlib_cli_output (ctx, " %U", format_gbp_ext_itf, gx);
161 
162  return (WALK_CONTINUE);
163 }
164 
165 static clib_error_t *
167  unformat_input_t * input, vlib_cli_command_t * cmd)
168 {
169  vlib_cli_output (vm, "External-Interfaces:");
171 
172  return (NULL);
173 }
174 
175 /*?
176  * Show Group Based Policy external interface and derived information
177  *
178  * @cliexpar
179  * @cliexstart{show gbp ext-itf}
180  * @cliexend
181  ?*/
182 /* *INDENT-OFF* */
183 VLIB_CLI_COMMAND (gbp_ext_itf_show_node, static) = {
184  .path = "show gbp ext-itf",
185  .short_help = "show gbp ext-itf\n",
186  .function = gbp_ext_itf_show,
187 };
188 /* *INDENT-ON* */
189 
190 static clib_error_t *
192 {
193  gx_logger = vlib_log_register_class ("gbp", "ext-itf");
194 
195  return (NULL);
196 }
197 
199 
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "gnu")
205  * End:
206  */
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
void gbp_itf_set_l2_input_feature(index_t gii, index_t useri, l2input_feat_masks_t feats)
Definition: gbp_itf.c:102
void gbp_route_domain_unlock(index_t index)
u32 vlib_log_class_t
Definition: log.h:21
u32 gx_itf
The interface.
Definition: gbp_ext_itf.h:32
#define GBP_EXT_ITF_ID
Definition: gbp_ext_itf.c:31
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:239
index_t * gbp_ext_itf_db
external interface configs keyed by sw_if_index
Definition: gbp_ext_itf.c:29
#define NULL
Definition: clib.h:58
gbp_ext_itf_t * gbp_ext_itf_pool
Pool of GBP ext_itfs.
Definition: gbp_ext_itf.c:24
A bridge Domain Representation.
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:41
static walk_rc_t gbp_ext_itf_show_one(gbp_ext_itf_t *gx, void *ctx)
Definition: gbp_ext_itf.c:158
u32 rd_id
Definition: gbp.api:261
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:166
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static gbp_bridge_domain_t * gbp_bridge_domain_get(index_t i)
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
void gbp_itf_unlock(index_t gii)
Definition: gbp_itf.c:81
enum walk_rc_t_ walk_rc_t
Walk return code.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u32 sw_if_index
Definition: vxlan_gbp.api:37
walk_rc_t(* gbp_ext_itf_cb_t)(gbp_ext_itf_t *gbpe, void *ctx)
Definition: gbp_ext_itf.h:57
u32 gx_fib_index[DPO_PROTO_NUM]
cached FIB indices from the RD
Definition: gbp_ext_itf.h:47
u8 * format_gbp_itf(u8 *s, va_list *args)
Definition: gbp_itf.c:190
unsigned int u32
Definition: types.h:88
index_t gx_bd
The BD this external interface is a member of.
Definition: gbp_ext_itf.h:37
int gbp_ext_itf_delete(u32 sw_if_index)
Definition: gbp_ext_itf.c:111
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
long ctx[MAX_CONNS]
Definition: main.c:144
u32 bd_id
Definition: gbp.api:260
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
int gbp_ext_itf_add(u32 sw_if_index, u32 bd_id, u32 rd_id)
Definition: gbp_ext_itf.c:52
An external interface maps directly to an oflex L3ExternalInterface.
Definition: gbp_ext_itf.h:27
static clib_error_t * gbp_ext_itf_init(vlib_main_t *vm)
Definition: gbp_ext_itf.c:191
vlib_log_class_t gx_logger
logger
Definition: gbp_ext_itf.c:36
vlib_main_t * vm
Definition: buffer.c:301
u8 * format_gbp_bridge_domain(u8 *s, va_list *args)
u32 grd_fib_index[FIB_PROTOCOL_IP_MAX]
index_t gx_rd
The RD this external interface is a member of.
Definition: gbp_ext_itf.h:42
index_t gbp_bridge_domain_find_and_lock(u32 bd_id)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
gbp_route_domain_t * gbp_route_domain_get(index_t i)
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:237
#define GBP_EXT_ITF_DBG(...)
Definition: gbp_ext_itf.c:38
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
A route Domain Representation.
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
void gbp_ext_itf_walk(gbp_ext_itf_cb_t cb, void *ctx)
Definition: gbp_ext_itf.c:144
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:70
u8 * format_gbp_ext_itf(u8 *s, va_list *args)
Definition: gbp_ext_itf.c:42
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:488
void gbp_bridge_domain_unlock(index_t index)
index_t gbp_itf_add_and_lock(u32 sw_if_index, u32 bd_index)
Definition: gbp_itf.c:57
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
index_t gbp_route_domain_find_and_lock(u32 rd_id)