From 5abd03e241c373fa06b60c3848ef0104ef503190 Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Tue, 15 Mar 2022 02:43:40 +0800 Subject: [PATCH] Fix: exclude the broadcast address to fake ip pool --- component/fakeip/pool.go | 35 ++++++++++++++++++++-------------- component/resolver/enhancer.go | 9 +++++++++ dns/enhancer.go | 14 +++++++++++++- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/component/fakeip/pool.go b/component/fakeip/pool.go index 925882bb..43b9cee1 100644 --- a/component/fakeip/pool.go +++ b/component/fakeip/pool.go @@ -22,14 +22,15 @@ type store interface { // Pool is a implementation about fake ip generator without storage type Pool struct { - max uint32 - min uint32 - gateway uint32 - offset uint32 - mux sync.Mutex - host *trie.DomainTrie - ipnet *net.IPNet - store store + max uint32 + min uint32 + gateway uint32 + broadcast uint32 + offset uint32 + mux sync.Mutex + host *trie.DomainTrie + ipnet *net.IPNet + store store } // Lookup return a fake ip with host @@ -82,6 +83,11 @@ func (p *Pool) Gateway() net.IP { return uintToIP(p.gateway) } +// Broadcast return broadcast ip +func (p *Pool) Broadcast() net.IP { + return uintToIP(p.broadcast) +} + // IPNet return raw ipnet func (p *Pool) IPNet() *net.IPNet { return p.ipnet @@ -144,7 +150,7 @@ func New(options Options) (*Pool, error) { min := ipToUint(options.IPNet.IP) + 2 ones, bits := options.IPNet.Mask.Size() - total := 1<