| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
#include <linux/proc_fs.h> |
| 3 |
#include <linux/ethtool.h> |
| 4 |
#include <linux/export.h> |
| 5 |
#include <net/net_namespace.h> |
| 6 |
#include <net/netns/generic.h> |
| 7 |
#include <net/bonding.h> |
| 8 |
|
| 9 |
#include "bonding_priv.h" |
| 10 |
|
| 11 |
static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) |
| 12 |
__acquires(RCU) |
| 13 |
{ |
| 14 |
struct bonding *bond = pde_data(file_inode(seq->file)); |
| 15 |
struct list_head *iter; |
| 16 |
struct slave *slave; |
| 17 |
loff_t off = 0; |
| 18 |
|
| 19 |
rcu_read_lock(); |
| 20 |
|
| 21 |
if (*pos == 0) |
| 22 |
return SEQ_START_TOKEN; |
| 23 |
|
| 24 |
bond_for_each_slave_rcu(bond, slave, iter) |
| 25 |
if (++off == *pos) |
| 26 |
return slave; |
| 27 |
|
| 28 |
return NULL; |
| 29 |
} |
| 30 |
|
| 31 |
static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 32 |
{ |
| 33 |
struct bonding *bond = pde_data(file_inode(seq->file)); |
| 34 |
struct list_head *iter; |
| 35 |
struct slave *slave; |
| 36 |
bool found = false; |
| 37 |
|
| 38 |
++*pos; |
| 39 |
if (v == SEQ_START_TOKEN) |
| 40 |
return bond_first_slave_rcu(bond); |
| 41 |
|
| 42 |
bond_for_each_slave_rcu(bond, slave, iter) { |
| 43 |
if (found) |
| 44 |
return slave; |
| 45 |
if (slave == v) |
| 46 |
found = true; |
| 47 |
} |
| 48 |
|
| 49 |
return NULL; |
| 50 |
} |
| 51 |
|
| 52 |
static void bond_info_seq_stop(struct seq_file *seq, void *v) |
| 53 |
__releases(RCU) |
| 54 |
{ |
| 55 |
rcu_read_unlock(); |
| 56 |
} |
| 57 |
|
| 58 |
static void bond_info_show_master(struct seq_file *seq) |
| 59 |
{ |
| 60 |
struct bonding *bond = pde_data(file_inode(seq->file)); |
| 61 |
const struct bond_opt_value *optval; |
| 62 |
struct slave *curr, *primary; |
| 63 |
int i; |
| 64 |
|
| 65 |
curr = rcu_dereference(bond->curr_active_slave); |
| 66 |
|
| 67 |
seq_printf(seq, "Bonding Mode: %s", |
| 68 |
bond_mode_name(BOND_MODE(bond))); |
| 69 |
|
| 70 |
if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && |
| 71 |
bond->params.fail_over_mac) { |
| 72 |
optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, |
| 73 |
bond->params.fail_over_mac); |
| 74 |
seq_printf(seq, " (fail_over_mac %s)", optval->string); |
| 75 |
} |
| 76 |
|
| 77 |
seq_printf(seq, "\n"); |
| 78 |
|
| 79 |
if (bond_mode_uses_xmit_hash(bond)) { |
| 80 |
optval = bond_opt_get_val(BOND_OPT_XMIT_HASH, |
| 81 |
bond->params.xmit_policy); |
| 82 |
seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", |
| 83 |
optval->string, bond->params.xmit_policy); |
| 84 |
} |
| 85 |
|
| 86 |
if (bond_uses_primary(bond)) { |
| 87 |
primary = rcu_dereference(bond->primary_slave); |
| 88 |
seq_printf(seq, "Primary Slave: %s", |
| 89 |
primary ? primary->dev->name : "None"); |
| 90 |
if (primary) { |
| 91 |
optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, |
| 92 |
bond->params.primary_reselect); |
| 93 |
seq_printf(seq, " (primary_reselect %s)", |
| 94 |
optval->string); |
| 95 |
} |
| 96 |
|
| 97 |
seq_printf(seq, "\nCurrently Active Slave: %s\n", |
| 98 |
(curr) ? curr->dev->name : "None"); |
| 99 |
} |
| 100 |
|
| 101 |
seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ? |
| 102 |
"up" : "down"); |
| 103 |
seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); |
| 104 |
seq_printf(seq, "Up Delay (ms): %d\n", |
| 105 |
bond->params.updelay * bond->params.miimon); |
| 106 |
seq_printf(seq, "Down Delay (ms): %d\n", |
| 107 |
bond->params.downdelay * bond->params.miimon); |
| 108 |
seq_printf(seq, "Peer Notification Delay (ms): %d\n", |
| 109 |
bond->params.peer_notif_delay * bond->params.miimon); |
| 110 |
|
| 111 |
|
| 112 |
/* ARP information */ |
| 113 |
if (bond->params.arp_interval > 0) { |
| 114 |
int printed = 0; |
| 115 |
|
| 116 |
seq_printf(seq, "ARP Polling Interval (ms): %d\n", |
| 117 |
bond->params.arp_interval); |
| 118 |
seq_printf(seq, "ARP Missed Max: %u\n", |
| 119 |
bond->params.missed_max); |
| 120 |
|
| 121 |
seq_printf(seq, "ARP IP target/s (n.n.n.n form):"); |
| 122 |
|
| 123 |
for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 124 |
if (!bond->params.arp_targets[i]) |
| 125 |
break; |
| 126 |
if (printed) |
| 127 |
seq_printf(seq, ","); |
| 128 |
seq_printf(seq, " %pI4", &bond->params.arp_targets[i]); |
| 129 |
printed = 1; |
| 130 |
} |
| 131 |
seq_printf(seq, "\n"); |
| 132 |
|
| 133 |
#if IS_ENABLED(CONFIG_IPV6) |
| 134 |
printed = 0; |
| 135 |
seq_printf(seq, "NS IPv6 target/s (xx::xx form):"); |
| 136 |
|
| 137 |
for (i = 0; (i < BOND_MAX_NS_TARGETS); i++) { |
| 138 |
if (ipv6_addr_any(&bond->params.ns_targets[i])) |
| 139 |
break; |
| 140 |
if (printed) |
| 141 |
seq_printf(seq, ","); |
| 142 |
seq_printf(seq, " %pI6c", &bond->params.ns_targets[i]); |
| 143 |
printed = 1; |
| 144 |
} |
| 145 |
seq_printf(seq, "\n"); |
| 146 |
#endif |
| 147 |
} |
| 148 |
|
| 149 |
if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
| 150 |
struct ad_info ad_info; |
| 151 |
|
| 152 |
seq_puts(seq, "\n802.3ad info\n"); |
| 153 |
seq_printf(seq, "LACP active: %s\n", |
| 154 |
(bond->params.lacp_active) ? "on" : "off"); |
| 155 |
seq_printf(seq, "LACP rate: %s\n", |
| 156 |
(bond->params.lacp_fast) ? "fast" : "slow"); |
| 157 |
seq_printf(seq, "Min links: %d\n", bond->params.min_links); |
| 158 |
optval = bond_opt_get_val(BOND_OPT_AD_SELECT, |
| 159 |
bond->params.ad_select); |
| 160 |
seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", |
| 161 |
optval->string); |
| 162 |
if (capable(CAP_NET_ADMIN)) { |
| 163 |
seq_printf(seq, "System priority: %d\n", |
| 164 |
BOND_AD_INFO(bond).system.sys_priority); |
| 165 |
seq_printf(seq, "System MAC address: %pM\n", |
| 166 |
&BOND_AD_INFO(bond).system.sys_mac_addr); |
| 167 |
|
| 168 |
if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
| 169 |
seq_printf(seq, |
| 170 |
"bond %s has no active aggregator\n", |
| 171 |
bond->dev->name); |
| 172 |
} else { |
| 173 |
seq_printf(seq, "Active Aggregator Info:\n"); |
| 174 |
|
| 175 |
seq_printf(seq, "\tAggregator ID: %d\n", |
| 176 |
ad_info.aggregator_id); |
| 177 |
seq_printf(seq, "\tNumber of ports: %d\n", |
| 178 |
ad_info.ports); |
| 179 |
seq_printf(seq, "\tActor Key: %d\n", |
| 180 |
ad_info.actor_key); |
| 181 |
seq_printf(seq, "\tPartner Key: %d\n", |
| 182 |
ad_info.partner_key); |
| 183 |
seq_printf(seq, "\tPartner Mac Address: %pM\n", |
| 184 |
ad_info.partner_system); |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
/* Note: runs under rcu_read_lock() */ |
| 191 |
static void bond_info_show_slave(struct seq_file *seq, |
| 192 |
const struct slave *slave) |
| 193 |
{ |
| 194 |
struct bonding *bond = pde_data(file_inode(seq->file)); |
| 195 |
|
| 196 |
seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); |
| 197 |
seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link)); |
| 198 |
if (slave->speed == SPEED_UNKNOWN) |
| 199 |
seq_printf(seq, "Speed: %s\n", "Unknown"); |
| 200 |
else |
| 201 |
seq_printf(seq, "Speed: %d Mbps\n", slave->speed); |
| 202 |
|
| 203 |
if (slave->duplex == DUPLEX_UNKNOWN) |
| 204 |
seq_printf(seq, "Duplex: %s\n", "Unknown"); |
| 205 |
else |
| 206 |
seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); |
| 207 |
|
| 208 |
seq_printf(seq, "Link Failure Count: %u\n", |
| 209 |
slave->link_failure_count); |
| 210 |
|
| 211 |
seq_printf(seq, "Permanent HW addr: %*phC\n", |
| 212 |
slave->dev->addr_len, slave->perm_hwaddr); |
| 213 |
seq_printf(seq, "Slave queue ID: %d\n", READ_ONCE(slave->queue_id)); |
| 214 |
|
| 215 |
if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
| 216 |
const struct port *port = &SLAVE_AD_INFO(slave)->port; |
| 217 |
const struct aggregator *agg = rcu_dereference(port->aggregator); |
| 218 |
|
| 219 |
if (agg) { |
| 220 |
seq_printf(seq, "Aggregator ID: %d\n", |
| 221 |
agg->aggregator_identifier); |
| 222 |
seq_printf(seq, "Actor Churn State: %s\n", |
| 223 |
bond_3ad_churn_desc(port->sm_churn_actor_state)); |
| 224 |
seq_printf(seq, "Partner Churn State: %s\n", |
| 225 |
bond_3ad_churn_desc(port->sm_churn_partner_state)); |
| 226 |
seq_printf(seq, "Actor Churned Count: %d\n", |
| 227 |
port->churn_actor_count); |
| 228 |
seq_printf(seq, "Partner Churned Count: %d\n", |
| 229 |
port->churn_partner_count); |
| 230 |
|
| 231 |
if (capable(CAP_NET_ADMIN)) { |
| 232 |
seq_puts(seq, "details actor lacp pdu:\n"); |
| 233 |
seq_printf(seq, " system priority: %d\n", |
| 234 |
port->actor_system_priority); |
| 235 |
seq_printf(seq, " system mac address: %pM\n", |
| 236 |
&port->actor_system); |
| 237 |
seq_printf(seq, " port key: %d\n", |
| 238 |
port->actor_oper_port_key); |
| 239 |
seq_printf(seq, " port priority: %d\n", |
| 240 |
port->actor_port_priority); |
| 241 |
seq_printf(seq, " port number: %d\n", |
| 242 |
port->actor_port_number); |
| 243 |
seq_printf(seq, " port state: %d\n", |
| 244 |
port->actor_oper_port_state); |
| 245 |
|
| 246 |
seq_puts(seq, "details partner lacp pdu:\n"); |
| 247 |
seq_printf(seq, " system priority: %d\n", |
| 248 |
port->partner_oper.system_priority); |
| 249 |
seq_printf(seq, " system mac address: %pM\n", |
| 250 |
&port->partner_oper.system); |
| 251 |
seq_printf(seq, " oper key: %d\n", |
| 252 |
port->partner_oper.key); |
| 253 |
seq_printf(seq, " port priority: %d\n", |
| 254 |
port->partner_oper.port_priority); |
| 255 |
seq_printf(seq, " port number: %d\n", |
| 256 |
port->partner_oper.port_number); |
| 257 |
seq_printf(seq, " port state: %d\n", |
| 258 |
port->partner_oper.port_state); |
| 259 |
} |
| 260 |
} else { |
| 261 |
seq_puts(seq, "Aggregator ID: N/A\n"); |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
static int bond_info_seq_show(struct seq_file *seq, void *v) |
| 267 |
{ |
| 268 |
if (v == SEQ_START_TOKEN) { |
| 269 |
seq_printf(seq, "%s\n", bond_version); |
| 270 |
bond_info_show_master(seq); |
| 271 |
} else |
| 272 |
bond_info_show_slave(seq, v); |
| 273 |
|
| 274 |
return 0; |
| 275 |
} |
| 276 |
|
| 277 |
static const struct seq_operations bond_info_seq_ops = { |
| 278 |
.start = bond_info_seq_start, |
| 279 |
.next = bond_info_seq_next, |
| 280 |
.stop = bond_info_seq_stop, |
| 281 |
.show = bond_info_seq_show, |
| 282 |
}; |
| 283 |
|
| 284 |
void bond_create_proc_entry(struct bonding *bond) |
| 285 |
{ |
| 286 |
struct net_device *bond_dev = bond->dev; |
| 287 |
struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
| 288 |
|
| 289 |
if (bn->proc_dir) { |
| 290 |
bond->proc_entry = proc_create_seq_data(bond_dev->name, 0444, |
| 291 |
bn->proc_dir, &bond_info_seq_ops, bond); |
| 292 |
if (bond->proc_entry == NULL) |
| 293 |
netdev_warn(bond_dev, "Cannot create /proc/net/%s/%s\n", |
| 294 |
DRV_NAME, bond_dev->name); |
| 295 |
else |
| 296 |
memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
void bond_remove_proc_entry(struct bonding *bond) |
| 301 |
{ |
| 302 |
struct net_device *bond_dev = bond->dev; |
| 303 |
struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
| 304 |
|
| 305 |
if (bn->proc_dir && bond->proc_entry) { |
| 306 |
remove_proc_entry(bond->proc_file_name, bn->proc_dir); |
| 307 |
memset(bond->proc_file_name, 0, IFNAMSIZ); |
| 308 |
bond->proc_entry = NULL; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
/* Create the bonding directory under /proc/net, if doesn't exist yet. |
| 313 |
* Caller must hold rtnl_lock. |
| 314 |
*/ |
| 315 |
void __net_init bond_create_proc_dir(struct bond_net *bn) |
| 316 |
{ |
| 317 |
if (!bn->proc_dir) { |
| 318 |
bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); |
| 319 |
if (!bn->proc_dir) |
| 320 |
pr_warn("Warning: Cannot create /proc/net/%s\n", |
| 321 |
DRV_NAME); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
/* Destroy the bonding directory under /proc/net, if empty. |
| 326 |
*/ |
| 327 |
void __net_exit bond_destroy_proc_dir(struct bond_net *bn) |
| 328 |
{ |
| 329 |
if (bn->proc_dir) { |
| 330 |
remove_proc_entry(DRV_NAME, bn->net->proc_net); |
| 331 |
bn->proc_dir = NULL; |
| 332 |
} |
| 333 |
} |