File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
1111 "net"
1212 "net/http"
1313 "net/http/httptest"
14+ "net/netip"
1415 "reflect"
1516 "strconv"
1617 "strings"
@@ -584,3 +585,29 @@ func (service *HTTPRestService) CreateOrUpdateNetworkContainerInternal(req *cns.
584585
585586 return returnCode
586587}
588+
589+ // IsCIDRSuperset returns true if newCIDR is a superset of oldCIDR (i.e., all IPs in oldCIDR are contained in newCIDR).
590+ func validateCIDRSuperset (newCIDR , oldCIDR string ) bool {
591+ // Parse newCIDR and oldCIDR into netip.Prefix
592+ newPrefix , err := netip .ParsePrefix (newCIDR )
593+ if err != nil {
594+ return false
595+ }
596+
597+ oldPrefix , err := netip .ParsePrefix (oldCIDR )
598+ if err != nil {
599+ return false
600+ }
601+
602+ // Condition 1: Check if the new prefix length is smaller (larger range) than the old prefix length
603+ if newPrefix .Bits () >= oldPrefix .Bits () {
604+ return false
605+ }
606+
607+ // Condition 2: Check for Overlap - this will also ensure containment
608+ if ! newPrefix .Overlaps (oldPrefix ) {
609+ return false
610+ }
611+
612+ return true
613+ }
You can’t perform that action at this time.
0 commit comments