Skip to content

Commit 0475212

Browse files
authored
feat: eBPF ingress/egress TC program for cilium external LB (#2710)
* tc egress + ingress bpf program for external lb dualstack svcs * changes work with ip -6 neigh add for LL * adding README and updated printk * use helper func to compare IPs * fix checksum * prep makefile changes for future image installs * remove generated files, update paths, addressing comments * remove old path * update dockerfile for bpf-tc * implement zap logging * update dockerfile * create qdisc before cilium so initcontainer can start bpf-tc to attach filters * addressing comments and change use debug macro for prints * remove checksum flag * logs to outfile * reduce image size, run nft delete in main.go, delete filters if they exist before adding on restart * rename to ipv6-hp-bpf * reorder load_bytes * delete filter by name
1 parent 6dabf70 commit 0475212

File tree

13 files changed

+583
-0
lines changed

13 files changed

+583
-0
lines changed

Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ endif
3535
REPO_ROOT = $(shell git rev-parse --show-toplevel)
3636
REVISION ?= $(shell git rev-parse --short HEAD)
3737
ACN_VERSION ?= $(shell git describe --exclude "azure-ipam*" --exclude "dropgz*" --exclude "zapai*" --tags --always)
38+
IPV6_HP_BPF_VERSION ?= $(notdir $(shell git describe --match "ipv6-hp-bpf*" --tags --always))
3839
AZURE_IPAM_VERSION ?= $(notdir $(shell git describe --match "azure-ipam*" --tags --always))
3940
CNI_VERSION ?= $(ACN_VERSION)
4041
CNI_DROPGZ_VERSION ?= $(notdir $(shell git describe --match "dropgz*" --tags --always))
@@ -44,6 +45,7 @@ ZAPAI_VERSION ?= $(notdir $(shell git describe --match "zapai*" --tags --alway
4445

4546
# Build directories.
4647
AZURE_IPAM_DIR = $(REPO_ROOT)/azure-ipam
48+
IPV6_HP_BPF_DIR = $(REPO_ROOT)/bpf-prog/ipv6-hp-bpf
4749
CNM_DIR = $(REPO_ROOT)/cnm/plugin
4850
CNI_NET_DIR = $(REPO_ROOT)/cni/network/plugin
4951
CNI_IPAM_DIR = $(REPO_ROOT)/cni/ipam/plugin
@@ -56,6 +58,7 @@ NPM_DIR = $(REPO_ROOT)/npm/cmd
5658
OUTPUT_DIR = $(REPO_ROOT)/output
5759
BUILD_DIR = $(OUTPUT_DIR)/$(GOOS)_$(GOARCH)
5860
AZURE_IPAM_BUILD_DIR = $(BUILD_DIR)/azure-ipam
61+
IPV6_HP_BPF_BUILD_DIR = $(BUILD_DIR)/bpf-prog/ipv6-hp-bpf
5962
IMAGE_DIR = $(OUTPUT_DIR)/images
6063
CNM_BUILD_DIR = $(BUILD_DIR)/cnm
6164
CNI_BUILD_DIR = $(BUILD_DIR)/cni
@@ -139,6 +142,7 @@ azure-cns: azure-cns-binary cns-archive
139142
acncli: acncli-binary acncli-archive
140143
azure-npm: azure-npm-binary npm-archive
141144
azure-ipam: azure-ipam-binary azure-ipam-archive
145+
ipv6-hp-bpf: ipv6-hp-bpf-binary ipv6-hp-bpf-archive
142146

143147

144148
##@ Versioning
@@ -154,6 +158,9 @@ acncli-version: version
154158
azure-ipam-version: ## prints the azure-ipam version
155159
@echo $(AZURE_IPAM_VERSION)
156160

161+
ipv6-hp-bpf-version: ## prints the ipv6-hp-bpf version
162+
@echo $(IPV6_HP_BPF_VERSION)
163+
157164
cni-version: ## prints the cni version
158165
@echo $(CNI_VERSION)
159166

@@ -175,6 +182,11 @@ zapai-version: ## prints the zapai version
175182
azure-ipam-binary:
176183
cd $(AZURE_IPAM_DIR) && CGO_ENABLED=0 go build -v -o $(AZURE_IPAM_BUILD_DIR)/azure-ipam$(EXE_EXT) -ldflags "-X github.com/Azure/azure-container-networking/azure-ipam/internal/buildinfo.Version=$(AZURE_IPAM_VERSION)" -gcflags="-dwarflocationlists=true"
177184

185+
# Build the ipv6-hp-bpf binary.
186+
ipv6-hp-bpf-binary:
187+
cd $(IPV6_HP_BPF_DIR) && CGO_ENABLED=0 go generate ./...
188+
cd $(IPV6_HP_BPF_DIR)/cmd/ipv6-hp-bpf && CGO_ENABLED=0 go build -v -o $(IPV6_HP_BPF_BUILD_DIR)$(EXE_EXT) -ldflags "-X main.version=$(IPV6_HP_BPF_VERSION)" -gcflags="-dwarflocationlists=true"
189+
178190
# Build the Azure CNM binary.
179191
cnm-binary:
180192
cd $(CNM_DIR) && CGO_ENABLED=0 go build -v -o $(CNM_BUILD_DIR)/azure-vnet-plugin$(EXE_EXT) -ldflags "-X main.version=$(ACN_VERSION)" -gcflags="-dwarflocationlists=true"
@@ -252,6 +264,7 @@ endif
252264
## Image name definitions.
253265
ACNCLI_IMAGE = acncli
254266
AZURE_IPAM_IMAGE = azure-ipam
267+
IPV6_HP_BPF_IMAGE = ipv6-hp-bpf
255268
CNI_IMAGE = azure-cni
256269
CNI_DROPGZ_IMAGE = cni-dropgz
257270
CNS_IMAGE = azure-cns
@@ -261,6 +274,7 @@ NPM_IMAGE = azure-npm
261274
ACNCLI_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(ACN_VERSION)
262275
AZURE_IPAM_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(AZURE_IPAM_VERSION)
263276
AZURE_IPAM_WINDOWS_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(AZURE_IPAM_VERSION)-$(OS_SKU_WIN)
277+
IPV6_HP_BPF_IMAGE_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(IPV6_HP_BPF_VERSION)
264278
CNI_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(CNI_VERSION)
265279
CNI_WINDOWS_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(CNI_VERSION)-$(OS_SKU_WIN)
266280
CNI_DROPGZ_PLATFORM_TAG ?= $(subst /,-,$(PLATFORM))$(if $(OS_VERSION),-$(OS_VERSION),)-$(CNI_DROPGZ_VERSION)
@@ -368,6 +382,34 @@ azure-ipam-image-pull: ## pull azure-ipam container image.
368382
IMAGE=$(AZURE_IPAM_IMAGE) \
369383
TAG=$(AZURE_IPAM_PLATFORM_TAG)
370384

385+
# ipv6-hp-bpf
386+
387+
ipv6-hp-bpf-image-name: # util target to print the ipv6-hp-bpf image name.
388+
@echo $(IPV6_HP_BPF_IMAGE)
389+
390+
ipv6-hp-bpf-image-name-and-tag: # util target to print the ipv6-hp-bpf image name and tag.
391+
@echo $(IMAGE_REGISTRY)/$(IPV6_HP_BPF_IMAGE):$(IPV6_HP_BPF_IMAGE_PLATFORM_TAG)
392+
393+
ipv6-hp-bpf-image: ## build ipv6-hp-bpf container image.
394+
$(MAKE) container \
395+
DOCKERFILE=bpf-prog/ipv6-hp-bpf/$(OS).Dockerfile \
396+
IMAGE=$(IPV6_HP_BPF_IMAGE) \
397+
EXTRA_BUILD_ARGS='--build-arg OS=$(OS) --build-arg ARCH=$(ARCH) --build-arg OS_VERSION=$(OS_VERSION) --build-arg DEBUG=$(DEBUG)'\
398+
PLATFORM=$(PLATFORM) \
399+
TAG=$(IPV6_HP_BPF_IMAGE_PLATFORM_TAG) \
400+
OS=$(OS) \
401+
ARCH=$(ARCH) \
402+
OS_VERSION=$(OS_VERSION)
403+
404+
ipv6-hp-bpf-image-push: ## push ipv6-hp-bpf container image.
405+
$(MAKE) container-push \
406+
IMAGE=$(IPV6_HP_BPF_IMAGE) \
407+
TAG=$(IPV6_HP_BPF_IMAGE_PLATFORM_TAG)
408+
409+
ipv6-hp-bpf-image-pull: ## pull ipv6-hp-bpf container image.
410+
$(MAKE) container-pull \
411+
IMAGE=$(IPV6_HP_BPF_IMAGE) \
412+
TAG=$(IPV6_HP_BPF_IMAGE_PLATFORM_TAG)
371413

372414
# cni
373415

@@ -742,6 +784,13 @@ ifeq ($(GOOS),linux)
742784
cd $(AZURE_IPAM_BUILD_DIR) && $(ARCHIVE_CMD) $(AZURE_IPAM_ARCHIVE_NAME) azure-ipam$(EXE_EXT)
743785
endif
744786

787+
# Create a ipv6-hp-bpf archive for the target platform.
788+
.PHONY: ipv6-hp-bpf-archive
789+
ipv6-hp-bpf-archive: ipv6-hp-bpf-binary
790+
ifeq ($(GOOS),linux)
791+
$(MKDIR) $(IPV6_HP_BPF_BUILD_DIR)
792+
cd $(IPV6_HP_BPF_BUILD_DIR) && $(ARCHIVE_CMD) $(IPV6_HP_BPF_ARCHIVE_NAME) ipv6-hp-bpf$(EXE_EXT)
793+
endif
745794

746795
##@ Utils
747796

bpf-prog/ipv6-hp-bpf/README

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ipv6-hp-bpf
2+
3+
`ipv6-hp-bpf` is a project that leverages eBPF (Extended Berkeley Packet Filter) technology for traffic control in Linux kernel. This is a POC to fix external load balancer services in cilium dualstack clusters.
4+
5+
## Description
6+
7+
The goal of this bpf program is to fix the issue described [here](https://github.com/cilium/cilium/issues/31326). It includes both egress and ingress TC programs. These programs are meant to replace the nftable rules since they don't work on cilium clusters.
8+
The egress bpf code converts the destination IPv6 of the packet from global unicast to link local, and ingress converts the source IPv6 from link local to global unicast.
9+
10+
## Usage
11+
12+
Follow the steps below to compile the program and install it onto your node:
13+
14+
1. Use the make command to build the binary or follow the steps below.
15+
```bash
16+
make ipv6-hp-bpf-binary
17+
```
18+
19+
2. Copy the new binary to your node(s).
20+
21+
3. Remove the nftable rules for ipv6 with the following commands:
22+
```bash
23+
nft delete chain ip6 azureSLBProbe postrouting
24+
nft delete chain ip6 azureSLBProbe prerouting
25+
nft -n list table ip6 azureSLBProbe
26+
```
27+
28+
4. Start the program with:
29+
```bash
30+
./ipv6-hp-bpf
31+
```
32+
5. Debugging logs can be seen in the node under `/sys/kernel/debug/traceing/trace_pipe`
33+
34+
## Manual Compilation
35+
For testing purposes you can compile the bpf program without go, and attach it to the interface yourself. This is how you would do it for egress:
36+
```bash
37+
clang -O2 -g -target bpf -c egress.c -o egress.o
38+
```
39+
40+
This will generate the egress.o file, which you can copy over to your cluster's node.
41+
To copy to the node you need to create a node-shell instance
42+
```bash
43+
kubectl cp egress.o nsenter-xxxxx:<path-in-node>
44+
```
45+
46+
Since this is for cilium clusters, cilium already creates a qdisc on eth0 of type clsact (which allows both ingress and egress filters to be attached). If cilium is not installed, you would have to create the qdisc on your own by doing the following:
47+
```bash
48+
tc qdisc add dev eth0 clsact
49+
```
50+
51+
## Attach the filter
52+
```bash
53+
tc filter add dev eth0 egress prio 1 bpf da obj egress.o sec classifier
54+
```
55+
56+
## Verify the filter is attached
57+
```bash
58+
tc filter show dev eth0 egress
59+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"net"
6+
"os/exec"
7+
8+
"github.com/Azure/azure-container-networking/bpf-prog/ipv6-hp-bpf/pkg/egress"
9+
"github.com/Azure/azure-container-networking/bpf-prog/ipv6-hp-bpf/pkg/ingress"
10+
"github.com/vishvananda/netlink"
11+
12+
"github.com/cilium/ebpf/rlimit"
13+
"go.uber.org/zap"
14+
)
15+
16+
var logger *zap.Logger
17+
18+
func main() {
19+
// Set up logger
20+
config := zap.NewProductionConfig()
21+
config.OutputPaths = []string{"stdout", "/var/log/azure-ipv6-hp-bpf.log"}
22+
logger, _ = config.Build()
23+
24+
// Remove resource limits for kernels <5.11.
25+
if err := rlimit.RemoveMemlock(); err != nil {
26+
logger.Error("Removing memlock", zap.Error(err))
27+
return
28+
}
29+
30+
// Check 'nft -n list tables ip6' to see if table exists
31+
cmd := exec.Command("nft", "-n", "list", "tables", "ip6")
32+
output, err := cmd.CombinedOutput()
33+
if err != nil {
34+
logger.Error("error running 'nft -n list tables ip6'", zap.Error(err), zap.String("output", string(output)))
35+
return
36+
}
37+
38+
// if azureSLBProbe table exists, delete it
39+
if bytes.Contains(output, []byte("azureSLBProbe")) {
40+
cmd := exec.Command("nft", "delete", "table", "ip6", "azureSLBProbe")
41+
err = cmd.Run()
42+
if err != nil {
43+
logger.Error("failed to run 'nft delete table ip6 azureSLBProbe'", zap.Error(err))
44+
return
45+
}
46+
}
47+
48+
ifname := "eth0"
49+
iface, err := net.InterfaceByName(ifname)
50+
if err != nil {
51+
logger.Error("Getting interface", zap.String("interface", ifname), zap.Error(err))
52+
}
53+
logger.Info("Interface has index", zap.String("interface", ifname), zap.Int("index", iface.Index))
54+
55+
// Create a qdisc filter for traffic on the interface.
56+
fq := &netlink.GenericQdisc{
57+
QdiscAttrs: netlink.QdiscAttrs{
58+
LinkIndex: iface.Index,
59+
Handle: netlink.MakeHandle(0xffff, 0),
60+
Parent: netlink.HANDLE_CLSACT,
61+
},
62+
QdiscType: "clsact",
63+
}
64+
if err := netlink.QdiscReplace(fq); err != nil {
65+
logger.Error("failed setting egress qdisc", zap.Error(err))
66+
return
67+
}
68+
69+
// Load the compiled eBPF ELF and load it into the kernel.
70+
// Set up ingress and egress filters to attach to eth0 clsact qdisc
71+
var objsEgress egress.EgressObjects
72+
defer objsEgress.Close()
73+
if err := egress.LoadEgressObjects(&objsEgress, nil); err != nil {
74+
logger.Error("Failed to load eBPF egress objects", zap.Error(err))
75+
}
76+
if err := egress.SetupEgressFilter(iface.Index, &objsEgress, logger); err != nil {
77+
logger.Error("Setting up egress filter", zap.Error(err))
78+
} else {
79+
logger.Info("Successfully set egress filter on", zap.String("interface", ifname))
80+
}
81+
82+
var objsIngress ingress.IngressObjects
83+
if err := ingress.LoadIngressObjects(&objsIngress, nil); err != nil {
84+
logger.Error("Loading eBPF ingress objects", zap.Error(err))
85+
}
86+
defer objsIngress.Close()
87+
if err := ingress.SetupIngressFilter(iface.Index, &objsIngress, logger); err != nil {
88+
logger.Error("Setting up ingress filter", zap.Error(err))
89+
} else {
90+
logger.Info("Successfully set ingress filter on", zap.String("interface", ifname))
91+
}
92+
}

bpf-prog/ipv6-hp-bpf/go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module github.com/Azure/azure-container-networking/bpf-prog/ipv6-hp-bpf
2+
3+
go 1.21.6
4+
5+
require (
6+
github.com/cilium/ebpf v0.15.0
7+
github.com/vishvananda/netlink v1.1.0
8+
go.uber.org/zap v1.27.0
9+
)
10+
11+
require (
12+
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
13+
go.uber.org/multierr v1.10.0 // indirect
14+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 // indirect
15+
golang.org/x/sys v0.15.0 // indirect
16+
)

bpf-prog/ipv6-hp-bpf/go.sum

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
github.com/cilium/ebpf v0.15.0 h1:7NxJhNiBT3NG8pZJ3c+yfrVdHY8ScgKD27sScgjLMMk=
2+
github.com/cilium/ebpf v0.15.0/go.mod h1:DHp1WyrLeiBh19Cf/tfiSMhqheEiK8fXFZ4No0P1Hso=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
6+
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
7+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
8+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
10+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
11+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
12+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
13+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15+
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
16+
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
17+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
18+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
19+
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
20+
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
21+
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
22+
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
23+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
24+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
25+
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
26+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
27+
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
28+
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
29+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 h1:Jvc7gsqn21cJHCmAWx0LiimpP18LZmUxkT5Mp7EZ1mI=
30+
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
31+
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
33+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
34+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
35+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <netinet/in.h>
2+
#include <stdbool.h>
3+
4+
#define L4_HDR_OFF (ETH_HLEN + sizeof(struct ipv6hdr))
5+
#define BPF_F_PSEUDO_HDR (1ULL << 4)
6+
7+
static __always_inline bool compare_ipv6_addr(const struct in6_addr *addr1, const struct in6_addr *addr2)
8+
{
9+
#pragma unroll
10+
for (int i = 0; i < sizeof(struct in6_addr); i++)
11+
{
12+
if (addr1->s6_addr[i] != addr2->s6_addr[i])
13+
{
14+
return false;
15+
}
16+
}
17+
return true;
18+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.21 AS builder
2+
ARG VERSION
3+
ARG DEBUG
4+
ARG OS
5+
WORKDIR /bpf-prog/ipv6-hp-bpf
6+
COPY ./bpf-prog/ipv6-hp-bpf .
7+
COPY ./bpf-prog/ipv6-hp-bpf/cmd/ipv6-hp-bpf/*.go /bpf-prog/ipv6-hp-bpf/
8+
COPY ./bpf-prog/ipv6-hp-bpf/include/helper.h /bpf-prog/ipv6-hp-bpf/include/helper.h
9+
RUN apt-get update && apt-get install -y llvm clang linux-libc-dev linux-headers-generic libbpf-dev libc6-dev gcc-multilib nftables iproute2
10+
RUN for dir in /usr/include/x86_64-linux-gnu/*; do ln -s "$dir" /usr/include/$(basename "$dir"); done
11+
ENV C_INCLUDE_PATH=/usr/include/bpf
12+
RUN if [ "$DEBUG" = "true" ]; then echo "\n#define DEBUG" >> /bpf-prog/ipv6-hp-bpf/include/helper.h; fi
13+
RUN GOOS=$OS CGO_ENABLED=0 go generate ./...
14+
RUN GOOS=$OS CGO_ENABLED=0 go build -a -o /go/bin/ipv6-hp-bpf -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" .
15+
16+
FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0
17+
COPY --from=builder /go/bin/ipv6-hp-bpf /ipv6-hp-bpf
18+
COPY --from=builder /usr/sbin/nft /usr/sbin/nft
19+
COPY --from=builder /sbin/ip /sbin/ip
20+
COPY --from=builder /lib/x86_64-linux-gnu/libnftables.so.1 /lib/x86_64-linux-gnu/
21+
COPY --from=builder /lib/x86_64-linux-gnu/libedit.so.2 /lib/x86_64-linux-gnu/
22+
COPY --from=builder /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/
23+
COPY --from=builder /lib/x86_64-linux-gnu/libmnl.so.0 /lib/x86_64-linux-gnu/
24+
COPY --from=builder /lib/x86_64-linux-gnu/libnftnl.so.11 /lib/x86_64-linux-gnu/
25+
COPY --from=builder /lib/x86_64-linux-gnu/libxtables.so.12 /lib/x86_64-linux-gnu/
26+
COPY --from=builder /lib/x86_64-linux-gnu/libjansson.so.4 /lib/x86_64-linux-gnu/
27+
COPY --from=builder /lib/x86_64-linux-gnu/libgmp.so.10 /lib/x86_64-linux-gnu/
28+
COPY --from=builder /lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/
29+
COPY --from=builder /lib/x86_64-linux-gnu/libbsd.so.0 /lib/x86_64-linux-gnu/
30+
COPY --from=builder /lib64/ld-linux-x86-64.so.2 /lib64/
31+
COPY --from=builder /lib/x86_64-linux-gnu/libmd.so.0 /lib/x86_64-linux-gnu/
32+
CMD ["/ipv6-hp-bpf"]

0 commit comments

Comments
 (0)