if (flow->dl_type == htons(ETH_TYPE_IP)) {
const struct ip_header *nh = pull_ip(&b);
if (nh) {
- flow->nw_src = get_unaligned_u32(&nh->ip_src);
- flow->nw_dst = get_unaligned_u32(&nh->ip_dst);
+ flow->nw_src = get_unaligned_be32(&nh->ip_src);
+ flow->nw_dst = get_unaligned_be32(&nh->ip_dst);
flow->nw_tos = nh->ip_tos & IP_DSCP_MASK;
flow->nw_proto = nh->ip_proto;
packet->l4 = b.data;
} else {
flow_wildcards_set_reg_mask(wc, idx,
(NXM_HASMASK(f->header)
- ? ntohl(get_unaligned_u32(maskp))
+ ? ntohl(get_unaligned_be32(maskp))
: UINT32_MAX));
- flow->regs[idx] = ntohl(get_unaligned_u32(value));
+ flow->regs[idx] = ntohl(get_unaligned_be32(value));
flow->regs[idx] &= wc->reg_masks[idx];
return 0;
}
switch (f->index) {
/* Metadata. */
case NFI_NXM_OF_IN_PORT:
- flow->in_port = ntohs(get_unaligned_u16(value));
+ flow->in_port = ntohs(get_unaligned_be16(value));
if (flow->in_port == OFPP_LOCAL) {
flow->in_port = ODPP_LOCAL;
}
memcpy(flow->dl_src, value, ETH_ADDR_LEN);
return 0;
case NFI_NXM_OF_ETH_TYPE:
- flow->dl_type = get_unaligned_u16(value);
+ flow->dl_type = get_unaligned_be16(value);
return 0;
/* 802.1Q header. */
if (wc->vlan_tci_mask) {
return NXM_DUP_TYPE;
} else {
- cls_rule_set_dl_tci(rule, get_unaligned_u16(value));
+ cls_rule_set_dl_tci(rule, get_unaligned_be16(value));
return 0;
}
case NFI_NXM_OF_VLAN_TCI_W:
if (wc->vlan_tci_mask) {
return NXM_DUP_TYPE;
} else {
- cls_rule_set_dl_tci_masked(rule, get_unaligned_u16(value),
- get_unaligned_u16(mask));
+ cls_rule_set_dl_tci_masked(rule, get_unaligned_be16(value),
+ get_unaligned_be16(mask));
return 0;
}
if (wc->nw_src_mask) {
return NXM_DUP_TYPE;
} else {
- cls_rule_set_nw_src(rule, get_unaligned_u32(value));
+ cls_rule_set_nw_src(rule, get_unaligned_be32(value));
return 0;
}
case NFI_NXM_OF_IP_SRC_W:
if (wc->nw_src_mask) {
return NXM_DUP_TYPE;
} else {
- ovs_be32 ip = get_unaligned_u32(value);
- ovs_be32 netmask = get_unaligned_u32(mask);
+ ovs_be32 ip = get_unaligned_be32(value);
+ ovs_be32 netmask = get_unaligned_be32(mask);
if (!cls_rule_set_nw_src_masked(rule, ip, netmask)) {
return NXM_BAD_MASK;
}
if (wc->nw_dst_mask) {
return NXM_DUP_TYPE;
} else {
- cls_rule_set_nw_dst(rule, get_unaligned_u32(value));
+ cls_rule_set_nw_dst(rule, get_unaligned_be32(value));
return 0;
}
case NFI_NXM_OF_IP_DST_W:
if (wc->nw_dst_mask) {
return NXM_DUP_TYPE;
} else {
- ovs_be32 ip = get_unaligned_u32(value);
- ovs_be32 netmask = get_unaligned_u32(mask);
+ ovs_be32 ip = get_unaligned_be32(value);
+ ovs_be32 netmask = get_unaligned_be32(mask);
if (!cls_rule_set_nw_dst_masked(rule, ip, netmask)) {
return NXM_BAD_MASK;
}
/* TCP header. */
case NFI_NXM_OF_TCP_SRC:
- flow->tp_src = get_unaligned_u16(value);
+ flow->tp_src = get_unaligned_be16(value);
return 0;
case NFI_NXM_OF_TCP_DST:
- flow->tp_dst = get_unaligned_u16(value);
+ flow->tp_dst = get_unaligned_be16(value);
return 0;
/* UDP header. */
case NFI_NXM_OF_UDP_SRC:
- flow->tp_src = get_unaligned_u16(value);
+ flow->tp_src = get_unaligned_be16(value);
return 0;
case NFI_NXM_OF_UDP_DST:
- flow->tp_dst = get_unaligned_u16(value);
+ flow->tp_dst = get_unaligned_be16(value);
return 0;
/* ICMP header. */
/* ARP header. */
case NFI_NXM_OF_ARP_OP:
- if (ntohs(get_unaligned_u16(value)) > 255) {
+ if (ntohs(get_unaligned_be16(value)) > 255) {
return NXM_BAD_VALUE;
} else {
- flow->nw_proto = ntohs(get_unaligned_u16(value));
+ flow->nw_proto = ntohs(get_unaligned_be16(value));
return 0;
}
/* Tunnel ID. */
case NFI_NXM_NX_TUN_ID:
- flow->tun_id = htonl(ntohll(get_unaligned_u64(value)));
+ flow->tun_id = htonl(ntohll(get_unaligned_be64(value)));
return 0;
/* Registers. */
#include <stdint.h>
#include "byte-order.h"
+#include "openvswitch/types.h"
/* Public API. */
static inline uint16_t get_unaligned_u16(const uint16_t *);
static inline void put_unaligned_u32(uint32_t *, uint32_t);
static inline void put_unaligned_u64(uint64_t *, uint64_t);
+static inline ovs_be16 get_unaligned_be16(const ovs_be16 *);
+static inline ovs_be32 get_unaligned_be32(const ovs_be32 *);
+static inline ovs_be64 get_unaligned_be64(const ovs_be64 *);
+static inline void put_unaligned_be16(ovs_be16 *, ovs_be16);
+static inline void put_unaligned_be32(ovs_be32 *, ovs_be32);
+static inline void put_unaligned_be64(ovs_be64 *, ovs_be64);
+
#ifdef __GNUC__
/* GCC implementations. */
-#define GCC_UNALIGNED_ACCESSORS(SIZE) \
-struct unaligned_u##SIZE { \
- uint##SIZE##_t x __attribute__((__packed__)); \
-}; \
-static inline struct unaligned_u##SIZE * \
-unaligned_u##SIZE(const uint##SIZE##_t *p) \
-{ \
- return (struct unaligned_u##SIZE *) p; \
-} \
- \
-static inline uint##SIZE##_t \
-get_unaligned_u##SIZE(const uint##SIZE##_t *p) \
-{ \
- return unaligned_u##SIZE(p)->x; \
-} \
- \
-static inline void \
-put_unaligned_u##SIZE(uint##SIZE##_t *p, uint##SIZE##_t x) \
-{ \
- unaligned_u##SIZE(p)->x = x; \
+#define GCC_UNALIGNED_ACCESSORS(TYPE, ABBREV) \
+struct unaligned_##ABBREV { \
+ TYPE x __attribute__((__packed__)); \
+}; \
+static inline struct unaligned_##ABBREV * \
+unaligned_##ABBREV(const TYPE *p) \
+{ \
+ return (struct unaligned_##ABBREV *) p; \
+} \
+ \
+static inline TYPE \
+get_unaligned_##ABBREV(const TYPE *p) \
+{ \
+ return unaligned_##ABBREV(p)->x; \
+} \
+ \
+static inline void \
+put_unaligned_##ABBREV(TYPE *p, TYPE x) \
+{ \
+ unaligned_##ABBREV(p)->x = x; \
}
-GCC_UNALIGNED_ACCESSORS(16);
-GCC_UNALIGNED_ACCESSORS(32);
-GCC_UNALIGNED_ACCESSORS(64);
+GCC_UNALIGNED_ACCESSORS(uint16_t, u16);
+GCC_UNALIGNED_ACCESSORS(uint32_t, u32);
+GCC_UNALIGNED_ACCESSORS(uint64_t, u64);
+
+GCC_UNALIGNED_ACCESSORS(ovs_be16, be16);
+GCC_UNALIGNED_ACCESSORS(ovs_be32, be32);
+GCC_UNALIGNED_ACCESSORS(ovs_be64, be64);
#else
/* Generic implementations. */
p[6] = x >> 8;
p[7] = x;
}
+
+/* Only sparse cares about the difference between uint<N>_t and ovs_be<N>, and
+ * that takes the GCC branch, so there's no point in working too hard on these
+ * accessors. */
+#define get_unaligned_be16 get_unaligned_u16
+#define get_unaligned_be32 get_unaligned_u32
+#define get_unaligned_be64 get_unaligned_u64
+#define put_unaligned_be16 put_unaligned_u16
+#define put_unaligned_be32 put_unaligned_u32
+#define put_unaligned_be64 put_unaligned_u64
#endif
#endif /* unaligned.h */