Skip to content

Commit 685fb6a

Browse files
viviendavem330
authored andcommitted
net: dsa: add FDB notifier
Add two new DSA_NOTIFIER_FDB_ADD and DSA_NOTIFIER_FDB_DEL events to notify not only a single switch, but all switches of a the fabric when an FDB entry is added or removed. For the moment, keep the current behavior and ignore other switches. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1faabf7 commit 685fb6a

3 files changed

Lines changed: 66 additions & 16 deletions

File tree

‎net/dsa/dsa_priv.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ enum {
2020
DSA_NOTIFIER_AGEING_TIME,
2121
DSA_NOTIFIER_BRIDGE_JOIN,
2222
DSA_NOTIFIER_BRIDGE_LEAVE,
23+
DSA_NOTIFIER_FDB_ADD,
24+
DSA_NOTIFIER_FDB_DEL,
2325
};
2426

2527
/* DSA_NOTIFIER_AGEING_TIME */
@@ -36,6 +38,14 @@ struct dsa_notifier_bridge_info {
3638
int port;
3739
};
3840

41+
/* DSA_NOTIFIER_FDB_* */
42+
struct dsa_notifier_fdb_info {
43+
const struct switchdev_obj_port_fdb *fdb;
44+
struct switchdev_trans *trans;
45+
int sw_index;
46+
int port;
47+
};
48+
3949
struct dsa_device_ops {
4050
struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
4151
struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,

‎net/dsa/port.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,26 @@ int dsa_port_fdb_add(struct dsa_port *dp,
151151
const struct switchdev_obj_port_fdb *fdb,
152152
struct switchdev_trans *trans)
153153
{
154-
struct dsa_switch *ds = dp->ds;
155-
156-
if (switchdev_trans_ph_prepare(trans)) {
157-
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
158-
return -EOPNOTSUPP;
159-
160-
return ds->ops->port_fdb_prepare(ds, dp->index, fdb, trans);
161-
}
162-
163-
ds->ops->port_fdb_add(ds, dp->index, fdb, trans);
154+
struct dsa_notifier_fdb_info info = {
155+
.sw_index = dp->ds->index,
156+
.port = dp->index,
157+
.trans = trans,
158+
.fdb = fdb,
159+
};
164160

165-
return 0;
161+
return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info);
166162
}
167163

168164
int dsa_port_fdb_del(struct dsa_port *dp,
169165
const struct switchdev_obj_port_fdb *fdb)
170166
{
171-
struct dsa_switch *ds = dp->ds;
172-
173-
if (ds->ops->port_fdb_del)
174-
return -EOPNOTSUPP;
167+
struct dsa_notifier_fdb_info info = {
168+
.sw_index = dp->ds->index,
169+
.port = dp->index,
170+
.fdb = fdb,
171+
};
175172

176-
return ds->ops->port_fdb_del(ds, dp->index, fdb);
173+
return dsa_port_notify(dp, DSA_NOTIFIER_FDB_DEL, &info);
177174
}
178175

179176
int dsa_port_fdb_dump(struct dsa_port *dp, struct switchdev_obj_port_fdb *fdb,

‎net/dsa/switch.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,43 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds,
8484
return 0;
8585
}
8686

87+
static int dsa_switch_fdb_add(struct dsa_switch *ds,
88+
struct dsa_notifier_fdb_info *info)
89+
{
90+
const struct switchdev_obj_port_fdb *fdb = info->fdb;
91+
struct switchdev_trans *trans = info->trans;
92+
93+
/* Do not care yet about other switch chips of the fabric */
94+
if (ds->index != info->sw_index)
95+
return 0;
96+
97+
if (switchdev_trans_ph_prepare(trans)) {
98+
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
99+
return -EOPNOTSUPP;
100+
101+
return ds->ops->port_fdb_prepare(ds, info->port, fdb, trans);
102+
}
103+
104+
ds->ops->port_fdb_add(ds, info->port, fdb, trans);
105+
106+
return 0;
107+
}
108+
109+
static int dsa_switch_fdb_del(struct dsa_switch *ds,
110+
struct dsa_notifier_fdb_info *info)
111+
{
112+
const struct switchdev_obj_port_fdb *fdb = info->fdb;
113+
114+
/* Do not care yet about other switch chips of the fabric */
115+
if (ds->index != info->sw_index)
116+
return 0;
117+
118+
if (!ds->ops->port_fdb_del)
119+
return -EOPNOTSUPP;
120+
121+
return ds->ops->port_fdb_del(ds, info->port, fdb);
122+
}
123+
87124
static int dsa_switch_event(struct notifier_block *nb,
88125
unsigned long event, void *info)
89126
{
@@ -100,6 +137,12 @@ static int dsa_switch_event(struct notifier_block *nb,
100137
case DSA_NOTIFIER_BRIDGE_LEAVE:
101138
err = dsa_switch_bridge_leave(ds, info);
102139
break;
140+
case DSA_NOTIFIER_FDB_ADD:
141+
err = dsa_switch_fdb_add(ds, info);
142+
break;
143+
case DSA_NOTIFIER_FDB_DEL:
144+
err = dsa_switch_fdb_del(ds, info);
145+
break;
103146
default:
104147
err = -EOPNOTSUPP;
105148
break;

0 commit comments

Comments
 (0)