Lunatik

netlink.rt.routeModule

Kernel routing table interface.

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

See also

Class route

route:__call ([pid]) Opens a session, calling the class: netlink.rt.route([pid]).
route:add (opts) Adds a route to the kernel routing table.
route:del (opts) Deletes a route from the kernel routing table.
route:list ([opts]) Lists all routes from the kernel routing tables.
route:new ([o]) Wraps a table in the class, or derives a class from it.

Class route in detail

route:__call ([pid])
Opens a session, calling the class: netlink.rt.route([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

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

route:add (opts)
Adds a route to the kernel routing table.

Parameters

  • opts table route parameters: optional family (default AF_INET), dst_len, dst, gateway, oif, table, protocol, scope, type. dst and gateway are the address bytes in network byte order, e.g. string.pack(">I4", net.aton("192.0.2.0")), never an integer.

Raises

the name of the errno a netlink error reply carries, EEXIST when the route exists.
route:del (opts)
Deletes a route from the kernel routing table.

Parameters

  • opts table route parameters: optional family (default AF_INET), dst_len, dst, oif, table, as add takes them.

Raises

the name of the errno a netlink error reply carries, ESRCH when no route matches.
route:list ([opts])
Lists all routes from the kernel routing tables.

Parameters

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

Returns

    table list of route tables, each with family, dst_len, src_len, tos, table, protocol, scope, type, flags, dst, gateway, oif and priority; dst and gateway are the address bytes in network byte order; table is the header’s when the reply lacks the TABLE attribute, and any other field whose attribute the reply lacks is nil.
route:new ([o])
Wraps a table in the class, or derives a class from it. It opens no socket: calling the class does, netlink.rt.route().

Parameters

  • o table an initial object table. (optional)

Returns

    route the wrapped table or the derived class.

See also