@@ -50,14 +50,14 @@ func allocateNetwork(size int, node *node) *netip.Prefix {
5050 return nil
5151 }
5252 if node .prefix .Bits () == size {
53- if ! node .isSplit () {
53+ if ! node .isSplitted () {
5454 node .acquired = true
5555 return & node .prefix
5656 }
5757 return nil
5858 }
5959
60- if ! node .isSplit () {
60+ if ! node .isSplitted () {
6161 node .split ()
6262 }
6363
@@ -81,7 +81,7 @@ func allocateNetworkWithPrefix(prefix netip.Prefix, node *node) *netip.Prefix {
8181 return nil
8282 }
8383
84- if ! node .isSplit () {
84+ if ! node .isSplitted () {
8585 node .split ()
8686 }
8787
@@ -157,6 +157,7 @@ func (n *node) ipAcquire() *netip.Addr {
157157
158158 size := int (math .Pow (2 , float64 (n .prefix .Addr ().BitLen ()- n .prefix .Bits ())))
159159
160+ // If the lastip is not initialized, set it to the first address of the prefix.
160161 if ! n .lastip .IsValid () {
161162 n .lastip = n .prefix .Addr ()
162163 }
@@ -168,6 +169,8 @@ func (n *node) ipAcquire() *netip.Addr {
168169 }
169170
170171 for i := 0 ; i < size ; i ++ {
172+ // we need to check if the address is contained in the prefix.
173+ // If it is not, we need to set it to the first address of the prefix to prevent overflow.
171174 if ! n .prefix .Contains (addr ) {
172175 addr = n .prefix .Addr ()
173176 }
@@ -235,7 +238,7 @@ func search(prefix netip.Prefix, node *node) *node {
235238}
236239
237240func (n * node ) split () {
238- if n .isSplit () {
241+ if n .isSplitted () {
239242 return
240243 }
241244 left , right := splitNetworkPrefix (n .prefix )
@@ -265,16 +268,16 @@ func (n *node) insert(nd nodeDirection, prefix netip.Prefix) {
265268}
266269
267270func (n * node ) bestDirection () (first , second nodeDirection ) {
268- if n .left .isSplit () {
271+ if n .left .isSplitted () {
269272 return leftDirection , rightDirection
270273 }
271- if n .right .isSplit () {
274+ if n .right .isSplitted () {
272275 return rightDirection , leftDirection
273276 }
274277 return leftDirection , rightDirection
275278}
276279
277- func (n * node ) isSplit () bool {
280+ func (n * node ) isSplitted () bool {
278281 if n .left != nil && n .right != nil {
279282 return true
280283 }
0 commit comments