Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 1 | #include <linux/proc_fs.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 2 | #include <linux/export.h> |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 3 | #include <net/net_namespace.h> |
| 4 | #include <net/netns/generic.h> |
| 5 | #include "bonding.h" |
| 6 | |
| 7 | |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 8 | static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) |
| 9 | __acquires(RCU) |
| 10 | __acquires(&bond->lock) |
| 11 | { |
| 12 | struct bonding *bond = seq->private; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 13 | struct list_head *iter; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 14 | struct slave *slave; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 15 | loff_t off = 0; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 16 | |
| 17 | /* make sure the bond won't be taken away */ |
| 18 | rcu_read_lock(); |
| 19 | read_lock(&bond->lock); |
| 20 | |
| 21 | if (*pos == 0) |
| 22 | return SEQ_START_TOKEN; |
| 23 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 24 | bond_for_each_slave(bond, slave, iter) |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 25 | if (++off == *pos) |
| 26 | return slave; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 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 = seq->private; |
Veaceslav Falico | f965084 | 2013-09-27 16:12:04 +0200 | [diff] [blame] | 34 | struct list_head *iter; |
| 35 | struct slave *slave; |
| 36 | bool found = false; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 37 | |
| 38 | ++*pos; |
| 39 | if (v == SEQ_START_TOKEN) |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 40 | return bond_first_slave(bond); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 41 | |
Veaceslav Falico | f965084 | 2013-09-27 16:12:04 +0200 | [diff] [blame] | 42 | if (bond_is_last_slave(bond, v)) |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 43 | return NULL; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 44 | |
Veaceslav Falico | f965084 | 2013-09-27 16:12:04 +0200 | [diff] [blame] | 45 | bond_for_each_slave(bond, slave, iter) { |
| 46 | if (found) |
| 47 | return slave; |
| 48 | if (slave == v) |
| 49 | found = true; |
| 50 | } |
| 51 | |
| 52 | return NULL; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void bond_info_seq_stop(struct seq_file *seq, void *v) |
| 56 | __releases(&bond->lock) |
| 57 | __releases(RCU) |
| 58 | { |
| 59 | struct bonding *bond = seq->private; |
| 60 | |
| 61 | read_unlock(&bond->lock); |
| 62 | rcu_read_unlock(); |
| 63 | } |
| 64 | |
| 65 | static void bond_info_show_master(struct seq_file *seq) |
| 66 | { |
| 67 | struct bonding *bond = seq->private; |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 68 | struct bond_opt_value *optval; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 69 | struct slave *curr; |
| 70 | int i; |
| 71 | |
| 72 | read_lock(&bond->curr_slave_lock); |
| 73 | curr = bond->curr_active_slave; |
| 74 | read_unlock(&bond->curr_slave_lock); |
| 75 | |
| 76 | seq_printf(seq, "Bonding Mode: %s", |
| 77 | bond_mode_name(bond->params.mode)); |
| 78 | |
| 79 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP && |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 80 | bond->params.fail_over_mac) { |
| 81 | optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, |
| 82 | bond->params.fail_over_mac); |
| 83 | seq_printf(seq, " (fail_over_mac %s)", optval->string); |
| 84 | } |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 85 | |
| 86 | seq_printf(seq, "\n"); |
| 87 | |
| 88 | if (bond->params.mode == BOND_MODE_XOR || |
| 89 | bond->params.mode == BOND_MODE_8023AD) { |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 90 | optval = bond_opt_get_val(BOND_OPT_XMIT_HASH, |
| 91 | bond->params.xmit_policy); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 92 | seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 93 | optval->string, bond->params.xmit_policy); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | if (USES_PRIMARY(bond->params.mode)) { |
| 97 | seq_printf(seq, "Primary Slave: %s", |
| 98 | (bond->primary_slave) ? |
| 99 | bond->primary_slave->dev->name : "None"); |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 100 | if (bond->primary_slave) { |
| 101 | optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, |
| 102 | bond->params.primary_reselect); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 103 | seq_printf(seq, " (primary_reselect %s)", |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 104 | optval->string); |
| 105 | } |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 106 | |
| 107 | seq_printf(seq, "\nCurrently Active Slave: %s\n", |
| 108 | (curr) ? curr->dev->name : "None"); |
| 109 | } |
| 110 | |
| 111 | seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ? |
| 112 | "up" : "down"); |
| 113 | seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); |
| 114 | seq_printf(seq, "Up Delay (ms): %d\n", |
| 115 | bond->params.updelay * bond->params.miimon); |
| 116 | seq_printf(seq, "Down Delay (ms): %d\n", |
| 117 | bond->params.downdelay * bond->params.miimon); |
| 118 | |
| 119 | |
| 120 | /* ARP information */ |
| 121 | if (bond->params.arp_interval > 0) { |
| 122 | int printed = 0; |
| 123 | seq_printf(seq, "ARP Polling Interval (ms): %d\n", |
| 124 | bond->params.arp_interval); |
| 125 | |
| 126 | seq_printf(seq, "ARP IP target/s (n.n.n.n form):"); |
| 127 | |
| 128 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 129 | if (!bond->params.arp_targets[i]) |
| 130 | break; |
| 131 | if (printed) |
| 132 | seq_printf(seq, ","); |
| 133 | seq_printf(seq, " %pI4", &bond->params.arp_targets[i]); |
| 134 | printed = 1; |
| 135 | } |
| 136 | seq_printf(seq, "\n"); |
| 137 | } |
| 138 | |
| 139 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 140 | struct ad_info ad_info; |
| 141 | |
| 142 | seq_puts(seq, "\n802.3ad info\n"); |
| 143 | seq_printf(seq, "LACP rate: %s\n", |
| 144 | (bond->params.lacp_fast) ? "fast" : "slow"); |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 145 | seq_printf(seq, "Min links: %d\n", bond->params.min_links); |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 146 | optval = bond_opt_get_val(BOND_OPT_AD_SELECT, |
| 147 | bond->params.ad_select); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 148 | seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 149 | optval->string); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 150 | |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 151 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 152 | seq_printf(seq, "bond %s has no active aggregator\n", |
| 153 | bond->dev->name); |
| 154 | } else { |
| 155 | seq_printf(seq, "Active Aggregator Info:\n"); |
| 156 | |
| 157 | seq_printf(seq, "\tAggregator ID: %d\n", |
| 158 | ad_info.aggregator_id); |
| 159 | seq_printf(seq, "\tNumber of ports: %d\n", |
| 160 | ad_info.ports); |
| 161 | seq_printf(seq, "\tActor Key: %d\n", |
| 162 | ad_info.actor_key); |
| 163 | seq_printf(seq, "\tPartner Key: %d\n", |
| 164 | ad_info.partner_key); |
| 165 | seq_printf(seq, "\tPartner Mac Address: %pM\n", |
| 166 | ad_info.partner_system); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static void bond_info_show_slave(struct seq_file *seq, |
| 172 | const struct slave *slave) |
| 173 | { |
| 174 | struct bonding *bond = seq->private; |
| 175 | |
| 176 | seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); |
Amerigo Wang | df2bcc4 | 2012-06-14 22:39:27 +0000 | [diff] [blame] | 177 | seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link)); |
Dan Carpenter | 589665f | 2011-11-04 08:21:38 +0000 | [diff] [blame] | 178 | if (slave->speed == SPEED_UNKNOWN) |
Weiping Pan | 98f41f6 | 2011-10-31 17:20:48 +0000 | [diff] [blame] | 179 | seq_printf(seq, "Speed: %s\n", "Unknown"); |
| 180 | else |
| 181 | seq_printf(seq, "Speed: %d Mbps\n", slave->speed); |
| 182 | |
Dan Carpenter | 589665f | 2011-11-04 08:21:38 +0000 | [diff] [blame] | 183 | if (slave->duplex == DUPLEX_UNKNOWN) |
Weiping Pan | 98f41f6 | 2011-10-31 17:20:48 +0000 | [diff] [blame] | 184 | seq_printf(seq, "Duplex: %s\n", "Unknown"); |
| 185 | else |
| 186 | seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); |
| 187 | |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 188 | seq_printf(seq, "Link Failure Count: %u\n", |
| 189 | slave->link_failure_count); |
| 190 | |
| 191 | seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr); |
| 192 | |
| 193 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 194 | const struct aggregator *agg |
| 195 | = SLAVE_AD_INFO(slave).port.aggregator; |
| 196 | |
| 197 | if (agg) |
| 198 | seq_printf(seq, "Aggregator ID: %d\n", |
| 199 | agg->aggregator_identifier); |
| 200 | else |
| 201 | seq_puts(seq, "Aggregator ID: N/A\n"); |
| 202 | } |
| 203 | seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); |
| 204 | } |
| 205 | |
| 206 | static int bond_info_seq_show(struct seq_file *seq, void *v) |
| 207 | { |
| 208 | if (v == SEQ_START_TOKEN) { |
| 209 | seq_printf(seq, "%s\n", bond_version); |
| 210 | bond_info_show_master(seq); |
| 211 | } else |
| 212 | bond_info_show_slave(seq, v); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static const struct seq_operations bond_info_seq_ops = { |
| 218 | .start = bond_info_seq_start, |
| 219 | .next = bond_info_seq_next, |
| 220 | .stop = bond_info_seq_stop, |
| 221 | .show = bond_info_seq_show, |
| 222 | }; |
| 223 | |
| 224 | static int bond_info_open(struct inode *inode, struct file *file) |
| 225 | { |
| 226 | struct seq_file *seq; |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 227 | int res; |
| 228 | |
| 229 | res = seq_open(file, &bond_info_seq_ops); |
| 230 | if (!res) { |
| 231 | /* recover the pointer buried in proc_dir_entry data */ |
| 232 | seq = file->private_data; |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 233 | seq->private = PDE_DATA(inode); |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | return res; |
| 237 | } |
| 238 | |
| 239 | static const struct file_operations bond_info_fops = { |
| 240 | .owner = THIS_MODULE, |
| 241 | .open = bond_info_open, |
| 242 | .read = seq_read, |
| 243 | .llseek = seq_lseek, |
| 244 | .release = seq_release, |
| 245 | }; |
| 246 | |
| 247 | void bond_create_proc_entry(struct bonding *bond) |
| 248 | { |
| 249 | struct net_device *bond_dev = bond->dev; |
| 250 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
| 251 | |
| 252 | if (bn->proc_dir) { |
| 253 | bond->proc_entry = proc_create_data(bond_dev->name, |
| 254 | S_IRUGO, bn->proc_dir, |
| 255 | &bond_info_fops, bond); |
| 256 | if (bond->proc_entry == NULL) |
| 257 | pr_warning("Warning: Cannot create /proc/net/%s/%s\n", |
| 258 | DRV_NAME, bond_dev->name); |
| 259 | else |
| 260 | memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | void bond_remove_proc_entry(struct bonding *bond) |
| 265 | { |
| 266 | struct net_device *bond_dev = bond->dev; |
| 267 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
| 268 | |
| 269 | if (bn->proc_dir && bond->proc_entry) { |
| 270 | remove_proc_entry(bond->proc_file_name, bn->proc_dir); |
| 271 | memset(bond->proc_file_name, 0, IFNAMSIZ); |
| 272 | bond->proc_entry = NULL; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | /* Create the bonding directory under /proc/net, if doesn't exist yet. |
| 277 | * Caller must hold rtnl_lock. |
| 278 | */ |
| 279 | void __net_init bond_create_proc_dir(struct bond_net *bn) |
| 280 | { |
| 281 | if (!bn->proc_dir) { |
| 282 | bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); |
| 283 | if (!bn->proc_dir) |
| 284 | pr_warning("Warning: cannot create /proc/net/%s\n", |
| 285 | DRV_NAME); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /* Destroy the bonding directory under /proc/net, if empty. |
| 290 | * Caller must hold rtnl_lock. |
| 291 | */ |
| 292 | void __net_exit bond_destroy_proc_dir(struct bond_net *bn) |
| 293 | { |
| 294 | if (bn->proc_dir) { |
| 295 | remove_proc_entry(DRV_NAME, bn->net->proc_net); |
| 296 | bn->proc_dir = NULL; |
| 297 | } |
| 298 | } |