#include "dynamic-string.h"
#include "ofp-util.h"
#include "packets.h"
-#include "vlog.h"
-
-VLOG_DEFINE_THIS_MODULE(match);
-
/* Converts the flow in 'flow' into a match in 'match', with the given
* 'wildcards'. */
void
match_set_metadata(struct match *match, ovs_be64 metadata)
{
- match_set_metadata_masked(match, metadata, htonll(UINT64_MAX));
+ match_set_metadata_masked(match, metadata, OVS_BE64_MAX);
}
void
void
match_set_tun_id(struct match *match, ovs_be64 tun_id)
{
- match_set_tun_id_masked(match, tun_id, htonll(UINT64_MAX));
+ match_set_tun_id_masked(match, tun_id, OVS_BE64_MAX);
}
void
void
match_set_tun_src(struct match *match, ovs_be32 src)
{
- match_set_tun_src_masked(match, src, htonl(UINT32_MAX));
+ match_set_tun_src_masked(match, src, OVS_BE32_MAX);
}
void
void
match_set_tun_dst(struct match *match, ovs_be32 dst)
{
- match_set_tun_dst_masked(match, dst, htonl(UINT32_MAX));
+ match_set_tun_dst_masked(match, dst, OVS_BE32_MAX);
}
void
void
match_set_dl_type(struct match *match, ovs_be16 dl_type)
{
- match->wc.masks.dl_type = htons(UINT16_MAX);
+ match->wc.masks.dl_type = OVS_BE16_MAX;
match->flow.dl_type = dl_type;
}
{
flow_set_dl_vlan(&match->flow, dl_vlan);
if (dl_vlan == htons(OFP10_VLAN_NONE)) {
- match->wc.masks.vlan_tci = htons(UINT16_MAX);
+ match->wc.masks.vlan_tci = OVS_BE16_MAX;
} else {
match->wc.masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
}
void
match_set_tp_src(struct match *match, ovs_be16 tp_src)
{
- match_set_tp_src_masked(match, tp_src, htons(UINT16_MAX));
+ match_set_tp_src_masked(match, tp_src, OVS_BE16_MAX);
}
void
void
match_set_tp_dst(struct match *match, ovs_be16 tp_dst)
{
- match_set_tp_dst_masked(match, tp_dst, htons(UINT16_MAX));
+ match_set_tp_dst_masked(match, tp_dst, OVS_BE16_MAX);
}
void
match_set_nw_src(struct match *match, ovs_be32 nw_src)
{
match->flow.nw_src = nw_src;
- match->wc.masks.nw_src = htonl(UINT32_MAX);
+ match->wc.masks.nw_src = OVS_BE32_MAX;
}
void
match_set_nw_dst(struct match *match, ovs_be32 nw_dst)
{
match->flow.nw_dst = nw_dst;
- match->wc.masks.nw_dst = htonl(UINT32_MAX);
+ match->wc.masks.nw_dst = OVS_BE32_MAX;
}
void
void
match_set_ipv6_label(struct match *match, ovs_be32 ipv6_label)
{
- match->wc.masks.ipv6_label = htonl(UINT32_MAX);
+ match->wc.masks.ipv6_label = OVS_BE32_MAX;
match->flow.ipv6_label = ipv6_label;
}
{
if (mask != htons(0)) {
ds_put_format(s, "%s=", name);
- if (mask == htons(UINT16_MAX)) {
+ if (mask == OVS_BE16_MAX) {
ds_put_format(s, "%"PRIu16, ntohs(value));
} else {
ds_put_format(s, "0x%"PRIx16"/0x%"PRIx16,
switch (wc->masks.tunnel.tun_id) {
case 0:
break;
- case CONSTANT_HTONLL(UINT64_MAX):
+ case OVS_BE64_MAX:
ds_put_format(s, "tun_id=%#"PRIx64",", ntohll(tnl->tun_id));
break;
default:
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 20);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 21);
if (priority != OFP_DEFAULT_PRIORITY) {
ds_put_format(s, "priority=%u,", priority);
switch (wc->masks.metadata) {
case 0:
break;
- case CONSTANT_HTONLL(UINT64_MAX):
+ case OVS_BE64_MAX:
ds_put_format(s, "metadata=%#"PRIx64",", ntohll(f->metadata));
break;
default:
format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src);
format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst);
if (wc->masks.ipv6_label) {
- if (wc->masks.ipv6_label == htonl(UINT32_MAX)) {
+ if (wc->masks.ipv6_label == OVS_BE32_MAX) {
ds_put_format(s, "ipv6_label=0x%05"PRIx32",",
ntohl(f->ipv6_label));
} else {
void
minimatch_init(struct minimatch *dst, const struct match *src)
{
- miniflow_init(&dst->flow, &src->flow);
minimask_init(&dst->mask, &src->wc);
+ miniflow_init_with_minimask(&dst->flow, &src->flow, &dst->mask);
}
/* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
minimask_clone(&dst->mask, &src->mask);
}
+/* Initializes 'dst' with the data in 'src', destroying 'src'. The caller must
+ * eventually free 'dst' with minimatch_destroy(). */
+void
+minimatch_move(struct minimatch *dst, struct minimatch *src)
+{
+ miniflow_move(&dst->flow, &src->flow);
+ minimask_move(&dst->mask, &src->mask);
+}
+
/* Frees any memory owned by 'match'. Does not free the storage in which
* 'match' itself resides; the caller is responsible for that. */
void
return miniflow_hash(&match->flow, minimask_hash(&match->mask, basis));
}
+/* Returns true if 'target' satisifies 'match', that is, if each bit for which
+ * 'match' specifies a particular value has the correct value in 'target'.
+ *
+ * This function is equivalent to miniflow_equal_flow_in_minimask(&match->flow,
+ * target, &match->mask) but it is faster because of the invariant that
+ * match->flow.map and match->mask.map are the same. */
+bool
+minimatch_matches_flow(const struct minimatch *match,
+ const struct flow *target)
+{
+ const uint32_t *target_u32 = (const uint32_t *) target;
+ const uint32_t *flowp = match->flow.values;
+ const uint32_t *maskp = match->mask.masks.values;
+ int i;
+
+ for (i = 0; i < MINI_N_MAPS; i++) {
+ uint32_t map;
+
+ for (map = match->flow.map[i]; map; map = zero_rightmost_1bit(map)) {
+ if ((*flowp++ ^ target_u32[raw_ctz(map)]) & *maskp++) {
+ return false;
+ }
+ }
+ target_u32 += 32;
+ }
+
+ return true;
+}
+
/* Appends a string representation of 'match' to 's'. If 'priority' is
* different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
void