[ovs-dev] [PATCH 07/25] ofp-util: Reduce scope of variables in ofputil_encode_flow_mod()
Simon Horman
horms at verge.net.au
Thu Jun 14 10:43:19 UTC 2012
Reduce scope of per-protocol variables in ofputil_encode_flow_mod()
These variables are only needed in one of the cases covered by the switch
statement and will increase in number as more cases (protocols) are
supported.
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v2
* No change
---
lib/ofp-util.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index eaf7b04..4219979 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1727,11 +1727,8 @@ struct ofpbuf *
ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
enum ofputil_protocol protocol)
{
- struct ofp10_flow_mod *ofm;
- struct nx_flow_mod *nfm;
struct ofpbuf *msg;
uint16_t command;
- int match_len;
command = (protocol & OFPUTIL_P_TID
? (fm->command & 0xff) | (fm->table_id << 8)
@@ -1739,7 +1736,9 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
switch (protocol) {
case OFPUTIL_P_OF10:
- case OFPUTIL_P_OF10_TID:
+ case OFPUTIL_P_OF10_TID: {
+ struct ofp10_flow_mod *ofm;
+
msg = ofpbuf_new(sizeof *ofm + fm->ofpacts_len);
ofm = put_openflow(sizeof *ofm, OFPT10_FLOW_MOD, msg);
ofputil_cls_rule_to_ofp10_match(&fm->cr, &ofm->match);
@@ -1752,9 +1751,13 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
ofm->out_port = htons(fm->out_port);
ofm->flags = htons(fm->flags);
break;
+ }
case OFPUTIL_P_NXM:
- case OFPUTIL_P_NXM_TID:
+ case OFPUTIL_P_NXM_TID: {
+ struct nx_flow_mod *nfm;
+ int match_len;
+
msg = ofpbuf_new(sizeof *nfm + NXM_TYPICAL_LEN + fm->ofpacts_len);
put_nxmsg(sizeof *nfm, NXT_FLOW_MOD, msg);
nfm = msg->data;
@@ -1770,6 +1773,7 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
nfm->flags = htons(fm->flags);
nfm->match_len = htons(match_len);
break;
+ }
default:
NOT_REACHED();
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list