OSDN Git Service

bonding: add netlink attributes to slave link dev
[uclinux-h8/linux.git] / drivers / net / bonding / bond_netlink.c
index e161c9c..21c6488 100644 (file)
 #include <linux/if_ether.h>
 #include <net/netlink.h>
 #include <net/rtnetlink.h>
+#include <linux/reciprocal_div.h>
 #include "bonding.h"
 
+int bond_get_slave(struct net_device *slave_dev, struct sk_buff *skb)
+{
+       struct slave *slave = bond_slave_get_rtnl(slave_dev);
+       const struct aggregator *agg;
+
+       if (nla_put_u8(skb, IFLA_SLAVE_STATE, bond_slave_state(slave)))
+               goto nla_put_failure;
+
+       if (nla_put_u8(skb, IFLA_SLAVE_MII_STATUS, slave->link))
+               goto nla_put_failure;
+
+       if (nla_put_u32(skb, IFLA_SLAVE_LINK_FAILURE_COUNT,
+                       slave->link_failure_count))
+               goto nla_put_failure;
+
+       if (nla_put(skb, IFLA_SLAVE_PERM_HWADDR,
+                   slave_dev->addr_len, slave->perm_hwaddr))
+               goto nla_put_failure;
+
+       if (nla_put_u16(skb, IFLA_SLAVE_QUEUE_ID, slave->queue_id))
+               goto nla_put_failure;
+
+       if (slave->bond->params.mode == BOND_MODE_8023AD) {
+               agg = SLAVE_AD_INFO(slave).port.aggregator;
+               if (agg)
+                       if (nla_put_u16(skb, IFLA_SLAVE_AD_AGGREGATOR_ID,
+                                       agg->aggregator_identifier))
+                               goto nla_put_failure;
+       }
+
+       return 0;
+
+nla_put_failure:
+       return -EMSGSIZE;
+}
+
 static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [IFLA_BOND_MODE]                = { .type = NLA_U8 },
        [IFLA_BOND_ACTIVE_SLAVE]        = { .type = NLA_U32 },
@@ -37,6 +74,14 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
        [IFLA_BOND_FAIL_OVER_MAC]       = { .type = NLA_U8 },
        [IFLA_BOND_XMIT_HASH_POLICY]    = { .type = NLA_U8 },
        [IFLA_BOND_RESEND_IGMP]         = { .type = NLA_U32 },
+       [IFLA_BOND_NUM_PEER_NOTIF]      = { .type = NLA_U8 },
+       [IFLA_BOND_ALL_SLAVES_ACTIVE]   = { .type = NLA_U8 },
+       [IFLA_BOND_MIN_LINKS]           = { .type = NLA_U32 },
+       [IFLA_BOND_LP_INTERVAL]         = { .type = NLA_U32 },
+       [IFLA_BOND_PACKETS_PER_SLAVE]   = { .type = NLA_U32 },
+       [IFLA_BOND_AD_LACP_RATE]        = { .type = NLA_U8 },
+       [IFLA_BOND_AD_SELECT]           = { .type = NLA_U8 },
+       [IFLA_BOND_AD_INFO]             = { .type = NLA_NESTED },
 };
 
 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -204,6 +249,64 @@ static int bond_changelink(struct net_device *bond_dev,
                if (err)
                        return err;
        }
+       if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
+               int num_peer_notif =
+                       nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
+
+               err = bond_option_num_peer_notif_set(bond, num_peer_notif);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
+               int all_slaves_active =
+                       nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
+
+               err = bond_option_all_slaves_active_set(bond,
+                                                       all_slaves_active);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_MIN_LINKS]) {
+               int min_links =
+                       nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
+
+               err = bond_option_min_links_set(bond, min_links);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_LP_INTERVAL]) {
+               int lp_interval =
+                       nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
+
+               err = bond_option_lp_interval_set(bond, lp_interval);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
+               int packets_per_slave =
+                       nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
+
+               err = bond_option_packets_per_slave_set(bond,
+                                                       packets_per_slave);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_AD_LACP_RATE]) {
+               int lacp_rate =
+                       nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
+
+               err = bond_option_lacp_rate_set(bond, lacp_rate);
+               if (err)
+                       return err;
+       }
+       if (data[IFLA_BOND_AD_SELECT]) {
+               int ad_select =
+                       nla_get_u8(data[IFLA_BOND_AD_SELECT]);
+
+               err = bond_option_ad_select_set(bond, ad_select);
+               if (err)
+                       return err;
+       }
        return 0;
 }
 
@@ -229,6 +332,7 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                nla_total_size(sizeof(u8)) +    /* IFLA_BOND_USE_CARRIER */
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_ARP_INTERVAL */
                                                /* IFLA_BOND_ARP_IP_TARGET */
+               nla_total_size(sizeof(struct nlattr)) +
                nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_ARP_VALIDATE */
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_ARP_ALL_TARGETS */
@@ -237,6 +341,19 @@ static size_t bond_get_size(const struct net_device *bond_dev)
                nla_total_size(sizeof(u8)) +    /* IFLA_BOND_FAIL_OVER_MAC */
                nla_total_size(sizeof(u8)) +    /* IFLA_BOND_XMIT_HASH_POLICY */
                nla_total_size(sizeof(u32)) +   /* IFLA_BOND_RESEND_IGMP */
+               nla_total_size(sizeof(u8)) +    /* IFLA_BOND_NUM_PEER_NOTIF */
+               nla_total_size(sizeof(u8)) +   /* IFLA_BOND_ALL_SLAVES_ACTIVE */
+               nla_total_size(sizeof(u32)) +   /* IFLA_BOND_MIN_LINKS */
+               nla_total_size(sizeof(u32)) +   /* IFLA_BOND_LP_INTERVAL */
+               nla_total_size(sizeof(u32)) +  /* IFLA_BOND_PACKETS_PER_SLAVE */
+               nla_total_size(sizeof(u8)) +    /* IFLA_BOND_AD_LACP_RATE */
+               nla_total_size(sizeof(u8)) +    /* IFLA_BOND_AD_SELECT */
+               nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
+               nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
+               nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
+               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*/
                0;
 }
 
@@ -246,6 +363,7 @@ static int bond_fill_info(struct sk_buff *skb,
        struct bonding *bond = netdev_priv(bond_dev);
        struct net_device *slave_dev = bond_option_active_slave_get(bond);
        struct nlattr *targets;
+       unsigned int packets_per_slave;
        int i, targets_added;
 
        if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
@@ -317,6 +435,69 @@ static int bond_fill_info(struct sk_buff *skb,
                        bond->params.resend_igmp))
                goto nla_put_failure;
 
+       if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
+                      bond->params.num_peer_notif))
+               goto nla_put_failure;
+
+       if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
+                      bond->params.all_slaves_active))
+               goto nla_put_failure;
+
+       if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
+                       bond->params.min_links))
+               goto nla_put_failure;
+
+       if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
+                       bond->params.lp_interval))
+               goto nla_put_failure;
+
+       packets_per_slave = bond->params.packets_per_slave;
+       if (packets_per_slave > 1)
+               packets_per_slave = reciprocal_value(packets_per_slave);
+
+       if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
+                       packets_per_slave))
+               goto nla_put_failure;
+
+       if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
+                      bond->params.lacp_fast))
+               goto nla_put_failure;
+
+       if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
+                      bond->params.ad_select))
+               goto nla_put_failure;
+
+       if (bond->params.mode == BOND_MODE_8023AD) {
+               struct ad_info info;
+
+               if (!bond_3ad_get_active_agg_info(bond, &info)) {
+                       struct nlattr *nest;
+
+                       nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
+                       if (!nest)
+                               goto nla_put_failure;
+
+                       if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
+                                       info.aggregator_id))
+                               goto nla_put_failure;
+                       if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
+                                       info.ports))
+                               goto nla_put_failure;
+                       if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
+                                       info.actor_key))
+                               goto nla_put_failure;
+                       if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
+                                       info.partner_key))
+                               goto nla_put_failure;
+                       if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
+                                   sizeof(info.partner_system),
+                                   &info.partner_system))
+                               goto nla_put_failure;
+
+                       nla_nest_end(skb, nest);
+               }
+       }
+
        return 0;
 
 nla_put_failure: