diff mbox

[ovs-dev,3/3] ovn-northd: Ensure that flows are added to correct types of datapaths.

Message ID 1468944433-3515-4-git-send-email-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff July 19, 2016, 4:07 p.m. UTC
A DP_TYPE_SWITCH_* flow should only be added to a logical switch datapath,
and a DP_TYPE_ROUTER_* flow should only be added to a logical router
datapath, but the code previously did not verify this and it caused a
problem in practice.

Suggested-by: Guru Shetty <guru@ovn.org>
Suggested-at: http://openvswitch.org/pipermail/dev/2016-July/075557.html
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 ovn/northd/ovn-northd.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Ben Pfaff July 20, 2016, 3:28 a.m. UTC | #1
On Tue, Jul 19, 2016 at 09:07:13AM -0700, Ben Pfaff wrote:
> A DP_TYPE_SWITCH_* flow should only be added to a logical switch datapath,
> and a DP_TYPE_ROUTER_* flow should only be added to a logical router
> datapath, but the code previously did not verify this and it caused a
> problem in practice.
> 
> Suggested-by: Guru Shetty <guru@ovn.org>
> Suggested-at: http://openvswitch.org/pipermail/dev/2016-July/075557.html
> Signed-off-by: Ben Pfaff <blp@ovn.org>

I applied this one because there's no change from the version you
previous acked.

I'll wait for a little while on the others in case there are comments.
diff mbox

Patch

diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 8418f53..9bb06a5 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -175,6 +175,20 @@  ovn_stage_to_str(enum ovn_stage stage)
         default: return "<unknown>";
     }
 }
+
+/* Returns the type of the datapath to which a flow with the given 'stage' may
+ * be added. */
+static enum ovn_datapath_type
+ovn_stage_to_datapath_type(enum ovn_stage stage)
+{
+    switch (stage) {
+#define PIPELINE_STAGE(DP_TYPE, PIPELINE, STAGE, TABLE, NAME)       \
+        case S_##DP_TYPE##_##PIPELINE##_##STAGE: return DP_##DP_TYPE;
+    PIPELINE_STAGES
+#undef PIPELINE_STAGE
+    default: OVS_NOT_REACHED();
+    }
+}
 
 static void
 usage(void)
@@ -303,6 +317,13 @@  ovn_datapath_destroy(struct hmap *datapaths, struct ovn_datapath *od)
     }
 }
 
+/* Returns 'od''s datapath type. */
+static enum ovn_datapath_type
+ovn_datapath_get_type(const struct ovn_datapath *od)
+{
+    return od->nbs ? DP_SWITCH : DP_ROUTER;
+}
+
 static struct ovn_datapath *
 ovn_datapath_find(struct hmap *datapaths, const struct uuid *uuid)
 {
@@ -1006,6 +1027,8 @@  ovn_lflow_add(struct hmap *lflow_map, struct ovn_datapath *od,
               enum ovn_stage stage, uint16_t priority,
               const char *match, const char *actions)
 {
+    ovs_assert(ovn_stage_to_datapath_type(stage) == ovn_datapath_get_type(od));
+
     struct ovn_lflow *lflow = xmalloc(sizeof *lflow);
     ovn_lflow_init(lflow, od, stage, priority,
                    xstrdup(match), xstrdup(actions));