summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2017-07-26 23:49:04 -0400
committerJoey Hess2017-07-26 23:49:04 -0400
commit24fe88f64069bd7463cb49d923a36abadae8a127 (patch)
tree8de26302edf4b7618ccafbc554b9603ea4479d76
parent2f277014efb5716cba54047f8b171b2018b41f97 (diff)
Added Network.dhcp' and Network.static', which allow specifying additional options for interfaces files.
-rw-r--r--debian/changelog7
-rw-r--r--joeyconfig.hs10
-rw-r--r--src/Propellor/Property/Network.hs59
3 files changed, 52 insertions, 24 deletions
diff --git a/debian/changelog b/debian/changelog
index 3944f454..7a049aa8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+propellor (4.6.1) UNRELEASED; urgency=medium
+
+ * Added Network.dhcp' and Network.static', which allow specifying
+ additional options for interfaces files.
+
+ -- Joey Hess <id@joeyh.name> Wed, 26 Jul 2017 23:40:48 -0400
+
propellor (4.6.0) unstable; urgency=medium
* Add Typeable instance to Bootstrapper, fixing build with old versions
diff --git a/joeyconfig.hs b/joeyconfig.hs
index 2dce2940..c0f4f4db 100644
--- a/joeyconfig.hs
+++ b/joeyconfig.hs
@@ -202,9 +202,6 @@ honeybee = host "honeybee.kitenet.net" $ props
& Apt.serviceInstalledRunning "ntp"
-- Home router
- & Network.static "eth0" (IPv4 "192.168.1.42")
- (Just (Network.Gateway (IPv4 "192.168.1.1")))
- `requires` Network.cleanInterfacesFile
& Network.static "wlan0" (IPv4 "10.1.1.1") Nothing
`requires` Network.cleanInterfacesFile
& Apt.serviceInstalledRunning "hostapd"
@@ -232,6 +229,13 @@ honeybee = host "honeybee.kitenet.net" $ props
, "nameserver 8.8.4.4"
]
& JoeySites.ipmasq "wlan0"
+ & Network.static' "eth0" (IPv4 "192.168.1.42")
+ (Just (Network.Gateway (IPv4 "192.168.1.1")))
+ -- When satellite is down, fall back to dialup
+ [ ("pre-up", "poff -a || true")
+ , ("post-down", "pon")
+ ]
+ `requires` Network.cleanInterfacesFile
& Apt.installed ["ppp"]
`before` File.hasContent "/etc/ppp/peers/provider"
[ "user \"joeyh@arczip.com\""
diff --git a/src/Propellor/Property/Network.hs b/src/Propellor/Property/Network.hs
index a50d3f95..b581fa3f 100644
--- a/src/Propellor/Property/Network.hs
+++ b/src/Propellor/Property/Network.hs
@@ -7,6 +7,9 @@ import Data.Char
type Interface = String
+-- | Options to put in a stanza of an ifupdown interfaces file.
+type InterfaceOptions = [(String, String)]
+
ifUp :: Interface -> Property DebianLike
ifUp iface = tightenTargets $ cmdProperty "ifup" [iface]
`assume` MadeChange
@@ -19,44 +22,51 @@ ifUp iface = tightenTargets $ cmdProperty "ifup" [iface]
--
-- No interfaces are brought up or down by this property.
cleanInterfacesFile :: Property DebianLike
-cleanInterfacesFile = tightenTargets $ hasContent interfacesFile
- [ "# Deployed by propellor, do not edit."
- , ""
- , "source-directory interfaces.d"
+cleanInterfacesFile = interfaceFileContains interfacesFile
+ [ "source-directory interfaces.d"
, ""
, "# The loopback network interface"
, "auto lo"
, "iface lo inet loopback"
]
+ []
`describe` ("clean " ++ interfacesFile)
-- | Configures an interface to get its address via dhcp.
dhcp :: Interface -> Property DebianLike
-dhcp iface = tightenTargets $ hasContent (interfaceDFile iface)
+dhcp iface = dhcp' iface mempty
+
+dhcp' :: Interface -> InterfaceOptions -> Property DebianLike
+dhcp' iface options = interfaceFileContains (interfaceDFile iface)
[ "auto " ++ iface
, "iface " ++ iface ++ " inet dhcp"
- ]
+ ] options
`describe` ("dhcp " ++ iface)
`requires` interfacesDEnabled
newtype Gateway = Gateway IPAddr
-- | Configures an interface with a static address and gateway.
-static :: Interface -> IPAddr -> Maybe Gateway-> Property DebianLike
-static iface addr gateway =
- tightenTargets $ hasContent (interfaceDFile iface) ls
+static :: Interface -> IPAddr -> Maybe Gateway -> Property DebianLike
+static iface addr gateway = static' iface addr gateway mempty
+
+static' :: Interface -> IPAddr -> Maybe Gateway -> InterfaceOptions -> Property DebianLike
+static' iface addr gateway options =
+ interfaceFileContains (interfaceDFile iface) headerlines options'
`describe` ("static IP address for " ++ iface)
`requires` interfacesDEnabled
where
- ls = catMaybes
- [ Just $ "auto " ++ iface
- , Just $ "iface " ++ iface ++ " " ++ inet ++ " static"
- , Just $ "\taddress " ++ val addr
+ headerlines =
+ [ "auto " ++ iface
+ , "iface " ++ iface ++ " " ++ inet ++ " static"
+ ]
+ options' = catMaybes
+ [ Just $ ("address", val addr)
, case gateway of
Just (Gateway gaddr) ->
- Just $ "\tgateway " ++ val gaddr
+ Just ("gateway", val gaddr)
Nothing -> Nothing
- ]
+ ] ++ options
inet = case addr of
IPv4 _ -> "inet"
IPv6 _ -> "inet6"
@@ -107,13 +117,13 @@ preserveStatic iface = tightenTargets $
-- | 6to4 ipv6 connection, should work anywhere
ipv6to4 :: Property DebianLike
-ipv6to4 = tightenTargets $ hasContent (interfaceDFile "sit0")
- [ "# Deployed by propellor, do not edit."
+ipv6to4 = tightenTargets $ interfaceFileContains (interfaceDFile "sit0")
+ [ "auto sit0"
, "iface sit0 inet6 static"
- , "\taddress 2002:5044:5531::1"
- , "\tnetmask 64"
- , "\tgateway ::192.88.99.1"
- , "auto sit0"
+ ]
+ [ ("address", "2002:5044:5531::1")
+ , ("netmask", "64")
+ , ("gateway", "::192.88.99.1")
]
`describe` "ipv6to4"
`requires` interfacesDEnabled
@@ -137,3 +147,10 @@ interfacesDEnabled :: Property DebianLike
interfacesDEnabled = tightenTargets $
containsLine interfacesFile "source-directory interfaces.d"
`describe` "interfaces.d directory enabled"
+
+interfaceFileContains :: FilePath -> [String] -> InterfaceOptions -> Property DebianLike
+interfaceFileContains f headerlines options = tightenTargets $ hasContent f $
+ warning : headerlines ++ map fmt options
+ where
+ fmt (k, v) = "\t" ++ k ++ " " ++ v
+ warning = "# Deployed by propellor, do not edit."