mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 08:20:11 +01:00
libnm-core: avoid cloning attributes of NMTCQdisc/NMTCAction to convert to string
(cherry picked from commit 48316f987a)
This commit is contained in:
parent
79ecdb589b
commit
70d8f5ddfe
5 changed files with 29 additions and 31 deletions
|
|
@ -262,7 +262,7 @@ const char **_nm_ip_address_get_attribute_names (const NMIPAddress *addr, gboole
|
|||
|
||||
gboolean _nm_ip_route_attribute_validate_all (const NMIPRoute *route);
|
||||
const char **_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length);
|
||||
GHashTable *_nm_ip_route_get_attributes_direct (NMIPRoute *route);
|
||||
GHashTable *_nm_ip_route_get_attributes (NMIPRoute *route);
|
||||
|
||||
NMSriovVF *_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, gboolean ignore_unknown, GError **error);
|
||||
gboolean _nm_sriov_vf_attribute_validate_all (const NMSriovVF *vf, GError **error);
|
||||
|
|
@ -560,6 +560,9 @@ gboolean _nm_utils_string_append_tc_tfilter_rest (GString *string,
|
|||
NMTCTfilter *tfilter,
|
||||
GError **error);
|
||||
|
||||
GHashTable *_nm_tc_qdisc_get_attributes (NMTCQdisc *qdisc);
|
||||
GHashTable *_nm_tc_action_get_attributes (NMTCAction *action);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline gboolean
|
||||
|
|
|
|||
|
|
@ -1943,10 +1943,9 @@ write_ip_values (GKeyFile *file,
|
|||
|
||||
if (is_route) {
|
||||
gs_free char *attributes = NULL;
|
||||
GHashTable *hash;
|
||||
|
||||
hash = _nm_ip_route_get_attributes_direct (array->pdata[i]);
|
||||
attributes = nm_utils_format_variant_attributes (hash, ',', '=');
|
||||
attributes = nm_utils_format_variant_attributes (_nm_ip_route_get_attributes (array->pdata[i]),
|
||||
',', '=');
|
||||
if (attributes) {
|
||||
g_strlcat (key_name, "_options", sizeof (key_name));
|
||||
nm_keyfile_plugin_kf_set_string (file, setting_name, key_name, attributes);
|
||||
|
|
|
|||
|
|
@ -1116,7 +1116,7 @@ nm_ip_route_set_metric (NMIPRoute *route,
|
|||
}
|
||||
|
||||
GHashTable *
|
||||
_nm_ip_route_get_attributes_direct (NMIPRoute *route)
|
||||
_nm_ip_route_get_attributes (NMIPRoute *route)
|
||||
{
|
||||
nm_assert (route);
|
||||
|
||||
|
|
|
|||
|
|
@ -342,6 +342,14 @@ nm_tc_qdisc_get_attribute_names (NMTCQdisc *qdisc)
|
|||
return nm_utils_strv_make_deep_copied_nonnull (names);
|
||||
}
|
||||
|
||||
GHashTable *
|
||||
_nm_tc_qdisc_get_attributes (NMTCQdisc *qdisc)
|
||||
{
|
||||
nm_assert (qdisc);
|
||||
|
||||
return qdisc->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_tc_qdisc_get_attribute:
|
||||
* @qdisc: the #NMTCQdisc
|
||||
|
|
@ -605,6 +613,14 @@ nm_tc_action_get_attribute_names (NMTCAction *action)
|
|||
return nm_utils_strv_make_deep_copied_nonnull (names);
|
||||
}
|
||||
|
||||
GHashTable *
|
||||
_nm_tc_action_get_attributes (NMTCAction *action)
|
||||
{
|
||||
nm_assert (action);
|
||||
|
||||
return action->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_tc_action_get_attribute:
|
||||
* @action: the #NMTCAction
|
||||
|
|
|
|||
|
|
@ -2332,12 +2332,9 @@ static const NMQdiscAttributeSpec *const tc_qdisc_attribute_spec[] = {
|
|||
void
|
||||
_nm_utils_string_append_tc_qdisc_rest (GString *string, NMTCQdisc *qdisc)
|
||||
{
|
||||
gs_unref_hashtable GHashTable *ht = NULL;
|
||||
guint32 handle = nm_tc_qdisc_get_handle (qdisc);
|
||||
const char *kind = nm_tc_qdisc_get_kind (qdisc);
|
||||
gs_strfreev char **attr_names = NULL;
|
||||
gs_free char *str = NULL;
|
||||
guint i;
|
||||
|
||||
if (handle != TC_H_UNSPEC && strcmp (kind, "ingress") != 0) {
|
||||
g_string_append (string, "handle ");
|
||||
|
|
@ -2347,16 +2344,9 @@ _nm_utils_string_append_tc_qdisc_rest (GString *string, NMTCQdisc *qdisc)
|
|||
|
||||
g_string_append (string, kind);
|
||||
|
||||
attr_names = nm_tc_qdisc_get_attribute_names (qdisc);
|
||||
if (attr_names[0])
|
||||
ht = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL);
|
||||
for (i = 0; attr_names[i]; i++) {
|
||||
g_hash_table_insert (ht, attr_names[i],
|
||||
nm_tc_qdisc_get_attribute (qdisc, attr_names[i]));
|
||||
}
|
||||
|
||||
if (i) {
|
||||
str = nm_utils_format_variant_attributes (ht, ' ', ' ');
|
||||
str = nm_utils_format_variant_attributes (_nm_tc_qdisc_get_attributes (qdisc),
|
||||
' ', ' ');
|
||||
if (str) {
|
||||
g_string_append_c (string, ' ');
|
||||
g_string_append (string, str);
|
||||
}
|
||||
|
|
@ -2548,24 +2538,14 @@ static const NMVariantAttributeSpec * const tc_action_attribute_spec[] = {
|
|||
static gboolean
|
||||
_string_append_tc_action (GString *string, NMTCAction *action, GError **error)
|
||||
{
|
||||
gs_unref_hashtable GHashTable *ht = NULL;
|
||||
const char *kind = nm_tc_action_get_kind (action);
|
||||
gs_strfreev char **attr_names = NULL;
|
||||
gs_free char *str = NULL;
|
||||
int i;
|
||||
|
||||
ht = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL);
|
||||
|
||||
g_string_append (string, kind);
|
||||
|
||||
attr_names = nm_tc_action_get_attribute_names (action);
|
||||
for (i = 0; attr_names[i]; i++) {
|
||||
g_hash_table_insert (ht, attr_names[i],
|
||||
nm_tc_action_get_attribute (action, attr_names[i]));
|
||||
}
|
||||
|
||||
if (i) {
|
||||
str = nm_utils_format_variant_attributes (ht, ' ', ' ');
|
||||
str = nm_utils_format_variant_attributes (_nm_tc_action_get_attributes (action),
|
||||
' ', ' ');
|
||||
if (str) {
|
||||
g_string_append_c (string, ' ');
|
||||
g_string_append (string, str);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue