]>
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> | |
5 | #include "bonding.h" | |
6 | ||
7 | ||
bd33acc3 AW |
8 | static 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; | |
9caff1e7 | 13 | struct list_head *iter; |
bd33acc3 | 14 | struct slave *slave; |
9caff1e7 | 15 | loff_t off = 0; |
bd33acc3 AW |
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 | ||
9caff1e7 | 24 | bond_for_each_slave(bond, slave, iter) |
bd33acc3 AW |
25 | if (++off == *pos) |
26 | return slave; | |
bd33acc3 AW |
27 | |
28 | return NULL; | |
29 | } | |
30 | ||
31 | static 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) | |
dec1e90e | 38 | return bond_first_slave(bond); |
bd33acc3 | 39 | |
dec1e90e | 40 | if (bond_is_last_slave(bond, slave)) |
41 | return NULL; | |
42 | slave = bond_next_slave(bond, slave); | |
bd33acc3 | 43 | |
dec1e90e | 44 | return slave; |
bd33acc3 AW |
45 | } |
46 | ||
47 | static void bond_info_seq_stop(struct seq_file *seq, void *v) | |
48 | __releases(&bond->lock) | |
49 | __releases(RCU) | |
50 | { | |
51 | struct bonding *bond = seq->private; | |
52 | ||
53 | read_unlock(&bond->lock); | |
54 | rcu_read_unlock(); | |
55 | } | |
56 | ||
57 | static void bond_info_show_master(struct seq_file *seq) | |
58 | { | |
59 | struct bonding *bond = seq->private; | |
60 | struct slave *curr; | |
61 | int i; | |
62 | ||
63 | read_lock(&bond->curr_slave_lock); | |
64 | curr = bond->curr_active_slave; | |
65 | read_unlock(&bond->curr_slave_lock); | |
66 | ||
67 | seq_printf(seq, "Bonding Mode: %s", | |
68 | bond_mode_name(bond->params.mode)); | |
69 | ||
70 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP && | |
71 | bond->params.fail_over_mac) | |
72 | seq_printf(seq, " (fail_over_mac %s)", | |
73 | fail_over_mac_tbl[bond->params.fail_over_mac].modename); | |
74 | ||
75 | seq_printf(seq, "\n"); | |
76 | ||
77 | if (bond->params.mode == BOND_MODE_XOR || | |
78 | bond->params.mode == BOND_MODE_8023AD) { | |
79 | seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", | |
80 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, | |
81 | bond->params.xmit_policy); | |
82 | } | |
83 | ||
84 | if (USES_PRIMARY(bond->params.mode)) { | |
85 | seq_printf(seq, "Primary Slave: %s", | |
86 | (bond->primary_slave) ? | |
87 | bond->primary_slave->dev->name : "None"); | |
88 | if (bond->primary_slave) | |
89 | seq_printf(seq, " (primary_reselect %s)", | |
90 | pri_reselect_tbl[bond->params.primary_reselect].modename); | |
91 | ||
92 | seq_printf(seq, "\nCurrently Active Slave: %s\n", | |
93 | (curr) ? curr->dev->name : "None"); | |
94 | } | |
95 | ||
96 | seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ? | |
97 | "up" : "down"); | |
98 | seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); | |
99 | seq_printf(seq, "Up Delay (ms): %d\n", | |
100 | bond->params.updelay * bond->params.miimon); | |
101 | seq_printf(seq, "Down Delay (ms): %d\n", | |
102 | bond->params.downdelay * bond->params.miimon); | |
103 | ||
104 | ||
105 | /* ARP information */ | |
106 | if (bond->params.arp_interval > 0) { | |
107 | int printed = 0; | |
108 | seq_printf(seq, "ARP Polling Interval (ms): %d\n", | |
109 | bond->params.arp_interval); | |
110 | ||
111 | seq_printf(seq, "ARP IP target/s (n.n.n.n form):"); | |
112 | ||
113 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { | |
114 | if (!bond->params.arp_targets[i]) | |
115 | break; | |
116 | if (printed) | |
117 | seq_printf(seq, ","); | |
118 | seq_printf(seq, " %pI4", &bond->params.arp_targets[i]); | |
119 | printed = 1; | |
120 | } | |
121 | seq_printf(seq, "\n"); | |
122 | } | |
123 | ||
124 | if (bond->params.mode == BOND_MODE_8023AD) { | |
125 | struct ad_info ad_info; | |
126 | ||
127 | seq_puts(seq, "\n802.3ad info\n"); | |
128 | seq_printf(seq, "LACP rate: %s\n", | |
129 | (bond->params.lacp_fast) ? "fast" : "slow"); | |
655f8919 | 130 | seq_printf(seq, "Min links: %d\n", bond->params.min_links); |
bd33acc3 AW |
131 | seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", |
132 | ad_select_tbl[bond->params.ad_select].modename); | |
133 | ||
318debd8 | 134 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
bd33acc3 AW |
135 | seq_printf(seq, "bond %s has no active aggregator\n", |
136 | bond->dev->name); | |
137 | } else { | |
138 | seq_printf(seq, "Active Aggregator Info:\n"); | |
139 | ||
140 | seq_printf(seq, "\tAggregator ID: %d\n", | |
141 | ad_info.aggregator_id); | |
142 | seq_printf(seq, "\tNumber of ports: %d\n", | |
143 | ad_info.ports); | |
144 | seq_printf(seq, "\tActor Key: %d\n", | |
145 | ad_info.actor_key); | |
146 | seq_printf(seq, "\tPartner Key: %d\n", | |
147 | ad_info.partner_key); | |
148 | seq_printf(seq, "\tPartner Mac Address: %pM\n", | |
149 | ad_info.partner_system); | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
df2bcc4a AW |
154 | static const char *bond_slave_link_status(s8 link) |
155 | { | |
156 | static const char * const status[] = { | |
157 | [BOND_LINK_UP] = "up", | |
158 | [BOND_LINK_FAIL] = "going down", | |
159 | [BOND_LINK_DOWN] = "down", | |
160 | [BOND_LINK_BACK] = "going back", | |
161 | }; | |
162 | ||
163 | return status[link]; | |
164 | } | |
165 | ||
bd33acc3 AW |
166 | static 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); | |
df2bcc4a | 172 | seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link)); |
589665f5 | 173 | if (slave->speed == SPEED_UNKNOWN) |
98f41f69 WP |
174 | seq_printf(seq, "Speed: %s\n", "Unknown"); |
175 | else | |
176 | seq_printf(seq, "Speed: %d Mbps\n", slave->speed); | |
177 | ||
589665f5 | 178 | if (slave->duplex == DUPLEX_UNKNOWN) |
98f41f69 WP |
179 | seq_printf(seq, "Duplex: %s\n", "Unknown"); |
180 | else | |
181 | seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); | |
182 | ||
bd33acc3 AW |
183 | seq_printf(seq, "Link Failure Count: %u\n", |
184 | slave->link_failure_count); | |
185 | ||
186 | seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr); | |
187 | ||
188 | if (bond->params.mode == BOND_MODE_8023AD) { | |
189 | const struct aggregator *agg | |
190 | = SLAVE_AD_INFO(slave).port.aggregator; | |
191 | ||
192 | if (agg) | |
193 | seq_printf(seq, "Aggregator ID: %d\n", | |
194 | agg->aggregator_identifier); | |
195 | else | |
196 | seq_puts(seq, "Aggregator ID: N/A\n"); | |
197 | } | |
198 | seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); | |
199 | } | |
200 | ||
201 | static int bond_info_seq_show(struct seq_file *seq, void *v) | |
202 | { | |
203 | if (v == SEQ_START_TOKEN) { | |
204 | seq_printf(seq, "%s\n", bond_version); | |
205 | bond_info_show_master(seq); | |
206 | } else | |
207 | bond_info_show_slave(seq, v); | |
208 | ||
209 | return 0; | |
210 | } | |
211 | ||
212 | static const struct seq_operations bond_info_seq_ops = { | |
213 | .start = bond_info_seq_start, | |
214 | .next = bond_info_seq_next, | |
215 | .stop = bond_info_seq_stop, | |
216 | .show = bond_info_seq_show, | |
217 | }; | |
218 | ||
219 | static int bond_info_open(struct inode *inode, struct file *file) | |
220 | { | |
221 | struct seq_file *seq; | |
bd33acc3 AW |
222 | int res; |
223 | ||
224 | res = seq_open(file, &bond_info_seq_ops); | |
225 | if (!res) { | |
226 | /* recover the pointer buried in proc_dir_entry data */ | |
227 | seq = file->private_data; | |
d9dda78b | 228 | seq->private = PDE_DATA(inode); |
bd33acc3 AW |
229 | } |
230 | ||
231 | return res; | |
232 | } | |
233 | ||
234 | static const struct file_operations bond_info_fops = { | |
235 | .owner = THIS_MODULE, | |
236 | .open = bond_info_open, | |
237 | .read = seq_read, | |
238 | .llseek = seq_lseek, | |
239 | .release = seq_release, | |
240 | }; | |
241 | ||
242 | void bond_create_proc_entry(struct bonding *bond) | |
243 | { | |
244 | struct net_device *bond_dev = bond->dev; | |
245 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | |
246 | ||
247 | if (bn->proc_dir) { | |
248 | bond->proc_entry = proc_create_data(bond_dev->name, | |
249 | S_IRUGO, bn->proc_dir, | |
250 | &bond_info_fops, bond); | |
251 | if (bond->proc_entry == NULL) | |
252 | pr_warning("Warning: Cannot create /proc/net/%s/%s\n", | |
253 | DRV_NAME, bond_dev->name); | |
254 | else | |
255 | memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); | |
256 | } | |
257 | } | |
258 | ||
259 | void bond_remove_proc_entry(struct bonding *bond) | |
260 | { | |
261 | struct net_device *bond_dev = bond->dev; | |
262 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); | |
263 | ||
264 | if (bn->proc_dir && bond->proc_entry) { | |
265 | remove_proc_entry(bond->proc_file_name, bn->proc_dir); | |
266 | memset(bond->proc_file_name, 0, IFNAMSIZ); | |
267 | bond->proc_entry = NULL; | |
268 | } | |
269 | } | |
270 | ||
271 | /* Create the bonding directory under /proc/net, if doesn't exist yet. | |
272 | * Caller must hold rtnl_lock. | |
273 | */ | |
274 | void __net_init bond_create_proc_dir(struct bond_net *bn) | |
275 | { | |
276 | if (!bn->proc_dir) { | |
277 | bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); | |
278 | if (!bn->proc_dir) | |
279 | pr_warning("Warning: cannot create /proc/net/%s\n", | |
280 | DRV_NAME); | |
281 | } | |
282 | } | |
283 | ||
284 | /* Destroy the bonding directory under /proc/net, if empty. | |
285 | * Caller must hold rtnl_lock. | |
286 | */ | |
287 | void __net_exit bond_destroy_proc_dir(struct bond_net *bn) | |
288 | { | |
289 | if (bn->proc_dir) { | |
290 | remove_proc_entry(DRV_NAME, bn->net->proc_net); | |
291 | bn->proc_dir = NULL; | |
292 | } | |
293 | } |