bond: add some missing options
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 15 Mar 2016 16:37:06 +0000 (17:37 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Tue, 29 Mar 2016 16:10:05 +0000 (18:10 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1299103

libnm-core/nm-core-internal.h
libnm-core/nm-setting-bond.c
libnm-core/nm-setting-bond.h
src/devices/nm-device-bond.c

index 60ee6d4..082ebc9 100644 (file)
@@ -288,6 +288,7 @@ typedef enum {
        NM_BOND_OPTION_TYPE_STRING,
        NM_BOND_OPTION_TYPE_BOTH,
        NM_BOND_OPTION_TYPE_IP,
+       NM_BOND_OPTION_TYPE_MAC,
        NM_BOND_OPTION_TYPE_IFNAME,
 } NMBondOptionType;
 
index f4b5057..3cb2174 100644 (file)
@@ -90,6 +90,18 @@ static const BondDefault defaults[] = {
        { NM_SETTING_BOND_OPTION_RESEND_IGMP,      "1",          NM_BOND_OPTION_TYPE_INT, 0, 255 },
        { NM_SETTING_BOND_OPTION_LACP_RATE,        "slow",       NM_BOND_OPTION_TYPE_BOTH, 0, 1,
          { "slow", "fast", NULL } },
+       { NM_SETTING_BOND_OPTION_ACTIVE_SLAVE,     "",           NM_BOND_OPTION_TYPE_IFNAME },
+       { NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO,"65535",      NM_BOND_OPTION_TYPE_INT, 1, 65535 },
+       { NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM,  "",           NM_BOND_OPTION_TYPE_MAC },
+       { NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY, "0",          NM_BOND_OPTION_TYPE_INT, 0, 1023},
+       { NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE,"0",          NM_BOND_OPTION_TYPE_INT, 0, 1},
+       { NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS,  "any",        NM_BOND_OPTION_TYPE_BOTH, 0, 1, {"any", "all"}},
+       { NM_SETTING_BOND_OPTION_MIN_LINKS,        "0",          NM_BOND_OPTION_TYPE_INT, 0, G_MAXINT },
+       { NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,     "1",          NM_BOND_OPTION_TYPE_INT, 0, 255 },
+       { NM_SETTING_BOND_OPTION_NUM_UNSOL_NA,     "1",          NM_BOND_OPTION_TYPE_INT, 0, 255 },
+       { NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE,"1",          NM_BOND_OPTION_TYPE_INT, 0, 65535 },
+       { NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB,   "1",          NM_BOND_OPTION_TYPE_INT, 0, 1 },
+       { NM_SETTING_BOND_OPTION_LP_INTERVAL,      "1",          NM_BOND_OPTION_TYPE_INT, 1, G_MAXINT },
 };
 
 /**
@@ -270,6 +282,8 @@ nm_setting_bond_validate_option (const char *name,
                                        || validate_list (name, value, &defaults[i]));
                        case NM_BOND_OPTION_TYPE_IP:
                                return validate_ip (name, value);
+                       case NM_BOND_OPTION_TYPE_MAC:
+                               return nm_utils_hwaddr_valid (value, ETH_ALEN);
                        case NM_BOND_OPTION_TYPE_IFNAME:
                                return validate_ifname (name, value);
                        }
@@ -456,6 +470,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
        GHashTableIter iter;
        const char *key, *value;
        int mode, miimon = 0, arp_interval = 0;
+       int num_grat_arp = -1, num_unsol_na = -1;
        const char *mode_orig, *mode_new;
        const char *arp_ip_target = NULL;
        const char *lacp_rate;
@@ -480,6 +495,12 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
        value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
        if (value)
                arp_interval = atoi (value);
+       value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP);
+       if (value)
+               num_grat_arp = atoi (value);
+       value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
+       if (value)
+               num_unsol_na = atoi (value);
 
        /* Can only set one of miimon and arp_interval */
        if (miimon > 0 && arp_interval > 0) {
@@ -658,6 +679,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
                return FALSE;
        }
 
+       if (   (num_grat_arp != -1 && num_unsol_na != -1)
+           && (num_grat_arp != num_unsol_na)) {
+               g_set_error (error,
+                            NM_CONNECTION_ERROR,
+                            NM_CONNECTION_ERROR_INVALID_PROPERTY,
+                            _("'%s' and '%s' cannot have different values"),
+                            NM_SETTING_BOND_OPTION_NUM_GRAT_ARP,
+                            NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
+               g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
+               return FALSE;
+       }
+
        if (!_nm_connection_verify_required_interface_name (connection, error))
                return FALSE;
 
index 055801a..98fcc6d 100644 (file)
@@ -42,21 +42,33 @@ G_BEGIN_DECLS
 #define NM_SETTING_BOND_OPTIONS "options"
 
 /* Valid options for the 'options' property */
-#define NM_SETTING_BOND_OPTION_MODE             "mode"
-#define NM_SETTING_BOND_OPTION_MIIMON           "miimon"
-#define NM_SETTING_BOND_OPTION_DOWNDELAY        "downdelay"
-#define NM_SETTING_BOND_OPTION_UPDELAY          "updelay"
-#define NM_SETTING_BOND_OPTION_ARP_INTERVAL     "arp_interval"
-#define NM_SETTING_BOND_OPTION_ARP_IP_TARGET    "arp_ip_target"
-#define NM_SETTING_BOND_OPTION_ARP_VALIDATE     "arp_validate"
-#define NM_SETTING_BOND_OPTION_PRIMARY          "primary"
-#define NM_SETTING_BOND_OPTION_PRIMARY_RESELECT "primary_reselect"
-#define NM_SETTING_BOND_OPTION_FAIL_OVER_MAC    "fail_over_mac"
-#define NM_SETTING_BOND_OPTION_USE_CARRIER      "use_carrier"
-#define NM_SETTING_BOND_OPTION_AD_SELECT        "ad_select"
-#define NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY "xmit_hash_policy"
-#define NM_SETTING_BOND_OPTION_RESEND_IGMP      "resend_igmp"
-#define NM_SETTING_BOND_OPTION_LACP_RATE        "lacp_rate"
+#define NM_SETTING_BOND_OPTION_MODE              "mode"
+#define NM_SETTING_BOND_OPTION_MIIMON            "miimon"
+#define NM_SETTING_BOND_OPTION_DOWNDELAY         "downdelay"
+#define NM_SETTING_BOND_OPTION_UPDELAY           "updelay"
+#define NM_SETTING_BOND_OPTION_ARP_INTERVAL      "arp_interval"
+#define NM_SETTING_BOND_OPTION_ARP_IP_TARGET     "arp_ip_target"
+#define NM_SETTING_BOND_OPTION_ARP_VALIDATE      "arp_validate"
+#define NM_SETTING_BOND_OPTION_PRIMARY           "primary"
+#define NM_SETTING_BOND_OPTION_PRIMARY_RESELECT  "primary_reselect"
+#define NM_SETTING_BOND_OPTION_FAIL_OVER_MAC     "fail_over_mac"
+#define NM_SETTING_BOND_OPTION_USE_CARRIER       "use_carrier"
+#define NM_SETTING_BOND_OPTION_AD_SELECT         "ad_select"
+#define NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY  "xmit_hash_policy"
+#define NM_SETTING_BOND_OPTION_RESEND_IGMP       "resend_igmp"
+#define NM_SETTING_BOND_OPTION_LACP_RATE         "lacp_rate"
+#define NM_SETTING_BOND_OPTION_ACTIVE_SLAVE      "active_slave"
+#define NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO "ad_actor_sys_prio"
+#define NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM   "ad_actor_system"
+#define NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY  "ad_user_port_key"
+#define NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE "all_slaves_active"
+#define NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS   "arp_all_targets"
+#define NM_SETTING_BOND_OPTION_MIN_LINKS         "min_links"
+#define NM_SETTING_BOND_OPTION_NUM_GRAT_ARP      "num_grat_arp"
+#define NM_SETTING_BOND_OPTION_NUM_UNSOL_NA      "num_unsol_na"
+#define NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE "packets_per_slave"
+#define NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB    "tlb_dynamic_lb"
+#define NM_SETTING_BOND_OPTION_LP_INTERVAL       "lp_interval"
 
 struct _NMSettingBond {
        NMSetting parent;
index d1da044..6ae29b9 100644 (file)
@@ -292,7 +292,7 @@ apply_bonding_config (NMDevice *device)
        set_bond_attr (device, "mode", mode);
 
        /* arp_interval not compatible with ALB, TLB */
-       if (g_strcmp0 (mode, "balance-alb") == 0 || g_strcmp0 (mode, "balance-tlb") == 0)
+       if (NM_IN_STRSET (mode, "balance-alb", "balance-tlb"))
                set_arp_interval = FALSE;
 
        if (set_arp_interval) {
@@ -306,18 +306,17 @@ apply_bonding_config (NMDevice *device)
        value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_ARP_VALIDATE);
        /* arp_validate > 0 only valid in active-backup mode */
        if (   value
-           && g_strcmp0 (value, "0") != 0
-           && g_strcmp0 (value, "none") != 0
-           && g_strcmp0 (mode, "active-backup") == 0)
+           && !nm_streq (value, "0")
+           && !nm_streq (value, "none")
+           && nm_streq (mode, "active-backup"))
                set_bond_attr (device, "arp_validate", value);
        else
                set_bond_attr (device, "arp_validate", "0");
 
-       if (   g_strcmp0 (mode, "active-backup") == 0
-           || g_strcmp0 (mode, "balance-alb") == 0
-           || g_strcmp0 (mode, "balance-tlb") == 0) {
+       if (NM_IN_STRSET (mode, "active-backup", "balance-alb", "balance-tlb")) {
                value = nm_setting_bond_get_option_by_name (s_bond, NM_SETTING_BOND_OPTION_PRIMARY);
                set_bond_attr (device, "primary", value ? value : "");
+               set_simple_option (device, "lp_internal", s_bond, NM_SETTING_BOND_OPTION_LP_INTERVAL);
        }
 
        /* Clear ARP targets */
@@ -335,15 +334,31 @@ apply_bonding_config (NMDevice *device)
        set_simple_option (device, "ad_select", s_bond, NM_SETTING_BOND_OPTION_AD_SELECT);
        set_simple_option (device, "xmit_hash_policy", s_bond, NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY);
        set_simple_option (device, "resend_igmp", s_bond, NM_SETTING_BOND_OPTION_RESEND_IGMP);
+       set_simple_option (device, "active_slave", s_bond, NM_SETTING_BOND_OPTION_ACTIVE_SLAVE);
+       set_simple_option (device, "all_slaves_active", s_bond, NM_SETTING_BOND_OPTION_ALL_SLAVES_ACTIVE);
+       set_simple_option (device, "num_grat_arp", s_bond, NM_SETTING_BOND_OPTION_NUM_GRAT_ARP);
+       set_simple_option (device, "num_unsol_na", s_bond, NM_SETTING_BOND_OPTION_NUM_UNSOL_NA);
 
-       if (   g_strcmp0 (mode, "4") == 0
-           || g_strcmp0 (mode, "802.3ad") == 0)
+       if (nm_streq (mode, "802.3ad")) {
                set_simple_option (device, "lacp_rate", s_bond, NM_SETTING_BOND_OPTION_LACP_RATE);
+               set_simple_option (device, "ad_actor_sys_prio", s_bond, NM_SETTING_BOND_OPTION_AD_ACTOR_SYS_PRIO);
+               set_simple_option (device, "ad_actor_system", s_bond, NM_SETTING_BOND_OPTION_AD_ACTOR_SYSTEM);
+               set_simple_option (device, "ad_user_port_key", s_bond, NM_SETTING_BOND_OPTION_AD_USER_PORT_KEY);
+               set_simple_option (device, "min_links", s_bond, NM_SETTING_BOND_OPTION_MIN_LINKS);
+       }
+
+       if (nm_streq (mode, "active-backup"))
+               set_simple_option (device, "arp_all_targets", s_bond, NM_SETTING_BOND_OPTION_ARP_ALL_TARGETS);
+
+       if (nm_streq (mode, "balance-rr"))
+               set_simple_option (device, "packets_per_slave", s_bond, NM_SETTING_BOND_OPTION_PACKETS_PER_SLAVE);
+
+       if (nm_streq (mode, "balance-tlb"))
+               set_simple_option (device, "tlb_dynamic_lb", s_bond, NM_SETTING_BOND_OPTION_TLB_DYNAMIC_LB);
 
        return NM_ACT_STAGE_RETURN_SUCCESS;
 }
 
-
 static NMActStageReturn
 act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
 {