@@ -82,6 +82,18 @@ typedef struct {
#endif
} ovs_32aligned_u64;
+/* A 128-bit value, in host byte order, that is only aligned on a 32-bit
+ * boundary. */
+typedef struct {
+ uint32_t u32[4];
+} ovs_32aligned_u128;
+
+/* A 128-bit value, in network byte order, that is only aligned on a 32-bit
+ * boundary. */
+typedef struct {
+ ovs_be32 be32[4];
+} ovs_32aligned_be128;
+
typedef union {
uint32_t u32[4];
struct {
@@ -216,6 +216,24 @@ put_32aligned_u64(ovs_32aligned_u64 *x, uint64_t value)
x->lo = value;
}
+/* Returns the value in 'x'. */
+static inline ovs_u128
+get_32aligned_u128(const ovs_32aligned_u128 *x)
+{
+ ovs_u128 u = { .u32 = { x->u32[0], x->u32[1], x->u32[2], x->u32[3] } };
+ return u;
+}
+
+/* Stores 'value' in 'x'. */
+static inline void
+put_32aligned_u128(ovs_32aligned_u128 *x, ovs_u128 value)
+{
+ x->u32[0] = value.u32[0];
+ x->u32[1] = value.u32[1];
+ x->u32[2] = value.u32[2];
+ x->u32[3] = value.u32[3];
+}
+
#ifndef __CHECKER__
/* Returns the value of 'x'. */
static inline ovs_be32
@@ -264,6 +282,25 @@ put_32aligned_be64(ovs_32aligned_be64 *x, ovs_be64 value)
x->lo = value >> 32;
#endif
}
+
+/* Returns the value of 'x'. */
+static inline ovs_be128
+get_32aligned_be128(const ovs_32aligned_be128 *x)
+{
+ ovs_be128 u = { .be32 = { x->be32[0], x->be32[1],
+ x->be32[2], x->be32[3] } };
+ return u;
+}
+
+/* Stores network byte order 'value' into 'x'. */
+static inline void
+put_32aligned_be128(ovs_32aligned_be128 *x, ovs_be128 value)
+{
+ x->be32[0] = value.be32[0];
+ x->be32[1] = value.be32[1];
+ x->be32[2] = value.be32[2];
+ x->be32[3] = value.be32[3];
+}
#else /* __CHECKER__ */
/* Making sparse happy with these functions also makes them unreadable, so
* don't bother to show it their implementations. */
@@ -271,6 +308,8 @@ ovs_be32 get_16aligned_be32(const ovs_16aligned_be32 *);
void put_16aligned_be32(ovs_16aligned_be32 *, ovs_be32);
ovs_be64 get_32aligned_be64(const ovs_32aligned_be64 *);
void put_32aligned_be64(ovs_32aligned_be64 *, ovs_be64);
+ovs_be128 get_32aligned_be128(const ovs_32aligned_be128 *);
+void put_32aligned_be128(ovs_32aligned_be128 *, ovs_be128);
#endif
#endif /* unaligned.h */
These are analogous to the existing helpers for 32-bit aligned 64-bit integers, and will have users in upcoming commits. Signed-off-by: Ben Pfaff <blp@ovn.org> --- include/openvswitch/types.h | 12 ++++++++++++ lib/unaligned.h | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)