blob: d8d4ada034b7d6cbddbdf8f227cfe44fa15b4b27 [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>
David S. Miller1ef80192014-11-10 13:27:49 -05005#include <net/bonding.h>
Amerigo Wangbd33acc2011-03-06 21:58:46 +00006
Matan Barak73b5a6f22015-04-26 15:55:57 +03007#include "bonding_priv.h"
Amerigo Wangbd33acc2011-03-06 21:58:46 +00008
Amerigo Wangbd33acc2011-03-06 21:58:46 +00009static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
10 __acquires(RCU)
Amerigo Wangbd33acc2011-03-06 21:58:46 +000011{
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
Amerigo Wangbd33acc2011-03-06 21:58:46 +000017 rcu_read_lock();
Amerigo Wangbd33acc2011-03-06 21:58:46 +000018
19 if (*pos == 0)
20 return SEQ_START_TOKEN;
21
Nikolay Aleksandrove9fe8ef2014-09-09 23:17:01 +020022 bond_for_each_slave_rcu(bond, slave, iter)
Amerigo Wangbd33acc2011-03-06 21:58:46 +000023 if (++off == *pos)
24 return slave;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000025
26 return NULL;
27}
28
29static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
30{
31 struct bonding *bond = seq->private;
Veaceslav Falicof9650842013-09-27 16:12:04 +020032 struct list_head *iter;
33 struct slave *slave;
34 bool found = false;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000035
36 ++*pos;
37 if (v == SEQ_START_TOKEN)
Nikolay Aleksandrove9fe8ef2014-09-09 23:17:01 +020038 return bond_first_slave_rcu(bond);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000039
Nikolay Aleksandrove9fe8ef2014-09-09 23:17:01 +020040 bond_for_each_slave_rcu(bond, slave, iter) {
Veaceslav Falicof9650842013-09-27 16:12:04 +020041 if (found)
42 return slave;
43 if (slave == v)
44 found = true;
45 }
46
47 return NULL;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000048}
49
50static void bond_info_seq_stop(struct seq_file *seq, void *v)
Amerigo Wangbd33acc2011-03-06 21:58:46 +000051 __releases(RCU)
52{
Amerigo Wangbd33acc2011-03-06 21:58:46 +000053 rcu_read_unlock();
54}
55
56static void bond_info_show_master(struct seq_file *seq)
57{
58 struct bonding *bond = seq->private;
stephen hemminger28f084c2014-03-06 14:20:17 -080059 const struct bond_opt_value *optval;
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +020060 struct slave *curr, *primary;
Amerigo Wangbd33acc2011-03-06 21:58:46 +000061 int i;
62
dingtianhong4335d602014-02-21 16:08:53 +080063 curr = rcu_dereference(bond->curr_active_slave);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000064
65 seq_printf(seq, "Bonding Mode: %s",
Veaceslav Falico01844092014-05-15 21:39:55 +020066 bond_mode_name(BOND_MODE(bond)));
Amerigo Wangbd33acc2011-03-06 21:58:46 +000067
Veaceslav Falico01844092014-05-15 21:39:55 +020068 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +010069 bond->params.fail_over_mac) {
70 optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
71 bond->params.fail_over_mac);
72 seq_printf(seq, " (fail_over_mac %s)", optval->string);
73 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +000074
75 seq_printf(seq, "\n");
76
Mahesh Bandeward7021322014-10-04 17:44:44 -070077 if (bond_mode_uses_xmit_hash(bond)) {
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010078 optval = bond_opt_get_val(BOND_OPT_XMIT_HASH,
79 bond->params.xmit_policy);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000080 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010081 optval->string, bond->params.xmit_policy);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000082 }
83
Veaceslav Falicoec0865a2014-05-15 21:39:54 +020084 if (bond_uses_primary(bond)) {
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +020085 primary = rcu_dereference(bond->primary_slave);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000086 seq_printf(seq, "Primary Slave: %s",
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +020087 primary ? primary->dev->name : "None");
88 if (primary) {
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +010089 optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
90 bond->params.primary_reselect);
Amerigo Wangbd33acc2011-03-06 21:58:46 +000091 seq_printf(seq, " (primary_reselect %s)",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +010092 optval->string);
93 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +000094
95 seq_printf(seq, "\nCurrently Active Slave: %s\n",
96 (curr) ? curr->dev->name : "None");
97 }
98
99 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
100 "up" : "down");
101 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
102 seq_printf(seq, "Up Delay (ms): %d\n",
103 bond->params.updelay * bond->params.miimon);
104 seq_printf(seq, "Down Delay (ms): %d\n",
105 bond->params.downdelay * bond->params.miimon);
106
107
108 /* ARP information */
109 if (bond->params.arp_interval > 0) {
110 int printed = 0;
111 seq_printf(seq, "ARP Polling Interval (ms): %d\n",
112 bond->params.arp_interval);
113
114 seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
115
116 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
117 if (!bond->params.arp_targets[i])
118 break;
119 if (printed)
120 seq_printf(seq, ",");
121 seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
122 printed = 1;
123 }
124 seq_printf(seq, "\n");
125 }
126
Veaceslav Falico01844092014-05-15 21:39:55 +0200127 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000128 struct ad_info ad_info;
129
130 seq_puts(seq, "\n802.3ad info\n");
131 seq_printf(seq, "LACP rate: %s\n",
132 (bond->params.lacp_fast) ? "fast" : "slow");
stephen hemminger655f8912011-06-22 09:54:39 +0000133 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100134 optval = bond_opt_get_val(BOND_OPT_AD_SELECT,
135 bond->params.ad_select);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000136 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100137 optval->string);
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700138 if (capable(CAP_NET_ADMIN)) {
139 seq_printf(seq, "System priority: %d\n",
140 BOND_AD_INFO(bond).system.sys_priority);
141 seq_printf(seq, "System MAC address: %pM\n",
142 &BOND_AD_INFO(bond).system.sys_mac_addr);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000143
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700144 if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
145 seq_printf(seq,
146 "bond %s has no active aggregator\n",
147 bond->dev->name);
148 } else {
149 seq_printf(seq, "Active Aggregator Info:\n");
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000150
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700151 seq_printf(seq, "\tAggregator ID: %d\n",
152 ad_info.aggregator_id);
153 seq_printf(seq, "\tNumber of ports: %d\n",
154 ad_info.ports);
155 seq_printf(seq, "\tActor Key: %d\n",
156 ad_info.actor_key);
157 seq_printf(seq, "\tPartner Key: %d\n",
158 ad_info.partner_key);
159 seq_printf(seq, "\tPartner Mac Address: %pM\n",
160 ad_info.partner_system);
161 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000162 }
163 }
164}
165
166static void bond_info_show_slave(struct seq_file *seq,
167 const struct slave *slave)
168{
169 struct bonding *bond = seq->private;
170
171 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
Amerigo Wangdf2bcc42012-06-14 22:39:27 +0000172 seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
Dan Carpenter589665f2011-11-04 08:21:38 +0000173 if (slave->speed == SPEED_UNKNOWN)
Weiping Pan98f41f62011-10-31 17:20:48 +0000174 seq_printf(seq, "Speed: %s\n", "Unknown");
175 else
176 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
177
Dan Carpenter589665f2011-11-04 08:21:38 +0000178 if (slave->duplex == DUPLEX_UNKNOWN)
Weiping Pan98f41f62011-10-31 17:20:48 +0000179 seq_printf(seq, "Duplex: %s\n", "Unknown");
180 else
181 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
182
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000183 seq_printf(seq, "Link Failure Count: %u\n",
184 slave->link_failure_count);
185
Jarod Wilsonfaeeb312017-04-04 17:32:42 -0400186 seq_printf(seq, "Permanent HW addr: %*phC\n",
187 slave->dev->addr_len, slave->perm_hwaddr);
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800188 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000189
Veaceslav Falico01844092014-05-15 21:39:55 +0200190 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800191 const struct port *port = &SLAVE_AD_INFO(slave)->port;
192 const struct aggregator *agg = port->aggregator;
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000193
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800194 if (agg) {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000195 seq_printf(seq, "Aggregator ID: %d\n",
196 agg->aggregator_identifier);
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800197 seq_printf(seq, "Actor Churn State: %s\n",
198 bond_3ad_churn_desc(port->sm_churn_actor_state));
199 seq_printf(seq, "Partner Churn State: %s\n",
200 bond_3ad_churn_desc(port->sm_churn_partner_state));
201 seq_printf(seq, "Actor Churned Count: %d\n",
202 port->churn_actor_count);
203 seq_printf(seq, "Partner Churned Count: %d\n",
204 port->churn_partner_count);
205
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700206 if (capable(CAP_NET_ADMIN)) {
207 seq_puts(seq, "details actor lacp pdu:\n");
208 seq_printf(seq, " system priority: %d\n",
209 port->actor_system_priority);
210 seq_printf(seq, " system mac address: %pM\n",
211 &port->actor_system);
212 seq_printf(seq, " port key: %d\n",
213 port->actor_oper_port_key);
214 seq_printf(seq, " port priority: %d\n",
215 port->actor_port_priority);
216 seq_printf(seq, " port number: %d\n",
217 port->actor_port_number);
218 seq_printf(seq, " port state: %d\n",
219 port->actor_oper_port_state);
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800220
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700221 seq_puts(seq, "details partner lacp pdu:\n");
222 seq_printf(seq, " system priority: %d\n",
223 port->partner_oper.system_priority);
224 seq_printf(seq, " system mac address: %pM\n",
225 &port->partner_oper.system);
226 seq_printf(seq, " oper key: %d\n",
227 port->partner_oper.key);
228 seq_printf(seq, " port priority: %d\n",
229 port->partner_oper.port_priority);
230 seq_printf(seq, " port number: %d\n",
231 port->partner_oper.port_number);
232 seq_printf(seq, " port state: %d\n",
233 port->partner_oper.port_state);
234 }
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800235 } else {
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000236 seq_puts(seq, "Aggregator ID: N/A\n");
Mahesh Bandewar14c95512015-02-23 17:50:11 -0800237 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000238 }
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000239}
240
241static int bond_info_seq_show(struct seq_file *seq, void *v)
242{
243 if (v == SEQ_START_TOKEN) {
244 seq_printf(seq, "%s\n", bond_version);
245 bond_info_show_master(seq);
246 } else
247 bond_info_show_slave(seq, v);
248
249 return 0;
250}
251
252static const struct seq_operations bond_info_seq_ops = {
253 .start = bond_info_seq_start,
254 .next = bond_info_seq_next,
255 .stop = bond_info_seq_stop,
256 .show = bond_info_seq_show,
257};
258
259static int bond_info_open(struct inode *inode, struct file *file)
260{
261 struct seq_file *seq;
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000262 int res;
263
264 res = seq_open(file, &bond_info_seq_ops);
265 if (!res) {
266 /* recover the pointer buried in proc_dir_entry data */
267 seq = file->private_data;
Al Virod9dda782013-03-31 18:16:14 -0400268 seq->private = PDE_DATA(inode);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000269 }
270
271 return res;
272}
273
274static const struct file_operations bond_info_fops = {
275 .owner = THIS_MODULE,
276 .open = bond_info_open,
277 .read = seq_read,
278 .llseek = seq_lseek,
279 .release = seq_release,
280};
281
282void bond_create_proc_entry(struct bonding *bond)
283{
284 struct net_device *bond_dev = bond->dev;
285 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
286
287 if (bn->proc_dir) {
288 bond->proc_entry = proc_create_data(bond_dev->name,
289 S_IRUGO, bn->proc_dir,
290 &bond_info_fops, bond);
291 if (bond->proc_entry == NULL)
Veaceslav Falicoc735ee62014-07-15 19:36:07 +0200292 netdev_warn(bond_dev, "Cannot create /proc/net/%s/%s\n",
293 DRV_NAME, bond_dev->name);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000294 else
295 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
296 }
297}
298
299void bond_remove_proc_entry(struct bonding *bond)
300{
301 struct net_device *bond_dev = bond->dev;
302 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
303
304 if (bn->proc_dir && bond->proc_entry) {
305 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
306 memset(bond->proc_file_name, 0, IFNAMSIZ);
307 bond->proc_entry = NULL;
308 }
309}
310
311/* Create the bonding directory under /proc/net, if doesn't exist yet.
312 * Caller must hold rtnl_lock.
313 */
314void __net_init bond_create_proc_dir(struct bond_net *bn)
315{
316 if (!bn->proc_dir) {
317 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
318 if (!bn->proc_dir)
Joe Perches90194262014-02-15 16:01:45 -0800319 pr_warn("Warning: Cannot create /proc/net/%s\n",
Joe Perches91565eb2014-02-15 15:57:04 -0800320 DRV_NAME);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000321 }
322}
323
324/* Destroy the bonding directory under /proc/net, if empty.
325 * Caller must hold rtnl_lock.
326 */
327void __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}