feat(amneziawg): support persistent keepalive ranges (#6881)

AmneziaWG clients accept a randomised PersistentKeepalive range such as 15-25,
which makes keepalive timing harder to fingerprint; the panel only stored a
single number. A client's keepalive may now be a range, validated the way
AmneziaWG parses it. The downloadable .conf and vpn:// profile carry the range,
Clash/Mihomo output gets its lower bound, and plain WireGuard stays scalar-only.
The range lives in an additive wg_keep_alive_range column, so the integer
column and an older panel binary keep working after a rollback.
This commit is contained in:
YoungReckless4
2026-10-24 07:36:49 +03:00
committed by GitHub
parent 207c705300
commit 35e09191de
59 changed files with 1871 additions and 146 deletions
+15 -2
View File
@@ -1338,6 +1338,9 @@ func (s *InboundService) AddInbound(inbound *model.Inbound) (*model.Inbound, boo
if err := validateClientsRenewal(clients); err != nil {
return inbound, false, err
}
if err := validateClientsKeepAlive(inbound.Protocol, clients); err != nil {
return inbound, false, err
}
for _, traffic := range inbound.ClientStats {
if err := validateClientRenewal(model.Client{Reset: traffic.Reset, ResetDay: traffic.ResetDay, ResetWeekday: traffic.ResetWeekday}); err != nil {
return inbound, false, err
@@ -1912,7 +1915,7 @@ func (s *InboundService) SetInboundEnable(id int, enable bool) (bool, error) {
return needRestart, nil
}
func (s *InboundService) validateUpdatedInboundClients(inbound *model.Inbound) error {
func (s *InboundService) validateUpdatedInboundClients(inbound, existing *model.Inbound) error {
clients, err := s.GetClients(inbound)
if err != nil {
return err
@@ -1920,6 +1923,16 @@ func (s *InboundService) validateUpdatedInboundClients(inbound *model.Inbound) e
if err := validateClientsRenewal(clients); err != nil {
return err
}
var existingClients []model.Client
if inbound.Protocol == existing.Protocol {
existingClients, err = s.GetClients(existing)
if err != nil {
return err
}
}
if err := validateClientsKeepAliveAgainstExisting(inbound.Protocol, clients, existingClients); err != nil {
return err
}
for _, client := range clients {
switch inbound.Protocol {
case model.Hysteria:
@@ -2038,7 +2051,7 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
inbound.Enable = stored.Enable
}
// On the clients actually saved: a protocol switch keeps the stored ones.
if err := s.validateUpdatedInboundClients(inbound); err != nil {
if err := s.validateUpdatedInboundClients(inbound, stored); err != nil {
return err
}
conflict, cErr := checkPortConflictTx(tx, inbound, inbound.Id)