summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-08-19 09:39:16 -0700
committerBen Pfaff <blp@nicira.com>2011-09-13 11:46:09 -0700
commit993410fbc742a6beec0841a2be542c4105684e12 (patch)
tree38ca6e5ab2306a74d95e412561b2b552918bfd23 /lib
parent75a75043564dc9b002fffa6c6ad71e0d4d5c892e (diff)
downloadopenvswitch-993410fbc742a6beec0841a2be542c4105684e12.tar.gz
classifier: Move zero_wildcards() to flow.c as public flow_zero_wildcards().
This function will soon be used elsewhere. As it doesn't inherently have anything to with the classifier, move it to flow.c.
Diffstat (limited to 'lib')
-rw-r--r--lib/classifier.c63
-rw-r--r--lib/flow.c60
-rw-r--r--lib/flow.h2
3 files changed, 64 insertions, 61 deletions
diff --git a/lib/classifier.c b/lib/classifier.c
index 430c59940..02011e0cc 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -45,7 +45,6 @@ static struct cls_rule *insert_rule(struct cls_table *, struct cls_rule *);
static bool flow_equal_except(const struct flow *, const struct flow *,
const struct flow_wildcards *);
-static void zero_wildcards(struct flow *, const struct flow_wildcards *);
/* Iterates RULE over HEAD and all of the cls_rules on HEAD->list. */
#define FOR_EACH_RULE_IN_LIST(RULE, HEAD) \
@@ -109,7 +108,7 @@ cls_rule_init_catchall(struct cls_rule *rule, unsigned int priority)
void
cls_rule_zero_wildcarded_fields(struct cls_rule *rule)
{
- zero_wildcards(&rule->flow, &rule->wc);
+ flow_zero_wildcards(&rule->flow, &rule->wc);
}
void
@@ -1016,7 +1015,7 @@ find_match(const struct cls_table *table, const struct flow *flow)
struct flow f;
f = *flow;
- zero_wildcards(&f, &table->wc);
+ flow_zero_wildcards(&f, &table->wc);
HMAP_FOR_EACH_WITH_HASH (rule, hmap_node, flow_hash(&f, 0),
&table->rules) {
if (flow_equal(&f, &rule->flow)) {
@@ -1161,61 +1160,3 @@ flow_equal_except(const struct flow *a, const struct flow *b,
&& (wc & FWW_ND_TARGET
|| ipv6_addr_equals(&a->nd_target, &b->nd_target)));
}
-
-static void
-zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
-{
- const flow_wildcards_t wc = wildcards->wildcards;
- int i;
-
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 1);
-
- for (i = 0; i < FLOW_N_REGS; i++) {
- flow->regs[i] &= wildcards->reg_masks[i];
- }
- flow->tun_id &= wildcards->tun_id_mask;
- flow->nw_src &= wildcards->nw_src_mask;
- flow->nw_dst &= wildcards->nw_dst_mask;
- if (wc & FWW_IN_PORT) {
- flow->in_port = 0;
- }
- flow->vlan_tci &= wildcards->vlan_tci_mask;
- if (wc & FWW_DL_TYPE) {
- flow->dl_type = 0;
- }
- if (wc & FWW_TP_SRC) {
- flow->tp_src = 0;
- }
- if (wc & FWW_TP_DST) {
- flow->tp_dst = 0;
- }
- if (wc & FWW_DL_SRC) {
- memset(flow->dl_src, 0, sizeof flow->dl_src);
- }
- if (wc & FWW_DL_DST) {
- flow->dl_dst[0] &= 0x01;
- memset(&flow->dl_dst[1], 0, 5);
- }
- if (wc & FWW_ETH_MCAST) {
- flow->dl_dst[0] &= 0xfe;
- }
- if (wc & FWW_NW_PROTO) {
- flow->nw_proto = 0;
- }
- if (wc & FWW_NW_TOS) {
- flow->nw_tos = 0;
- }
- if (wc & FWW_ARP_SHA) {
- memset(flow->arp_sha, 0, sizeof flow->arp_sha);
- }
- if (wc & FWW_ARP_THA) {
- memset(flow->arp_tha, 0, sizeof flow->arp_tha);
- }
- flow->ipv6_src = ipv6_addr_bitand(&flow->ipv6_src,
- &wildcards->ipv6_src_mask);
- flow->ipv6_dst = ipv6_addr_bitand(&flow->ipv6_dst,
- &wildcards->ipv6_dst_mask);
- if (wc & FWW_ND_TARGET) {
- memset(&flow->nd_target, 0, sizeof flow->nd_target);
- }
-}
diff --git a/lib/flow.c b/lib/flow.c
index 916d41c54..8ec31ab97 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -445,6 +445,66 @@ flow_extract_stats(const struct flow *flow, struct ofpbuf *packet,
stats->n_packets = 1;
}
+/* For every bit of a field that is wildcarded in 'wildcards', sets the
+ * corresponding bit in 'flow' to zero. */
+void
+flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
+{
+ const flow_wildcards_t wc = wildcards->wildcards;
+ int i;
+
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 1);
+
+ for (i = 0; i < FLOW_N_REGS; i++) {
+ flow->regs[i] &= wildcards->reg_masks[i];
+ }
+ flow->tun_id &= wildcards->tun_id_mask;
+ flow->nw_src &= wildcards->nw_src_mask;
+ flow->nw_dst &= wildcards->nw_dst_mask;
+ if (wc & FWW_IN_PORT) {
+ flow->in_port = 0;
+ }
+ flow->vlan_tci &= wildcards->vlan_tci_mask;
+ if (wc & FWW_DL_TYPE) {
+ flow->dl_type = 0;
+ }
+ if (wc & FWW_TP_SRC) {
+ flow->tp_src = 0;
+ }
+ if (wc & FWW_TP_DST) {
+ flow->tp_dst = 0;
+ }
+ if (wc & FWW_DL_SRC) {
+ memset(flow->dl_src, 0, sizeof flow->dl_src);
+ }
+ if (wc & FWW_DL_DST) {
+ flow->dl_dst[0] &= 0x01;
+ memset(&flow->dl_dst[1], 0, 5);
+ }
+ if (wc & FWW_ETH_MCAST) {
+ flow->dl_dst[0] &= 0xfe;
+ }
+ if (wc & FWW_NW_PROTO) {
+ flow->nw_proto = 0;
+ }
+ if (wc & FWW_NW_TOS) {
+ flow->nw_tos = 0;
+ }
+ if (wc & FWW_ARP_SHA) {
+ memset(flow->arp_sha, 0, sizeof flow->arp_sha);
+ }
+ if (wc & FWW_ARP_THA) {
+ memset(flow->arp_tha, 0, sizeof flow->arp_tha);
+ }
+ flow->ipv6_src = ipv6_addr_bitand(&flow->ipv6_src,
+ &wildcards->ipv6_src_mask);
+ flow->ipv6_dst = ipv6_addr_bitand(&flow->ipv6_dst,
+ &wildcards->ipv6_dst_mask);
+ if (wc & FWW_ND_TARGET) {
+ memset(&flow->nd_target, 0, sizeof flow->nd_target);
+ }
+}
+
char *
flow_to_string(const struct flow *flow)
{
diff --git a/lib/flow.h b/lib/flow.h
index 1b3ee1817..e7b49a8f2 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -82,6 +82,8 @@ int flow_extract(struct ofpbuf *, ovs_be64 tun_id, uint16_t in_port,
struct flow *);
void flow_extract_stats(const struct flow *flow, struct ofpbuf *packet,
struct dpif_flow_stats *);
+void flow_zero_wildcards(struct flow *, const struct flow_wildcards *);
+
char *flow_to_string(const struct flow *);
void flow_format(struct ds *, const struct flow *);
void flow_print(FILE *, const struct flow *);