mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Add dns and tunnel context to conntection
This commit is contained in:
parent
a085b6d430
commit
ff31b7c8c5
5 changed files with 31 additions and 8 deletions
|
@ -264,8 +264,9 @@ func UpdateIPsAndCNAMEs(q *resolver.Query, rrCache *resolver.RRCache, conn *netw
|
||||||
// Create new record for this IP.
|
// Create new record for this IP.
|
||||||
record := resolver.ResolvedDomain{
|
record := resolver.ResolvedDomain{
|
||||||
Domain: q.FQDN,
|
Domain: q.FQDN,
|
||||||
Expires: rrCache.Expires,
|
RRCache: rrCache,
|
||||||
Resolver: rrCache.Resolver,
|
Resolver: rrCache.Resolver,
|
||||||
|
Expires: rrCache.Expires,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve all CNAMEs in the correct order and add the to the record.
|
// Resolve all CNAMEs in the correct order and add the to the record.
|
||||||
|
|
|
@ -222,17 +222,27 @@ func handleRequest(ctx context.Context, w dns.ResponseWriter, request *dns.Msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Handle special cases.
|
// Handle special cases.
|
||||||
switch {
|
if rrCache == nil {
|
||||||
case rrCache == nil:
|
|
||||||
tracer.Warning("nameserver: received successful, but empty reply from resolver")
|
tracer.Warning("nameserver: received successful, but empty reply from resolver")
|
||||||
return reply(nsutil.ServerFailure("internal error: empty reply"))
|
return reply(nsutil.ServerFailure("internal error: empty reply"))
|
||||||
case rrCache.RCode == dns.RcodeNameError:
|
}
|
||||||
|
|
||||||
|
// Add dns context and resolver to connection.
|
||||||
|
conn.DNSContext = rrCache
|
||||||
|
conn.Resolver = rrCache.Resolver
|
||||||
|
|
||||||
|
// Return now if NXDomain.
|
||||||
|
if rrCache.RCode == dns.RcodeNameError {
|
||||||
return reply(nsutil.NxDomain("no answer found (NXDomain)"))
|
return reply(nsutil.NxDomain("no answer found (NXDomain)"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tracer.Trace("nameserver: deciding on resolved dns")
|
tracer.Trace("nameserver: deciding on resolved dns")
|
||||||
rrCache = firewall.FilterResolvedDNS(ctx, conn, q, rrCache)
|
rrCache = firewall.FilterResolvedDNS(ctx, conn, q, rrCache)
|
||||||
|
|
||||||
|
// Add dns context and resolver to connection.
|
||||||
|
conn.DNSContext = rrCache
|
||||||
|
conn.Resolver = rrCache.Resolver
|
||||||
|
|
||||||
// Check again if there is a responder from the firewall.
|
// Check again if there is a responder from the firewall.
|
||||||
if responder, ok := conn.Reason.Context.(nsutil.Responder); ok {
|
if responder, ok := conn.Reason.Context.(nsutil.Responder); ok {
|
||||||
tracer.Infof("nameserver: handing over request for %s to special filter responder: %s", q.ID(), conn.Reason.Msg)
|
tracer.Infof("nameserver: handing over request for %s to special filter responder: %s", q.ID(), conn.Reason.Msg)
|
||||||
|
|
|
@ -143,6 +143,12 @@ type Connection struct { //nolint:maligned // TODO: fix alignment
|
||||||
// that iniated the connection. It is set once when the connection
|
// that iniated the connection. It is set once when the connection
|
||||||
// object is created and is considered immutable afterwards.
|
// object is created and is considered immutable afterwards.
|
||||||
ProcessContext ProcessContext
|
ProcessContext ProcessContext
|
||||||
|
// DNSContext holds additional information about the DNS request that was
|
||||||
|
// probably used to resolve the IP of this connection.
|
||||||
|
DNSContext *resolver.RRCache
|
||||||
|
// TunnelContext holds additional information about the tunnel that this
|
||||||
|
// connection is using.
|
||||||
|
TunnelContext interface{}
|
||||||
// Internal is set to true if the connection is attributed as an
|
// Internal is set to true if the connection is attributed as an
|
||||||
// Portmaster internal connection. Internal may be set at different
|
// Portmaster internal connection. Internal may be set at different
|
||||||
// points and access to it must be guarded by the connection lock.
|
// points and access to it must be guarded by the connection lock.
|
||||||
|
@ -327,6 +333,7 @@ func NewConnectionFromFirstPacket(pkt packet.Packet) *Connection {
|
||||||
|
|
||||||
var scope string
|
var scope string
|
||||||
var resolverInfo *resolver.ResolverInfo
|
var resolverInfo *resolver.ResolverInfo
|
||||||
|
var dnsContext *resolver.RRCache
|
||||||
|
|
||||||
if inbound {
|
if inbound {
|
||||||
|
|
||||||
|
@ -358,6 +365,7 @@ func NewConnectionFromFirstPacket(pkt packet.Packet) *Connection {
|
||||||
scope = lastResolvedDomain.Domain
|
scope = lastResolvedDomain.Domain
|
||||||
entity.Domain = lastResolvedDomain.Domain
|
entity.Domain = lastResolvedDomain.Domain
|
||||||
entity.CNAME = lastResolvedDomain.CNAMEs
|
entity.CNAME = lastResolvedDomain.CNAMEs
|
||||||
|
dnsContext = lastResolvedDomain.RRCache
|
||||||
resolverInfo = lastResolvedDomain.Resolver
|
resolverInfo = lastResolvedDomain.Resolver
|
||||||
removeOpenDNSRequest(proc.Pid, lastResolvedDomain.Domain)
|
removeOpenDNSRequest(proc.Pid, lastResolvedDomain.Domain)
|
||||||
}
|
}
|
||||||
|
@ -401,6 +409,7 @@ func NewConnectionFromFirstPacket(pkt packet.Packet) *Connection {
|
||||||
IPProtocol: pkt.Info().Protocol,
|
IPProtocol: pkt.Info().Protocol,
|
||||||
LocalPort: pkt.Info().LocalPort(),
|
LocalPort: pkt.Info().LocalPort(),
|
||||||
ProcessContext: getProcessContext(pkt.Ctx(), proc),
|
ProcessContext: getProcessContext(pkt.Ctx(), proc),
|
||||||
|
DNSContext: dnsContext,
|
||||||
process: proc,
|
process: proc,
|
||||||
// remote endpoint
|
// remote endpoint
|
||||||
Entity: entity,
|
Entity: entity,
|
||||||
|
|
|
@ -44,6 +44,9 @@ type ResolvedDomain struct {
|
||||||
// information.
|
// information.
|
||||||
Resolver *ResolverInfo
|
Resolver *ResolverInfo
|
||||||
|
|
||||||
|
// RRCache holds the DNS response that was received for this domain.
|
||||||
|
RRCache *RRCache
|
||||||
|
|
||||||
// Expires holds the timestamp when this entry expires.
|
// Expires holds the timestamp when this entry expires.
|
||||||
// This does not mean that the entry may not be used anymore afterwards,
|
// This does not mean that the entry may not be used anymore afterwards,
|
||||||
// but that this is used to calcuate the TTL of the database record.
|
// but that this is used to calcuate the TTL of the database record.
|
||||||
|
|
|
@ -24,13 +24,13 @@ type RRCache struct {
|
||||||
RCode int
|
RCode int
|
||||||
|
|
||||||
// Response Content
|
// Response Content
|
||||||
Answer []dns.RR
|
Answer []dns.RR `json:"-"`
|
||||||
Ns []dns.RR
|
Ns []dns.RR `json:"-"`
|
||||||
Extra []dns.RR
|
Extra []dns.RR `json:"-"`
|
||||||
Expires int64
|
Expires int64
|
||||||
|
|
||||||
// Resolver Information
|
// Resolver Information
|
||||||
Resolver *ResolverInfo
|
Resolver *ResolverInfo `json:"-"`
|
||||||
|
|
||||||
// Metadata about the request and handling
|
// Metadata about the request and handling
|
||||||
ServedFromCache bool
|
ServedFromCache bool
|
||||||
|
|
Loading…
Add table
Reference in a new issue