Commit a2d59f5f authored by Thomas Haller's avatar Thomas Haller

platform: add buffer argument to platform to-string functions

Arguably, it is more convenient to use the static buffer as
it saves typing.

But having such a low-level function use a static buffer also
limits the way how to use it. As it was, you could not avoid
using the static buffer.

E.g. you cannot do:

  char buf[100];

  _LOGD ("nmp-object: %s; platform-link: %s",
         nmp_object_to_string (nmpobj, buf, sizeof(buf)),
         nm_platform_link_to_string (link));

This will fail for non-obvious reasons because both
to-string functions end up using the same static buffer.

Also change the to-string implementations to accept NULL
as valid and return it as "(null)".

https://bugzilla.gnome.org/show_bug.cgi?id=756427
parent 7e2710fc
......@@ -983,9 +983,11 @@ nmtst_platform_ip4_routes_equal (const NMPlatformIP4Route *a, const NMPlatformIP
for (i = 0; i < len; i++) {
if (nm_platform_ip4_route_cmp (&a[i], &b[i]) != 0) {
char buf[sizeof (_nm_platform_to_string_buffer)];
g_error ("Error comparing IPv4 route[%lu]: %s vs %s", (long unsigned) i,
nmtst_static_1024_01 (nm_platform_ip4_route_to_string (&a[i])),
nmtst_static_1024_02 (nm_platform_ip4_route_to_string (&b[i])));
nm_platform_ip4_route_to_string (&a[i], NULL, 0),
nm_platform_ip4_route_to_string (&b[i], buf, sizeof (buf)));
g_assert_not_reached ();
}
}
......@@ -1015,9 +1017,11 @@ nmtst_platform_ip6_routes_equal (const NMPlatformIP6Route *a, const NMPlatformIP
for (i = 0; i < len; i++) {
if (nm_platform_ip6_route_cmp (&a[i], &b[i]) != 0) {
char buf[sizeof (_nm_platform_to_string_buffer)];
g_error ("Error comparing IPv6 route[%lu]: %s vs %s", (long unsigned) i,
nmtst_static_1024_01 (nm_platform_ip6_route_to_string (&a[i])),
nmtst_static_1024_02 (nm_platform_ip6_route_to_string (&b[i])));
nm_platform_ip6_route_to_string (&a[i], NULL, 0),
nm_platform_ip6_route_to_string (&b[i], buf, sizeof (buf)));
g_assert_not_reached ();
}
}
......
......@@ -320,7 +320,7 @@ process_classful_routes (GHashTable *options, guint32 priority, NMIP4Config *ip4
nm_ip4_config_add_route (ip4_config, &route);
nm_log_info (LOGD_DHCP, " static route %s",
nm_platform_ip4_route_to_string (&route));
nm_platform_ip4_route_to_string (&route, NULL, 0));
}
out:
......@@ -469,7 +469,7 @@ nm_dhcp_utils_ip4_config_from_options (int ifindex,
route.metric = priority;
nm_ip4_config_add_route (ip4_config, &route);
nm_log_dbg (LOGD_IP, "adding route for server identifier: %s",
nm_platform_ip4_route_to_string (&route));
nm_platform_ip4_route_to_string (&route, NULL, 0));
}
}
else
......
......@@ -281,7 +281,7 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g
}
if (!success) {
_LOGW (vtable->vt->addr_family, "failed to add default route %s with effective metric %u",
vtable->vt->route_to_string (&entry->route), (guint) entry->effective_metric);
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) entry->effective_metric);
}
return TRUE;
}
......@@ -553,23 +553,23 @@ _resync_all (const VTableIP *vtable, NMDefaultRouteManager *self, const Entry *c
g_array_append_val (changed_metrics, expected_metric);
if (old_entry) {
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": sync:update %s (%u -> %u)", LOG_ENTRY_ARGS (i, entry),
vtable->vt->route_to_string (&entry->route), (guint) old_entry->effective_metric,
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) old_entry->effective_metric,
(guint) expected_metric);
} else {
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": sync:add %s (%u)", LOG_ENTRY_ARGS (i, entry),
vtable->vt->route_to_string (&entry->route), (guint) expected_metric);
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) expected_metric);
}
} else if (entry->effective_metric != expected_metric) {
g_array_append_val (changed_metrics, entry->effective_metric);
g_array_append_val (changed_metrics, expected_metric);
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": sync:metric %s (%u -> %u)", LOG_ENTRY_ARGS (i, entry),
vtable->vt->route_to_string (&entry->route), (guint) entry->effective_metric,
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) entry->effective_metric,
(guint) expected_metric);
} else {
if (!_vt_routes_has_entry (vtable, routes, entry)) {
g_array_append_val (changed_metrics, entry->effective_metric);
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": sync:re-add %s (%u -> %u)", LOG_ENTRY_ARGS (i, entry),
vtable->vt->route_to_string (&entry->route), (guint) entry->effective_metric,
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) entry->effective_metric,
(guint) entry->effective_metric);
}
}
......@@ -636,7 +636,7 @@ _entry_at_idx_update (const VTableIP *vtable, NMDefaultRouteManager *self, guint
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": %s %s (%"G_GUINT32_FORMAT")",
LOG_ENTRY_ARGS (entry_idx, entry),
old_entry ? "record:update" : "record:add ",
vtable->vt->route_to_string (&entry->route),
vtable->vt->route_to_string (&entry->route, NULL, 0),
entry->effective_metric);
g_ptr_array_sort_with_data (entries, _sort_entries_cmp, NULL);
......@@ -658,7 +658,7 @@ _entry_at_idx_remove (const VTableIP *vtable, NMDefaultRouteManager *self, guint
entry = g_ptr_array_index (entries, entry_idx);
_LOGD (vtable->vt->addr_family, LOG_ENTRY_FMT": record:remove %s (%u)", LOG_ENTRY_ARGS (entry_idx, entry),
vtable->vt->route_to_string (&entry->route), (guint) entry->effective_metric);
vtable->vt->route_to_string (&entry->route, NULL, 0), (guint) entry->effective_metric);
/* Remove the entry from the list (but don't free it yet) */
g_ptr_array_index (entries, entry_idx) = NULL;
......
......@@ -1199,7 +1199,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
/* addresses */
for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++)
g_message (" a: %s", nm_platform_ip4_address_to_string (nm_ip4_config_get_address (config, i)));
g_message (" a: %s", nm_platform_ip4_address_to_string (nm_ip4_config_get_address (config, i), NULL, 0));
/* default gateway */
if (nm_ip4_config_has_gateway (config)) {
......@@ -1215,7 +1215,7 @@ nm_ip4_config_dump (const NMIP4Config *config, const char *detail)
/* routes */
for (i = 0; i < nm_ip4_config_get_num_routes (config); i++)
g_message (" rt: %s", nm_platform_ip4_route_to_string (nm_ip4_config_get_route (config, i)));
g_message (" rt: %s", nm_platform_ip4_route_to_string (nm_ip4_config_get_route (config, i), NULL, 0));
/* domains */
for (i = 0; i < nm_ip4_config_get_num_domains (config); i++)
......
......@@ -1166,7 +1166,7 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
/* addresses */
for (i = 0; i < nm_ip6_config_get_num_addresses (config); i++)
g_message (" a: %s", nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i)));
g_message (" a: %s", nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i), NULL, 0));
/* default gateway */
tmp = nm_ip6_config_get_gateway (config);
......@@ -1181,7 +1181,7 @@ nm_ip6_config_dump (const NMIP6Config *config, const char *detail)
/* routes */
for (i = 0; i < nm_ip6_config_get_num_routes (config); i++)
g_message (" rt: %s", nm_platform_ip6_route_to_string (nm_ip6_config_get_route (config, i)));
g_message (" rt: %s", nm_platform_ip6_route_to_string (nm_ip6_config_get_route (config, i), NULL, 0));
/* domains */
for (i = 0; i < nm_ip6_config_get_num_domains (config); i++)
......
......@@ -467,12 +467,12 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
if (_LOGT_ENABLED (vtable->vt->addr_family)) {
for (i = 0; i < known_routes_idx->len; i++) {
_LOGT (vtable->vt->addr_family, "%3d: sync new route #%u: %s",
ifindex, i, vtable->vt->route_to_string (VTABLE_ROUTE_INDEX (vtable, known_routes, i)));
ifindex, i, vtable->vt->route_to_string (VTABLE_ROUTE_INDEX (vtable, known_routes, i), NULL, 0));
}
for (i = 0; i < ipx_routes->index->len; i++)
_LOGT (vtable->vt->addr_family, "%3d: STATE: has #%u - %s (%lld)",
ifindex, i,
vtable->vt->route_to_string (ipx_routes->index->entries[i]),
vtable->vt->route_to_string (ipx_routes->index->entries[i], NULL, 0),
(long long) g_array_index (ipx_routes->effective_metrics, gint64, i));
}
......@@ -512,7 +512,8 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
cur_ipx_route->rx.ifindex = ifindex;
cur_ipx_route->rx.metric = vtable->vt->metric_normalize (cur_ipx_route->rx.metric);
ipx_routes_changed = TRUE;
_LOGT (vtable->vt->addr_family, "%3d: STATE: update #%u - %s", ifindex, i_ipx_routes, vtable->vt->route_to_string (cur_ipx_route));
_LOGT (vtable->vt->addr_family, "%3d: STATE: update #%u - %s", ifindex, i_ipx_routes,
vtable->vt->route_to_string (cur_ipx_route, NULL, 0));
}
} else if (cur_known_route) {
g_assert (!cur_ipx_route || route_id_cmp_result > 0);
......@@ -570,7 +571,8 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
&& cur_plat_route->rx.metric == *p_effective_metric) {
/* we are about to delete cur_ipx_route and we have a matching route
* in platform. Delete it. */
_LOGT (vtable->vt->addr_family, "%3d: platform rt-rm #%u - %s", ifindex, i_plat_routes, vtable->vt->route_to_string (cur_plat_route));
_LOGT (vtable->vt->addr_family, "%3d: platform rt-rm #%u - %s", ifindex, i_plat_routes,
vtable->vt->route_to_string (cur_plat_route, NULL, 0));
vtable->vt->route_delete (priv->platform, ifindex, cur_plat_route);
}
}
......@@ -582,7 +584,8 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
for (i = 0; i < to_delete_indexes->len; i++) {
guint idx = g_array_index (to_delete_indexes, guint, i);
_LOGT (vtable->vt->addr_family, "%3d: STATE: delete #%u - %s", ifindex, idx, vtable->vt->route_to_string (ipx_routes->index->entries[idx]));
_LOGT (vtable->vt->addr_family, "%3d: STATE: delete #%u - %s", ifindex, idx,
vtable->vt->route_to_string (ipx_routes->index->entries[idx], NULL, 0));
g_array_index (to_delete_indexes, guint, i) = _route_index_reverse_idx (vtable, ipx_routes->index, idx, ipx_routes->entries);
}
g_array_sort (to_delete_indexes, (GCompareFunc) _sort_indexes_cmp);
......@@ -606,7 +609,8 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
g_array_index (ipx_routes->effective_metrics_reverse, gint64, j++) = -1;
_LOGT (vtable->vt->addr_family, "%3d: STATE: added #%u - %s", ifindex, ipx_routes->entries->len - 1, vtable->vt->route_to_string (ipx_route));
_LOGT (vtable->vt->addr_family, "%3d: STATE: added #%u - %s", ifindex, ipx_routes->entries->len - 1,
vtable->vt->route_to_string (ipx_route, NULL, 0));
}
g_ptr_array_unref (to_add_routes);
}
......@@ -693,7 +697,7 @@ _vx_route_sync (const VTableIP *vtable, NMRouteManager *self, int ifindex, const
next:
_LOGT (vtable->vt->addr_family, "%3d: new metric #%u - %s (%lld)",
ifindex, i_ipx_routes,
vtable->vt->route_to_string (cur_ipx_route),
vtable->vt->route_to_string (cur_ipx_route, NULL, 0),
(long long) *p_effective_metric);
}
}
......@@ -716,7 +720,7 @@ next:
g_assert (cur_plat_route->rx.ifindex == ifindex);
_LOGT (vtable->vt->addr_family, "%3d: platform rt #%u - %s", ifindex, i_plat_routes, vtable->vt->route_to_string (cur_plat_route));
_LOGT (vtable->vt->addr_family, "%3d: platform rt #%u - %s", ifindex, i_plat_routes, vtable->vt->route_to_string (cur_plat_route, NULL, 0));
/* skip over @cur_ipx_route that are ordered before @cur_plat_route */
while ( cur_ipx_route
......@@ -870,7 +874,7 @@ next:
_LOGD (vtable->vt->addr_family,
"ignore error adding IPv%c route to kernel: %s",
vtable->vt->is_ip4 ? '4' : '6',
vtable->vt->route_to_string (cur_ipx_route));
vtable->vt->route_to_string (cur_ipx_route, NULL, 0));
} else {
/* Remember that there was a failure, but for now continue trying
* to sync the remaining routes. */
......
This diff is collapsed.
......@@ -313,7 +313,7 @@ typedef struct {
int addr_family;
gsize sizeof_route;
int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b);
const char *(*route_to_string) (const NMPlatformIPXRoute *route);
const char *(*route_to_string) (const NMPlatformIPXRoute *route, char *buf, gsize len);
GArray *(*route_get_all) (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags);
gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric);
gboolean (*route_delete) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route);
......@@ -324,8 +324,6 @@ typedef struct {
extern const NMPlatformVTableRoute nm_platform_vtable_route_v4;
extern const NMPlatformVTableRoute nm_platform_vtable_route_v6;
extern char _nm_platform_to_string_buffer[256];
typedef struct {
int peer;
} NMPlatformVethProperties;
......@@ -745,11 +743,13 @@ gboolean nm_platform_ip6_route_add (NMPlatform *self, int ifindex, NMIPConfigSou
gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, int plen, guint32 metric);
gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, int plen, guint32 metric);
const char *nm_platform_link_to_string (const NMPlatformLink *link);
const char *nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address);
const char *nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address);
const char *nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route);
const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route);
extern char _nm_platform_to_string_buffer[1024];
const char *nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len);
const char *nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *buf, gsize len);
const char *nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *buf, gsize len);
const char *nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsize len);
const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsize len);
int nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b);
int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b);
......
......@@ -372,7 +372,6 @@ nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode
const NMPClass *klass;
char buf2[sizeof (_nm_platform_to_string_buffer)];
char buf3[sizeof (_nm_platform_to_string_buffer)];
const char *str;
if (!buf) {
buf = _nm_platform_to_string_buffer;
......@@ -380,7 +379,7 @@ nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode
}
if (!obj) {
g_strlcpy (buf, "NULL", buf_size);
g_strlcpy (buf, "(null)", buf_size);
return buf;
}
......@@ -392,7 +391,7 @@ nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode
case NMP_OBJECT_TO_STRING_ID:
return klass->cmd_plobj_to_string_id (&obj->object, buf, buf_size);
case NMP_OBJECT_TO_STRING_ALL:
g_strlcpy (buf2, NMP_OBJECT_GET_CLASS (obj)->cmd_plobj_to_string (&obj->object), sizeof (buf2));
NMP_OBJECT_GET_CLASS (obj)->cmd_plobj_to_string (&obj->object, buf2, sizeof (buf2));
if (NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_LINK) {
g_snprintf (buf3, sizeof (buf3),
......@@ -411,9 +410,7 @@ nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode
buf3, buf2);
return buf;
case NMP_OBJECT_TO_STRING_PUBLIC:
str = NMP_OBJECT_GET_CLASS (obj)->cmd_plobj_to_string (&obj->object);
if (str != buf)
g_strlcpy (buf, str, buf_size);
NMP_OBJECT_GET_CLASS (obj)->cmd_plobj_to_string (&obj->object, buf, buf_size);
return buf;
default:
g_return_val_if_reached ("ERROR");
......@@ -1800,7 +1797,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.cmd_plobj_id_equal = _vt_cmd_plobj_id_equal_link,
.cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_link,
.cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_link,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj)) nm_platform_link_to_string,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_link_to_string,
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_link_cmp,
},
[NMP_OBJECT_TYPE_IP4_ADDRESS - 1] = {
......@@ -1824,7 +1821,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.cmd_plobj_id_equal = _vt_cmd_plobj_id_equal_ip4_address,
.cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip4_address,
.cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip4_address,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj)) nm_platform_ip4_address_to_string,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip4_address_to_string,
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip4_address_cmp,
},
[NMP_OBJECT_TYPE_IP6_ADDRESS - 1] = {
......@@ -1848,7 +1845,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.cmd_plobj_id_equal = _vt_cmd_plobj_id_equal_ip6_address,
.cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip6_address,
.cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip6_address,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj)) nm_platform_ip6_address_to_string,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_address_to_string,
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip6_address_cmp
},
[NMP_OBJECT_TYPE_IP4_ROUTE - 1] = {
......@@ -1872,7 +1869,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.cmd_plobj_id_equal = _vt_cmd_plobj_id_equal_ip4_route,
.cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip4_route,
.cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip4_route,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj)) nm_platform_ip4_route_to_string,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip4_route_to_string,
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip4_route_cmp,
},
[NMP_OBJECT_TYPE_IP6_ROUTE - 1] = {
......@@ -1896,7 +1893,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = {
.cmd_plobj_id_equal = _vt_cmd_plobj_id_equal_ip6_route,
.cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip6_route,
.cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip6_route,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj)) nm_platform_ip6_route_to_string,
.cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_route_to_string,
.cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip6_route_cmp,
},
};
......
......@@ -138,7 +138,7 @@ typedef struct {
gboolean (*cmd_plobj_id_equal) (const NMPlatformObject *obj1, const NMPlatformObject *obj2);
guint (*cmd_plobj_id_hash) (const NMPlatformObject *obj);
const char *(*cmd_plobj_to_string_id) (const NMPlatformObject *obj, char *buf, gsize buf_size);
const char *(*cmd_plobj_to_string) (const NMPlatformObject *obj);
const char *(*cmd_plobj_to_string) (const NMPlatformObject *obj, char *buf, gsize len);
int (*cmd_plobj_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2);
} NMPClass;
......
......@@ -75,12 +75,12 @@ dump_interface (NMPlatformLink *link)
for (i = 0; i < ip4_addresses->len; i++) {
ip4_address = &g_array_index (ip4_addresses, NMPlatformIP4Address, i);
printf (" ip4-address %s\n", nm_platform_ip4_address_to_string (ip4_address));
printf (" ip4-address %s\n", nm_platform_ip4_address_to_string (ip4_address, NULL, 0));
}
for (i = 0; i < ip6_addresses->len; i++) {
ip6_address = &g_array_index (ip6_addresses, NMPlatformIP6Address, i);
printf (" ip6-address %s\n", nm_platform_ip6_address_to_string (ip6_address));
printf (" ip6-address %s\n", nm_platform_ip6_address_to_string (ip6_address, NULL, 0));
}
g_array_unref (ip4_addresses);
......
......@@ -58,28 +58,28 @@ test_nm_platform_ip6_address_to_string_flags (void)
{
NMPlatformIP6Address addr = { 0 };
g_assert_cmpstr (strstr (nm_platform_ip6_address_to_string (&addr), " flags "), ==, NULL);
g_assert_cmpstr (strstr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags "), ==, NULL);
addr.flags = IFA_F_MANAGETEMPADDR;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags mngtmpaddr ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags mngtmpaddr ");
addr.flags = IFA_F_NOPREFIXROUTE;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags noprefixroute ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags noprefixroute ");
addr.flags = IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags mngtmpaddr,noprefixroute ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags mngtmpaddr,noprefixroute ");
addr.flags = IFA_F_TENTATIVE | IFA_F_NOPREFIXROUTE;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,noprefixroute ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags tentative,noprefixroute ");
addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags tentative,permanent,mngtmpaddr,noprefixroute ");
addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE | 0x8000;
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
addr.flags = IFA_F_TENTATIVE | IFA_F_PERMANENT | IFA_F_MANAGETEMPADDR| IFA_F_NOPREFIXROUTE | ((G_MAXUINT - (G_MAXUINT >> 1)) >> 1);
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
nmtst_assert_str_has_substr (nm_platform_ip6_address_to_string (&addr, NULL, 0), " flags tentative,permanent,mngtmpaddr,noprefixroute, ");
}
/******************************************************************/
......
......@@ -264,8 +264,8 @@ test_nm_ip6_config_addresses_sort_check (NMIP6Config *config, NMSettingIP6Config
if (!nm_ip6_config_equal (copy, config)) {
g_message ("%s", "SORTING yields unexpected output:");
for (i = 0; i < addr_count; i++) {
g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i)));
g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (copy, i)));
g_message (" >> [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (config, i), NULL, 0));
g_message (" << [%d] = %s", i, nm_platform_ip6_address_to_string (nm_ip6_config_get_address (copy, i), NULL, 0));
}
g_assert_not_reached ();
}
......
......@@ -797,10 +797,12 @@ _assert_route_check (const NMPlatformVTableRoute *vtable, gboolean has, const NM
if (!has) {
g_assert (!r);
} else {
char buf[sizeof (_nm_platform_to_string_buffer)];
if (!r || vtable->route_cmp (route, r) != 0)
g_error ("Invalid route. Expect %s, has %s",
nmtst_static_1024_01 (vtable->route_to_string (route)),
nmtst_static_1024_02 (vtable->route_to_string (r)));
vtable->route_to_string (route, NULL, 0),
vtable->route_to_string (r, buf, sizeof (buf)));
g_assert (r);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment