当前位置: 首页 > news >正文

ubuntu 18.04 中 eBPF samples/bpf 编译

1. history 信息

一次成功编译 bpf 后执行 history 得到的信息:

yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ history1  ls2  mkdir ex3  cd ex4  mkdir ex_kernel5  ls /boot/6  sudo apt install linux-source7  ls /usr/src/8  uname -r9  cd ex_kernel/10  wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.tar.gz11  ls12  tar zxf linux-5.4.tar.gz 13  ls14  cd linux-5.4/15  cp /boot/config-5.4.0-152-generic .config16  make oldconfig17  python --version18  sudo apt install python319  python3 --version20  python21  sudo apt install -y bison build-essential cmake flex git libedit-dev pkg-config libmnl-dev    python zlib1g-dev libssl-dev libelf-dev libcap-dev libfl-dev llvm clang pkg-config    gcc-multilib luajit libluajit-5.1-dev libncurses5-dev libclang-dev clang-tools22  make oldconfig23  make prepare24  make modules_prepare25  make headers_install26  make M=samples/bpf27  cd samples/bpf28  ls29  ./sockex130  ./trace531  ./tracex532  ./sampleip 33  cd ..34  l35  wget36  wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz37  ls38  tar zxf linux-5.4.1.tar.gz 39  uname -r40  cd linux-5.4.1/41  cp /boot/config-5.4.0-152-generic .config42  cd ..43  cd linux-5.444  ls45  cd samples/bpf/46  ls47  sudo ./tracex648  ls49  sudo ./sockex150  cd ../../../linux-5.4.1/51  ls52  make oldconfig53  make prepare54  make modules_prepare55  make headers_install56  make M=samples/bpf57  ls58  cd samples/bpf/59  ls60  sudo ./sockex161  cd ../..62  ls63  cd ..64  ls65  git --version66  sudo apt install nasm67  ls68  cd ..69  mkdir asm_ex70  cd ex71  cd ex_kernel/72  ls73  cd linux-5.474  ls75  make -j476  llc -version77  ls78  history
yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ 

2. 使用 ubuntu 18.04

    ubuntu 18.04 编译 BPF比较简单, ubuntu 22.04 适合系统熟手;

找一台 旧机器,安装一个 ubuntu 18.0;

使用国内源:

yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ cat /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ 

         

sudo apt update
sudo apt upgrade

3. 选择linux kernel 源代码版本

$ name -ryingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ uname -r
5.4.0-84-generic
yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ 

http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz

$ wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz$ tar dxf linux-5.4.1.tar.gz
$ cd linux-5.4.1/# or 版本不一定合适
$ sudo apt install linux-source
$ ls /usr/src/

4. 编译 bpf

4.1 准备环境

sudo apt install -y bison build-essential cmake flex git libedit-dev pkg-config libmnl-dev    python zlib1g-dev libssl-dev libelf-dev libcap-dev libfl-dev llvm clang pkg-config    gcc-multilib luajit libluajit-5.1-dev libncurses5-dev libclang-dev clang-tools

4.2 拷贝当前系统的kernel 配置文件 .config

$ cp /boot/config-5.4.0-152-generic /home/yingzhi/ex/ex_kernel/linux-5.4.1/.config

4.3 编译ebpf samples

$ cd /home/yingzhi/ex/ex_kernel/linux-5.4.1/
$ make oldconfig
$ make prepare
$ make modules_prepare
$ make headers_install
$ make M=samples/bpf

4.4 运行 示例

ls ./samples/bpf/

$ sudo ./sockex1

5. bpf 原理

5.1 架构

5.2 编写并分析一个示例

5.3 bpf map

5.4 bpf trace

5.5 bpf tool

5.6 bpf && network

5.7 xdp

6. eBPF JIT

7. 参考:

1. 

eBPF - Introduction, Tutorials & Community Resources

http://www.lryc.cn/news/174726.html

相关文章:

  • 新版Chromedriver在哪下载(Chromedriver 116.0.5845.188的寻找之旅)
  • React基础知识点
  • linux用户和权限命令学习记录
  • React(react18)中组件通信05——redux ➕ react-redux(含数据共享)
  • 字符函数和字符串函数(1)
  • Visual Studio Code从GIT拉取vue项目并运行
  • 【知识分享】Java获取全年每个月的有几周且每周是几号到几号
  • 学信息系统项目管理师第4版系列11_信息安全管理
  • sql注入原理分析
  • Mac磁盘空间满了怎么办?Mac如何清理磁盘空间
  • 能ping通但无法上网的问题
  • 仿制 Google Chrome 的恐龙小游戏
  • Redis面试题(五)
  • 组队竞赛(int溢出问题)
  • Swift SwiftUI 隐藏键盘
  • Python与数据分析--Pandas-1
  • 如何完美通过token获取用户信息(springboot)
  • 2023 “华为杯” 中国研究生数学建模竞赛(B题)深度剖析|数学建模完整代码+建模过程全解全析
  • 文件相关工具类
  • 18795-2012 茶叶标准样品制备技术条件
  • C++11互斥锁的使用
  • unity 桌面程序
  • echarts统一纵坐标y轴的刻度线,刻度线对齐。
  • 一个数据库版本兼容问题
  • 学习Nano编辑器:入门指南、安装步骤、基本操作和高级功能
  • 在北京多有钱能称为富
  • Chrome扩展程序开发随记
  • 使用命令行快速创建Vite项目
  • int *a, int **a, int a[], int *a[]的区别
  • leetcode100----双指针