network-tc-ebpf

发布于:2022-10-30 ⋅ 阅读:(405) ⋅ 点赞:(0)

eBPF 的发展历史和核心设计 - eBPF 的发展历史和核心设计

eBPF Talk: 解密 XDP generic 模式 - eBPF Talk: 解密 XDP generic 模式

深入理解 tc ebpf 的 direct-action (da) 模式(2020) - 深入理解 tc ebpf 的 direct-action (da) 模式(2020)

全面介绍eBPF-概念 - 全面介绍eBPF-概念

Service Mesh架构新技能之eBPF入门与实践-技术圈

tc-bpf(8) - Linux manual page

tc/BPF and XDP/BPF - Hangbin Liu's blog

test_tc_dtime.c « progs « bpf « selftests « testing « tools - kernel/git/netdev/net.git - Netdev Group's networking tree

GitHub - pabeni/xdp_walkthrough_examples: sample code for an XDP walkthrough

你的第一个TC BPF 程序 - 腾讯云开发者社区-腾讯云

linux-bpf-learning/tc at master · nevermosby/linux-bpf-learning · GitHub


1. 编译 ebpf程序

clang -I ./headers/ -O2 -target bpf -c tc_hello.c -o tc_hello.o

2. 查看,加载tc

tc qdisc show dev ens34

tc qdisc add dev ens34 clsact

tc filter add dev ens34 ingress bpf da obj tc_hello.o sec ingress

tc qdisc show dev ens34 ingress

tc qdisc show dev ens34 egress

tc filter del dev ens34 ingress

tc qdisc del dev ens34 clsact

cat /sys/kernel/debug/tracing/trace_pipe

3. 源码

#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <stdint.h>

#include <iproute2/bpf_elf.h>

#include "bpf_endian.h"
#include "bpf_helpers.h"

static __always_inline int account_data(struct __sk_buff *skb, uint32_t dir)
{
        const char fmt_str[] = "hello\n";
        bpf_trace_printk(fmt_str, sizeof(fmt_str));

        return TC_ACT_OK;
}

SEC("ingress")
int tc_ingress(struct __sk_buff *skb)
{
    return account_data(skb, 0);
}

SEC("egress")
int tc_egress(struct __sk_buff *skb)
{
    return account_data(skb, 1);
}

char __license[] SEC("license") = "GPL";

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到