File tree Expand file tree Collapse file tree 7 files changed +66
-17
lines changed Expand file tree Collapse file tree 7 files changed +66
-17
lines changed Original file line number Diff line number Diff line change 5050 val; \
5151 })
5252
53- #if !ENHANCED_KERNEL
5453struct bpf_mem_ptr {
5554 void * ptr ;
5655 __u32 size ;
5756};
5857
58+ #if !ENHANCED_KERNEL
5959static inline int bpf__strncmp (char * dst , int n , const char * src ) {
6060 if (dst == NULL || src == NULL )
6161 return -1 ;
Original file line number Diff line number Diff line change @@ -13,7 +13,20 @@ function bpf_compile_range_adjust() {
1313}
1414
1515function 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
1730 export ENHANCED_KERNEL=" enhanced"
1831 else
1932 export ENHANCED_KERNEL=" unenhanced"
Original file line number Diff line number Diff line change 33#
44# Usage:
55# 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
77#
88
99# base image
10- FROM openeuler/openeuler:23.03
10+ FROM openeuler/openeuler:23.09
1111
1212# container work directory
1313WORKDIR /kmesh
@@ -17,12 +17,11 @@ WORKDIR /kmesh
1717ADD . /kmesh
1818
1919# 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
2122RUN yum install -y kmod \
2223 && 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
2625
2726RUN chmod +x start_kmesh.sh
2827
Original file line number Diff line number Diff line change 3434 - name : kmesh-cniplugin-install-path
3535 hostPath :
3636 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
3748 containers :
3849 - name : kmesh
3950 image : kmesh:latest
@@ -65,13 +76,27 @@ spec:
6576 - name : kube-config-path
6677 mountPath : /root/.kube
6778 readOnly : true
79+ # k8s default cni conflist path
6880 - name : cni
6981 mountPath : /etc/cni/net.d
7082 readOnly : false
83+ # k8s deafult cni path
7184 - name : kmesh-cniplugin-install-path
7285 mountPath : /opt/cni/bin
7386 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
7498 resources :
7599 limits :
76- memory : " 200Mi"
100+ # image online-compile needs 800Mi, or only 200Mi
101+ memory : " 800Mi"
77102 cpu : " 1"
Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ helper_name=(
1515 get_msg_header_element
1616)
1717
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' }`
1919for 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' }`
2121 if [ -n " $current_line " ]; then
2222 helper_id=` expr $current_line - $base_line `
2323 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() {
1414function dependency_pkg_install() {
1515 if command -v apt > /dev/null; then
1616 # 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
1818 install_libboundscheck
1919 elif command -v yum > /dev/null; then
2020 # 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
2222 fi
2323}
2424
@@ -41,6 +41,18 @@ function adapt_low_version_kernel() {
4141 fi
4242}
4343
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+
4455dependency_pkg_install
4556fix_libbpf_bug
4657adapt_low_version_kernel
58+ adapt_include_env
Original file line number Diff line number Diff line change @@ -7,21 +7,21 @@ function set_config() {
77}
88
99# 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
1111 set_config MDA_LOOPBACK_ADDR 1
1212else
1313 set_config MDA_LOOPBACK_ADDR 0
1414fi
1515
1616# 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
1818 set_config MDA_NAT_ACCEL 1
1919else
2020 set_config MDA_NAT_ACCEL 0
2121fi
2222
2323# 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
2525 set_config MDA_GID_UID_FILTER 1
2626else
2727 set_config MDA_GID_UID_FILTER 0
4242fi
4343
4444# 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
4646 set_config ENHANCED_KERNEL 1
4747else
4848 set_config ENHANCED_KERNEL 0
You can’t perform that action at this time.
0 commit comments