^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) * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/bonding.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* "show" function for the bond_masters attribute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * The class parameter is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static ssize_t bonding_show_bonds(struct class *cls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct class_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct bond_net *bn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) container_of(attr, struct bond_net, class_attr_bonding_masters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) list_for_each_entry(bond, &bn->dev_list, bond_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (res > (PAGE_SIZE - IFNAMSIZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* not enough space for another interface name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if ((PAGE_SIZE - res) > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) res = PAGE_SIZE - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) res += sprintf(buf + res, "++more++ ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) res += sprintf(buf + res, "%s ", bond->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) buf[res-1] = '\n'; /* eat the leftover space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) list_for_each_entry(bond, &bn->dev_list, bond_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* "store" function for the bond_masters attribute. This is what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * creates and deletes entire bonds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * The class parameter is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static ssize_t bonding_store_bonds(struct class *cls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct class_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct bond_net *bn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) container_of(attr, struct bond_net, class_attr_bonding_masters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) char command[IFNAMSIZ + 1] = {0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) char *ifname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int rv, res = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ifname = command + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if ((strlen(command) <= 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) !dev_valid_name(ifname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto err_no_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (command[0] == '+') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pr_info("%s is being created...\n", ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) rv = bond_create(bn->net, ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (rv == -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) pr_info("%s already exists\n", ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pr_info("%s creation failed\n", ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) res = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) } else if (command[0] == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct net_device *bond_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bond_dev = bond_get_by_name(bn, ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (bond_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pr_info("%s is being deleted...\n", ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unregister_netdevice(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pr_err("unable to delete non-existent %s\n", ifname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) res = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) goto err_no_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Always return either count or an error. If you return 0, you'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * get called forever, which is bad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) err_no_cmd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -EPERM;
^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) /* class attribute for bond_masters file. This ends up in /sys/class/net */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static const struct class_attribute class_attr_bonding_masters = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .name = "bonding_masters",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .show = bonding_show_bonds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .store = bonding_store_bonds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Generic "store" method for bonding sysfs option setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static ssize_t bonding_sysfs_store_option(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) const char *buffer, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const struct bond_option *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) char *buffer_clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) opt = bond_opt_get_by_name(attr->attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (WARN_ON(!opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) buffer_clone = kstrndup(buffer, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!buffer_clone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ret = bond_opt_tryset_rtnl(bond, opt->id, buffer_clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) kfree(buffer_clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Show the slaves in the current bond. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static ssize_t bonding_show_slaves(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (res > (PAGE_SIZE - IFNAMSIZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* not enough space for another interface name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if ((PAGE_SIZE - res) > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) res = PAGE_SIZE - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) res += sprintf(buf + res, "++more++ ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) res += sprintf(buf + res, "%s ", slave->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) buf[res-1] = '\n'; /* eat the leftover space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static DEVICE_ATTR(slaves, 0644, bonding_show_slaves,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Show the bonding mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static ssize_t bonding_show_mode(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static DEVICE_ATTR(mode, 0644, bonding_show_mode, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Show the bonding transmit hash method. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static ssize_t bonding_show_xmit_hash(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static DEVICE_ATTR(xmit_hash_policy, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) bonding_show_xmit_hash, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* Show arp_validate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static ssize_t bonding_show_arp_validate(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) bond->params.arp_validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static DEVICE_ATTR(arp_validate, 0644, bonding_show_arp_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* Show arp_all_targets. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static ssize_t bonding_show_arp_all_targets(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) bond->params.arp_all_targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return sprintf(buf, "%s %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) val->string, bond->params.arp_all_targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static DEVICE_ATTR(arp_all_targets, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) bonding_show_arp_all_targets, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Show fail_over_mac. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static ssize_t bonding_show_fail_over_mac(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) bond->params.fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static DEVICE_ATTR(fail_over_mac, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) bonding_show_fail_over_mac, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* Show the arp timer interval. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static ssize_t bonding_show_arp_interval(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return sprintf(buf, "%d\n", bond->params.arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static DEVICE_ATTR(arp_interval, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) bonding_show_arp_interval, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* Show the arp targets. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static ssize_t bonding_show_arp_targets(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int i, res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (bond->params.arp_targets[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) res += sprintf(buf + res, "%pI4 ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) &bond->params.arp_targets[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) buf[res-1] = '\n'; /* eat the leftover space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static DEVICE_ATTR(arp_ip_target, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) bonding_show_arp_targets, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* Show the up and down delays. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static ssize_t bonding_show_downdelay(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static DEVICE_ATTR(downdelay, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) bonding_show_downdelay, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static ssize_t bonding_show_updelay(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static DEVICE_ATTR(updelay, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) bonding_show_updelay, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static ssize_t bonding_show_peer_notif_delay(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) bond->params.peer_notif_delay * bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static DEVICE_ATTR(peer_notif_delay, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) bonding_show_peer_notif_delay, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Show the LACP interval. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static ssize_t bonding_show_lacp(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static DEVICE_ATTR(lacp_rate, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) bonding_show_lacp, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static ssize_t bonding_show_min_links(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return sprintf(buf, "%u\n", bond->params.min_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static DEVICE_ATTR(min_links, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) bonding_show_min_links, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t bonding_show_ad_select(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static DEVICE_ATTR(ad_select, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) bonding_show_ad_select, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /* Show the number of peer notifications to send after a failover event. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static ssize_t bonding_show_num_peer_notif(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return sprintf(buf, "%d\n", bond->params.num_peer_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static DEVICE_ATTR(num_grat_arp, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) bonding_show_num_peer_notif, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static DEVICE_ATTR(num_unsol_na, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) bonding_show_num_peer_notif, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* Show the MII monitor interval. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static ssize_t bonding_show_miimon(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return sprintf(buf, "%d\n", bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static DEVICE_ATTR(miimon, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) bonding_show_miimon, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Show the primary slave. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static ssize_t bonding_show_primary(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct slave *primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) primary = rcu_dereference(bond->primary_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (primary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) count = sprintf(buf, "%s\n", primary->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static DEVICE_ATTR(primary, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) bonding_show_primary, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Show the primary_reselect flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static ssize_t bonding_show_primary_reselect(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) const struct bond_opt_value *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) bond->params.primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return sprintf(buf, "%s %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) val->string, bond->params.primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static DEVICE_ATTR(primary_reselect, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) bonding_show_primary_reselect, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* Show the use_carrier flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static ssize_t bonding_show_carrier(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return sprintf(buf, "%d\n", bond->params.use_carrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static DEVICE_ATTR(use_carrier, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) bonding_show_carrier, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* Show currently active_slave. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static ssize_t bonding_show_active_slave(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct net_device *slave_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) slave_dev = bond_option_active_slave_get_rcu(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) count = sprintf(buf, "%s\n", slave_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static DEVICE_ATTR(active_slave, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) bonding_show_active_slave, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* Show link status of the bond interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static ssize_t bonding_show_mii_status(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) bool active = netif_carrier_ok(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return sprintf(buf, "%s\n", active ? "up" : "down");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static DEVICE_ATTR(mii_status, 0444, bonding_show_mii_status, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* Show current 802.3ad aggregator ID. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static ssize_t bonding_show_ad_aggregator(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) count = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) bond_3ad_get_active_agg_info(bond, &ad_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) ? 0 : ad_info.aggregator_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static DEVICE_ATTR(ad_aggregator, 0444, bonding_show_ad_aggregator, NULL);
^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) /* Show number of active 802.3ad ports. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static ssize_t bonding_show_ad_num_ports(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) count = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) bond_3ad_get_active_agg_info(bond, &ad_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ? 0 : ad_info.ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static DEVICE_ATTR(ad_num_ports, 0444, bonding_show_ad_num_ports, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* Show current 802.3ad actor key. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static ssize_t bonding_show_ad_actor_key(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) count = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) bond_3ad_get_active_agg_info(bond, &ad_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ? 0 : ad_info.actor_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static DEVICE_ATTR(ad_actor_key, 0444, bonding_show_ad_actor_key, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* Show current 802.3ad partner key. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static ssize_t bonding_show_ad_partner_key(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) count = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) bond_3ad_get_active_agg_info(bond, &ad_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ? 0 : ad_info.partner_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static DEVICE_ATTR(ad_partner_key, 0444, bonding_show_ad_partner_key, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /* Show current 802.3ad partner mac. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static ssize_t bonding_show_ad_partner_mac(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) if (!bond_3ad_get_active_agg_info(bond, &ad_info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) count = sprintf(buf, "%pM\n", ad_info.partner_system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static DEVICE_ATTR(ad_partner_mac, 0444, bonding_show_ad_partner_mac, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* Show the queue_ids of the slaves in the current bond. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static ssize_t bonding_show_queue_id(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* not enough space for another interface_name:queue_id pair */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if ((PAGE_SIZE - res) > 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) res = PAGE_SIZE - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) res += sprintf(buf + res, "++more++ ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) res += sprintf(buf + res, "%s:%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) slave->dev->name, slave->queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) buf[res-1] = '\n'; /* eat the leftover space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static DEVICE_ATTR(queue_id, 0644, bonding_show_queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /* Show the all_slaves_active flag. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static ssize_t bonding_show_slaves_active(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return sprintf(buf, "%d\n", bond->params.all_slaves_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) static DEVICE_ATTR(all_slaves_active, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) bonding_show_slaves_active, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* Show the number of IGMP membership reports to send on link failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static ssize_t bonding_show_resend_igmp(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return sprintf(buf, "%d\n", bond->params.resend_igmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) static DEVICE_ATTR(resend_igmp, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) bonding_show_resend_igmp, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static ssize_t bonding_show_lp_interval(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return sprintf(buf, "%d\n", bond->params.lp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static DEVICE_ATTR(lp_interval, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) bonding_show_lp_interval, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) static DEVICE_ATTR(tlb_dynamic_lb, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static ssize_t bonding_show_packets_per_slave(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) unsigned int packets_per_slave = bond->params.packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return sprintf(buf, "%u\n", packets_per_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static DEVICE_ATTR(packets_per_slave, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) bonding_show_packets_per_slave, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static DEVICE_ATTR(ad_actor_sys_prio, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) static ssize_t bonding_show_ad_actor_system(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return sprintf(buf, "%pM\n", bond->params.ad_actor_system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static DEVICE_ATTR(ad_actor_system, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) bonding_show_ad_actor_system, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static ssize_t bonding_show_ad_user_port_key(struct device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct bonding *bond = to_bond(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return sprintf(buf, "%hu\n", bond->params.ad_user_port_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static DEVICE_ATTR(ad_user_port_key, 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) bonding_show_ad_user_port_key, bonding_sysfs_store_option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) static struct attribute *per_bond_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) &dev_attr_slaves.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) &dev_attr_mode.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) &dev_attr_fail_over_mac.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) &dev_attr_arp_validate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) &dev_attr_arp_all_targets.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) &dev_attr_arp_interval.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) &dev_attr_arp_ip_target.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) &dev_attr_downdelay.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) &dev_attr_updelay.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) &dev_attr_peer_notif_delay.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) &dev_attr_lacp_rate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) &dev_attr_ad_select.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) &dev_attr_xmit_hash_policy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) &dev_attr_num_grat_arp.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) &dev_attr_num_unsol_na.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) &dev_attr_miimon.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) &dev_attr_primary.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) &dev_attr_primary_reselect.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) &dev_attr_use_carrier.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) &dev_attr_active_slave.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) &dev_attr_mii_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) &dev_attr_ad_aggregator.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) &dev_attr_ad_num_ports.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) &dev_attr_ad_actor_key.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) &dev_attr_ad_partner_key.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) &dev_attr_ad_partner_mac.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) &dev_attr_queue_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) &dev_attr_all_slaves_active.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) &dev_attr_resend_igmp.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) &dev_attr_min_links.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) &dev_attr_lp_interval.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) &dev_attr_packets_per_slave.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) &dev_attr_tlb_dynamic_lb.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) &dev_attr_ad_actor_sys_prio.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) &dev_attr_ad_actor_system.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) &dev_attr_ad_user_port_key.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) static const struct attribute_group bonding_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) .name = "bonding",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) .attrs = per_bond_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* Initialize sysfs. This sets up the bonding_masters file in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * /sys/class/net.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int bond_create_sysfs(struct bond_net *bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) bn->class_attr_bonding_masters = class_attr_bonding_masters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) bn->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /* Permit multiple loads of the module by ignoring failures to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * create the bonding_masters sysfs file. Bonding devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * created by second or subsequent loads of the module will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * not be listed in, or controllable by, bonding_masters, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * will have the usual "bonding" sysfs directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * This is done to preserve backwards compatibility for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * initscripts/sysconfig, which load bonding multiple times to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * configure multiple bonding devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (ret == -EEXIST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Is someone being kinky and naming a device bonding_master? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (__dev_get_by_name(bn->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) class_attr_bonding_masters.attr.name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) pr_err("network device named %s already exists in sysfs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) class_attr_bonding_masters.attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) /* Remove /sys/class/net/bonding_masters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) void bond_destroy_sysfs(struct bond_net *bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /* Initialize sysfs for each bond. This sets up and registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * the 'bondctl' directory for each individual bond under /sys/class/net.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) void bond_prepare_sysfs_group(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) bond->dev->sysfs_groups[0] = &bonding_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)