From e878338bf1409f0dd6d23cb57822a2c4c1a69e0f Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Thu, 19 Jul 2012 09:21:49 -0700 Subject: [PATCH] OXM: Allow masking of ARP SHA and THA Signed-off-by: Simon Horman [blp@nicira.com added NEWS, updated a few overlooked meta-flow bits] Signed-off-by: Ben Pfaff --- NEWS | 3 ++- lib/classifier.c | 54 +++++++++++++++++++++++++--------------------- lib/classifier.h | 4 ++++ lib/flow.c | 52 +++++++++++++++++++++++++++++--------------- lib/flow.h | 18 ++++++++-------- lib/meta-flow.c | 54 +++++++++++++++++++++++++++++----------------- lib/nx-match.c | 28 ++++++++++-------------- lib/ofp-util.c | 13 +++++------ tests/ovs-ofctl.at | 12 +++++++++++ 9 files changed, 144 insertions(+), 94 deletions(-) diff --git a/NEWS b/NEWS index 9ada569f..ee119ce3 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,8 @@ post-v1.8.0 cooperating group of processes or threads that emitted a log message. The default log patterns now include this information. - OpenFlow: - - Allow bitwise masking for IPv6 flow label. + - Allow bitwise masking for SHA and THA fields in ARP, SLL and TLL + fields in IPv6 neighbor discovery messages, and IPv6 flow label. v1.8.0 - xx xxx xxxx diff --git a/lib/classifier.c b/lib/classifier.c index 088367a9..33245aea 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -412,15 +412,31 @@ cls_rule_set_icmp_code(struct cls_rule *rule, uint8_t icmp_code) void cls_rule_set_arp_sha(struct cls_rule *rule, const uint8_t sha[ETH_ADDR_LEN]) { - rule->wc.wildcards &= ~FWW_ARP_SHA; - memcpy(rule->flow.arp_sha, sha, ETH_ADDR_LEN); + cls_rule_set_eth(sha, rule->flow.arp_sha, rule->wc.arp_sha_mask); +} + +void +cls_rule_set_arp_sha_masked(struct cls_rule *rule, + const uint8_t arp_sha[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]) +{ + cls_rule_set_eth_masked(arp_sha, mask, + rule->flow.arp_sha, rule->wc.arp_sha_mask); } void cls_rule_set_arp_tha(struct cls_rule *rule, const uint8_t tha[ETH_ADDR_LEN]) { - rule->wc.wildcards &= ~FWW_ARP_THA; - memcpy(rule->flow.arp_tha, tha, ETH_ADDR_LEN); + cls_rule_set_eth(tha, rule->flow.arp_tha, rule->wc.arp_tha_mask); +} + +void +cls_rule_set_arp_tha_masked(struct cls_rule *rule, + const uint8_t arp_tha[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]) +{ + cls_rule_set_eth_masked(arp_tha, mask, + rule->flow.arp_tha, rule->wc.arp_tha_mask); } void @@ -566,7 +582,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); if (rule->priority != OFP_DEFAULT_PRIORITY) { ds_put_format(s, "priority=%d,", rule->priority); @@ -704,14 +720,8 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) } } if (f->dl_type == htons(ETH_TYPE_ARP)) { - if (!(w & FWW_ARP_SHA)) { - ds_put_format(s, "arp_sha="ETH_ADDR_FMT",", - ETH_ADDR_ARGS(f->arp_sha)); - } - if (!(w & FWW_ARP_THA)) { - ds_put_format(s, "arp_tha="ETH_ADDR_FMT",", - ETH_ADDR_ARGS(f->arp_tha)); - } + format_eth_masked(s, "arp_sha", f->arp_sha, wc->arp_sha_mask); + format_eth_masked(s, "arp_tha", f->arp_tha, wc->arp_tha_mask); } if (!(w & FWW_NW_DSCP)) { ds_put_format(s, "nw_tos=%"PRIu8",", f->nw_tos & IP_DSCP_MASK); @@ -748,14 +758,8 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) format_be16_masked(s, "icmp_code", f->tp_dst, wc->tp_dst_mask); format_ipv6_netmask(s, "nd_target", &f->nd_target, &wc->nd_target_mask); - if (!(w & FWW_ARP_SHA)) { - ds_put_format(s, "nd_sll="ETH_ADDR_FMT",", - ETH_ADDR_ARGS(f->arp_sha)); - } - if (!(w & FWW_ARP_THA)) { - ds_put_format(s, "nd_tll="ETH_ADDR_FMT",", - ETH_ADDR_ARGS(f->arp_tha)); - } + format_eth_masked(s, "nd_sll", f->arp_sha, wc->arp_sha_mask); + format_eth_masked(s, "nd_tll", f->arp_tha, wc->arp_tha_mask); } else { format_be16_masked(s, "tp_src", f->tp_src, wc->tp_src_mask); format_be16_masked(s, "tp_dst", f->tp_dst, wc->tp_dst_mask); @@ -1262,7 +1266,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, const flow_wildcards_t wc = wildcards->wildcards; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); for (i = 0; i < FLOW_N_REGS; i++) { if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) { @@ -1288,8 +1292,10 @@ flow_equal_except(const struct flow *a, const struct flow *b, && (wc & FWW_NW_DSCP || !((a->nw_tos ^ b->nw_tos) & IP_DSCP_MASK)) && (wc & FWW_NW_ECN || !((a->nw_tos ^ b->nw_tos) & IP_ECN_MASK)) && !((a->nw_frag ^ b->nw_frag) & wildcards->nw_frag_mask) - && (wc & FWW_ARP_SHA || eth_addr_equals(a->arp_sha, b->arp_sha)) - && (wc & FWW_ARP_THA || eth_addr_equals(a->arp_tha, b->arp_tha)) + && eth_addr_equal_except(a->arp_sha, b->arp_sha, + wildcards->arp_sha_mask) + && eth_addr_equal_except(a->arp_tha, b->arp_tha, + wildcards->arp_tha_mask) && !((a->ipv6_label ^ b->ipv6_label) & wildcards->ipv6_label_mask) && ipv6_equal_except(&a->ipv6_src, &b->ipv6_src, &wildcards->ipv6_src_mask) diff --git a/lib/classifier.h b/lib/classifier.h index d63dfb0f..b76b9573 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -134,7 +134,11 @@ void cls_rule_set_nw_frag_masked(struct cls_rule *, void cls_rule_set_icmp_type(struct cls_rule *, uint8_t); void cls_rule_set_icmp_code(struct cls_rule *, uint8_t); void cls_rule_set_arp_sha(struct cls_rule *, const uint8_t[6]); +void cls_rule_set_arp_sha_masked(struct cls_rule *, const uint8_t[6], + const uint8_t [6]); void cls_rule_set_arp_tha(struct cls_rule *, const uint8_t[6]); +void cls_rule_set_arp_tha_masked(struct cls_rule *, const uint8_t[6], + const uint8_t [6]); void cls_rule_set_ipv6_src(struct cls_rule *, const struct in6_addr *); void cls_rule_set_ipv6_src_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); diff --git a/lib/flow.c b/lib/flow.c index 76f6b27f..5ba3e10d 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -444,7 +444,7 @@ 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 == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); for (i = 0; i < FLOW_N_REGS; i++) { flow->regs[i] &= wildcards->reg_masks[i]; @@ -478,12 +478,8 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) flow->nw_ttl = 0; } flow->nw_frag &= wildcards->nw_frag_mask; - 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); - } + eth_addr_bitand(flow->arp_sha, wildcards->arp_sha_mask, flow->arp_sha); + eth_addr_bitand(flow->arp_tha, wildcards->arp_tha_mask, 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, @@ -497,7 +493,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) void flow_get_metadata(const struct flow *flow, struct flow_metadata *fmd) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); fmd->tun_id = flow->tun_id; fmd->tun_id_mask = htonll(UINT64_MAX); @@ -591,7 +587,7 @@ flow_print(FILE *stream, const struct flow *flow) void flow_wildcards_init_catchall(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); wc->wildcards = FWW_ALL; wc->tun_id_mask = htonll(0); @@ -609,6 +605,8 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) wc->tp_dst_mask = htons(0); memset(wc->dl_src_mask, 0, ETH_ADDR_LEN); memset(wc->dl_dst_mask, 0, ETH_ADDR_LEN); + memset(wc->arp_sha_mask, 0, ETH_ADDR_LEN); + memset(wc->arp_tha_mask, 0, ETH_ADDR_LEN); memset(wc->zeros, 0, sizeof wc->zeros); } @@ -617,7 +615,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) void flow_wildcards_init_exact(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); wc->wildcards = 0; wc->tun_id_mask = htonll(UINT64_MAX); @@ -635,6 +633,8 @@ flow_wildcards_init_exact(struct flow_wildcards *wc) wc->tp_dst_mask = htons(UINT16_MAX); memset(wc->dl_src_mask, 0xff, ETH_ADDR_LEN); memset(wc->dl_dst_mask, 0xff, ETH_ADDR_LEN); + memset(wc->arp_sha_mask, 0xff, ETH_ADDR_LEN); + memset(wc->arp_tha_mask, 0xff, ETH_ADDR_LEN); memset(wc->zeros, 0, sizeof wc->zeros); } @@ -645,7 +645,7 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); if (wc->wildcards || wc->tun_id_mask != htonll(UINT64_MAX) @@ -657,6 +657,8 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) || wc->metadata_mask != htonll(UINT64_MAX) || !eth_mask_is_exact(wc->dl_src_mask) || !eth_mask_is_exact(wc->dl_dst_mask) + || !eth_mask_is_exact(wc->arp_sha_mask) + || !eth_mask_is_exact(wc->arp_tha_mask) || !ipv6_mask_is_exact(&wc->ipv6_src_mask) || !ipv6_mask_is_exact(&wc->ipv6_dst_mask) || wc->ipv6_label_mask != htonl(UINT32_MAX) @@ -681,7 +683,7 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); if (wc->wildcards != FWW_ALL || wc->tun_id_mask != htonll(0) @@ -693,6 +695,8 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) || wc->metadata_mask != htonll(0) || !eth_addr_is_zero(wc->dl_src_mask) || !eth_addr_is_zero(wc->dl_dst_mask) + || !eth_addr_is_zero(wc->arp_sha_mask) + || !eth_addr_is_zero(wc->arp_tha_mask) || !ipv6_mask_is_any(&wc->ipv6_src_mask) || !ipv6_mask_is_any(&wc->ipv6_dst_mask) || wc->ipv6_label_mask != htonl(0) @@ -720,7 +724,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); dst->wildcards = src1->wildcards | src2->wildcards; dst->tun_id_mask = src1->tun_id_mask & src2->tun_id_mask; @@ -742,6 +746,8 @@ flow_wildcards_combine(struct flow_wildcards *dst, dst->tp_dst_mask = src1->tp_dst_mask & src2->tp_dst_mask; eth_addr_bitand(src1->dl_src_mask, src2->dl_src_mask, dst->dl_src_mask); eth_addr_bitand(src1->dl_dst_mask, src2->dl_dst_mask, dst->dl_dst_mask); + eth_addr_bitand(src1->arp_sha_mask, src2->arp_sha_mask, dst->arp_sha_mask); + eth_addr_bitand(src1->arp_tha_mask, src2->arp_tha_mask, dst->arp_tha_mask); } /* Returns a hash of the wildcards in 'wc'. */ @@ -751,7 +757,7 @@ flow_wildcards_hash(const struct flow_wildcards *wc, uint32_t basis) /* If you change struct flow_wildcards and thereby trigger this * assertion, please check that the new struct flow_wildcards has no holes * in it before you update the assertion. */ - BUILD_ASSERT_DECL(sizeof *wc == 104 + FLOW_N_REGS * 4); + BUILD_ASSERT_DECL(sizeof *wc == 112 + FLOW_N_REGS * 4); return hash_bytes(wc, sizeof *wc, basis); } @@ -763,7 +769,7 @@ flow_wildcards_equal(const struct flow_wildcards *a, { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); if (a->wildcards != b->wildcards || a->tun_id_mask != b->tun_id_mask @@ -778,7 +784,9 @@ flow_wildcards_equal(const struct flow_wildcards *a, || a->tp_src_mask != b->tp_src_mask || a->tp_dst_mask != b->tp_dst_mask || !eth_addr_equals(a->dl_src_mask, b->dl_src_mask) - || !eth_addr_equals(a->dl_dst_mask, b->dl_dst_mask)) { + || !eth_addr_equals(a->dl_dst_mask, b->dl_dst_mask) + || !eth_addr_equals(a->arp_sha_mask, b->arp_sha_mask) + || !eth_addr_equals(a->arp_tha_mask, b->arp_tha_mask)) { return false; } @@ -801,7 +809,7 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, uint8_t eth_masked[ETH_ADDR_LEN]; struct in6_addr ipv6_masked; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); for (i = 0; i < FLOW_N_REGS; i++) { if ((a->reg_masks[i] & b->reg_masks[i]) != b->reg_masks[i]) { @@ -819,6 +827,16 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, return true; } + eth_addr_bitand(a->arp_sha_mask, b->arp_sha_mask, eth_masked); + if (!eth_addr_equals(eth_masked, b->arp_sha_mask)) { + return true; + } + + eth_addr_bitand(a->arp_tha_mask, b->arp_tha_mask, eth_masked); + if (!eth_addr_equals(eth_masked, b->arp_tha_mask)) { + return true; + } + ipv6_masked = ipv6_addr_bitand(&a->ipv6_src_mask, &b->ipv6_src_mask); if (!ipv6_addr_equals(&ipv6_masked, &b->ipv6_src_mask)) { return true; diff --git a/lib/flow.h b/lib/flow.h index 7c88b6db..0cec1c99 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -34,7 +34,7 @@ struct ofpbuf; /* This sequence number should be incremented whenever anything involving flows * or the wildcarding of flows changes. This will cause build assertion * failures in places which likely need to be updated. */ -#define FLOW_WC_SEQ 13 +#define FLOW_WC_SEQ 14 #define FLOW_N_REGS 8 BUILD_ASSERT_DECL(FLOW_N_REGS <= NXM_NX_MAX_REGS); @@ -103,7 +103,7 @@ BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->nw_frag) == 1); BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE); /* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */ -BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 13); +BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 14); void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id, uint16_t in_port, struct flow *); @@ -155,13 +155,11 @@ typedef unsigned int OVS_BITWISE flow_wildcards_t; /* No corresponding OFPFW10_* bits. */ #define FWW_NW_DSCP ((OVS_FORCE flow_wildcards_t) (1 << 1)) #define FWW_NW_ECN ((OVS_FORCE flow_wildcards_t) (1 << 2)) -#define FWW_ARP_SHA ((OVS_FORCE flow_wildcards_t) (1 << 3)) -#define FWW_ARP_THA ((OVS_FORCE flow_wildcards_t) (1 << 6)) -#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 7)) -#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 8)) - 1)) +#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 3)) +#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 6)) - 1)) /* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */ -BUILD_ASSERT_DECL(FWW_ALL == ((1 << 8) - 1) && FLOW_WC_SEQ == 13); +BUILD_ASSERT_DECL(FWW_ALL == ((1 << 6) - 1) && FLOW_WC_SEQ == 14); /* Information on wildcards for a flow, as a supplement to "struct flow". * @@ -185,11 +183,13 @@ struct flow_wildcards { uint8_t nw_frag_mask; /* 1-bit in each significant nw_frag bit. */ uint8_t dl_src_mask[6]; /* 1-bit in each significant dl_src bit. */ uint8_t dl_dst_mask[6]; /* 1-bit in each significant dl_dst bit. */ - uint8_t zeros[5]; /* Padding field set to zero. */ + uint8_t arp_sha_mask[6]; /* 1-bit in each significant dl_dst bit. */ + uint8_t arp_tha_mask[6]; /* 1-bit in each significant dl_dst bit. */ + uint8_t zeros[1]; /* Padding field set to zero. */ }; /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ -BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 136 && FLOW_WC_SEQ == 13); +BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 144 && FLOW_WC_SEQ == 14); void flow_wildcards_init_catchall(struct flow_wildcards *); void flow_wildcards_init_exact(struct flow_wildcards *); diff --git a/lib/meta-flow.c b/lib/meta-flow.c index a5505c96..f1e34a30 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -307,7 +307,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_ARP_SHA, "arp_sha", NULL, MF_FIELD_SIZES(mac), - MFM_NONE, FWW_ARP_SHA, + MFM_FULLY, 0, MFS_ETHERNET, MFP_ARP, false, @@ -316,7 +316,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_ARP_THA, "arp_tha", NULL, MF_FIELD_SIZES(mac), - MFM_NONE, FWW_ARP_THA, + MFM_FULLY, 0, MFS_ETHERNET, MFP_ARP, false, @@ -424,7 +424,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_ND_SLL, "nd_sll", NULL, MF_FIELD_SIZES(mac), - MFM_NONE, FWW_ARP_SHA, + MFM_FULLY, 0, MFS_ETHERNET, MFP_ND_SOLICIT, false, @@ -433,7 +433,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_ND_TLL, "nd_tll", NULL, MF_FIELD_SIZES(mac), - MFM_NONE, FWW_ARP_THA, + MFM_FULLY, 0, MFS_ETHERNET, MFP_ND_ADVERT, false, @@ -562,10 +562,6 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IP_ECN: case MFF_IP_TTL: case MFF_ARP_OP: - case MFF_ARP_SHA: - case MFF_ARP_THA: - case MFF_ND_SLL: - case MFF_ND_TLL: assert(mf->fww_bit != 0); return (wc->wildcards & mf->fww_bit) != 0; @@ -582,6 +578,14 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_ETH_DST: return eth_addr_is_zero(wc->dl_dst_mask); + case MFF_ARP_SHA: + case MFF_ND_SLL: + return eth_addr_is_zero(wc->arp_sha_mask); + + case MFF_ARP_THA: + case MFF_ND_TLL: + return eth_addr_is_zero(wc->arp_tha_mask); + case MFF_VLAN_TCI: return !wc->vlan_tci_mask; case MFF_VLAN_VID: @@ -648,10 +652,6 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, case MFF_IP_ECN: case MFF_IP_TTL: case MFF_ARP_OP: - case MFF_ARP_SHA: - case MFF_ARP_THA: - case MFF_ND_SLL: - case MFF_ND_TLL: assert(mf->fww_bit != 0); memset(mask, wc->wildcards & mf->fww_bit ? 0x00 : 0xff, mf->n_bytes); break; @@ -716,6 +716,14 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, case MFF_ARP_TPA: mask->be32 = wc->nw_dst_mask; break; + case MFF_ARP_SHA: + case MFF_ND_SLL: + memcpy(mask->mac, wc->arp_sha_mask, ETH_ADDR_LEN); + break; + case MFF_ARP_THA: + case MFF_ND_TLL: + memcpy(mask->mac, wc->arp_tha_mask, ETH_ADDR_LEN); + break; case MFF_TCP_SRC: case MFF_UDP_SRC: @@ -1431,14 +1439,14 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule) case MFF_ARP_SHA: case MFF_ND_SLL: - rule->wc.wildcards |= FWW_ARP_SHA; - memset(rule->flow.arp_sha, 0, sizeof rule->flow.arp_sha); + memset(rule->flow.arp_sha, 0, ETH_ADDR_LEN); + memset(rule->wc.arp_sha_mask, 0, ETH_ADDR_LEN); break; case MFF_ARP_THA: case MFF_ND_TLL: - rule->wc.wildcards |= FWW_ARP_THA; - memset(rule->flow.arp_tha, 0, sizeof rule->flow.arp_tha); + memset(rule->flow.arp_tha, 0, ETH_ADDR_LEN); + memset(rule->wc.arp_tha_mask, 0, ETH_ADDR_LEN); break; case MFF_TCP_SRC: @@ -1502,14 +1510,10 @@ mf_set(const struct mf_field *mf, case MFF_IP_DSCP: case MFF_IP_ECN: case MFF_ARP_OP: - case MFF_ARP_SHA: - case MFF_ARP_THA: case MFF_ICMPV4_TYPE: case MFF_ICMPV4_CODE: case MFF_ICMPV6_TYPE: case MFF_ICMPV6_CODE: - case MFF_ND_SLL: - case MFF_ND_TLL: NOT_REACHED(); case MFF_TUN_ID: @@ -1532,6 +1536,16 @@ mf_set(const struct mf_field *mf, cls_rule_set_dl_src_masked(rule, value->mac, mask->mac); break; + case MFF_ARP_SHA: + case MFF_ND_SLL: + cls_rule_set_arp_sha_masked(rule, value->mac, mask->mac); + break; + + case MFF_ARP_THA: + case MFF_ND_TLL: + cls_rule_set_arp_tha_masked(rule, value->mac, mask->mac); + break; + case MFF_VLAN_TCI: cls_rule_set_dl_tci_masked(rule, value->be16, mask->be16); break; diff --git a/lib/nx-match.c b/lib/nx-match.c index 3d017c6a..0f676926 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -493,7 +493,7 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr, int match_len; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); /* Metadata. */ if (!(wc & FWW_IN_PORT)) { @@ -548,15 +548,13 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr, flow->tp_src == htons(ND_NEIGHBOR_ADVERT))) { nxm_put_ipv6(b, oxm ? OXM_OF_IPV6_ND_TARGET : NXM_NX_ND_TARGET, &flow->nd_target, &cr->wc.nd_target_mask); - if (!(wc & FWW_ARP_SHA) - && flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)) { - nxm_put_eth(b, oxm ? OXM_OF_IPV6_ND_SLL : NXM_NX_ND_SLL, - flow->arp_sha); + if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)) { + nxm_put_eth_masked(b, oxm ? OXM_OF_IPV6_ND_SLL : NXM_NX_ND_SLL, + flow->arp_sha, cr->wc.arp_sha_mask); } - if (!(wc & FWW_ARP_THA) - && flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) { - nxm_put_eth(b, oxm ? OXM_OF_IPV6_ND_TLL : NXM_NX_ND_TLL, - flow->arp_tha); + if (flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) { + nxm_put_eth_masked(b, oxm ? OXM_OF_IPV6_ND_TLL : NXM_NX_ND_TLL, + flow->arp_tha, cr->wc.arp_tha_mask); } } } else if (!(wc & FWW_DL_TYPE) && flow->dl_type == htons(ETH_TYPE_ARP)) { @@ -569,14 +567,10 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr, flow->nw_src, cr->wc.nw_src_mask); nxm_put_32m(b, oxm ? OXM_OF_ARP_TPA : NXM_OF_ARP_TPA, flow->nw_dst, cr->wc.nw_dst_mask); - if (!(wc & FWW_ARP_SHA)) { - nxm_put_eth(b, oxm ? OXM_OF_ARP_SHA : NXM_NX_ARP_SHA, - flow->arp_sha); - } - if (!(wc & FWW_ARP_THA)) { - nxm_put_eth(b, oxm ? OXM_OF_ARP_THA : NXM_NX_ARP_THA, - flow->arp_tha); - } + nxm_put_eth_masked(b, oxm ? OXM_OF_ARP_SHA : NXM_NX_ARP_SHA, + flow->arp_sha, cr->wc.arp_sha_mask); + nxm_put_eth_masked(b, oxm ? OXM_OF_ARP_THA : NXM_NX_ARP_THA, + flow->arp_tha, cr->wc.arp_tha_mask); } /* Tunnel ID. */ diff --git a/lib/ofp-util.c b/lib/ofp-util.c index ecd05513..faa0687c 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -104,14 +104,14 @@ static const flow_wildcards_t WC_INVARIANTS = 0 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); /* Initialize most of rule->wc. */ flow_wildcards_init_catchall(wc); wc->wildcards = (OVS_FORCE flow_wildcards_t) ofpfw & WC_INVARIANTS; /* Wildcard fields that aren't defined by ofp10_match or tun_id. */ - wc->wildcards |= FWW_ARP_SHA | FWW_ARP_THA | FWW_NW_ECN | FWW_NW_TTL; + wc->wildcards |= FWW_NW_ECN | FWW_NW_TTL; if (ofpfw & OFPFW10_NW_TOS) { /* OpenFlow 1.0 defines a TOS wildcard, but it's much later in @@ -1463,7 +1463,7 @@ ofputil_usable_protocols(const struct cls_rule *rule) { const struct flow_wildcards *wc = &rule->wc; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 13); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); /* NXM and OF1.1+ supports bitwise matching on ethernet addresses. */ if (!eth_mask_is_exact(wc->dl_src_mask) @@ -1481,7 +1481,8 @@ ofputil_usable_protocols(const struct cls_rule *rule) } /* Only NXM supports matching ARP hardware addresses. */ - if (!(wc->wildcards & FWW_ARP_SHA) || !(wc->wildcards & FWW_ARP_THA)) { + if (!eth_addr_is_zero(wc->arp_sha_mask) || + !eth_addr_is_zero(wc->arp_tha_mask)) { return OFPUTIL_P_NXM_ANY; } @@ -4109,10 +4110,10 @@ ofputil_normalize_rule(struct cls_rule *rule) wc.wildcards |= FWW_NW_TTL; } if (!(may_match & MAY_ARP_SHA)) { - wc.wildcards |= FWW_ARP_SHA; + memset(wc.arp_sha_mask, 0, ETH_ADDR_LEN); } if (!(may_match & MAY_ARP_THA)) { - wc.wildcards |= FWW_ARP_THA; + memset(wc.arp_tha_mask, 0, ETH_ADDR_LEN); } if (!(may_match & MAY_IPV6)) { wc.ipv6_src_mask = wc.ipv6_dst_mask = in6addr_any; diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index d3f173b1..d6ade557 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -1399,11 +1399,17 @@ OXM_OF_ARP_TPA_W(C0D80000/FFFF0000) OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_SHA(0002e30f80a4) OXM_OF_ETH_TYPE(0800) OXM_OF_ARP_SHA(0002e30f80a4) OXM_OF_ARP_SHA(0002e30f80a4) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_SHA_W(0002e30f80a4/ffffffffffff) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_SHA_W(0002e30f80a4/000000000000) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_SHA_W(0002e30f80a4/00000000000f) # ARP destination hardware address OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_THA(0002e30f80a4) OXM_OF_ETH_TYPE(0800) OXM_OF_ARP_THA(0002e30f80a4) OXM_OF_ARP_THA(0002e30f80a4) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_THA_W(0002e30f80a4/ffffffffffff) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_THA_W(0002e30f80a4/000000000000) +OXM_OF_ETH_TYPE(0806) OXM_OF_ARP_THA_W(0002e30f80a4/00000000000f) # IPv6 source OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_SRC(20010db83c4d00010002000300040005) @@ -1568,11 +1574,17 @@ nx_pull_match() returned error OFPBMC_BAD_PREREQ OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_SHA(0002e30f80a4) nx_pull_match() returned error OFPBMC_BAD_PREREQ nx_pull_match() returned error OFPBMC_BAD_PREREQ +OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_SHA(0002e30f80a4) +OXM_OF_ETH_TYPE(0806) +OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_SHA_W(000000000004/00000000000f) # ARP destination hardware address OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_THA(0002e30f80a4) nx_pull_match() returned error OFPBMC_BAD_PREREQ nx_pull_match() returned error OFPBMC_BAD_PREREQ +OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_THA(0002e30f80a4) +OXM_OF_ETH_TYPE(0806) +OXM_OF_ETH_TYPE(0806), OXM_OF_ARP_THA_W(000000000004/00000000000f) # IPv6 source OXM_OF_ETH_TYPE(86dd), OXM_OF_IPV6_SRC(20010db83c4d00010002000300040005) -- 2.30.2