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 MTU from skb->_skb_refdst #388

Merged
merged 1 commit into from
Jul 7, 2024
Merged
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
18 changes: 18 additions & 0 deletions bpf/kprobe_pwru.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
#define ETH_P_IP 0x800
#define ETH_P_IPV6 0x86dd

#define RTAX_MTU 2
#define SKB_DST_NOREF 1UL
#define SKB_DST_PTRMASK ~(SKB_DST_NOREF)
#define __SKB_DST_PTR(X) \
((struct dst_entry *)((X) & SKB_DST_PTRMASK))

#define DST_METRICS_FLAGS 0x3UL
#define __DST_METRICS_PTR(X) \
((u32 *)((X) & ~DST_METRICS_FLAGS))


const static bool TRUE = true;

volatile const static __u64 BPF_PROG_ADDR = 0;
Expand Down Expand Up @@ -230,6 +241,13 @@ set_meta(struct sk_buff *skb, struct skb_meta *meta) {
meta->protocol = BPF_CORE_READ(skb, protocol);
meta->ifindex = BPF_CORE_READ(skb, dev, ifindex);
meta->mtu = BPF_CORE_READ(skb, dev, mtu);
struct dst_entry *dst = __SKB_DST_PTR(BPF_CORE_READ(skb, _skb_refdst));
if (dst) {
u32 *metrics = __DST_METRICS_PTR(BPF_CORE_READ(dst, _metrics));
bpf_probe_read_kernel(&meta->mtu, sizeof(meta->mtu), metrics + RTAX_MTU - 1);
if (!meta->mtu)
meta->mtu = BPF_CORE_READ(dst, dev, mtu);
}
}

static __always_inline void
Expand Down
Loading