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