2 * interface.c: mpls interfaces
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/vnet.h>
19 #include <vnet/pg/pg.h>
20 #include <vnet/mpls/mpls.h>
21 #include <vnet/fib/mpls_fib.h>
22 #include <vnet/fib/ip4_fib.h>
23 #include <vnet/adj/adj_midchain.h>
24 #include <vnet/dpo/classify_dpo.h>
28 mpls_sw_interface_is_enabled (u32 sw_if_index)
30 mpls_main_t * mm = &mpls_main;
32 if (vec_len(mm->mpls_enabled_by_sw_if_index) <= sw_if_index)
35 return (mm->mpls_enabled_by_sw_if_index[sw_if_index]);
39 mpls_sw_interface_enable_disable (mpls_main_t * mm,
44 fib_node_index_t lfib_index;
45 vnet_main_t *vnm = vnet_get_main ();
46 vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
48 vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
50 lfib_index = fib_table_find(FIB_PROTOCOL_MPLS,
51 MPLS_FIB_DEFAULT_TABLE_ID);
54 return VNET_API_ERROR_NO_SUCH_FIB;
57 * enable/disable only on the 1<->0 transition
61 if (1 != ++mm->mpls_enabled_by_sw_if_index[sw_if_index])
64 fib_table_lock(lfib_index, FIB_PROTOCOL_MPLS,
65 (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
67 vec_validate(mm->fib_index_by_sw_if_index, sw_if_index);
68 mm->fib_index_by_sw_if_index[sw_if_index] = lfib_index;
72 ASSERT(mm->mpls_enabled_by_sw_if_index[sw_if_index] > 0);
73 if (0 != --mm->mpls_enabled_by_sw_if_index[sw_if_index])
76 fib_table_unlock(mm->fib_index_by_sw_if_index[sw_if_index],
78 (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
81 vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled",
82 sw_if_index, !is_enable, 0, 0);
86 else if (hi->l3_if_count)
93 mpls_interface_enable_disable (vlib_main_t * vm,
94 unformat_input_t * input,
95 vlib_cli_command_t * cmd)
97 vnet_main_t * vnm = vnet_get_main();
98 clib_error_t * error = 0;
99 u32 sw_if_index, enable;
104 if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
106 error = clib_error_return (0, "unknown interface `%U'",
107 format_unformat_error, input);
111 if (unformat (input, "enable"))
113 else if (unformat (input, "disable"))
117 error = clib_error_return (0, "expected 'enable' or 'disable'",
118 format_unformat_error, input);
122 rv = mpls_sw_interface_enable_disable(&mpls_main, sw_if_index, enable, 0);
124 if (VNET_API_ERROR_NO_SUCH_FIB == rv)
125 error = clib_error_return (0, "default MPLS table must be created first");
132 * This command enables an interface to accpet MPLS packets
135 * @cliexstart{set interface mpls}
136 * set interface mpls GigEthernet0/8/0 enable
139 VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
140 .path = "set interface mpls",
141 .function = mpls_interface_enable_disable,
142 .short_help = "Enable/Disable an interface for MPLS forwarding",