bridge enhancements for net-next
Subsystems (4)
cover bridge enhancements for net-next
These patches add more netlink support for bridge.
It is possible to do basic configuration bridge with just netlink. Later enhancements will add statistics and parameters.
The intention is to switch to pure netlink in future and support RSTP and deprecate the old ioctl, sysfs and STP code.
PATCH 1/7 bridge: change arguments to fdb_create
Later patch provides ability to create non-local static entry. To make this easier move the updating of the flag values to after the code that creates entry.
net/bridge/br_fdb.c +10 -8
@@ -320,8 +320,7 @@ static inline struct net_bridge_fdb_entrstatic struct net_bridge_fdb_entry *fdb_create (struct hlist_head *head,struct net_bridge_port *source, -const unsigned char *addr, -int is_local) +const unsigned char *addr) {struct net_bridge_fdb_entry *fdb;
@@ -329,10 +328,9 @@ static struct net_bridge_fdb_entry *fdb_if (fdb) {memcpy (fdb->addr.addr, addr,ETH_ALEN ); fdb->dst = source; - fdb->is_local = is_local; - fdb->is_static = is_local; + fdb->is_local =0 ; + fdb->is_static =0 ; fdb->ageing_timer = jiffies; -hlist_add_head_rcu (&fdb->hlist, head); }return fdb;
@@ -360,12 +358,15 @@ static int fdb_insert(struct net_bridgefdb_delete (fdb); } -if (!fdb_create (head, source, addr,1 )) + fdb =fdb_create (head, source, addr); +if (!fdb)return -ENOMEM ; + fdb->is_local = fdb->is_static =1 ;return 0 ; } +/* Add entry for local address of interface */ int br_fdb_insert (struct net_bridge *br,struct net_bridge_port *source,const unsigned char *addr) {
@@ -407,8 +408,9 @@ void br_fdb_update(struct net_bridge *br } }else {spin_lock (&br->hash_lock); -if (!fdb_find (head, addr)) -fdb_create (head, source, addr,0 ); +if (likely (!fdb_find (head, addr))) +fdb_create (head, source, addr); +/* else we lose race and someone else inserts * it first, don't bother updating */
PATCH 2/7 bridge: track last used time in forwarding table
In reply to Stephen HemmingerAdds tracking the last used time in forwarding table. Rename ageing_timer to updated to better describe it.
--- net/bridge/br_fdb.c | 10 +++++----- net/bridge/br_input.c | 5 +++-- net/bridge/br_private.h | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-)
net/bridge/br_fdb.c +5 -5
@@ -62,7 +62,7 @@ static inline int has_expired(const stru const struct net_bridge_fdb_entry *fdb) {return !fdb->is_static && -time_before_eq (fdb->ageing_timer +hold_time (br), jiffies); +time_before_eq (fdb->updated +hold_time (br), jiffies); }static inline int br_mac_hash (const unsigned char *mac)
@@ -140,7 +140,7 @@ void br_fdb_cleanup(unsigned long _data)unsigned long this_timer;if (f->is_static)continue ; - this_timer = f->ageing_timer + delay; + this_timer = f->updated + delay;if (time_before_eq (this_timer, jiffies))fdb_delete (f);else if (time_before (this_timer, next_timer))
@@ -293,7 +293,7 @@ int br_fdb_fillbuf(struct net_bridge *br fe->is_local = f->is_local;if (!f->is_static) - fe->ageing_timer_value =jiffies_to_clock_t (jiffies - f->ageing_timer); + fe->ageing_timer_value =jiffies_to_clock_t (jiffies - f->updated); ++fe; ++num; }
@@ -330,7 +330,7 @@ static struct net_bridge_fdb_entry *fdb_ fdb->dst = source; fdb->is_local =0 ; fdb->is_static =0 ; - fdb->ageing_timer = jiffies; + fdb->updated = fdb->used = jiffies;hlist_add_head_rcu (&fdb->hlist, head); }return fdb;
@@ -404,7 +404,7 @@ void br_fdb_update(struct net_bridge *br }else {/* fastpath: update of existing entry */ fdb->dst = source; - fdb->ageing_timer = jiffies; + fdb->updated = jiffies; } }else {spin_lock (&br->hash_lock);
net/bridge/br_input.c +3 -2
@@ -98,9 +98,10 @@ int br_handle_frame_finish(struct sk_buf }if (skb) { -if (dst) +if (dst) { + dst->used = jiffies;br_forward (dst->dst, skb, skb2); -else + }else br_flood_forward (br, skb, skb2); }
net/bridge/br_private.h +2 -1
@@ -64,7 +64,8 @@ struct net_bridge_fdb_entrystruct net_bridge_port *dst;struct rcu_head rcu; -unsigned long ageing_timer; +unsigned long updated; +unsigned long used;mac_addr addr;unsigned char is_local;unsigned char is_static;
PATCH 3/7 bridge: split rcu and no-rcu cases of fdb lookup
In reply to Stephen HemmingerIn some cases, look up of forward database entry is done with RCU; and for others no RCU is needed because of locking. Split the two cases into two differnt loops (and take off inline).
net/bridge/br_fdb.c +16 -3
@@ -305,8 +305,21 @@ int br_fdb_fillbuf(struct net_bridge *brreturn num; } -static inline struct net_bridge_fdb_entry *fdb_find (struct hlist_head *head, -const unsigned char *addr) +static struct net_bridge_fdb_entry *fdb_find (struct hlist_head *head, +const unsigned char *addr) +{ +struct hlist_node *h; +struct net_bridge_fdb_entry *fdb; + +hlist_for_each_entry (fdb, h, head, hlist) { +if (!compare_ether_addr (fdb->addr.addr, addr)) +return fdb; + } +return NULL ; +} + +static struct net_bridge_fdb_entry *fdb_find_rcu (struct hlist_head *head, +const unsigned char *addr) {struct hlist_node *h;struct net_bridge_fdb_entry *fdb;
@@ -393,7 +406,7 @@ void br_fdb_update(struct net_bridge *br source->state == BR_STATE_FORWARDING))return ; - fdb =fdb_find (head, addr); + fdb =fdb_find_rcu (head, addr);if (likely (fdb)) {/* attempt to update an entry for a local interface */ if (unlikely (fdb->is_local)) {
PATCH 4/7 bridge: add netlink notification on forward entry changes
In reply to Stephen HemmingerThis allows applications to query and monitor bridge forwarding table in the same method used for neighbor table. The forward table entries are returned in same structure format as used by the ioctl. If more information is desired in future, the netlink method is extensible.
Example (using bridge extensions to iproute2)
# br monitor
--- net/bridge/br_fdb.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ net/bridge/br_netlink.c | 1 net/bridge/br_private.h | 1 3 files changed, 127 insertions(+)
net/bridge/br_fdb.c +125 -0
@@ -28,6 +28,7 @@static struct kmem_cache *br_fdb_cache__read_mostly ;static int fdb_insert (struct net_bridge *br,struct net_bridge_port *source,const unsigned char *addr); +static void fdb_notify (const struct net_bridge_fdb_entry *,int );static u32 fdb_salt__read_mostly ;
@@ -81,6 +82,7 @@ static void fdb_rcu_free(struct rcu_headstatic inline void fdb_delete (struct net_bridge_fdb_entry *f) { +fdb_notify (f,RTM_DELNEIGH );hlist_del_rcu (&f->hlist);call_rcu (&f->rcu, fdb_rcu_free); }
@@ -345,6 +347,7 @@ static struct net_bridge_fdb_entry *fdb_ fdb->is_static =0 ; fdb->updated = fdb->used = jiffies;hlist_add_head_rcu (&fdb->hlist, head); +fdb_notify (fdb,RTM_NEWNEIGH ); }return fdb; }
@@ -430,3 +433,125 @@ void br_fdb_update(struct net_bridge *brspin_unlock (&br->hash_lock); } } + +static int fdb_to_nud (const struct net_bridge_fdb_entry *fdb) +{ +if (fdb->is_local) +return NUD_PERMANENT ; +else if (fdb->is_static) +return NUD_NOARP ; +else if (has_expired (fdb->dst->br, fdb)) +return NUD_STALE ; +else +return NUD_REACHABLE ; +} + +static int fdb_fill_info (struct sk_buff *skb, +const struct net_bridge_fdb_entry *fdb, +u32 pid,u32 seq,int type,unsigned int flags) +{ +unsigned long now = jiffies; +struct nda_cacheinfo ci; +struct nlmsghdr *nlh; +struct ndmsg *ndm; + + nlh =nlmsg_put (skb, pid, seq, type,sizeof (*ndm), flags); +if (nlh ==NULL ) +return -EMSGSIZE ; + + + ndm =nlmsg_data (nlh); + ndm->ndm_family =AF_BRIDGE ; + ndm->ndm_pad1 =0 ; + ndm->ndm_pad2 =0 ; + ndm->ndm_flags =0 ; + ndm->ndm_type =0 ; + ndm->ndm_ifindex = fdb->dst->dev->ifindex; + ndm->ndm_state =fdb_to_nud (fdb); + +NLA_PUT (skb,NDA_LLADDR ,ETH_ALEN , &fdb->addr); + + ci.ndm_used =jiffies_to_clock_t (now - fdb->used); + ci.ndm_confirmed =0 ; + ci.ndm_updated =jiffies_to_clock_t (now - fdb->updated); + ci.ndm_refcnt =0 ; +NLA_PUT (skb,NDA_CACHEINFO ,sizeof (ci), &ci); + +return nlmsg_end (skb, nlh); + +nla_put_failure: +nlmsg_cancel (skb, nlh); +return -EMSGSIZE ; +} + +static inline size_t fdb_nlmsg_size (void ) +{ +return NLMSG_ALIGN (sizeof (struct ndmsg )) + +nla_total_size (ETH_ALEN )/* NDA_LLADDR */ + +nla_total_size (sizeof (struct nda_cacheinfo )); +} + +static void fdb_notify (const struct net_bridge_fdb_entry *fdb,int type) +{ +struct net *net =dev_net (fdb->dst->dev); +struct sk_buff *skb; +int err = -ENOBUFS ; + + skb =nlmsg_new (fdb_nlmsg_size (),GFP_ATOMIC ); +if (skb ==NULL ) + goto errout; + + err =fdb_fill_info (skb, fdb,0 ,0 , type,0 ); +if (err <0 ) { +/* -EMSGSIZE implies BUG in fdb_nlmsg_size() */ +WARN_ON (err == -EMSGSIZE ); +kfree_skb (skb); + goto errout; + } +rtnl_notify (skb, net,0 ,RTNLGRP_NEIGH ,NULL ,GFP_ATOMIC ); +return ; +errout: +if (err <0 ) +rtnl_set_sk_err (net,RTNLGRP_NEIGH , err); +} + +/* Dump information about entries, in response to GETNEIGH */ +int br_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb) +{ +struct net *net =sock_net (skb->sk); +struct net_device *dev; +int idx =0 ; + +rcu_read_lock (); +for_each_netdev_rcu (net, dev) { +struct net_bridge *br =netdev_priv (dev); +int i; + +if (!(dev->priv_flags &IFF_EBRIDGE )) +continue ; + +for (i =0 ; i <BR_HASH_SIZE ; i++) { +struct hlist_node *h; +struct net_bridge_fdb_entry *f; + +hlist_for_each_entry_rcu (f, h, &br->hash[i], hlist) { +if (idx < cb->args[0 ]) + goto skip; + +if (fdb_fill_info (skb, f, +NETLINK_CB (cb->skb).pid, + cb->nlh->nlmsg_seq, +RTM_NEWNEIGH , +NLM_F_MULTI ) <0 ) +break ; +skip: + ++idx; + } + } + } +rcu_read_unlock (); + + cb->args[0 ] = idx; + +return skb->len; +}
net/bridge/br_private.h +1 -0
@@ -354,6 +354,7 @@ extern int br_fdb_insert(struct net_bridextern void br_fdb_update (struct net_bridge *br,struct net_bridge_port *source,const unsigned char *addr); +extern int br_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb);/* br_forward.c */ extern void br_deliver(const struct net_bridge_port *to,
net/bridge/br_netlink.c +1 -0
@@ -196,6 +196,7 @@ int __init br_netlink_init(void)/* Only the first call to __rtnl_register can fail */ __rtnl_register (PF_BRIDGE ,RTM_SETLINK , br_rtm_setlink,NULL ); +__rtnl_register (PF_BRIDGE ,RTM_GETNEIGH ,NULL , br_fdb_dump);return 0 ; }
PATCH 5/7 bridge: allow creating/deleting fdb entries via netlink
In reply to Stephen HemmingerUse RTM_NEWNEIGH and RTM_DELNEIGH to allow updating of entries in bridge forwarding table. This allows manipulating static entries which is not possible with existing tools.
Example (using bridge extensions to iproute2)
# br fdb add 00:02:03:04:05:06 dev eth0
--- net/bridge/br_fdb.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ net/bridge/br_netlink.c | 3 + net/bridge/br_private.h | 2 3 files changed, 144 insertions(+)
net/bridge/br_fdb.c +139 -0
@@ -555,3 +555,142 @@ skip:return skb->len; } + +/* Create new static fdb entry */ +static int fdb_add_entry (struct net_bridge_port *source,const __u8 *addr, +__u16 state) +{ +struct net_bridge *br = source->br; +struct hlist_head *head = &br->hash[br_mac_hash (addr)]; +struct net_bridge_fdb_entry *fdb; + + fdb =fdb_find (head, addr); +if (fdb) +return -EEXIST ; + + fdb =fdb_create (head, source, addr); +if (!fdb) +return -ENOMEM ; + +if (state &NUD_PERMANENT ) + fdb->is_local = fdb->is_static =1 ; +else if (state &NUD_NOARP ) + fdb->is_static =1 ; +return 0 ; +} + +/* Add new permanent fdb entry with RTM_NEWNEIGH */ +int br_fdb_add (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) +{ +struct net *net =sock_net (skb->sk); +struct ndmsg *ndm; +struct nlattr *tb[NDA_MAX +1 ]; +struct net_device *dev; +struct net_bridge_port *p; +const __u8 *addr; +int err; + +ASSERT_RTNL (); + err =nlmsg_parse (nlh,sizeof (*ndm), tb,NDA_MAX ,NULL ); +if (err <0 ) +return err; + + ndm =nlmsg_data (nlh); +if (ndm->ndm_ifindex ==0 ) { +pr_info ("bridge: RTM_NEWNEIGH with invalid ifindex\n" ); +return -EINVAL ; + } + + dev =__dev_get_by_index (net, ndm->ndm_ifindex); +if (dev ==NULL ) { +pr_info ("bridge: RTM_NEWNEIGH with unknown ifindex\n" ); +return -ENODEV ; + } + +if (!tb[NDA_LLADDR ] ||nla_len (tb[NDA_LLADDR ]) !=ETH_ALEN ) { +pr_info ("bridge: RTM_NEWNEIGH with invalid address\n" ); +return -EINVAL ; + } + + addr =nla_data (tb[NDA_LLADDR ]); +if (!is_valid_ether_addr (addr)) { +pr_info ("bridge: RTM_NEWNEIGH with invalid ether address\n" ); +return -EINVAL ; + } + + p =br_port_get_rtnl (dev); +if (p ==NULL ) { +pr_info ("bridge: RTM_NEWNEIGH %s not a bridge port\n" , + dev->name); +return -EINVAL ; + } + +spin_lock_bh (&p->br->hash_lock); + err =fdb_add_entry (p, addr, ndm->ndm_state); +spin_unlock_bh (&p->br->hash_lock); + +return err; +} + +static int fdb_delete_by_addr (struct net_bridge_port *p,const u8 *addr) +{ +struct net_bridge *br = p->br; +struct hlist_head *head = &br->hash[br_mac_hash (addr)]; +struct net_bridge_fdb_entry *fdb; + + fdb =fdb_find (head, addr); +if (!fdb) +return -ENOENT ; + +fdb_delete (fdb); +return 0 ; +} + +/* Remove neighbor entry with RTM_DELNEIGH */ +int br_fdb_delete (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg) +{ +struct net *net =sock_net (skb->sk); +struct ndmsg *ndm; +struct net_bridge_port *p; +struct nlattr *llattr; +const __u8 *addr; +struct net_device *dev; +int err; + +ASSERT_RTNL (); +if (nlmsg_len (nlh) <sizeof (*ndm)) +return -EINVAL ; + + ndm =nlmsg_data (nlh); +if (ndm->ndm_ifindex ==0 ) { +pr_info ("bridge: RTM_DELNEIGH with invalid ifindex\n" ); +return -EINVAL ; + } + + dev =__dev_get_by_index (net, ndm->ndm_ifindex); +if (dev ==NULL ) { +pr_info ("bridge: RTM_DELNEIGH with unknown ifindex\n" ); +return -ENODEV ; + } + + llattr =nlmsg_find_attr (nlh,sizeof (*ndm),NDA_LLADDR ); +if (llattr ==NULL ||nla_len (llattr) !=ETH_ALEN ) { +pr_info ("bridge: RTM_DELNEIGH with invalid address\n" ); +return -EINVAL ; + } + + addr =nla_data (llattr); + + p =br_port_get_rtnl (dev); +if (p ==NULL ) { +pr_info ("bridge: RTM_DELNEIGH %s not a bridge port\n" , + dev->name); +return -EINVAL ; + } + +spin_lock_bh (&p->br->hash_lock); + err =fdb_delete_by_addr (p, addr); +spin_unlock_bh (&p->br->hash_lock); + +return err; +}
net/bridge/br_netlink.c +3 -0
@@ -196,6 +196,9 @@ int __init br_netlink_init(void)/* Only the first call to __rtnl_register can fail */ __rtnl_register (PF_BRIDGE ,RTM_SETLINK , br_rtm_setlink,NULL ); + +__rtnl_register (PF_BRIDGE ,RTM_NEWNEIGH , br_fdb_add,NULL ); +__rtnl_register (PF_BRIDGE ,RTM_DELNEIGH , br_fdb_delete,NULL );__rtnl_register (PF_BRIDGE ,RTM_GETNEIGH ,NULL , br_fdb_dump);return 0 ;
net/bridge/br_private.h +2 -0
@@ -355,6 +355,8 @@ extern void br_fdb_update(struct net_bristruct net_bridge_port *source, const unsigned char *addr);extern int br_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb); +extern int br_fdb_add (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg); +extern int br_fdb_delete (struct sk_buff *skb,struct nlmsghdr *nlh,void *arg);/* br_forward.c */ extern void br_deliver(const struct net_bridge_port *to,
Re: [PATCH 5/7] bridge: allow creating/deleting fdb entries via netlink
Hello all,
I would appreciate if someone can elaborate about "bridge extensions to iproute2" mentioned here.
I downloaded latest iproute2 git tree and did not find it there. googling for it did not gave much info about it.
I will appreciate if someone can tell who develop it, what is the status, site, repository tree, etc.
rgs,
Kevin
Quoted 190 lines · Stephen Hemminger
Use
RTM_NEWNEIGHandRTM_DELNEIGHto allow updating of entries in bridge forwarding table. This allows manipulating static entries which is not possible with existing tools.Example (using bridge extensions to iproute2)
# br fdb add 00:02:03:04:05:06 dev eth0Signed-off-by Stephen Hemminger <[email protected]>---
net/bridge/br_fdb.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++net/bridge/br_netlink.c| 3 +
net/bridge/br_private.h | 23 files changed, 144 insertions(+)net/bridge/br_fdb.c 2011-03-22 10:25:01.057042585 -0700 renamed from net/bridge/br_fdb.c 2011-03-22 10:25:00.329008182 -0700 +139
-0@@ -555,3 +555,142 @@ skip: return skb->len; } + +/* Create new static fdb entry */ +static int fdb_add_entry(struct net_bridge_port *source, const __u8 *addr, + __u16 state) +{ + struct net_bridge *br = source->br; + struct hlist_head *head = &br->hash[br_mac_hash(addr)]; + struct net_bridge_fdb_entry *fdb; + + fdb = fdb_find(head, addr); + if (fdb) + return -EEXIST; + + fdb = fdb_create(head, source, addr); + if (!fdb) + return -ENOMEM; + + if (state & NUD_PERMANENT) + fdb->is_local = fdb->is_static = 1; + else if (state & NUD_NOARP) + fdb->is_static = 1; + return 0; +} + +/* Add new permanent fdb entry with RTM_NEWNEIGH */ +int br_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) +{ + struct net *net = sock_net(skb->sk); + struct ndmsg *ndm; + struct nlattr *tb[NDA_MAX+1]; + struct net_device *dev; + struct net_bridge_port *p; + const __u8 *addr; + int err; + + ASSERT_RTNL(); + err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL); + if (err < 0) + return err; + + ndm = nlmsg_data(nlh); + if (ndm->ndm_ifindex == 0) { + pr_info("bridge: RTM_NEWNEIGH with invalid ifindex\n"); + return -EINVAL; + } + + dev = __dev_get_by_index(net, ndm->ndm_ifindex); + if (dev == NULL) { + pr_info("bridge: RTM_NEWNEIGH with unknown ifindex\n"); + return -ENODEV; + } + + if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) { + pr_info("bridge: RTM_NEWNEIGH with invalid address\n"); + return -EINVAL; + } + + addr = nla_data(tb[NDA_LLADDR]); + if (!is_valid_ether_addr(addr)) { + pr_info("bridge: RTM_NEWNEIGH with invalid ether address\n"); + return -EINVAL; + } + + p = br_port_get_rtnl(dev); + if (p == NULL) { + pr_info("bridge: RTM_NEWNEIGH %s not a bridge port\n", + dev->name); + return -EINVAL; + } + + spin_lock_bh(&p->br->hash_lock); + err = fdb_add_entry(p, addr, ndm->ndm_state); + spin_unlock_bh(&p->br->hash_lock); + + return err; +} + +static int fdb_delete_by_addr(struct net_bridge_port *p, const u8 *addr) +{ + struct net_bridge *br = p->br; + struct hlist_head *head = &br->hash[br_mac_hash(addr)]; + struct net_bridge_fdb_entry *fdb; + + fdb = fdb_find(head, addr); + if (!fdb) + return -ENOENT; + + fdb_delete(fdb); + return 0; +} + +/* Remove neighbor entry with RTM_DELNEIGH */ +int br_fdb_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) +{ + struct net *net = sock_net(skb->sk); + struct ndmsg *ndm; + struct net_bridge_port *p; + struct nlattr *llattr; + const __u8 *addr; + struct net_device *dev; + int err; + + ASSERT_RTNL(); + if (nlmsg_len(nlh) < sizeof(*ndm)) + return -EINVAL; + + ndm = nlmsg_data(nlh); + if (ndm->ndm_ifindex == 0) { + pr_info("bridge: RTM_DELNEIGH with invalid ifindex\n"); + return -EINVAL; + } + + dev = __dev_get_by_index(net, ndm->ndm_ifindex); + if (dev == NULL) { + pr_info("bridge: RTM_DELNEIGH with unknown ifindex\n"); + return -ENODEV; + } + + llattr = nlmsg_find_attr(nlh, sizeof(*ndm), NDA_LLADDR); + if (llattr == NULL || nla_len(llattr) != ETH_ALEN) { + pr_info("bridge: RTM_DELNEIGH with invalid address\n"); + return -EINVAL; + } + + addr = nla_data(llattr); + + p = br_port_get_rtnl(dev); + if (p == NULL) { + pr_info("bridge: RTM_DELNEIGH %s not a bridge port\n", + dev->name); + return -EINVAL; + } + + spin_lock_bh(&p->br->hash_lock); + err = fdb_delete_by_addr(p, addr); + spin_unlock_bh(&p->br->hash_lock); + + return err; +}net/bridge/br_netlink.c 2011-03-22 10:25:01.057042585 -0700 renamed from net/bridge/br_netlink.c 2011-03-22 10:25:00.329008182 -0700 +3
-0@@ -196,6 +196,9 @@ int __init br_netlink_init(void) /* Only the first call to __rtnl_register can fail */ __rtnl_register(PF_BRIDGE, RTM_SETLINK, br_rtm_setlink, NULL); + + __rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, br_fdb_add, NULL); + __rtnl_register(PF_BRIDGE, RTM_DELNEIGH, br_fdb_delete, NULL); __rtnl_register(PF_BRIDGE, RTM_GETNEIGH, NULL, br_fdb_dump); return 0;net/bridge/br_private.h 2011-03-22 10:25:01.057042585 -0700 renamed from net/bridge/br_private.h 2011-03-22 10:25:00.329008182 -0700 +2
-1@@ -355,6 +355,8 @@ extern void br_fdb_update(struct net_bri struct net_bridge_port *source, const unsigned char *addr); extern int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb); +extern int br_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); +extern int br_fdb_delete(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg); /* br_forward.c */ extern void br_deliver(const struct net_bridge_port *to, --To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 5/7] bridge: allow creating/deleting fdb entries via netlink
Quoted 10 lines · On Wed, 5 Oct 2011 21:06:54 +0200 Kevin Wilson <[email protected]> wrote:
Hello all,
I would appreciate if someone can elaborate about "bridge extensions to iproute2" mentioned here.
I downloaded latest iproute2 git tree and did not find it there. googling for it did not gave much info about it.
I will appreciate if someone can tell who develop it, what is the status, site, repository tree, etc.rgs,
Kevin
The patch to handle this was posted, but is not committed to the tree yet.
--
Quoted 1 line
From
8e3d00d0602420dadc3d23877a4995ea3d7496c2Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <[email protected]>
Date: Tue, 4 Oct 2011 09:31:58 -0700
Subject: [PATCH] Add support for bridging control.
This adds a new 'bridge' command which is the bridging equivalent of the ip command.
--- Makefile | 2 +- br/.gitignore | 1 + br/Makefile | 14 +++ br/br_common.h | 13 +++ br/bridge.c | 104 ++++++++++++++++++++++ br/fdb.c | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++ br/link.c | 142 +++++++++++++++++++++++++++++++ br/monitor.c | 138 ++++++++++++++++++++++++++++++ man/man8/bridge.8 | 177 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 835 insertions(+), 1 deletions(-) create mode 100644 br/.gitignore create mode 100644 br/Makefile create mode 100644 br/br_common.h create mode 100644 br/bridge.c create mode 100644 br/fdb.c create mode 100644 br/link.c create mode 100644 br/monitor.c create mode 100644 man/man8/bridge.8
Makefile +1 -1
@@ -33,7 +33,7 @@ CCOPTS = -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall CFLAGS = $(CCOPTS) -I../include $(DEFINES) YACCFLAGS = -d -t -v -SUBDIRS=lib ip tc misc netem genl +SUBDIRS=lib ip tc br misc netem genl LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a LDLIBS += $(LIBNETLINK)
br/.gitignore new file +1 -0
@@ -0,0 +1 @@ +bridge
br/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +BROBJ = bridge.o fdb.o monitor.o link.o + +include ../Config + +all: bridge + +bridge: $(BROBJ) $(LIBNETLINK) + +install: all + install -m 0755 bridge $(DESTDIR)$(SBINDIR) + +clean: + rm -f $(BROBJ) bridge +
br/br_common.h new file +13 -0
@@ -0,0 +1,13 @@ +extern int print_linkinfo (const struct sockaddr_nl *who, +struct nlmsghdr *n, +void *arg); +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_monitor (int argc,char **argv); + +extern int show_stats; +extern int show_detail; +extern int timestamp; +extern struct rtnl_handle rth;
br/bridge.c new file +104 -0
104 lines not on this page · raw message
br/fdb.c new file +245 -0
245 lines not on this page · raw message
br/link.c new file +142 -0
142 lines not on this page · raw message
br/monitor.c new file +138 -0
138 lines not on this page · raw message
man/man8/bridge.8 new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
1.7.6.3
Re: [PATCH 5/7] bridge: allow creating/deleting fdb entries via netlink
Quoted 15 lines · Stephen Hemminger
Quoted 10 lines · On Wed, 5 Oct 2011 21:06:54 +0200 Kevin Wilson <[email protected]> wrote:
Hello all,
I would appreciate if someone can elaborate about "bridge extensions to iproute2" mentioned here.
I downloaded latest iproute2 git tree and did not find it there. googling for it did not gave much info about it.
I will appreciate if someone can tell who develop it, what is the status, site, repository tree, etc.rgs,
KevinThe patch to handle this was posted, but is not committed to the tree yet.
[...]
br/bridge.c line 28
Quoted 4 lines
br/bridge.c new file +4
-0+static void usage (void ) +{ +fprintf (stderr, +"Usage: br [ OPTIONS ] OBJECT { COMMAND | help }\n"
[...]
This and the sub-command usage functions still report the command name as 'br'.
Ben.
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
PATCH 6/7 bridge: allow creating bridge devices with netlink
In reply to Stephen HemmingerAdd netlink device ops to allow creating bridge device via netlink. This works in a manner similar to vlan, macvlan and bonding.
Example:
# ip link add link dev br0 type bridge # ip link del dev br0
The change required rearranging initializtion code to deal with being called by create link. Most of the initialization happens in br_dev_setup, but allocation of stats is done in ndo_init callback to deal with allocation failure. Sysfs setup has to wait until after the network device kobject is registered.
--- net/bridge/br.c | 1 net/bridge/br_device.c | 41 +++++++++++++++++++++++ net/bridge/br_if.c | 83 ++---------------------------------------------- net/bridge/br_netlink.c | 55 +++++++++++++++++++++++++++---- net/bridge/br_notify.c | 6 +++ 5 files changed, 100 insertions(+), 86 deletions(-)
net/bridge/br_device.c +41 -0
@@ -74,6 +74,17 @@ out:return NETDEV_TX_OK ; } +static int br_dev_init (struct net_device *dev) +{ +struct net_bridge *br =netdev_priv (dev); + + br->stats = alloc_percpu(struct br_cpu_netstats); +if (!br->stats) +return -ENOMEM ; + +return 0 ; +} +static int br_dev_open (struct net_device *dev) {struct net_bridge *br =netdev_priv (dev);
@@ -334,6 +345,7 @@ static const struct ethtool_ops br_ethtostatic const struct net_device_ops br_netdev_ops = { .ndo_open = br_dev_open, .ndo_stop = br_dev_stop, + .ndo_init = br_dev_init, .ndo_start_xmit = br_dev_xmit, .ndo_get_stats64 = br_get_stats64, .ndo_set_mac_address = br_set_mac_address,
@@ -357,18 +369,47 @@ static void br_dev_free(struct net_devicfree_netdev (dev); } +static struct device_type br_type = { + .name ="bridge" , +}; +void br_dev_setup (struct net_device *dev) { +struct net_bridge *br =netdev_priv (dev); +random_ether_addr (dev->dev_addr);ether_setup (dev); dev->netdev_ops = &br_netdev_ops; dev->destructor = br_dev_free;SET_ETHTOOL_OPS (dev, &br_ethtool_ops); +SET_NETDEV_DEVTYPE (dev, &br_type); dev->tx_queue_len =0 ; dev->priv_flags =IFF_EBRIDGE ; dev->features =NETIF_F_SG |NETIF_F_FRAGLIST |NETIF_F_HIGHDMA |NETIF_F_GSO_MASK |NETIF_F_NO_CSUM |NETIF_F_LLTX |NETIF_F_NETNS_LOCAL |NETIF_F_GSO |NETIF_F_HW_VLAN_TX ; + + br->dev = dev; +spin_lock_init (&br->lock); +INIT_LIST_HEAD (&br->port_list); +spin_lock_init (&br->hash_lock); + + br->bridge_id.prio[0 ] =0x80 ; + br->bridge_id.prio[1 ] =0x00 ; + +memcpy (br->group_addr, br_group_address,ETH_ALEN ); + + br->feature_mask = dev->features; + br->stp_enabled =BR_NO_STP ; + br->designated_root = br->bridge_id; + br->bridge_max_age = br->max_age =20 *HZ ; + br->bridge_hello_time = br->hello_time =2 *HZ ; + br->bridge_forward_delay = br->forward_delay =15 *HZ ; + br->ageing_time =300 *HZ ; + +br_netfilter_rtable_init (br); +br_stp_timer_init (br); +br_multicast_init (br); }
net/bridge/br_netlink.c +47 -8
80 lines not on this page · raw message
net/bridge/br_if.c +5 -78
103 lines not on this page · raw message
net/bridge/br.c +1 -0
@@ -104,3 +104,4 @@ module_init(br_init) module_exit(br_deinit) MODULE_LICENSE("GPL");MODULE_VERSION (BR_VERSION ); +MODULE_ALIAS_RTNL_LINK ("bridge" );
net/bridge/br_notify.c +6 -0
@@ -36,6 +36,12 @@ static int br_device_event(struct notifistruct net_bridge *br;int err; +/* register of bridge completed, add sysfs entries */ +if ((dev->priv_flags &&IFF_EBRIDGE ) && event ==NETDEV_REGISTER ) { +br_sysfs_addbr (dev); +return NOTIFY_DONE ; + } +/* not a port of a bridge */ p =br_port_get_rtnl (dev);if (!p)
PATCH 7/7 bridge: range check STP parameters
In reply to Stephen HemmingerApply restrictions on STP parameters based 802.1D 1998 standard.
* Fixes missing locking in set path cost ioctl
* Uses common code for both ioctl and sysfs
This is based on an earlier patch Sasikanth V but with overhaul.
Note:
1. It does NOT enforce the restriction on the relationship max_age and forward delay or hello time because in existing implementation these are set as independant operations.
2. If STP is disabled, there is no restriction on forward delay
3. No restriction on holding time because users use Linux code to act as hub or be sticky.
4. Although standard allow 0-255, Linux only allows 0-63 for port priority because more bits are reserved for port number.
--- net/bridge/br_ioctl.c | 40 ++++++++---------------------------- net/bridge/br_private.h | 13 ++++++++--- net/bridge/br_private_stp.h | 13 +++++++++++ net/bridge/br_stp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ net/bridge/br_stp_if.c | 21 +++++++++++++++---- net/bridge/br_sysfs_br.c | 39 ++--------------------------------- net/bridge/br_sysfs_if.c | 26 +++++++---------------- 7 files changed, 107 insertions(+), 93 deletions(-)
net/bridge/br_ioctl.c +9 -31
@@ -181,40 +181,19 @@ static int old_dev_ioctl(struct net_deviif (!capable (CAP_NET_ADMIN ))return -EPERM ; -spin_lock_bh (&br->lock); - br->bridge_forward_delay =clock_t_to_jiffies (args[1 ]); -if (br_is_root_bridge (br)) - br->forward_delay = br->bridge_forward_delay; -spin_unlock_bh (&br->lock); -return 0 ; +return br_set_forward_delay (br, args[1 ]);case BRCTL_SET_BRIDGE_HELLO_TIME : - { -unsigned long t =clock_t_to_jiffies (args[1 ]);if (!capable (CAP_NET_ADMIN ))return -EPERM ; -if (t <HZ ) -return -EINVAL ; - -spin_lock_bh (&br->lock); - br->bridge_hello_time = t; -if (br_is_root_bridge (br)) - br->hello_time = br->bridge_hello_time; -spin_unlock_bh (&br->lock); -return 0 ; - } +return br_set_hello_time (br, args[1 ]);case BRCTL_SET_BRIDGE_MAX_AGE :if (!capable (CAP_NET_ADMIN ))return -EPERM ; -spin_lock_bh (&br->lock); - br->bridge_max_age =clock_t_to_jiffies (args[1 ]); -if (br_is_root_bridge (br)) - br->max_age = br->bridge_max_age; -spin_unlock_bh (&br->lock); -return 0 ; +return br_set_max_age (br, args[1 ]);case BRCTL_SET_AGEING_TIME :if (!capable (CAP_NET_ADMIN ))
@@ -275,19 +254,16 @@ static int old_dev_ioctl(struct net_devicase BRCTL_SET_PORT_PRIORITY : {struct net_bridge_port *p; -int ret =0 ; +int ret;if (!capable (CAP_NET_ADMIN ))return -EPERM ; -if (args[2 ] >= (1 <<(16 -BR_PORT_BITS ))) -return -ERANGE ; -spin_lock_bh (&br->lock);if ((p =br_get_port (br, args[1 ])) ==NULL ) ret = -EINVAL ;else -br_stp_set_port_priority (p, args[2 ]); + ret =br_stp_set_port_priority (p, args[2 ]);spin_unlock_bh (&br->lock);return ret; }
@@ -295,15 +271,17 @@ static int old_dev_ioctl(struct net_devicase BRCTL_SET_PATH_COST : {struct net_bridge_port *p; -int ret =0 ; +int ret;if (!capable (CAP_NET_ADMIN ))return -EPERM ; +spin_lock_bh (&br->lock);if ((p =br_get_port (br, args[1 ])) ==NULL ) ret = -EINVAL ;else -br_stp_set_path_cost (p, args[2 ]); + ret =br_stp_set_path_cost (p, args[2 ]); +spin_unlock_bh (&br->lock);return ret; }
net/bridge/br_private.h +9 -4
@@ -495,6 +495,11 @@ extern struct net_bridge_port *br_get_poextern void br_init_port (struct net_bridge_port *p);extern void br_become_designated_port (struct net_bridge_port *p); +extern int br_set_forward_delay (struct net_bridge *br,unsigned long x); +extern int br_set_hello_time (struct net_bridge *br,unsigned long x); +extern int br_set_max_age (struct net_bridge *br,unsigned long x); + +/* br_stp_if.c */ extern void br_stp_enable_bridge (struct net_bridge *br);extern void br_stp_disable_bridge (struct net_bridge *br);
@@ -505,10 +510,10 @@ extern bool br_stp_recalculate_bridge_idextern void br_stp_change_bridge_id (struct net_bridge *br,const unsigned char *a);extern void br_stp_set_bridge_priority (struct net_bridge *br,u16 newprio); -extern void br_stp_set_port_priority (struct net_bridge_port *p, -u8 newprio); -extern void br_stp_set_path_cost (struct net_bridge_port *p, -u32 path_cost); +extern int br_stp_set_port_priority (struct net_bridge_port *p, +unsigned long newprio); +extern int br_stp_set_path_cost (struct net_bridge_port *p, +unsigned long path_cost);extern ssize_t br_show_bridge_id (char *buf,const struct bridge_id *id);/* br_stp_bpdu.c */
net/bridge/br_private_stp.h +13 -0
@@ -16,6 +16,19 @@#define BPDU_TYPE_CONFIG 0#define BPDU_TYPE_TCN 0x80 +/* IEEE 802.1D-1998 timer values */ +#define BR_MIN_HELLO_TIME (1*HZ) +#define BR_MAX_HELLO_TIME (10*HZ) + +#define BR_MIN_FORWARD_DELAY (2*HZ) +#define BR_MAX_FORWARD_DELAY (30*HZ) + +#define BR_MIN_MAX_AGE (6*HZ) +#define BR_MAX_MAX_AGE (40*HZ) + +#define BR_MIN_PATH_COST 1 +#define BR_MAX_PATH_COST 65535 +struct br_config_bpdu {unsigned topology_change:1 ;
net/bridge/br_stp.c +48 -0
51 lines not on this page · raw message
net/bridge/br_stp_if.c +17 -4
@@ -20,7 +20,7 @@/* Port id is composed of priority and port number. -* NB: least significant bits of priority are dropped to +* NB: some bits of priority are dropped to * make room for more ports. */ static inline port_id br_make_port_id (__u8 priority,__u16 port_no)
@@ -29,6 +29,8 @@ static inline port_id br_make_port_id(__ | (port_no & ((1<<BR_PORT_BITS)-1)); } +#define BR_MAX_PORT_PRIORITY ((u16)~0 >> BR_PORT_BITS) +/* called under bridge lock */ void br_init_port (struct net_bridge_port *p) {
@@ -255,10 +257,14 @@ void br_stp_set_bridge_priority(struct n }/* called under bridge lock */ -void br_stp_set_port_priority (struct net_bridge_port *p,u8 newprio) +int br_stp_set_port_priority (struct net_bridge_port *p,unsigned long newprio) { -port_id new_port_id =br_make_port_id (newprio, p->port_no); +port_id new_port_id; + +if (newprio >BR_MAX_PORT_PRIORITY ) +return -ERANGE ; + new_port_id =br_make_port_id (newprio, p->port_no);if (br_is_designated_port (p)) p->designated_port = new_port_id;
@@ -269,14 +275,21 @@ void br_stp_set_port_priority(struct netbr_become_designated_port (p);br_port_state_selection (p->br); } + +return 0 ; }/* called under bridge lock */ -void br_stp_set_path_cost (struct net_bridge_port *p,u32 path_cost) +int br_stp_set_path_cost (struct net_bridge_port *p,unsigned long path_cost) { +if (path_cost <BR_MIN_PATH_COST || + path_cost >BR_MAX_PATH_COST ) +return -ERANGE ; + p->path_cost = path_cost;br_configuration_update (p->br);br_port_state_selection (p->br); +return 0 ; }ssize_t br_show_bridge_id (char *buf,const struct bridge_id *id)
net/bridge/br_sysfs_br.c +3 -36
@@ -43,9 +43,7 @@ static ssize_t store_bridge_parm(structif (endp == buf)return -EINVAL ; -spin_lock_bh (&br->lock); err = (*set)(br, val); -spin_unlock_bh (&br->lock);return err ? err : len; }
@@ -57,20 +55,11 @@ static ssize_t show_forward_delay(structreturn sprintf (buf,"%lu\n" ,jiffies_to_clock_t (br->forward_delay)); } -static int set_forward_delay (struct net_bridge *br,unsigned long val) -{ -unsigned long delay =clock_t_to_jiffies (val); - br->forward_delay = delay; -if (br_is_root_bridge (br)) - br->bridge_forward_delay = delay; -return 0 ; -} -static ssize_t store_forward_delay (struct device *d,struct device_attribute *attr,const char *buf,size_t len) { -return store_bridge_parm (d, buf, len, set_forward_delay); +return store_bridge_parm (d, buf, len, br_set_forward_delay); } static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR, show_forward_delay, store_forward_delay);
@@ -82,24 +71,11 @@ static ssize_t show_hello_time(struct de jiffies_to_clock_t(to_bridge(d)->hello_time)); } -static int set_hello_time (struct net_bridge *br,unsigned long val) -{ -unsigned long t =clock_t_to_jiffies (val); - -if (t <HZ ) -return -EINVAL ; - - br->hello_time = t; -if (br_is_root_bridge (br)) - br->bridge_hello_time = t; -return 0 ; -} -static ssize_t store_hello_time (struct device *d,struct device_attribute *attr,const char *buf,size_t len) { -return store_bridge_parm (d, buf, len, set_hello_time); +return store_bridge_parm (d, buf, len, br_set_hello_time); } static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time, store_hello_time);
@@ -111,19 +87,10 @@ static ssize_t show_max_age(struct devic jiffies_to_clock_t(to_bridge(d)->max_age)); } -static int set_max_age (struct net_bridge *br,unsigned long val) -{ -unsigned long t =clock_t_to_jiffies (val); - br->max_age = t; -if (br_is_root_bridge (br)) - br->bridge_max_age = t; -return 0 ; -} -static ssize_t store_max_age (struct device *d,struct device_attribute *attr,const char *buf,size_t len) { -return store_bridge_parm (d, buf, len, set_max_age); +return store_bridge_parm (d, buf, len, br_set_max_age); } static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age);
net/bridge/br_sysfs_if.c +8 -18
@@ -23,7 +23,7 @@struct brport_attribute {struct attribute attr;ssize_t (*show)(struct net_bridge_port *,char *); -ssize_t (*store)(struct net_bridge_port *,unsigned long ); +int (*store)(struct net_bridge_port *,unsigned long ); };#define BRPORT_ATTR (_name,_mode,_show,_store) \
@@ -38,27 +38,17 @@ static ssize_t show_path_cost(struct net {return sprintf (buf,"%d\n" , p->path_cost); } -static ssize_t store_path_cost (struct net_bridge_port *p,unsigned long v) -{ -br_stp_set_path_cost (p, v); -return 0 ; -} + static BRPORT_ATTR(path_cost, S_IRUGO | S_IWUSR, - show_path_cost, store_path_cost); + show_path_cost, br_stp_set_path_cost);static ssize_t show_priority (struct net_bridge_port *p,char *buf) {return sprintf (buf,"%d\n" , p->priority); } -static ssize_t store_priority (struct net_bridge_port *p,unsigned long v) -{ -if (v >= (1 <<(16 -BR_PORT_BITS ))) -return -ERANGE ; -br_stp_set_port_priority (p, v); -return 0 ; -} + static BRPORT_ATTR(priority, S_IRUGO | S_IWUSR, - show_priority, store_priority); + show_priority, br_stp_set_port_priority);static ssize_t show_designated_root (struct net_bridge_port *p,char *buf) {
@@ -136,7 +126,7 @@ static ssize_t show_hold_timer(struct ne } static BRPORT_ATTR(hold_timer, S_IRUGO, show_hold_timer, NULL); -static ssize_t store_flush (struct net_bridge_port *p,unsigned long v) +static int store_flush (struct net_bridge_port *p,unsigned long v) {br_fdb_delete_by_port (p->br, p,0 );// Don't delete local entry return 0 ;
@@ -148,7 +138,7 @@ static ssize_t show_hairpin_mode(structint hairpin_mode = (p->flags &BR_HAIRPIN_MODE ) ?1 :0 ;return sprintf (buf,"%d\n" , hairpin_mode); } -static ssize_t store_hairpin_mode (struct net_bridge_port *p,unsigned long v) +static int store_hairpin_mode (struct net_bridge_port *p,unsigned long v) {if (v) p->flags |=BR_HAIRPIN_MODE ;
@@ -165,7 +155,7 @@ static ssize_t show_multicast_router(strreturn sprintf (buf,"%d\n" , p->multicast_router); } -static ssize_t store_multicast_router (struct net_bridge_port *p, +static int store_multicast_router (struct net_bridge_port *p,unsigned long v) {return br_multicast_set_port_router (p, v);
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Mon, 04 Apr 2011 17:03:26 -0700
Quoted 6 lines
These patches add more netlink support for bridge.
It is possible to do basic configuration bridge with just netlink. Later enhancements will add statistics and parameters.The intention is to switch to pure netlink in future and support RSTP and deprecate the old ioctl, sysfs and STP code.
Looks good, all applied, thanks Stephen.