ifcfg-rh: omit empty next hop for routes in legacy format
Don't add "via (null)" if the next hop is missing. https://bugzilla.redhat.com/show_bug.cgi?id=1452648
This commit is contained in:
@@ -1915,12 +1915,8 @@ get_route_attributes_string (NMIPRoute *route, int family)
|
|||||||
static gboolean
|
static gboolean
|
||||||
write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
|
write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
|
||||||
{
|
{
|
||||||
const char *dest, *next_hop;
|
nm_auto_free_gstring GString *contents = NULL;
|
||||||
char **route_items;
|
|
||||||
gs_free char *route_contents = NULL;
|
|
||||||
NMIPRoute *route;
|
NMIPRoute *route;
|
||||||
guint32 prefix;
|
|
||||||
gint64 metric;
|
|
||||||
guint32 i, num;
|
guint32 i, num;
|
||||||
|
|
||||||
g_return_val_if_fail (filename != NULL, FALSE);
|
g_return_val_if_fail (filename != NULL, FALSE);
|
||||||
@@ -1934,36 +1930,34 @@ write_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
route_items = g_malloc0 (sizeof (char *) * (num + 1));
|
contents = g_string_new ("");
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
|
const char *next_hop;
|
||||||
gs_free char *options = NULL;
|
gs_free char *options = NULL;
|
||||||
|
gint64 metric;
|
||||||
|
|
||||||
route = nm_setting_ip_config_get_route (s_ip4, i);
|
route = nm_setting_ip_config_get_route (s_ip4, i);
|
||||||
|
|
||||||
dest = nm_ip_route_get_dest (route);
|
|
||||||
prefix = nm_ip_route_get_prefix (route);
|
|
||||||
next_hop = nm_ip_route_get_next_hop (route);
|
next_hop = nm_ip_route_get_next_hop (route);
|
||||||
metric = nm_ip_route_get_metric (route);
|
metric = nm_ip_route_get_metric (route);
|
||||||
|
|
||||||
options = get_route_attributes_string (route, AF_INET);
|
options = get_route_attributes_string (route, AF_INET);
|
||||||
|
|
||||||
if (metric == -1) {
|
g_string_append_printf (contents, "%s/%u",
|
||||||
route_items[i] = g_strdup_printf ("%s/%u via %s%s%s\n",
|
nm_ip_route_get_dest (route),
|
||||||
dest, prefix, next_hop,
|
nm_ip_route_get_prefix (route));
|
||||||
options ? " " : "",
|
if (next_hop)
|
||||||
options ?: "");
|
g_string_append_printf (contents, " via %s", next_hop);
|
||||||
} else {
|
if (metric >= 0)
|
||||||
route_items[i] = g_strdup_printf ("%s/%u via %s metric %u%s%s\n",
|
g_string_append_printf (contents, " metric %u", (guint) metric);
|
||||||
dest, prefix, next_hop, (guint32) metric,
|
if (options) {
|
||||||
options ? " " : "",
|
g_string_append_c (contents, ' ');
|
||||||
options ?: "");
|
g_string_append (contents, options);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
route_items[num] = NULL;
|
|
||||||
route_contents = g_strjoinv (NULL, route_items);
|
|
||||||
g_strfreev (route_items);
|
|
||||||
|
|
||||||
if (!g_file_set_contents (filename, route_contents, -1, NULL)) {
|
g_string_append_c (contents, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_file_set_contents (filename, contents->str, contents->len, NULL)) {
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
|
||||||
"Writing route file '%s' failed", filename);
|
"Writing route file '%s' failed", filename);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -2474,32 +2468,33 @@ write_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
contents = g_string_new ("");
|
contents = g_string_new ("");
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
gs_free char *options = NULL;
|
gs_free char *options = NULL;
|
||||||
|
const char *next_hop;
|
||||||
|
gint64 metric;
|
||||||
|
|
||||||
route = nm_setting_ip_config_get_route (s_ip6, i);
|
route = nm_setting_ip_config_get_route (s_ip6, i);
|
||||||
|
next_hop = nm_ip_route_get_next_hop (route);
|
||||||
|
metric = nm_ip_route_get_metric (route);
|
||||||
options = get_route_attributes_string (route, AF_INET6);
|
options = get_route_attributes_string (route, AF_INET6);
|
||||||
|
|
||||||
if (nm_ip_route_get_metric (route) == -1) {
|
g_string_append_printf (contents, "%s/%u",
|
||||||
g_string_append_printf (contents, "%s/%u via %s%s%s",
|
|
||||||
nm_ip_route_get_dest (route),
|
nm_ip_route_get_dest (route),
|
||||||
nm_ip_route_get_prefix (route),
|
nm_ip_route_get_prefix (route));
|
||||||
nm_ip_route_get_next_hop (route),
|
if (next_hop)
|
||||||
options ? " " : "",
|
g_string_append_printf (contents, " via %s", next_hop);
|
||||||
options ?: "");
|
if (metric >= 0)
|
||||||
} else {
|
g_string_append_printf (contents, " metric %u", (guint) metric);
|
||||||
g_string_append_printf (contents, "%s/%u via %s metric %u%s%s",
|
if (options) {
|
||||||
nm_ip_route_get_dest (route),
|
g_string_append_c (contents, ' ');
|
||||||
nm_ip_route_get_prefix (route),
|
g_string_append (contents, options);
|
||||||
nm_ip_route_get_next_hop (route),
|
|
||||||
(unsigned) nm_ip_route_get_metric (route),
|
|
||||||
options ? " " : "",
|
|
||||||
options ?: "");
|
|
||||||
}
|
|
||||||
g_string_append (contents, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_file_set_contents (filename, contents->str, -1, NULL)) {
|
g_string_append_c (contents, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_file_set_contents (filename, contents->str, contents->len, NULL)) {
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
|
||||||
"Writing route6 file '%s' failed", filename);
|
"Writing route6 file '%s' failed", filename);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Reference in New Issue
Block a user