1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2013 Red Hat, Inc.
22 #include "nm-default.h"
25 #include <dbus/dbus-glib.h>
27 #include "nm-setting-dcb.h"
28 #include "nm-param-spec-specialized.h"
30 #include "nm-utils-private.h"
31 #include "nm-dbus-glib-types.h"
32 #include "nm-setting-private.h"
35 * SECTION:nm-setting-dcb
36 * @short_description: Connection properties for Data Center Bridging
37 * @include: nm-setting-dcb.h
39 * The #NMSettingDcb object is a #NMSetting subclass that describes properties
40 * for enabling and using Data Center Bridging (DCB) on Ethernet networks.
41 * DCB is a set of protocols (including 802.1Qbb, 802.1Qaz, 802.1Qau, and
42 * 802.1AB) to eliminate packet loss in Ethernet networks and support the use
43 * of storage technologies like Fibre Channel over Ethernet (FCoE) and iSCSI.
49 * nm_setting_dcb_error_quark:
51 * Registers an error quark for #NMSettingDcb if necessary.
53 * Returns: the error quark used for #NMSettingDcb errors.
58 nm_setting_dcb_error_quark (void)
62 if (G_UNLIKELY (!quark))
63 quark = g_quark_from_static_string ("nm-setting-dcb-error-quark");
68 G_DEFINE_TYPE_WITH_CODE (NMSettingDcb, nm_setting_dcb, NM_TYPE_SETTING,
69 _nm_register_setting (NM_SETTING_DCB_SETTING_NAME,
72 NM_SETTING_DCB_ERROR))
73 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DCB)
75 #define NM_SETTING_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_DCB, NMSettingDcbPrivate))
78 NMSettingDcbFlags app_fcoe_flags;
79 gint app_fcoe_priority;
82 NMSettingDcbFlags app_iscsi_flags;
83 gint app_iscsi_priority;
85 NMSettingDcbFlags app_fip_flags;
86 gint app_fip_priority;
88 /* Priority Flow Control */
89 NMSettingDcbFlags pfc_flags;
93 NMSettingDcbFlags priority_group_flags;
94 guint priority_group_id[8];
95 guint priority_group_bandwidth[8];
96 guint priority_bandwidth[8];
97 guint priority_strict[8];
98 guint priority_traffic_class[8];
99 } NMSettingDcbPrivate;
104 PROP_APP_FCOE_PRIORITY,
107 PROP_APP_ISCSI_FLAGS,
108 PROP_APP_ISCSI_PRIORITY,
111 PROP_APP_FIP_PRIORITY,
116 PROP_PRIORITY_GROUP_FLAGS,
117 PROP_PRIORITY_GROUP_ID,
118 PROP_PRIORITY_GROUP_BANDWIDTH,
119 PROP_PRIORITY_BANDWIDTH,
120 PROP_PRIORITY_STRICT,
121 PROP_PRIORITY_TRAFFIC_CLASS,
127 * nm_setting_dcb_new:
129 * Creates a new #NMSettingDcb object with default values.
131 * Returns: (transfer full): the new empty #NMSettingDcb object
136 nm_setting_dcb_new (void)
138 return (NMSetting *) g_object_new (NM_TYPE_SETTING_DCB, NULL);
142 * nm_setting_dcb_get_app_fcoe_flags:
143 * @setting: the #NMSettingDcb
145 * Returns: the #NMSettingDcb:app-fcoe-flags property of the setting
150 nm_setting_dcb_get_app_fcoe_flags (NMSettingDcb *setting)
152 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
154 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_flags;
158 * nm_setting_dcb_get_app_fcoe_priority:
159 * @setting: the #NMSettingDcb
161 * Returns: the #NMSettingDcb:app-fcoe-priority property of the setting
166 nm_setting_dcb_get_app_fcoe_priority (NMSettingDcb *setting)
168 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
170 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_priority;
174 * nm_setting_dcb_get_app_fcoe_mode:
175 * @setting: the #NMSettingDcb
177 * Returns: the #NMSettingDcb:app-fcoe-mode property of the setting
182 nm_setting_dcb_get_app_fcoe_mode (NMSettingDcb *setting)
184 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), NULL);
186 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_mode;
190 * nm_setting_dcb_get_app_iscsi_flags:
191 * @setting: the #NMSettingDcb
193 * Returns: the #NMSettingDcb:app-iscsi-flags property of the setting
198 nm_setting_dcb_get_app_iscsi_flags (NMSettingDcb *setting)
200 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
202 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_iscsi_flags;
206 * nm_setting_dcb_get_app_iscsi_priority:
207 * @setting: the #NMSettingDcb
209 * Returns: the #NMSettingDcb:app-iscsi-priority property of the setting
214 nm_setting_dcb_get_app_iscsi_priority (NMSettingDcb *setting)
216 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
218 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_iscsi_priority;
222 * nm_setting_dcb_get_app_fip_flags:
223 * @setting: the #NMSettingDcb
225 * Returns: the #NMSettingDcb:app-fip-flags property of the setting
230 nm_setting_dcb_get_app_fip_flags (NMSettingDcb *setting)
232 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
234 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fip_flags;
238 * nm_setting_dcb_get_app_fip_priority:
239 * @setting: the #NMSettingDcb
241 * Returns: the #NMSettingDcb:app-fip-priority property of the setting
246 nm_setting_dcb_get_app_fip_priority (NMSettingDcb *setting)
248 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
250 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fip_priority;
254 * nm_setting_dcb_get_priority_flow_control_flags:
255 * @setting: the #NMSettingDcb
257 * Returns: the #NMSettingDcb:priority-flow-control-flags property of the setting
262 nm_setting_dcb_get_priority_flow_control_flags (NMSettingDcb *setting)
264 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
266 return NM_SETTING_DCB_GET_PRIVATE (setting)->pfc_flags;
270 * nm_setting_dcb_get_priority_flow_control:
271 * @setting: the #NMSettingDcb
272 * @user_priority: the User Priority (0 - 7) to retrieve flow control for
274 * Returns: %TRUE if flow control is enabled for the given @user_priority,
275 * %FALSE if not enabled
280 nm_setting_dcb_get_priority_flow_control (NMSettingDcb *setting, guint user_priority)
282 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), FALSE);
283 g_return_val_if_fail (user_priority <= 7, FALSE);
285 return !!NM_SETTING_DCB_GET_PRIVATE (setting)->pfc[user_priority];
289 * nm_setting_dcb_set_priority_flow_control:
290 * @setting: the #NMSettingDcb
291 * @user_priority: the User Priority (0 - 7) to set flow control for
292 * @enabled: %TRUE to enable flow control for this priority, %FALSE to disable it
294 * These values are only valid when #NMSettingDcb:priority-flow-control includes
295 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
300 nm_setting_dcb_set_priority_flow_control (NMSettingDcb *setting,
304 NMSettingDcbPrivate *priv;
305 guint uint_enabled = enabled ? 1 : 0;
307 g_return_if_fail (NM_IS_SETTING_DCB (setting));
308 g_return_if_fail (user_priority <= 7);
310 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
311 if (priv->pfc[user_priority] != uint_enabled) {
312 priv->pfc[user_priority] = uint_enabled;
313 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL);
318 * nm_setting_dcb_get_priority_group_flags:
319 * @setting: the #NMSettingDcb
321 * Returns: the #NMSettingDcb:priority-group-flags property of the setting
326 nm_setting_dcb_get_priority_group_flags (NMSettingDcb *setting)
328 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
330 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_flags;
334 * nm_setting_dcb_get_priority_group_id:
335 * @setting: the #NMSettingDcb
336 * @user_priority: the User Priority (0 - 7) to retrieve the group ID for
338 * Returns: the group number @user_priority is assigned to. These values are
339 * only valid when #NMSettingDcb:priority-group-flags includes the
340 * %NM_SETTING_DCB_FLAG_ENABLE flag.
345 nm_setting_dcb_get_priority_group_id (NMSettingDcb *setting, guint user_priority)
347 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
348 g_return_val_if_fail (user_priority <= 7, 0);
350 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_id[user_priority];
354 * nm_setting_dcb_set_priority_group_id:
355 * @setting: the #NMSettingDcb
356 * @user_priority: the User Priority (0 - 7) to set flow control for
357 * @group_id: the group (0 - 7) to assign @user_priority to, or 15 for the
358 * unrestricted group.
360 * These values are only valid when #NMSettingDcb:priority-group-flags includes
361 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
366 nm_setting_dcb_set_priority_group_id (NMSettingDcb *setting,
370 NMSettingDcbPrivate *priv;
372 g_return_if_fail (NM_IS_SETTING_DCB (setting));
373 g_return_if_fail (user_priority <= 7);
374 g_return_if_fail (group_id <= 7 || group_id == 15);
376 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
377 if (priv->priority_group_id[user_priority] != group_id) {
378 priv->priority_group_id[user_priority] = group_id;
379 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_GROUP_ID);
384 * nm_setting_dcb_get_priority_group_bandwidth:
385 * @setting: the #NMSettingDcb
386 * @group_id: the priority group (0 - 7) to retrieve the bandwidth percentage for
388 * Returns: the bandwidth percentage assigned to @group_id. These values are
389 * only valid when #NMSettingDcb:priority-group-flags includes the
390 * %NM_SETTING_DCB_FLAG_ENABLE flag.
395 nm_setting_dcb_get_priority_group_bandwidth (NMSettingDcb *setting, guint group_id)
397 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
398 g_return_val_if_fail (group_id <= 7, FALSE);
400 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_bandwidth[group_id];
404 * nm_setting_dcb_set_priority_group_bandwidth:
405 * @setting: the #NMSettingDcb
406 * @group_id: the priority group (0 - 7) to set the bandwidth percentage for
407 * @bandwidth_percent: the bandwidth percentage (0 - 100) to assign to @group_id to
409 * These values are only valid when #NMSettingDcb:priority-group-flags includes
410 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
415 nm_setting_dcb_set_priority_group_bandwidth (NMSettingDcb *setting,
417 guint bandwidth_percent)
419 NMSettingDcbPrivate *priv;
421 g_return_if_fail (NM_IS_SETTING_DCB (setting));
422 g_return_if_fail (group_id <= 7);
423 g_return_if_fail (bandwidth_percent <= 100);
425 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
426 if (priv->priority_group_bandwidth[group_id] != bandwidth_percent) {
427 priv->priority_group_bandwidth[group_id] = bandwidth_percent;
428 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH);
433 * nm_setting_dcb_get_priority_bandwidth:
434 * @setting: the #NMSettingDcb
435 * @user_priority: the User Priority (0 - 7) to retrieve the group bandwidth percentage for
437 * Returns: the allowed bandwidth percentage of @user_priority in its priority group.
438 * These values are only valid when #NMSettingDcb:priority-group-flags includes the
439 * %NM_SETTING_DCB_FLAG_ENABLE flag.
444 nm_setting_dcb_get_priority_bandwidth (NMSettingDcb *setting, guint user_priority)
446 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
447 g_return_val_if_fail (user_priority <= 7, FALSE);
449 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_bandwidth[user_priority];
453 * nm_setting_dcb_set_priority_bandwidth:
454 * @setting: the #NMSettingDcb
455 * @user_priority: the User Priority (0 - 7) to set the bandwidth percentage for
456 * @bandwidth_percent: the bandwidth percentage (0 - 100) that @user_priority is
457 * allowed to use within its priority group
459 * These values are only valid when #NMSettingDcb:priority-group-flags includes
460 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
465 nm_setting_dcb_set_priority_bandwidth (NMSettingDcb *setting,
467 guint bandwidth_percent)
469 NMSettingDcbPrivate *priv;
471 g_return_if_fail (NM_IS_SETTING_DCB (setting));
472 g_return_if_fail (user_priority <= 7);
473 g_return_if_fail (bandwidth_percent <= 100);
475 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
476 if (priv->priority_bandwidth[user_priority] != bandwidth_percent) {
477 priv->priority_bandwidth[user_priority] = bandwidth_percent;
478 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_BANDWIDTH);
483 * nm_setting_dcb_get_priority_strict_bandwidth:
484 * @setting: the #NMSettingDcb
485 * @user_priority: the User Priority (0 - 7) to retrieve strict bandwidth for
487 * Returns: %TRUE if @user_priority may use all of the bandwidth allocated to its
488 * assigned group, or %FALSE if not. These values are only valid when
489 * #NMSettingDcb:priority-group-flags includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
494 nm_setting_dcb_get_priority_strict_bandwidth (NMSettingDcb *setting, guint user_priority)
496 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
497 g_return_val_if_fail (user_priority <= 7, FALSE);
499 return !!NM_SETTING_DCB_GET_PRIVATE (setting)->priority_strict[user_priority];
503 * nm_setting_dcb_set_priority_strict_bandwidth:
504 * @setting: the #NMSettingDcb
505 * @user_priority: the User Priority (0 - 7) to set strict bandwidth for
506 * @strict: %TRUE to allow @user_priority to use all the bandwidth allocated to
507 * its priority group, or %FALSE if not
509 * These values are only valid when #NMSettingDcb:priority-group-flags includes
510 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
515 nm_setting_dcb_set_priority_strict_bandwidth (NMSettingDcb *setting,
519 NMSettingDcbPrivate *priv;
520 guint uint_strict = strict ? 1 : 0;
522 g_return_if_fail (NM_IS_SETTING_DCB (setting));
523 g_return_if_fail (user_priority <= 7);
525 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
526 if (priv->priority_strict[user_priority] != uint_strict) {
527 priv->priority_strict[user_priority] = uint_strict;
528 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH);
533 * nm_setting_dcb_get_priority_traffic_class:
534 * @setting: the #NMSettingDcb
535 * @user_priority: the User Priority (0 - 7) to retrieve the traffic class for
537 * Returns: the traffic class assigned to @user_priority. These values are only
538 * valid when #NMSettingDcb:priority-group-flags includes the
539 * %NM_SETTING_DCB_FLAG_ENABLE flag.
544 nm_setting_dcb_get_priority_traffic_class (NMSettingDcb *setting, guint user_priority)
546 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
547 g_return_val_if_fail (user_priority <= 7, FALSE);
549 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_traffic_class[user_priority];
553 * nm_setting_dcb_set_priority_traffic_clas:
554 * @setting: the #NMSettingDcb
555 * @user_priority: the User Priority (0 - 7) to set the bandwidth percentage for
556 * @traffic_class: the traffic_class (0 - 7) that @user_priority should map to
558 * These values are only valid when #NMSettingDcb:priority-group-flags includes
559 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
564 nm_setting_dcb_set_priority_traffic_class (NMSettingDcb *setting,
568 NMSettingDcbPrivate *priv;
570 g_return_if_fail (NM_IS_SETTING_DCB (setting));
571 g_return_if_fail (user_priority <= 7);
572 g_return_if_fail (traffic_class <= 7);
574 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
575 if (priv->priority_traffic_class[user_priority] != traffic_class) {
576 priv->priority_traffic_class[user_priority] = traffic_class;
577 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS);
581 /******************************************************************/
583 #define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
584 NM_SETTING_DCB_FLAG_ADVERTISE | \
585 NM_SETTING_DCB_FLAG_WILLING)
588 check_dcb_flags (NMSettingDcbFlags flags, const char *prop_name, GError **error)
590 if (flags & ~DCB_FLAGS_ALL) {
591 g_set_error_literal (error,
592 NM_SETTING_DCB_ERROR,
593 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
595 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
599 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && (flags & ~NM_SETTING_DCB_FLAG_ENABLE)) {
600 g_set_error_literal (error,
601 NM_SETTING_DCB_ERROR,
602 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
603 _("flags invalid - disabled"));
604 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
612 check_uint_array (const guint *array,
614 NMSettingDcbFlags flags,
618 const char *prop_name,
623 /* Ensure each element is <= to max or equals extra */
624 for (i = 0; i < len; i++) {
625 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && array[i]) {
626 g_set_error_literal (error,
627 NM_SETTING_DCB_ERROR,
628 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
629 _("property invalid (not enabled)"));
630 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
634 if ((array[i] > max) && (array[i] != extra)) {
635 g_set_error_literal (error,
636 NM_SETTING_DCB_ERROR,
637 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
638 _("element invalid"));
639 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
645 /* Verify sum of percentages */
647 if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
648 /* If the feature is enabled, sum must equal 100% */
650 g_set_error_literal (error,
651 NM_SETTING_DCB_ERROR,
652 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
654 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
658 /* If the feature is disabled, sum must equal 0%, which was checked
659 * by the for() loop above.
661 g_assert_cmpint (sum, ==, 0);
669 check_priority (gint val,
670 NMSettingDcbFlags flags,
671 const char *prop_name,
674 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && (val >= 0)) {
675 g_set_error_literal (error,
676 NM_SETTING_DCB_ERROR,
677 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
678 _("property invalid (not enabled)"));
679 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
683 if (val < -1 || val > 7) {
684 g_set_error_literal (error,
685 NM_SETTING_DCB_ERROR,
686 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
687 _("property invalid"));
688 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
695 verify (NMSetting *setting, GSList *all_settings, GError **error)
697 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
699 if (!check_dcb_flags (priv->app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_FLAGS, error))
702 if (!check_priority (priv->app_fcoe_priority, priv->app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_PRIORITY, error))
705 if (!priv->app_fcoe_mode) {
706 g_set_error_literal (error,
707 NM_SETTING_DCB_ERROR,
708 NM_SETTING_DCB_ERROR_MISSING_PROPERTY,
709 _("property missing"));
710 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, NM_SETTING_DCB_APP_FCOE_MODE);
714 if (strcmp (priv->app_fcoe_mode, NM_SETTING_DCB_FCOE_MODE_FABRIC) &&
715 strcmp (priv->app_fcoe_mode, NM_SETTING_DCB_FCOE_MODE_VN2VN)) {
716 g_set_error_literal (error,
717 NM_SETTING_DCB_ERROR,
718 NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
719 _("property invalid"));
720 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, NM_SETTING_DCB_APP_FCOE_MODE);
724 if (!check_dcb_flags (priv->app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_FLAGS, error))
727 if (!check_priority (priv->app_iscsi_priority, priv->app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_PRIORITY, error))
730 if (!check_dcb_flags (priv->app_fip_flags, NM_SETTING_DCB_APP_FIP_FLAGS, error))
733 if (!check_priority (priv->app_fip_priority, priv->app_fip_flags, NM_SETTING_DCB_APP_FIP_PRIORITY, error))
736 if (!check_dcb_flags (priv->pfc_flags, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, error))
739 if (!check_uint_array (priv->pfc, G_N_ELEMENTS (priv->pfc), priv->pfc_flags, 1, 0, FALSE, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, error))
742 if (!check_dcb_flags (priv->priority_group_flags, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, error))
745 if (!check_uint_array (priv->priority_group_id,
746 G_N_ELEMENTS (priv->priority_group_id),
747 priv->priority_group_flags,
751 NM_SETTING_DCB_PRIORITY_GROUP_ID,
755 if (!check_uint_array (priv->priority_group_bandwidth,
756 G_N_ELEMENTS (priv->priority_group_bandwidth),
757 priv->priority_group_flags,
761 NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH,
765 /* FIXME: sum bandwidths in each group */
766 if (!check_uint_array (priv->priority_bandwidth,
767 G_N_ELEMENTS (priv->priority_bandwidth),
768 priv->priority_group_flags,
772 NM_SETTING_DCB_PRIORITY_BANDWIDTH,
776 if (!check_uint_array (priv->priority_strict,
777 G_N_ELEMENTS (priv->priority_strict),
778 priv->priority_group_flags,
782 NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH,
786 if (!check_uint_array (priv->priority_traffic_class,
787 G_N_ELEMENTS (priv->priority_traffic_class),
788 priv->priority_group_flags,
792 NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS,
799 /******************************************************************/
802 nm_setting_dcb_init (NMSettingDcb *setting)
807 set_uint_array (const GValue *v, uint *a, size_t len)
809 GArray *src = g_value_get_boxed (v);
810 const guint total_len = len * sizeof (a[0]);
812 memset (a, 0, total_len);
814 g_return_if_fail (g_array_get_element_size (src) == sizeof (a[0]));
815 g_return_if_fail (src->len == len);
816 memcpy (a, src->data, total_len);
819 #define SET_UINT_ARRAY(v, a) set_uint_array (v, a, G_N_ELEMENTS (a))
822 set_property (GObject *object, guint prop_id,
823 const GValue *value, GParamSpec *pspec)
825 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
828 case PROP_APP_FCOE_FLAGS:
829 priv->app_fcoe_flags = g_value_get_uint (value);
831 case PROP_APP_FCOE_PRIORITY:
832 priv->app_fcoe_priority = g_value_get_int (value);
834 case PROP_APP_FCOE_MODE:
835 g_free (priv->app_fcoe_mode);
836 priv->app_fcoe_mode = g_value_dup_string (value);
838 case PROP_APP_ISCSI_FLAGS:
839 priv->app_iscsi_flags = g_value_get_uint (value);
841 case PROP_APP_ISCSI_PRIORITY:
842 priv->app_iscsi_priority = g_value_get_int (value);
844 case PROP_APP_FIP_FLAGS:
845 priv->app_fip_flags = g_value_get_uint (value);
847 case PROP_APP_FIP_PRIORITY:
848 priv->app_fip_priority = g_value_get_int (value);
851 priv->pfc_flags = g_value_get_uint (value);
854 SET_UINT_ARRAY (value, priv->pfc);
856 case PROP_PRIORITY_GROUP_FLAGS:
857 priv->priority_group_flags = g_value_get_uint (value);
859 case PROP_PRIORITY_GROUP_ID:
860 SET_UINT_ARRAY (value, priv->priority_group_id);
862 case PROP_PRIORITY_GROUP_BANDWIDTH:
863 SET_UINT_ARRAY (value, priv->priority_group_bandwidth);
865 case PROP_PRIORITY_BANDWIDTH:
866 SET_UINT_ARRAY (value, priv->priority_bandwidth);
868 case PROP_PRIORITY_STRICT:
869 SET_UINT_ARRAY (value, priv->priority_strict);
871 case PROP_PRIORITY_TRAFFIC_CLASS:
872 SET_UINT_ARRAY (value, priv->priority_traffic_class);
875 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
880 #define TAKE_UINT_ARRAY(v, a) \
882 guint len = G_N_ELEMENTS (a); \
883 GArray *dst = g_array_sized_new (FALSE, TRUE, sizeof (guint), len); \
884 g_array_append_vals (dst, (a), len); \
885 g_value_take_boxed (v, dst); \
889 get_property (GObject *object, guint prop_id,
890 GValue *value, GParamSpec *pspec)
892 NMSettingDcb *setting = NM_SETTING_DCB (object);
893 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
896 case PROP_APP_FCOE_FLAGS:
897 g_value_set_uint (value, priv->app_fcoe_flags);
899 case PROP_APP_FCOE_PRIORITY:
900 g_value_set_int (value, priv->app_fcoe_priority);
902 case PROP_APP_FCOE_MODE:
903 g_value_set_string (value, priv->app_fcoe_mode);
905 case PROP_APP_ISCSI_FLAGS:
906 g_value_set_uint (value, priv->app_iscsi_flags);
908 case PROP_APP_ISCSI_PRIORITY:
909 g_value_set_int (value, priv->app_iscsi_priority);
911 case PROP_APP_FIP_FLAGS:
912 g_value_set_uint (value, priv->app_fip_flags);
914 case PROP_APP_FIP_PRIORITY:
915 g_value_set_int (value, priv->app_fip_priority);
918 g_value_set_uint (value, priv->pfc_flags);
921 TAKE_UINT_ARRAY (value, priv->pfc);
923 case PROP_PRIORITY_GROUP_FLAGS:
924 g_value_set_uint (value, priv->priority_group_flags);
926 case PROP_PRIORITY_GROUP_ID:
927 TAKE_UINT_ARRAY (value, priv->priority_group_id);
929 case PROP_PRIORITY_GROUP_BANDWIDTH:
930 TAKE_UINT_ARRAY (value, priv->priority_group_bandwidth);
932 case PROP_PRIORITY_BANDWIDTH:
933 TAKE_UINT_ARRAY (value, priv->priority_bandwidth);
935 case PROP_PRIORITY_STRICT:
936 TAKE_UINT_ARRAY (value, priv->priority_strict);
938 case PROP_PRIORITY_TRAFFIC_CLASS:
939 TAKE_UINT_ARRAY (value, priv->priority_traffic_class);
942 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
948 finalize (GObject *object)
950 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
952 g_free (priv->app_fcoe_mode);
954 G_OBJECT_CLASS (nm_setting_dcb_parent_class)->finalize (object);
958 nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
960 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
961 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
963 g_type_class_add_private (setting_class, sizeof (NMSettingDcbPrivate));
965 /* virtual methods */
966 object_class->set_property = set_property;
967 object_class->get_property = get_property;
968 object_class->finalize = finalize;
969 parent_class->verify = verify;
973 * NMSettingDcb:app-fcoe-flags:
975 * Specifies the #NMSettingDcbFlags for the DCB FCoE application. Flags may
976 * be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
977 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
981 g_object_class_install_property
982 (object_class, PROP_APP_FCOE_FLAGS,
983 g_param_spec_uint (NM_SETTING_DCB_APP_FCOE_FLAGS, "", "",
986 G_PARAM_STATIC_STRINGS));
989 * NMSettingDcb:app-fcoe-priority:
991 * The highest User Priority (0 - 7) which FCoE frames should use, or -1 for
992 * default priority. Only used when the #NMSettingDcb:app-fcoe-flags
993 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
997 g_object_class_install_property
998 (object_class, PROP_APP_FCOE_PRIORITY,
999 g_param_spec_int (NM_SETTING_DCB_APP_FCOE_PRIORITY, "", "",
1003 G_PARAM_STATIC_STRINGS));
1006 * NMSettingDcb:app-fcoe-mode:
1008 * The FCoE controller mode; either %NM_SETTING_DCB_FCOE_MODE_FABRIC
1009 * (default) or %NM_SETTING_DCB_FCOE_MODE_VN2VN.
1013 g_object_class_install_property
1014 (object_class, PROP_APP_FCOE_MODE,
1015 g_param_spec_string (NM_SETTING_DCB_APP_FCOE_MODE, "", "",
1016 NM_SETTING_DCB_FCOE_MODE_FABRIC,
1019 G_PARAM_STATIC_STRINGS));
1022 * NMSettingDcb:app-iscsi-flags:
1024 * Specifies the #NMSettingDcbFlags for the DCB iSCSI application. Flags
1025 * may be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1026 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1030 g_object_class_install_property
1031 (object_class, PROP_APP_ISCSI_FLAGS,
1032 g_param_spec_uint (NM_SETTING_DCB_APP_ISCSI_FLAGS, "", "",
1033 0, DCB_FLAGS_ALL, 0,
1035 G_PARAM_STATIC_STRINGS));
1038 * NMSettingDcb:app-iscsi-priority:
1040 * The highest User Priority (0 - 7) which iSCSI frames should use, or -1
1041 * for default priority. Only used when the #NMSettingDcb:app-iscsi-flags
1042 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
1046 g_object_class_install_property
1047 (object_class, PROP_APP_ISCSI_PRIORITY,
1048 g_param_spec_int (NM_SETTING_DCB_APP_ISCSI_PRIORITY, "", "",
1052 G_PARAM_STATIC_STRINGS));
1055 * NMSettingDcb:app-fip-flags:
1057 * Specifies the #NMSettingDcbFlags for the DCB FIP application. Flags may
1058 * be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1059 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1063 g_object_class_install_property
1064 (object_class, PROP_APP_FIP_FLAGS,
1065 g_param_spec_uint (NM_SETTING_DCB_APP_FIP_FLAGS, "", "",
1066 0, DCB_FLAGS_ALL, 0,
1068 G_PARAM_STATIC_STRINGS));
1071 * NMSettingDcb:app-fip-priority:
1073 * The highest User Priority (0 - 7) which FIP frames should use, or -1 for
1074 * default priority. Only used when the #NMSettingDcb:app-fip-flags
1075 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
1079 g_object_class_install_property
1080 (object_class, PROP_APP_FIP_PRIORITY,
1081 g_param_spec_int (NM_SETTING_DCB_APP_FIP_PRIORITY, "", "",
1085 G_PARAM_STATIC_STRINGS));
1088 * NMSettingDcb:priority-flow-control-flags:
1090 * Specifies the #NMSettingDcbFlags for DCB Priority Flow Control (PFC).
1091 * Flags may be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1092 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1096 g_object_class_install_property
1097 (object_class, PROP_PFC_FLAGS,
1098 g_param_spec_uint (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, "", "",
1099 0, DCB_FLAGS_ALL, 0,
1101 G_PARAM_STATIC_STRINGS));
1104 * NMSettingDcb:priority-flow-control:
1106 * An array of 8 uint values, where the array index corresponds to the User
1107 * Priority (0 - 7) and the value indicates whether or not the corresponding
1108 * priority should transmit priority pause. Allowed values are 0 (do not
1109 * transmit pause) and 1 (transmit pause).
1113 g_object_class_install_property
1114 (object_class, PROP_PFC,
1115 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, "", "",
1116 DBUS_TYPE_G_UINT_ARRAY,
1118 G_PARAM_STATIC_STRINGS));
1121 * NMSettingDcb:priority-group-flags:
1123 * Specifies the #NMSettingDcbFlags for DCB Priority Groups. Flags may be
1124 * any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1125 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1129 g_object_class_install_property
1130 (object_class, PROP_PRIORITY_GROUP_FLAGS,
1131 g_param_spec_uint (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, "", "",
1132 0, DCB_FLAGS_ALL, 0,
1134 G_PARAM_STATIC_STRINGS));
1137 * NMSettingDcb:priority-group-id:
1139 * An array of 8 uint values, where the array index corresponds to the User
1140 * Priority (0 - 7) and the value indicates the Priority Group ID. Allowed
1141 * Priority Group ID values are 0 - 7 or 15 for the unrestricted group.
1145 g_object_class_install_property
1146 (object_class, PROP_PRIORITY_GROUP_ID,
1147 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_GROUP_ID, "", "",
1148 DBUS_TYPE_G_UINT_ARRAY,
1150 G_PARAM_STATIC_STRINGS));
1153 * NMSettingDcb:priority-group-bandwidth:
1155 * An array of 8 uint values, where the array index corresponds to the
1156 * Priority Group ID (0 - 7) and the value indicates the percentage of link
1157 * bandwidth allocated to that group. Allowed values are 0 - 100, and the
1158 * sum of all values must total 100 percent.
1162 g_object_class_install_property
1163 (object_class, PROP_PRIORITY_GROUP_BANDWIDTH,
1164 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, "", "",
1165 DBUS_TYPE_G_UINT_ARRAY,
1167 G_PARAM_STATIC_STRINGS));
1170 * NMSettingDcb:priority-bandwidth:
1172 * An array of 8 uint values, where the array index corresponds to the User
1173 * Priority (0 - 7) and the value indicates the percentage of bandwidth of
1174 * the priority's assigned group that the priority may use. The sum of all
1175 * percentages for priorities which belong to the same group must total 100
1180 g_object_class_install_property
1181 (object_class, PROP_PRIORITY_BANDWIDTH,
1182 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_BANDWIDTH, "", "",
1183 DBUS_TYPE_G_UINT_ARRAY,
1185 G_PARAM_STATIC_STRINGS));
1188 * NMSettingDcb:priority-strict-bandwidth:
1190 * An array of 8 uint values, where the array index corresponds to the User
1191 * Priority (0 - 7) and the value indicates whether or not the priority may
1192 * use all of the bandwidth allocated to its assigned group. Allowed values
1193 * are 0 (the priority may not utilize all bandwidth) or 1 (the priority may
1194 * utilize all bandwidth).
1198 g_object_class_install_property
1199 (object_class, PROP_PRIORITY_STRICT,
1200 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, "", "",
1201 DBUS_TYPE_G_UINT_ARRAY,
1203 G_PARAM_STATIC_STRINGS));
1206 * NMSettingDcb:priority-traffic-class:
1208 * An array of 8 uint values, where the array index corresponds to the User
1209 * Priority (0 - 7) and the value indicates the traffic class (0 - 7) to
1210 * which the priority is mapped.
1214 g_object_class_install_property
1215 (object_class, PROP_PRIORITY_TRAFFIC_CLASS,
1216 _nm_param_spec_specialized (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, "", "",
1217 DBUS_TYPE_G_UINT_ARRAY,
1219 G_PARAM_STATIC_STRINGS));