Я создал ns1 и ns2 в качестве клиентов.
ns3 и ns1 имеют одноранговые узлы veth3_1, veth1_3.ns3 и ns2 имеют одноранговые узлы veth3_2, veth2_3.
Пакет UDP от ns1 к ns2 получен в программе XDP, развернутой в veth2_3.
Код: Выделить всё
SEC("xdp_ingress")
int xdp_ingress_func(struct xdp_md* ctx) {
void* data_end = (void*)(long)ctx->data_end;
void* data = (void*)(long)ctx->data;
struct ethhdr* eth = data;
if ((void*)(eth + 1) > data_end) {
return XDP_PASS;
}
if (eth->h_proto != __builtin_bswap16(ETH_P_IP)) {
return XDP_PASS;
}
char tmp_mac[6];
__builtin_memcpy(tmp_mac, eth->h_dest, ETH_ALEN);
__builtin_memcpy(eth->h_dest, eth->h_source, ETH_ALEN);
__builtin_memcpy(eth->h_source, tmp_mac, ETH_ALEN);
return XDP_TX;
}
Но я не могу наблюдать за пересылкой пакетов обратно.
Вот настройка оболочки для среды:
Код: Выделить всё
ip link add veth1_3 type veth peer name veth3_1
ip link add veth2_3 type veth peer name veth3_2
# ns3
ip link set veth3_1 netns ns5
ip link set veth3_2 netns ns5
ip netns exec ns3 sysctl -w net.ipv4.ip_forward=1
ip netns exec ns3 ip link add name br0 type bridge
ip netns exec ns3 ip link set br0 up
ip netns exec ns3 ip link set veth3_1 master br0
ip netns exec ns3 ip link set veth3_2 master br0
ip netns exec ns3 ip link set veth3_1 up
ip netns exec ns3 ip link set veth3_2 up
ip netns exec ns3 ip addr add 10.0.0.1/8 dev br0
# ns1
ip link set veth1_3 netns ns1
ip netns exec ns1 ip addr add 10.0.0.2/8 dev veth1_3
ip netns exec ns1 ip link set veth1_3 up
ip netns exec ns1 ip link set lo up
ip netns exec ns1 ip route add default via 10.0.0.1
# ns2
ip link set veth2_3 netns ns2
ip netns exec ns2 ip addr add 10.0.0.3/8 dev veth2_3
ip netns exec ns2 ip link set veth2_3 up
ip netns exec ns2 ip link set lo up
ip netns exec ns2 ip route add default via 10.0.0.1
На самом деле, на выходе tc veth1_3 я помещаю еще один заголовок IP и UDP перед исходным заголовком L3.Как |IP|TCP| к |IP|UDP|IP|TCP|.
Я проверил правильность адреса L2.
Я проверил в bpf_printk, что пакет принимается программой XDP и выполняется до возврата XDP_TX;.
Подробнее здесь: https://stackoverflow.com/questions/790 ... forwarding