* [PATCH net-next] bonding: show master index when dumping slave info
@ 2025-10-17 3:03 Hangbin Liu
2025-10-17 3:05 ` [PATCH iproute2-next] bond: slave: print master name Hangbin Liu
2025-10-17 6:10 ` [PATCH net-next] bonding: show master index when dumping slave info Nikolay Aleksandrov
0 siblings, 2 replies; 7+ messages in thread
From: Hangbin Liu @ 2025-10-17 3:03 UTC (permalink / raw)
To: netdev
Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Stephen Hemminger,
David Ahern, linux-kselftest, Hangbin Liu
Currently, there is no straightforward way to obtain the master/slave
relationship via netlink. Users have to retrieve all slaves through sysfs
to determine these relationships.
To address this, we can either list all slaves under the bond interface
or display the master index in each slave. Since the number of slaves could
be quite large (e.g., 100+), it is more efficient to show the master
information in the slave entry.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
drivers/net/bonding/bond_netlink.c | 4 ++++
include/uapi/linux/if_link.h | 1 +
2 files changed, 5 insertions(+)
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index 286f11c517f7..ff3f11674a8b 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -29,6 +29,7 @@ static size_t bond_get_slave_size(const struct net_device *bond_dev,
nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */
nla_total_size(sizeof(s32)) + /* IFLA_BOND_SLAVE_PRIO */
nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_ACTOR_PORT_PRIO */
+ nla_total_size(sizeof(u32)) + /* IFLA_BOND_SLAVE_MASTER */
0;
}
@@ -38,6 +39,9 @@ static int bond_fill_slave_info(struct sk_buff *skb,
{
struct slave *slave = bond_slave_get_rtnl(slave_dev);
+ if (nla_put_u32(skb, IFLA_BOND_SLAVE_MASTER, bond_dev->ifindex))
+ goto nla_put_failure;
+
if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
goto nla_put_failure;
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 3b491d96e52e..bad41a1807f7 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -1567,6 +1567,7 @@ enum {
IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE,
IFLA_BOND_SLAVE_PRIO,
IFLA_BOND_SLAVE_ACTOR_PORT_PRIO,
+ IFLA_BOND_SLAVE_MASTER,
__IFLA_BOND_SLAVE_MAX,
};
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH iproute2-next] bond: slave: print master name
2025-10-17 3:03 [PATCH net-next] bonding: show master index when dumping slave info Hangbin Liu
@ 2025-10-17 3:05 ` Hangbin Liu
2025-10-18 8:57 ` Stephen Hemminger
2025-10-17 6:10 ` [PATCH net-next] bonding: show master index when dumping slave info Nikolay Aleksandrov
1 sibling, 1 reply; 7+ messages in thread
From: Hangbin Liu @ 2025-10-17 3:05 UTC (permalink / raw)
To: netdev
Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Stephen Hemminger,
David Ahern, linux-kselftest, Hangbin Liu
Add a new attribute to display the name of the master interface for
each slave.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
ip/iplink_bond_slave.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
index c88100e248dd..55deaadf5fe2 100644
--- a/ip/iplink_bond_slave.c
+++ b/ip/iplink_bond_slave.c
@@ -92,6 +92,17 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t
if (!tb)
return;
+ if (tb[IFLA_BOND_SLAVE_MASTER]) {
+ unsigned int ifindex = rta_getattr_u32(tb[IFLA_BOND_SLAVE_MASTER]);
+
+ if (ifindex) {
+ print_string(PRINT_ANY,
+ "master",
+ "master %s ",
+ ll_index_to_name(ifindex));
+ }
+ }
+
if (tb[IFLA_BOND_SLAVE_STATE])
print_slave_state(f, tb[IFLA_BOND_SLAVE_STATE]);
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH iproute2-next] bond: slave: print master name
2025-10-17 3:05 ` [PATCH iproute2-next] bond: slave: print master name Hangbin Liu
@ 2025-10-18 8:57 ` Stephen Hemminger
0 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2025-10-18 8:57 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, David Ahern,
linux-kselftest
On Fri, 17 Oct 2025 03:05:09 +0000
Hangbin Liu <liuhangbin@gmail.com> wrote:
> diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
> index c88100e248dd..55deaadf5fe2 100644
> --- a/ip/iplink_bond_slave.c
> +++ b/ip/iplink_bond_slave.c
> @@ -92,6 +92,17 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t
> if (!tb)
> return;
>
> + if (tb[IFLA_BOND_SLAVE_MASTER]) {
> + unsigned int ifindex = rta_getattr_u32(tb[IFLA_BOND_SLAVE_MASTER]);
> +
> + if (ifindex) {
> + print_string(PRINT_ANY,
> + "master",
> + "master %s ",
> + ll_index_to_name(ifindex));
> + }
> + }
You should use print_color_string(PRINT_ANY, COLOR_IFNAME, ...) here
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] bonding: show master index when dumping slave info
2025-10-17 3:03 [PATCH net-next] bonding: show master index when dumping slave info Hangbin Liu
2025-10-17 3:05 ` [PATCH iproute2-next] bond: slave: print master name Hangbin Liu
@ 2025-10-17 6:10 ` Nikolay Aleksandrov
2025-10-17 7:26 ` Hangbin Liu
2025-10-17 9:56 ` Jiri Pirko
1 sibling, 2 replies; 7+ messages in thread
From: Nikolay Aleksandrov @ 2025-10-17 6:10 UTC (permalink / raw)
To: Hangbin Liu, netdev
Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Stephen Hemminger,
David Ahern, linux-kselftest
On 10/17/25 06:03, Hangbin Liu wrote:
> Currently, there is no straightforward way to obtain the master/slave
> relationship via netlink. Users have to retrieve all slaves through sysfs
> to determine these relationships.
>
How about IFLA_MASTER? Why not use that?
> To address this, we can either list all slaves under the bond interface
> or display the master index in each slave. Since the number of slaves could
> be quite large (e.g., 100+), it is more efficient to show the master
> information in the slave entry.
>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> drivers/net/bonding/bond_netlink.c | 4 ++++
> include/uapi/linux/if_link.h | 1 +
> 2 files changed, 5 insertions(+)
>
> diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
> index 286f11c517f7..ff3f11674a8b 100644
> --- a/drivers/net/bonding/bond_netlink.c
> +++ b/drivers/net/bonding/bond_netlink.c
> @@ -29,6 +29,7 @@ static size_t bond_get_slave_size(const struct net_device *bond_dev,
> nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE */
> nla_total_size(sizeof(s32)) + /* IFLA_BOND_SLAVE_PRIO */
> nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_ACTOR_PORT_PRIO */
> + nla_total_size(sizeof(u32)) + /* IFLA_BOND_SLAVE_MASTER */
> 0;
> }
>
> @@ -38,6 +39,9 @@ static int bond_fill_slave_info(struct sk_buff *skb,
> {
> struct slave *slave = bond_slave_get_rtnl(slave_dev);
>
> + if (nla_put_u32(skb, IFLA_BOND_SLAVE_MASTER, bond_dev->ifindex))
> + goto nla_put_failure;
> +
> if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
> goto nla_put_failure;
>
> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> index 3b491d96e52e..bad41a1807f7 100644
> --- a/include/uapi/linux/if_link.h
> +++ b/include/uapi/linux/if_link.h
> @@ -1567,6 +1567,7 @@ enum {
> IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE,
> IFLA_BOND_SLAVE_PRIO,
> IFLA_BOND_SLAVE_ACTOR_PORT_PRIO,
> + IFLA_BOND_SLAVE_MASTER,
> __IFLA_BOND_SLAVE_MAX,
> };
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next] bonding: show master index when dumping slave info
2025-10-17 6:10 ` [PATCH net-next] bonding: show master index when dumping slave info Nikolay Aleksandrov
@ 2025-10-17 7:26 ` Hangbin Liu
2025-10-17 9:56 ` Jiri Pirko
1 sibling, 0 replies; 7+ messages in thread
From: Hangbin Liu @ 2025-10-17 7:26 UTC (permalink / raw)
To: Nikolay Aleksandrov
Cc: netdev, Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Stephen Hemminger,
David Ahern, linux-kselftest
On Fri, Oct 17, 2025 at 09:10:09AM +0300, Nikolay Aleksandrov wrote:
> On 10/17/25 06:03, Hangbin Liu wrote:
> > Currently, there is no straightforward way to obtain the master/slave
> > relationship via netlink. Users have to retrieve all slaves through sysfs
> > to determine these relationships.
> >
>
> How about IFLA_MASTER? Why not use that?
Ah, I didn't notice this. We can show the master info directly with this...
# ip link show dummy0
3: dummy0: <BROADCAST,NOARP,SLAVE,UP,LOWER_UP> mtu 1500 qdisc noqueue master bond0 ...
Please ignore this patch.
Thanks
Hangbin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] bonding: show master index when dumping slave info
2025-10-17 6:10 ` [PATCH net-next] bonding: show master index when dumping slave info Nikolay Aleksandrov
2025-10-17 7:26 ` Hangbin Liu
@ 2025-10-17 9:56 ` Jiri Pirko
2025-10-18 9:52 ` Hangbin Liu
1 sibling, 1 reply; 7+ messages in thread
From: Jiri Pirko @ 2025-10-17 9:56 UTC (permalink / raw)
To: Nikolay Aleksandrov
Cc: Hangbin Liu, netdev, Jay Vosburgh, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Stephen Hemminger, David Ahern, linux-kselftest
Fri, Oct 17, 2025 at 08:10:09AM +0200, razor@blackwall.org wrote:
>On 10/17/25 06:03, Hangbin Liu wrote:
>> Currently, there is no straightforward way to obtain the master/slave
>> relationship via netlink. Users have to retrieve all slaves through sysfs
>> to determine these relationships.
>>
>
>How about IFLA_MASTER? Why not use that?
It's been there for a decade. Plus is, it exposes master for all
slave-master devices. Odd that you missed it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next] bonding: show master index when dumping slave info
2025-10-17 9:56 ` Jiri Pirko
@ 2025-10-18 9:52 ` Hangbin Liu
0 siblings, 0 replies; 7+ messages in thread
From: Hangbin Liu @ 2025-10-18 9:52 UTC (permalink / raw)
To: Jiri Pirko
Cc: Nikolay Aleksandrov, netdev, Jay Vosburgh, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Stephen Hemminger, David Ahern, linux-kselftest
On Fri, Oct 17, 2025 at 11:56:55AM +0200, Jiri Pirko wrote:
> Fri, Oct 17, 2025 at 08:10:09AM +0200, razor@blackwall.org wrote:
> >On 10/17/25 06:03, Hangbin Liu wrote:
> >> Currently, there is no straightforward way to obtain the master/slave
> >> relationship via netlink. Users have to retrieve all slaves through sysfs
> >> to determine these relationships.
> >>
> >
> >How about IFLA_MASTER? Why not use that?
>
> It's been there for a decade. Plus is, it exposes master for all
> slave-master devices. Odd that you missed it.
Once, I wanted to find the slaves from a master interface but couldn’t. So I
added it to my to-do list. Later, I noticed that the master information was
already available in the slave, but I forgot about it after long time.
Recently, when I reviewed my to-do list, I realized that printing all slaves
from the master interface seemed impractical. So I tried to list the master
information in the slave again — and forgot about IFLA_MASTER...
Hangbin
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-18 9:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-17 3:03 [PATCH net-next] bonding: show master index when dumping slave info Hangbin Liu
2025-10-17 3:05 ` [PATCH iproute2-next] bond: slave: print master name Hangbin Liu
2025-10-18 8:57 ` Stephen Hemminger
2025-10-17 6:10 ` [PATCH net-next] bonding: show master index when dumping slave info Nikolay Aleksandrov
2025-10-17 7:26 ` Hangbin Liu
2025-10-17 9:56 ` Jiri Pirko
2025-10-18 9:52 ` Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).