FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
gbp_recirc.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 
16 #include <plugins/gbp/gbp_recirc.h>
19 
20 #include <vnet/dpo/dvr_dpo.h>
21 #include <vnet/fib/fib_table.h>
22 
23 /**
24  * Pool of GBP recircs
25  */
27 
28 /**
29  * Recirc configs keyed by sw_if_index
30  */
32 
33 int
34 gbp_recirc_add (u32 sw_if_index, epg_id_t epg_id, u8 is_ext)
35 {
36  gbp_recirc_t *gr;
37  index_t gri;
38 
40 
41  gri = gbp_recirc_db[sw_if_index];
42 
43  if (INDEX_INVALID == gri)
44  {
46  fib_protocol_t fproto;
47 
48  pool_get (gbp_recirc_pool, gr);
49  memset (gr, 0, sizeof (*gr));
50  gri = gr - gbp_recirc_pool;
51 
52  gr->gr_epg = epg_id;
53  gr->gr_is_ext = is_ext;
54  gr->gr_sw_if_index = sw_if_index;
55 
56  /*
57  * IP enable the recirc interface
58  */
61 
62  /*
63  * cache the FIB indicies of the EPG
64  */
65  gepg = gbp_endpoint_group_find (gr->gr_epg);
66 
67  if (NULL == gepg)
68  return (VNET_API_ERROR_NO_SUCH_ENTRY);
69 
71  {
72  gr->gr_fib_index[fproto] = gepg->gepg_fib_index[fproto];
73  }
74 
75  /*
76  * Packets on the recirculation interface are subjet to src-EPG
77  * classification. Recirc interfaces are L2-emulation mode.
78  * for internal EPGs this is via an LPM on all external subnets.
79  * for external EPGs this is via a port mapping.
80  */
81  if (gr->gr_is_ext)
82  {
83  /*
84  * recirc is for post-NAT translation packets going into
85  * the external EPG, these are classified to the NAT EPG
86  * based on its port
87  */
89  vnet_feature_enable_disable ("ip4-unicast",
90  "ip4-gbp-src-classify",
91  gr->gr_sw_if_index, 1, 0, 0);
92  vnet_feature_enable_disable ("ip6-unicast",
93  "ip6-gbp-src-classify",
94  gr->gr_sw_if_index, 1, 0, 0);
95  }
96  else
97  {
98  /*
99  * recirc is for pre-NAT translation packets coming from
100  * the external EPG, these are classified based on a LPM
101  * in the EPG's route-domain
102  */
103  vnet_feature_enable_disable ("ip4-unicast",
104  "ip4-gbp-lpm-classify",
105  gr->gr_sw_if_index, 1, 0, 0);
106  vnet_feature_enable_disable ("ip6-unicast",
107  "ip6-gbp-lpm-classify",
108  gr->gr_sw_if_index, 1, 0, 0);
109  }
110 
111  gbp_recirc_db[sw_if_index] = gri;
112  }
113 
114  return (0);
115 }
116 
117 void
118 gbp_recirc_delete (u32 sw_if_index)
119 {
120  gbp_recirc_t *gr;
121  index_t gri;
122 
123  gri = gbp_recirc_db[sw_if_index];
124 
125  if (INDEX_INVALID != gri)
126  {
127  gr = pool_elt_at_index (gbp_recirc_pool, gri);
128 
129  if (gr->gr_is_ext)
130  {
132  vnet_feature_enable_disable ("ip4-unicast",
133  "ip4-gbp-src-classify",
134  gr->gr_sw_if_index, 0, 0, 0);
135  vnet_feature_enable_disable ("ip6-unicast",
136  "ip6-gbp-src-classify",
137  gr->gr_sw_if_index, 0, 0, 0);
138  }
139  else
140  {
141  vnet_feature_enable_disable ("ip4-unicast",
142  "ip4-gbp-lpm-classify",
143  gr->gr_sw_if_index, 0, 0, 0);
144  vnet_feature_enable_disable ("ip6-unicast",
145  "ip6-gbp-lpm-classify",
146  gr->gr_sw_if_index, 0, 0, 0);
147  }
148 
151 
152  gbp_recirc_db[sw_if_index] = INDEX_INVALID;
153  pool_put (gbp_recirc_pool, gr);
154  }
155 }
156 
157 void
159 {
160  gbp_recirc_t *gbpe;
161 
162  /* *INDENT-OFF* */
163  pool_foreach(gbpe, gbp_recirc_pool,
164  {
165  if (!cb(gbpe, ctx))
166  break;
167  });
168  /* *INDENT-ON* */
169 }
170 
171 static int
173 {
174  vnet_main_t *vnm = vnet_get_main ();
175  vlib_main_t *vm;
176 
177  vm = ctx;
178  vlib_cli_output (vm, " %U, epg:%d, ext:%d",
180  gr->gr_sw_if_index, gr->gr_epg, gr->gr_is_ext);
181 
182  return (1);
183 }
184 
185 static clib_error_t *
187  unformat_input_t * input, vlib_cli_command_t * cmd)
188 {
189  vlib_cli_output (vm, "Recirculation-Interfaces:");
191 
192  return (NULL);
193 }
194 
195 
196 /*?
197  * Show Group Based Policy Recircs and derived information
198  *
199  * @cliexpar
200  * @cliexstart{show gbp recirc}
201  * @cliexend
202  ?*/
203 /* *INDENT-OFF* */
204 VLIB_CLI_COMMAND (gbp_recirc_show_node, static) = {
205  .path = "show gbp recirc",
206  .short_help = "show gbp recirc\n",
207  .function = gbp_recirc_show,
208 };
209 /* *INDENT-ON* */
210 
211 /*
212  * fd.io coding-style-patch-verification: ON
213  *
214  * Local Variables:
215  * eval: (c-set-style "gnu")
216  * End:
217  */
void gbp_itf_epg_delete(u32 sw_if_index)
Definition: gbp_endpoint.c:117
int(* gbp_recirc_cb_t)(gbp_recirc_t *gbpe, void *ctx)
Definition: gbp_recirc.h:52
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
#define NULL
Definition: clib.h:55
u32 gr_fib_index[FIB_PROTOCOL_IP_MAX]
FIB indices the EPG is mapped to.
Definition: gbp_recirc.h:35
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
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:227
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u8 gr_is_ext
Is the interface for packets post-NAT translatoin (i.e.
Definition: gbp_recirc.h:41
u32 gepg_fib_index[FIB_PROTOCOL_IP_MAX]
resulting FIB indices
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
gbp_endpoint_group_t * gbp_endpoint_group_find(epg_id_t epg_id)
u32 epg_id_t
Definition: gbp_types.h:21
An Endpoint Group representation.
Definition: gbp_recirc.h:25
unsigned int u32
Definition: types.h:88
epg_id_t gr_epg
EPG ID that packets will classify to when they arrive on this recirc.
Definition: gbp_recirc.h:30
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip4_forward.c:496
gbp_recirc_t * gbp_recirc_pool
Pool of GBP recircs.
Definition: gbp_recirc.c:26
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
An Endpoint Group representation.
void gbp_itf_epg_update(u32 sw_if_index, epg_id_t src_epg, u8 do_policy)
Port to EPG mapping management.
Definition: gbp_endpoint.c:98
static clib_error_t * gbp_recirc_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gbp_recirc.c:186
vlib_main_t * vm
Definition: buffer.c:294
u32 gr_sw_if_index
Definition: gbp_recirc.h:45
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
long ctx[MAX_CONNS]
Definition: main.c:126
void gbp_recirc_walk(gbp_recirc_cb_t cb, void *ctx)
Definition: gbp_recirc.c:158
index_t * gbp_recirc_db
Recirc configs keyed by sw_if_index.
Definition: gbp_recirc.c:31
void gbp_recirc_delete(u32 sw_if_index)
Definition: gbp_recirc.c:118
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:70
int gbp_recirc_add(u32 sw_if_index, epg_id_t epg_id, u8 is_ext)
Definition: gbp_recirc.c:34
static int gbp_recirc_show_one(gbp_recirc_t *gr, void *ctx)
Definition: gbp_recirc.c:172
#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:486
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:142
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:233