Re: [ovs-dev] [PATCH OVS v3 4/4] ovs-tc: offload datapath rules matching on internal ports

2019-04-10 Thread Roi Dayan



On 09/04/2019 17:36, John Hurley wrote:
> Rules applied to OvS internal ports are not represented in TC datapaths.
> However, it is possible to support rules matching on internal ports in TC.
> The start_xmit ndo of OvS internal ports directs packets back into the OvS
> kernel datapath where they are rematched with the ingress port now being
> that of the internal port. Due to this, rules matching on an internal port
> can be added as TC filters to an egress qdisc for these ports.
> 
> Allow rules applied to internal ports to be offloaded to TC as egress
> filters. Rules redirecting to an internal port are also offloaded. These
> are supported by the redirect ingress functionality applied in an earlier
> patch.
> 
> Signed-off-by: John Hurley 
> ---
>  lib/dpif.c   | 13 +
>  lib/netdev-linux.c   |  1 +
>  lib/netdev-tc-offloads.c | 41 +
>  3 files changed, 35 insertions(+), 20 deletions(-)
> 
> diff --git a/lib/dpif.c b/lib/dpif.c
> index 457c9bf..063ba20 100644
> --- a/lib/dpif.c
> +++ b/lib/dpif.c
> @@ -101,12 +101,9 @@ static bool should_log_flow_message(const struct 
> vlog_module *module,
>  struct seq *tnl_conf_seq;
>  
>  static bool
> -dpif_is_internal_port(const char *type)
> +dpif_is_tap_port(const char *type)
>  {
> -/* For userspace datapath, tap devices are the equivalent
> - * of internal devices in the kernel datapath, so both
> - * these types are 'internal' devices. */
> -return !strcmp(type, "internal") || !strcmp(type, "tap");
> +return !strcmp(type, "tap");
>  }
>  
>  static void
> @@ -359,7 +356,7 @@ do_open(const char *name, const char *type, bool create, 
> struct dpif **dpifp)
>  struct netdev *netdev;
>  int err;
>  
> -if (dpif_is_internal_port(dpif_port.type)) {
> +if (dpif_is_tap_port(dpif_port.type)) {
>  continue;
>  }
>  
> @@ -434,7 +431,7 @@ dpif_remove_netdev_ports(struct dpif *dpif) {
>  struct dpif_port dpif_port;
>  
>  DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) {
> -if (!dpif_is_internal_port(dpif_port.type)) {
> +if (!dpif_is_tap_port(dpif_port.type)) {
>  netdev_ports_remove(dpif_port.port_no, dpif->dpif_class);
>  }
>  }
> @@ -582,7 +579,7 @@ dpif_port_add(struct dpif *dpif, struct netdev *netdev, 
> odp_port_t *port_nop)
>  VLOG_DBG_RL(&dpmsg_rl, "%s: added %s as port %"PRIu32,
>  dpif_name(dpif), netdev_name, port_no);
>  
> -if (!dpif_is_internal_port(netdev_get_type(netdev))) {
> +if (!dpif_is_tap_port(netdev_get_type(netdev))) {
>  
>  struct dpif_port dpif_port;
>  
> diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> index 87337e0..776d938 100644
> --- a/lib/netdev-linux.c
> +++ b/lib/netdev-linux.c
> @@ -3340,6 +3340,7 @@ const struct netdev_class netdev_tap_class = {
>  
>  const struct netdev_class netdev_internal_class = {
>  NETDEV_LINUX_CLASS_COMMON,
> +LINUX_FLOW_OFFLOAD_API,
>  .type = "internal",
>  .construct = netdev_linux_construct,
>  .get_stats = netdev_internal_get_stats,
> diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
> index 634c9b9..d5c66ac 100644
> --- a/lib/netdev-tc-offloads.c
> +++ b/lib/netdev-tc-offloads.c
> @@ -59,6 +59,12 @@ is_internal_port(const char *type)
>  return !strcmp(type, "internal");
>  }
>  
> +static enum tc_qdisc_hook
> +get_tc_qdisc_hook(struct netdev *netdev)
> +{
> +return is_internal_port(netdev_get_type(netdev)) ? TC_EGRESS : 
> TC_INGRESS;
> +}
> +
>  static struct netlink_field set_flower_map[][4] = {
>  [OVS_KEY_ATTR_IPV4] = {
>  { offsetof(struct ovs_key_ipv4, ipv4_src),
> @@ -185,11 +191,12 @@ del_ufid_tc_mapping(const ovs_u128 *ufid)
>  /* Wrapper function to delete filter and ufid tc mapping */
>  static int
>  del_filter_and_ufid_mapping(int ifindex, int prio, int handle,
> -uint32_t block_id, const ovs_u128 *ufid)
> +uint32_t block_id, const ovs_u128 *ufid,
> +enum tc_qdisc_hook hook)
>  {
>  int err;
>  
> -err = tc_del_filter(ifindex, prio, handle, block_id, TC_INGRESS);
> +err = tc_del_filter(ifindex, prio, handle, block_id, hook);
>  del_ufid_tc_mapping(ufid);
>  
>  return err;
> @@ -346,6 +353,7 @@ get_block_id_from_netdev(struct netdev *netdev)
>  int
>  netdev_tc_flow_flush(struct netdev *netdev)
>  {
> +enum tc_qdisc_hook hook = get_tc_qdisc_hook(netdev);
>  int ifindex = netdev_get_ifindex(netdev);
>  uint32_t block_id = 0;
>  
> @@ -357,13 +365,14 @@ netdev_tc_flow_flush(struct netdev *netdev)
>  
>  block_id = get_block_id_from_netdev(netdev);
>  
> -return tc_flush(ifindex, block_id, TC_INGRESS);
> +return tc_flush(ifindex, block_id, hook);
>  }
>  
>  int
>  netdev_tc_flow_dump_create(struct netdev *net

[ovs-dev] [PATCH OVS v3 4/4] ovs-tc: offload datapath rules matching on internal ports

2019-04-09 Thread John Hurley
Rules applied to OvS internal ports are not represented in TC datapaths.
However, it is possible to support rules matching on internal ports in TC.
The start_xmit ndo of OvS internal ports directs packets back into the OvS
kernel datapath where they are rematched with the ingress port now being
that of the internal port. Due to this, rules matching on an internal port
can be added as TC filters to an egress qdisc for these ports.

Allow rules applied to internal ports to be offloaded to TC as egress
filters. Rules redirecting to an internal port are also offloaded. These
are supported by the redirect ingress functionality applied in an earlier
patch.

Signed-off-by: John Hurley 
---
 lib/dpif.c   | 13 +
 lib/netdev-linux.c   |  1 +
 lib/netdev-tc-offloads.c | 41 +
 3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/lib/dpif.c b/lib/dpif.c
index 457c9bf..063ba20 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -101,12 +101,9 @@ static bool should_log_flow_message(const struct 
vlog_module *module,
 struct seq *tnl_conf_seq;
 
 static bool
-dpif_is_internal_port(const char *type)
+dpif_is_tap_port(const char *type)
 {
-/* For userspace datapath, tap devices are the equivalent
- * of internal devices in the kernel datapath, so both
- * these types are 'internal' devices. */
-return !strcmp(type, "internal") || !strcmp(type, "tap");
+return !strcmp(type, "tap");
 }
 
 static void
@@ -359,7 +356,7 @@ do_open(const char *name, const char *type, bool create, 
struct dpif **dpifp)
 struct netdev *netdev;
 int err;
 
-if (dpif_is_internal_port(dpif_port.type)) {
+if (dpif_is_tap_port(dpif_port.type)) {
 continue;
 }
 
@@ -434,7 +431,7 @@ dpif_remove_netdev_ports(struct dpif *dpif) {
 struct dpif_port dpif_port;
 
 DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) {
-if (!dpif_is_internal_port(dpif_port.type)) {
+if (!dpif_is_tap_port(dpif_port.type)) {
 netdev_ports_remove(dpif_port.port_no, dpif->dpif_class);
 }
 }
@@ -582,7 +579,7 @@ dpif_port_add(struct dpif *dpif, struct netdev *netdev, 
odp_port_t *port_nop)
 VLOG_DBG_RL(&dpmsg_rl, "%s: added %s as port %"PRIu32,
 dpif_name(dpif), netdev_name, port_no);
 
-if (!dpif_is_internal_port(netdev_get_type(netdev))) {
+if (!dpif_is_tap_port(netdev_get_type(netdev))) {
 
 struct dpif_port dpif_port;
 
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 87337e0..776d938 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -3340,6 +3340,7 @@ const struct netdev_class netdev_tap_class = {
 
 const struct netdev_class netdev_internal_class = {
 NETDEV_LINUX_CLASS_COMMON,
+LINUX_FLOW_OFFLOAD_API,
 .type = "internal",
 .construct = netdev_linux_construct,
 .get_stats = netdev_internal_get_stats,
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 634c9b9..d5c66ac 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -59,6 +59,12 @@ is_internal_port(const char *type)
 return !strcmp(type, "internal");
 }
 
+static enum tc_qdisc_hook
+get_tc_qdisc_hook(struct netdev *netdev)
+{
+return is_internal_port(netdev_get_type(netdev)) ? TC_EGRESS : TC_INGRESS;
+}
+
 static struct netlink_field set_flower_map[][4] = {
 [OVS_KEY_ATTR_IPV4] = {
 { offsetof(struct ovs_key_ipv4, ipv4_src),
@@ -185,11 +191,12 @@ del_ufid_tc_mapping(const ovs_u128 *ufid)
 /* Wrapper function to delete filter and ufid tc mapping */
 static int
 del_filter_and_ufid_mapping(int ifindex, int prio, int handle,
-uint32_t block_id, const ovs_u128 *ufid)
+uint32_t block_id, const ovs_u128 *ufid,
+enum tc_qdisc_hook hook)
 {
 int err;
 
-err = tc_del_filter(ifindex, prio, handle, block_id, TC_INGRESS);
+err = tc_del_filter(ifindex, prio, handle, block_id, hook);
 del_ufid_tc_mapping(ufid);
 
 return err;
@@ -346,6 +353,7 @@ get_block_id_from_netdev(struct netdev *netdev)
 int
 netdev_tc_flow_flush(struct netdev *netdev)
 {
+enum tc_qdisc_hook hook = get_tc_qdisc_hook(netdev);
 int ifindex = netdev_get_ifindex(netdev);
 uint32_t block_id = 0;
 
@@ -357,13 +365,14 @@ netdev_tc_flow_flush(struct netdev *netdev)
 
 block_id = get_block_id_from_netdev(netdev);
 
-return tc_flush(ifindex, block_id, TC_INGRESS);
+return tc_flush(ifindex, block_id, hook);
 }
 
 int
 netdev_tc_flow_dump_create(struct netdev *netdev,
struct netdev_flow_dump **dump_out)
 {
+enum tc_qdisc_hook hook = get_tc_qdisc_hook(netdev);
 struct netdev_flow_dump *dump;
 uint32_t block_id = 0;
 int ifindex;
@@ -379,7 +388,7 @@ netdev_tc_flow_dump_create(struct netdev *netdev,
 dump = xzalloc(size