Line data Source code
1 : /* fd_fib4_netlink.h provides APIs for importing routes from Linux netlink. */ 2 : 3 : #if defined(__linux__) 4 : 5 : #include "fd_fib4.h" 6 : #include "fd_netlink1.h" 7 : 8 : /* FD_FIB_NETLINK_* gives error codes for netlink import operations. */ 9 : 10 0 : #define FD_FIB_NETLINK_SUCCESS (0) /* success */ 11 0 : #define FD_FIB_NETLINK_ERR_OOPS (1) /* unexpected internal error */ 12 0 : #define FD_FIB_NETLINK_ERR_IO (2) /* netlink I/O error */ 13 0 : #define FD_FIB_NETLINK_ERR_INTR (3) /* netlink read was interrupted */ 14 0 : #define FD_FIB_NETLINK_ERR_SPACE (4) /* fib is too small */ 15 : 16 : FD_PROTOTYPES_BEGIN 17 : 18 : /* fd_fib4_netlink_load_table mirrors a route table from netlink to fib. 19 : The route table is requested via RTM_GETROUTE,NLM_F_REQUEST|NLM_F_DUMP. 20 : table_id is in [0,2^31). table_id is typically RT_TABLE_LOCAL or 21 : RT_TABLE_MAIN. These are 255 and 254 respectively on Linux. Assumes 22 : netlink has a usable rtnetlink socket. fib is a writable join to a fib4 23 : object. Logs to debug level for diagnostics and warning level in case 24 : of error. 25 : 26 : Returns FD_FIB4_NETLINK_SUCCESS on success and leaves netlink ready 27 : for the next request. fib is not guaranteed to mirror the route 28 : table precisely even on success. (May turn routes with unsupported 29 : type or attribute into blackhole routes.) 30 : 31 : On failure, leaves a route table that blackholes all packets. 32 : Return values FD_FIB4_NETLINK_ERR_{...} in case of error as follows: 33 : 34 : OOPS: Internal error (bug) occurred. 35 : IO: Unrecoverable send/recv error or failed to parse MULTIPART msg. 36 : INTR: Concurrent write overran read of the routing table. Try again. 37 : SPACE: Routing table is too small to mirror the requested table. 38 : 39 : On return, the netlink socket is ready for the next request (even in 40 : case of error) unless the error is FD_FIB_NETLINK_ERR_IO. */ 41 : 42 : int 43 : fd_fib4_netlink_load_table( fd_fib4_t * fib, 44 : fd_netlink_t * netlink, 45 : uint table_id ); 46 : 47 : FD_FN_CONST char const * 48 : fd_fib4_netlink_strerror( int err ); 49 : 50 : FD_PROTOTYPES_END 51 : 52 : #endif /* defined(__linux__) */