---
url: /manual/xdp.md
description: XDP/AF_XDP 在驱动层加速代理流，以及失败时的 tc 回退
---

# XDP：驱动层加速

`capture.xdp` 的主路径只做一件事：把已经判定为代理流的 LAN 帧从网卡驱动直接送到 AF_XDP socket，跳过 tc 到 TAP 的一段。配置了全功能 flowtable 时，部分直连流还会进入 native 实验路径。

## 完整配置

```yaml check
inbounds:
  router:
    type: capture
    lan: [br-lan]
    wan: [eth0]
    xdp: true
    xsk: auto

outbounds:
  direct:
    type: direct
  proxy:
    type: socks
    server: 127.0.0.1:1080

route:
  final: proxy

dns:
  servers:
    real: {type: udp, address: 1.1.1.1:53}
  final: real
```

字段见 [capture](/configuration/inbound/capture#xdp) 和 [capture#xsk](/configuration/inbound/capture#xsk)。

## 包怎么走

```text
LAN member -> native XDP -> AF_XDP -> gateway
LAN member -> tc -> TAP -> gateway          (fallback)
```

软件网桥本身没有驱动 XDP。mayami 把 XDP 挂到它的成员口；tc 仍挂在网桥上。单个成员时可从同一个 XSK 发回，多成员时 XSK 只收，发送交给网桥转发表。带 VLAN filtering 或 isolated 的成员不挂 XDP，避免绕过桥的过滤。

## 要求和回退

代理流 XDP 需要 Linux `BPF_SYSCALL`、`BPF_JIT`、BTF、cls_bpf、clsact、TUN、cgroup BPF、bpffs，以及驱动原生 `BASIC|REDIRECT`。零拷贝另需 `ZEROCOPY`；没有就协商 copy。

驱动的 native 直连路径还要求 `administration: exclusive`、Linux 6.18 语义、flowtable/conntrack kfunc 和严格的域条件。任何条件不满足都应退回 tc，正确性不变。

::: info 仅 Linux
XDP、AF_XDP、BTF 和 tc 都只在 Linux 上提供。其他平台不接受这些能力。
:::

## 验证

```sh
bpftool net
mayami api status
```

日志应说明 dispatcher 挂在哪个成员上，以及 `XDP unavailable, kernel capture retained` 这类回退原因。

## 相关

* [capture](/configuration/inbound/capture)
* [Router](/manual/router)
* [limits](/manual/limits)
