From e50ed58a1f4218a905cde2bcd87132c2c8e70fd3 Mon Sep 17 00:00:00 2001 From: Guoshuai Li Date: Fri, 2 Feb 2018 10:50:29 +0800 Subject: ovn-controller: Process logical flow matches before actions. Otherwise, when the match field has "is_chassis_resident", and the match is not actually resident, and the action has meter or group, the group/meter ID is assigned even though it will never be used. Signed-off-by: Guoshuai Li Signed-off-by: Ben Pfaff --- ovn/controller/lflow.c | 60 ++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'ovn') diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c index 1e79a5355..df125b188 100644 --- a/ovn/controller/lflow.c +++ b/ovn/controller/lflow.c @@ -254,31 +254,6 @@ consider_logical_flow(struct controller_ctx *ctx, return; } - /* Encode OVN logical actions into OpenFlow. */ - uint64_t ofpacts_stub[1024 / 8]; - struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub); - struct lookup_port_aux aux = { - .ovnsb_idl = ctx->ovnsb_idl, - .dp = lflow->logical_datapath - }; - struct ovnact_encode_params ep = { - .lookup_port = lookup_port_cb, - .aux = &aux, - .is_switch = is_switch(ldp), - .is_gateway_router = is_gateway_router(ldp, local_datapaths), - .group_table = group_table, - .meter_table = meter_table, - - .pipeline = ingress ? OVNACT_P_INGRESS : OVNACT_P_EGRESS, - .ingress_ptable = OFTABLE_LOG_INGRESS_PIPELINE, - .egress_ptable = OFTABLE_LOG_EGRESS_PIPELINE, - .output_ptable = output_ptable, - .mac_bind_ptable = OFTABLE_MAC_BINDING, - }; - ovnacts_encode(ovnacts.data, ovnacts.size, &ep, &ofpacts); - ovnacts_free(ovnacts.data, ovnacts.size); - ofpbuf_uninit(&ovnacts); - /* Translate OVN match into table of OpenFlow matches. */ struct hmap matches; struct expr *expr; @@ -296,11 +271,16 @@ consider_logical_flow(struct controller_ctx *ctx, VLOG_WARN_RL(&rl, "error parsing match \"%s\": %s", lflow->match, error); expr_destroy(prereqs); - ofpbuf_uninit(&ofpacts); free(error); + ovnacts_free(ovnacts.data, ovnacts.size); + ofpbuf_uninit(&ovnacts); return; } + struct lookup_port_aux aux = { + .ovnsb_idl = ctx->ovnsb_idl, + .dp = lflow->logical_datapath + }; struct condition_aux cond_aux = { ctx->ovnsb_idl, chassis, active_tunnels, chassis_index}; expr = expr_simplify(expr, is_chassis_resident_cb, &cond_aux); @@ -309,6 +289,34 @@ consider_logical_flow(struct controller_ctx *ctx, &matches); expr_destroy(expr); + if (hmap_is_empty(&matches)) { + ovnacts_free(ovnacts.data, ovnacts.size); + ofpbuf_uninit(&ovnacts); + expr_matches_destroy(&matches); + return; + } + + /* Encode OVN logical actions into OpenFlow. */ + uint64_t ofpacts_stub[1024 / 8]; + struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub); + struct ovnact_encode_params ep = { + .lookup_port = lookup_port_cb, + .aux = &aux, + .is_switch = is_switch(ldp), + .is_gateway_router = is_gateway_router(ldp, local_datapaths), + .group_table = group_table, + .meter_table = meter_table, + + .pipeline = ingress ? OVNACT_P_INGRESS : OVNACT_P_EGRESS, + .ingress_ptable = OFTABLE_LOG_INGRESS_PIPELINE, + .egress_ptable = OFTABLE_LOG_EGRESS_PIPELINE, + .output_ptable = output_ptable, + .mac_bind_ptable = OFTABLE_MAC_BINDING, + }; + ovnacts_encode(ovnacts.data, ovnacts.size, &ep, &ofpacts); + ovnacts_free(ovnacts.data, ovnacts.size); + ofpbuf_uninit(&ovnacts); + /* Prepare the OpenFlow matches for adding to the flow table. */ struct expr_match *m; HMAP_FOR_EACH (m, hmap_node, &matches) { -- cgit v1.2.1