Unicast/multicast packet using xdp/tc eBPF

不问归期 提交于 2021-01-29 18:19:13

问题


I trying a design a load balancer using ebpf. I want to transmit the incoming packet to different destinations (devices connected in the same network). Although I have used the clone_bpf_redirect helper function to redirect the packet to real/ virtual interfaces and its working fine. Now I want to broadcast/unicast the packet to other devices connected in the same network. XDP does not support it, as far as I know. Therefore, using tc bpf hook. Is there any helper function or which action should I use? Can anyone please guide me on how can I do this?

eBpf load divider: 192.168.98.178 (load divider) Reciever 1: 192.168.98.131 Reciever 2: 192.168.98.138

    iph->daddr = htonl(3232260739);  //Dest: 192.168.98.131 
    iph->check = 0;
    iph->check = checksum((unsigned short *)iph, sizeof(struct iphdr));

    // Update upd packet checksum of 
    sum = old_daddr + (~ntohs(*(unsigned short *)&iph->daddr) & 0xffff);
    sum += ntohs(udp->check);
    sum = (sum & 0xffff) + (sum>>16);
    udp->check = htons(sum + (sum>>16) - 1);
// clone the packet and redirect to infdex 
    bpf_clone_redirect(skb,  skb->ifindex, 0);
//clone the packet and redirect to infdex (virtual interface 2)
    bpf_clone_redirect(skb,  skb->ifindex + 2, 0);
//clone the packet and redirect to infdex (virtual interface 4)
    bpf_clone_redirect(skb,  skb->ifindex + 4, 0);
            return TC_ACT_OK;
// Or
         //   return TC_ACT_REDIRECT;

sudo tc filter add dev ens33 ingress bpf da obj bpf_loadbalancer.o sec ingress

after this, I am getting the 1 packet to 3 different ifindex but I want to get the same packet to other devices connected into the network. can anybody please help me how can I redirect the packet out of the device, not the interfaces? Thanks

来源:https://stackoverflow.com/questions/63997103/unicast-multicast-packet-using-xdp-tc-ebpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!