Pull request 2210: AG-32341-client-duplicate-uids
Squashed commit of the following: commit 6f83ec8a4f0dfb2360912116a48d35d1f7df7f66 Merge: 2fea9c06a2383ab57c
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 26 19:23:15 2024 +0300 Merge branch 'master' into AG-32341-client-duplicate-uids commit 2fea9c06af9a0b349e612620292bc629f514fead Merge: 672a30ce4b9d5e5ba0
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 26 14:00:49 2024 +0300 Merge branch 'master' into AG-32341-client-duplicate-uids commit 672a30ce402f51819d741ea92ec5283eea4e6813 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 26 13:59:59 2024 +0300 all: upd chlog commit 7c2b26e3ece123d67d0377f816003600408b5e94 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 21:08:47 2024 +0300 all: imp chlog commit fcca9afe0cdb3d23e6fc653dd334161cbc6d832a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 18:56:34 2024 +0300 all: fix client duplicate uids
This commit is contained in:
parent
2383ab57c6
commit
c05bce7a3f
|
@ -32,8 +32,16 @@ NOTE: Add new changes BELOW THIS COMMENT.
|
|||
- Private rDNS resolution now also affects `SOA` and `NS` requests ([#6882]).
|
||||
- Rewrite rules mechanics was changed due to improve resolving in safe search.
|
||||
|
||||
### Deprecated
|
||||
|
||||
- Currently, AdGuard Home skips persistent clients that have duplicate fields
|
||||
when reading them from the configuration file. This behaviour is deprecated
|
||||
and will cause errors on startup in a future release.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Acceptance of duplicate UIDs for persistent clients at startup. See also the
|
||||
section on client settings on the [Wiki page][wiki-config].
|
||||
- Domain specifications for top-level domains not considered for requests to
|
||||
unqualified domains ([#6744]).
|
||||
- Support for link-local subnets, i.e. `fe80::/16`, as client identifiers
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/netip"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
)
|
||||
|
||||
// macKey contains MAC as byte array of 6, 8, or 20 bytes.
|
||||
|
@ -82,15 +83,25 @@ func (ci *Index) Add(c *Persistent) {
|
|||
ci.uidToClient[c.UID] = c
|
||||
}
|
||||
|
||||
// ErrDuplicateUID is an error returned by [Index.Clashes] when adding a
|
||||
// persistent client with a UID that already exists in an index.
|
||||
const ErrDuplicateUID errors.Error = "duplicate uid"
|
||||
|
||||
// Clashes returns an error if the index contains a different persistent client
|
||||
// with at least a single identifier contained by c. c must be non-nil.
|
||||
func (ci *Index) Clashes(c *Persistent) (err error) {
|
||||
_, ok := ci.uidToClient[c.UID]
|
||||
if ok {
|
||||
return ErrDuplicateUID
|
||||
}
|
||||
|
||||
for _, id := range c.ClientIDs {
|
||||
existing, ok := ci.clientIDToUID[id]
|
||||
var existing UID
|
||||
existing, ok = ci.clientIDToUID[id]
|
||||
if ok && existing != c.UID {
|
||||
p := ci.uidToClient[existing]
|
||||
|
||||
return fmt.Errorf("another client %q uses the same ID %q", p.Name, id)
|
||||
return fmt.Errorf("another client %q uses the same ClientID %q", p.Name, id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,13 @@ func (clients *clientsContainer) addFromConfig(
|
|||
|
||||
_, err = clients.add(cli)
|
||||
if err != nil {
|
||||
log.Error("clients: adding client at index %d %s: %s", i, cli.Name, err)
|
||||
if errors.Is(err, client.ErrDuplicateUID) {
|
||||
return fmt.Errorf("clients: adding client %s at index %d: %w", cli.Name, i, err)
|
||||
}
|
||||
|
||||
// TODO(s.chzhen): Return an error instead of logging if more
|
||||
// stringent requirements are implemented.
|
||||
log.Error("clients: adding client %s at index %d: %s", cli.Name, i, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue