I forgot to mention that this function makes sense only for writeable fields. 
Hence some of the cases could be changed to NOT_REACHED's, but maybe that is 
not important.

  Jarno

On Oct 14, 2013, at 3:57 PM, Jarno Rajahalme <[email protected]> wrote:

> Sets mask bits for the given field and its prerequisite fields.
> Needed for later patches.
> 
> Signed-off-by: Jarno Rajahalme <[email protected]>
> ---
> lib/meta-flow.c |   37 +++++++++++++++++++++++++++++++++++++
> lib/meta-flow.h |   15 +++++++++------
> 2 files changed, 46 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/meta-flow.c b/lib/meta-flow.c
> index 02fee46..77ea1c5 100644
> --- a/lib/meta-flow.c
> +++ b/lib/meta-flow.c
> @@ -1017,6 +1017,43 @@ mf_are_prereqs_ok(const struct mf_field *mf, const 
> struct flow *flow)
>     NOT_REACHED();
> }
> 
> +static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
> +
> +/* Set field and it's prerequisities in the mask.
> + * The caller is responsible for setting the mask for dl_type. */
> +void
> +mf_force_prereqs(const struct mf_field *mf, struct flow *mask)
> +{
> +    mf_set_flow_value(mf, &exact_match_mask, mask);
> +
> +    switch (mf->prereqs) {
> +    case MFP_ND:
> +    case MFP_ND_SOLICIT:
> +    case MFP_ND_ADVERT:
> +        mask->tp_src = OVS_BE16_MAX;
> +        mask->tp_dst = OVS_BE16_MAX;
> +        /* Fall through. */
> +    case MFP_TCP:
> +    case MFP_UDP:
> +    case MFP_SCTP:
> +    case MFP_ICMPV4:
> +    case MFP_ICMPV6:
> +        mask->nw_proto = 0xff;
> +        /* Fall through. */
> +    case MFP_ARP:
> +    case MFP_IPV4:
> +    case MFP_IPV6:
> +    case MFP_MPLS:
> +    case MFP_VLAN_VID:
> +    case MFP_IP_ANY:
> +        /* mask->dl_type = OVS_BE16_MAX; */
> +        /* Fall through. */
> +    case MFP_NONE:
> +        break;
> +    }
> +}
> +
> +
> /* Returns true if 'value' may be a valid value *as part of a masked match*,
>  * false otherwise.
>  *
> diff --git a/lib/meta-flow.h b/lib/meta-flow.h
> index dd8b95d..80fde5e 100644
> --- a/lib/meta-flow.h
> +++ b/lib/meta-flow.h
> @@ -297,15 +297,18 @@ struct mf_field {
> 
> /* The representation of a field's value. */
> union mf_value {
> -    uint8_t u8;
> -    ovs_be16 be16;
> -    ovs_be32 be32;
> -    ovs_be64 be64;
> -    uint8_t mac[ETH_ADDR_LEN];
>     struct in6_addr ipv6;
> +    uint8_t mac[ETH_ADDR_LEN];
> +    ovs_be64 be64;
> +    ovs_be32 be32;
> +    ovs_be16 be16;
> +    uint8_t u8;
> };
> BUILD_ASSERT_DECL(sizeof(union mf_value) == 16);
> 
> +#define MF_EXACT_MASK_INITIALIZER { { { { ~0, ~0, ~0, ~0,  ~0, ~0, ~0, ~0, \
> +                        ~0, ~0, ~0, ~0,  ~0, ~0, ~0, ~0 } } } }
> +
> /* Part of a field. */
> struct mf_subfield {
>     const struct mf_field *field;
> @@ -341,7 +344,7 @@ void mf_get_mask(const struct mf_field *, const struct 
> flow_wildcards *,
> 
> /* Prerequisites. */
> bool mf_are_prereqs_ok(const struct mf_field *, const struct flow *);
> -void mf_force_prereqs(const struct mf_field *, struct match *);
> +void mf_force_prereqs(const struct mf_field *, struct flow *mask);
> 
> /* Field values. */
> bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
> -- 
> 1.7.10.4
> 

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to