blob: c1ac7a61229a4d21e4a069380a984bcc570ccced [file] [log] [blame]
Damjan Marion8389fb92017-10-13 18:29:53 +02001/*
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
18#ifndef _VNET_DEVICES_VIRTIO_TAP_H_
19#define _VNET_DEVICES_VIRTIO_TAP_H_
20
21#ifndef MIN
22#define MIN(x,y) (((x)<(y))?(x):(y))
23#endif
24
25typedef struct
26{
Damjan Marion2df39092017-12-04 20:03:37 +010027 u32 id;
28 u8 mac_addr_set;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020029 mac_address_t mac_addr;
Damjan Marion7c6102b2019-11-08 17:59:56 +010030 u8 num_rx_queues;
Damjan Marion8389fb92017-10-13 18:29:53 +020031 u16 rx_ring_sz;
32 u16 tx_ring_sz;
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010033 u32 tap_flags;
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +020034#define TAP_FLAG_GSO (1 << 0)
Mohsin Kazmiba0061f2019-12-18 17:08:54 +010035#define TAP_FLAG_CSUM_OFFLOAD (1 << 1)
Mohsin Kazmib49bc1a2020-02-14 17:51:04 +000036#define TAP_FLAG_PERSIST (1 << 2)
37#define TAP_FLAG_ATTACH (1 << 3)
Mohsin Kazmi206acf82020-04-06 14:19:54 +020038#define TAP_FLAG_TUN (1 << 4)
Damjan Marion91c6ef72017-12-01 13:34:24 +010039 u8 *host_namespace;
Damjan Marion2df39092017-12-04 20:03:37 +010040 u8 *host_if_name;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020041 mac_address_t host_mac_addr;
Damjan Marion91c6ef72017-12-01 13:34:24 +010042 u8 *host_bridge;
43 ip4_address_t host_ip4_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010044 u8 host_ip4_prefix_len;
Damjan Marion7866c452018-01-18 13:35:11 +010045 ip4_address_t host_ip4_gw;
46 u8 host_ip4_gw_set;
Damjan Marion91c6ef72017-12-01 13:34:24 +010047 ip6_address_t host_ip6_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010048 u8 host_ip6_prefix_len;
Damjan Marion7866c452018-01-18 13:35:11 +010049 ip6_address_t host_ip6_gw;
50 u8 host_ip6_gw_set;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020051 u8 host_mtu_set;
52 u32 host_mtu_size;
Damjan Marion8389fb92017-10-13 18:29:53 +020053 /* return */
54 u32 sw_if_index;
Damjan Marion91c6ef72017-12-01 13:34:24 +010055 int rv;
56 clib_error_t *error;
Damjan Marion8389fb92017-10-13 18:29:53 +020057} tap_create_if_args_t;
58
59/** TAP interface details struct */
60typedef struct
61{
Milan Lenco73e7f422017-12-14 10:04:25 +010062 u32 id;
Damjan Marion8389fb92017-10-13 18:29:53 +020063 u32 sw_if_index;
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010064 u32 tap_flags;
Damjan Marion8389fb92017-10-13 18:29:53 +020065 u8 dev_name[64];
Milan Lenco73e7f422017-12-14 10:04:25 +010066 u16 tx_ring_sz;
67 u16 rx_ring_sz;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020068 mac_address_t host_mac_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010069 u8 host_if_name[64];
70 u8 host_namespace[64];
71 u8 host_bridge[64];
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020072 ip4_address_t host_ip4_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010073 u8 host_ip4_prefix_len;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020074 ip6_address_t host_ip6_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010075 u8 host_ip6_prefix_len;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020076 u32 host_mtu_size;
Damjan Marion8389fb92017-10-13 18:29:53 +020077} tap_interface_details_t;
78
Damjan Marion2df39092017-12-04 20:03:37 +010079typedef struct
80{
Damjan Marion07a38572018-01-21 06:44:18 -080081 /* logging */
82 vlib_log_class_t log_default;
Neale Rannscbe8d652018-04-27 04:42:47 -070083
84 /* bit-map of in-use IDs */
85 uword *tap_ids;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020086
87 /* host mtu size, configurable through startup.conf */
88 int host_mtu_size;
Damjan Marion2df39092017-12-04 20:03:37 +010089} tap_main_t;
90
Damjan Marion91c6ef72017-12-01 13:34:24 +010091void tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args);
Damjan Marion8389fb92017-10-13 18:29:53 +020092int tap_delete_if (vlib_main_t * vm, u32 sw_if_index);
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +020093int tap_gso_enable_disable (vlib_main_t * vm, u32 sw_if_index,
94 int enable_disable);
Mohsin Kazmiba0061f2019-12-18 17:08:54 +010095int
96tap_csum_offload_enable_disable (vlib_main_t * vm, u32 sw_if_index,
97 int enable_disable);
Damjan Marion8389fb92017-10-13 18:29:53 +020098int tap_dump_ifs (tap_interface_details_t ** out_tapids);
99
100#endif /* _VNET_DEVICES_VIRTIO_TAP_H_ */
101
102/*
103 * fd.io coding-style-patch-verification: ON
104 *
105 * Local Variables:
106 * eval: (c-set-style "gnu")
107 * End:
108 */