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