[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240201034653.450138-2-stephen@networkplumber.org>
Date: Wed, 31 Jan 2024 19:45:58 -0800
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH 1/3] net/sched: netem: use extack
The error handling in netem predates introduction of extack,
and was mostly using pr_info(). Use extack to put errors in
result rather than console log.
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
net/sched/sch_netem.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index fa678eb88528..7c37a69aba0e 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -782,15 +782,18 @@ static void dist_free(struct disttable *d)
* signed 16 bit values.
*/
-static int get_dist_table(struct disttable **tbl, const struct nlattr *attr)
+static int get_dist_table(struct disttable **tbl, const struct nlattr *attr,
+ struct netlink_ext_ack *extack)
{
size_t n = nla_len(attr)/sizeof(__s16);
const __s16 *data = nla_data(attr);
struct disttable *d;
int i;
- if (!n || n > NETEM_DIST_MAX)
+ if (!n || n > NETEM_DIST_MAX) {
+ NL_SET_ERR_MSG_FMT_MOD(extack, "invalid distribution table size: %zu", n);
return -EINVAL;
+ }
d = kvmalloc(struct_size(d, table, n), GFP_KERNEL);
if (!d)
@@ -865,7 +868,8 @@ static void get_rate(struct netem_sched_data *q, const struct nlattr *attr)
q->cell_size_reciprocal = (struct reciprocal_value) { 0 };
}
-static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr)
+static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr,
+ struct netlink_ext_ack *extack)
{
const struct nlattr *la;
int rem;
@@ -878,7 +882,7 @@ static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr)
const struct tc_netem_gimodel *gi = nla_data(la);
if (nla_len(la) < sizeof(struct tc_netem_gimodel)) {
- pr_info("netem: incorrect gi model size\n");
+ NL_SET_ERR_MSG_MOD(extack, "incorrect GI model size");
return -EINVAL;
}
@@ -897,7 +901,7 @@ static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr)
const struct tc_netem_gemodel *ge = nla_data(la);
if (nla_len(la) < sizeof(struct tc_netem_gemodel)) {
- pr_info("netem: incorrect ge model size\n");
+ NL_SET_ERR_MSG_MOD(extack, "incorrect GE model size");
return -EINVAL;
}
@@ -911,7 +915,7 @@ static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr)
}
default:
- pr_info("netem: unknown loss type %u\n", type);
+ NL_SET_ERR_MSG_FMT_MOD(extack, "unknown loss type: %u", type);
return -EINVAL;
}
}
@@ -934,12 +938,13 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
};
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
- const struct nla_policy *policy, int len)
+ const struct nla_policy *policy, int len,
+ struct netlink_ext_ack *extack)
{
int nested_len = nla_len(nla) - NLA_ALIGN(len);
if (nested_len < 0) {
- pr_info("netem: invalid attributes len %d\n", nested_len);
+ NL_SET_ERR_MSG_MOD(extack, "invalid nested attribute length");
return -EINVAL;
}
@@ -966,18 +971,18 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
int ret;
qopt = nla_data(opt);
- ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt));
+ ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt), extack);
if (ret < 0)
return ret;
if (tb[TCA_NETEM_DELAY_DIST]) {
- ret = get_dist_table(&delay_dist, tb[TCA_NETEM_DELAY_DIST]);
+ ret = get_dist_table(&delay_dist, tb[TCA_NETEM_DELAY_DIST], extack);
if (ret)
goto table_free;
}
if (tb[TCA_NETEM_SLOT_DIST]) {
- ret = get_dist_table(&slot_dist, tb[TCA_NETEM_SLOT_DIST]);
+ ret = get_dist_table(&slot_dist, tb[TCA_NETEM_SLOT_DIST], extack);
if (ret)
goto table_free;
}
@@ -988,7 +993,7 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt,
old_loss_model = q->loss_model;
if (tb[TCA_NETEM_LOSS]) {
- ret = get_loss_clg(q, tb[TCA_NETEM_LOSS]);
+ ret = get_loss_clg(q, tb[TCA_NETEM_LOSS], extack);
if (ret) {
q->loss_model = old_loss_model;
q->clg = old_clg;
@@ -1068,18 +1073,16 @@ static int netem_init(struct Qdisc *sch, struct nlattr *opt,
struct netlink_ext_ack *extack)
{
struct netem_sched_data *q = qdisc_priv(sch);
- int ret;
qdisc_watchdog_init(&q->watchdog, sch);
- if (!opt)
+ if (!opt) {
+ NL_SET_ERR_MSG_MOD(extack, "Netem missing required parameters");
return -EINVAL;
+ }
q->loss_model = CLG_RANDOM;
- ret = netem_change(sch, opt, extack);
- if (ret)
- pr_info("netem: change failed\n");
- return ret;
+ return netem_change(sch, opt, extack);
}
static void netem_destroy(struct Qdisc *sch)
--
2.43.0
Powered by blists - more mailing lists