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