#ifndef FLOW_H
#define FLOW_H 1
+#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
sizeof *flow / sizeof(uint32_t), basis);
}
+/* Given the wildcard bit count in bits 'shift' through 'shift + 5' (inclusive)
+ * of 'wildcards', returns a 32-bit bit mask with a 1 in each bit that must
+ * match and a 0 in each bit that is wildcarded.
+ *
+ * The bits in 'wildcards' are in the format used in enum ofp_flow_wildcards: 0
+ * is exact match, 1 ignores the LSB, 2 ignores the 2 least-significant bits,
+ * ..., 32 and higher wildcard the entire field. This is the *opposite* of the
+ * usual convention where e.g. /24 indicates that 8 bits (not 24 bits) are
+ * wildcarded.
+ *
+ * 'wildcards' is in host byte order. The return value is in network byte
+ * order. */
+static inline uint32_t
+flow_nw_bits_to_mask(uint32_t wildcards, int shift)
+{
+ wildcards = (wildcards >> shift) & 0x3f;
+ return wildcards < 32 ? htonl(~((1u << wildcards) - 1)) : 0;
+}
+
#endif /* flow.h */
&& (w & OFPFW_TP_DST || a->tp_dst == b->tp_dst));
}
-static uint32_t make_nw_mask(int n_wild_bits)
-{
- n_wild_bits &= (1u << OFPFW_NW_SRC_BITS) - 1;
- return n_wild_bits < 32 ? htonl(~((1u << n_wild_bits) - 1)) : 0;
-}
-
/* Returns nonzero if 'a' and 'b' match, that is, if their fields are equal
* modulo wildcards in 'b', zero otherwise. */
inline int
}
/* We set these late because code above adjusts to->wildcards. */
- to->nw_src_mask = make_nw_mask(to->wildcards >> OFPFW_NW_SRC_SHIFT);
- to->nw_dst_mask = make_nw_mask(to->wildcards >> OFPFW_NW_DST_SHIFT);
+ to->nw_src_mask = flow_nw_bits_to_mask(to->wildcards, OFPFW_NW_SRC_SHIFT);
+ to->nw_dst_mask = flow_nw_bits_to_mask(to->wildcards, OFPFW_NW_DST_SHIFT);
}
/* Allocates and returns a new flow with room for 'actions_len' actions.