netlink-1.1.1.0: Netlink communication for Haskell

Maintainerongy
Stabilitytesting
PortabilityLinux
Safe HaskellNone
LanguageHaskell2010

System.Linux.Netlink

Description

This is the base module for the netlink package. It contains functions and datatype used by every netlink module. All definitions are (supposed to be) generic enough to be used by implementations of more specific netlink interfaces.

Synopsis

Documentation

data Header Source #

Data type for the netlink header

Constructors

Header 

Fields

  • messageType :: MessageType

    The message type

  • messageFlags :: Word16

    The message flags

  • messageSeqNum :: Word32

    The sequence message number

  • messagePID :: Word32

    The pid of the sending process (0 is from kernel for receiving or "let the kernel set it" for sending)

Instances
Eq Header Source # 
Instance details

Defined in System.Linux.Netlink

Methods

(==) :: Header -> Header -> Bool

(/=) :: Header -> Header -> Bool

Show Header Source # 
Instance details

Defined in System.Linux.Netlink

Methods

showsPrec :: Int -> Header -> ShowS

show :: Header -> String

showList :: [Header] -> ShowS

type Attributes = Map Int ByteString Source #

Type used for netlink attributes

data Packet a Source #

The generic netlink message type

Constructors

Packet 

Fields

ErrorMsg 

Fields

DoneMsg 

Fields

Instances
Show NL80211Packet 
Instance details

Defined in System.Linux.Netlink.GeNetlink.NL80211

Methods

showsPrec :: Int -> NL80211Packet -> ShowS

show :: NL80211Packet -> String

showList :: [NL80211Packet] -> ShowS

Show RoutePacket 
Instance details

Defined in System.Linux.Netlink.Route

Methods

showsPrec :: Int -> RoutePacket -> ShowS

show :: RoutePacket -> String

showList :: [RoutePacket] -> ShowS

Eq a => Eq (Packet a) Source # 
Instance details

Defined in System.Linux.Netlink

Methods

(==) :: Packet a -> Packet a -> Bool

(/=) :: Packet a -> Packet a -> Bool

Show a => Show (Packet a) Source # 
Instance details

Defined in System.Linux.Netlink

Methods

showsPrec :: Int -> Packet a -> ShowS

show :: Packet a -> String

showList :: [Packet a] -> ShowS

Show a => Show (GenlPacket a)

Show Instance for GenlPacket

Instance details

Defined in System.Linux.Netlink.GeNetlink

Methods

showsPrec :: Int -> GenlPacket a -> ShowS

show :: GenlPacket a -> String

showList :: [GenlPacket a] -> ShowS

class Convertable a where Source #

Typeclase used by the system. Basically Storable for Get and PutM

getGet Returns a Get function for the convertable.

The MessageType is passed so that the function can parse different data structures based on the message type.

Methods

getGet Source #

Arguments

:: MessageType 
-> Get a

get a Get function for the static data

getPut Source #

Arguments

:: a 
-> Put

get a PutM function for the static data

Instances
Convertable NoData Source # 
Instance details

Defined in System.Linux.Netlink

Methods

getGet :: MessageType -> Get NoData Source #

getPut :: NoData -> Put Source #

Convertable GenlHeader Source #

The Convertable instance for GenlHeader

Instance details

Defined in System.Linux.Netlink.GeNetlink

Methods

getGet :: MessageType -> Get GenlHeader Source #

getPut :: GenlHeader -> Put Source #

Convertable Message Source # 
Instance details

Defined in System.Linux.Netlink.Route

Methods

getGet :: MessageType -> Get Message Source #

getPut :: Message -> Put Source #

Convertable a => Convertable (GenlData a) Source #

The Convertable instance for GenlData

Instance details

Defined in System.Linux.Netlink.GeNetlink

Methods

getGet :: MessageType -> Get (GenlData a) Source #

getPut :: GenlData a -> Put Source #

data NoData Source #

Datatype to be used when there is no additional static header

Constructors

NoData 
Instances
Eq NoData Source # 
Instance details

Defined in System.Linux.Netlink

Methods

(==) :: NoData -> NoData -> Bool

(/=) :: NoData -> NoData -> Bool

Show NoData Source # 
Instance details

Defined in System.Linux.Netlink

Methods

showsPrec :: Int -> NoData -> ShowS

show :: NoData -> String

showList :: [NoData] -> ShowS

Convertable NoData Source # 
Instance details

Defined in System.Linux.Netlink

Methods

getGet :: MessageType -> Get NoData Source #

getPut :: NoData -> Put Source #

Show (GenlData NoData)

Show instance of GenlData for NoData

Instance details

Defined in System.Linux.Netlink.GeNetlink

Methods

showsPrec :: Int -> GenlData NoData -> ShowS

show :: GenlData NoData -> String

showList :: [GenlData NoData] -> ShowS

data NetlinkSocket Source #

Typesafe wrapper around a CInt (fd)

getPacket Source #

Arguments

:: ByteString

The buffer to read from

-> Get a

The function to read a single message

-> Either String [a]

Either an error message or a list of messages read

Read packets from the buffer

getAttributes :: Get Attributes Source #

Get Attributes

getHeader :: Get (Int, Header) Source #

Get the netlink Header

putHeader Source #

Arguments

:: Int

The length of the message

-> Header

The header itself

-> Put 

PutM the netlink Header

putAttributes :: Attributes -> Put Source #

PutM a Map of Attributes

putPacket :: (Convertable a, Eq a, Show a) => Packet a -> [ByteString] Source #

PutM a Packet so it can e sent

getPackets :: (Convertable a, Eq a, Show a) => ByteString -> Either String [Packet a] Source #

Read all Packets from a buffer

The packets may have additional static data defined by the protocol.

makeSocket :: IO NetlinkSocket Source #

Open and return a NetlinkSocket, for legacy reasons this opens a route socket

makeSocketGeneric Source #

Arguments

:: Int

The netlink family to use

-> IO NetlinkSocket 

Open a NetlinkSocket. This is the generic function

getNetlinkFd :: NetlinkSocket -> Fd Source #

Get the raw Fd used for netlink communcation (this can be plugged into eventing)

closeSocket :: NetlinkSocket -> IO () Source #

Close a NetlinkSocket when it is no longer used

joinMulticastGroup Source #

Arguments

:: NetlinkSocket

The socket to join with

-> Word32

The id of the group to join, values of System.Linux.Netlink.Constants.eRTNLGRP_*

-> IO () 

Join a netlink multicast group

leaveMulticastGroup Source #

Arguments

:: NetlinkSocket

The socket to leave

-> Word32

The id of the group to leave, values of System.Linux.Netlink.Constants.eRTNLGRP_*

-> IO () 

Leave a netlink multicast group

query :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO [Packet a] Source #

Query data over netlink.

This sends a Packet over netlink and returns the answer. This blocks in a safe foregin function until the other side replies.

queryOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> Packet a -> IO (Packet a) Source #

The same as query but requires the answer to be a single message

recvOne :: (Convertable a, Eq a, Show a) => NetlinkSocket -> IO [Packet a] Source #

Calls recvmsg once and returns all received messages

This should only be used outside of the package when reading multicast messages.

The prototype of this function is unintuitive, but this cannot be avoided without buffering in userspace with the netlink api.

showNLAttrs :: Attributes -> String Source #

Convert generic NLAttrs into a string (# and hexdump)

showAttrs Source #

Arguments

:: (Int -> String)

A function from element id to its name

-> Attributes

The attributes

-> String

A string with Element name and hexdump of element

Helper function to convert attributes into a string

showAttr :: (Int -> String) -> (Int, ByteString) -> String Source #

Helper function to generically show a single attribute

showPacket :: Show a => Packet a -> String Source #

Helperfunction for show instance of Packet and further specializations