diff --git a/luci-app-mosdns b/luci-app-mosdns new file mode 160000 index 0000000..97867ea --- /dev/null +++ b/luci-app-mosdns @@ -0,0 +1 @@ +Subproject commit 97867eae9df8201c1408000e7160749f76d60bcb diff --git a/mosdns/Makefile b/mosdns/Makefile new file mode 100644 index 0000000..7d1f6ff --- /dev/null +++ b/mosdns/Makefile @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-3.0-only +# +# Copyright (C) 2021 ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_NAME:=mosdns +PKG_VERSION:=5.3.1 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/IrineSistiana/mosdns/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=7c8c795de794df52fd2b51214826aea9ebde0dcd0da78d8dda9cc5e4ab98cd80 + +PKG_LICENSE:=GPL-3.0 +PKG_LICENSE_FILE:=LICENSE +PKG_MAINTAINER:=Tianling Shen + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_USE_MIPS16:=0 +PKG_BUILD_FLAGS:=no-mips16 + +GO_PKG:=github.com/IrineSistiana/mosdns +GO_PKG_LDFLAGS_X:=main.version=v$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk +include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk + +define Package/mosdns + SECTION:=net + CATEGORY:=Network + SUBMENU:=IP Addresses and Names + TITLE:=A plug-in DNS forwarder/splitter + URL:=https://github.com/IrineSistiana/mosdns + DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle +endef + +define Package/mosdns/install + $(call GoPackage/Package/Install/Bin,$(1)) +endef + +$(eval $(call GoBinPackage,mosdns)) +$(eval $(call BuildPackage,mosdns)) diff --git a/mosdns/patches/201-compatible-with-go1.20.patch b/mosdns/patches/201-compatible-with-go1.20.patch new file mode 100644 index 0000000..9099c69 --- /dev/null +++ b/mosdns/patches/201-compatible-with-go1.20.patch @@ -0,0 +1,51 @@ +From 329ba9ca89d25da58d1b51b8107f164beae816bb Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Tue, 19 Sep 2023 21:15:12 +0800 +Subject: [PATCH 1/5] compatible with go1.20 + +--- + go.mod | 6 ++---- + go.sum | 4 ++-- + 2 files changed, 4 insertions(+), 6 deletions(-) + +diff --git a/go.mod b/go.mod +index 1839776..1b4cc4b 100644 +--- a/go.mod ++++ b/go.mod +@@ -1,8 +1,6 @@ + module github.com/IrineSistiana/mosdns/v5 + +-go 1.21 +- +-toolchain go1.21.1 ++go 1.20 + + require ( + github.com/IrineSistiana/go-bytes-pool v0.0.0-20230918115058-c72bd9761c57 +@@ -45,7 +43,7 @@ require ( + github.com/magiconair/properties v1.8.7 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/mdlayher/netlink v1.7.2 // indirect +- github.com/mdlayher/socket v0.5.0 // indirect ++ github.com/mdlayher/socket v0.4.1 // indirect + github.com/onsi/ginkgo/v2 v2.13.0 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect +diff --git a/go.sum b/go.sum +index 41a59b2..ad95d6d 100644 +--- a/go.sum ++++ b/go.sum +@@ -173,8 +173,8 @@ github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvls + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= + github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g= + github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= +-github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI= +-github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI= ++github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= ++github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= + github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE= + github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY= + github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +-- +2.42.0 + diff --git a/mosdns/patches/203-add-response-for-bad-request-in-ServeHTTP-handler.patch b/mosdns/patches/203-add-response-for-bad-request-in-ServeHTTP-handler.patch new file mode 100644 index 0000000..463e96c --- /dev/null +++ b/mosdns/patches/203-add-response-for-bad-request-in-ServeHTTP-handler.patch @@ -0,0 +1,24 @@ +From 0b86b89629f32e7c8b859239aa1a4814f256053c Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Thu, 28 Sep 2023 16:42:54 +0800 +Subject: [PATCH 3/5] add response for bad request in ServeHTTP handler + +--- + pkg/server/http_handler.go | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/pkg/server/http_handler.go b/pkg/server/http_handler.go +index 5a41314..8f33b3f 100644 +--- a/pkg/server/http_handler.go ++++ b/pkg/server/http_handler.go +@@ -93,6 +93,7 @@ func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + if err != nil { + h.warnErr(req, "invalid request", err) + w.WriteHeader(http.StatusBadRequest) ++ w.Write([]byte("Bad Request")) + return + } + +-- +2.42.0 + diff --git a/mosdns/patches/204-black_hole-apply-Fisher-Yates-shuffle-algorithm-to-r.patch b/mosdns/patches/204-black_hole-apply-Fisher-Yates-shuffle-algorithm-to-r.patch new file mode 100644 index 0000000..f623815 --- /dev/null +++ b/mosdns/patches/204-black_hole-apply-Fisher-Yates-shuffle-algorithm-to-r.patch @@ -0,0 +1,56 @@ +From e34dca717e78d24a84b98c2b5d371c4253b7e260 Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Wed, 20 Sep 2023 14:51:19 +0800 +Subject: [PATCH 4/5] black_hole: apply Fisher-Yates shuffle algorithm to + randomize IP order + +--- + plugin/executable/black_hole/black_hole.go | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/plugin/executable/black_hole/black_hole.go b/plugin/executable/black_hole/black_hole.go +index 775253d..f955019 100644 +--- a/plugin/executable/black_hole/black_hole.go ++++ b/plugin/executable/black_hole/black_hole.go +@@ -27,6 +27,8 @@ import ( + "github.com/miekg/dns" + "net/netip" + "strings" ++ "math/rand" ++ "sync" + ) + + const PluginType = "black_hole" +@@ -40,6 +42,7 @@ var _ sequence.Executable = (*BlackHole)(nil) + type BlackHole struct { + ipv4 []netip.Addr + ipv6 []netip.Addr ++ shuffleMutex sync.Mutex + } + + // QuickSetup format: [ipv4|ipv6] ... +@@ -65,9 +68,21 @@ func NewBlackHole(ips []string) (*BlackHole, error) { + return b, nil + } + ++func (b *BlackHole) shuffleIPs() { ++ b.shuffleMutex.Lock() ++ defer b.shuffleMutex.Unlock() ++ rand.Shuffle(len(b.ipv4), func(i, j int) { ++ b.ipv4[i], b.ipv4[j] = b.ipv4[j], b.ipv4[i] ++ }) ++ rand.Shuffle(len(b.ipv6), func(i, j int) { ++ b.ipv6[i], b.ipv6[j] = b.ipv6[j], b.ipv6[i] ++ }) ++} ++ + // Exec implements sequence.Executable. It set a response with given ips if + // query has corresponding qtypes. + func (b *BlackHole) Exec(_ context.Context, qCtx *query_context.Context) error { ++ b.shuffleIPs() + if r := b.Response(qCtx.Q()); r != nil { + qCtx.SetResponse(r) + } +-- +2.42.0 + diff --git a/mosdns/patches/205-format-logtime.patch b/mosdns/patches/205-format-logtime.patch new file mode 100644 index 0000000..204bc8e --- /dev/null +++ b/mosdns/patches/205-format-logtime.patch @@ -0,0 +1,51 @@ +From 2dc08749e2de8f19ef869e7f89c9979edbbc71ff Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Wed, 20 Sep 2023 21:05:18 +0800 +Subject: [PATCH 5/5] format logtime + +--- + mlog/logger.go | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/mlog/logger.go b/mlog/logger.go +index 861f091..1508db0 100644 +--- a/mlog/logger.go ++++ b/mlog/logger.go +@@ -21,9 +21,11 @@ package mlog + + import ( + "fmt" ++ "os" ++ "time" ++ + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +- "os" + ) + + type LogConfig struct { +@@ -64,10 +66,18 @@ func NewLogger(lc LogConfig) (*zap.Logger, error) { + out = stderr + } + +- if lc.Production { +- return zap.New(zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), out, lvl)), nil ++ encoderConfig := zap.NewDevelopmentEncoderConfig() ++ encoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { ++ enc.AppendString(t.Format("2006-01-02 15:04:05")) + } +- return zap.New(zapcore.NewCore(zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()), out, lvl)), nil ++ ++ core := zapcore.NewCore( ++ zapcore.NewConsoleEncoder(encoderConfig), ++ out, ++ lvl, ++ ) ++ ++ return zap.New(core), nil + } + + // L is a global logger. +-- +2.42.0 + diff --git a/v2dat/Makefile b/v2dat/Makefile new file mode 100644 index 0000000..cbf9aea --- /dev/null +++ b/v2dat/Makefile @@ -0,0 +1,46 @@ +# +# Copyright (C) 2015-2016 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v3. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=v2dat +PKG_SOURCE_DATE:=2022-12-15 +PKG_SOURCE_VERSION:=47b8ee51fb528e11e1a83453b7e767a18d20d1f7 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_DATE).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/urlesistiana/v2dat/tar.gz/$(PKG_SOURCE_VERSION)? +PKG_HASH:=dca45a31006aca3dba5f543f6990ca755ffb2bde8e533cc2bbe6bac9ec12f157 +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION) + +PKG_LICENSE:=GPL-3.0 +PKG_LICENSE_FILE:=LICENSE +PKG_MAINTAINER:=sbwml + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_USE_MIPS16:=0 +PKG_BUILD_FLAGS:=no-mips16 + +GO_PKG:=github.com/urlesistiana/v2dat + +include $(INCLUDE_DIR)/package.mk +include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk + +define Package/v2dat + SECTION:=utils + CATEGORY:=Utilities + TITLE:=V2ray geo/ip data unpack tools + URL:=https://github.com/urlesistiana/v2dat + DEPENDS:=$(GO_ARCH_DEPENDS) +endef + +define Package/v2dat/install + $(call GoPackage/Package/Install/Bin,$(1)) +endef + +$(eval $(call GoBinPackage,v2dat)) +$(eval $(call BuildPackage,v2dat)) diff --git a/v2dat/patches/100-format-logtime.patch b/v2dat/patches/100-format-logtime.patch new file mode 100644 index 0000000..ba18ffc --- /dev/null +++ b/v2dat/patches/100-format-logtime.patch @@ -0,0 +1,47 @@ +From 7c6a252ab3f7d9aeb743f9fa8d0cc8c7402f984d Mon Sep 17 00:00:00 2001 +From: sbwml +Date: Wed, 20 Sep 2023 20:52:27 +0800 +Subject: [PATCH] format logtime + +--- + mlog/logger.go | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/mlog/logger.go b/mlog/logger.go +index c8b08a9..b44c88d 100644 +--- a/mlog/logger.go ++++ b/mlog/logger.go +@@ -1,17 +1,28 @@ + package mlog + +-import "go.uber.org/zap" ++import ( ++ "time" ++ ++ "go.uber.org/zap" ++ "go.uber.org/zap/zapcore" ++) + + var logger = mustInitLogger() + + func mustInitLogger() *zap.Logger { +- l, err := zap.NewDevelopment(zap.WithCaller(false)) ++ config := zap.NewDevelopmentConfig() ++ config.EncoderConfig.EncodeTime = customTimeEncoder ++ l, err := config.Build(zap.WithCaller(false)) + if err != nil { + panic("failed to init mlog:" + err.Error()) + } + return l + } + ++func customTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { ++ enc.AppendString(t.Format("2006-01-02 15:04:05")) ++} ++ + func L() *zap.Logger { + return logger + } +-- +2.34.8 +