diff mbox

[ovs-dev,2/2] datapath: Only set mark and labels with a commit flag.

Message ID 1467207330-4730-2-git-send-email-jarno@ovn.org
State Accepted
Headers show

Commit Message

Jarno Rajahalme June 29, 2016, 1:35 p.m. UTC
Upstream commit:
    commit 7d904c7bcd51f72579c0c3134a50896c5a3efb9f
    Author: Jarno Rajahalme <jarno@ovn.org>
    Date:   Tue Jun 21 14:59:38 2016 -0700

    openvswitch: Only set mark and labels with a commit flag.

    Only set conntrack mark or labels when the commit flag is specified.
    This makes sure we can not set them before the connection has been
    persisted, as in that case the mark and labels would be lost in an
    event of an userspace upcall.

    OVS userspace already requires the commit flag to accept setting
    ct_mark and/or ct_labels.  Validate for this in the kernel API.

    Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 datapath/conntrack.c | 76 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 51 insertions(+), 25 deletions(-)

Comments

Joe Stringer June 29, 2016, 2:14 p.m. UTC | #1
On 29 June 2016 at 15:35, Jarno Rajahalme <jarno@ovn.org> wrote:
> Upstream commit:
>     commit 7d904c7bcd51f72579c0c3134a50896c5a3efb9f
>     Author: Jarno Rajahalme <jarno@ovn.org>
>     Date:   Tue Jun 21 14:59:38 2016 -0700
>
>     openvswitch: Only set mark and labels with a commit flag.
>
>     Only set conntrack mark or labels when the commit flag is specified.
>     This makes sure we can not set them before the connection has been
>     persisted, as in that case the mark and labels would be lost in an
>     event of an userspace upcall.
>
>     OVS userspace already requires the commit flag to accept setting
>     ct_mark and/or ct_labels.  Validate for this in the kernel API.
>
>     Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
>     Signed-off-by: David S. Miller <davem@davemloft.net>
>
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Acked-by: Joe Stringer <joe@ovn.org>
Pravin Shelar July 1, 2016, 6:37 p.m. UTC | #2
On Wed, Jun 29, 2016 at 7:14 AM, Joe Stringer <joe@ovn.org> wrote:
> On 29 June 2016 at 15:35, Jarno Rajahalme <jarno@ovn.org> wrote:
>> Upstream commit:
>>     commit 7d904c7bcd51f72579c0c3134a50896c5a3efb9f
>>     Author: Jarno Rajahalme <jarno@ovn.org>
>>     Date:   Tue Jun 21 14:59:38 2016 -0700
>>
>>     openvswitch: Only set mark and labels with a commit flag.
>>
>>     Only set conntrack mark or labels when the commit flag is specified.
>>     This makes sure we can not set them before the connection has been
>>     persisted, as in that case the mark and labels would be lost in an
>>     event of an userspace upcall.
>>
>>     OVS userspace already requires the commit flag to accept setting
>>     ct_mark and/or ct_labels.  Validate for this in the kernel API.
>>
>>     Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
>>     Signed-off-by: David S. Miller <davem@davemloft.net>
>>
>> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
>
> Acked-by: Joe Stringer <joe@ovn.org>

I pushed both patches to master.

The patch did not apply cleanly to 2.5, so I sent out branch-2.5 patch
for review.
diff mbox

Patch

diff --git a/datapath/conntrack.c b/datapath/conntrack.c
index 55f9867..9a79e73 100644
--- a/datapath/conntrack.c
+++ b/datapath/conntrack.c
@@ -879,6 +879,42 @@  static bool labels_nonzero(const struct ovs_key_ct_labels *labels)
 	return false;
 }
 
+/* Lookup connection and confirm if unconfirmed. */
+static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
+			 const struct ovs_conntrack_info *info,
+			 struct sk_buff *skb)
+{
+	int err;
+
+	err = __ovs_ct_lookup(net, key, info, skb);
+	if (err)
+		return err;
+
+	/* Apply changes before confirming the connection so that the initial
+	 * conntrack NEW netlink event carries the values given in the CT
+	 * action.
+	 */
+	if (info->mark.mask) {
+		err = ovs_ct_set_mark(skb, key, info->mark.value,
+				      info->mark.mask);
+		if (err)
+			return err;
+	}
+	if (labels_nonzero(&info->labels.mask)) {
+		err = ovs_ct_set_labels(skb, key, &info->labels.value,
+					&info->labels.mask);
+		if (err)
+			return err;
+	}
+	/* This will take care of sending queued events even if the connection
+	 * is already confirmed.
+	 */
+	if (nf_conntrack_confirm(skb) != NF_ACCEPT)
+		return -EINVAL;
+
+	return 0;
+}
+
 /* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
  * value if 'skb' is freed.
  */
@@ -900,34 +936,10 @@  int ovs_ct_execute(struct net *net, struct sk_buff *skb,
 	}
 
 	if (info->commit)
-		err = __ovs_ct_lookup(net, key, info, skb);
+		err = ovs_ct_commit(net, key, info, skb);
 	else
 		err = ovs_ct_lookup(net, key, info, skb);
-	if (err)
-		goto err;
 
-	/* Apply changes before confirming the connection so that the initial
-	 * conntrack NEW netlink event carries the values given in the CT
-	 * action.
-	 */
-	if (info->mark.mask) {
-		err = ovs_ct_set_mark(skb, key, info->mark.value,
-				      info->mark.mask);
-		if (err)
-			goto err;
-	}
-	if (labels_nonzero(&info->labels.mask)) {
-		err = ovs_ct_set_labels(skb, key, &info->labels.value,
-					&info->labels.mask);
-		if (err)
-			goto err;
-	}
-	/* This will take care of sending queued events even if the connection
-	 * is already confirmed.
-	 */
-	if (info->commit && nf_conntrack_confirm(skb) != NF_ACCEPT)
-		err = -EINVAL;
-err:
 	skb_push(skb, nh_ofs);
 	if (err)
 		kfree_skb(skb);
@@ -1189,6 +1201,20 @@  static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
 		}
 	}
 
+#ifdef CONFIG_NF_CONNTRACK_MARK
+	if (!info->commit && info->mark.mask) {
+		OVS_NLERR(log,
+			  "Setting conntrack mark requires 'commit' flag.");
+		return -EINVAL;
+	}
+#endif
+#ifdef CONFIG_NF_CONNTRACK_LABELS
+	if (!info->commit && labels_nonzero(&info->labels.mask)) {
+		OVS_NLERR(log,
+			  "Setting conntrack labels requires 'commit' flag.");
+		return -EINVAL;
+	}
+#endif
 	if (rem > 0) {
 		OVS_NLERR(log, "Conntrack attr has %d unknown bytes", rem);
 		return -EINVAL;