From 2b79964407f282426b3efc33775bb30886da818d Mon Sep 17 00:00:00 2001 From: Christian Deacon Date: Wed, 26 Feb 2025 17:10:04 -0500 Subject: [PATCH] Update install script. --- README.md | 1 + install.sh | 41 +++++++++++++++++++++++++++++++---------- src/xdp/prog.c | 16 ++++++++-------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5a451dc..2f3ae9b 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Additionally, here is a list of flags you may pass to this script. | --no-install | Build the tool and/or LibXDP without installing them. | | --clean | Remove build files for the tool and LibXDP. | | --no-static | Do *not* statically link LibXDP and LibBPF object files when building the tool. This makes the build process faster, but you may need to alter your `LD_LIBRARY_PATH` env variable before running the tool and requires LibXDP to be installed on your system already. | +| --objdump | Dumps the XDP/BPF object file using [`llvm-objdump`](https://llvm.org/docs/CommandGuide/llvm-objdump.html) to Assemby into `objdump.asm`. | | --help | Displays help message. | ![Script Build Demo](./images/build_script.gif) diff --git a/install.sh b/install.sh index 418eb4e..65f128f 100755 --- a/install.sh +++ b/install.sh @@ -2,6 +2,8 @@ LIBXDP=0 INSTALL=1 CLEAN=0 +OBJDUMP=0 +HELP=0 STATIC=1 while [[ $# -gt 0 ]]; do @@ -32,17 +34,14 @@ while [[ $# -gt 0 ]]; do shift ;; - --help) - echo "Usage: install.sh [OPTIONS]" - echo - echo "Options:" - echo " --libxdp Build and install LibXDP before building the tool." - echo " --no-install Build the tool and/or LibXDP without installing them." - echo " --clean Remove build files for the tool and LibXDP." - echo " --no-static Do not statically link LibXDP and LibBPF object files when building the tool and rely on shared libraries (-lbpf and -lxdp flags)." - echo " --help Display this help message." + --objdump) + OBJDUMP=1 - exit 0 + shift + ;; + + --help) + HELP=1 shift ;; @@ -53,6 +52,20 @@ while [[ $# -gt 0 ]]; do esac done +if [ "$HELP" -gt 0 ]; then + echo "Usage: install.sh [OPTIONS]" + echo + echo "Options:" + echo " --libxdp Build and install LibXDP before building the tool." + echo " --no-install Build the tool and/or LibXDP without installing them." + echo " --clean Remove build files for the tool and LibXDP." + echo " --no-static Do not statically link LibXDP and LibBPF object files when building the tool and rely on shared libraries (-lbpf and -lxdp flags)." + echo " --objdump Dumps the XDP/BPF object file using 'llvm-objdump' to Assemby into 'objdump.asm'." + echo " --help Display this help message." + + exit 0 +fi + if [ "$CLEAN" -gt 0 ]; then if [ "$LIBXDP" -gt 0 ]; then echo "Cleaning LibXDP..." @@ -67,6 +80,14 @@ if [ "$CLEAN" -gt 0 ]; then exit 0 fi +if [ "$OBJDUMP" -gt 0 ]; then + echo "Dumping object file..." + + ./scripts/objdump.sh + + exit 0 +fi + if [ "$LIBXDP" -gt 0 ]; then echo "Building LibXDP..." diff --git a/src/xdp/prog.c b/src/xdp/prog.c index 098d8f4..c08ada1 100644 --- a/src/xdp/prog.c +++ b/src/xdp/prog.c @@ -55,7 +55,7 @@ int xdp_prog_main(struct xdp_md *ctx) // Set IPv4 and IPv6 common variables. if (eth->h_proto == htons(ETH_P_IPV6)) { - iph6 = (data + sizeof(struct ethhdr)); + iph6 = data + sizeof(struct ethhdr); if (unlikely(iph6 + 1 > (struct ipv6hdr *)data_end)) { @@ -66,7 +66,7 @@ int xdp_prog_main(struct xdp_md *ctx) } else { - iph = (data + sizeof(struct ethhdr)); + iph = data + sizeof(struct ethhdr); if (unlikely(iph + 1 > (struct iphdr *)data_end)) { @@ -152,7 +152,7 @@ int xdp_prog_main(struct xdp_md *ctx) { case IPPROTO_TCP: // Scan TCP header. - tcph = (data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr)); + tcph = data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr); // Check TCP header. if (unlikely(tcph + 1 > (struct tcphdr *)data_end)) @@ -170,7 +170,7 @@ int xdp_prog_main(struct xdp_md *ctx) case IPPROTO_UDP: // Scan UDP header. - udph = (data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr)); + udph = data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr); // Check TCP header. if (unlikely(udph + 1 > (struct udphdr *)data_end)) @@ -188,7 +188,7 @@ int xdp_prog_main(struct xdp_md *ctx) case IPPROTO_ICMPV6: // Scan ICMPv6 header. - icmp6h = (data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr)); + icmp6h = data + sizeof(struct ethhdr) + sizeof(struct ipv6hdr); // Check ICMPv6 header. if (unlikely(icmp6h + 1 > (struct icmp6hdr *)data_end)) @@ -207,7 +207,7 @@ int xdp_prog_main(struct xdp_md *ctx) { case IPPROTO_TCP: // Scan TCP header. - tcph = (data + sizeof(struct ethhdr) + (iph->ihl * 4)); + tcph = data + sizeof(struct ethhdr) + (iph->ihl * 4); // Check TCP header. if (unlikely(tcph + 1 > (struct tcphdr *)data_end)) @@ -225,7 +225,7 @@ int xdp_prog_main(struct xdp_md *ctx) case IPPROTO_UDP: // Scan UDP header. - udph = (data + sizeof(struct ethhdr) + (iph->ihl * 4)); + udph = data + sizeof(struct ethhdr) + (iph->ihl * 4); // Check TCP header. if (unlikely(udph + 1 > (struct udphdr *)data_end)) @@ -243,7 +243,7 @@ int xdp_prog_main(struct xdp_md *ctx) case IPPROTO_ICMP: // Scan ICMP header. - icmph = (data + sizeof(struct ethhdr) + (iph->ihl * 4)); + icmph = data + sizeof(struct ethhdr) + (iph->ihl * 4); // Check ICMP header. if (unlikely(icmph + 1 > (struct icmphdr *)data_end))