docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> } <mask> Context.clients.Init(config.Clients, Context.dhcpServer, Context.etcHosts) <mask> config.Clients = nil <mask> <mask> if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && <mask> config.RlimitNoFile != 0 { <mask> aghos.SetRlimit(config.RlimitNoFile) <mask> } <mask> <mask> // override bind host/port from the console <mask> if args.bindHost != nil { <mask> config.BindHost = args.bindHost </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove func setRlimit(val uint) { </s> add func setRlimit(val uint64) (err error) { </s> remove err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> remove rlim.Max = uint64(val) rlim.Cur = uint64(val) err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add rlim.Max = val rlim.Cur = val return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> add // TODO(a.garipov): github.com/kardianos/service doesn't seem to // support OpenBSD currently. Either patch it to do so or make // our own implementation of the service.System interface. if runtime.GOOS == "openbsd" { log.Fatal("service actions are not supported on openbsd") }
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep add keep keep keep keep keep keep
<mask> Context.pidFileName = args.pidFile <mask> } <mask> } <mask> <mask> func initWeb(args options, clientBuildFS fs.FS) (web *Web, err error) { <mask> var clientFS, clientBetaFS fs.FS <mask> if args.localFrontend { <mask> log.Info("warning: using local frontend files") </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> add func fatalOnError(err error) { if err != nil { log.Fatal(err) } } </s> add var err error </s> remove func setRlimit(val uint) { </s> add func setRlimit(val uint64) (err error) { </s> remove func setRlimit(val uint) { </s> add func setRlimit(val uint64) (err error) { </s> remove rlim.Max = uint64(val) rlim.Cur = uint64(val) err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add rlim.Max = val rlim.Cur = val return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> remove err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep add keep keep keep keep keep
<mask> return web, nil <mask> } <mask> <mask> // run performs configurating and starts AdGuard Home. <mask> func run(args options, clientBuildFS fs.FS) { <mask> var err error <mask> <mask> // configure config filename </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> add var err error </s> add return nil </s> remove rlim.Max = uint64(val) rlim.Cur = uint64(val) err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add rlim.Max = val rlim.Cur = val return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> add // ErrUnsupported is returned when the functionality is unsupported on the // current operating system. // // TODO(a.garipov): Make a structured error and use it everywhere instead of // a bunch of fmt.Errorf and all that. const ErrUnsupported errors.Error = "unsupported" </s> remove err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> remove err := config.write() if err != nil { log.Fatal(err) } </s> add err = config.write() fatalOnError(err)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep add keep keep keep keep keep keep
<mask> // run performs configurating and starts AdGuard Home. <mask> func run(args options, clientBuildFS fs.FS) { <mask> // configure config filename <mask> initConfigFilename(args) <mask> <mask> // configure working dir and config path <mask> initWorkingDir(args) <mask> </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> add func fatalOnError(err error) { if err != nil { log.Fatal(err) } } </s> add return nil </s> add // ErrUnsupported is returned when the functionality is unsupported on the // current operating system. // // TODO(a.garipov): Make a structured error and use it everywhere instead of // a bunch of fmt.Errorf and all that. const ErrUnsupported errors.Error = "unsupported" </s> remove err := config.write() if err != nil { log.Fatal(err) } </s> add err = config.write() fatalOnError(err) </s> remove setupConfig(args) </s> add err = setupConfig(args) fatalOnError(err) </s> remove log.Fatalf("can't initialize dhcp module") </s> add return fmt.Errorf("initing dhcp: %w", err)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep keep replace keep keep keep replace replace replace replace keep keep keep keep
<mask> // but also avoid relying on automatic Go init() function <mask> filtering.InitModule() <mask> <mask> setupConfig(args) <mask> <mask> if !Context.firstRun { <mask> // Save the updated config <mask> err := config.write() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> if config.DebugPProf { <mask> mux := http.NewServeMux() <mask> mux.HandleFunc("/debug/pprof/", pprof.Index) </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> add func fatalOnError(err error) { if err != nil { log.Fatal(err) } } </s> remove if err != nil { log.Fatalf("%s", err) } </s> add fatalOnError(err) </s> remove rlim.Max = uint64(val) rlim.Cur = uint64(val) err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add rlim.Max = val rlim.Cur = val return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> }() <mask> } <mask> } <mask> <mask> err := os.MkdirAll(Context.getDataDir(), 0o755) <mask> if err != nil { <mask> log.Fatalf("Cannot create DNS data dir at %s: %s", Context.getDataDir(), err) <mask> } <mask> <mask> sessFilename := filepath.Join(Context.getDataDir(), "sessions.db") </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove log.Fatal(serr) </s> add fatalOnError(serr) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatalf("%s", err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) </s> remove rlim.Max = uint64(val) rlim.Cur = uint64(val) err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add rlim.Max = val rlim.Cur = val return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep replace replace replace keep keep keep keep keep keep keep replace replace replace keep keep
<mask> <mask> Context.web, err = initWeb(args, clientBuildFS) <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> Context.subnetDetector, err = aghnet.NewSubnetDetector() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> Context.subnetDetector, err = aghnet.NewSubnetDetector() <mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> if !Context.firstRun { </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove err := config.write() if err != nil { log.Fatal(err) } </s> add err = config.write() fatalOnError(err) </s> remove if err != nil { log.Fatalf("%s", err) } </s> add fatalOnError(err) </s> add func fatalOnError(err error) { if err != nil { log.Fatal(err) } } </s> remove if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && config.RlimitNoFile != 0 { aghos.SetRlimit(config.RlimitNoFile) </s> add if config.RlimitNoFile != 0 { err = aghos.SetRlimit(config.RlimitNoFile) if err != nil && !errors.Is(err, aghos.ErrUnsupported) { return fmt.Errorf("setting rlimit: %w", err) } </s> remove log.Fatal(serr) </s> add fatalOnError(serr)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> if !Context.firstRun { <mask> err = initDNSServer() <mask> if err != nil { <mask> log.Fatalf("%s", err) <mask> } <mask> <mask> Context.tls.Start() <mask> Context.etcHosts.Start() <mask> <mask> go func() { </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove log.Fatal(serr) </s> add fatalOnError(serr) </s> remove err := config.write() if err != nil { log.Fatal(err) } </s> add err = config.write() fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && config.RlimitNoFile != 0 { aghos.SetRlimit(config.RlimitNoFile) </s> add if config.RlimitNoFile != 0 { err = aghos.SetRlimit(config.RlimitNoFile) if err != nil && !errors.Is(err, aghos.ErrUnsupported) { return fmt.Errorf("setting rlimit: %w", err) } </s> remove err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim) if err != nil { log.Error("Setrlimit() failed: %v", err) } </s> add return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> go func() { <mask> serr := startDNSServer() <mask> if serr != nil { <mask> closeDNSServer() <mask> log.Fatal(serr) <mask> } <mask> }() <mask> <mask> if Context.dhcpServer != nil { <mask> err = Context.dhcpServer.Start() </s> Pull request: all: openbsd support Updates #2439. Squashed commit of the following: commit 3ff109e43751132d77500256c8869938680ac281 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:46:17 2021 +0300 all: imp code, docs commit 512ee6d78cfee511f429d09c8366bb7dd8019aa8 Author: Ainar Garipov <[email protected]> Date: Thu Jun 3 20:06:41 2021 +0300 all: openbsd support </s> remove if err != nil { log.Fatalf("%s", err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove if err != nil { log.Fatal(err) } </s> add fatalOnError(err) </s> remove err := os.MkdirAll(Context.getDataDir(), 0o755) </s> add err = os.MkdirAll(Context.getDataDir(), 0o755) </s> remove if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && config.RlimitNoFile != 0 { aghos.SetRlimit(config.RlimitNoFile) </s> add if config.RlimitNoFile != 0 { err = aghos.SetRlimit(config.RlimitNoFile) if err != nil && !errors.Is(err, aghos.ErrUnsupported) { return fmt.Errorf("setting rlimit: %w", err) } </s> remove err := config.write() if err != nil { log.Fatal(err) } </s> add err = config.write() fatalOnError(err)
https://github.com/AdguardTeam/AdGuardHome/commit/3b87478470ff49fbfe850c8f12492265a3c9491b
internal/home/home.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.TLS.PortHTTPS)) <mask> // validate current TLS config and update warnings (it could have been loaded from file) <mask> data := validateCertificates(config.TLS) <mask> if data.WarningValidation != "" { <mask> log.Fatal(data.WarningValidation) <mask> os.Exit(1) <mask> } <mask> config.TLS = data // update warnings <mask> </s> /tls/ -- add internal usable flag to simplify logic when https needs to be booted up </s> add data.usable = true </s> remove if data.WarningValidation == "" { </s> add if data.usable { </s> add // is usable? set by validator usable bool
https://github.com/AdguardTeam/AdGuardHome/commit/3c374b594000a47bef40c2d5d20d7ba677c74b31
app.go
keep keep add keep keep keep keep keep
<mask> ValidKey bool `yaml:"-" json:"valid_key"` <mask> KeyType string `yaml:"-" json:"key_type,omitempty"` <mask> <mask> // warnings <mask> Warning string `yaml:"-" json:"warning,omitempty"` <mask> WarningValidation string `yaml:"-" json:"warning_validation,omitempty"` <mask> } <mask> </s> /tls/ -- add internal usable flag to simplify logic when https needs to be booted up </s> add data.usable = true </s> remove if data.WarningValidation == "" { </s> add if data.usable { </s> remove if data.WarningValidation != "" { </s> add if !data.usable {
https://github.com/AdguardTeam/AdGuardHome/commit/3c374b594000a47bef40c2d5d20d7ba677c74b31
config.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> restartHTTPS := false <mask> data = validateCertificates(data) <mask> if data.WarningValidation == "" { <mask> if !reflect.DeepEqual(config.TLS.tlsConfigSettings, data.tlsConfigSettings) { <mask> log.Printf("tls config settings have changed, will restart HTTPS server") <mask> restartHTTPS = true <mask> } <mask> config.TLS = data </s> /tls/ -- add internal usable flag to simplify logic when https needs to be booted up </s> add data.usable = true </s> remove if data.WarningValidation != "" { </s> add if !data.usable { </s> add // is usable? set by validator usable bool
https://github.com/AdguardTeam/AdGuardHome/commit/3c374b594000a47bef40c2d5d20d7ba677c74b31
control.go
keep keep keep add keep keep keep keep keep
<mask> if err != nil { <mask> data.WarningValidation = fmt.Sprintf("Invalid certificate or key: %s", err) <mask> return data <mask> } <mask> } <mask> <mask> return data <mask> } <mask> </s> /tls/ -- add internal usable flag to simplify logic when https needs to be booted up </s> remove if data.WarningValidation == "" { </s> add if data.usable { </s> remove if data.WarningValidation != "" { </s> add if !data.usable { </s> add // is usable? set by validator usable bool
https://github.com/AdguardTeam/AdGuardHome/commit/3c374b594000a47bef40c2d5d20d7ba677c74b31
control.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> if err != nil { <mask> return false, fmt.Errorf("couldn't find interface by name %s: %w", ifaceName, err) <mask> } <mask> <mask> // get ipv4 address of an interface <mask> ifaceIPNet := getIfaceIPv4(*iface) <mask> if len(ifaceIPNet) == 0 { <mask> return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) <mask> } <mask> <mask> if runtime.GOOS == "darwin" { </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv4 addresses", ifaceName) </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) } </s> remove return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv6 addresses", ifaceName) </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // get ipv4 address of an interface <mask> ifaceIPNet := getIfaceIPv4(*iface) <mask> if len(ifaceIPNet) == 0 { <mask> return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) <mask> } <mask> <mask> if runtime.GOOS == "darwin" { <mask> return false, fmt.Errorf("can't find DHCP server: not supported on macOS") <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> add // TODO(a.garipov): Find out what this is about. Perhaps this // information is outdated or at least incomplete. </s> remove return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv6 addresses", ifaceName) </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) } </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err) </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep add keep keep keep keep
<mask> return false, fmt.Errorf("interface %s has no ipv4 addresses", ifaceName) <mask> } <mask> <mask> if runtime.GOOS == "darwin" { <mask> return false, fmt.Errorf("can't find DHCP server: not supported on macOS") <mask> } <mask> </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv4 addresses", ifaceName) </s> remove return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv6 addresses", ifaceName) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) } </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep replace replace replace replace replace replace replace replace replace replace keep keep replace
<mask> } <mask> <mask> for { <mask> // wait for answer <mask> log.Tracef("Waiting %v for an answer", defaultDiscoverTime) <mask> // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts <mask> b := make([]byte, 1500) <mask> _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) <mask> n, _, err := c.ReadFrom(b) <mask> if isTimeout(err) { <mask> // timed out -- no DHCP servers <mask> log.Debug("DHCPv4: didn't receive DHCP response") <mask> return false, nil <mask> } <mask> if err != nil { <mask> return false, fmt.Errorf("couldn't receive packet: %w", err) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) continue </s> add b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if err != nil { if isTimeout(err) { log.Debug("dhcpv4: didn't receive dhcp response") return false, false, nil </s> remove log.Tracef("Received packet (%v bytes)", n) </s> add // TODO(a.garipov): Refactor further. Inspect error handling, remove the next // parameter, address the TODO, etc. func tryConn(req *dhcpv4.DHCPv4, c net.PacketConn, iface *net.Interface) (ok, next bool, err error) { // TODO: replicate dhclient's behavior of retrying several times with // progressively longer timeouts. log.Tracef("waiting %v for an answer", defaultDiscoverTime) </s> add } } </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove log.Tracef("The packet is from an active DHCP server") // that's a DHCP server there return true, nil </s> add response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("dhcpv4: encoding: %s", err) return false, true, err
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep add keep keep keep keep keep
<mask> if err != nil { <mask> log.Debug("%s", err) <mask> } <mask> <mask> // TODO(a.garipov): Refactor further. Inspect error handling, remove the next <mask> // parameter, address the TODO, etc. <mask> func tryConn(req *dhcpv4.DHCPv4, c net.PacketConn, iface *net.Interface) (ok, next bool, err error) { <mask> // TODO: replicate dhclient's behavior of retrying several times with </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove log.Tracef("Received packet (%v bytes)", n) </s> add // TODO(a.garipov): Refactor further. Inspect error handling, remove the next // parameter, address the TODO, etc. func tryConn(req *dhcpv4.DHCPv4, c net.PacketConn, iface *net.Interface) (ok, next bool, err error) { // TODO: replicate dhclient's behavior of retrying several times with // progressively longer timeouts. log.Tracef("waiting %v for an answer", defaultDiscoverTime) </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove // Get IPv6 address list func getIfaceIPv6(iface net.Interface) []net.IP { </s> add // ifaceIPv6Addrs returns the interface's IPv6 addresses. func ifaceIPv6Addrs(iface *net.Interface) (ips []net.IP, err error) { </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove return res </s> add return ips, nil </s> remove // Start - start server </s> add // Start starts the IPv6 DHCP server.
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep replace keep replace replace replace replace keep
<mask> return false, fmt.Errorf("couldn't receive packet: %w", err) <mask> } <mask> <mask> log.Tracef("Received packet (%v bytes)", n) <mask> <mask> response, err := dhcpv4.FromBytes(b[:n]) <mask> if err != nil { <mask> log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) <mask> continue <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return false, fmt.Errorf("couldn't receive packet: %w", err) </s> add log.Debug("%s", err) </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove log.Tracef("The packet is from an active DHCP server") // that's a DHCP server there return true, nil </s> add response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("dhcpv4: encoding: %s", err) return false, true, err </s> remove log.Debug("DHCPv4: received message from server: %s", response.Summary()) </s> add return false, false, fmt.Errorf("receiving packet: %w", err) } </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) }
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep replace keep replace replace replace replace replace replace replace replace keep keep
<mask> continue <mask> } <mask> <mask> log.Debug("DHCPv4: received message from server: %s", response.Summary()) <mask> <mask> if !(response.OpCode == dhcpv4.OpcodeBootReply && <mask> response.HWType == iana.HWTypeEthernet && <mask> bytes.Equal(response.ClientHWAddr, iface.HardwareAddr) && <mask> bytes.Equal(response.TransactionID[:], req.TransactionID[:]) && <mask> response.Options.Has(dhcpv4.OptionDHCPMessageType)) { <mask> log.Debug("DHCPv4: received message from server doesn't match our request") <mask> continue <mask> } <mask> <mask> log.Tracef("The packet is from an active DHCP server") </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove log.Tracef("The packet is from an active DHCP server") // that's a DHCP server there return true, nil </s> add response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("dhcpv4: encoding: %s", err) return false, true, err </s> remove response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) continue </s> add b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if err != nil { if isTimeout(err) { log.Debug("dhcpv4: didn't receive dhcp response") return false, false, nil </s> remove func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { </s> add func ip4InRange(start, stop, ip net.IP) bool { </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove return false, fmt.Errorf("couldn't receive packet: %w", err) </s> add log.Debug("%s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> log.Debug("DHCPv4: received message from server doesn't match our request") <mask> continue <mask> } <mask> <mask> log.Tracef("The packet is from an active DHCP server") <mask> // that's a DHCP server there <mask> return true, nil <mask> } <mask> } <mask> <mask> // CheckIfOtherDHCPServersPresentV6 sends a DHCP request to the specified network interface, <mask> // and waits for a response for a period defined by defaultDiscoverTime </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove if !(response.OpCode == dhcpv4.OpcodeBootReply && response.HWType == iana.HWTypeEthernet && bytes.Equal(response.ClientHWAddr, iface.HardwareAddr) && bytes.Equal(response.TransactionID[:], req.TransactionID[:]) && response.Options.Has(dhcpv4.OptionDHCPMessageType)) { log.Debug("DHCPv4: received message from server doesn't match our request") continue } </s> add log.Tracef("received packet, %d bytes", n) </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // Start - start server </s> add // Start starts the IPv6 DHCP server. </s> add case 1: // Some Android devices use 8.8.8.8 if there is no secondary DNS // server. Fix that by setting the secondary DNS address to our // address as well. // // See https://github.com/AdguardTeam/AdGuardHome/issues/1708. log.Debug("dhcpv4: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> remove log.Debug("DHCPv4: received message from server: %s", response.Summary()) </s> add return false, false, fmt.Errorf("receiving packet: %w", err) }
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep keep replace keep keep keep keep keep
<mask> if err != nil { <mask> return false, fmt.Errorf("dhcpv6: net.InterfaceByName: %s: %w", ifaceName, err) <mask> } <mask> <mask> ifaceIPNet := getIfaceIPv6(*iface) <mask> if len(ifaceIPNet) == 0 { <mask> return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) <mask> } <mask> <mask> srcIP := ifaceIPNet[0] </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv6 addresses", ifaceName) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv4 addresses", ifaceName) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> ifaceIPNet := getIfaceIPv6(*iface) <mask> if len(ifaceIPNet) == 0 { <mask> return false, fmt.Errorf("dhcpv6: couldn't find IPv6 address of interface %s %+v", ifaceName, iface) <mask> } <mask> <mask> srcIP := ifaceIPNet[0] <mask> src := net.JoinHostPort(srcIP.String(), "546") <mask> dst := "[ff02::1:2]:547" </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) } </s> remove return false, fmt.Errorf("couldn't find IPv4 address of interface %s %+v", ifaceName, iface) </s> add return false, fmt.Errorf("interface %s has no ipv4 addresses", ifaceName) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/check_other_dhcp.go
keep keep keep keep replace keep keep keep keep keep
<mask> othSrv := map[string]interface{}{} <mask> foundVal := "no" <mask> if found4 { <mask> foundVal = "yes" <mask> } else if err != nil { <mask> foundVal = "error" <mask> othSrv["error"] = err4.Error() <mask> } <mask> othSrv["found"] = foundVal <mask> v4["other_server"] = othSrv </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove if ipnet.IP.To4() == nil { res = append(res, ipnet.IP) </s> add if ip := ipnet.IP.To16(); ip != nil { ips = append(ips, ip) </s> remove var res []net.IP </s> add </s> remove response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) continue </s> add b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if err != nil { if isTimeout(err) { log.Debug("dhcpv4: didn't receive dhcp response") return false, false, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/dhcp_http.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> } <mask> return operr.Timeout() <mask> } <mask> <mask> // Get IPv4 address list <mask> func getIfaceIPv4(iface net.Interface) []net.IP { <mask> addrs, err := iface.Addrs() <mask> if err != nil { <mask> return nil <mask> } <mask> <mask> var res []net.IP <mask> for _, a := range addrs { <mask> ipnet, ok := a.(*net.IPNet) <mask> if !ok { <mask> continue <mask> } <mask> if ipnet.IP.To4() != nil { <mask> res = append(res, ipnet.IP.To4()) <mask> } <mask> } <mask> return res <mask> } <mask> <mask> func parseIPv4(text string) (net.IP, error) { <mask> result := net.ParseIP(text) <mask> if result == nil { <mask> return nil, fmt.Errorf("%s is not an IP address", text) <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return nil </s> add return nil, err </s> remove var res []net.IP </s> add </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove if ipnet.IP.To4() == nil { res = append(res, ipnet.IP) </s> add if ip := ipnet.IP.To16(); ip != nil { ips = append(ips, ip) </s> remove // Get IPv6 address list func getIfaceIPv6(iface net.Interface) []net.IP { </s> add // ifaceIPv6Addrs returns the interface's IPv6 addresses. func ifaceIPv6Addrs(iface *net.Interface) (ips []net.IP, err error) { </s> remove return res </s> add return ips, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/helpers.go
keep keep keep keep replace keep keep keep keep keep
<mask> func (s *v4Server) WriteDiskConfig6(c *V6ServerConf) { <mask> } <mask> <mask> // Return TRUE if IP address is within range [start..stop] <mask> func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { <mask> if len(start) != 4 || len(stop) != 4 { <mask> return false <mask> } <mask> from := binary.BigEndian.Uint32(start) <mask> to := binary.BigEndian.Uint32(stop) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove func (s *v4Server) processRequest(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> add func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove return nil </s> add return nil, err </s> remove if ipnet.IP.To4() == nil { res = append(res, ipnet.IP) </s> add if ip := ipnet.IP.To16(); ip != nil { ips = append(ips, ip) </s> remove func (s *v4Server) processDiscover(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) *Lease { </s> add func (s *v4Server) processDiscover(req, resp *dhcpv4.DHCPv4) *Lease {
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep keep keep
<mask> s.conf.notify(LeaseChangedAdded) <mask> } <mask> <mask> // Process Discover request and return lease <mask> func (s *v4Server) processDiscover(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) *Lease { <mask> mac := req.ClientHWAddr <mask> <mask> s.leasesLock.Lock() <mask> defer s.leasesLock.Unlock() <mask> </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove func (s *v4Server) processRequest(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> add func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> remove func (s *v4Server) process(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) int { </s> add func (s *v4Server) process(req, resp *dhcpv4.DHCPv4) int { </s> remove func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { </s> add func ip4InRange(start, stop, ip net.IP) bool { </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove log.Tracef("The packet is from an active DHCP server") // that's a DHCP server there return true, nil </s> add response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("dhcpv4: encoding: %s", err) return false, true, err </s> remove // Start - start server </s> add // Start starts the IPv6 DHCP server.
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep keep keep
<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 *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) (*Lease, bool) { <mask> var lease *Lease <mask> mac := req.ClientHWAddr <mask> hostname := req.Options.Get(dhcpv4.OptionHostName) <mask> reqIP := req.Options.Get(dhcpv4.OptionRequestedIPAddress) <mask> if reqIP == nil { </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove func (s *v4Server) processDiscover(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) *Lease { </s> add func (s *v4Server) processDiscover(req, resp *dhcpv4.DHCPv4) *Lease { </s> remove func (s *v4Server) process(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) int { </s> add func (s *v4Server) process(req, resp *dhcpv4.DHCPv4) int { </s> remove func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { </s> add func ip4InRange(start, stop, ip net.IP) bool { </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove return nil </s> add return nil, err
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep keep keep
<mask> // Find a lease associated with MAC and prepare response <mask> // Return 1: OK <mask> // Return 0: error; reply with Nak <mask> // Return -1: error; don't reply <mask> func (s *v4Server) process(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) int { <mask> var lease *Lease <mask> <mask> resp.UpdateOption(dhcpv4.OptServerIdentifier(s.conf.dnsIPAddrs[0])) <mask> <mask> switch req.MessageType() { </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove func (s *v4Server) processRequest(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> add func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> remove func (s *v4Server) processDiscover(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) *Lease { </s> add func (s *v4Server) processDiscover(req, resp *dhcpv4.DHCPv4) *Lease { </s> remove func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { </s> add func ip4InRange(start, stop, ip net.IP) bool { </s> add } } </s> remove log.Tracef("Received packet (%v bytes)", n) </s> add // TODO(a.garipov): Refactor further. Inspect error handling, remove the next // parameter, address the TODO, etc. func tryConn(req *dhcpv4.DHCPv4, c net.PacketConn, iface *net.Interface) (ok, next bool, err error) { // TODO: replicate dhclient's behavior of retrying several times with // progressively longer timeouts. log.Tracef("waiting %v for an answer", defaultDiscoverTime) </s> remove log.Tracef("The packet is from an active DHCP server") // that's a DHCP server there return true, nil </s> add response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("dhcpv4: encoding: %s", err) return false, true, err
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep keep keep
<mask> return <mask> } <mask> } <mask> <mask> // Start - start server <mask> func (s *v4Server) Start() error { <mask> if !s.conf.Enabled { <mask> return nil <mask> } <mask> </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // Start - start server </s> add // Start starts the IPv6 DHCP server. </s> remove return res </s> add return ips, nil </s> remove func (s *v4Server) processRequest(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> add func (s *v4Server) processRequest(req, resp *dhcpv4.DHCPv4) (*Lease, bool) { </s> remove func (s *v4Server) processDiscover(req *dhcpv4.DHCPv4, resp *dhcpv4.DHCPv4) *Lease { </s> add func (s *v4Server) processDiscover(req, resp *dhcpv4.DHCPv4) *Lease { </s> remove func ip4InRange(start net.IP, stop net.IP, ip net.IP) bool { </s> add func ip4InRange(start, stop, ip net.IP) bool { </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep keep keep
<mask> if !s.conf.Enabled { <mask> return nil <mask> } <mask> <mask> iface, err := net.InterfaceByName(s.conf.InterfaceName) <mask> if err != nil { <mask> return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) <mask> } <mask> <mask> log.Debug("dhcpv4: starting...") </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) }
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep keep replace keep keep keep replace replace replace keep
<mask> } <mask> <mask> iface, err := net.InterfaceByName(s.conf.InterfaceName) <mask> if err != nil { <mask> return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) <mask> } <mask> <mask> log.Debug("dhcpv4: starting...") <mask> s.conf.dnsIPAddrs = getIfaceIPv4(*iface) <mask> if len(s.conf.dnsIPAddrs) == 0 { <mask> log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) <mask> return nil </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) }
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep add keep keep keep keep keep keep
<mask> case 0: <mask> log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) <mask> <mask> return nil <mask> } <mask> <mask> s.conf.dnsIPAddrs = dnsIPAddrs <mask> <mask> laddr := &net.UDPAddr{ <mask> IP: net.ParseIP("0.0.0.0"), </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) </s> add s.conf.dnsIPAddrs = dnsIPAddrs </s> add case 1: // See the comment in (*v4Server).Start. log.Debug("dhcpv6: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep add keep keep keep keep keep
<mask> default: <mask> // Go on. <mask> } <mask> <mask> laddr := &net.UDPAddr{ <mask> IP: net.ParseIP("0.0.0.0"), <mask> Port: dhcpv4.ServerPort, <mask> } <mask> s.srv, err = server4.NewServer(iface.Name, laddr, s.packetHandler, server4.WithDebugLogger()) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> add case 1: // Some Android devices use 8.8.8.8 if there is no secondary DNS // server. Fix that by setting the secondary DNS address to our // address as well. // // See https://github.com/AdguardTeam/AdGuardHome/issues/1708. log.Debug("dhcpv4: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> add s.conf.dnsIPAddrs = dnsIPAddrs </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) </s> add case 1: // See the comment in (*v4Server).Start. log.Debug("dhcpv6: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // Get IPv6 address list func getIfaceIPv6(iface net.Interface) []net.IP { </s> add // ifaceIPv6Addrs returns the interface's IPv6 addresses. func ifaceIPv6Addrs(iface *net.Interface) (ips []net.IP, err error) {
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v4.go
keep keep keep replace replace keep keep replace keep
<mask> } <mask> } <mask> <mask> // Get IPv6 address list <mask> func getIfaceIPv6(iface net.Interface) []net.IP { <mask> addrs, err := iface.Addrs() <mask> if err != nil { <mask> return nil <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove var res []net.IP </s> add </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) } </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> if err != nil { <mask> return nil <mask> } <mask> <mask> var res []net.IP <mask> for _, a := range addrs { <mask> ipnet, ok := a.(*net.IPNet) <mask> if !ok { <mask> continue <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove return nil </s> add return nil, err </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove if ipnet.IP.To4() == nil { res = append(res, ipnet.IP) </s> add if ip := ipnet.IP.To16(); ip != nil { ips = append(ips, ip) </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // wait for answer log.Tracef("Waiting %v for an answer", defaultDiscoverTime) // TODO: replicate dhclient's behaviour of retrying several times with progressively bigger timeouts b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if isTimeout(err) { // timed out -- no DHCP servers log.Debug("DHCPv4: didn't receive DHCP response") return false, nil </s> add ok, next, err := tryConn(req, c, iface) if next { continue } if ok { return true, nil </s> remove response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) continue </s> add b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if err != nil { if isTimeout(err) { log.Debug("dhcpv4: didn't receive dhcp response") return false, false, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep replace replace keep keep replace
<mask> if !ok { <mask> continue <mask> } <mask> if ipnet.IP.To4() == nil { <mask> res = append(res, ipnet.IP) <mask> } <mask> } <mask> return res </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove var res []net.IP </s> add </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove return nil </s> add return nil, err </s> remove response, err := dhcpv4.FromBytes(b[:n]) if err != nil { log.Debug("DHCPv4: dhcpv4.FromBytes: %s", err) continue </s> add b := make([]byte, 1500) _ = c.SetReadDeadline(time.Now().Add(defaultDiscoverTime)) n, _, err := c.ReadFrom(b) if err != nil { if isTimeout(err) { log.Debug("dhcpv4: didn't receive dhcp response") return false, false, nil
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> s.ra.packetSendPeriod = 1 * time.Second <mask> return s.ra.Init() <mask> } <mask> <mask> // Start - start server <mask> func (s *v6Server) Start() error { <mask> if !s.conf.Enabled { <mask> return nil <mask> } <mask> </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove return res </s> add return ips, nil </s> remove // Get IPv4 address list func getIfaceIPv4(iface net.Interface) []net.IP { addrs, err := iface.Addrs() if err != nil { return nil } var res []net.IP for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ipnet.IP.To4() != nil { res = append(res, ipnet.IP.To4()) } } return res } </s> add </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove // Get IPv6 address list func getIfaceIPv6(iface net.Interface) []net.IP { </s> add // ifaceIPv6Addrs returns the interface's IPv6 addresses. func ifaceIPv6Addrs(iface *net.Interface) (ips []net.IP, err error) {
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> if !s.conf.Enabled { <mask> return nil <mask> } <mask> <mask> iface, err := net.InterfaceByName(s.conf.InterfaceName) <mask> if err != nil { <mask> return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) <mask> } <mask> <mask> s.conf.dnsIPAddrs = getIfaceIPv6(*iface) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err) </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep replace keep keep replace replace replace keep keep keep keep
<mask> if err != nil { <mask> return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) <mask> } <mask> <mask> s.conf.dnsIPAddrs = getIfaceIPv6(*iface) <mask> if len(s.conf.dnsIPAddrs) == 0 { <mask> log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) <mask> return nil <mask> } <mask> <mask> err = s.initRA(iface) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) </s> remove return fmt.Errorf("dhcpv4: Couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err) </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface) </s> remove // get ipv4 address of an interface ifaceIPNet := getIfaceIPv4(*iface) </s> add ifaceIPNet, err := ifaceIPv4Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv4 addrs for iface %s: %w", ifaceName, err) } </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep add keep keep keep keep keep
<mask> case 0: <mask> log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) <mask> <mask> return nil <mask> } <mask> <mask> s.conf.dnsIPAddrs = dnsIPAddrs <mask> <mask> err = s.initRA(iface) </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> add case 1: // Some Android devices use 8.8.8.8 if there is no secondary DNS // server. Fix that by setting the secondary DNS address to our // address as well. // // See https://github.com/AdguardTeam/AdGuardHome/issues/1708. log.Debug("dhcpv4: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> remove s.conf.dnsIPAddrs = getIfaceIPv4(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("dhcpv4: no IPv6 address for interface %s", iface.Name) </s> add dnsIPAddrs, err := ifaceIPv4Addrs(iface) if err != nil { return fmt.Errorf("dhcpv4: getting ipv4 addrs for iface %s: %w", ifaceName, err) } switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv4: no ipv4 address for interface %s", iface.Name) </s> remove return fmt.Errorf("couldn't find interface by name %s: %w", s.conf.InterfaceName, err) </s> add return fmt.Errorf("dhcpv6: getting ipv6 addrs for iface %s: %w", ifaceName, err) </s> add s.conf.dnsIPAddrs = dnsIPAddrs </s> remove ifaceIPNet := getIfaceIPv6(*iface) </s> add ifaceIPNet, err := ifaceIPv6Addrs(iface) if err != nil { return false, fmt.Errorf("getting ipv6 addrs for iface %s: %w", ifaceName, err) }
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep add keep keep keep keep
<mask> default: <mask> // Go on. <mask> } <mask> <mask> err = s.initRA(iface) <mask> if err != nil { <mask> return err <mask> } </s> Pull request: * dhcpd: send secondary dns as well Merge in DNS/adguard-home from 1708-secondary-dns to master Updates #1708. Squashed commit of the following: commit 4529452e31131763f00c9c834cc95638f1a3d142 Author: Ainar Garipov <[email protected]> Date: Mon Nov 9 18:12:57 2020 +0300 * dhcpd: send secondary dns as well </s> add case 1: // See the comment in (*v4Server).Start. log.Debug("dhcpv6: setting secondary dns ip to iself for interface %s", iface.Name) dnsIPAddrs = append(dnsIPAddrs, dnsIPAddrs[0]) default: // Go on. </s> add s.conf.dnsIPAddrs = dnsIPAddrs </s> remove s.conf.dnsIPAddrs = getIfaceIPv6(*iface) if len(s.conf.dnsIPAddrs) == 0 { log.Debug("DHCPv6: no IPv6 address for interface %s", iface.Name) </s> add switch len(dnsIPAddrs) { case 0: log.Debug("dhcpv6: no ipv6 address for interface %s", iface.Name) </s> remove // Start - start server </s> add // ifaceIPv4Addrs returns the interface's IPv4 addresses. func ifaceIPv4Addrs(iface *net.Interface) (ips []net.IP, err error) { addrs, err := iface.Addrs() if err != nil { return nil, err } for _, a := range addrs { ipnet, ok := a.(*net.IPNet) if !ok { continue } if ip := ipnet.IP.To4(); ip != nil { ips = append(ips, ip) } } return ips, nil } // Start starts the IPv4 DHCP server. </s> remove // Get IPv6 address list func getIfaceIPv6(iface net.Interface) []net.IP { </s> add // ifaceIPv6Addrs returns the interface's IPv6 addresses. func ifaceIPv6Addrs(iface *net.Interface) (ips []net.IP, err error) { </s> remove iface, err := net.InterfaceByName(s.conf.InterfaceName) </s> add ifaceName := s.conf.InterfaceName iface, err := net.InterfaceByName(ifaceName) if err != nil { return fmt.Errorf("dhcpv6: finding interface %s by name: %w", ifaceName, err) } log.Debug("dhcpv4: starting...") dnsIPAddrs, err := ifaceIPv6Addrs(iface)
https://github.com/AdguardTeam/AdGuardHome/commit/3cc5bf210d432ef1c75e25fba8f7bb20d8e213b9
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> if client == nil || serverInfo == nil || (serverInfo != nil && serverInfo.ServerCert.NotAfter < now) { <mask> p.Lock() <mask> <mask> // Using "udp" for DNSCrypt upstreams by default <mask> client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} <mask> si, _, err := client.Dial(p.boot.address) <mask> <mask> if err != nil { <mask> p.Unlock() <mask> return nil, errorx.Decorate(err, "Failed to fetch certificate info from %s", p.Address()) </s> upgrade dnscrypt client to v1.0.0 </s> add golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb h1:zzdd4xkMwu/GRxhSUJaCPh4/jil9kAbsU7AUmXboO+A= golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 h1:iCzOf0xz39Tstp+Tu/WwyGjUXCk34QhQORRxBeXXTA4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= </s> add github.com/ameshkov/dnscrypt v1.0.0 h1:Y7YexPCxtVCTDXlXu9n17+1H5YS25vftx8vV8Dhuu+E= github.com/ameshkov/dnscrypt v1.0.0/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= </s> remove golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb // indirect </s> remove github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f </s> add github.com/ameshkov/dnscrypt v1.0.0
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
dnsforward/upstream.go
keep keep keep keep replace keep keep keep keep keep
<mask> module github.com/AdguardTeam/AdGuardHome <mask> <mask> require ( <mask> github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect <mask> github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f <mask> github.com/beefsack/go-rate v0.0.0-20180408011153-efa7637bb9b6 <mask> github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7 <mask> github.com/go-ole/go-ole v1.2.1 // indirect <mask> github.com/go-test/deep v1.0.1 <mask> github.com/gobuffalo/packr v1.19.0 </s> upgrade dnscrypt client to v1.0.0 </s> add github.com/ameshkov/dnscrypt v1.0.0 h1:Y7YexPCxtVCTDXlXu9n17+1H5YS25vftx8vV8Dhuu+E= github.com/ameshkov/dnscrypt v1.0.0/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= </s> remove golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb // indirect </s> add golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb h1:zzdd4xkMwu/GRxhSUJaCPh4/jil9kAbsU7AUmXboO+A= golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 h1:iCzOf0xz39Tstp+Tu/WwyGjUXCk34QhQORRxBeXXTA4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= </s> remove client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} </s> add client = &dnscrypt.Client{Timeout: defaultTimeout, AdjustPayloadSize: true}
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
go.mod
keep keep keep keep replace keep keep keep
<mask> github.com/shirou/gopsutil v2.18.10+incompatible <mask> github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect <mask> go.uber.org/goleak v0.10.0 <mask> golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 <mask> golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 <mask> gopkg.in/asaskevich/govalidator.v4 v4.0.0-20160518190739-766470278477 <mask> gopkg.in/yaml.v2 v2.2.1 <mask> ) </s> upgrade dnscrypt client to v1.0.0 </s> add golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb h1:zzdd4xkMwu/GRxhSUJaCPh4/jil9kAbsU7AUmXboO+A= golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 h1:iCzOf0xz39Tstp+Tu/WwyGjUXCk34QhQORRxBeXXTA4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= </s> remove github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f </s> add github.com/ameshkov/dnscrypt v1.0.0 </s> add github.com/ameshkov/dnscrypt v1.0.0 h1:Y7YexPCxtVCTDXlXu9n17+1H5YS25vftx8vV8Dhuu+E= github.com/ameshkov/dnscrypt v1.0.0/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= </s> remove client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} </s> add client = &dnscrypt.Client{Timeout: defaultTimeout, AdjustPayloadSize: true}
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
go.mod
keep keep add keep keep keep keep keep
<mask> github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us= <mask> github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f h1:vOaSvI9B3wqzV1g8raDeVzRJnq5RHQxsz0MVXudxdNU= <mask> github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= <mask> github.com/beefsack/go-rate v0.0.0-20180408011153-efa7637bb9b6 h1:KXlsf+qt/X5ttPGEjR0tPH1xaWWoKBEg9Q1THAj2h3I= <mask> github.com/beefsack/go-rate v0.0.0-20180408011153-efa7637bb9b6/go.mod h1:6YNgTHLutezwnBvyneBbwvB8C82y3dcoOj5EQJIdGXA= <mask> github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7 h1:NpQ+gkFOH27AyDypSCJ/LdsIi/b4rdnEb1N5+IpFfYs= <mask> github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7/go.mod h1:8c4/i2VlovMO2gBnHGQPN5EJw+H0lx1u/5p+cgsXtCk= <mask> github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= </s> upgrade dnscrypt client to v1.0.0 </s> remove github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f </s> add github.com/ameshkov/dnscrypt v1.0.0 </s> add golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb h1:zzdd4xkMwu/GRxhSUJaCPh4/jil9kAbsU7AUmXboO+A= golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 h1:iCzOf0xz39Tstp+Tu/WwyGjUXCk34QhQORRxBeXXTA4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= </s> remove golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb // indirect </s> remove client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} </s> add client = &dnscrypt.Client{Timeout: defaultTimeout, AdjustPayloadSize: true}
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
go.sum
keep add keep keep keep keep keep
<mask> golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 h1:gT0Y6H7hbVPUtvtk0YGxMXPgN+p8fYlqWkgJeUCZcaQ= <mask> golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= <mask> golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= <mask> golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= <mask> golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= <mask> golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= <mask> golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 h1:0oC8rFnE+74kEmuHZ46F6KHsMr5Gx2gUQPuNz28iQZM= </s> upgrade dnscrypt client to v1.0.0 </s> remove golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb // indirect </s> add golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb h1:zzdd4xkMwu/GRxhSUJaCPh4/jil9kAbsU7AUmXboO+A= golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= </s> add github.com/ameshkov/dnscrypt v1.0.0 h1:Y7YexPCxtVCTDXlXu9n17+1H5YS25vftx8vV8Dhuu+E= github.com/ameshkov/dnscrypt v1.0.0/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= </s> remove github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f </s> add github.com/ameshkov/dnscrypt v1.0.0 </s> remove client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} </s> add client = &dnscrypt.Client{Timeout: defaultTimeout, AdjustPayloadSize: true}
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
go.sum
keep add keep keep keep keep keep
<mask> golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 h1:0oC8rFnE+74kEmuHZ46F6KHsMr5Gx2gUQPuNz28iQZM= <mask> golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= <mask> gopkg.in/asaskevich/govalidator.v4 v4.0.0-20160518190739-766470278477 h1:5xUJw+lg4zao9W4HIDzlFbMYgSgtvNVHh00MEHvbGpQ= <mask> gopkg.in/asaskevich/govalidator.v4 v4.0.0-20160518190739-766470278477/go.mod h1:QDV1vrFSrowdoOba0UM8VJPUZONT7dnfdLsM+GG53Z8= <mask> gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= <mask> gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= <mask> gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= </s> upgrade dnscrypt client to v1.0.0 </s> remove golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 golang.org/x/sys v0.0.0-20181217223516-dcdaa6325bcb // indirect </s> add golang.org/x/net v0.0.0-20181217023233-e147a9138326 h1:iCzOf0xz39Tstp+Tu/WwyGjUXCk34QhQORRxBeXXTA4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= </s> add github.com/ameshkov/dnscrypt v1.0.0 h1:Y7YexPCxtVCTDXlXu9n17+1H5YS25vftx8vV8Dhuu+E= github.com/ameshkov/dnscrypt v1.0.0/go.mod h1:EC7Z1GguyEEwhuLXrcgkRTE3GdyPDSWq2OXefhydGWo= </s> remove github.com/ameshkov/dnscrypt v0.0.0-20181217090431-1215bb8b150f </s> add github.com/ameshkov/dnscrypt v1.0.0 </s> remove client = &dnscrypt.Client{Proto: "udp", Timeout: defaultTimeout} </s> add client = &dnscrypt.Client{Timeout: defaultTimeout, AdjustPayloadSize: true}
https://github.com/AdguardTeam/AdGuardHome/commit/3d179079661e3c97041a8448ec3aecea40199032
go.sum
keep keep keep add keep keep keep keep keep keep
<mask> log.Debug("Clients: set WHOIS info for auto-client %s: %v", ch.Host, ch.WhoisInfo) <mask> return <mask> } <mask> <mask> ch = &ClientHost{ <mask> Source: ClientSourceWHOIS, <mask> } <mask> ch.WhoisInfo = info <mask> clients.ipHost[ip] = ch <mask> log.Debug("Clients: set WHOIS info for auto-client with IP %s: %v", ip, ch.WhoisInfo) </s> -: add one more test </s> add // don't allow duplicates by CIDR ok, err = clients.AddHost("2.2.2.2", "test", ClientSourceRDNS) assert.False(t, ok) assert.Nil(t, err) </s> remove IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa"}, </s> add IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa", "2.2.2.0/24"},
https://github.com/AdguardTeam/AdGuardHome/commit/3dd91cf17962b4b5d39f31424adeeab579416666
home/clients.go
keep keep keep keep replace keep keep keep keep keep
<mask> testIP := "1.2.3.4" <mask> <mask> // add a client <mask> c = Client{ <mask> IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa"}, <mask> Name: "client1", <mask> } <mask> ok, err := clients.Add(c) <mask> assert.True(t, ok) <mask> assert.Nil(t, err) </s> -: add one more test </s> add // don't allow duplicates by CIDR ok, err = clients.AddHost("2.2.2.2", "test", ClientSourceRDNS) assert.False(t, ok) assert.Nil(t, err) </s> add // Create a ClientHost implicitly so that we don't do this check again
https://github.com/AdguardTeam/AdGuardHome/commit/3dd91cf17962b4b5d39f31424adeeab579416666
home/clients_test.go
keep keep keep add keep
<mask> // try adding a duplicate IP which for a Mac-based client <mask> ok, err = clients.AddHost(testIP, "test", ClientSourceRDNS) <mask> assert.False(t, ok) <mask> assert.Nil(t, err) <mask> } </s> -: add one more test </s> remove IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa"}, </s> add IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa", "2.2.2.0/24"}, </s> add // Create a ClientHost implicitly so that we don't do this check again
https://github.com/AdguardTeam/AdGuardHome/commit/3dd91cf17962b4b5d39f31424adeeab579416666
home/clients_test.go
keep keep keep add keep keep keep keep keep
<mask> // Package dnsforward contains a DNS forwarding server. <mask> package dnsforward <mask> <mask> import ( <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "os" <mask> "runtime" </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add "os" </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err) </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one. </s> add var err error </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> remove var err error </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/dnsforward.go
keep keep keep add keep keep keep keep keep keep
<mask> "errors" <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "runtime" <mask> "sync" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" <mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add "errors" </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> remove var err error </s> add </s> add log.Debug("ipset: no ipsets for host %s", host) </s> add log.Debug("ipset: starting processing") </s> add var err error
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/dnsforward.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> // Initialize IPSET configuration <mask> // -- <mask> err := s.ipset.init(s.conf.IPSETList) <mask> if err != nil { <mask> // ipset cannot be initialized in a Snap version (and maybe - without root) <mask> // this needs to be handled properly <mask> // TODO: Handle this properly <mask> log.Info("Cannot initialize ipset module due to %v", err) <mask> } <mask> <mask> // Prepare DNS servers settings <mask> // -- <mask> err = s.prepareUpstreamSettings() </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one. </s> add var err error </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> add "errors" </s> remove var err error </s> add </s> add log.Debug("ipset: no ipsets for host %s", host)
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/dnsforward.go
keep keep add keep keep keep keep
<mask> nameToIpset map[string]ipsetProps <mask> domainToIpsets map[string][]ipsetProps <mask> <mask> addedIPs map[[16]byte]struct{} <mask> <mask> ipv4Conn *ipset.Conn <mask> ipv6Conn *ipset.Conn </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> remove var err error </s> add </s> add log.Debug("ipset: no ipsets for host %s", host) </s> add log.Debug("ipset: starting processing") </s> add var err error </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep keep add keep keep keep keep
<mask> <mask> // process adds the resolved IP addresses to the domain's ipsets, if any. <mask> func (c *ipsetCtx) process(ctx *dnsContext) (rc resultCode) { <mask> if c == nil { <mask> return resultCodeSuccess <mask> } <mask> </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err) </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one. </s> add log.Debug("ipset: no ipsets for host %s", host) </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> add log.Debug("ipset: starting processing") </s> remove var err error </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep add keep keep keep keep keep
<mask> } <mask> <mask> c.mu.Lock() <mask> defer c.mu.Unlock() <mask> <mask> if c.skipIpsetProcessing(ctx) { <mask> log.Debug("ipset: skipped processing for request") </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add log.Debug("ipset: no ipsets for host %s", host) </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> add var err error </s> remove var err error </s> add </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err) </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one.
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep keep keep add keep keep keep keep keep
<mask> host = strings.TrimSuffix(host, ".") <mask> host = strings.ToLower(host) <mask> sets := c.lookupHost(host) <mask> if len(sets) == 0 { <mask> return resultCodeSuccess <mask> } <mask> <mask> log.Debug("ipset: found ipsets %+v for host %s", sets, host) <mask> </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> remove var err error </s> add </s> add var err error </s> add log.Debug("ipset: starting processing") </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one. </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> v4s = append(v4s, ip) <mask> } <mask> <mask> var err error <mask> setLoop: <mask> for _, set := range sets { <mask> switch set.family { <mask> case netfilter.ProtoIPv4: <mask> err = c.addIPs(host, set, v4s) </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add } else { log.Debug("ipset: processed %d new ips", len(v4s)+len(v6s)) } for _, ip := range v4s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} } for _, ip := range v6s { var iparr [16]byte copy(iparr[:], ip.To16()) c.addedIPs[iparr] = struct{}{} </s> add var err error </s> add log.Debug("ipset: no ipsets for host %s", host) </s> add log.Debug("ipset: starting processing") </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err) </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one.
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep keep add keep keep keep keep
<mask> } <mask> if err != nil { <mask> log.Error("ipset: adding host ips: %s", err) <mask> } <mask> <mask> return resultCodeSuccess <mask> } </s> Pull request: dnsforward: imp ipset caching, logging, and eperm handling Merge in DNS/adguard-home from ipset-fix to master Updates #2619. Squashed commit of the following: commit 6939c823598b1e74cb3d991aad1b928547fd26a9 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 16:55:14 2021 +0300 dnsforward: imp code commit 99e3a7c30b79d7929ddd9b700d7dd3d2683ec6d2 Author: Ainar Garipov <[email protected]> Date: Mon Feb 1 15:52:12 2021 +0300 dnsforward: imp ipset caching, logging, and eperm handling </s> add log.Debug("ipset: no ipsets for host %s", host) </s> remove // ipset cannot be initialized in a Snap version (and maybe - without root) // this needs to be handled properly // TODO: Handle this properly log.Info("Cannot initialize ipset module due to %v", err) </s> add if !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions. // // Log and go on. log.Error("cannot initialize ipset: %s", err) </s> add var err error </s> add log.Debug("ipset: starting processing") </s> remove var err error </s> add </s> add // TODO(a.garipov): Currently, the ipset list is static, and we don't // read the IPs already in sets, so we can assume that all incoming IPs // are either added to all corresponding ipsets or not. When that stops // being the case, for example if we add dynamic reconfiguration of // ipsets, this map will need to become a per-ipset-name one.
https://github.com/AdguardTeam/AdGuardHome/commit/3e0238aa99c18fe5eae1a4a122f43daf8918bd75
internal/dnsforward/ipset_linux.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> // Respond with results <mask> func (s *Server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) <mask> if err != nil { <mask> errorText := fmt.Sprintf("failed to read request body: %s", err) <mask> log.Error(errorText) <mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> <mask> interfaceName := strings.TrimSpace(string(body)) <mask> if interfaceName == "" { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty interface name specified") log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> remove errorText := fmt.Sprintf("empty language specified") log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("unknown language specified: %s", language) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/dhcp_http.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> interfaceName := strings.TrimSpace(string(body)) <mask> if interfaceName == "" { <mask> errorText := fmt.Sprintf("empty interface name specified") <mask> log.Error(errorText) <mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> <mask> found4, err4 := CheckIfOtherDHCPServersPresentV4(interfaceName) <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("empty language specified") log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("unknown language specified: %s", language) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/dhcp_http.go
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
<mask> <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func check(t *testing.T, result bool, msg string) { <mask> if !result { <mask> t.Fatal(msg) <mask> } <mask> } <mask> <mask> func testNotify(flags uint32) { <mask> } <mask> <mask> // Leases database store/load <mask> func TestDB(t *testing.T) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove if err != nil { return false } return true </s> add return err == nil
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/dhcpd_test.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> // ServerPort is the port that DHCP servers and relay agents listen on. <mask> ServerPort = 67 <mask> ) <mask> <mask> var ( <mask> // DefaultServers is the address of all link-local DHCP servers and <mask> // relay agents. <mask> DefaultServers = &net.UDPAddr{ <mask> IP: net.IPv4bcast, <mask> Port: ServerPort, <mask> } <mask> ) <mask> <mask> var ( <mask> // ErrNoResponse is returned when no response packet is received. <mask> ErrNoResponse = errors.New("no matching response packet received") <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove func Main(version string, channel string, armVer string) { </s> add func Main(version, channel, armVer string) { </s> remove // nolint func withBufferCap(n int) ClientOpt { return func(c *Client) (err error) { c.bufferCap = n return } } </s> add </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/nclient4/client.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> return <mask> } <mask> } <mask> <mask> // nolint <mask> func withBufferCap(n int) ClientOpt { <mask> return func(c *Client) (err error) { <mask> c.bufferCap = n <mask> return <mask> } <mask> } <mask> <mask> // WithRetry configures the number of retransmissions to attempt. <mask> // <mask> // Default is 3. <mask> func WithRetry(r int) ClientOpt { <mask> return func(c *Client) (err error) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> add func withBufferCap(n int) ClientOpt { return func(c *Client) (err error) { c.bufferCap = n return } } </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/nclient4/client.go
keep keep keep add keep keep keep keep keep
<mask> p.ClientHWAddr = net.HardwareAddr{0xa, 0xb, 0xc, 0xd, 0xe, 0xf} <mask> return p <mask> } <mask> <mask> func TestSendAndRead(t *testing.T) { <mask> for _, tt := range []struct { <mask> desc string <mask> send *dhcpv4.DHCPv4 <mask> server []*dhcpv4.DHCPv4 </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err) </s> remove for _, it := range u.nResult { udb.NResult = append(udb.NResult, it) } </s> add udb.NResult = append(udb.NResult, u.nResult...)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/nclient4/client_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> if err != nil { <mask> return nil <mask> } <mask> <mask> m := make(map[string]string, 0) <mask> <mask> matches := re.FindAllStringSubmatch(out, -1) <mask> for i := range matches { <mask> port := matches[i][1] <mask> device := matches[i][2] </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove units := []*unitDB{} //per-hour units </s> add // Per-hour units. units := []*unitDB{} </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects. </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/network_utils.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> // Return TRUE if IP address is within range [start..0xff] <mask> // nolint(staticcheck) <mask> func ip6InRange(start net.IP, ip net.IP) bool { <mask> if len(start) != 16 { <mask> return false <mask> } <mask> //lint:ignore SA1021 TODO(e.burkov): Ignore this for now, think about using masks. <mask> if !bytes.Equal(start[:15], ip[:15]) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists. </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove var ip string ip = <-w.ipChan </s> add ip := <-w.ipChan </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> case dhcpv6.MessageTypeSolicit: <mask> // <mask> <mask> case dhcpv6.MessageTypeConfirm: <mask> lifetime = lease.Expiry.Sub(time.Now()) <mask> <mask> case dhcpv6.MessageTypeRequest, <mask> dhcpv6.MessageTypeRenew, <mask> dhcpv6.MessageTypeRebind: <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (s *v6Server) process(msg *dhcpv6.Message, req dhcpv6.DHCPv6, resp dhcpv6.DHCPv6) bool { </s> add func (s *v6Server) process(msg *dhcpv6.Message, req, resp dhcpv6.DHCPv6) bool { </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event </s> remove // skip duplicate events </s> add </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove for { select { case t := <-ticker.C: t.Second() log.Debug("Free OS memory") debug.FreeOSMemory() } </s> add for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory() </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> return lifetime <mask> } <mask> <mask> // Find a lease associated with MAC and prepare response <mask> func (s *v6Server) process(msg *dhcpv6.Message, req dhcpv6.DHCPv6, resp dhcpv6.DHCPv6) bool { <mask> switch msg.Type() { <mask> case dhcpv6.MessageTypeSolicit, <mask> dhcpv6.MessageTypeRequest, <mask> dhcpv6.MessageTypeConfirm, <mask> dhcpv6.MessageTypeRenew, </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove lifetime = lease.Expiry.Sub(time.Now()) </s> add lifetime = time.Until(lease.Expiry) </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove var ip string ip = <-w.ipChan </s> add ip := <-w.ipChan
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dhcpd/v6.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // SetFilters - set new filters (synchronously or asynchronously) <mask> // When filters are set asynchronously, the old filters continue working until the new filters are ready. <mask> // In this case the caller must ensure that the old filter files are intact. <mask> func (d *Dnsfilter) SetFilters(blockFilters []Filter, allowFilters []Filter, async bool) error { <mask> if async { <mask> params := filtersInitializerParams{ <mask> allowFilters: allowFilters, <mask> blockFilters: blockFilters, <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove for { select { case t := <-ticker.C: t.Second() log.Debug("Free OS memory") debug.FreeOSMemory() } </s> add for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory() </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove if err != nil { return false } return true </s> add return err == nil
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep replace keep keep replace replace replace replace keep keep keep keep
<mask> // Adding rule and matching against the rules <mask> // <mask> <mask> // Return TRUE if file exists <mask> func fileExists(fn string) bool { <mask> _, err := os.Stat(fn) <mask> if err != nil { <mask> return false <mask> } <mask> return true <mask> } <mask> <mask> func createFilteringEngine(filters []Filter) (*filterlist.RuleStorage, *urlfilter.DNSEngine, error) { <mask> listArray := []filterlist.RuleList{} </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err) </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace keep keep keep keep keep
<mask> IgnoreCosmetic: true, <mask> } <mask> } else if runtime.GOOS == "windows" { <mask> // On Windows we don't pass a file to urlfilter because <mask> // it's difficult to update this file while it's being used. <mask> data, err := ioutil.ReadFile(f.FilePath) <mask> if err != nil { <mask> return nil, nil, fmt.Errorf("ioutil.ReadFile(): %s: %w", f.FilePath, err) <mask> } <mask> list = &filterlist.StringRuleList{ </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { </s> add // On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() { </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects.
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace keep keep keep keep keep
<mask> filteringEngine := urlfilter.NewDNSEngine(rulesStorage) <mask> return rulesStorage, filteringEngine, nil <mask> } <mask> <mask> // Initialize urlfilter objects <mask> func (d *Dnsfilter) initFiltering(allowFilters, blockFilters []Filter) error { <mask> rulesStorage, filteringEngine, err := createFilteringEngine(blockFilters) <mask> if err != nil { <mask> return err <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove // New creates properly initialized DNS Filter that is ready to be used </s> add // New creates properly initialized DNS Filter that is ready to be used. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> return nil <mask> } <mask> <mask> // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups <mask> func (d *Dnsfilter) matchHost(host string, qtype uint16, setts RequestFilteringSettings) (Result, error) { <mask> d.engineLock.RLock() <mask> // Keep in mind that this lock must be held no just when calling Match() <mask> // but also while using the rules returned by it. <mask> defer d.engineLock.RUnlock() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove // New creates properly initialized DNS Filter that is ready to be used </s> add // New creates properly initialized DNS Filter that is ready to be used. </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove func (d *Dnsfilter) SetFilters(blockFilters []Filter, allowFilters []Filter, async bool) error { </s> add func (d *Dnsfilter) SetFilters(blockFilters, allowFilters []Filter, async bool) error {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep replace keep keep keep keep replace keep keep
<mask> <mask> // InitModule() - manually initialize blocked services map <mask> func InitModule() { <mask> initBlockedServices() <mask> } <mask> <mask> // New creates properly initialized DNS Filter that is ready to be used <mask> func New(c *Config, blockFilters []Filter) *Dnsfilter { <mask> if c != nil { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects. </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> cacheConf := cache.Config{ <mask> EnableLRU: true, <mask> } <mask> <mask> // initialize objects only once <mask> <mask> if gctx.safebrowsingCache == nil { <mask> cacheConf.MaxSize = c.SafeBrowsingCacheSize <mask> gctx.safebrowsingCache = cache.New(cacheConf) <mask> } <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // New creates properly initialized DNS Filter that is ready to be used </s> add // New creates properly initialized DNS Filter that is ready to be used. </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects. </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used. </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found.
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace keep keep keep
<mask> // <mask> // stats <mask> // <mask> <mask> // GetStats return dns filtering stats since startup <mask> func (d *Dnsfilter) GetStats() Stats { <mask> return gctx.stats <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects. </s> remove func (d *Dnsfilter) SetFilters(blockFilters []Filter, allowFilters []Filter, async bool) error { </s> add func (d *Dnsfilter) SetFilters(blockFilters, allowFilters []Filter, async bool) error { </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove // nolint func withBufferCap(n int) ClientOpt { return func(c *Client) (err error) { c.bufferCap = n return } } </s> add </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> <mask> import ( <mask> "fmt" <mask> "net" <mask> "os" <mask> "path" <mask> "runtime" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> "github.com/stretchr/testify/assert" </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove const dnsTimeout = 3 * time.Second const defaultSafebrowsingServer = "https://dns-family.adguard.com/dns-query" const defaultParentalServer = "https://dns-family.adguard.com/dns-query" const sbTXTSuffix = "sb.dns.adguard.com." const pcTXTSuffix = "pc.dns.adguard.com." </s> add const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://dns-family.adguard.com/dns-query` defaultParentalServer = `https://dns-family.adguard.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` ) </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove func check(t *testing.T, result bool, msg string) { if !result { t.Fatal(msg) } } </s> add </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> gctx.safeSearchCache.Clear() <mask> } <mask> } <mask> <mask> func _Func() string { <mask> pc := make([]uintptr, 10) // at least 1 entry needed <mask> runtime.Callers(2, pc) <mask> f := runtime.FuncForPC(pc[0]) <mask> return path.Base(f.Name()) <mask> } <mask> <mask> func NewForTest(c *Config, filters []Filter) *Dnsfilter { <mask> setts = RequestFilteringSettings{} <mask> setts.FilteringEnabled = true <mask> if c != nil { <mask> c.SafeBrowsingCacheSize = 10000 </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // New creates properly initialized DNS Filter that is ready to be used </s> add // New creates properly initialized DNS Filter that is ready to be used. </s> remove // initialize objects only once </s> add </s> remove var hour int32 hour = 1 </s> add var hour int32 = 1 </s> remove // Initialize urlfilter objects </s> add // Initialize urlfilter objects. </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> t.Errorf("Expected hostname %s to match", hostname) <mask> } <mask> } <mask> <mask> func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { <mask> t.Helper() <mask> ret, err := d.CheckHost(hostname, qtype, &setts) <mask> if err != nil { <mask> t.Errorf("Error while matching host %s: %s", hostname, err) <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used. </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> remove // runCommand runs shell command </s> add // RunCommand runs shell command.
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> 0.0.0.2 host2 <mask> ::1 host2 <mask> `, <mask> addr, addr6) <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte(text), <mask> }} <mask> d := NewForTest(nil, filters) <mask> defer d.Close() <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> // FILTERING <mask> <mask> var blockingRules = "||example.org^\n" <mask> var whitelistRules = "||example.org^\n@@||test.example.org\n" <mask> var importantRules = "@@||example.org^\n||test.example.org^$important\n" <mask> var regexRules = "/example\\.org/\n@@||test.example.org^\n" <mask> var maskRules = "test*.example.org^\nexam*.com\n" <mask> <mask> var tests = []struct { <mask> testname string <mask> rules string <mask> hostname string </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var hour int32 hour = 1 </s> add var hour int32 = 1 </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove var ip string ip = <-w.ipChan </s> add ip := <-w.ipChan </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> func TestMatching(t *testing.T) { <mask> for _, test := range tests { <mask> t.Run(fmt.Sprintf("%s-%s", test.testname, test.hostname), func(t *testing.T) { <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte(test.rules), <mask> }} <mask> d := NewForTest(nil, filters) <mask> defer d.Close() <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> add func withBufferCap(n int) ClientOpt { return func(c *Client) (err error) { c.bufferCap = n return } } </s> remove if err != nil { return false } return true </s> add return err == nil
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> func TestWhitelist(t *testing.T) { <mask> rules := `||host1^ <mask> ||host2^ <mask> ` <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte(rules), <mask> }} <mask> <mask> whiteRules := `||host1^ <mask> ||host3^ </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> whiteRules := `||host1^ <mask> ||host3^ <mask> ` <mask> whiteFilters := []Filter{Filter{ <mask> ID: 0, Data: []byte(whiteRules), <mask> }} <mask> d := NewForTest(nil, filters) <mask> d.SetFilters(filters, whiteFilters, false) <mask> defer d.Close() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> // Check behaviour without any per-client settings, <mask> // then apply per-client settings and check behaviour once again <mask> func TestClientSettings(t *testing.T) { <mask> var r Result <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte("||example.org^\n"), <mask> }} <mask> d := NewForTest(&Config{ParentalEnabled: true, SafeBrowsingEnabled: false}, filters) <mask> defer d.Close() <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove // initialize objects only once </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts) <mask> assert.True(t, r.IsFiltered && r.Reason == FilteredBlockedService) <mask> } <mask> <mask> func prepareTestDir() string { <mask> const dir = "./agh-test" <mask> _ = os.RemoveAll(dir) <mask> _ = os.MkdirAll(dir, 0755) <mask> return dir <mask> } <mask> <mask> // BENCHMARKS <mask> <mask> func BenchmarkSafeBrowsing(b *testing.B) { <mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) <mask> defer d.Close() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event </s> remove // skip duplicate events </s> add </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> func (d *Dnsfilter) setCacheResult(cache cache.Cache, host string, res Result) int { <mask> var buf bytes.Buffer <mask> <mask> expire := uint(time.Now().Unix()) + d.Config.CacheTime*60 <mask> var exp []byte <mask> exp = make([]byte, 4) <mask> binary.BigEndian.PutUint32(exp, uint32(expire)) <mask> _, _ = buf.Write(exp) <mask> <mask> enc := gob.NewEncoder(&buf) <mask> err := enc.Encode(res) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl )
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/safe_search.go
keep keep keep keep replace replace replace replace replace keep keep keep keep keep
<mask> "github.com/miekg/dns" <mask> "golang.org/x/net/publicsuffix" <mask> ) <mask> <mask> const dnsTimeout = 3 * time.Second <mask> const defaultSafebrowsingServer = "https://dns-family.adguard.com/dns-query" <mask> const defaultParentalServer = "https://dns-family.adguard.com/dns-query" <mask> const sbTXTSuffix = "sb.dns.adguard.com." <mask> const pcTXTSuffix = "pc.dns.adguard.com." <mask> <mask> func (d *Dnsfilter) initSecurityServices() error { <mask> var err error <mask> d.safeBrowsingServer = defaultSafebrowsingServer <mask> d.parentalServer = defaultParentalServer </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> remove for _, it := range u.nResult { udb.NResult = append(udb.NResult, it) } </s> add udb.NResult = append(udb.NResult, u.nResult...)
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
keep keep keep keep replace keep keep keep keep keep
<mask> expire byte[4] <mask> hash byte[32] <mask> ... <mask> */ <mask> func (c *sbCtx) setCache(prefix []byte, hashes []byte) { <mask> d := make([]byte, 4+len(hashes)) <mask> expire := uint(time.Now().Unix()) + c.cacheTime*60 <mask> binary.BigEndian.PutUint32(d[:4], uint32(expire)) <mask> copy(d[4:], hashes) <mask> c.cache.Set(prefix, d) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName))
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
keep keep keep keep replace keep replace keep
<mask> } <mask> <mask> // convert hash array to string <mask> func (c *sbCtx) getQuestion() string { <mask> q := "" <mask> for hash := range c.hashToHost { <mask> q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
keep keep keep keep replace replace replace keep replace keep keep
<mask> for hash := range c.hashToHost { <mask> q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) <mask> } <mask> if c.svc == "SafeBrowsing" { <mask> q += sbTXTSuffix <mask> } else { <mask> q += pcTXTSuffix <mask> } <mask> return q <mask> } <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n } </s> remove svc: "SafeBrowsing", </s> add svc: "SafeBrowsing", hashToHost: hashes, </s> remove // test getQuestion() c.hashToHost = hashes </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
keep keep keep keep replace keep keep replace replace keep keep
<mask> _, ok = hashes[sha256.Sum256([]byte("com"))] <mask> assert.False(t, ok) <mask> <mask> c := &sbCtx{ <mask> svc: "SafeBrowsing", <mask> } <mask> <mask> // test getQuestion() <mask> c.hashToHost = hashes <mask> q := c.getQuestion() <mask> assert.True(t, strings.Index(q, "7a1b.") >= 0) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove assert.True(t, strings.Index(q, "7a1b.") >= 0) assert.True(t, strings.Index(q, "af5a.") >= 0) assert.True(t, strings.Index(q, "eb11.") >= 0) assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) </s> add assert.True(t, strings.Contains(q, "7a1b.")) assert.True(t, strings.Contains(q, "af5a.")) assert.True(t, strings.Contains(q, "eb11.")) assert.True(t, strings.HasSuffix(q, "sb.dns.adguard.com.")) </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String()
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc_test.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> <mask> // test getQuestion() <mask> c.hashToHost = hashes <mask> q := c.getQuestion() <mask> assert.True(t, strings.Index(q, "7a1b.") >= 0) <mask> assert.True(t, strings.Index(q, "af5a.") >= 0) <mask> assert.True(t, strings.Index(q, "eb11.") >= 0) <mask> assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) <mask> } <mask> <mask> func TestSafeBrowsingCache(t *testing.T) { <mask> c := &sbCtx{ <mask> svc: "SafeBrowsing", </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // test getQuestion() c.hashToHost = hashes </s> add </s> remove svc: "SafeBrowsing", </s> add svc: "SafeBrowsing", hashToHost: hashes, </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove m := make(map[string]string, 0) </s> add m := make(map[string]string) </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc_test.go
keep replace replace replace replace replace keep replace replace keep keep keep keep
<mask> <mask> /* <mask> expire byte[4] <mask> name_len byte[2] <mask> name byte[] <mask> */ <mask> func (s *session) serialize() []byte { <mask> var data []byte <mask> data = make([]byte, 4+2+len(s.userName)) <mask> binary.BigEndian.PutUint32(data[0:4], s.expire) <mask> binary.BigEndian.PutUint16(data[4:6], uint16(len(s.userName))) <mask> copy(data[6:], []byte(s.userName)) <mask> return data </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n } </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> remove func (s *v6Server) process(msg *dhcpv6.Message, req dhcpv6.DHCPv6, resp dhcpv6.DHCPv6) bool { </s> add func (s *v6Server) process(msg *dhcpv6.Message, req, resp dhcpv6.DHCPv6) bool {
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> log.Debug("Auth: added user: %s", u.Name) <mask> } <mask> <mask> // UserFind - find a user <mask> func (a *Auth) UserFind(login string, password string) User { <mask> a.lock.Lock() <mask> defer a.lock.Unlock() <mask> for _, u := range a.users { <mask> if u.Name == login && <mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove units := []*unitDB{} //per-hour units </s> add // Per-hour units. units := []*unitDB{}
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/auth.go
keep keep keep keep replace keep keep keep keep keep
<mask> "sync/atomic" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" <mask> "github.com/AdguardTeam/AdGuardHome/internal/util" <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> var nextFilterID = time.Now().Unix() // semi-stable way to generate an unique ID <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove data.WarningValidation = fmt.Sprintf("You have specified an empty certificate") </s> add data.WarningValidation = "You have specified an empty certificate" </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> remove const dnsTimeout = 3 * time.Second const defaultSafebrowsingServer = "https://dns-family.adguard.com/dns-query" const defaultParentalServer = "https://dns-family.adguard.com/dns-query" const sbTXTSuffix = "sb.dns.adguard.com." const pcTXTSuffix = "pc.dns.adguard.com." </s> add const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://dns-family.adguard.com/dns-query` defaultParentalServer = `https://dns-family.adguard.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` )
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> n, err := reader.Read(buf) <mask> total += n <mask> <mask> if htmlTest { <mask> // gather full buffer firstChunk and perform its data tests <mask> num := util.MinInt(n, len(firstChunk)-firstChunkLen) <mask> copied := copy(firstChunk[firstChunkLen:], buf[:num]) <mask> firstChunkLen += copied <mask> <mask> if firstChunkLen == len(firstChunk) || err == io.EOF { <mask> if !isPrintableText(firstChunk, firstChunkLen) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") { </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists.
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> return false, fmt.Errorf("data contains non-printable characters") <mask> } <mask> <mask> s := strings.ToLower(string(firstChunk)) <mask> if strings.Index(s, "<html") >= 0 || <mask> strings.Index(s, "<!doctype") >= 0 { <mask> return false, fmt.Errorf("data is HTML, not plain text") <mask> } <mask> <mask> htmlTest = false <mask> firstChunk = nil </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n } </s> remove // test getQuestion() c.hashToHost = hashes </s> add </s> remove ips, _ := a.table[host] if len(ips) != 0 { </s> add if ips, ok := a.table[host]; ok { </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() { </s> remove assert.True(t, strings.Index(q, "7a1b.") >= 0) assert.True(t, strings.Index(q, "af5a.") >= 0) assert.True(t, strings.Index(q, "eb11.") >= 0) assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) </s> add assert.True(t, strings.Contains(q, "7a1b.")) assert.True(t, strings.Contains(q, "af5a.")) assert.True(t, strings.Contains(q, "eb11.")) assert.True(t, strings.HasSuffix(q, "sb.dns.adguard.com."))
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go