2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2015-04-14 22:34:01 +02:00
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __NM_PLATFORM_UTILS_H__
|
|
|
|
|
#define __NM_PLATFORM_UTILS_H__
|
|
|
|
|
|
|
|
|
|
#include "nm-platform.h"
|
2015-05-12 14:44:03 +02:00
|
|
|
#include "nm-setting-wired.h"
|
shared: build helper "libnm-libnm-core-{intern|aux}.la" library for libnm-core
"libnm-core" implements common functionality for "NetworkManager" and
"libnm".
Note that clients like "nmcli" cannot access the internal API provided
by "libnm-core". So, if nmcli wants to do something that is also done by
"libnm-core", , "libnm", or "NetworkManager", the code would have to be
duplicated.
Instead, such code can be in "libnm-libnm-core-{intern|aux}.la".
Note that:
0) "libnm-libnm-core-intern.la" is used by libnm-core itsself.
On the other hand, "libnm-libnm-core-aux.la" is not used by
libnm-core, but provides utilities on top of it.
1) they both extend "libnm-core" with utlities that are not public
API of libnm itself. Maybe part of the code should one day become
public API of libnm. On the other hand, this is code for which
we may not want to commit to a stable interface or which we
don't want to provide as part of the API.
2) "libnm-libnm-core-intern.la" is statically linked by "libnm-core"
and thus directly available to "libnm" and "NetworkManager".
On the other hand, "libnm-libnm-core-aux.la" may be used by "libnm"
and "NetworkManager".
Both libraries may be statically linked by libnm clients (like
nmcli).
3) it must only use glib, libnm-glib-aux.la, and the public API
of libnm-core.
This is important: it must not use "libnm-core/nm-core-internal.h"
nor "libnm-core/nm-utils-private.h" so the static library is usable
by nmcli which couldn't access these.
Note that "shared/nm-meta-setting.c" is an entirely different case,
because it behaves differently depending on whether linking against
"libnm-core" or the client programs. As such, this file must be compiled
twice.
(cherry picked from commit af07ed01c04867e281cc3982a7ab0d244d4f8e2e)
2019-04-15 09:26:53 +02:00
|
|
|
#include "nm-libnm-core-intern/nm-ethtool-utils.h"
|
2018-07-16 15:42:07 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2015-04-14 22:34:01 +02:00
|
|
|
|
2016-12-11 22:46:14 +01:00
|
|
|
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,
|
2015-05-12 14:44:03 +02:00
|
|
|
const char * wol_password);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-12-11 22:46:14 +01:00
|
|
|
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);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-12-11 22:46:14 +01:00
|
|
|
gboolean nmp_utils_ethtool_get_permanent_address(int ifindex, guint8 *buf, size_t *length);
|
2018-07-16 15:42:07 +02:00
|
|
|
|
2016-12-12 13:47:52 +01:00
|
|
|
typedef struct {
|
|
|
|
|
/* We don't want to include <linux/ethtool.h> in header files,
|
|
|
|
|
* thus create a ABI compatible version of struct ethtool_drvinfo.*/
|
|
|
|
|
guint32 _private_cmd;
|
|
|
|
|
char driver[32];
|
|
|
|
|
char version[32];
|
|
|
|
|
char fw_version[32];
|
|
|
|
|
char _private_bus_info[32];
|
|
|
|
|
char _private_erom_version[32];
|
|
|
|
|
char _private_reserved2[12];
|
|
|
|
|
guint32 _private_n_priv_flags;
|
|
|
|
|
guint32 _private_n_stats;
|
|
|
|
|
guint32 _private_testinfo_len;
|
|
|
|
|
guint32 _private_eedump_len;
|
|
|
|
|
guint32 _private_regdump_len;
|
|
|
|
|
} NMPUtilsEthtoolDriverInfo;
|
|
|
|
|
|
2016-12-11 22:46:14 +01:00
|
|
|
gboolean nmp_utils_ethtool_get_driver_info(int ifindex, NMPUtilsEthtoolDriverInfo *data);
|
2015-05-02 07:59:59 +02:00
|
|
|
|
2018-07-16 15:42:07 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMEthtoolID ethtool_id;
|
|
|
|
|
|
|
|
|
|
guint8 n_kernel_names;
|
|
|
|
|
|
|
|
|
|
/* one NMEthtoolID refers to one or more kernel_names. The reason for supporting this complexity
|
|
|
|
|
* (where one NMSettingEthtool option refers to multiple kernel features) is to follow what
|
|
|
|
|
* ethtool does, where "tx" is an alias for multiple features. */
|
|
|
|
|
const char *const *kernel_names;
|
|
|
|
|
} NMEthtoolFeatureInfo;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
const NMEthtoolFeatureInfo *info;
|
|
|
|
|
|
|
|
|
|
guint idx_ss_features;
|
|
|
|
|
|
|
|
|
|
/* one NMEthtoolFeatureInfo references one or more kernel_names. This is the index
|
|
|
|
|
* of the matching info->kernel_names */
|
|
|
|
|
guint8 idx_kernel_name;
|
|
|
|
|
|
|
|
|
|
bool available : 1;
|
|
|
|
|
bool requested : 1;
|
|
|
|
|
bool active : 1;
|
|
|
|
|
bool never_changed : 1;
|
|
|
|
|
} NMEthtoolFeatureState;
|
|
|
|
|
|
|
|
|
|
struct _NMEthtoolFeatureStates {
|
|
|
|
|
guint n_states;
|
|
|
|
|
|
|
|
|
|
guint n_ss_features;
|
|
|
|
|
|
|
|
|
|
/* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */
|
|
|
|
|
const NMEthtoolFeatureState *const *states_indexed[_NM_ETHTOOL_ID_FEATURE_NUM];
|
|
|
|
|
|
|
|
|
|
/* the same content, here as a list of n_states entries. */
|
|
|
|
|
const NMEthtoolFeatureState states_list[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NMEthtoolFeatureStates *nmp_utils_ethtool_get_features(int ifindex);
|
|
|
|
|
|
|
|
|
|
gboolean nmp_utils_ethtool_set_features(
|
|
|
|
|
int ifindex,
|
|
|
|
|
const NMEthtoolFeatureStates *features,
|
|
|
|
|
const NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */,
|
|
|
|
|
gboolean do_set /* or reset */);
|
|
|
|
|
|
2020-05-14 09:16:30 +02:00
|
|
|
struct _NMEthtoolCoalesceState {
|
2020-05-14 09:16:31 +02:00
|
|
|
guint32
|
|
|
|
|
s[_NM_ETHTOOL_ID_COALESCE_NUM /* indexed by (NMEthtoolID - _NM_ETHTOOL_ID_COALESCE_FIRST) */
|
|
|
|
|
];
|
2020-05-07 17:11:34 +02:00
|
|
|
};
|
|
|
|
|
|
2020-05-14 09:16:30 +02:00
|
|
|
gboolean nmp_utils_ethtool_get_coalesce(int ifindex, NMEthtoolCoalesceState *coalesce);
|
2020-05-07 17:11:34 +02:00
|
|
|
|
|
|
|
|
gboolean nmp_utils_ethtool_set_coalesce(int ifindex, const NMEthtoolCoalesceState *coalesce);
|
|
|
|
|
|
2020-05-14 18:27:54 +02:00
|
|
|
struct _NMEthtoolRingState {
|
|
|
|
|
guint32 rx_pending;
|
|
|
|
|
guint32 rx_mini_pending;
|
|
|
|
|
guint32 rx_jumbo_pending;
|
|
|
|
|
guint32 tx_pending;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
gboolean nmp_utils_ethtool_get_ring(int ifindex, NMEthtoolRingState *ring);
|
|
|
|
|
|
|
|
|
|
gboolean nmp_utils_ethtool_set_ring(int ifindex, const NMEthtoolRingState *ring);
|
|
|
|
|
|
2018-07-16 15:42:07 +02:00
|
|
|
/*****************************************************************************/
|
2015-05-02 07:59:59 +02:00
|
|
|
|
2016-12-11 22:46:14 +01:00
|
|
|
gboolean nmp_utils_mii_supports_carrier_detect(int ifindex);
|
2015-05-03 12:49:46 +02:00
|
|
|
|
2017-03-12 15:54:02 +01:00
|
|
|
struct udev_device;
|
|
|
|
|
|
|
|
|
|
const char *nmp_utils_udev_get_driver(struct udev_device *udevice);
|
2015-05-02 07:59:59 +02:00
|
|
|
|
2016-05-16 13:16:49 +02:00
|
|
|
NMIPConfigSource nmp_utils_ip_config_source_from_rtprot(guint8 rtprot) _nm_const;
|
|
|
|
|
guint8 nmp_utils_ip_config_source_coerce_to_rtprot(NMIPConfigSource source) _nm_const;
|
|
|
|
|
NMIPConfigSource nmp_utils_ip_config_source_coerce_from_rtprot(NMIPConfigSource source) _nm_const;
|
|
|
|
|
NMIPConfigSource nmp_utils_ip_config_source_round_trip_rtprot(NMIPConfigSource source) _nm_const;
|
platform: extend NMIPConfigSource to preserve the rtm_protocol field
For addresses (NMPlatformIPAddress) the @addr_source field is ignored
on a platform level. That is, all addresses inside the platform cache
have this value set to NM_IP_CONFIG_SOURCE_KERNEL. Maybe, for that reason,
the source should not be a part of the NMPlatformIPAddress structure, but
it is convenient for users to piggy back the source inside the platform
address structure.
For routes, the source is stored in NMPlatformIPRoute's @rt_source
field. When adding a route to kernel, we set the @rtm_protocol of the
route depending on the source. However, we want to map different source
values to the same protocol value.
On the other hand, when kernel sends us a route that gets put inside
the cache, we must preserve the protocol value and must not map
different protocol values to the same source.
The reason is, that a user can add two routes that only differ by
@rtm_protocol. In that sense, the @rtm_protocol fields is part of the
unique ID of a kernel route, and thus different values must map to
different sources.
Fix this, by extending the range of NMIPConfigSource to contain
a range of protocol fields.
2016-04-11 17:35:29 +02:00
|
|
|
const char *nmp_utils_ip_config_source_to_string(NMIPConfigSource source, char *buf, gsize len);
|
2016-04-10 12:01:51 +02:00
|
|
|
|
2016-12-26 11:54:30 +01:00
|
|
|
const char *nmp_utils_if_indextoname(int ifindex, char *out_ifname /*IFNAMSIZ*/);
|
|
|
|
|
int nmp_utils_if_nametoindex(const char *ifname);
|
|
|
|
|
|
2016-12-08 13:55:17 +01:00
|
|
|
int nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_ifname);
|
2016-12-07 18:15:13 +08:00
|
|
|
|
2015-04-14 22:34:01 +02:00
|
|
|
#endif /* __NM_PLATFORM_UTILS_H__ */
|