-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (115 loc) · 4.33 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2024 Anya Lin <[email protected]>
include $(TOPDIR)/rules.mk
PKG_NAME:=einat-ebpf
PKG_UPSTREAM_VERSION:=0.1.5
PKG_UPSTREAM_GITHASH:=
PKG_VERSION:=$(PKG_UPSTREAM_VERSION)$(if $(PKG_UPSTREAM_GITHASH),~$(call version_abbrev,$(PKG_UPSTREAM_GITHASH)))
PKG_RELEASE:=2
ifeq ($(PKG_UPSTREAM_GITHASH),)
PKG_SOURCE_URL:=https://codeload.github.com/EHfive/einat-ebpf/tar.gz/refs/tags/v$(PKG_UPSTREAM_VERSION)?
PKG_HASH:=d1d834c45c593e7765b931f0556d7750030b60243ab89c03a735bf674e59f850
PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.gz
else
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/EHfive/einat-ebpf.git
PKG_SOURCE_VERSION:=$(PKG_UPSTREAM_GITHASH)
PKG_MIRROR_HASH:=05ccebb3fb2dde30c7fc35953ee86efa6796745bda18cbc85534c2a268992443
PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz
endif
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_SUBDIR)
PKG_MAINTAINER:=Anya Lin <[email protected]>
PKG_LICENSE:=GPL-2.0-or-later GPL-2.0-only
PKG_LICENSE_FILES:=LICENSE
PKG_BUILD_DEPENDS:=rust/host libbpf #HAS_BPF_TOOLCHAIN:bpf-headers # requires modified kernel
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16
PKG_CONFIG_DEPENDS+= \
CONFIG_EINAT_EBPF_IPV6 \
CONFIG_EINAT_EBPF_BACKEND_LIBBPF \
CONFIG_EINAT_EBPF_BINDGEN \
CONFIG_EINAT_EBPF_STATIC \
include $(INCLUDE_DIR)/bpf.mk
include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/rust/rust-package.mk
# The LLVM_PATH var is required so that einat's build script finds llvm-strip
TARGET_PATH_PKG:=$(LLVM_PATH):$(TARGET_PATH_PKG)
# $(TOPDIR)/feeds/packages/lang/rust/rust-values.mk
# RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
EINAT_EBPF_RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||powerpc64||riscv64||x86_64) # Architectures other than x86_64 and aarch64 have not been tested.
ifeq ($(ARCH),arm)
CONFIG_EINAT_EBPF_BINDGEN:=y
else ifeq ($(ARCH),i386)
CONFIG_EINAT_EBPF_BINDGEN:=y
else ifeq ($(ARCH),i686)
CONFIG_EINAT_EBPF_BINDGEN:=y
endif
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
SUBMENU:=Routing and Redirection
TITLE:=eBPF-based Endpoint-Independent NAT
URL:=https://github.com/EHfive/einat-ebpf
# You need enable KERNEL_DEBUG_INFO_BTF and disable KERNEL_DEBUG_INFO_REDUCED
DEPENDS:=$(EINAT_EBPF_RUST_ARCH_DEPENDS) $(BPF_DEPENDS) \
+kmod-sched-core +kmod-sched-bpf \
+EINAT_EBPF_BACKEND_LIBBPF:libbpf \
+@KERNEL_DEBUG_FS +@KERNEL_DEBUG_INFO_BTF
USERID:=einat:einat
PROVIDES:=einat
endef
define Package/$(PKG_NAME)/description
This eBPF application implements an "Endpoint-Independent Mapping" and
"Endpoint-Independent Filtering" NAT(network address translation) on
TC egress and ingress hooks.
endef
define Package/$(PKG_NAME)/config
menu "Features configuration"
depends on PACKAGE_einat-ebpf
config EINAT_EBPF_IPV6
bool "Enable IPV6 NAT66 feature"
default n
help
It would increase load time of eBPF programs to
about 4 times.
config EINAT_EBPF_BACKEND_LIBBPF
bool "Enable libbpf backend"
default n
help
Add fallback BPF loading backend: "libbpf".
config EINAT_EBPF_BINDGEN
bool "Enable bindgen"
default n
help
Bindgen for libbpf headers, required on 32-bit
platforms.
config EINAT_EBPF_STATIC
bool "Enable static compile"
default n
endmenu
endef
RUST_PKG_FEATURES:=$(subst $(space),$(comma),$(strip \
$(if $(CONFIG_EINAT_EBPF_IPV6),ipv6) \
$(if $(CONFIG_EINAT_EBPF_BACKEND_LIBBPF),libbpf) \
$(if $(CONFIG_EINAT_EBPF_BINDGEN),bindgen) \
$(if $(CONFIG_EINAT_EBPF_STATIC),static) \
))
#export EINAT_BPF_CFLAGS="-I/usr/include/aarch64-linux-gnu"
define Package/$(PKG_NAME)/conffiles
/etc/config/einat
endef
define Package/$(PKG_NAME)/install
$(CURDIR)/.prepare.sh $(VERSION) $(CURDIR) $(PKG_INSTALL_DIR)/bin/einat
$(INSTALL_DIR) $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/einat $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/init.d/
$(INSTALL_BIN) $(CURDIR)/files/einat.init $(1)/etc/init.d/einat
$(INSTALL_DIR) $(1)/etc/config/
$(INSTALL_CONF) $(CURDIR)/files/einat.config $(1)/etc/config/einat
$(INSTALL_DIR) $(1)/etc/capabilities/
$(INSTALL_CONF) $(CURDIR)/files/capabilities.json $(1)/etc/capabilities/einat.json
endef
$(eval $(call RustBinPackage,$(PKG_NAME)))
$(eval $(call BuildPackage,$(PKG_NAME)))