FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
interface.c
Go to the documentation of this file.
1 /*
2  * interface.c: mpls interfaces
3  *
4  * Copyright (c) 2012 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/mpls/mpls.h>
20 #include <vnet/fib/mpls_fib.h>
21 #include <vnet/fib/ip4_fib.h>
22 #include <vnet/adj/adj_midchain.h>
23 #include <vnet/dpo/classify_dpo.h>
24 
25 
26 u8
28 {
29  mpls_main_t * mm = &mpls_main;
30 
32  return (0);
33 
35 }
36 
37 int
40  u8 is_enable,
41  u8 is_api)
42 {
43  fib_node_index_t lfib_index;
44  vnet_main_t *vnm = vnet_get_main ();
46 
48 
49  lfib_index = fib_table_find(FIB_PROTOCOL_MPLS,
51 
52  if (~0 == lfib_index)
53  return VNET_API_ERROR_NO_SUCH_FIB;
54 
55  /*
56  * enable/disable only on the 1<->0 transition
57  */
58  if (is_enable)
59  {
61  return (0);
62 
64  (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
65 
67  mm->fib_index_by_sw_if_index[sw_if_index] = lfib_index;
68  }
69  else
70  {
73  return (0);
74 
77  (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
78  }
79 
80  vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled",
81  sw_if_index, !is_enable, 0, 0);
82 
83  if (is_enable)
84  hi->l3_if_count++;
85  else if (hi->l3_if_count)
86  hi->l3_if_count--;
87 
88  return (0);
89 }
90 
91 static clib_error_t *
93  unformat_input_t * input,
94  vlib_cli_command_t * cmd)
95 {
96  vnet_main_t * vnm = vnet_get_main();
97  clib_error_t * error = 0;
98  u32 sw_if_index, enable;
99  int rv;
100 
101  sw_if_index = ~0;
102 
104  {
105  error = clib_error_return (0, "unknown interface `%U'",
106  format_unformat_error, input);
107  goto done;
108  }
109 
110  if (unformat (input, "enable"))
111  enable = 1;
112  else if (unformat (input, "disable"))
113  enable = 0;
114  else
115  {
116  error = clib_error_return (0, "expected 'enable' or 'disable'",
117  format_unformat_error, input);
118  goto done;
119  }
120 
122 
123  if (VNET_API_ERROR_NO_SUCH_FIB == rv)
124  error = clib_error_return (0, "default MPLS table must be created first");
125 
126  done:
127  return error;
128 }
129 
130 /*?
131  * This command enables an interface to accpet MPLS packets
132  *
133  * @cliexpar
134  * @cliexstart{set interface mpls}
135  * set interface mpls GigEthernet0/8/0 enable
136  * @cliexend
137  ?*/
139  .path = "set interface mpls",
140  .function = mpls_interface_enable_disable,
141  .short_help = "Enable/Disable an interface for MPLS forwarding",
142 };
143 
144 static void
146  bool verbose)
147 {
148  mpls_main_t *mm = &mpls_main;
149  u8 enabled;
150 
152 
153  if (enabled)
154  {
156  sw_if_index);
157  vlib_cli_output (vm, " MPLS enabled");
158  }
159  else if (verbose)
160  {
162  sw_if_index);
163  vlib_cli_output (vm, " MPLS disabled");
164  }
165 }
166 
167 static walk_rc_t
169 {
170  show_mpls_one_interface (vnm, ctx, si->sw_if_index, false);
171 
172  return (WALK_CONTINUE);
173 }
174 
175 static clib_error_t *
177  vlib_cli_command_t *cmd)
178 {
179  vnet_main_t *vnm = vnet_get_main ();
181 
182  sw_if_index = ~0;
183 
185  ;
186 
187  if (~0 == sw_if_index)
188  {
190  }
191  else
192  {
193  show_mpls_one_interface (vnm, vm, sw_if_index, true);
194  }
195 
196  return NULL;
197 }
198 
199 /*?
200  * This command displays the MPLS forwarding state of an interface
201  *
202  * @cliexpar
203  * @cliexstart{show mpls interface}
204  * set mpls interface GigEthernet0/8/0
205  * @cliexend
206  ?*/
208  .path = "show mpls interface",
209  .function = show_mpls_interface,
210  .short_help = "Show MPLS interface forwarding",
211 };
mpls_sw_interface_is_enabled
u8 mpls_sw_interface_is_enabled(u32 sw_if_index)
Definition: interface.c:27
show_mpls_interface_command
static vlib_cli_command_t show_mpls_interface_command
(constructor) VLIB_CLI_COMMAND (show_mpls_interface_command)
Definition: interface.c:207
adj_midchain.h
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vnet_sw_interface_t
Definition: interface.h:869
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
mpls_main
mpls_main_t mpls_main
Definition: mpls.c:25
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
show_mpls_interface
static clib_error_t * show_mpls_interface(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface.c:176
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
mpls.h
unformat_input_t
struct _unformat_input_t unformat_input_t
mpls_main_t::mpls_enabled_by_sw_if_index
u8 * mpls_enabled_by_sw_if_index
Definition: mpls.h:60
error
Definition: cJSON.c:88
set_interface_ip_table_command
static vlib_cli_command_t set_interface_ip_table_command
(constructor) VLIB_CLI_COMMAND (set_interface_ip_table_command)
Definition: interface.c:138
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
mpls_fib.h
vnet_sw_interface_t::sw_if_index
u32 sw_if_index
Definition: interface.h:876
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
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
show_mpls_one_interface
static void show_mpls_one_interface(vnet_main_t *vnm, vlib_main_t *vm, u32 sw_if_index, bool verbose)
Definition: interface.c:145
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
mpls_interface_enable_disable
static clib_error_t * mpls_interface_enable_disable(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface.c:92
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:458
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
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
FIB_PROTOCOL_MPLS
@ FIB_PROTOCOL_MPLS
Definition: fib_types.h:38
fib_table_lock
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
Definition: fib_table.c:1361
MPLS_FIB_DEFAULT_TABLE_ID
#define MPLS_FIB_DEFAULT_TABLE_ID
Definition: mpls_fib.h:28
u32
unsigned int u32
Definition: types.h:88
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
mpls_sw_interface_enable_disable
int mpls_sw_interface_enable_disable(mpls_main_t *mm, u32 sw_if_index, u8 is_enable, u8 is_api)
Definition: interface.c:38
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
si
vnet_sw_interface_t * si
Definition: interface_output.c:418
FIB_SOURCE_CLI
@ FIB_SOURCE_CLI
From the CLI.
Definition: fib_source.h:79
FIB_SOURCE_API
@ FIB_SOURCE_API
From the control plane API.
Definition: fib_source.h:75
vnet_feature_enable_disable
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: pnat_test_stubs.h:50
ip4_fib.h
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vnet_sw_interface_walk
void vnet_sw_interface_walk(vnet_main_t *vnm, vnet_sw_interface_walk_t fn, void *ctx)
Walk all the SW interfaces in the system.
Definition: interface.c:1163
fib_table_unlock
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1342
show_mpls_interface_walk
static walk_rc_t show_mpls_interface_walk(vnet_main_t *vnm, vnet_sw_interface_t *si, void *ctx)
Definition: interface.c:168
mpls_main_t
Definition: mpls.h:41
mpls_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: mpls.h:44
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
vlib_cli_command_t
Definition: cli.h:92
fib_table_find
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1111
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.
classify_dpo.h