bridge: export port_no and port_id via IFA_INFO_DATA
Subsystems (3)
PATCH 1/2 bridge: export port_no and port_id via IFA_INFO_DATA
port_no will be used to get ifindex of a port in user-space, export it togather with port_id.
--- include/uapi/linux/if_link.h | 2 ++ net/bridge/br_netlink.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletions(-)
include/uapi/linux/if_link.h +2 -0
@@ -218,6 +218,8 @@ enum {IFLA_BRPORT_MODE ,/* mode (hairpin) */ IFLA_BRPORT_GUARD ,/* bpdu guard */ IFLA_BRPORT_PROTECT ,/* root port protection */ +IFLA_BRPORT_NO ,/* port no */ +IFLA_BRPORT_ID ,/* port id */ __IFLA_BRPORT_MAX };#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
net/bridge/br_netlink.c +7 -1
@@ -28,6 +28,8 @@ static inline size_t br_port_info_size(void) +nla_total_size (1 )/* IFLA_BRPORT_MODE */ +nla_total_size (1 )/* IFLA_BRPORT_GUARD */ +nla_total_size (1 )/* IFLA_BRPORT_PROTECT */ + +nla_total_size (2 )/* IFLA_BRPORT_NO */ + +nla_total_size (2 )/* IFLA_BRPORT_ID */ +0 ; }
@@ -53,7 +55,9 @@ static int br_port_fill_attrs(struct sk_buff *skb,nla_put_u32 (skb,IFLA_BRPORT_COST , p->path_cost) ||nla_put_u8 (skb,IFLA_BRPORT_MODE , mode) ||nla_put_u8 (skb,IFLA_BRPORT_GUARD , !!(p->flags &BR_BPDU_GUARD )) || - nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK))) +nla_put_u8 (skb,IFLA_BRPORT_PROTECT , !!(p->flags &BR_ROOT_BLOCK )) || +nla_put_u16 (skb,IFLA_BRPORT_NO , p->port_no) || + nla_put_u16(skb, IFLA_BRPORT_ID, p->port_id)) return -EMSGSIZE;return 0 ;
@@ -168,6 +172,8 @@ static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, + [IFLA_BRPORT_NO] = { .type = NLA_U16 }, + [IFLA_BRPORT_ID] = { .type = NLA_U16 }, };/* Change the state of the port and notify spanning tree */
PATCH 2/2 bridge: export multicast database via netlink
This patch exports bridge multicast database via netlink message type RTM_GETMDB. Similar to fdb, but currently bridge-specific. We may need to support modify multicast database too (RTM_{ADD,DEL}MDB).
--- include/uapi/linux/if_bridge.h | 26 ++++++ include/uapi/linux/rtnetlink.h | 3 + net/bridge/Makefile | 2 +- net/bridge/br_mdb.c | 166 ++++++++++++++++++++++++++++++++++++++++ net/bridge/br_multicast.c | 2 + net/bridge/br_private.h | 2 + 6 files changed, 200 insertions(+), 1 deletions(-)
include/uapi/linux/if_bridge.h +26 -0
@@ -116,4 +116,30 @@ enum { __IFLA_BRIDGE_MAX, };#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) + +/* Bridge multicast database attributes +* [MDBA_MDB] = { +* [MDBA_MCADDR] +* [MDBA_BRPORT_NO] +* } +* [MDBA_ROUTER] = { +* [MDBA_BRPORT_NO] +* } +*/ +enum { +MDBA_UNSPEC , +MDBA_MDB , +MDBA_ROUTER , + __MDBA_MAX, +}; +#define MDBA_MAX (__MDBA_MAX - 1) + +enum { +MDBA_MDB_UNSPEC , +MDBA_MCADDR , +MDBA_BRPORT_NO , + __MDBA_MDB_MAX, +}; +#define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1) +#endif /* _UAPI_LINUX_IF_BRIDGE_H */
include/uapi/linux/rtnetlink.h +3 -0
@@ -125,6 +125,9 @@ enum { RTM_GETNETCONF = 82,#define RTM_GETNETCONF RTM_GETNETCONF + RTM_GETMDB = 86, +#define RTM_GETMDB RTM_GETMDB + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
net/bridge/Makefile +1 -1
@@ -12,6 +12,6 @@ bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o bridge-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o -bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o +bridge-$(CONFIG_BRIDGE_IGMP_SNOOPING) += br_multicast.o br_mdb.o obj-$(CONFIG_BRIDGE_NF_EBTABLES) += netfilter/
net/bridge/br_mdb.c new file +166 -0
166 lines not on this page · raw message
net/bridge/br_multicast.c +2 -0
@@ -322,6 +322,7 @@ static int br_mdb_rehash(struct net_bridge_mdb_htable __rcu **mdbp, int max, mdb->size = old ? old->size :0 ; mdb->ver = old ? old->ver ^1 :0 ; + mdb->seq = old ? (old->seq +1 ):0 ;if (!old || elasticity)get_random_bytes (&mdb->secret,sizeof (mdb->secret));
@@ -1584,6 +1585,7 @@ void br_multicast_init(struct net_bridge *br) br_multicast_querier_expired, (unsigned long)br);setup_timer (&br->multicast_query_timer, br_multicast_query_expired, (unsigned long )br); +br_mdb_init (); }void br_multicast_open (struct net_bridge *br)
net/bridge/br_private.h +2 -0
@@ -105,6 +105,7 @@ struct net_bridge_mdb_htableu32 max;u32 secret;u32 ver; +u32 seq; };struct net_bridge_port
@@ -432,6 +433,7 @@ extern int br_multicast_set_port_router(struct net_bridge_port *p,extern int br_multicast_toggle (struct net_bridge *br,unsigned long val);extern int br_multicast_set_querier (struct net_bridge *br,unsigned long val);extern int br_multicast_set_hash_max (struct net_bridge *br,unsigned long val); +extern void br_mdb_init (void );static inline bool br_multicast_is_router (struct net_bridge *br) {
Re: [PATCH net-next v1 2/2] bridge: export multicast database via netlink
Quoted 5 lines · Cong Wang
include/uapi/linux/if_bridge.h +5
-0+enum { +MDBA_UNSPEC , +MDBA_MDB , +MDBA_ROUTER , + __MDBA_MAX,
include/uapi/linux/if_bridge.h enum { · line 143
Quoted 10 lines
include/uapi/linux/if_bridge.h +10
-0+}; +#define MDBA_MAX (__MDBA_MAX - 1) + +enum { +MDBA_MDB_UNSPEC , +MDBA_MCADDR , +MDBA_BRPORT_NO , + __MDBA_MDB_MAX, +}; +#define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1)
So juse use these enums from iproute2 directly instead redefining them.
Quoted 17 lines
net/bridge/br_mdb.c new file +11
-0@@ -0,0 +1,166 @@ +#include <linux/err.h> +#include <linux/if_ether.h> +#include <linux/igmp.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/rculist.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <net/ip.h> +#if IS_ENABLED (CONFIG_IPV6 ) +#include <net/ipv6.h>
net/bridge/br_mdb.c line 21
Quoted 10 lines
net/bridge/br_mdb.c new file +10
-0+#include <net/mld.h> +#include <net/addrconf.h> +#include <net/ip6_checksum.h> +#endif + +#include "br_private.h" + +struct br_port_msg { +int ifindex; +};
Make that __u32 ifindex and move the definition into if_bridge.h so you can reuse it in iproute2.
Quoted 11 lines
net/bridge/br_mdb.c new file +11
-0+static int br_rports_fill_info (struct sk_buff *skb,struct netlink_callback *cb, +u32 seq,struct net_device *dev) +{ +struct net_bridge *br =netdev_priv (dev); +struct net_bridge_port *p; +struct hlist_node *n; +struct nlattr *nest; + +if (!br->multicast_router ||hlist_empty (&br->router_list)) { +printk (KERN_INFO "no router on bridge\n" ); +return 0 ;
net/bridge/br_mdb.c line 43
Quoted 10 lines
net/bridge/br_mdb.c new file +10
-0+ } + + nest =nla_nest_start (skb,MDBA_ROUTER ); +if (nest ==NULL ) +return -EMSGSIZE ; + +hlist_for_each_entry_rcu (p, n, &br->router_list, rlist) { +if (p &&nla_put_u16 (skb,MDBA_BRPORT_NO , p->port_no)) + goto fail; + }
port_no 0 is reserved, right?
We can reduce message size here and make it easier to extend by using p->port_no as the attribute id by doing something like this:
hlist_for_each_entry_rcu(p, n, &br->router_list, rlist)
if (nla_put_flag(skb, p->port_no)) goto fail;
This will result in an empty attribute body for now and if you ever need to include more data you can simply start putting attributes insde that empty body and old users will continue to function.
Quoted 11 lines
net/bridge/br_mdb.c new file +11
-0+static int br_mdb_fill_info (struct sk_buff *skb,struct netlink_callback *cb, +u32 seq,struct net_device *dev) +{ +struct net_bridge *br =netdev_priv (dev); +struct net_bridge_mdb_htable *mdb; +struct nlattr *nest; +unsigned int i; +int s_idx; + +if (br->multicast_disabled) { +printk (KERN_INFO "multicast is disabled on bridge\n" );
net/bridge/br_mdb.c line 72
Quoted 10 lines
net/bridge/br_mdb.c new file +10
-0+return 0 ; + } + + mdb =rcu_dereference (br->mdb); +if (!mdb) { +printk (KERN_INFO "no mdb on bridge\n" ); +return 0 ; + } + + cb->seq = mdb->seq;
I'm not sure how this is supposed to worl. cb->seq may not change throughout the complete dump process or the dump will be interrupted and the user is required to restart.
Each bridge will have its own mdb resulting in a differing seq.
Quoted 26 lines
net/bridge/br_mdb.c new file +26
-0+ s_idx = cb->args[1 ]; +if (s_idx >= mdb->max) +return 0 ; + + nest =nla_nest_start (skb,MDBA_MDB ); +if (nest ==NULL ) +return -EMSGSIZE ; + +for (i = s_idx; i < mdb->max; i++) { +struct hlist_node *h; +struct net_bridge_mdb_entry *mp; +struct net_bridge_port_group *p, **pp; +struct net_bridge_port *port; + +hlist_for_each_entry_rcu (mp, h, &mdb->mhash[i], hlist[mdb->ver]) { +for (pp = &mp->ports; + (p =rcu_dereference (*pp)) !=NULL ; + pp = &p->next) { + port = p->port; +if (port) { +printk (KERN_INFO "port %u, mcaddr: %pI4\n" , port->port_no, &mp->addr.u.ip4); +if (nla_put_u16 (skb,MDBA_BRPORT_NO , port->port_no) || +nla_put_be32 (skb,MDBA_MCADDR , p->addr.u.ip4)) + goto fail; + } + }
net/bridge/br_mdb.c line 108
Quoted 10 lines
net/bridge/br_mdb.c new file +10
-0+ } + } + + cb->args[1 ] = i; +nla_nest_end (skb, nest); +return 0 ; +fail: + cb->args[1 ] = i; +nla_nest_cancel (skb, nest); +return -EMSGSIZE ;
This still relies on the assumption that all of mdb->mhash[] will fit into a single netlink message. Is that guaranteed? If so that would simplify this a lot and you wouldn't have to worry about rehashes at all.
As-is it looks broken, you store an offset into the hash but if you run out of space you trim away the complete nested attribute again and thus offseting will actually result in data loss because that data has never been wired but you will skip over it next time.
You need something like this:
for (i = 0; i < mdb->max; i++) {
[...]
hlist_for_each_entry_rcu(mp, h, &mdb->mhash[i], hlist[mdb->ver]) {
if (idx < s_idx)
goto skip;
hentry = nla_nest_start(...)
if (nla_put_u16(...) ||
nla_put_32(...)) {
nla_nest_cancel(skb, hentry);
err = -EMSGSIZE;
goto out;
}
nla_nest_end(skb, hentry);
skip:
idx++;
}
}out:
cb->args[1] = idx; nla_nest_end(skb, nest); return err;
Quoted 42 lines
net/bridge/br_mdb.c new file +42
-0+} + +static int br_mdb_dump (struct sk_buff *skb,struct netlink_callback *cb) +{ +struct net_device *dev; +struct net *net =sock_net (skb->sk); +struct nlmsghdr *nlh; +u32 seq = cb->nlh->nlmsg_seq; +int idx =0 , s_idx; + + s_idx = cb->args[0 ]; + +rcu_read_lock (); + +for_each_netdev_rcu (net, dev) { +if (dev->priv_flags &IFF_EBRIDGE ) { +struct br_port_msg *bpm; + +if (idx < s_idx) + goto cont; + + nlh =nlmsg_put (skb,NETLINK_CB (cb->skb).portid, + seq,RTM_GETMDB , +sizeof (*bpm),NLM_F_MULTI ); +if (nlh ==NULL ) +break ; + + bpm =nlmsg_data (nlh); + bpm->ifindex = dev->ifindex; +if (br_mdb_fill_info (skb, cb, seq, dev) <0 ) { +printk (KERN_INFO "br_mdb_fill_info failed\n" ); + goto fail; + } +if (br_rports_fill_info (skb, cb, seq, dev) <0 ) { +printk (KERN_INFO "br_rports_fill_info failed\n" ); + goto fail; + } + +nlmsg_end (skb, nlh); +cont: + idx++; + }
net/bridge/br_mdb.c line 160
Quoted 10 lines
net/bridge/br_mdb.c new file +10
-0+ } + +rcu_read_unlock (); + cb->args[0 ] = idx; +return skb->len; + +fail: +rcu_read_unlock (); +nlmsg_cancel (skb, nlh); +return skb->len;
Assuming you implement partial messages as proposed above you don't want to nlmsg_cancel() here. Instead you just want to nlmsg_end() and send out the message with a partial MDB_MDBA and continue where you left off.
Re: [PATCH net-next v1 2/2] bridge: export multicast database via netlink
Quoted 16 lines · Thomas Graf
net/bridge/br_mdb.c line 43
Quoted 9 lines · Cong Wang
net/bridge/br_mdb.c new file +9
-0+ + nest =nla_nest_start (skb,MDBA_ROUTER ); +if (nest ==NULL ) +return -EMSGSIZE ; + +hlist_for_each_entry_rcu (p, n, &br->router_list, rlist) { +if (p &&nla_put_u16 (skb,MDBA_BRPORT_NO , p->port_no)) + goto fail; + }
port_no0 is reserved, right?We can reduce message size here and make it easier to extend by using
p->port_noas the attribute id by doing something like this:
Quoted 7 lines
hlist_for_each_entry_rcu(p, n, &br->router_list, rlist)if (nla_put_flag(skb, p->port_no)) goto fail;This will result in an empty attribute body for now and if you ever need to include more data you can simply start putting attributes insde that empty body and old users will continue to function.
I don't understand this. nla_put_flag() is used to put a flag (only one bit set) into a netlink message, so why should we use it to put p->port_no here? And why port_no 0 matters here?
[...]
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + cb->seq = mdb->seq;I'm not sure how this is supposed to worl.
cb->seqmay not change throughout the complete dump process or the dump will be interrupted and the user is required to restart.Each bridge will have its own mdb resulting in a differing seq.
So I should use net->dev_base_seq + mdb->seq ?
All of the rest suggestions are taken by me.
Thanks for your detailed review!
Re: [PATCH net-next v1 2/2] bridge: export multicast database via netlink
Quoted 3 lines · Cong Wang
I don't understand this.
nla_put_flag()is used to put a flag (only one bit set) into a netlink message, so why should we use it to putp->port_nohere? And whyport_no0 matters here?
nla_put_flag() will simply add a netlink attribute with no payload, i.e. just the header. Assuming that port_no == 0 is invalid the port_no can be used as attribute id as both are 16bit integers.
It will look like this:
MDBA_ROUTERS = {
{
.nla_len = 4,
.nla_type = <port_no_1>,
},
{
.nla_len = 4,
.nla_type = <port_no_2>, }
[...]
}
If you ever need to extend this you can just add payload to the per port attribute and nothing will break.
Quoted 1 line
So I should use
net->dev_base_seq+mdb->seq?
No you can't, mdb->seq is not stable throughout a dump. What you can do is save mdb->seq in cb->args[] and in case you continue dumping from the same mdb in the next call to your dump function you check if it changed and bump cb->seq if it did to trigger an interrupt.
Re: [PATCH net-next v1 2/2] bridge: export multicast database via netlink
Quoted 19 lines · Thomas Graf
Quoted 3 lines · Cong Wang
I don't understand this.
nla_put_flag()is used to put a flag (only one bit set) into a netlink message, so why should we use it to putp->port_nohere? And whyport_no0 matters here?
nla_put_flag()will simply add a netlink attribute with no payload, i.e. just the header. Assuming thatport_no== 0 is invalid theport_nocan be used as attribute id as both are 16bit integers.It will look like this:
MDBA_ROUTERS= {{ .nla_len = 4, .nla_type = <port_no_1>, }, { .nla_len = 4, .nla_type = <port_no_2>,
Quoted 6 lines
}
[...]
}If you ever need to extend this you can just add payload to the per port attribute and nothing will break.
Never mind, I will use port->dev->ifindex instead of port->port_no. This will also make the user-space easier.
Quoted 8 lines
Quoted 2 lines
So I should use
net->dev_base_seq+mdb->seq?No you can't,
mdb->seqis not stable throughout a dump. What you can do is savemdb->seqin cb->args[] and in case you continue dumping from the same mdb in the next call to your dump function you check if it changed and bumpcb->seqif it did to trigger an interrupt.
Ok, will do.
Thanks!
PATCH 1/1 Add mdb command to bridge
In reply to Cong WangSample output:
# ./bridge/bridge mdb bridge dev br0 multicast database: port no 1, multicast addr 224.8.8.9 port no 2, multicast addr 224.8.8.8 router ports: 2
TODO: display device name too
--- bridge/Makefile | 2 +- bridge/br_common.h | 35 ++++++++++ bridge/bridge.c | 1 + bridge/mdb.c | 157 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/rtnetlink.h | 3 + 5 files changed, 197 insertions(+), 1 deletions(-)
bridge/Makefile +1 -1
@@ -1,4 +1,4 @@ -BROBJ = bridge.o fdb.o monitor.o link.o +BROBJ = bridge.o fdb.o monitor.o link.o mdb.o include ../Config
bridge/br_common.h +35 -0
@@ -5,6 +5,7 @@ extern int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);extern int do_fdb (int argc,char **argv); +extern int do_mdb (int argc,char **argv);extern int do_monitor (int argc,char **argv);extern int preferred_family;
@@ -12,3 +13,37 @@ extern int show_stats;extern int show_detail;extern int timestamp;extern struct rtnl_handle rth; + +/* Bridge multicast database attributes +* [MDBA_MDB] = { +* [MDBA_MCADDR] +* [MDBA_BRPORT_NO] +* } +* [MDBA_ROUTER] = { +* [MDBA_BRPORT_NO] +* } +*/ +enum { +MDBA_UNSPEC , +MDBA_MDB , +MDBA_ROUTER , + __MDBA_MAX, +}; +#define MDBA_MAX (__MDBA_MAX - 1) + +enum { +MDBA_MDB_UNSPEC , +MDBA_MCADDR , +MDBA_BRPORT_NO , + __MDBA_MDB_MAX, +}; +#define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1) + +struct br_port_msg { +int ifindex; +}; + +#ifndef MDBA_RTA +#define MDBA_RTA (r) \ + ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct br_port_msg)))) +#endif
bridge/bridge.c +1 -0
@@ -43,6 +43,7 @@ static const struct cmd {int (*func)(int argc,char **argv); } cmds[] = { { "fdb", do_fdb }, + { "mdb", do_mdb }, { "monitor", do_monitor }, { "help", do_help }, { 0 }
bridge/mdb.c new file +157 -0
157 lines not on this page · raw message
include/linux/rtnetlink.h +3 -0
@@ -120,6 +120,9 @@ enum { RTM_SETDCB,#define RTM_SETDCB RTM_SETDCB + RTM_GETMDB = 86, +#define RTM_GETMDB RTM_GETMDB + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
Re: [PATCH iproute2 v1] Add mdb command to bridge
Quoted 40 lines · Cong Wang
bridge/br_common.h +25
-0@@ -5,6 +5,7 @@ extern int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);extern int do_fdb (int argc,char **argv); +extern int do_mdb (int argc,char **argv);extern int do_monitor (int argc,char **argv);extern int preferred_family;@@ -12,3 +13,37 @@ extern int show_stats;extern int show_detail;extern int timestamp;extern struct rtnl_handle rth; + +/* Bridge multicast database attributes +* [MDBA_MDB] = { +* [MDBA_MCADDR] +* [MDBA_BRPORT_NO] +* } +* [MDBA_ROUTER] = { +* [MDBA_BRPORT_NO] +* } +*/ +enum { +MDBA_UNSPEC , +MDBA_MDB , +MDBA_ROUTER , + __MDBA_MAX, +}; +#define MDBA_MAX (__MDBA_MAX - 1) + +enum { +MDBA_MDB_UNSPEC , +MDBA_MCADDR , +MDBA_BRPORT_NO , + __MDBA_MDB_MAX, +};
bridge/br_common.h extern int show_stats; · line 49
Quoted 10 lines
bridge/br_common.h +10
-0+#define MDBA_MDB_MAX (__MDBA_MDB_MAX - 1) + +struct br_port_msg { +int ifindex; +}; + +#ifndef MDBA_RTA +#define MDBA_RTA (r) \ + ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct br_port_msg)))) +#endif
You shouldn't need to duplicate the attribute ids and struct br_port_msg in iproute2. Just put these definitions in a uapi kernel header and include the header from iproute2.
Re: [PATCH iproute2 v1] Add mdb command to bridge
Quoted 4 lines · Thomas Graf
You shouldn't need to duplicate the attribute ids and struct
br_port_msgin iproute2. Just put these definitions in a uapi kernel header and include the header from iproute2.
Right, I was confused by include/linux/rtnetlink.h, thought iproute2 has its own copy of these headers, but they should be exported from kernel.
Thanks!
net/bridge/br_netlink.c static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { · line 179
Quoted 9 lines · Cong Wang
net/bridge/br_netlink.c +2
-0@@ -168,6 +172,8 @@ static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, + [IFLA_BRPORT_NO] = { .type = NLA_U16 }, + [IFLA_BRPORT_ID] = { .type = NLA_U16 }, };/* Change the state of the port and notify spanning tree */
I missed this in the first round. Not much of a point in adding policy entries if the attributes are read-only as in this case.
Quoted 9 lines · Thomas Graf
Quoted 8 lines · Cong Wang
net/bridge/br_netlink.c +2
-0@@ -168,6 +172,8 @@ static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, + [IFLA_BRPORT_NO] = { .type = NLA_U16 }, + [IFLA_BRPORT_ID] = { .type = NLA_U16 }, };
Quoted 4 lines
net/bridge/br_netlink.c static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { · line 179
Quoted 1 line
net/bridge/br_netlink.c +0
-0/* Change the state of the port and notify spanning tree */ I missed this in the first round. Not much of a point in adding policy entries if the attributes are read-only as in this case.
Yeah, remove these lines now.
Quoted 54 lines · On Fri, 30 Nov 2012 17:58:32 +0800 Cong Wang <[email protected]> wrote:
port_nowill be used to get ifindex of a port in user-space, export it togather withport_id.Cc Herbert Xu <[email protected]>Cc Stephen Hemminger <[email protected]>Cc "David S. Miller" <[email protected]>Cc Thomas Graf <[email protected]>Cc Jesper Dangaard Brouer <[email protected]>Signed-off-by Cong Wang <[email protected]>Acked-by Thomas Graf <[email protected]>Signed-off-by Cong Wang <[email protected]>--- include/uapi/linux/if_link.h | 2 ++ net/bridge/br_netlink.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletions(-)include/uapi/linux/if_link.h +2
-0@@ -218,6 +218,8 @@ enum {IFLA_BRPORT_MODE ,/* mode (hairpin) */ IFLA_BRPORT_GUARD ,/* bpdu guard */ IFLA_BRPORT_PROTECT ,/* root port protection */ +IFLA_BRPORT_NO ,/* port no */ +IFLA_BRPORT_ID ,/* port id */ __IFLA_BRPORT_MAX };#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)net/bridge/br_netlink.c +5
-1@@ -28,6 +28,8 @@ static inline size_t br_port_info_size(void) +nla_total_size (1 )/* IFLA_BRPORT_MODE */ +nla_total_size (1 )/* IFLA_BRPORT_GUARD */ +nla_total_size (1 )/* IFLA_BRPORT_PROTECT */ + +nla_total_size (2 )/* IFLA_BRPORT_NO */ + +nla_total_size (2 )/* IFLA_BRPORT_ID */ +0 ; }@@ -53,7 +55,9 @@ static int br_port_fill_attrs(struct sk_buff *skb,nla_put_u32 (skb,IFLA_BRPORT_COST , p->path_cost) ||nla_put_u8 (skb,IFLA_BRPORT_MODE , mode) ||nla_put_u8 (skb,IFLA_BRPORT_GUARD , !!(p->flags &BR_BPDU_GUARD )) || - nla_put_u8(skb, IFLA_BRPORT_PROTECT, !!(p->flags & BR_ROOT_BLOCK))) +nla_put_u8 (skb,IFLA_BRPORT_PROTECT , !!(p->flags &BR_ROOT_BLOCK )) || +nla_put_u16 (skb,IFLA_BRPORT_NO , p->port_no) || + nla_put_u16(skb, IFLA_BRPORT_ID, p->port_id)) return -EMSGSIZE;return 0 ;
net/bridge/br_netlink.c static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { · line 179
Quoted 8 lines
net/bridge/br_netlink.c +2
-0@@ -168,6 +172,8 @@ static const struct nla_policy ifla_brport_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, + [IFLA_BRPORT_NO] = { .type = NLA_U16 }, + [IFLA_BRPORT_ID] = { .type = NLA_U16 }, };/* Change the state of the port and notify spanning tree */
I don't think these are necessary. The device is already available and the relationship can be determined from other messages. This is what RSTP daemon does.
Quoted 4 lines · Stephen Hemminger
I don't think these are necessary. The device is already available and the relationship
can be determined from other messages. This is what RSTP daemon does.
Rethinking about it, I think we can just put port->dev->ifindex instead of port->port_no in the netlink message, so patch 1/2 is not needed at more.
Thanks!