Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect and output skb->cb when --filter-trace-tc #461

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bpf/kprobe_pwru.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct skb_meta {
u32 len;
u32 mtu;
u16 protocol;
u16 pad;
u32 cb[5];
} __attribute__((packed));

struct tuple {
Expand Down Expand Up @@ -143,7 +143,8 @@ struct config {
u8 output_shinfo: 1;
u8 output_stack: 1;
u8 output_caller: 1;
u8 output_unused: 2;
u8 output_cb: 1;
u8 output_unused: 1;
u8 is_set: 1;
u8 track_skb: 1;
u8 track_skb_by_stackid: 1;
Expand Down Expand Up @@ -443,6 +444,11 @@ set_output(void *ctx, struct sk_buff *skb, struct event_t *event) {
if (cfg->output_stack) {
event->print_stack_id = bpf_get_stackid(ctx, &print_stack_map, BPF_F_FAST_STACK_CMP);
}

if (cfg->output_cb) {
struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)&skb->cb;
bpf_probe_read_kernel(&event->meta.cb, sizeof(event->meta.cb), (void *)&cb->data);
}
}

static __noinline bool
Expand Down
4 changes: 4 additions & 0 deletions internal/pwru/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
OutputShinfoMask
OutputStackMask
OutputCallerMask
OutputCbMask
)

const (
Expand Down Expand Up @@ -69,6 +70,9 @@ func GetConfig(flags *Flags) (cfg FilterCfg, err error) {
if flags.OutputCaller {
cfg.OutputFlags |= OutputCallerMask
}
if flags.FilterTraceTc {
cfg.OutputFlags |= OutputCbMask
}
if flags.FilterTrackSkb {
cfg.FilterFlags |= TrackSkbMask
}
Expand Down
18 changes: 18 additions & 0 deletions internal/pwru/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type jsonPrinter struct {
Proto uint16 `json:"proto,omitempty"`
Mtu uint32 `json:"mtu,omitempty"`
Len uint32 `json:"len,omitempty"`
Cb [5]uint32 `json:"cb,omitempty"`
Tuple *jsonTuple `json:"tuple,omitempty"`
Stack interface{} `json:"stack,omitempty"`
SkbMetadata interface{} `json:"skb_metadata,omitempty"`
Expand Down Expand Up @@ -141,6 +142,9 @@ func (o *output) PrintHeader() {
}
if o.flags.OutputMeta {
fmt.Fprintf(o.writer, " %-10s %-8s %16s %-6s %-5s %-5s", "NETNS", "MARK/x", centerAlignString("IFACE", 16), "PROTO", "MTU", "LEN")
if o.flags.FilterTraceTc {
fmt.Fprintf(o.writer, " %-56s", "__sk_buff->cb[]")
}
}
if o.flags.OutputTuple {
fmt.Fprintf(o.writer, " %s", "TUPLE")
Expand Down Expand Up @@ -187,6 +191,9 @@ func (o *output) PrintJson(event *Event) {
d.Proto = byteorder.NetworkToHost16(event.Meta.Proto)
d.Mtu = event.Meta.MTU
d.Len = event.Meta.Len
if o.flags.FilterTraceTc {
d.Cb = event.Meta.Cb
}
}

if o.flags.OutputTuple {
Expand Down Expand Up @@ -330,6 +337,14 @@ func getMetaData(event *Event, o *output) (metaData string) {
return metaData
}

func getCb(event *Event) (cb string) {
res := []string{}
for _, val := range event.Meta.Cb {
res = append(res, fmt.Sprintf("0x%08X", val))
}
return fmt.Sprintf("[%s]", strings.Join(res, ","))
}

func getOutFuncName(o *output, event *Event, addr uint64) string {
var funcName string

Expand Down Expand Up @@ -410,6 +425,9 @@ func (o *output) Print(event *Event) {

if o.flags.OutputMeta {
fmt.Fprintf(o.writer, " %s", getMetaData(event, o))
if o.flags.FilterTraceTc {
fmt.Fprintf(o.writer, " %s", getCb(event))
}
}

if o.flags.OutputTuple {
Expand Down
2 changes: 1 addition & 1 deletion internal/pwru/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type Meta struct {
Len uint32
MTU uint32
Proto uint16
Pad uint16
Cb [5]uint32
}

type StackData struct {
Expand Down
Loading