From 51c14ddd8df9617e641748a98ac52b78fd19290a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 18 Jun 2012 15:09:49 -0700 Subject: [PATCH] flow: Ensure that padding is always zeroed. Signed-off-by: Ben Pfaff --- lib/flow.h | 2 +- lib/ofp-util.c | 1 + tests/test-bundle.c | 1 + tests/test-classifier.c | 1 + tests/test-multipath.c | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/flow.h b/lib/flow.h index 406324ad..30cd044d 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -75,7 +75,7 @@ struct flow { uint8_t arp_tha[6]; /* ARP/ND target hardware address. */ uint8_t nw_ttl; /* IP TTL/Hop Limit. */ uint8_t nw_frag; /* FLOW_FRAG_* flags. */ - uint8_t reserved[2]; /* Reserved for 64-bit packing. */ + uint8_t zeros[2]; /* Must be zero. */ }; /* Represents the metadata fields of struct flow. */ diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 02615292..c120e0b6 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -138,6 +138,7 @@ ofputil_cls_rule_from_ofp10_match(const struct ofp10_match *match, uint32_t ofpfw = ntohl(match->wildcards) & OFPFW10_ALL; /* Initialize rule->priority, rule->wc. */ + memset(rule->flow.zeros, 0, sizeof rule->flow.zeros); rule->priority = !ofpfw ? UINT16_MAX : priority; ofputil_wildcard_from_ofpfw10(ofpfw, &rule->wc); diff --git a/tests/test-bundle.c b/tests/test-bundle.c index f2d9b824..aa8b6f0f 100644 --- a/tests/test-bundle.c +++ b/tests/test-bundle.c @@ -136,6 +136,7 @@ main(int argc, char *argv[]) flows = xmalloc(N_FLOWS * sizeof *flows); for (i = 0; i < N_FLOWS; i++) { random_bytes(&flows[i], sizeof flows[i]); + memset(flows[i].zeros, 0, sizeof flows[i].zeros); flows[i].regs[0] = OFPP_NONE; } diff --git a/tests/test-classifier.c b/tests/test-classifier.c index baa4cc1a..da72d910 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -379,6 +379,7 @@ compare_classifiers(struct classifier *cls, struct tcls *tcls) unsigned int x; x = rand () % N_FLOW_VALUES; + memset(&flow, 0, sizeof flow); flow.nw_src = nw_src_values[get_value(&x, N_NW_SRC_VALUES)]; flow.nw_dst = nw_dst_values[get_value(&x, N_NW_DST_VALUES)]; flow.tun_id = tun_id_values[get_value(&x, N_TUN_ID_VALUES)]; diff --git a/tests/test-multipath.c b/tests/test-multipath.c index 8a355677..b990c133 100644 --- a/tests/test-multipath.c +++ b/tests/test-multipath.c @@ -60,6 +60,7 @@ main(int argc, char *argv[]) struct flow flow; random_bytes(&flow, sizeof flow); + memset(flow.zeros, 0, sizeof flow.zeros); mp.max_link = n - 1; multipath_execute(&mp, &flow); -- 2.30.2