385 lines
14 KiB
Diff
385 lines
14 KiB
Diff
From 21a9b646ed49d1269c65a7ffca946c9340972bab Mon Sep 17 00:00:00 2001
|
|
From: Thomas Haller <thaller@redhat.com>
|
|
Date: Mon, 21 Oct 2013 14:36:59 +0200
|
|
Subject: [PATCH 1/3] core: omit "dev -" for *_to_string of NMPlatformIP*
|
|
addresses and routes
|
|
|
|
The NMPlatformIP[46]Address and NMPlatformIP[46]Route structs have a
|
|
field 'dev'. Before this field was always printed in the *_to_string
|
|
functions and a missing device was signaled as ' dev -'.
|
|
This had the advantage, that the output contained the same fields
|
|
regardless whether there was a device set or not.
|
|
|
|
Change it, not to print the device if it is not set. This has the
|
|
advantage, that it looks better in the logfiles.
|
|
|
|
(cherry picked from commit 69d154012d5f144c97d07f965bad35e1d9306900)
|
|
|
|
Signed-off-by: Thomas Haller <thaller@redhat.com>
|
|
---
|
|
src/platform/nm-platform.c | 36 ++++++++++++++++++++++++++++--------
|
|
1 file changed, 28 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
|
|
index 0b56464..da6c72d 100644
|
|
--- a/src/platform/nm-platform.c
|
|
+++ b/src/platform/nm-platform.c
|
|
@@ -1714,15 +1714,20 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
|
|
static char buffer[256];
|
|
char s_address[INET_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
+ char *str_dev;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
|
|
inet_ntop (AF_INET, &address->address, s_address, sizeof (s_address));
|
|
+
|
|
s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
+ str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u dev %s",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s",
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
- (guint)address->timestamp, s_dev ? s_dev : "-");
|
|
+ (guint)address->timestamp,
|
|
+ str_dev ? str_dev : "");
|
|
+ g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
@@ -1746,11 +1751,14 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
char s_address[INET6_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
char *str_flags;
|
|
+ char *str_dev;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
|
|
inet_ntop (AF_INET6, &address->address, s_address, sizeof (s_address));
|
|
+
|
|
s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
+ str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
rtnl_addr_flags2str(address->flags, s_flags, sizeof (s_flags));
|
|
|
|
@@ -1770,11 +1778,13 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
|
|
str_flags = s_flags[0] ? g_strconcat (" flags ", s_flags, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u dev %s%s",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s%s",
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
- (guint)address->timestamp, s_dev ? s_dev : "-",
|
|
+ (guint)address->timestamp,
|
|
+ str_dev ? str_dev : "",
|
|
str_flags ? str_flags : "");
|
|
g_free (str_flags);
|
|
+ g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
@@ -1796,16 +1806,21 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route)
|
|
static char buffer[256];
|
|
char s_network[INET_ADDRSTRLEN], s_gateway[INET_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
+ char *str_dev;
|
|
|
|
g_return_val_if_fail (route, "(unknown)");
|
|
|
|
inet_ntop (AF_INET, &route->network, s_network, sizeof(s_network));
|
|
inet_ntop (AF_INET, &route->gateway, s_gateway, sizeof(s_gateway));
|
|
+
|
|
s_dev = route->ifindex > 0 ? nm_platform_link_get_name (route->ifindex) : NULL;
|
|
+ str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d via %s dev %s metric %u mss %u",
|
|
- s_network, route->plen, s_gateway, s_dev ? s_dev : "-",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d via %s%s metric %u mss %u",
|
|
+ s_network, route->plen, s_gateway,
|
|
+ str_dev ? str_dev : "",
|
|
route->metric, route->mss);
|
|
+ g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
@@ -1827,16 +1842,21 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
|
|
static char buffer[256];
|
|
char s_network[INET6_ADDRSTRLEN], s_gateway[INET6_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
+ char *str_dev;
|
|
|
|
g_return_val_if_fail (route, "(unknown)");
|
|
|
|
inet_ntop (AF_INET6, &route->network, s_network, sizeof(s_network));
|
|
inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway));
|
|
+
|
|
s_dev = route->ifindex > 0 ? nm_platform_link_get_name (route->ifindex) : NULL;
|
|
+ str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d via %s dev %s metric %u mss %u",
|
|
- s_network, route->plen, s_gateway, s_dev ? s_dev : "-",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d via %s%s metric %u mss %u",
|
|
+ s_network, route->plen, s_gateway,
|
|
+ str_dev ? str_dev : "",
|
|
route->metric, route->mss);
|
|
+ g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
--
|
|
1.8.5.3
|
|
|
|
|
|
From 442d7195c74e415f15fa0264eca6e7bcf7f278e6 Mon Sep 17 00:00:00 2001
|
|
From: Thomas Haller <thaller@redhat.com>
|
|
Date: Mon, 2 Dec 2013 21:12:05 +0100
|
|
Subject: [PATCH 2/3] core: print peer_address in NMPlatform address_to_string
|
|
|
|
(cherry picked from commit 1b0f832c7f7c02d29b9421005c78d52ad6a47905)
|
|
|
|
Signed-off-by: Thomas Haller <thaller@redhat.com>
|
|
---
|
|
src/platform/nm-platform.c | 22 ++++++++++++++++++++--
|
|
1 file changed, 20 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
|
|
index da6c72d..677c23a 100644
|
|
--- a/src/platform/nm-platform.c
|
|
+++ b/src/platform/nm-platform.c
|
|
@@ -1713,21 +1713,30 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
|
|
{
|
|
static char buffer[256];
|
|
char s_address[INET_ADDRSTRLEN];
|
|
+ char s_peer[INET_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
char *str_dev;
|
|
+ char *str_peer = NULL;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
|
|
inet_ntop (AF_INET, &address->address, s_address, sizeof (s_address));
|
|
|
|
+ if (address->peer_address) {
|
|
+ inet_ntop (AF_INET, &address->peer_address, s_peer, sizeof (s_peer));
|
|
+ str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
+ }
|
|
+
|
|
s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s%s",
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
(guint)address->timestamp,
|
|
+ str_peer ? str_peer : "",
|
|
str_dev ? str_dev : "");
|
|
g_free (str_dev);
|
|
+ g_free (str_peer);
|
|
return buffer;
|
|
}
|
|
|
|
@@ -1749,14 +1758,21 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
static char buffer[256];
|
|
char s_flags[256];
|
|
char s_address[INET6_ADDRSTRLEN];
|
|
+ char s_peer[INET6_ADDRSTRLEN];
|
|
const char *s_dev;
|
|
char *str_flags;
|
|
char *str_dev;
|
|
+ char *str_peer = NULL;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
|
|
inet_ntop (AF_INET6, &address->address, s_address, sizeof (s_address));
|
|
|
|
+ if (!IN6_IS_ADDR_UNSPECIFIED (&address->peer_address)) {
|
|
+ inet_ntop (AF_INET6, &address->peer_address, s_peer, sizeof (s_peer));
|
|
+ str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
+ }
|
|
+
|
|
s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
|
|
@@ -1778,13 +1794,15 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
|
|
str_flags = s_flags[0] ? g_strconcat (" flags ", s_flags, NULL) : NULL;
|
|
|
|
- g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s%s",
|
|
+ g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s%s%s",
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
(guint)address->timestamp,
|
|
+ str_peer ? str_peer : "",
|
|
str_dev ? str_dev : "",
|
|
str_flags ? str_flags : "");
|
|
g_free (str_flags);
|
|
g_free (str_dev);
|
|
+ g_free (str_peer);
|
|
return buffer;
|
|
}
|
|
|
|
--
|
|
1.8.5.3
|
|
|
|
|
|
From aaa86cd61058c8a97c8149b2ebd6eca449aae5b7 Mon Sep 17 00:00:00 2001
|
|
From: Thomas Haller <thaller@redhat.com>
|
|
Date: Tue, 18 Feb 2014 12:52:16 +0100
|
|
Subject: [PATCH 3/3] platform: refactor address_to_string() to return device
|
|
as numeric if ifname is unknown
|
|
|
|
(cherry picked from commit a6767f215e0b7ab55949e4410d399f315a225578)
|
|
|
|
Signed-off-by: Thomas Haller <thaller@redhat.com>
|
|
---
|
|
src/platform/nm-platform.c | 57 +++++++++++++++++++++++++++-------------------
|
|
1 file changed, 33 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
|
|
index 677c23a..37d4318 100644
|
|
--- a/src/platform/nm-platform.c
|
|
+++ b/src/platform/nm-platform.c
|
|
@@ -1696,6 +1696,27 @@ nm_platform_route_flush (int ifindex)
|
|
|
|
/******************************************************************/
|
|
|
|
+#define TO_STRING_DEV_BUF_SIZE (5+15+1)
|
|
+static void
|
|
+_to_string_dev (int ifindex, char *buf, size_t size)
|
|
+{
|
|
+ g_assert (buf && size >= TO_STRING_DEV_BUF_SIZE);
|
|
+
|
|
+ if (ifindex){
|
|
+ const char *name = ifindex > 0 ? nm_platform_link_get_name (ifindex) : NULL;
|
|
+
|
|
+ strcpy (buf, " dev ");
|
|
+ buf += 5;
|
|
+ size -= 5;
|
|
+
|
|
+ if (name)
|
|
+ g_strlcpy (buf, name, size);
|
|
+ else
|
|
+ g_snprintf (buf, size, "%d", ifindex);
|
|
+ } else
|
|
+ buf[0] = 0;
|
|
+}
|
|
+
|
|
/**
|
|
* nm_platform_ip4_address_to_string:
|
|
* @route: pointer to NMPlatformIP4Address address structure
|
|
@@ -1714,8 +1735,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
|
|
static char buffer[256];
|
|
char s_address[INET_ADDRSTRLEN];
|
|
char s_peer[INET_ADDRSTRLEN];
|
|
- const char *s_dev;
|
|
- char *str_dev;
|
|
+ char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
char *str_peer = NULL;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
@@ -1727,15 +1747,13 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address)
|
|
str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
}
|
|
|
|
- s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
- str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
+ _to_string_dev (address->ifindex, str_dev, sizeof (str_dev));
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%s/%d lft %u pref %u time %u%s%s",
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
(guint)address->timestamp,
|
|
str_peer ? str_peer : "",
|
|
- str_dev ? str_dev : "");
|
|
- g_free (str_dev);
|
|
+ str_dev);
|
|
g_free (str_peer);
|
|
return buffer;
|
|
}
|
|
@@ -1759,9 +1777,8 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
char s_flags[256];
|
|
char s_address[INET6_ADDRSTRLEN];
|
|
char s_peer[INET6_ADDRSTRLEN];
|
|
- const char *s_dev;
|
|
char *str_flags;
|
|
- char *str_dev;
|
|
+ char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
char *str_peer = NULL;
|
|
|
|
g_return_val_if_fail (address, "(unknown)");
|
|
@@ -1773,8 +1790,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
}
|
|
|
|
- s_dev = address->ifindex > 0 ? nm_platform_link_get_name (address->ifindex) : NULL;
|
|
- str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
+ _to_string_dev (address->ifindex, str_dev, sizeof (str_dev));
|
|
|
|
rtnl_addr_flags2str(address->flags, s_flags, sizeof (s_flags));
|
|
|
|
@@ -1798,10 +1814,9 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address)
|
|
s_address, address->plen, (guint)address->lifetime, (guint)address->preferred,
|
|
(guint)address->timestamp,
|
|
str_peer ? str_peer : "",
|
|
- str_dev ? str_dev : "",
|
|
+ str_dev,
|
|
str_flags ? str_flags : "");
|
|
g_free (str_flags);
|
|
- g_free (str_dev);
|
|
g_free (str_peer);
|
|
return buffer;
|
|
}
|
|
@@ -1823,22 +1838,19 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route)
|
|
{
|
|
static char buffer[256];
|
|
char s_network[INET_ADDRSTRLEN], s_gateway[INET_ADDRSTRLEN];
|
|
- const char *s_dev;
|
|
- char *str_dev;
|
|
+ char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
|
|
g_return_val_if_fail (route, "(unknown)");
|
|
|
|
inet_ntop (AF_INET, &route->network, s_network, sizeof(s_network));
|
|
inet_ntop (AF_INET, &route->gateway, s_gateway, sizeof(s_gateway));
|
|
|
|
- s_dev = route->ifindex > 0 ? nm_platform_link_get_name (route->ifindex) : NULL;
|
|
- str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
+ _to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%s/%d via %s%s metric %u mss %u",
|
|
s_network, route->plen, s_gateway,
|
|
- str_dev ? str_dev : "",
|
|
+ str_dev,
|
|
route->metric, route->mss);
|
|
- g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
@@ -1859,22 +1871,19 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
|
|
{
|
|
static char buffer[256];
|
|
char s_network[INET6_ADDRSTRLEN], s_gateway[INET6_ADDRSTRLEN];
|
|
- const char *s_dev;
|
|
- char *str_dev;
|
|
+ char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
|
|
g_return_val_if_fail (route, "(unknown)");
|
|
|
|
inet_ntop (AF_INET6, &route->network, s_network, sizeof(s_network));
|
|
inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway));
|
|
|
|
- s_dev = route->ifindex > 0 ? nm_platform_link_get_name (route->ifindex) : NULL;
|
|
- str_dev = s_dev ? g_strconcat (" dev ", s_dev, NULL) : NULL;
|
|
+ _to_string_dev (route->ifindex, str_dev, sizeof (str_dev));
|
|
|
|
g_snprintf (buffer, sizeof (buffer), "%s/%d via %s%s metric %u mss %u",
|
|
s_network, route->plen, s_gateway,
|
|
- str_dev ? str_dev : "",
|
|
+ str_dev,
|
|
route->metric, route->mss);
|
|
- g_free (str_dev);
|
|
return buffer;
|
|
}
|
|
|
|
--
|
|
1.8.5.3
|
|
|