docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
// ErrPermission may happen here on Linux systems where // AdGuard Home is installed using Snap. That doesn't // necessarily mean that the machine doesn't have // a static IP, so we can assume that it has and go on. // If the machine doesn't, we'll get an error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. // // TODO(a.garipov): I was thinking about moving this // into IfaceHasStaticIP, but then we wouldn't be able // to log it. Think about it more.
<mask> var hasStaticIP bool <mask> hasStaticIP, err = sysutil.IfaceHasStaticIP(ifaceName) <mask> if err != nil { <mask> if errors.Is(err, os.ErrPermission) { <mask> log.Info("error while checking static ip: %s; "+ <mask> "assuming machine has static ip and going on", err) <mask> hasStaticIP = true <mask> } else if errors.Is(err, sysutil.ErrNoStaticIPInfo) { <mask> // Couldn't obtain a definitive answer. Assume static </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/dhcpd/http.go
} else if errors.Is(err, sysutil.ErrNoStaticIPInfo) { // Couldn't obtain a definitive answer. Assume static // IP an go on. log.Info("can't check for static ip; " + "assuming machine has static ip and going on") hasStaticIP = true
<mask> log.Info("error while checking static ip: %s; "+ <mask> "assuming machine has static ip and going on", err) <mask> hasStaticIP = true <mask> } else { <mask> err = fmt.Errorf("checking static ip: %w", err) <mask> <mask> return http.StatusInternalServerError, err <mask> } </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err </s> remove if has || err != nil { break </s> add if err != nil { return false, err
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/dhcpd/http.go
err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err
<mask> log.Info("error while checking static ip: %s; "+ <mask> "assuming machine has static ip and going on", err) <mask> hasStaticIP = true <mask> } else { <mask> return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) <mask> } <mask> } <mask> <mask> if !hasStaticIP { <mask> err = sysutil.IfaceSetStaticIP(ifaceName) </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add </s> remove if has || err != nil { break </s> add if err != nil { return false, err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/dhcpd/http.go
err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err
<mask> <mask> if !hasStaticIP { <mask> err = sysutil.IfaceSetStaticIP(ifaceName) <mask> if err != nil { <mask> return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) <mask> } <mask> } <mask> <mask> err = s.Start() <mask> if err != nil { </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err </s> remove if has || err != nil { break </s> add if err != nil { return false, err
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/dhcpd/http.go
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
<mask> "os/exec" <mask> "strings" <mask> <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> // ErrNoStaticIPInfo is returned by IfaceHasStaticIP when no information about </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return has, err </s> add return false, ErrNoStaticIPInfo
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net.go
// ErrNoStaticIPInfo is returned by IfaceHasStaticIP when no information about // the IP being static is available. const ErrNoStaticIPInfo agherr.Error = "no information about static ip"
<mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> // IfaceHasStaticIP checks if interface is configured to have static IP address. <mask> // If it can't give a definitive answer, it returns false and an error for which <mask> // errors.Is(err, ErrNoStaticIPInfo) is true. <mask> func IfaceHasStaticIP(ifaceName string) (has bool, err error) { <mask> return ifaceHasStaticIP(ifaceName) <mask> } </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return has, err </s> add return false, ErrNoStaticIPInfo </s> remove var f *os.File </s> add // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net.go
// If it can't give a definitive answer, it returns false and an error for which // errors.Is(err, ErrNoStaticIPInfo) is true.
<mask> // the IP being static is available. <mask> const ErrNoStaticIPInfo agherr.Error = "no information about static ip" <mask> <mask> // IfaceHasStaticIP checks if interface is configured to have static IP address. <mask> func IfaceHasStaticIP(ifaceName string) (has bool, err error) { <mask> return ifaceHasStaticIP(ifaceName) <mask> } <mask> </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return has, err </s> add return false, ErrNoStaticIPInfo </s> remove var f *os.File </s> add // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net.go
// TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior.
<mask> // maxConfigFileSize is the maximum length of interfaces configuration file. <mask> const maxConfigFileSize = 1024 * 1024 <mask> <mask> func ifaceHasStaticIP(ifaceName string) (has bool, err error) { <mask> var f *os.File <mask> for _, check := range []struct { <mask> checker func(io.Reader, string) (bool, error) <mask> filePath string <mask> }{{ <mask> checker: dhcpcdStaticConfig, </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return has, err </s> add return false, ErrNoStaticIPInfo
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
var f *os.File
<mask> }, { <mask> checker: ifacesStaticConfig, <mask> filePath: "/etc/network/interfaces", <mask> }} { <mask> f, err = os.Open(check.filePath) <mask> if err != nil { <mask> // ErrNotExist can happen here if there is no such file. <mask> // This is normal, as not every system uses those files. <mask> if errors.Is(err, os.ErrNotExist) { <mask> err = nil </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove var f *os.File </s> add // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior. </s> remove // ErrPermission may happen here on Linux systems where AdGuard // Home is installed using Snap. That doesn't necessarily mean // that the machine doesn't have a static IP, so we can assume // that it has and go on. If the machine doesn't, we'll get an // error later. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. </s> add </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
// ErrNotExist can happen here if there is no such file. // This is normal, as not every system uses those files.
<mask> }} { <mask> var f *os.File <mask> f, err = os.Open(check.filePath) <mask> if err != nil { <mask> if errors.Is(err, os.ErrNotExist) { <mask> err = nil <mask> <mask> continue <mask> } <mask> </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err </s> remove if has || err != nil { break </s> add if err != nil { return false, err </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
if err != nil { return false, err
<mask> } <mask> defer fileReadCloser.Close() <mask> <mask> has, err = check.checker(fileReadCloser, ifaceName) <mask> if has || err != nil { <mask> break <mask> } <mask> } <mask> <mask> return has, err <mask> } </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove return has, err </s> add return false, ErrNoStaticIPInfo </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
return has, nil
<mask> has, err = check.checker(fileReadCloser, ifaceName) <mask> if err != nil { <mask> return false, err <mask> } <mask> } <mask> <mask> return false, ErrNoStaticIPInfo <mask> } </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove if has || err != nil { break </s> add if err != nil { return false, err </s> remove return has, err </s> add return false, ErrNoStaticIPInfo </s> remove return http.StatusInternalServerError, fmt.Errorf("setting static ip: %w", err) </s> add err = fmt.Errorf("setting static ip: %w", err) return http.StatusInternalServerError, err </s> remove return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) </s> add err = fmt.Errorf("checking static ip: %w", err) return http.StatusInternalServerError, err
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
return false, ErrNoStaticIPInfo
<mask> break <mask> } <mask> } <mask> <mask> return has, err <mask> } <mask> <mask> // dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to <mask> // have a static IP. <mask> func dhcpcdStaticConfig(r io.Reader, ifaceName string) (has bool, err error) { </s> Pull request: all: fix statip ip ck Merge in DNS/adguard-home from fix-static-ip-check to master Squashed commit of the following: commit af365c106f3d620afc77492a06f5368611328f5f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:55:35 2021 +0300 all: doc changes commit 922afb262458fc488e03cad232430d90c504f2f3 Merge: 43fec5fb dbcc55f5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:53:31 2021 +0300 Merge branch 'master' into fix-static-ip-check commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Feb 15 18:37:16 2021 +0300 all: fix statip ip ck </s> remove if has || err != nil { break </s> add if err != nil { return false, err </s> remove var f *os.File </s> add // TODO(a.garipov): Currently, this function returns the first // definitive result. So if /etc/dhcpcd.conf has a static IP while // /etc/network/interfaces doesn't, it will return true. Perhaps this // is not the most desirable behavior.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f68f6c9b37cea1f33cb6fa791e6678b9df3a237b
internal/sysutil/net_linux.go
"net"
<mask> "fmt" <mask> "io/ioutil" <mask> "log" <mask> "net/http" <mask> "os" <mask> "strconv" <mask> "strings" <mask> "time" </s> Use dnsforward for checking if upstream DNS server is working. </s> remove "github.com/AdguardTeam/AdGuardHome/upstream" </s> add "github.com/miekg/dns" </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) } </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
"github.com/miekg/dns"
<mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dnsforward" <mask> "github.com/AdguardTeam/AdGuardHome/upstream" <mask> <mask> "gopkg.in/asaskevich/govalidator.v4" <mask> ) <mask> <mask> const updatePeriod = time.Minute * 30 </s> Use dnsforward for checking if upstream DNS server is working. </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) } </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input)
<mask> } <mask> } <mask> <mask> func checkDNS(input string) error { <mask> u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) <mask> <mask> if err != nil { <mask> return err <mask> } <mask> defer u.Close() <mask> </s> Use dnsforward for checking if upstream DNS server is working. </s> remove return err </s> add return fmt.Errorf("Failed to choose upstream for %s: %s", input, err) </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
return fmt.Errorf("Failed to choose upstream for %s: %s", input, err)
<mask> func checkDNS(input string) error { <mask> u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) <mask> <mask> if err != nil { <mask> return err <mask> } <mask> defer u.Close() <mask> <mask> alive, err := upstream.IsAlive(u) <mask> </s> Use dnsforward for checking if upstream DNS server is working. </s> remove u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) </s> add log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input) </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
<mask> <mask> if err != nil { <mask> return err <mask> } <mask> defer u.Close() <mask> <mask> alive, err := upstream.IsAlive(u) <mask> <mask> if err != nil { <mask> return fmt.Errorf("couldn't communicate with DNS server %s: %s", input, err) <mask> } <mask> </s> Use dnsforward for checking if upstream DNS server is working. </s> remove return err </s> add return fmt.Errorf("Failed to choose upstream for %s: %s", input, err) </s> remove u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) </s> add log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input) </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
req := dns.Msg{} req.Id = dns.Id() req.RecursionDesired = true req.Question = []dns.Question{ {Name: "google-public-dns-a.google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET}, } reply, err := u.Exchange(&req)
<mask> return fmt.Errorf("Failed to choose upstream for %s: %s", input, err) <mask> } <mask> <mask> if err != nil { <mask> return fmt.Errorf("couldn't communicate with DNS server %s: %s", input, err) <mask> } <mask> if len(reply.Answer) != 1 { <mask> return fmt.Errorf("DNS server %s returned wrong answer", input) </s> Use dnsforward for checking if upstream DNS server is working. </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) } </s> remove return err </s> add return fmt.Errorf("Failed to choose upstream for %s: %s", input, err) </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add </s> remove u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) </s> add log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) }
<mask> <mask> if err != nil { <mask> return fmt.Errorf("couldn't communicate with DNS server %s: %s", input, err) <mask> } <mask> <mask> if !alive { <mask> return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) <mask> } <mask> <mask> return nil <mask> } <mask> </s> Use dnsforward for checking if upstream DNS server is working. </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add </s> remove u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) </s> add log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input) </s> remove return err </s> add return fmt.Errorf("Failed to choose upstream for %s: %s", input, err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
log.Printf("DNS %s works OK", input)
<mask> } <mask> <mask> return nil <mask> } <mask> <mask> func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) { <mask> now := time.Now() </s> Use dnsforward for checking if upstream DNS server is working. </s> remove u, err := upstream.NewUpstream(input, config.CoreDNS.BootstrapDNS) </s> add log.Printf("Checking if DNS %s works...", input) u, err := dnsforward.GetUpstream(input) </s> remove return err </s> add return fmt.Errorf("Failed to choose upstream for %s: %s", input, err) </s> remove defer u.Close() alive, err := upstream.IsAlive(u) </s> add </s> remove if !alive { return fmt.Errorf("DNS server has not passed the healthcheck: %s", input) </s> add if len(reply.Answer) != 1 { return fmt.Errorf("DNS server %s returned wrong answer", input) } if t, ok := reply.Answer[0].(*dns.A); ok { if !net.IPv4(8, 8, 8, 8).Equal(t.A) { return fmt.Errorf("DNS server %s returned wrong answer: %v", input, t.A) }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f6942213c8c57f5721512fb220cd553415237df6
control.go
if clientExists(ip) { return } // add IP to rdnsIP, if not exists dnsctx.rdnsLock.Lock() defer dnsctx.rdnsLock.Unlock() _, ok := dnsctx.rdnsIP[ip] if ok { return } dnsctx.rdnsIP[ip] = true
<mask> } <mask> <mask> func beginAsyncRDNS(ip string) { <mask> log.Tracef("Adding %s for rDNS resolve", ip) <mask> select { <mask> case dnsctx.rdnsChannel <- ip: <mask> // <mask> default: </s> + dns: resolve hosts via rDNS for the top clients after the server has been started </s> remove if clientExists(ip) { return } // add IP to rdnsIP, if not exists dnsctx.rdnsLock.Lock() defer dnsctx.rdnsLock.Unlock() _, ok := dnsctx.rdnsIP[ip] if ok { return } dnsctx.rdnsIP[ip] = true </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f7150e6a19bfc5643fef4106bd068f6ba099f8e2
dns.go
<mask> <mask> func onDNSRequest(d *proxy.DNSContext) { <mask> if d.Req.Question[0].Qtype == dns.TypeA { <mask> ip, _, _ := net.SplitHostPort(d.Addr.String()) <mask> if clientExists(ip) { <mask> return <mask> } <mask> <mask> // add IP to rdnsIP, if not exists <mask> dnsctx.rdnsLock.Lock() <mask> defer dnsctx.rdnsLock.Unlock() <mask> _, ok := dnsctx.rdnsIP[ip] <mask> if ok { <mask> return <mask> } <mask> dnsctx.rdnsIP[ip] = true <mask> <mask> beginAsyncRDNS(ip) <mask> } <mask> } <mask> <mask> func generateServerConfig() dnsforward.ServerConfig { </s> + dns: resolve hosts via rDNS for the top clients after the server has been started
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f7150e6a19bfc5643fef4106bd068f6ba099f8e2
dns.go
top := dnsServer.GetStatsTop() for k := range top.Clients { beginAsyncRDNS(k) }
<mask> if err != nil { <mask> return errorx.Decorate(err, "Couldn't start forwarding DNS server") <mask> } <mask> <mask> return nil <mask> } <mask> <mask> func reconfigureDNSServer() error { <mask> if !isRunning() { </s> + dns: resolve hosts via rDNS for the top clients after the server has been started </s> remove if clientExists(ip) { return } // add IP to rdnsIP, if not exists dnsctx.rdnsLock.Lock() defer dnsctx.rdnsLock.Unlock() _, ok := dnsctx.rdnsIP[ip] if ok { return } dnsctx.rdnsIP[ip] = true </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f7150e6a19bfc5643fef4106bd068f6ba099f8e2
dns.go
<mask> // <mask> // See https://stackoverflow.com/a/32294443/1892060. <mask> const maxDomainNameLen = 253 <mask> <mask> const invalidCharMsg = "invalid char %q at index %d in %q" <mask> <mask> // ValidateDomainNameLabel returns an error if label is not a valid label of <mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> l := len(label) <mask> if l > maxDomainLabelLen { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err)) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
defer agherr.Annotate("validating label %q: %w", &err, label)
<mask> <mask> // ValidateDomainNameLabel returns an error if label is not a valid label of <mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> l := len(label) <mask> if l > maxDomainLabelLen { <mask> return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) <mask> } else if l == 0 { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove const invalidCharMsg = "invalid char %q at index %d in %q" </s> add </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err)) </s> remove return fmt.Errorf("%q is too long, max: %d", name, maxDomainNameLen) </s> add return fmt.Errorf("too long, max: %d", maxDomainNameLen) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen)
<mask> // a domain name. <mask> func ValidateDomainNameLabel(label string) (err error) { <mask> l := len(label) <mask> if l > maxDomainLabelLen { <mask> return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) <mask> } else if l == 0 { <mask> return agherr.Error("label is empty") <mask> } <mask> <mask> if r := label[0]; !IsValidHostOuterRune(rune(r)) { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf("%q is too long, max: %d", name, maxDomainNameLen) </s> add return fmt.Errorf("too long, max: %d", maxDomainNameLen) </s> remove return fmt.Errorf(invalidCharMsg, r, 0, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, 0) </s> remove const invalidCharMsg = "invalid char %q at index %d in %q" </s> add </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
return fmt.Errorf("invalid char %q at index %d", r, 0)
<mask> return agherr.Error("label is empty") <mask> } <mask> <mask> if r := label[0]; !IsValidHostOuterRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, 0, label) <mask> } else if l == 1 { <mask> return nil <mask> } <mask> <mask> for i, r := range label[1 : l-1] { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf(invalidCharMsg, r, i+1, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, i+1) </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove return fmt.Errorf(invalidCharMsg, r, l-1, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, l-1) </s> remove return fmt.Errorf("%q is too long, max: %d", name, maxDomainNameLen) </s> add return fmt.Errorf("too long, max: %d", maxDomainNameLen) </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
return fmt.Errorf("invalid char %q at index %d", r, i+1)
<mask> } <mask> <mask> for i, r := range label[1 : l-1] { <mask> if !isValidHostRune(r) { <mask> return fmt.Errorf(invalidCharMsg, r, i+1, label) <mask> } <mask> } <mask> <mask> if r := label[l-1]; !IsValidHostOuterRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, l-1, label) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf(invalidCharMsg, r, 0, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, 0) </s> remove return fmt.Errorf(invalidCharMsg, r, l-1, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, l-1) </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
return fmt.Errorf("invalid char %q at index %d", r, l-1)
<mask> } <mask> } <mask> <mask> if r := label[l-1]; !IsValidHostOuterRune(rune(r)) { <mask> return fmt.Errorf(invalidCharMsg, r, l-1, label) <mask> } <mask> <mask> return nil <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf(invalidCharMsg, r, i+1, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, i+1) </s> remove return fmt.Errorf(invalidCharMsg, r, 0, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, 0) </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
defer agherr.Annotate("validating domain name %q: %w", &err, name)
<mask> // TODO(a.garipov): After making sure that this works correctly, port this into <mask> // module golibs. <mask> func ValidateDomainName(name string) (err error) { <mask> name, err = idna.ToASCII(name) <mask> if err != nil { <mask> return err <mask> } </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err)) </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
return fmt.Errorf("too long, max: %d", maxDomainNameLen)
<mask> l := len(name) <mask> if l == 0 { <mask> return agherr.Error("domain name is empty") <mask> } else if l > maxDomainNameLen { <mask> return fmt.Errorf("%q is too long, max: %d", name, maxDomainNameLen) <mask> } <mask> <mask> labels := strings.Split(name, ".") <mask> for i, l := range labels { <mask> err = ValidateDomainNameLabel(l) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf("%q is too long, max: %d", label, maxDomainLabelLen) </s> add return fmt.Errorf("label is too long, max: %d", maxDomainLabelLen) </s> remove return fmt.Errorf(invalidCharMsg, r, 0, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, 0) </s> remove return fmt.Errorf(invalidCharMsg, r, i+1, label) </s> add return fmt.Errorf("invalid char %q at index %d", r, i+1) </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr.go
wantErrMsg: `validating domain name "": domain name is empty`,
<mask> wantErrMsg: "", <mask> }, { <mask> name: "empty", <mask> in: "", <mask> wantErrMsg: `domain name is empty`, <mask> }, { <mask> name: "bad_symbol", <mask> in: "!!!", <mask> wantErrMsg: `invalid domain name label at index 0: ` + <mask> `invalid char '!' at index 0 in "!!!"`, </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`, </s> add wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`, </s> remove wantErrMsg: `local domain: invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `local domain: validating domain name "!!!": ` + `invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`,
<mask> wantErrMsg: `domain name is empty`, <mask> }, { <mask> name: "bad_symbol", <mask> in: "!!!", <mask> wantErrMsg: `invalid domain name label at index 0: ` + <mask> `invalid char '!' at index 0 in "!!!"`, <mask> }, { <mask> name: "bad_length", <mask> in: longDomainName, <mask> wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, <mask> }, { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, </s> add wantErrMsg: `validating domain name "` + longDomainName + `": too long, max: 253`, </s> remove wantErrMsg: `domain name is empty`, </s> add wantErrMsg: `validating domain name "": domain name is empty`, </s> remove wantErrMsg: `invalid domain name label at index 0: "` + longLabel + `" is too long, max: 63`, </s> add wantErrMsg: `validating domain name "` + longLabelDomainName + `": ` + `invalid domain name label at index 0: validating label "` + longLabel + `": label is too long, max: 63`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "` + longDomainName + `": too long, max: 253`,
<mask> `invalid char '!' at index 0 in "!!!"`, <mask> }, { <mask> name: "bad_length", <mask> in: longDomainName, <mask> wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, <mask> }, { <mask> name: "bad_label_length", <mask> in: longLabelDomainName, <mask> wantErrMsg: `invalid domain name label at index 0: "` + longLabel + <mask> `" is too long, max: 63`, </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 0: "` + longLabel + `" is too long, max: 63`, </s> add wantErrMsg: `validating domain name "` + longLabelDomainName + `": ` + `invalid domain name label at index 0: validating label "` + longLabel + `": label is too long, max: 63`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `domain name is empty`, </s> add wantErrMsg: `validating domain name "": domain name is empty`, </s> remove wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`, </s> add wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`,
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "` + longLabelDomainName + `": ` + `invalid domain name label at index 0: validating label "` + longLabel + `": label is too long, max: 63`,
<mask> wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, <mask> }, { <mask> name: "bad_label_length", <mask> in: longLabelDomainName, <mask> wantErrMsg: `invalid domain name label at index 0: "` + longLabel + <mask> `" is too long, max: 63`, <mask> }, { <mask> name: "bad_label_empty", <mask> in: "example..com", <mask> wantErrMsg: `invalid domain name label at index 1: label is empty`, <mask> }, { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, </s> add wantErrMsg: `validating domain name "` + longDomainName + `": too long, max: 253`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`, </s> remove wantErrMsg: `domain name is empty`, </s> add wantErrMsg: `validating domain name "": domain name is empty`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`,
<mask> in: longLabelDomainName, <mask> wantErrMsg: `invalid domain name label at index 0: "` + longLabel + <mask> `" is too long, max: 63`, <mask> }, { <mask> name: "bad_label_empty", <mask> in: "example..com", <mask> wantErrMsg: `invalid domain name label at index 1: label is empty`, <mask> }, { <mask> name: "bad_label_first_symbol", <mask> in: "example.-aa.com", <mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '-' at index 0 in "-aa"`, </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 0: "` + longLabel + `" is too long, max: 63`, </s> add wantErrMsg: `validating domain name "` + longLabelDomainName + `": ` + `invalid domain name label at index 0: validating label "` + longLabel + `": label is too long, max: 63`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`, </s> remove wantErrMsg: `"` + longDomainName + `" is too long, max: 253`, </s> add wantErrMsg: `validating domain name "` + longDomainName + `": too long, max: 253`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`, </s> add wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`,
<mask> wantErrMsg: `invalid domain name label at index 1: label is empty`, <mask> }, { <mask> name: "bad_label_first_symbol", <mask> in: "example.-aa.com", <mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '-' at index 0 in "-aa"`, <mask> }, { <mask> name: "bad_label_last_symbol", <mask> in: "example-.aa.com", <mask> wantErrMsg: `invalid domain name label at index 0:` + <mask> ` invalid char '-' at index 7 in "example-"`, </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`, </s> add wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '!' at index 1 in "a!!!"`, </s> add wantErrMsg: `validating domain name "example.a!!!.com": ` + `invalid domain name label at index 1: ` + `validating label "a!!!": invalid char '!' at index 1`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove wantErrMsg: `domain name is empty`, </s> add wantErrMsg: `validating domain name "": domain name is empty`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`,
<mask> ` invalid char '-' at index 0 in "-aa"`, <mask> }, { <mask> name: "bad_label_last_symbol", <mask> in: "example-.aa.com", <mask> wantErrMsg: `invalid domain name label at index 0:` + <mask> ` invalid char '-' at index 7 in "example-"`, <mask> }, { <mask> name: "bad_label_symbol", <mask> in: "example.a!!!.com", <mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '!' at index 1 in "a!!!"`, </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '!' at index 1 in "a!!!"`, </s> add wantErrMsg: `validating domain name "example.a!!!.com": ` + `invalid domain name label at index 1: ` + `validating label "a!!!": invalid char '!' at index 1`, </s> remove name: "bad_label_empty", in: "example..com", wantErrMsg: `invalid domain name label at index 1: label is empty`, </s> add name: "bad_label_empty", in: "example..com", wantErrMsg: `validating domain name "example..com": ` + `invalid domain name label at index 1: ` + `validating label "": label is empty`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove wantErrMsg: `local domain: invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `local domain: validating domain name "!!!": ` + `invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
wantErrMsg: `validating domain name "example.a!!!.com": ` + `invalid domain name label at index 1: ` + `validating label "a!!!": invalid char '!' at index 1`,
<mask> ` invalid char '-' at index 7 in "example-"`, <mask> }, { <mask> name: "bad_label_symbol", <mask> in: "example.a!!!.com", <mask> wantErrMsg: `invalid domain name label at index 1:` + <mask> ` invalid char '!' at index 1 in "a!!!"`, <mask> }} <mask> <mask> for _, tc := range testCases { <mask> t.Run(tc.name, func(t *testing.T) { <mask> err := ValidateDomainName(tc.in) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `invalid domain name label at index 0:` + ` invalid char '-' at index 7 in "example-"`, </s> add wantErrMsg: `validating domain name "example-.aa.com": ` + `invalid domain name label at index 0: ` + `validating label "example-": invalid char '-' at index 7`, </s> remove wantErrMsg: `local domain: invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `local domain: validating domain name "!!!": ` + `invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '-' at index 0 in "-aa"`, </s> add wantErrMsg: `validating domain name "example.-aa.com": ` + `invalid domain name label at index 1: ` + `validating label "-aa": invalid char '-' at index 0`, </s> remove wantErrMsg: `client id check: invalid client id: invalid char '!' ` + `at index 0 in "!!!"`, </s> add wantErrMsg: `client id check: invalid client id "!!!": ` + `invalid char '!' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `validating domain name "!!!": invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/aghnet/addr_test.go
// Expiry is the expiration time of the lease. The unix timestamp value // of 1 means that this is a static lease. Expiry time.Time `json:"expires"` Hostname string `json:"hostname"`
<mask> <mask> // Lease contains the necessary information about a DHCP lease <mask> type Lease struct { <mask> HWAddr net.HardwareAddr `json:"mac"` <mask> IP net.IP `json:"ip"` <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove Hostname string `json:"hostname"` // Lease expiration time // 1: static lease Expiry time.Time `json:"expires"` </s> add </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request. </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) { </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd.go
<mask> // Lease contains the necessary information about a DHCP lease <mask> type Lease struct { <mask> HWAddr net.HardwareAddr `json:"mac"` <mask> IP net.IP `json:"ip"` <mask> Hostname string `json:"hostname"` <mask> <mask> // Lease expiration time <mask> // 1: static lease <mask> Expiry time.Time `json:"expires"` <mask> } <mask> <mask> // IsStatic returns true if the lease is static. <mask> // <mask> // TODO(a.garipov): Just make it a boolean field. </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) { </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd.go
require.NoError(t, err)
<mask> GatewayIP: net.IP{192, 168, 10, 1}, <mask> SubnetMask: net.IP{255, 255, 255, 0}, <mask> notify: testNotify, <mask> }) <mask> require.Nil(t, err) <mask> <mask> s.srv6, err = v6Create(V6ServerConf{}) <mask> require.Nil(t, err) <mask> <mask> leases := []Lease{{ </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100}, </s> remove require.Nil(t, err) require.Nil(t, s.srv4.AddStaticLease(leases[1])) </s> add require.NoError(t, err) err = s.srv4.AddStaticLease(leases[1]) require.NoError(t, err) </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
require.NoError(t, err)
<mask> }) <mask> require.Nil(t, err) <mask> <mask> s.srv6, err = v6Create(V6ServerConf{}) <mask> require.Nil(t, err) <mask> <mask> leases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 100}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> Expiry: time.Now().Add(time.Hour), </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100}, </s> remove IP: net.IP{192, 168, 10, 101}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, IP: net.IP{192, 168, 10, 101}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100},
<mask> s.srv6, err = v6Create(V6ServerConf{}) <mask> require.Nil(t, err) <mask> <mask> leases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 100}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> Expiry: time.Now().Add(time.Hour), <mask> }, { <mask> IP: net.IP{192, 168, 10, 101}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, <mask> }} <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 101}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, IP: net.IP{192, 168, 10, 101}, </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
Hostname: "static-2.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, IP: net.IP{192, 168, 10, 101},
<mask> IP: net.IP{192, 168, 10, 100}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> Expiry: time.Now().Add(time.Hour), <mask> }, { <mask> IP: net.IP{192, 168, 10, 101}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, <mask> }} <mask> <mask> srv4, ok := s.srv4.(*v4Server) <mask> require.True(t, ok) <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
require.NoError(t, err) err = s.srv4.AddStaticLease(leases[1]) require.NoError(t, err)
<mask> srv4, ok := s.srv4.(*v4Server) <mask> require.True(t, ok) <mask> <mask> err = srv4.addLease(&leases[0]) <mask> require.Nil(t, err) <mask> require.Nil(t, s.srv4.AddStaticLease(leases[1])) <mask> <mask> s.dbStore() <mask> t.Cleanup(func() { <mask> assert.Nil(t, os.Remove(dbFilename)) <mask> }) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove assert.Nil(t, os.Remove(dbFilename)) </s> add assert.NoError(t, os.Remove(dbFilename)) </s> remove IP: net.IP{192, 168, 10, 101}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, IP: net.IP{192, 168, 10, 101}, </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
assert.NoError(t, os.Remove(dbFilename))
<mask> require.Nil(t, s.srv4.AddStaticLease(leases[1])) <mask> <mask> s.dbStore() <mask> t.Cleanup(func() { <mask> assert.Nil(t, os.Remove(dbFilename)) <mask> }) <mask> s.srv4.ResetLeases(nil) <mask> s.dbLoad() <mask> <mask> ll := s.srv4.GetLeases(LeasesAll) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove require.Nil(t, err) require.Nil(t, s.srv4.AddStaticLease(leases[1])) </s> add require.NoError(t, err) err = s.srv4.AddStaticLease(leases[1]) require.NoError(t, err) </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove require.Nil(t, err) </s> add require.NoError(t, err) </s> remove assert.True(t, s.conf.GatewayIP.Equal(resp.Router()[0])) </s> add router := resp.Router() require.Len(t, router, 1) assert.Equal(t, s.conf.GatewayIP, router[0]) </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100},
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/dhcpd_test.go
// leasesLock protects leases, leaseHosts, and leasedOffsets.
<mask> <mask> // leases contains all dynamic and static leases. <mask> leases []*Lease <mask> <mask> // leasesLock protects leases and leasedOffsets. <mask> leasesLock sync.Mutex <mask> } <mask> <mask> // WriteDiskConfig4 - write configuration <mask> func (s *v4Server) WriteDiskConfig4(c *V4ServerConf) { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Lock() s.conf.notify(LeaseChangedDBStore) s.leasesLock.Unlock() </s> add func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() s.conf.notify(LeaseChangedDBStore) s.leaseHosts.Add(l.Hostname) }() </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request. </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, ) </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
l.Hostname, err = s.validHostnameForClient(l.Hostname, l.Hostname, l.IP)
<mask> s.leaseHosts = aghstrings.NewSet() <mask> s.leases = nil <mask> <mask> for _, l := range leases { <mask> l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) <mask> if err != nil { <mask> log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) <mask> } <mask> <mask> err = s.addLease(l) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, ) </s> remove log.Info("dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err) </s> add log.Info( "dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err, ) </s> remove lease.Hostname, err = s.validHostnameForClient(cliHostname, reqIP) </s> add lease.Hostname, err = s.validHostnameForClient(cliHostname, lease.Hostname, reqIP) </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, )
<mask> <mask> for _, l := range leases { <mask> l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) <mask> if err != nil { <mask> log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) <mask> } <mask> <mask> err = s.addLease(l) <mask> if err != nil { <mask> // TODO(a.garipov): Wrap and bubble up the error. </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) </s> add l.Hostname, err = s.validHostnameForClient(l.Hostname, l.Hostname, l.IP) </s> remove log.Info("dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err) </s> add log.Info( "dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err, ) </s> remove lease.Hostname, err = s.validHostnameForClient(cliHostname, reqIP) </s> add lease.Hostname, err = s.validHostnameForClient(cliHostname, lease.Hostname, reqIP) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return agherr.Error("static lease already exists")
<mask> l := s.leases[i] <mask> <mask> if bytes.Equal(l.HWAddr, lease.HWAddr) { <mask> if l.IsStatic() { <mask> return fmt.Errorf("static lease already exists") <mask> } <mask> <mask> s.rmLeaseByIndex(i) <mask> if i == len(s.leases) { <mask> break </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if net.IP.Equal(l.IP, lease.IP) { </s> add if l.IP.Equal(lease.IP) { </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove break </s> add return </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l.IP.Equal(lease.IP) {
<mask> <mask> l = s.leases[i] <mask> } <mask> <mask> if net.IP.Equal(l.IP, lease.IP) { <mask> if l.IsStatic() { <mask> return fmt.Errorf("static lease already exists") <mask> } <mask> <mask> s.rmLeaseByIndex(i) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove break </s> add return </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return agherr.Error("static lease already exists")
<mask> } <mask> <mask> if net.IP.Equal(l.IP, lease.IP) { <mask> if l.IsStatic() { <mask> return fmt.Errorf("static lease already exists") <mask> } <mask> <mask> s.rmLeaseByIndex(i) <mask> } <mask> } </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if net.IP.Equal(l.IP, lease.IP) { </s> add if l.IP.Equal(lease.IP) { </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
// addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) {
<mask> <mask> return nil <mask> } <mask> <mask> func (s *v4Server) addStaticLease(l *Lease) (err error) { <mask> if sn := s.conf.subnet; !sn.Contains(l.IP) { <mask> return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) <mask> } <mask> <mask> s.leases = append(s.leases, l) <mask> <mask> r := s.conf.ipRange <mask> offset, ok := r.offset(l.IP) <mask> if ok { <mask> s.leasedOffsets.set(offset, true) <mask> } </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove offset, ok := r.offset(l.IP) if ok { s.leasedOffsets.set(offset, true) } s.leaseHosts.Add(l.Hostname) </s> add offset, inOffset := r.offset(l.IP) </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
offset, inOffset := r.offset(l.IP)
<mask> <mask> s.leases = append(s.leases, l) <mask> <mask> r := s.conf.ipRange <mask> offset, ok := r.offset(l.IP) <mask> if ok { <mask> s.leasedOffsets.set(offset, true) <mask> } <mask> <mask> s.leaseHosts.Add(l.Hostname) <mask> <mask> return nil <mask> } <mask> <mask> func (s *v4Server) addDynamicLease(l *Lease) (err error) { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove s.leaseHosts.Add(l.Hostname) </s> add </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset {
<mask> } <mask> <mask> s.leaseHosts.Add(l.Hostname) <mask> <mask> return nil <mask> } <mask> <mask> func (s *v4Server) addDynamicLease(l *Lease) (err error) { <mask> r := s.conf.ipRange <mask> offset, ok := r.offset(l.IP) <mask> if !ok { <mask> return fmt.Errorf("lease %s (%s) out of range, not adding", l.IP, l.HWAddr) <mask> } <mask> <mask> s.leases = append(s.leases, l) <mask> s.leaseHosts.Add(l.Hostname) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leaseHosts.Add(l.Hostname) </s> add </s> remove offset, ok := r.offset(l.IP) if ok { s.leasedOffsets.set(offset, true) } s.leaseHosts.Add(l.Hostname) </s> add offset, inOffset := r.offset(l.IP) </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
<mask> return fmt.Errorf("lease %s (%s) out of range, not adding", l.IP, l.HWAddr) <mask> } <mask> <mask> s.leases = append(s.leases, l) <mask> s.leaseHosts.Add(l.Hostname) <mask> s.leasedOffsets.set(offset, true) <mask> <mask> return nil <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove offset, ok := r.offset(l.IP) if ok { s.leasedOffsets.set(offset, true) } s.leaseHosts.Add(l.Hostname) </s> add offset, inOffset := r.offset(l.IP) </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l.Hostname != "" { s.leaseHosts.Add(l.Hostname)
<mask> s.leases = append(s.leases, l) <mask> s.leaseHosts.Add(l.Hostname) <mask> s.leasedOffsets.set(offset, true) <mask> <mask> return nil <mask> } <mask> <mask> // addLease adds a dynamic or static lease. <mask> func (s *v4Server) addLease(l *Lease) (err error) { <mask> err = s.validateLease(l) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> if l.IsStatic() { <mask> return s.addStaticLease(l) <mask> } </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove offset, ok := r.offset(l.IP) if ok { s.leasedOffsets.set(offset, true) } s.leaseHosts.Add(l.Hostname) </s> add offset, inOffset := r.offset(l.IP) </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove s.leaseHosts.Add(l.Hostname) </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return nil
<mask> if err != nil { <mask> return err <mask> } <mask> <mask> if l.IsStatic() { <mask> return s.addStaticLease(l) <mask> } <mask> <mask> return s.addDynamicLease(l) <mask> } <mask> <mask> // Remove a lease with the same properties <mask> func (s *v4Server) rmLease(lease Lease) error { <mask> if len(s.leases) == 0 { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) { </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
// rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
<mask> <mask> return s.addDynamicLease(l) <mask> } <mask> <mask> // Remove a lease with the same properties <mask> func (s *v4Server) rmLease(lease Lease) error { <mask> if len(s.leases) == 0 { <mask> return nil <mask> } <mask> <mask> for i, l := range s.leases { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove defer agherr.Annotate("dhcpv4: %w", &err) </s> add defer agherr.Annotate("dhcpv4: adding static lease: %w", &err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
defer agherr.Annotate("dhcpv4: adding static lease: %w", &err)
<mask> } <mask> <mask> // AddStaticLease adds a static lease. It is safe for concurrent use. <mask> func (s *v4Server) AddStaticLease(l Lease) (err error) { <mask> defer agherr.Annotate("dhcpv4: %w", &err) <mask> <mask> if ip4 := l.IP.To4(); ip4 == nil { <mask> return fmt.Errorf("invalid ip %q, only ipv4 is supported", l.IP) <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) { </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
err = aghnet.ValidateHardwareAddress(l.HWAddr)
<mask> } <mask> <mask> l.Expiry = time.Unix(leaseExpireStatic, 0) <mask> <mask> l.Hostname, err = normalizeHostname(l.Hostname) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> // Perform the following actions in an anonymous function to make sure </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, ) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err)) </s> remove l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) </s> add l.Hostname, err = s.validHostnameForClient(l.Hostname, l.Hostname, l.IP)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
// addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) {
<mask> <mask> return nil <mask> } <mask> <mask> // Send ICMP to the specified machine <mask> // Return TRUE if it doesn't reply, which probably means that the IP is available <mask> func (s *v4Server) addrAvailable(target net.IP) bool { <mask> if s.conf.ICMPTimeout == 0 { <mask> return true <mask> } <mask> <mask> pinger, err := ping.NewPinger(target.String()) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) { </s> remove log.Error("ping.NewPinger(): %v", err) </s> add log.Error("dhcpv4: ping.NewPinger(): %s", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Error("dhcpv4: ping.NewPinger(): %s", err)
<mask> } <mask> <mask> pinger, err := ping.NewPinger(target.String()) <mask> if err != nil { <mask> log.Error("ping.NewPinger(): %v", err) <mask> <mask> return true <mask> } <mask> <mask> pinger.SetPrivileged(true) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Debug("dhcpv4: Sending ICMP Echo to %v", target) </s> add log.Debug("dhcpv4: sending icmp echo to %s", target) </s> remove log.Error("pinger.Run(): %v", err) </s> add log.Error("dhcpv4: pinger.Run(): %s", err) </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Debug("dhcpv4: sending icmp echo to %s", target)
<mask> reply := false <mask> pinger.OnRecv = func(_ *ping.Packet) { <mask> reply = true <mask> } <mask> log.Debug("dhcpv4: Sending ICMP Echo to %v", target) <mask> <mask> err = pinger.Run() <mask> if err != nil { <mask> log.Error("pinger.Run(): %v", err) <mask> return true </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Error("pinger.Run(): %v", err) </s> add log.Error("dhcpv4: pinger.Run(): %s", err) </s> remove log.Info("dhcpv4: IP conflict: %v is already used by another device", target) </s> add log.Info("dhcpv4: ip conflict: %s is already used by another device", target) </s> remove log.Debug("dhcpv4: ICMP procedure is complete: %v", target) </s> add log.Debug("dhcpv4: icmp procedure is complete: %q", target) </s> remove log.Error("ping.NewPinger(): %v", err) </s> add log.Error("dhcpv4: ping.NewPinger(): %s", err) </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Error("dhcpv4: pinger.Run(): %s", err)
<mask> log.Debug("dhcpv4: Sending ICMP Echo to %v", target) <mask> <mask> err = pinger.Run() <mask> if err != nil { <mask> log.Error("pinger.Run(): %v", err) <mask> return true <mask> } <mask> <mask> if reply { <mask> log.Info("dhcpv4: IP conflict: %v is already used by another device", target) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Info("dhcpv4: IP conflict: %v is already used by another device", target) </s> add log.Info("dhcpv4: ip conflict: %s is already used by another device", target) </s> remove log.Debug("dhcpv4: Sending ICMP Echo to %v", target) </s> add log.Debug("dhcpv4: sending icmp echo to %s", target) </s> remove log.Debug("dhcpv4: ICMP procedure is complete: %v", target) </s> add log.Debug("dhcpv4: icmp procedure is complete: %q", target) </s> remove log.Error("ping.NewPinger(): %v", err) </s> add log.Error("dhcpv4: ping.NewPinger(): %s", err) </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Info("dhcpv4: ip conflict: %s is already used by another device", target)
<mask> return true <mask> } <mask> <mask> if reply { <mask> log.Info("dhcpv4: IP conflict: %v is already used by another device", target) <mask> return false <mask> } <mask> <mask> log.Debug("dhcpv4: ICMP procedure is complete: %v", target) <mask> return true </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Debug("dhcpv4: ICMP procedure is complete: %v", target) </s> add log.Debug("dhcpv4: icmp procedure is complete: %q", target) </s> remove log.Error("pinger.Run(): %v", err) </s> add log.Error("dhcpv4: pinger.Run(): %s", err) </s> remove log.Debug("dhcpv4: Sending ICMP Echo to %v", target) </s> add log.Debug("dhcpv4: sending icmp echo to %s", target) </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Debug("dhcpv4: icmp procedure is complete: %q", target)
<mask> log.Info("dhcpv4: IP conflict: %v is already used by another device", target) <mask> return false <mask> } <mask> <mask> log.Debug("dhcpv4: ICMP procedure is complete: %v", target) <mask> return true <mask> } <mask> <mask> // findLease finds a lease by its MAC-address. <mask> func (s *v4Server) findLease(mac net.HardwareAddr) (l *Lease) { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Info("dhcpv4: IP conflict: %v is already used by another device", target) </s> add log.Info("dhcpv4: ip conflict: %s is already used by another device", target) </s> remove log.Error("pinger.Run(): %v", err) </s> add log.Error("dhcpv4: pinger.Run(): %s", err) </s> remove log.Debug("dhcpv4: Sending ICMP Echo to %v", target) </s> add log.Debug("dhcpv4: sending icmp echo to %s", target) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() s.conf.notify(LeaseChangedDBStore) s.leaseHosts.Add(l.Hostname) }()
<mask> <mask> func (s *v4Server) commitLease(l *Lease) { <mask> l.Expiry = time.Now().Add(s.conf.leaseTime) <mask> <mask> s.leasesLock.Lock() <mask> s.conf.notify(LeaseChangedDBStore) <mask> s.leasesLock.Unlock() <mask> <mask> s.conf.notify(LeaseChangedAdded) <mask> } <mask> <mask> // Process Discover request and return lease </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request. </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove // Remove a lease with the same properties func (s *v4Server) rmLease(lease Lease) error { </s> add // rmLease removes a lease with the same properties. func (s *v4Server) rmLease(lease Lease) (err error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
// processDiscover is the handler for the DHCP Discover request.
<mask> <mask> s.conf.notify(LeaseChangedAdded) <mask> } <mask> <mask> // Process Discover request and return lease <mask> func (s *v4Server) processDiscover(req, resp *dhcpv4.DHCPv4) (l *Lease, err error) { <mask> mac := req.ClientHWAddr <mask> <mask> s.leasesLock.Lock() <mask> defer s.leasesLock.Unlock() </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Lock() s.conf.notify(LeaseChangedDBStore) s.leasesLock.Unlock() </s> add func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() s.conf.notify(LeaseChangedDBStore) s.leaseHosts.Add(l.Hostname) }() </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
err = aghnet.ValidateHardwareAddress(mac) if err != nil { return nil, err }
<mask> mac := req.ClientHWAddr <mask> <mask> s.leasesLock.Lock() <mask> defer s.leasesLock.Unlock() <mask> <mask> l = s.findLease(mac) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request. </s> remove // TODO(a.garipov): Refactor this mess. </s> add </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove s.leasesLock.Lock() s.conf.notify(LeaseChangedDBStore) s.leasesLock.Unlock() </s> add func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() s.conf.notify(LeaseChangedDBStore) s.leaseHosts.Add(l.Hostname) }() </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
<mask> <mask> s.leasesLock.Lock() <mask> defer s.leasesLock.Unlock() <mask> <mask> // TODO(a.garipov): Refactor this mess. <mask> l = s.findLease(mac) <mask> if l == nil { <mask> toStore := false <mask> for l == nil { <mask> l, err = s.reserveLease(mac) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) } </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
<mask> defer s.leasesLock.Unlock() <mask> <mask> // TODO(a.garipov): Refactor this mess. <mask> l = s.findLease(mac) <mask> if l == nil { <mask> toStore := false <mask> for l == nil { <mask> l, err = s.reserveLease(mac) <mask> if err != nil { <mask> return nil, fmt.Errorf("reserving a lease: %w", err) <mask> } <mask> <mask> if l == nil { <mask> log.Debug("dhcpv4: no more ip addresses") <mask> if toStore { <mask> s.conf.notify(LeaseChangedDBStore) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // TODO(a.garipov): Refactor this mess. </s> add </s> remove if l == nil { log.Debug("dhcpv4: no more ip addresses") if toStore { s.conf.notify(LeaseChangedDBStore) } </s> add resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer)) </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses") </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer))
<mask> if err != nil { <mask> return nil, fmt.Errorf("reserving a lease: %w", err) <mask> } <mask> <mask> if l == nil { <mask> log.Debug("dhcpv4: no more ip addresses") <mask> if toStore { <mask> s.conf.notify(LeaseChangedDBStore) <mask> } <mask> <mask> // TODO(a.garipov): Return a special error? <mask> return nil, nil <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) } </s> remove // TODO(a.garipov): Return a special error? return nil, nil } </s> add return l, nil } </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }() </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return l, nil }
<mask> if toStore { <mask> s.conf.notify(LeaseChangedDBStore) <mask> } <mask> <mask> // TODO(a.garipov): Return a special error? <mask> return nil, nil <mask> } <mask> <mask> toStore = true <mask> <mask> if !s.addrAvailable(l.IP) { <mask> s.blocklistLease(l) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }() </s> remove if l == nil { log.Debug("dhcpv4: no more ip addresses") if toStore { s.conf.notify(LeaseChangedDBStore) } </s> add resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer)) </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) } </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }()
<mask> // TODO(a.garipov): Return a special error? <mask> return nil, nil <mask> } <mask> <mask> toStore = true <mask> <mask> if !s.addrAvailable(l.IP) { <mask> s.blocklistLease(l) <mask> l = nil <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove // TODO(a.garipov): Return a special error? return nil, nil } </s> add return l, nil } </s> remove if l == nil { log.Debug("dhcpv4: no more ip addresses") if toStore { s.conf.notify(LeaseChangedDBStore) } </s> add resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer)) </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) } </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses")
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) }
<mask> } <mask> <mask> toStore = true <mask> <mask> if !s.addrAvailable(l.IP) { <mask> s.blocklistLease(l) <mask> l = nil <mask> <mask> continue <mask> } <mask> <mask> break </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses") </s> remove // TODO(a.garipov): Return a special error? return nil, nil } </s> add return l, nil } </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }() </s> remove s.conf.notify(LeaseChangedDBStore) } else { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) </s> add needsUpdate = true if s.addrAvailable(l.IP) { leaseReady = true } else { s.blocklistLease(l) l = nil </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l == nil { log.Debug("dhcpv4: no more ip addresses")
<mask> if !s.addrAvailable(l.IP) { <mask> s.blocklistLease(l) <mask> l = nil <mask> <mask> continue <mask> } <mask> <mask> break <mask> } <mask> <mask> s.conf.notify(LeaseChangedDBStore) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove // TODO(a.garipov): Return a special error? return nil, nil } </s> add return l, nil } </s> remove toStore = true </s> add needsUpdate := false defer func() { if needsUpdate { s.conf.notify(LeaseChangedDBStore) } }() </s> remove break </s> add return nil, nil </s> remove s.conf.notify(LeaseChangedDBStore) } else { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) </s> add needsUpdate = true if s.addrAvailable(l.IP) { leaseReady = true } else { s.blocklistLease(l) l = nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return nil, nil
<mask> <mask> continue <mask> } <mask> <mask> break <mask> } <mask> <mask> s.conf.notify(LeaseChangedDBStore) <mask> } else { <mask> reqIP := req.RequestedIPAddress() </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.conf.notify(LeaseChangedDBStore) } else { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) </s> add needsUpdate = true if s.addrAvailable(l.IP) { leaseReady = true } else { s.blocklistLease(l) l = nil </s> remove continue } </s> add if l == nil { log.Debug("dhcpv4: no more ip addresses") </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove if !s.addrAvailable(l.IP) { s.blocklistLease(l) l = nil </s> add leaseReady := false for !leaseReady { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
needsUpdate = true if s.addrAvailable(l.IP) { leaseReady = true } else { s.blocklistLease(l) l = nil
<mask> <mask> break <mask> } <mask> <mask> s.conf.notify(LeaseChangedDBStore) <mask> } else { <mask> reqIP := req.RequestedIPAddress() <mask> if len(reqIP) != 0 && !reqIP.Equal(l.IP) { <mask> log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) <mask> } <mask> } <mask> <mask> resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer)) <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) } </s> remove break </s> add return nil, nil </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false </s> remove if l == nil { log.Debug("dhcpv4: no more ip addresses") if toStore { s.conf.notify(LeaseChangedDBStore) } </s> add resp.UpdateOption(dhcpv4.OptMessageType(dhcpv4.MessageTypeOffer))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
// processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac)
<mask> copy(b[i:], []byte(o.name)) <mask> return b <mask> } <mask> <mask> // normalizeHostname normalizes a hostname sent by the client. If err is not <mask> // nil, norm is an empty string. <mask> func normalizeHostname(name string) (norm string, err error) { <mask> if name == "" { <mask> return "", nil <mask> } <mask> <mask> norm = strings.ToLower(name) <mask> parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { <mask> return c != '.' && !aghnet.IsValidHostOuterRune(c) <mask> }) <mask> <mask> if len(parts) == 0 { <mask> return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) <mask> } <mask> <mask> norm = strings.Join(parts, "-") <mask> norm = strings.TrimSuffix(norm, "-") <mask> <mask> return norm, nil <mask> } <mask> <mask> // validateHostname validates a hostname sent by the client. <mask> func (s *v4Server) validateHostname(name string) (err error) { <mask> defer agherr.Annotate("validating hostname: %s", &err) <mask> <mask> if name == "" { <mask> return nil <mask> } <mask> <mask> err = aghnet.ValidateDomainName(name) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> if s.leaseHosts.Has(name) { <mask> return agherr.Error("hostname exists") <mask> } <mask> <mask> return nil <mask> } <mask> <mask> // validHostnameForClient accepts the hostname sent by the client and returns <mask> // either a normalized version of that hostname or a new hostname generated from <mask> // the client's IP address. <mask> // <mask> // hostname is always a non-empty valid hostname. If err is not nil, it <mask> // describes the issues encountered when normalizing cliHostname. <mask> func (s *v4Server) validHostnameForClient( <mask> cliHostname string, <mask> ip net.IP, <mask> ) (hostname string, err error) { <mask> hostname, err = normalizeHostname(cliHostname) <mask> if err == nil { <mask> err = s.validateHostname(hostname) <mask> if err != nil { <mask> // Go on and assign a hostname made from the IP below, <mask> // returning the error that we've got. <mask> hostname = "" <mask> } <mask> } <mask> <mask> if hostname == "" { <mask> hostname = aghnet.GenerateHostname(ip) <mask> } <mask> <mask> if hostname != cliHostname { <mask> log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) <mask> } <mask> <mask> return hostname, err <mask> } <mask> <mask> // validateLease returns an error if the lease is invalid. <mask> func (s *v4Server) validateLease(l *Lease) (err error) { <mask> defer agherr.Annotate("validating lease: %s", &err) <mask> <mask> if l == nil { <mask> return agherr.Error("lease is nil") <mask> } <mask> <mask> err = aghnet.ValidateHardwareAddress(l.HWAddr) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> err = s.validateHostname(l.Hostname) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> if sn := s.conf.subnet; !sn.Contains(l.IP) { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove if l.IsStatic() { return s.addStaticLease(l) } return s.addDynamicLease(l) </s> add return nil </s> remove return fmt.Errorf("invalid client id: %w", err) </s> add // Replace the domain name label wrapper with our own. return fmt.Errorf("invalid client id %q: %w", clientID, errors.Unwrap(err)) </s> remove return nil } // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { err = s.validateLease(l) if err != nil { return err </s> add if l.Hostname != "" { s.leaseHosts.Add(l.Hostname) </s> remove // Send ICMP to the specified machine // Return TRUE if it doesn't reply, which probably means that the IP is available func (s *v4Server) addrAvailable(target net.IP) bool { </s> add // addrAvailable sends an ICP request to the specified IP address. It returns // true if the remote host doesn't reply, which probably means that the IP // address is available. // // TODO(a.garipov): I'm not sure that this is the best way to do this. func (s *v4Server) addrAvailable(target net.IP) (avail bool) { </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, )
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return nil, false
<mask> } <mask> <mask> err = s.validateHostname(l.Hostname) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> if sn := s.conf.subnet; !sn.Contains(l.IP) { <mask> return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) <mask> } <mask> <mask> r := s.conf.ipRange <mask> if !l.IsStatic() && !r.contains(l.IP) { <mask> return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) <mask> } <mask> <mask> return nil <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return nil } // Process Request request and return lease // Return false if we don't need to reply func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { var err error mac := req.ClientHWAddr </s> add </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove if l == nil { toStore := false for l == nil { l, err = s.reserveLease(mac) if err != nil { return nil, fmt.Errorf("reserving a lease: %w", err) } </s> add if l != nil { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
<mask> if !l.IsStatic() && !r.contains(l.IP) { <mask> return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) <mask> } <mask> <mask> return nil <mask> } <mask> <mask> // Process Request request and return lease <mask> // Return false if we don't need to reply <mask> func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, ok bool) { <mask> var err error <mask> <mask> mac := req.ClientHWAddr <mask> reqIP := req.RequestedIPAddress() <mask> if reqIP == nil { <mask> reqIP = req.ClientIPAddr <mask> } <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return err } if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } r := s.conf.ipRange if !l.IsStatic() && !r.contains(l.IP) { return fmt.Errorf("dynamic lease range %s does not contain the ip %q", r, l.IP) </s> add return nil, false </s> remove // Process Discover request and return lease </s> add // processDiscover is the handler for the DHCP Discover request. </s> remove func (s *v4Server) addStaticLease(l *Lease) (err error) { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } s.leases = append(s.leases, l) </s> add // addLease adds a dynamic or static lease. func (s *v4Server) addLease(l *Lease) (err error) { </s> remove return nil } func (s *v4Server) addDynamicLease(l *Lease) (err error) { r := s.conf.ipRange offset, ok := r.offset(l.IP) if !ok { </s> add if l.IsStatic() { if sn := s.conf.subnet; !sn.Contains(l.IP) { return fmt.Errorf("subnet %s does not contain the ip %q", sn, l.IP) } } else if !inOffset { </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock()
<mask> <mask> return nil, false <mask> } <mask> <mask> s.leasesLock.Lock() <mask> for _, l := range s.leases { <mask> if bytes.Equal(l.HWAddr, mac) { <mask> if !l.IP.Equal(reqIP) { <mask> s.leasesLock.Unlock() <mask> log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) <mask> <mask> return nil, true <mask> } <mask> <mask> lease = l </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac) </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true } </s> remove s.leasesLock.Unlock() </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue
<mask> if !l.IP.Equal(reqIP) { <mask> s.leasesLock.Unlock() <mask> log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) <mask> <mask> return nil, true <mask> } <mask> <mask> lease = l <mask> <mask> break </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true } </s> remove s.leasesLock.Unlock() </s> add </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true }
<mask> <mask> return nil, true <mask> } <mask> <mask> lease = l <mask> <mask> break <mask> } <mask> } <mask> s.leasesLock.Unlock() </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Unlock() </s> add </s> remove break </s> add return </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
return
<mask> } <mask> <mask> lease = l <mask> <mask> break <mask> } <mask> } <mask> s.leasesLock.Unlock() <mask> <mask> if lease == nil { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Unlock() </s> add </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true } </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac) </s> remove return fmt.Errorf("static lease already exists") </s> add return agherr.Error("static lease already exists") </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
}() if mismatch { return nil, true
<mask> } <mask> <mask> return <mask> } <mask> } <mask> <mask> if lease == nil { <mask> log.Debug("dhcpv4: no reserved lease for %s", mac) <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac) </s> remove s.leasesLock.Unlock() </s> add </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove break </s> add return
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
<mask> <mask> break <mask> } <mask> } <mask> s.leasesLock.Unlock() <mask> <mask> if lease == nil { <mask> log.Debug("dhcpv4: no lease for %s", mac) <mask> <mask> return nil, true </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Debug("dhcpv4: no lease for %s", mac) </s> add log.Debug("dhcpv4: no reserved lease for %s", mac) </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Debug("dhcpv4: no reserved lease for %s", mac)
<mask> } <mask> s.leasesLock.Unlock() <mask> <mask> if lease == nil { <mask> log.Debug("dhcpv4: no lease for %s", mac) <mask> <mask> return nil, true <mask> } <mask> <mask> if !lease.IsStatic() { </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove s.leasesLock.Unlock() </s> add </s> remove s.leasesLock.Lock() for _, l := range s.leases { if bytes.Equal(l.HWAddr, mac) { if !l.IP.Equal(reqIP) { s.leasesLock.Unlock() log.Debug("dhcpv4: mismatched OptionRequestedIPAddress in request message for %s", mac) </s> add mismatch := false func() { s.leasesLock.Lock() defer s.leasesLock.Unlock() </s> remove return nil, true </s> add for _, l := range s.leases { if !bytes.Equal(l.HWAddr, mac) { continue </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
lease.Hostname, err = s.validHostnameForClient(cliHostname, lease.Hostname, reqIP)
<mask> } <mask> <mask> if !lease.IsStatic() { <mask> cliHostname := req.HostName() <mask> lease.Hostname, err = s.validHostnameForClient(cliHostname, reqIP) <mask> if err != nil { <mask> log.Info("dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err) <mask> } <mask> <mask> s.commitLease(lease) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove log.Info("dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err) </s> add log.Info( "dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err, ) </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, ) </s> remove l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) </s> add l.Hostname, err = s.validHostnameForClient(l.Hostname, l.Hostname, l.IP) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove log.Error("pinger.Run(): %v", err) </s> add log.Error("dhcpv4: pinger.Run(): %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
log.Info( "dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err, )
<mask> if !lease.IsStatic() { <mask> cliHostname := req.HostName() <mask> lease.Hostname, err = s.validHostnameForClient(cliHostname, reqIP) <mask> if err != nil { <mask> log.Info("dhcpv4: warning: client hostname %q is invalid: %s", cliHostname, err) <mask> } <mask> <mask> s.commitLease(lease) <mask> } else if len(lease.Hostname) != 0 { <mask> o := &optFQDN{ </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove lease.Hostname, err = s.validHostnameForClient(cliHostname, reqIP) </s> add lease.Hostname, err = s.validHostnameForClient(cliHostname, lease.Hostname, reqIP) </s> remove log.Info("dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err) </s> add log.Info( "dhcpv4: warning: previous hostname %q is invalid: %s", l.Hostname, err, ) </s> remove l.Hostname, err = s.validHostnameForClient(l.Hostname, l.IP) </s> add l.Hostname, err = s.validHostnameForClient(l.Hostname, l.Hostname, l.IP) </s> remove // normalizeHostname normalizes a hostname sent by the client. If err is not // nil, norm is an empty string. func normalizeHostname(name string) (norm string, err error) { if name == "" { return "", nil } norm = strings.ToLower(name) parts := strings.FieldsFunc(norm, func(c rune) (ok bool) { return c != '.' && !aghnet.IsValidHostOuterRune(c) }) if len(parts) == 0 { return "", fmt.Errorf("normalizing hostname %q: no valid parts", name) } norm = strings.Join(parts, "-") norm = strings.TrimSuffix(norm, "-") return norm, nil } // validateHostname validates a hostname sent by the client. func (s *v4Server) validateHostname(name string) (err error) { defer agherr.Annotate("validating hostname: %s", &err) if name == "" { return nil } err = aghnet.ValidateDomainName(name) if err != nil { return err } if s.leaseHosts.Has(name) { return agherr.Error("hostname exists") } return nil } // validHostnameForClient accepts the hostname sent by the client and returns // either a normalized version of that hostname or a new hostname generated from // the client's IP address. // // hostname is always a non-empty valid hostname. If err is not nil, it // describes the issues encountered when normalizing cliHostname. func (s *v4Server) validHostnameForClient( cliHostname string, ip net.IP, ) (hostname string, err error) { hostname, err = normalizeHostname(cliHostname) if err == nil { err = s.validateHostname(hostname) if err != nil { // Go on and assign a hostname made from the IP below, // returning the error that we've got. hostname = "" } } if hostname == "" { hostname = aghnet.GenerateHostname(ip) } if hostname != cliHostname { log.Info("dhcpv4: normalized hostname %q into %q", cliHostname, hostname) } return hostname, err } // validateLease returns an error if the lease is invalid. func (s *v4Server) validateLease(l *Lease) (err error) { defer agherr.Annotate("validating lease: %s", &err) if l == nil { return agherr.Error("lease is nil") } err = aghnet.ValidateHardwareAddress(l.HWAddr) if err != nil { return err } err = s.validateHostname(l.Hostname) </s> add // processDiscover is the handler for the DHCP Request request. func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (lease *Lease, needsReply bool) { mac := req.ClientHWAddr err := aghnet.ValidateHardwareAddress(mac) </s> remove s.conf.notify(LeaseChangedDBStore) } else { reqIP := req.RequestedIPAddress() if len(reqIP) != 0 && !reqIP.Equal(l.IP) { log.Debug("dhcpv4: different RequestedIP: %s != %s", reqIP, l.IP) </s> add needsUpdate = true if s.addrAvailable(l.IP) { leaseReady = true } else { s.blocklistLease(l) l = nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4.go
Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
<mask> assert.Empty(t, ls) <mask> <mask> // Add static lease. <mask> l := Lease{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> } <mask> <mask> err = s.AddStaticLease(l) <mask> require.NoError(t, err) <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
<mask> s, ok := sIface.(*v4Server) <mask> require.True(t, ok) <mask> <mask> dynLeases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }, { <mask> IP: net.IP{192, 168, 10, 151}, <mask> HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }} <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152}, </s> remove IP: net.IP{192, 168, 10, 101}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBB}, IP: net.IP{192, 168, 10, 101}, </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151},
<mask> dynLeases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }, { <mask> IP: net.IP{192, 168, 10, 151}, <mask> HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }} <mask> <mask> for i := range dynLeases { <mask> err = s.addLease(&dynLeases[i]) <mask> require.NoError(t, err) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
<mask> require.NoError(t, err) <mask> } <mask> <mask> stLeases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }, { <mask> IP: net.IP{192, 168, 10, 152}, <mask> HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }} <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152}, </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152},
<mask> stLeases := []Lease{{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }, { <mask> IP: net.IP{192, 168, 10, 152}, <mask> HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> }} <mask> <mask> for _, l := range stLeases { <mask> err = s.AddStaticLease(l) <mask> require.NoError(t, err) </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-1.local", HWAddr: net.HardwareAddr{0x11, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150},
<mask> <mask> s.conf.dnsIPAddrs = []net.IP{{192, 168, 10, 1}} <mask> <mask> l := Lease{ <mask> IP: net.IP{192, 168, 10, 150}, <mask> HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, <mask> } <mask> err = s.AddStaticLease(l) <mask> require.NoError(t, err) <mask> <mask> var req, resp *dhcpv4.DHCPv4 </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 152}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 152}, </s> remove IP: net.IP{192, 168, 10, 150}, HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "static-1.local", HWAddr: net.HardwareAddr{0x33, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 150}, </s> remove IP: net.IP{192, 168, 10, 151}, HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, </s> add Hostname: "dynamic-2.local", HWAddr: net.HardwareAddr{0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 151}, </s> remove IP: net.IP{192, 168, 10, 100}, HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, Expiry: time.Now().Add(time.Hour), </s> add Expiry: time.Now().Add(time.Hour), Hostname: "static-1.local", HWAddr: net.HardwareAddr{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, IP: net.IP{192, 168, 10, 100},
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go
router := resp.Router() require.Len(t, router, 1) assert.Equal(t, s.conf.GatewayIP, router[0])
<mask> t.Run("ack", func(t *testing.T) { <mask> assert.Equal(t, dhcpv4.MessageTypeAck, resp.MessageType()) <mask> assert.Equal(t, mac, resp.ClientHWAddr) <mask> assert.True(t, s.conf.RangeStart.Equal(resp.YourIPAddr)) <mask> assert.True(t, s.conf.GatewayIP.Equal(resp.Router()[0])) <mask> assert.True(t, s.conf.GatewayIP.Equal(resp.ServerIdentifier())) <mask> assert.Equal(t, s.conf.subnet.Mask, resp.SubnetMask()) <mask> assert.Equal(t, s.conf.leaseTime.Seconds(), resp.IPAddressLeaseTime(-1).Seconds()) <mask> }) <mask> </s> Pull request: dhcpd: imp normalization, validation Updates #3056. Squashed commit of the following: commit 875954fc8d59980a39b03032007cbc15d87801ea Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 19:54:24 2021 +0300 all: imp err msgs commit c6ea471038ce28f608084b59d3447ff64124260f Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed May 5 17:55:12 2021 +0300 dhcpd: imp normalization, validation </s> remove wantErrMsg: `normalizing hostname "! ! !": no valid parts`, </s> add wantErrMsg: `normalizing "! ! !": no valid parts`, </s> remove wantErrMsg: `client id check: invalid client id: invalid char '!' ` + `at index 0 in "!!!"`, </s> add wantErrMsg: `client id check: invalid client id "!!!": ` + `invalid char '!' at index 0`, </s> remove wantErrMsg: `invalid domain name label at index 1:` + ` invalid char '!' at index 1 in "a!!!"`, </s> add wantErrMsg: `validating domain name "example.a!!!.com": ` + `invalid domain name label at index 1: ` + `validating label "a!!!": invalid char '!' at index 1`, </s> remove wantErrMsg: `local domain: invalid domain name label at index 0: ` + `invalid char '!' at index 0 in "!!!"`, </s> add wantErrMsg: `local domain: validating domain name "!!!": ` + `invalid domain name label at index 0: ` + `validating label "!!!": invalid char '!' at index 0`, </s> remove lease = l </s> add if l.IP.Equal(reqIP) { lease = l } else { log.Debug( `dhcpv4: mismatched OptionRequestedIPAddress `+ `in request message for %s`, mac, ) mismatch = true }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/f717776c640ce31ffbc742144164edffc24c22e6
internal/dhcpd/v4_test.go