-
Notifications
You must be signed in to change notification settings - Fork 136
bpf tc can't load by tc or cargo bpf load #204
Comments
Hello @Sherlock-Holo Did you check this example?
Some sections are needed to be removed to load tc program
and then create qdisc if not exists $ sudo tc qdisc add dev lo clsact and try loading it $ sudo tc filter add ingress dev lo bpf da obj target/bpf/programs/learn_bpf/learn_bpf.elf sec tc_action/test |
I try but it reports
even I split the |
my llvm-strip version is
|
Then you sholud remove .debug_loc first. And then try removing .text section. |
so try
so keep trying
now can load by tc |
@rhdxmr well... that's so hard to try to remove the I have try similar bpf tc codes, written by c, and compile by and load by tc success directly, no need to remove any section is a plan to let redbpf can load by tc directly without removing some section? |
I understand your feeling because I also thought that running those commands are unintitive and bothering steps. And there is also another problem. .BTF section is unnecessary and problematic when running tc utility but it is useful in many cases other than tc case. So .BTF related sections are needed to be included to bpf obj optionally. I hope to handle these problems and help users but I guess it takes time. |
for now the problem of tc can be bypassed, but It seems https://github.com/foniod/redbpf/blob/main/cargo-bpf/src/load.rs#L35 |
@rhdxmr though strip these sections can let tc to load the bpf tc, but it seems it lost a lot of debug info, I am writing a TCP port block bpf tc, and it denied by bpf Verifier, without any analysis info |
As you said, redbpf/redbpf/src/load/loader.rs Lines 39 to 43 in a9b98c2
|
Are there any reasons the loader not support tc bpf? I also read the loader codes, and doesn't found any tc load codes |
I wrote a BPF program that is doing wrong pointer arithmetic. #![no_std]
#![no_main]
use redbpf_probes::tc::prelude::*;
program!(0xFFFFFFFE, "GPL");
#[tc_action]
unsafe fn test(skb: SkBuff) -> TcActionResult {
let invalid_p = skb.skb.add(10000) as *const u8;
let a = *invalid_p;
if a == 0 {
Ok(TcAction::Ok)
} else {
Ok(TcAction::Shot)
}
} All sections that are problematic with tc utility are removed. $ llvm-strip --no-strip-all --remove-section .BTF --remove-section .BTF.ext --remove-section .debug_loc --remove-section .debug_info --remove-section .debug_ranges --remove-section .debug_pubnames --remove-section .debug_pubtypes --remove-section .debug_frame --remove-section .debug_line --remove-section .text target/bpf/programs/learn_bpf/learn_bpf.elf
$ llvm-objdump --headers target/bpf/programs/learn_bpf/learn_bpf.elf
target/bpf/programs/learn_bpf/learn_bpf.elf: file format elf64-bpf
Sections:
Idx Name Size VMA Type
0 00000000 0000000000000000
1 tc_action/test 00000038 0000000000000000 TEXT
2 license 00000004 0000000000000000 DATA
3 version 00000004 0000000000000000 DATA
4 .debug_abbrev 000001ff 0000000000000000
5 .debug_str 0000071f 0000000000000000
6 .symtab 000000d8 0000000000000000
7 .strtab 00000076 0000000000000000 And I loaded the BPF program with tc $ sudo tc filter add ingress dev lo bpf da obj target/bpf/programs/learn_bpf/learn_bpf.elf sec tc_action/test
Prog section 'tc_action/test' rejected: Permission denied (13)!
- Type: 3
- Instructions: 7 (0 over limit)
- License: GPL
Verifier analysis:
0: (07) r1 += 1840000
1: (71) r1 = *(u8 *)(r1 +0)
dereference of modified ctx ptr R1 off=1840000 disallowed
processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
Error fetching program/map!
Unable to load program The output shows BPF verifier log that dumps BPF byte code.
|
tc_action BPF program is intended to be loaded by tc utility. And.. I am not sure RedBPF is a suitable tool for loading tc_action BPF programs. |
oh, add the
thanks for your tips |
the problem is similar: I convert a |
I guess I am not on the same page.. I don't know what you are saying. Can you elaborate? |
sorry for the confusing content I send it to the wrong web page, that's my fault. |
Ah ha that's OK. |
I create a shell script to remove those sections, but I am not familiar with the elf section. Are there any sections is necessary for other BPF program? if all of them are optional, maybe we can remove them at
|
It's ok to remove .debug_xxxx sections at tc-map-share.rs. It's just an example program so it does not affect other BPF programs. |
Is the rust code for bpf are directly compiled by llvm? Something like:
Or multiple steps are utilized to translate .rust to .xxx to .bpf? |
@d0u9 |
I just found that article, and that is much complex than I thought before. |
I agreed with your opinion so I tried to remove Thanks, |
I'm using Archlinux
I try this codes
and build with
cargo bpf build
When I try to load it by
sudo tc filter add ingress bpf da obj target/bpf/programs/learn_bpf/learn_bpf.elf sec tc_action/test
it reports
also I try to use cargo-bpf,
sudo -E cargo bpf load -i lo target/bpf/programs/learn_bpf/learn_bpf.elf
, it just stuck without any output.How should I do to load the bpf tc program?
The text was updated successfully, but these errors were encountered: