From 014b50fcbe2a86384cc5d7eb0289bd68e5537756 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2017 12:52:41 +0100 Subject: [PATCH] platform: fix TC to-string/hash/cmp functions to include the action Also add a define NM_PLATFORM_ACTION_KIND_SIMPLE. It makes the uses of "simple" grepable. (cherry picked from commit fe3d7209e70944ec218d133cd66aa946e28c5a94) --- src/platform/nm-linux-platform.c | 4 +++- src/platform/nm-platform.c | 37 ++++++++++++++++++++++++++++++-- src/platform/nm-platform.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 3bd7293462..10d1a6efe1 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2962,12 +2962,14 @@ _add_action (struct nl_msg *msg, { struct nlattr *prio; + nm_assert (action || action->kind); + if (!(prio = nla_nest_start (msg, 1 /* priority */))) goto nla_put_failure; NLA_PUT_STRING (msg, TCA_ACT_KIND, action->kind); - if (strcmp (action->kind, "simple") == 0) + if (nm_streq (action->kind, NM_PLATFORM_ACTION_KIND_SIMPLE)) _add_action_simple (msg, &action->simple); nla_nest_end (msg, prio); diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 9f56bce4b1..2ca379e4ed 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -5347,17 +5347,39 @@ const char * nm_platform_tfilter_to_string (const NMPlatformTfilter *tfilter, char *buf, gsize len) { char str_dev[TO_STRING_DEV_BUF_SIZE]; + char act_buf[300]; + char *p; + gsize l; if (!nm_utils_to_string_buffer_init_null (tfilter, &buf, &len)) return buf; - g_snprintf (buf, len, "%s%s family %d handle %x parent %x info %x", + if (tfilter->action.kind) { + p = act_buf; + l = sizeof (act_buf); + + nm_utils_strbuf_append (&p, &l, " \"%s\"", tfilter->action.kind); + if (nm_streq (tfilter->action.kind, NM_PLATFORM_ACTION_KIND_SIMPLE)) { + gs_free char *t = NULL; + + nm_utils_strbuf_append (&p, &l, + " (\"%s\")", + nm_utils_str_utf8safe_escape (tfilter->action.kind, + NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL + | NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_NON_ASCII, + &t)); + } + } else + act_buf[0] = '\0'; + + g_snprintf (buf, len, "%s%s family %d handle %x parent %x info %x%s", tfilter->kind, _to_string_dev (NULL, tfilter->ifindex, str_dev, sizeof (str_dev)), tfilter->addr_family, tfilter->handle, tfilter->parent, - tfilter->info); + tfilter->info, + act_buf); return buf; } @@ -5372,6 +5394,11 @@ nm_platform_tfilter_hash_update (const NMPlatformTfilter *obj, NMHashState *h) obj->handle, obj->parent, obj->info); + nm_hash_update_str (h, obj->action.kind); + if (obj->action.kind) { + if (nm_streq (obj->action.kind, NM_PLATFORM_ACTION_KIND_SIMPLE)) + nm_hash_update_str (h, obj->action.simple.sdata); + } } int @@ -5385,6 +5412,12 @@ nm_platform_tfilter_cmp (const NMPlatformTfilter *a, const NMPlatformTfilter *b) NM_CMP_FIELD (a, b, handle); NM_CMP_FIELD (a, b, info); + NM_CMP_FIELD_STR_INTERNED (a, b, action.kind); + if (a->action.kind) { + if (nm_streq (a->action.kind, NM_PLATFORM_ACTION_KIND_SIMPLE)) + NM_CMP_FIELD_STR (a, b, action.simple.sdata); + } + return 0; } diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 4e877574c2..f6bf02bf54 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -549,6 +549,8 @@ typedef struct { }; } NMPlatformAction; +#define NM_PLATFORM_ACTION_KIND_SIMPLE "simple" + typedef struct { __NMPlatformObject_COMMON; const char *kind;