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