From 39cc5c4adea207465e88d309dedf61990201301b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 4 Jan 2016 11:36:14 -0800 Subject: Use initializers for struct ofputil_flow_mod instead of assignments. A few bugs have been fixed lately that were related to struct ofputil_flow_mod not being fully initialized in a few places. This commit changes several pieces of code from using individual assignments to fields in struct ofputil_flow_mod, to using whole initializers or assignments to a whole struct. This should help prevent similar problems in the future. CC: Ilya Maximets Signed-off-by: Ben Pfaff Acked-by: Russell Bryant --- lib/ofp-parse.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'lib/ofp-parse.c') diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index fdc30d9b7..c346f102b 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. + * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -332,27 +332,21 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string, OVS_NOT_REACHED(); } - match_init_catchall(&fm->match); - fm->priority = OFP_DEFAULT_PRIORITY; - fm->cookie = htonll(0); - fm->cookie_mask = htonll(0); + *fm = (struct ofputil_flow_mod) { + .match = MATCH_CATCHALL_INITIALIZER, + .priority = OFP_DEFAULT_PRIORITY, + .table_id = 0xff, + .command = command, + .buffer_id = UINT32_MAX, + .out_port = OFPP_ANY, + .out_group = OFPG_ANY, + .delete_reason = OFPRR_DELETE, + }; + /* For modify, by default, don't update the cookie. */ if (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT) { - /* For modify, by default, don't update the cookie. */ fm->new_cookie = OVS_BE64_MAX; - } else{ - fm->new_cookie = htonll(0); } - fm->modify_cookie = false; - fm->table_id = 0xff; - fm->command = command; - fm->idle_timeout = OFP_FLOW_PERMANENT; - fm->hard_timeout = OFP_FLOW_PERMANENT; - fm->buffer_id = UINT32_MAX; - fm->out_port = OFPP_ANY; - fm->flags = 0; - fm->importance = 0; - fm->out_group = OFPG_ANY; - fm->delete_reason = OFPRR_DELETE; + if (fields & F_ACTIONS) { act_str = extract_actions(string); if (!act_str) { -- cgit v1.2.1