From: Ben Pfaff Date: Mon, 18 Jun 2012 18:36:03 +0000 (-0700) Subject: flow: Use bit-mask for TTL match, instead of FWW_* flag. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3840c40624f366f560af6165c7e36ec13fc3a51b;p=openvswitch flow: Use bit-mask for TTL match, instead of FWW_* flag. Signed-off-by: Ben Pfaff --- diff --git a/lib/classifier.c b/lib/classifier.c index 79ba657e..5add1758 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -403,7 +403,7 @@ cls_rule_set_nw_ecn(struct cls_rule *rule, uint8_t nw_ecn) void cls_rule_set_nw_ttl(struct cls_rule *rule, uint8_t nw_ttl) { - rule->wc.wildcards &= ~FWW_NW_TTL; + rule->wc.nw_ttl_mask = UINT8_MAX; rule->flow.nw_ttl = nw_ttl; } @@ -607,7 +607,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); if (rule->priority != OFP_DEFAULT_PRIORITY) { ds_put_format(s, "priority=%d,", rule->priority); @@ -754,7 +754,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) if (wc->nw_tos_mask & IP_ECN_MASK) { ds_put_format(s, "nw_ecn=%"PRIu8",", f->nw_tos & IP_ECN_MASK); } - if (!(w & FWW_NW_TTL)) { + if (wc->nw_ttl_mask) { ds_put_format(s, "nw_ttl=%"PRIu8",", f->nw_ttl); } switch (wc->nw_frag_mask) { @@ -1291,7 +1291,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 == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); for (i = 0; i < FLOW_N_REGS; i++) { if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) { @@ -1313,7 +1313,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, && eth_addr_equal_except(a->dl_dst, b->dl_dst, wildcards->dl_dst_mask) && (wc & FWW_NW_PROTO || a->nw_proto == b->nw_proto) - && (wc & FWW_NW_TTL || a->nw_ttl == b->nw_ttl) + && !((a->nw_ttl ^ b->nw_ttl) & wildcards->nw_ttl_mask) && !((a->nw_tos ^ b->nw_tos) & wildcards->nw_tos_mask) && !((a->nw_frag ^ b->nw_frag) & wildcards->nw_frag_mask) && eth_addr_equal_except(a->arp_sha, b->arp_sha, diff --git a/lib/flow.c b/lib/flow.c index 0b0bc445..0844b3bc 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -445,7 +445,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 == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); for (i = 0; i < FLOW_N_REGS; i++) { flow->regs[i] &= wildcards->reg_masks[i]; @@ -470,9 +470,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) } flow->ipv6_label &= wildcards->ipv6_label_mask; flow->nw_tos &= wildcards->nw_tos_mask; - if (wc & FWW_NW_TTL) { - flow->nw_ttl = 0; - } + flow->nw_ttl &= wildcards->nw_ttl_mask; flow->nw_frag &= wildcards->nw_frag_mask; 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); @@ -489,7 +487,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 == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); fmd->tun_id = flow->tun_id; fmd->metadata = flow->metadata; @@ -577,7 +575,7 @@ flow_print(FILE *stream, const struct flow *flow) void flow_wildcards_init_catchall(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); wc->wildcards = FWW_ALL; wc->tun_id_mask = htonll(0); @@ -598,6 +596,8 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) memset(wc->arp_sha_mask, 0, ETH_ADDR_LEN); memset(wc->arp_tha_mask, 0, ETH_ADDR_LEN); wc->nw_tos_mask = 0; + wc->nw_ttl_mask = 0; + memset(wc->zeros, 0, sizeof wc->zeros); } /* Initializes 'wc' as an exact-match set of wildcards; that is, 'wc' does not @@ -605,7 +605,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) void flow_wildcards_init_exact(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); wc->wildcards = 0; wc->tun_id_mask = htonll(UINT64_MAX); @@ -626,6 +626,8 @@ flow_wildcards_init_exact(struct flow_wildcards *wc) memset(wc->arp_sha_mask, 0xff, ETH_ADDR_LEN); memset(wc->arp_tha_mask, 0xff, ETH_ADDR_LEN); wc->nw_tos_mask = UINT8_MAX; + wc->nw_ttl_mask = UINT8_MAX; + memset(wc->zeros, 0, sizeof wc->zeros); } /* Returns true if 'wc' is exact-match, false if 'wc' wildcards any bits or @@ -635,7 +637,7 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); if (wc->wildcards || wc->tun_id_mask != htonll(UINT64_MAX) @@ -654,7 +656,8 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) || wc->ipv6_label_mask != htonl(UINT32_MAX) || !ipv6_mask_is_exact(&wc->nd_target_mask) || wc->nw_frag_mask != UINT8_MAX - || wc->nw_tos_mask != UINT8_MAX) { + || wc->nw_tos_mask != UINT8_MAX + || wc->nw_ttl_mask != UINT8_MAX) { return false; } @@ -674,7 +677,7 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); if (wc->wildcards != FWW_ALL || wc->tun_id_mask != htonll(0) @@ -693,7 +696,8 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) || wc->ipv6_label_mask != htonl(0) || !ipv6_mask_is_any(&wc->nd_target_mask) || wc->nw_frag_mask != 0 - || wc->nw_tos_mask != 0) { + || wc->nw_tos_mask != 0 + || wc->nw_ttl_mask != 0) { return false; } @@ -716,7 +720,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); dst->wildcards = src1->wildcards | src2->wildcards; dst->tun_id_mask = src1->tun_id_mask & src2->tun_id_mask; @@ -742,6 +746,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, 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); dst->nw_tos_mask = src1->nw_tos_mask & src2->nw_tos_mask; + dst->nw_ttl_mask = src1->nw_ttl_mask & src2->nw_ttl_mask; } /* Returns a hash of the wildcards in 'wc'. */ @@ -751,7 +756,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 == 112 + FLOW_N_REGS * 4); + BUILD_ASSERT_DECL(sizeof *wc == 120 + FLOW_N_REGS * 4); return hash_bytes(wc, sizeof *wc, basis); } @@ -763,7 +768,7 @@ flow_wildcards_equal(const struct flow_wildcards *a, { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); if (a->wildcards != b->wildcards || a->tun_id_mask != b->tun_id_mask @@ -782,7 +787,8 @@ flow_wildcards_equal(const struct flow_wildcards *a, || !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) - || a->nw_tos_mask != b->nw_tos_mask) { + || a->nw_tos_mask != b->nw_tos_mask + || a->nw_ttl_mask != b->nw_ttl_mask) { return false; } @@ -805,7 +811,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 == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); for (i = 0; i < FLOW_N_REGS; i++) { if ((a->reg_masks[i] & b->reg_masks[i]) != b->reg_masks[i]) { @@ -858,7 +864,8 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, || (a->tp_src_mask & b->tp_src_mask) != b->tp_src_mask || (a->tp_dst_mask & b->tp_dst_mask) != b->tp_dst_mask || (a->nw_frag_mask & b->nw_frag_mask) != b->nw_frag_mask - || (a->nw_tos_mask & b->nw_tos_mask) != b->nw_tos_mask); + || (a->nw_tos_mask & b->nw_tos_mask) != b->nw_tos_mask + || (a->nw_ttl_mask & b->nw_ttl_mask) != b->nw_ttl_mask); } /* Sets the wildcard mask for register 'idx' in 'wc' to 'mask'. diff --git a/lib/flow.h b/lib/flow.h index 53960004..d7abe3b1 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 14 +#define FLOW_WC_SEQ 15 #define FLOW_N_REGS 8 BUILD_ASSERT_DECL(FLOW_N_REGS <= NXM_NX_MAX_REGS); @@ -95,7 +95,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 == 14); +BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 15); void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id, uint16_t in_port, struct flow *); @@ -144,11 +144,10 @@ typedef unsigned int OVS_BITWISE flow_wildcards_t; #define FWW_IN_PORT ((OVS_FORCE flow_wildcards_t) (1 << 0)) #define FWW_DL_TYPE ((OVS_FORCE flow_wildcards_t) (1 << 1)) #define FWW_NW_PROTO ((OVS_FORCE flow_wildcards_t) (1 << 2)) -#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 3)) -#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 4)) - 1)) +#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 3)) - 1)) /* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */ -BUILD_ASSERT_DECL(FWW_ALL == ((1 << 4) - 1) && FLOW_WC_SEQ == 14); +BUILD_ASSERT_DECL(FWW_ALL == ((1 << 3) - 1) && FLOW_WC_SEQ == 15); /* Information on wildcards for a flow, as a supplement to "struct flow". * @@ -175,10 +174,12 @@ struct flow_wildcards { 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 nw_tos_mask; /* 1-bit in each significant nw_tos bit. */ + uint8_t nw_ttl_mask; /* 1-bit in each significant nw_ttl bit. */ + uint8_t zeros[7]; /* Padding field set to zero. */ }; /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ -BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 144 && FLOW_WC_SEQ == 14); +BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 152 && FLOW_WC_SEQ == 15); 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 70c97ef0..7bfdff31 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -278,7 +278,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_IP_TTL, "nw_ttl", NULL, MF_FIELD_SIZES(u8), - MFM_NONE, FWW_NW_TTL, + MFM_NONE, 0, MFS_DECIMAL, MFP_IP_ANY, true, @@ -576,7 +576,6 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IN_PORT: case MFF_ETH_TYPE: case MFF_IP_PROTO: - case MFF_IP_TTL: case MFF_ARP_OP: assert(mf->fww_bit != 0); return (wc->wildcards & mf->fww_bit) != 0; @@ -629,6 +628,8 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) return !(wc->nw_tos_mask & IP_DSCP_MASK); case MFF_IP_ECN: return !(wc->nw_tos_mask & IP_ECN_MASK); + case MFF_IP_TTL: + return !wc->nw_ttl_mask; case MFF_ND_TARGET: return ipv6_mask_is_any(&wc->nd_target_mask); @@ -672,7 +673,6 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, case MFF_IN_PORT: case MFF_ETH_TYPE: case MFF_IP_PROTO: - case MFF_IP_TTL: case MFF_ARP_OP: assert(mf->fww_bit != 0); memset(mask, wc->wildcards & mf->fww_bit ? 0x00 : 0xff, mf->n_bytes); @@ -739,6 +739,9 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, mask->ipv6 = wc->nd_target_mask; break; + case MFF_IP_TTL: + mask->u8 = wc->nw_ttl_mask; + break; case MFF_IP_FRAG: mask->u8 = wc->nw_frag_mask & FLOW_NW_FRAG_MASK; break; @@ -1475,7 +1478,7 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule) break; case MFF_IP_TTL: - rule->wc.wildcards |= FWW_NW_TTL; + rule->wc.nw_ttl_mask = 0; rule->flow.nw_ttl = 0; break; diff --git a/lib/nx-match.c b/lib/nx-match.c index c92f8cc8..0eb65d8f 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -510,7 +510,7 @@ nxm_put_ip(struct ofpbuf *b, const struct cls_rule *cr, flow->nw_tos & IP_ECN_MASK); } - if (!oxm && !(wc & FWW_NW_TTL)) { + if (!oxm && cr->wc.nw_ttl_mask) { nxm_put_8(b, NXM_NX_IP_TTL, flow->nw_ttl); } @@ -559,7 +559,7 @@ nx_put_raw(struct ofpbuf *b, bool oxm, const struct cls_rule *cr, int match_len; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); /* Metadata. */ if (!(wc & FWW_IN_PORT)) { diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 6723d4a5..451f5537 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -84,14 +84,12 @@ ofputil_netmask_to_wcbits(ovs_be32 netmask) void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); /* Initialize most of rule->wc. */ flow_wildcards_init_catchall(wc); - /* Start with wildcard fields that aren't defined by ofp10_match. */ - wc->wildcards = FWW_NW_TTL; - + wc->wildcards = 0; if (ofpfw & OFPFW10_IN_PORT) { wc->wildcards |= FWW_IN_PORT; } @@ -905,7 +903,7 @@ ofputil_usable_protocols(const struct cls_rule *rule) { const struct flow_wildcards *wc = &rule->wc; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15); /* NXM and OF1.1+ supports bitwise matching on ethernet addresses. */ if (!eth_mask_is_exact(wc->dl_src_mask) @@ -960,7 +958,7 @@ ofputil_usable_protocols(const struct cls_rule *rule) } /* Only NXM supports matching IP TTL/hop limit. */ - if (!(wc->wildcards & FWW_NW_TTL)) { + if (wc->nw_ttl_mask) { return OFPUTIL_P_NXM_ANY; } @@ -3638,7 +3636,7 @@ ofputil_normalize_rule__(struct cls_rule *rule, bool may_log) } if (!(may_match & MAY_IPVx)) { wc.nw_tos_mask = 0; - wc.wildcards |= FWW_NW_TTL; + wc.nw_ttl_mask = 0; } if (!(may_match & MAY_ARP_SHA)) { memset(wc.arp_sha_mask, 0, ETH_ADDR_LEN);