cpt-harlock / xdp_tunnel_bpf

Copy of kernel BPF Ip-Ip tunnel example
1 stars 0 forks source link

bpf_skb_set_tunnel_key #1

Open michelle4liu opened 1 month ago

michelle4liu commented 1 month ago

hi~ May I ask a question? I have tried bpf_skb_set_tunnel_key, which seems like work, but not.....

VladimiroPaschali commented 1 month ago

Hi, this is custom tunnel, if you need to add an IP to the virtual IP map you can try:

struct vip vip;
// vip.family = AF_INET;
vip.family = 2;
// vip.protocol = IPPROTO_UDP;
vip.protocol = 17;

vip.dport=3072;
// vip.daddr.v4=inet_addr("16.0.0.1");
vip.daddr.v4=16777264;

struct iptnl_info tnl;
tnl.saddr.v4 = inet_addr("10.10.1.2");
tnl.daddr.v4 = inet_addr("10.10.1.1");

tnl.family = AF_INET;
tnl.dmac[0] = 0x00;
tnl.dmac[1] = 0x00;
tnl.dmac[2] = 0x00;
tnl.dmac[3] = 0x00;
tnl.dmac[4] = 0x00;
tnl.dmac[5] = 0x00;

__u8 key = 0;

assert(bpf_map__update_elem(tunnel->maps.vip2tnl, &key ,sizeof(__u8), &tnl,sizeof(struct iptnl_info), BPF_ANY)==0);