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 <net/bonding.h>
8 static void *bond_info_seq_start(struct seq_file
*seq
, loff_t
*pos
)
11 struct bonding
*bond
= seq
->private;
12 struct list_head
*iter
;
19 return SEQ_START_TOKEN
;
21 bond_for_each_slave_rcu(bond
, slave
, iter
)
28 static void *bond_info_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
30 struct bonding
*bond
= seq
->private;
31 struct list_head
*iter
;
36 if (v
== SEQ_START_TOKEN
)
37 return bond_first_slave_rcu(bond
);
39 bond_for_each_slave_rcu(bond
, slave
, iter
) {
49 static void bond_info_seq_stop(struct seq_file
*seq
, void *v
)
55 static void bond_info_show_master(struct seq_file
*seq
)
57 struct bonding
*bond
= seq
->private;
58 const struct bond_opt_value
*optval
;
59 struct slave
*curr
, *primary
;
62 curr
= rcu_dereference(bond
->curr_active_slave
);
64 seq_printf(seq
, "Bonding Mode: %s",
65 bond_mode_name(BOND_MODE(bond
)));
67 if (BOND_MODE(bond
) == BOND_MODE_ACTIVEBACKUP
&&
68 bond
->params
.fail_over_mac
) {
69 optval
= bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC
,
70 bond
->params
.fail_over_mac
);
71 seq_printf(seq
, " (fail_over_mac %s)", optval
->string
);
74 seq_printf(seq
, "\n");
76 if (bond_mode_uses_xmit_hash(bond
)) {
77 optval
= bond_opt_get_val(BOND_OPT_XMIT_HASH
,
78 bond
->params
.xmit_policy
);
79 seq_printf(seq
, "Transmit Hash Policy: %s (%d)\n",
80 optval
->string
, bond
->params
.xmit_policy
);
83 if (bond_uses_primary(bond
)) {
84 primary
= rcu_dereference(bond
->primary_slave
);
85 seq_printf(seq
, "Primary Slave: %s",
86 primary
? primary
->dev
->name
: "None");
88 optval
= bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT
,
89 bond
->params
.primary_reselect
);
90 seq_printf(seq
, " (primary_reselect %s)",
94 seq_printf(seq
, "\nCurrently Active Slave: %s\n",
95 (curr
) ? curr
->dev
->name
: "None");
98 seq_printf(seq
, "MII Status: %s\n", netif_carrier_ok(bond
->dev
) ?
100 seq_printf(seq
, "MII Polling Interval (ms): %d\n", bond
->params
.miimon
);
101 seq_printf(seq
, "Up Delay (ms): %d\n",
102 bond
->params
.updelay
* bond
->params
.miimon
);
103 seq_printf(seq
, "Down Delay (ms): %d\n",
104 bond
->params
.downdelay
* bond
->params
.miimon
);
107 /* ARP information */
108 if (bond
->params
.arp_interval
> 0) {
110 seq_printf(seq
, "ARP Polling Interval (ms): %d\n",
111 bond
->params
.arp_interval
);
113 seq_printf(seq
, "ARP IP target/s (n.n.n.n form):");
115 for (i
= 0; (i
< BOND_MAX_ARP_TARGETS
); i
++) {
116 if (!bond
->params
.arp_targets
[i
])
119 seq_printf(seq
, ",");
120 seq_printf(seq
, " %pI4", &bond
->params
.arp_targets
[i
]);
123 seq_printf(seq
, "\n");
126 if (BOND_MODE(bond
) == BOND_MODE_8023AD
) {
127 struct ad_info ad_info
;
129 seq_puts(seq
, "\n802.3ad info\n");
130 seq_printf(seq
, "LACP rate: %s\n",
131 (bond
->params
.lacp_fast
) ? "fast" : "slow");
132 seq_printf(seq
, "Min links: %d\n", bond
->params
.min_links
);
133 optval
= bond_opt_get_val(BOND_OPT_AD_SELECT
,
134 bond
->params
.ad_select
);
135 seq_printf(seq
, "Aggregator selection policy (ad_select): %s\n",
138 if (__bond_3ad_get_active_agg_info(bond
, &ad_info
)) {
139 seq_printf(seq
, "bond %s has no active aggregator\n",
142 seq_printf(seq
, "Active Aggregator Info:\n");
144 seq_printf(seq
, "\tAggregator ID: %d\n",
145 ad_info
.aggregator_id
);
146 seq_printf(seq
, "\tNumber of ports: %d\n",
148 seq_printf(seq
, "\tActor Key: %d\n",
150 seq_printf(seq
, "\tPartner Key: %d\n",
151 ad_info
.partner_key
);
152 seq_printf(seq
, "\tPartner Mac Address: %pM\n",
153 ad_info
.partner_system
);
158 static void bond_info_show_slave(struct seq_file
*seq
,
159 const struct slave
*slave
)
161 struct bonding
*bond
= seq
->private;
163 seq_printf(seq
, "\nSlave Interface: %s\n", slave
->dev
->name
);
164 seq_printf(seq
, "MII Status: %s\n", bond_slave_link_status(slave
->link
));
165 if (slave
->speed
== SPEED_UNKNOWN
)
166 seq_printf(seq
, "Speed: %s\n", "Unknown");
168 seq_printf(seq
, "Speed: %d Mbps\n", slave
->speed
);
170 if (slave
->duplex
== DUPLEX_UNKNOWN
)
171 seq_printf(seq
, "Duplex: %s\n", "Unknown");
173 seq_printf(seq
, "Duplex: %s\n", slave
->duplex
? "full" : "half");
175 seq_printf(seq
, "Link Failure Count: %u\n",
176 slave
->link_failure_count
);
178 seq_printf(seq
, "Permanent HW addr: %pM\n", slave
->perm_hwaddr
);
179 seq_printf(seq
, "Slave queue ID: %d\n", slave
->queue_id
);
181 if (BOND_MODE(bond
) == BOND_MODE_8023AD
) {
182 const struct port
*port
= &SLAVE_AD_INFO(slave
)->port
;
183 const struct aggregator
*agg
= port
->aggregator
;
186 seq_printf(seq
, "Aggregator ID: %d\n",
187 agg
->aggregator_identifier
);
188 seq_printf(seq
, "Actor Churn State: %s\n",
189 bond_3ad_churn_desc(port
->sm_churn_actor_state
));
190 seq_printf(seq
, "Partner Churn State: %s\n",
191 bond_3ad_churn_desc(port
->sm_churn_partner_state
));
192 seq_printf(seq
, "Actor Churned Count: %d\n",
193 port
->churn_actor_count
);
194 seq_printf(seq
, "Partner Churned Count: %d\n",
195 port
->churn_partner_count
);
197 seq_puts(seq
, "details actor lacp pdu:\n");
198 seq_printf(seq
, " system priority: %d\n",
199 port
->actor_system_priority
);
200 seq_printf(seq
, " port key: %d\n",
201 port
->actor_oper_port_key
);
202 seq_printf(seq
, " port priority: %d\n",
203 port
->actor_port_priority
);
204 seq_printf(seq
, " port number: %d\n",
205 port
->actor_port_number
);
206 seq_printf(seq
, " port state: %d\n",
207 port
->actor_oper_port_state
);
209 seq_puts(seq
, "details partner lacp pdu:\n");
210 seq_printf(seq
, " system priority: %d\n",
211 port
->partner_oper
.system_priority
);
212 seq_printf(seq
, " oper key: %d\n",
213 port
->partner_oper
.key
);
214 seq_printf(seq
, " port priority: %d\n",
215 port
->partner_oper
.port_priority
);
216 seq_printf(seq
, " port number: %d\n",
217 port
->partner_oper
.port_number
);
218 seq_printf(seq
, " port state: %d\n",
219 port
->partner_oper
.port_state
);
221 seq_puts(seq
, "Aggregator ID: N/A\n");
226 static int bond_info_seq_show(struct seq_file
*seq
, void *v
)
228 if (v
== SEQ_START_TOKEN
) {
229 seq_printf(seq
, "%s\n", bond_version
);
230 bond_info_show_master(seq
);
232 bond_info_show_slave(seq
, v
);
237 static const struct seq_operations bond_info_seq_ops
= {
238 .start
= bond_info_seq_start
,
239 .next
= bond_info_seq_next
,
240 .stop
= bond_info_seq_stop
,
241 .show
= bond_info_seq_show
,
244 static int bond_info_open(struct inode
*inode
, struct file
*file
)
246 struct seq_file
*seq
;
249 res
= seq_open(file
, &bond_info_seq_ops
);
251 /* recover the pointer buried in proc_dir_entry data */
252 seq
= file
->private_data
;
253 seq
->private = PDE_DATA(inode
);
259 static const struct file_operations bond_info_fops
= {
260 .owner
= THIS_MODULE
,
261 .open
= bond_info_open
,
264 .release
= seq_release
,
267 void bond_create_proc_entry(struct bonding
*bond
)
269 struct net_device
*bond_dev
= bond
->dev
;
270 struct bond_net
*bn
= net_generic(dev_net(bond_dev
), bond_net_id
);
273 bond
->proc_entry
= proc_create_data(bond_dev
->name
,
274 S_IRUGO
, bn
->proc_dir
,
275 &bond_info_fops
, bond
);
276 if (bond
->proc_entry
== NULL
)
277 netdev_warn(bond_dev
, "Cannot create /proc/net/%s/%s\n",
278 DRV_NAME
, bond_dev
->name
);
280 memcpy(bond
->proc_file_name
, bond_dev
->name
, IFNAMSIZ
);
284 void bond_remove_proc_entry(struct bonding
*bond
)
286 struct net_device
*bond_dev
= bond
->dev
;
287 struct bond_net
*bn
= net_generic(dev_net(bond_dev
), bond_net_id
);
289 if (bn
->proc_dir
&& bond
->proc_entry
) {
290 remove_proc_entry(bond
->proc_file_name
, bn
->proc_dir
);
291 memset(bond
->proc_file_name
, 0, IFNAMSIZ
);
292 bond
->proc_entry
= NULL
;
296 /* Create the bonding directory under /proc/net, if doesn't exist yet.
297 * Caller must hold rtnl_lock.
299 void __net_init
bond_create_proc_dir(struct bond_net
*bn
)
302 bn
->proc_dir
= proc_mkdir(DRV_NAME
, bn
->net
->proc_net
);
304 pr_warn("Warning: Cannot create /proc/net/%s\n",
309 /* Destroy the bonding directory under /proc/net, if empty.
310 * Caller must hold rtnl_lock.
312 void __net_exit
bond_destroy_proc_dir(struct bond_net
*bn
)
315 remove_proc_entry(DRV_NAME
, bn
->net
->proc_net
);