xdpcap

tcpdump like XDP packet capture

  • 所有者: cloudflare/xdpcap
  • 平台:
  • 許可證: BSD 3-Clause "New" or "Revised" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

xdpcap

xdpcap is a tcpdump like tool for eXpress Data Path (XDP).
It can capture packets and actions / return codes from XDP programs,
using standard tcpdump / libpcap filter expressions.

Instrumentation

XDP programs need to expose at least one hook point:

struct bpf_map_def xdpcap_hook = {
	.type = BPF_MAP_TYPE_PROG_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 4, // The max value of XDP_* constants
};

This map must be pinned inside a bpffs.

hook.h provides a convenience macro for declaring such maps:

#include "hook.h"

struct bpf_map_def xdpcap_hook = XDPCAP_HOOK();

return XDP_* statements should be modified to "feed" a hook:

#include "hook.h"

struct bpf_map_def xdpcap_hook = XDPCAP_HOOK();

int xdp_main(struct xdp_md *ctx) {
	return xdpcap_exit(ctx, &xdpcap_hook, XDP_PASS);
}

For a full example, see testdata/xdp_hook.c.

Depending on the granularity desired,
a program can expose multiple hook points,
or a hook can be reused across programs by using the same underlying map.

Package xdpcap provides a wrapper for
creating and pinning the hook maps using the newtools/ebpf loader.

Installation

go get -u github.com/cloudflare/xdpcap/cmd/xdpcap

Usage

  • Capture packets to a pcap:
    xdpcap /path/to/pinned/map dump.pcap "tcp and port 80"

  • Display captured packets:
    sudo xdpcap /path/to/pinned/map - "tcp and port 80", sudo tcpdump -r -

Limitations

  • filters run after the instrumented XDP program.
    If the program modifies the packet,
    the filter should match the modified packet,
    not the original input packet.

Tests

  • sudo -E $(which go) test

主要指標

概覽
名稱與所有者cloudflare/xdpcap
主編程語言Go
編程語言Go (語言數: 2)
平台
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2019-03-12 09:41:37
推送於2024-09-25 22:46:54
最后一次提交2024-09-19 21:53:29
發布數0
用户参与
星數738
關注者數23
派生數77
提交數52
已啟用問題?
問題數37
打開的問題數13
拉請求數26
打開的拉請求數5
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?