[ovs-dev] [patch net-next 11/13] sw_flow: add misc section to key with in_port_ifindex field

Jiri Pirko jiri at resnulli.us
Wed Sep 3 09:24:58 UTC 2014


Signed-off-by: Jiri Pirko <jiri at resnulli.us>
---
 include/net/sw_flow.h        |  3 +++
 net/openvswitch/hw_offload.c | 22 ++++++++++++++++++++++
 net/switchdev/switchdev.c    |  2 ++
 3 files changed, 27 insertions(+)

diff --git a/include/net/sw_flow.h b/include/net/sw_flow.h
index 3af7758..a144d8e 100644
--- a/include/net/sw_flow.h
+++ b/include/net/sw_flow.h
@@ -69,6 +69,9 @@ struct sw_flow_key {
 			} nd;
 		} ipv6;
 	};
+	struct {
+		u32	in_port_ifindex; /* Input switch port ifindex (or 0). */
+	} misc;
 } __aligned(BITS_PER_LONG/8); /* Ensure that we can do comparisons as longs. */
 
 struct sw_flow_key_range {
diff --git a/net/openvswitch/hw_offload.c b/net/openvswitch/hw_offload.c
index 45a0c5f..5c3edd0 100644
--- a/net/openvswitch/hw_offload.c
+++ b/net/openvswitch/hw_offload.c
@@ -83,6 +83,24 @@ errout:
 	return err;
 }
 
+void ovs_hw_flow_adjust(struct datapath *dp, struct ovs_flow *flow)
+{
+	struct vport *vport;
+
+	flow->flow.key.misc.in_port_ifindex = 0;
+	flow->flow.mask->key.misc.in_port_ifindex = 0;
+	vport = ovs_vport_ovsl(dp, flow->flow.key.phy.in_port);
+	if (vport && vport->ops->type == OVS_VPORT_TYPE_NETDEV) {
+		struct net_device *dev;
+
+		dev = vport->ops->get_netdev(vport);
+		if (dev) {
+			flow->flow.key.misc.in_port_ifindex = dev->ifindex;
+			flow->flow.mask->key.misc.in_port_ifindex = 0xFFFFFFFF;
+		}
+	}
+}
+
 int ovs_hw_flow_insert(struct datapath *dp, struct ovs_flow *flow)
 {
 	struct sw_flow_actions *actions;
@@ -93,6 +111,8 @@ int ovs_hw_flow_insert(struct datapath *dp, struct ovs_flow *flow)
 	ASSERT_OVSL();
 	BUG_ON(flow->flow.actions);
 
+	ovs_hw_flow_adjust(dp, flow);
+
 	err = sw_flow_action_create(dp, &actions, flow->sf_acts);
 	if (err)
 		return err;
@@ -124,6 +144,8 @@ int ovs_hw_flow_remove(struct datapath *dp, struct ovs_flow *flow)
 
 	ASSERT_OVSL();
 
+	ovs_hw_flow_adjust(dp, flow);
+
 	if (!flow->flow.actions) {
 		err = sw_flow_action_create(dp, &actions, flow->sf_acts);
 		if (err)
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index e079707..05acb0b 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -129,6 +129,8 @@ static void print_flow(const struct sw_flow *flow, struct net_device *dev,
 	print_flow_key_ip(PREFIX_MASK, &flow->mask->key);
 	print_flow_key_ipv4(PREFIX_NONE, &flow->key);
 	print_flow_key_ipv4(PREFIX_MASK, &flow->mask->key);
+	print_flow_key_misc(PREFIX_NONE, &flow->key);
+	print_flow_key_misc(PREFIX_MASK, &flow->mask->key);
 	print_flow_actions(flow->actions);
 }
 
-- 
1.9.3




More information about the dev mailing list