mirror of
https://github.com/openvswitch/ovs
synced 2025-09-04 16:25:17 +00:00
netdev: Pass class structure, instead of type, to "create" function.
This opens up the possibility of storing private data at a relative offset to the class structure, instead of having to keep a separate table.
This commit is contained in:
@@ -487,8 +487,9 @@ netdev_linux_cache_cb(const struct rtnetlink_change *change,
|
|||||||
|
|
||||||
/* Creates the netdev device of 'type' with 'name'. */
|
/* Creates the netdev device of 'type' with 'name'. */
|
||||||
static int
|
static int
|
||||||
netdev_linux_create_system(const char *name, const char *type OVS_UNUSED,
|
netdev_linux_create_system(const struct netdev_class *class OVS_UNUSED,
|
||||||
const struct shash *args, struct netdev_dev **netdev_devp)
|
const char *name, const struct shash *args,
|
||||||
|
struct netdev_dev **netdev_devp)
|
||||||
{
|
{
|
||||||
struct netdev_dev_linux *netdev_dev;
|
struct netdev_dev_linux *netdev_dev;
|
||||||
int error;
|
int error;
|
||||||
@@ -520,8 +521,9 @@ netdev_linux_create_system(const char *name, const char *type OVS_UNUSED,
|
|||||||
* buffers, across all readers. Therefore once data is read it will
|
* buffers, across all readers. Therefore once data is read it will
|
||||||
* be unavailable to other reads for tap devices. */
|
* be unavailable to other reads for tap devices. */
|
||||||
static int
|
static int
|
||||||
netdev_linux_create_tap(const char *name, const char *type OVS_UNUSED,
|
netdev_linux_create_tap(const struct netdev_class *class OVS_UNUSED,
|
||||||
const struct shash *args, struct netdev_dev **netdev_devp)
|
const char *name, const struct shash *args,
|
||||||
|
struct netdev_dev **netdev_devp)
|
||||||
{
|
{
|
||||||
struct netdev_dev_linux *netdev_dev;
|
struct netdev_dev_linux *netdev_dev;
|
||||||
struct tap_state *state;
|
struct tap_state *state;
|
||||||
|
@@ -85,8 +85,9 @@ parse_config(const char *name, const struct shash *args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
netdev_patch_create(const char *name, const char *type OVS_UNUSED,
|
netdev_patch_create(const struct netdev_class *class OVS_UNUSED,
|
||||||
const struct shash *args, struct netdev_dev **netdev_devp)
|
const char *name, const struct shash *args,
|
||||||
|
struct netdev_dev **netdev_devp)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct odp_vport_add ova;
|
struct odp_vport_add ova;
|
||||||
|
@@ -129,11 +129,11 @@ struct netdev_class {
|
|||||||
* to be called. May be null if nothing is needed here. */
|
* to be called. May be null if nothing is needed here. */
|
||||||
void (*wait)(void);
|
void (*wait)(void);
|
||||||
|
|
||||||
/* Attempts to create a network device of 'type' with 'name'.
|
/* Attempts to create a network device named 'name' with initial 'args' in
|
||||||
* 'type' corresponds to the 'type' field used in the netdev_class
|
* 'netdev_class'. On success sets 'netdev_devp' to the newly created
|
||||||
* structure. On success sets 'netdev_devp' to the newly created device. */
|
* device. */
|
||||||
int (*create)(const char *name, const char *type, const struct shash *args,
|
int (*create)(const struct netdev_class *netdev_class, const char *name,
|
||||||
struct netdev_dev **netdev_devp);
|
const struct shash *args, struct netdev_dev **netdev_devp);
|
||||||
|
|
||||||
/* Destroys 'netdev_dev'.
|
/* Destroys 'netdev_dev'.
|
||||||
*
|
*
|
||||||
|
@@ -39,7 +39,7 @@ struct netdev_tunnel {
|
|||||||
struct netdev netdev;
|
struct netdev netdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int netdev_tunnel_create(const char *name, const char *type,
|
static int netdev_tunnel_create(const struct netdev_class *, const char *name,
|
||||||
const struct shash *args, struct netdev_dev **);
|
const struct shash *args, struct netdev_dev **);
|
||||||
|
|
||||||
static struct netdev_dev_tunnel *
|
static struct netdev_dev_tunnel *
|
||||||
@@ -155,7 +155,7 @@ parse_config(const char *name, const char *type, const struct shash *args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
netdev_tunnel_create(const char *name, const char *type,
|
netdev_tunnel_create(const struct netdev_class *class, const char *name,
|
||||||
const struct shash *args, struct netdev_dev **netdev_devp)
|
const struct shash *args, struct netdev_dev **netdev_devp)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@@ -163,11 +163,11 @@ netdev_tunnel_create(const char *name, const char *type,
|
|||||||
struct tnl_port_config port_config;
|
struct tnl_port_config port_config;
|
||||||
struct netdev_dev_tunnel *netdev_dev;
|
struct netdev_dev_tunnel *netdev_dev;
|
||||||
|
|
||||||
ovs_strlcpy(ova.port_type, type, sizeof ova.port_type);
|
ovs_strlcpy(ova.port_type, class->type, sizeof ova.port_type);
|
||||||
ovs_strlcpy(ova.devname, name, sizeof ova.devname);
|
ovs_strlcpy(ova.devname, name, sizeof ova.devname);
|
||||||
ova.config = &port_config;
|
ova.config = &port_config;
|
||||||
|
|
||||||
err = parse_config(name, type, args, &port_config);
|
err = parse_config(name, class->type, args, &port_config);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -190,12 +190,7 @@ netdev_tunnel_create(const char *name, const char *type,
|
|||||||
|
|
||||||
netdev_dev = xmalloc(sizeof *netdev_dev);
|
netdev_dev = xmalloc(sizeof *netdev_dev);
|
||||||
|
|
||||||
if (!strcmp(type, "gre")) {
|
netdev_dev_init(&netdev_dev->netdev_dev, name, class);
|
||||||
netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_gre_class);
|
|
||||||
} else {
|
|
||||||
netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_capwap_class);
|
|
||||||
}
|
|
||||||
|
|
||||||
*netdev_devp = &netdev_dev->netdev_dev;
|
*netdev_devp = &netdev_dev->netdev_dev;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -276,7 +276,7 @@ create_device(struct netdev_options *options, struct netdev_dev **netdev_devp)
|
|||||||
return EAFNOSUPPORT;
|
return EAFNOSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return netdev_class->create(options->name, options->type, options->args,
|
return netdev_class->create(netdev_class, options->name, options->args,
|
||||||
netdev_devp);
|
netdev_devp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user