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