--- /dev/null
+From 0ca0898bec9c4b58a5cc6dcc062862e3573eed7d Mon Sep 17 00:00:00 2001
+From: mzz2017 <mzz@tuta.io>
+Date: Sat, 11 Dec 2021 15:34:17 +0800
+Subject: [PATCH] fix: when no addr found, lookup again
+
+---
+ service/common/resolv/resolver.go | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/common/resolv/resolver.go
++++ b/common/resolv/resolver.go
+@@ -39,7 +39,7 @@ func init() {
+
+ func LookupHost(host string) (addrs []string, err error) {
+ addrs, err = net.LookupHost(host)
+- lookupAgain := err != nil
++ lookupAgain := len(addrs) == 0 || err != nil
+ if !lookupAgain {
+ for _, addr := range addrs {
+ if ip := net.ParseIP(addr); ip != nil && (ip.IsLoopback() || ip.IsUnspecified()) {
--- /dev/null
+From ce463911b8b480363cdf2b55518e4e7ac85ca6d7 Mon Sep 17 00:00:00 2001
+From: mzz2017 <mzz@tuta.io>
+Date: Thu, 16 Dec 2021 23:44:07 +0800
+Subject: [PATCH] fix: incorrect ipv6 routing. #329
+
+---
+ service/core/v2ray/v2rayTmpl.go | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+--- a/core/v2ray/v2rayTmpl.go
++++ b/core/v2ray/v2rayTmpl.go
+@@ -516,7 +516,7 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: firstOutboundTag,
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"ext:LoyalsoldierSite.dat:geolocation-!cn"},
+ })
+ } else {
+@@ -524,7 +524,7 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: firstOutboundTag,
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"geosite:geolocation-!cn"},
+ })
+ }
+@@ -532,19 +532,19 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: "direct",
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"geosite:cn"},
+ },
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: "proxy",
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ IP: []string{"geoip:hk", "geoip:mo"},
+ },
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: "direct",
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ IP: []string{"geoip:private", "geoip:cn"},
+ },
+ )
+@@ -554,13 +554,13 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: firstOutboundTag,
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"ext:LoyalsoldierSite.dat:gfw"},
+ },
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: firstOutboundTag,
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"ext:LoyalsoldierSite.dat:greatfire"},
+ })
+ } else {
+@@ -568,7 +568,7 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: firstOutboundTag,
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ Domain: []string{"geosite:geolocation-!cn"},
+ })
+ }
+@@ -576,11 +576,11 @@ func (t *Template) AppendRoutingRuleByMo
+ coreObj.RoutingRule{
+ Type: "field",
+ OutboundTag: "direct",
+- InboundTag: inbounds,
++ InboundTag: deepcopy.Copy(inbounds).([]string),
+ },
+ )
+ case configure.RoutingAMode:
+- if err := parseRoutingA(t, inbounds); err != nil {
++ if err := parseRoutingA(t, deepcopy.Copy(inbounds).([]string)); err != nil {
+ return err
+ }
+ }
--- /dev/null
+From 68c28fb85cf079a678ce5334a18b9d848faa9d06 Mon Sep 17 00:00:00 2001
+From: mzz2017 <mzz@tuta.io>
+Date: Sun, 19 Dec 2021 17:08:13 +0800
+Subject: [PATCH] fix: a problem that REDIRECT must work with port-sharing for
+ intranet
+
+---
+ service/core/v2ray/v2rayTmpl.go | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/core/v2ray/v2rayTmpl.go
++++ b/core/v2ray/v2rayTmpl.go
+@@ -878,6 +878,13 @@ func (t *Template) setDualStack() {
+ if !t.Setting.PortSharing {
+ // copy a group of ipv6 inbounds and set the tag
+ for i := range t.Inbounds {
++ if t.Inbounds[i].Tag == "transparent" && t.Setting.TransparentType == configure.TransparentRedirect {
++ // https://ipset.netfilter.org/iptables-extensions.man.html#lbDK
++ // REDIRECT redirects the packet to the machine itself by changing the destination IP to the primary address of the incoming interface.
++ // So we should listen at 0.0.0.0 instead of 127.0.0.1
++ inbounds6[i].Tag = "THIS_IS_A_DROPPED_TAG"
++ continue
++ }
+ if t.Inbounds[i].Tag == "dns-in" {
+ t.Inbounds[i].Listen = "127.2.0.17"
+ inbounds6[i].Tag = "THIS_IS_A_DROPPED_TAG"