File tree 7 files changed +66
-17
lines changed
7 files changed +66
-17
lines changed Original file line number Diff line number Diff line change 50
50
val; \
51
51
})
52
52
53
- #if !ENHANCED_KERNEL
54
53
struct bpf_mem_ptr {
55
54
void * ptr ;
56
55
__u32 size ;
57
56
};
58
57
58
+ #if !ENHANCED_KERNEL
59
59
static inline int bpf__strncmp (char * dst , int n , const char * src ) {
60
60
if (dst == NULL || src == NULL )
61
61
return -1 ;
Original file line number Diff line number Diff line change @@ -13,7 +13,20 @@ function bpf_compile_range_adjust() {
13
13
}
14
14
15
15
function set_enhanced_kernel_env() {
16
- if grep -q " FN(parse_header_msg)" /usr/include/linux/bpf.h; then
16
+ # we use /usr/include/linux/bpf.h to determine the runtime environment’s
17
+ # support for kmesh. Considering the case of online image compilation, a
18
+ # variable KERNEL_HEADER_LINUX_BPF is used here to specify the path of the
19
+ # source of macro definition.
20
+ # When using an online compiled image, /usr/include/linux/bpf.h in host
21
+ # machine will be mounted to config/linux-bpf.h.
22
+ # Otherwise, /usr/include/linux/bpf.h from the current compilation
23
+ # environment will be obtained
24
+ export KERNEL_HEADER_LINUX_BPF=$ROOT_DIR /config/linux-bpf.h
25
+ if [ ! -f " $KERNEL_HEADER_LINUX_BPF " ]; then
26
+ export KERNEL_HEADER_LINUX_BPF=/usr/include/linux/bpf.h
27
+ fi
28
+
29
+ if grep -q " FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF ; then
17
30
export ENHANCED_KERNEL=" enhanced"
18
31
else
19
32
export ENHANCED_KERNEL=" unenhanced"
Original file line number Diff line number Diff line change 3
3
#
4
4
# Usage:
5
5
# docker build -f kmesh.dockerfile -t kmesh:latest .
6
- # docker run -itd --privileged=true -v /etc/cni/net.d:/etc/cni/net.d -v /opt/cni/bin:/opt/cni/bin -v /mnt:/mnt -v /sys/fs/bpf:/sys/fs/bpf -v /lib/modules:/lib/modules --name kmesh kmesh:latest
6
+ # docker run -itd --privileged=true -v /usr/src:/usr/src -v /usr/include/linux/bpf.h:/kmesh/config/linux-bpf.h -v / etc/cni/net.d:/etc/cni/net.d -v /opt/cni/bin:/opt/cni/bin -v /mnt:/mnt -v /sys/fs/bpf:/sys/fs/bpf -v /lib/modules:/lib/modules --name kmesh kmesh:latest
7
7
#
8
8
9
9
# base image
10
- FROM openeuler/openeuler:23.03
10
+ FROM openeuler/openeuler:23.09
11
11
12
12
# container work directory
13
13
WORKDIR /kmesh
@@ -17,12 +17,11 @@ WORKDIR /kmesh
17
17
ADD . /kmesh
18
18
19
19
# install pkg dependencies
20
- # RUN yum install -y kmod util-linux kmesh
20
+ # RUN yum install -y kmod util-linux
21
+ # install package in online-compile image
21
22
RUN yum install -y kmod \
22
23
&& yum install -y util-linux \
23
- && yum install -y kmesh-*.rpm \
24
- && yum clean all \
25
- && rm -rf /var/cache/yum
24
+ && yum install -y make golang clang llvm libboundscheck protobuf-c-devel bpftool libbpf libbpf-devel cmake
26
25
27
26
RUN chmod +x start_kmesh.sh
28
27
Original file line number Diff line number Diff line change 34
34
- name : kmesh-cniplugin-install-path
35
35
hostPath :
36
36
path : /opt/cni/bin
37
+ # Optional:
38
+ # online compilation image needs to determine the support
39
+ # to kmesh in host during compilation, based on this file.
40
+ - name : linux-bpf
41
+ hostPath :
42
+ path : /usr/include/linux/bpf.h
43
+ # Optional:
44
+ # online compilation image needs compile kmesh.ko by host file
45
+ - name : ko-build-path
46
+ hostPath :
47
+ path : /usr/src
37
48
containers :
38
49
- name : kmesh
39
50
image : kmesh:latest
@@ -65,13 +76,27 @@ spec:
65
76
- name : kube-config-path
66
77
mountPath : /root/.kube
67
78
readOnly : true
79
+ # k8s default cni conflist path
68
80
- name : cni
69
81
mountPath : /etc/cni/net.d
70
82
readOnly : false
83
+ # k8s deafult cni path
71
84
- name : kmesh-cniplugin-install-path
72
85
mountPath : /opt/cni/bin
73
86
readOnly : false
87
+ # Optional:
88
+ # online compilation image needs to determine the support
89
+ # to kmesh in host during compilation, based on this file.
90
+ - name : linux-bpf
91
+ mountPath : /kmesh/config/linux-bpf.h
92
+ readOnly : true
93
+ # Optional:
94
+ # online compilation image needs compile kmesh.ko by host file
95
+ - name : ko-build-path
96
+ mountPath : /usr/src
97
+ readOnly : true
74
98
resources :
75
99
limits :
76
- memory : " 200Mi"
100
+ # image online-compile needs 800Mi, or only 200Mi
101
+ memory : " 800Mi"
77
102
cpu : " 1"
Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ helper_name=(
15
15
get_msg_header_element
16
16
)
17
17
18
- base_line=` grep -nr " FN(unspec)" /usr/include/linux/bpf.h | awk -F " :" {' print $1' }`
18
+ base_line=` grep -nr " FN(unspec)" $KERNEL_HEADER_LINUX_BPF | awk -F " :" {' print $1' }`
19
19
for name in ${helper_name[@]} ; do
20
- current_line=` grep -nr " FN($name )" /usr/include/linux/bpf.h | awk -F " :" {' print $1' }`
20
+ current_line=` grep -nr " FN($name )" $KERNEL_HEADER_LINUX_BPF | awk -F " :" {' print $1' }`
21
21
if [ -n " $current_line " ]; then
22
22
helper_id=` expr $current_line - $base_line `
23
23
sed -Ei " /$name /s/([0-9]+)[^0-9]*$/$helper_id ;/" $ROOT_DIR /depends/include/bpf_helper_defs_ext.h
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ function install_libboundscheck() {
14
14
function dependency_pkg_install() {
15
15
if command -v apt > /dev/null; then
16
16
# apt install
17
- apt-get update && apt-get install -y git make clang libbpf-dev llvm rpm linux-tools-generic protobuf-compiler libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler cmake golang
17
+ apt-get update && apt-get install -y git make clang libbpf-dev llvm linux-tools-generic protobuf-compiler libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler cmake golang
18
18
install_libboundscheck
19
19
elif command -v yum > /dev/null; then
20
20
# yum install
21
- yum install -y git make golang clang llvm libboundscheck protobuf protobuf-c protobuf-c-devel bpftool rpm-build rpmdevtools libbpf libbpf-devel cmake
21
+ yum install -y git make golang clang llvm libboundscheck protobuf protobuf-c protobuf-c-devel bpftool libbpf libbpf-devel cmake
22
22
fi
23
23
}
24
24
@@ -41,6 +41,18 @@ function adapt_low_version_kernel() {
41
41
fi
42
42
}
43
43
44
+ # Special case:
45
+ # There is a structure that is only defined in certain environments and is
46
+ # only used during the compilation stage. Therefore, the definition of this
47
+ # structure in the include directory is dynamically adjusted according to
48
+ # the current compilation environment during compilation.
49
+ function adapt_include_env {
50
+ if grep -q " struct bpf_mem_ptr {" /usr/include/linux/bpf.h; then
51
+ sed -i ' /bpf_mem_ptr/{N;N;N;N;d;}' bpf/kmesh/include/kmesh_common.h
52
+ fi
53
+ }
54
+
44
55
dependency_pkg_install
45
56
fix_libbpf_bug
46
57
adapt_low_version_kernel
58
+ adapt_include_env
Original file line number Diff line number Diff line change @@ -7,21 +7,21 @@ function set_config() {
7
7
}
8
8
9
9
# MDA_LOOPBACK_ADDR
10
- if grep -q " FN(get_netns_cookie)" /usr/include/linux/bpf.h ; then
10
+ if grep -q " FN(get_netns_cookie)" $KERNEL_HEADER_LINUX_BPF ; then
11
11
set_config MDA_LOOPBACK_ADDR 1
12
12
else
13
13
set_config MDA_LOOPBACK_ADDR 0
14
14
fi
15
15
16
16
# MDA_NAT_ACCEL
17
- if grep -q " FN(sk_original_addr)" /usr/include/linux/bpf.h ; then
17
+ if grep -q " FN(sk_original_addr)" $KERNEL_HEADER_LINUX_BPF ; then
18
18
set_config MDA_NAT_ACCEL 1
19
19
else
20
20
set_config MDA_NAT_ACCEL 0
21
21
fi
22
22
23
23
# MDA_GID_UID_FILTER
24
- if grep -q " FN(get_sockops_uid_gid)" /usr/include/linux/bpf.h ; then
24
+ if grep -q " FN(get_sockops_uid_gid)" $KERNEL_HEADER_LINUX_BPF ; then
25
25
set_config MDA_GID_UID_FILTER 1
26
26
else
27
27
set_config MDA_GID_UID_FILTER 0
42
42
fi
43
43
44
44
# ENHANCED_KERNEL
45
- if grep -q " FN(parse_header_msg)" /usr/include/linux/bpf.h ; then
45
+ if grep -q " FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF ; then
46
46
set_config ENHANCED_KERNEL 1
47
47
else
48
48
set_config ENHANCED_KERNEL 0
You can’t perform that action at this time.
0 commit comments