Commit eab2fc82 authored by Toke Høiland-Jørgensen's avatar Toke Høiland-Jørgensen Committed by David S. Miller

sch_cake: Interpret fwmark parameter as a bitmask

We initially interpreted the fwmark parameter as a flag that simply turned
on the feature, using the whole skb->mark field as the index into the CAKE
tin_order array. However, it is quite common for different applications to
use different parts of the mask field for their own purposes, each using a
different mask.

Support this use of subsets of the mark by interpreting the TCA_CAKE_FWMARK
parameter as a bitmask to apply to the fwmark field when reading it. The
result will be right-shifted by the number of unset lower bits of the mask
before looking up the tin.

In the original commit message we also failed to credit Felix Resch with
originally suggesting the fwmark feature back in 2017; so the Suggested-By
in this commit covers the whole fwmark feature.

Fixes: 0b5c7efd ("sch_cake: Permit use of connmarks as tin classifiers")
Suggested-by: default avatarFelix Resch <fuller@beif.de>
Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5bf7295f
...@@ -211,6 +211,9 @@ struct cake_sched_data { ...@@ -211,6 +211,9 @@ struct cake_sched_data {
u8 ack_filter; u8 ack_filter;
u8 atm_mode; u8 atm_mode;
u32 fwmark_mask;
u16 fwmark_shft;
/* time_next = time_this + ((len * rate_ns) >> rate_shft) */ /* time_next = time_this + ((len * rate_ns) >> rate_shft) */
u16 rate_shft; u16 rate_shft;
ktime_t time_next_packet; ktime_t time_next_packet;
...@@ -258,8 +261,7 @@ enum { ...@@ -258,8 +261,7 @@ enum {
CAKE_FLAG_AUTORATE_INGRESS = BIT(1), CAKE_FLAG_AUTORATE_INGRESS = BIT(1),
CAKE_FLAG_INGRESS = BIT(2), CAKE_FLAG_INGRESS = BIT(2),
CAKE_FLAG_WASH = BIT(3), CAKE_FLAG_WASH = BIT(3),
CAKE_FLAG_SPLIT_GSO = BIT(4), CAKE_FLAG_SPLIT_GSO = BIT(4)
CAKE_FLAG_FWMARK = BIT(5)
}; };
/* COBALT operates the Codel and BLUE algorithms in parallel, in order to /* COBALT operates the Codel and BLUE algorithms in parallel, in order to
...@@ -1543,7 +1545,7 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch, ...@@ -1543,7 +1545,7 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,
struct sk_buff *skb) struct sk_buff *skb)
{ {
struct cake_sched_data *q = qdisc_priv(sch); struct cake_sched_data *q = qdisc_priv(sch);
u32 tin; u32 tin, mark;
u8 dscp; u8 dscp;
/* Tin selection: Default to diffserv-based selection, allow overriding /* Tin selection: Default to diffserv-based selection, allow overriding
...@@ -1551,14 +1553,13 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch, ...@@ -1551,14 +1553,13 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,
*/ */
dscp = cake_handle_diffserv(skb, dscp = cake_handle_diffserv(skb,
q->rate_flags & CAKE_FLAG_WASH); q->rate_flags & CAKE_FLAG_WASH);
mark = (skb->mark & q->fwmark_mask) >> q->fwmark_shft;
if (q->tin_mode == CAKE_DIFFSERV_BESTEFFORT) if (q->tin_mode == CAKE_DIFFSERV_BESTEFFORT)
tin = 0; tin = 0;
else if (q->rate_flags & CAKE_FLAG_FWMARK && /* use fw mark */ else if (mark && mark <= q->tin_cnt)
skb->mark && tin = q->tin_order[mark - 1];
skb->mark <= q->tin_cnt)
tin = q->tin_order[skb->mark - 1];
else if (TC_H_MAJ(skb->priority) == sch->handle && else if (TC_H_MAJ(skb->priority) == sch->handle &&
TC_H_MIN(skb->priority) > 0 && TC_H_MIN(skb->priority) > 0 &&
...@@ -2172,6 +2173,7 @@ static const struct nla_policy cake_policy[TCA_CAKE_MAX + 1] = { ...@@ -2172,6 +2173,7 @@ static const struct nla_policy cake_policy[TCA_CAKE_MAX + 1] = {
[TCA_CAKE_MPU] = { .type = NLA_U32 }, [TCA_CAKE_MPU] = { .type = NLA_U32 },
[TCA_CAKE_INGRESS] = { .type = NLA_U32 }, [TCA_CAKE_INGRESS] = { .type = NLA_U32 },
[TCA_CAKE_ACK_FILTER] = { .type = NLA_U32 }, [TCA_CAKE_ACK_FILTER] = { .type = NLA_U32 },
[TCA_CAKE_FWMARK] = { .type = NLA_U32 },
}; };
static void cake_set_rate(struct cake_tin_data *b, u64 rate, u32 mtu, static void cake_set_rate(struct cake_tin_data *b, u64 rate, u32 mtu,
...@@ -2619,10 +2621,8 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -2619,10 +2621,8 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt,
} }
if (tb[TCA_CAKE_FWMARK]) { if (tb[TCA_CAKE_FWMARK]) {
if (!!nla_get_u32(tb[TCA_CAKE_FWMARK])) q->fwmark_mask = nla_get_u32(tb[TCA_CAKE_FWMARK]);
q->rate_flags |= CAKE_FLAG_FWMARK; q->fwmark_shft = q->fwmark_mask ? __ffs(q->fwmark_mask) : 0;
else
q->rate_flags &= ~CAKE_FLAG_FWMARK;
} }
if (q->tins) { if (q->tins) {
...@@ -2784,8 +2784,7 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -2784,8 +2784,7 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb)
!!(q->rate_flags & CAKE_FLAG_SPLIT_GSO))) !!(q->rate_flags & CAKE_FLAG_SPLIT_GSO)))
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u32(skb, TCA_CAKE_FWMARK, if (nla_put_u32(skb, TCA_CAKE_FWMARK, q->fwmark_mask))
!!(q->rate_flags & CAKE_FLAG_FWMARK)))
goto nla_put_failure; goto nla_put_failure;
return nla_nest_end(skb, opts); return nla_nest_end(skb, opts);
......
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