[ovs-dev] [PATCH 06/12] ct-dpif: Add timeout policy related utility functions.

William Tu u9012063 at gmail.com
Fri Jul 26 16:04:32 UTC 2019


On Thu, Jul 25, 2019 at 04:24:08PM -0700, Yi-Hung Wei wrote:
> These functions will be useful in the following patches.
> 
> Signed-off-by: Yi-Hung Wei <yihung.wei at gmail.com>
> ---
>  lib/ct-dpif.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/ct-dpif.h |  3 +++
>  2 files changed, 56 insertions(+)
> 
> diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
> index ae347a9bb46d..1625754e2441 100644
> --- a/lib/ct-dpif.c
> +++ b/lib/ct-dpif.c
> @@ -761,6 +761,59 @@ ct_dpif_format_zone_limits(uint32_t default_limit,
>      }
>  }
>  
> +static const char *const ct_dpif_tp_attr_string[] = {
> +#define CT_DPIF_TP_TCP_ATTR(ATTR) \
> +    [CT_DPIF_TP_ATTR_TCP_##ATTR] = "TCP_"#ATTR,
> +    CT_DPIF_TP_TCP_ATTRS
> +#undef CT_DPIF_TP_TCP_ATTR
> +#define CT_DPIF_TP_UDP_ATTR(ATTR) \
> +    [CT_DPIF_TP_ATTR_UDP_##ATTR] = "UDP_"#ATTR,
> +    CT_DPIF_TP_UDP_ATTRS
> +#undef CT_DPIF_TP_UDP_ATTR
> +#define CT_DPIF_TP_ICMP_ATTR(ATTR) \
> +    [CT_DPIF_TP_ATTR_ICMP_##ATTR] = "ICMP_"#ATTR,
> +    CT_DPIF_TP_ICMP_ATTRS
> +#undef CT_DPIF_TP_ICMP_ATTR
> +};
> +
> +static bool
> +ct_dpif_set_timeout_policy_attr(struct ct_dpif_timeout_policy *tp,
> +                                  uint32_t attr, uint32_t value)

There is a little mis-aligned above.

Otherwise LGTM
Acked-by: William Tu <u9012063 at gmail.com>

> +{
> +    if (tp->present & (1 << attr) && tp->attrs[attr] == value) {
> +        return false;
> +    }
> +    tp->attrs[attr] = value;
> +    tp->present |= 1 << attr;
> +    return true;
> +}
> +
> +/* Sets a timeout value identified by '*name' to 'value'.
> + * Returns true if the attribute is changed */
> +bool
> +ct_dpif_set_timeout_policy_attr_by_name(struct ct_dpif_timeout_policy *tp,
> +                                        const char *name, uint32_t value)
> +{
> +    uint32_t i;
> +
> +    for (i = 0; i < CT_DPIF_TP_ATTR_MAX; ++i) {
> +        if (!strcasecmp(name, ct_dpif_tp_attr_string[i])) {
> +            return ct_dpif_set_timeout_policy_attr(tp, i, value);
> +        }
> +    }
> +    return false;
> +}
> +
> +bool
> +ct_dpif_timeout_policy_support_ipproto(uint8_t ipproto)
> +{
> +    if (ipproto == IPPROTO_TCP || ipproto == IPPROTO_UDP ||
> +        ipproto == IPPROTO_ICMP || ipproto == IPPROTO_ICMPV6) {
> +        return true;
> +    }
> +    return false;
> +}
> +
>  int
>  ct_dpif_add_timeout_policy(struct dpif *dpif, bool is_default,
>                             const struct ct_dpif_timeout_policy *tp)
> diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h
> index 9dc33bede527..de032cc416ce 100644
> --- a/lib/ct-dpif.h
> +++ b/lib/ct-dpif.h
> @@ -305,6 +305,9 @@ bool ct_dpif_parse_zone_limit_tuple(const char *s, uint16_t *pzone,
>                                      uint32_t *plimit, struct ds *);
>  void ct_dpif_format_zone_limits(uint32_t default_limit,
>                                  const struct ovs_list *, struct ds *);
> +bool ct_dpif_set_timeout_policy_attr_by_name(struct ct_dpif_timeout_policy *tp,
> +                                             const char *key, uint32_t value);
> +bool ct_dpif_timeout_policy_support_ipproto(uint8_t ipproto);
>  int ct_dpif_add_timeout_policy(struct dpif *dpif, bool is_default,
>                                 const struct ct_dpif_timeout_policy *tp);
>  int ct_dpif_get_timeout_policy(struct dpif *dpif, bool is_default,
> -- 
> 2.7.4
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev


More information about the dev mailing list