Commit 758cc43c authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[PKT_SCHED]: Fix dsmark to apply changes consistent

Fixes dsmark to do all configuration sanity checks first and
only apply the changes if all of them can be applied without
any errors. Also fixes the weak sanity checks for DSMARK_VALUE
and DSMASK_MASK.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8f48bcd4
...@@ -62,6 +62,21 @@ struct dsmark_qdisc_data { ...@@ -62,6 +62,21 @@ struct dsmark_qdisc_data {
int set_tc_index; int set_tc_index;
}; };
static inline int dsmark_valid_indices(u16 indices)
{
while (indices != 1) {
if (indices & 1)
return 0;
indices >>= 1;
}
return 1;
}
static inline int dsmark_valid_index(struct dsmark_qdisc_data *p, u16 index)
{
return (index <= p->indices && index > 0);
}
/* ------------------------- Class/flow operations ------------------------- */ /* ------------------------- Class/flow operations ------------------------- */
...@@ -120,31 +135,39 @@ static void dsmark_put(struct Qdisc *sch, unsigned long cl) ...@@ -120,31 +135,39 @@ static void dsmark_put(struct Qdisc *sch, unsigned long cl)
static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
struct rtattr **tca, unsigned long *arg) struct rtattr **tca, unsigned long *arg)
{ {
struct dsmark_qdisc_data *p = PRIV(sch); struct dsmark_qdisc_data *p = PRIV(sch);
struct rtattr *opt = tca[TCA_OPTIONS-1]; struct rtattr *opt = tca[TCA_OPTIONS-1];
struct rtattr *tb[TCA_DSMARK_MAX]; struct rtattr *tb[TCA_DSMARK_MAX];
int err = -EINVAL;
u8 mask = 0;
DPRINTK("dsmark_change(sch %p,[qdisc %p],classid %x,parent %x)," DPRINTK("dsmark_change(sch %p,[qdisc %p],classid %x,parent %x),"
"arg 0x%lx\n",sch,p,classid,parent,*arg); "arg 0x%lx\n", sch, p, classid, parent, *arg);
if (*arg > p->indices)
return -ENOENT; if (!dsmark_valid_index(p, *arg)) {
if (!opt || rtattr_parse_nested(tb, TCA_DSMARK_MAX, opt)) err = -ENOENT;
return -EINVAL; goto rtattr_failure;
if (tb[TCA_DSMARK_MASK-1]) {
if (!RTA_PAYLOAD(tb[TCA_DSMARK_MASK-1]))
return -EINVAL;
p->mask[*arg-1] = *(__u8 *) RTA_DATA(tb[TCA_DSMARK_MASK-1]);
}
if (tb[TCA_DSMARK_VALUE-1]) {
if (!RTA_PAYLOAD(tb[TCA_DSMARK_VALUE-1]))
return -EINVAL;
p->value[*arg-1] = *(__u8 *) RTA_DATA(tb[TCA_DSMARK_VALUE-1]);
} }
return 0;
}
if (!opt || rtattr_parse_nested(tb, TCA_DSMARK_MAX, opt))
goto rtattr_failure;
if (tb[TCA_DSMARK_MASK-1])
mask = RTA_GET_U8(tb[TCA_DSMARK_MASK-1]);
if (tb[TCA_DSMARK_VALUE-1])
p->value[*arg-1] = RTA_GET_U8(tb[TCA_DSMARK_VALUE-1]);
if (tb[TCA_DSMARK_MASK-1])
p->mask[*arg-1] = mask;
err = 0;
rtattr_failure:
return err;
}
static int dsmark_delete(struct Qdisc *sch,unsigned long arg) static int dsmark_delete(struct Qdisc *sch,unsigned long arg)
{ {
...@@ -328,43 +351,53 @@ static unsigned int dsmark_drop(struct Qdisc *sch) ...@@ -328,43 +351,53 @@ static unsigned int dsmark_drop(struct Qdisc *sch)
} }
static int dsmark_init(struct Qdisc *sch,struct rtattr *opt) static int dsmark_init(struct Qdisc *sch, struct rtattr *opt)
{ {
struct dsmark_qdisc_data *p = PRIV(sch); struct dsmark_qdisc_data *p = PRIV(sch);
struct rtattr *tb[TCA_DSMARK_MAX]; struct rtattr *tb[TCA_DSMARK_MAX];
__u16 tmp; int err = -EINVAL;
u32 default_index = NO_DEFAULT_INDEX;
DPRINTK("dsmark_init(sch %p,[qdisc %p],opt %p)\n",sch,p,opt); u16 indices;
if (!opt || u8 *mask;
rtattr_parse(tb,TCA_DSMARK_MAX,RTA_DATA(opt),RTA_PAYLOAD(opt)) < 0 ||
!tb[TCA_DSMARK_INDICES-1] || DPRINTK("dsmark_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
RTA_PAYLOAD(tb[TCA_DSMARK_INDICES-1]) < sizeof(__u16))
return -EINVAL; if (!opt || rtattr_parse_nested(tb, TCA_DSMARK_MAX, opt) < 0)
p->indices = *(__u16 *) RTA_DATA(tb[TCA_DSMARK_INDICES-1]); goto errout;
if (!p->indices)
return -EINVAL; indices = RTA_GET_U16(tb[TCA_DSMARK_INDICES-1]);
for (tmp = p->indices; tmp != 1; tmp >>= 1) { if (!indices || !dsmark_valid_indices(indices))
if (tmp & 1) goto errout;
return -EINVAL;
} if (tb[TCA_DSMARK_DEFAULT_INDEX-1])
p->default_index = NO_DEFAULT_INDEX; default_index = RTA_GET_U16(tb[TCA_DSMARK_DEFAULT_INDEX-1]);
if (tb[TCA_DSMARK_DEFAULT_INDEX-1]) {
if (RTA_PAYLOAD(tb[TCA_DSMARK_DEFAULT_INDEX-1]) < sizeof(__u16)) mask = kmalloc(indices * 2, GFP_KERNEL);
return -EINVAL; if (mask == NULL) {
p->default_index = err = -ENOMEM;
*(__u16 *) RTA_DATA(tb[TCA_DSMARK_DEFAULT_INDEX-1]); goto errout;
} }
p->set_tc_index = !!tb[TCA_DSMARK_SET_TC_INDEX-1];
p->mask = kmalloc(p->indices*2,GFP_KERNEL); p->mask = mask;
if (!p->mask) memset(p->mask, 0xff, indices);
return -ENOMEM;
p->value = p->mask+p->indices; p->value = p->mask + indices;
memset(p->mask,0xff,p->indices); memset(p->value, 0, indices);
memset(p->value,0,p->indices);
if (!(p->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops))) p->indices = indices;
p->default_index = default_index;
p->set_tc_index = RTA_GET_FLAG(tb[TCA_DSMARK_SET_TC_INDEX-1]);
p->q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops);
if (p->q == NULL)
p->q = &noop_qdisc; p->q = &noop_qdisc;
DPRINTK("dsmark_init: qdisc %p\n",&p->q);
return 0; DPRINTK("dsmark_init: qdisc %p\n", p->q);
err = 0;
errout:
rtattr_failure:
return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment