summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Firewall.hs
diff options
context:
space:
mode:
authorJoey Hess2017-02-26 16:45:33 -0400
committerJoey Hess2017-02-26 16:45:33 -0400
commitae7359a0b0cf58ec83a7ea80fc51d4e6f5be72bf (patch)
tree2a1d75a78cf00992bde8551c33b1bc41406bf85c /src/Propellor/Property/Firewall.hs
parentdb4121edeeba2899926333df46308ca0baf45b71 (diff)
convert from* in Firewall to val
Diffstat (limited to 'src/Propellor/Property/Firewall.hs')
-rw-r--r--src/Propellor/Property/Firewall.hs71
1 files changed, 35 insertions, 36 deletions
diff --git a/src/Propellor/Property/Firewall.hs b/src/Propellor/Property/Firewall.hs
index ce08cc06..ab667da3 100644
--- a/src/Propellor/Property/Firewall.hs
+++ b/src/Propellor/Property/Firewall.hs
@@ -15,7 +15,6 @@ module Propellor.Property.Firewall (
TCPFlag(..),
Frequency(..),
IPWithMask(..),
- fromIPWithMask
) where
import Data.Monoid
@@ -44,9 +43,9 @@ rule c tb tg rs = property ("firewall rule: " <> show r) addIpTable
toIpTable :: Rule -> [CommandParam]
toIpTable r = map Param $
- fromChain (ruleChain r) :
+ val (ruleChain r) :
toIpTableArg (ruleRules r) ++
- ["-t", fromTable (ruleTable r), "-j", fromTarget (ruleTarget r)]
+ ["-t", val (ruleTable r), "-j", val (ruleTarget r)]
toIpTableArg :: Rules -> [String]
toIpTableArg Everything = []
@@ -64,12 +63,12 @@ toIpTableArg (Ctstate states) =
toIpTableArg (ICMPType i) =
[ "-m"
, "icmp"
- , "--icmp-type", fromICMPTypeMatch i
+ , "--icmp-type", val i
]
toIpTableArg (RateLimit f) =
[ "-m"
, "limit"
- , "--limit", fromFrequency f
+ , "--limit", val f
]
toIpTableArg (TCPFlags m c) =
[ "-m"
@@ -87,16 +86,16 @@ toIpTableArg (GroupOwner (Group g)) =
]
toIpTableArg (Source ipwm) =
[ "-s"
- , intercalate "," (map fromIPWithMask ipwm)
+ , intercalate "," (map val ipwm)
]
toIpTableArg (Destination ipwm) =
[ "-d"
- , intercalate "," (map fromIPWithMask ipwm)
+ , intercalate "," (map val ipwm)
]
toIpTableArg (NotDestination ipwm) =
[ "!"
, "-d"
- , intercalate "," (map fromIPWithMask ipwm)
+ , intercalate "," (map val ipwm)
]
toIpTableArg (NatDestination ip mport) =
[ "--to-destination"
@@ -107,10 +106,10 @@ toIpTableArg (r :- r') = toIpTableArg r <> toIpTableArg r'
data IPWithMask = IPWithNoMask IPAddr | IPWithIPMask IPAddr IPAddr | IPWithNumMask IPAddr Int
deriving (Eq, Show)
-fromIPWithMask :: IPWithMask -> String
-fromIPWithMask (IPWithNoMask ip) = fromIPAddr ip
-fromIPWithMask (IPWithIPMask ip ipm) = fromIPAddr ip ++ "/" ++ fromIPAddr ipm
-fromIPWithMask (IPWithNumMask ip m) = fromIPAddr ip ++ "/" ++ show m
+instance ConfigurableValue IPWithMask where
+ val (IPWithNoMask ip) = fromIPAddr ip
+ val (IPWithIPMask ip ipm) = fromIPAddr ip ++ "/" ++ fromIPAddr ipm
+ val (IPWithNumMask ip m) = fromIPAddr ip ++ "/" ++ show m
data Rule = Rule
{ ruleChain :: Chain
@@ -122,33 +121,33 @@ data Rule = Rule
data Table = Filter | Nat | Mangle | Raw | Security
deriving (Eq, Show)
-fromTable :: Table -> String
-fromTable Filter = "filter"
-fromTable Nat = "nat"
-fromTable Mangle = "mangle"
-fromTable Raw = "raw"
-fromTable Security = "security"
+instance ConfigurableValue Table where
+ val Filter = "filter"
+ val Nat = "nat"
+ val Mangle = "mangle"
+ val Raw = "raw"
+ val Security = "security"
data Target = ACCEPT | REJECT | DROP | LOG | TargetCustom String
deriving (Eq, Show)
-fromTarget :: Target -> String
-fromTarget ACCEPT = "ACCEPT"
-fromTarget REJECT = "REJECT"
-fromTarget DROP = "DROP"
-fromTarget LOG = "LOG"
-fromTarget (TargetCustom t) = t
+instance ConfigurableValue Target where
+ val ACCEPT = "ACCEPT"
+ val REJECT = "REJECT"
+ val DROP = "DROP"
+ val LOG = "LOG"
+ val (TargetCustom t) = t
data Chain = INPUT | OUTPUT | FORWARD | PREROUTING | POSTROUTING | ChainCustom String
deriving (Eq, Show)
-fromChain :: Chain -> String
-fromChain INPUT = "INPUT"
-fromChain OUTPUT = "OUTPUT"
-fromChain FORWARD = "FORWARD"
-fromChain PREROUTING = "PREROUTING"
-fromChain POSTROUTING = "POSTROUTING"
-fromChain (ChainCustom c) = c
+instance ConfigurableValue Chain where
+ val INPUT = "INPUT"
+ val OUTPUT = "OUTPUT"
+ val FORWARD = "FORWARD"
+ val PREROUTING = "PREROUTING"
+ val POSTROUTING = "POSTROUTING"
+ val (ChainCustom c) = c
data Proto = TCP | UDP | ICMP
deriving (Eq, Show)
@@ -159,15 +158,15 @@ data ConnectionState = ESTABLISHED | RELATED | NEW | INVALID
data ICMPTypeMatch = ICMPTypeName String | ICMPTypeCode Int
deriving (Eq, Show)
-fromICMPTypeMatch :: ICMPTypeMatch -> String
-fromICMPTypeMatch (ICMPTypeName t) = t
-fromICMPTypeMatch (ICMPTypeCode c) = show c
+instance ConfigurableValue ICMPTypeMatch where
+ val (ICMPTypeName t) = t
+ val (ICMPTypeCode c) = val c
data Frequency = NumBySecond Int
deriving (Eq, Show)
-fromFrequency :: Frequency -> String
-fromFrequency (NumBySecond n) = show n ++ "/second"
+instance ConfigurableValue Frequency where
+ val (NumBySecond n) = val n ++ "/second"
type TCPFlagMask = [TCPFlag]