Skip to content

Commit

Permalink
Post-merge build fix-ups.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Feb 24, 2020
1 parent 53b1800 commit 140f759
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 90 deletions.
26 changes: 21 additions & 5 deletions bpf-gpl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ C_FILES:=tc.c connect_balancer.c
all: $(OBJS)
ut-objs: $(UT_OBJS)

connect_time%.ll: connect_balancer.c connect_balancer.d
$(CC) $(CFLAGS) `./calculate-flags $@` -c $< -o $@
COMPILE=$(CC) $(CFLAGS) `./calculate-flags $@` -c $< -o $@
connect_time_%v4.ll: connect_balancer.c connect_balancer.d calculate-flags
$(COMPILE)
connect_time_%v6.ll: connect_balancer_v6.c connect_balancer_v6.d calculate-flags
$(COMPILE)

UT_CFLAGS=\
-D__BPFTOOL_LOADER__ \
Expand All @@ -62,11 +65,24 @@ ut/%.ll: ut/%.c ut/ut.h tc.c tc.d
$(CC) $(CFLAGS) $(UT_CFLAGS) -c $< -o $@

# Production and UT versions of the main binaries.
%.ll: tc.c tc.d
$(CC) $(CFLAGS) `./calculate-flags $@` -c $< -o $@
# Combining the targets into one rule causes make to fail to rebuild the .ll files. Not sure why.
to%.ll: tc.c tc.d calculate-flags
$(COMPILE)
from%.ll: tc.c tc.d calculate-flags
$(COMPILE)
test%.ll: tc.c tc.d calculate-flags
$(COMPILE)

LINK=$(LD) -march=bpf -filetype=obj -o $@ $<
bin/%.o: %.ll | bin
bin/to%.o: to%.ll | bin
$(LINK)
bin/from%.o: from%.ll | bin
$(LINK)
bin/test%.o: test%.ll | bin
$(LINK)
bin/connect_time_%v4.o: connect_time_%v4.ll | bin
$(LINK)
bin/connect_time_%v6.o: connect_time_%v6.ll | bin
$(LINK)
ut/%.o: ut/%.ll
$(LINK)
Expand Down
2 changes: 1 addition & 1 deletion bpf-gpl/calculate-flags
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if [[ "${filename}" =~ .*host([0-9a-fA-Fx]+).* ]]; then
args+=("-DCALI_HOST_IP=${BASH_REMATCH[1]}")
fi

if [[ "${filename}" =~ ut_.* ]]; then
if [[ "${filename}" =~ test_.* ]]; then
args+=("-D__BPFTOOL_LOADER__")
args+=("-DCALI_VXLAN_PORT=5665")
args+=("-DCALI_NAT_TUNNEL_MTU=700")
Expand Down
19 changes: 17 additions & 2 deletions bpf-gpl/connect_balancer_v6.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Project Calico BPF dataplane programs.
// Copyright (c) 2020 Tigera, Inc. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <linux/bpf.h>
#include <sys/socket.h>

#include "../include/bpf.h"
#include "../include/log.h"
#include "bpf.h"
#include "log.h"

#include "sendrecv.h"

Expand Down
3 changes: 2 additions & 1 deletion bpf-gpl/list-objs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#
# WARNING: naming and set of cases must be kept in sync with tc.ProgFilename() in Felix's compiler.go.
for log_level in debug info no_log; do
echo "bin/connect_time_$log_level.o"
echo "bin/connect_time_${log_level}_v4.o"
echo "bin/connect_time_${log_level}_v6.o"
for host_drop in "" "host_drop_"; do
if [ "${host_drop}" = "host_drop_" ]; then
# The workload-to-host drop setting only applies to the from-workload hook.
Expand Down
79 changes: 1 addition & 78 deletions bpf/nat/connecttime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
package nat

import (
"bufio"
"encoding/json"
"fmt"
"os"
"os/exec"
"path"
"strconv"
"strings"
"sync"

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

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

type cgroupProgs struct {
Expand Down Expand Up @@ -188,7 +185,7 @@ func ProgFileName(logLevel string, ipver int) string {

switch ipver {
case 4:
return fmt.Sprintf("connect_time_%s.o", logLevel)
return fmt.Sprintf("connect_time_%s_v4.o", logLevel)
case 6:
return fmt.Sprintf("connect_time_%s_v6.o", logLevel)
}
Expand All @@ -197,80 +194,6 @@ func ProgFileName(logLevel string, ipver int) string {
return ""
}

func compileConnectTimeLoadBalancer(logLevel, inFile, outFile string) error {
args := []string{
"-x",
"c",
"-D__KERNEL__",
"-D__ASM_SYSREG_H",
"-D__BPFTOOL_LOADER__",
"-DCALI_LOG_LEVEL=CALI_LOG_LEVEL_" + strings.ToUpper(logLevel),
fmt.Sprintf("-DCALI_COMPILE_FLAGS=%d", tc.CompileFlagCgroup),
"-DCALI_LOG_PFX=CALI",
"-Wno-unused-value",
"-Wno-pointer-sign",
"-Wno-compare-distinct-pointer-types",
"-Wunused",
"-Wall",
"-Werror",
"-fno-stack-protector",
"-O2",
"-emit-llvm",
"-c", inFile,
"-o", "-",
}

clang := exec.Command("clang", args...)
clangStdout, err := clang.StdoutPipe()
if err != nil {
return err
}
clangStderr, err := clang.StderrPipe()
if err != nil {
return err
}
err = clang.Start()
if err != nil {
log.WithError(err).Panic("Failed to start clang.")
return err
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
scanner := bufio.NewScanner(clangStderr)
for scanner.Scan() {
log.Warnf("clang stderr: %s", scanner.Text())
}
if err != nil {
log.WithError(err).Error("Error while reading clang stderr")
}
}()
llc := exec.Command("llc", "-march=bpf", "-filetype=obj", "-o", outFile)
llc.Stdin = clangStdout
out, err := llc.CombinedOutput()
if err != nil {
log.WithError(err).WithField("out", string(out)).Error("Failed to compile C program (llc step)")
return err
}
err = clang.Wait()
if err != nil {
log.WithError(err).Error("Clang failed.")
return err
}
wg.Wait()

return nil
}

func CompileConnectTimeLoadBalancer(logLevel string, outFile string) error {
return compileConnectTimeLoadBalancer(logLevel, "bpf/cgroup/connect_balancer.c", outFile)
}

func CompileConnectTimeLoadBalancerV6(logLevel string, outFile string) error {
return compileConnectTimeLoadBalancer(logLevel, "bpf/cgroup/connect_balancer_v6.c", outFile)
}

func ensureCgroupPath(cgroupv2 string) (string, error) {
cgroupRoot, err := bpf.MaybeMountCgroupV2()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion bpf/ut/bpf_prog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func runBpfTest(t *testing.T, section string, rules [][][]*proto.Rule, testFn fu
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(bpfFsDir)

obj := "../../bpf-gpl/bin/ut_"
obj := "../../bpf-gpl/bin/test_"
if strings.Contains(section, "from") {
obj += "from_"
} else {
Expand Down
4 changes: 2 additions & 2 deletions fv/test-connection/test-connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func tryConnect(remoteIpAddr, remotePort, sourceIpAddr, sourcePort, protocol, lo
defer conn.Close()

for {
req := conncheck.NewRequest()
req := connectivity.NewRequest()
data, err := json.Marshal(req)
if err != nil {
log.WithError(err).Fatal("Failed to marshal data")
Expand All @@ -270,7 +270,7 @@ func tryConnect(remoteIpAddr, remotePort, sourceIpAddr, sourcePort, protocol, lo
log.Fatalf("From address %+v does not match remoteAddr %+v", from, remoteAddrResolved)
}

var resp conncheck.Response
var resp connectivity.Response
err = json.Unmarshal(bufIn[:n], &resp)
if err != nil {
log.WithError(err).Fatal("Failed to read response")
Expand Down

0 comments on commit 140f759

Please sign in to comment.