Lunatik

netlink.sessionModule

Netlink request/response session.

A session owns an AF_NETLINK socket and the transaction discipline on it: talk and dump send one request and drain its complete reply, raising on a kernel error reply (NLMSG_ERROR). Protocol modules (rtnetlink, generic netlink) derive from this class. All methods block and require a sleepable runtime.

See also

Class session

session:__call ([pid]) Creates a session backed by an AF_NETLINK socket of the class’s proto.
session:close () Closes the underlying socket.
session:dump (mtype, payload) Sends a dump request and drains the multipart reply until NLMSG_DONE.
session:new ([o]) Derives a protocol class from the session, as netlink.genl and the netlink.rt classes are, or wraps a table in it.
session:request (mtype, payload[, flags=0]) Sends one request (NLM_F_REQUEST plus flags) with a fresh sequence number, without waiting for a reply.
session:talk (mtype, payload[, flags=0]) Sends a request with NLM_F_ACK and drains the reply up to the kernel acknowledgment, keeping the socket in sync.

Class session in detail

Base class for netlink sessions.
session:__call ([pid])
Creates a session backed by an AF_NETLINK socket of the class’s proto.

Parameters

  • pid integer a task whose network namespace the session talks to, as socket.new takes it; the initial network namespace when absent. (optional)

Returns

    session a new session object; nil and "ESRCH" if no task has that pid, or the task has exited.

Raises

EOPNOTSUPP on a kernel whose sockets cannot hold a namespace of their own.

See also

session:close ()
Closes the underlying socket.
session:dump (mtype, payload)
Sends a dump request and drains the multipart reply until NLMSG_DONE.

Parameters

  • mtype integer message type.
  • payload string the family header and attributes.

Returns

    table the parsed reply messages (the trailing NLMSG_DONE included; see netlink.message.parse).

Raises

on a netlink error reply.
session:new ([o])
Derives a protocol class from the session, as netlink.genl and the netlink.rt classes are, or wraps a table in it. It opens no socket: calling a derived class does, e.g. netlink.rt.route() or netlink.genl().

Parameters

  • o table an initial object table. (optional)

Returns

    session the derived class or the wrapped table.

See also

session:request (mtype, payload[, flags=0])
Sends one request (NLM_F_REQUEST plus flags) with a fresh sequence number, without waiting for a reply.

Parameters

  • mtype integer message type.
  • payload string the family header and attributes.
  • flags integer additional NLM_F_* flags. (default 0)
session:talk (mtype, payload[, flags=0])
Sends a request with NLM_F_ACK and drains the reply up to the kernel acknowledgment, keeping the socket in sync.

Parameters

  • mtype integer message type.
  • payload string the family header and attributes.
  • flags integer extra NLM_F_* flags. (default 0)

Returns

    table the parsed reply messages (the trailing ack included).

Raises

on a netlink error reply.