Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 18 | #define _GNU_SOURCE |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <net/if.h> |
| 23 | #include <linux/if_tun.h> |
| 24 | #include <sys/ioctl.h> |
| 25 | #include <linux/virtio_net.h> |
| 26 | #include <linux/vhost.h> |
| 27 | #include <sys/eventfd.h> |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 28 | #include <sched.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 29 | |
| 30 | #include <linux/netlink.h> |
| 31 | #include <linux/rtnetlink.h> |
| 32 | |
| 33 | #include <vlib/vlib.h> |
| 34 | #include <vlib/unix/unix.h> |
| 35 | #include <vnet/ethernet/ethernet.h> |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 36 | #include <vnet/ip/ip4_packet.h> |
| 37 | #include <vnet/ip/ip6_packet.h> |
Damjan Marion | 17fdae7 | 2017-11-30 20:56:37 +0100 | [diff] [blame] | 38 | #include <vnet/devices/netlink.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 39 | #include <vnet/devices/virtio/virtio.h> |
Damjan Marion | c99b4cd | 2017-12-04 15:25:58 +0100 | [diff] [blame] | 40 | #include <vnet/devices/tap/tap.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 41 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 42 | tap_main_t tap_main; |
| 43 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 44 | #define _IOCTL(fd,a,...) \ |
| 45 | if (ioctl (fd, a, __VA_ARGS__) < 0) \ |
| 46 | { \ |
| 47 | err = clib_error_return_unix (0, "ioctl(" #a ")"); \ |
| 48 | goto error; \ |
| 49 | } |
| 50 | |
| 51 | static u32 |
| 52 | virtio_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, |
| 53 | u32 flags) |
| 54 | { |
| 55 | /* nothing for now */ |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 56 | //TODO On MTU change call vnet_netlink_set_if_mtu |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
Mohsin Kazmi | e4ac48e | 2019-04-17 12:06:57 +0200 | [diff] [blame] | 60 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
| 61 | |
| 62 | static clib_error_t * |
| 63 | call_tap_read_ready (clib_file_t * uf) |
| 64 | { |
| 65 | /* nothing to do */ |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | tap_delete_if_cp (u32 * sw_if_index) |
| 71 | { |
| 72 | vlib_main_t *vm = vlib_get_main (); |
| 73 | tap_delete_if (vm, *sw_if_index); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Tap clean-up routine: |
| 78 | * Linux side of tap interface can be deleted i.e. tap is |
| 79 | * attached to container and if someone will delete this |
| 80 | * container, will also removes tap interface. While VPP |
| 81 | * will have other side of tap. This function will RPC |
| 82 | * main thread to call the tap_delete_if to cleanup tap. |
| 83 | */ |
| 84 | static clib_error_t * |
| 85 | call_tap_error_ready (clib_file_t * uf) |
| 86 | { |
| 87 | vl_api_rpc_call_main_thread (tap_delete_if_cp, (u8 *) & uf->private_data, |
| 88 | sizeof (uf->private_data)); |
| 89 | return 0; |
| 90 | } |
| 91 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 92 | static int |
| 93 | open_netns_fd (char *netns) |
| 94 | { |
| 95 | u8 *s = 0; |
| 96 | int fd; |
| 97 | |
| 98 | if (strncmp (netns, "pid:", 4) == 0) |
| 99 | s = format (0, "/proc/%u/ns/net%c", atoi (netns + 4), 0); |
| 100 | else if (netns[0] == '/') |
| 101 | s = format (0, "%s%c", netns, 0); |
| 102 | else |
| 103 | s = format (0, "/var/run/netns/%s%c", netns, 0); |
| 104 | |
| 105 | fd = open ((char *) s, O_RDONLY); |
| 106 | vec_free (s); |
| 107 | return fd; |
| 108 | } |
| 109 | |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 110 | #define TAP_MAX_INSTANCE 1024 |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 111 | |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 112 | void |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 113 | tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) |
| 114 | { |
| 115 | vnet_main_t *vnm = vnet_get_main (); |
| 116 | virtio_main_t *vim = &virtio_main; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 117 | tap_main_t *tm = &tap_main; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 118 | vnet_sw_interface_t *sw; |
| 119 | vnet_hw_interface_t *hw; |
Damjan Marion | 4e671d2 | 2017-12-09 21:19:01 +0100 | [diff] [blame] | 120 | int i; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 121 | int old_netns_fd = -1; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 122 | struct ifreq ifr; |
| 123 | size_t hdrsz; |
| 124 | struct vhost_memory *vhost_mem = 0; |
| 125 | virtio_if_t *vif = 0; |
Mohsin Kazmi | e4ac48e | 2019-04-17 12:06:57 +0200 | [diff] [blame] | 126 | clib_file_t t = { 0 }; |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 127 | clib_error_t *err = 0; |
Steven Luong | 4a310d2 | 2019-02-21 14:55:52 -0800 | [diff] [blame] | 128 | int fd = -1; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 129 | |
| 130 | if (args->id != ~0) |
| 131 | { |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 132 | if (clib_bitmap_get (tm->tap_ids, args->id)) |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 133 | { |
| 134 | args->rv = VNET_API_ERROR_INVALID_INTERFACE; |
| 135 | args->error = clib_error_return (0, "interface already exists"); |
| 136 | return; |
| 137 | } |
| 138 | } |
| 139 | else |
| 140 | { |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 141 | args->id = clib_bitmap_first_clear (tm->tap_ids); |
| 142 | } |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 143 | |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 144 | if (args->id > TAP_MAX_INSTANCE) |
| 145 | { |
| 146 | args->rv = VNET_API_ERROR_UNSPECIFIED; |
| 147 | args->error = clib_error_return (0, "cannot find free interface id"); |
| 148 | return; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 149 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 150 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 151 | clib_memset (&ifr, 0, sizeof (ifr)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 152 | pool_get (vim->interfaces, vif); |
| 153 | vif->dev_instance = vif - vim->interfaces; |
| 154 | vif->tap_fd = -1; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 155 | vif->id = args->id; |
| 156 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 157 | if ((vif->fd = open ("/dev/vhost-net", O_RDWR | O_NONBLOCK)) < 0) |
| 158 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 159 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_1; |
| 160 | args->error = clib_error_return_unix (0, "open '/dev/vhost-net'"); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 161 | goto error; |
| 162 | } |
| 163 | |
| 164 | _IOCTL (vif->fd, VHOST_GET_FEATURES, &vif->remote_features); |
| 165 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 166 | if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF)) == 0) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 167 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 168 | args->rv = VNET_API_ERROR_UNSUPPORTED; |
| 169 | args->error = clib_error_return (0, "vhost-net backend doesn't support " |
| 170 | "VIRTIO_NET_F_MRG_RXBUF feature"); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 171 | goto error; |
| 172 | } |
| 173 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 174 | if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC)) == |
| 175 | 0) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 176 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 177 | args->rv = VNET_API_ERROR_UNSUPPORTED; |
| 178 | args->error = clib_error_return (0, "vhost-net backend doesn't support " |
| 179 | "VIRTIO_RING_F_INDIRECT_DESC feature"); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 180 | goto error; |
| 181 | } |
| 182 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 183 | if ((vif->remote_features & VIRTIO_FEATURE (VIRTIO_F_VERSION_1)) == 0) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 184 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 185 | args->rv = VNET_API_ERROR_UNSUPPORTED; |
| 186 | args->error = clib_error_return (0, "vhost-net backend doesn't support " |
| 187 | "VIRTIO_F_VERSION_1 features"); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 188 | goto error; |
| 189 | } |
| 190 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 191 | vif->features |= VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF); |
| 192 | vif->features |= VIRTIO_FEATURE (VIRTIO_F_VERSION_1); |
| 193 | vif->features |= VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC); |
| 194 | |
| 195 | virtio_set_net_hdr_size (vif); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 196 | |
| 197 | _IOCTL (vif->fd, VHOST_SET_FEATURES, &vif->features); |
| 198 | |
| 199 | if ((vif->tap_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) |
| 200 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 201 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; |
| 202 | args->error = clib_error_return_unix (0, "open '/dev/net/tun'"); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 203 | goto error; |
| 204 | } |
| 205 | |
| 206 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 207 | _IOCTL (vif->tap_fd, TUNSETIFF, (void *) &ifr); |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 208 | vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 209 | |
Mohsin Kazmi | 2a6861f | 2019-04-15 13:17:55 +0200 | [diff] [blame] | 210 | if (!args->host_if_name) |
Benoît Ganne | c30d87e | 2019-07-15 17:16:49 +0200 | [diff] [blame] | 211 | args->host_if_name = (void *) ifr.ifr_ifrn.ifrn_name; |
Mohsin Kazmi | 2a6861f | 2019-04-15 13:17:55 +0200 | [diff] [blame] | 212 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 213 | unsigned int offload = 0; |
| 214 | hdrsz = sizeof (struct virtio_net_hdr_v1); |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 215 | if (args->tap_flags & TAP_FLAG_GSO) |
| 216 | { |
| 217 | offload = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6; |
| 218 | vif->gso_enabled = 1; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | vif->gso_enabled = 0; |
| 223 | } |
| 224 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 225 | _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload); |
| 226 | _IOCTL (vif->tap_fd, TUNSETVNETHDRSZ, &hdrsz); |
| 227 | _IOCTL (vif->fd, VHOST_SET_OWNER, 0); |
| 228 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 229 | /* if namespace is specified, all further netlink messages should be excuted |
| 230 | after we change our net namespace */ |
| 231 | if (args->host_namespace) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 232 | { |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 233 | old_netns_fd = open ("/proc/self/ns/net", O_RDONLY); |
| 234 | if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1) |
| 235 | { |
| 236 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; |
| 237 | args->error = clib_error_return_unix (0, "open_netns_fd '%s'", |
| 238 | args->host_namespace); |
| 239 | goto error; |
| 240 | } |
| 241 | args->error = vnet_netlink_set_link_netns (vif->ifindex, fd, |
| 242 | (char *) args->host_if_name); |
| 243 | if (args->error) |
| 244 | { |
| 245 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 246 | goto error; |
| 247 | } |
Steven Luong | 4a310d2 | 2019-02-21 14:55:52 -0800 | [diff] [blame] | 248 | if (setns (fd, CLONE_NEWNET) == -1) |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 249 | { |
| 250 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_3; |
| 251 | args->error = clib_error_return_unix (0, "setns '%s'", |
| 252 | args->host_namespace); |
| 253 | goto error; |
| 254 | } |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 255 | if ((vif->ifindex = if_nametoindex ((char *) args->host_if_name)) == 0) |
| 256 | { |
| 257 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_3; |
| 258 | args->error = clib_error_return_unix (0, "if_nametoindex '%s'", |
| 259 | args->host_if_name); |
| 260 | goto error; |
| 261 | } |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | if (args->host_if_name) |
| 266 | { |
| 267 | args->error = vnet_netlink_set_link_name (vif->ifindex, |
| 268 | (char *) |
| 269 | args->host_if_name); |
| 270 | if (args->error) |
| 271 | { |
| 272 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 273 | goto error; |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if (!ethernet_mac_address_is_zero (args->host_mac_addr)) |
| 279 | { |
| 280 | args->error = vnet_netlink_set_link_addr (vif->ifindex, |
| 281 | args->host_mac_addr); |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 282 | if (args->error) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 283 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 284 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 285 | goto error; |
| 286 | } |
| 287 | } |
| 288 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 289 | if (args->host_bridge) |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 290 | { |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 291 | args->error = vnet_netlink_set_link_master (vif->ifindex, |
| 292 | (char *) args->host_bridge); |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 293 | if (args->error) |
| 294 | { |
| 295 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 296 | goto error; |
| 297 | } |
| 298 | } |
| 299 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 300 | |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 301 | if (args->host_ip4_prefix_len) |
| 302 | { |
| 303 | args->error = vnet_netlink_add_ip4_addr (vif->ifindex, |
| 304 | &args->host_ip4_addr, |
| 305 | args->host_ip4_prefix_len); |
| 306 | if (args->error) |
| 307 | { |
| 308 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 309 | goto error; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | if (args->host_ip6_prefix_len) |
| 314 | { |
| 315 | args->error = vnet_netlink_add_ip6_addr (vif->ifindex, |
| 316 | &args->host_ip6_addr, |
| 317 | args->host_ip6_prefix_len); |
| 318 | if (args->error) |
| 319 | { |
| 320 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 321 | goto error; |
| 322 | } |
| 323 | } |
| 324 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 325 | args->error = vnet_netlink_set_link_state (vif->ifindex, 1 /* UP */ ); |
| 326 | if (args->error) |
| 327 | { |
| 328 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 329 | goto error; |
| 330 | } |
| 331 | |
Damjan Marion | 7866c45 | 2018-01-18 13:35:11 +0100 | [diff] [blame] | 332 | if (args->host_ip4_gw_set) |
| 333 | { |
| 334 | args->error = vnet_netlink_add_ip4_route (0, 0, &args->host_ip4_gw); |
| 335 | if (args->error) |
| 336 | { |
| 337 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 338 | goto error; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (args->host_ip6_gw_set) |
| 343 | { |
| 344 | args->error = vnet_netlink_add_ip6_route (0, 0, &args->host_ip6_gw); |
| 345 | if (args->error) |
| 346 | { |
| 347 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 348 | goto error; |
| 349 | } |
| 350 | } |
| 351 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 352 | /* switch back to old net namespace */ |
| 353 | if (args->host_namespace) |
| 354 | { |
| 355 | if (setns (old_netns_fd, CLONE_NEWNET) == -1) |
| 356 | { |
| 357 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_2; |
| 358 | args->error = clib_error_return_unix (0, "setns '%s'", |
| 359 | args->host_namespace); |
| 360 | goto error; |
| 361 | } |
| 362 | } |
| 363 | |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 364 | if (args->host_mtu_set) |
| 365 | { |
| 366 | args->error = |
| 367 | vnet_netlink_set_link_mtu (vif->ifindex, args->host_mtu_size); |
| 368 | if (args->error) |
| 369 | { |
| 370 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 371 | goto error; |
| 372 | } |
| 373 | } |
| 374 | else if (tm->host_mtu_size != 0) |
| 375 | { |
| 376 | args->error = |
| 377 | vnet_netlink_set_link_mtu (vif->ifindex, tm->host_mtu_size); |
| 378 | if (args->error) |
| 379 | { |
| 380 | args->rv = VNET_API_ERROR_NETLINK_ERROR; |
| 381 | goto error; |
| 382 | } |
| 383 | args->host_mtu_set = 1; |
| 384 | args->host_mtu_size = tm->host_mtu_size; |
| 385 | } |
| 386 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 387 | /* Set vhost memory table */ |
| 388 | i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region); |
| 389 | vhost_mem = clib_mem_alloc (i); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 390 | clib_memset (vhost_mem, 0, i); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 391 | vhost_mem->nregions = 1; |
| 392 | vhost_mem->regions[0].memory_size = (1ULL << 47) - 4096; |
| 393 | _IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem); |
| 394 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 395 | if ((args->error = |
| 396 | virtio_vring_init (vm, vif, RX_QUEUE (0), args->rx_ring_sz))) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 397 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 398 | args->rv = VNET_API_ERROR_INIT_FAILED; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 399 | goto error; |
| 400 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 401 | vif->num_rxqs = 1; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 402 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 403 | if ((args->error = |
| 404 | virtio_vring_init (vm, vif, TX_QUEUE (0), args->tx_ring_sz))) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 405 | { |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 406 | args->rv = VNET_API_ERROR_INIT_FAILED; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 407 | goto error; |
| 408 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 409 | vif->num_txqs = 1; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 410 | |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 411 | if (!args->mac_addr_set) |
Benoît Ganne | fe750c2 | 2019-03-25 11:41:34 +0100 | [diff] [blame] | 412 | ethernet_mac_address_generate (args->mac_addr); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 413 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 414 | clib_memcpy (vif->mac_addr, args->mac_addr, 6); |
| 415 | |
Benoît Ganne | c30d87e | 2019-07-15 17:16:49 +0200 | [diff] [blame] | 416 | vif->host_if_name = format (0, "%s%c", args->host_if_name, 0); |
| 417 | vif->net_ns = format (0, "%s%c", args->host_namespace, 0); |
| 418 | vif->host_bridge = format (0, "%s%c", args->host_bridge, 0); |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 419 | vif->host_mtu_size = args->host_mtu_size; |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 420 | clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6); |
| 421 | vif->host_ip4_prefix_len = args->host_ip4_prefix_len; |
| 422 | vif->host_ip6_prefix_len = args->host_ip6_prefix_len; |
| 423 | if (args->host_ip4_prefix_len) |
| 424 | clib_memcpy (&vif->host_ip4_addr, &args->host_ip4_addr, 4); |
| 425 | if (args->host_ip6_prefix_len) |
| 426 | clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16); |
| 427 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 428 | vif->type = VIRTIO_IF_TYPE_TAP; |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 429 | args->error = ethernet_register_interface (vnm, virtio_device_class.index, |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 430 | vif->dev_instance, |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 431 | vif->mac_addr, |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 432 | &vif->hw_if_index, |
| 433 | virtio_eth_flag_change); |
| 434 | if (args->error) |
| 435 | { |
| 436 | args->rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 437 | goto error; |
| 438 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 439 | |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 440 | tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 1); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 441 | sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index); |
| 442 | vif->sw_if_index = sw->sw_if_index; |
| 443 | args->sw_if_index = vif->sw_if_index; |
| 444 | hw = vnet_get_hw_interface (vnm, vif->hw_if_index); |
| 445 | hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE; |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 446 | if (args->tap_flags & TAP_FLAG_GSO) |
| 447 | { |
| 448 | hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO; |
| 449 | vnm->interface_main.gso_interface_count++; |
| 450 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 451 | vnet_hw_interface_set_input_node (vnm, vif->hw_if_index, |
| 452 | virtio_input_node.index); |
| 453 | vnet_hw_interface_assign_rx_thread (vnm, vif->hw_if_index, 0, ~0); |
| 454 | vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, 0, |
| 455 | VNET_HW_INTERFACE_RX_MODE_DEFAULT); |
| 456 | vif->per_interface_next_index = ~0; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 457 | virtio_vring_set_numa_node (vm, vif, RX_QUEUE (0)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 458 | vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP; |
| 459 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, |
| 460 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 461 | vif->cxq_vring = NULL; |
| 462 | |
Mohsin Kazmi | e4ac48e | 2019-04-17 12:06:57 +0200 | [diff] [blame] | 463 | t.read_function = call_tap_read_ready; |
| 464 | t.error_function = call_tap_error_ready; |
| 465 | t.file_descriptor = vif->tap_fd; |
| 466 | t.private_data = vif->sw_if_index; |
| 467 | t.description = format (0, "tap sw_if_index %u fd: %u", |
| 468 | vif->sw_if_index, vif->tap_fd); |
| 469 | vif->tap_file_index = clib_file_add (&file_main, &t); |
| 470 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 471 | goto done; |
| 472 | |
| 473 | error: |
Damjan Marion | 91c6ef7 | 2017-12-01 13:34:24 +0100 | [diff] [blame] | 474 | if (err) |
| 475 | { |
| 476 | ASSERT (args->error == 0); |
| 477 | args->error = err; |
| 478 | args->rv = VNET_API_ERROR_SYSCALL_ERROR_3; |
| 479 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 480 | if (vif->tap_fd != -1) |
| 481 | close (vif->tap_fd); |
| 482 | if (vif->fd != -1) |
| 483 | close (vif->fd); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 484 | vec_foreach_index (i, vif->rxq_vrings) virtio_vring_free_rx (vm, vif, |
| 485 | RX_QUEUE (i)); |
| 486 | vec_foreach_index (i, vif->txq_vrings) virtio_vring_free_tx (vm, vif, |
| 487 | TX_QUEUE (i)); |
| 488 | vec_free (vif->rxq_vrings); |
| 489 | vec_free (vif->txq_vrings); |
Benoît Ganne | c30d87e | 2019-07-15 17:16:49 +0200 | [diff] [blame] | 490 | |
| 491 | vec_free (vif->host_if_name); |
| 492 | vec_free (vif->net_ns); |
| 493 | vec_free (vif->host_bridge); |
| 494 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 495 | clib_memset (vif, 0, sizeof (virtio_if_t)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 496 | pool_put (vim->interfaces, vif); |
| 497 | |
| 498 | done: |
| 499 | if (vhost_mem) |
| 500 | clib_mem_free (vhost_mem); |
Damjan Marion | 4e671d2 | 2017-12-09 21:19:01 +0100 | [diff] [blame] | 501 | if (old_netns_fd != -1) |
| 502 | close (old_netns_fd); |
Steven Luong | 4a310d2 | 2019-02-21 14:55:52 -0800 | [diff] [blame] | 503 | if (fd != -1) |
| 504 | close (fd); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | int |
| 508 | tap_delete_if (vlib_main_t * vm, u32 sw_if_index) |
| 509 | { |
| 510 | vnet_main_t *vnm = vnet_get_main (); |
| 511 | virtio_main_t *mm = &virtio_main; |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 512 | tap_main_t *tm = &tap_main; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 513 | int i; |
| 514 | virtio_if_t *vif; |
| 515 | vnet_hw_interface_t *hw; |
| 516 | |
| 517 | hw = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 518 | if (hw == NULL || virtio_device_class.index != hw->dev_class_index) |
| 519 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 520 | |
| 521 | vif = pool_elt_at_index (mm->interfaces, hw->dev_instance); |
| 522 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 523 | if (vif->type != VIRTIO_IF_TYPE_TAP) |
| 524 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 525 | |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 526 | /* decrement if this was a GSO interface */ |
| 527 | if (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) |
| 528 | vnm->interface_main.gso_interface_count--; |
| 529 | |
Mohsin Kazmi | e4ac48e | 2019-04-17 12:06:57 +0200 | [diff] [blame] | 530 | clib_file_del_by_index (&file_main, vif->tap_file_index); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 531 | /* bring down the interface */ |
| 532 | vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0); |
| 533 | vnet_sw_interface_set_flags (vnm, vif->sw_if_index, 0); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 534 | vnet_hw_interface_unassign_rx_thread (vnm, vif->hw_if_index, RX_QUEUE (0)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 535 | |
| 536 | ethernet_delete_interface (vnm, vif->hw_if_index); |
| 537 | vif->hw_if_index = ~0; |
| 538 | |
| 539 | if (vif->tap_fd != -1) |
| 540 | close (vif->tap_fd); |
| 541 | if (vif->fd != -1) |
| 542 | close (vif->fd); |
| 543 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 544 | vec_foreach_index (i, vif->rxq_vrings) virtio_vring_free_rx (vm, vif, |
| 545 | RX_QUEUE (i)); |
| 546 | vec_foreach_index (i, vif->txq_vrings) virtio_vring_free_tx (vm, vif, |
| 547 | TX_QUEUE (i)); |
| 548 | vec_free (vif->rxq_vrings); |
| 549 | vec_free (vif->txq_vrings); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 550 | |
Benoît Ganne | 8d879e1 | 2019-06-27 17:31:28 +0200 | [diff] [blame] | 551 | vec_free (vif->host_if_name); |
| 552 | vec_free (vif->net_ns); |
| 553 | vec_free (vif->host_bridge); |
| 554 | |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 555 | tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 556 | clib_memset (vif, 0, sizeof (*vif)); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 557 | pool_put (mm->interfaces, vif); |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | int |
Andrew Yourtchenko | 6a7cff7 | 2018-10-12 16:09:22 +0200 | [diff] [blame] | 563 | tap_gso_enable_disable (vlib_main_t * vm, u32 sw_if_index, int enable_disable) |
| 564 | { |
| 565 | vnet_main_t *vnm = vnet_get_main (); |
| 566 | virtio_main_t *mm = &virtio_main; |
| 567 | virtio_if_t *vif; |
| 568 | vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 569 | clib_error_t *err = 0; |
| 570 | |
| 571 | if (hw == NULL || virtio_device_class.index != hw->dev_class_index) |
| 572 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 573 | |
| 574 | vif = pool_elt_at_index (mm->interfaces, hw->dev_instance); |
| 575 | |
| 576 | const unsigned int gso_on = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6; |
| 577 | const unsigned int gso_off = 0; |
| 578 | unsigned int offload = enable_disable ? gso_on : gso_off; |
| 579 | _IOCTL (vif->tap_fd, TUNSETOFFLOAD, offload); |
| 580 | vif->gso_enabled = enable_disable ? 1 : 0; |
| 581 | if (enable_disable) |
| 582 | { |
| 583 | if ((hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0) |
| 584 | { |
| 585 | vnm->interface_main.gso_interface_count++; |
| 586 | hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO; |
| 587 | } |
| 588 | } |
| 589 | else |
| 590 | { |
| 591 | if ((hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) != 0) |
| 592 | { |
| 593 | vnm->interface_main.gso_interface_count--; |
| 594 | hw->flags &= ~VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | error: |
| 599 | if (err) |
| 600 | { |
| 601 | clib_warning ("Error %s gso on sw_if_index %d", |
| 602 | enable_disable ? "enabling" : "disabling", sw_if_index); |
| 603 | return VNET_API_ERROR_SYSCALL_ERROR_3; |
| 604 | } |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | int |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 609 | tap_dump_ifs (tap_interface_details_t ** out_tapids) |
| 610 | { |
| 611 | vnet_main_t *vnm = vnet_get_main (); |
| 612 | virtio_main_t *mm = &virtio_main; |
| 613 | virtio_if_t *vif; |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 614 | virtio_vring_t *vring; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 615 | vnet_hw_interface_t *hi; |
| 616 | tap_interface_details_t *r_tapids = NULL; |
| 617 | tap_interface_details_t *tapid = NULL; |
| 618 | |
| 619 | /* *INDENT-OFF* */ |
| 620 | pool_foreach (vif, mm->interfaces, |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 621 | if (vif->type != VIRTIO_IF_TYPE_TAP) |
| 622 | continue; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 623 | vec_add2(r_tapids, tapid, 1); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 624 | clib_memset (tapid, 0, sizeof (*tapid)); |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 625 | tapid->id = vif->id; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 626 | tapid->sw_if_index = vif->sw_if_index; |
| 627 | hi = vnet_get_hw_interface (vnm, vif->hw_if_index); |
| 628 | clib_memcpy(tapid->dev_name, hi->name, |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 629 | MIN (ARRAY_LEN (tapid->dev_name) - 1, |
| 630 | strlen ((const char *) hi->name))); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 631 | vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS(0)); |
| 632 | tapid->rx_ring_sz = vring->size; |
| 633 | vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS(0)); |
| 634 | tapid->tx_ring_sz = vring->size; |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 635 | clib_memcpy(tapid->host_mac_addr, vif->host_mac_addr, 6); |
| 636 | if (vif->host_if_name) |
| 637 | { |
| 638 | clib_memcpy(tapid->host_if_name, vif->host_if_name, |
| 639 | MIN (ARRAY_LEN (tapid->host_if_name) - 1, |
| 640 | strlen ((const char *) vif->host_if_name))); |
| 641 | } |
| 642 | if (vif->net_ns) |
| 643 | { |
| 644 | clib_memcpy(tapid->host_namespace, vif->net_ns, |
| 645 | MIN (ARRAY_LEN (tapid->host_namespace) - 1, |
| 646 | strlen ((const char *) vif->net_ns))); |
| 647 | } |
| 648 | if (vif->host_bridge) |
| 649 | { |
| 650 | clib_memcpy(tapid->host_bridge, vif->host_bridge, |
| 651 | MIN (ARRAY_LEN (tapid->host_bridge) - 1, |
| 652 | strlen ((const char *) vif->host_bridge))); |
| 653 | } |
| 654 | if (vif->host_ip4_prefix_len) |
| 655 | clib_memcpy(tapid->host_ip4_addr, &vif->host_ip4_addr, 4); |
| 656 | tapid->host_ip4_prefix_len = vif->host_ip4_prefix_len; |
| 657 | if (vif->host_ip6_prefix_len) |
| 658 | clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16); |
| 659 | tapid->host_ip6_prefix_len = vif->host_ip6_prefix_len; |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 660 | tapid->host_mtu_size = vif->host_mtu_size; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 661 | ); |
| 662 | /* *INDENT-ON* */ |
| 663 | |
| 664 | *out_tapids = r_tapids; |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static clib_error_t * |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 670 | tap_mtu_config (vlib_main_t * vm, unformat_input_t * input) |
| 671 | { |
| 672 | tap_main_t *tm = &tap_main; |
| 673 | |
| 674 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 675 | { |
| 676 | if (unformat (input, "host-mtu %d", &tm->host_mtu_size)) |
| 677 | ; |
| 678 | else |
| 679 | return clib_error_return (0, "unknown input `%U'", |
| 680 | format_unformat_error, input); |
| 681 | } |
| 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | /* tap { host-mtu <size> } configuration. */ |
| 687 | VLIB_CONFIG_FUNCTION (tap_mtu_config, "tap"); |
| 688 | |
| 689 | static clib_error_t * |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 690 | tap_init (vlib_main_t * vm) |
| 691 | { |
Damjan Marion | 2df3909 | 2017-12-04 20:03:37 +0100 | [diff] [blame] | 692 | tap_main_t *tm = &tap_main; |
Mohsin Kazmi | a23b615 | 2018-05-17 17:21:39 +0200 | [diff] [blame] | 693 | clib_error_t *error = 0; |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 694 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 695 | tm->log_default = vlib_log_register_class ("tap", 0); |
Mohsin Kazmi | a23b615 | 2018-05-17 17:21:39 +0200 | [diff] [blame] | 696 | vlib_log_debug (tm->log_default, "initialized"); |
Neale Ranns | cbe8d65 | 2018-04-27 04:42:47 -0700 | [diff] [blame] | 697 | |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 698 | tm->host_mtu_size = 0; |
| 699 | |
Mohsin Kazmi | a23b615 | 2018-05-17 17:21:39 +0200 | [diff] [blame] | 700 | return error; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | VLIB_INIT_FUNCTION (tap_init); |
| 704 | |
| 705 | /* |
| 706 | * fd.io coding-style-patch-verification: ON |
| 707 | * |
| 708 | * Local Variables: |
| 709 | * eval: (c-set-style "gnu") |
| 710 | * End: |
| 711 | */ |