Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Updated the libbpf version and made changes to the relevant files
Browse files Browse the repository at this point in the history
Signed-off-by: phansGithub <[email protected]>
  • Loading branch information
phansGithub authored and phansGithub committed Sep 22, 2023
1 parent 93d43de commit 627a513
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 57 deletions.
44 changes: 38 additions & 6 deletions .github/workflows/public-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,20 @@ jobs:
with:
go-version: 1.19

- name: Install dependencies
run: sudo apt-get update && sudo apt install libbpf-dev clang llvm gcc-multilib
- name: Install libbpf and libxdp
run: |
sudo apt update
sudo apt install -y wget build-essential golang
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf1_1.1.0-1_amd64.deb
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf-dev_1.1.0-1_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp-dev_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libbpf1_1.1.0-1_amd64.deb
sudo apt install -y ./libbpf-dev_1.1.0-1_amd64.deb
sudo apt install -y ./libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libxdp-dev_1.3.0-2ubuntu2_amd64.deb

- name: Run build
run: make build
Expand All @@ -54,8 +66,18 @@ jobs:
with:
go-version: 1.19

- name: Install dependencies
run: sudo apt-get update && sudo apt install libbpf-dev clang llvm gcc-multilib
- name: Install libbpf and libxdp
run: |
sudo apt update
sudo apt install -y wget build-essential golang
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf1_1.1.0-1_amd64.deb
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf-dev_1.1.0-1_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp-dev_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libbpf1_1.1.0-1_amd64.deb
sudo apt install -y ./libbpf-dev_1.1.0-1_amd64.deb
sudo apt install -y ./libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libxdp-dev_1.3.0-2ubuntu2_amd64.deb
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
Expand All @@ -73,8 +95,18 @@ jobs:
with:
go-version: 1.19

- name: Install dependencies
run: sudo apt-get update && sudo apt install libbpf-dev clang llvm gcc-multilib
- name: Install libbpf and libxdp
run: |
sudo apt update
sudo apt install -y wget build-essential golang
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf1_1.1.0-1_amd64.deb
sudo wget http://security.ubuntu.com/ubuntu/pool/main/libb/libbpf/libbpf-dev_1.1.0-1_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo wget https://mirrors.edge.kernel.org/ubuntu/pool/main/x/xdp-tools/libxdp-dev_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libbpf1_1.1.0-1_amd64.deb
sudo apt install -y ./libbpf-dev_1.1.0-1_amd64.deb
sudo apt install -y ./libxdp1_1.3.0-2ubuntu2_amd64.deb
sudo apt install -y ./libxdp-dev_1.3.0-2ubuntu2_amd64.deb
- name: unit-tests
run: make test
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clangformat:
@echo "****** Clang Format ******"
@echo
-clang-format -i -style=file internal/bpf/*.c internal/bpf/*.h
-clang-format -i -style=file internal/bpf/xdp-pass/*.c
# -clang-format -i -style=file internal/bpf/xdp-pass/*.c
@echo
@echo

Expand All @@ -40,10 +40,10 @@ format: clangformat
buildc:
@echo "****** Build BPF ******"
@echo
gcc ./internal/bpf/bpfWrapper.c -lbpf -c -o ./internal/bpf/bpfWrapper.o
gcc ./internal/bpf/bpfWrapper.c -lxdp -c -o ./internal/bpf/bpfWrapper.o
ar rs ./internal/bpf/libwrapper.a ./internal/bpf/bpfWrapper.o &> /dev/null
@echo "****** Build xdp_pass ******"
make -C ./internal/bpf/xdp-pass/
# make -C ./internal/bpf/xdp-pass/
@echo
@echo
@echo
Expand All @@ -58,7 +58,7 @@ builddp: buildc
buildcni: buildc
@echo "****** Build CNI ******"
@echo
go build -o ./bin/afxdp ./cmd/cni
go build -ldflags="-extldflags=-static" -tags netgo -o ./bin/afxdp ./cmd/cni
@echo
@echo

Expand Down
14 changes: 7 additions & 7 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ var (
afxdpMinimumLinux = "4.18.0" // minimum Linux version for AF_XDP support

/* UDS*/
udsMaxTimeout = 300 // maximum configurable uds timeout in seconds
udsMinTimeout = 30 // minimum (and default) uds timeout in seconds
udsMsgBufSize = 64 // uds message buffer size
udsCtlBufSize = 4 // uds control buffer size
udsProtocol = "unixpacket" // uds protocol: "unix"=SOCK_STREAM, "unixdomain"=SOCK_DGRAM, "unixpacket"=SOCK_SEQPACKET
udsSockDir = "/tmp/afxdp_dp/" // host location where we place our uds sockets. If changing location remember to update daemonset mount point
udsPodPath = "/tmp/afxdp.sock" // the uds filepath as it will appear in the end user application pod
udsMaxTimeout = 300 // maximum configurable uds timeout in seconds
udsMinTimeout = 30 // minimum (and default) uds timeout in seconds
udsMsgBufSize = 64 // uds message buffer size
udsCtlBufSize = 4 // uds control buffer size
udsProtocol = "unixpacket" // uds protocol: "unix"=SOCK_STREAM, "unixdomain"=SOCK_DGRAM, "unixpacket"=SOCK_SEQPACKET
udsSockDir = "/tmp/afxdp_dp/" // host location where we place our uds sockets. If changing location remember to update daemonset mount point
udsPodPath = "/tmp/afxdp.sock" // the uds filepath as it will appear in the end user application pod

udsDirFileMode = 0700 // permissions for the directory in which we create our uds sockets

Expand Down
29 changes: 17 additions & 12 deletions images/amd64.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.20@sha256:52921e63cc544c79c111db1d8461d8ab9070992d9c636e1573176642690c14b5 as cnibuilder
FROM golang:1.20@sha256:efe38cb419e2b2012f66d1782d2efe2fd8884c71d9f342581e1697ba9047b5f8 as cnibuilder
COPY . /usr/src/afxdp_k8s_plugins
WORKDIR /usr/src/afxdp_k8s_plugins
RUN apt-get update && apt-get -y install --no-install-recommends libbpf-dev=1:0.3-2 \
&& apt-get -y install --no-install-recommends clang=1:11.0-51+nmu5 llvm=1:11.0-51+nmu5 gcc-multilib=4:10.2.1-1 \
&& make buildcni
RUN apt-get update \
&& apt-get -y install --no-install-recommends libxdp-dev=1.3.1-1 \
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends clang=1:14.0-55.6 \
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends llvm=1:14.0-55.6 \
&& apt-get -y install -o APT::Keep-Downloaded-Packages=false --no-install-recommends gcc-multilib=4:12.2.0-3 \
&& make buildcni

FROM golang:1.20-alpine@sha256:87d0a3309b34e2ca732efd69fb899d3c420d3382370fd6e7e6d2cb5c930f27f9 as dpbuilder
FROM golang:1.20-alpine@sha256:ebceb16dc094769b6e2a393d51e0417c19084ba20eb8967fb3f7675c32b45774 as dpbuilder
COPY . /usr/src/afxdp_k8s_plugins
WORKDIR /usr/src/afxdp_k8s_plugins
RUN apk add --no-cache build-base~=0.5 libbsd-dev~=0.11 \
&& apk add --no-cache libbpf-dev~=0.5 --repository=https://dl-cdn.alpinelinux.org/alpine/v3.15/community \
&& apk add --no-cache llvm~=15.0.7-r0 clang~=15.0.7-r0 \
&& make builddp
RUN apk add --no-cache build-base~=0.5-r3 \
&& apk add --no-cache libbsd-dev~=0.11.7 \
&& apk add --no-cache libxdp-dev~=1.2.10-r0 \
&& apk add --no-cache llvm15~=15.0.7-r0 \
&& apk add --no-cache clang15~=15.0.7-r0 \
&& make builddp

FROM amd64/alpine:3.17@sha256:e2e16842c9b54d985bf1ef9242a313f36b856181f188de21313820e177002501
RUN apk --no-cache -U add iproute2-rdma~=6.0 acl~=2.3 \
&& apk --no-cache -U add libbpf~=0.5 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.15/community
FROM amd64/alpine:3.18@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70
RUN apk --no-cache -U add iproute2-rdma~=6.3.0-r0 acl~=2.3 \
&& apk add --no-cache libxdp~=1.2.10-r0
COPY --from=cnibuilder /usr/src/afxdp_k8s_plugins/bin/afxdp /afxdp/afxdp
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/bin/afxdp-dp /afxdp/afxdp-dp
COPY --from=dpbuilder /usr/src/afxdp_k8s_plugins/images/entrypoint.sh /afxdp/entrypoint.sh
Expand Down
37 changes: 19 additions & 18 deletions internal/bpf/bpfWrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <bpf/xsk.h> // for xsk_setup_xdp_prog, bpf_set_link_xdp_fd
#include <linux/if_link.h> // for XDP_FLAGS_DRV_MODE
#include <net/if.h> // for if_nametoindex
#include <xdp/libxdp.h>
#include <xdp/xsk.h> // for xsk_setup_xdp_prog, bpf_set_link_xdp_fd

#include "bpfWrapper.h"
#include "log.h"
Expand All @@ -40,12 +40,12 @@ int Load_bpf_send_xsk_map(char *ifname) {
} else {
Log_Info("%s: if_index for interface %s is %d", __FUNCTION__, ifname, if_index);
}

Log_Info("%s: starting setup of xdp program on "
"interface %s (%d)",
__FUNCTION__, ifname, if_index);

err = xsk_setup_xdp_prog(if_index, &fd);
Log_Info("Error value: %d", err);
if (err) {
Log_Error("%s: setup of xdp program failed, "
"returned: %d",
Expand All @@ -59,7 +59,7 @@ int Load_bpf_send_xsk_map(char *ifname) {
__FUNCTION__, ifname, if_index, fd);
return fd;
}

Log_Info("FD value: %d", fd);
return -1;
}

Expand Down Expand Up @@ -136,6 +136,7 @@ int Configure_busy_poll(int fd, int busy_timeout, int busy_budget) {
int Clean_bpf(char *ifname) {
int if_index, err;
int fd = -1;
struct xdp_multiprog *mp = NULL;

Log_Info("%s: disovering if_index for interface %s", __FUNCTION__, ifname);

Expand All @@ -150,19 +151,19 @@ int Clean_bpf(char *ifname) {
Log_Info("%s: starting removal of xdp program on interface %s (%d)", __FUNCTION__, ifname,
if_index);

err = bpf_set_link_xdp_fd(if_index, fd, XDP_FLAGS_UPDATE_IF_NOEXIST);
mp = xdp_multiprog__get_from_ifindex(if_index);
if (!mp) {
Log_Error("%s: unable to receive correct multi_prog reference : %s", __FUNCTION__,
mp);
return -1;
}

err = xdp_multiprog__detach(mp);
if (err) {
if (err == EBUSY_CODE_WARNING) {
// unloading of XDP program found to return EBUSY error of -16 on certain
// host libbpf versions. doesn't break functionality and this problem is
// being investigated.
Log_Warning("%s: Removal of xdp program is reporting error code: (%d)",
__FUNCTION__, err);
} else {
Log_Error("%s: Removal of xdp program failed, returned: (%d)", __FUNCTION__,
err);
return 1;
}
Log_Error("%s: Removal of xdp program failed, returned: "
"returned: %d",
__FUNCTION__, err);
return -1;
}

Log_Info("%s: removed xdp program from interface %s (%d)", __FUNCTION__, ifname, if_index);
Expand Down Expand Up @@ -190,14 +191,14 @@ int Load_attach_bpf_xdp_pass(char *ifname) {
__FUNCTION__, ifname, ifindex);

/* Load the BPF program */
err = bpf_prog_load(filename, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
err = bpf_xdp_query_id(ifindex, (int)xdp_flags, &prog_fd);
if (err < 0) {
Log_Error("%s: Couldn't load BPF-OBJ file(%s)\n", __FUNCTION__, filename);
return -1;
}

/* Attach the program to the interface at the xdp hook */
err = bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags);
err = bpf_xdp_attach(ifindex, prog_fd, XDP_FLAGS_UPDATE_IF_NOEXIST, NULL);
if (err < 0) {
Log_Error("%s: Couldn't attach the XDP PASS PROGRAM TO %s\n", __FUNCTION__, ifname);
return -1;
Expand Down
6 changes: 3 additions & 3 deletions internal/bpf/bpfWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package bpf

//#include <bpf/libbpf.h>
//#include <bpf/xsk.h>
//#include <xdp/libxdp.h>
//#include <xdp/xsk.h>
//#cgo CFLAGS: -I.
//#cgo LDFLAGS: -L. -lbpf
//#cgo LDFLAGS: -L. -lxdp -lbpf -lelf -lz
//#include "bpfWrapper.h"
//#include "log.h"
import "C"
Expand Down
28 changes: 21 additions & 7 deletions internal/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ package cni
import (
"encoding/json"
"fmt"
"os"
"regexp"
"runtime"
"strings"

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
Expand All @@ -32,14 +37,8 @@ import (
"github.com/intel/afxdp-plugins-for-kubernetes/internal/tools"
logging "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"os"
"regexp"
"runtime"
"strings"
)

var bpfHandler = bpf.NewHandler()

/*
NetConfig holds the config passed via stdin
*/
Expand Down Expand Up @@ -347,7 +346,22 @@ func CmdDel(args *skel.CmdArgs) error {

if !cfg.SkipUnloadBpf {
logging.Infof("cmdDel(): removing BPF program from device")
if err := bpfHandler.Cleanbpf(cfg.Device); err != nil {

device, err := netlink.LinkByName(cfg.Device)
if err != nil {
err = fmt.Errorf("cmdDel(): failed to find device %q in containerNS: %w", cfg.Device, err)
logging.Errorf(err.Error())

return err
}
device.Attrs().Xdp.Attached = false
if err := netlink.LinkSetDown(device); err != nil {
err = fmt.Errorf("cmdDel(): error setting device to down state: %w", err)
logging.Errorf(err.Error())

return err
}
if err := netlink.LinkSetXdpFd(device, -1); err != nil {
err = fmt.Errorf("cmdDel(): error removing BPF program from device: %w", err)
logging.Errorf(err.Error())

Expand Down

0 comments on commit 627a513

Please sign in to comment.