bonding: add netlink support for sys prio, actor sys mac, and port key
authorAndy Gospodarek <gospo@cumulusnetworks.com>
Sat, 9 May 2015 07:01:58 +0000 (00:01 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 11 May 2015 14:59:32 +0000 (10:59 -0400)
Adds netlink support for the following bonding options:
* BOND_OPT_AD_ACTOR_SYS_PRIO
* BOND_OPT_AD_ACTOR_SYSTEM
* BOND_OPT_AD_USER_PORT_KEY

When setting the actor system mac address we assume the netlink message
contains a binary mac and not a string representation of a mac.

Signed-off-by: Andy Gospodarek <gospo@cumulusnetworks.com>
[jt: completed the setting side of the netlink attributes]
Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_netlink.c
drivers/net/bonding/bond_options.c
include/uapi/linux/if_link.h

index 7b11243660113484f59d97e2b3ffc9d5b1cb5d98..f7015eb4f8db69714e515100d00b8494fb93512d 100644 (file)
@@ -94,6 +94,10 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [IFLA_BOND_AD_LACP_RATE]        = { .type = NLA_U8 },
        [IFLA_BOND_AD_SELECT]           = { .type = NLA_U8 },
        [IFLA_BOND_AD_INFO]             = { .type = NLA_NESTED },
+       [IFLA_BOND_AD_ACTOR_SYS_PRIO]   = { .type = NLA_U16 },
+       [IFLA_BOND_AD_USER_PORT_KEY]    = { .type = NLA_U16 },
+       [IFLA_BOND_AD_ACTOR_SYSTEM]     = { .type = NLA_BINARY,
+                                           .len  = ETH_ALEN },
 };
 
 static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = {
@@ -379,6 +383,36 @@ static int bond_changelink(struct net_device *bond_dev,
                if (err)
                        return err;
        }
+       if (data[IFLA_BOND_AD_ACTOR_SYS_PRIO]) {
+               int actor_sys_prio =
+                       nla_get_u16(data[IFLA_BOND_AD_ACTOR_SYS_PRIO]);
+
+               bond_opt_initval(&newval, actor_sys_prio);
+               err = __bond_opt_set(bond, BOND_OPT_AD_ACTOR_SYS_PRIO, &newval);
+               if (err)
+                       return err;
+       }
+
+       if (data[IFLA_BOND_AD_USER_PORT_KEY]) {
+               int port_key =
+                       nla_get_u16(data[IFLA_BOND_AD_USER_PORT_KEY]);
+
+               bond_opt_initval(&newval, port_key);
+               err = __bond_opt_set(bond, BOND_OPT_AD_USER_PORT_KEY, &newval);
+               if (err)
+                       return err;
+       }
+
+       if (data[IFLA_BOND_AD_ACTOR_SYSTEM]) {
+               if (nla_len(data[IFLA_BOND_AD_ACTOR_SYSTEM]) != ETH_ALEN)
+                       return -EINVAL;
+
+               bond_opt_initval(&newval,
+                                nla_get_be64(data[IFLA_BOND_AD_ACTOR_SYSTEM]));
+               err = __bond_opt_set(bond, BOND_OPT_AD_ACTOR_SYSTEM, &newval);
+               if (err)
+                       return err;
+       }
        return 0;
 }
 
@@ -426,6 +460,9 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
                nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
                nla_total_size(ETH_ALEN) +    /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
+               nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_ACTOR_SYS_PRIO */
+               nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_USER_PORT_KEY */
+               nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_ACTOR_SYSTEM */
                0;
 }
 
@@ -551,6 +588,19 @@ static int bond_fill_info(struct sk_buff *skb,
        if (BOND_MODE(bond) == BOND_MODE_8023AD) {
                struct ad_info info;
 
+               if (nla_put_u16(skb, IFLA_BOND_AD_ACTOR_SYS_PRIO,
+                               bond->params.ad_actor_sys_prio))
+                       goto nla_put_failure;
+
+               if (nla_put_u16(skb, IFLA_BOND_AD_USER_PORT_KEY,
+                               bond->params.ad_user_port_key))
+                       goto nla_put_failure;
+
+               if (nla_put(skb, IFLA_BOND_AD_ACTOR_SYSTEM,
+                           sizeof(bond->params.ad_actor_system),
+                           &bond->params.ad_actor_system))
+                       goto nla_put_failure;
+
                if (!bond_3ad_get_active_agg_info(bond, &info)) {
                        struct nlattr *nest;
 
index c85da05721e6621aeb26d5e895919091dc26e510..9a32bbd7724e183acad0053ae8044d2fd796540c 100644 (file)
@@ -1394,7 +1394,7 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
                                             const struct bond_opt_value *newval)
 {
-       netdev_info(bond->dev, "Setting ad_actor_sys_prio to (%llu)\n",
+       netdev_info(bond->dev, "Setting ad_actor_sys_prio to %llu\n",
                    newval->value);
 
        bond->params.ad_actor_sys_prio = newval->value;
@@ -1405,24 +1405,36 @@ static int bond_option_ad_actor_system_set(struct bonding *bond,
                                           const struct bond_opt_value *newval)
 {
        u8 macaddr[ETH_ALEN];
+       u8 *mac;
        int i;
 
-       i = sscanf(newval->string, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-                  &macaddr[0], &macaddr[1], &macaddr[2],
-                  &macaddr[3], &macaddr[4], &macaddr[5]);
-       if (i != ETH_ALEN || !is_valid_ether_addr(macaddr)) {
-               netdev_err(bond->dev, "Invalid MAC address.\n");
-               return -EINVAL;
+       if (newval->string) {
+               i = sscanf(newval->string, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+                          &macaddr[0], &macaddr[1], &macaddr[2],
+                          &macaddr[3], &macaddr[4], &macaddr[5]);
+               if (i != ETH_ALEN)
+                       goto err;
+               mac = macaddr;
+       } else {
+               mac = (u8 *)&newval->value;
        }
 
-       ether_addr_copy(bond->params.ad_actor_system, macaddr);
+       if (!is_valid_ether_addr(mac))
+               goto err;
+
+       netdev_info(bond->dev, "Setting ad_actor_system to %pM\n", mac);
+       ether_addr_copy(bond->params.ad_actor_system, mac);
        return 0;
+
+err:
+       netdev_err(bond->dev, "Invalid MAC address.\n");
+       return -EINVAL;
 }
 
 static int bond_option_ad_user_port_key_set(struct bonding *bond,
                                            const struct bond_opt_value *newval)
 {
-       netdev_info(bond->dev, "Setting ad_user_port_key to (%llu)\n",
+       netdev_info(bond->dev, "Setting ad_user_port_key to %llu\n",
                    newval->value);
 
        bond->params.ad_user_port_key = newval->value;
index d9cd19214b9816c036db8f8d26de81c3d53dffb7..6d6e502e1051309ec38f3fe55788ca7cbe3a5425 100644 (file)
@@ -417,6 +417,9 @@ enum {
        IFLA_BOND_AD_LACP_RATE,
        IFLA_BOND_AD_SELECT,
        IFLA_BOND_AD_INFO,
+       IFLA_BOND_AD_ACTOR_SYS_PRIO,
+       IFLA_BOND_AD_USER_PORT_KEY,
+       IFLA_BOND_AD_ACTOR_SYSTEM,
        __IFLA_BOND_MAX,
 };