module Cidr
( Cidr(..),
cidr_from_string,
- contains
+ combine_all
) where
import IPv4Address
where
addr1masked = apply_mask addr1 mbits1
addr2masked = apply_mask addr2 mbits1
+
+
+contains_proper :: Cidr -> Cidr -> Bool
+contains_proper cidr1 cidr2 =
+ (cidr1 `contains` cidr2) && (not (cidr1 == cidr2))
+
+
+-- A CIDR range is redundant (with respect to the given list) if
+-- another CIDR range in that list properly contains it.
+redundant :: [Cidr] -> Cidr -> Bool
+redundant cidrlist cidr = any ((flip contains_proper) cidr) cidrlist
+
+
+-- We want to get rid of all the Cidrs that are properly contained
+-- in some other Cidr.
+combine_all :: [Cidr] -> [Cidr]
+combine_all cidrs =
+ filter (not . (redundant cidrs)) cidrs