blob: 6b88c34fe41e95c06a466cca43ffd6c33bc525aa [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
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +020025#define foreach_tapv2_flags \
26 _ (GSO, 0) \
27 _ (CSUM_OFFLOAD, 1) \
28 _ (PERSIST, 2) \
29 _ (ATTACH, 3) \
30 _ (TUN, 4) \
Mohsin Kazmi50bd1652020-08-26 11:07:48 +020031 _ (GRO_COALESCE, 5) \
32 _ (PACKED, 6) \
33 _ (IN_ORDER, 7)
Mohsin Kazmid88fc0f2020-04-30 19:05:56 +020034
35typedef enum
36{
37#define _(a, b) TAP_FLAG_##a = (1 << b),
38 foreach_tapv2_flags
39#undef _
40} tap_flag_t;
41
Damjan Marion8389fb92017-10-13 18:29:53 +020042typedef struct
43{
Damjan Marion2df39092017-12-04 20:03:37 +010044 u32 id;
45 u8 mac_addr_set;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020046 mac_address_t mac_addr;
Nathan Skrzypczak40edaf62021-12-15 18:45:59 +010047 u16 num_rx_queues;
48 u16 num_tx_queues;
Damjan Marion8389fb92017-10-13 18:29:53 +020049 u16 rx_ring_sz;
50 u16 tx_ring_sz;
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010051 u32 tap_flags;
Damjan Marion91c6ef72017-12-01 13:34:24 +010052 u8 *host_namespace;
Damjan Marion2df39092017-12-04 20:03:37 +010053 u8 *host_if_name;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020054 mac_address_t host_mac_addr;
Damjan Marion91c6ef72017-12-01 13:34:24 +010055 u8 *host_bridge;
56 ip4_address_t host_ip4_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010057 u8 host_ip4_prefix_len;
Damjan Marion7866c452018-01-18 13:35:11 +010058 ip4_address_t host_ip4_gw;
59 u8 host_ip4_gw_set;
Damjan Marion91c6ef72017-12-01 13:34:24 +010060 ip6_address_t host_ip6_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010061 u8 host_ip6_prefix_len;
Damjan Marion7866c452018-01-18 13:35:11 +010062 ip6_address_t host_ip6_gw;
63 u8 host_ip6_gw_set;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020064 u8 host_mtu_set;
65 u32 host_mtu_size;
Damjan Marion8389fb92017-10-13 18:29:53 +020066 /* return */
67 u32 sw_if_index;
Damjan Marion91c6ef72017-12-01 13:34:24 +010068 int rv;
69 clib_error_t *error;
Damjan Marion8389fb92017-10-13 18:29:53 +020070} tap_create_if_args_t;
71
72/** TAP interface details struct */
73typedef struct
74{
Milan Lenco73e7f422017-12-14 10:04:25 +010075 u32 id;
Damjan Marion8389fb92017-10-13 18:29:53 +020076 u32 sw_if_index;
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010077 u32 tap_flags;
Damjan Marion8389fb92017-10-13 18:29:53 +020078 u8 dev_name[64];
Milan Lenco73e7f422017-12-14 10:04:25 +010079 u16 tx_ring_sz;
80 u16 rx_ring_sz;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020081 mac_address_t host_mac_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010082 u8 host_if_name[64];
83 u8 host_namespace[64];
84 u8 host_bridge[64];
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020085 ip4_address_t host_ip4_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010086 u8 host_ip4_prefix_len;
Jakub Grajciar5de4fb72019-09-03 10:40:01 +020087 ip6_address_t host_ip6_addr;
Milan Lenco73e7f422017-12-14 10:04:25 +010088 u8 host_ip6_prefix_len;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020089 u32 host_mtu_size;
Damjan Marion8389fb92017-10-13 18:29:53 +020090} tap_interface_details_t;
91
Damjan Marion2df39092017-12-04 20:03:37 +010092typedef struct
93{
Damjan Marion07a38572018-01-21 06:44:18 -080094 /* logging */
95 vlib_log_class_t log_default;
Neale Rannscbe8d652018-04-27 04:42:47 -070096
97 /* bit-map of in-use IDs */
98 uword *tap_ids;
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +020099
100 /* host mtu size, configurable through startup.conf */
101 int host_mtu_size;
Mohsin Kazmib21fd4b2021-09-22 20:03:28 +0000102 u16 msg_id_base;
Damjan Marion2df39092017-12-04 20:03:37 +0100103} tap_main_t;
104
Mohsin Kazmib21fd4b2021-09-22 20:03:28 +0000105extern tap_main_t tap_main;
Damjan Marion91c6ef72017-12-01 13:34:24 +0100106void tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args);
Damjan Marion8389fb92017-10-13 18:29:53 +0200107int tap_delete_if (vlib_main_t * vm, u32 sw_if_index);
Andrew Yourtchenko6a7cff72018-10-12 16:09:22 +0200108int tap_gso_enable_disable (vlib_main_t * vm, u32 sw_if_index,
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200109 int enable_disable, int packet_coalesce);
Mohsin Kazmiba0061f2019-12-18 17:08:54 +0100110int
111tap_csum_offload_enable_disable (vlib_main_t * vm, u32 sw_if_index,
112 int enable_disable);
Damjan Marion8389fb92017-10-13 18:29:53 +0200113int tap_dump_ifs (tap_interface_details_t ** out_tapids);
Matthew Smithbd50ed12020-07-24 13:38:03 -0500114int tap_set_carrier (u32 hw_if_index, u32 carrier_up);
Alexander Chernavina6c34a12020-09-04 09:24:20 -0400115int tap_set_speed (u32 hw_if_index, u32 speed);
Damjan Marion8389fb92017-10-13 18:29:53 +0200116
117#endif /* _VNET_DEVICES_VIRTIO_TAP_H_ */
118
119/*
120 * fd.io coding-style-patch-verification: ON
121 *
122 * Local Variables:
123 * eval: (c-set-style "gnu")
124 * End:
125 */