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

@@ -16,10 +16,11 @@ func newHandler(ctx context.Context, logger infoWarner, logging bool,
updaterLooper UpdaterLooper,
publicIPLooper PublicIPLoop,
storage Storage,
ipv6Supported bool,
) http.Handler {
handler := &handler{}
vpn := newVPNHandler(ctx, vpnLooper, storage, logger)
vpn := newVPNHandler(ctx, vpnLooper, storage, ipv6Supported, logger)
openvpn := newOpenvpnHandler(ctx, vpnLooper, pfGetter, logger)
dns := newDNSHandler(ctx, unboundLooper, logger)
updater := newUpdaterHandler(ctx, updaterLooper, logger)

View File

@@ -11,10 +11,12 @@ import (
func New(ctx context.Context, address string, logEnabled bool, logger Logger,
buildInfo models.BuildInformation, openvpnLooper VPNLooper,
pfGetter PortForwardedGetter, unboundLooper DNSLoop,
updaterLooper UpdaterLooper, publicIPLooper PublicIPLoop, storage Storage) (
updaterLooper UpdaterLooper, publicIPLooper PublicIPLoop, storage Storage,
ipv6Supported bool) (
server *httpserver.Server, err error) {
handler := newHandler(ctx, logger, logEnabled, buildInfo,
openvpnLooper, pfGetter, unboundLooper, updaterLooper, publicIPLooper, storage)
openvpnLooper, pfGetter, unboundLooper, updaterLooper, publicIPLooper,
storage, ipv6Supported)
httpServerSettings := httpserver.Settings{
Address: address,

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