[ovs-dev] [PATCH 2/3] datapath: Make __parse_flow_nlattrs() more generic.

Pravin Shelar pshelar at nicira.com
Fri Aug 15 22:02:25 UTC 2014


On Thu, Aug 14, 2014 at 10:03 PM, Joe Stringer <joestringer at nicira.com> wrote:
> This allows future patches to reuse the nla error detection code, by
> passing their own definitions for expected attribute lengths and types.
>
> Signed-off-by: Joe Stringer <joestringer at nicira.com>
> ---
>  datapath/flow_netlink.c |   34 +++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c
> index e525c9d..933b2a1 100644
> --- a/datapath/flow_netlink.c
> +++ b/datapath/flow_netlink.c
> @@ -285,9 +285,10 @@ static bool is_all_zero(const u8 *fp, size_t size)
>         return true;
>  }
>
> -static int __parse_flow_nlattrs(const struct nlattr *attr,
> -                               const struct nlattr *a[],
> -                               u64 *attrsp, bool nz)
> +static int parse_nlattrs(const struct nlattr *attr, const struct nlattr *a[],
> +                        const int expected_lens[], int max_attr,
> +                        bool allow_duplicate_attrs, const char *attr_str,
> +                        u64 *attrsp, bool nz)
>  {
>         const struct nlattr *nla;
>         u64 attrs;
> @@ -298,22 +299,23 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
>                 u16 type = nla_type(nla);
>                 int expected_len;
>
> -               if (type > OVS_KEY_ATTR_MAX) {
> -                       OVS_NLERR("Unknown key attribute (type=%d, max=%d).\n",
> -                                 type, OVS_KEY_ATTR_MAX);
> +               if (type > max_attr) {
> +                       OVS_NLERR("Unknown %s attribute (type=%d, max=%d).\n",
> +                                 attr_str, type, max_attr);
>                         return -EINVAL;
>                 }
>
> -               if (attrs & (1ULL << type)) {
> -                       OVS_NLERR("Duplicate key attribute (type %d).\n", type);
> +               if (!allow_duplicate_attrs && (attrs & (1ULL << type))) {
> +                       OVS_NLERR("Duplicate %s attribute (type %d).\n",
> +                                 attr_str, type);
>                         return -EINVAL;
>                 }
>
> -               expected_len = ovs_key_lens[type];
> +               expected_len = expected_lens[type];
>                 if (nla_len(nla) != expected_len && expected_len != -1) {
> -                       OVS_NLERR("Key attribute has unexpected length (type=%d"
> -                                 ", length=%d, expected=%d).\n", type,
> -                                 nla_len(nla), expected_len);
> +                       OVS_NLERR("%s attribute has unexpected length (type=%d"
> +                                 ", length=%d, expected=%d).\n", attr_str,
> +                                 type, nla_len(nla), expected_len);
>                         return -EINVAL;
>                 }
>
> @@ -323,7 +325,7 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
>                 }
>         }
>         if (rem) {
> -               OVS_NLERR("Message has %d unknown bytes.\n", rem);
> +               OVS_NLERR("%s message has %d unknown bytes.\n", attr_str, rem);
>                 return -EINVAL;
>         }
>
This is good idea. I think we can improve it even further.
There is nla_parse() function in netlink which does attribute parsing,
but it is not as strict as OVS needs. Can you look into improving the
API or adding another API which works for us.

Thanks,
Pravin.



More information about the dev mailing list