From f40ef76c790bb15fc73a123b2a8dede4e6618ad9 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Thu, 22 Jun 2023 14:18:43 +0300 Subject: [PATCH] Pull request 1861: 4923-gopacket-dhcp vol.1 Merge in DNS/adguard-home from 4923-gopacket-dhcp to master Updates #4923. Squashed commit of the following: commit edf36ce8b1873272c3daebe8cc8f8132793aac44 Merge: a17513d3e 123ca8738 Author: Eugene Burkov Date: Thu Jun 22 14:14:39 2023 +0300 Merge branch 'master' into 4923-gopacket-dhcp commit a17513d3e0a9e596d56444dfa46478eee15631de Merge: f04727c29 994906fbd Author: Eugene Burkov Date: Wed Jun 21 17:49:09 2023 +0300 Merge branch 'master' into 4923-gopacket-dhcp commit f04727c29eaf22f9eb53f3aa33d42d00e177b224 Author: Eugene Burkov Date: Tue Jun 20 15:42:31 2023 +0300 home: revert clients container commit c58284ac6b5b2274da5eed2e853847d757709e5b Author: Eugene Burkov Date: Mon Jun 19 21:10:36 2023 +0300 all: imp code, names, docs commit 4c4613c939e1325d11655822d9dbc3f05a6d203c Author: Eugene Burkov Date: Tue Jun 13 18:51:12 2023 +0300 all: imp code commit 0b4a6e0dd561d9b7bb78dea21dcc947bcd0bd583 Author: Eugene Burkov Date: Wed Jun 7 18:40:15 2023 +0300 all: imp api commit 0425edea03d6ca0859657df683bef6ec45bfc399 Author: Eugene Burkov Date: Mon Jun 5 15:57:23 2023 +0300 dhcpsvc: introduce package commit 5628ebe6cccf91e2c48778966730bcbbe9e1d9f2 Author: Eugene Burkov Date: Thu Jun 1 17:49:12 2023 +0300 WIP --- internal/dhcpd/bitset.go | 5 +- internal/dhcpd/conn_bsd.go | 17 ++-- internal/dhcpd/conn_linux.go | 17 ++-- internal/dhcpd/dhcpd.go | 7 +- internal/dhcpd/routeradv.go | 2 +- internal/dhcpsvc/config.go | 86 ++++++++++++++++++ internal/dhcpsvc/dhcpsvc.go | 120 ++++++++++++++++++++++++ internal/dnsforward/dnsforward.go | 21 +++++ internal/home/clients.go | 146 +++++++++++++++--------------- internal/home/rdns_test.go | 7 +- 10 files changed, 324 insertions(+), 104 deletions(-) create mode 100644 internal/dhcpsvc/config.go create mode 100644 internal/dhcpsvc/dhcpsvc.go diff --git a/internal/dhcpd/bitset.go b/internal/dhcpd/bitset.go index e726319c..7459c2f1 100644 --- a/internal/dhcpd/bitset.go +++ b/internal/dhcpd/bitset.go @@ -25,11 +25,8 @@ func (s *bitSet) isSet(n uint64) (ok bool) { var word uint64 word, ok = s.words[wordIdx] - if !ok { - return false - } - return word&(1< src { - return false - } - - rc.Host = host - rc.Source = src - } else { + if !ok { rc = &RuntimeClient{ - Host: host, - Source: src, - WHOIS: &whois.Info{}, + WHOIS: &whois.Info{}, } clients.ipToRC[ip] = rc + } else if src < rc.Source { + return false } + rc.Host = host + rc.Source = src + log.Debug("clients: added %s -> %q [%d]", ip, host, len(clients.ipToRC)) return true @@ -827,38 +863,6 @@ func (clients *clientsContainer) addFromSystemARP() { log.Debug("clients: added %d client aliases from arp neighborhood", added) } -// updateFromDHCP adds the clients that have a non-empty hostname from the DHCP -// server. -func (clients *clientsContainer) updateFromDHCP(add bool) { - if clients.dhcpServer == nil || !config.Clients.Sources.DHCP { - return - } - - clients.lock.Lock() - defer clients.lock.Unlock() - - clients.rmHostsBySrc(ClientSourceDHCP) - - if !add { - return - } - - leases := clients.dhcpServer.Leases(dhcpd.LeasesAll) - n := 0 - for _, l := range leases { - if l.Hostname == "" { - continue - } - - ok := clients.addHostLocked(l.IP, l.Hostname, ClientSourceDHCP) - if ok { - n++ - } - } - - log.Debug("clients: added %d client aliases from dhcp", n) -} - // close gracefully closes all the client-specific upstream configurations of // the persistent clients. func (clients *clientsContainer) close() (err error) { diff --git a/internal/home/rdns_test.go b/internal/home/rdns_test.go index 4e424273..078a092f 100644 --- a/internal/home/rdns_test.go +++ b/internal/home/rdns_test.go @@ -228,12 +228,7 @@ func TestRDNS_WorkerLoop(t *testing.T) { for _, tc := range testCases { w.Reset() - cc := &clientsContainer{ - list: map[string]*Client{}, - idIndex: map[string]*Client{}, - ipToRC: map[netip.Addr]*RuntimeClient{}, - allTags: stringutil.NewSet(), - } + cc := newClientsContainer() ch := make(chan netip.Addr) rdns := &RDNS{ exchanger: &rDNSExchanger{