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