platform: move ethtool ioctl functions to a separate file

We're going to replace most of the ioctl-based ethtool functions with
a netlink-based equivalent. Move the ioctl ones to a separate file so
that it's easier to see what still needs to be converted. Also add a
common prefix to the function names.
This commit is contained in:
Beniamino Galvani 2025-03-19 13:37:10 +01:00
parent 88efe48916
commit e8a3cd611e
10 changed files with 1888 additions and 1854 deletions

View file

@ -15,6 +15,7 @@
#include "libnm-base/nm-ethtool-base.h"
#include "libnm-platform/nmp-object.h"
#include "libnm-platform/nmp-netns.h"
#include "libnm-platform/nmp-ethtool-ioctl.h"
#include "libnm-platform/nm-platform-utils.h"
#include "test-common.h"
@ -3183,10 +3184,10 @@ test_netns_general(gpointer fixture, gconstpointer test_data)
* Work around that and skip asserts that are known to fail. */
ethtool_support = nmtstp_run_command("ethtool -i dummy1_ > /dev/null") == 0;
if (ethtool_support) {
g_assert(nmp_utils_ethtool_get_driver_info(
g_assert(nmp_ethtool_ioctl_get_driver_info(
nmtstp_link_get_typed(platform_1, 0, "dummy1_", NM_LINK_TYPE_DUMMY)->ifindex,
&driver_info));
g_assert(nmp_utils_ethtool_get_driver_info(
g_assert(nmp_ethtool_ioctl_get_driver_info(
nmtstp_link_get_typed(platform_1, 0, "dummy2a", NM_LINK_TYPE_DUMMY)->ifindex,
&driver_info));
g_assert_cmpint(nmtstp_run_command("ethtool -i dummy1_ > /dev/null"), ==, 0);
@ -3197,10 +3198,10 @@ test_netns_general(gpointer fixture, gconstpointer test_data)
g_assert(nm_platform_netns_push(platform_2, &netns_tmp));
if (ethtool_support) {
g_assert(nmp_utils_ethtool_get_driver_info(
g_assert(nmp_ethtool_ioctl_get_driver_info(
nmtstp_link_get_typed(platform_2, 0, "dummy1_", NM_LINK_TYPE_DUMMY)->ifindex,
&driver_info));
g_assert(nmp_utils_ethtool_get_driver_info(
g_assert(nmp_ethtool_ioctl_get_driver_info(
nmtstp_link_get_typed(platform_2, 0, "dummy2b", NM_LINK_TYPE_DUMMY)->ifindex,
&driver_info));
g_assert_cmpint(nmtstp_run_command("ethtool -i dummy1_ > /dev/null"), ==, 0);
@ -4031,7 +4032,7 @@ test_ethtool_features_get(void)
_LOGT(">>> ethtool-features-get RUN %u (do-set=%s", i_run, do_set ? "set" : "reset");
features = nmp_utils_ethtool_get_features(IFINDEX);
features = nmp_ethtool_ioctl_get_features(IFINDEX);
g_ptr_array_add(gfree_keeper, features);
ethtool_features_dump(features);
@ -4044,7 +4045,7 @@ test_ethtool_features_get(void)
features = gfree_keeper->pdata[i_run * 2 - 1];
}
nmp_utils_ethtool_set_features(IFINDEX, features, requested, do_set);
nmp_ethtool_ioctl_set_features(IFINDEX, features, requested, do_set);
}
}

View file

@ -14,6 +14,7 @@
#include "libnm-platform/nm-netlink.h"
#include "libnm-platform/nm-platform.h"
#include "libnm-platform/nm-platform-utils.h"
#include "libnm-platform/nmp-ethtool-ioctl.h"
#define _NMLOG_PREFIX_NAME "devlink"
#define _NMLOG_DOMAIN LOGD_PLATFORM | LOGD_DEVICE
@ -118,7 +119,7 @@ nm_devlink_get_dev_identifier(NMDevlink *self, char **out_bus, char **out_addr,
return FALSE;
}
if (!nmp_utils_ethtool_get_driver_info(self->ifindex, &ethtool_driver_info)) {
if (!nmp_ethtool_ioctl_get_driver_info(self->ifindex, &ethtool_driver_info)) {
g_set_error(error,
NM_UTILS_ERROR,
NM_UTILS_ERROR_UNKNOWN,

View file

@ -12,6 +12,7 @@ libnm_platform = static_library(
'nmp-netns.c',
'nmp-object.c',
'nmp-plobj.c',
'nmp-ethtool-ioctl.c',
'devlink/nm-devlink.c',
'wifi/nm-wifi-utils-nl80211.c',
'wifi/nm-wifi-utils.c',

View file

@ -41,6 +41,7 @@
#include "libnm-platform/nm-netlink.h"
#include "libnm-platform/nm-platform-utils.h"
#include "libnm-platform/nmp-netns.h"
#include "libnm-platform/nmp-ethtool-ioctl.h"
#include "libnm-platform/devlink/nm-devlink.h"
#include "libnm-platform/wifi/nm-wifi-utils-wext.h"
#include "libnm-platform/wifi/nm-wifi-utils.h"
@ -1320,7 +1321,7 @@ _linktype_get_type(NMPlatform *platform,
NMPUtilsEthtoolDriverInfo driver_info;
/* Fallback OVS detection for kernel <= 3.16 */
if (nmp_utils_ethtool_get_driver_info(ifindex, &driver_info)) {
if (nmp_ethtool_ioctl_get_driver_info(ifindex, &driver_info)) {
if (nm_streq(driver_info.driver, "openvswitch"))
return NM_LINK_TYPE_OPENVSWITCH;
@ -8966,8 +8967,8 @@ link_supports_carrier_detect(NMPlatform *platform, int ifindex)
* us whether the device actually supports carrier detection in the first
* place. We assume any device that does implements one of these two APIs.
*/
return nmp_utils_ethtool_supports_carrier_detect(ifindex)
|| nmp_utils_mii_supports_carrier_detect(ifindex);
return nmp_ethtool_ioctl_supports_carrier_detect(ifindex)
|| nmp_mii_ioctl_supports_carrier_detect(ifindex);
}
static gboolean
@ -8985,7 +8986,7 @@ link_supports_vlans(NMPlatform *platform, int ifindex)
if (!nm_platform_netns_push(platform, &netns))
return FALSE;
return nmp_utils_ethtool_supports_vlans(ifindex);
return nmp_ethtool_ioctl_supports_vlans(ifindex);
}
static gboolean
@ -9063,7 +9064,7 @@ link_get_permanent_address_ethtool(NMPlatform *platform, int ifindex, NMPLinkAdd
if (!nm_platform_netns_push(platform, &netns))
return FALSE;
if (!nmp_utils_ethtool_get_permanent_address(ifindex, buffer, &len))
if (!nmp_ethtool_ioctl_get_permanent_address(ifindex, buffer, &len))
return FALSE;
nm_assert(len <= _NM_UTILS_HWADDR_LEN_MAX);
memcpy(out_address->data, buffer, len);
@ -10391,7 +10392,7 @@ link_get_wake_on_lan(NMPlatform *platform, int ifindex)
return FALSE;
if (type == NM_LINK_TYPE_ETHERNET)
return nmp_utils_ethtool_get_wake_on_lan(ifindex);
return nmp_ethtool_ioctl_get_wake_on_lan(ifindex);
else if (type == NM_LINK_TYPE_WIFI) {
WIFI_GET_WIFI_DATA(wifi_data, platform, ifindex, FALSE);
@ -10416,7 +10417,7 @@ link_get_driver_info(NMPlatform *platform,
if (!nm_platform_netns_push(platform, &netns))
return FALSE;
if (!nmp_utils_ethtool_get_driver_info(ifindex, &driver_info))
if (!nmp_ethtool_ioctl_get_driver_info(ifindex, &driver_info))
return FALSE;
NM_SET_OUT(out_driver_name, g_strdup(driver_info.driver));
NM_SET_OUT(out_driver_version, g_strdup(driver_info.version));

File diff suppressed because it is too large Load diff

View file

@ -8,72 +8,17 @@
#include "libnm-base/nm-base.h"
#include "libnm-platform/nmp-base.h"
#include "libnm-platform/nm-platform.h"
/*****************************************************************************/
const char *nmp_utils_ethtool_get_driver(int ifindex);
gboolean nmp_utils_ethtool_supports_carrier_detect(int ifindex);
gboolean nmp_utils_ethtool_supports_vlans(int ifindex);
int nmp_utils_ethtool_get_peer_ifindex(int ifindex);
gboolean nmp_utils_ethtool_get_wake_on_lan(int ifindex);
gboolean nmp_utils_ethtool_set_wake_on_lan(int ifindex,
_NMSettingWiredWakeOnLan wol,
const char *wol_password);
const char *nm_platform_link_duplex_type_to_string(NMPlatformLinkDuplexType duplex);
extern const guint8 _nmp_link_mode_all_advertised_modes_bits[79];
extern const guint32 _nmp_link_mode_all_advertised_modes[3];
gboolean nmp_utils_ethtool_get_link_settings(int ifindex,
gboolean *out_autoneg,
guint32 *out_speed,
NMPlatformLinkDuplexType *out_duplex);
gboolean nmp_utils_ethtool_set_link_settings(int ifindex,
gboolean autoneg,
guint32 speed,
NMPlatformLinkDuplexType duplex);
gboolean nmp_utils_ethtool_get_permanent_address(int ifindex, guint8 *buf, size_t *length);
gboolean nmp_utils_ethtool_get_driver_info(int ifindex, NMPUtilsEthtoolDriverInfo *data);
NMEthtoolFeatureStates *nmp_utils_ethtool_get_features(int ifindex);
gboolean nmp_utils_ethtool_set_features(
int ifindex,
const NMEthtoolFeatureStates *features,
const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */,
gboolean do_set /* or reset */);
gboolean nmp_utils_ethtool_get_coalesce(int ifindex, NMEthtoolCoalesceState *coalesce);
gboolean nmp_utils_ethtool_set_coalesce(int ifindex, const NMEthtoolCoalesceState *coalesce);
gboolean nmp_utils_ethtool_get_ring(int ifindex, NMEthtoolRingState *ring);
gboolean nmp_utils_ethtool_set_ring(int ifindex, const NMEthtoolRingState *ring);
gboolean nmp_utils_ethtool_get_channels(int ifindex, NMEthtoolChannelsState *channels);
gboolean nmp_utils_ethtool_set_channels(int ifindex, const NMEthtoolChannelsState *channels);
gboolean nmp_utils_ethtool_get_pause(int ifindex, NMEthtoolPauseState *pause);
gboolean nmp_utils_ethtool_set_pause(int ifindex, const NMEthtoolPauseState *pause);
gboolean nmp_utils_ethtool_get_eee(int ifindex, NMEthtoolEEEState *eee);
gboolean nmp_utils_ethtool_set_eee(int ifindex, const NMEthtoolEEEState *eee);
gboolean nmp_utils_ethtool_get_fec_mode(int ifindex, uint32_t *fec_mode);
gboolean nmp_utils_ethtool_set_fec_mode(int ifindex, uint32_t fec_mode);
/*****************************************************************************/
gboolean nmp_utils_mii_supports_carrier_detect(int ifindex);
struct udev_device;
const char *nmp_utils_udev_get_driver(struct udev_device *udevice);

View file

@ -31,6 +31,7 @@
#include "libnm-log-core/nm-logging.h"
#include "libnm-platform/nm-platform-utils.h"
#include "libnm-platform/nmp-netns.h"
#include "libnm-platform/nmp-ethtool-ioctl.h"
#include "libnm-udev-aux/nm-udev-utils.h"
#include "nm-platform-private.h"
#include "nmp-object.h"
@ -3230,7 +3231,7 @@ nm_platform_link_veth_get_properties(NMPlatform *self, int ifindex, int *out_pee
if (!nm_platform_netns_push(self, &netns))
return FALSE;
peer_ifindex = nmp_utils_ethtool_get_peer_ifindex(plink->ifindex);
peer_ifindex = nmp_ethtool_ioctl_get_peer_ifindex(plink->ifindex);
if (peer_ifindex <= 0)
return FALSE;
@ -3561,7 +3562,7 @@ nm_platform_ethtool_set_wake_on_lan(NMPlatform *self,
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_wake_on_lan(ifindex, wol, wol_password);
return nmp_ethtool_ioctl_set_wake_on_lan(ifindex, wol, wol_password);
}
gboolean
@ -3575,7 +3576,7 @@ nm_platform_ethtool_set_link_settings(NMPlatform *self,
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_link_settings(ifindex, autoneg, speed, duplex);
return nmp_ethtool_ioctl_set_link_settings(ifindex, autoneg, speed, duplex);
}
gboolean
@ -3589,7 +3590,7 @@ nm_platform_ethtool_get_link_settings(NMPlatform *self,
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_get_link_settings(ifindex, out_autoneg, out_speed, out_duplex);
return nmp_ethtool_ioctl_get_link_settings(ifindex, out_autoneg, out_speed, out_duplex);
}
/*****************************************************************************/
@ -3601,7 +3602,7 @@ nm_platform_ethtool_get_features(NMPlatform *self, int ifindex)
g_return_val_if_fail(ifindex > 0, NULL);
return nmp_utils_ethtool_get_features(ifindex);
return nmp_ethtool_ioctl_get_features(ifindex);
}
gboolean
@ -3616,7 +3617,7 @@ nm_platform_ethtool_set_features(
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_features(ifindex, features, requested, do_set);
return nmp_ethtool_ioctl_set_features(ifindex, features, requested, do_set);
}
gboolean
@ -3626,7 +3627,7 @@ nm_platform_ethtool_get_fec_mode(NMPlatform *self, int ifindex, uint32_t *fec_mo
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_get_fec_mode(ifindex, fec_mode);
return nmp_ethtool_ioctl_get_fec_mode(ifindex, fec_mode);
}
gboolean
@ -3636,7 +3637,7 @@ nm_platform_ethtool_set_fec_mode(NMPlatform *self, int ifindex, uint32_t fec_mod
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_fec_mode(ifindex, fec_mode);
return nmp_ethtool_ioctl_set_fec_mode(ifindex, fec_mode);
}
gboolean
@ -3647,7 +3648,7 @@ nm_platform_ethtool_get_coalesce(NMPlatform *self, int ifindex, NMEthtoolCoalesc
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(coalesce, FALSE);
return nmp_utils_ethtool_get_coalesce(ifindex, coalesce);
return nmp_ethtool_ioctl_get_coalesce(ifindex, coalesce);
}
gboolean
@ -3659,7 +3660,7 @@ nm_platform_ethtool_set_coalesce(NMPlatform *self,
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_coalesce(ifindex, coalesce);
return nmp_ethtool_ioctl_set_coalesce(ifindex, coalesce);
}
gboolean
@ -3670,7 +3671,7 @@ nm_platform_ethtool_get_ring(NMPlatform *self, int ifindex, NMEthtoolRingState *
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(ring, FALSE);
return nmp_utils_ethtool_get_ring(ifindex, ring);
return nmp_ethtool_ioctl_get_ring(ifindex, ring);
}
gboolean
@ -3680,7 +3681,7 @@ nm_platform_ethtool_set_ring(NMPlatform *self, int ifindex, const NMEthtoolRingS
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_ring(ifindex, ring);
return nmp_ethtool_ioctl_set_ring(ifindex, ring);
}
gboolean
@ -3691,7 +3692,7 @@ nm_platform_ethtool_get_channels(NMPlatform *self, int ifindex, NMEthtoolChannel
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(channels, FALSE);
return nmp_utils_ethtool_get_channels(ifindex, channels);
return nmp_ethtool_ioctl_get_channels(ifindex, channels);
}
gboolean
@ -3703,7 +3704,7 @@ nm_platform_ethtool_set_channels(NMPlatform *self,
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_channels(ifindex, channels);
return nmp_ethtool_ioctl_set_channels(ifindex, channels);
}
gboolean
@ -3714,7 +3715,7 @@ nm_platform_ethtool_get_pause(NMPlatform *self, int ifindex, NMEthtoolPauseState
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(pause, FALSE);
return nmp_utils_ethtool_get_pause(ifindex, pause);
return nmp_ethtool_ioctl_get_pause(ifindex, pause);
}
gboolean
@ -3724,7 +3725,7 @@ nm_platform_ethtool_set_pause(NMPlatform *self, int ifindex, const NMEthtoolPaus
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_pause(ifindex, pause);
return nmp_ethtool_ioctl_set_pause(ifindex, pause);
}
gboolean
@ -3735,7 +3736,7 @@ nm_platform_ethtool_get_eee(NMPlatform *self, int ifindex, NMEthtoolEEEState *ee
g_return_val_if_fail(ifindex > 0, FALSE);
g_return_val_if_fail(eee, FALSE);
return nmp_utils_ethtool_get_eee(ifindex, eee);
return nmp_ethtool_ioctl_get_eee(ifindex, eee);
}
gboolean
@ -3745,7 +3746,7 @@ nm_platform_ethtool_set_eee(NMPlatform *self, int ifindex, const NMEthtoolEEESta
g_return_val_if_fail(ifindex > 0, FALSE);
return nmp_utils_ethtool_set_eee(ifindex, eee);
return nmp_ethtool_ioctl_set_eee(ifindex, eee);
}
/*****************************************************************************/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,67 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#ifndef __NMP_ETHTOOL_IOCTL_H__
#define __NMP_ETHTOOL_IOCTL_H__
#include "libnm-platform/nmp-base.h"
#include "libnm-platform/nm-netlink.h"
gboolean nmp_ethtool_ioctl_supports_carrier_detect(int ifindex);
gboolean nmp_ethtool_ioctl_supports_vlans(int ifindex);
int nmp_ethtool_ioctl_get_peer_ifindex(int ifindex);
gboolean nmp_ethtool_ioctl_get_wake_on_lan(int ifindex);
gboolean nmp_ethtool_ioctl_set_wake_on_lan(int ifindex,
_NMSettingWiredWakeOnLan wol,
const char *wol_password);
gboolean nmp_ethtool_ioctl_get_link_settings(int ifindex,
gboolean *out_autoneg,
guint32 *out_speed,
NMPlatformLinkDuplexType *out_duplex);
gboolean nmp_ethtool_ioctl_set_link_settings(int ifindex,
gboolean autoneg,
guint32 speed,
NMPlatformLinkDuplexType duplex);
gboolean nmp_ethtool_ioctl_get_permanent_address(int ifindex, guint8 *buf, size_t *length);
gboolean nmp_ethtool_ioctl_get_driver_info(int ifindex, NMPUtilsEthtoolDriverInfo *data);
NMEthtoolFeatureStates *nmp_ethtool_ioctl_get_features(int ifindex);
gboolean nmp_ethtool_ioctl_set_features(
int ifindex,
const NMEthtoolFeatureStates *features,
const NMOptionBool *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */,
gboolean do_set /* or reset */);
gboolean nmp_ethtool_ioctl_get_coalesce(int ifindex, NMEthtoolCoalesceState *coalesce);
gboolean nmp_ethtool_ioctl_set_coalesce(int ifindex, const NMEthtoolCoalesceState *coalesce);
gboolean nmp_ethtool_ioctl_get_ring(int ifindex, NMEthtoolRingState *ring);
gboolean nmp_ethtool_ioctl_set_ring(int ifindex, const NMEthtoolRingState *ring);
gboolean nmp_ethtool_ioctl_get_channels(int ifindex, NMEthtoolChannelsState *channels);
gboolean nmp_ethtool_ioctl_set_channels(int ifindex, const NMEthtoolChannelsState *channels);
gboolean nmp_ethtool_ioctl_get_pause(int ifindex, NMEthtoolPauseState *pause);
gboolean nmp_ethtool_ioctl_set_pause(int ifindex, const NMEthtoolPauseState *pause);
gboolean nmp_ethtool_ioctl_get_eee(int ifindex, NMEthtoolEEEState *eee);
gboolean nmp_ethtool_ioctl_set_eee(int ifindex, const NMEthtoolEEEState *eee);
gboolean nmp_ethtool_ioctl_get_fec_mode(int ifindex, uint32_t *fec_mode);
gboolean nmp_ethtool_ioctl_set_fec_mode(int ifindex, uint32_t fec_mode);
gboolean nmp_mii_ioctl_supports_carrier_detect(int ifindex);
#endif /* __NMP_ETHTOOL_IOCTL_H__ */

View file

@ -16,6 +16,7 @@
#include "libnm-platform/nm-platform-utils.h"
#include "libnm-platform/wifi/nm-wifi-utils.h"
#include "libnm-platform/wpan/nm-wpan-utils.h"
#include "libnm-platform/nmp-ethtool-ioctl.h"
/*****************************************************************************/
@ -647,7 +648,7 @@ _link_get_driver(struct udev_device *udevice, const char *kind, int ifindex)
if (ifindex > 0) {
NMPUtilsEthtoolDriverInfo driver_info;
if (nmp_utils_ethtool_get_driver_info(ifindex, &driver_info)) {
if (nmp_ethtool_ioctl_get_driver_info(ifindex, &driver_info)) {
if (driver_info.driver[0])
return g_intern_string(driver_info.driver);
}