Blame libnm-core/nm-team-utils.h

Packit Service 87a54e
/* SPDX-License-Identifier: LGPL-2.1-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2019 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#ifndef __NM_TEAM_UITLS_H__
Packit 5756e2
#define __NM_TEAM_UITLS_H__
Packit 5756e2
Packit Service a1bd4f
#if !((NETWORKMANAGER_COMPILATION) &NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_PRIVATE)
Packit Service a1bd4f
    #error Cannot use this header.
Packit 5756e2
#endif
Packit 5756e2
Packit 5756e2
#include "nm-glib-aux/nm-value-type.h"
Packit 5756e2
#include "nm-core-internal.h"
Packit 5756e2
Packit 5756e2
struct _NMSetting;
Packit 5756e2
Packit 5756e2
struct NMTeamLinkWatcher;
Packit 5756e2
Packit 5756e2
typedef enum {
Packit 5756e2
Packit Service a1bd4f
    _NM_TEAM_ATTRIBUTE_0            = 0,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_CONFIG        = 1,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_LINK_WATCHERS = 2,
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_TEAM_ATTRIBUTE_START = 3,
Packit Service a1bd4f
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_COUNT = _NM_TEAM_ATTRIBUTE_START,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_NOTIFY_PEERS_INTERVAL,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_COUNT,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_MCAST_REJOIN_INTERVAL,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_HWADDR_POLICY,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_HASH,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_TX_BALANCER_INTERVAL,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_ACTIVE,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_FAST_RATE,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_SYS_PRIO,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_MIN_PORTS,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_MASTER_RUNNER_AGG_SELECT_POLICY,
Packit Service a1bd4f
    _NM_TEAM_ATTRIBUTE_MASTER_NUM,
Packit Service a1bd4f
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_PORT_QUEUE_ID = _NM_TEAM_ATTRIBUTE_START,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_PORT_PRIO,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_PORT_STICKY,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_PORT_LACP_PRIO,
Packit Service a1bd4f
    NM_TEAM_ATTRIBUTE_PORT_LACP_KEY,
Packit Service a1bd4f
    _NM_TEAM_ATTRIBUTE_PORT_NUM,
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_TEAM_ATTRIBUTE_NUM = MAX(_NM_TEAM_ATTRIBUTE_MASTER_NUM, _NM_TEAM_ATTRIBUTE_PORT_NUM),
Packit 5756e2
Packit 5756e2
} NMTeamAttribute;
Packit 5756e2
Packit 5756e2
static inline guint32
Packit Service a1bd4f
nm_team_attribute_to_flags(NMTeamAttribute team_attr)
Packit 5756e2
{
Packit Service a1bd4f
    nm_assert(_NM_INT_NOT_NEGATIVE(team_attr));
Packit Service a1bd4f
    nm_assert(team_attr < _NM_TEAM_ATTRIBUTE_NUM);
Packit Service a1bd4f
    G_STATIC_ASSERT_EXPR(_NM_TEAM_ATTRIBUTE_NUM < 32);
Packit 5756e2
Packit Service a1bd4f
    return ((guint32) 1) << team_attr;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
struct _NMTeamSettingData {
Packit Service a1bd4f
    const char *_js_str;
Packit Service a1bd4f
Packit Service a1bd4f
    const GPtrArray *link_watchers;
Packit Service a1bd4f
Packit Service a1bd4f
    /* this means that @_js_str is unset and needs to be created by
Packit Service a1bd4f
     * converting the properties to JSON. This flag indicates that
Packit Service a1bd4f
     * we need to re-generate the JSON string on-demand (lazily). */
Packit Service a1bd4f
    bool _js_str_need_synthetize;
Packit Service a1bd4f
Packit Service a1bd4f
    bool strict_validated : 1;
Packit Service a1bd4f
Packit Service a1bd4f
    /* indicates tha the JSON is invalid. Usually, we do a very relaxed validation of
Packit Service a1bd4f
     * the JSON config, in case !@strict_validated and accept all unknown fields. This
Packit Service a1bd4f
     * flag indicates that the JSON value is not even parsable as JSON. nm_connection_verify()
Packit Service a1bd4f
     * would reject such a setting. */
Packit Service a1bd4f
    bool js_str_invalid : 1;
Packit Service a1bd4f
Packit Service a1bd4f
    bool is_port : 1;
Packit Service a1bd4f
Packit Service a1bd4f
    guint32 has_fields_mask;
Packit Service a1bd4f
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        struct {
Packit Service a1bd4f
            const GPtrArray *runner_tx_hash;
Packit Service a1bd4f
            const char *     runner;
Packit Service a1bd4f
            const char *     runner_hwaddr_policy;
Packit Service a1bd4f
            const char *     runner_tx_balancer;
Packit Service a1bd4f
            const char *     runner_agg_select_policy;
Packit Service a1bd4f
            gint32           notify_peers_count;
Packit Service a1bd4f
            gint32           notify_peers_interval;
Packit Service a1bd4f
            gint32           mcast_rejoin_count;
Packit Service a1bd4f
            gint32           mcast_rejoin_interval;
Packit Service a1bd4f
            gint32           runner_sys_prio;
Packit Service a1bd4f
            gint32           runner_min_ports;
Packit Service a1bd4f
            gint32           runner_tx_balancer_interval;
Packit Service a1bd4f
            bool             runner_active;
Packit Service a1bd4f
            bool             runner_fast_rate;
Packit Service a1bd4f
        } master;
Packit Service a1bd4f
        struct {
Packit Service a1bd4f
            gint32 queue_id;
Packit Service a1bd4f
            gint32 prio;
Packit Service a1bd4f
            gint32 lacp_prio;
Packit Service a1bd4f
            gint32 lacp_key;
Packit Service a1bd4f
            bool   sticky;
Packit Service a1bd4f
        } port;
Packit Service a1bd4f
    };
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    union {
Packit Service a1bd4f
        const struct _NMTeamSettingData d;
Packit 5756e2
Packit Service a1bd4f
        struct _NMTeamSettingData _data_priv;
Packit Service a1bd4f
    };
Packit 5756e2
} NMTeamSetting;
Packit 5756e2
Packit Service a1bd4f
NMTeamSetting *nm_team_setting_new(gboolean is_port, const char *js_str);
Packit 5756e2
Packit Service a1bd4f
void nm_team_setting_free(NMTeamSetting *self);
Packit 5756e2
Packit Service a1bd4f
NM_AUTO_DEFINE_FCN0(NMTeamSetting *, _nm_auto_free_team_setting, nm_team_setting_free);
Packit Service a1bd4f
#define nm_auto_free_team_setting nm_auto(_nm_auto_free_team_setting)
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
const char *nm_team_setting_config_get(const NMTeamSetting *self);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_config_set(NMTeamSetting *self, const char *js_str);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
gconstpointer _nm_team_setting_value_get(const NMTeamSetting *self,
Packit Service a1bd4f
                                         NMTeamAttribute      team_attr,
Packit Service a1bd4f
                                         NMValueType          value_type);
Packit 5756e2
Packit 5756e2
static inline gboolean
Packit Service a1bd4f
nm_team_setting_value_get_bool(const NMTeamSetting *self, NMTeamAttribute team_attr)
Packit 5756e2
{
Packit Service a1bd4f
    const bool *p;
Packit 5756e2
Packit Service a1bd4f
    p = _nm_team_setting_value_get(self, team_attr, NM_VALUE_TYPE_BOOL);
Packit Service a1bd4f
    return p ? *p : 0;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static inline gint32
Packit Service a1bd4f
nm_team_setting_value_get_int32(const NMTeamSetting *self, NMTeamAttribute team_attr)
Packit 5756e2
{
Packit Service a1bd4f
    const gint32 *p;
Packit 5756e2
Packit Service a1bd4f
    p = _nm_team_setting_value_get(self, team_attr, NM_VALUE_TYPE_INT32);
Packit Service a1bd4f
    return p ? *p : 0;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static inline const char *
Packit Service a1bd4f
nm_team_setting_value_get_string(const NMTeamSetting *self, NMTeamAttribute team_attr)
Packit 5756e2
{
Packit Service a1bd4f
    const char *const *p;
Packit 5756e2
Packit Service a1bd4f
    p = _nm_team_setting_value_get(self, team_attr, NM_VALUE_TYPE_STRING);
Packit Service a1bd4f
    return p ? *p : NULL;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_reset(NMTeamSetting * self,
Packit 5756e2
                                    NMTeamAttribute team_attr,
Packit Service a1bd4f
                                    gboolean        to_default /* or else unset */);
Packit Service a1bd4f
Packit Service a1bd4f
guint32 _nm_team_setting_value_set(NMTeamSetting * self,
Packit Service a1bd4f
                                   NMTeamAttribute team_attr,
Packit Service a1bd4f
                                   NMValueType     value_type,
Packit Service a1bd4f
                                   gconstpointer   val);
Packit 5756e2
Packit 5756e2
static inline guint32
Packit Service a1bd4f
nm_team_setting_value_set_bool(NMTeamSetting *self, NMTeamAttribute team_attr, gboolean val)
Packit 5756e2
{
Packit Service a1bd4f
    const bool bool_val = val;
Packit 5756e2
Packit Service a1bd4f
    return _nm_team_setting_value_set(self, team_attr, NM_VALUE_TYPE_BOOL, &bool_val);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static inline guint32
Packit Service a1bd4f
nm_team_setting_value_set_int32(NMTeamSetting *self, NMTeamAttribute team_attr, gint32 val)
Packit 5756e2
{
Packit Service a1bd4f
    return _nm_team_setting_value_set(self, team_attr, NM_VALUE_TYPE_INT32, &val;;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static inline guint32
Packit Service a1bd4f
nm_team_setting_value_set_string(NMTeamSetting *self, NMTeamAttribute team_attr, const char *arg)
Packit 5756e2
{
Packit Service a1bd4f
    return _nm_team_setting_value_set(self, team_attr, NM_VALUE_TYPE_STRING, &arg;;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_link_watchers_add(NMTeamSetting *                 self,
Packit Service a1bd4f
                                                const struct NMTeamLinkWatcher *link_watcher);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_link_watchers_remove(NMTeamSetting *self, guint idx);
Packit 5756e2
Packit Service a1bd4f
guint32
Packit Service a1bd4f
nm_team_setting_value_link_watchers_remove_by_value(NMTeamSetting *                 self,
Packit Service a1bd4f
                                                    const struct NMTeamLinkWatcher *link_watcher);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_link_watchers_set_list(NMTeamSetting *                        self,
Packit Service a1bd4f
                                                     const struct NMTeamLinkWatcher *const *arr,
Packit Service a1bd4f
                                                     guint                                  len);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_master_runner_tx_hash_add(NMTeamSetting *self, const char *txhash);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_master_runner_tx_hash_remove(NMTeamSetting *self, guint idx);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_value_master_runner_tx_hash_set_list(NMTeamSetting *    self,
Packit Service a1bd4f
                                                             const char *const *arr,
Packit Service a1bd4f
                                                             guint              len);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
gboolean nm_team_setting_verify(const NMTeamSetting *self, GError **error);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
int nm_team_setting_cmp(const NMTeamSetting *self_a,
Packit Service a1bd4f
                        const NMTeamSetting *self_b,
Packit Service a1bd4f
                        gboolean             ignore_js_str);
Packit 5756e2
Packit Service a1bd4f
guint32 nm_team_setting_reset(NMTeamSetting *self, const NMTeamSetting *src);
Packit 5756e2
Packit Service a1bd4f
gboolean nm_team_setting_reset_from_dbus(NMTeamSetting *                 self,
Packit Service a1bd4f
                                         GVariant *                      setting_dict,
Packit Service a1bd4f
                                         GHashTable *                    keys,
Packit Service a1bd4f
                                         guint32 *                       out_changed,
Packit Service a1bd4f
                                         guint /* NMSettingParseFlags */ parse_flags,
Packit Service a1bd4f
                                         GError **                       error);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
GPtrArray *
Packit Service a1bd4f
_nm_utils_team_link_watchers_from_variant(GVariant *value, gboolean strict_parsing, GError **error);
Packit Service a1bd4f
GVariant *_nm_utils_team_link_watchers_to_variant(const GPtrArray *link_watchers);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
gboolean nm_team_setting_maybe_changed(struct _NMSetting *      source,
Packit Service a1bd4f
                                       const GParamSpec *const *obj_properties,
Packit Service a1bd4f
                                       guint32                  changed);
Packit 5756e2
Packit 5756e2
struct _NMSettingTeam;
Packit 5756e2
struct _NMSettingTeamPort;
Packit Service a1bd4f
NMTeamSetting *_nm_setting_team_get_team_setting(struct _NMSettingTeam *setting);
Packit Service a1bd4f
NMTeamSetting *_nm_setting_team_port_get_team_setting(struct _NMSettingTeamPort *setting);
Packit Service a1bd4f
NMTeamSetting *_nm_setting_get_team_setting(struct _NMSetting *setting);
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
extern const NMSettInfoPropertType nm_sett_info_propert_type_team_b;
Packit 5756e2
extern const NMSettInfoPropertType nm_sett_info_propert_type_team_i;
Packit 5756e2
extern const NMSettInfoPropertType nm_sett_info_propert_type_team_s;
Packit 5756e2
extern const NMSettInfoPropertType nm_sett_info_propert_type_team_as;
Packit 5756e2
extern const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers;
Packit 5756e2
Packit 5756e2
#endif /* __NM_TEAM_UITLS_H__ */