1 #include <linux/proc_fs.h>
2 #include <linux/export.h>
3 #include <net/net_namespace.h>
4 #include <net/netns/generic.h>
8 static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
10 __acquires(&bond->lock)
12 struct bonding *bond = seq->private;
17 /* make sure the bond won't be taken away */
19 read_lock(&bond->lock);
22 return SEQ_START_TOKEN;
24 bond_for_each_slave(bond, slave, i) {
32 static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos)
34 struct bonding *bond = seq->private;
35 struct slave *slave = v;
38 if (v == SEQ_START_TOKEN)
39 return bond->first_slave;
43 return (slave == bond->first_slave) ? NULL : slave;
46 static void bond_info_seq_stop(struct seq_file *seq, void *v)
47 __releases(&bond->lock)
50 struct bonding *bond = seq->private;
52 read_unlock(&bond->lock);
56 static void bond_info_show_master(struct seq_file *seq)
58 struct bonding *bond = seq->private;
62 read_lock(&bond->curr_slave_lock);
63 curr = bond->curr_active_slave;
64 read_unlock(&bond->curr_slave_lock);
66 seq_printf(seq, "Bonding Mode: %s",
67 bond_mode_name(bond->params.mode));
69 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP &&
70 bond->params.fail_over_mac)
71 seq_printf(seq, " (fail_over_mac %s)",
72 fail_over_mac_tbl[bond->params.fail_over_mac].modename);
74 seq_printf(seq, "\n");
76 if (bond->params.mode == BOND_MODE_XOR ||
77 bond->params.mode == BOND_MODE_8023AD) {
78 seq_printf(seq, "Transmit Hash Policy: %s (%d)\n",
79 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
80 bond->params.xmit_policy);
83 if (USES_PRIMARY(bond->params.mode)) {
84 seq_printf(seq, "Primary Slave: %s",
85 (bond->primary_slave) ?
86 bond->primary_slave->dev->name : "None");
87 if (bond->primary_slave)
88 seq_printf(seq, " (primary_reselect %s)",
89 pri_reselect_tbl[bond->params.primary_reselect].modename);
91 seq_printf(seq, "\nCurrently Active Slave: %s\n",
92 (curr) ? curr->dev->name : "None");
95 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
97 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
98 seq_printf(seq, "Up Delay (ms): %d\n",
99 bond->params.updelay * bond->params.miimon);
100 seq_printf(seq, "Down Delay (ms): %d\n",
101 bond->params.downdelay * bond->params.miimon);
104 /* ARP information */
105 if (bond->params.arp_interval > 0) {
107 seq_printf(seq, "ARP Polling Interval (ms): %d\n",
108 bond->params.arp_interval);
110 seq_printf(seq, "ARP IP target/s (n.n.n.n form):");
112 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
113 if (!bond->params.arp_targets[i])
116 seq_printf(seq, ",");
117 seq_printf(seq, " %pI4", &bond->params.arp_targets[i]);
120 seq_printf(seq, "\n");
123 if (bond->params.mode == BOND_MODE_8023AD) {
124 struct ad_info ad_info;
126 seq_puts(seq, "\n802.3ad info\n");
127 seq_printf(seq, "LACP rate: %s\n",
128 (bond->params.lacp_fast) ? "fast" : "slow");
129 seq_printf(seq, "Min links: %d\n", bond->params.min_links);
130 seq_printf(seq, "Aggregator selection policy (ad_select): %s\n",
131 ad_select_tbl[bond->params.ad_select].modename);
133 if (__bond_3ad_get_active_agg_info(bond, &ad_info)) {
134 seq_printf(seq, "bond %s has no active aggregator\n",
137 seq_printf(seq, "Active Aggregator Info:\n");
139 seq_printf(seq, "\tAggregator ID: %d\n",
140 ad_info.aggregator_id);
141 seq_printf(seq, "\tNumber of ports: %d\n",
143 seq_printf(seq, "\tActor Key: %d\n",
145 seq_printf(seq, "\tPartner Key: %d\n",
146 ad_info.partner_key);
147 seq_printf(seq, "\tPartner Mac Address: %pM\n",
148 ad_info.partner_system);
153 static const char *bond_slave_link_status(s8 link)
155 static const char * const status[] = {
156 [BOND_LINK_UP] = "up",
157 [BOND_LINK_FAIL] = "going down",
158 [BOND_LINK_DOWN] = "down",
159 [BOND_LINK_BACK] = "going back",
165 static void bond_info_show_slave(struct seq_file *seq,
166 const struct slave *slave)
168 struct bonding *bond = seq->private;
170 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
171 seq_printf(seq, "MII Status: %s\n", bond_slave_link_status(slave->link));
172 if (slave->speed == SPEED_UNKNOWN)
173 seq_printf(seq, "Speed: %s\n", "Unknown");
175 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
177 if (slave->duplex == DUPLEX_UNKNOWN)
178 seq_printf(seq, "Duplex: %s\n", "Unknown");
180 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
182 seq_printf(seq, "Link Failure Count: %u\n",
183 slave->link_failure_count);
185 seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr);
187 if (bond->params.mode == BOND_MODE_8023AD) {
188 const struct aggregator *agg
189 = SLAVE_AD_INFO(slave).port.aggregator;
192 seq_printf(seq, "Aggregator ID: %d\n",
193 agg->aggregator_identifier);
195 seq_puts(seq, "Aggregator ID: N/A\n");
197 seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id);
200 static int bond_info_seq_show(struct seq_file *seq, void *v)
202 if (v == SEQ_START_TOKEN) {
203 seq_printf(seq, "%s\n", bond_version);
204 bond_info_show_master(seq);
206 bond_info_show_slave(seq, v);
211 static const struct seq_operations bond_info_seq_ops = {
212 .start = bond_info_seq_start,
213 .next = bond_info_seq_next,
214 .stop = bond_info_seq_stop,
215 .show = bond_info_seq_show,
218 static int bond_info_open(struct inode *inode, struct file *file)
220 struct seq_file *seq;
223 res = seq_open(file, &bond_info_seq_ops);
225 /* recover the pointer buried in proc_dir_entry data */
226 seq = file->private_data;
227 seq->private = PDE_DATA(inode);
233 static const struct file_operations bond_info_fops = {
234 .owner = THIS_MODULE,
235 .open = bond_info_open,
238 .release = seq_release,
241 void bond_create_proc_entry(struct bonding *bond)
243 struct net_device *bond_dev = bond->dev;
244 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
247 bond->proc_entry = proc_create_data(bond_dev->name,
248 S_IRUGO, bn->proc_dir,
249 &bond_info_fops, bond);
250 if (bond->proc_entry == NULL)
251 pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
252 DRV_NAME, bond_dev->name);
254 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
258 void bond_remove_proc_entry(struct bonding *bond)
260 struct net_device *bond_dev = bond->dev;
261 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
263 if (bn->proc_dir && bond->proc_entry) {
264 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
265 memset(bond->proc_file_name, 0, IFNAMSIZ);
266 bond->proc_entry = NULL;
270 /* Create the bonding directory under /proc/net, if doesn't exist yet.
271 * Caller must hold rtnl_lock.
273 void __net_init bond_create_proc_dir(struct bond_net *bn)
276 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
278 pr_warning("Warning: cannot create /proc/net/%s\n",
283 /* Destroy the bonding directory under /proc/net, if empty.
284 * Caller must hold rtnl_lock.
286 void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
289 remove_proc_entry(DRV_NAME, bn->net->proc_net);