Skip to content

Commit eab2fc8

Browse files
tohojodavem330
authored andcommitted
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: 0b5c7ef ("sch_cake: Permit use of connmarks as tin classifiers") Suggested-by: Felix Resch <fuller@beif.de> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5bf7295 commit eab2fc8

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

‎net/sched/sch_cake.c‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ struct cake_sched_data {
211211
u8 ack_filter;
212212
u8 atm_mode;
213213

214+
u32 fwmark_mask;
215+
u16 fwmark_shft;
216+
214217
/* time_next = time_this + ((len * rate_ns) >> rate_shft) */
215218
u16 rate_shft;
216219
ktime_t time_next_packet;
@@ -258,8 +261,7 @@ enum {
258261
CAKE_FLAG_AUTORATE_INGRESS = BIT(1),
259262
CAKE_FLAG_INGRESS = BIT(2),
260263
CAKE_FLAG_WASH = BIT(3),
261-
CAKE_FLAG_SPLIT_GSO = BIT(4),
262-
CAKE_FLAG_FWMARK = BIT(5)
264+
CAKE_FLAG_SPLIT_GSO = BIT(4)
263265
};
264266

265267
/* COBALT operates the Codel and BLUE algorithms in parallel, in order to
@@ -1543,22 +1545,21 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,
15431545
struct sk_buff *skb)
15441546
{
15451547
struct cake_sched_data *q = qdisc_priv(sch);
1546-
u32 tin;
1548+
u32 tin, mark;
15471549
u8 dscp;
15481550

15491551
/* Tin selection: Default to diffserv-based selection, allow overriding
15501552
* using firewall marks or skb->priority.
15511553
*/
15521554
dscp = cake_handle_diffserv(skb,
15531555
q->rate_flags & CAKE_FLAG_WASH);
1556+
mark = (skb->mark & q->fwmark_mask) >> q->fwmark_shft;
15541557

15551558
if (q->tin_mode == CAKE_DIFFSERV_BESTEFFORT)
15561559
tin = 0;
15571560

1558-
else if (q->rate_flags & CAKE_FLAG_FWMARK && /* use fw mark */
1559-
skb->mark &&
1560-
skb->mark <= q->tin_cnt)
1561-
tin = q->tin_order[skb->mark - 1];
1561+
else if (mark && mark <= q->tin_cnt)
1562+
tin = q->tin_order[mark - 1];
15621563

15631564
else if (TC_H_MAJ(skb->priority) == sch->handle &&
15641565
TC_H_MIN(skb->priority) > 0 &&
@@ -2172,6 +2173,7 @@ static const struct nla_policy cake_policy[TCA_CAKE_MAX + 1] = {
21722173
[TCA_CAKE_MPU] = { .type = NLA_U32 },
21732174
[TCA_CAKE_INGRESS] = { .type = NLA_U32 },
21742175
[TCA_CAKE_ACK_FILTER] = { .type = NLA_U32 },
2176+
[TCA_CAKE_FWMARK] = { .type = NLA_U32 },
21752177
};
21762178

21772179
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,
26192621
}
26202622

26212623
if (tb[TCA_CAKE_FWMARK]) {
2622-
if (!!nla_get_u32(tb[TCA_CAKE_FWMARK]))
2623-
q->rate_flags |= CAKE_FLAG_FWMARK;
2624-
else
2625-
q->rate_flags &= ~CAKE_FLAG_FWMARK;
2624+
q->fwmark_mask = nla_get_u32(tb[TCA_CAKE_FWMARK]);
2625+
q->fwmark_shft = q->fwmark_mask ? __ffs(q->fwmark_mask) : 0;
26262626
}
26272627

26282628
if (q->tins) {
@@ -2784,8 +2784,7 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb)
27842784
!!(q->rate_flags & CAKE_FLAG_SPLIT_GSO)))
27852785
goto nla_put_failure;
27862786

2787-
if (nla_put_u32(skb, TCA_CAKE_FWMARK,
2788-
!!(q->rate_flags & CAKE_FLAG_FWMARK)))
2787+
if (nla_put_u32(skb, TCA_CAKE_FWMARK, q->fwmark_mask))
27892788
goto nla_put_failure;
27902789

27912790
return nla_nest_end(skb, opts);

0 commit comments

Comments
 (0)