Signed-off-by: Ben Pfaff <b...@nicira.com> --- lib/flow.c | 46 +++++++++++++++++++++++++--------------------- lib/util.h | 5 ++++- 2 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/lib/flow.c b/lib/flow.c index d2dcc46..9dc29ee 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -50,25 +50,32 @@ const uint8_t flow_segment_u64s[4] = { FLOW_U64S }; +/* Asserts that field 'f1' follows immediately after 'f0' in struct flow, + * without any intervening padding. */ +#define ASSERT_SEQUENTIAL(f0, f1) \ + BUILD_ASSERT_DECL(offsetof(struct flow, f0) \ + + MEMBER_SIZEOF(struct flow, f0) \ + == offsetof(struct flow, f1)) + +/* Asserts that fields 'f0' and 'f1' are in the same 32-bit aligned word within + * struct flow. */ +#define ASSERT_SAME_WORD(f0, f1) \ + BUILD_ASSERT_DECL(offsetof(struct flow, f0) / 4 \ + == offsetof(struct flow, f1) / 4) + +/* Asserts that 'f0' and 'f1' are both sequential and within the same 32-bit + * aligned word in struct flow. */ +#define ASSERT_SEQUENTIAL_SAME_WORD(f0, f1) \ + ASSERT_SEQUENTIAL(f0, f1); \ + ASSERT_SAME_WORD(f0, f1) + /* miniflow_extract() assumes the following to be true to optimize the * extraction process. */ -BUILD_ASSERT_DECL(offsetof(struct flow, dl_type) + 2 - == offsetof(struct flow, vlan_tci) && - offsetof(struct flow, dl_type) / 4 - == offsetof(struct flow, vlan_tci) / 4 ); - -BUILD_ASSERT_DECL(offsetof(struct flow, nw_frag) + 3 - == offsetof(struct flow, nw_proto) && - offsetof(struct flow, nw_tos) + 2 - == offsetof(struct flow, nw_proto) && - offsetof(struct flow, nw_ttl) + 1 - == offsetof(struct flow, nw_proto) && - offsetof(struct flow, nw_frag) / 4 - == offsetof(struct flow, nw_tos) / 4 && - offsetof(struct flow, nw_ttl) / 4 - == offsetof(struct flow, nw_tos) / 4 && - offsetof(struct flow, nw_proto) / 4 - == offsetof(struct flow, nw_tos) / 4); +ASSERT_SEQUENTIAL_SAME_WORD(dl_type, vlan_tci); + +ASSERT_SEQUENTIAL_SAME_WORD(nw_frag, nw_tos); +ASSERT_SEQUENTIAL_SAME_WORD(nw_tos, nw_ttl); +ASSERT_SEQUENTIAL_SAME_WORD(nw_ttl, nw_proto); /* TCP flags in the middle of a BE64, zeroes in the other half. */ BUILD_ASSERT_DECL(offsetof(struct flow, tcp_flags) % 8 == 4); @@ -80,10 +87,7 @@ BUILD_ASSERT_DECL(offsetof(struct flow, tcp_flags) % 8 == 4); #define TCP_FLAGS_BE32(tcp_ctl) ((OVS_FORCE ovs_be32)TCP_FLAGS_BE16(tcp_ctl)) #endif -BUILD_ASSERT_DECL(offsetof(struct flow, tp_src) + 2 - == offsetof(struct flow, tp_dst) && - offsetof(struct flow, tp_src) / 4 - == offsetof(struct flow, tp_dst) / 4); +ASSERT_SEQUENTIAL_SAME_WORD(tp_src, tp_dst); /* Removes 'size' bytes from the head end of '*datap', of size '*sizep', which * must contain at least 'size' bytes of data. Returns the first byte of data diff --git a/lib/util.h b/lib/util.h index 78abfd3..906b9a5 100644 --- a/lib/util.h +++ b/lib/util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -199,6 +199,9 @@ ovs_prefetch_range(const void *start, size_t size) ((char *) &(OBJECT)->MEMBER - (char *) (OBJECT)) #endif +/* Yields the size of MEMBER within STRUCT. */ +#define MEMBER_SIZEOF(STRUCT, MEMBER) (sizeof(((STRUCT *) NULL)->MEMBER)) + /* Given POINTER, the address of the given MEMBER in a STRUCT object, returns the STRUCT object. */ #define CONTAINER_OF(POINTER, STRUCT, MEMBER) \ -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev