From a3af1bb99c9b9dcf40acc8524503c917b94250f4 Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Tue, 1 Feb 2022 13:11:31 +0100 Subject: [PATCH] tc-policy: Implement new BPF section that disallow using TXQ zero Signed-off-by: Jesper Dangaard Brouer --- tc-policy/tc_txq_policy.c | 3 ++- tc-policy/tc_txq_policy_kern.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tc-policy/tc_txq_policy.c b/tc-policy/tc_txq_policy.c index 48c1105..5eb8161 100644 --- a/tc-policy/tc_txq_policy.c +++ b/tc-policy/tc_txq_policy.c @@ -212,7 +212,8 @@ int tc_attach_egress(struct user_config *cfg, struct tc_txq_policy_kern *obj) DECLARE_LIBBPF_OPTS(bpf_tc_opts, attach_egress); /* Selecting BPF-prog here: */ - fd = bpf_program__fd(obj->progs.queue_map_4); + //fd = bpf_program__fd(obj->progs.queue_map_4); + fd = bpf_program__fd(obj->progs.not_txq_zero); if (fd < 0) { fprintf(stderr, "Couldn't find egress program\n"); err = -ENOENT; diff --git a/tc-policy/tc_txq_policy_kern.c b/tc-policy/tc_txq_policy_kern.c index ef63bee..31dcf29 100644 --- a/tc-policy/tc_txq_policy_kern.c +++ b/tc-policy/tc_txq_policy_kern.c @@ -52,3 +52,23 @@ int queue_map_4 (struct __sk_buff *skb) return TC_ACT_OK; } + +/* + * Section name "tc" is preferred over "classifier" as its being deprecated + * https://github.com/libbpf/libbpf/wiki/Libbpf-1.0-migration-guide#bpf-program-sec-annotation-deprecations + */ + +SEC("tc") +int not_txq_zero (struct __sk_buff *skb) +{ + /* Existing skb->queue_mapping can come from skb_record_rx_queue() which + * is usually called by drivers in early RX handling when creating SKB. + */ + + /* At this stage queue_mapping is 1-indexed. + * Thus, code is changing TXQ zero to be remapped to TXQ 3. */ + if (skb->queue_mapping == 1) + skb->queue_mapping = 4; + + return TC_ACT_OK; +}