diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-04-26 22:07:06 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-04-26 22:07:06 +0200 |
commit | 492568c72273ee2e7f98bc520e46fa01c2959851 (patch) | |
tree | a679607e71a648140774a1e5c739ae247eaaff22 /src/Network.hs | |
parent | 9bf4a7b3e3c44ef8cc255b27d2c6d74af95f73ce (diff) |
Route tracking in namespaces and helper functions
Diffstat (limited to 'src/Network.hs')
-rw-r--r-- | src/Network.hs | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/Network.hs b/src/Network.hs index 50dc7a3..d892404 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -146,14 +146,10 @@ newSubnet net vname = atomicallyWithIO $ do linkUp vethSub -- sometimes gets stuck with NO-CARRIER for a while. linkUp vethNet - postpone $ do - -- If the new subnet can be split further, routing rule for the whole prefix is needed - when (allowsSubnets (netPrefix sub)) $ callOn net $ "ip route add " - <> textIpNetwork (netPrefix sub) - <> " via " <> textIpAddress bridge - <> " dev " <> linkName vethNet - <> " src " <> textIpAddress router - callOn sub $ "ip route add default via " <> textIpAddress router <> " dev br0 src " <> textIpAddress bridge + -- If the new subnet can be split further, routing rule for the whole prefix is needed + when (allowsSubnets (netPrefix sub)) $ do + addRoute (netPrefix sub) bridge vethNet router + addRoute (IpPrefix []) router (netBridge sub) bridge return sub { netUpstream = Just vethSub } newNetwork :: IpPrefix -> FilePath -> WriterT [IO ()] STM Network @@ -202,12 +198,6 @@ newNode nodeNetwork vname = atomicallyWithIO $ do addAddress nodeUpstream $ nodeIp linkUp $ nodeUpstream linkUp $ loopback node - postpone $ callOn node $ "ip route add default via " <> textIpAddress (lanIp 1) <> " dev veth0 src " <> textIpAddress nodeIp + addRoute (IpPrefix []) (lanIp 1) nodeUpstream nodeIp return node - -atomicallyWithIO :: MonadIO m => WriterT [IO ()] STM a -> m a -atomicallyWithIO act = liftIO $ do - (x, fin) <- atomically $ runWriterT act - sequence_ fin - return x |