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_FIB_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, clears fib to its default THROW route, permitting a 56 : caller to fall through to another table via fd_fib4_hop_or. 57 : Return values FD_FIB_NETLINK_ERR_{...} in case of error as follows: 58 : 59 : OOPS: Internal error (bug) occurred. 60 : IO: Unrecoverable send/recv error or failed to parse MULTIPART msg. 61 : INTR: Concurrent write overran read of the routing table. Try again. 62 : SPACE: Routing table is too small to mirror the requested table. 63 : 64 : On return, the netlink socket is ready for the next request (even in 65 : case of error) unless the error is FD_FIB_NETLINK_ERR_IO. */ 66 : 67 : int 68 : fd_fib4_netlink_load_table( fd_fib4_t * fib, 69 : fd_netlink_t * netlink, 70 : uint table_id ); 71 : 72 : FD_FN_CONST char const * 73 : fd_fib4_netlink_strerror( int err ); 74 : 75 : FD_PROTOTYPES_END 76 : 77 : #endif /* defined(__linux__) */ 78 : 79 : #endif /* HEADER_fd_src_waltz_ip_fd_fib4_netlink_h */