fix(settings): validate Wireguard addresses depending on IPv6 support

This commit is contained in:
Quentin McGaw
2022-12-14 11:29:40 +00:00
parent 16acd1b162
commit f70f0aca9c
9 changed files with 44 additions and 31 deletions

View File

@@ -10,20 +10,22 @@ import (
)
func newVPNHandler(ctx context.Context, looper VPNLooper,
storage Storage, w warner) http.Handler {
storage Storage, ipv6Supported bool, w warner) http.Handler {
return &vpnHandler{
ctx: ctx,
looper: looper,
storage: storage,
warner: w,
ctx: ctx,
looper: looper,
storage: storage,
ipv6Supported: ipv6Supported,
warner: w,
}
}
type vpnHandler struct {
ctx context.Context //nolint:containedctx
looper VPNLooper
storage Storage
warner warner
ctx context.Context //nolint:containedctx
looper VPNLooper
storage Storage
ipv6Supported bool
warner warner
}
func (h *vpnHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -114,7 +116,7 @@ func (h *vpnHandler) patchSettings(w http.ResponseWriter, r *http.Request) {
updatedSettings := h.looper.GetSettings() // already copied
updatedSettings.OverrideWith(overrideSettings)
err = updatedSettings.Validate(h.storage)
err = updatedSettings.Validate(h.storage, h.ipv6Supported)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return