}
}
- if (!netdev_open_default(bond->name, &bond_dev)) {
+ if (!netdev_open(bond->name, "system", &bond_dev)) {
netdev_set_stats(bond_dev, &bond_stats);
netdev_close(bond_dev);
}
uint16_t port_no)
{
struct dp_netdev_port *port;
- struct netdev_options netdev_options;
struct netdev *netdev;
bool internal;
int mtu;
}
/* Open and validate network device. */
- memset(&netdev_options, 0, sizeof netdev_options);
- netdev_options.name = devname;
if (dp->class == &dpif_dummy_class) {
- netdev_options.type = "dummy";
+ type = "dummy";
} else if (internal) {
- netdev_options.type = "tap";
+ type = "tap";
}
- error = netdev_open(&netdev_options, &netdev);
+ error = netdev_open(devname, type, &netdev);
if (error) {
return error;
}
shash_add(sh, "tunnel_egress_iface", xstrdup(iface));
- if (!netdev_open_default(iface, &egress_netdev)) {
+ if (!netdev_open(iface, "system", &egress_netdev)) {
shash_add(sh, "tunnel_egress_iface_carrier",
xstrdup(netdev_get_carrier(egress_netdev)
? "up" : "down"));
}
}
-/* Opens the network device named 'name' (e.g. "eth0") and returns zero if
- * successful, otherwise a positive errno value. On success, sets '*netdevp'
- * to the new network device, otherwise to null.
+/* Opens the network device named 'name' (e.g. "eth0") of the specified 'type'
+ * (e.g. "system") and returns zero if successful, otherwise a positive errno
+ * value. On success, sets '*netdevp' to the new network device, otherwise to
+ * null.
*
* Some network devices may need to be configured (with netdev_set_config())
* before they can be used. */
int
-netdev_open(struct netdev_options *options, struct netdev **netdevp)
+netdev_open(const char *name, const char *type, struct netdev **netdevp)
{
struct netdev_dev *netdev_dev;
int error;
*netdevp = NULL;
netdev_initialize();
- netdev_dev = shash_find_data(&netdev_dev_shash, options->name);
+ netdev_dev = shash_find_data(&netdev_dev_shash, name);
if (!netdev_dev) {
const struct netdev_class *class;
- class = netdev_lookup_provider(options->type);
+ class = netdev_lookup_provider(type);
if (!class) {
VLOG_WARN("could not create netdev %s of unknown type %s",
- options->name, options->type);
+ name, type);
return EAFNOSUPPORT;
}
- error = class->create(class, options->name, &netdev_dev);
+ error = class->create(class, name, &netdev_dev);
if (error) {
return error;
}
return error;
}
-int
-netdev_open_default(const char *name, struct netdev **netdevp)
-{
- struct netdev_options options;
-
- memset(&options, 0, sizeof options);
- options.name = name;
-
- return netdev_open(&options, netdevp);
-}
-
/* Reconfigures the device 'netdev' with 'args'. 'args' may be empty
* or NULL if none are needed. */
int
struct netdev *netdev;
int error;
- error = netdev_open_default(name, &netdev);
+ error = netdev_open(name, "system", &netdev);
if (!error) {
netdev_close(netdev);
return true;
SSET_FOR_EACH (name, &dev_list) {
struct in_addr dev_in4;
- if (!netdev_open_default(name, &netdev)
+ if (!netdev_open(name, "system", &netdev)
&& !netdev_get_in4(netdev, &dev_in4, NULL)
&& dev_in4.s_addr == in4->s_addr) {
goto exit;
uint64_t tx_window_errors;
};
-struct netdev_options {
- const char *name;
- const char *type;
-};
-
struct netdev;
struct netdev_class;
void netdev_enumerate_types(struct sset *types);
/* Open and close. */
-int netdev_open(struct netdev_options *, struct netdev **);
-int netdev_open_default(const char *name, struct netdev **);
+int netdev_open(const char *name, const char *type, struct netdev **);
void netdev_close(struct netdev *);
bool netdev_exists(const char *name);
{
netdev_close(r->remote_netdev);
- retval = netdev_open_default(next_hop_dev, &r->remote_netdev);
+ retval = netdev_open(next_hop_dev, "system", &r->remote_netdev);
if (retval) {
VLOG_WARN_RL(&rl, "cannot open netdev %s (next hop "
"to controller "IP_FMT"): %s",
int error;
*in_bandp = NULL;
- error = netdev_open_default(local_name, &local_netdev);
+ error = netdev_open(local_name, "system", &local_netdev);
if (error) {
VLOG_ERR("failed to initialize in-band control: cannot open "
"datapath local port %s (%s)", local_name, strerror(error));
if (agent_device) {
struct netdev *netdev;
- if (!netdev_open_default(agent_device, &netdev)) {
+ if (!netdev_open(agent_device, "system", &netdev)) {
int error = netdev_get_in4(netdev, &in4, NULL);
netdev_close(netdev);
if (!error) {
dpif_sflow_del_port(ds, odp_port);
/* Open network device. */
- error = netdev_open_default(netdev_name, &netdev);
+ error = netdev_open(netdev_name, "system", &netdev);
if (error) {
VLOG_WARN_RL(&rl, "failed to open network device \"%s\": %s",
netdev_name, strerror(error));
ofport_open(const struct ofproto_port *ofproto_port, struct ofp_phy_port *opp)
{
uint32_t curr, advertised, supported, peer;
- struct netdev_options netdev_options;
enum netdev_flags flags;
struct netdev *netdev;
int error;
- memset(&netdev_options, 0, sizeof netdev_options);
- netdev_options.name = ofproto_port->name;
- netdev_options.type = ofproto_port->type;
-
- error = netdev_open(&netdev_options, &netdev);
+ error = netdev_open(ofproto_port->name, ofproto_port->type, &netdev);
if (error) {
VLOG_WARN_RL(&rl, "ignoring port %s (%"PRIu16") because netdev %s "
"cannot be opened (%s)",
SSET_FOR_EACH (port, &s.ports) {
struct netdev *netdev;
- error = netdev_open_default(port, &netdev);
+ error = netdev_open(port, "system", &netdev);
if (error) {
VLOG_FATAL("%s: failed to open network device (%s)",
port, strerror(error));
struct netdev *netdev;
int retval;
- retval = netdev_open_default(netdev_name, &netdev);
+ retval = netdev_open(netdev_name, "system", &netdev);
if (!retval) {
retval = netdev_turn_flags_on(netdev, NETDEV_UP, true);
netdev_close(netdev);
run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath");
for (i = 2; i < argc; i++) {
+ const char *name, *type;
char *save_ptr = NULL;
- struct netdev_options options;
struct netdev *netdev = NULL;
struct shash args;
char *option;
int error;
- options.name = strtok_r(argv[i], ",", &save_ptr);
- options.type = "system";
+ name = strtok_r(argv[i], ",", &save_ptr);
+ type = "system";
- if (!options.name) {
+ if (!name) {
ovs_error(0, "%s is not a valid network device name", argv[i]);
continue;
}
}
if (!strcmp(key, "type")) {
- options.type = value;
+ type = value;
} else if (!shash_add_once(&args, key, value)) {
ovs_error(0, "duplicate \"%s\" option", key);
}
}
- error = netdev_open(&options, &netdev);
+ error = netdev_open(name, type, &netdev);
if (error) {
- ovs_error(error, "%s: failed to open network device",
- options.name);
+ ovs_error(error, "%s: failed to open network device", name);
goto next;
}
error = netdev_set_config(netdev, &args);
if (error) {
- ovs_error(error, "%s: failed to configure network device",
- options.name);
+ ovs_error(error, "%s: failed to configure network device", name);
goto next;
}
error = dpif_port_add(dpif, netdev, NULL);
if (error) {
- ovs_error(error, "adding %s to %s failed", options.name, argv[1]);
+ ovs_error(error, "adding %s to %s failed", name, argv[1]);
goto next;
}
- error = if_up(options.name);
+ error = if_up(name);
next:
netdev_close(netdev);
printf("\tport %u: %s", dpif_port.port_no, dpif_port.name);
if (strcmp(dpif_port.type, "system")) {
- struct netdev_options netdev_options;
struct netdev *netdev;
int error;
printf (" (%s", dpif_port.type);
- netdev_options.name = dpif_port.name;
- netdev_options.type = dpif_port.type;
- error = netdev_open(&netdev_options, &netdev);
+ error = netdev_open(dpif_port.name, dpif_port.type, &netdev);
if (!error) {
struct shash config;
/* Open the netdev. */
if (!iface->netdev) {
- struct netdev_options options;
- options.name = iface->name;
- options.type = iface->type;
- error = netdev_open(&options, &iface->netdev);
+ error = netdev_open(iface->name, iface->type, &iface->netdev);
if (error) {
VLOG_WARN("could not open network device %s (%s)",
iface->name, strerror(error));
if (port_is_bond_fake_iface(port)) {
if (ofproto_port_query_by_name(br->ofproto, port->name,
&ofproto_port)) {
- struct netdev_options options;
struct netdev *netdev;
int error;
- options.name = port->name;
- options.type = "internal";
- error = netdev_open(&options, &netdev);
+ error = netdev_open(port->name, "internal", &netdev);
if (!error) {
ofproto_port_add(br->ofproto, netdev, NULL);
netdev_close(netdev);
struct mac *mac = &local_macs[n_local_macs];
struct netdev *netdev;
- error = netdev_open_default(iface_name, &netdev);
+ error = netdev_open(iface_name, "system", &netdev);
if (!error) {
if (!netdev_get_etheraddr(netdev, mac->addr)) {
n_local_macs++;