Skip to content

Commit 0b5c7ef

Browse files
ldir-EDB0davem330
authored andcommitted
sch_cake: Permit use of connmarks as tin classifiers
Add flag 'FWMARK' to enable use of firewall connmarks as tin selector. The connmark (skbuff->mark) needs to be in the range 1->tin_cnt ie. for diffserv3 the mark needs to be 1->3. Background Typically CAKE uses DSCP as the basis for tin selection. DSCP values are relatively easily changed as part of the egress path, usually with iptables & the mangle table, ingress is more challenging. CAKE is often used on the WAN interface of a residential gateway where passthrough of DSCP from the ISP is either missing or set to unhelpful values thus use of ingress DSCP values for tin selection isn't helpful in that environment. An approach to solving the ingress tin selection problem is to use CAKE's understanding of tc filters. Naive tc filters could match on source/destination port numbers and force tin selection that way, but multiple filters don't scale particularly well as each filter must be traversed whether it matches or not. e.g. a simple example to map 3 firewall marks to tins: MAJOR=$( tc qdisc show dev $DEV | head -1 | awk '{print $3}' ) tc filter add dev $DEV parent $MAJOR protocol all handle 0x01 fw action skbedit priority ${MAJOR}1 tc filter add dev $DEV parent $MAJOR protocol all handle 0x02 fw action skbedit priority ${MAJOR}2 tc filter add dev $DEV parent $MAJOR protocol all handle 0x03 fw action skbedit priority ${MAJOR}3 Another option is to use eBPF cls_act with tc filters e.g. MAJOR=$( tc qdisc show dev $DEV | head -1 | awk '{print $3}' ) tc filter add dev $DEV parent $MAJOR bpf da obj my-bpf-fwmark-to-class.o This has the disadvantages of a) needing someone to write & maintain the bpf program, b) a bpf toolchain to compile it and c) needing to hardcode the major number in the bpf program so it matches the cake instance (or forcing the cake instance to a particular major number) since the major number cannot be passed to the bpf program via tc command line. As already hinted at by the previous examples, it would be helpful to associate tins with something that survives the Internet path and ideally allows tin selection on both egress and ingress. Netfilter's conntrack permits setting an identifying mark on a connection which can also be restored to an ingress packet with tc action connmark e.g. tc filter add dev eth0 parent ffff: protocol all prio 10 u32 \ match u32 0 0 flowid 1:1 action connmark action mirred egress redirect dev ifb1 Since tc's connmark action has restored any connmark into skb->mark, any of the previous solutions are based upon it and in one form or another copy that mark to the skb->priority field where again CAKE picks this up. This change cuts out at least one of the (less intuitive & non-scalable) middlemen and permit direct access to skb->mark. Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7126399 commit 0b5c7ef

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎include/uapi/linux/pkt_sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ enum {
10211021
TCA_CAKE_INGRESS,
10221022
TCA_CAKE_ACK_FILTER,
10231023
TCA_CAKE_SPLIT_GSO,
1024+
TCA_CAKE_FWMARK,
10241025
__TCA_CAKE_MAX
10251026
};
10261027
#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)

‎net/sched/sch_cake.c‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ enum {
258258
CAKE_FLAG_AUTORATE_INGRESS = BIT(1),
259259
CAKE_FLAG_INGRESS = BIT(2),
260260
CAKE_FLAG_WASH = BIT(3),
261-
CAKE_FLAG_SPLIT_GSO = BIT(4)
261+
CAKE_FLAG_SPLIT_GSO = BIT(4),
262+
CAKE_FLAG_FWMARK = BIT(5)
262263
};
263264

264265
/* COBALT operates the Codel and BLUE algorithms in parallel, in order to
@@ -1566,12 +1567,20 @@ static struct cake_tin_data *cake_select_tin(struct Qdisc *sch,
15661567
if (q->rate_flags & CAKE_FLAG_WASH)
15671568
cake_wash_diffserv(skb);
15681569
} else if (q->tin_mode != CAKE_DIFFSERV_BESTEFFORT) {
1569-
/* extract the Diffserv Precedence field, if it exists */
1570-
/* and clear DSCP bits if washing */
1571-
tin = q->tin_index[cake_handle_diffserv(skb,
1572-
q->rate_flags & CAKE_FLAG_WASH)];
1573-
if (unlikely(tin >= q->tin_cnt))
1574-
tin = 0;
1570+
if (q->rate_flags & CAKE_FLAG_FWMARK && /* use fw mark */
1571+
skb->mark &&
1572+
skb->mark <= q->tin_cnt) {
1573+
tin = q->tin_order[skb->mark - 1];
1574+
if (q->rate_flags & CAKE_FLAG_WASH)
1575+
cake_wash_diffserv(skb);
1576+
} else {
1577+
/* extract the Diffserv Precedence field, if it exists */
1578+
/* and clear DSCP bits if washing */
1579+
tin = q->tin_index[cake_handle_diffserv(skb,
1580+
q->rate_flags & CAKE_FLAG_WASH)];
1581+
if (unlikely(tin >= q->tin_cnt))
1582+
tin = 0;
1583+
}
15751584
} else {
15761585
tin = 0;
15771586
if (q->rate_flags & CAKE_FLAG_WASH)
@@ -2624,6 +2633,13 @@ static int cake_change(struct Qdisc *sch, struct nlattr *opt,
26242633
q->rate_flags &= ~CAKE_FLAG_SPLIT_GSO;
26252634
}
26262635

2636+
if (tb[TCA_CAKE_FWMARK]) {
2637+
if (!!nla_get_u32(tb[TCA_CAKE_FWMARK]))
2638+
q->rate_flags |= CAKE_FLAG_FWMARK;
2639+
else
2640+
q->rate_flags &= ~CAKE_FLAG_FWMARK;
2641+
}
2642+
26272643
if (q->tins) {
26282644
sch_tree_lock(sch);
26292645
cake_reconfigure(sch);
@@ -2783,6 +2799,10 @@ static int cake_dump(struct Qdisc *sch, struct sk_buff *skb)
27832799
!!(q->rate_flags & CAKE_FLAG_SPLIT_GSO)))
27842800
goto nla_put_failure;
27852801

2802+
if (nla_put_u32(skb, TCA_CAKE_FWMARK,
2803+
!!(q->rate_flags & CAKE_FLAG_FWMARK)))
2804+
goto nla_put_failure;
2805+
27862806
return nla_nest_end(skb, opts);
27872807

27882808
nla_put_failure:

0 commit comments

Comments
 (0)