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 : ushort dev_type; /* one of ARPHRD_ETHER/_LOOPBACK_/IPGRE*/ 32 : uint gre_dst_ip; 33 : uint gre_src_ip; 34 : }; 35 : 36 : typedef struct fd_netdev fd_netdev_t; 37 : 38 : /* FD_NETDEV_BOND_SLAVE_MAX is the max supported number of bond slaves. */ 39 : 40 : #define FD_NETDEV_BOND_SLAVE_MAX (16) 41 : 42 : /* fd_netdev_bond_t lists active slaves of a bond device. */ 43 : 44 : struct fd_netdev_bond { 45 : uchar slave_cnt; 46 : ushort slave_idx[ FD_NETDEV_BOND_SLAVE_MAX ]; 47 : }; 48 : 49 : typedef struct fd_netdev_bond fd_netdev_bond_t; 50 : 51 : /* fd_netdev_tbl_t provides an interface table. 52 : 53 : This table is optimized for frequent reads and rare writes. It is 54 : generally not thread-safe to modify the table in-place. The only safe 55 : way to sync modifications to other threads is by copying the table in 56 : its entirety. */ 57 : 58 : struct fd_netdev_tbl_private; 59 : typedef struct fd_netdev_tbl_private fd_netdev_tbl_t; 60 : 61 : struct fd_netdev_tbl_hdr { 62 : ushort dev_max; 63 : ushort bond_max; 64 : ushort dev_cnt; 65 : ushort bond_cnt; 66 : }; 67 : typedef struct fd_netdev_tbl_hdr fd_netdev_tbl_hdr_t; 68 : 69 : struct fd_netdev_tbl_join { 70 : fd_netdev_tbl_hdr_t * hdr; 71 : fd_netdev_t * dev_tbl; 72 : fd_netdev_bond_t * bond_tbl; 73 : }; 74 : typedef struct fd_netdev_tbl_join fd_netdev_tbl_join_t; 75 : 76 6 : #define FD_NETDEV_TBL_MAGIC (0xd5f9ba2710d6bf0aUL) /* random */ 77 : 78 : /* FD_NETDEV_TBL_ALIGN is the return value of fd_netdev_tbl_align() */ 79 : 80 18 : #define FD_NETDEV_TBL_ALIGN (16UL) 81 : 82 : FD_PROTOTYPES_BEGIN 83 : 84 : /* fd_netdev_tbl_{align,footprint} describe a memory region suitable to 85 : back a netdev_tbl with dev_max interfaces and bond_max bond masters. */ 86 : 87 : FD_FN_CONST ulong 88 : fd_netdev_tbl_align( void ); 89 : 90 : FD_FN_CONST ulong 91 : fd_netdev_tbl_footprint( ulong dev_max, 92 : ulong bond_max ); 93 : 94 : /* fd_netdev_tbl_new formats a memory region as an empty netdev_tbl. 95 : Returns shmem on success. On failure returns NULL and logs reason for 96 : failure. */ 97 : 98 : void * 99 : fd_netdev_tbl_new( void * shmem, 100 : ulong dev_max, 101 : ulong bond_max ); 102 : 103 : /* fd_netdev_tbl_join joins a netdev_tbl at shtbl. ljoin points to a 104 : fd_netdev_tbl_join_t[1] to which object information is written to. 105 : Returns ljoin on success. On failure, returns NULL and logs reason for 106 : failure. */ 107 : 108 : fd_netdev_tbl_join_t * 109 : fd_netdev_tbl_join( void * ljoin, 110 : void * shtbl ); 111 : 112 : /* fd_netdev_tbl_leave undoes a fd_netdev_tbl_join. Returns ownership 113 : of the region backing join to the caller. (Warning: This returns ljoin, 114 : not shtbl) */ 115 : 116 : void * 117 : fd_netdev_tbl_leave( fd_netdev_tbl_join_t * join ); 118 : 119 : /* fd_netdev_tbl_delete unformats the memory region backing a netdev_tbl 120 : and returns ownership of the region back to the caller. */ 121 : 122 : void * 123 : fd_netdev_tbl_delete( void * shtbl ); 124 : 125 : /* fd_netdev_tbl_reset resets the table to the state of a newly constructed 126 : empty object (clears all devices and bonds). */ 127 : 128 : void 129 : fd_netdev_tbl_reset( fd_netdev_tbl_join_t * tbl ); 130 : 131 : #if FD_HAS_HOSTED 132 : 133 : /* fd_netdev_tbl_fprintf prints the interface table to the given FILE * 134 : pointer (or target equivalent). Outputs ASCII encoding with LF 135 : newlines. Returns errno on failure and 0 on success. */ 136 : 137 : int 138 : fd_netdev_tbl_fprintf( fd_netdev_tbl_join_t const * tbl, 139 : void * file ); 140 : 141 : #endif /* FD_HAS_HOSTED */ 142 : 143 : FD_PROTOTYPES_END 144 : 145 : char const * 146 : fd_oper_status_cstr( uint oper_status ); 147 : 148 : #endif /* HEADER_fd_src_waltz_mib_fd_netdev_h */