Skip to content

Commit cf6b8e1

Browse files
scottfeldmandavem330
authored andcommitted
bridge: add API to notify bridge driver of learned FBD on offloaded device
When the swdev device learns a new mac/vlan on a port, it sends some async notification to the driver and the driver installs an FDB in the device. To give a holistic system view, the learned mac/vlan should be reflected in the bridge's FBD table, so the user, using normal iproute2 cmds, can view what is currently learned by the device. This API on the bridge driver gives a way for the swdev driver to install an FBD entry in the bridge FBD table. (And remove one). This is equivalent to the device running these cmds: bridge fdb [add|del] <mac> dev <dev> vid <vlan id> master This patch needs some extra eyeballs for review, in paricular around the locking and contexts. Signed-off-by: Scott Feldman <sfeldma@gmail.com> Signed-off-by: Jiri Pirko <jiri@resnulli.us> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 38dcf35 commit cf6b8e1

4 files changed

Lines changed: 111 additions & 2 deletions

File tree

‎include/linux/if_bridge.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __use
3737
typedef int br_should_route_hook_t(struct sk_buff *skb);
3838
extern br_should_route_hook_t __rcu *br_should_route_hook;
3939

40+
#if IS_ENABLED(CONFIG_BRIDGE)
41+
int br_fdb_external_learn_add(struct net_device *dev,
42+
const unsigned char *addr, u16 vid);
43+
int br_fdb_external_learn_del(struct net_device *dev,
44+
const unsigned char *addr, u16 vid);
45+
#else
46+
static inline int br_fdb_external_learn_add(struct net_device *dev,
47+
const unsigned char *addr, u16 vid)
48+
{
49+
return 0;
50+
}
51+
static inline int br_fdb_external_learn_del(struct net_device *dev,
52+
const unsigned char *addr, u16 vid)
53+
{
54+
return 0;
55+
}
56+
#endif
57+
4058
#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
4159
int br_multicast_list_adjacent(struct net_device *dev,
4260
struct list_head *br_ip_list);

‎include/uapi/linux/neighbour.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum {
3838
#define NTF_SELF 0x02
3939
#define NTF_MASTER 0x04
4040
#define NTF_PROXY 0x08 /* == ATF_PUBL */
41+
#define NTF_EXT_LEARNED 0x10
4142
#define NTF_ROUTER 0x80
4243

4344
/*

‎net/bridge/br_fdb.c‎

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct hlist_head *head,
481481
fdb->is_local = 0;
482482
fdb->is_static = 0;
483483
fdb->added_by_user = 0;
484+
fdb->added_by_external_learn = 0;
484485
fdb->updated = fdb->used = jiffies;
485486
hlist_add_head_rcu(&fdb->hlist, head);
486487
}
@@ -613,7 +614,7 @@ static int fdb_fill_info(struct sk_buff *skb, const struct net_bridge *br,
613614
ndm->ndm_family = AF_BRIDGE;
614615
ndm->ndm_pad1 = 0;
615616
ndm->ndm_pad2 = 0;
616-
ndm->ndm_flags = 0;
617+
ndm->ndm_flags = fdb->added_by_external_learn ? NTF_EXT_LEARNED : 0;
617618
ndm->ndm_type = 0;
618619
ndm->ndm_ifindex = fdb->dst ? fdb->dst->dev->ifindex : br->dev->ifindex;
619620
ndm->ndm_state = fdb_to_nud(fdb);
@@ -983,3 +984,91 @@ void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p)
983984
}
984985
}
985986
}
987+
988+
int br_fdb_external_learn_add(struct net_device *dev,
989+
const unsigned char *addr, u16 vid)
990+
{
991+
struct net_bridge_port *p;
992+
struct net_bridge *br;
993+
struct hlist_head *head;
994+
struct net_bridge_fdb_entry *fdb;
995+
int err = 0;
996+
997+
rtnl_lock();
998+
999+
p = br_port_get_rtnl(dev);
1000+
if (!p) {
1001+
pr_info("bridge: %s not a bridge port\n", dev->name);
1002+
err = -EINVAL;
1003+
goto err_rtnl_unlock;
1004+
}
1005+
1006+
br = p->br;
1007+
1008+
spin_lock_bh(&br->hash_lock);
1009+
1010+
head = &br->hash[br_mac_hash(addr, vid)];
1011+
fdb = fdb_find(head, addr, vid);
1012+
if (!fdb) {
1013+
fdb = fdb_create(head, p, addr, vid);
1014+
if (!fdb) {
1015+
err = -ENOMEM;
1016+
goto err_unlock;
1017+
}
1018+
fdb->added_by_external_learn = 1;
1019+
fdb_notify(br, fdb, RTM_NEWNEIGH);
1020+
} else if (fdb->added_by_external_learn) {
1021+
/* Refresh entry */
1022+
fdb->updated = fdb->used = jiffies;
1023+
} else if (!fdb->added_by_user) {
1024+
/* Take over SW learned entry */
1025+
fdb->added_by_external_learn = 1;
1026+
fdb->updated = jiffies;
1027+
fdb_notify(br, fdb, RTM_NEWNEIGH);
1028+
}
1029+
1030+
err_unlock:
1031+
spin_unlock_bh(&br->hash_lock);
1032+
err_rtnl_unlock:
1033+
rtnl_unlock();
1034+
1035+
return err;
1036+
}
1037+
EXPORT_SYMBOL(br_fdb_external_learn_add);
1038+
1039+
int br_fdb_external_learn_del(struct net_device *dev,
1040+
const unsigned char *addr, u16 vid)
1041+
{
1042+
struct net_bridge_port *p;
1043+
struct net_bridge *br;
1044+
struct hlist_head *head;
1045+
struct net_bridge_fdb_entry *fdb;
1046+
int err = 0;
1047+
1048+
rtnl_lock();
1049+
1050+
p = br_port_get_rtnl(dev);
1051+
if (!p) {
1052+
pr_info("bridge: %s not a bridge port\n", dev->name);
1053+
err = -EINVAL;
1054+
goto err_rtnl_unlock;
1055+
}
1056+
1057+
br = p->br;
1058+
1059+
spin_lock_bh(&br->hash_lock);
1060+
1061+
head = &br->hash[br_mac_hash(addr, vid)];
1062+
fdb = fdb_find(head, addr, vid);
1063+
if (fdb && fdb->added_by_external_learn)
1064+
fdb_delete(br, fdb);
1065+
else
1066+
err = -ENOENT;
1067+
1068+
spin_unlock_bh(&br->hash_lock);
1069+
err_rtnl_unlock:
1070+
rtnl_unlock();
1071+
1072+
return err;
1073+
}
1074+
EXPORT_SYMBOL(br_fdb_external_learn_del);

‎net/bridge/br_private.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ struct net_bridge_fdb_entry
100100
mac_addr addr;
101101
unsigned char is_local:1,
102102
is_static:1,
103-
added_by_user:1;
103+
added_by_user:1,
104+
added_by_external_learn:1;
104105
__u16 vlan_id;
105106
};
106107

0 commit comments

Comments
 (0)