From 6f1f04afac07d065b1992f5e8ec2bb0ae5435432 Mon Sep 17 00:00:00 2001 From: Jijiang Liu Date: Thu, 23 Oct 2014 21:18:53 +0800 Subject: [PATCH] ethdev: UDP tunnels Add two functions to support UDP tunneling port configuration. There are "some" destination UDP port numbers that have unique meaning. In terms of VxLAN, "IANA has assigned the value 4789 for the VXLAN UDP port, and this value SHOULD be used by default as the destination UDP port. Some early implementations of VXLAN have used other values for the destination port. To enable interoperability with these implementations, the destination port SHOULD be configurable." Signed-off-by: Jijiang Liu Acked-by: Helin Zhang Tested-by: Yong Liu Acked-by: Thomas Monjalon --- lib/librte_ether/rte_eth_ctrl.h | 12 ++++++++ lib/librte_ether/rte_ethdev.c | 52 +++++++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 54 +++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/lib/librte_ether/rte_eth_ctrl.h b/lib/librte_ether/rte_eth_ctrl.h index df21ac6069..9a90d19d89 100644 --- a/lib/librte_ether/rte_eth_ctrl.h +++ b/lib/librte_ether/rte_eth_ctrl.h @@ -71,6 +71,18 @@ enum rte_filter_op { RTE_ETH_FILTER_OP_MAX }; +/** + * Tunneled type. + */ +enum rte_eth_tunnel_type { + RTE_TUNNEL_TYPE_NONE = 0, + RTE_TUNNEL_TYPE_VXLAN, + RTE_TUNNEL_TYPE_GENEVE, + RTE_TUNNEL_TYPE_TEREDO, + RTE_TUNNEL_TYPE_NVGRE, + RTE_TUNNEL_TYPE_MAX, +}; + #ifdef __cplusplus } #endif diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 50f10d96f9..ff1c769164 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -2037,6 +2037,58 @@ rte_eth_dev_rss_hash_conf_get(uint8_t port_id, return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf); } +int +rte_eth_dev_udp_tunnel_add(uint8_t port_id, + struct rte_eth_udp_tunnel *udp_tunnel) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -ENODEV; + } + + if (udp_tunnel == NULL) { + PMD_DEBUG_TRACE("Invalid udp_tunnel parameter\n"); + return -EINVAL; + } + + if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { + PMD_DEBUG_TRACE("Invalid tunnel type\n"); + return -EINVAL; + } + + dev = &rte_eth_devices[port_id]; + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP); + return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel); +} + +int +rte_eth_dev_udp_tunnel_delete(uint8_t port_id, + struct rte_eth_udp_tunnel *udp_tunnel) +{ + struct rte_eth_dev *dev; + + if (port_id >= nb_ports) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); + return -ENODEV; + } + dev = &rte_eth_devices[port_id]; + + if (udp_tunnel == NULL) { + PMD_DEBUG_TRACE("Invalid udp_tunnel parametr\n"); + return -EINVAL; + } + + if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { + PMD_DEBUG_TRACE("Invalid tunnel type\n"); + return -EINVAL; + } + + FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP); + return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel); +} + int rte_eth_led_on(uint8_t port_id) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index b69a6af8ba..8bf274d075 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -709,6 +709,14 @@ struct rte_fdir_conf { uint8_t drop_queue; }; +/** + * UDP tunneling configuration. + */ +struct rte_eth_udp_tunnel { + uint16_t udp_port; + uint8_t prot_type; +}; + /** * Possible l4type of FDIR filters. */ @@ -1266,6 +1274,15 @@ typedef int (*eth_mirror_rule_reset_t)(struct rte_eth_dev *dev, uint8_t rule_id); /**< @internal Remove a traffic mirroring rule on an Ethernet device */ +typedef int (*eth_udp_tunnel_add_t)(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *tunnel_udp); +/**< @internal Add tunneling UDP info */ + +typedef int (*eth_udp_tunnel_del_t)(struct rte_eth_dev *dev, + struct rte_eth_udp_tunnel *tunnel_udp); +/**< @internal Delete tunneling UDP info */ + + #ifdef RTE_NIC_BYPASS enum { @@ -1446,6 +1463,8 @@ struct eth_dev_ops { eth_set_vf_rx_t set_vf_rx; /**< enable/disable a VF receive */ eth_set_vf_tx_t set_vf_tx; /**< enable/disable a VF transmit */ eth_set_vf_vlan_filter_t set_vf_vlan_filter; /**< Set VF VLAN filter */ + eth_udp_tunnel_add_t udp_tunnel_add; + eth_udp_tunnel_del_t udp_tunnel_del; eth_set_queue_rate_limit_t set_queue_rate_limit; /**< Set queue rate limit */ eth_set_vf_rate_limit_t set_vf_rate_limit; /**< Set VF rate limit */ @@ -3342,6 +3361,41 @@ int rte_eth_dev_rss_hash_conf_get(uint8_t port_id, struct rte_eth_rss_conf *rss_conf); + /** + * Add UDP tunneling port of an Ethernet device for filtering a specific + * tunneling packet by UDP port number. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param tunnel_udp + * UDP tunneling configuration. + * + * @return + * - (0) if successful. + * - (-ENODEV) if port identifier is invalid. + * - (-ENOTSUP) if hardware doesn't support tunnel type. + */ +int +rte_eth_dev_udp_tunnel_add(uint8_t port_id, + struct rte_eth_udp_tunnel *tunnel_udp); + + /** + * Detete UDP tunneling port configuration of Ethernet device + * + * @param port_id + * The port identifier of the Ethernet device. + * @param tunnel_udp + * UDP tunneling configuration. + * + * @return + * - (0) if successful. + * - (-ENODEV) if port identifier is invalid. + * - (-ENOTSUP) if hardware doesn't support tunnel type. + */ +int +rte_eth_dev_udp_tunnel_delete(uint8_t port_id, + struct rte_eth_udp_tunnel *tunnel_udp); + /** * add syn filter * -- 2.20.1