william linn
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # loxilb ebpf ## Introduction Loxilb is a networking solution that utilizes eBPF, leverage eBPF to modify the packet processing rules as they traverse the network stack in the Linux kernel. This can be particularly useful for network behavior without altering existing applications or the operating system itself. ## Core Components ### Object Files loxilb generates two primary object files during build: ``` /opt/loxilb/llb_ebpf_main.o # TC layer processing (305KB) /opt/loxilb/llb_xdp_main.o # XDP layer processing (95KB) ``` ### Hook Points | Feature | TC eBPF | XDP | | -------- | -------- | -------- | | Packet Format| Socket Buffer (skb) | XDP Frame Format | |Processing Level| L2-L7 | Primarily L2 1. TC eBPF Layer * Handles majority of L4+ processing * Optimized for complex operations * Supports TCP checksum offload * Handles connection tracking 2. XDP Layer * Performs quick L2 operations * Handles packet mirroring * Used for operations requiring multiple packet copies ### loxilb eBPF Maps eBPF (extended Berkeley Packet Filter) maps are essential data structures within the Linux kernel that facilitate efficient storage and sharing of data between eBPF programs and user-space applications. They function as key-value stores, enabling eBPF programs to maintain state across multiple invocations and allowing communication between the kernel and user space. * State Preservation * Kernel-User Space Communication * Data Sharing Among eBPF Programs LoxiLB utilizes eBPF maps to store and manage various data structures essential for packet processing. These maps are pinned to the filesystem, allowing for persistent storage and easy access. Commonly used maps include: * Interface Maps: Store information about network interfaces. * Connection Tracking Maps: Maintain state information for active connections. * NAT Maps: Handle Network Address Translation entries. * Policy Maps: Store security and routing policies. ## loxilb eBPF pipeline ![image](https://hackmd.io/_uploads/SJC03O2f1x.png =50%x) Then I will detail analysis of loxilb's end-to-end packet processing pipeline and Load Balancer based on this architecture diagram. ### What is eBPF Tail Call? An eBPF tail call is a mechanism that allows one eBPF program to call another eBPF program without returning to the original program. It's like a "jump" instruction that transfers control completely to another program and have benefit in: * Modular code structure * Efficient processing pipeline * Compliance with eBPF verifier limits ### Pipeline Selection Fast Path (pipe1)and Slow Path (pipe2), these two pipelines address the need for optimizing different types of packet processing tasks based on their complexity and requirements. ``` [Incoming Packet] ↓ [Parse Packet Headers] ↓ [Connection Lookup]─────Yes──┐ ↓ ↓ [Is Established?] [Process & Forward (Fast Path)] ↓ │ No │ ↓ │ [Tail Call to Slow Path] │ │ │ └──────────────────────┘ ``` #### TCP and UDP example ``` ### TCP Example: CLOSED → SYN_SENT → SYN_RECEIVED → ESTABLISHED │ │ │ ▼ [Slow Path Processing] [Move to Fast Path] ### UDP Example: NEW → SEEN → ESTABLISHED │ │ │ ▼ [Slow Path] [Move to Fast Path] ``` ### 1. Initial Packet Reception and Parsing `kernel/llb_kern_entry.c` ``` [Incoming Packet] → [packet parsing] ↓ [intf map] - Interface configuration lookup - Interface index - VLAN information - Zone information - Policy parameters ``` * When a packet arrives(parsing happens in `dp_parse_d0`), the packet parsing module extracts key metadata such as: * Source/destination MAC addresses * IP addresses * Layer 4 ports (if applicable) * Metadata is stored in the `xfi` structure, which guides further processing. * Interface-specific rules and properties are checked using `intf_map`. ### 2. QoS Processing `kernel/llb_kern_policer.c` ``` [QoS Stage] ↓ [pol map] - Policy lookup - Traffic policing rules - Rate limiting - Traffic shaping ↓ [qos map] - QoS parameters - Priority queues - Bandwidth allocation ``` * Traffic policies (e.g., rate-limiting, prioritization) are applied based on: * Policy map `pol_map`: Defines access control and prioritization policies. * QoS map `qos_map`: Ensures compliance with Quality of Service requirements (e.g., rate shaping). * Packets violating policies may be dropped or delayed. ### 3. Layer 2 Forwarding `kernel/llb_kern_l2fwd.c` #### Key Components * `l2fwd` (Layer 2 forwarding) * `l2tunfwd` (Layer 2 tunneling forwarding) #### Maps Used: * `smac_map`: Source MAC address * `dmac_map`: Destination MAC address * `rmac_map`: Router MAC address #### `l2fwd` (MAC-based forwarding) ``` [l2fwd Stage] ↓ [smac map] - Source MAC processing - MAC learning - Source validation ↓ [dmac map] - Destination MAC processing - MAC lookup - L2 forwarding decision ``` #### `l2tunfwd` (tunneling at Layer 2) ``` [l2tunfwd Stage] - VXLAN processing - NVGRE processing - Other L2 tunnel protocols ``` ### 4. Layer 3 Forwarding `kernel/llb_kern_l3fwd.c` #### Key Functions * `dp_ing_l3()`: Entry point for L3 ingress processing. * `dp_l3_fwd()`: Main function for Layer 3 forwarding. * `dp_do_rtv4()` and `dp_do_rtv6()`: Handle IPv4 and IPv6 route lookups and apply forwarding actions. * `dp_do_ctops()`: Handles connection tracking and NAT for packets. #### Maps Used: * `ct_map`: Connection tracking table for stateful flow handling. * `rt_v4_map`: IPv4 routing table. * `rt_v6_map`: IPv6 routing table. * `LL_DP_RTV4_STATS_MAP` and `LL_DP_RTV6_STATS_MAP`: Statistics for routes. ### 5. Load Balancer / Layer 4 Forwarding #### `kernel/llb_kern_ct.c` Provides connection tracking infrastructure ##### Key Components * Connection State Tracking: - Maintains connection states for all protocols (TCP/UDP/SCTP/ICMP) - Required for stateful operation in both load balancing and L4 forwarding * NAT Support Infrastructure: - Tracks NAT translations - Maintains original and translated addresses/ports - Essential for load balancer backend selection #### `kernel/llb_kern_natlbfwd.c`: Network Address Translation (NAT) and Load Balancer forwarding implementation #### Multiple load balancing algorithms: * Round Robin ```c if (act->sel_type == NAT_LB_SEL_RR) { bpf_spin_lock(&act->lock); i = act->sel_hint; // Iterate through endpoints while (n < LLB_MAX_NXFRMS) { if (nxfrm_act->inactive == 0) { // Select next backend in rotation act->sel_hint = (i + 1) % LLB_MAX_NXFRMS; sel = i; break; } } } ``` * Hash-based ```c if (act->sel_type == NAT_LB_SEL_HASH) { // Hash packet for backend selection sel = dp_get_pkt_hash(ctx) % act->nxfrm; // Fallback if selected backend is inactive if (act->nxfrms[sel].inactive) { for (i = 0; i < LLB_MAX_NXFRMS; i++) { if (act->nxfrms[i].inactive == 0) { sel = i; break; } } } } ``` * Least Connections ```c if (act->sel_type == NAT_LB_SEL_LC) { struct dp_nat_epacts *epa; __u32 lc = 0; // Find backend with least active connections for (i = 0; i < LLB_MAX_NXFRMS; i++) { if (nxfrm_act->inactive == 0) { __u32 as = epa->active_sess[i]; if (lc > as || sel < 0) { sel = i; lc = as; } } } } ``` * Persistent RR * N3 (GTP tunnel) based ## Conclusion about loxilb's effective use of eBPF ### Smart Pipeline Design * Dual pipeline architecture (Fast/Slow) optimizes performance * Fast path for established connections * Slow path for new connections and complex processing ### Effective Use of eBPF Features * Tail calls to overcome program size limits * Maps for state management * TC and XDP hooks for different processing needs ### loxilb particularly suitable for * Modern cloud-native environments * High-performance networking * Complex load balancing scenarios * Situations requiring efficient packet processing ## references * [What is eBPF ??](https://docs.loxilb.io/main/ebpf/) * [loxilb eBPF implementation details](https://docs.loxilb.io/latest/loxilbebpf/#loading-of-loxilb-ebpf-program) * [State synchronization of eBPF Maps using Go - A tale of two frameworks !](https://www.loxilb.io/post/state-synchronization-of-ebpf-maps-using-go-a-tale-of-two-frameworks) * [学习 loxilb(1):本地构建与测试](https://fuchencong.com/2024/06/27/loxilb-01/) ## About Hello, I'm William Lin. I'd like to share my excitement about being a member of the free5gc project, which is a part of the Linux Foundation. I'm always eager to discuss any aspects of core network development or related technologies. ### Connect with Me - GitHub: [williamlin0518](https://github.com/williamlin0518) - Linkedin: [Cheng Wei Lin](https://www.linkedin.com/in/cheng-wei-lin-b36b7b235/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully