Line data Source code
1 : #ifndef HEADER_fd_src_waltz_mib_fd_netdev_h 2 : #define HEADER_fd_src_waltz_mib_fd_netdev_h 3 : 4 : /* fd_netdev_tbl.h provides a network interface table. 5 : The entrypoint of this API is fd_netlink_tbl_t. */ 6 : 7 : #include "../../util/fd_util_base.h" 8 : 9 : /* FD_OPER_STATUS_* give the operational state of a network interface. 10 : See RFC 2863 Section 3.1.14: https://datatracker.ietf.org/doc/html/rfc2863#section-3.1.14 */ 11 : 12 0 : #define FD_OPER_STATUS_INVALID (0) 13 0 : #define FD_OPER_STATUS_UP (1) /* ready to pass packets */ 14 0 : #define FD_OPER_STATUS_DOWN (2) 15 0 : #define FD_OPER_STATUS_TESTING (3) /* in some test mode */ 16 0 : #define FD_OPER_STATUS_UNKNOWN (4) /* status can not be determined */ 17 0 : #define FD_OPER_STATUS_DORMANT (5) 18 0 : #define FD_OPER_STATUS_NOT_PRESENT (6) /* some component is missing */ 19 0 : #define FD_OPER_STATUS_LOWER_LAYER_DOWN (7) /* down due to state of lower-layer interface(s) */ 20 : 21 : /* fd_netdev_t holds basic configuration of a network device. */ 22 : 23 : struct fd_netdev { 24 : ushort mtu; /* Largest layer-3 payload that fits in a packet */ 25 : uchar mac_addr[6]; /* MAC address */ 26 : ushort if_idx; /* Interface index */ 27 : short slave_tbl_idx; /* index to bond slave table, -1 if not a bond master */ 28 : short master_idx; /* index of bond master, -1 if not a bond slave */ 29 : char name[16]; /* cstr interface name (max 15 length) */ 30 : uchar oper_status; /* one of FD_OPER_STATUS_{...} */ 31 : uchar pad[1]; 32 : /* padded to 32 bytes */ 33 : }; 34 : 35 : typedef struct fd_netdev fd_netdev_t; 36 : 37 : /* FD_NETDEV_BOND_SLAVE_MAX is the max supported number of bond slaves. */ 38 : 39 : #define FD_NETDEV_BOND_SLAVE_MAX (16) 40 : 41 : /* fd_netdev_bond_t lists active slaves of a bond device. */ 42 : 43 : struct fd_netdev_bond { 44 : uchar slave_cnt; 45 : ushort slave_idx[ FD_NETDEV_BOND_SLAVE_MAX ]; 46 : }; 47 : 48 : typedef struct fd_netdev_bond fd_netdev_bond_t; 49 : 50 : /* fd_netdev_tbl_t provides an interface table. 51 : 52 : This table is optimized for frequent reads and rare writes. It is 53 : generally not thread-safe to modify the table in-place. The only safe 54 : way to sync modifications to other threads is by copying the table in 55 : its entirety. */ 56 : 57 : struct fd_netdev_tbl_private; 58 : typedef struct fd_netdev_tbl_private fd_netdev_tbl_t; 59 : 60 : struct fd_netdev_tbl_hdr { 61 : ushort dev_max; 62 : ushort bond_max; 63 : ushort dev_cnt; 64 : ushort bond_cnt; 65 : }; 66 : typedef struct fd_netdev_tbl_hdr fd_netdev_tbl_hdr_t; 67 : 68 : struct fd_netdev_tbl_join { 69 : fd_netdev_tbl_hdr_t * hdr; 70 : fd_netdev_t * dev_tbl; 71 : fd_netdev_bond_t * bond_tbl; 72 : }; 73 : typedef struct fd_netdev_tbl_join fd_netdev_tbl_join_t; 74 : 75 0 : #define FD_NETDEV_TBL_MAGIC (0xd5f9ba2710d6bf0aUL) /* random */ 76 : 77 : /* FD_NETDEV_TBL_ALIGN is the return value of fd_netdev_tbl_align() */ 78 : 79 9 : #define FD_NETDEV_TBL_ALIGN (16UL) 80 : 81 : FD_PROTOTYPES_BEGIN 82 : 83 : /* fd_netdev_tbl_{align,footprint} describe a memory region suitable to 84 : back a netdev_tbl with dev_max interfaces and bond_max bond masters. */ 85 : 86 : FD_FN_CONST ulong 87 : fd_netdev_tbl_align( void ); 88 : 89 : FD_FN_CONST ulong 90 : fd_netdev_tbl_footprint( ulong dev_max, 91 : ulong bond_max ); 92 : 93 : /* fd_netdev_tbl_new formats a memory region as an empty netdev_tbl. 94 : Returns shmem on success. On failure returns NULL and logs reason for 95 : failure. */ 96 : 97 : void * 98 : fd_netdev_tbl_new( void * shmem, 99 : ulong dev_max, 100 : ulong bond_max ); 101 : 102 : /* fd_netdev_tbl_join joins a netdev_tbl at shtbl. ljoin points to a 103 : fd_netdev_tbl_join_t[1] to which object information is written to. 104 : Returns ljoin on success. On failure, returns NULL and logs reason for 105 : failure. */ 106 : 107 : fd_netdev_tbl_join_t * 108 : fd_netdev_tbl_join( void * ljoin, 109 : void * shtbl ); 110 : 111 : /* fd_netdev_tbl_leave undoes a fd_netdev_tbl_join. Returns ownership 112 : of the region backing join to the caller. (Warning: This returns ljoin, 113 : not shtbl) */ 114 : 115 : void * 116 : fd_netdev_tbl_leave( fd_netdev_tbl_join_t * join ); 117 : 118 : /* fd_netdev_tbl_delete unformats the memory region backing a netdev_tbl 119 : and returns ownership of the region back to the caller. */ 120 : 121 : void * 122 : fd_netdev_tbl_delete( void * shtbl ); 123 : 124 : /* fd_netdev_tbl_reset resets the table to the state of a newly constructed 125 : empty object (clears all devices and bonds). */ 126 : 127 : void 128 : fd_netdev_tbl_reset( fd_netdev_tbl_join_t * tbl ); 129 : 130 : #if FD_HAS_HOSTED 131 : 132 : /* fd_netdev_tbl_fprintf prints the interface table to the given FILE * 133 : pointer (or target equivalent). Outputs ASCII encoding with LF 134 : newlines. Returns errno on failure and 0 on success. */ 135 : 136 : int 137 : fd_netdev_tbl_fprintf( fd_netdev_tbl_join_t const * tbl, 138 : void * file ); 139 : 140 : #endif /* FD_HAS_HOSTED */ 141 : 142 : FD_PROTOTYPES_END 143 : 144 : char const * 145 : fd_oper_status_cstr( uint oper_status ); 146 : 147 : #endif /* HEADER_fd_src_waltz_mib_fd_netdev_h */