LCOV - code coverage report
Current view: top level - app/shared/commands/configure - ethtool-loopback.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 28 0.0 %
Date: 2025-10-13 04:42:14 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* This stage disables the "tx-udp-segmentation" offload on the loopback
       2             :    interface.  If left enabled, AF_XDP will drop loopback UDP packets sent
       3             :    by processes that enable TX segmentation via SOL_UDP/UDP_SEGMENT sockopt
       4             :    or cmsg.
       5             : 
       6             :    TLDR tx-udp-segmentation and AF_XDP are incompatible. */
       7             : 
       8             : #include "configure.h"
       9             : 
      10             : #include "fd_ethtool_ioctl.h"
      11             : 
      12           0 : #define NAME "ethtool-loopback"
      13             : 
      14             : static int
      15           0 : enabled( fd_config_t const * config ) {
      16             : 
      17             :   /* if we're running in a network namespace, we configure ethtool on
      18             :      the virtual device as part of netns setup, not here */
      19           0 :   if( config->development.netns.enabled ) return 0;
      20             : 
      21             :   /* only enable if network stack is XDP */
      22           0 :   if( 0!=strcmp( config->net.provider, "xdp" ) ) return 0;
      23             : 
      24           0 :   return 1;
      25           0 : }
      26             : 
      27             : static void
      28             : init_perm( fd_cap_chk_t *      chk,
      29           0 :            fd_config_t const * config FD_PARAM_UNUSED ) {
      30           0 :   fd_cap_chk_root( chk, NAME, "disable loopback " FD_ETHTOOL_FEATURE_TXUDPSEG " with `ethtool --offload lo " FD_ETHTOOL_FEATURE_TXUDPSEG " off`" );
      31           0 : }
      32             : 
      33             : static void
      34           0 : init( fd_config_t const * config FD_PARAM_UNUSED ) {
      35           0 :   fd_ethtool_ioctl_t ioc;
      36           0 :   if( FD_UNLIKELY( &ioc != fd_ethtool_ioctl_init( &ioc, "lo" ) ) )
      37           0 :     FD_LOG_ERR(( "error configuring network device (lo), unable to init ethtool ioctl" ));
      38             : 
      39           0 :   FD_TEST( 0==fd_ethtool_ioctl_feature_set( &ioc, FD_ETHTOOL_FEATURE_TXUDPSEG, 0 ) );
      40             : 
      41           0 :   fd_ethtool_ioctl_fini( &ioc );
      42           0 : }
      43             : 
      44             : static configure_result_t
      45           0 : check( fd_config_t const * config FD_PARAM_UNUSED ) {
      46           0 :   fd_ethtool_ioctl_t ioc;
      47           0 :   if( FD_UNLIKELY( &ioc != fd_ethtool_ioctl_init( &ioc, "lo" ) ) )
      48           0 :     FD_LOG_ERR(( "error configuring network device (lo), unable to init ethtool ioctl" ));
      49             : 
      50           0 :   int udpseg_active;
      51           0 :   FD_TEST( 0==fd_ethtool_ioctl_feature_test( &ioc, FD_ETHTOOL_FEATURE_TXUDPSEG, &udpseg_active ) );
      52             : 
      53           0 :   fd_ethtool_ioctl_fini( &ioc );
      54             : 
      55           0 :   if( udpseg_active ) {
      56           0 :     NOT_CONFIGURED( "device `lo` has " FD_ETHTOOL_FEATURE_TXUDPSEG " enabled. Should be disabled" );
      57           0 :   }
      58             : 
      59           0 :   CONFIGURE_OK();
      60           0 : }
      61             : 
      62             : configure_stage_t fd_cfg_stage_ethtool_loopback = {
      63             :   .name            = NAME,
      64             :   .always_recreate = 0,
      65             :   .enabled         = enabled,
      66             :   .init_perm       = init_perm,
      67             :   .fini_perm       = NULL,
      68             :   .init            = init,
      69             :   .fini            = NULL,
      70             :   .check           = check,
      71             : };
      72             : 
      73             : #undef NAME

Generated by: LCOV version 1.14