Skip to content

Commit

Permalink
Pull request: all: fix lint and naming issues vol. 2
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from 2276-fix-lint-2 to master

Updates #2276.

Squashed commit of the following:

commit 24760b9
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Dec 7 14:39:50 2020 +0300

    all: fix lint and naming issues vol. 2
  • Loading branch information
ainar-g authored and Blakhard committed Dec 10, 2020
1 parent ff09a4f commit df9a634
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 189 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions internal/dhcpd/dhcpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ServerConfig struct {
HTTPRegister func(string, string, func(http.ResponseWriter, *http.Request)) `yaml:"-"`
}

// OnLeaseChangedT is a callback for lease changes.
type OnLeaseChangedT func(flags int)

// flags for onLeaseChanged()
Expand All @@ -74,6 +75,7 @@ type Server struct {
onLeaseChanged []OnLeaseChangedT
}

// ServerInterface is an interface for servers.
type ServerInterface interface {
Leases(flags int) []Lease
SetOnLeaseChanged(onLeaseChanged OnLeaseChangedT)
Expand Down
22 changes: 0 additions & 22 deletions internal/dhcpd/nclient4/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
"context"
"errors"
"fmt"
"log"
"net"
"os"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -317,26 +315,6 @@ func WithTimeout(d time.Duration) ClientOpt {
}
}

// WithSummaryLogger logs one-line DHCPv4 message summaries when sent & received.
func WithSummaryLogger() ClientOpt {
return func(c *Client) (err error) {
c.logger = ShortSummaryLogger{
Printfer: log.New(os.Stderr, "[dhcpv4] ", log.LstdFlags),
}
return
}
}

// WithDebugLogger logs multi-line full DHCPv4 messages when sent & received.
func WithDebugLogger() ClientOpt {
return func(c *Client) (err error) {
c.logger = DebugLogger{
Printfer: log.New(os.Stderr, "[dhcpv4] ", log.LstdFlags),
}
return
}
}

// WithLogger set the logger (see interface Logger).
func WithLogger(newLogger Logger) ClientOpt {
return func(c *Client) (err error) {
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 10 additions & 5 deletions internal/dhcpd/router_adv.go → internal/dhcpd/routeradv.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,18 @@ func (ra *raCtx) Init() error {
data := createICMPv6RAPacket(params)

var err error
success := false
ipAndScope := ra.ipAddr.String() + "%" + ra.ifaceName
ra.conn, err = icmp.ListenPacket("ip6:ipv6-icmp", ipAndScope)
if err != nil {
return fmt.Errorf("dhcpv6 ra: icmp.ListenPacket: %w", err)
}
success := false
defer func() {
if !success {
ra.Close()
cerr := ra.Close()
if cerr != nil {
log.Error("closing context: %s", cerr)
}
}
}()

Expand Down Expand Up @@ -227,13 +230,15 @@ func (ra *raCtx) Init() error {
return nil
}

// Close - close module
func (ra *raCtx) Close() {
// Close closes the module.
func (ra *raCtx) Close() (err error) {
log.Debug("dhcpv6 ra: closing")

ra.stop.Store(1)

if ra.conn != nil {
ra.conn.Close()
return ra.conn.Close()
}

return nil
}
File renamed without changes.
5 changes: 3 additions & 2 deletions internal/dhcpd/v46_windows.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// +build windows

package dhcpd

// 'u-root/u-root' package, a dependency of 'insomniacslk/dhcp' package, doesn't build on Windows

import "net"

type winServer struct {
}
type winServer struct{}

func (s *winServer) ResetLeases(leases []*Lease) {}
func (s *winServer) GetLeases(flags int) []Lease { return nil }
Expand Down
8 changes: 6 additions & 2 deletions internal/dhcpd/v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,18 +628,22 @@ func (s *v6Server) Start() error {

// Stop - stop server
func (s *v6Server) Stop() {
s.ra.Close()
err := s.ra.Close()
if err != nil {
log.Error("dhcpv6: s.ra.Close: %s", err)
}

// DHCPv6 server may not be initialized if ra_slaac_only=true
if s.srv == nil {
return
}

log.Debug("DHCPv6: stopping")
err := s.srv.Close()
err = s.srv.Close()
if err != nil {
log.Error("DHCPv6: srv.Close: %s", err)
}

// now server.Serve() will return
s.srv = nil
}
Expand Down
File renamed without changes.
25 changes: 17 additions & 8 deletions internal/dnsfilter/dnsfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,20 @@ func (d *Dnsfilter) Close() {
}

func (d *Dnsfilter) reset() {
var err error

if d.rulesStorage != nil {
_ = d.rulesStorage.Close()
err = d.rulesStorage.Close()
if err != nil {
log.Error("dnsfilter: rulesStorage.Close: %s", err)
}
}

if d.rulesStorageWhite != nil {
d.rulesStorageWhite.Close()
err = d.rulesStorageWhite.Close()
if err != nil {
log.Error("dnsfilter: rulesStorageWhite.Close: %s", err)
}
}
}

Expand Down Expand Up @@ -336,9 +345,9 @@ func (d *Dnsfilter) CheckHost(host string, qtype uint16, setts *RequestFiltering
// Now check the hosts file -- do we have any rules for it?
// just like DNS rewrites, it has higher priority than filtering rules.
if d.Config.AutoHosts != nil {
matched, err := d.checkAutoHosts(host, qtype, &result)
matched := d.checkAutoHosts(host, qtype, &result)
if matched {
return result, err
return result, nil
}
}

Expand Down Expand Up @@ -403,13 +412,13 @@ func (d *Dnsfilter) CheckHost(host string, qtype uint16, setts *RequestFiltering
return Result{}, nil
}

func (d *Dnsfilter) checkAutoHosts(host string, qtype uint16, result *Result) (matched bool, err error) {
func (d *Dnsfilter) checkAutoHosts(host string, qtype uint16, result *Result) (matched bool) {
ips := d.Config.AutoHosts.Process(host, qtype)
if ips != nil {
result.Reason = RewriteEtcHosts
result.IPList = ips

return true, nil
return true
}

revHosts := d.Config.AutoHosts.ProcessReverse(host, qtype)
Expand All @@ -422,10 +431,10 @@ func (d *Dnsfilter) checkAutoHosts(host string, qtype uint16, result *Result) (m
result.ReverseHosts[i] = revHosts[i] + "."
}

return true, nil
return true
}

return false, nil
return false
}

// Process rewrites table
Expand Down
148 changes: 0 additions & 148 deletions internal/dnsfilter/safe_search.go

This file was deleted.

Loading

0 comments on commit df9a634

Please sign in to comment.