Commit | Line | Data |
---|---|---|
bd33acc3 | 1 | #include <linux/proc_fs.h> |
ee40fa06 | 2 | #include <linux/export.h> |
bd33acc3 AW |
3 | #include <net/net_namespace.h> |
4 | #include <net/netns/generic.h> | |
1ef8019b | 5 | #include <net/bonding.h> |
bd33acc3 | 6 | |
73b5a6f2 | 7 | #include "bonding_priv.h" |
bd33acc3 | 8 | |
bd33acc3 AW |
9 | static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) |
10 | __acquires(RCU) | |
bd33acc3 AW |
11 | { |
12 | struct bonding *bond = seq->private; | |
9caff1e7 | 13 | struct list_head *iter; |
bd33acc3 | 14 | struct slave *slave; |
9caff1e7 | 15 | loff_t off = 0; |
bd33acc3 | 16 | |
bd33acc3 | 17 | rcu_read_lock(); |
bd33acc3 AW |
18 | |
19 | if (*pos == 0) | |
20 | return SEQ_START_TOKEN; | |
21 | ||
e9fe8efe | 22 | bond_for_each_slave_rcu(bond, slave, iter) |
bd33acc3 AW |
23 | if (++off == *pos) |
24 | return slave; | |
bd33acc3 AW |
25 | |
26 | return NULL; | |
27 | } | |
28 | ||
29 | static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
30 | { | |
31 | struct bonding *bond = seq->private; | |
f9650845 VF |
32 | struct list_head *iter; |
33 | struct slave *slave; | |
34 | bool found = false; | |
bd33acc3 AW |
35 | |
36 | ++*pos; | |
37 | if (v == SEQ_START_TOKEN) | |
e9fe8efe | 38 | return bond_first_slave_rcu(bond); |
bd33acc3 | 39 | |
e9fe8efe | 40 | bond_for_each_slave_rcu(bond, slave, iter) { |
f9650845 VF |
41 | if (found) |
42 | return slave; | |
43 | if (slave == v) | |
44 | found = true; | |
45 | } | |
46 | ||
47 | return NULL; | |
bd33acc3 AW |
48 | } |
49 | ||
50 | static void bond_info_seq_stop(struct seq_file *seq, void *v) | |
bd33acc3 AW |
51 | __releases(RCU) |
52 | { | |
bd33acc3 AW |
53 | rcu_read_unlock(); |
54 | } | |
55 | ||
56 | static void bond_info_show_master(struct seq_file *seq) | |
57 | { | |
58 | struct bonding *bond = seq->private; | |
28f084cc | 59 | const struct bond_opt_value *optval; |
059b47e8 | 60 | struct slave *curr, *primary; |
bd33acc3 AW |
61 | int i; |
62 | ||
4335d60e | 63 | curr = rcu_dereference(bond->curr_active_slave); |
bd33acc3 AW |
64 | |
65 | seq_printf(seq, "Bonding Mode: %s", | |
01844098 | 66 | bond_mode_name(BOND_MODE(bond))); |
bd33acc3 | 67 | |
01844098 | 68 | if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && |
1df6b6aa NA |
69 | 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 | } | |
bd33acc3 AW |
74 | |
75 | seq_printf(seq, "\n"); | |
76 | ||
d7021325 | 77 | if (bond_mode_uses_xmit_hash(bond)) { |
a4b32ce7 NA |
78 | optval = bond_opt_get_val(BOND_OPT_XMIT_HASH, |
79 | bond->params.xmit_policy); | |
bd33acc3 | 80 | seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", |
a4b32ce7 | 81 | optval->string, bond->params.xmit_policy); |
bd33acc3 AW |
82 | } |
83 | ||
ec0865a9 | 84 | if (bond_uses_primary(bond)) { |
059b47e8 | 85 | primary = rcu_dereference(bond->primary_slave); |
bd33acc3 | 86 | seq_printf(seq, "Primary Slave: %s", |
059b47e8 NA |
87 | primary ? primary->dev->name : "None"); |
88 | if (primary) { | |
388d3a6d NA |
89 | optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, |
90 | bond->params.primary_reselect); | |
bd33acc3 | 91 | seq_printf(seq, " (primary_reselect %s)", |
388d3a6d NA |
92 | optval->string); |
93 | } | |
bd33acc3 AW |
94 | |
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 | ||
01844098 | 127 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
bd33acc3 AW |
128 | 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"); | |
655f8919 | 133 | seq_printf(seq, "Min links: %d\n", bond->params.min_links); |
9e5f5eeb NA |
134 | optval = bond_opt_get_val(BOND_OPT_AD_SELECT, |
135 | bond->params.ad_select); | |
bd33acc3 | 136 | seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", |
9e5f5eeb | 137 | optval->string); |
bd33acc3 | 138 | |
318debd8 | 139 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
bd33acc3 AW |
140 | seq_printf(seq, "bond %s has no active aggregator\n", |
141 | bond->dev->name); | |
142 | } else { | |
143 | seq_printf(seq, "Active Aggregator Info:\n"); | |
144 | ||
145 | seq_printf(seq, "\tAggregator ID: %d\n", | |
146 | ad_info.aggregator_id); | |
147 | seq_printf(seq, "\tNumber of ports: %d\n", | |
148 | ad_info.ports); | |
149 | seq_printf(seq, "\tActor Key: %d\n", | |
150 | ad_info.actor_key); | |
151 | seq_printf(seq, "\tPartner Key: %d\n", | |
152 | ad_info.partner_key); | |
153 | seq_printf(seq, "\tPartner Mac Address: %pM\n", | |
154 | ad_info.partner_system); | |
155 | } | |
156 | } | |
157 | } | |
158 | ||
159 | static void bond_info_show_slave(struct seq_file *seq, | |
160 | const struct slave *slave) | |
161 | { | |
162 | struct bonding *bond = seq->private; | |
163 | ||
164 | seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); | |
df2bcc4a | 165 | seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link)); |
589665f5 | 166 | if (slave->speed == SPEED_UNKNOWN) |
98f41f69 WP |
167 | seq_printf(seq, "Speed: %s\n", "Unknown"); |
168 | else | |
169 | seq_printf(seq, "Speed: %d Mbps\n", slave->speed); | |
170 | ||
589665f5 | 171 | if (slave->duplex == DUPLEX_UNKNOWN) |
98f41f69 WP |
172 | seq_printf(seq, "Duplex: %s\n", "Unknown"); |
173 | else | |
174 | seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); | |
175 | ||
bd33acc3 AW |
176 | seq_printf(seq, "Link Failure Count: %u\n", |
177 | slave->link_failure_count); | |
178 | ||
179 | seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr); | |
14c9551a | 180 | seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); |
bd33acc3 | 181 | |
01844098 | 182 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
14c9551a MB |
183 | const struct port *port = &SLAVE_AD_INFO(slave)->port; |
184 | const struct aggregator *agg = port->aggregator; | |
bd33acc3 | 185 | |
14c9551a | 186 | if (agg) { |
bd33acc3 AW |
187 | seq_printf(seq, "Aggregator ID: %d\n", |
188 | agg->aggregator_identifier); | |
14c9551a MB |
189 | seq_printf(seq, "Actor Churn State: %s\n", |
190 | bond_3ad_churn_desc(port->sm_churn_actor_state)); | |
191 | seq_printf(seq, "Partner Churn State: %s\n", | |
192 | bond_3ad_churn_desc(port->sm_churn_partner_state)); | |
193 | seq_printf(seq, "Actor Churned Count: %d\n", | |
194 | port->churn_actor_count); | |
195 | seq_printf(seq, "Partner Churned Count: %d\n", | |
196 | port->churn_partner_count); | |
197 | ||
198 | seq_puts(seq, "details actor lacp pdu:\n"); | |
199 | seq_printf(seq, " system priority: %d\n", | |
200 | port->actor_system_priority); | |
201 | seq_printf(seq, " port key: %d\n", | |
202 | port->actor_oper_port_key); | |
203 | seq_printf(seq, " port priority: %d\n", | |
204 | port->actor_port_priority); | |
205 | seq_printf(seq, " port number: %d\n", | |
206 | port->actor_port_number); | |
207 | seq_printf(seq, " port state: %d\n", | |
208 | port->actor_oper_port_state); | |
209 | ||
210 | seq_puts(seq, "details partner lacp pdu:\n"); | |
211 | seq_printf(seq, " system priority: %d\n", | |
212 | port->partner_oper.system_priority); | |
213 | seq_printf(seq, " oper key: %d\n", | |
214 | port->partner_oper.key); | |
215 | seq_printf(seq, " port priority: %d\n", | |
216 | port->partner_oper.port_priority); | |
217 | seq_printf(seq, " port number: %d\n", | |
218 | port->partner_oper.port_number); | |
219 | seq_printf(seq, " port state: %d\n", | |
220 | port->partner_oper.port_state); | |
221 | } else { | |
bd33acc3 | 222 | seq_puts(seq, "Aggregator ID: N/A\n"); |
14c9551a | 223 | } |
bd33acc3 | 224 | } |
bd33acc3 AW |
225 | } |
226 | ||
227 | static int bond_info_seq_show(struct seq_file *seq, void *v) | |
228 | { | |
229 | if (v == SEQ_START_TOKEN) { | |
230 | seq_printf(seq, "%s\n", bond_version); | |
231 | bond_info_show_master(seq); | |
232 | } else | |
233 | bond_info_show_slave(seq, v); | |
234 | ||
235 | return 0; | |
236 | } | |
237 | ||
238 | static const struct seq_operations bond_info_seq_ops = { | |
239 | .start = bond_info_seq_start, | |
240 | .next = bond_info_seq_next, | |
241 | .stop = bond_info_seq_stop, | |
242 | .show = bond_info_seq_show, | |
243 | }; | |
244 | ||
245 | static int bond_info_open(struct inode *inode, struct file *file) | |
246 | { | |
247 | struct seq_file *seq; | |
bd33acc3 AW |
248 | int res; |
249 | ||
250 | res = seq_open(file, &bond_info_seq_ops); | |
251 | if (!res) { | |
252 | /* recover the pointer buried in proc_dir_entry data */ | |
253 | seq = file->private_data; | |
d9dda78b | 254 | seq->private = PDE_DATA(inode); |
bd33acc3 AW |
255 | } |
256 | ||
257 | return res; | |
258 | } | |
259 | ||
260 | static const struct file_operations bond_info_fops = { | |
261 | .owner = THIS_MODULE, | |
262 | .open = bond_info_open, | |
263 | .read = seq_read, | |
264 | .llseek = seq_lseek, | |
265 | .release = seq_release, | |
266 | }; | |
267 | ||
268 | void bond_create_proc_entry(struct bonding *bond) | |
269 | { | |
270 | struct net_device *bond_dev = bond->dev; | |
271 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | |
272 | ||
273 | if (bn->proc_dir) { | |
274 | bond->proc_entry = proc_create_data(bond_dev->name, | |
275 | S_IRUGO, bn->proc_dir, | |
276 | &bond_info_fops, bond); | |
277 | if (bond->proc_entry == NULL) | |
c735ee6c VF |
278 | netdev_warn(bond_dev, "Cannot create /proc/net/%s/%s\n", |
279 | DRV_NAME, bond_dev->name); | |
bd33acc3 AW |
280 | else |
281 | memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); | |
282 | } | |
283 | } | |
284 | ||
285 | void bond_remove_proc_entry(struct bonding *bond) | |
286 | { | |
287 | struct net_device *bond_dev = bond->dev; | |
288 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | |
289 | ||
290 | if (bn->proc_dir && bond->proc_entry) { | |
291 | remove_proc_entry(bond->proc_file_name, bn->proc_dir); | |
292 | memset(bond->proc_file_name, 0, IFNAMSIZ); | |
293 | bond->proc_entry = NULL; | |
294 | } | |
295 | } | |
296 | ||
297 | /* Create the bonding directory under /proc/net, if doesn't exist yet. | |
298 | * Caller must hold rtnl_lock. | |
299 | */ | |
300 | void __net_init bond_create_proc_dir(struct bond_net *bn) | |
301 | { | |
302 | if (!bn->proc_dir) { | |
303 | bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); | |
304 | if (!bn->proc_dir) | |
90194264 | 305 | pr_warn("Warning: Cannot create /proc/net/%s\n", |
91565ebb | 306 | DRV_NAME); |
bd33acc3 AW |
307 | } |
308 | } | |
309 | ||
310 | /* Destroy the bonding directory under /proc/net, if empty. | |
311 | * Caller must hold rtnl_lock. | |
312 | */ | |
313 | void __net_exit bond_destroy_proc_dir(struct bond_net *bn) | |
314 | { | |
315 | if (bn->proc_dir) { | |
316 | remove_proc_entry(DRV_NAME, bn->net->proc_net); | |
317 | bn->proc_dir = NULL; | |
318 | } | |
319 | } |