Loading...
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
8static 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
31static 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
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;
68 const struct bond_opt_value *optval;
69 struct slave *curr;
70 int i;
71
72 curr = rcu_dereference(bond->curr_active_slave);
73
74 seq_printf(seq, "Bonding Mode: %s",
75 bond_mode_name(bond->params.mode));
76
77 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
78 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 }
83
84 seq_printf(seq, "\n");
85
86 if (bond->params.mode == BOND_MODE_XOR ||
87 bond->params.mode == BOND_MODE_8023AD) {
88 optval = bond_opt_get_val(BOND_OPT_XMIT_HASH,
89 bond->params.xmit_policy);
90 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
91 optval->string, bond->params.xmit_policy);
92 }
93
94 if (USES_PRIMARY(bond->params.mode)) {
95 seq_printf(seq, "Primary Slave: %s",
96 (bond->primary_slave) ?
97 bond->primary_slave->dev->name : "None");
98 if (bond->primary_slave) {
99 optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
100 bond->params.primary_reselect);
101 seq_printf(seq, " (primary_reselect %s)",
102 optval->string);
103 }
104
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
137 if (bond->params.mode == BOND_MODE_8023AD) {
138 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");
143 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
144 optval = bond_opt_get_val(BOND_OPT_AD_SELECT,
145 bond->params.ad_select);
146 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
147 optval->string);
148
149 if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
150 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);
175 seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
176 if (slave->speed == SPEED_UNKNOWN)
177 seq_printf(seq, "Speed: %s\n", "Unknown");
178 else
179 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
180
181 if (slave->duplex == DUPLEX_UNKNOWN)
182 seq_printf(seq, "Duplex: %s\n", "Unknown");
183 else
184 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
185
186 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
191 if (bond->params.mode == BOND_MODE_8023AD) {
192 const struct aggregator *agg
193 = SLAVE_AD_INFO(slave).port.aggregator;
194
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;
225 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;
231 seq->private = PDE_DATA(inode);
232 }
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)
255 pr_warn("Warning: Cannot create /proc/net/%s/%s\n",
256 DRV_NAME, bond_dev->name);
257 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)
282 pr_warn("Warning: Cannot create /proc/net/%s\n",
283 DRV_NAME);
284 }
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}
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/proc_fs.h>
3#include <linux/export.h>
4#include <net/net_namespace.h>
5#include <net/netns/generic.h>
6#include <net/bonding.h>
7
8#include "bonding_priv.h"
9
10static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
11 __acquires(RCU)
12{
13 struct bonding *bond = PDE_DATA(file_inode(seq->file));
14 struct list_head *iter;
15 struct slave *slave;
16 loff_t off = 0;
17
18 rcu_read_lock();
19
20 if (*pos == 0)
21 return SEQ_START_TOKEN;
22
23 bond_for_each_slave_rcu(bond, slave, iter)
24 if (++off == *pos)
25 return slave;
26
27 return NULL;
28}
29
30static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
31{
32 struct bonding *bond = PDE_DATA(file_inode(seq->file));
33 struct list_head *iter;
34 struct slave *slave;
35 bool found = false;
36
37 ++*pos;
38 if (v == SEQ_START_TOKEN)
39 return bond_first_slave_rcu(bond);
40
41 bond_for_each_slave_rcu(bond, slave, iter) {
42 if (found)
43 return slave;
44 if (slave == v)
45 found = true;
46 }
47
48 return NULL;
49}
50
51static void bond_info_seq_stop(struct seq_file *seq, void *v)
52 __releases(RCU)
53{
54 rcu_read_unlock();
55}
56
57static void bond_info_show_master(struct seq_file *seq)
58{
59 struct bonding *bond = PDE_DATA(file_inode(seq->file));
60 const struct bond_opt_value *optval;
61 struct slave *curr, *primary;
62 int i;
63
64 curr = rcu_dereference(bond->curr_active_slave);
65
66 seq_printf(seq, "Bonding Mode: %s",
67 bond_mode_name(BOND_MODE(bond)));
68
69 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
70 bond->params.fail_over_mac) {
71 optval = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
72 bond->params.fail_over_mac);
73 seq_printf(seq, " (fail_over_mac %s)", optval->string);
74 }
75
76 seq_printf(seq, "\n");
77
78 if (bond_mode_uses_xmit_hash(bond)) {
79 optval = bond_opt_get_val(BOND_OPT_XMIT_HASH,
80 bond->params.xmit_policy);
81 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
82 optval->string, bond->params.xmit_policy);
83 }
84
85 if (bond_uses_primary(bond)) {
86 primary = rcu_dereference(bond->primary_slave);
87 seq_printf(seq, "Primary Slave: %s",
88 primary ? primary->dev->name : "None");
89 if (primary) {
90 optval = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
91 bond->params.primary_reselect);
92 seq_printf(seq, " (primary_reselect %s)",
93 optval->string);
94 }
95
96 seq_printf(seq, "\nCurrently Active Slave: %s\n",
97 (curr) ? curr->dev->name : "None");
98 }
99
100 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
101 "up" : "down");
102 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
103 seq_printf(seq, "Up Delay (ms): %d\n",
104 bond->params.updelay * bond->params.miimon);
105 seq_printf(seq, "Down Delay (ms): %d\n",
106 bond->params.downdelay * bond->params.miimon);
107 seq_printf(seq, "Peer Notification Delay (ms): %d\n",
108 bond->params.peer_notif_delay * bond->params.miimon);
109
110
111 /* ARP information */
112 if (bond->params.arp_interval > 0) {
113 int printed = 0;
114 seq_printf(seq, "ARP Polling Interval (ms): %d\n",
115 bond->params.arp_interval);
116
117 seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
118
119 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
120 if (!bond->params.arp_targets[i])
121 break;
122 if (printed)
123 seq_printf(seq, ",");
124 seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
125 printed = 1;
126 }
127 seq_printf(seq, "\n");
128 }
129
130 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
131 struct ad_info ad_info;
132
133 seq_puts(seq, "\n802.3ad info\n");
134 seq_printf(seq, "LACP rate: %s\n",
135 (bond->params.lacp_fast) ? "fast" : "slow");
136 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
137 optval = bond_opt_get_val(BOND_OPT_AD_SELECT,
138 bond->params.ad_select);
139 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
140 optval->string);
141 if (capable(CAP_NET_ADMIN)) {
142 seq_printf(seq, "System priority: %d\n",
143 BOND_AD_INFO(bond).system.sys_priority);
144 seq_printf(seq, "System MAC address: %pM\n",
145 &BOND_AD_INFO(bond).system.sys_mac_addr);
146
147 if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
148 seq_printf(seq,
149 "bond %s has no active aggregator\n",
150 bond->dev->name);
151 } else {
152 seq_printf(seq, "Active Aggregator Info:\n");
153
154 seq_printf(seq, "\tAggregator ID: %d\n",
155 ad_info.aggregator_id);
156 seq_printf(seq, "\tNumber of ports: %d\n",
157 ad_info.ports);
158 seq_printf(seq, "\tActor Key: %d\n",
159 ad_info.actor_key);
160 seq_printf(seq, "\tPartner Key: %d\n",
161 ad_info.partner_key);
162 seq_printf(seq, "\tPartner Mac Address: %pM\n",
163 ad_info.partner_system);
164 }
165 }
166 }
167}
168
169static void bond_info_show_slave(struct seq_file *seq,
170 const struct slave *slave)
171{
172 struct bonding *bond = PDE_DATA(file_inode(seq->file));
173
174 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
175 seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
176 if (slave->speed == SPEED_UNKNOWN)
177 seq_printf(seq, "Speed: %s\n", "Unknown");
178 else
179 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
180
181 if (slave->duplex == DUPLEX_UNKNOWN)
182 seq_printf(seq, "Duplex: %s\n", "Unknown");
183 else
184 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
185
186 seq_printf(seq, "Link Failure Count: %u\n",
187 slave->link_failure_count);
188
189 seq_printf(seq, "Permanent HW addr: %*phC\n",
190 slave->dev->addr_len, slave->perm_hwaddr);
191 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
192
193 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
194 const struct port *port = &SLAVE_AD_INFO(slave)->port;
195 const struct aggregator *agg = port->aggregator;
196
197 if (agg) {
198 seq_printf(seq, "Aggregator ID: %d\n",
199 agg->aggregator_identifier);
200 seq_printf(seq, "Actor Churn State: %s\n",
201 bond_3ad_churn_desc(port->sm_churn_actor_state));
202 seq_printf(seq, "Partner Churn State: %s\n",
203 bond_3ad_churn_desc(port->sm_churn_partner_state));
204 seq_printf(seq, "Actor Churned Count: %d\n",
205 port->churn_actor_count);
206 seq_printf(seq, "Partner Churned Count: %d\n",
207 port->churn_partner_count);
208
209 if (capable(CAP_NET_ADMIN)) {
210 seq_puts(seq, "details actor lacp pdu:\n");
211 seq_printf(seq, " system priority: %d\n",
212 port->actor_system_priority);
213 seq_printf(seq, " system mac address: %pM\n",
214 &port->actor_system);
215 seq_printf(seq, " port key: %d\n",
216 port->actor_oper_port_key);
217 seq_printf(seq, " port priority: %d\n",
218 port->actor_port_priority);
219 seq_printf(seq, " port number: %d\n",
220 port->actor_port_number);
221 seq_printf(seq, " port state: %d\n",
222 port->actor_oper_port_state);
223
224 seq_puts(seq, "details partner lacp pdu:\n");
225 seq_printf(seq, " system priority: %d\n",
226 port->partner_oper.system_priority);
227 seq_printf(seq, " system mac address: %pM\n",
228 &port->partner_oper.system);
229 seq_printf(seq, " oper key: %d\n",
230 port->partner_oper.key);
231 seq_printf(seq, " port priority: %d\n",
232 port->partner_oper.port_priority);
233 seq_printf(seq, " port number: %d\n",
234 port->partner_oper.port_number);
235 seq_printf(seq, " port state: %d\n",
236 port->partner_oper.port_state);
237 }
238 } else {
239 seq_puts(seq, "Aggregator ID: N/A\n");
240 }
241 }
242}
243
244static int bond_info_seq_show(struct seq_file *seq, void *v)
245{
246 if (v == SEQ_START_TOKEN) {
247 seq_printf(seq, "%s\n", bond_version);
248 bond_info_show_master(seq);
249 } else
250 bond_info_show_slave(seq, v);
251
252 return 0;
253}
254
255static const struct seq_operations bond_info_seq_ops = {
256 .start = bond_info_seq_start,
257 .next = bond_info_seq_next,
258 .stop = bond_info_seq_stop,
259 .show = bond_info_seq_show,
260};
261
262void bond_create_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) {
268 bond->proc_entry = proc_create_seq_data(bond_dev->name, 0444,
269 bn->proc_dir, &bond_info_seq_ops, bond);
270 if (bond->proc_entry == NULL)
271 netdev_warn(bond_dev, "Cannot create /proc/net/%s/%s\n",
272 DRV_NAME, bond_dev->name);
273 else
274 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
275 }
276}
277
278void bond_remove_proc_entry(struct bonding *bond)
279{
280 struct net_device *bond_dev = bond->dev;
281 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
282
283 if (bn->proc_dir && bond->proc_entry) {
284 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
285 memset(bond->proc_file_name, 0, IFNAMSIZ);
286 bond->proc_entry = NULL;
287 }
288}
289
290/* Create the bonding directory under /proc/net, if doesn't exist yet.
291 * Caller must hold rtnl_lock.
292 */
293void __net_init bond_create_proc_dir(struct bond_net *bn)
294{
295 if (!bn->proc_dir) {
296 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
297 if (!bn->proc_dir)
298 pr_warn("Warning: Cannot create /proc/net/%s\n",
299 DRV_NAME);
300 }
301}
302
303/* Destroy the bonding directory under /proc/net, if empty.
304 * Caller must hold rtnl_lock.
305 */
306void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
307{
308 if (bn->proc_dir) {
309 remove_proc_entry(DRV_NAME, bn->net->proc_net);
310 bn->proc_dir = NULL;
311 }
312}