2019-09-10 11:19:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-10-03 23:42:26 -05:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2013-10-03 23:42:26 -05:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
|
|
#include "nm-dcb.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nm-platform.h"
|
2013-10-03 23:42:26 -05:00
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
|
|
|
|
|
static const char *helper_names[] = { "dcbtool", "fcoeadm" };
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
do_helper (const char *iface,
|
|
|
|
|
guint which,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
|
|
|
|
{
|
2019-04-04 13:46:46 +02:00
|
|
|
gs_free const char **split = NULL;
|
|
|
|
|
gs_free char *cmdline = NULL;
|
|
|
|
|
gs_free const char **argv = NULL;
|
|
|
|
|
gsize i;
|
|
|
|
|
gsize u;
|
2013-10-03 23:42:26 -05:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (fmt != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
va_start (args, fmt);
|
|
|
|
|
cmdline = g_strdup_vprintf (fmt, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2019-04-04 13:46:46 +02:00
|
|
|
split = nm_utils_strsplit_set_with_empty (cmdline, " ");
|
2013-10-03 23:42:26 -05:00
|
|
|
if (!split) {
|
core: drop all remaining core-internal error domains
A number of classes in core had their own error domains that aren't
really necessary.
In the case of NMDcbError, NMDhcpManagerError, NMDnsManagerError,
NMDnsmasqManagerError, NMPppManagerError, and NMSessionMonitorError,
most of the codes they defined weren't even being used, and at any
rate, the errors were always returned into contexts where they would
just have their message extracted and then get thrown away without
anyone ever looking at the domain or code. So all uses of those
domains can just be replaced with NM_MANAGER_ERROR_FAILED without any
loss of information.
NMAuthManagerError only had 1 error code, and it just indicated
"something went wrong", so it can be replaced with
NM_MANAGER_ERROR_FAILED without loss of information.
(nm-auth-manager.c has also been fixed to return
NM_MANAGER_ERROR_FAILED when the CheckAuthorization D-Bus call fails,
rather than returning whatever error domain/code the D-Bus call
returned.)
NMVpnManagerError used 2 of its 4 error codes, and they could actually
end up getting returned across D-Bus in some cases. But there are
NMManagerError codes that are semantically similar enough to make the
NMVpnManagerError ones unnecessary.
2014-10-16 16:51:22 -04:00
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
|
2013-10-03 23:42:26 -05:00
|
|
|
"failure parsing %s command line", helper_names[which]);
|
2019-04-04 13:46:46 +02:00
|
|
|
return FALSE;
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate space for path, custom arg, interface name, arguments, and NULL */
|
2019-04-04 13:46:46 +02:00
|
|
|
i = 0;
|
|
|
|
|
argv = g_new (const char *, NM_PTRARRAY_LEN (split) + 4);
|
2013-10-03 23:42:26 -05:00
|
|
|
argv[i++] = NULL; /* Placeholder for dcbtool path */
|
|
|
|
|
if (which == DCBTOOL) {
|
|
|
|
|
argv[i++] = "sc";
|
|
|
|
|
argv[i++] = (char *) iface;
|
|
|
|
|
}
|
2019-04-04 13:46:46 +02:00
|
|
|
for (u = 0; split[u]; u++)
|
|
|
|
|
argv[i++] = split[u];
|
2013-10-03 23:42:26 -05:00
|
|
|
argv[i++] = NULL;
|
|
|
|
|
|
2019-04-04 13:46:46 +02:00
|
|
|
if (!run_func ((char **) argv, which, user_data, error)) {
|
2019-04-16 15:24:58 +02:00
|
|
|
g_assert (!error || *error);
|
2019-04-04 13:46:46 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
dcb: separate DCB enable/disable and wait for carrier changes (rh #799241) (rh #1081991)
Non-git-master versions of lldpad refuse to touch a device that doesn't
have a carrier. And when enabling/disabling DCB, the kernel driver will
reconfigure itself and may turn carrier off for a few seconds. So we
must ensure that before enabling/disabling DCB, the carrier is already
on. Next we must ensure that *after* enabling/disabling DCB, the
carrier is back on before doing further DCB setup.
There's a race condition between enabling/disabling DCB and receiving
the carrier event in NetworkManager that has to be handled carefully.
Because the carrier may not yet be down after the dcbtool call to
enable/disable DCB returns, we need to wait for a couple seconds for
the carrier to go down, and then again for it to come back up.
Otherwise we might see the still-on carrier, proceed with DCB setup,
and the carrier finally goes down halfway through the setup, which
will fail the operations with "DCB not enabled, link down, or DCB
not supported" errors from lldpad.
2014-03-27 13:49:50 -05:00
|
|
|
gboolean
|
|
|
|
|
_dcb_enable (const char *iface,
|
|
|
|
|
gboolean enable,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
if (enable)
|
|
|
|
|
return do_helper (iface, DCBTOOL, run_func, user_data, error, "dcb on");
|
|
|
|
|
else
|
|
|
|
|
return do_helper (iface, DCBTOOL, run_func, user_data, error, "dcb off");
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 23:42:26 -05:00
|
|
|
#define SET_FLAGS(f, tag) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if (!do_helper (iface, DCBTOOL, run_func, user_data, error, tag " e:%c a:%c w:%c", \
|
|
|
|
|
f & NM_SETTING_DCB_FLAG_ENABLE ? '1' : '0', \
|
|
|
|
|
f & NM_SETTING_DCB_FLAG_ADVERTISE ? '1' : '0', \
|
|
|
|
|
f & NM_SETTING_DCB_FLAG_WILLING ? '1' : '0')) \
|
|
|
|
|
return FALSE; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
#define SET_APP(f, s, tag) \
|
|
|
|
|
G_STMT_START { \
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
int prio = nm_setting_dcb_get_app_##tag##_priority (s); \
|
2013-10-03 23:42:26 -05:00
|
|
|
\
|
|
|
|
|
SET_FLAGS (f, "app:" #tag); \
|
|
|
|
|
if ((f & NM_SETTING_DCB_FLAG_ENABLE) && (prio >= 0)) { \
|
|
|
|
|
if (!do_helper (iface, DCBTOOL, run_func, user_data, error, "app:" #tag " appcfg:%02x", (1 << prio))) \
|
|
|
|
|
return FALSE; \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_dcb_setup (const char *iface,
|
|
|
|
|
NMSettingDcb *s_dcb,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingDcbFlags flags;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_assert (s_dcb);
|
|
|
|
|
|
|
|
|
|
/* FCoE */
|
|
|
|
|
flags = nm_setting_dcb_get_app_fcoe_flags (s_dcb);
|
|
|
|
|
SET_APP (flags, s_dcb, fcoe);
|
|
|
|
|
|
|
|
|
|
/* iSCSI */
|
|
|
|
|
flags = nm_setting_dcb_get_app_iscsi_flags (s_dcb);
|
|
|
|
|
SET_APP (flags, s_dcb, iscsi);
|
|
|
|
|
|
|
|
|
|
/* FIP */
|
|
|
|
|
flags = nm_setting_dcb_get_app_fip_flags (s_dcb);
|
|
|
|
|
SET_APP (flags, s_dcb, fip);
|
|
|
|
|
|
|
|
|
|
/* Priority Flow Control */
|
|
|
|
|
flags = nm_setting_dcb_get_priority_flow_control_flags (s_dcb);
|
|
|
|
|
SET_FLAGS (flags, "pfc");
|
|
|
|
|
if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
|
|
|
|
|
char buf[10];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
|
buf[i] = nm_setting_dcb_get_priority_flow_control (s_dcb, i) ? '1' : '0';
|
|
|
|
|
buf[i] = 0;
|
|
|
|
|
if (!do_helper (iface, DCBTOOL, run_func, user_data, error, "pfc pfcup:%s", buf))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Priority Groups */
|
|
|
|
|
flags = nm_setting_dcb_get_priority_group_flags (s_dcb);
|
|
|
|
|
if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
GString *s;
|
|
|
|
|
gboolean success;
|
2013-10-03 23:42:26 -05:00
|
|
|
guint id;
|
|
|
|
|
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
s = g_string_sized_new (150);
|
|
|
|
|
|
|
|
|
|
g_string_append_printf (s, "pg e:1 a:%c w:%c",
|
|
|
|
|
flags & NM_SETTING_DCB_FLAG_ADVERTISE ? '1' : '0',
|
|
|
|
|
flags & NM_SETTING_DCB_FLAG_WILLING ? '1' : '0');
|
|
|
|
|
|
2013-10-03 23:42:26 -05:00
|
|
|
/* Priority Groups */
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append (s, " pgid:");
|
2013-10-03 23:42:26 -05:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
id = nm_setting_dcb_get_priority_group_id (s_dcb, i);
|
|
|
|
|
g_assert (id < 8 || id == 15);
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append_c (s, (id < 8) ? ('0' + id) : 'f');
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Priority Group Bandwidth */
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append_printf (s, " pgpct:%u,%u,%u,%u,%u,%u,%u,%u",
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 0),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 1),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 2),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 3),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 4),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 5),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 6),
|
|
|
|
|
nm_setting_dcb_get_priority_group_bandwidth (s_dcb, 7));
|
2013-10-03 23:42:26 -05:00
|
|
|
|
|
|
|
|
/* Priority Bandwidth */
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append_printf (s, " uppct:%u,%u,%u,%u,%u,%u,%u,%u",
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 0),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 1),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 2),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 3),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 4),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 5),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 6),
|
|
|
|
|
nm_setting_dcb_get_priority_bandwidth (s_dcb, 7));
|
2013-10-03 23:42:26 -05:00
|
|
|
|
|
|
|
|
/* Strict Bandwidth */
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append (s, " strict:");
|
2013-10-03 23:42:26 -05:00
|
|
|
for (i = 0; i < 8; i++)
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append_c (s, nm_setting_dcb_get_priority_strict_bandwidth (s_dcb, i) ? '1' : '0');
|
2013-10-03 23:42:26 -05:00
|
|
|
|
|
|
|
|
/* Priority Traffic Class */
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append (s, " up2tc:");
|
2013-10-03 23:42:26 -05:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
|
id = nm_setting_dcb_get_priority_traffic_class (s_dcb, i);
|
|
|
|
|
g_assert (id < 8);
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_append_c (s, '0' + id);
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
|
2014-04-02 09:24:21 -04:00
|
|
|
success = do_helper (iface, DCBTOOL, run_func, user_data, error, "%s", s->str);
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
if (!success)
|
2013-10-03 23:42:26 -05:00
|
|
|
return FALSE;
|
dcb: set all Priority Group options at the same time (rh #799241)
First, lldpad doesn't support disabling priority groups (e:0)
without specifying a complete priority group config (which wouldn't
be used anyway, since you're turning it off!). While this bug is
being fixed upstream, we'll just ignore errors turning off
PG, since if you're using DCB on an interface, you probably want
to use it all the time.
Second, lldpad really wants all PG options on the same configuration
line, not split apart, because it validates the complete package
of options before applying them, regardless of whether or not they
are given in the same command. Since NM was just emitting all the
options in separate dcbtool invocations anyway, just combine them
all into a single invocation.
2014-03-18 13:39:52 -05:00
|
|
|
} else {
|
|
|
|
|
/* Ignore disable failure since lldpad <= 0.9.46 does not support disabling
|
|
|
|
|
* priority groups without specifying an entire PG config.
|
|
|
|
|
*/
|
2014-04-01 15:01:38 -04:00
|
|
|
(void) do_helper (iface, DCBTOOL, run_func, user_data, error, "pg e:0");
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_dcb_cleanup (const char *iface,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
2014-03-20 12:39:44 -05:00
|
|
|
const char *cmds[] = {
|
|
|
|
|
"app:fcoe e:0",
|
|
|
|
|
"app:iscsi e:0",
|
|
|
|
|
"app:fip e:0",
|
|
|
|
|
"pfc e:0",
|
|
|
|
|
"pg e:0",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
const char **iter = cmds;
|
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
|
|
/* Turn everything off and return first error we get (if any) */
|
|
|
|
|
while (iter && *iter) {
|
2014-04-02 09:24:21 -04:00
|
|
|
if (!do_helper (iface, DCBTOOL, run_func, user_data, success ? error : NULL, "%s", *iter))
|
2014-03-20 12:39:44 -05:00
|
|
|
success = FALSE;
|
|
|
|
|
iter++;
|
|
|
|
|
}
|
|
|
|
|
|
dcb: separate DCB enable/disable and wait for carrier changes (rh #799241) (rh #1081991)
Non-git-master versions of lldpad refuse to touch a device that doesn't
have a carrier. And when enabling/disabling DCB, the kernel driver will
reconfigure itself and may turn carrier off for a few seconds. So we
must ensure that before enabling/disabling DCB, the carrier is already
on. Next we must ensure that *after* enabling/disabling DCB, the
carrier is back on before doing further DCB setup.
There's a race condition between enabling/disabling DCB and receiving
the carrier event in NetworkManager that has to be handled carefully.
Because the carrier may not yet be down after the dcbtool call to
enable/disable DCB returns, we need to wait for a couple seconds for
the carrier to go down, and then again for it to come back up.
Otherwise we might see the still-on carrier, proceed with DCB setup,
and the carrier finally goes down halfway through the setup, which
will fail the operations with "DCB not enabled, link down, or DCB
not supported" errors from lldpad.
2014-03-27 13:49:50 -05:00
|
|
|
if (!_dcb_enable (iface, FALSE, run_func, user_data, success ? error : NULL))
|
|
|
|
|
success = FALSE;
|
|
|
|
|
|
2014-03-20 12:39:44 -05:00
|
|
|
return success;
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_fcoe_setup (const char *iface,
|
|
|
|
|
NMSettingDcb *s_dcb,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingDcbFlags flags;
|
|
|
|
|
|
|
|
|
|
g_assert (s_dcb);
|
|
|
|
|
|
|
|
|
|
flags = nm_setting_dcb_get_app_fcoe_flags (s_dcb);
|
|
|
|
|
if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
|
|
|
|
|
const char *mode = nm_setting_dcb_get_app_fcoe_mode (s_dcb);
|
|
|
|
|
|
|
|
|
|
if (!do_helper (NULL, FCOEADM, run_func, user_data, error, "-m %s -c %s", mode, iface))
|
|
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
if (!do_helper (NULL, FCOEADM, run_func, user_data, error, "-d %s", iface))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_fcoe_cleanup (const char *iface,
|
|
|
|
|
DcbFunc run_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
return do_helper (NULL, FCOEADM, run_func, user_data, error, "-d %s", iface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
run_helper (char **argv, guint which, gpointer user_data, GError **error)
|
|
|
|
|
{
|
2014-07-31 14:02:22 -05:00
|
|
|
const char *helper_path;
|
2013-10-03 23:42:26 -05:00
|
|
|
int exit_status = 0;
|
|
|
|
|
gboolean success;
|
|
|
|
|
char *errmsg = NULL, *outmsg = NULL;
|
|
|
|
|
char *cmdline;
|
|
|
|
|
|
2014-07-31 14:02:22 -05:00
|
|
|
helper_path = nm_utils_find_helper ((which == DCBTOOL) ? "dcbtool" : "fcoeadm", NULL, error);
|
|
|
|
|
if (!helper_path)
|
|
|
|
|
return FALSE;
|
2013-10-03 23:42:26 -05:00
|
|
|
|
2014-07-31 14:02:22 -05:00
|
|
|
argv[0] = (char *) helper_path;
|
2013-10-03 23:42:26 -05:00
|
|
|
cmdline = g_strjoinv (" ", argv);
|
|
|
|
|
nm_log_dbg (LOGD_DCB, "%s", cmdline);
|
|
|
|
|
|
|
|
|
|
success = g_spawn_sync ("/", argv, NULL, 0 /*G_SPAWN_DEFAULT*/,
|
2015-01-12 11:31:10 -05:00
|
|
|
NULL, NULL,
|
2013-10-03 23:42:26 -05:00
|
|
|
&outmsg, &errmsg, &exit_status, error);
|
|
|
|
|
/* Log any stderr output */
|
|
|
|
|
if (success && WIFEXITED (exit_status) && WEXITSTATUS (exit_status) && (errmsg || outmsg)) {
|
2014-03-19 15:39:51 -05:00
|
|
|
gboolean ignore_error = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Ignore fcoeadm "success" errors like when FCoE is already set up */
|
|
|
|
|
if (errmsg && strstr (errmsg, "Connection already created"))
|
|
|
|
|
ignore_error = TRUE;
|
|
|
|
|
|
|
|
|
|
if (ignore_error == FALSE) {
|
|
|
|
|
nm_log_warn (LOGD_DCB, "'%s' failed: '%s'",
|
|
|
|
|
cmdline, (errmsg && strlen (errmsg)) ? errmsg : outmsg);
|
core: drop all remaining core-internal error domains
A number of classes in core had their own error domains that aren't
really necessary.
In the case of NMDcbError, NMDhcpManagerError, NMDnsManagerError,
NMDnsmasqManagerError, NMPppManagerError, and NMSessionMonitorError,
most of the codes they defined weren't even being used, and at any
rate, the errors were always returned into contexts where they would
just have their message extracted and then get thrown away without
anyone ever looking at the domain or code. So all uses of those
domains can just be replaced with NM_MANAGER_ERROR_FAILED without any
loss of information.
NMAuthManagerError only had 1 error code, and it just indicated
"something went wrong", so it can be replaced with
NM_MANAGER_ERROR_FAILED without loss of information.
(nm-auth-manager.c has also been fixed to return
NM_MANAGER_ERROR_FAILED when the CheckAuthorization D-Bus call fails,
rather than returning whatever error domain/code the D-Bus call
returned.)
NMVpnManagerError used 2 of its 4 error codes, and they could actually
end up getting returned across D-Bus in some cases. But there are
NMManagerError codes that are semantically similar enough to make the
NMVpnManagerError ones unnecessary.
2014-10-16 16:51:22 -04:00
|
|
|
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
|
2014-03-19 15:39:51 -05:00
|
|
|
"Failed to run '%s'", cmdline);
|
|
|
|
|
success = FALSE;
|
|
|
|
|
}
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
2014-07-31 14:02:22 -05:00
|
|
|
|
2014-03-19 14:42:51 -05:00
|
|
|
g_free (outmsg);
|
2013-10-03 23:42:26 -05:00
|
|
|
g_free (errmsg);
|
|
|
|
|
g_free (cmdline);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
dcb: separate DCB enable/disable and wait for carrier changes (rh #799241) (rh #1081991)
Non-git-master versions of lldpad refuse to touch a device that doesn't
have a carrier. And when enabling/disabling DCB, the kernel driver will
reconfigure itself and may turn carrier off for a few seconds. So we
must ensure that before enabling/disabling DCB, the carrier is already
on. Next we must ensure that *after* enabling/disabling DCB, the
carrier is back on before doing further DCB setup.
There's a race condition between enabling/disabling DCB and receiving
the carrier event in NetworkManager that has to be handled carefully.
Because the carrier may not yet be down after the dcbtool call to
enable/disable DCB returns, we need to wait for a couple seconds for
the carrier to go down, and then again for it to come back up.
Otherwise we might see the still-on carrier, proceed with DCB setup,
and the carrier finally goes down halfway through the setup, which
will fail the operations with "DCB not enabled, link down, or DCB
not supported" errors from lldpad.
2014-03-27 13:49:50 -05:00
|
|
|
gboolean
|
|
|
|
|
nm_dcb_enable (const char *iface, gboolean enable, GError **error)
|
|
|
|
|
{
|
|
|
|
|
return _dcb_enable (iface, enable, run_helper, GUINT_TO_POINTER (DCBTOOL), error);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 23:42:26 -05:00
|
|
|
gboolean
|
|
|
|
|
nm_dcb_setup (const char *iface, NMSettingDcb *s_dcb, GError **error)
|
|
|
|
|
{
|
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
|
|
success = _dcb_setup (iface, s_dcb, run_helper, GUINT_TO_POINTER (DCBTOOL), error);
|
|
|
|
|
if (success)
|
|
|
|
|
success = _fcoe_setup (iface, s_dcb, run_helper, GUINT_TO_POINTER (FCOEADM), error);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 15:06:22 -05:00
|
|
|
static void
|
|
|
|
|
carrier_wait (const char *iface, guint secs, gboolean up)
|
|
|
|
|
{
|
|
|
|
|
int ifindex, count = secs * 10;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (iface != NULL);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, iface);
|
2014-03-31 15:06:22 -05:00
|
|
|
if (ifindex > 0) {
|
|
|
|
|
/* To work around driver quirks and lldpad handling of carrier status,
|
|
|
|
|
* we must wait a short period of time to see if the carrier goes
|
|
|
|
|
* down, and then wait for the carrier to come back up again. Otherwise
|
|
|
|
|
* subsequent lldpad calls may fail with "Device not found, link down
|
|
|
|
|
* or DCB not enabled" errors.
|
|
|
|
|
*/
|
|
|
|
|
nm_log_dbg (LOGD_DCB, "(%s): cleanup waiting for carrier %s",
|
|
|
|
|
iface, up ? "up" : "down");
|
|
|
|
|
g_usleep (G_USEC_PER_SEC / 4);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
while (nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex) != up && count-- > 0) {
|
2014-03-31 15:06:22 -05:00
|
|
|
g_usleep (G_USEC_PER_SEC / 10);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_refresh (NM_PLATFORM_GET, ifindex);
|
2014-03-31 15:06:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 23:42:26 -05:00
|
|
|
gboolean
|
|
|
|
|
nm_dcb_cleanup (const char *iface, GError **error)
|
|
|
|
|
{
|
dcb: separate DCB enable/disable and wait for carrier changes (rh #799241) (rh #1081991)
Non-git-master versions of lldpad refuse to touch a device that doesn't
have a carrier. And when enabling/disabling DCB, the kernel driver will
reconfigure itself and may turn carrier off for a few seconds. So we
must ensure that before enabling/disabling DCB, the carrier is already
on. Next we must ensure that *after* enabling/disabling DCB, the
carrier is back on before doing further DCB setup.
There's a race condition between enabling/disabling DCB and receiving
the carrier event in NetworkManager that has to be handled carefully.
Because the carrier may not yet be down after the dcbtool call to
enable/disable DCB returns, we need to wait for a couple seconds for
the carrier to go down, and then again for it to come back up.
Otherwise we might see the still-on carrier, proceed with DCB setup,
and the carrier finally goes down halfway through the setup, which
will fail the operations with "DCB not enabled, link down, or DCB
not supported" errors from lldpad.
2014-03-27 13:49:50 -05:00
|
|
|
/* Ignore FCoE cleanup errors */
|
|
|
|
|
_fcoe_cleanup (iface, run_helper, GUINT_TO_POINTER (FCOEADM), NULL);
|
2014-03-31 15:06:22 -05:00
|
|
|
|
|
|
|
|
/* Must pause a bit to wait for carrier-up since disabling FCoE may
|
|
|
|
|
* cause the device to take the link down, making lldpad return errors.
|
|
|
|
|
*/
|
|
|
|
|
carrier_wait (iface, 2, FALSE);
|
|
|
|
|
carrier_wait (iface, 4, TRUE);
|
|
|
|
|
|
dcb: separate DCB enable/disable and wait for carrier changes (rh #799241) (rh #1081991)
Non-git-master versions of lldpad refuse to touch a device that doesn't
have a carrier. And when enabling/disabling DCB, the kernel driver will
reconfigure itself and may turn carrier off for a few seconds. So we
must ensure that before enabling/disabling DCB, the carrier is already
on. Next we must ensure that *after* enabling/disabling DCB, the
carrier is back on before doing further DCB setup.
There's a race condition between enabling/disabling DCB and receiving
the carrier event in NetworkManager that has to be handled carefully.
Because the carrier may not yet be down after the dcbtool call to
enable/disable DCB returns, we need to wait for a couple seconds for
the carrier to go down, and then again for it to come back up.
Otherwise we might see the still-on carrier, proceed with DCB setup,
and the carrier finally goes down halfway through the setup, which
will fail the operations with "DCB not enabled, link down, or DCB
not supported" errors from lldpad.
2014-03-27 13:49:50 -05:00
|
|
|
return _dcb_cleanup (iface, run_helper, GUINT_TO_POINTER (DCBTOOL), error);
|
2013-10-03 23:42:26 -05:00
|
|
|
}
|
|
|
|
|
|