Skip to content

Commit

Permalink
dnsx/summary: exit and base are not actual proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 7, 2023
1 parent 1657718 commit 4a086e3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 94 deletions.
2 changes: 1 addition & 1 deletion intra/dns53/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (t *dot) Query(network string, q []byte, smm *dnsx.Summary) ([]byte, error)
smm.Server = t.GetAddr()
if t.relay != nil {
smm.RelayServer = t.relay.GetAddr()
} else if len(pid) > 0 && pid != dnsx.NetNoProxy {
} else if !dnsx.IsLocalProxy(pid) {
smm.RelayServer = dnsx.SummaryProxyLabel + pid
}
smm.Status = status
Expand Down
2 changes: 1 addition & 1 deletion intra/dns53/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (t *transport) Query(network string, q []byte, smm *dnsx.Summary) (r []byte
smm.Server = t.GetAddr()
if t.relay != nil {
smm.RelayServer = t.relay.GetAddr()
} else if len(pid) > 0 && pid != dnsx.NetNoProxy {
} else if !dnsx.IsLocalProxy(pid) {
smm.RelayServer = dnsx.SummaryProxyLabel + pid
}
smm.Status = status
Expand Down
2 changes: 1 addition & 1 deletion intra/dnscrypt/multiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func resolve(network string, data []byte, si *ServerInfo, smm *dnsx.Summary) (re
if noAnonRelay {
if si.relay != nil {
smm.RelayServer = si.relay.GetAddr()
} else if len(pid) > 0 && pid != dnsx.NetNoProxy {
} else if !dnsx.IsLocalProxy(pid) {
smm.RelayServer = dnsx.SummaryProxyLabel + pid
}
}
Expand Down
184 changes: 94 additions & 90 deletions intra/dnsx/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,96 +654,6 @@ func (r *resolver) accept(c io.ReadWriteCloser) {
// TODO: Cancel outstanding queries.
}

func isReserved(id string) bool {
switch id {
case Default, Goos, System, Local, Alg, DcProxy, BlockAll, Preferred, BlockFree:
return true
case CT + Default, CT + Goos, CT + System, CT + Local, CT + Alg, CT + DcProxy, CT + BlockAll, CT + Preferred, CT + BlockFree:
return true
}
return false
}

func useFallback(id string) bool {
switch id {
case System, Local, Alg, Preferred, BlockFree:
return true
case CT + System, CT + Local, CT + Alg, CT + Preferred, CT + BlockFree:
return true
}
return false
}

func isTransportID(match string, ids ...string) bool {
for _, t := range ids {
if t == match {
return true
}
}
return false
}

func isAnyBlockAll(ids ...string) bool {
return isTransportID(BlockAll, ids...)
}

func isAnyLocal(ids ...string) bool {
return isTransportID(Local, ids...)
}

func overrideProxyIfNeeded(pid string, ids ...string) string {
for _, id := range ids {
switch id {
// note: Goos is anyway hard-coded to use NetExitProxy
case Default, Goos: // exit
return NetExitProxy
case CT + Default, CT + Goos: // exit
return NetExitProxy
case System, Local: // base
return NetNoProxy
case CT + System, CT + Local: // base
return NetNoProxy
}
}
return pid // as-is
}

func skipBlock(tr ...Transport) bool {
for _, t := range tr {
if t == nil {
continue
}
switch t.ID() {
case Default, BlockFree, Alg:
return true
case CT + Default, CT + BlockFree, CT + Alg:
return true
}
}
return false
}

func unpack(q []byte) (*dns.Msg, error) {
msg := &dns.Msg{}
err := msg.Unpack(q)
return msg, err
}

func qname(msg *dns.Msg) string {
n := xdns.QName(msg)
n, _ = xdns.NormalizeQName(n)
return n
}

func qtype(msg *dns.Msg) int {
return int(xdns.QType(msg))
}

func (r *resolver) loadaddrs(csvaddr string) {
r.fakeTcpAddr(csvaddr)
r.fakeUdpAddr(csvaddr)
}

func writeto(w io.Writer, b []byte, l int) (int, error) {
prependsz := 2
rlbuf := make([]byte, l+prependsz)
Expand Down Expand Up @@ -851,6 +761,100 @@ func (r *resolver) preferencesFrom(qname string, s *NsOpts, chosenids ...string)
return
}

func IsLocalProxy(pid string) bool {
return len(pid) <= 0 || pid == NetNoProxy || pid == NetExitProxy
}

func isReserved(id string) bool {
switch id {
case Default, Goos, System, Local, Alg, DcProxy, BlockAll, Preferred, BlockFree:
return true
case CT + Default, CT + Goos, CT + System, CT + Local, CT + Alg, CT + DcProxy, CT + BlockAll, CT + Preferred, CT + BlockFree:
return true
}
return false
}

func useFallback(id string) bool {
switch id {
case System, Local, Alg, Preferred, BlockFree:
return true
case CT + System, CT + Local, CT + Alg, CT + Preferred, CT + BlockFree:
return true
}
return false
}

func isTransportID(match string, ids ...string) bool {
for _, t := range ids {
if t == match {
return true
}
}
return false
}

func isAnyBlockAll(ids ...string) bool {
return isTransportID(BlockAll, ids...)
}

func isAnyLocal(ids ...string) bool {
return isTransportID(Local, ids...)
}

func overrideProxyIfNeeded(pid string, ids ...string) string {
for _, id := range ids {
switch id {
// note: Goos is anyway hard-coded to use NetExitProxy
case Default, Goos: // exit
return NetExitProxy
case CT + Default, CT + Goos: // exit
return NetExitProxy
case System, Local: // base
return NetNoProxy
case CT + System, CT + Local: // base
return NetNoProxy
}
}
return pid // as-is
}

func skipBlock(tr ...Transport) bool {
for _, t := range tr {
if t == nil {
continue
}
switch t.ID() {
case Default, BlockFree, Alg:
return true
case CT + Default, CT + BlockFree, CT + Alg:
return true
}
}
return false
}

func unpack(q []byte) (*dns.Msg, error) {
msg := &dns.Msg{}
err := msg.Unpack(q)
return msg, err
}

func qname(msg *dns.Msg) string {
n := xdns.QName(msg)
n, _ = xdns.NormalizeQName(n)
return n
}

func qtype(msg *dns.Msg) int {
return int(xdns.QType(msg))
}

func (r *resolver) loadaddrs(csvaddr string) {
r.fakeTcpAddr(csvaddr)
r.fakeUdpAddr(csvaddr)
}

func map2csv(ts map[string]Transport) string {
s := ""
for _, t := range ts {
Expand Down
2 changes: 1 addition & 1 deletion intra/doh/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (t *transport) Query(network string, q []byte, smm *dnsx.Summary) (r []byte
if noOdohRelay {
if t.relay != nil {
smm.RelayServer = t.relay.GetAddr()
} else if len(pid) > 0 && pid != dnsx.NetNoProxy {
} else if !dnsx.IsLocalProxy(pid) {
smm.RelayServer = dnsx.SummaryProxyLabel + pid
}
}
Expand Down

0 comments on commit 4a086e3

Please sign in to comment.