Commit eef50d46 authored by David S. Miller's avatar David S. Miller

Merge branch 'switchdev-callback'

Vivien Didelot says:

====================
net: switchdev: use specific switchdev_obj_*

This patchset changes switchdev add, del, dump operations from this:

    int     (*switchdev_port_obj_add)(struct net_device *dev,
                                      struct switchdev_obj *obj,
                                      struct switchdev_trans *trans);
    int     (*switchdev_port_obj_del)(struct net_device *dev,
                                      struct switchdev_obj *obj);
    int     (*switchdev_port_obj_dump)(struct net_device *dev,
                                      struct switchdev_obj *obj);

to something similar to the notifier_call callback of a notifier_block:

    int     (*switchdev_port_obj_add)(struct net_device *dev,
                                      enum switchdev_obj_id id,
                                      const void *obj,
                                      struct switchdev_trans *trans);
    int     (*switchdev_port_obj_del)(struct net_device *dev,
                                      enum switchdev_obj_id id,
                                      const void *obj);
    int     (*switchdev_port_obj_dump)(struct net_device *dev,
                                       enum switchdev_obj_id id, void *obj,
                                       int (*cb)(void *obj));

This allows the caller to pass and expect back a specific switchdev_obj_*
structure (e.g. switchdev_obj_fdb) instead of the generic switchdev_obj one.

This will simplify pushing the callback function down to the drivers.

The first 3 patches get rid of the dev parameter of the dump callback, since it
is not always neeeded (e.g. vlan_dump) and some drivers (such as DSA drivers)
may not have easy access to it.

Patches 4 and 5 implement the change in the switchdev operations and its users.

Patch 6 extracts the inner switchdev_obj_* structures from switchdev_obj and
removes this last one.

v2: fix error spotted by kbuild (extra ';' inline switchdev_port_obj_dump).
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 79b0eb2a 44bbcf5c
...@@ -4437,26 +4437,25 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port, ...@@ -4437,26 +4437,25 @@ static int rocker_port_fdb_add(struct rocker_port *rocker_port,
} }
static int rocker_port_obj_add(struct net_device *dev, static int rocker_port_obj_add(struct net_device *dev,
struct switchdev_obj *obj, enum switchdev_obj_id id, const void *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct rocker_port *rocker_port = netdev_priv(dev); struct rocker_port *rocker_port = netdev_priv(dev);
const struct switchdev_obj_ipv4_fib *fib4; const struct switchdev_obj_ipv4_fib *fib4;
int err = 0; int err = 0;
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_VLAN: case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlans_add(rocker_port, trans, err = rocker_port_vlans_add(rocker_port, trans, obj);
&obj->u.vlan);
break; break;
case SWITCHDEV_OBJ_IPV4_FIB: case SWITCHDEV_OBJ_IPV4_FIB:
fib4 = &obj->u.ipv4_fib; fib4 = obj;
err = rocker_port_fib_ipv4(rocker_port, trans, err = rocker_port_fib_ipv4(rocker_port, trans,
htonl(fib4->dst), fib4->dst_len, htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id, 0); fib4->fi, fib4->tb_id, 0);
break; break;
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_add(rocker_port, trans, &obj->u.fdb); err = rocker_port_fdb_add(rocker_port, trans, obj);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -4509,25 +4508,25 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port, ...@@ -4509,25 +4508,25 @@ static int rocker_port_fdb_del(struct rocker_port *rocker_port,
} }
static int rocker_port_obj_del(struct net_device *dev, static int rocker_port_obj_del(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id, const void *obj)
{ {
struct rocker_port *rocker_port = netdev_priv(dev); struct rocker_port *rocker_port = netdev_priv(dev);
const struct switchdev_obj_ipv4_fib *fib4; const struct switchdev_obj_ipv4_fib *fib4;
int err = 0; int err = 0;
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_VLAN: case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlans_del(rocker_port, &obj->u.vlan); err = rocker_port_vlans_del(rocker_port, obj);
break; break;
case SWITCHDEV_OBJ_IPV4_FIB: case SWITCHDEV_OBJ_IPV4_FIB:
fib4 = &obj->u.ipv4_fib; fib4 = obj;
err = rocker_port_fib_ipv4(rocker_port, NULL, err = rocker_port_fib_ipv4(rocker_port, NULL,
htonl(fib4->dst), fib4->dst_len, htonl(fib4->dst), fib4->dst_len,
fib4->fi, fib4->tb_id, fib4->fi, fib4->tb_id,
ROCKER_OP_FLAG_REMOVE); ROCKER_OP_FLAG_REMOVE);
break; break;
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_del(rocker_port, NULL, &obj->u.fdb); err = rocker_port_fdb_del(rocker_port, NULL, obj);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -4538,10 +4537,10 @@ static int rocker_port_obj_del(struct net_device *dev, ...@@ -4538,10 +4537,10 @@ static int rocker_port_obj_del(struct net_device *dev,
} }
static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
struct switchdev_obj *obj) struct switchdev_obj_fdb *fdb,
int (*cb)(void *obj))
{ {
struct rocker *rocker = rocker_port->rocker; struct rocker *rocker = rocker_port->rocker;
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
struct rocker_fdb_tbl_entry *found; struct rocker_fdb_tbl_entry *found;
struct hlist_node *tmp; struct hlist_node *tmp;
unsigned long lock_flags; unsigned long lock_flags;
...@@ -4556,7 +4555,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4556,7 +4555,7 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
fdb->ndm_state = NUD_REACHABLE; fdb->ndm_state = NUD_REACHABLE;
fdb->vid = rocker_port_vlan_to_vid(rocker_port, fdb->vid = rocker_port_vlan_to_vid(rocker_port,
found->key.vlan_id); found->key.vlan_id);
err = obj->cb(rocker_port->dev, obj); err = cb(fdb);
if (err) if (err)
break; break;
} }
...@@ -4566,9 +4565,9 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port, ...@@ -4566,9 +4565,9 @@ static int rocker_port_fdb_dump(const struct rocker_port *rocker_port,
} }
static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
struct switchdev_obj *obj) struct switchdev_obj_vlan *vlan,
int (*cb)(void *obj))
{ {
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
u16 vid; u16 vid;
int err = 0; int err = 0;
...@@ -4579,7 +4578,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4579,7 +4578,7 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
if (rocker_vlan_id_is_internal(htons(vid))) if (rocker_vlan_id_is_internal(htons(vid)))
vlan->flags |= BRIDGE_VLAN_INFO_PVID; vlan->flags |= BRIDGE_VLAN_INFO_PVID;
vlan->vid_begin = vlan->vid_end = vid; vlan->vid_begin = vlan->vid_end = vid;
err = obj->cb(rocker_port->dev, obj); err = cb(vlan);
if (err) if (err)
break; break;
} }
...@@ -4588,17 +4587,18 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port, ...@@ -4588,17 +4587,18 @@ static int rocker_port_vlan_dump(const struct rocker_port *rocker_port,
} }
static int rocker_port_obj_dump(struct net_device *dev, static int rocker_port_obj_dump(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id, void *obj,
int (*cb)(void *obj))
{ {
const struct rocker_port *rocker_port = netdev_priv(dev); const struct rocker_port *rocker_port = netdev_priv(dev);
int err = 0; int err = 0;
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = rocker_port_fdb_dump(rocker_port, obj); err = rocker_port_fdb_dump(rocker_port, obj, cb);
break; break;
case SWITCHDEV_OBJ_PORT_VLAN: case SWITCHDEV_OBJ_PORT_VLAN:
err = rocker_port_vlan_dump(rocker_port, obj); err = rocker_port_vlan_dump(rocker_port, obj, cb);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
......
...@@ -64,30 +64,29 @@ enum switchdev_obj_id { ...@@ -64,30 +64,29 @@ enum switchdev_obj_id {
SWITCHDEV_OBJ_PORT_FDB, SWITCHDEV_OBJ_PORT_FDB,
}; };
struct switchdev_obj { /* SWITCHDEV_OBJ_PORT_VLAN */
enum switchdev_obj_id id; struct switchdev_obj_vlan {
int (*cb)(struct net_device *dev, struct switchdev_obj *obj); u16 flags;
union { u16 vid_begin;
struct switchdev_obj_vlan { /* PORT_VLAN */ u16 vid_end;
u16 flags; };
u16 vid_begin;
u16 vid_end; /* SWITCHDEV_OBJ_IPV4_FIB */
} vlan; struct switchdev_obj_ipv4_fib {
struct switchdev_obj_ipv4_fib { /* IPV4_FIB */ u32 dst;
u32 dst; int dst_len;
int dst_len; struct fib_info *fi;
struct fib_info *fi; u8 tos;
u8 tos; u8 type;
u8 type; u32 nlflags;
u32 nlflags; u32 tb_id;
u32 tb_id; };
} ipv4_fib;
struct switchdev_obj_fdb { /* PORT_FDB */ /* SWITCHDEV_OBJ_PORT_FDB */
const unsigned char *addr; struct switchdev_obj_fdb {
u16 vid; const unsigned char *addr;
u16 ndm_state; u16 vid;
} fdb; u16 ndm_state;
} u;
}; };
void switchdev_trans_item_enqueue(struct switchdev_trans *trans, void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
...@@ -102,11 +101,11 @@ void *switchdev_trans_item_dequeue(struct switchdev_trans *trans); ...@@ -102,11 +101,11 @@ void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
* *
* @switchdev_port_attr_set: Set a port attribute (see switchdev_attr). * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
* *
* @switchdev_port_obj_add: Add an object to port (see switchdev_obj). * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
* *
* @switchdev_port_obj_del: Delete an object from port (see switchdev_obj). * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
* *
* @switchdev_port_obj_dump: Dump port objects (see switchdev_obj). * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj_*).
*/ */
struct switchdev_ops { struct switchdev_ops {
int (*switchdev_port_attr_get)(struct net_device *dev, int (*switchdev_port_attr_get)(struct net_device *dev,
...@@ -115,12 +114,15 @@ struct switchdev_ops { ...@@ -115,12 +114,15 @@ struct switchdev_ops {
struct switchdev_attr *attr, struct switchdev_attr *attr,
struct switchdev_trans *trans); struct switchdev_trans *trans);
int (*switchdev_port_obj_add)(struct net_device *dev, int (*switchdev_port_obj_add)(struct net_device *dev,
struct switchdev_obj *obj, enum switchdev_obj_id id,
const void *obj,
struct switchdev_trans *trans); struct switchdev_trans *trans);
int (*switchdev_port_obj_del)(struct net_device *dev, int (*switchdev_port_obj_del)(struct net_device *dev,
struct switchdev_obj *obj); enum switchdev_obj_id id,
const void *obj);
int (*switchdev_port_obj_dump)(struct net_device *dev, int (*switchdev_port_obj_dump)(struct net_device *dev,
struct switchdev_obj *obj); enum switchdev_obj_id id, void *obj,
int (*cb)(void *obj));
}; };
enum switchdev_notifier_type { enum switchdev_notifier_type {
...@@ -150,9 +152,12 @@ int switchdev_port_attr_get(struct net_device *dev, ...@@ -150,9 +152,12 @@ int switchdev_port_attr_get(struct net_device *dev,
struct switchdev_attr *attr); struct switchdev_attr *attr);
int switchdev_port_attr_set(struct net_device *dev, int switchdev_port_attr_set(struct net_device *dev,
struct switchdev_attr *attr); struct switchdev_attr *attr);
int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj); int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj); const void *obj);
int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj); int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
const void *obj);
int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
void *obj, int (*cb)(void *obj));
int register_switchdev_notifier(struct notifier_block *nb); int register_switchdev_notifier(struct notifier_block *nb);
int unregister_switchdev_notifier(struct notifier_block *nb); int unregister_switchdev_notifier(struct notifier_block *nb);
int call_switchdev_notifiers(unsigned long val, struct net_device *dev, int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
...@@ -197,19 +202,22 @@ static inline int switchdev_port_attr_set(struct net_device *dev, ...@@ -197,19 +202,22 @@ static inline int switchdev_port_attr_set(struct net_device *dev,
} }
static inline int switchdev_port_obj_add(struct net_device *dev, static inline int switchdev_port_obj_add(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id,
const void *obj)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int switchdev_port_obj_del(struct net_device *dev, static inline int switchdev_port_obj_del(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id,
const void *obj)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int switchdev_port_obj_dump(struct net_device *dev, static inline int switchdev_port_obj_dump(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id, void *obj,
int (*cb)(void *obj))
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -133,15 +133,12 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr) ...@@ -133,15 +133,12 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
static void fdb_del_external_learn(struct net_bridge_fdb_entry *f) static void fdb_del_external_learn(struct net_bridge_fdb_entry *f)
{ {
struct switchdev_obj obj = { struct switchdev_obj_fdb fdb = {
.id = SWITCHDEV_OBJ_PORT_FDB, .addr = f->addr.addr,
.u.fdb = { .vid = f->vlan_id,
.addr = f->addr.addr,
.vid = f->vlan_id,
},
}; };
switchdev_port_obj_del(f->dst->dev, &obj); switchdev_port_obj_del(f->dst->dev, SWITCHDEV_OBJ_PORT_FDB, &fdb);
} }
static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f) static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f)
......
...@@ -80,16 +80,13 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, ...@@ -80,16 +80,13 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
if (ops->ndo_vlan_rx_add_vid) { if (ops->ndo_vlan_rx_add_vid) {
err = vlan_vid_add(dev, br->vlan_proto, vid); err = vlan_vid_add(dev, br->vlan_proto, vid);
} else { } else {
struct switchdev_obj vlan_obj = { struct switchdev_obj_vlan v = {
.id = SWITCHDEV_OBJ_PORT_VLAN, .flags = flags,
.u.vlan = { .vid_begin = vid,
.flags = flags, .vid_end = vid,
.vid_begin = vid,
.vid_end = vid,
},
}; };
err = switchdev_port_obj_add(dev, &vlan_obj); err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
...@@ -132,15 +129,12 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, ...@@ -132,15 +129,12 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
if (ops->ndo_vlan_rx_kill_vid) { if (ops->ndo_vlan_rx_kill_vid) {
vlan_vid_del(dev, br->vlan_proto, vid); vlan_vid_del(dev, br->vlan_proto, vid);
} else { } else {
struct switchdev_obj vlan_obj = { struct switchdev_obj_vlan v = {
.id = SWITCHDEV_OBJ_PORT_VLAN, .vid_begin = vid,
.u.vlan = { .vid_end = vid,
.vid_begin = vid,
.vid_end = vid,
},
}; };
err = switchdev_port_obj_del(dev, &vlan_obj); err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
} }
......
...@@ -242,10 +242,9 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds, ...@@ -242,10 +242,9 @@ static int dsa_bridge_check_vlan_range(struct dsa_switch *ds,
} }
static int dsa_slave_port_vlan_add(struct net_device *dev, static int dsa_slave_port_vlan_add(struct net_device *dev,
struct switchdev_obj *obj, const struct switchdev_obj_vlan *vlan,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
u16 vid; u16 vid;
...@@ -279,9 +278,8 @@ static int dsa_slave_port_vlan_add(struct net_device *dev, ...@@ -279,9 +278,8 @@ static int dsa_slave_port_vlan_add(struct net_device *dev,
} }
static int dsa_slave_port_vlan_del(struct net_device *dev, static int dsa_slave_port_vlan_del(struct net_device *dev,
struct switchdev_obj *obj) const struct switchdev_obj_vlan *vlan)
{ {
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
u16 vid; u16 vid;
...@@ -300,9 +298,9 @@ static int dsa_slave_port_vlan_del(struct net_device *dev, ...@@ -300,9 +298,9 @@ static int dsa_slave_port_vlan_del(struct net_device *dev,
} }
static int dsa_slave_port_vlan_dump(struct net_device *dev, static int dsa_slave_port_vlan_dump(struct net_device *dev,
struct switchdev_obj *obj) struct switchdev_obj_vlan *vlan,
int (*cb)(void *obj))
{ {
struct switchdev_obj_vlan *vlan = &obj->u.vlan;
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
DECLARE_BITMAP(members, DSA_MAX_PORTS); DECLARE_BITMAP(members, DSA_MAX_PORTS);
...@@ -334,7 +332,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev, ...@@ -334,7 +332,7 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
if (test_bit(p->port, untagged)) if (test_bit(p->port, untagged))
vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED; vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
err = obj->cb(dev, obj); err = cb(vlan);
if (err) if (err)
break; break;
} }
...@@ -343,10 +341,9 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev, ...@@ -343,10 +341,9 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
} }
static int dsa_slave_port_fdb_add(struct net_device *dev, static int dsa_slave_port_fdb_add(struct net_device *dev,
struct switchdev_obj *obj, const struct switchdev_obj_fdb *fdb,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
...@@ -360,9 +357,8 @@ static int dsa_slave_port_fdb_add(struct net_device *dev, ...@@ -360,9 +357,8 @@ static int dsa_slave_port_fdb_add(struct net_device *dev,
} }
static int dsa_slave_port_fdb_del(struct net_device *dev, static int dsa_slave_port_fdb_del(struct net_device *dev,
struct switchdev_obj *obj) const struct switchdev_obj_fdb *fdb)
{ {
struct switchdev_obj_fdb *fdb = &obj->u.fdb;
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
...@@ -374,7 +370,8 @@ static int dsa_slave_port_fdb_del(struct net_device *dev, ...@@ -374,7 +370,8 @@ static int dsa_slave_port_fdb_del(struct net_device *dev,
} }
static int dsa_slave_port_fdb_dump(struct net_device *dev, static int dsa_slave_port_fdb_dump(struct net_device *dev,
struct switchdev_obj *obj) struct switchdev_obj_fdb *fdb,
int (*cb)(void *obj))
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->parent;
...@@ -393,11 +390,11 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev, ...@@ -393,11 +390,11 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev,
if (ret < 0) if (ret < 0)
break; break;
obj->u.fdb.addr = addr; fdb->addr = addr;
obj->u.fdb.vid = vid; fdb->vid = vid;
obj->u.fdb.ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE; fdb->ndm_state = is_static ? NUD_NOARP : NUD_REACHABLE;
ret = obj->cb(dev, obj); ret = cb(fdb);
if (ret < 0) if (ret < 0)
break; break;
} }
...@@ -472,7 +469,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev, ...@@ -472,7 +469,7 @@ static int dsa_slave_port_attr_set(struct net_device *dev,
} }
static int dsa_slave_port_obj_add(struct net_device *dev, static int dsa_slave_port_obj_add(struct net_device *dev,
struct switchdev_obj *obj, enum switchdev_obj_id id, const void *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
int err; int err;
...@@ -482,7 +479,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -482,7 +479,7 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
* supported, return -EOPNOTSUPP. * supported, return -EOPNOTSUPP.
*/ */
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = dsa_slave_port_fdb_add(dev, obj, trans); err = dsa_slave_port_fdb_add(dev, obj, trans);
break; break;
...@@ -498,11 +495,11 @@ static int dsa_slave_port_obj_add(struct net_device *dev, ...@@ -498,11 +495,11 @@ static int dsa_slave_port_obj_add(struct net_device *dev,
} }
static int dsa_slave_port_obj_del(struct net_device *dev, static int dsa_slave_port_obj_del(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id, const void *obj)
{ {
int err; int err;
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = dsa_slave_port_fdb_del(dev, obj); err = dsa_slave_port_fdb_del(dev, obj);
break; break;
...@@ -518,16 +515,17 @@ static int dsa_slave_port_obj_del(struct net_device *dev, ...@@ -518,16 +515,17 @@ static int dsa_slave_port_obj_del(struct net_device *dev,
} }
static int dsa_slave_port_obj_dump(struct net_device *dev, static int dsa_slave_port_obj_dump(struct net_device *dev,
struct switchdev_obj *obj) enum switchdev_obj_id id, void *obj,
int (*cb)(void *obj))
{ {
int err; int err;
switch (obj->id) { switch (id) {
case SWITCHDEV_OBJ_PORT_FDB: case SWITCHDEV_OBJ_PORT_FDB:
err = dsa_slave_port_fdb_dump(dev, obj); err = dsa_slave_port_fdb_dump(dev, obj, cb);
break; break;
case SWITCHDEV_OBJ_PORT_VLAN: case SWITCHDEV_OBJ_PORT_VLAN:
err = dsa_slave_port_vlan_dump(dev, obj); err = dsa_slave_port_vlan_dump(dev, obj, cb);
break; break;
default: default:
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
......
...@@ -270,7 +270,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr) ...@@ -270,7 +270,7 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr)
EXPORT_SYMBOL_GPL(switchdev_port_attr_set); EXPORT_SYMBOL_GPL(switchdev_port_attr_set);
static int __switchdev_port_obj_add(struct net_device *dev, static int __switchdev_port_obj_add(struct net_device *dev,
struct switchdev_obj *obj, enum switchdev_obj_id id, const void *obj,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
...@@ -279,7 +279,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -279,7 +279,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_add) if (ops && ops->switchdev_port_obj_add)
return ops->switchdev_port_obj_add(dev, obj, trans); return ops->switchdev_port_obj_add(dev, id, obj, trans);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to add object on * bond/team/vlan dev, so recurse down to add object on
...@@ -287,7 +287,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -287,7 +287,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = __switchdev_port_obj_add(lower_dev, obj, trans); err = __switchdev_port_obj_add(lower_dev, id, obj, trans);
if (err) if (err)
break; break;
} }
...@@ -299,6 +299,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -299,6 +299,7 @@ static int __switchdev_port_obj_add(struct net_device *dev,
* switchdev_port_obj_add - Add port object * switchdev_port_obj_add - Add port object
* *
* @dev: port device * @dev: port device
* @id: object ID
* @obj: object to add * @obj: object to add
* *
* Use a 2-phase prepare-commit transaction model to ensure * Use a 2-phase prepare-commit transaction model to ensure
...@@ -307,7 +308,8 @@ static int __switchdev_port_obj_add(struct net_device *dev, ...@@ -307,7 +308,8 @@ static int __switchdev_port_obj_add(struct net_device *dev,
* *
* rtnl_lock must be held. * rtnl_lock must be held.
*/ */
int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj) int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
const void *obj)
{ {
struct switchdev_trans trans; struct switchdev_trans trans;
int err; int err;
...@@ -324,7 +326,7 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj) ...@@ -324,7 +326,7 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj)
*/ */
trans.ph_prepare = true; trans.ph_prepare = true;
err = __switchdev_port_obj_add(dev, obj, &trans); err = __switchdev_port_obj_add(dev, id, obj, &trans);
if (err) { if (err) {
/* Prepare phase failed: abort the transaction. Any /* Prepare phase failed: abort the transaction. Any
* resources reserved in the prepare phase are * resources reserved in the prepare phase are
...@@ -343,8 +345,8 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj) ...@@ -343,8 +345,8 @@ int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj)
*/ */
trans.ph_prepare = false; trans.ph_prepare = false;
err = __switchdev_port_obj_add(dev, obj, &trans); err = __switchdev_port_obj_add(dev, id, obj, &trans);
WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, obj->id); WARN(err, "%s: Commit of object (id=%d) failed.\n", dev->name, id);
switchdev_trans_items_warn_destroy(dev, &trans); switchdev_trans_items_warn_destroy(dev, &trans);
return err; return err;
...@@ -355,9 +357,11 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add); ...@@ -355,9 +357,11 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add);
* switchdev_port_obj_del - Delete port object * switchdev_port_obj_del - Delete port object
* *
* @dev: port device * @dev: port device
* @id: object ID
* @obj: object to delete * @obj: object to delete
*/ */
int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj) int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
const void *obj)
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
struct net_device *lower_dev; struct net_device *lower_dev;
...@@ -365,7 +369,7 @@ int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj) ...@@ -365,7 +369,7 @@ int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj)
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_del) if (ops && ops->switchdev_port_obj_del)
return ops->switchdev_port_obj_del(dev, obj); return ops->switchdev_port_obj_del(dev, id, obj);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to delete object on * bond/team/vlan dev, so recurse down to delete object on
...@@ -373,7 +377,7 @@ int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj) ...@@ -373,7 +377,7 @@ int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj)
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = switchdev_port_obj_del(lower_dev, obj); err = switchdev_port_obj_del(lower_dev, id, obj);
if (err) if (err)
break; break;
} }
...@@ -386,9 +390,12 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del); ...@@ -386,9 +390,12 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del);
* switchdev_port_obj_dump - Dump port objects * switchdev_port_obj_dump - Dump port objects
* *
* @dev: port device * @dev: port device
* @id: object ID
* @obj: object to dump * @obj: object to dump
* @cb: function to call with a filled object
*/ */
int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj) int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
void *obj, int (*cb)(void *obj))
{ {
const struct switchdev_ops *ops = dev->switchdev_ops; const struct switchdev_ops *ops = dev->switchdev_ops;
struct net_device *lower_dev; struct net_device *lower_dev;
...@@ -396,7 +403,7 @@ int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj) ...@@ -396,7 +403,7 @@ int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj)
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
if (ops && ops->switchdev_port_obj_dump) if (ops && ops->switchdev_port_obj_dump)
return ops->switchdev_port_obj_dump(dev, obj); return ops->switchdev_port_obj_dump(dev, id, obj, cb);
/* Switch device port(s) may be stacked under /* Switch device port(s) may be stacked under
* bond/team/vlan dev, so recurse down to dump objects on * bond/team/vlan dev, so recurse down to dump objects on
...@@ -404,7 +411,7 @@ int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj) ...@@ -404,7 +411,7 @@ int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj)
*/ */
netdev_for_each_lower_dev(dev, lower_dev, iter) { netdev_for_each_lower_dev(dev, lower_dev, iter) {
err = switchdev_port_obj_dump(lower_dev, obj); err = switchdev_port_obj_dump(lower_dev, id, obj, cb);
break; break;
} }
...@@ -476,7 +483,7 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev, ...@@ -476,7 +483,7 @@ int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
EXPORT_SYMBOL_GPL(call_switchdev_notifiers); EXPORT_SYMBOL_GPL(call_switchdev_notifiers);
struct switchdev_vlan_dump { struct switchdev_vlan_dump {
struct switchdev_obj obj; struct switchdev_obj_vlan vlan;
struct sk_buff *skb; struct sk_buff *skb;
u32 filter_mask; u32 filter_mask;
u16 flags; u16 flags;
...@@ -484,8 +491,7 @@ struct switchdev_vlan_dump { ...@@ -484,8 +491,7 @@ struct switchdev_vlan_dump {
u16 end; u16 end;
}; };
static int switchdev_port_vlan_dump_put(struct net_device *dev, static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump)
struct switchdev_vlan_dump *dump)
{ {
struct bridge_vlan_info vinfo; struct bridge_vlan_info vinfo;
...@@ -515,12 +521,11 @@ static int switchdev_port_vlan_dump_put(struct net_device *dev, ...@@ -515,12 +521,11 @@ static int switchdev_port_vlan_dump_put(struct net_device *dev,
return 0; return 0;
} }
static int switchdev_port_vlan_dump_cb(struct net_device *dev, static int switchdev_port_vlan_dump_cb(void *obj)
struct switchdev_obj *obj)
{ {
struct switchdev_obj_vlan *vlan = obj;
struct switchdev_vlan_dump *dump = struct switchdev_vlan_dump *dump =
container_of(obj, struct switchdev_vlan_dump, obj); container_of(vlan, struct switchdev_vlan_dump, vlan);
struct switchdev_obj_vlan *vlan = &dump->obj.u.vlan;
int err = 0; int err = 0;
if (vlan->vid_begin > vlan->vid_end) if (vlan->vid_begin > vlan->vid_end)
...@@ -531,7 +536,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev, ...@@ -531,7 +536,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev,
for (dump->begin = dump->end = vlan->vid_begin; for (dump->begin = dump->end = vlan->vid_begin;
dump->begin <= vlan->vid_end; dump->begin <= vlan->vid_end;
dump->begin++, dump->end++) { dump->begin++, dump->end++) {
err = switchdev_port_vlan_dump_put(dev, dump); err = switchdev_port_vlan_dump_put(dump);
if (err) if (err)
return err; return err;
} }
...@@ -543,7 +548,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev, ...@@ -543,7 +548,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev,
/* prepend */ /* prepend */
dump->begin = vlan->vid_begin; dump->begin = vlan->vid_begin;
} else { } else {
err = switchdev_port_vlan_dump_put(dev, dump); err = switchdev_port_vlan_dump_put(dump);
dump->flags = vlan->flags; dump->flags = vlan->flags;
dump->begin = vlan->vid_begin; dump->begin = vlan->vid_begin;
dump->end = vlan->vid_end; dump->end = vlan->vid_end;
...@@ -555,7 +560,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev, ...@@ -555,7 +560,7 @@ static int switchdev_port_vlan_dump_cb(struct net_device *dev,
/* append */ /* append */
dump->end = vlan->vid_end; dump->end = vlan->vid_end;
} else { } else {
err = switchdev_port_vlan_dump_put(dev, dump); err = switchdev_port_vlan_dump_put(dump);
dump->flags = vlan->flags; dump->flags = vlan->flags;
dump->begin = vlan->vid_begin; dump->begin = vlan->vid_begin;
dump->end = vlan->vid_end; dump->end = vlan->vid_end;
...@@ -572,10 +577,6 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, ...@@ -572,10 +577,6 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev,
u32 filter_mask) u32 filter_mask)
{ {
struct switchdev_vlan_dump dump = { struct switchdev_vlan_dump dump = {
.obj = {
.id = SWITCHDEV_OBJ_PORT_VLAN,
.cb = switchdev_port_vlan_dump_cb,
},
.skb = skb, .skb = skb,
.filter_mask = filter_mask, .filter_mask = filter_mask,
}; };
...@@ -583,12 +584,14 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, ...@@ -583,12 +584,14 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev,
if ((filter_mask & RTEXT_FILTER_BRVLAN) || if ((filter_mask & RTEXT_FILTER_BRVLAN) ||
(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) {
err = switchdev_port_obj_dump(dev, &dump.obj); err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_PORT_VLAN,
&dump.vlan,
switchdev_port_vlan_dump_cb);
if (err) if (err)
goto err_out; goto err_out;
if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) if (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)
/* last one */ /* last one */
err = switchdev_port_vlan_dump_put(dev, &dump); err = switchdev_port_vlan_dump_put(&dump);
} }
err_out: err_out:
...@@ -696,14 +699,12 @@ static int switchdev_port_br_setlink_protinfo(struct net_device *dev, ...@@ -696,14 +699,12 @@ static int switchdev_port_br_setlink_protinfo(struct net_device *dev,
static int switchdev_port_br_afspec(struct net_device *dev, static int switchdev_port_br_afspec(struct net_device *dev,
struct nlattr *afspec, struct nlattr *afspec,
int (*f)(struct net_device *dev, int (*f)(struct net_device *dev,
struct switchdev_obj *obj)) enum switchdev_obj_id id,
const void *obj))
{ {
struct nlattr *attr; struct nlattr *attr;
struct bridge_vlan_info *vinfo; struct bridge_vlan_info *vinfo;
struct switchdev_obj obj = { struct switchdev_obj_vlan vlan = { 0 };
.id = SWITCHDEV_OBJ_PORT_VLAN,
};
struct switchdev_obj_vlan *vlan = &obj.u.vlan;
int rem; int rem;
int err; int err;
...@@ -713,30 +714,30 @@ static int switchdev_port_br_afspec(struct net_device *dev, ...@@ -713,30 +714,30 @@ static int switchdev_port_br_afspec(struct net_device *dev,
if (nla_len(attr) != sizeof(struct bridge_vlan_info)) if (nla_len(attr) != sizeof(struct bridge_vlan_info))
return -EINVAL; return -EINVAL;
vinfo = nla_data(attr); vinfo = nla_data(attr);
vlan->flags = vinfo->flags; vlan.flags = vinfo->flags;
if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
if (vlan->vid_begin) if (vlan.vid_begin)
return -EINVAL; return -EINVAL;
vlan->vid_begin = vinfo->vid; vlan.vid_begin = vinfo->vid;
} else if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END) { } else if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END) {
if (!vlan->vid_begin) if (!vlan.vid_begin)
return -EINVAL; return -EINVAL;
vlan->vid_end = vinfo->vid; vlan.vid_end = vinfo->vid;
if (vlan->vid_end <= vlan->vid_begin) if (vlan.vid_end <= vlan.vid_begin)
return -EINVAL; return -EINVAL;
err = f(dev, &obj); err = f(dev, SWITCHDEV_OBJ_PORT_VLAN, &vlan);
if (err) if (err)
return err; return err;
memset(vlan, 0, sizeof(*vlan)); memset(&vlan, 0, sizeof(vlan));
} else { } else {
if (vlan->vid_begin) if (vlan.vid_begin)
return -EINVAL; return -EINVAL;
vlan->vid_begin = vinfo->vid; vlan.vid_begin = vinfo->vid;
vlan->vid_end = vinfo->vid; vlan.vid_end = vinfo->vid;
err = f(dev, &obj); err = f(dev, SWITCHDEV_OBJ_PORT_VLAN, &vlan);
if (err) if (err)
return err; return err;
memset(vlan, 0, sizeof(*vlan)); memset(&vlan, 0, sizeof(vlan));
} }
} }
...@@ -818,15 +819,12 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -818,15 +819,12 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
struct net_device *dev, const unsigned char *addr, struct net_device *dev, const unsigned char *addr,
u16 vid, u16 nlm_flags) u16 vid, u16 nlm_flags)
{ {
struct switchdev_obj obj = { struct switchdev_obj_fdb fdb = {
.id = SWITCHDEV_OBJ_PORT_FDB, .addr = addr,
.u.fdb = { .vid = vid,
.addr = addr,
.vid = vid,
},
}; };
return switchdev_port_obj_add(dev, &obj); return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_FDB, &fdb);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_add); EXPORT_SYMBOL_GPL(switchdev_port_fdb_add);
...@@ -845,30 +843,28 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -845,30 +843,28 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
struct net_device *dev, const unsigned char *addr, struct net_device *dev, const unsigned char *addr,
u16 vid) u16 vid)
{ {
struct switchdev_obj obj = { struct switchdev_obj_fdb fdb = {
.id = SWITCHDEV_OBJ_PORT_FDB, .addr = addr,
.u.fdb = { .vid = vid,
.addr = addr,
.vid = vid,
},
}; };
return switchdev_port_obj_del(dev, &obj); return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_FDB, &fdb);
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_del); EXPORT_SYMBOL_GPL(switchdev_port_fdb_del);
struct switchdev_fdb_dump { struct switchdev_fdb_dump {
struct switchdev_obj obj; struct switchdev_obj_fdb fdb;
struct net_device *dev;
struct sk_buff *skb; struct sk_buff *skb;
struct netlink_callback *cb; struct netlink_callback *cb;
int idx; int idx;
}; };
static int switchdev_port_fdb_dump_cb(struct net_device *dev, static int switchdev_port_fdb_dump_cb(void *obj)
struct switchdev_obj *obj)
{ {
struct switchdev_obj_fdb *fdb = obj;
struct switchdev_fdb_dump *dump = struct switchdev_fdb_dump *dump =
container_of(obj, struct switchdev_fdb_dump, obj); container_of(fdb, struct switchdev_fdb_dump, fdb);
u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 portid = NETLINK_CB(dump->cb->skb).portid;
u32 seq = dump->cb->nlh->nlmsg_seq; u32 seq = dump->cb->nlh->nlmsg_seq;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
...@@ -888,13 +884,13 @@ static int switchdev_port_fdb_dump_cb(struct net_device *dev, ...@@ -888,13 +884,13 @@ static int switchdev_port_fdb_dump_cb(struct net_device *dev,
ndm->ndm_pad2 = 0; ndm->ndm_pad2 = 0;
ndm->ndm_flags = NTF_SELF; ndm->ndm_flags = NTF_SELF;
ndm->ndm_type = 0; ndm->ndm_type = 0;
ndm->ndm_ifindex = dev->ifindex; ndm->ndm_ifindex = dump->dev->ifindex;
ndm->ndm_state = obj->u.fdb.ndm_state; ndm->ndm_state = fdb->ndm_state;
if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, obj->u.fdb.addr)) if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, fdb->addr))
goto nla_put_failure; goto nla_put_failure;
if (obj->u.fdb.vid && nla_put_u16(dump->skb, NDA_VLAN, obj->u.fdb.vid)) if (fdb->vid && nla_put_u16(dump->skb, NDA_VLAN, fdb->vid))
goto nla_put_failure; goto nla_put_failure;
nlmsg_end(dump->skb, nlh); nlmsg_end(dump->skb, nlh);
...@@ -924,16 +920,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -924,16 +920,14 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct net_device *filter_dev, int idx) struct net_device *filter_dev, int idx)
{ {
struct switchdev_fdb_dump dump = { struct switchdev_fdb_dump dump = {
.obj = { .dev = dev,
.id = SWITCHDEV_OBJ_PORT_FDB,
.cb = switchdev_port_fdb_dump_cb,
},
.skb = skb, .skb = skb,
.cb = cb, .cb = cb,
.idx = idx, .idx = idx,
}; };
switchdev_port_obj_dump(dev, &dump.obj); switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_PORT_FDB, &dump.fdb,
switchdev_port_fdb_dump_cb);
return dump.idx; return dump.idx;
} }
EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump); EXPORT_SYMBOL_GPL(switchdev_port_fdb_dump);
...@@ -1011,17 +1005,14 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) ...@@ -1011,17 +1005,14 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
u8 tos, u8 type, u32 nlflags, u32 tb_id) u8 tos, u8 type, u32 nlflags, u32 tb_id)
{ {
struct switchdev_obj fib_obj = { struct switchdev_obj_ipv4_fib ipv4_fib = {
.id = SWITCHDEV_OBJ_IPV4_FIB, .dst = dst,
.u.ipv4_fib = { .dst_len = dst_len,
.dst = dst, .fi = fi,
.dst_len = dst_len, .tos = tos,
.fi = fi, .type = type,
.tos = tos, .nlflags = nlflags,
.type = type, .tb_id = tb_id,
.nlflags = nlflags,
.tb_id = tb_id,
},
}; };
struct net_device *dev; struct net_device *dev;
int err = 0; int err = 0;
...@@ -1042,7 +1033,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1042,7 +1033,7 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
if (!dev) if (!dev)
return 0; return 0;
err = switchdev_port_obj_add(dev, &fib_obj); err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_IPV4_FIB, &ipv4_fib);
if (!err) if (!err)
fi->fib_flags |= RTNH_F_OFFLOAD; fi->fib_flags |= RTNH_F_OFFLOAD;
...@@ -1065,17 +1056,14 @@ EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_add); ...@@ -1065,17 +1056,14 @@ EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_add);
int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
u8 tos, u8 type, u32 tb_id) u8 tos, u8 type, u32 tb_id)
{ {
struct switchdev_obj fib_obj = { struct switchdev_obj_ipv4_fib ipv4_fib = {
.id = SWITCHDEV_OBJ_IPV4_FIB, .dst = dst,
.u.ipv4_fib = { .dst_len = dst_len,
.dst = dst, .fi = fi,
.dst_len = dst_len, .tos = tos,
.fi = fi, .type = type,
.tos = tos, .nlflags = 0,
.type = type, .tb_id = tb_id,
.nlflags = 0,
.tb_id = tb_id,
},
}; };
struct net_device *dev; struct net_device *dev;
int err = 0; int err = 0;
...@@ -1087,7 +1075,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, ...@@ -1087,7 +1075,7 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
if (!dev) if (!dev)
return 0; return 0;
err = switchdev_port_obj_del(dev, &fib_obj); err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_IPV4_FIB, &ipv4_fib);
if (!err) if (!err)
fi->fib_flags &= ~RTNH_F_OFFLOAD; fi->fib_flags &= ~RTNH_F_OFFLOAD;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment