Open arayu05 opened 3 years ago
Not pretty sure, but you may need to update the checksum accordingly.
See the BPF helper bpf_csum_update
.
we tried updating checksum as below, Also tried updating eth header but still the same issue:
if(value){
//uint32_t new_daddr = *value;
bpf_trace_printk("old address is: %lu\n", old_daddr);
bpf_trace_printk("ip daddr found in the ip my_list %lu\n", *value);
//ethr hdr update
// eth->h_dest[0] = ;
// eth->h_dest[1] = ;
// eth->h_dest[2] = ;
// eth->h_dest[3] = ;
// eth->h_dest[4] = ;
// eth->h_dest[5] = ;
//ip->tos = 7 << 2;
ip->daddr = *value;
ip->check = 0;
ip->check = checksum((unsigned short *)ip, sizeof(struct iphdr));
bpf_trace_printk("ip daddr changed to %lu\n", ip->daddr);
unsigned long sum;
// Update checksum
sum = old_daddr + (~ntohs(*(unsigned short *)&ip->daddr) & 0xffff);
sum += ntohs(udp->check);
sum = (sum & 0xffff) + (sum>>16);
udp->check = htons(sum + (sum>>16) - 1);
}`
Couldn't use bpf_csum_update() and it needs skb buff in the param which is not used in xdp code right? we are using ctx pointer.
@Ayushri-wipro Do you solve this problem ? Or I may spend some time working on it.
Hi @chenhengqi I couldn't solve the issue till now. can you please suggest a proper way of doing it?
@chenhengqi Can you please suggest if I am doing right. Or else what is the correct way to reroute the packet.
Hi, I tried below code for testing the IP routing of data packets.
iplist.py -
filter.c -
But this is not routing the packet coming at 127.0.0.1 to 127.0.0.2 I tested it with nc (netcat) commands. Is there something wrong in the code?
Also, sometimes it prints correct updated address(127.0.0.2) in uint32 format in ip->daddr and sometimes it randomly prints 0 as updated daddr.