mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
Unify dns log
This commit is contained in:
parent
2b46178ff9
commit
5e323958b6
6 changed files with 42 additions and 31 deletions
|
@ -1,13 +1,17 @@
|
|||
package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
"github.com/xtls/xray-core/core"
|
||||
dns_feature "github.com/xtls/xray-core/features/dns"
|
||||
"golang.org/x/net/dns/dnsmessage"
|
||||
)
|
||||
|
@ -225,3 +229,19 @@ L:
|
|||
|
||||
return ipRecord, nil
|
||||
}
|
||||
|
||||
// toDnsContext create a new background context with parent inbound, session and dns log
|
||||
func toDnsContext(ctx context.Context, addr string) context.Context {
|
||||
dnsCtx := core.ToBackgroundDetachedContext(ctx)
|
||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||
dnsCtx = session.ContextWithInbound(dnsCtx, inbound)
|
||||
}
|
||||
dnsCtx = session.ContextWithContent(dnsCtx, session.ContentFromContext(ctx))
|
||||
dnsCtx = log.ContextWithAccessMessage(dnsCtx, &log.AccessMessage{
|
||||
From: "DNS",
|
||||
To: addr,
|
||||
Status: log.AccessAccepted,
|
||||
Reason: "",
|
||||
})
|
||||
return dnsCtx
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue