LCOV - code coverage report
Current view: top level - waltz/ip - fd_fib4_netlink.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 5 0.0 %
Date: 2026-09-01 04:28:17 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_ip_fd_fib4_netlink_h
       2             : #define HEADER_fd_src_waltz_ip_fd_fib4_netlink_h
       3             : 
       4             : /* fd_fib4_netlink.h provides APIs for importing routes from Linux netlink. */
       5             : 
       6             : #if defined(__linux__)
       7             : 
       8             : #include "fd_fib4.h"
       9             : #include "fd_iproute.h"
      10             : #include "fd_netlink1.h"
      11             : 
      12             : /* FD_FIB_NETLINK_* gives error codes for netlink import operations. */
      13             : 
      14           0 : #define FD_FIB_NETLINK_SUCCESS   (0) /* success */
      15           0 : #define FD_FIB_NETLINK_ERR_OOPS  (1) /* unexpected internal error */
      16           0 : #define FD_FIB_NETLINK_ERR_IO    (2) /* netlink I/O error */
      17           0 : #define FD_FIB_NETLINK_ERR_INTR  (3) /* netlink read was interrupted */
      18           0 : #define FD_FIB_NETLINK_ERR_SPACE (4) /* fib is too small */
      19             : 
      20             : FD_PROTOTYPES_BEGIN
      21             : 
      22             : /* Translates one RTM_{NEW,DEL}ROUTE message to an fd_iproute_msg_t.
      23             :    Returns 1 if the netlink msg was translated, and 0 otherwise (the
      24             :    message did not match table_id and was ignored). */
      25             : 
      26             : int
      27             : fd_fib4_netlink_translate( struct nlmsghdr const * msg_hdr,
      28             :                            uint                    table_id,
      29             :                            fd_iproute_msg_t *      route );
      30             : 
      31             : typedef int (*fd_fib4_netlink_route_fn_t)( void * arg, fd_iproute_msg_t const * route );
      32             : 
      33             : /* fd_fib4_netlink_dump_table dumps a table and invokes fn once per
      34             :    accepted route. */
      35             : 
      36             : int
      37             : fd_fib4_netlink_dump_table( fd_netlink_t *             netlink,
      38             :                             uint                       table_id,
      39             :                             fd_fib4_netlink_route_fn_t fn,
      40             :                             void *                     arg );
      41             : 
      42             : /* fd_fib4_netlink_load_table mirrors a route table from netlink to fib.
      43             :    The route table is requested via RTM_GETROUTE,NLM_F_REQUEST|NLM_F_DUMP.
      44             :    table_id is in [0,2^31).  table_id is typically RT_TABLE_LOCAL or
      45             :    RT_TABLE_MAIN.  These are 255 and 254 respectively on Linux.  Assumes
      46             :    netlink has a usable rtnetlink socket.  fib is a writable join to a fib4
      47             :    object.  Logs to debug level for diagnostics and warning level in case
      48             :    of error.
      49             : 
      50             :    Returns FD_FIB4_NETLINK_SUCCESS on success and leaves netlink ready
      51             :    for the next request.  fib is not guaranteed to mirror the route
      52             :    table precisely even on success.  (May turn routes with unsupported
      53             :    type or attribute into blackhole routes.)
      54             : 
      55             :    On failure, leaves a route table that blackholes all packets.
      56             :    Return values FD_FIB4_NETLINK_ERR_{...} in case of error as follows:
      57             : 
      58             :      OOPS:  Internal error (bug) occurred.
      59             :      IO:    Unrecoverable send/recv error or failed to parse MULTIPART msg.
      60             :      INTR:  Concurrent write overran read of the routing table.  Try again.
      61             :      SPACE: Routing table is too small to mirror the requested table.
      62             : 
      63             :    On return, the netlink socket is ready for the next request (even in
      64             :    case of error) unless the error is FD_FIB_NETLINK_ERR_IO. */
      65             : 
      66             : int
      67             : fd_fib4_netlink_load_table( fd_fib4_t *    fib,
      68             :                             fd_netlink_t * netlink,
      69             :                             uint           table_id );
      70             : 
      71             : FD_FN_CONST char const *
      72             : fd_fib4_netlink_strerror( int err );
      73             : 
      74             : FD_PROTOTYPES_END
      75             : 
      76             : #endif /* defined(__linux__) */
      77             : 
      78             : #endif /* HEADER_fd_src_waltz_ip_fd_fib4_netlink_h */

Generated by: LCOV version 1.14