-- | Function to generate blacklist packet filtering rules.
makeBlacklistFilter :: (Eq a, Show a) =>
                       String -> (Packet -> a) -> (FirewallState -> [a]) -> PacketFilterRule Action
makeBlacklistFilter name getField blacklist packet = do
  fwState <- get
  let field = getField packet
  if field `elem` blacklist fwState
    then do logMsg LogInfo ("Dropping packet because " ++ name ++ " " ++ show field
                            ++ " is blacklisted.")
            return DROP
    else return PASS

-- | Filter a packet by the protocol blacklist in FirewallState.
makeBlacklistFilter :: (Eq a, Show a) =>
                       String -> (Packet -> a) -> (FirewallState -> [a]) -> PacketFilterRule Action
makeBlacklistFilter name getField blacklist packet = do
  fwState <- get
  let field = getField packet
  if field `elem` blacklist fwState
    then do logMsg LogInfo ("Dropping packet because " ++ name ++ " " ++ show field
                            ++ " is blacklisted.")
            return DROP
    else return PASS

-- | Filter a packet by the protocol blacklist in FirewallState.
makeBlacklistFilter name getField blacklist packet = do
  fwState <- get
  let field = getField packet
  if field `elem` blacklist fwState
    then do logMsg LogInfo ("Dropping packet because " ++ name ++ " " ++ show field
                            ++ " is blacklisted.")
            return DROP
    else return PASS

-- | Filter a packet by the protocol blacklist in FirewallState.