FD.io VPP  v20.05.1-6-gf53edbc3b
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 
24 
25 /**
26  * A zero'd out struct we can use in the vec_validate
27  */
28 static const l2_emulation_t ezero = { };
29 
30 void
32 {
34  vec_validate_init_empty (em->l2_emulations, sw_if_index, ezero);
35 
37 
38  l23e->enabled = 1;
39 
40  /*
41  * L3 enable the interface - using IP unnumbered from the control
42  * plane may not be possible since there may be no BVI interface
43  * to which to unnumber
44  */
45  ip4_sw_interface_enable_disable (sw_if_index, 1);
46  ip6_sw_interface_enable_disable (sw_if_index, 1);
47 
48  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_L2_EMULATION, 1);
49 }
50 
51 
52 void
54 {
56  if (vec_len (em->l2_emulations) >= sw_if_index)
57  {
59  clib_memset (l23e, 0, sizeof (*l23e));
60 
61  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_L2_EMULATION, 0);
62  ip4_sw_interface_enable_disable (sw_if_index, 0);
63  ip6_sw_interface_enable_disable (sw_if_index, 0);
64  }
65 }
66 
67 static clib_error_t *
69  u32 sw_if_index, u32 is_add)
70 {
72  if (is_add)
73  {
74  vec_validate_init_empty (em->l2_emulations, sw_if_index, ezero);
75  }
76 
77  return (NULL);
78 }
79 
81 
82 static clib_error_t *
84  unformat_input_t * input, vlib_cli_command_t * cmd)
85 {
86  vnet_main_t *vnm = vnet_get_main ();
87  u32 sw_if_index = ~0;
88  u8 enable = 1;
89 
91  {
92  if (unformat (input, "%U", unformat_vnet_sw_interface,
93  vnm, &sw_if_index))
94  ;
95  else if (unformat (input, "enable"))
96  enable = 1;
97  else if (unformat (input, "disable"))
98  enable = 0;
99  else
100  break;
101  }
102 
103  if (~0 == sw_if_index)
104  return clib_error_return (0, "interface must be specified");
105 
106  if (enable)
107  l2_emulation_enable (sw_if_index);
108  else
109  l2_emulation_disable (sw_if_index);
110 
111  return (NULL);
112 }
113 
114 /*?
115  * Configure l2 emulation.
116  * When the interface is in L2 mode, configure the extraction of L3
117  * packets out of the L2 path and into the L3 path.
118  *
119  * @cliexpar
120  * @cliexstart{set interface l2 input l2-emulation <interface-name> [disable]}
121  * @cliexend
122  ?*/
123 /* *INDENT-OFF* */
124 VLIB_CLI_COMMAND (l2_emulation_cli_node, static) = {
125  .path = "set interface l2 l2-emulation",
126  .short_help =
127  "set interface l2 l2-emulation <interface-name> [disable|enable]\n",
128  .function = l2_emulation_cli,
129 };
130 /* *INDENT-ON* */
131 
132 static clib_error_t *
134  unformat_input_t * input, vlib_cli_command_t * cmd)
135 {
137  vnet_main_t *vnm = vnet_get_main ();
138  l2_emulation_t *l23e;
140 
141  vec_foreach_index (sw_if_index, em->l2_emulations)
142  {
143  l23e = &em->l2_emulations[sw_if_index];
144  if (l23e->enabled)
145  {
146  vlib_cli_output (vm, "%U\n",
147  format_vnet_sw_if_index_name, vnm, sw_if_index);
148  }
149  }
150  return (NULL);
151 }
152 
153 /*?
154  * Show l2 emulation.
155  * When the interface is in L2 mode, configure the extraction of L3
156  * packets out of the L2 path and into the L3 path.
157  *
158  * @cliexpar
159  * @cliexstart{show interface l2 l2-emulation}
160  * @cliexend
161  ?*/
162 /* *INDENT-OFF* */
163 VLIB_CLI_COMMAND (l2_emulation_show_node, static) = {
164  .path = "show interface l2 l2-emulation",
165  .short_help = "show interface l2 l2-emulation\n",
166  .function = l2_emulation_show,
167 };
168 /* *INDENT-ON* */
169 
170 static clib_error_t *
172 {
174  vlib_node_t *node;
175 
176  node = vlib_get_node_by_name (vm, (u8 *) "l2-emulation");
177  em->l2_emulation_node_index = node->index;
178 
179  /* Initialize the feature next-node indexes */
184  em->l2_input_feat_next);
185 
186  return 0;
187 }
188 
190 
191 /*
192  * fd.io coding-style-patch-verification: ON
193  *
194  * Local Variables:
195  * eval: (c-set-style "gnu")
196  * End:
197  */
#define vec_foreach_index(var, v)
Iterate over vector indices.
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static clib_error_t * l2_emulation_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: l2e.c:68
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:282
Grouping of global data for the L2 emulation feature.
Definition: l2e.h:46
u32 l2_input_feat_next[32]
Next nodes for L2 output features.
Definition: l2e.h:60
void l2_emulation_disable(u32 sw_if_index)
Definition: l2e.c:53
unformat_function_t unformat_vnet_sw_interface
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(l2_emulation_interface_add_del)
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip4_forward.c:640
l2_emulation_main_t l2_emulation_main
Definition: l2e.c:23
struct _unformat_input_t unformat_input_t
vlib_main_t * vm
Definition: in2out_ed.c:1599
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 l2_emulation_node_index
Definition: l2e.h:50
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
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:62
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
static clib_error_t * l2_emulation_cli(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2e.c:83
u8 enabled
Enabled or Disabled.
Definition: l2e.h:31
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
void l2_emulation_enable(u32 sw_if_index)
L2 Emulation is a feautre that is applied to L2 ports to &#39;extract&#39; IP packets from the L2 path and in...
Definition: l2e.c:31
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:538
Per-interface L2 configuration.
Definition: l2e.h:25
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static clib_error_t * l2_emulation_init(vlib_main_t *vm)
Definition: l2e.c:171
l2_emulation_t * l2_emulations
Per-interface vector of emulation configs.
Definition: l2e.h:55
#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:554
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:239
static clib_error_t * l2_emulation_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2e.c:133
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171