From 2428cf92362ed1850689683140646b2ca82aa5a7 Mon Sep 17 00:00:00 2001 From: mc36 Date: Sun, 22 Dec 2024 18:34:22 +0100 Subject: [PATCH] automatic commit at releng box --- cfg/p4lang4.ini | 2 +- misc/native/p4xdp_kern.c | 24 ++++++++ misc/native/p4xdp_msg.h | 71 ++++++++++++++++++++++++ misc/native/p4xdp_tab.h | 5 +- misc/native/p4xdp_user.c | 2 +- src/org/freertr/serv/servP4langConn.java | 3 + 6 files changed, 103 insertions(+), 4 deletions(-) diff --git a/cfg/p4lang4.ini b/cfg/p4lang4.ini index 2459dde795..9417e1d7f1 100644 --- a/cfg/p4lang4.ini +++ b/cfg/p4lang4.ini @@ -1,4 +1,4 @@ -xdp punting route mpls bundle vlan pppoe eompls bridge vpls evpn hairpin sgt loconn pmtud vrfysrc gre l2tp l3tp gtp nsh polka gretap pppoetap l2tptap l3tptap pckoudp vxlan +xdp punting route mpls bundle vlan pppoe eompls bridge vpls evpn hairpin sgt loconn pmtud vrfysrc gre l2tp l3tp gtp nsh polka gretap pppoetap l2tptap l3tptap pckoudp vxlan pwhe qemu-img create -f qcow2 -o backing_file=../img/p4xdp.img,backing_fmt=raw $fn$ qemu-system-x86_64 -monitor none -serial stdio -nographic -no-reboot -enable-kvm -cpu host -smp cores=2,threads=1,sockets=1 -drive file=$fn$,format=qcow2,cache=unsafe -m 1024 $nc$ diff --git a/misc/native/p4xdp_kern.c b/misc/native/p4xdp_kern.c index e5b518428c..22bd3a976d 100644 --- a/misc/native/p4xdp_kern.c +++ b/misc/native/p4xdp_kern.c @@ -299,6 +299,12 @@ struct { put32msb(bufD, bufP, label); \ neik = resm->hop; \ goto ethtyp_tx; \ + case 7: \ + if (bpf_xdp_adjust_head(ctx, bufP) != 0) goto drop; \ + prt = resm->port; \ + continue; \ + case 8: \ + goto cpu; \ default: \ goto drop; @@ -1163,6 +1169,24 @@ __u32 xdp_router(struct xdp_md *ctx) { putUdpHeader(neir); putIpv6header(neir, IP_PROTOCOL_UDP); break; + case 11: // pwhe + bufP -= sizeof(macaddr) + 16; + if (bpf_xdp_adjust_head(ctx, bufP) != 0) goto drop; + bufP = sizeof(macaddr) + 16; + revalidatePacket(bufP + 2); + bufP -= sizeof(macaddr); + __builtin_memcpy(&bufD[bufP], &macaddr, sizeof(macaddr)); + bufP -= 4; + tmp = 0x1ff | (neir->trgPort << 12); + put32msb(bufD, bufP, tmp); + bufP -= 4; + tmp = 0xff | (neir->srcPort << 12); + put32msb(bufD, bufP, tmp); + ethtyp = ETHERTYPE_MPLS_UCAST; + bufP -= 2; + put16msb(bufD, bufP, ethtyp); + __builtin_memcpy(&macaddr[0], neir->mac2, sizeof(neir->mac2)); + break; default: goto drop; } diff --git a/misc/native/p4xdp_msg.h b/misc/native/p4xdp_msg.h index e65ccaa166..8aa331d063 100644 --- a/misc/native/p4xdp_msg.h +++ b/misc/native/p4xdp_msg.h @@ -489,6 +489,56 @@ int doOneCommand(unsigned char* buf) { } return 0; } + if (strcmp(arg[0], "pwhenei4") == 0) { + inet_pton(AF_INET, arg[3], buf2); + rou4.vrf = atoi(arg[5]); + memcpy(rou4.addr, buf2, sizeof(rou4.addr)); + rou4.bits = routes_bits + (sizeof(rou4.addr) * 8); + rour.cmd = 1; + i = rour.hop = atoi(arg[2]); + str2mac(&neir.macs[0], arg[4]); + str2mac(&neir.macs[6], arg[6]); + neir.port = atoi(arg[7]); + neir.aclport = atoi(arg[8]); + str2mac(&neir.mac2[0], arg[9]); + str2mac(&neir.mac2[6], arg[10]); + neir.srcPort = atoi(arg[11]); + neir.trgPort = atoi(arg[12]); + neir.cmd = 11; + if (del == 0) { + if (bpf_map_delete_elem(route4_fd, &rou4) != 0) warn("error removing entry"); + if (bpf_map_delete_elem(neighs_fd, &i) != 0) warn("error removing entry"); + } else { + if (bpf_map_update_elem(route4_fd, &rou4, &rour, BPF_ANY) != 0) warn("error setting entry"); + if (bpf_map_update_elem(neighs_fd, &i, &neir, BPF_ANY) != 0) warn("error setting entry"); + } + return 0; + } + if (strcmp(arg[0], "pwhenei6") == 0) { + inet_pton(AF_INET6, arg[3], buf2); + rou6.vrf = atoi(arg[5]); + memcpy(rou6.addr, buf2, sizeof(rou6.addr)); + rou6.bits = routes_bits + (sizeof(rou6.addr) * 8); + rour.cmd = 1; + i = rour.hop = atoi(arg[2]); + str2mac(&neir.macs[0], arg[4]); + str2mac(&neir.macs[6], arg[6]); + neir.port = atoi(arg[7]); + neir.aclport = atoi(arg[8]); + str2mac(&neir.mac2[0], arg[9]); + str2mac(&neir.mac2[6], arg[10]); + neir.srcPort = atoi(arg[11]); + neir.trgPort = atoi(arg[12]); + neir.cmd = 11; + if (del == 0) { + if (bpf_map_delete_elem(route6_fd, &rou6) != 0) warn("error removing entry"); + if (bpf_map_delete_elem(neighs_fd, &i) != 0) warn("error removing entry"); + } else { + if (bpf_map_update_elem(route6_fd, &rou6, &rour, BPF_ANY) != 0) warn("error setting entry"); + if (bpf_map_update_elem(neighs_fd, &i, &neir, BPF_ANY) != 0) warn("error setting entry"); + } + return 0; + } if (strcmp(arg[0], "myaddr4") == 0) { inet_pton(AF_INET, arg[2], buf2); rou4.vrf = atoi(arg[5]); @@ -763,6 +813,27 @@ int doOneCommand(unsigned char* buf) { } return 0; } + if (strcmp(arg[0], "pwhelab") == 0) { + i = atoi(arg[2]); + labr.port = atoi(arg[3]); + labr.cmd = 7; + if (del == 0) { + if (bpf_map_delete_elem(labels_fd, &i) != 0) warn("error removing entry"); + } else { + if (bpf_map_update_elem(labels_fd, &i, &labr, BPF_ANY) != 0) warn("error setting entry"); + } + return 0; + } + if (strcmp(arg[0], "cpulabel") == 0) { + i = atoi(arg[2]); + labr.cmd = 8; + if (del == 0) { + if (bpf_map_delete_elem(labels_fd, &i) != 0) warn("error removing entry"); + } else { + if (bpf_map_update_elem(labels_fd, &i, &labr, BPF_ANY) != 0) warn("error setting entry"); + } + return 0; + } if (strcmp(arg[0], "hairpin") == 0) { o = atoi(arg[2]); bunn.cmd = 2; diff --git a/misc/native/p4xdp_tab.h b/misc/native/p4xdp_tab.h index a52b83b0b2..0b707a437f 100644 --- a/misc/native/p4xdp_tab.h +++ b/misc/native/p4xdp_tab.h @@ -54,8 +54,9 @@ struct routes_res { }; struct neigh_res { - __u32 cmd; // 1=rawip, 2=pppoe, 3=gre4, 4=gre6, 5=l2tp4, 6=l2tp6, 7=l3tp4, 8=l3tp6, 9=gtp4, 10=gtp6 + __u32 cmd; // 1=rawip, 2=pppoe, 3=gre4, 4=gre6, 5=l2tp4, 6=l2tp6, 7=l3tp4, 8=l3tp6, 9=gtp4, 10=gtp6, 11=pwhe __u8 macs[12]; + __u8 mac2[12]; __u32 port; __u32 aclport; __u32 sess; @@ -68,7 +69,7 @@ struct neigh_res { }; struct label_res { - __u32 cmd; // 1=route, 2=pop, 3=swap, 4=xconn, 5=vpls, 6=push + __u32 cmd; // 1=route, 2=pop, 3=swap, 4=xconn, 5=vpls, 6=push, 7=pwhe, 8=punt __u32 ver; __u32 hop; __u32 vrf; diff --git a/misc/native/p4xdp_user.c b/misc/native/p4xdp_user.c index 242d3a1234..335893058d 100644 --- a/misc/native/p4xdp_user.c +++ b/misc/native/p4xdp_user.c @@ -77,7 +77,7 @@ void doStatLoop() { FILE *commands = fdopen(commandSock, "w"); if (commands == NULL) err("failed to open file"); fprintf(commands, "platform p4xdp\r\n"); - fprintf(commands, "capabilities punting route mpls bundle vlan pppoe eompls bridge vpls evpn hairpin sgt loconn pmtud vrfysrc gre l2tp l3tp gtp nsh polka gretap pppoetap l2tptap l3tptap pckoudp vxlan\r\n"); + fprintf(commands, "capabilities punting route mpls bundle vlan pppoe eompls bridge vpls evpn hairpin sgt loconn pmtud vrfysrc gre l2tp l3tp gtp nsh polka gretap pppoetap l2tptap l3tptap pckoudp vxlan pwhe\r\n"); for (int i = 0; i < dataPorts; i++) fprintf(commands, "portname %i %s\r\n", i, ifaceName[i]); fprintf(commands, "cpuport %i\r\n", cpuPort); fprintf(commands, "dynrange 32768 1073741823\r\n"); diff --git a/src/org/freertr/serv/servP4langConn.java b/src/org/freertr/serv/servP4langConn.java index 8a136fc5de..7508cc847f 100644 --- a/src/org/freertr/serv/servP4langConn.java +++ b/src/org/freertr/serv/servP4langConn.java @@ -3556,6 +3556,9 @@ private void doNeighs(boolean ipv4, servP4langIfc ifc, ipIfc ipi) { if (hop == null) { return; } + if (hop.mac == null) { + return; + } ll = servP4langUtil.getLabel(ntry); } String afi;