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 | 192b13f | 2019-03-15 02:16:20 -0700 | [diff] [blame] | 30 | #include <vnet/l2/l2_bvi.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 31 | #include <vnet/l2/l2_arp_term.h> |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 32 | #include <vnet/ip/ip_types_api.h> |
| 33 | #include <vnet/ethernet/ethernet_types_api.h> |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 34 | |
| 35 | #include <vnet/vnet_msg_enum.h> |
| 36 | |
| 37 | #define vl_typedefs /* define message structures */ |
| 38 | #include <vnet/vnet_all_api_h.h> |
| 39 | #undef vl_typedefs |
| 40 | |
| 41 | #define vl_endianfun /* define message structures */ |
| 42 | #include <vnet/vnet_all_api_h.h> |
| 43 | #undef vl_endianfun |
| 44 | |
| 45 | /* instantiate all the print functions we know about */ |
| 46 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 47 | #define vl_printfun |
| 48 | #include <vnet/vnet_all_api_h.h> |
| 49 | #undef vl_printfun |
| 50 | |
| 51 | #include <vlibapi/api_helper_macros.h> |
| 52 | |
Jerome Tollet | 5f93e3b | 2020-12-18 09:44:24 +0100 | [diff] [blame] | 53 | #define foreach_vpe_api_msg \ |
| 54 | _ (L2_XCONNECT_DUMP, l2_xconnect_dump) \ |
| 55 | _ (L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \ |
| 56 | _ (L2_FIB_TABLE_DUMP, l2_fib_table_dump) \ |
| 57 | _ (L2FIB_FLUSH_ALL, l2fib_flush_all) \ |
| 58 | _ (L2FIB_FLUSH_INT, l2fib_flush_int) \ |
| 59 | _ (L2FIB_FLUSH_BD, l2fib_flush_bd) \ |
| 60 | _ (L2FIB_ADD_DEL, l2fib_add_del) \ |
| 61 | _ (WANT_L2_MACS_EVENTS, want_l2_macs_events) \ |
| 62 | _ (L2_FLAGS, l2_flags) \ |
| 63 | _ (SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \ |
| 64 | _ (SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \ |
| 65 | _ (L2_PATCH_ADD_DEL, l2_patch_add_del) \ |
| 66 | _ (L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \ |
| 67 | _ (BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \ |
| 68 | _ (BD_IP_MAC_FLUSH, bd_ip_mac_flush) \ |
| 69 | _ (BD_IP_MAC_DUMP, bd_ip_mac_dump) \ |
| 70 | _ (BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \ |
| 71 | _ (BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \ |
| 72 | _ (BRIDGE_FLAGS, bridge_flags) \ |
| 73 | _ (L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \ |
| 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) \ |
| 77 | _ (BVI_CREATE, bvi_create) \ |
| 78 | _ (BVI_DELETE, bvi_delete) \ |
| 79 | _ (WANT_L2_ARP_TERM_EVENTS, want_l2_arp_term_events) \ |
| 80 | _ (BRIDGE_DOMAIN_SET_LEARN_LIMIT, bridge_domain_set_learn_limit) \ |
| 81 | _ (BRIDGE_DOMAIN_SET_DEFAULT_LEARN_LIMIT, \ |
| 82 | bridge_domain_set_default_learn_limit) |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 83 | |
| 84 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 85 | send_l2_xconnect_details (vl_api_registration_t * reg, u32 context, |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 86 | u32 rx_sw_if_index, u32 tx_sw_if_index) |
| 87 | { |
| 88 | vl_api_l2_xconnect_details_t *mp; |
| 89 | |
| 90 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 91 | clib_memset (mp, 0, sizeof (*mp)); |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 92 | mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS); |
| 93 | mp->context = context; |
| 94 | mp->rx_sw_if_index = htonl (rx_sw_if_index); |
| 95 | mp->tx_sw_if_index = htonl (tx_sw_if_index); |
| 96 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 97 | vl_api_send_msg (reg, (u8 *) mp); |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void |
| 101 | vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp) |
| 102 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 103 | vl_api_registration_t *reg; |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 104 | vnet_main_t *vnm = vnet_get_main (); |
| 105 | vnet_interface_main_t *im = &vnm->interface_main; |
| 106 | l2input_main_t *l2im = &l2input_main; |
| 107 | vnet_sw_interface_t *swif; |
| 108 | l2_input_config_t *config; |
| 109 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 110 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 111 | if (!reg) |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 112 | return; |
| 113 | |
| 114 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 115 | pool_foreach (swif, im->sw_interfaces) |
| 116 | { |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 117 | config = vec_elt_at_index (l2im->configs, swif->sw_if_index); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 118 | if (l2_input_is_xconnect(config)) |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 119 | send_l2_xconnect_details (reg, mp->context, swif->sw_if_index, |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 120 | config->output_sw_if_index); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 121 | } |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 122 | /* *INDENT-ON* */ |
| 123 | } |
| 124 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 125 | static void |
| 126 | vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp) |
| 127 | { |
| 128 | int rv = 0; |
| 129 | vl_api_l2_fib_clear_table_reply_t *rmp; |
| 130 | |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 131 | /* Clear all MACs including static MACs */ |
| 132 | l2fib_clear_table (); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 133 | |
| 134 | REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY); |
| 135 | } |
| 136 | |
| 137 | static void |
| 138 | send_l2fib_table_entry (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 139 | vl_api_registration_t * reg, |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 140 | l2fib_entry_key_t * l2fe_key, |
| 141 | l2fib_entry_result_t * l2fe_res, u32 context) |
| 142 | { |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 143 | vl_api_l2_fib_table_details_t *mp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 144 | |
| 145 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 146 | clib_memset (mp, 0, sizeof (*mp)); |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 147 | mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 148 | |
| 149 | mp->bd_id = |
| 150 | ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id); |
| 151 | |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 152 | mac_address_encode ((mac_address_t *) l2fe_key->fields.mac, mp->mac); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 153 | mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index); |
Neale Ranns | 7341b6d | 2018-09-19 04:07:02 -0700 | [diff] [blame] | 154 | mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0); |
| 155 | mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0); |
| 156 | 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] | 157 | mp->context = context; |
| 158 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 159 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 163 | vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp) |
| 164 | { |
| 165 | vpe_api_main_t *am = &vpe_api_main; |
| 166 | bd_main_t *bdm = &bd_main; |
| 167 | l2fib_entry_key_t *l2fe_key = NULL; |
| 168 | l2fib_entry_result_t *l2fe_res = NULL; |
| 169 | u32 ni, bd_id = ntohl (mp->bd_id); |
| 170 | u32 bd_index; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 171 | vl_api_registration_t *reg; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 172 | uword *p; |
| 173 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 174 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 175 | if (!reg) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 176 | return; |
| 177 | |
| 178 | /* see l2fib_table_dump: ~0 means "any" */ |
| 179 | if (bd_id == ~0) |
| 180 | bd_index = ~0; |
| 181 | else |
| 182 | { |
| 183 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 184 | if (p == 0) |
| 185 | return; |
| 186 | |
| 187 | bd_index = p[0]; |
| 188 | } |
| 189 | |
| 190 | l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res); |
| 191 | |
| 192 | vec_foreach_index (ni, l2fe_key) |
| 193 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 194 | 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] | 195 | vec_elt_at_index (l2fe_res, ni), mp->context); |
| 196 | } |
| 197 | vec_free (l2fe_key); |
| 198 | vec_free (l2fe_res); |
| 199 | } |
| 200 | |
| 201 | static void |
| 202 | vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp) |
| 203 | { |
| 204 | bd_main_t *bdm = &bd_main; |
| 205 | l2input_main_t *l2im = &l2input_main; |
| 206 | vl_api_l2fib_add_del_reply_t *rmp; |
| 207 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 208 | u32 bd_id = ntohl (mp->bd_id); |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 209 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 210 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 211 | if (!p) |
| 212 | { |
| 213 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 214 | goto bad_sw_if_index; |
| 215 | } |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 216 | u32 bd_index = p[0]; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 217 | |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 218 | mac_address_t mac; |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 219 | |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 220 | mac_address_decode (mp->mac, &mac); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 221 | if (mp->is_add) |
| 222 | { |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 223 | if (mp->filter_mac) |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 224 | l2fib_add_filter_entry (mac.bytes, bd_index); |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 225 | else |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 226 | { |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 227 | l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE; |
Eyal Bari | 31a71ab | 2017-06-25 14:42:33 +0300 | [diff] [blame] | 228 | u32 sw_if_index = ntohl (mp->sw_if_index); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 229 | VALIDATE_SW_IF_INDEX (mp); |
| 230 | if (vec_len (l2im->configs) <= sw_if_index) |
| 231 | { |
| 232 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 233 | goto bad_sw_if_index; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | l2_input_config_t *config; |
| 238 | config = vec_elt_at_index (l2im->configs, sw_if_index); |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 239 | if (!l2_input_is_bridge (config)) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 240 | { |
| 241 | rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 242 | goto bad_sw_if_index; |
| 243 | } |
| 244 | } |
Neale Ranns | b54d081 | 2018-09-06 06:22:56 -0700 | [diff] [blame] | 245 | if (mp->static_mac) |
| 246 | flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC; |
| 247 | if (mp->bvi_mac) |
| 248 | flags |= L2FIB_ENTRY_RESULT_FLAG_BVI; |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 249 | l2fib_add_entry (mac.bytes, bd_index, sw_if_index, flags); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 250 | } |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 251 | } |
| 252 | else |
| 253 | { |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 254 | u32 sw_if_index = ntohl (mp->sw_if_index); |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 255 | if (l2fib_del_entry (mac.bytes, bd_index, sw_if_index)) |
John Lo | 7dbd726 | 2018-05-31 10:25:18 -0400 | [diff] [blame] | 256 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | BAD_SW_IF_INDEX_LABEL; |
| 260 | |
| 261 | REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY); |
| 262 | } |
| 263 | |
| 264 | static void |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 265 | vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp) |
| 266 | { |
| 267 | int rv = 0; |
| 268 | vl_api_want_l2_macs_events_reply_t *rmp; |
| 269 | l2learn_main_t *lm = &l2learn_main; |
| 270 | l2fib_main_t *fm = &l2fib_main; |
| 271 | u32 pid = ntohl (mp->pid); |
| 272 | u32 learn_limit = ntohl (mp->learn_limit); |
| 273 | |
| 274 | if (mp->enable_disable) |
| 275 | { |
| 276 | if (lm->client_pid == 0) |
| 277 | { |
| 278 | lm->client_pid = pid; |
| 279 | lm->client_index = mp->client_index; |
| 280 | |
| 281 | if (mp->max_macs_in_event) |
| 282 | fm->max_macs_in_event = mp->max_macs_in_event * 10; |
| 283 | else |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 284 | { |
| 285 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 286 | goto exit; |
| 287 | } |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 288 | |
| 289 | if (mp->scan_delay) |
| 290 | fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3; |
| 291 | else |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 292 | { |
| 293 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 294 | goto exit; |
| 295 | } |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 296 | |
| 297 | /* change learn limit and flush all learned MACs */ |
| 298 | if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT)) |
| 299 | lm->global_learn_limit = learn_limit; |
| 300 | else |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 301 | { |
| 302 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 303 | goto exit; |
| 304 | } |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 305 | |
| 306 | l2fib_flush_all_mac (vlib_get_main ()); |
| 307 | } |
| 308 | else if (lm->client_pid != pid) |
| 309 | { |
| 310 | rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT; |
| 311 | goto exit; |
| 312 | } |
| 313 | } |
| 314 | else if (lm->client_pid) |
| 315 | { |
| 316 | lm->client_pid = 0; |
| 317 | lm->client_index = 0; |
John Lo | dbfa574 | 2017-09-02 08:27:36 -0400 | [diff] [blame] | 318 | if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT)) |
John Lo | e531f4c | 2017-08-22 09:16:50 -0400 | [diff] [blame] | 319 | lm->global_learn_limit = learn_limit; |
| 320 | else |
| 321 | lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT; |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | exit: |
| 325 | REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY); |
| 326 | } |
| 327 | |
| 328 | static void |
Eyal Bari | f24991c | 2017-04-05 05:33:21 +0300 | [diff] [blame] | 329 | vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp) |
| 330 | { |
| 331 | int rv = 0; |
| 332 | vlib_main_t *vm = vlib_get_main (); |
| 333 | vl_api_l2fib_flush_int_reply_t *rmp; |
| 334 | |
| 335 | VALIDATE_SW_IF_INDEX (mp); |
| 336 | |
| 337 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 338 | l2fib_flush_int_mac (vm, sw_if_index); |
| 339 | |
| 340 | BAD_SW_IF_INDEX_LABEL; |
| 341 | REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY); |
| 342 | } |
| 343 | |
| 344 | static void |
Eyal Bari | 7537e71 | 2017-04-27 14:07:55 +0300 | [diff] [blame] | 345 | vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp) |
| 346 | { |
| 347 | int rv = 0; |
| 348 | vl_api_l2fib_flush_all_reply_t *rmp; |
| 349 | |
| 350 | l2fib_flush_all_mac (vlib_get_main ()); |
| 351 | REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY); |
| 352 | } |
| 353 | |
| 354 | static void |
Eyal Bari | f24991c | 2017-04-05 05:33:21 +0300 | [diff] [blame] | 355 | vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp) |
| 356 | { |
| 357 | int rv = 0; |
| 358 | vlib_main_t *vm = vlib_get_main (); |
| 359 | bd_main_t *bdm = &bd_main; |
| 360 | vl_api_l2fib_flush_bd_reply_t *rmp; |
| 361 | |
| 362 | u32 bd_id = ntohl (mp->bd_id); |
| 363 | uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 364 | if (p == 0) |
| 365 | { |
| 366 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 367 | goto out; |
| 368 | } |
| 369 | l2fib_flush_bd_mac (vm, *p); |
| 370 | out: |
| 371 | REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY); |
| 372 | } |
| 373 | |
| 374 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 375 | vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp) |
| 376 | { |
| 377 | vl_api_l2_flags_reply_t *rmp; |
| 378 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 379 | u32 rbm = 0; |
| 380 | |
| 381 | VALIDATE_SW_IF_INDEX (mp); |
| 382 | |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 383 | u32 sw_if_index = ntohl (mp->sw_if_index); |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 384 | u32 flags = ntohl (mp->feature_bitmap); |
| 385 | u32 bitmap = 0; |
| 386 | |
| 387 | if (flags & L2_LEARN) |
| 388 | bitmap |= L2INPUT_FEAT_LEARN; |
| 389 | |
| 390 | if (flags & L2_FWD) |
| 391 | bitmap |= L2INPUT_FEAT_FWD; |
| 392 | |
| 393 | if (flags & L2_FLOOD) |
| 394 | bitmap |= L2INPUT_FEAT_FLOOD; |
| 395 | |
| 396 | if (flags & L2_UU_FLOOD) |
| 397 | bitmap |= L2INPUT_FEAT_UU_FLOOD; |
| 398 | |
| 399 | if (flags & L2_ARP_TERM) |
| 400 | bitmap |= L2INPUT_FEAT_ARP_TERM; |
| 401 | |
| 402 | rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 403 | |
| 404 | BAD_SW_IF_INDEX_LABEL; |
| 405 | |
| 406 | /* *INDENT-OFF* */ |
| 407 | REPLY_MACRO2(VL_API_L2_FLAGS_REPLY, |
| 408 | ({ |
| 409 | rmp->resulting_feature_bitmap = ntohl(rbm); |
| 410 | })); |
| 411 | /* *INDENT-ON* */ |
| 412 | } |
| 413 | |
| 414 | static void |
Jerome Tollet | 5f93e3b | 2020-12-18 09:44:24 +0100 | [diff] [blame] | 415 | vl_api_bridge_domain_set_default_learn_limit_t_handler ( |
| 416 | vl_api_bridge_domain_set_default_learn_limit_t *mp) |
| 417 | { |
| 418 | vl_api_bridge_domain_set_default_learn_limit_reply_t *rmp; |
| 419 | int rv = 0; |
| 420 | |
| 421 | l2learn_main.bd_default_learn_limit = ntohl (mp->learn_limit); |
| 422 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_DEFAULT_LEARN_LIMIT_REPLY); |
| 423 | } |
| 424 | |
| 425 | static void |
| 426 | vl_api_bridge_domain_set_learn_limit_t_handler ( |
| 427 | vl_api_bridge_domain_set_learn_limit_t *mp) |
| 428 | { |
| 429 | vlib_main_t *vm = vlib_get_main (); |
| 430 | bd_main_t *bdm = &bd_main; |
| 431 | vl_api_bridge_domain_set_learn_limit_reply_t *rmp; |
| 432 | int rv = 0; |
| 433 | u32 bd_id = ntohl (mp->bd_id); |
| 434 | uword *p; |
| 435 | |
| 436 | if (bd_id == 0) |
| 437 | { |
| 438 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 439 | goto out; |
| 440 | } |
| 441 | |
| 442 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 443 | if (p == 0) |
| 444 | { |
| 445 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 446 | goto out; |
| 447 | } |
| 448 | bd_set_learn_limit (vm, *p, ntohl (mp->learn_limit)); |
| 449 | out: |
| 450 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_LEARN_LIMIT_REPLY); |
| 451 | } |
| 452 | |
| 453 | static void |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 454 | vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t |
| 455 | * mp) |
| 456 | { |
| 457 | vlib_main_t *vm = vlib_get_main (); |
| 458 | bd_main_t *bdm = &bd_main; |
| 459 | vl_api_bridge_domain_set_mac_age_reply_t *rmp; |
| 460 | int rv = 0; |
| 461 | u32 bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 462 | uword *p; |
| 463 | |
| 464 | if (bd_id == 0) |
| 465 | { |
| 466 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 467 | goto out; |
| 468 | } |
| 469 | |
| 470 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame] | 471 | if (p == 0) |
| 472 | { |
| 473 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 474 | goto out; |
| 475 | } |
| 476 | bd_set_mac_age (vm, *p, mp->mac_age); |
| 477 | out: |
| 478 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY); |
| 479 | } |
| 480 | |
| 481 | static void |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 482 | vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp) |
| 483 | { |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 484 | l2_bridge_domain_add_del_args_t a = { |
| 485 | .is_add = mp->is_add, |
| 486 | .flood = mp->flood, |
| 487 | .uu_flood = mp->uu_flood, |
| 488 | .forward = mp->forward, |
| 489 | .learn = mp->learn, |
| 490 | .arp_term = mp->arp_term, |
Mohsin Kazmi | 5e6f734 | 2019-04-05 17:40:20 +0200 | [diff] [blame] | 491 | .arp_ufwd = mp->arp_ufwd, |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 492 | .mac_age = mp->mac_age, |
| 493 | .bd_id = ntohl (mp->bd_id), |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 494 | .bd_tag = mp->bd_tag |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | int rv = bd_add_del (&a); |
| 498 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 499 | vl_api_bridge_domain_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 500 | REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY); |
| 501 | } |
| 502 | |
| 503 | static void |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 504 | send_bridge_domain_details (l2input_main_t * l2im, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 505 | vl_api_registration_t * reg, |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 506 | l2_bridge_domain_t * bd_config, |
| 507 | u32 n_sw_ifs, u32 context) |
| 508 | { |
| 509 | vl_api_bridge_domain_details_t *mp; |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 510 | l2_flood_member_t *m; |
| 511 | vl_api_bridge_domain_sw_if_t *sw_ifs; |
| 512 | l2_input_config_t *input_cfg; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 513 | |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 514 | mp = vl_msg_api_alloc (sizeof (*mp) + |
| 515 | (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t))); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 516 | clib_memset (mp, 0, sizeof (*mp)); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 517 | mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS); |
| 518 | mp->bd_id = ntohl (bd_config->bd_id); |
| 519 | mp->flood = bd_feature_flood (bd_config); |
| 520 | mp->uu_flood = bd_feature_uu_flood (bd_config); |
| 521 | mp->forward = bd_feature_forward (bd_config); |
| 522 | mp->learn = bd_feature_learn (bd_config); |
| 523 | mp->arp_term = bd_feature_arp_term (bd_config); |
Mohsin Kazmi | 5e6f734 | 2019-04-05 17:40:20 +0200 | [diff] [blame] | 524 | mp->arp_ufwd = bd_feature_arp_ufwd (bd_config); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 525 | mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 526 | 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] | 527 | mp->mac_age = bd_config->mac_age; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame] | 528 | if (bd_config->bd_tag) |
| 529 | { |
| 530 | strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag, |
| 531 | ARRAY_LEN (mp->bd_tag) - 1); |
| 532 | mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0; |
| 533 | } |
| 534 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 535 | mp->context = context; |
| 536 | |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 537 | sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details; |
| 538 | vec_foreach (m, bd_config->members) |
| 539 | { |
| 540 | sw_ifs->sw_if_index = ntohl (m->sw_if_index); |
| 541 | input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index); |
| 542 | sw_ifs->shg = input_cfg->shg; |
| 543 | sw_ifs++; |
| 544 | mp->n_sw_ifs++; |
| 545 | } |
| 546 | mp->n_sw_ifs = htonl (mp->n_sw_ifs); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 547 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 548 | vl_api_send_msg (reg, (u8 *) mp); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void |
| 552 | vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp) |
| 553 | { |
| 554 | bd_main_t *bdm = &bd_main; |
| 555 | l2input_main_t *l2im = &l2input_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 556 | vl_api_registration_t *reg; |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 557 | u32 bd_id, bd_index, end, filter_sw_if_index; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 558 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 559 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 560 | if (!reg) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 561 | return; |
| 562 | |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 563 | filter_sw_if_index = ntohl (mp->sw_if_index); |
| 564 | if (filter_sw_if_index != ~0) |
| 565 | return; /* UNIMPLEMENTED */ |
| 566 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 567 | bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 568 | if (bd_id == 0) |
| 569 | return; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 570 | |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 571 | if (bd_id == ~0) |
| 572 | bd_index = 0, end = vec_len (l2im->bd_configs); |
| 573 | else |
| 574 | { |
| 575 | bd_index = bd_find_index (bdm, bd_id); |
| 576 | if (bd_index == ~0) |
| 577 | return; |
| 578 | |
| 579 | end = bd_index + 1; |
| 580 | } |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 581 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 582 | for (; bd_index < end; bd_index++) |
| 583 | { |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 584 | l2_bridge_domain_t *bd_config = |
| 585 | l2input_bd_config_from_index (l2im, bd_index); |
Dave Barach | 11fb09e | 2020-08-06 12:10:09 -0400 | [diff] [blame] | 586 | /* skip placeholder bd_id 0 */ |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 587 | if (bd_config && (bd_config->bd_id > 0)) |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 588 | send_bridge_domain_details (l2im, reg, bd_config, |
Ole Troan | 01384fe | 2017-05-12 11:55:35 +0200 | [diff] [blame] | 589 | vec_len (bd_config->members), |
| 590 | mp->context); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 594 | static bd_flags_t |
| 595 | bd_flags_decode (vl_api_bd_flags_t v) |
| 596 | { |
| 597 | bd_flags_t f = L2_NONE; |
| 598 | |
| 599 | v = ntohl (v); |
| 600 | |
| 601 | if (v & BRIDGE_API_FLAG_LEARN) |
| 602 | f |= L2_LEARN; |
| 603 | if (v & BRIDGE_API_FLAG_FWD) |
| 604 | f |= L2_FWD; |
| 605 | if (v & BRIDGE_API_FLAG_FLOOD) |
| 606 | f |= L2_FLOOD; |
| 607 | if (v & BRIDGE_API_FLAG_UU_FLOOD) |
| 608 | f |= L2_UU_FLOOD; |
| 609 | if (v & BRIDGE_API_FLAG_ARP_TERM) |
| 610 | f |= L2_ARP_TERM; |
Mohsin Kazmi | 5e6f734 | 2019-04-05 17:40:20 +0200 | [diff] [blame] | 611 | if (v & BRIDGE_API_FLAG_ARP_UFWD) |
| 612 | f |= L2_ARP_UFWD; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 613 | |
| 614 | return (f); |
| 615 | } |
| 616 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 617 | static void |
| 618 | vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp) |
| 619 | { |
| 620 | vlib_main_t *vm = vlib_get_main (); |
| 621 | bd_main_t *bdm = &bd_main; |
| 622 | vl_api_bridge_flags_reply_t *rmp; |
Dave Barach | 98d6b61 | 2019-01-03 09:30:00 -0500 | [diff] [blame] | 623 | u32 bitmap = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 624 | int rv = 0; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 625 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 626 | bd_flags_t flags = bd_flags_decode (mp->flags); |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 627 | u32 bd_id = ntohl (mp->bd_id); |
Jon Loeliger | 1c7d485 | 2017-05-02 11:06:23 -0500 | [diff] [blame] | 628 | if (bd_id == 0) |
| 629 | { |
| 630 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 631 | goto out; |
| 632 | } |
| 633 | |
Eyal Bari | 259fca7 | 2017-05-14 10:38:39 +0300 | [diff] [blame] | 634 | u32 bd_index = bd_find_index (bdm, bd_id); |
| 635 | if (bd_index == ~0) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 636 | { |
| 637 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 638 | goto out; |
| 639 | } |
| 640 | |
Dave Barach | 98d6b61 | 2019-01-03 09:30:00 -0500 | [diff] [blame] | 641 | bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 642 | |
| 643 | out: |
| 644 | /* *INDENT-OFF* */ |
| 645 | REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY, |
| 646 | ({ |
John Lo | 8d00fff | 2017-08-03 00:35:36 -0400 | [diff] [blame] | 647 | rmp->resulting_feature_bitmap = ntohl(bitmap); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 648 | })); |
| 649 | /* *INDENT-ON* */ |
| 650 | } |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 651 | |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 652 | static void |
| 653 | vl_api_l2_interface_vlan_tag_rewrite_t_handler |
| 654 | (vl_api_l2_interface_vlan_tag_rewrite_t * mp) |
| 655 | { |
| 656 | int rv = 0; |
| 657 | vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp; |
| 658 | vnet_main_t *vnm = vnet_get_main (); |
| 659 | vlib_main_t *vm = vlib_get_main (); |
| 660 | u32 vtr_op; |
| 661 | |
| 662 | VALIDATE_SW_IF_INDEX (mp); |
| 663 | |
| 664 | vtr_op = ntohl (mp->vtr_op); |
| 665 | |
| 666 | /* The L2 code is unsuspicious */ |
| 667 | switch (vtr_op) |
| 668 | { |
| 669 | case L2_VTR_DISABLED: |
| 670 | case L2_VTR_PUSH_1: |
| 671 | case L2_VTR_PUSH_2: |
| 672 | case L2_VTR_POP_1: |
| 673 | case L2_VTR_POP_2: |
| 674 | case L2_VTR_TRANSLATE_1_1: |
| 675 | case L2_VTR_TRANSLATE_1_2: |
| 676 | case L2_VTR_TRANSLATE_2_1: |
| 677 | case L2_VTR_TRANSLATE_2_2: |
| 678 | break; |
| 679 | |
| 680 | default: |
| 681 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 682 | goto bad_sw_if_index; |
| 683 | } |
| 684 | |
| 685 | rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op, |
| 686 | ntohl (mp->push_dot1q), ntohl (mp->tag1), |
| 687 | ntohl (mp->tag2)); |
| 688 | |
| 689 | BAD_SW_IF_INDEX_LABEL; |
| 690 | |
| 691 | REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY); |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | vl_api_l2_interface_pbb_tag_rewrite_t_handler |
| 696 | (vl_api_l2_interface_pbb_tag_rewrite_t * mp) |
| 697 | { |
| 698 | vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp; |
| 699 | vnet_main_t *vnm = vnet_get_main (); |
| 700 | vlib_main_t *vm = vlib_get_main (); |
| 701 | u32 vtr_op; |
| 702 | int rv = 0; |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 703 | mac_address_t b_dmac, b_smac; |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 704 | |
| 705 | VALIDATE_SW_IF_INDEX (mp); |
| 706 | |
| 707 | vtr_op = ntohl (mp->vtr_op); |
| 708 | |
| 709 | switch (vtr_op) |
| 710 | { |
| 711 | case L2_VTR_DISABLED: |
| 712 | case L2_VTR_PUSH_2: |
| 713 | case L2_VTR_POP_2: |
| 714 | case L2_VTR_TRANSLATE_2_1: |
| 715 | break; |
| 716 | |
| 717 | default: |
| 718 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 719 | goto bad_sw_if_index; |
| 720 | } |
| 721 | |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 722 | mac_address_decode (mp->b_dmac, &b_dmac); |
| 723 | mac_address_decode (mp->b_smac, &b_smac); |
| 724 | |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 725 | rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op, |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 726 | b_dmac.bytes, b_smac.bytes, ntohs (mp->b_vlanid), |
Pavel Kotucek | adec587 | 2017-01-25 08:50:53 +0100 | [diff] [blame] | 727 | ntohl (mp->i_sid), ntohs (mp->outer_tag)); |
| 728 | |
| 729 | BAD_SW_IF_INDEX_LABEL; |
| 730 | |
| 731 | REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY); |
| 732 | } |
| 733 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 734 | static void |
| 735 | vl_api_sw_interface_set_l2_xconnect_t_handler |
| 736 | (vl_api_sw_interface_set_l2_xconnect_t * mp) |
| 737 | { |
| 738 | vl_api_sw_interface_set_l2_xconnect_reply_t *rmp; |
| 739 | int rv = 0; |
| 740 | u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index); |
| 741 | u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index); |
| 742 | vlib_main_t *vm = vlib_get_main (); |
| 743 | vnet_main_t *vnm = vnet_get_main (); |
| 744 | |
| 745 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 746 | |
| 747 | if (mp->enable) |
| 748 | { |
| 749 | VALIDATE_TX_SW_IF_INDEX (mp); |
| 750 | rv = set_int_l2_mode (vm, vnm, MODE_L2_XC, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 751 | rx_sw_if_index, 0, |
| 752 | L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 753 | } |
| 754 | else |
| 755 | { |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 756 | rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, |
| 757 | L2_BD_PORT_TYPE_NORMAL, 0, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Alexander Chernavin | e178b27 | 2018-09-24 05:42:01 -0400 | [diff] [blame] | 760 | switch (rv) |
| 761 | { |
| 762 | case MODE_ERROR_ETH: |
| 763 | rv = VNET_API_ERROR_NON_ETHERNET; |
| 764 | break; |
| 765 | case MODE_ERROR_BVI_DEF: |
| 766 | rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI; |
| 767 | break; |
| 768 | } |
| 769 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 770 | BAD_RX_SW_IF_INDEX_LABEL; |
| 771 | BAD_TX_SW_IF_INDEX_LABEL; |
| 772 | |
| 773 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY); |
| 774 | } |
| 775 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 776 | static int |
| 777 | l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l) |
| 778 | { |
| 779 | v = clib_net_to_host_u32 (v); |
| 780 | |
| 781 | switch (v) |
| 782 | { |
| 783 | case L2_API_PORT_TYPE_NORMAL: |
| 784 | *l = L2_BD_PORT_TYPE_NORMAL; |
| 785 | return 0; |
| 786 | case L2_API_PORT_TYPE_BVI: |
| 787 | *l = L2_BD_PORT_TYPE_BVI; |
| 788 | return 0; |
| 789 | case L2_API_PORT_TYPE_UU_FWD: |
| 790 | *l = L2_BD_PORT_TYPE_UU_FWD; |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | return (VNET_API_ERROR_INVALID_VALUE); |
| 795 | } |
| 796 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 797 | static void |
| 798 | vl_api_sw_interface_set_l2_bridge_t_handler |
| 799 | (vl_api_sw_interface_set_l2_bridge_t * mp) |
| 800 | { |
| 801 | bd_main_t *bdm = &bd_main; |
| 802 | vl_api_sw_interface_set_l2_bridge_reply_t *rmp; |
| 803 | int rv = 0; |
| 804 | vlib_main_t *vm = vlib_get_main (); |
| 805 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 806 | l2_bd_port_type_t pt; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 807 | |
| 808 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 809 | u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 810 | rv = l2_bd_port_type_decode (mp->port_type, &pt); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 811 | |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 812 | if (0 != rv) |
| 813 | goto out; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 814 | if (mp->enable) |
| 815 | { |
| 816 | VALIDATE_BD_ID (mp); |
| 817 | u32 bd_id = ntohl (mp->bd_id); |
| 818 | u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id); |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 819 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 820 | rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 821 | rx_sw_if_index, bd_index, pt, mp->shg, 0); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 822 | } |
| 823 | else |
| 824 | { |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 825 | 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] | 826 | } |
| 827 | |
Alexander Chernavin | e178b27 | 2018-09-24 05:42:01 -0400 | [diff] [blame] | 828 | switch (rv) |
| 829 | { |
| 830 | case MODE_ERROR_ETH: |
| 831 | rv = VNET_API_ERROR_NON_ETHERNET; |
| 832 | break; |
| 833 | case MODE_ERROR_BVI_DEF: |
| 834 | rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI; |
| 835 | break; |
| 836 | } |
| 837 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 838 | BAD_RX_SW_IF_INDEX_LABEL; |
| 839 | BAD_BD_ID_LABEL; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 840 | out: |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 841 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY); |
| 842 | } |
| 843 | |
| 844 | static void |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 845 | send_bd_ip_mac_entry (vpe_api_main_t * am, |
| 846 | vl_api_registration_t * reg, |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 847 | u32 bd_id, |
| 848 | const ip46_address_t * ip, |
| 849 | ip46_type_t itype, |
| 850 | const mac_address_t * mac, u32 context) |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 851 | { |
| 852 | vl_api_bd_ip_mac_details_t *mp; |
| 853 | |
| 854 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 855 | clib_memset (mp, 0, sizeof (*mp)); |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 856 | mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS); |
| 857 | |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 858 | mp->context = context; |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 859 | mp->entry.bd_id = ntohl (bd_id); |
| 860 | |
| 861 | ip_address_encode (ip, itype, &mp->entry.ip); |
| 862 | mac_address_encode (mac, mp->entry.mac); |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 863 | |
| 864 | vl_api_send_msg (reg, (u8 *) mp); |
| 865 | } |
| 866 | |
| 867 | static void |
| 868 | vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp) |
| 869 | { |
| 870 | vpe_api_main_t *am = &vpe_api_main; |
| 871 | bd_main_t *bdm = &bd_main; |
| 872 | l2_bridge_domain_t *bd_config; |
| 873 | u32 bd_id = ntohl (mp->bd_id); |
Mohsin Kazmi | b24dfec | 2018-08-23 12:24:19 +0200 | [diff] [blame] | 874 | u32 bd_index, start, end; |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 875 | vl_api_registration_t *reg; |
| 876 | uword *p; |
| 877 | |
| 878 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 879 | if (!reg) |
| 880 | return; |
| 881 | |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 882 | /* see bd_id: ~0 means "any" */ |
| 883 | if (bd_id == ~0) |
Mohsin Kazmi | b24dfec | 2018-08-23 12:24:19 +0200 | [diff] [blame] | 884 | { |
| 885 | start = 1; |
| 886 | end = vec_len (l2input_main.bd_configs); |
| 887 | } |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 888 | else |
| 889 | { |
| 890 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 891 | if (p == 0) |
| 892 | return; |
| 893 | |
| 894 | bd_index = p[0]; |
| 895 | vec_validate (l2input_main.bd_configs, bd_index); |
| 896 | start = bd_index; |
| 897 | end = start + 1; |
| 898 | } |
| 899 | |
| 900 | for (bd_index = start; bd_index < end; bd_index++) |
| 901 | { |
| 902 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 903 | if (bd_is_valid (bd_config)) |
| 904 | { |
| 905 | ip4_address_t ip4_addr; |
| 906 | ip6_address_t *ip6_addr; |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 907 | mac_address_t mac; |
| 908 | u64 mac64; |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 909 | bd_id = bd_config->bd_id; |
| 910 | |
| 911 | /* *INDENT-OFF* */ |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 912 | hash_foreach (ip4_addr.as_u32, mac64, bd_config->mac_by_ip4, |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 913 | ({ |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 914 | ip46_address_t ip = { |
| 915 | .ip4 = ip4_addr, |
| 916 | }; |
| 917 | mac_address_from_u64(&mac, mac64); |
| 918 | |
| 919 | send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP4, |
| 920 | &mac, mp->context); |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 921 | })); |
| 922 | |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 923 | hash_foreach_mem (ip6_addr, mac64, bd_config->mac_by_ip6, |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 924 | ({ |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 925 | ip46_address_t ip = { |
| 926 | .ip6 = *ip6_addr, |
| 927 | }; |
| 928 | mac_address_from_u64(&mac, mac64); |
| 929 | |
| 930 | send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP6, |
| 931 | &mac, mp->context); |
Mohsin Kazmi | 5d82d2f | 2018-08-13 19:17:54 +0200 | [diff] [blame] | 932 | })); |
| 933 | /* *INDENT-ON* */ |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | static void |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 939 | vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp) |
| 940 | { |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 941 | ip46_address_t ip_addr = ip46_address_initializer; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 942 | vl_api_bd_ip_mac_add_del_reply_t *rmp; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 943 | bd_main_t *bdm = &bd_main; |
| 944 | u32 bd_index, bd_id; |
| 945 | mac_address_t mac; |
| 946 | ip46_type_t type; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 947 | int rv = 0; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 948 | uword *p; |
| 949 | |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 950 | bd_id = ntohl (mp->entry.bd_id); |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 951 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 952 | if (bd_id == 0) |
| 953 | { |
| 954 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 955 | goto out; |
| 956 | } |
| 957 | |
| 958 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 959 | if (p == 0) |
| 960 | { |
| 961 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 962 | goto out; |
| 963 | } |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 964 | bd_index = p[0]; |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 965 | |
Neale Ranns | bc764c8 | 2019-06-19 07:07:13 -0700 | [diff] [blame] | 966 | type = ip_address_decode (&mp->entry.ip, &ip_addr); |
| 967 | mac_address_decode (mp->entry.mac, &mac); |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 968 | |
| 969 | 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] | 970 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 971 | |
| 972 | out: |
| 973 | REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY); |
| 974 | } |
| 975 | |
John Lo | e26c81f | 2019-01-07 15:16:33 -0500 | [diff] [blame] | 976 | static void |
| 977 | vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp) |
| 978 | { |
| 979 | vl_api_bd_ip_mac_flush_reply_t *rmp; |
| 980 | bd_main_t *bdm = &bd_main; |
| 981 | u32 bd_index, bd_id; |
| 982 | int rv = 0; |
| 983 | uword *p; |
| 984 | |
| 985 | bd_id = ntohl (mp->bd_id); |
| 986 | |
| 987 | if (bd_id == 0) |
| 988 | { |
| 989 | rv = VNET_API_ERROR_BD_NOT_MODIFIABLE; |
| 990 | goto out; |
| 991 | } |
| 992 | |
| 993 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 994 | if (p == 0) |
| 995 | { |
| 996 | rv = VNET_API_ERROR_NO_SUCH_ENTRY; |
| 997 | goto out; |
| 998 | } |
| 999 | bd_index = p[0]; |
| 1000 | |
| 1001 | bd_flush_ip_mac (bd_index); |
| 1002 | |
| 1003 | out: |
| 1004 | REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY); |
| 1005 | } |
| 1006 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1007 | extern void l2_efp_filter_configure (vnet_main_t * vnet_main, |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 1008 | u32 sw_if_index, u8 enable); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1009 | |
| 1010 | static void |
| 1011 | vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t * |
| 1012 | mp) |
| 1013 | { |
| 1014 | int rv; |
| 1015 | vl_api_l2_interface_efp_filter_reply_t *rmp; |
| 1016 | vnet_main_t *vnm = vnet_get_main (); |
| 1017 | |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 1018 | VALIDATE_SW_IF_INDEX (mp); |
| 1019 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1020 | // enable/disable the feature |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 1021 | 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] | 1022 | rv = vnm->api_errno; |
| 1023 | |
Neale Ranns | 6b9b41c | 2018-07-23 05:47:09 -0400 | [diff] [blame] | 1024 | BAD_SW_IF_INDEX_LABEL; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1025 | REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY); |
| 1026 | } |
| 1027 | |
| 1028 | static void |
| 1029 | vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp) |
| 1030 | { |
| 1031 | extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index, |
| 1032 | int is_add); |
| 1033 | vl_api_l2_patch_add_del_reply_t *rmp; |
| 1034 | int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index, |
| 1035 | int is_add); |
| 1036 | int rv = 0; |
| 1037 | |
| 1038 | VALIDATE_RX_SW_IF_INDEX (mp); |
| 1039 | VALIDATE_TX_SW_IF_INDEX (mp); |
| 1040 | |
| 1041 | rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index), |
| 1042 | ntohl (mp->tx_sw_if_index), |
| 1043 | (int) (mp->is_add != 0)); |
| 1044 | |
| 1045 | BAD_RX_SW_IF_INDEX_LABEL; |
| 1046 | BAD_TX_SW_IF_INDEX_LABEL; |
| 1047 | |
| 1048 | REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY); |
| 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp) |
| 1053 | { |
| 1054 | vl_api_sw_interface_set_vpath_reply_t *rmp; |
| 1055 | int rv = 0; |
| 1056 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 1057 | |
| 1058 | VALIDATE_SW_IF_INDEX (mp); |
| 1059 | |
| 1060 | l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable); |
| 1061 | vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4", |
| 1062 | sw_if_index, mp->enable, 0, 0); |
| 1063 | vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4", |
| 1064 | sw_if_index, mp->enable, 0, 0); |
| 1065 | vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6", |
| 1066 | sw_if_index, mp->enable, 0, 0); |
| 1067 | vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6", |
| 1068 | sw_if_index, mp->enable, 0, 0); |
| 1069 | |
| 1070 | BAD_SW_IF_INDEX_LABEL; |
| 1071 | |
| 1072 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY); |
| 1073 | } |
| 1074 | |
Neale Ranns | 192b13f | 2019-03-15 02:16:20 -0700 | [diff] [blame] | 1075 | static void |
| 1076 | vl_api_bvi_create_t_handler (vl_api_bvi_create_t * mp) |
| 1077 | { |
| 1078 | vl_api_bvi_create_reply_t *rmp; |
| 1079 | mac_address_t mac; |
| 1080 | u32 sw_if_index; |
| 1081 | int rv; |
| 1082 | |
| 1083 | mac_address_decode (mp->mac, &mac); |
| 1084 | |
| 1085 | rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index); |
| 1086 | |
| 1087 | /* *INDENT-OFF* */ |
| 1088 | REPLY_MACRO2(VL_API_BVI_CREATE_REPLY, |
| 1089 | ({ |
| 1090 | rmp->sw_if_index = ntohl (sw_if_index); |
| 1091 | })); |
| 1092 | /* *INDENT-ON* */ |
| 1093 | } |
| 1094 | |
| 1095 | static void |
| 1096 | vl_api_bvi_delete_t_handler (vl_api_bvi_delete_t * mp) |
| 1097 | { |
| 1098 | vl_api_bvi_delete_reply_t *rmp; |
| 1099 | int rv; |
| 1100 | |
| 1101 | rv = l2_bvi_delete (ntohl (mp->sw_if_index)); |
| 1102 | |
| 1103 | REPLY_MACRO (VL_API_BVI_DELETE_REPLY); |
| 1104 | } |
| 1105 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1106 | static bool |
| 1107 | l2_arp_term_publish_event_is_equal (const l2_arp_term_publish_event_t * e1, |
| 1108 | const l2_arp_term_publish_event_t * e2) |
| 1109 | { |
| 1110 | if (e1 == NULL || e2 == NULL) |
| 1111 | return false; |
| 1112 | return (ip46_address_is_equal (&e1->ip, &e2->ip) && |
| 1113 | (e1->sw_if_index == e2->sw_if_index) && |
| 1114 | (mac_address_equal (&e1->mac, &e2->mac))); |
| 1115 | } |
| 1116 | |
| 1117 | static uword |
| 1118 | l2_arp_term_process (vlib_main_t * vm, vlib_node_runtime_t * rt, |
| 1119 | vlib_frame_t * f) |
| 1120 | { |
| 1121 | /* These cross the longjmp boundary (vlib_process_wait_for_event) |
| 1122 | * and need to be volatile - to prevent them from being optimized into |
| 1123 | * a register - which could change during suspension */ |
| 1124 | volatile f64 last = vlib_time_now (vm); |
| 1125 | volatile l2_arp_term_publish_event_t last_event = { }; |
| 1126 | |
| 1127 | l2_arp_term_main_t *l2am = &l2_arp_term_main; |
| 1128 | |
| 1129 | while (1) |
| 1130 | { |
| 1131 | uword event_type = L2_ARP_TERM_EVENT_PUBLISH; |
| 1132 | vpe_client_registration_t *reg; |
| 1133 | f64 now; |
| 1134 | |
| 1135 | vlib_process_wait_for_event (vm); |
| 1136 | |
| 1137 | vlib_process_get_event_data (vm, &event_type); |
| 1138 | now = vlib_time_now (vm); |
| 1139 | |
| 1140 | if (event_type == L2_ARP_TERM_EVENT_PUBLISH) |
| 1141 | { |
| 1142 | l2_arp_term_publish_event_t *event; |
| 1143 | |
| 1144 | vec_foreach (event, l2am->publish_events) |
| 1145 | { |
| 1146 | /* dampen duplicate events - cast away volatile */ |
| 1147 | if (l2_arp_term_publish_event_is_equal |
| 1148 | (event, (l2_arp_term_publish_event_t *) & last_event) && |
| 1149 | (now - last) < 10.0) |
| 1150 | { |
| 1151 | continue; |
| 1152 | } |
| 1153 | last_event = *event; |
| 1154 | last = now; |
| 1155 | |
| 1156 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1157 | pool_foreach (reg, vpe_api_main.l2_arp_term_events_registrations) |
| 1158 | { |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1159 | vl_api_registration_t *vl_reg; |
| 1160 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
Dave Barach | ffd1546 | 2020-02-18 10:12:23 -0500 | [diff] [blame] | 1161 | ALWAYS_ASSERT (vl_reg != NULL); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1162 | |
| 1163 | if (reg && vl_api_can_send_msg (vl_reg)) |
| 1164 | { |
| 1165 | vl_api_l2_arp_term_event_t * vevent; |
| 1166 | vevent = vl_msg_api_alloc (sizeof *vevent); |
| 1167 | clib_memset (vevent, 0, sizeof *vevent); |
| 1168 | vevent->_vl_msg_id = htons (VL_API_L2_ARP_TERM_EVENT); |
| 1169 | vevent->client_index = reg->client_index; |
| 1170 | vevent->pid = reg->client_pid; |
| 1171 | ip_address_encode(&event->ip, |
| 1172 | event->type, |
| 1173 | &vevent->ip); |
| 1174 | vevent->sw_if_index = htonl(event->sw_if_index); |
| 1175 | mac_address_encode(&event->mac, vevent->mac); |
| 1176 | vl_api_send_msg (vl_reg, (u8 *) vevent); |
| 1177 | } |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1178 | } |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 1179 | /* *INDENT-ON* */ |
| 1180 | } |
| 1181 | vec_reset_length (l2am->publish_events); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
| 1188 | /* *INDENT-OFF* */ |
| 1189 | VLIB_REGISTER_NODE (l2_arp_term_process_node) = { |
| 1190 | .function = l2_arp_term_process, |
| 1191 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1192 | .name = "l2-arp-term-publisher", |
| 1193 | }; |
| 1194 | /* *INDENT-ON* */ |
| 1195 | |
| 1196 | static void |
| 1197 | vl_api_want_l2_arp_term_events_t_handler (vl_api_want_l2_arp_term_events_t * |
| 1198 | mp) |
| 1199 | { |
| 1200 | vl_api_want_l2_arp_term_events_reply_t *rmp; |
| 1201 | vpe_api_main_t *am = &vpe_api_main; |
| 1202 | vpe_client_registration_t *rp; |
| 1203 | int rv = 0; |
| 1204 | uword *p; |
| 1205 | |
| 1206 | p = hash_get (am->l2_arp_term_events_registration_hash, mp->client_index); |
| 1207 | |
| 1208 | if (p) |
| 1209 | { |
| 1210 | if (mp->enable) |
| 1211 | { |
| 1212 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 1213 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 1214 | goto reply; |
| 1215 | } |
| 1216 | else |
| 1217 | { |
| 1218 | rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]); |
| 1219 | pool_put (am->l2_arp_term_events_registrations, rp); |
| 1220 | hash_unset (am->l2_arp_term_events_registration_hash, |
| 1221 | mp->client_index); |
| 1222 | if (pool_elts (am->l2_arp_term_events_registrations) == 0) |
| 1223 | l2_arp_term_set_publisher_node (false); |
| 1224 | goto reply; |
| 1225 | } |
| 1226 | } |
| 1227 | if (mp->enable == 0) |
| 1228 | { |
| 1229 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 1230 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 1231 | goto reply; |
| 1232 | } |
| 1233 | pool_get (am->l2_arp_term_events_registrations, rp); |
| 1234 | rp->client_index = mp->client_index; |
| 1235 | rp->client_pid = mp->pid; |
| 1236 | hash_set (am->l2_arp_term_events_registration_hash, rp->client_index, |
| 1237 | rp - am->l2_arp_term_events_registrations); |
| 1238 | l2_arp_term_set_publisher_node (true); |
| 1239 | |
| 1240 | reply: |
| 1241 | REPLY_MACRO (VL_API_WANT_L2_ARP_TERM_EVENTS_REPLY); |
| 1242 | } |
| 1243 | |
| 1244 | static clib_error_t * |
| 1245 | want_l2_arp_term_events_reaper (u32 client_index) |
| 1246 | { |
| 1247 | vpe_client_registration_t *rp; |
| 1248 | vpe_api_main_t *am; |
| 1249 | uword *p; |
| 1250 | |
| 1251 | am = &vpe_api_main; |
| 1252 | |
| 1253 | /* remove from the registration hash */ |
| 1254 | p = hash_get (am->l2_arp_term_events_registration_hash, client_index); |
| 1255 | |
| 1256 | if (p) |
| 1257 | { |
| 1258 | rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]); |
| 1259 | pool_put (am->l2_arp_term_events_registrations, rp); |
| 1260 | hash_unset (am->l2_arp_term_events_registration_hash, client_index); |
| 1261 | if (pool_elts (am->l2_arp_term_events_registrations) == 0) |
| 1262 | l2_arp_term_set_publisher_node (false); |
| 1263 | } |
| 1264 | return (NULL); |
| 1265 | } |
| 1266 | |
| 1267 | VL_MSG_API_REAPER_FUNCTION (want_l2_arp_term_events_reaper); |
| 1268 | |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1269 | /* |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 1270 | * l2_api_hookup |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1271 | * Add vpe's API message handlers to the table. |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 1272 | * vlib has already mapped shared memory and |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1273 | * added the client registration handlers. |
| 1274 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 1275 | */ |
| 1276 | #define vl_msg_name_crc_list |
| 1277 | #include <vnet/vnet_all_api_h.h> |
| 1278 | #undef vl_msg_name_crc_list |
| 1279 | |
| 1280 | static void |
| 1281 | setup_message_id_table (api_main_t * am) |
| 1282 | { |
| 1283 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1284 | foreach_vl_msg_name_crc_l2; |
| 1285 | #undef _ |
| 1286 | } |
| 1287 | |
| 1288 | static clib_error_t * |
| 1289 | l2_api_hookup (vlib_main_t * vm) |
| 1290 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1291 | api_main_t *am = vlibapi_get_main (); |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1292 | |
| 1293 | #define _(N,n) \ |
| 1294 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1295 | vl_api_##n##_t_handler, \ |
| 1296 | vl_noop_handler, \ |
| 1297 | vl_api_##n##_t_endian, \ |
| 1298 | vl_api_##n##_t_print, \ |
| 1299 | sizeof(vl_api_##n##_t), 1); |
| 1300 | foreach_vpe_api_msg; |
| 1301 | #undef _ |
| 1302 | |
Steven Luong | c5fa2b8 | 2019-04-25 11:19:49 -0700 | [diff] [blame] | 1303 | /* Mark VL_API_BRIDGE_DOMAIN_DUMP as mp safe */ |
| 1304 | am->is_mp_safe[VL_API_BRIDGE_DOMAIN_DUMP] = 1; |
| 1305 | |
Matus Fabian | f468e23 | 2016-12-02 06:00:53 -0800 | [diff] [blame] | 1306 | /* |
| 1307 | * Set up the (msg_name, crc, message-id) table |
| 1308 | */ |
| 1309 | setup_message_id_table (am); |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
| 1314 | VLIB_API_INIT_FUNCTION (l2_api_hookup); |
| 1315 | |
| 1316 | /* |
| 1317 | * fd.io coding-style-patch-verification: ON |
| 1318 | * |
| 1319 | * Local Variables: |
| 1320 | * eval: (c-set-style "gnu") |
| 1321 | * End: |
| 1322 | */ |