|
|
36cfb7 |
From 56a3a027d053ab592a3363a92108c93c150301f5 Mon Sep 17 00:00:00 2001
|
|
|
36cfb7 |
From: Kamal Heib <kheib@redhat.com>
|
|
|
36cfb7 |
Date: Thu, 9 Nov 2017 04:44:32 -0500
|
|
|
36cfb7 |
Subject: [PATCH] devlink: Change netlink attribute validation
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1456539
|
|
|
36cfb7 |
|
|
|
36cfb7 |
commit 4f10cede93b758785f5b201774ed3e02eaf1a7bb
|
|
|
36cfb7 |
Author: Arkadi Sharshevsky <arkadis@mellanox.com>
|
|
|
36cfb7 |
Date: Wed May 3 13:25:22 2017 +0200
|
|
|
36cfb7 |
|
|
|
36cfb7 |
devlink: Change netlink attribute validation
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Currently the netlink attribute resolving is done by a sequence of
|
|
|
36cfb7 |
if's. Change the attribute resolving to table lookup.
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
|
|
|
36cfb7 |
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
|
|
|
36cfb7 |
Reviewed-by: Greg Rose <gvrose8192@gmail.com>
|
|
|
36cfb7 |
|
|
|
36cfb7 |
Signed-off-by: Kamal Heib <kheib@redhat.com>
|
|
|
36cfb7 |
---
|
|
|
e138d9 |
devlink/devlink.c | 103 ++++++++++++++--------------------------------
|
|
|
36cfb7 |
1 file changed, 30 insertions(+), 73 deletions(-)
|
|
|
36cfb7 |
|
|
|
36cfb7 |
diff --git a/devlink/devlink.c b/devlink/devlink.c
|
|
|
e138d9 |
index e90226e48369b..35220d802a618 100644
|
|
|
36cfb7 |
--- a/devlink/devlink.c
|
|
|
36cfb7 |
+++ b/devlink/devlink.c
|
|
|
36cfb7 |
@@ -232,88 +232,45 @@ static bool dl_no_arg(struct dl *dl)
|
|
|
36cfb7 |
return dl_argc(dl) == 0;
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
|
|
|
36cfb7 |
+static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_INDEX] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_TYPE] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_DESIRED_TYPE] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_NETDEV_IFINDEX] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_NETDEV_NAME] = MNL_TYPE_NUL_STRING,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_PORT_IBDEV_NAME] = MNL_TYPE_NUL_STRING,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_INDEX] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_SIZE] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_INGRESS_POOL_COUNT] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_EGRESS_POOL_COUNT] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_INGRESS_TC_COUNT] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_EGRESS_TC_COUNT] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_POOL_INDEX] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_POOL_TYPE] = MNL_TYPE_U8,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_POOL_SIZE] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = MNL_TYPE_U8,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_THRESHOLD] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_TC_INDEX] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_OCC_CUR] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_SB_OCC_MAX] = MNL_TYPE_U32,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_ESWITCH_MODE] = MNL_TYPE_U16,
|
|
|
36cfb7 |
+ [DEVLINK_ATTR_ESWITCH_INLINE_MODE] = MNL_TYPE_U8,
|
|
|
36cfb7 |
+};
|
|
|
36cfb7 |
+
|
|
|
36cfb7 |
static int attr_cb(const struct nlattr *attr, void *data)
|
|
|
36cfb7 |
{
|
|
|
36cfb7 |
const struct nlattr **tb = data;
|
|
|
36cfb7 |
int type;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
- type = mnl_attr_get_type(attr);
|
|
|
36cfb7 |
-
|
|
|
36cfb7 |
if (mnl_attr_type_valid(attr, DEVLINK_ATTR_MAX) < 0)
|
|
|
36cfb7 |
return MNL_CB_ERROR;
|
|
|
36cfb7 |
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_BUS_NAME &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_DEV_NAME &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_INDEX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_TYPE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_DESIRED_TYPE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_NETDEV_IFINDEX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_NETDEV_NAME &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_PORT_IBDEV_NAME &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_INDEX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_SIZE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_INGRESS_POOL_COUNT &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_EGRESS_POOL_COUNT &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_INGRESS_TC_COUNT &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_EGRESS_TC_COUNT &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_POOL_INDEX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_POOL_TYPE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U8) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_POOL_SIZE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U8) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_THRESHOLD &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_TC_INDEX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_OCC_CUR &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_SB_OCC_MAX &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_ESWITCH_MODE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
|
|
|
36cfb7 |
- return MNL_CB_ERROR;
|
|
|
36cfb7 |
- if (type == DEVLINK_ATTR_ESWITCH_INLINE_MODE &&
|
|
|
36cfb7 |
- mnl_attr_validate(attr, MNL_TYPE_U8) < 0)
|
|
|
36cfb7 |
+ type = mnl_attr_get_type(attr);
|
|
|
36cfb7 |
+ if (mnl_attr_validate(attr, devlink_policy[type]) < 0)
|
|
|
36cfb7 |
return MNL_CB_ERROR;
|
|
|
36cfb7 |
+
|
|
|
36cfb7 |
tb[type] = attr;
|
|
|
36cfb7 |
return MNL_CB_OK;
|
|
|
36cfb7 |
}
|
|
|
36cfb7 |
--
|
|
|
e138d9 |
2.21.0
|
|
|
36cfb7 |
|