diff options
author | Jakub Grajciar <jgrajcia@cisco.com> | 2019-09-03 10:40:01 +0200 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-12-11 09:39:42 +0000 |
commit | 5de4fb7076a46ab75e2d3c30079dd6639af16a86 (patch) | |
tree | 3ac12410c3d0769f5d950df53d6abb43fe54e5b9 /src/vnet/devices | |
parent | 8dc75c0cc3ac0db13778a0a32f9aa81597b80556 (diff) |
devices: tap API cleanup
Use consistent API types.
Type: fix
Change-Id: I11cc7f6347b7a60e5fd41e54f0c7994e2d81199f
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'src/vnet/devices')
-rw-r--r-- | src/vnet/devices/tap/cli.c | 2 | ||||
-rw-r--r-- | src/vnet/devices/tap/tap.c | 28 | ||||
-rw-r--r-- | src/vnet/devices/tap/tap.h | 10 | ||||
-rw-r--r-- | src/vnet/devices/tap/tapv2.api | 123 | ||||
-rw-r--r-- | src/vnet/devices/tap/tapv2_api.c | 58 |
5 files changed, 128 insertions, 93 deletions
diff --git a/src/vnet/devices/tap/cli.c b/src/vnet/devices/tap/cli.c index abec8f07842..a85fcbff25c 100644 --- a/src/vnet/devices/tap/cli.c +++ b/src/vnet/devices/tap/cli.c @@ -90,7 +90,7 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input, else if (unformat (line_input, "gso")) args.tap_flags |= TAP_FLAG_GSO; else if (unformat (line_input, "hw-addr %U", - unformat_ethernet_address, args.mac_addr)) + unformat_ethernet_address, args.mac_addr.bytes)) args.mac_addr_set = 1; else { diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c index 38f0605277d..061c6ac26a1 100644 --- a/src/vnet/devices/tap/tap.c +++ b/src/vnet/devices/tap/tap.c @@ -170,9 +170,9 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) vif->num_rxqs = args->num_rx_queues; num_q_pairs = clib_max (vif->num_rxqs, vif->num_txqs); - if (ethernet_mac_address_is_zero (args->host_mac_addr)) - ethernet_mac_address_generate (args->host_mac_addr); - clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6); + if (ethernet_mac_address_is_zero (args->host_mac_addr.bytes)) + ethernet_mac_address_generate (args->host_mac_addr.bytes); + clib_memcpy (vif->host_mac_addr, args->host_mac_addr.bytes, 6); if ((vif->tap_fd = tfd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) { @@ -345,6 +345,17 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) } } + if (!ethernet_mac_address_is_zero (args->host_mac_addr.bytes)) + { + args->error = vnet_netlink_set_link_addr (vif->ifindex, + args->host_mac_addr.bytes); + if (args->error) + { + args->rv = VNET_API_ERROR_NETLINK_ERROR; + goto error; + } + } + if (args->host_bridge) { args->error = vnet_netlink_set_link_master (vif->ifindex, @@ -547,14 +558,15 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) } if (!args->mac_addr_set) - ethernet_mac_address_generate (args->mac_addr); + ethernet_mac_address_generate (args->mac_addr.bytes); - clib_memcpy (vif->mac_addr, args->mac_addr, 6); + clib_memcpy (vif->mac_addr, args->mac_addr.bytes, 6); vif->host_if_name = format (0, "%s%c", host_if_name, 0); vif->net_ns = format (0, "%s%c", args->host_namespace, 0); vif->host_bridge = format (0, "%s%c", args->host_bridge, 0); vif->host_mtu_size = args->host_mtu_size; + clib_memcpy (vif->host_mac_addr, args->host_mac_addr.bytes, 6); vif->host_ip4_prefix_len = args->host_ip4_prefix_len; vif->host_ip6_prefix_len = args->host_ip6_prefix_len; if (args->host_ip4_prefix_len) @@ -726,7 +738,7 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids) tapid->rx_ring_sz = vring->size; vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS(0)); tapid->tx_ring_sz = vring->size; - clib_memcpy(tapid->host_mac_addr, vif->host_mac_addr, 6); + clib_memcpy(&tapid->host_mac_addr, vif->host_mac_addr, 6); if (vif->host_if_name) { clib_memcpy(tapid->host_if_name, vif->host_if_name, @@ -746,10 +758,10 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids) strlen ((const char *) vif->host_bridge))); } if (vif->host_ip4_prefix_len) - clib_memcpy(tapid->host_ip4_addr, &vif->host_ip4_addr, 4); + clib_memcpy(tapid->host_ip4_addr.as_u8, &vif->host_ip4_addr, 4); tapid->host_ip4_prefix_len = vif->host_ip4_prefix_len; if (vif->host_ip6_prefix_len) - clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16); + clib_memcpy(tapid->host_ip6_addr.as_u8, &vif->host_ip6_addr, 16); tapid->host_ip6_prefix_len = vif->host_ip6_prefix_len; tapid->host_mtu_size = vif->host_mtu_size; ); diff --git a/src/vnet/devices/tap/tap.h b/src/vnet/devices/tap/tap.h index 46edf02b1e9..6eba7affa35 100644 --- a/src/vnet/devices/tap/tap.h +++ b/src/vnet/devices/tap/tap.h @@ -26,7 +26,7 @@ typedef struct { u32 id; u8 mac_addr_set; - u8 mac_addr[6]; + mac_address_t mac_addr; u8 num_rx_queues; u16 rx_ring_sz; u16 tx_ring_sz; @@ -34,7 +34,7 @@ typedef struct #define TAP_FLAG_GSO (1 << 0) u8 *host_namespace; u8 *host_if_name; - u8 host_mac_addr[6]; + mac_address_t host_mac_addr; u8 *host_bridge; ip4_address_t host_ip4_addr; u8 host_ip4_prefix_len; @@ -61,13 +61,13 @@ typedef struct u8 dev_name[64]; u16 tx_ring_sz; u16 rx_ring_sz; - u8 host_mac_addr[6]; + mac_address_t host_mac_addr; u8 host_if_name[64]; u8 host_namespace[64]; u8 host_bridge[64]; - u8 host_ip4_addr[4]; + ip4_address_t host_ip4_addr; u8 host_ip4_prefix_len; - u8 host_ip6_addr[16]; + ip6_address_t host_ip6_addr; u8 host_ip6_prefix_len; u32 host_mtu_size; } tap_interface_details_t; diff --git a/src/vnet/devices/tap/tapv2.api b/src/vnet/devices/tap/tapv2.api index c11a07cf72a..ec8bd4539b9 100644 --- a/src/vnet/devices/tap/tapv2.api +++ b/src/vnet/devices/tap/tapv2.api @@ -19,7 +19,15 @@ the Linux kernel TAP device driver */ -option version = "2.1.0"; +option version = "3.0.0"; + +import "vnet/interface_types.api"; +import "vnet/ethernet/ethernet_types.api"; +import "vnet/ip/ip_types.api"; + +enum tap_flags { + TAP_FLAG_GSO = 1, +}; /** \brief Initialize a new tap interface with the given parameters @param client_index - opaque cookie to identify the sender @@ -27,61 +35,60 @@ option version = "2.1.0"; @param id - interface id, 0xffffffff means auto @param use_random_mac - let the system generate a unique mac address @param mac_address - mac addr to assign to the interface if use_random not set + @param num_rx_queues - number of rx queues @param tx_ring_sz - the number of entries of TX ring @param rx_ring_sz - the number of entries of RX ring + @param host_mtu_set - host MTU should be set + @param host_mtu_size - host MTU size @param host_mac_addr_set - host side interface mac address should be set @param host_mac_addr - host side interface mac address - @param host_if_name_set - host side interface name should be set - @param host_if_name - host side interface name - @param host_namespace_set - host namespace should be set - @param host_namespace - host namespace to attach interface to - @param host_bridge_set - host bridge should be set - @param host_bridge - host bridge to attach interface to - @param host_ip4_addr_set - host IPv4 ip address should be set - @param host_ip4_addr - host IPv4 ip address - @param host_ip4_prefix_len - host IPv4 ip address prefix length - @param host_ip6_addr_set - host IPv6 ip address should be set - @param host_ip6_addr - host IPv6 ip address - @param host_ip6_prefix_len - host IPv6 ip address prefix length + @param host_ip4_prefix_set - host IPv4 ip address should be set + @param host_ip4_prefix - host IPv4 ip address + @param host_ip6_prefix_set - host IPv6 ip address should be set + @param host_ip6_prefix - host IPv6 ip address @param host_ip4_gw_set - host IPv4 default gateway should be set @param host_ip4_gw - host IPv4 default gateway @param host_ip6_gw_set - host IPv6 default gateway should be set @param host_ip6_gw - host IPv6 default gateway - @param host_mtu_set - host MTU should be set - @param host_mtu_size - host MTU size @param tap_flags - flags for the TAP interface creation + @param host_if_name_set - host side interface name should be set + @param host_if_name - host side interface name + @param host_namespace_set - host namespece should be set + @param host_namespace - host namespace to attach interface to + @param host_bridge_set - host bridge should be set + @param host_bridge - host bridge to attach interface to + @param tag - tag */ define tap_create_v2 { u32 client_index; u32 context; - u32 id [default= 0xffffffff] ; - u8 use_random_mac; - u8 mac_address[6]; + u32 id [default=0xffffffff]; + bool use_random_mac [default=true]; + vl_api_mac_address_t mac_address; + u8 num_rx_queues [default=1]; u16 tx_ring_sz; /* optional, default is 256 entries, must be power of 2 */ u16 rx_ring_sz; /* optional, default is 256 entries, must be power of 2 */ - u8 host_namespace_set; - u8 host_namespace[64]; - u8 host_mac_addr_set; - u8 host_mac_addr[6]; - u8 host_if_name_set; - u8 host_if_name[64]; - u8 host_bridge_set; - u8 host_bridge[64]; - u8 host_ip4_addr_set; - u8 host_ip4_addr[4]; - u8 host_ip4_prefix_len; - u8 host_ip6_addr_set; - u8 host_ip6_addr[16]; - u8 host_ip6_prefix_len; - u8 host_ip4_gw_set; - u8 host_ip4_gw[4]; - u8 host_ip6_gw_set; - u8 host_ip6_gw[16]; - u8 host_mtu_set; + bool host_mtu_set; u32 host_mtu_size; - u8 tag[64]; - u32 tap_flags; + bool host_mac_addr_set; + vl_api_mac_address_t host_mac_addr; + bool host_ip4_prefix_set; + vl_api_ip4_address_with_prefix_t host_ip4_prefix; + bool host_ip6_prefix_set; + vl_api_ip6_address_with_prefix_t host_ip6_prefix; + bool host_ip4_gw_set; + vl_api_ip4_address_t host_ip4_gw; + bool host_ip6_gw_set; + vl_api_ip6_address_t host_ip6_gw; + vl_api_tap_flags_t tap_flags; + bool host_namespace_set; + string host_namespace[64]; + bool host_if_name_set; + string host_if_name[64]; + bool host_bridge_set; + string host_bridge[64]; + string tag[]; }; /** \brief Reply for tap create reply @@ -93,7 +100,7 @@ define tap_create_v2_reply { u32 context; i32 retval; - u32 sw_if_index; + vl_api_interface_index_t sw_if_index; }; /** \brief Delete tap interface @@ -105,50 +112,50 @@ autoreply define tap_delete_v2 { u32 client_index; u32 context; - u32 sw_if_index; + vl_api_interface_index_t sw_if_index; }; -/** \brief Dump tap interfaces request */ +/** \brief Dump tap interfaces request + @param sw_if_index - filter by sw_if_index UNIMPLEMENTED +*/ define sw_interface_tap_v2_dump { u32 client_index; u32 context; + vl_api_interface_index_t sw_if_index [default=0xffffffff]; }; /** \brief Reply for tap dump request @param sw_if_index - software index of tap interface @param id - interface id - @param dev_name - Linux tap device name @param tx_ring_sz - the number of entries of TX ring @param rx_ring_sz - the number of entries of RX ring + @param host_mtu_size - host mtu size @param host_mac_addr - mac address assigned to the host side of the interface + @param host_ip4_prefix - host IPv4 ip address + @param host_ip6_prefix - host IPv6 ip address + @param tap_flags - flags for the TAP interface creation + @param dev_name - Linux tap device name @param host_if_name - host side interface name @param host_namespace - host namespace the interface is attached into @param host_bridge - host bridge the interface is attached into - @param host_ip4_addr - host IPv4 ip address - @param host_ip4_prefix_len - host IPv4 ip address prefix length; 0 if unset - @param host_ip6_addr - host IPv6 ip address - @param host_ip6_prefix_len - host IPv6 ip address prefix length; 0 if unset - @param host_mtu_size - host mtu size */ define sw_interface_tap_v2_details { u32 context; u32 sw_if_index; u32 id; - u8 dev_name[64]; u16 tx_ring_sz; u16 rx_ring_sz; - u8 host_mac_addr[6]; - u8 host_if_name[64]; - u8 host_namespace[64]; - u8 host_bridge[64]; - u8 host_ip4_addr[4]; - u8 host_ip4_prefix_len; - u8 host_ip6_addr[16]; - u8 host_ip6_prefix_len; u32 host_mtu_size; - u32 tap_flags; + vl_api_mac_address_t host_mac_addr; + vl_api_ip4_address_with_prefix_t host_ip4_prefix; + vl_api_ip6_address_with_prefix_t host_ip6_prefix; + vl_api_tap_flags_t tap_flags; + string dev_name[64]; + string host_if_name[64]; + string host_namespace[64]; + string host_bridge[64]; }; /* diff --git a/src/vnet/devices/tap/tapv2_api.c b/src/vnet/devices/tap/tapv2_api.c index af3c2763f48..1f1e18a7b6e 100644 --- a/src/vnet/devices/tap/tapv2_api.c +++ b/src/vnet/devices/tap/tapv2_api.c @@ -25,6 +25,9 @@ #include <vnet/ethernet/ethernet.h> #include <vnet/ip/ip.h> +#include <vnet/ethernet/ethernet_types_api.h> +#include <vnet/ip/ip_types_api.h> + #include <vnet/vnet_msg_enum.h> #define vl_typedefs /* define message structures */ @@ -68,20 +71,28 @@ vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp) ap->id = ntohl (mp->id); if (!mp->use_random_mac) { - clib_memcpy (ap->mac_addr, mp->mac_address, 6); + mac_address_decode (mp->mac_address, &ap->mac_addr); ap->mac_addr_set = 1; } ap->rx_ring_sz = ntohs (mp->rx_ring_sz); ap->tx_ring_sz = ntohs (mp->tx_ring_sz); ap->sw_if_index = (u32) ~ 0; + if (mp->num_rx_queues < 1) + { + ap->rv = VNET_API_ERROR_INVALID_ARGUMENT; + ap->sw_if_index = ~0; + goto done; + } + + ap->num_rx_queues = mp->num_rx_queues; + if (mp->host_if_name_set) ap->host_if_name = mp->host_if_name; if (mp->host_mac_addr_set) { - clib_memcpy (ap->host_mac_addr, mp->host_mac_addr, 6); - ap->mac_addr_set = 1; + mac_address_decode (mp->host_mac_addr, &ap->host_mac_addr); } if (mp->host_namespace_set) @@ -90,27 +101,27 @@ vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp) if (mp->host_bridge_set) ap->host_bridge = mp->host_bridge; - if (mp->host_ip4_addr_set) + if (mp->host_ip4_prefix_set) { - clib_memcpy (&ap->host_ip4_addr.as_u8, mp->host_ip4_addr, 4); - ap->host_ip4_prefix_len = mp->host_ip4_prefix_len; + ip4_address_decode (mp->host_ip4_prefix.address, &ap->host_ip4_addr); + ap->host_ip4_prefix_len = mp->host_ip4_prefix.len; } - if (mp->host_ip6_addr_set) + if (mp->host_ip6_prefix_set) { - clib_memcpy (&ap->host_ip6_addr, mp->host_ip6_addr, 16); - ap->host_ip6_prefix_len = mp->host_ip6_prefix_len; + ip6_address_decode (mp->host_ip6_prefix.address, &ap->host_ip6_addr); + ap->host_ip6_prefix_len = mp->host_ip6_prefix.len; } if (mp->host_ip4_gw_set) { - clib_memcpy (&ap->host_ip4_gw, mp->host_ip4_gw, 4); + ip4_address_decode (mp->host_ip4_gw, &ap->host_ip4_gw); ap->host_ip4_gw_set = 1; } if (mp->host_ip6_gw_set) { - clib_memcpy (&ap->host_ip6_gw, mp->host_ip6_gw, 16); + ip6_address_decode (mp->host_ip6_gw, &ap->host_ip6_gw); ap->host_ip6_gw_set = 1; } @@ -126,15 +137,13 @@ vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp) /* If a tag was supplied... */ - if (mp->tag[0]) + if (vl_api_string_len (&mp->tag)) { - /* Make sure it's a proper C-string */ - mp->tag[ARRAY_LEN (mp->tag) - 1] = 0; - u8 *tag = format (0, "%s%c", mp->tag, 0); + u8 *tag = format (0, "%s%c", vl_api_from_api_string (&mp->tag), 0); vnet_set_sw_interface_tag (vnm, tag, ap->sw_if_index); } - +done: rmp = vl_msg_api_alloc (sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_TAP_CREATE_V2_REPLY); rmp->context = mp->context; @@ -191,7 +200,7 @@ tap_send_sw_interface_details (vpe_api_main_t * am, strlen ((const char *) tap_if->dev_name))); mp->rx_ring_sz = htons (tap_if->rx_ring_sz); mp->tx_ring_sz = htons (tap_if->tx_ring_sz); - clib_memcpy (mp->host_mac_addr, tap_if->host_mac_addr, 6); + mac_address_encode (&tap_if->host_mac_addr, mp->host_mac_addr); clib_memcpy (mp->host_if_name, tap_if->host_if_name, MIN (ARRAY_LEN (mp->host_if_name) - 1, strlen ((const char *) tap_if->host_if_name))); @@ -202,12 +211,14 @@ tap_send_sw_interface_details (vpe_api_main_t * am, MIN (ARRAY_LEN (mp->host_bridge) - 1, strlen ((const char *) tap_if->host_bridge))); mp->host_mtu_size = htonl (tap_if->host_mtu_size); + mac_address_encode (&tap_if->host_mac_addr, mp->host_mac_addr); + if (tap_if->host_ip4_prefix_len) - clib_memcpy (&mp->host_ip4_addr, &tap_if->host_ip4_addr, 4); - mp->host_ip4_prefix_len = tap_if->host_ip4_prefix_len; + ip4_address_encode (&tap_if->host_ip4_addr, mp->host_ip4_prefix.address); + mp->host_ip4_prefix.len = tap_if->host_ip4_prefix_len; if (tap_if->host_ip6_prefix_len) - clib_memcpy (&mp->host_ip6_addr, &tap_if->host_ip6_addr, 16); - mp->host_ip6_prefix_len = tap_if->host_ip6_prefix_len; + ip6_address_encode (&tap_if->host_ip6_addr, mp->host_ip6_prefix.address); + mp->host_ip6_prefix.len = tap_if->host_ip6_prefix_len; mp->context = context; vl_api_send_msg (reg, (u8 *) mp); @@ -222,11 +233,16 @@ vl_api_sw_interface_tap_v2_dump_t_handler (vl_api_sw_interface_tap_v2_dump_t * vl_api_registration_t *reg; tap_interface_details_t *tapifs = NULL; tap_interface_details_t *tap_if = NULL; + u32 filter_sw_if_index; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; + filter_sw_if_index = htonl (mp->sw_if_index); + if (filter_sw_if_index != ~0) + return; /* UNIMPLEMENTED */ + rv = tap_dump_ifs (&tapifs); if (rv) return; |