Copyright | (c) Formaltech Inc. 2017 |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | Linux |
Safe Haskell | None |
Language | Haskell2010 |
System.Linux.RTNetlink
Description
RTNetlink is an extensible, high-level, pure Haskell interface for manipulating network interfaces on Linux: creating and destroying interfaces, changing and dumping interface settings, adding and removing addresses.
The core interface of RTNetlink is the RTNL
monad. RTNL
handles the heavy
lifting of opening and closing netlink sockets, incrementing sequence numbers,
and getting the responses for the current sequence number behind the scenes.
Messages not that are not responses to a sent message, such as those sent to
group subscribers, are stored in the backlog and can be retrieved with
getBacklog
.
The basic way to use RTNL
is to use the create
, destroy
, dump
, and
change
convenience functions. If you want more control, you can use talk
and talk_
. Import modules like System.Linux.RTNetlink.Link to get access
to prefab instances of Create
and Destroy
messages, etc. Or import
System.Linux.RTNetlink.Message to get access to the core typeclasses and
create your own messages. System.Linux.RTNetlink.Packet has a number of
functions to make this easier.
Example:
module Main where import System.Linux.RTNetlink import System.Linux.RTNetlink.Link import Control.Monad (when) main :: IO () main = runRTNL $ do let mybridge = LinkName "mybridge" create (Bridge mybridge) change mybridge Up state <- dump mybridge when (head state == Up) $ liftIO (putStrLn "I did it, mom!") destroy mybridge
- data RTNL a
- tryRTNL :: RTNL a -> IO (Either String a)
- runRTNL :: RTNL a -> IO a
- runRTNLGroups :: [RTNetlinkGroup] -> RTNL a -> IO a
- create :: Create c => c -> RTNL ()
- destroy :: Destroy d => d -> RTNL ()
- dump :: (Request q, Reply r) => q -> RTNL [r]
- change :: Change id c => id -> c -> RTNL ()
- getBacklog :: Reply r => RTNL [r]
- clearBacklog :: RTNL ()
- talk :: (Header h, Reply r) => (SequenceNumber -> NLMessage h) -> RTNL [r]
- talk_ :: Header h => (SequenceNumber -> NLMessage h) -> RTNL ()
- talkRaw :: ByteString -> RTNL [ByteString]
- liftIO :: MonadIO m => forall a. IO a -> m a
The RTNL monad
RTNL monad to simplify netlink communication.
tryRTNL :: RTNL a -> IO (Either String a) Source #
Run an RTNL function and catch all IOError
s. This means that functions
in this module are guaranteed not to throw uncaught exceptions.
runRTNL :: RTNL a -> IO a Source #
Run an RTNL function. RTNL functions in this module throw exclusively
IOError
s.
runRTNLGroups :: [RTNetlinkGroup] -> RTNL a -> IO a Source #
Run an RTNL function and specify some groups to subscribe to.
High-level communication
getBacklog :: Reply r => RTNL [r] Source #
Get all the Reply
s of a particular type in the backlog and queued
on the socket.
clearBacklog :: RTNL () Source #
Clear the backlog.
Lower-level communication
talkRaw :: ByteString -> RTNL [ByteString] Source #
Lowest-level RTNL function. Send a BytsString
and receive all responses
and queued messages as ByteString
s.
_Note:_ This function does nothing to manage sequence numbers or distinguish between responses and queued messages. Nothing will be added to the backlog.