blob: b215b479bb3a6917ffd6d37f30f989996d176f5b [file] [log] [blame]
Amerigo Wangbd33acc2011-03-06 21:58:46 +00001#include <linux/proc_fs.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -04002#include <linux/export.h>
Amerigo Wangbd33acc2011-03-06 21:58:46 +00003#include <net/net_namespace.h>
4#include <net/netns/generic.h>
5#include "bonding.h"
6
7
Amerigo Wangbd33acc2011-03-06 21:58:46 +00008static 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 Falico9caff1e72013-09-25 09:20:14 +020013 struct list_head *iter;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000014 struct slave *slave;
Veaceslav Falico9caff1e72013-09-25 09:20:14 +020015 loff_t off = 0;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000016
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 Falico9caff1e72013-09-25 09:20:14 +020024 bond_for_each_slave(bond, slave, iter)
Amerigo Wangbd33acc2011-03-06 21:58:46 +000025 if (++off == *pos)
26 return slave;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000027
28 return NULL;
29}
30
31static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
32{
33 struct bonding *bond = seq->private;
Veaceslav Falicof9650842013-09-27 16:12:04 +020034 struct list_head *iter;
35 struct slave *slave;
36 bool found = false;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000037
38 ++*pos;
39 if (v == SEQ_START_TOKEN)
nikolay@redhat.comdec1e902013-08-01 16:54:47 +020040 return bond_first_slave(bond);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000041
Veaceslav Falicof9650842013-09-27 16:12:04 +020042 if (bond_is_last_slave(bond, v))
nikolay@redhat.comdec1e902013-08-01 16:54:47 +020043 return NULL;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000044
Veaceslav Falicof9650842013-09-27 16:12:04 +020045 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 Wangbd33acc2011-03-06 21:58:46 +000053}
54
55static 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
65static void bond_info_show_master(struct seq_file *seq)
66{
67 struct bonding *bond = seq->private;
stephen hemminger28f084c2014-03-06 14:20:17 -080068 const struct bond_opt_value *optval;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000069 struct slave *curr;
70 int i;
71
dingtianhong4335d602014-02-21 16:08:53 +080072 curr = rcu_dereference(bond->curr_active_slave);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000073
74 seq_printf(seq, "Bonding Mode: %s",
Veaceslav Falico01844092014-05-15 21:39:55 +020075 bond_mode_name(BOND_MODE(bond)));
Amerigo Wangbd33acc2011-03-06 21:58:46 +000076
Veaceslav Falico01844092014-05-15 21:39:55 +020077 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +010078 bond->params.fail_over_mac) {
79 optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
80 bond->params.fail_over_mac);
81 seq_printf(seq, " (fail_over_mac %s)", optval->string);
82 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +000083
84 seq_printf(seq, "\n");
85
Veaceslav Falico01844092014-05-15 21:39:55 +020086 if (BOND_MODE(bond) == BOND_MODE_XOR ||
87 BOND_MODE(bond) == BOND_MODE_8023AD) {
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010088 optval = bond_opt_get_val(BOND_OPT_XMIT_HASH,
89 bond->params.xmit_policy);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000090 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010091 optval->string, bond->params.xmit_policy);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000092 }
93
Veaceslav Falicoec0865a2014-05-15 21:39:54 +020094 if (bond_uses_primary(bond)) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +000095 seq_printf(seq, "Primary Slave: %s",
96 (bond->primary_slave) ?
97 bond->primary_slave->dev->name : "None");
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +010098 if (bond->primary_slave) {
99 optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
100 bond->params.primary_reselect);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000101 seq_printf(seq, " (primary_reselect %s)",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100102 optval->string);
103 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000104
105 seq_printf(seq, "\nCurrently Active Slave: %s\n",
106 (curr) ? curr->dev->name : "None");
107 }
108
109 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
110 "up" : "down");
111 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
112 seq_printf(seq, "Up Delay (ms): %d\n",
113 bond->params.updelay * bond->params.miimon);
114 seq_printf(seq, "Down Delay (ms): %d\n",
115 bond->params.downdelay * bond->params.miimon);
116
117
118 /* ARP information */
119 if (bond->params.arp_interval > 0) {
120 int printed = 0;
121 seq_printf(seq, "ARP Polling Interval (ms): %d\n",
122 bond->params.arp_interval);
123
124 seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
125
126 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
127 if (!bond->params.arp_targets[i])
128 break;
129 if (printed)
130 seq_printf(seq, ",");
131 seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
132 printed = 1;
133 }
134 seq_printf(seq, "\n");
135 }
136
Veaceslav Falico01844092014-05-15 21:39:55 +0200137 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000138 struct ad_info ad_info;
139
140 seq_puts(seq, "\n802.3ad info\n");
141 seq_printf(seq, "LACP rate: %s\n",
142 (bond->params.lacp_fast) ? "fast" : "slow");
stephen hemminger655f8912011-06-22 09:54:39 +0000143 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100144 optval = bond_opt_get_val(BOND_OPT_AD_SELECT,
145 bond->params.ad_select);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000146 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100147 optval->string);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000148
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000149 if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000150 seq_printf(seq, "bond %s has no active aggregator\n",
151 bond->dev->name);
152 } else {
153 seq_printf(seq, "Active Aggregator Info:\n");
154
155 seq_printf(seq, "\tAggregator ID: %d\n",
156 ad_info.aggregator_id);
157 seq_printf(seq, "\tNumber of ports: %d\n",
158 ad_info.ports);
159 seq_printf(seq, "\tActor Key: %d\n",
160 ad_info.actor_key);
161 seq_printf(seq, "\tPartner Key: %d\n",
162 ad_info.partner_key);
163 seq_printf(seq, "\tPartner Mac Address: %pM\n",
164 ad_info.partner_system);
165 }
166 }
167}
168
169static void bond_info_show_slave(struct seq_file *seq,
170 const struct slave *slave)
171{
172 struct bonding *bond = seq->private;
173
174 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
Amerigo Wangdf2bcc42012-06-14 22:39:27 +0000175 seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
Dan Carpenter589665f2011-11-04 08:21:38 +0000176 if (slave->speed == SPEED_UNKNOWN)
Weiping Pan98f41f62011-10-31 17:20:48 +0000177 seq_printf(seq, "Speed: %s\n", "Unknown");
178 else
179 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
180
Dan Carpenter589665f2011-11-04 08:21:38 +0000181 if (slave->duplex == DUPLEX_UNKNOWN)
Weiping Pan98f41f62011-10-31 17:20:48 +0000182 seq_printf(seq, "Duplex: %s\n", "Unknown");
183 else
184 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
185
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000186 seq_printf(seq, "Link Failure Count: %u\n",
187 slave->link_failure_count);
188
189 seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
190
Veaceslav Falico01844092014-05-15 21:39:55 +0200191 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000192 const struct aggregator *agg
dingtianhong3fdddd82014-05-12 15:08:43 +0800193 = SLAVE_AD_INFO(slave)->port.aggregator;
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000194
195 if (agg)
196 seq_printf(seq, "Aggregator ID: %d\n",
197 agg->aggregator_identifier);
198 else
199 seq_puts(seq, "Aggregator ID: N/A\n");
200 }
201 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
202}
203
204static int bond_info_seq_show(struct seq_file *seq, void *v)
205{
206 if (v == SEQ_START_TOKEN) {
207 seq_printf(seq, "%s\n", bond_version);
208 bond_info_show_master(seq);
209 } else
210 bond_info_show_slave(seq, v);
211
212 return 0;
213}
214
215static const struct seq_operations bond_info_seq_ops = {
216 .start = bond_info_seq_start,
217 .next = bond_info_seq_next,
218 .stop = bond_info_seq_stop,
219 .show = bond_info_seq_show,
220};
221
222static int bond_info_open(struct inode *inode, struct file *file)
223{
224 struct seq_file *seq;
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000225 int res;
226
227 res = seq_open(file, &bond_info_seq_ops);
228 if (!res) {
229 /* recover the pointer buried in proc_dir_entry data */
230 seq = file->private_data;
Al Virod9dda782013-03-31 18:16:14 -0400231 seq->private = PDE_DATA(inode);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000232 }
233
234 return res;
235}
236
237static const struct file_operations bond_info_fops = {
238 .owner = THIS_MODULE,
239 .open = bond_info_open,
240 .read = seq_read,
241 .llseek = seq_lseek,
242 .release = seq_release,
243};
244
245void bond_create_proc_entry(struct bonding *bond)
246{
247 struct net_device *bond_dev = bond->dev;
248 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
249
250 if (bn->proc_dir) {
251 bond->proc_entry = proc_create_data(bond_dev->name,
252 S_IRUGO, bn->proc_dir,
253 &bond_info_fops, bond);
254 if (bond->proc_entry == NULL)
Joe Perches91565eb2014-02-15 15:57:04 -0800255 pr_warn("Warning: Cannot create /proc/net/%s/%s\n",
256 DRV_NAME, bond_dev->name);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000257 else
258 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
259 }
260}
261
262void bond_remove_proc_entry(struct bonding *bond)
263{
264 struct net_device *bond_dev = bond->dev;
265 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
266
267 if (bn->proc_dir && bond->proc_entry) {
268 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
269 memset(bond->proc_file_name, 0, IFNAMSIZ);
270 bond->proc_entry = NULL;
271 }
272}
273
274/* Create the bonding directory under /proc/net, if doesn't exist yet.
275 * Caller must hold rtnl_lock.
276 */
277void __net_init bond_create_proc_dir(struct bond_net *bn)
278{
279 if (!bn->proc_dir) {
280 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
281 if (!bn->proc_dir)
Joe Perches90194262014-02-15 16:01:45 -0800282 pr_warn("Warning: Cannot create /proc/net/%s\n",
Joe Perches91565eb2014-02-15 15:57:04 -0800283 DRV_NAME);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000284 }
285}
286
287/* Destroy the bonding directory under /proc/net, if empty.
288 * Caller must hold rtnl_lock.
289 */
290void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
291{
292 if (bn->proc_dir) {
293 remove_proc_entry(DRV_NAME, bn->net->proc_net);
294 bn->proc_dir = NULL;
295 }
296}