Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
BPFの現在
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
kwi
January 13, 2017
Technology
1k
0
Share
BPFの現在
Linux eBPFをネットワーク機能まわりで使う使い方について。
kwi
January 13, 2017
More Decks by kwi
See All by kwi
SmartCitizen紹介
kwi
0
350
こんなのどうかな?
kwi
1
410
加古川パスタ♡の件
kwi
0
180
給食データを味わう
kwi
0
130
rocket-up
kwi
0
64
測ってみようよ
kwi
1
470
神戸市ウェブサイト動態
kwi
0
340
Code for 選挙
kwi
0
290
Code for Japan Summit 2017 紹介
kwi
0
150
Other Decks in Technology
See All in Technology
クラウドからエッジまで ~ 1,700台を支える監視設計~
optfit
0
110
PdM・Eng・QAで進めるAI駆動開発の現在地/aidd-with-pdm-eng-qa
shota_kusaba
0
250
可視化から活用へ — Mesh化・Segmentation・アライメントの研究動向
gpuunite_official
0
230
既存プロダクトQAから新規プロダクトQAへ
ryotakahashi
0
160
エンタープライズの厳格な制約を開発者に意識させない:クラウドネイティブ開発基盤設計/cloudnative-kaigi-golden-path
mhrtech
0
450
"うちにはまだ早い"は本当? ─ 小さく始めるPlatform Engineering入門
harukasakihara
7
630
AI対話分析の夢と、汚いデータの現実 Looker / Dataplex / Dataform で実現する品質ファーストな基盤設計
waiwai2111
0
650
開発サイクルのボーダーレス化に伴う組織変革から学んだこと / Organizational Transformation Amid the Borderless Development Cycle
mii3king
0
230
Fラン学生が考える、AI時代のデザインに執着した突破口
husengs7
1
210
R&D 祭 2024 UE5で絵コンテ・作画の制作支援ツールをつくる話
olmdrd
PRO
0
190
ワールドカフェ再び、そしてゴール・ルール・ロール・ツール / World Café Revisited, and the Goals-Rules-Roles-Tools
ks91
PRO
0
180
M&Aで増え続けるプロダクトに少数QAはどう立ち向かうか─GENDAが挑む、全員で取り組む品質標準化戦略 / GENDA Tech Talk #4
genda
0
150
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.9k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
The Spectacular Lies of Maps
axbom
PRO
1
750
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
500
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Building an army of robots
kneath
306
46k
Speed Design
sergeychernyshev
33
1.7k
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
380
Transcript
BPF の現在 Kawai, Hiroaki
cBPF, eBPF • BPF = Berkeley Packet Filter • cBPF
= Classic BPF – eBPF と区別するとき • tcpdump/libpcap – フィルタ式 – nfbpf_compile root@ubuntu:~# tcpdump -d arp (000) ldh [12] (001) jeq #0x806 jt 2 jf 3 (002) ret #262144 (003) ret #0 root@ubuntu:~# tcpdump -dd arp { 0x28, 0, 0, 0x0000000c }, { 0x15, 0, 1, 0x00000806 }, { 0x6, 0, 0, 0x00040000 }, { 0x6, 0, 0, 0x00000000 }, root@ubuntu:~# tcpdump -ddd arp 4 40 0 0 12 21 0 1 2054 6 0 0 262144 6 0 0 0
cBPF • フィルタ式 – pcap_compile • C macro (linux/filter.h) –
ex: BPF_STMT(BPF_LD | BPF_IMM, 1) • libseccomp – ex: seccomp_rule_add(SCMP_ACT_ALLOW, SCMP_SYS(close), 0);
eBPF • eBPF = 命令セットとして整備(別物) – ISA (Instruction Set Architecture)
– 64bit(x86_64, ARM64と整ってきたので) • JIT in kernel – CPU 命令セットにマッピング – cBPF も eBPF 経由で JIT される https://events.linuxfoundation.org/sites/events/files/slides/ebpf_on_the_mainframe_lcon_2015.pdf
eBPF compiler • フィルタ式 = DSL から C 言語(限定版)へ •
clang でコンパイル – eBPF / ELF オブジェクトファイル – tc はこれを使ったりする clang -O2 -emit-llvm -c bpf.c -o - \ | llc -march=bpf -filetype=obj -o bpf.o Ref: samples/bpf/README.rst
LLVM_P4 • P4実行環境としてのeBPF – CではなくP4で # p4llvm switch1.p4 # opt
–O2 switch1.ll –o switch1.ll # llc –march=bpf –filetype=obj –o switch1.o switch1.ll # tc qdisc add dev eth3 ingress # tc filter add dev eth3 parent ffff: bpf obj switch1.o exp /tmp/p4cli https://schd.ws/hosted_files/2016p4workshop/1d/Intel%20Fastabend-P4%20on%20the%20Edge.pdf
実行環境 • Linux kernel – socket filter – seccomp2 –
tc filter&action, iptables bpf module – tracing, perf – cgroup • Userland – iovisor/ubpf (Big switch) Chrome : packet=syscall引数 tcpdump libpcap iovisor
Load into kernel • 設定方法 – cBPF Bytecode バイト列を設定する •
cBPF (w/ extension) Bytecode は内部で eBPF 化 – eBPF/ELF ファイルから読み込む • Persistent (pinned) bpf object – Kernel /sys/fs/bpf で保持できる – “FD” が出てきたらこれを指していることも
networking • socket : ingress only, cBPF & eBPF •
tc : ingress & egress, cBPF & eBPF • iptables(netfilter) xt_bpf : socket 相当 • xdp : ingress only, eBPF • Lwt : pinned bpf, eBPF 新しいkernelでないと ダメなやつも多々…
Linux kernel • setsockopt SOL_SOCKET SO_ATTACH_BPF – SO_ATTACH_FILTER : cBPF
• rtnetlink – struct tcmsg/TCA_KIND=”bpf”, TCA_ACT_BPF – stcuct ifinfomsg/IFLA_XDP – struct rtmsg/LWT_BPF_IN, LWT_BPF_OUT, … • bpf(2) : fd 使う
bpf_prog_type • in-kernel での制限チェックで使われる • Packet data にアクセスできるか等 • きちんと完了するプログラムか等
• BPF fd の属性値として保持される • linux/bpf.h – BPF_PROG_TYPE_* – fdinfo (4.8~) SOCKET_FILTER KPROBE SCHED_CLS, SCHED_ACT TRACEPOINT XDP PERF_EVENT CGROUP_SKB, CGROUP_SOCK LWT_IN, LWT_OUT, LWT_XMIT
eBPF in C • 引数と返値 – tc : struct __sk_buff
• filter classifier と filter action で返値の意味が異なる – xdp : struct xdp_md : sk_buff に似せてある • BPF MAP – パケット数えたり – ルールを保持したり
BPF MAP • 種類 – BPF_TABLE • BPF_HASH • BPF_HISTOGRAM
• BPF_STACK_TRACE – BPF_TABLE_PUBLIC – BPF_PERF_OUTPUT – BPF_PERF_ARRAY root@ubuntu:/proc/3463/fd# ls -l total 0 lrwx------ 1 root root 64 Dec 22 02:21 0 -> /dev/pts/17 lrwx------ 1 root root 64 Dec 22 02:21 1 -> /dev/pts/17 lrwx------ 1 root root 64 Dec 22 02:21 10 -> anon_inode:bpf-map lrwx------ 1 root root 64 Dec 22 02:21 11 -> anon_inode:bpf-map lrwx------ 1 root root 64 Dec 22 02:21 12 -> anon_inode:bpf-prog lrwx------ 1 root root 64 Dec 22 02:21 13 -> anon_inode:bpf-prog lrwx------ 1 root root 64 Dec 22 02:21 14 -> anon_inode:bpf-prog lrwx------ 1 root root 64 Dec 22 02:21 15 -> anon_inode:bpf-prog lrwx------ 1 root root 64 Dec 22 02:21 2 -> /dev/pts/17 lr-x------ 1 root root 64 Dec 22 02:21 3 -> /dev/urandom lr-x------ 1 root root 64 Dec 22 02:21 4 -> pipe:[35440] l-wx------ 1 root root 64 Dec 22 02:21 5 -> pipe:[35440] lrwx------ 1 root root 64 Dec 22 02:21 6 -> socket:[35441] lr-x------ 1 root root 64 Dec 22 02:21 7 -> pipe:[35442] l-wx------ 1 root root 64 Dec 22 02:21 8 -> pipe:[35442] lrwx------ 1 root root 64 Dec 22 02:21 9 -> socket:[35443]
Writing eBPF • iovisor/bcc 使う(依存は増える) – BPF_MAP_GET_NEXT_KEY 無かったりとかもある • tc
filter classifier 使うのが現実的な選択 • C言語はコンパイラのココロを読みながら書く – prog_load失敗する=ココロが通じなかったとき • bpf_trace_printk – cat /sys/kernel/debug/tracing/trace_pipe
Tools • ubpf-disassembler (ubpf) – eBPF • bpfc (netsniff-ng) –
cBPF (w/ extension) • bpf_dbg (kernel) – eBPF