Lunatik

netlink.rt.ruleModule

FIB rule (policy routing) interface.

A netlink.session specialization over the NETLINK_ROUTE protocol: create an instance with netlink.rt.rule(), then add, delete and list FIB rules; the underlying socket is closed by close() (or the to-be-closed __close). All methods block and require a sleepable runtime.

See also

Class rule

rule:__call ([pid]) Opens a session, calling the class: netlink.rt.rule([pid]).
rule:add (opts) Adds a FIB rule directing matching lookups to a routing table.
rule:del (opts) Deletes a FIB rule matching the given parameters.
rule:list ([opts]) Lists all FIB rules from the kernel.
rule:new ([o]) Wraps a table in the class, or derives a class from it.

Class rule in detail

rule:__call ([pid])
Opens a session, calling the class: netlink.rt.rule([pid]).

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

    rule a new rule 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

rule:add (opts)
Adds a FIB rule directing matching lookups to a routing table.

Parameters

  • opts table rule parameters: optional family (default AF_INET), table, priority, fwmark, protocol, action (default FR_ACT_TO_TBL).

Raises

the name of the errno a netlink error reply carries, EEXIST when the rule exists.
rule:del (opts)
Deletes a FIB rule matching the given parameters.

Parameters

  • opts table rule parameters: optional family (default AF_INET), table, priority, fwmark.

Raises

the name of the errno a netlink error reply carries, ENOENT when no rule matches.
rule:list ([opts])
Lists all FIB rules from the kernel.

Parameters

  • opts table list options: family, the address family of the records listed (default AF_UNSPEC, every family). (optional)

Returns

    table list of rule tables, each with family, action, flags, table, priority and fwmark; table is the header’s when the reply lacks the TABLE attribute, and any other field whose attribute the reply lacks is nil.
rule:new ([o])
Wraps a table in the class, or derives a class from it. It opens no socket: calling the class does, netlink.rt.rule().

Parameters

  • o table an initial object table. (optional)

Returns

    rule the wrapped table or the derived class.

See also