chiark / gitweb /
networkd: add support for bond transmit hash policy
authorSusant Sahani <susant@redhat.com>
Mon, 21 Jul 2014 13:07:05 +0000 (18:37 +0530)
committerTom Gundersen <teg@jklm.no>
Mon, 21 Jul 2014 18:35:21 +0000 (20:35 +0200)
This patch adds support  the transmit hash policy to use
for slave selection in balance-xor, 802.3ad, and tlb modes

layer2, layer3+4, layer2+3, encap3+4, encap3+4

Added:
1. BondXmitHashPolicy
2. conf param TransmitHashPolicy

Test conf:
[NetDev]
Name=bond1
Kind=bond

[Bond]
Mode=802.3ad
TransmitHashPolicy=layer2+3

test output:
cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2+3 (2)
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

802.3ad info
LACP rate: slow
Min links: 0
Aggregator selection policy (ad_select): stable
bond bond1 has no active aggregator

[tomegun: dropped bond_ prefix from new Bond variable, drop repeated man-page section]

man/systemd.netdev.xml
src/network/networkd-netdev-bond.c
src/network/networkd-netdev-bond.h
src/network/networkd-netdev-gperf.gperf

index 0a2cbab..ba212ec 100644 (file)
                                           </para>
                                         </listitem>
                                 </varlistentry>
+
+                                <varlistentry>
+                                  <term><varname>TransmitHashPolicy=</varname></term>
+                                  <listitem>
+                                    <para>Selects the transmit hash policy to use for slave selection in
+                                    balance-xor, 802.3ad, and tlb modes.
+                                    <literal>layer2</literal>
+                                    <literal>layer3+4</literal>
+                                    <literal>layer2+3</literal>
+                                    <literal>encap2+3</literal>
+                                    <literal>802.3ad</literal>
+                                    <literal>encap3+4</literal>
+                                    </para>
+                                  </listitem>
+                                </varlistentry>
+
                         </variablelist>
         </refsect1>
 
index 562f9eb..c4d1fcd 100644 (file)
@@ -42,6 +42,21 @@ static const char* const bond_mode_table[_NETDEV_BOND_MODE_MAX] = {
 DEFINE_STRING_TABLE_LOOKUP(bond_mode, BondMode);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode, "Failed to parse bond mode");
 
+
+static const char* const bond_xmit_hash_policy_table[_NETDEV_BOND_XMIT_HASH_POLICY_MAX] = {
+        [NETDEV_BOND_XMIT_HASH_POLICY_LAYER2] = "layer2",
+        [NETDEV_BOND_XMIT_HASH_POLICY_LAYER34] = "layer3+4",
+        [NETDEV_BOND_XMIT_HASH_POLICY_LAYER23] = "layer2+3",
+        [NETDEV_BOND_XMIT_HASH_POLICY_ENCAP23] = "encap2+3",
+        [NETDEV_BOND_XMIT_HASH_POLICY_ENCAP34] = "encap3+4",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(bond_xmit_hash_policy, BondXmitHashPolicy);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_xmit_hash_policy,
+                         bond_xmit_hash_policy,
+                         BondXmitHashPolicy,
+                         "Failed to parse bond transmit hash policy")
+
 static uint8_t bond_mode_to_kernel(BondMode mode) {
         switch (mode) {
         case NETDEV_BOND_MODE_BALANCE_RR:
@@ -63,6 +78,23 @@ static uint8_t bond_mode_to_kernel(BondMode mode) {
         }
 }
 
+static uint8_t bond_xmit_hash_policy_to_kernel(BondXmitHashPolicy policy) {
+        switch (policy) {
+        case NETDEV_BOND_XMIT_HASH_POLICY_LAYER2:
+                return BOND_XMIT_POLICY_LAYER2;
+        case NETDEV_BOND_XMIT_HASH_POLICY_LAYER34:
+                return BOND_XMIT_POLICY_LAYER34;
+        case NETDEV_BOND_XMIT_HASH_POLICY_LAYER23:
+                return BOND_XMIT_POLICY_LAYER23;
+        case NETDEV_BOND_XMIT_HASH_POLICY_ENCAP23:
+                return BOND_XMIT_POLICY_ENCAP23;
+        case NETDEV_BOND_XMIT_HASH_POLICY_ENCAP34:
+                return BOND_XMIT_POLICY_ENCAP34;
+        default:
+                return (uint8_t) -1;
+        }
+}
+
 static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
         Bond *b = BOND(netdev);
         int r;
@@ -83,6 +115,17 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m
                 }
         }
 
+        if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) {
+                r = sd_rtnl_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY,
+                                              bond_xmit_hash_policy_to_kernel(b->xmit_hash_policy));
+                if (r < 0) {
+                        log_error_netdev(netdev,
+                                         "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %s",
+                                         strerror(-r));
+                        return r;
+                }
+        }
+
         return 0;
 }
 
@@ -93,6 +136,7 @@ static void bond_init(NetDev *netdev) {
         assert(b);
 
         b->mode = _NETDEV_BOND_MODE_INVALID;
+        b->xmit_hash_policy = _NETDEV_BOND_XMIT_HASH_POLICY_INVALID;
 }
 
 const NetDevVTable bond_vtable = {
index 09731b7..0e9955e 100644 (file)
@@ -37,10 +37,21 @@ typedef enum BondMode {
         _NETDEV_BOND_MODE_INVALID = -1
 } BondMode;
 
+typedef enum BondXmitHashPolicy {
+        NETDEV_BOND_XMIT_HASH_POLICY_LAYER2,
+        NETDEV_BOND_XMIT_HASH_POLICY_LAYER34,
+        NETDEV_BOND_XMIT_HASH_POLICY_LAYER23,
+        NETDEV_BOND_XMIT_HASH_POLICY_ENCAP23,
+        NETDEV_BOND_XMIT_HASH_POLICY_ENCAP34,
+        _NETDEV_BOND_XMIT_HASH_POLICY_MAX,
+        _NETDEV_BOND_XMIT_HASH_POLICY_INVALID = -1
+} BondXmitHashPolicy;
+
 struct Bond {
         NetDev meta;
 
         BondMode mode;
+        BondXmitHashPolicy xmit_hash_policy;
 };
 
 extern const NetDevVTable bond_vtable;
@@ -48,4 +59,8 @@ extern const NetDevVTable bond_vtable;
 const char *bond_mode_to_string(BondMode d) _const_;
 BondMode bond_mode_from_string(const char *d) _pure_;
 
+const char *bond_xmit_hash_policy_to_string(BondXmitHashPolicy d) _const_;
+BondXmitHashPolicy bond_xmit_hash_policy_from_string(const char *d) _pure_;
+
 int config_parse_bond_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_bond_xmit_hash_policy(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
index b46b8db..bafdccf 100644 (file)
@@ -52,3 +52,4 @@ Tap.PacketInfo,          config_parse_bool,                  0,
 Tap.User,                config_parse_string,                0,                             offsetof(TunTap, user_name)
 Tap.Group,               config_parse_string,                0,                             offsetof(TunTap, group_name)
 Bond.Mode,               config_parse_bond_mode,             0,                             offsetof(Bond, mode)
+Bond.TransmitHashPolicy, config_parse_bond_xmit_hash_policy, 0,                             offsetof(Bond, xmit_hash_policy)