Skip to content

Commit 8ae5bcd

Browse files
viviendavem330
authored andcommitted
net: dsa: add MDB notifier
Add two new DSA_NOTIFIER_MDB_ADD and DSA_NOTIFIER_MDB_DEL events to notify not only a single switch, but all switches of a the fabric when an MDB 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 685fb6a commit 8ae5bcd

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
@@ -22,6 +22,8 @@ enum {
2222
DSA_NOTIFIER_BRIDGE_LEAVE,
2323
DSA_NOTIFIER_FDB_ADD,
2424
DSA_NOTIFIER_FDB_DEL,
25+
DSA_NOTIFIER_MDB_ADD,
26+
DSA_NOTIFIER_MDB_DEL,
2527
};
2628

2729
/* DSA_NOTIFIER_AGEING_TIME */
@@ -46,6 +48,14 @@ struct dsa_notifier_fdb_info {
4648
int port;
4749
};
4850

51+
/* DSA_NOTIFIER_MDB_* */
52+
struct dsa_notifier_mdb_info {
53+
const struct switchdev_obj_port_mdb *mdb;
54+
struct switchdev_trans *trans;
55+
int sw_index;
56+
int port;
57+
};
58+
4959
struct dsa_device_ops {
5060
struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
5161
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
@@ -188,29 +188,26 @@ int dsa_port_mdb_add(struct dsa_port *dp,
188188
const struct switchdev_obj_port_mdb *mdb,
189189
struct switchdev_trans *trans)
190190
{
191-
struct dsa_switch *ds = dp->ds;
192-
193-
if (switchdev_trans_ph_prepare(trans)) {
194-
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
195-
return -EOPNOTSUPP;
196-
197-
return ds->ops->port_mdb_prepare(ds, dp->index, mdb, trans);
198-
}
199-
200-
ds->ops->port_mdb_add(ds, dp->index, mdb, trans);
191+
struct dsa_notifier_mdb_info info = {
192+
.sw_index = dp->ds->index,
193+
.port = dp->index,
194+
.trans = trans,
195+
.mdb = mdb,
196+
};
201197

202-
return 0;
198+
return dsa_port_notify(dp, DSA_NOTIFIER_MDB_ADD, &info);
203199
}
204200

205201
int dsa_port_mdb_del(struct dsa_port *dp,
206202
const struct switchdev_obj_port_mdb *mdb)
207203
{
208-
struct dsa_switch *ds = dp->ds;
209-
210-
if (ds->ops->port_mdb_del)
211-
return ds->ops->port_mdb_del(ds, dp->index, mdb);
204+
struct dsa_notifier_mdb_info info = {
205+
.sw_index = dp->ds->index,
206+
.port = dp->index,
207+
.mdb = mdb,
208+
};
212209

213-
return -EOPNOTSUPP;
210+
return dsa_port_notify(dp, DSA_NOTIFIER_MDB_DEL, &info);
214211
}
215212

216213
int dsa_port_mdb_dump(struct dsa_port *dp, struct switchdev_obj_port_mdb *mdb,

‎net/dsa/switch.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,43 @@ static int dsa_switch_fdb_del(struct dsa_switch *ds,
121121
return ds->ops->port_fdb_del(ds, info->port, fdb);
122122
}
123123

124+
static int dsa_switch_mdb_add(struct dsa_switch *ds,
125+
struct dsa_notifier_mdb_info *info)
126+
{
127+
const struct switchdev_obj_port_mdb *mdb = info->mdb;
128+
struct switchdev_trans *trans = info->trans;
129+
130+
/* Do not care yet about other switch chips of the fabric */
131+
if (ds->index != info->sw_index)
132+
return 0;
133+
134+
if (switchdev_trans_ph_prepare(trans)) {
135+
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
136+
return -EOPNOTSUPP;
137+
138+
return ds->ops->port_mdb_prepare(ds, info->port, mdb, trans);
139+
}
140+
141+
ds->ops->port_mdb_add(ds, info->port, mdb, trans);
142+
143+
return 0;
144+
}
145+
146+
static int dsa_switch_mdb_del(struct dsa_switch *ds,
147+
struct dsa_notifier_mdb_info *info)
148+
{
149+
const struct switchdev_obj_port_mdb *mdb = info->mdb;
150+
151+
/* Do not care yet about other switch chips of the fabric */
152+
if (ds->index != info->sw_index)
153+
return 0;
154+
155+
if (!ds->ops->port_mdb_del)
156+
return -EOPNOTSUPP;
157+
158+
return ds->ops->port_mdb_del(ds, info->port, mdb);
159+
}
160+
124161
static int dsa_switch_event(struct notifier_block *nb,
125162
unsigned long event, void *info)
126163
{
@@ -143,6 +180,12 @@ static int dsa_switch_event(struct notifier_block *nb,
143180
case DSA_NOTIFIER_FDB_DEL:
144181
err = dsa_switch_fdb_del(ds, info);
145182
break;
183+
case DSA_NOTIFIER_MDB_ADD:
184+
err = dsa_switch_mdb_add(ds, info);
185+
break;
186+
case DSA_NOTIFIER_MDB_DEL:
187+
err = dsa_switch_mdb_del(ds, info);
188+
break;
146189
default:
147190
err = -EOPNOTSUPP;
148191
break;

0 commit comments

Comments
 (0)