Git Product home page Git Product logo

cilium-ebpf-tc's Introduction

Playing with cilium ebpf to add a tc filter

tc ingress/egress packet monitor

An ebpf filter bpf/bpf.c is added to the kernel tc extension point. This records information about the incoming/outgoing packets (depending on where the user space program places the filter). Packet information is recorded in an ebpf map.

User space code main.go repeatedly reads and outputs the contents of the map.

Setup

See bpf/README.md for setting up kernel source and generating the bpf headers. Instructions are for ubuntu but should be easy to adapt to other distros.

Running

Run build-and-run.sh to:

  1. build the ebpf object code (using bpf2go) and generate go 'headers' (tc_bpf*.go files)
  2. build the go program
  3. run the go program

main.go sets up a qdisc, adds it to the interface (change this by editing the INTERFACE constant in main.go) as a tc filter and then outputs the contents of the ebpf map from userspace.

Run remove-filter-and-qdisc.sh to:

  1. Remove the tc filter and qdisc added by the run script.

cilium-ebpf-tc's People

Contributors

georgenicoll avatar

Watchers

 avatar  avatar

Forkers

nobinpegasus

cilium-ebpf-tc's Issues

[Feature] I want to also capture the pid info additional to the network infos

SEC("tc_prog")
int tc_main(struct __sk_buff *skb)
{
    void *data_end = (void *)(__u64)skb->data_end;
    void *data = (void *)(__u64)skb->data;
    struct ethhdr *eth;
    struct iphdr *ip;
    struct tcphdr *tcp;
    struct udphdr *udp;
    // int pid = (int) bpf_get_current_pid_tgid() >> 32;
    // if (skb->protocol != bpf_htons(ETH_P_IP))
    //     return TC_ACT_OK;
    __u32 pid = bpf_get_current_pid_tgid() >> 32;
    ```
    I want something like this. I know bpf_get_current_pid_tgid() can be used with ctx. So how should I do the edits?
    So that I can get the pid with the current code?

The code is showing wrong port information

The source port and dest port doesn't match the actual one.
I've cross checked it using wireshark
Look at this image
image

Now look at this. Most of the time. Source port and Dest port are the same in your code

image

Please fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.