- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试重定向 NIC 和 WIFI 之间的流量。我正在尝试从 eth0 转发数据包,通过 wlan0 发送偶数数据包,通过 wlan1 发送奇数数据包。
我无法成功地将数据包从一个接口(interface)重定向到另一个接口(interface),除非这些接口(interface)是虚拟的(例如在 xdp-tutorial 中创建的接口(interface))。
是否有一个简单的例子可以将入口数据包从 eth0 的 MAC 28:f1:f1:f1:f1:f1 重定向到 wlan0 的 MAC e4:f1:f1:f1:f1:f1? (示例 MAC)因此,如果我通过以太网端口连接第二台计算机(假设路由正确)并 ping 8.8.8.8,它会通过 wlan0 发送数据包吗?
在这方面,我将不胜感激。
编辑:
我使用的代码来自xdp-tutorial。
逐步设置:
# Mount map directory
sudo mount -t bpf bpf /sys/fs/bpf/
# Load the programs
sudo ./xdp_loader -d eth0 -S --filename xdp_prog_kern_03.o --progsec xdp_redirect_map -F
sudo ./xdp_loader -d wlan0 -S --filename xdp_prog_kern_03.o --progsec xdp_pass -F
# Set up redirect map
sudo ./xdp_prog_user -d eth0 -r wlan0 --src-mac 28:f1:f1:f1:f1:f1 --dest-mac e4:f1:f1:f1:f1:f1
最后一条命令输出:
map dir: /sys/fs/bpf/eth0
redirect from ifnum=5 to ifnum=3
forward: 28:f1:f1:f1:f1:f1 -> e4:f1:f1:f1:f1:f1
相关的BPF代码是
struct bpf_map_def SEC("maps") tx_port = {
.type = BPF_MAP_TYPE_DEVMAP,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 256,
};
struct bpf_map_def SEC("maps") redirect_params = {
.type = BPF_MAP_TYPE_HASH,
.key_size = ETH_ALEN,
.value_size = ETH_ALEN,
.max_entries = 1,
};
SEC("xdp_redirect_map")
int xdp_redirect_map_func(struct xdp_md *ctx)
{
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
struct hdr_cursor nh;
struct ethhdr *eth;
int eth_type;
int action = XDP_PASS;
unsigned char *dst;
/* These keep track of the next header type and iterator pointer */
nh.pos = data;
/* Parse Ethernet and IP/IPv6 headers */
eth_type = parse_ethhdr(&nh, data_end, ð);
if (eth_type == -1)
return xdp_stats_record_action(ctx, XDP_DROP);
/* Do we know where to redirect this packet? */
dst = bpf_map_lookup_elem(&redirect_params, eth->h_source);
if (!dst)
goto out;
/* Set a proper destination address */
memcpy(eth->h_dest, dst, ETH_ALEN);
action = bpf_redirect_map(&tx_port, 0, 0);
out:
return xdp_stats_record_action(ctx, action);
}
SEC("xdp_pass")
int xdp_pass_func(struct xdp_md *ctx)
{
return xdp_stats_record_action(ctx, XDP_PASS);
}
map 的内容是:
# Output of redirect_params
sudo bpftool map dump id 33
key: 28 f1 f1 f1 f1 f1 value: e4 f1 f1 f1 f1 f1
Found 1 element
# Output of tx_port
key: 00 00 00 00 value: 03 00 00 00
key:
01 00 00 00
value:
No such file or directory
# And then the No such file or directory repeats with every key
最佳答案
截至目前,Linux Kernel 5.5 包含对 TUN 和 NIC 驱动程序的 bpf_prog_run_xdp
函数调用。
drivers/net/tun.c
drivers/net/ethernet
/broadcom/bnxt/bnxt_xdp.c, line 144
cavium/thunder/nicvf_main.c, line 559
freescale/dpaa2/dpaa2-eth.c, line 305
intel/i40e/i40e_txrx.c, line 2212
intel/ice/ice_txrx.c, line 442
ixgbe/ixgbe_main.c, line 2213
marvell/mvneta.c, line 2099
mellanox/mlx4/en_rx.c, line 785
mellanox/mlx5/core/en/xdp.c, line 141
netronome/nfp/nfp_net_common.c, line 1917
qlogic/qede/qede_fp.c, line 1075
sfc/rx.c, line 700
socionext/netsec.c, line 890
ti/cpsw_priv.c, line 1337
因此,正如评论中所讨论的那样,似乎没有 XDP 本地调用 wifi 驱动程序。
注意:Linux 内核版本、自定义驱动程序或 ip
或 'bpftool` 的结果不会共享给调试。此外,我也无法找到允许 802MAC header 的 XDP 代码更改。
关于xdp-bpf - 如何使用XDP在NIC和WIFI之间转发数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60828999/
我正在尝试重定向 NIC 和 WIFI 之间的流量。我正在尝试从 eth0 转发数据包,通过 wlan0 发送偶数数据包,通过 wlan1 发送奇数数据包。 我无法成功地将数据包从一个接口(inter
我有一个简单的布局。这是一个带有以下代码的按钮: 我在两台设备上运行它,一台比另一台小。我注意到按钮的大小没有变化。我虽然在使用 dip 时, View 的大小会根据屏幕大小而变化。我错了吗? 最佳
我需要编写一个位于两台服务器之间的应用程序,并通过向每个数据包添加特定的 HTTP header 来修改从一台服务器发送到另一台服务器的 HTTP 数据包。 显然它必须尽可能快地完成,我发现通过使用
我确实对 DPDK 有一些经验,但目前我正在阅读许多关于 XDP 的博客。我试图比较这两种技术并了解 DPDK 和 XDP 之间的差异。这提出了一些问题。我希望有人可以帮助我解决以下问题: 使用 DP
我正在使用 xdp(使用 XDP_TX 操作)构建 icmp resv 数据包。 Linux:centos8 内核4.18.0-80.el8.x86_64 LLVM:7.0.1 clang:clang
关于AF-XDP套接字框架(+ libbpf)中的数据包大小是否存在已知(或未知)错误? 我的应用程序遇到奇怪的数据包丢失: 所有数据包都具有相同大小(1442字节)的IPv4/UDP/RTP数据包流
我想在XDP程序中收到的数据包中插入时间戳。我知道如何获取时间戳的唯一方法是调用bpf_ktime_get_ns。 但是,创建可比较时间戳的用户空间等效函数是什么?据我所知,ktime_get_ns返
我使用 Adobe LiveCycle Designer 创建了一个 PDF 表单。我现在正努力在填写完 PDF 后以编程方式从 PDF 中提取数据。 我尝试使用 poppler (qt4 绑定(
我的团队有一个使用 Adobe LiveCycle 设计器创建的模板 (XDP)。 情况: 我们正在替换旧的 Acrobat 表单(XFDF 格式)使用此 LiveCycle作为更大升级的一部分
所以,根据标题,我正在尝试加载 XDP 程序,令人惊讶的是 bpf 验证器向我吐口水,并出现著名的后沿错误: libbpf: load bpf program failed: Invalid argu
主要问题是我无法在网络接口(interface) (XDP) 中加载 eBPF 代码。 我尝试在 Raspberry Pi 3 上加载,配置如下: Raspbian GNU/Linux 10(巴斯特)
升级 Ubuntu 16.04 后,无法再编译 eBPF。 bpf.h文件缺少关键结构和 uapi似乎没有安装 header 。 示例代码: #include int main() { re
我有:LiveCycle 服务器(ES3、JBOSS)、Workbench、Designer。 我使用 LC Desginer 将 PDF 转换为 XDP - 现在是模板。 现在我需要将该 XDP 文
Note: I have installed AEM_6.4_Quickstart.jar and AEM-FORMS-6.4-OSX-5.0.86.zip installed into it to
我是一名优秀的程序员,十分优秀!