Module fib

Forwarding Information Base (FIB) rules.

This library allows Lua scripts to add and delete FIB rules, similar to the user-space ip rule add and ip rule del commands. FIB rules are used to influence routing decisions by selecting different routing tables based on various criteria.

Functions

delrule (table, priority) Deletes an existing FIB rule.
newrule (table, priority) Adds a new FIB rule.


Functions

delrule (table, priority)
Deletes an existing FIB rule. This function binds the kernel fib_nl_delrule API. It removes a FIB rule that matches the specified routing table and priority.

Parameters:

  • table integer The routing table identifier of the rule to delete.
  • priority integer The priority of the rule to delete.

Returns:

    nil

Raises:

Error if the rule cannot be deleted (e.g., rule not found, kernel error).

Usage:

    fib.delrule(100, 10000) -- Delete the rule with priority 10000 that looks up table 100
newrule (table, priority)
Adds a new FIB rule. This function binds the kernel fib_nl_newrule API. It creates a new FIB rule that directs lookups to the specified routing table for packets matching this rule's priority.

Note: This function creates a relatively simple rule. The rule is always for IPv4 (AF_INET), the action is always to look up the specified table (FR_ACT_TO_TBL), and the protocol is set to RTPROT_KERNEL. It does not support specifying other match conditions (e.g., source/destination IP, interface, fwmark).

Parameters:

  • table integer The routing table identifier (e.g., 254 for main, 255 for local).
  • priority integer The priority of the rule. Lower numbers have higher precedence.

Returns:

    nil

Raises:

Error if the rule cannot be added (e.g., due to kernel error, invalid parameters).

Usage:

    fib.newrule(100, 10000) -- Add a rule with priority 10000 to lookup table 100
generated by LDoc 1.5.0 Last updated 2025-06-27 17:53:55