Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from Carl-Baldwin/v4-and-v6-are-not-the-same
Browse files Browse the repository at this point in the history
Explicitly return false for networks of different IP versions
  • Loading branch information
CARL BALDWIN authored and GitHub Enterprise committed May 11, 2018
2 parents a6c4dd1 + 6f86afa commit b76a2a9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions net_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
// containsNet returns true if net2 is a subset of net1. To be clear, it
// returns true if net1 == net2 also.
func containsNet(net1, net2 *net.IPNet) bool {
// If the two networks are different IP versions, return false
if len(net1.IP) != len(net2.IP) {
return false
}
if !net1.Contains(net2.IP) {
return false
}
Expand All @@ -20,6 +24,11 @@ func containsNet(net1, net2 *net.IPNet) bool {
// netDifference returns the set difference a - b. It returns the list of CIDRs
// in order from largest to smallest. They are *not* sorted by network IP.
func netDifference(a, b *net.IPNet) (result []*net.IPNet) {
// If the two networks are different IP versions, return a
if len(a.IP) != len(b.IP) {
return []*net.IPNet{a}
}

// If b contains a then the difference is empty
if containsNet(b, a) {
return
Expand Down

0 comments on commit b76a2a9

Please sign in to comment.