Skip to content

Commit

Permalink
Update UDP bit logic + cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: astoycos <[email protected]>
  • Loading branch information
astoycos committed Nov 3, 2022
1 parent 559040f commit 36719a2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
8 changes: 6 additions & 2 deletions bpf/xdp_udp.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static __always_inline __u16 udp_checksum(struct iphdr *ip, struct udphdr * udp,
// Last byte
if (i + 1 == udp_len) {
csum_total += (*(__u8 *)buf);
// Verifier fails without this print statement, I have no Idea why :/
bpf_printk("Adding last byte %X to csum", (*(__u8 *)buf));
} else {
csum_total += *buf;
}
Expand Down Expand Up @@ -197,10 +199,12 @@ int xdp_prog_func(struct xdp_md *ctx) {
bpf_printk("new dest hwaddr %x:%x:%x:%x:%x:%x", 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->check = iph_csum(ip);

udp->check = 0;
if (!bk->nocksum){
udp->check = udp_checksum(ip, udp, data_end);
int tmp_check = udp_checksum(ip, udp, data_end);
bpf_printk("Manual Cksum: %X Diff Cksum %X", tmp_check, udp_csum_diff(udp));
udp->check = tmp_check;
}

bpf_printk("destination interface index %d", bk->ifindex);
Expand Down
Binary file modified userspace-go/bpf_bpfeb.o
Binary file not shown.
Binary file modified userspace-go/bpf_bpfel.o
Binary file not shown.
Binary file modified userspace-go/userspace-go
Binary file not shown.
15 changes: 7 additions & 8 deletions userspace-go/xdp_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ func main() {
if err != nil {
log.Fatalf("lookup network iface %s: %s", ifaceName, err)
}

// opts := ebpf.CollectionOptions{
// Programs: ebpf.ProgramOptions{
// LogLevel: 3,
// LogSize: 80 * 1024,
// },
// }

var ve *ebpf.VerifierError
objs := bpfObjects{}
if err := loadBpfObjects(&objs, nil); err != nil {
Expand Down Expand Up @@ -73,20 +67,25 @@ func main() {
log.Printf("Press Ctrl-C to exit and remove the program")

b := bpfBackend{
// Hardcoded Src IP (main Nic)
Saddr: ip2int("10.8.125.12"),
// Hardcoded Dst IP (container)
Daddr: ip2int("192.168.10.2"),
// Hardcoded Dst Port (UDP echo server)
Dport: 9875,
// Host-Side Veth Mac
Shwaddr: hwaddr2bytes("06:56:87:ec:fd:1f"),
// Container-Side Veth Mac
Dhwaddr: hwaddr2bytes("86:ad:33:29:ff:5e"),
Nocksum: 0,
// Hardcoded Host side Veth index
Ifindex: 8,
}

key := bpfVipKey{
// Hardcoded main NIC IP
Vip: ip2int("10.8.125.12"),
//Vip: ip2int("192.168.10.1"),
// Hardcoded main NIC port
Port: 8888,
}

Expand Down

0 comments on commit 36719a2

Please sign in to comment.