SlideShare a Scribd company logo
1 of 28
Download to read offline
⾃⼰的eBPF程式⾃⼰做
Create an eBPF program by yourself
Huai-En Tseng
About me
• Huai-En Tseng 曾懷恩

• ChungHwa telecommunication laboratory.

• Associate researcher in Broadband
networks laboratory

• Focus on virtualization, high performance
computing, Linux kernel, system
programming optimization, network protocol
implementation, SDN

• Github: https://github.com/w180112

• Linkedin: https://www.linkedin.com/in/huai-
en-tseng-a10975157/
Contents
• What's eBPF/BPF?

• How to build eBPF from in-kernel source

• Program an eBPF program by hand

• Quick demo
What's eBPF/BPF?
• Berkeley Packet Filter

• in-kernel virtual machine

• basement of tcpdump and Wireshark 

• invented in 1992 at USENIX conference

• BSD socket provides BPF injection custom rules
• Main idea: copy and filter
What's eBPF/BPF?
What's eBPF/BPF?
• extend BPF

• from filter to monitoring, traffic control, kernel tracing

• high level c language to inject the BPF pseudo code

• kernel space - user space can exchange info using BPF map structure

• compiled by llvm/clang, in-kernel verifier

• the traditional BPF is also called classic BPF(cBPF)
eBPF machanism
• An eBPF program can be split into 2 parts

• user space BPF loader

• kernel space BPF elf program

• BPF loader loads BPF program into

kernel space 

• Then BPF program can be executed in in-kernel
BPF virtual machine
eBPF types
• eBPF supports many different features

• kernel tracing

• network monitoring

• traffic control 

• eXpress Data Path

• increasing in each kernel version from v3.17
eBPF types listed in /include/uapi/inux/bpf.h

in kernel version v5.8.9
eBPF maps
• In eBPF, there are several maps structures

• Unlike cBPF using recv(), eBPF exchange
information between kernel space eBPF
program and user space BPF loader

• BPF_MAP_TYPE_ARRAY,
BPF_MAP_TYPE_PERCPU_ARRAY

• BPF_MAP_TYPE_HASH,
BPF_MAP_TYPE_PERCPU_HASH

• and others
eBPF maps listed in /include/uapi/inux/bpf.h

in kernel version v5.8.9
What's eBPF/BPF? - XDP
What's eBPF/BPF? - XDP
Contents
• What's eBPF/BPF?

• How to build eBPF from in-kernel source

• Program an eBPF program by hand

• Quick demo
eBPF tools
• BCC

• TC

• iproute2

• In-kernel source
in-kernel eBPF examples
• Many eBPF example source code is included in Linux kernel source code
under samples/bpf/

• and can be compiled by its own makefile
How to compile
• How to compile in-kernel eBPF source code? (Ubuntu 18.04)

• prerequisite

• verify your kernel version and download the kernel source code
match to your kernel version

• install required packages

• cd to /usr/src/linux-source-5.0.0/linux-source-5.0.0/ and start to
compile
Contents
• What's eBPF/BPF?

• How to build eBPF from in-kernel source

• Program an eBPF program by hand

• Quick demo
eBPF program analyzing
• Each eBPF program has hook point and type, programmer should define
the type in eBPF loader

• eBPF loader will look for SEC() to find eBPF hook point function definition

• The hook point type is depends on what types of eBPF in eBPF loader

• e.g. in XDP eBPF program source code, the parameter of hook point
function is a struct xdp_md pointer variable
eBPF program analyzing - using XDP
head of packet
tail of packet
eBPF program analyzing - using XDP
• Each XDP program should return XDP_* value at the end of XDP function
definition
drop packet directly
allow packet go through 

into network stack
eBPF program analyzing - using XDP
• Our eBPF program is just like this so far.
• Now, let's start to add some code. First, we need to get the packet we
receive
eBPF program analyzing - using XDP
• Next, we can add whatever we want to
implement in this XDP program

• For this example, we try to filter and
drop incoming packets which are UDP
and port 55688
eBPF program analyzing
• We sometimes want to exchange data between user space eBPF loader
using MAP structure

• In this example, we try to statistic each incoming udp packet and store
into the map structure
Atomic operation
eBPF loader analyzing
• In eBPF loader, there are several steps to load eBPF program:

• find eBPF elf file and load the eBPF file file

• bpf_prog_load_xattr()

• find the hook point in eBPF program - the string in SEC()

• bpf_object__find_program_by_title()

• load the hook point function followed by the SEC()

• bpf_program__fd()

• In XDP loader, we need to attach the XDP program to network interface

• bpf_set_link_xdp_fd()
eBPF loader analyzing
• If the map structure is used, we should:

• find whether there is map in eBPF program and the map if so

• bpf_map__next()

• bpf_map__fd()

• set the entries in the map to 0

• bpf_map_update_elem()

• Then we can fetch the value in the map in each entry

• bpf_map_lookup_elem()
Modify the makefile in kernel source
• This makefile uses kbuild system to compile.

• Define the compile executable file name 

• hostprogs-y += get_pkts

• Define the object files loader needs

• get_pkts-objs := bpf_load.o get_pkts_user.o

• Add always variable to compile elf file

• always += get_pkts_kern.o
Contents
• What's eBPF/BPF?

• How to build eBPF from in-kernel source

• Program an eBPF program by hand

• Quick demo
Quick demo
Thanks for attending

More Related Content

What's hot

Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumScyllaDB
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCKernel TLV
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
Replacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumReplacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumMichal Rostecki
 
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdf
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdfKCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdf
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdfRaphaël PINSON
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedBrendan Gregg
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPFAlex Maestretti
 
Laravel ユーザなら知っておくべきAuthオートログイン
Laravel ユーザなら知っておくべきAuthオートログインLaravel ユーザなら知っておくべきAuthオートログイン
Laravel ユーザなら知っておくべきAuthオートログインMasashi Shinbara
 
eBPF Perf Tools 2019
eBPF Perf Tools 2019eBPF Perf Tools 2019
eBPF Perf Tools 2019Brendan Gregg
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KernelThomas Graf
 
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMXPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMThe Linux Foundation
 
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...ContainerDay Security 2023
 
Go logging using eBPF
Go logging using eBPFGo logging using eBPF
Go logging using eBPFZain Asgar
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdf
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdfNHN 게임서버엔진팀 리빌딩과 운영 방침.pdf
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdfMancheol Jeon
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFoholiab
 

What's hot (20)

Using eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in CiliumUsing eBPF for High-Performance Networking in Cilium
Using eBPF for High-Performance Networking in Cilium
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
Replacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with CiliumReplacing iptables with eBPF in Kubernetes with Cilium
Replacing iptables with eBPF in Kubernetes with Cilium
 
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdf
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdfKCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdf
KCD Zurich 2023 — Bridge Dev & Ops with eBPF.pdf
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting Started
 
Security Monitoring with eBPF
Security Monitoring with eBPFSecurity Monitoring with eBPF
Security Monitoring with eBPF
 
Laravel ユーザなら知っておくべきAuthオートログイン
Laravel ユーザなら知っておくべきAuthオートログインLaravel ユーザなら知っておくべきAuthオートログイン
Laravel ユーザなら知っておくべきAuthオートログイン
 
eBPF Basics
eBPF BasicseBPF Basics
eBPF Basics
 
eBPF Perf Tools 2019
eBPF Perf Tools 2019eBPF Perf Tools 2019
eBPF Perf Tools 2019
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
 
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARMXPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
XPDS16: Porting Xen on ARM to a new SOC - Julien Grall, ARM
 
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...
Enhancing Network and Runtime Security with Cilium and Tetragon by Raymond De...
 
Go logging using eBPF
Go logging using eBPFGo logging using eBPF
Go logging using eBPF
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdf
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdfNHN 게임서버엔진팀 리빌딩과 운영 방침.pdf
NHN 게임서버엔진팀 리빌딩과 운영 방침.pdf
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPFA Kernel of Truth: Intrusion Detection and Attestation with eBPF
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
 

Similar to Create an eBPF program by yourself

DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthFelipe Prado
 
story_of_bpf-1.pdf
story_of_bpf-1.pdfstory_of_bpf-1.pdf
story_of_bpf-1.pdfhegikip775
 
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdf
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdfCalico-eBPF-Dataplane-CNCF-Webinar-Slides.pdf
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdfyingxinwang4
 
Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug huntingAndrea Righi
 
Compiling P4 to XDP, IOVISOR Summit 2017
Compiling P4 to XDP, IOVISOR Summit 2017Compiling P4 to XDP, IOVISOR Summit 2017
Compiling P4 to XDP, IOVISOR Summit 2017Cheng-Chun William Tu
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMSherif Mousa
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsKernel TLV
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studioNitesh Singh
 
Transparent eBPF Offload: Playing Nice with the Linux Kernel
Transparent eBPF Offload: Playing Nice with the Linux KernelTransparent eBPF Offload: Playing Nice with the Linux Kernel
Transparent eBPF Offload: Playing Nice with the Linux KernelOpen-NFP
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadOpen-NFP
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookAnne Nicolas
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)p3castro
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machineAlexei Starovoitov
 
eBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniqueseBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniquesNetronome
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017OpenEBS
 
Rina p4 rina workshop
Rina p4   rina workshopRina p4   rina workshop
Rina p4 rina workshopEduard Grasa
 
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructureDevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructureAngelo Failla
 

Similar to Create an eBPF program by yourself (20)

DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depth
 
story_of_bpf-1.pdf
story_of_bpf-1.pdfstory_of_bpf-1.pdf
story_of_bpf-1.pdf
 
Ebpf ovsconf-2016
Ebpf ovsconf-2016Ebpf ovsconf-2016
Ebpf ovsconf-2016
 
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdf
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdfCalico-eBPF-Dataplane-CNCF-Webinar-Slides.pdf
Calico-eBPF-Dataplane-CNCF-Webinar-Slides.pdf
 
Kernel bug hunting
Kernel bug huntingKernel bug hunting
Kernel bug hunting
 
eBPF Workshop
eBPF WorkshopeBPF Workshop
eBPF Workshop
 
Compiling P4 to XDP, IOVISOR Summit 2017
Compiling P4 to XDP, IOVISOR Summit 2017Compiling P4 to XDP, IOVISOR Summit 2017
Compiling P4 to XDP, IOVISOR Summit 2017
 
Building Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARMBuilding Embedded Linux Full Tutorial for ARM
Building Embedded Linux Full Tutorial for ARM
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
 
Embedded c & working with avr studio
Embedded c & working with avr studioEmbedded c & working with avr studio
Embedded c & working with avr studio
 
Transparent eBPF Offload: Playing Nice with the Linux Kernel
Transparent eBPF Offload: Playing Nice with the Linux KernelTransparent eBPF Offload: Playing Nice with the Linux Kernel
Transparent eBPF Offload: Playing Nice with the Linux Kernel
 
P4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC OffloadP4, EPBF, and Linux TC Offload
P4, EPBF, and Linux TC Offload
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
eBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current TechniqueseBPF Debugging Infrastructure - Current Techniques
eBPF Debugging Infrastructure - Current Techniques
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
 
Rina p4 rina workshop
Rina p4   rina workshopRina p4   rina workshop
Rina p4 rina workshop
 
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructureDevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 

Recently uploaded

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Recently uploaded (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Create an eBPF program by yourself

  • 1. ⾃⼰的eBPF程式⾃⼰做 Create an eBPF program by yourself Huai-En Tseng
  • 2. About me • Huai-En Tseng 曾懷恩 • ChungHwa telecommunication laboratory. • Associate researcher in Broadband networks laboratory • Focus on virtualization, high performance computing, Linux kernel, system programming optimization, network protocol implementation, SDN • Github: https://github.com/w180112 • Linkedin: https://www.linkedin.com/in/huai- en-tseng-a10975157/
  • 3. Contents • What's eBPF/BPF? • How to build eBPF from in-kernel source • Program an eBPF program by hand • Quick demo
  • 4. What's eBPF/BPF? • Berkeley Packet Filter • in-kernel virtual machine • basement of tcpdump and Wireshark • invented in 1992 at USENIX conference • BSD socket provides BPF injection custom rules
  • 5. • Main idea: copy and filter What's eBPF/BPF?
  • 6. What's eBPF/BPF? • extend BPF • from filter to monitoring, traffic control, kernel tracing • high level c language to inject the BPF pseudo code • kernel space - user space can exchange info using BPF map structure • compiled by llvm/clang, in-kernel verifier • the traditional BPF is also called classic BPF(cBPF)
  • 7. eBPF machanism • An eBPF program can be split into 2 parts • user space BPF loader • kernel space BPF elf program • BPF loader loads BPF program into
 kernel space • Then BPF program can be executed in in-kernel BPF virtual machine
  • 8. eBPF types • eBPF supports many different features • kernel tracing • network monitoring • traffic control • eXpress Data Path • increasing in each kernel version from v3.17 eBPF types listed in /include/uapi/inux/bpf.h
 in kernel version v5.8.9
  • 9. eBPF maps • In eBPF, there are several maps structures • Unlike cBPF using recv(), eBPF exchange information between kernel space eBPF program and user space BPF loader • BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY • BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH • and others eBPF maps listed in /include/uapi/inux/bpf.h
 in kernel version v5.8.9
  • 12. Contents • What's eBPF/BPF? • How to build eBPF from in-kernel source • Program an eBPF program by hand • Quick demo
  • 13. eBPF tools • BCC • TC • iproute2 • In-kernel source
  • 14. in-kernel eBPF examples • Many eBPF example source code is included in Linux kernel source code under samples/bpf/ • and can be compiled by its own makefile
  • 15. How to compile • How to compile in-kernel eBPF source code? (Ubuntu 18.04) • prerequisite • verify your kernel version and download the kernel source code match to your kernel version • install required packages • cd to /usr/src/linux-source-5.0.0/linux-source-5.0.0/ and start to compile
  • 16. Contents • What's eBPF/BPF? • How to build eBPF from in-kernel source • Program an eBPF program by hand • Quick demo
  • 17. eBPF program analyzing • Each eBPF program has hook point and type, programmer should define the type in eBPF loader • eBPF loader will look for SEC() to find eBPF hook point function definition • The hook point type is depends on what types of eBPF in eBPF loader • e.g. in XDP eBPF program source code, the parameter of hook point function is a struct xdp_md pointer variable
  • 18. eBPF program analyzing - using XDP head of packet tail of packet
  • 19. eBPF program analyzing - using XDP • Each XDP program should return XDP_* value at the end of XDP function definition drop packet directly allow packet go through 
 into network stack
  • 20. eBPF program analyzing - using XDP • Our eBPF program is just like this so far. • Now, let's start to add some code. First, we need to get the packet we receive
  • 21. eBPF program analyzing - using XDP • Next, we can add whatever we want to implement in this XDP program • For this example, we try to filter and drop incoming packets which are UDP and port 55688
  • 22. eBPF program analyzing • We sometimes want to exchange data between user space eBPF loader using MAP structure • In this example, we try to statistic each incoming udp packet and store into the map structure Atomic operation
  • 23. eBPF loader analyzing • In eBPF loader, there are several steps to load eBPF program: • find eBPF elf file and load the eBPF file file • bpf_prog_load_xattr() • find the hook point in eBPF program - the string in SEC() • bpf_object__find_program_by_title() • load the hook point function followed by the SEC() • bpf_program__fd() • In XDP loader, we need to attach the XDP program to network interface • bpf_set_link_xdp_fd()
  • 24. eBPF loader analyzing • If the map structure is used, we should: • find whether there is map in eBPF program and the map if so • bpf_map__next() • bpf_map__fd() • set the entries in the map to 0 • bpf_map_update_elem() • Then we can fetch the value in the map in each entry • bpf_map_lookup_elem()
  • 25. Modify the makefile in kernel source • This makefile uses kbuild system to compile. • Define the compile executable file name • hostprogs-y += get_pkts • Define the object files loader needs • get_pkts-objs := bpf_load.o get_pkts_user.o • Add always variable to compile elf file • always += get_pkts_kern.o
  • 26. Contents • What's eBPF/BPF? • How to build eBPF from in-kernel source • Program an eBPF program by hand • Quick demo