LCOV - code coverage report
Current view: top level - disco/net - fd_net_tile.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 1 24 4.2 %
Date: 2026-08-13 04:56:22 Functions: 0 102 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_net_fd_net_tile_h
       2             : #define HEADER_fd_src_disco_net_fd_net_tile_h
       3             : 
       4             : /* fd_net_tile.h contains APIs for providing XDP networking to a
       5             :    Firedancer topology using the 'net' tile. */
       6             : 
       7             : #include "../fd_disco_base.h"
       8             : #include "../../tango/dcache/fd_dcache.h"
       9             : #include "../../waltz/xdp/fd_xdp1.h"
      10             : #include "../../waltz/ip/fd_fib4.h"
      11             : 
      12             : struct fd_topo;
      13             : typedef struct fd_topo fd_topo_t;
      14             : struct fd_topo_tile;
      15             : 
      16             : /* Helpers for consumers of net tile RX packets */
      17             : 
      18             : struct fd_net_rx_bounds {
      19             :   ulong base;   /* base address of wksp containing dcache */
      20             :   ulong pkt_lo; /* lowest permitted pointer to packet payload */
      21             :   ulong pkt_hi; /* one past last valid byte of packet payload region */
      22             : };
      23             : 
      24             : typedef struct fd_net_rx_bounds fd_net_rx_bounds_t;
      25             : 
      26             : /* FD_NET_BOND_SLAVE_MAX is the hardcoded max number of slave devices
      27             :    per network bonding setup. */
      28             : 
      29           3 : #define FD_NET_BOND_SLAVE_MAX 16U
      30             : 
      31             : FD_PROTOTYPES_BEGIN
      32             : 
      33             : /* fd_net_rx_bounds_init initializes a bounds checker for RX packets
      34             :    produced by the net tile.  dcache is a local join to a dcache that
      35             :    will carry packet payloads. */
      36             : 
      37             : FD_FN_UNUSED static void
      38             : fd_net_rx_bounds_init( fd_net_rx_bounds_t * bounds,
      39           0 :                        void *               dcache ) {
      40           0 :   bounds->base   = (ulong)fd_wksp_containing( dcache );
      41           0 :   bounds->pkt_lo = (ulong)dcache;
      42           0 :   bounds->pkt_hi = bounds->pkt_lo + fd_dcache_data_sz( dcache );
      43           0 :   if( FD_UNLIKELY( !bounds->base ) ) FD_LOG_ERR(( "Failed to find wksp containing dcache" ));
      44           0 : }
      45             : 
      46             : /* fd_net_rx_translate_frag helps net tile consumers locate packet
      47             :    paylads.  bounds is a net_rx_bounds object for the net tile that the
      48             :    frag was received from.  chunk, ctl, sz are frag_meta parameters.
      49             : 
      50             :    Returns a pointer in the local address space to the first byte of an
      51             :    incoming packet.  Terminates the application if the given {chunk,ctl}
      52             :    params would produce an out of bounds buffer. */
      53             : 
      54             : FD_FN_UNUSED static void const *
      55             : fd_net_rx_translate_frag( fd_net_rx_bounds_t const * bounds,
      56             :                           ulong                      chunk,
      57             :                           ulong                      ctl,
      58           0 :                           ulong                      sz ) {
      59           0 :   ulong p = ((ulong)bounds->base + (chunk<<FD_CHUNK_LG_SZ) + ctl);
      60           0 :   if( FD_UNLIKELY( !( (p      >= bounds->pkt_lo) &
      61           0 :                       (p + sz <= bounds->pkt_hi ) &
      62           0 :                       (sz     <= FD_NET_MTU     ) ) ) ) {
      63           0 :     FD_LOG_ERR(( "frag %p (chunk=%lu ctl=%lu sz=%lu) is not in bounds [%p:%p)",
      64           0 :                  (void *)p, chunk, ctl, sz,
      65           0 :                  (void *)bounds->pkt_lo, (void *)bounds->pkt_hi ));
      66           0 :   }
      67           0 :   return (void const *)p;
      68           0 : }
      69             : 
      70             : FD_PROTOTYPES_END
      71             : 
      72             : /* Topology APIs */
      73             : 
      74             : FD_PROTOTYPES_BEGIN
      75             : 
      76             : /* fd_topos_net_tiles appends the net and netlnk tiles to the
      77             :    topology.  These tiles provide fast XDP networking. */
      78             : 
      79             : /* FIXME layering violation */
      80             : struct fd_config_net;
      81             : typedef struct fd_config_net fd_config_net_t;
      82             : 
      83             : void
      84             : fd_topos_net_tiles( fd_topo_t *             topo,
      85             :                     ulong                   net_tile_cnt,
      86             :                     fd_config_net_t const * net_config,
      87             :                     ulong                   netlnk_max_routes,
      88             :                     ulong                   netlnk_max_peer_routes,
      89             :                     ulong                   netlnk_max_neighbors,
      90             :                     int                     xsk_core_dump,
      91             :                     ulong const             tile_to_cpu[ FD_TILE_MAX ] );
      92             : 
      93             : /* fd_topos_net_rx_link is like fd_topob_link, but for net->app tile
      94             :    packet RX links. */
      95             : 
      96             : void
      97             : fd_topos_net_rx_link( fd_topo_t *  topo,
      98             :                       char const * link_name,
      99             :                       ulong        net_kind_id,
     100             :                       ulong        depth );
     101             : 
     102             : /* fd_topob_tile_in_net registers a net TX link with all net tiles. */
     103             : 
     104             : void
     105             : fd_topos_tile_in_net( fd_topo_t *  topo,
     106             :                       char const * fseq_wksp,
     107             :                       char const * link_name,
     108             :                       ulong        link_kind_id,
     109             :                       int          reliable,
     110             :                       int          polled );
     111             : 
     112             : /* This should be called *after* all app<->net tile links have been
     113             :    created.  Should be called once per net tile. */
     114             : 
     115             : void
     116             : fd_topos_net_tile_finish( fd_topo_t * topo,
     117             :                           ulong       net_kind_id );
     118             : 
     119             : /* fd_net_tile_fib4_join returns a pointer to the fib4 object a remote
     120             :    net tile's address space.  Intended for diagnostics only. */
     121             : 
     122             : fd_fib4_t *
     123             : fd_net_tile_fib4_join( fd_fib4_t *                 out,
     124             :                        fd_topo_t const *           topo,
     125             :                        struct fd_topo_tile const * net_tile,
     126             :                        int                         main_table );
     127             : 
     128             : #if defined(__linux__)
     129             : 
     130             : /* fd_topo_install_xdp installs XDP programs to all network devices used
     131             :    by the topology.  This creates a number of file descriptors which
     132             :    will be returned into the fds array.  On entry *fds_cnt is the array
     133             :    size of fds.  On exit, *fds_cnt is the number of fd array entries
     134             :    used.  Closing these fds will undo XDP program installation.
     135             :    bind_addr is an optional IPv4 address to used for filtering by dst
     136             :    IP.  If dry_run is set, does not actually install XDP config, but
     137             :    just returns file descriptors where installs would have occurred. */
     138             : 
     139             : void
     140             : fd_topo_install_xdp( fd_topo_t const * topo,
     141             :                      fd_xdp_fds_t *    fds,
     142             :                      uint *            fds_cnt,
     143             :                      uint              bind_addr,
     144             :                      int               dry_run );
     145             : 
     146             : /* FD_TOPO_XDP_FDS_MAX is the max length of the fd_xdp_fds_t array for
     147             :    an arbitrary supported topology.  (Number of bond slave devices plus
     148             :    loopback) */
     149             : 
     150           0 : #define FD_TOPO_XDP_FDS_MAX (FD_NET_BOND_SLAVE_MAX+1)
     151             : 
     152             : /* fd_topo_install_xdp_simple is a convenience wrapper of the above. */
     153             : 
     154             : FD_FN_UNUSED static void
     155             : fd_topo_install_xdp_simple( fd_topo_t const * topo,
     156           0 :                             uint              bind_addr ) {
     157           0 :   fd_xdp_fds_t fds[ FD_TOPO_XDP_FDS_MAX ];
     158           0 :   uint         fds_cnt = FD_TOPO_XDP_FDS_MAX;
     159           0 :   fd_topo_install_xdp( topo, fds, &fds_cnt, bind_addr, 0 );
     160           0 : }
     161             : 
     162             : #endif /* defined(__linux__) */
     163             : 
     164             : FD_PROTOTYPES_END
     165             : 
     166             : #endif /* HEADER_fd_src_disco_net_fd_net_tile_h */

Generated by: LCOV version 1.14