FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l2e.c
Go to the documentation of this file.
1 /*
2  * l2e.c : Extract L3 packets from the L2 input and feed
3  * them into the L3 path.
4  *
5  * Copyright (c) 2013 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 #include <plugins/l2e/l2e.h>
20 #include <vnet/l2/l2_input.h>
21 #include <vnet/l2/feat_bitmap.h>
22 #include <vnet/ip/ip.h>
23 
25 
26 /**
27  * A zero'd out struct we can use in the vec_validate
28  */
29 static const l2_emulation_t ezero = { };
30 
31 __clib_export void
33 {
36 
38 
39  l23e->enabled = 1;
40 
41  /*
42  * L3 enable the interface - using IP unnumbered from the control
43  * plane may not be possible since there may be no BVI interface
44  * to which to unnumber
45  */
48 
49  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_L2_EMULATION, 1);
50 }
51 
52 
53 __clib_export void
55 {
57  if (vec_len (em->l2_emulations) >= sw_if_index)
58  {
60  clib_memset (l23e, 0, sizeof (*l23e));
61 
62  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_L2_EMULATION, 0);
65  }
66 }
67 
68 static clib_error_t *
70  u32 sw_if_index, u32 is_add)
71 {
73  if (is_add)
74  {
76  }
77 
78  return (NULL);
79 }
80 
82 
83 static clib_error_t *
85  unformat_input_t * input, vlib_cli_command_t * cmd)
86 {
87  vnet_main_t *vnm = vnet_get_main ();
88  u32 sw_if_index = ~0;
89  u8 enable = 1;
90 
92  {
93  if (unformat (input, "%U", unformat_vnet_sw_interface,
94  vnm, &sw_if_index))
95  ;
96  else if (unformat (input, "enable"))
97  enable = 1;
98  else if (unformat (input, "disable"))
99  enable = 0;
100  else
101  break;
102  }
103 
104  if (~0 == sw_if_index)
105  return clib_error_return (0, "interface must be specified");
106 
107  if (enable)
109  else
111 
112  return (NULL);
113 }
114 
115 /*?
116  * Configure l2 emulation.
117  * When the interface is in L2 mode, configure the extraction of L3
118  * packets out of the L2 path and into the L3 path.
119  *
120  * @cliexpar
121  * @cliexstart{set interface l2 input l2-emulation <interface-name> [disable]}
122  * @cliexend
123  ?*/
124 /* *INDENT-OFF* */
126  .path = "set interface l2 l2-emulation",
127  .short_help =
128  "set interface l2 l2-emulation <interface-name> [disable|enable]\n",
129  .function = l2_emulation_cli,
130 };
131 /* *INDENT-ON* */
132 
133 static clib_error_t *
135  unformat_input_t * input, vlib_cli_command_t * cmd)
136 {
138  vnet_main_t *vnm = vnet_get_main ();
139  l2_emulation_t *l23e;
141 
143  {
144  l23e = &em->l2_emulations[sw_if_index];
145  if (l23e->enabled)
146  {
147  vlib_cli_output (vm, "%U\n",
149  }
150  }
151  return (NULL);
152 }
153 
154 /*?
155  * Show l2 emulation.
156  * When the interface is in L2 mode, configure the extraction of L3
157  * packets out of the L2 path and into the L3 path.
158  *
159  * @cliexpar
160  * @cliexstart{show interface l2 l2-emulation}
161  * @cliexend
162  ?*/
163 /* *INDENT-OFF* */
165  .path = "show interface l2 l2-emulation",
166  .short_help = "show interface l2 l2-emulation\n",
167  .function = l2_emulation_show,
168 };
169 /* *INDENT-ON* */
170 
171 static clib_error_t *
173 {
175  vlib_node_t *node;
176 
177  node = vlib_get_node_by_name (vm, (u8 *) "l2-emulation");
178  em->l2_emulation_node_index = node->index;
179 
180  /* Initialize the feature next-node indexes */
185  em->l2_input_feat_next);
186 
187  return 0;
188 }
189 
191 
192 /*
193  * fd.io coding-style-patch-verification: ON
194  *
195  * Local Variables:
196  * eval: (c-set-style "gnu")
197  * End:
198  */
ip4_sw_interface_enable_disable
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip4_forward.c:601
l2_emulation_main_t_::l2_emulations
l2_emulation_t * l2_emulations
Per-interface vector of emulation configs.
Definition: l2e.h:55
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
l2_emulation_disable
__clib_export void l2_emulation_disable(u32 sw_if_index)
Definition: l2e.c:54
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
l2_emulation_interface_add_del
static clib_error_t * l2_emulation_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: l2e.c:69
l2_emulation_cli_node
static vlib_cli_command_t l2_emulation_cli_node
(constructor) VLIB_CLI_COMMAND (l2_emulation_cli_node)
Definition: l2e.c:125
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
l2e.h
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
l2input_intf_bitmap_enable
u32 l2input_intf_bitmap_enable(u32 sw_if_index, l2input_feat_masks_t feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_input.c:177
l2input_get_feat_names
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:59
l2_emulation_t_::enabled
u8 enabled
Enabled or Disabled.
Definition: l2e.h:31
l2_emulation_cli
static clib_error_t * l2_emulation_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2e.c:84
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
L2INPUT_N_FEAT
@ L2INPUT_N_FEAT
Definition: l2_input.h:163
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
l2_input.h
vnet_main_t
Definition: vnet.h:76
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
l2_emulation_init
static clib_error_t * l2_emulation_init(vlib_main_t *vm)
Definition: l2e.c:172
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:455
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
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
ip.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ezero
static const l2_emulation_t ezero
A zero'd out struct we can use in the vec_validate.
Definition: l2e.c:29
ip6_sw_interface_enable_disable
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:239
l2_emulation_main
l2_emulation_main_t l2_emulation_main
Definition: l2e.c:24
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
l2_emulation_show_node
static vlib_cli_command_t l2_emulation_show_node
(constructor) VLIB_CLI_COMMAND (l2_emulation_show_node)
Definition: l2e.c:164
vlib_node_t
Definition: node.h:247
VNET_SW_INTERFACE_ADD_DEL_FUNCTION
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(l2_emulation_interface_add_del)
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
feat_bitmap.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
l2_emulation_main_t_
Grouping of global data for the L2 emulation feature.
Definition: l2e.h:46
l2_emulation_t_
Per-interface L2 configuration.
Definition: l2e.h:25
l2_emulation_main_t_::l2_input_feat_next
u32 l2_input_feat_next[32]
Next nodes for L2 output features.
Definition: l2e.h:60
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
l2_emulation_main_t_::l2_emulation_node_index
u32 l2_emulation_node_index
Definition: l2e.h:50
l2_emulation_show
static clib_error_t * l2_emulation_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2e.c:134
feat_bitmap_init_next_nodes
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
Definition: feat_bitmap.h:43
l2_emulation_enable
__clib_export void l2_emulation_enable(u32 sw_if_index)
L2 Emulation is a feautre that is applied to L2 ports to 'extract' IP packets from the L2 path and in...
Definition: l2e.c:32
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137