Skip to content

Commit 48838c4

Browse files
committed
Tc
1 parent ed8253c commit 48838c4

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

docker/entrypoint.sh

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,49 @@ NETNS=${NETNS:-}
3636

3737
SEG_DEV_NAME=${SEG_DEV_NAME:-_seg}
3838

39-
PROG=/opt/sfunnel/src/tc_sfunnel.o
39+
SRC_DIR=/opt/sfunnel/src
40+
PROG_DIR=/opt/sfunnel/bin
41+
PROG_INGRESS=${PROG_DIR}/tc_sfunnel_ingress.o
42+
PROG_EGRESS=${PROG_DIR}/tc_sfunnel_egress.o
4043

41-
#Compile eBPF program only if rulesset are defined at load time
42-
#either via file or ENV
44+
#Compile eBPF programs (INGRESS/EGRESS)
4345
compile(){
44-
cd /opt/sfunnel/src
45-
SEG_DEV_IFINDEX=${SEG_DEV_IFINDEX} SEG_PAIR_DEV_IFINDEX=${SEG_PAIR_DEV_IFINDEX} SEG_PAIR_DEV_MAC="${SEG_PAIR_DEV_MAC}" DEBUG=${DEBUG} FILE=/etc/sfunnel/ruleset make
46+
cd ${SRC_DIR}
47+
mkdir -p ${PROG_DIR}
48+
49+
for INGRESS in 0 1; do
50+
INGRESS=${INGRESS} SEG_DEV_IFINDEX=${SEG_DEV_IFINDEX} SEG_PAIR_DEV_IFINDEX=${SEG_PAIR_DEV_IFINDEX} SEG_PAIR_DEV_MAC="${SEG_PAIR_DEV_MAC}" DEBUG=${DEBUG} FILE=/etc/sfunnel/ruleset make
51+
if [ "$INGRESS" -eq 1 ]; then
52+
mv ${SRC_DIR}/tc_sfunnel.o ${PROG_INGRESS}
53+
else
54+
mv ${SRC_DIR}/tc_sfunnel.o ${PROG_EGRESS}
55+
fi
56+
done
4657
}
4758

48-
#$1: PROG
49-
#$2: IFACE
50-
#$3: direction {ingress, egress}
59+
#$1: IFACE
60+
#$2: direction {ingress, egress}
5161
load_prog(){
62+
PROG=$( [[ ${2} == "ingress" ]] && echo ${PROG_INGRESS} || echo ${PROG_EGRESS} )
5263
for ((i=1; i<${N_ATTEMPTS}; i++)); do
53-
echo "[INFO] Attaching BPF program '${1}' to '${2}' direction '${3}'..."
54-
tc filter add dev ${2} ${3} bpf da obj ${1} verbose
64+
echo "[INFO] Attaching BPF program '${PROG}' to '${1}' direction '${2}'..."
65+
tc filter add dev ${1} ${2} bpf da obj ${PROG} verbose
5566
if [[ "$?" == "1" ]]; then
56-
echo "[WARNING] attempt ${i} failed on iface '${2}', direction '${3}', prog '${1}'. Retrying in ${RETRY_DELAY} seconds..."
67+
echo "[WARNING] attempt ${i} failed on iface '${1}', direction '${2}', prog '${PROG}'. Retrying in ${RETRY_DELAY} seconds..."
5768
sleep ${RETRY_DELAY}
5869
else
5970
break;
6071
fi
6172
done
6273

6374
if [[ ${i} -ge ${N_ATTEMPTS} ]]; then
64-
echo "[ERROR] unable to attach BPF program to '${2}'!"
75+
echo "[ERROR] unable to attach BPF program to '${1}'!"
6576
exit 1
6677
fi
6778

6879
echo ""
6980
}
7081

71-
#$1: PROG
7282
#$2: IFACE
7383
#$3: direction {ingress, egress}
7484
clean_prog(){
@@ -160,7 +170,7 @@ else
160170

161171
OP=load_prog
162172
OP_STR=attach
163-
echo -e "[INFO] Attaching BPF program '${PROG}' on IFACES={$IFACES} DIRECTION=${DIRECTION} using clsact qdisc...\n"
173+
echo -e "[INFO] Attaching BPF program on IFACES={$IFACES} DIRECTION=${DIRECTION} using clsact qdisc...\n"
164174
fi
165175

166176
for IFACE in ${IFACES}; do
@@ -170,10 +180,10 @@ for IFACE in ${IFACES}; do
170180
fi
171181

172182
if [[ ${DIRECTION} != "egress" ]]; then
173-
${OP} ${PROG} ${IFACE} ingress
183+
${OP} ${IFACE} ingress
174184
fi
175185
if [[ ${DIRECTION} != "ingress" ]]; then
176-
${OP} ${PROG} ${IFACE} egress
186+
${OP} ${IFACE} egress
177187
fi
178188

179189
echo -e "[INFO] Successfully ${OP_STR}ed BPF program(s) on '${IFACE}' DIRECTION=${DIRECTION}.\n"
@@ -200,7 +210,7 @@ if [[ "${SEG_DEV_NAME}" != "" ]]; then
200210
fi
201211

202212
if [[ ${DIRECTION} != "egress" ]]; then
203-
${OP} ${PROG} ${SEG_DEV_NAME}_pair ingress
213+
${OP} ${SEG_DEV_NAME}_pair ingress
204214
fi
205215
fi
206216

src/common.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
#define CHECK_SKB_PTR_VAL( SKB, PTR, VAL ) \
1717
if ( (void*)(PTR) > ((void*)(unsigned long long) SKB -> data_end )) { \
18-
PRINTK("PTR: %p on pkt with length: %d out of bounds!\n", \
19-
PTR, SKB ->len);\
18+
PRINTK("[%d:0x%p] PTR: 0x%p on pkt with length: %d out of bounds!\n", \
19+
SKB ->ifindex, SKB, \
20+
PTR, SKB ->len); \
2021
return VAL; \
2122
} do{}while(0)
2223
#define CHECK_SKB_PTR( SKB, PTR ) CHECK_SKB_PTR_VAL( SKB, PTR, TC_ACT_OK)

0 commit comments

Comments
 (0)