diff --git a/mosdns/Makefile b/mosdns/Makefile index c4a68f16cef..62d32d1991e 100644 --- a/mosdns/Makefile +++ b/mosdns/Makefile @@ -5,12 +5,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mosdns -PKG_VERSION:=5.3.1 +PKG_VERSION:=5.3.3 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_HASH:=1d7eeaa735cb48ed2d436797d7f2a82541699f74647cd293ee411a72cdc65f5f PKG_LICENSE:=GPL-3.0 PKG_LICENSE_FILE:=LICENSE @@ -36,8 +36,6 @@ define Package/mosdns DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle endef -GO_PKG_TARGET_VARS:=$(filter-out CGO_ENABLED=%,$(GO_PKG_TARGET_VARS)) CGO_ENABLED=0 - define Package/mosdns/install $(call GoPackage/Package/Install/Bin,$(1)) endef 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 00000000000..38b7974bfc2 --- /dev/null +++ b/mosdns/patches/203-add-response-for-bad-request-in-ServeHTTP-handler.patch @@ -0,0 +1,19 @@ +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(+) + +--- a/pkg/server/http_handler.go ++++ b/pkg/server/http_handler.go +@@ -93,6 +93,7 @@ func (h *HttpHandler) ServeHTTP(w http.R + if err != nil { + h.warnErr(req, "invalid request", err) + w.WriteHeader(http.StatusBadRequest) ++ w.Write([]byte("Bad Request")) + return + } + 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 00000000000..fa18e86c1a0 --- /dev/null +++ b/mosdns/patches/204-black_hole-apply-Fisher-Yates-shuffle-algorithm-to-r.patch @@ -0,0 +1,51 @@ +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(+) + +--- 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) + type BlackHole struct { + ipv4 []netip.Addr + ipv6 []netip.Addr ++ shuffleMutex sync.Mutex + } + + // QuickSetup format: [ipv4|ipv6] ... +@@ -65,9 +68,21 @@ func NewBlackHole(ips []string) (*BlackH + 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) + } diff --git a/mosdns/patches/205-format-logtime.patch b/mosdns/patches/205-format-logtime.patch new file mode 100644 index 00000000000..1628ad04194 --- /dev/null +++ b/mosdns/patches/205-format-logtime.patch @@ -0,0 +1,46 @@ +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(-) + +--- 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.Logge + 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.