Skip to contentSkip to conversation

openvswitch: add ct_clear action

PATCH Superseded Eric Garver 5 participants 9 messages Oct 6, 2017 – Oct 10, 2017 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openvswitch: add ct_clear action

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
 	OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
 	OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
 	OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+	OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
 	__OVS_ACTION_ATTR_MAX,	      /* Nothing past this will be accepted
 				       * from userspace. */
net/openvswitch/actions.c +5 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
 				return err == -EINPROGRESS ? 0 : err;
 			break;
 
+		case OVS_ACTION_ATTR_CT_CLEAR:
+			err = ovs_ct_clear(skb, key);
+			break;
+
 		case OVS_ACTION_ATTR_PUSH_ETH:
 			err = push_eth(skb, key, nla_data(a));
 			break;
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
 		case OVS_ACTION_ATTR_POP_ETH:
 			err = pop_eth(skb, key);
 			break;
+
 		}
 
 		if (unlikely(err)) {
net/openvswitch/conntrack.c +12 -0
index d558e882ca0c..f9b73c726ad7 100644
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
 	return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+	if (skb_nfct(skb)) {
+		nf_conntrack_put(skb_nfct(skb));
+		nf_ct_set(skb, NULL, 0);
+	}
+
+	ovs_ct_fill_key(skb, key);
+
+	return 0;
+}
+
 static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
 			     const struct sw_flow_key *key, bool log)
 {
net/openvswitch/conntrack.h +7 -0
index bc7efd1867ab..399dfdd2c4f9 100644
@@ -30,6 +30,7 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *, struct sk_buff *);
 
 int ovs_ct_execute(struct net *, struct sk_buff *, struct sw_flow_key *,
 		   const struct ovs_conntrack_info *);
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key);
 
 void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key);
 int ovs_ct_put_key(const struct sw_flow_key *swkey,
@@ -73,6 +74,12 @@ static inline int ovs_ct_execute(struct net *net, struct sk_buff *skb,
 	return -ENOTSUPP;
 }
 
+static inline int ovs_ct_clear(struct sk_buff *skb,
+			       struct sw_flow_key *key)
+{
+	return -ENOTSUPP;
+}
+
 static inline void ovs_ct_fill_key(const struct sk_buff *skb,
 				   struct sw_flow_key *key)
 {
net/openvswitch/flow_netlink.c +5 -0
index e8eb427ce6d1..198bb828d592 100644
@@ -75,6 +75,7 @@ static bool actions_may_change_flow(const struct nlattr *actions)
 			break;
 
 		case OVS_ACTION_ATTR_CT:
+		case OVS_ACTION_ATTR_CT_CLEAR:
 		case OVS_ACTION_ATTR_HASH:
 		case OVS_ACTION_ATTR_POP_ETH:
 		case OVS_ACTION_ATTR_POP_MPLS:
@@ -2479,6 +2480,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
 			[OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
 			[OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
 			[OVS_ACTION_ATTR_CT] = (u32)-1,
+			[OVS_ACTION_ATTR_CT_CLEAR] = 0,
 			[OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
 			[OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
 			[OVS_ACTION_ATTR_POP_ETH] = 0,
@@ -2620,6 +2622,9 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
 			skip_copy = true;
 			break;
 
+		case OVS_ACTION_ATTR_CT_CLEAR:
+			break;
+
 		case OVS_ACTION_ATTR_PUSH_ETH:
 			/* Disallow pushing an Ethernet header if one
 			 * is already present */
Signature · 1 line
2.12.0
maintainer
#1 lore raw

From: Eric Garver <[email protected]>
Date: Fri, 6 Oct 2017 12:44:26 -0400

Quoted 6 lines

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Pravin et al., this needs your review.

Thanks.

#2 lore raw
In reply to Eric Garver
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Quoted 6 lines
net/openvswitch/conntrack.c +3 -0
+       return 0;
+}
+
 static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
                             const struct sw_flow_key *key, bool log)
 {
#3 lore raw
Quoted 77 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

Quoted 5 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Really this is trying to just zero the CT key fields, but reuses existing functions, right? This means that subsequent upcalls, for instance, won't have the outdated view of the CT state from the previous lookup (that was prior to the ct_clear). I'd expect these key fields to be cleared.

#9 lore raw
In reply to a message not in the archive
Quoted 8 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Thanks for the review Pravin!

Quoted 36 lines
Quoted 36 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +0 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
Quoted 15 lines

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 13 lines
net/openvswitch/actions.c +5 -0
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Right. Not sure how that got there. :/

Quoted 10 lines
Quoted 10 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
Quoted 7 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 5 lines
net/openvswitch/conntrack.c +5 -0
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

I think that will be fine. I'll run my tests again to verify.

Quoted 6 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Good point.

Quoted 6 lines
Quoted 6 lines
net/openvswitch/conntrack.c +3 -0
+       return 0;
+}
+
 static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
                             const struct sw_flow_key *key, bool log)
 {
#4 lore raw
In reply to Joe Stringer
Quoted 78 lines · Joe Stringer
Quoted 77 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

Quoted 8 lines
Quoted 5 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Really this is trying to just zero the CT key fields, but reuses existing functions, right? This means that subsequent upcalls, for

Right.

Quoted 3 lines

instance, won't have the outdated view of the CT state from the previous lookup (that was prior to the ct_clear). I'd expect these key fields to be cleared.

I assumed Pravin was saying that we don't need to clear them if there is no conntrack state. They should already be zero.

#5 lore raw
Quoted 88 lines · Eric Garver
Quoted 78 lines · Joe Stringer
Quoted 77 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

Quoted 8 lines
Quoted 5 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Really this is trying to just zero the CT key fields, but reuses existing functions, right? This means that subsequent upcalls, for

Quoted 8 lines

Right.

Quoted 3 lines

instance, won't have the outdated view of the CT state from the previous lookup (that was prior to the ct_clear). I'd expect these key fields to be cleared.

I assumed Pravin was saying that we don't need to clear them if there is no conntrack state. They should already be zero.

The conntrack calls aren't going to clear it, so I don't see what else would clear it?

If you execute ct(),ct_clear(), then the first ct will set the values.. what will zero them?

#6 lore raw
Quoted 95 lines · Joe Stringer
Quoted 94 lines · Eric Garver
Quoted 78 lines · Joe Stringer
Quoted 77 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

Quoted 8 lines
Quoted 5 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Really this is trying to just zero the CT key fields, but reuses existing functions, right? This means that subsequent upcalls, for

Right.

Quoted 3 lines

instance, won't have the outdated view of the CT state from the previous lookup (that was prior to the ct_clear). I'd expect these key fields to be cleared.

Quoted 8 lines
Quoted 2 lines

I assumed Pravin was saying that we don't need to clear them if there is no conntrack state. They should already be zero.

The conntrack calls aren't going to clear it, so I don't see what else would clear it?

If you execute ct(),ct_clear(), then the first ct will set the values.. what will zero them?

I meant move ovs_ct_fill_key() to inside the if statement. i.e.

       if (skb_nfct(skb)) {
               nf_conntrack_put(skb_nfct(skb));
               nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
               ovs_ct_fill_key(skb, key);
       }

Should be nothing to fill/zero if we have not yet done conntrack. Is there a case where we may lose skb->_nfct, but the key still has conntrack data?

#7 lore raw
Quoted 114 lines · Eric Garver
Quoted 95 lines · Joe Stringer
Quoted 94 lines · Eric Garver
Quoted 78 lines · Joe Stringer
Quoted 77 lines · Pravin Shelar
Quoted 6 lines · Eric Garver

This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred.

Patch mostly looks good. I have following comments.

Quoted 44 lines
---
 include/uapi/linux/openvswitch.h |  2 ++
 net/openvswitch/actions.c        |  5 +++++
 net/openvswitch/conntrack.c      | 12 ++++++++++++
 net/openvswitch/conntrack.h      |  7 +++++++
 net/openvswitch/flow_netlink.c   |  5 +++++
 5 files changed, 31 insertions(+)
include/uapi/linux/openvswitch.h +2 -0
index 156ee4cab82e..1b6e510e2cc6 100644
@@ -806,6 +806,7 @@ struct ovs_action_push_eth {
  * packet.
  * @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
  * packet.
+ * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -835,6 +836,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_TRUNC,        /* u32 struct ovs_action_trunc. */
        OVS_ACTION_ATTR_PUSH_ETH,     /* struct ovs_action_push_eth. */
        OVS_ACTION_ATTR_POP_ETH,      /* No argument. */
+       OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
net/openvswitch/actions.c +4 -0
index a54a556fcdb5..db9c7f2e662b 100644
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                                return err == -EINPROGRESS ? 0 : err;
                        break;
 
+               case OVS_ACTION_ATTR_CT_CLEAR:
+                       err = ovs_ct_clear(skb, key);
+                       break;
+
                case OVS_ACTION_ATTR_PUSH_ETH:
                        err = push_eth(skb, key, nla_data(a));
                        break;

net/openvswitch/actions.c static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · line 1218

Quoted 5 lines
net/openvswitch/actions.c +1 -0
@@ -1210,6 +1214,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_ETH:
                        err = pop_eth(skb, key);
                        break;
+
                }

Unrelated change.

Quoted 7 lines
net/openvswitch/actions.c +0 -0
                if (unlikely(err)) {
net/openvswitch/conntrack.c +0 -0
index d558e882ca0c..f9b73c726ad7 100644

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1136

Quoted 8 lines
net/openvswitch/conntrack.c +5 -0
@@ -1129,6 +1129,18 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
        return err;
 }
 
+int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       if (skb_nfct(skb)) {
+               nf_conntrack_put(skb_nfct(skb));
+               nf_ct_set(skb, NULL, 0);

Can the new conntract state be appropriate? may be IP_CT_UNTRACKED?

Quoted 8 lines
Quoted 5 lines

net/openvswitch/conntrack.c int ovs_ct_execute(struct net *net, struct sk_buff *skb, · line 1140

Quoted 4 lines
net/openvswitch/conntrack.c +4 -0
+       }
+
+       ovs_ct_fill_key(skb, key);
+

I do not see need to refill the key if there is no skb-nf-ct.

Really this is trying to just zero the CT key fields, but reuses existing functions, right? This means that subsequent upcalls, for

Right.

Quoted 3 lines

instance, won't have the outdated view of the CT state from the previous lookup (that was prior to the ct_clear). I'd expect these key fields to be cleared.

Quoted 8 lines
Quoted 2 lines

I assumed Pravin was saying that we don't need to clear them if there is no conntrack state. They should already be zero.

The conntrack calls aren't going to clear it, so I don't see what else would clear it?

If you execute ct(),ct_clear(), then the first ct will set the values.. what will zero them?

I meant move ovs_ct_fill_key() to inside the if statement. i.e.

       if (skb_nfct(skb)) {
               nf_conntrack_put(skb_nfct(skb));
               nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
               ovs_ct_fill_key(skb, key);
       }
Quoted 3 lines

Should be nothing to fill/zero if we have not yet done conntrack. Is there a case where we may lose skb->_nfct, but the key still has conntrack data?

Ah, misreading on my part. Right, if there is no nfct then it should already have the right value. I don't think there's a way to lose it and leave the key with conntrack data.