^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/if_link.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/bonding.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static size_t bond_get_slave_size(const struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) const struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_STATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_MII_STATUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) nla_total_size(sizeof(u32)) + /* IFLA_BOND_SLAVE_LINK_FAILURE_COUNT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) nla_total_size(MAX_ADDR_LEN) + /* IFLA_BOND_SLAVE_PERM_HWADDR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_QUEUE_ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_AGGREGATOR_ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int bond_fill_slave_info(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) const struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct slave *slave = bond_slave_get_rtnl(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (nla_put_u8(skb, IFLA_BOND_SLAVE_MII_STATUS, slave->link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (nla_put_u32(skb, IFLA_BOND_SLAVE_LINK_FAILURE_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) slave->link_failure_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (nla_put(skb, IFLA_BOND_SLAVE_PERM_HWADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) slave_dev->addr_len, slave->perm_hwaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, slave->queue_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const struct aggregator *agg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const struct port *ad_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ad_port = &SLAVE_AD_INFO(slave)->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) agg = SLAVE_AD_INFO(slave)->port.aggregator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (agg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (nla_put_u16(skb, IFLA_BOND_SLAVE_AD_AGGREGATOR_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) agg->aggregator_identifier))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (nla_put_u8(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ad_port->actor_oper_port_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (nla_put_u16(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ad_port->partner_oper.port_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) [IFLA_BOND_MODE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) [IFLA_BOND_MIIMON] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) [IFLA_BOND_PRIMARY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) [IFLA_BOND_AD_ACTOR_SYS_PRIO] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) [IFLA_BOND_AD_USER_PORT_KEY] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) [IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NLA_BINARY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .len = ETH_ALEN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) [IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) [IFLA_BOND_PEER_NOTIF_DELAY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) [IFLA_BOND_SLAVE_QUEUE_ID] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int bond_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (tb[IFLA_ADDRESS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int bond_slave_changelink(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct bond_opt_value newval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (data[IFLA_BOND_SLAVE_QUEUE_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u16 queue_id = nla_get_u16(data[IFLA_BOND_SLAVE_QUEUE_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) char queue_id_str[IFNAMSIZ + 7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* queue_id option setting expects slave_name:queue_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) snprintf(queue_id_str, sizeof(queue_id_str), "%s:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) slave_dev->name, queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) bond_opt_initstr(&newval, queue_id_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) err = __bond_opt_set(bond, BOND_OPT_QUEUE_ID, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct bond_opt_value newval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int miimon = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (data[IFLA_BOND_MODE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int mode = nla_get_u8(data[IFLA_BOND_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) bond_opt_initval(&newval, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) err = __bond_opt_set(bond, BOND_OPT_MODE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (data[IFLA_BOND_ACTIVE_SLAVE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct net_device *slave_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) char *active_slave = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (ifindex != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) slave_dev = __dev_get_by_index(dev_net(bond_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) active_slave = slave_dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) bond_opt_initstr(&newval, active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) err = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (data[IFLA_BOND_MIIMON]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) bond_opt_initval(&newval, miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err = __bond_opt_set(bond, BOND_OPT_MIIMON, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (data[IFLA_BOND_UPDELAY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) bond_opt_initval(&newval, updelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) err = __bond_opt_set(bond, BOND_OPT_UPDELAY, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (data[IFLA_BOND_DOWNDELAY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) bond_opt_initval(&newval, downdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (data[IFLA_BOND_PEER_NOTIF_DELAY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int delay = nla_get_u32(data[IFLA_BOND_PEER_NOTIF_DELAY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) bond_opt_initval(&newval, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) err = __bond_opt_set(bond, BOND_OPT_PEER_NOTIF_DELAY, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (data[IFLA_BOND_USE_CARRIER]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) bond_opt_initval(&newval, use_carrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) err = __bond_opt_set(bond, BOND_OPT_USE_CARRIER, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (data[IFLA_BOND_ARP_INTERVAL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (arp_interval && miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) netdev_err(bond->dev, "ARP monitoring cannot be used with MII monitoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) bond_opt_initval(&newval, arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (data[IFLA_BOND_ARP_IP_TARGET]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int i = 0, rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) bond_option_arp_ip_targets_clear(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) __be32 target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (nla_len(attr) < sizeof(target))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) target = nla_get_be32(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) bond_opt_initval(&newval, (__force u64)target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (i == 0 && bond->params.arp_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (data[IFLA_BOND_ARP_VALIDATE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (arp_validate && miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) netdev_err(bond->dev, "ARP validating cannot be used with MII monitoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bond_opt_initval(&newval, arp_validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int arp_all_targets =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) bond_opt_initval(&newval, arp_all_targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (data[IFLA_BOND_PRIMARY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) char *primary = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) primary = dev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) bond_opt_initstr(&newval, primary);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) err = __bond_opt_set(bond, BOND_OPT_PRIMARY, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (data[IFLA_BOND_PRIMARY_RESELECT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int primary_reselect =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) bond_opt_initval(&newval, primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) err = __bond_opt_set(bond, BOND_OPT_PRIMARY_RESELECT, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (data[IFLA_BOND_FAIL_OVER_MAC]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) int fail_over_mac =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) bond_opt_initval(&newval, fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int xmit_hash_policy =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) bond_opt_initval(&newval, xmit_hash_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (data[IFLA_BOND_RESEND_IGMP]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int resend_igmp =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) bond_opt_initval(&newval, resend_igmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) err = __bond_opt_set(bond, BOND_OPT_RESEND_IGMP, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int num_peer_notif =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) bond_opt_initval(&newval, num_peer_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) err = __bond_opt_set(bond, BOND_OPT_NUM_PEER_NOTIF, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int all_slaves_active =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) bond_opt_initval(&newval, all_slaves_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) err = __bond_opt_set(bond, BOND_OPT_ALL_SLAVES_ACTIVE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (data[IFLA_BOND_MIN_LINKS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int min_links =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) bond_opt_initval(&newval, min_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) err = __bond_opt_set(bond, BOND_OPT_MINLINKS, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (data[IFLA_BOND_LP_INTERVAL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) int lp_interval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) bond_opt_initval(&newval, lp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) err = __bond_opt_set(bond, BOND_OPT_LP_INTERVAL, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int packets_per_slave =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) bond_opt_initval(&newval, packets_per_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (data[IFLA_BOND_AD_LACP_RATE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int lacp_rate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) bond_opt_initval(&newval, lacp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) err = __bond_opt_set(bond, BOND_OPT_LACP_RATE, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (data[IFLA_BOND_AD_SELECT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int ad_select =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) nla_get_u8(data[IFLA_BOND_AD_SELECT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) bond_opt_initval(&newval, ad_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) err = __bond_opt_set(bond, BOND_OPT_AD_SELECT, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (data[IFLA_BOND_AD_ACTOR_SYS_PRIO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int actor_sys_prio =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) nla_get_u16(data[IFLA_BOND_AD_ACTOR_SYS_PRIO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) bond_opt_initval(&newval, actor_sys_prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) err = __bond_opt_set(bond, BOND_OPT_AD_ACTOR_SYS_PRIO, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (data[IFLA_BOND_AD_USER_PORT_KEY]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int port_key =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) nla_get_u16(data[IFLA_BOND_AD_USER_PORT_KEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) bond_opt_initval(&newval, port_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) err = __bond_opt_set(bond, BOND_OPT_AD_USER_PORT_KEY, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (data[IFLA_BOND_AD_ACTOR_SYSTEM]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (nla_len(data[IFLA_BOND_AD_ACTOR_SYSTEM]) != ETH_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) bond_opt_initval(&newval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) nla_get_u64(data[IFLA_BOND_AD_ACTOR_SYSTEM]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) err = __bond_opt_set(bond, BOND_OPT_AD_ACTOR_SYSTEM, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (data[IFLA_BOND_TLB_DYNAMIC_LB]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int dynamic_lb = nla_get_u8(data[IFLA_BOND_TLB_DYNAMIC_LB]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) bond_opt_initval(&newval, dynamic_lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) err = __bond_opt_set(bond, BOND_OPT_TLB_DYNAMIC_LB, &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) err = bond_changelink(bond_dev, tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err = register_netdevice(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) netif_carrier_off(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) bond_work_init_all(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static size_t bond_get_size(const struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* IFLA_BOND_ARP_IP_TARGET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) nla_total_size(sizeof(struct nlattr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_ACTOR_SYS_PRIO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_USER_PORT_KEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_ACTOR_SYSTEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) nla_total_size(sizeof(u8)) + /* IFLA_BOND_TLB_DYNAMIC_LB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) nla_total_size(sizeof(u32)) + /* IFLA_BOND_PEER_NOTIF_DELAY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static int bond_option_active_slave_get_ifindex(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) const struct net_device *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) slave = bond_option_active_slave_get_rcu(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ifindex = slave ? slave->ifindex : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int bond_fill_info(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) const struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) unsigned int packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int ifindex, i, targets_added;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct nlattr *targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct slave *primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (nla_put_u8(skb, IFLA_BOND_MODE, BOND_MODE(bond)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ifindex = bond_option_active_slave_get_ifindex(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (ifindex && nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) bond->params.updelay * bond->params.miimon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) bond->params.downdelay * bond->params.miimon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (nla_put_u32(skb, IFLA_BOND_PEER_NOTIF_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) bond->params.peer_notif_delay * bond->params.miimon))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) targets = nla_nest_start_noflag(skb, IFLA_BOND_ARP_IP_TARGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!targets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) targets_added = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (bond->params.arp_targets[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (nla_put_be32(skb, i, bond->params.arp_targets[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) targets_added = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (targets_added)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) nla_nest_end(skb, targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) nla_nest_cancel(skb, targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) bond->params.arp_all_targets))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) primary = rtnl_dereference(bond->primary_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (primary &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) nla_put_u32(skb, IFLA_BOND_PRIMARY, primary->dev->ifindex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) bond->params.primary_reselect))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) bond->params.fail_over_mac))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) bond->params.xmit_policy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) bond->params.resend_igmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) bond->params.num_peer_notif))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) bond->params.all_slaves_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) bond->params.min_links))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) bond->params.lp_interval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) packets_per_slave = bond->params.packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) packets_per_slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) bond->params.lacp_fast))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) bond->params.ad_select))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (nla_put_u8(skb, IFLA_BOND_TLB_DYNAMIC_LB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) bond->params.tlb_dynamic_lb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct ad_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (nla_put_u16(skb, IFLA_BOND_AD_ACTOR_SYS_PRIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) bond->params.ad_actor_sys_prio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (nla_put_u16(skb, IFLA_BOND_AD_USER_PORT_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) bond->params.ad_user_port_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (nla_put(skb, IFLA_BOND_AD_ACTOR_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) ETH_ALEN, &bond->params.ad_actor_system))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (!bond_3ad_get_active_agg_info(bond, &info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) nest = nla_nest_start_noflag(skb, IFLA_BOND_AD_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) info.aggregator_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) info.ports))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) info.actor_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) info.partner_key))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) sizeof(info.partner_system),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) &info.partner_system))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static size_t bond_get_linkxstats_size(const struct net_device *dev, int attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) case IFLA_STATS_LINK_XSTATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) case IFLA_STATS_LINK_XSTATS_SLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return bond_3ad_stats_size() + nla_total_size(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static int bond_fill_linkxstats(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) int *prividx, int attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct nlattr *nla __maybe_unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct nlattr *nest, *nest2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) switch (attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) case IFLA_STATS_LINK_XSTATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) case IFLA_STATS_LINK_XSTATS_SLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) slave = bond_slave_get_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (!slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) bond = slave->bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) nest = nla_nest_start_noflag(skb, LINK_XSTATS_TYPE_BOND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) struct bond_3ad_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) stats = &SLAVE_AD_INFO(slave)->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) stats = &BOND_AD_INFO(bond).stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) nest2 = nla_nest_start_noflag(skb, BOND_XSTATS_3AD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!nest2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (bond_3ad_stats_fill(skb, stats)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) nla_nest_cancel(skb, nest2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) nla_nest_end(skb, nest2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct rtnl_link_ops bond_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) .kind = "bond",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) .priv_size = sizeof(struct bonding),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .setup = bond_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .maxtype = IFLA_BOND_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .policy = bond_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .validate = bond_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .newlink = bond_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .changelink = bond_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .get_size = bond_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .fill_info = bond_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .get_num_tx_queues = bond_get_num_tx_queues,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) as for TX queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) .fill_linkxstats = bond_fill_linkxstats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) .get_linkxstats_size = bond_get_linkxstats_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) .slave_maxtype = IFLA_BOND_SLAVE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) .slave_policy = bond_slave_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) .slave_changelink = bond_slave_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .get_slave_size = bond_get_slave_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) .fill_slave_info = bond_fill_slave_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int __init bond_netlink_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) return rtnl_link_register(&bond_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) void bond_netlink_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) rtnl_link_unregister(&bond_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) MODULE_ALIAS_RTNL_LINK("bond");