forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b27547e
commit 08bb7d4
Showing
5 changed files
with
121 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dnsforward | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet" | ||
"github.com/AdguardTeam/dnsproxy/proxy" | ||
"github.com/AdguardTeam/golibs/log" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
// type check | ||
var _ proxy.BeforeRequestHandler = (*Server)(nil) | ||
|
||
// HandleBefore is the handler that is called before any other processing, | ||
// including logs. It performs access checks and puts the client ID, if there | ||
// is one, into the server's cache. | ||
// | ||
// TODO(e.burkov): Write tests. | ||
func (s *Server) HandleBefore( | ||
_ *proxy.Proxy, | ||
pctx *proxy.DNSContext, | ||
) (err error) { | ||
clientID, err := s.clientIDFromDNSContext(pctx) | ||
if err != nil { | ||
return fmt.Errorf("getting clientid: %w", err) | ||
} | ||
|
||
blocked, _ := s.IsBlockedClient(pctx.Addr.Addr(), clientID) | ||
if blocked { | ||
return s.preBlockedResponse(pctx) | ||
} | ||
|
||
if len(pctx.Req.Question) == 1 { | ||
q := pctx.Req.Question[0] | ||
qt := q.Qtype | ||
host := aghnet.NormalizeDomain(q.Name) | ||
if s.access.isBlockedHost(host, qt) { | ||
log.Debug("access: request %s %s is in access blocklist", dns.Type(qt), host) | ||
|
||
return s.preBlockedResponse(pctx) | ||
} | ||
} | ||
|
||
if clientID != "" { | ||
key := [8]byte{} | ||
binary.BigEndian.PutUint64(key[:], pctx.RequestID) | ||
s.clientIDCache.Set(key[:], []byte(clientID)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters