Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * tap_api.c - vnet tap device driver API support |
| 4 | * |
| 5 | * Copyright (c) 2017 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/ethernet/ethernet.h> |
| 26 | #include <vnet/ip/ip.h> |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 27 | #include <vnet/ethernet/ethernet_types_api.h> |
| 28 | #include <vnet/ip/ip_types_api.h> |
Damjan Marion | c99b4cd | 2017-12-04 15:25:58 +0100 | [diff] [blame] | 29 | #include <vnet/devices/tap/tap.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 30 | |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 31 | #include <vnet/format_fns.h> |
| 32 | #include <vnet/devices/tap/tapv2.api_enum.h> |
| 33 | #include <vnet/devices/tap/tapv2.api_types.h> |
| 34 | |
Mohsin Kazmi | b21fd4b | 2021-09-22 20:03:28 +0000 | [diff] [blame] | 35 | #define REPLY_MSG_ID_BASE tap_main.msg_id_base |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 36 | #include <vlibapi/api_helper_macros.h> |
| 37 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 38 | static void |
| 39 | vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp) |
| 40 | { |
Paul Vinciguerra | 44d0691 | 2019-10-30 01:53:25 +0000 | [diff] [blame] | 41 | vl_api_registration_t *reg; |
| 42 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 43 | if (!reg) |
| 44 | return; |
| 45 | |
Jerome Tollet | 0b06111 | 2018-06-04 16:40:26 +0100 | [diff] [blame] | 46 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 47 | vlib_main_t *vm = vlib_get_main (); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 48 | vl_api_tap_create_v2_reply_t *rmp; |
Paul Vinciguerra | 44d0691 | 2019-10-30 01:53:25 +0000 | [diff] [blame] | 49 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 50 | tap_create_if_args_t _a, *ap = &_a; |
| 51 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 52 | clib_memset (ap, 0, sizeof (*ap)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 53 | |
Steven | 9e63569 | 2018-03-01 09:36:01 -0800 | [diff] [blame] | 54 | ap->id = ntohl (mp->id); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 55 | if (!mp->use_random_mac) |
| 56 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 57 | mac_address_decode (mp->mac_address, &ap->mac_addr); |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 58 | ap->mac_addr_set = 1; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 59 | } |
Milan Lenco | 2aef64f | 2017-12-05 12:18:15 +0100 | [diff] [blame] | 60 | ap->rx_ring_sz = ntohs (mp->rx_ring_sz); |
| 61 | ap->tx_ring_sz = ntohs (mp->tx_ring_sz); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 62 | ap->sw_if_index = (u32) ~ 0; |
Mohsin Kazmi | 9f32b6a | 2020-02-14 12:09:04 +0000 | [diff] [blame] | 63 | ap->num_rx_queues = 1; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 64 | |
Mohsin Kazmi | 9f32b6a | 2020-02-14 12:09:04 +0000 | [diff] [blame] | 65 | if (mp->num_rx_queues > 1) |
| 66 | ap->num_rx_queues = mp->num_rx_queues; |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 67 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 68 | if (mp->host_if_name_set) |
Mohsin Kazmi | 784bbcc | 2020-10-21 18:32:59 +0200 | [diff] [blame] | 69 | ap->host_if_name = format (0, "%s%c", mp->host_if_name, 0); |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 70 | |
| 71 | if (mp->host_mac_addr_set) |
| 72 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 73 | mac_address_decode (mp->host_mac_addr, &ap->host_mac_addr); |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 76 | if (mp->host_namespace_set) |
Mohsin Kazmi | 784bbcc | 2020-10-21 18:32:59 +0200 | [diff] [blame] | 77 | ap->host_namespace = format (0, "%s%c", mp->host_namespace, 0); |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 78 | |
| 79 | if (mp->host_bridge_set) |
Mohsin Kazmi | 784bbcc | 2020-10-21 18:32:59 +0200 | [diff] [blame] | 80 | ap->host_bridge = format (0, "%s%c", mp->host_bridge, 0); |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 81 | |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 82 | if (mp->host_ip4_prefix_set) |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 83 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 84 | ip4_address_decode (mp->host_ip4_prefix.address, &ap->host_ip4_addr); |
| 85 | ap->host_ip4_prefix_len = mp->host_ip4_prefix.len; |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 88 | if (mp->host_ip6_prefix_set) |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 89 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 90 | ip6_address_decode (mp->host_ip6_prefix.address, &ap->host_ip6_addr); |
| 91 | ap->host_ip6_prefix_len = mp->host_ip6_prefix.len; |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Damjan Marion | 7866c45 | 2018-01-18 13:35:11 +0100 | [diff] [blame] | 94 | if (mp->host_ip4_gw_set) |
| 95 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 96 | ip4_address_decode (mp->host_ip4_gw, &ap->host_ip4_gw); |
Damjan Marion | 7866c45 | 2018-01-18 13:35:11 +0100 | [diff] [blame] | 97 | ap->host_ip4_gw_set = 1; |
| 98 | } |
| 99 | |
| 100 | if (mp->host_ip6_gw_set) |
| 101 | { |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 102 | ip6_address_decode (mp->host_ip6_gw, &ap->host_ip6_gw); |
Damjan Marion | 7866c45 | 2018-01-18 13:35:11 +0100 | [diff] [blame] | 103 | ap->host_ip6_gw_set = 1; |
| 104 | } |
| 105 | |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 106 | if (mp->host_mtu_set) |
| 107 | { |
| 108 | ap->host_mtu_size = ntohl (mp->host_mtu_size); |
| 109 | ap->host_mtu_set = 1; |
| 110 | } |
| 111 | |
Mohsin Kazmi | a1a2246 | 2020-09-02 11:59:37 +0000 | [diff] [blame] | 112 | STATIC_ASSERT (((int) TAP_API_FLAG_GSO == (int) TAP_FLAG_GSO), |
| 113 | "tap gso api flag mismatch"); |
| 114 | STATIC_ASSERT (((int) TAP_API_FLAG_CSUM_OFFLOAD == |
| 115 | (int) TAP_FLAG_CSUM_OFFLOAD), |
| 116 | "tap checksum offload api flag mismatch"); |
| 117 | STATIC_ASSERT (((int) TAP_API_FLAG_PERSIST == (int) TAP_FLAG_PERSIST), |
| 118 | "tap persist api flag mismatch"); |
| 119 | STATIC_ASSERT (((int) TAP_API_FLAG_ATTACH == (int) TAP_FLAG_ATTACH), |
| 120 | "tap attach api flag mismatch"); |
| 121 | STATIC_ASSERT (((int) TAP_API_FLAG_TUN == (int) TAP_FLAG_TUN), |
| 122 | "tap tun api flag mismatch"); |
| 123 | STATIC_ASSERT (((int) TAP_API_FLAG_GRO_COALESCE == |
| 124 | (int) TAP_FLAG_GRO_COALESCE), |
| 125 | "tap gro coalesce api flag mismatch"); |
| 126 | STATIC_ASSERT (((int) TAP_API_FLAG_PACKED == (int) TAP_FLAG_PACKED), |
| 127 | "tap packed api flag mismatch"); |
| 128 | STATIC_ASSERT (((int) TAP_API_FLAG_IN_ORDER == |
| 129 | (int) TAP_FLAG_IN_ORDER), "tap in-order api flag mismatch"); |
| 130 | |
Andrew Yourtchenko | 754f24b | 2019-01-07 20:56:46 +0100 | [diff] [blame] | 131 | ap->tap_flags = ntohl (mp->tap_flags); |
| 132 | |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 133 | tap_create_if (vm, ap); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 134 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 135 | |
Jerome Tollet | 0b06111 | 2018-06-04 16:40:26 +0100 | [diff] [blame] | 136 | /* If a tag was supplied... */ |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 137 | if (vl_api_string_len (&mp->tag)) |
Jerome Tollet | 0b06111 | 2018-06-04 16:40:26 +0100 | [diff] [blame] | 138 | { |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 139 | u8 *tag = vl_api_from_api_to_new_vec (mp, &mp->tag); |
Jerome Tollet | 0b06111 | 2018-06-04 16:40:26 +0100 | [diff] [blame] | 140 | vnet_set_sw_interface_tag (vnm, tag, ap->sw_if_index); |
| 141 | } |
| 142 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 143 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 144 | rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_TAP_CREATE_V2_REPLY); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 145 | rmp->context = mp->context; |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 146 | rmp->retval = ntohl (ap->rv); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 147 | rmp->sw_if_index = ntohl (ap->sw_if_index); |
| 148 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 149 | vl_api_send_msg (reg, (u8 *) rmp); |
Mohsin Kazmi | 784bbcc | 2020-10-21 18:32:59 +0200 | [diff] [blame] | 150 | |
| 151 | vec_free (ap->host_if_name); |
| 152 | vec_free (ap->host_namespace); |
| 153 | vec_free (ap->host_bridge); |
| 154 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 158 | vl_api_tap_delete_v2_t_handler (vl_api_tap_delete_v2_t * mp) |
| 159 | { |
Paul Vinciguerra | 44d0691 | 2019-10-30 01:53:25 +0000 | [diff] [blame] | 160 | vl_api_registration_t *reg; |
| 161 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 162 | if (!reg) |
| 163 | return; |
| 164 | |
Jerome Tollet | 0b06111 | 2018-06-04 16:40:26 +0100 | [diff] [blame] | 165 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 166 | vlib_main_t *vm = vlib_get_main (); |
| 167 | int rv; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 168 | vl_api_tap_delete_v2_reply_t *rmp; |
Paul Vinciguerra | 44d0691 | 2019-10-30 01:53:25 +0000 | [diff] [blame] | 169 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 170 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 171 | |
| 172 | rv = tap_delete_if (vm, sw_if_index); |
| 173 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 174 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 175 | rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_TAP_DELETE_V2_REPLY); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 176 | rmp->context = mp->context; |
| 177 | rmp->retval = ntohl (rv); |
| 178 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 179 | vl_api_send_msg (reg, (u8 *) rmp); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 180 | |
| 181 | if (!rv) |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 182 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static void |
| 186 | tap_send_sw_interface_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 187 | vl_api_registration_t * reg, |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 188 | tap_interface_details_t * tap_if, u32 context) |
| 189 | { |
| 190 | vl_api_sw_interface_tap_v2_details_t *mp; |
| 191 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 192 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 193 | mp->_vl_msg_id = |
| 194 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_TAP_V2_DETAILS); |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 195 | mp->id = htonl (tap_if->id); |
| 196 | mp->sw_if_index = htonl (tap_if->sw_if_index); |
Andrew Yourtchenko | 754f24b | 2019-01-07 20:56:46 +0100 | [diff] [blame] | 197 | mp->tap_flags = htonl (tap_if->tap_flags); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 198 | clib_memcpy (mp->dev_name, tap_if->dev_name, |
| 199 | MIN (ARRAY_LEN (mp->dev_name) - 1, |
| 200 | strlen ((const char *) tap_if->dev_name))); |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 201 | mp->rx_ring_sz = htons (tap_if->rx_ring_sz); |
| 202 | mp->tx_ring_sz = htons (tap_if->tx_ring_sz); |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 203 | mac_address_encode (&tap_if->host_mac_addr, mp->host_mac_addr); |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 204 | clib_memcpy (mp->host_if_name, tap_if->host_if_name, |
| 205 | MIN (ARRAY_LEN (mp->host_if_name) - 1, |
| 206 | strlen ((const char *) tap_if->host_if_name))); |
| 207 | clib_memcpy (mp->host_namespace, tap_if->host_namespace, |
| 208 | MIN (ARRAY_LEN (mp->host_namespace) - 1, |
| 209 | strlen ((const char *) tap_if->host_namespace))); |
| 210 | clib_memcpy (mp->host_bridge, tap_if->host_bridge, |
| 211 | MIN (ARRAY_LEN (mp->host_bridge) - 1, |
| 212 | strlen ((const char *) tap_if->host_bridge))); |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 213 | mp->host_mtu_size = htonl (tap_if->host_mtu_size); |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 214 | mac_address_encode (&tap_if->host_mac_addr, mp->host_mac_addr); |
| 215 | |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 216 | if (tap_if->host_ip4_prefix_len) |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 217 | ip4_address_encode (&tap_if->host_ip4_addr, mp->host_ip4_prefix.address); |
| 218 | mp->host_ip4_prefix.len = tap_if->host_ip4_prefix_len; |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 219 | if (tap_if->host_ip6_prefix_len) |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 220 | ip6_address_encode (&tap_if->host_ip6_addr, mp->host_ip6_prefix.address); |
| 221 | mp->host_ip6_prefix.len = tap_if->host_ip6_prefix_len; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 222 | |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 223 | mp->context = context; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 224 | vl_api_send_msg (reg, (u8 *) mp); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | static void |
| 228 | vl_api_sw_interface_tap_v2_dump_t_handler (vl_api_sw_interface_tap_v2_dump_t * |
| 229 | mp) |
| 230 | { |
| 231 | int rv; |
| 232 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 233 | vl_api_registration_t *reg; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 234 | tap_interface_details_t *tapifs = NULL; |
| 235 | tap_interface_details_t *tap_if = NULL; |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 236 | u32 filter_sw_if_index; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 237 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 238 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 239 | if (!reg) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 240 | return; |
| 241 | |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 242 | filter_sw_if_index = htonl (mp->sw_if_index); |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 243 | if (mp->sw_if_index != ~0) |
| 244 | VALIDATE_SW_IF_INDEX (mp); |
Jakub Grajciar | 5de4fb7 | 2019-09-03 10:40:01 +0200 | [diff] [blame] | 245 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 246 | rv = tap_dump_ifs (&tapifs); |
| 247 | if (rv) |
| 248 | return; |
| 249 | |
| 250 | vec_foreach (tap_if, tapifs) |
| 251 | { |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 252 | if ((filter_sw_if_index == ~0) |
| 253 | || (tap_if->sw_if_index == filter_sw_if_index)) |
| 254 | tap_send_sw_interface_details (am, reg, tap_if, mp->context); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 255 | } |
Paul Vinciguerra | 073d74d | 2020-04-27 01:12:48 -0400 | [diff] [blame] | 256 | BAD_SW_IF_INDEX_LABEL; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 257 | vec_free (tapifs); |
| 258 | } |
| 259 | |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 260 | #include <vnet/devices/tap/tapv2.api.c> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 261 | static clib_error_t * |
| 262 | tapv2_api_hookup (vlib_main_t * vm) |
| 263 | { |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 264 | /* |
| 265 | * Set up the (msg_name, crc, message-id) table |
| 266 | */ |
Filip Tehlar | 3808ec0 | 2021-06-22 12:03:55 +0000 | [diff] [blame] | 267 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | VLIB_API_INIT_FUNCTION (tapv2_api_hookup); |
| 273 | |
| 274 | /* |
| 275 | * fd.io coding-style-patch-verification: ON |
| 276 | * |
| 277 | * Local Variables: |
| 278 | * eval: (c-set-style "gnu") |
| 279 | * End: |
| 280 | */ |