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