Signed-off-by: Simon Horman <ho...@verge.net.au> --- lib/classifier.c | 13 ++++++++++--- lib/classifier.h | 1 + lib/flow.c | 13 +++++++++---- lib/flow.h | 12 ++++++------ lib/meta-flow.c | 20 ++++++++++++++++---- lib/meta-flow.h | 1 + lib/nx-match.c | 6 ++---- lib/ofp-util.c | 7 +++---- tests/ovs-ofctl.at | 6 ++++++ 9 files changed, 54 insertions(+), 25 deletions(-)
diff --git a/lib/classifier.c b/lib/classifier.c index 6e8f4d2..89b2ed8 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -436,8 +436,15 @@ cls_rule_set_ipv6_dst_masked(struct cls_rule *rule, const struct in6_addr *dst, void cls_rule_set_ipv6_label(struct cls_rule *rule, ovs_be32 ipv6_label) { - rule->wc.wildcards &= ~FWW_IPV6_LABEL; + cls_rule_set_ipv6_label_masked(rule, ipv6_label, htonl(UINT32_MAX)); +} + +void +cls_rule_set_ipv6_label_masked(struct cls_rule *rule, ovs_be32 ipv6_label, + ovs_be32 mask) +{ rule->flow.ipv6_label = ipv6_label; + rule->wc.ipv6_label_mask = mask; } void @@ -655,7 +662,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) if (f->dl_type == htons(ETH_TYPE_IPV6)) { format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->ipv6_src_mask); format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->ipv6_dst_mask); - if (!(w & FWW_IPV6_LABEL)) { + if (wc->ipv6_label_mask) { ds_put_format(s, "ipv6_label=0x%05"PRIx32",", ntohl(f->ipv6_label)); } } else { @@ -1241,7 +1248,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, && !((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)) - && (wc & FWW_IPV6_LABEL || a->ipv6_label == b->ipv6_label) + && !((a->ipv6_label ^ b->ipv6_label) & wildcards->ipv6_label_mask) && ipv6_equal_except(&a->ipv6_src, &b->ipv6_src, &wildcards->ipv6_src_mask) && ipv6_equal_except(&a->ipv6_dst, &b->ipv6_dst, diff --git a/lib/classifier.h b/lib/classifier.h index ec7316c..8761b59 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -139,6 +139,7 @@ void cls_rule_set_ipv6_dst(struct cls_rule *, const struct in6_addr *); void cls_rule_set_ipv6_dst_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); void cls_rule_set_ipv6_label(struct cls_rule *, ovs_be32); +void cls_rule_set_ipv6_label_masked(struct cls_rule *, ovs_be32, ovs_be32); void cls_rule_set_nd_target(struct cls_rule *, const struct in6_addr *); void cls_rule_set_nd_target_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); diff --git a/lib/flow.c b/lib/flow.c index 9ad1898..64b4e83 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -467,9 +467,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) if (wc & FWW_NW_PROTO) { flow->nw_proto = 0; } - if (wc & FWW_IPV6_LABEL) { - flow->ipv6_label = htonl(0); - } + flow->ipv6_label &= wildcards->ipv6_label_mask; if (wc & FWW_NW_DSCP) { flow->nw_tos &= ~IP_DSCP_MASK; } @@ -601,6 +599,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) wc->nw_dst_mask = htonl(0); wc->ipv6_src_mask = in6addr_any; wc->ipv6_dst_mask = in6addr_any; + wc->ipv6_label_mask = htonl(0); wc->nd_target_mask = in6addr_any; memset(wc->reg_masks, 0, sizeof wc->reg_masks); wc->metadata_mask = htonll(0); @@ -626,6 +625,7 @@ flow_wildcards_init_exact(struct flow_wildcards *wc) wc->nw_dst_mask = htonl(UINT32_MAX); wc->ipv6_src_mask = in6addr_exact; wc->ipv6_dst_mask = in6addr_exact; + wc->ipv6_label_mask = htonl(UINT32_MAX); wc->nd_target_mask = in6addr_exact; memset(wc->reg_masks, 0xff, sizeof wc->reg_masks); wc->metadata_mask = htonll(UINT64_MAX); @@ -659,6 +659,7 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) || !eth_mask_is_exact(wc->dl_dst_mask) || !ipv6_mask_is_exact(&wc->ipv6_src_mask) || !ipv6_mask_is_exact(&wc->ipv6_dst_mask) + || wc->ipv6_label_mask != htonl(UINT32_MAX) || !ipv6_mask_is_exact(&wc->nd_target_mask) || wc->nw_frag_mask != UINT8_MAX) { return false; @@ -694,6 +695,7 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) || !eth_addr_is_zero(wc->dl_dst_mask) || !ipv6_mask_is_any(&wc->ipv6_src_mask) || !ipv6_mask_is_any(&wc->ipv6_dst_mask) + || wc->ipv6_label_mask != htonl(0) || !ipv6_mask_is_any(&wc->nd_target_mask) || wc->nw_frag_mask != 0) { return false; @@ -728,6 +730,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, &src2->ipv6_src_mask); dst->ipv6_dst_mask = ipv6_addr_bitand(&src1->ipv6_dst_mask, &src2->ipv6_dst_mask); + dst->ipv6_label_mask = src1->ipv6_label_mask & src2->ipv6_label_mask; dst->nd_target_mask = ipv6_addr_bitand(&src1->nd_target_mask, &src2->nd_target_mask); for (i = 0; i < FLOW_N_REGS; i++) { @@ -748,7 +751,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 == 96 + FLOW_N_REGS * 4); + BUILD_ASSERT_DECL(sizeof *wc == 104 + FLOW_N_REGS * 4); return hash_bytes(wc, sizeof *wc, basis); } @@ -770,6 +773,7 @@ flow_wildcards_equal(const struct flow_wildcards *a, || a->metadata_mask != b->metadata_mask || !ipv6_addr_equals(&a->ipv6_src_mask, &b->ipv6_src_mask) || !ipv6_addr_equals(&a->ipv6_dst_mask, &b->ipv6_dst_mask) + || a->ipv6_label_mask != b->ipv6_label_mask || !ipv6_addr_equals(&a->nd_target_mask, &b->nd_target_mask) || a->tp_src_mask != b->tp_src_mask || a->tp_dst_mask != b->tp_dst_mask @@ -834,6 +838,7 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, || (a->tun_id_mask & b->tun_id_mask) != b->tun_id_mask || (a->nw_src_mask & b->nw_src_mask) != b->nw_src_mask || (a->nw_dst_mask & b->nw_dst_mask) != b->nw_dst_mask + || (a->ipv6_label_mask & b->ipv6_label_mask) != b->ipv6_label_mask || (a->vlan_tci_mask & b->vlan_tci_mask) != b->vlan_tci_mask || (a->metadata_mask & b->metadata_mask) != b->metadata_mask || (a->tp_src_mask & b->tp_src_mask) != b->tp_src_mask diff --git a/lib/flow.h b/lib/flow.h index 0e01421..3203007 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -157,12 +157,11 @@ typedef unsigned int OVS_BITWISE flow_wildcards_t; #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_IPV6_LABEL ((OVS_FORCE flow_wildcards_t) (1 << 7)) -#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 8)) -#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 9)) - 1)) +#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 7)) +#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 8)) - 1)) /* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */ -BUILD_ASSERT_DECL(FWW_ALL == ((1 << 9) - 1) && FLOW_WC_SEQ == 12); +BUILD_ASSERT_DECL(FWW_ALL == ((1 << 8) - 1) && FLOW_WC_SEQ == 12); /* Information on wildcards for a flow, as a supplement to "struct flow". * @@ -179,17 +178,18 @@ struct flow_wildcards { struct in6_addr ipv6_dst_mask; /* 1-bit in each signficant ipv6_dst bit. */ struct in6_addr nd_target_mask; /* 1-bit in each significant nd_target bit. */ + ovs_be32 ipv6_label_mask; /* 1 bit in each significant ipv6_label bit. */ ovs_be16 vlan_tci_mask; /* 1-bit in each significant vlan_tci bit. */ ovs_be16 tp_src_mask; /* 1-bit in each significant tp_src bit. */ ovs_be16 tp_dst_mask; /* 1-bit in each significant tp_dst bit. */ 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[1]; /* Padding field set to zero. */ + uint8_t zeros[5]; /* Padding field set to zero. */ }; /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ -BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 128 && FLOW_WC_SEQ == 12); +BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 136 && FLOW_WC_SEQ == 12); 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 9b2797c..7970e10 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -222,7 +222,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { { MFF_IPV6_LABEL, "ipv6_label", NULL, 4, 20, - MFM_NONE, FWW_IPV6_LABEL, + MFM_IPV6_LABEL, 0, MFS_HEXADECIMAL, MFP_IPV6, false, @@ -561,7 +561,6 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IP_DSCP: case MFF_IP_ECN: case MFF_IP_TTL: - case MFF_IPV6_LABEL: case MFF_ARP_OP: case MFF_ARP_SHA: case MFF_ARP_THA: @@ -600,6 +599,9 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IPV6_DST: return ipv6_mask_is_any(&wc->ipv6_dst_mask); + case MFF_IPV6_LABEL: + return !wc->ipv6_label_mask; + case MFF_ND_TARGET: return ipv6_mask_is_any(&wc->nd_target_mask); @@ -749,6 +751,9 @@ mf_is_mask_valid(const struct mf_field *mf, const union mf_value *mask) case MFM_FULLY: return true; + + case MFM_IPV6_LABEL: + return !(mask->be32 & ~htonl(IPV6_LABEL_MASK)); } NOT_REACHED(); @@ -1403,7 +1408,7 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule) break; case MFF_IPV6_LABEL: - rule->wc.wildcards |= FWW_IPV6_LABEL; + rule->wc.ipv6_label_mask = 0; rule->flow.ipv6_label = 0; break; @@ -1505,7 +1510,6 @@ mf_set(const struct mf_field *mf, case MFF_ETH_TYPE: case MFF_VLAN_VID: case MFF_VLAN_PCP: - case MFF_IPV6_LABEL: case MFF_IP_PROTO: case MFF_IP_TTL: case MFF_IP_DSCP: @@ -1561,6 +1565,14 @@ mf_set(const struct mf_field *mf, cls_rule_set_ipv6_dst_masked(rule, &value->ipv6, &mask->ipv6); break; + case MFF_IPV6_LABEL: + if (mask->be32 == htonl(IPV6_LABEL_MASK)) { + mf_set_value(mf, value, rule); + } else { + cls_rule_set_ipv6_label_masked(rule, value->be32, mask->be32); + } + break; + case MFF_ND_TARGET: cls_rule_set_nd_target_masked(rule, &value->ipv6, &mask->ipv6); break; diff --git a/lib/meta-flow.h b/lib/meta-flow.h index 1fecc15..08fd585 100644 --- a/lib/meta-flow.h +++ b/lib/meta-flow.h @@ -176,6 +176,7 @@ enum mf_prereqs { enum mf_maskable { MFM_NONE, /* No sub-field masking. */ MFM_FULLY, /* Every bit is individually maskable. */ + MFM_IPV6_LABEL, /* Low 20 bits */ }; /* How to format or parse a field's value. */ diff --git a/lib/nx-match.c b/lib/nx-match.c index 3e3b4c6..97498ee 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -535,10 +535,8 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr, oxm ? OXM_OF_ICMPV6_TYPE : NXM_NX_ICMPV6_TYPE, oxm ? OXM_OF_ICMPV6_CODE : NXM_NX_ICMPV6_CODE, oxm); - if (!(wc & FWW_IPV6_LABEL)) { - nxm_put_32(b, oxm ? OXM_OF_IPV6_FLABEL : NXM_NX_IPV6_LABEL, - flow->ipv6_label); - } + nxm_put_32m(b, oxm ? OXM_OF_IPV6_FLABEL : NXM_NX_IPV6_LABEL, + flow->ipv6_label, cr->wc.ipv6_label_mask); if (flow->nw_proto == IPPROTO_ICMPV6 && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) || diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 99f92a8..a06357e 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -111,8 +111,7 @@ ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *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 - | FWW_IPV6_LABEL); + wc->wildcards |= (FWW_ARP_SHA | FWW_ARP_THA | FWW_NW_ECN | FWW_NW_TTL); if (ofpfw & OFPFW10_NW_TOS) { /* OpenFlow 1.0 defines a TOS wildcard, but it's much later in @@ -1487,7 +1486,7 @@ ofputil_usable_protocols(const struct cls_rule *rule) } /* Only NXM supports matching IPv6 flow label. */ - if (!(wc->wildcards & FWW_IPV6_LABEL)) { + if (wc->ipv6_label_mask) { return OFPUTIL_P_NXM_ANY; } @@ -3830,7 +3829,7 @@ ofputil_normalize_rule(struct cls_rule *rule) } if (!(may_match & MAY_IPV6)) { wc.ipv6_src_mask = wc.ipv6_dst_mask = in6addr_any; - wc.wildcards |= FWW_IPV6_LABEL; + wc.ipv6_label_mask = htonl(0); } if (!(may_match & MAY_ND_TARGET)) { wc.nd_target_mask = in6addr_any; diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index e77d3fc..b6244f4 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -1122,6 +1122,9 @@ OXM_OF_ETH_TYPE(0800) OXM_OF_IPV6_DST_W(20010db83c4d00010000000000000000/fffffff OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_FLABEL(1000000f) OXM_OF_IPV6_FLABEL(0000000f) OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_FLABEL(0000000f) +OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_FLABEL_W(0000000f/0000000f) +OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_FLABEL_W(0000000f/000fffff) +OXM_OF_ETH_TYPE(86dd) OXM_OF_IPV6_FLABEL_W(0000000f/100fffff) # ND source hardware address OXM_OF_ETH_TYPE(86dd) OXM_OF_IP_PROTO(3a) OXM_OF_ICMPV6_TYPE(87) OXM_OF_IPV6_ND_TARGET(20010db83c4d00010002000300040005) OXM_OF_IPV6_ND_SLL(0002e30f80a4) @@ -1263,6 +1266,9 @@ nx_pull_match() returned error OFPBMC_BAD_PREREQ nx_pull_match() returned error OFPBMC_BAD_VALUE nx_pull_match() returned error OFPBMC_BAD_PREREQ OXM_OF_ETH_TYPE(86dd), OXM_OF_IPV6_FLABEL(0000000f) +OXM_OF_ETH_TYPE(86dd), OXM_OF_IPV6_FLABEL_W(0000000f/0000000f) +OXM_OF_ETH_TYPE(86dd), OXM_OF_IPV6_FLABEL(0000000f) +nx_pull_match() returned error OFPBMC_BAD_MASK # ND source hardware address OXM_OF_ETH_TYPE(86dd), OXM_OF_IP_PROTO(3a), OXM_OF_ICMPV6_TYPE(87), OXM_OF_IPV6_ND_TARGET(20010db83c4d00010002000300040005), OXM_OF_IPV6_ND_SLL(0002e30f80a4) -- 1.7.10.2.484.gcd07cc5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev