Skip to content

Commit

Permalink
Ship BPF prgrams in debs/rpms.
Browse files Browse the repository at this point in the history
* move the BPF programs to /var/lib/calico
* update deb/RPM builds.
  • Loading branch information
fasaxc committed Feb 24, 2020
1 parent 140f759 commit 1093a9e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ BPF_GPL_O_FILES:=$(addprefix bpf-gpl/,$(shell bpf-gpl/list-objs))

# There's a one-to-one mapping from UT C files to objects and the same for the apache programs..
BPF_GPL_UT_O_FILES:=$(BPF_GPL_UT_C_FILES:.c=.o) $(addprefix bpf-gpl/,$(shell bpf-gpl/list-ut-objs))
BPF_APACHE_C_FILES:=$(wildcard bpf-apache/*.c)
BPF_APACHE_O_FILES:=$(addprefix bpf-apache/bin/,$(notdir $(BPF_APACHE_C_FILES:.c=.o)))

ALL_BPF_PROGS=$(BPF_GPL_O_FILES) $(BPF_APACHE_O_FILES)
Expand Down Expand Up @@ -672,7 +673,7 @@ ut-bpf: bin/bpf_ut.test bin/bpf.test build-bpf
--privileged \
-e RUN_AS_ROOT=true \
-v `pwd`:/code \
-v `pwd`/bpf-gpl/bin:/code/bpf/bin \
-v `pwd`/bpf-gpl/bin:/usr/lib/calico/bpf \
$(CALICO_BUILD) sh -c ' \
mount bpffs /sys/fs/bpf -t bpf && \
cd /go/src/$(PACKAGE_NAME)/bpf/ut && \
Expand Down
2 changes: 2 additions & 0 deletions bpf/bpf_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ type MapInfo struct {
KeySize int
ValueSize int
}

const ObjectDir = "/usr/lib/calico/bpf"
4 changes: 2 additions & 2 deletions bpf/nat/connecttime.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func installProgram(name, ipver, bpfMount, cgroupPath, logLevel string, maps ...
var filename string

if ipver == "6" {
filename = path.Join("/code/bpf/bin", ProgFileName(logLevel, 6))
filename = path.Join(bpf.ObjectDir, ProgFileName(logLevel, 6))
} else {
filename = path.Join("/code/bpf/bin", ProgFileName(logLevel, 4))
filename = path.Join(bpf.ObjectDir, ProgFileName(logLevel, 4))
}
args := []string{"prog", "loadall", filename, progPinDir, "type", "cgroup/" + name + ipver}
for _, m := range maps {
Expand Down
4 changes: 3 additions & 1 deletion bpf/tc/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/projectcalico/felix/bpf"
)

type AttachPoint struct {
Expand Down Expand Up @@ -76,7 +78,7 @@ func AttachProgram(attachPoint AttachPoint, hostIP net.IP) error {
_ = os.RemoveAll(tempDir)
}()

preCompiledBinary := path.Join("/code/bpf/bin", attachPoint.Filename)
preCompiledBinary := path.Join(bpf.ObjectDir, attachPoint.Filename)
tempBinary := path.Join(tempDir, attachPoint.Filename)

exeData, err := ioutil.ReadFile(preCompiledBinary)
Expand Down
2 changes: 1 addition & 1 deletion dataplane/linux/sockmap_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type sockmapState struct {
}

func NewSockmapState() (*sockmapState, error) {
lib, err := bpf.NewBPFLib("/code/bpf/bin/")
lib, err := bpf.NewBPFLib("/usr/lib/calico/bpf/")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion dataplane/linux/xdp_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type xdpState struct {
}

func NewXDPState(allowGenericXDP bool) (*xdpState, error) {
lib, err := bpf.NewBPFLib("/code/bpf/bin/")
lib, err := bpf.NewBPFLib("/usr/lib/calico/bpf/")
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions debian/calico-felix.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
usr/bin/calico-felix usr/bin
usr/lib/calico/bpf/* usr/lib/calico/bpf
usr/etc/calico/felix.cfg.example etc/calico
4 changes: 3 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DH_VERBOSE=1

%:
dh $@ --with systemd
Expand All @@ -22,6 +22,8 @@ override_dh_install:
install -m 644 etc/bird/*.template debian/tmp/usr/share/calico/bird
install -d debian/tmp/usr/bin
install -m 755 bin/* etc/calico-diags etc/*.sh debian/tmp/usr/bin/
install -d debian/tmp/usr/lib/calico/bpf
install -m 644 bpf-apache/bin/*.o bpf-gpl/bin/*.o debian/tmp/usr/lib/calico/bpf/
dh_install

# strip fails on some of our binaries, disable it.
Expand Down
2 changes: 1 addition & 1 deletion docker-image/Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ADD calico-felix-wrapper /usr/bin
ADD bin/calico-felix-amd64 /code/calico-felix
ADD bin/calico-bpf /usr/bin/calico-bpf

ADD bpf/ /code/bpf/
ADD bpf/bin/* /usr/lib/calico/bpf/

RUN ln -s /code/calico-felix /usr/bin
COPY --from=bpftool /bpftool /usr/bin
Expand Down
5 changes: 5 additions & 0 deletions rpm/felix.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ fi
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT/usr/bin/
install -m 755 bin/* $RPM_BUILD_ROOT/usr/bin/
install -d $RPM_BUILD_ROOT/usr/lib/calico/bpf/
install -m 644 bpf-gpl/bin/* $RPM_BUILD_ROOT/usr/lib/calico/bpf/
install -m 644 bpf-apache/bin/* $RPM_BUILD_ROOT/usr/lib/calico/bpf/


# Setup directories
install -d -m 755 %{buildroot}%{_datadir}/calico
Expand Down Expand Up @@ -139,6 +143,7 @@ rm -rf $RPM_BUILD_ROOT
%files -n calico-felix
%defattr(-,root,root,-)
/usr/bin/calico-felix
/usr/lib/calico/bpf/*
/etc/calico/felix.cfg.example
%if 0%{?el7}
%{_unitdir}/calico-felix.service
Expand Down

0 comments on commit 1093a9e

Please sign in to comment.