Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * l2_api.c - layer 2 forwarding api |
| 4 | * |
| 5 | * Copyright (c) 2016 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 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/l2/l2_input.h> |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 26 | #include <vnet/l2/l2_fib.h> |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 27 | #include <vnet/l2/l2_vtr.h> |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 28 | #include <vnet/l2/l2_learn.h> |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 29 | #include <vnet/l2/l2_bd.h> |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 30 | #include <vnet/ip/ip_types_api.h> |
| 31 | #include <vnet/ethernet/ethernet_types_api.h> |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 32 | |
| 33 | #include <vnet/vnet_msg_enum.h> |
| 34 | |
| 35 | #define vl_typedefs /* define message structures */ |
| 36 | #include <vnet/vnet_all_api_h.h> |
| 37 | #undef vl_typedefs |
| 38 | |
| 39 | #define vl_endianfun /* define message structures */ |
| 40 | #include <vnet/vnet_all_api_h.h> |
| 41 | #undef vl_endianfun |
| 42 | |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 43 | #define vl_api_bridge_domain_details_t_endian vl_noop_handler |
| 44 | #define vl_api_bridge_domain_details_t_print vl_noop_handler |
| 45 | |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 46 | /* instantiate all the print functions we know about */ |
| 47 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 48 | #define vl_printfun |
| 49 | #include <vnet/vnet_all_api_h.h> |
| 50 | #undef vl_printfun |
| 51 | |
| 52 | #include <vlibapi/api_helper_macros.h> |
| 53 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 54 | #define foreach_vpe_api_msg \ |
| 55 | _(L2_XCONNECT_DUMP, l2_xconnect_dump) \ |
| 56 | _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \ |
| 57 | _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \ |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 58 | _(L2FIB_FLUSH_ALL, l2fib_flush_all) \ |
Eyal Bari | f24991c | 2017-04-05 05:33:21 +0300 | [diff] [blame] | 59 | _(L2FIB_FLUSH_INT, l2fib_flush_int) \ |
| 60 | _(L2FIB_FLUSH_BD, l2fib_flush_bd) \ |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 61 | _(L2FIB_ADD_DEL, l2fib_add_del) \ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 62 | _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \ |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 63 | _(L2_FLAGS, l2_flags) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 64 | _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \ |
| 65 | _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \ |
| 66 | _(L2_PATCH_ADD_DEL, l2_patch_add_del) \ |
| 67 | _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \ |
| 68 | _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \ |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 69 | _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 70 | _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \ |
| 71 | _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \ |
| 72 | _(BRIDGE_FLAGS, bridge_flags) \ |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 73 | _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 74 | _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \ |
| 75 | _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \ |
| 76 | _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 77 | |
| 78 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 79 | send_l2_xconnect_details (vl_api_registration_t * reg, u32 context, |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 80 | u32 rx_sw_if_index, u32 tx_sw_if_index) |
| 81 | { |
| 82 | vl_api_l2_xconnect_details_t *mp; |
| 83 | |
| 84 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 85 | clib_memset (mp, 0, sizeof (*mp)); |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 86 | mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS); |
| 87 | mp->context = context; |
| 88 | mp->rx_sw_if_index = htonl (rx_sw_if_index); |
| 89 | mp->tx_sw_if_index = htonl (tx_sw_if_index); |
| 90 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 91 | vl_api_send_msg (reg, (u8 *) mp); |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void |
| 95 | vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp) |
| 96 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 97 | vl_api_registration_t *reg; |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 98 | vnet_main_t *vnm = vnet_get_main (); |
| 99 | vnet_interface_main_t *im = &vnm->interface_main; |
| 100 | l2input_main_t *l2im = &l2input_main; |
| 101 | vnet_sw_interface_t *swif; |
| 102 | l2_input_config_t *config; |
| 103 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 104 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 105 | if (!reg) |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 106 | return; |
| 107 | |
| 108 | /* *INDENT-OFF* */ |
| 109 | pool_foreach (swif, im->sw_interfaces, |
| 110 | ({ |
| 111 | config = vec_elt_at_index (l2im->configs, swif->sw_if_index); |
| 112 | if (config->xconnect) |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 113 | send_l2_xconnect_details (reg, mp->context, swif->sw_if_index, |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 114 | config->output_sw_if_index); |
| 115 | })); |
| 116 | /* *INDENT-ON* */ |
| 117 | } |
| 118 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 119 | static void |
| 120 | vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp) |
| 121 | { |
| 122 | int rv = 0; |
| 123 | vl_api_l2_fib_clear_table_reply_t *rmp; |
| 124 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 125 | /* Clear all MACs including static MACs */ |
| 126 | l2fib_clear_table (); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 127 | |
| 128 | REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY); |
| 129 | } |
| 130 | |
| 131 | static void |
| 132 | send_l2fib_table_entry (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 133 | vl_api_registration_t * reg, |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 134 | l2fib_entry_key_t * l2fe_key, |
| 135 | l2fib_entry_result_t * l2fe_res, u32 context) |
| 136 | { |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 137 | vl_api_l2_fib_table_details_t *mp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 138 | |
| 139 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 140 | clib_memset (mp, 0, sizeof (*mp)); |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 141 | mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 142 | |
| 143 | mp->bd_id = |
| 144 | ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id); |
| 145 | |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 146 | clib_memcpy (mp->mac, l2fe_key->fields.mac, 6); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 147 | mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index); |
Neale Ranns | 7341b6d | 2018-09-19 04:07:02 -0700 | [diff] [blame] | 148 | mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0); |
| 149 | mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0); |
| 150 | mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 151 | mp->context = context; |
| 152 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 153 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 157 | vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp) |
| 158 | { |
| 159 | vpe_api_main_t *am = &vpe_api_main; |
| 160 | bd_main_t *bdm = &bd_main; |
| 161 | l2fib_entry_key_t *l2fe_key = NULL; |
| 162 | l2fib_entry_result_t *l2fe_res = NULL; |
| 163 | u32 ni, bd_id = ntohl (mp->bd_id); |
| 164 | u32 bd_index; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 165 | vl_api_registration_t *reg; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 166 | uword *p; |
| 167 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 168 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 169 | if (!reg) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 170 | return; |
| 171 | |
| 172 | /* see l2fib_table_dump: ~0 means "any" */ |
| 173 | if (bd_id == ~0) |
| 174 | bd_index = ~0; |
| 175 | else |
| 176 | { |
| 177 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 178 | if (p == 0) |
| 179 | return; |
| 180 | |
| 181 | bd_index = p[0]; |
| 182 | } |
| 183 | |
| 184 | l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res); |
| 185 | |
| 186 | vec_foreach_index (ni, l2fe_key) |
| 187 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 188 | send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni), |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 189 | vec_elt_at_index (l2fe_res, ni), mp->context); |
| 190 | } |
| 191 | vec_free (l2fe_key); |
| 192 | vec_free (l2fe_res); |
| 193 | } |
| 194 | |
| 195 | static void |
| 196 | vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp) |
| 197 | { |
| 198 | bd_main_t *bdm = &bd_main; |
| 199 | l2input_main_t *l2im = &l2input_main; |
| 200 | vl_api_l2fib_add_del_reply_t *rmp; |
| 201 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 202 | u32 bd_id = ntohl (mp->bd_id); |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 203 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 204 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 205 | if (!p) |
| 206 | { |
| 207 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 208 | goto bad_sw_if_index; |
| 209 | } |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 210 | u32 bd_index = p[0]; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 211 | |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 212 | u8 mac[6]; |
| 213 | |
| 214 | clib_memcpy (mac, mp->mac, 6); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 215 | if (mp->is_add) |
| 216 | { |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 217 | if (mp->filter_mac) |
| 218 | l2fib_add_filter_entry (mac, bd_index); |
| 219 | else |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 220 | { |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 221 | l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE; |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 222 | u32 sw_if_index = ntohl (mp->sw_if_index); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 223 | VALIDATE_SW_IF_INDEX (mp); |
| 224 | if (vec_len (l2im->configs) <= sw_if_index) |
| 225 | { |
| 226 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 227 | goto bad_sw_if_index; |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | l2_input_config_t *config; |
| 232 | config = vec_elt_at_index (l2im->configs, sw_if_index); |
| 233 | if (config->bridge == 0) |
| 234 | { |
| 235 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 236 | goto bad_sw_if_index; |
| 237 | } |
| 238 | } |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 239 | if (mp->static_mac) |
| 240 | flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC; |
| 241 | if (mp->bvi_mac) |
| 242 | flags |= L2FIB_ENTRY_RESULT_FLAG_BVI; |
| 243 | l2fib_add_entry (mac, bd_index, sw_if_index, flags); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 244 | } |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 245 | } |
| 246 | else |
| 247 | { |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 248 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 249 | if (l2fib_del_entry (mac, bd_index, sw_if_index)) |
| 250 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | BAD_SW_IF_INDEX_LABEL; |
| 254 | |
| 255 | REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY); |
| 256 | } |
| 257 | |
| 258 | static void |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 259 | vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp) |
| 260 | { |
| 261 | int rv = 0; |
| 262 | vl_api_want_l2_macs_events_reply_t *rmp; |
| 263 | l2learn_main_t *lm = &l2learn_main; |
| 264 | l2fib_main_t *fm = &l2fib_main; |
| 265 | u32 pid = ntohl (mp->pid); |
| 266 | u32 learn_limit = ntohl (mp->learn_limit); |
| 267 | |
| 268 | if (mp->enable_disable) |
| 269 | { |
| 270 | if (lm->client_pid == 0) |
| 271 | { |
| 272 | lm->client_pid = pid; |
| 273 | lm->client_index = mp->client_index; |
| 274 | |
| 275 | if (mp->max_macs_in_event) |
| 276 | fm->max_macs_in_event = mp->max_macs_in_event * 10; |
| 277 | else |
| 278 | fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT; |
| 279 | |
| 280 | if (mp->scan_delay) |
| 281 | fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3; |
| 282 | else |
| 283 | fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT; |
| 284 | |
| 285 | /* change learn limit and flush all learned MACs */ |
| 286 | if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT)) |
| 287 | lm->global_learn_limit = learn_limit; |
| 288 | else |
| 289 | lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT; |
| 290 | |
| 291 | l2fib_flush_all_mac (vlib_get_main ()); |
| 292 | } |
| 293 | else if (lm->client_pid != pid) |
| 294 | { |
| 295 | rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT; |
| 296 | goto exit; |
| 297 | } |
| 298 | } |
| 299 | else if (lm->client_pid) |
| 300 | { |
| 301 | lm->client_pid = 0; |
| 302 | lm->client_index = 0; |
John Lo | dbfa574 | 2017-09-02 08:27:36 -0400 | [diff] [blame] | 303 | if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT)) |
John Lo | e531f4c | 2017-08-22 09:16:50 -0400 | [diff] [blame] | 304 | lm->global_learn_limit = learn_limit; |
| 305 | else |
| 306 | lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | exit: |
| 310 | REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY); |
| 311 | } |
| 312 | |
| 313 | static void |
Eyal Bari | f24991c | 2017-04-05 05:33:21 +0300 | [diff] [blame] | 314 | vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp) |
| 315 | { |
| 316 | int rv = 0; |
| 317 | vlib_main_t *vm = vlib_get_main (); |
| 318 | vl_api_l2fib_flush_int_reply_t *rmp; |
| 319 | |
| 320 | VALIDATE_SW_IF_INDEX (mp); |
| 321 | |
| 322 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 323 | l2fib_flush_int_mac (vm, sw_if_index); |
| 324 | |
| 325 | BAD_SW_IF_INDEX_LABEL; |
| 326 | REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY); |
| 327 | } |
| 328 | |
| 329 | static void |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 330 | vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp) |
| 331 | { |
| 332 | int rv = 0; |
| 333 | vl_api_l2fib_flush_all_reply_t *rmp; |
| 334 | |
| 335 | l2fib_flush_all_mac (vlib_get_main ()); |
| 336 | REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY); |
| 337 | } |
| 338 | |
| 339 | static void |
Eyal Bari | f24991c | 2017-04-05 05:33:21 +0300 | [diff] [blame] | 340 | vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp) |
| 341 | { |
| 342 | int rv = 0; |
| 343 | vlib_main_t *vm = vlib_get_main (); |
| 344 | bd_main_t *bdm = &bd_main; |
| 345 | vl_api_l2fib_flush_bd_reply_t *rmp; |
| 346 | |
| 347 | u32 bd_id = ntohl (mp->bd_id); |
| 348 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 349 | if (p == 0) |
| 350 | { |
| 351 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 352 | goto out; |
| 353 | } |
| 354 | l2fib_flush_bd_mac (vm, *p); |
| 355 | out: |
| 356 | REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY); |
| 357 | } |
| 358 | |
| 359 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 360 | vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp) |
| 361 | { |
| 362 | vl_api_l2_flags_reply_t *rmp; |
| 363 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 364 | u32 rbm = 0; |
| 365 | |
| 366 | VALIDATE_SW_IF_INDEX (mp); |
| 367 | |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 368 | u32 sw_if_index = ntohl (mp->sw_if_index); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 369 | u32 flags = ntohl (mp->feature_bitmap); |
| 370 | u32 bitmap = 0; |
| 371 | |
| 372 | if (flags & L2_LEARN) |
| 373 | bitmap |= L2INPUT_FEAT_LEARN; |
| 374 | |
| 375 | if (flags & L2_FWD) |
| 376 | bitmap |= L2INPUT_FEAT_FWD; |
| 377 | |
| 378 | if (flags & L2_FLOOD) |
| 379 | bitmap |= L2INPUT_FEAT_FLOOD; |
| 380 | |
| 381 | if (flags & L2_UU_FLOOD) |
| 382 | bitmap |= L2INPUT_FEAT_UU_FLOOD; |
| 383 | |
| 384 | if (flags & L2_ARP_TERM) |
| 385 | bitmap |= L2INPUT_FEAT_ARP_TERM; |
| 386 | |
| 387 | rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 388 | |
| 389 | BAD_SW_IF_INDEX_LABEL; |
| 390 | |
| 391 | /* *INDENT-OFF* */ |
| 392 | REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, |
| 393 | ({ |
| 394 | rmp->resulting_feature_bitmap = ntohl(rbm); |
| 395 | })); |
| 396 | /* *INDENT-ON* */ |
| 397 | } |
| 398 | |
| 399 | static void |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 400 | vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t |
| 401 | * mp) |
| 402 | { |
| 403 | vlib_main_t *vm = vlib_get_main (); |
| 404 | bd_main_t *bdm = &bd_main; |
| 405 | vl_api_bridge_domain_set_mac_age_reply_t *rmp; |
| 406 | int rv = 0; |
| 407 | u32 bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 408 | uword *p; |
| 409 | |
| 410 | if (bd_id == 0) |
| 411 | { |
| 412 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 413 | goto out; |
| 414 | } |
| 415 | |
| 416 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 417 | if (p == 0) |
| 418 | { |
| 419 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 420 | goto out; |
| 421 | } |
| 422 | bd_set_mac_age (vm, *p, mp->mac_age); |
| 423 | out: |
| 424 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY); |
| 425 | } |
| 426 | |
| 427 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 428 | vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp) |
| 429 | { |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 430 | l2_bridge_domain_add_del_args_t a = { |
| 431 | .is_add = mp->is_add, |
| 432 | .flood = mp->flood, |
| 433 | .uu_flood = mp->uu_flood, |
| 434 | .forward = mp->forward, |
| 435 | .learn = mp->learn, |
| 436 | .arp_term = mp->arp_term, |
| 437 | .mac_age = mp->mac_age, |
| 438 | .bd_id = ntohl (mp->bd_id), |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 439 | .bd_tag = mp->bd_tag |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | int rv = bd_add_del (&a); |
| 443 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 444 | vl_api_bridge_domain_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 445 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY); |
| 446 | } |
| 447 | |
| 448 | static void |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 449 | send_bridge_domain_details (l2input_main_t * l2im, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 450 | vl_api_registration_t * reg, |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 451 | l2_bridge_domain_t * bd_config, |
| 452 | u32 n_sw_ifs, u32 context) |
| 453 | { |
| 454 | vl_api_bridge_domain_details_t *mp; |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 455 | l2_flood_member_t *m; |
| 456 | vl_api_bridge_domain_sw_if_t *sw_ifs; |
| 457 | l2_input_config_t *input_cfg; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 458 | |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 459 | mp = vl_msg_api_alloc (sizeof (*mp) + |
| 460 | (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t))); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 461 | clib_memset (mp, 0, sizeof (*mp)); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 462 | mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS); |
| 463 | mp->bd_id = ntohl (bd_config->bd_id); |
| 464 | mp->flood = bd_feature_flood (bd_config); |
| 465 | mp->uu_flood = bd_feature_uu_flood (bd_config); |
| 466 | mp->forward = bd_feature_forward (bd_config); |
| 467 | mp->learn = bd_feature_learn (bd_config); |
| 468 | mp->arp_term = bd_feature_arp_term (bd_config); |
| 469 | mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 470 | mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 471 | mp->mac_age = bd_config->mac_age; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 472 | if (bd_config->bd_tag) |
| 473 | { |
| 474 | strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag, |
| 475 | ARRAY_LEN (mp->bd_tag) - 1); |
| 476 | mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0; |
| 477 | } |
| 478 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 479 | mp->context = context; |
| 480 | |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 481 | sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details; |
| 482 | vec_foreach (m, bd_config->members) |
| 483 | { |
| 484 | sw_ifs->sw_if_index = ntohl (m->sw_if_index); |
| 485 | input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index); |
| 486 | sw_ifs->shg = input_cfg->shg; |
| 487 | sw_ifs++; |
| 488 | mp->n_sw_ifs++; |
| 489 | } |
| 490 | mp->n_sw_ifs = htonl (mp->n_sw_ifs); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 491 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 492 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static void |
| 496 | vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp) |
| 497 | { |
| 498 | bd_main_t *bdm = &bd_main; |
| 499 | l2input_main_t *l2im = &l2input_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 500 | vl_api_registration_t *reg; |
| 501 | u32 bd_id, bd_index, end; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 502 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 503 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 504 | if (!reg) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 505 | return; |
| 506 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 507 | bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 508 | if (bd_id == 0) |
| 509 | return; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 510 | |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 511 | if (bd_id == ~0) |
| 512 | bd_index = 0, end = vec_len (l2im->bd_configs); |
| 513 | else |
| 514 | { |
| 515 | bd_index = bd_find_index (bdm, bd_id); |
| 516 | if (bd_index == ~0) |
| 517 | return; |
| 518 | |
| 519 | end = bd_index + 1; |
| 520 | } |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 521 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 522 | for (; bd_index < end; bd_index++) |
| 523 | { |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 524 | l2_bridge_domain_t *bd_config = |
| 525 | l2input_bd_config_from_index (l2im, bd_index); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 526 | /* skip dummy bd_id 0 */ |
| 527 | if (bd_config && (bd_config->bd_id > 0)) |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 528 | send_bridge_domain_details (l2im, reg, bd_config, |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 529 | vec_len (bd_config->members), |
| 530 | mp->context); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 534 | static bd_flags_t |
| 535 | bd_flags_decode (vl_api_bd_flags_t v) |
| 536 | { |
| 537 | bd_flags_t f = L2_NONE; |
| 538 | |
| 539 | v = ntohl (v); |
| 540 | |
| 541 | if (v & BRIDGE_API_FLAG_LEARN) |
| 542 | f |= L2_LEARN; |
| 543 | if (v & BRIDGE_API_FLAG_FWD) |
| 544 | f |= L2_FWD; |
| 545 | if (v & BRIDGE_API_FLAG_FLOOD) |
| 546 | f |= L2_FLOOD; |
| 547 | if (v & BRIDGE_API_FLAG_UU_FLOOD) |
| 548 | f |= L2_UU_FLOOD; |
| 549 | if (v & BRIDGE_API_FLAG_ARP_TERM) |
| 550 | f |= L2_ARP_TERM; |
| 551 | |
| 552 | return (f); |
| 553 | } |
| 554 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 555 | static void |
| 556 | vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp) |
| 557 | { |
| 558 | vlib_main_t *vm = vlib_get_main (); |
| 559 | bd_main_t *bdm = &bd_main; |
| 560 | vl_api_bridge_flags_reply_t *rmp; |
Dave Barach | 98d6b61 | 2019-01-03 09:30:00 -0500 | [diff] [blame^] | 561 | u32 bitmap = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 562 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 563 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 564 | bd_flags_t flags = bd_flags_decode (mp->flags); |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 565 | u32 bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 566 | if (bd_id == 0) |
| 567 | { |
| 568 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 569 | goto out; |
| 570 | } |
| 571 | |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 572 | u32 bd_index = bd_find_index (bdm, bd_id); |
| 573 | if (bd_index == ~0) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 574 | { |
| 575 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 576 | goto out; |
| 577 | } |
| 578 | |
Dave Barach | 98d6b61 | 2019-01-03 09:30:00 -0500 | [diff] [blame^] | 579 | bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 580 | |
| 581 | out: |
| 582 | /* *INDENT-OFF* */ |
| 583 | REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY, |
| 584 | ({ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 585 | rmp->resulting_feature_bitmap = ntohl(bitmap); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 586 | })); |
| 587 | /* *INDENT-ON* */ |
| 588 | } |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 589 | |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 590 | static void |
| 591 | vl_api_l2_interface_vlan_tag_rewrite_t_handler |
| 592 | (vl_api_l2_interface_vlan_tag_rewrite_t * mp) |
| 593 | { |
| 594 | int rv = 0; |
| 595 | vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp; |
| 596 | vnet_main_t *vnm = vnet_get_main (); |
| 597 | vlib_main_t *vm = vlib_get_main (); |
| 598 | u32 vtr_op; |
| 599 | |
| 600 | VALIDATE_SW_IF_INDEX (mp); |
| 601 | |
| 602 | vtr_op = ntohl (mp->vtr_op); |
| 603 | |
| 604 | /* The L2 code is unsuspicious */ |
| 605 | switch (vtr_op) |
| 606 | { |
| 607 | case L2_VTR_DISABLED: |
| 608 | case L2_VTR_PUSH_1: |
| 609 | case L2_VTR_PUSH_2: |
| 610 | case L2_VTR_POP_1: |
| 611 | case L2_VTR_POP_2: |
| 612 | case L2_VTR_TRANSLATE_1_1: |
| 613 | case L2_VTR_TRANSLATE_1_2: |
| 614 | case L2_VTR_TRANSLATE_2_1: |
| 615 | case L2_VTR_TRANSLATE_2_2: |
| 616 | break; |
| 617 | |
| 618 | default: |
| 619 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 620 | goto bad_sw_if_index; |
| 621 | } |
| 622 | |
| 623 | rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op, |
| 624 | ntohl (mp->push_dot1q), ntohl (mp->tag1), |
| 625 | ntohl (mp->tag2)); |
| 626 | |
| 627 | BAD_SW_IF_INDEX_LABEL; |
| 628 | |
| 629 | REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY); |
| 630 | } |
| 631 | |
| 632 | static void |
| 633 | vl_api_l2_interface_pbb_tag_rewrite_t_handler |
| 634 | (vl_api_l2_interface_pbb_tag_rewrite_t * mp) |
| 635 | { |
| 636 | vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp; |
| 637 | vnet_main_t *vnm = vnet_get_main (); |
| 638 | vlib_main_t *vm = vlib_get_main (); |
| 639 | u32 vtr_op; |
| 640 | int rv = 0; |
| 641 | |
| 642 | VALIDATE_SW_IF_INDEX (mp); |
| 643 | |
| 644 | vtr_op = ntohl (mp->vtr_op); |
| 645 | |
| 646 | switch (vtr_op) |
| 647 | { |
| 648 | case L2_VTR_DISABLED: |
| 649 | case L2_VTR_PUSH_2: |
| 650 | case L2_VTR_POP_2: |
| 651 | case L2_VTR_TRANSLATE_2_1: |
| 652 | break; |
| 653 | |
| 654 | default: |
| 655 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 656 | goto bad_sw_if_index; |
| 657 | } |
| 658 | |
| 659 | rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op, |
| 660 | mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid), |
| 661 | ntohl (mp->i_sid), ntohs (mp->outer_tag)); |
| 662 | |
| 663 | BAD_SW_IF_INDEX_LABEL; |
| 664 | |
| 665 | REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY); |
| 666 | } |
| 667 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 668 | static void |
| 669 | vl_api_sw_interface_set_l2_xconnect_t_handler |
| 670 | (vl_api_sw_interface_set_l2_xconnect_t * mp) |
| 671 | { |
| 672 | vl_api_sw_interface_set_l2_xconnect_reply_t *rmp; |
| 673 | int rv = 0; |
| 674 | u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index); |
| 675 | u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index); |
| 676 | vlib_main_t *vm = vlib_get_main (); |
| 677 | vnet_main_t *vnm = vnet_get_main (); |
| 678 | |
| 679 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 680 | |
| 681 | if (mp->enable) |
| 682 | { |
| 683 | VALIDATE_TX_SW_IF_INDEX (mp); |
| 684 | rv = set_int_l2_mode (vm, vnm, MODE_L2_XC, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 685 | rx_sw_if_index, 0, |
| 686 | L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 687 | } |
| 688 | else |
| 689 | { |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 690 | rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, |
| 691 | L2_BD_PORT_TYPE_NORMAL, 0, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Alexander Chernavin | e178b27 | 2018-09-24 05:42:01 -0400 | [diff] [blame] | 694 | switch (rv) |
| 695 | { |
| 696 | case MODE_ERROR_ETH: |
| 697 | rv = VNET_API_ERROR_NON_ETHERNET; |
| 698 | break; |
| 699 | case MODE_ERROR_BVI_DEF: |
| 700 | rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI; |
| 701 | break; |
| 702 | } |
| 703 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 704 | BAD_RX_SW_IF_INDEX_LABEL; |
| 705 | BAD_TX_SW_IF_INDEX_LABEL; |
| 706 | |
| 707 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY); |
| 708 | } |
| 709 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 710 | static int |
| 711 | l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l) |
| 712 | { |
| 713 | v = clib_net_to_host_u32 (v); |
| 714 | |
| 715 | switch (v) |
| 716 | { |
| 717 | case L2_API_PORT_TYPE_NORMAL: |
| 718 | *l = L2_BD_PORT_TYPE_NORMAL; |
| 719 | return 0; |
| 720 | case L2_API_PORT_TYPE_BVI: |
| 721 | *l = L2_BD_PORT_TYPE_BVI; |
| 722 | return 0; |
| 723 | case L2_API_PORT_TYPE_UU_FWD: |
| 724 | *l = L2_BD_PORT_TYPE_UU_FWD; |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | return (VNET_API_ERROR_INVALID_VALUE); |
| 729 | } |
| 730 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 731 | static void |
| 732 | vl_api_sw_interface_set_l2_bridge_t_handler |
| 733 | (vl_api_sw_interface_set_l2_bridge_t * mp) |
| 734 | { |
| 735 | bd_main_t *bdm = &bd_main; |
| 736 | vl_api_sw_interface_set_l2_bridge_reply_t *rmp; |
| 737 | int rv = 0; |
| 738 | vlib_main_t *vm = vlib_get_main (); |
| 739 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 740 | l2_bd_port_type_t pt; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 741 | |
| 742 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 743 | u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 744 | rv = l2_bd_port_type_decode (mp->port_type, &pt); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 745 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 746 | if (0 != rv) |
| 747 | goto out; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 748 | if (mp->enable) |
| 749 | { |
| 750 | VALIDATE_BD_ID (mp); |
| 751 | u32 bd_id = ntohl (mp->bd_id); |
| 752 | u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 753 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 754 | rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 755 | rx_sw_if_index, bd_index, pt, mp->shg, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 759 | rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Alexander Chernavin | e178b27 | 2018-09-24 05:42:01 -0400 | [diff] [blame] | 762 | switch (rv) |
| 763 | { |
| 764 | case MODE_ERROR_ETH: |
| 765 | rv = VNET_API_ERROR_NON_ETHERNET; |
| 766 | break; |
| 767 | case MODE_ERROR_BVI_DEF: |
| 768 | rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI; |
| 769 | break; |
| 770 | } |
| 771 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 772 | BAD_RX_SW_IF_INDEX_LABEL; |
| 773 | BAD_BD_ID_LABEL; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 774 | out: |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 775 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY); |
| 776 | } |
| 777 | |
| 778 | static void |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 779 | send_bd_ip_mac_entry (vpe_api_main_t * am, |
| 780 | vl_api_registration_t * reg, |
| 781 | u32 bd_id, u8 is_ipv6, |
| 782 | u8 * ip_address, u8 * mac_address, u32 context) |
| 783 | { |
| 784 | vl_api_bd_ip_mac_details_t *mp; |
| 785 | |
| 786 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 787 | clib_memset (mp, 0, sizeof (*mp)); |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 788 | mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS); |
| 789 | |
| 790 | mp->bd_id = ntohl (bd_id); |
| 791 | |
| 792 | clib_memcpy (mp->mac_address, mac_address, 6); |
| 793 | mp->is_ipv6 = is_ipv6; |
| 794 | clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4); |
| 795 | mp->context = context; |
| 796 | |
| 797 | vl_api_send_msg (reg, (u8 *) mp); |
| 798 | } |
| 799 | |
| 800 | static void |
| 801 | vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp) |
| 802 | { |
| 803 | vpe_api_main_t *am = &vpe_api_main; |
| 804 | bd_main_t *bdm = &bd_main; |
| 805 | l2_bridge_domain_t *bd_config; |
| 806 | u32 bd_id = ntohl (mp->bd_id); |
Mohsin Kazmi | b24dfec | 2018-08-23 12:24:19 +0200 | [diff] [blame] | 807 | u32 bd_index, start, end; |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 808 | vl_api_registration_t *reg; |
| 809 | uword *p; |
| 810 | |
| 811 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 812 | if (!reg) |
| 813 | return; |
| 814 | |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 815 | /* see bd_id: ~0 means "any" */ |
| 816 | if (bd_id == ~0) |
Mohsin Kazmi | b24dfec | 2018-08-23 12:24:19 +0200 | [diff] [blame] | 817 | { |
| 818 | start = 1; |
| 819 | end = vec_len (l2input_main.bd_configs); |
| 820 | } |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 821 | else |
| 822 | { |
| 823 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 824 | if (p == 0) |
| 825 | return; |
| 826 | |
| 827 | bd_index = p[0]; |
| 828 | vec_validate (l2input_main.bd_configs, bd_index); |
| 829 | start = bd_index; |
| 830 | end = start + 1; |
| 831 | } |
| 832 | |
| 833 | for (bd_index = start; bd_index < end; bd_index++) |
| 834 | { |
| 835 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 836 | if (bd_is_valid (bd_config)) |
| 837 | { |
| 838 | ip4_address_t ip4_addr; |
| 839 | ip6_address_t *ip6_addr; |
| 840 | u64 mac_addr; |
| 841 | bd_id = bd_config->bd_id; |
| 842 | |
| 843 | /* *INDENT-OFF* */ |
| 844 | hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4, |
| 845 | ({ |
| 846 | send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context); |
| 847 | })); |
| 848 | |
| 849 | hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6, |
| 850 | ({ |
| 851 | send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context); |
| 852 | })); |
| 853 | /* *INDENT-ON* */ |
| 854 | } |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | static void |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 859 | vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp) |
| 860 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 861 | ip46_address_t ip_addr = ip46_address_initializer; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 862 | vl_api_bd_ip_mac_add_del_reply_t *rmp; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 863 | bd_main_t *bdm = &bd_main; |
| 864 | u32 bd_index, bd_id; |
| 865 | mac_address_t mac; |
| 866 | ip46_type_t type; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 867 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 868 | uword *p; |
| 869 | |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 870 | bd_id = ntohl (mp->bd_id); |
| 871 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 872 | if (bd_id == 0) |
| 873 | { |
| 874 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 875 | goto out; |
| 876 | } |
| 877 | |
| 878 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 879 | if (p == 0) |
| 880 | { |
| 881 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 882 | goto out; |
| 883 | } |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 884 | bd_index = p[0]; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 885 | |
| 886 | type = ip_address_decode (&mp->ip, &ip_addr); |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 887 | mac_address_decode (mp->mac, &mac); |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 888 | |
| 889 | if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add)) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 890 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 891 | |
| 892 | out: |
| 893 | REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY); |
| 894 | } |
| 895 | |
| 896 | extern void l2_efp_filter_configure (vnet_main_t * vnet_main, |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 897 | u32 sw_if_index, u8 enable); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 898 | |
| 899 | static void |
| 900 | vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t * |
| 901 | mp) |
| 902 | { |
| 903 | int rv; |
| 904 | vl_api_l2_interface_efp_filter_reply_t *rmp; |
| 905 | vnet_main_t *vnm = vnet_get_main (); |
| 906 | |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 907 | VALIDATE_SW_IF_INDEX (mp); |
| 908 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 909 | // enable/disable the feature |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 910 | l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 911 | rv = vnm->api_errno; |
| 912 | |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 913 | BAD_SW_IF_INDEX_LABEL; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 914 | REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY); |
| 915 | } |
| 916 | |
| 917 | static void |
| 918 | vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp) |
| 919 | { |
| 920 | extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index, |
| 921 | int is_add); |
| 922 | vl_api_l2_patch_add_del_reply_t *rmp; |
| 923 | int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index, |
| 924 | int is_add); |
| 925 | int rv = 0; |
| 926 | |
| 927 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 928 | VALIDATE_TX_SW_IF_INDEX (mp); |
| 929 | |
| 930 | rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index), |
| 931 | ntohl (mp->tx_sw_if_index), |
| 932 | (int) (mp->is_add != 0)); |
| 933 | |
| 934 | BAD_RX_SW_IF_INDEX_LABEL; |
| 935 | BAD_TX_SW_IF_INDEX_LABEL; |
| 936 | |
| 937 | REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY); |
| 938 | } |
| 939 | |
| 940 | static void |
| 941 | vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp) |
| 942 | { |
| 943 | vl_api_sw_interface_set_vpath_reply_t *rmp; |
| 944 | int rv = 0; |
| 945 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 946 | |
| 947 | VALIDATE_SW_IF_INDEX (mp); |
| 948 | |
| 949 | l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable); |
| 950 | vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4", |
| 951 | sw_if_index, mp->enable, 0, 0); |
| 952 | vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4", |
| 953 | sw_if_index, mp->enable, 0, 0); |
| 954 | vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6", |
| 955 | sw_if_index, mp->enable, 0, 0); |
| 956 | vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6", |
| 957 | sw_if_index, mp->enable, 0, 0); |
| 958 | |
| 959 | BAD_SW_IF_INDEX_LABEL; |
| 960 | |
| 961 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY); |
| 962 | } |
| 963 | |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 964 | /* |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 965 | * l2_api_hookup |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 966 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 967 | * vlib has already mapped shared memory and |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 968 | * added the client registration handlers. |
| 969 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 970 | */ |
| 971 | #define vl_msg_name_crc_list |
| 972 | #include <vnet/vnet_all_api_h.h> |
| 973 | #undef vl_msg_name_crc_list |
| 974 | |
| 975 | static void |
| 976 | setup_message_id_table (api_main_t * am) |
| 977 | { |
| 978 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 979 | foreach_vl_msg_name_crc_l2; |
| 980 | #undef _ |
| 981 | } |
| 982 | |
| 983 | static clib_error_t * |
| 984 | l2_api_hookup (vlib_main_t * vm) |
| 985 | { |
| 986 | api_main_t *am = &api_main; |
| 987 | |
| 988 | #define _(N,n) \ |
| 989 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 990 | vl_api_##n##_t_handler, \ |
| 991 | vl_noop_handler, \ |
| 992 | vl_api_##n##_t_endian, \ |
| 993 | vl_api_##n##_t_print, \ |
| 994 | sizeof(vl_api_##n##_t), 1); |
| 995 | foreach_vpe_api_msg; |
| 996 | #undef _ |
| 997 | |
| 998 | /* |
| 999 | * Set up the (msg_name, crc, message-id) table |
| 1000 | */ |
| 1001 | setup_message_id_table (am); |
| 1002 | |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | VLIB_API_INIT_FUNCTION (l2_api_hookup); |
| 1007 | |
| 1008 | /* |
| 1009 | * fd.io coding-style-patch-verification: ON |
| 1010 | * |
| 1011 | * Local Variables: |
| 1012 | * eval: (c-set-style "gnu") |
| 1013 | * End: |
| 1014 | */ |