Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosdns: bump version #1550

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mosdns/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0b86b89629f32e7c8b859239aa1a4814f256053c Mon Sep 17 00:00:00 2001
From: sbwml <[email protected]>
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
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From e34dca717e78d24a84b98c2b5d371c4253b7e260 Mon Sep 17 00:00:00 2001
From: sbwml <[email protected]>
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)
}
46 changes: 46 additions & 0 deletions mosdns/patches/205-format-logtime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 2dc08749e2de8f19ef869e7f89c9979edbbc71ff Mon Sep 17 00:00:00 2001
From: sbwml <[email protected]>
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.
Loading