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