diff --git a/build/build.sh b/build/build.sh index b85072e..cd0f9e4 100755 --- a/build/build.sh +++ b/build/build.sh @@ -6,6 +6,7 @@ function build() { VERSION=$(lookup-version "$ROOT"/../internal/const/const.go) DIST=$ROOT/"../dist/${NAME}" MUSL_DIR="/usr/local/opt/musl-cross/bin" + SRCDIR=$(realpath "$ROOT/..") # for macOS users: precompiled gcc can be downloaded from https://github.com/messense/homebrew-macos-cross-toolchains GCC_X86_64_DIR="/usr/local/gcc/x86_64-unknown-linux-gnu/bin" @@ -70,6 +71,8 @@ function build() { CC_PATH="" CXX_PATH="" + CGO_LDFLAGS="" + CGO_CFLAGS="" BUILD_TAG=$TAG if [[ `uname -a` == *"Darwin"* && "${OS}" == "linux" ]]; then if [ "${ARCH}" == "amd64" ]; then @@ -79,7 +82,7 @@ function build() { CC_PATH="x86_64-unknown-linux-gnu-gcc" CXX_PATH="x86_64-unknown-linux-gnu-g++" if [ "$TAG" = "plus" ]; then - BUILD_TAG="plus,script" + BUILD_TAG="plus,script,packet" fi else CC_PATH="x86_64-linux-musl-gcc" @@ -97,7 +100,7 @@ function build() { CC_PATH="aarch64-unknown-linux-gnu-gcc" CXX_PATH="aarch64-unknown-linux-gnu-g++" if [ "$TAG" = "plus" ]; then - BUILD_TAG="plus,script" + BUILD_TAG="plus,script,packet" fi else CC_PATH="aarch64-linux-musl-gcc" @@ -117,13 +120,26 @@ function build() { CXX_PATH="mips64el-linux-musl-g++" fi fi + + # libpcap + if [ "$OS" == "linux" ] && [[ "$ARCH" == "amd64" || "$ARCH" == "arm64" ]] && [ "$TAG" == "plus" ]; then + CGO_LDFLAGS="-L${SRCDIR}/libs/libpcap/${ARCH} -lpcap" + CGO_CFLAGS="-I${SRCDIR}/libs/libpcap/src/libpcap -I${SRCDIR}/libs/libpcap/src/libpcap/pcap" + fi + if [ ! -z $CC_PATH ]; then - env CC=$MUSL_DIR/$CC_PATH CXX=$MUSL_DIR/$CXX_PATH GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags "-linkmode external -extldflags -static -s -w" "$ROOT"/../cmd/edge-node/main.go + env CC=$MUSL_DIR/$CC_PATH \ + CXX=$MUSL_DIR/$CXX_PATH GOOS="${OS}" \ + GOARCH="${ARCH}" CGO_ENABLED=1 \ + CGO_LDFLAGS="${CGO_LDFLAGS}" \ + CGO_CFLAGS="${CGO_CFLAGS}" \ + go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags "-linkmode external -extldflags -static -s -w" "$ROOT"/../cmd/edge-node/main.go else if [[ `uname` == *"Linux"* ]] && [ "$OS" == "linux" ] && [[ "$ARCH" == "amd64" || "$ARCH" == "arm64" ]] && [ "$TAG" == "plus" ]; then - BUILD_TAG="plus,script" + BUILD_TAG="plus,script,packet" fi - env GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags="-s -w" "$ROOT"/../cmd/edge-node/main.go + + env GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=1 CGO_LDFLAGS="${CGO_LDFLAGS}" CGO_CFLAGS="${CGO_CFLAGS}" go build -trimpath -tags $BUILD_TAG -o "$DIST"/bin/${NAME} -ldflags="-s -w" "$ROOT"/../cmd/edge-node/main.go fi if [ ! -f "${DIST}/bin/${NAME}" ]; then diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 19b9bce..2b718d3 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -146,12 +146,12 @@ func (this *Node) Start() { remotelogs.Println("NODE", "init config ...") err = this.syncConfig(0) if err != nil { - _, err := nodeconfigs.SharedNodeConfig() + _, err = nodeconfigs.SharedNodeConfig() if err != nil { // 无本地数据时,会尝试多次读取 tryTimes := 0 for { - err := this.syncConfig(0) + err = this.syncConfig(0) if err != nil { tryTimes++ diff --git a/internal/nodes/node_tasks.go b/internal/nodes/node_tasks.go index b4f7762..2fdfab5 100644 --- a/internal/nodes/node_tasks.go +++ b/internal/nodes/node_tasks.go @@ -97,6 +97,8 @@ func (this *Node) execTask(rpcClient *rpc.RPCClient, task *pb.NodeTask) error { err = this.notifyPlusChange() case "toaChanged": err = this.execTOAChangedTask() + case "networkSecurityPolicyChanged": + err = this.execNetworkSecurityPolicyChangedTask(rpcClient) default: // 特殊任务 if strings.HasPrefix(task.Type, "ipListDeleted") { // 删除IP名单 diff --git a/internal/nodes/node_tasks_ext.go b/internal/nodes/node_tasks_ext.go index 18f70d2..f65310c 100644 --- a/internal/nodes/node_tasks_ext.go +++ b/internal/nodes/node_tasks_ext.go @@ -29,3 +29,8 @@ func (this *Node) execHTTPPagesPolicyChangedTask(rpcClient *rpc.RPCClient) error // stub return nil } + +func (this *Node) execNetworkSecurityPolicyChangedTask(rpcClient *rpc.RPCClient) error { + // stub + return nil +}