blob: 95de93b9038675994e66622eff5423ae082583c0 [file] [log] [blame]
Amerigo Wangbd33acc2011-03-06 21:58:46 +00001#include <linux/proc_fs.h>
2#include <net/net_namespace.h>
3#include <net/netns/generic.h>
4#include "bonding.h"
5
6
Amerigo Wangbd33acc2011-03-06 21:58:46 +00007static 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
31static 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
45static 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
55static 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 hemminger655f8912011-06-22 09:54:39 +0000128 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
Amerigo Wangbd33acc2011-03-06 21:58:46 +0000129 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
152static 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");
160 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
161 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
162 seq_printf(seq, "Link Failure Count: %u\n",
163 slave->link_failure_count);
164
165 seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
166
167 if (bond->params.mode == BOND_MODE_8023AD) {
168 const struct aggregator *agg
169 = SLAVE_AD_INFO(slave).port.aggregator;
170
171 if (agg)
172 seq_printf(seq, "Aggregator ID: %d\n",
173 agg->aggregator_identifier);
174 else
175 seq_puts(seq, "Aggregator ID: N/A\n");
176 }
177 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
178}
179
180static int bond_info_seq_show(struct seq_file *seq, void *v)
181{
182 if (v == SEQ_START_TOKEN) {
183 seq_printf(seq, "%s\n", bond_version);
184 bond_info_show_master(seq);
185 } else
186 bond_info_show_slave(seq, v);
187
188 return 0;
189}
190
191static const struct seq_operations bond_info_seq_ops = {
192 .start = bond_info_seq_start,
193 .next = bond_info_seq_next,
194 .stop = bond_info_seq_stop,
195 .show = bond_info_seq_show,
196};
197
198static int bond_info_open(struct inode *inode, struct file *file)
199{
200 struct seq_file *seq;
201 struct proc_dir_entry *proc;
202 int res;
203
204 res = seq_open(file, &bond_info_seq_ops);
205 if (!res) {
206 /* recover the pointer buried in proc_dir_entry data */
207 seq = file->private_data;
208 proc = PDE(inode);
209 seq->private = proc->data;
210 }
211
212 return res;
213}
214
215static const struct file_operations bond_info_fops = {
216 .owner = THIS_MODULE,
217 .open = bond_info_open,
218 .read = seq_read,
219 .llseek = seq_lseek,
220 .release = seq_release,
221};
222
223void bond_create_proc_entry(struct bonding *bond)
224{
225 struct net_device *bond_dev = bond->dev;
226 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
227
228 if (bn->proc_dir) {
229 bond->proc_entry = proc_create_data(bond_dev->name,
230 S_IRUGO, bn->proc_dir,
231 &bond_info_fops, bond);
232 if (bond->proc_entry == NULL)
233 pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
234 DRV_NAME, bond_dev->name);
235 else
236 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
237 }
238}
239
240void bond_remove_proc_entry(struct bonding *bond)
241{
242 struct net_device *bond_dev = bond->dev;
243 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
244
245 if (bn->proc_dir && bond->proc_entry) {
246 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
247 memset(bond->proc_file_name, 0, IFNAMSIZ);
248 bond->proc_entry = NULL;
249 }
250}
251
252/* Create the bonding directory under /proc/net, if doesn't exist yet.
253 * Caller must hold rtnl_lock.
254 */
255void __net_init bond_create_proc_dir(struct bond_net *bn)
256{
257 if (!bn->proc_dir) {
258 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
259 if (!bn->proc_dir)
260 pr_warning("Warning: cannot create /proc/net/%s\n",
261 DRV_NAME);
262 }
263}
264
265/* Destroy the bonding directory under /proc/net, if empty.
266 * Caller must hold rtnl_lock.
267 */
268void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
269{
270 if (bn->proc_dir) {
271 remove_proc_entry(DRV_NAME, bn->net->proc_net);
272 bn->proc_dir = NULL;
273 }
274}