https://github.com/cilium/cilium
Raw File
Tip revision: fd2f5154a873b90c2eb684d454c7f334b0a3a4b3 authored by Thomas Graf on 19 March 2018, 12:07:33 UTC
Prepare for 1.0.0-rc8 release
Tip revision: fd2f515
join_ep.sh
#!/bin/bash
#
# Copyright 2016-2017 Authors of Cilium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

LIB=$1
RUNDIR=$2
EPDIR=$3
IFNAME=$4
DEBUG=$5
EPID=$6

function bpf_preprocess()
{
	SRC=$1

	clang -E -O2 -target bpf -I$RUNDIR/globals -I$EPDIR		\
		-I$LIB/include -c $LIB/$SRC -o $EPDIR/$SRC
}

function bpf_compile()
{
	IN=$1
	OUT=$2
	TYPE=$3
	EXTRA_CFLAGS=$4

	clang -O2 -target bpf -emit-llvm $EXTRA_CFLAGS			\
	      -Wno-address-of-packed-member -Wno-unknown-warning-option	\
	      -I$RUNDIR/globals -I$EPDIR -I$LIB/include			\
	      -D__NR_CPUS__=$(nproc)					\
	      -c $LIB/$IN -o - |					\
	llc -march=bpf -mcpu=probe -filetype=$TYPE -o $EPDIR/$OUT
}

echo "Join EP id=$EPDIR ifname=$IFNAME"

# Only generate ASM output if debug is enabled.
if [[ "${DEBUG}" == "true" ]]; then
  echo "kernel version: " `uname -a`
  echo "clang version: " `clang --version`
  bpf_compile bpf_lxc.c bpf_lxc.asm asm -g
  bpf_preprocess bpf_lxc.c
fi

bpf_compile bpf_lxc.c bpf_lxc.o obj

tc qdisc replace dev $IFNAME clsact || true

# Move the old calls map to a temporary location so it can be removed after the
# program has been replaced
CALLS_MAP="/sys/fs/bpf/tc/globals/cilium_calls_${EPID}"
mv "$CALLS_MAP" "${CALLS_MAP}.old" 2> /dev/null || true
tc filter replace dev $IFNAME ingress prio 1 handle 1 bpf da obj $EPDIR/bpf_lxc.o sec from-container || {
	mv "${CALLS_MAP}.old" "${CALLS_MAP}"
	exit 1
}

rm "${CALLS_MAP}.old" 2> /dev/null || true
back to top