mirror of
https://github.com/openvswitch/ovs
synced 2025-09-01 23:05:29 +00:00
dpif: Hide the contents of struct dpif.
This helps prepare for multiple dpif implementations, and ensures that code outside dpif.c does not depend on its internals.
This commit is contained in:
57
lib/dpif.c
57
lib/dpif.c
@@ -49,6 +49,13 @@
|
||||
#include "vlog.h"
|
||||
#define THIS_MODULE VLM_dpif
|
||||
|
||||
/* A datapath interface. */
|
||||
struct dpif {
|
||||
char *name;
|
||||
unsigned int minor;
|
||||
int fd;
|
||||
};
|
||||
|
||||
/* Rate limit for individual messages going to or from the datapath, output at
|
||||
* DBG level. This is very high because, if these are enabled, it is because
|
||||
* we really need to see them. */
|
||||
@@ -60,24 +67,26 @@ static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
|
||||
static int get_minor_from_name(const char *name, unsigned int *minor);
|
||||
static int name_to_minor(const char *name, unsigned int *minor);
|
||||
static int lookup_minor(const char *name, unsigned int *minor);
|
||||
static int open_by_minor(unsigned int minor, struct dpif *);
|
||||
static int open_by_minor(unsigned int minor, struct dpif **dpifp);
|
||||
static int make_openvswitch_device(unsigned int minor, char **fnp);
|
||||
static void check_rw_odp_flow(struct odp_flow *);
|
||||
|
||||
int
|
||||
dpif_open(const char *name, struct dpif *dpif)
|
||||
dpif_open(const char *name, struct dpif **dpifp)
|
||||
{
|
||||
struct dpif *dpif;
|
||||
unsigned int minor;
|
||||
int listen_mask;
|
||||
int error;
|
||||
|
||||
dpif->fd = -1;
|
||||
*dpifp = NULL;
|
||||
|
||||
error = name_to_minor(name, &dpif->minor);
|
||||
error = name_to_minor(name, &minor);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
error = open_by_minor(dpif->minor, dpif);
|
||||
error = open_by_minor(minor, &dpif);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
@@ -95,6 +104,7 @@ dpif_open(const char *name, struct dpif *dpif)
|
||||
dpif_close(dpif);
|
||||
return error;
|
||||
}
|
||||
*dpifp = dpif;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -103,9 +113,8 @@ dpif_close(struct dpif *dpif)
|
||||
{
|
||||
if (dpif) {
|
||||
free(dpif->name);
|
||||
dpif->name = NULL;
|
||||
close(dpif->fd);
|
||||
dpif->fd = -1;
|
||||
free(dpif);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,14 +136,17 @@ do_ioctl(const struct dpif *dpif, int cmd, const char *cmd_name,
|
||||
}
|
||||
|
||||
int
|
||||
dpif_create(const char *name, struct dpif *dpif)
|
||||
dpif_create(const char *name, struct dpif **dpifp)
|
||||
{
|
||||
unsigned int minor;
|
||||
int error;
|
||||
|
||||
*dpifp = NULL;
|
||||
if (!get_minor_from_name(name, &minor)) {
|
||||
/* Minor was specified in 'name', go ahead and create it. */
|
||||
error = open_by_minor(minor, dpif);
|
||||
struct dpif *dpif;
|
||||
|
||||
error = open_by_minor(minor, &dpif);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
@@ -146,19 +158,24 @@ dpif_create(const char *name, struct dpif *dpif)
|
||||
} else {
|
||||
error = ioctl(dpif->fd, ODP_DP_CREATE, name) < 0 ? errno : 0;
|
||||
}
|
||||
if (error) {
|
||||
if (!error) {
|
||||
*dpifp = dpif;
|
||||
} else {
|
||||
dpif_close(dpif);
|
||||
}
|
||||
return error;
|
||||
} else {
|
||||
for (minor = 0; minor < ODP_MAX; minor++) {
|
||||
error = open_by_minor(minor, dpif);
|
||||
struct dpif *dpif;
|
||||
|
||||
error = open_by_minor(minor, &dpif);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
error = ioctl(dpif->fd, ODP_DP_CREATE, name) < 0 ? errno : 0;
|
||||
if (!error) {
|
||||
*dpifp = dpif;
|
||||
return 0;
|
||||
}
|
||||
dpif_close(dpif);
|
||||
@@ -700,7 +717,7 @@ dpif_get_netflow_ids(const struct dpif *dpif,
|
||||
}
|
||||
|
||||
struct dpifmon {
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
struct nl_sock *sock;
|
||||
int local_ifindex;
|
||||
};
|
||||
@@ -718,7 +735,7 @@ dpifmon_create(const char *datapath_name, struct dpifmon **monp)
|
||||
if (error) {
|
||||
goto error;
|
||||
}
|
||||
error = dpif_port_get_name(&mon->dpif, ODPP_LOCAL,
|
||||
error = dpif_port_get_name(mon->dpif, ODPP_LOCAL,
|
||||
local_name, sizeof local_name);
|
||||
if (error) {
|
||||
goto error_close_dpif;
|
||||
@@ -741,7 +758,7 @@ dpifmon_create(const char *datapath_name, struct dpifmon **monp)
|
||||
return 0;
|
||||
|
||||
error_close_dpif:
|
||||
dpif_close(&mon->dpif);
|
||||
dpif_close(mon->dpif);
|
||||
error:
|
||||
free(mon);
|
||||
*monp = NULL;
|
||||
@@ -752,7 +769,7 @@ void
|
||||
dpifmon_destroy(struct dpifmon *mon)
|
||||
{
|
||||
if (mon) {
|
||||
dpif_close(&mon->dpif);
|
||||
dpif_close(mon->dpif);
|
||||
nl_sock_destroy(mon->sock);
|
||||
}
|
||||
}
|
||||
@@ -1025,14 +1042,14 @@ get_minor_from_name(const char *name, unsigned int *minor)
|
||||
}
|
||||
|
||||
static int
|
||||
open_by_minor(unsigned int minor, struct dpif *dpif)
|
||||
open_by_minor(unsigned int minor, struct dpif **dpifp)
|
||||
{
|
||||
struct dpif *dpif;
|
||||
int error;
|
||||
char *fn;
|
||||
int fd;
|
||||
|
||||
dpif->minor = -1;
|
||||
dpif->fd = -1;
|
||||
*dpifp = NULL;
|
||||
error = make_openvswitch_device(minor, &fn);
|
||||
if (error) {
|
||||
return error;
|
||||
@@ -1045,11 +1062,13 @@ open_by_minor(unsigned int minor, struct dpif *dpif)
|
||||
free(fn);
|
||||
return error;
|
||||
}
|
||||
|
||||
free(fn);
|
||||
|
||||
dpif = xmalloc(sizeof *dpif);
|
||||
dpif->name = xasprintf("dp%u", dpif->minor);
|
||||
dpif->minor = minor;
|
||||
dpif->fd = fd;
|
||||
*dpifp = dpif;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
12
lib/dpif.h
12
lib/dpif.h
@@ -27,17 +27,11 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct dpif;
|
||||
struct ofpbuf;
|
||||
|
||||
/* A datapath interface. Opaque. */
|
||||
struct dpif {
|
||||
char *name;
|
||||
unsigned int minor;
|
||||
int fd;
|
||||
};
|
||||
|
||||
int dpif_open(const char *name, struct dpif *);
|
||||
int dpif_create(const char *name, struct dpif *);
|
||||
int dpif_open(const char *name, struct dpif **);
|
||||
int dpif_create(const char *name, struct dpif **);
|
||||
void dpif_close(struct dpif *);
|
||||
|
||||
const char *dpif_name(const struct dpif *);
|
||||
|
@@ -192,7 +192,7 @@ struct ofproto {
|
||||
char *serial; /* Serial number. */
|
||||
|
||||
/* Datapath. */
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
struct dpifmon *dpifmon;
|
||||
struct port_array ports; /* Index is ODP port nr; ofport->opp.port_no is
|
||||
* OFP port nr. */
|
||||
@@ -262,7 +262,7 @@ ofproto_create(const char *datapath, const struct ofhooks *ofhooks, void *aux,
|
||||
struct dpifmon *dpifmon;
|
||||
struct odp_stats stats;
|
||||
struct ofproto *p;
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
int error;
|
||||
|
||||
*ofprotop = NULL;
|
||||
@@ -273,36 +273,36 @@ ofproto_create(const char *datapath, const struct ofhooks *ofhooks, void *aux,
|
||||
VLOG_ERR("failed to open datapath %s: %s", datapath, strerror(error));
|
||||
return error;
|
||||
}
|
||||
error = dpif_get_dp_stats(&dpif, &stats);
|
||||
error = dpif_get_dp_stats(dpif, &stats);
|
||||
if (error) {
|
||||
VLOG_ERR("failed to obtain stats for datapath %s: %s",
|
||||
datapath, strerror(error));
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
return error;
|
||||
}
|
||||
error = dpif_set_listen_mask(&dpif, ODPL_MISS | ODPL_ACTION);
|
||||
error = dpif_set_listen_mask(dpif, ODPL_MISS | ODPL_ACTION);
|
||||
if (error) {
|
||||
VLOG_ERR("failed to listen on datapath %s: %s",
|
||||
datapath, strerror(error));
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
return error;
|
||||
}
|
||||
dpif_flow_flush(&dpif);
|
||||
dpif_purge(&dpif);
|
||||
dpif_flow_flush(dpif);
|
||||
dpif_purge(dpif);
|
||||
|
||||
/* Start monitoring datapath ports for status changes. */
|
||||
error = dpifmon_create(datapath, &dpifmon);
|
||||
if (error) {
|
||||
VLOG_ERR("failed to starting monitoring datapath %s: %s",
|
||||
datapath, strerror(error));
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Initialize settings. */
|
||||
p = xcalloc(1, sizeof *p);
|
||||
p->fallback_dpid = pick_fallback_dpid();
|
||||
p->datapath_id = pick_datapath_id(&dpif, p->fallback_dpid);
|
||||
p->datapath_id = pick_datapath_id(dpif, p->fallback_dpid);
|
||||
VLOG_INFO("using datapath ID %012"PRIx64, p->datapath_id);
|
||||
p->manufacturer = xstrdup("Nicira Networks, Inc.");
|
||||
p->hardware = xstrdup("Reference Implementation");
|
||||
@@ -373,7 +373,7 @@ ofproto_set_datapath_id(struct ofproto *p, uint64_t datapath_id)
|
||||
uint64_t old_dpid = p->datapath_id;
|
||||
p->datapath_id = (datapath_id
|
||||
? datapath_id
|
||||
: pick_datapath_id(&p->dpif, p->fallback_dpid));
|
||||
: pick_datapath_id(p->dpif, p->fallback_dpid));
|
||||
if (p->datapath_id != old_dpid) {
|
||||
VLOG_INFO("datapath ID changed to %012"PRIx64, p->datapath_id);
|
||||
rconn_reconnect(p->controller->rconn);
|
||||
@@ -431,7 +431,7 @@ ofproto_set_in_band(struct ofproto *p, bool in_band)
|
||||
{
|
||||
if (in_band != (p->in_band != NULL)) {
|
||||
if (in_band) {
|
||||
return in_band_create(p, &p->dpif, p->switch_status,
|
||||
return in_band_create(p, p->dpif, p->switch_status,
|
||||
p->controller->rconn, &p->in_band);
|
||||
} else {
|
||||
ofproto_set_discovery(p, false, NULL, true);
|
||||
@@ -454,7 +454,7 @@ ofproto_set_discovery(struct ofproto *p, bool discovery,
|
||||
return error;
|
||||
}
|
||||
error = discovery_create(re, update_resolv_conf,
|
||||
&p->dpif, p->switch_status,
|
||||
p->dpif, p->switch_status,
|
||||
&p->discovery);
|
||||
if (error) {
|
||||
return error;
|
||||
@@ -705,7 +705,7 @@ ofproto_destroy(struct ofproto *p)
|
||||
ofconn_destroy(ofconn, p);
|
||||
}
|
||||
|
||||
dpif_close(&p->dpif);
|
||||
dpif_close(p->dpif);
|
||||
dpifmon_destroy(p->dpifmon);
|
||||
PORT_ARRAY_FOR_EACH (ofport, &p->ports, port_no) {
|
||||
ofport_free(ofport);
|
||||
@@ -760,7 +760,7 @@ ofproto_run1(struct ofproto *p)
|
||||
struct ofpbuf *buf;
|
||||
int error;
|
||||
|
||||
error = dpif_recv(&p->dpif, &buf);
|
||||
error = dpif_recv(p->dpif, &buf);
|
||||
if (error) {
|
||||
if (error == ENODEV) {
|
||||
/* Someone destroyed the datapath behind our back. The caller
|
||||
@@ -768,7 +768,7 @@ ofproto_run1(struct ofproto *p)
|
||||
* spin from here on out. */
|
||||
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
|
||||
VLOG_ERR_RL(&rl, "%s: datapath was destroyed externally",
|
||||
dpif_name(&p->dpif));
|
||||
dpif_name(p->dpif));
|
||||
return ENODEV;
|
||||
}
|
||||
break;
|
||||
@@ -895,7 +895,7 @@ ofproto_wait(struct ofproto *p)
|
||||
struct ofconn *ofconn;
|
||||
size_t i;
|
||||
|
||||
dpif_recv_wait(&p->dpif);
|
||||
dpif_recv_wait(p->dpif);
|
||||
dpifmon_wait(p->dpifmon);
|
||||
LIST_FOR_EACH (ofconn, struct ofconn, node, &p->all_conns) {
|
||||
ofconn_wait(ofconn);
|
||||
@@ -966,7 +966,7 @@ ofproto_send_packet(struct ofproto *p, const flow_t *flow,
|
||||
|
||||
/* XXX Should we translate the dpif_execute() errno value into an OpenFlow
|
||||
* error code? */
|
||||
dpif_execute(&p->dpif, flow->in_port, odp_actions.actions,
|
||||
dpif_execute(p->dpif, flow->in_port, odp_actions.actions,
|
||||
odp_actions.n_actions, packet);
|
||||
return 0;
|
||||
}
|
||||
@@ -1018,7 +1018,7 @@ ofproto_flush_flows(struct ofproto *ofproto)
|
||||
{
|
||||
COVERAGE_INC(ofproto_flush);
|
||||
classifier_for_each(&ofproto->cls, CLS_INC_ALL, destroy_rule, ofproto);
|
||||
dpif_flow_flush(&ofproto->dpif);
|
||||
dpif_flow_flush(ofproto->dpif);
|
||||
if (ofproto->in_band) {
|
||||
in_band_flushed(ofproto->in_band);
|
||||
}
|
||||
@@ -1041,7 +1041,7 @@ reinit_ports(struct ofproto *p)
|
||||
PORT_ARRAY_FOR_EACH (ofport, &p->ports, port_no) {
|
||||
svec_add (&devnames, (char *) ofport->opp.name);
|
||||
}
|
||||
dpif_port_list(&p->dpif, &odp_ports, &n_odp_ports);
|
||||
dpif_port_list(p->dpif, &odp_ports, &n_odp_ports);
|
||||
for (i = 0; i < n_odp_ports; i++) {
|
||||
svec_add (&devnames, odp_ports[i].devname);
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ refresh_port_group(struct ofproto *p, unsigned int group)
|
||||
ports[n_ports++] = port_no;
|
||||
}
|
||||
}
|
||||
dpif_port_group_set(&p->dpif, group, ports, n_ports);
|
||||
dpif_port_group_set(p->dpif, group, ports, n_ports);
|
||||
free(ports);
|
||||
}
|
||||
|
||||
@@ -1209,7 +1209,7 @@ update_port(struct ofproto *p, const char *devname)
|
||||
|
||||
COVERAGE_INC(ofproto_update_port);
|
||||
ofport = shash_find_data(&p->port_by_name, devname);
|
||||
error = dpif_port_query_by_name(&p->dpif, devname, &odp_port);
|
||||
error = dpif_port_query_by_name(p->dpif, devname, &odp_port);
|
||||
if (!error) {
|
||||
if (!ofport) {
|
||||
/* New port. */
|
||||
@@ -1262,7 +1262,7 @@ init_ports(struct ofproto *p)
|
||||
size_t i;
|
||||
int error;
|
||||
|
||||
error = dpif_port_list(&p->dpif, &ports, &n_ports);
|
||||
error = dpif_port_list(p->dpif, &ports, &n_ports);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
@@ -1464,7 +1464,7 @@ rule_execute(struct ofproto *ofproto, struct rule *rule,
|
||||
}
|
||||
|
||||
/* Execute the ODP actions. */
|
||||
if (!dpif_execute(&ofproto->dpif, flow->in_port,
|
||||
if (!dpif_execute(ofproto->dpif, flow->in_port,
|
||||
actions, n_actions, packet)) {
|
||||
struct odp_flow_stats stats;
|
||||
flow_extract_stats(flow, packet, &stats);
|
||||
@@ -1573,7 +1573,7 @@ do_put_flow(struct ofproto *ofproto, struct rule *rule, int flags,
|
||||
put->flow.actions = rule->odp_actions;
|
||||
put->flow.n_actions = rule->n_odp_actions;
|
||||
put->flags = flags;
|
||||
return dpif_flow_put(&ofproto->dpif, put);
|
||||
return dpif_flow_put(ofproto->dpif, put);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1654,7 +1654,7 @@ rule_uninstall(struct ofproto *p, struct rule *rule)
|
||||
odp_flow.key = rule->cr.flow;
|
||||
odp_flow.actions = NULL;
|
||||
odp_flow.n_actions = 0;
|
||||
if (!dpif_flow_del(&p->dpif, &odp_flow)) {
|
||||
if (!dpif_flow_del(p->dpif, &odp_flow)) {
|
||||
update_stats(rule, &odp_flow.stats);
|
||||
}
|
||||
rule->installed = false;
|
||||
@@ -1802,7 +1802,7 @@ handle_get_config_request(struct ofproto *p, struct ofconn *ofconn,
|
||||
bool drop_frags;
|
||||
|
||||
/* Figure out flags. */
|
||||
dpif_get_drop_frags(&p->dpif, &drop_frags);
|
||||
dpif_get_drop_frags(p->dpif, &drop_frags);
|
||||
flags = drop_frags ? OFPC_FRAG_DROP : OFPC_FRAG_NORMAL;
|
||||
if (ofconn->send_flow_exp) {
|
||||
flags |= OFPC_SEND_FLOW_EXP;
|
||||
@@ -1835,10 +1835,10 @@ handle_set_config(struct ofproto *p, struct ofconn *ofconn,
|
||||
if (ofconn == p->controller) {
|
||||
switch (flags & OFPC_FRAG_MASK) {
|
||||
case OFPC_FRAG_NORMAL:
|
||||
dpif_set_drop_frags(&p->dpif, false);
|
||||
dpif_set_drop_frags(p->dpif, false);
|
||||
break;
|
||||
case OFPC_FRAG_DROP:
|
||||
dpif_set_drop_frags(&p->dpif, true);
|
||||
dpif_set_drop_frags(p->dpif, true);
|
||||
break;
|
||||
default:
|
||||
VLOG_WARN_RL(&rl, "requested bad fragment mode (flags=%"PRIx16")",
|
||||
@@ -2143,7 +2143,7 @@ handle_packet_out(struct ofproto *p, struct ofconn *ofconn,
|
||||
return error;
|
||||
}
|
||||
|
||||
dpif_execute(&p->dpif, flow.in_port, actions.actions, actions.n_actions,
|
||||
dpif_execute(p->dpif, flow.in_port, actions.actions, actions.n_actions,
|
||||
&payload);
|
||||
ofpbuf_delete(buffer);
|
||||
|
||||
@@ -2286,7 +2286,7 @@ handle_table_stats_request(struct ofproto *p, struct ofconn *ofconn,
|
||||
n_wild = classifier_count(&p->cls) - classifier_count_exact(&p->cls);
|
||||
|
||||
/* Hash table. */
|
||||
dpif_get_dp_stats(&p->dpif, &dpstats);
|
||||
dpif_get_dp_stats(p->dpif, &dpstats);
|
||||
ots = append_stats_reply(sizeof *ots, ofconn, &msg);
|
||||
memset(ots, 0, sizeof *ots);
|
||||
ots->table_id = TABLEID_HASH;
|
||||
@@ -2381,7 +2381,7 @@ query_stats(struct ofproto *p, struct rule *rule,
|
||||
|
||||
packet_count = rule->packet_count;
|
||||
byte_count = rule->byte_count;
|
||||
if (!dpif_flow_get_multiple(&p->dpif, odp_flows, n_odp_flows)) {
|
||||
if (!dpif_flow_get_multiple(p->dpif, odp_flows, n_odp_flows)) {
|
||||
size_t i;
|
||||
for (i = 0; i < n_odp_flows; i++) {
|
||||
struct odp_flow *odp_flow = &odp_flows[i];
|
||||
@@ -3139,7 +3139,7 @@ update_used(struct ofproto *p)
|
||||
size_t i;
|
||||
int error;
|
||||
|
||||
error = dpif_flow_list_all(&p->dpif, &flows, &n_flows);
|
||||
error = dpif_flow_list_all(p->dpif, &flows, &n_flows);
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
@@ -3152,7 +3152,7 @@ update_used(struct ofproto *p)
|
||||
classifier_find_rule_exactly(&p->cls, &f->key, 0, UINT16_MAX));
|
||||
if (!rule || !rule->installed) {
|
||||
COVERAGE_INC(ofproto_unexpected_rule);
|
||||
dpif_flow_del(&p->dpif, f);
|
||||
dpif_flow_del(p->dpif, f);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -211,9 +211,9 @@ static int if_up(const char *netdev_name)
|
||||
static void
|
||||
do_add_dp(int argc UNUSED, char *argv[])
|
||||
{
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
run(dpif_create(argv[1], &dpif), "add_dp");
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
if (argc > 2) {
|
||||
do_add_if(argc, argv);
|
||||
}
|
||||
@@ -222,10 +222,10 @@ do_add_dp(int argc UNUSED, char *argv[])
|
||||
static void
|
||||
do_del_dp(int argc UNUSED, char *argv[])
|
||||
{
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
run(dpif_delete(&dpif), "del_dp");
|
||||
dpif_close(&dpif);
|
||||
run(dpif_delete(dpif), "del_dp");
|
||||
dpif_close(dpif);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -270,7 +270,7 @@ static void
|
||||
do_add_if(int argc UNUSED, char *argv[])
|
||||
{
|
||||
bool failure = false;
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
int i;
|
||||
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
@@ -320,10 +320,10 @@ do_add_if(int argc UNUSED, char *argv[])
|
||||
}
|
||||
}
|
||||
if (port < 0) {
|
||||
port = get_free_port(&dpif);
|
||||
port = get_free_port(dpif);
|
||||
}
|
||||
|
||||
error = dpif_port_add(&dpif, devname, port, flags);
|
||||
error = dpif_port_add(dpif, devname, port, flags);
|
||||
if (error) {
|
||||
ovs_error(error, "adding %s as port %"PRIu16" of %s failed",
|
||||
devname, port, argv[1]);
|
||||
@@ -332,7 +332,7 @@ do_add_if(int argc UNUSED, char *argv[])
|
||||
failure = true;
|
||||
}
|
||||
}
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
if (failure) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -362,7 +362,7 @@ static void
|
||||
do_del_if(int argc UNUSED, char *argv[])
|
||||
{
|
||||
bool failure = false;
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
int i;
|
||||
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
@@ -373,18 +373,18 @@ do_del_if(int argc UNUSED, char *argv[])
|
||||
|
||||
if (!name[strspn(name, "0123456789")]) {
|
||||
port = atoi(name);
|
||||
} else if (!get_port_number(&dpif, name, &port)) {
|
||||
} else if (!get_port_number(dpif, name, &port)) {
|
||||
failure = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
error = dpif_port_del(&dpif, port);
|
||||
error = dpif_port_del(dpif, port);
|
||||
if (error) {
|
||||
ovs_error(error, "deleting port %s from %s failed", name, argv[1]);
|
||||
failure = true;
|
||||
}
|
||||
}
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
if (failure) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -432,12 +432,12 @@ do_show(int argc UNUSED, char *argv[])
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *name = argv[i];
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
int error;
|
||||
|
||||
error = dpif_open(name, &dpif);
|
||||
if (!error) {
|
||||
show_dpif(&dpif);
|
||||
show_dpif(dpif);
|
||||
} else {
|
||||
ovs_error(error, "opening datapath %s failed", name);
|
||||
failure = true;
|
||||
@@ -447,13 +447,13 @@ do_show(int argc UNUSED, char *argv[])
|
||||
unsigned int i;
|
||||
for (i = 0; i < ODP_MAX; i++) {
|
||||
char name[128];
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
int error;
|
||||
|
||||
sprintf(name, "dp%u", i);
|
||||
error = dpif_open(name, &dpif);
|
||||
if (!error) {
|
||||
show_dpif(&dpif);
|
||||
show_dpif(dpif);
|
||||
} else if (error != ENODEV) {
|
||||
ovs_error(error, "opening datapath %s failed", name);
|
||||
failure = true;
|
||||
@@ -469,13 +469,13 @@ static void
|
||||
do_dump_flows(int argc UNUSED, char *argv[])
|
||||
{
|
||||
struct odp_flow *flows;
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
size_t n_flows;
|
||||
struct ds ds;
|
||||
size_t i;
|
||||
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
run(dpif_flow_list_all(&dpif, &flows, &n_flows), "listing all flows");
|
||||
run(dpif_flow_list_all(dpif, &flows, &n_flows), "listing all flows");
|
||||
|
||||
ds_init(&ds);
|
||||
for (i = 0; i < n_flows; i++) {
|
||||
@@ -485,40 +485,40 @@ do_dump_flows(int argc UNUSED, char *argv[])
|
||||
|
||||
f->actions = actions;
|
||||
f->n_actions = MAX_ACTIONS;
|
||||
dpif_flow_get(&dpif, f);
|
||||
dpif_flow_get(dpif, f);
|
||||
|
||||
ds_clear(&ds);
|
||||
format_odp_flow(&ds, f);
|
||||
printf("%s\n", ds_cstr(&ds));
|
||||
}
|
||||
ds_destroy(&ds);
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
}
|
||||
|
||||
static void
|
||||
do_del_flows(int argc UNUSED, char *argv[])
|
||||
{
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
run(dpif_flow_flush(&dpif), "deleting all flows");
|
||||
dpif_close(&dpif);
|
||||
run(dpif_flow_flush(dpif), "deleting all flows");
|
||||
dpif_close(dpif);
|
||||
}
|
||||
|
||||
static void
|
||||
do_dump_groups(int argc UNUSED, char *argv[])
|
||||
{
|
||||
struct odp_stats stats;
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
unsigned int i;
|
||||
|
||||
run(dpif_open(argv[1], &dpif), "opening datapath");
|
||||
run(dpif_get_dp_stats(&dpif, &stats), "get datapath stats");
|
||||
run(dpif_get_dp_stats(dpif, &stats), "get datapath stats");
|
||||
for (i = 0; i < stats.max_groups; i++) {
|
||||
uint16_t ports[UINT16_MAX];
|
||||
size_t n_ports;
|
||||
|
||||
if (!dpif_port_group_get(&dpif, i, ports,
|
||||
if (!dpif_port_group_get(dpif, i, ports,
|
||||
ARRAY_SIZE(ports), &n_ports) && n_ports) {
|
||||
size_t j;
|
||||
|
||||
@@ -529,7 +529,7 @@ do_dump_groups(int argc UNUSED, char *argv[])
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -251,7 +251,7 @@ static void run(int retval, const char *message, ...)
|
||||
static void
|
||||
open_vconn(const char *name, struct vconn **vconnp)
|
||||
{
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
struct stat s;
|
||||
|
||||
if (strstr(name, ":")) {
|
||||
@@ -268,9 +268,9 @@ open_vconn(const char *name, struct vconn **vconnp)
|
||||
char *socket_name;
|
||||
char *vconn_name;
|
||||
|
||||
run(dpif_port_get_name(&dpif, ODPP_LOCAL, dpif_name, sizeof dpif_name),
|
||||
run(dpif_port_get_name(dpif, ODPP_LOCAL, dpif_name, sizeof dpif_name),
|
||||
"obtaining name of %s", dpif_name);
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
if (strcmp(dpif_name, name)) {
|
||||
VLOG_INFO("datapath %s is named %s", name, dpif_name);
|
||||
}
|
||||
|
@@ -158,7 +158,7 @@ struct bridge {
|
||||
struct ofproto *ofproto; /* OpenFlow switch. */
|
||||
|
||||
/* Kernel datapath information. */
|
||||
struct dpif dpif; /* Kernel datapath. */
|
||||
struct dpif *dpif; /* Datapath. */
|
||||
struct port_array ifaces; /* Indexed by kernel datapath port number. */
|
||||
|
||||
/* Bridge ports. */
|
||||
@@ -260,7 +260,7 @@ bridge_get_ifaces(struct svec *svec)
|
||||
struct iface *iface = port->ifaces[j];
|
||||
if (iface->dp_ifidx < 0) {
|
||||
VLOG_ERR("%s interface not in datapath %s, ignoring",
|
||||
iface->name, dpif_name(&br->dpif));
|
||||
iface->name, dpif_name(br->dpif));
|
||||
} else {
|
||||
if (iface->dp_ifidx != ODPP_LOCAL) {
|
||||
svec_add(svec, iface->name);
|
||||
@@ -281,19 +281,19 @@ bridge_init(void)
|
||||
bond_init();
|
||||
|
||||
for (i = 0; i < DP_MAX; i++) {
|
||||
struct dpif dpif;
|
||||
struct dpif *dpif;
|
||||
char devname[16];
|
||||
|
||||
sprintf(devname, "dp%d", i);
|
||||
retval = dpif_open(devname, &dpif);
|
||||
if (!retval) {
|
||||
char dpif_name[IF_NAMESIZE];
|
||||
if (dpif_port_get_name(&dpif, ODPP_LOCAL,
|
||||
if (dpif_port_get_name(dpif, ODPP_LOCAL,
|
||||
dpif_name, sizeof dpif_name)
|
||||
|| !cfg_has("bridge.%s.port", dpif_name)) {
|
||||
dpif_delete(&dpif);
|
||||
dpif_delete(dpif);
|
||||
}
|
||||
dpif_close(&dpif);
|
||||
dpif_close(dpif);
|
||||
} else if (retval != ENODEV) {
|
||||
VLOG_ERR("failed to delete datapath dp%d: %s",
|
||||
i, strerror(retval));
|
||||
@@ -418,16 +418,16 @@ bridge_reconfigure(void)
|
||||
size_t n_dpif_ports;
|
||||
struct svec want_ifaces;
|
||||
|
||||
dpif_port_list(&br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
bridge_get_all_ifaces(br, &want_ifaces);
|
||||
for (i = 0; i < n_dpif_ports; i++) {
|
||||
const struct odp_port *p = &dpif_ports[i];
|
||||
if (!svec_contains(&want_ifaces, p->devname)
|
||||
&& strcmp(p->devname, br->name)) {
|
||||
int retval = dpif_port_del(&br->dpif, p->port);
|
||||
int retval = dpif_port_del(br->dpif, p->port);
|
||||
if (retval) {
|
||||
VLOG_ERR("failed to remove %s interface from %s: %s",
|
||||
p->devname, dpif_name(&br->dpif),
|
||||
p->devname, dpif_name(br->dpif),
|
||||
strerror(retval));
|
||||
}
|
||||
}
|
||||
@@ -441,7 +441,7 @@ bridge_reconfigure(void)
|
||||
struct svec cur_ifaces, want_ifaces, add_ifaces;
|
||||
int next_port_no;
|
||||
|
||||
dpif_port_list(&br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
svec_init(&cur_ifaces);
|
||||
for (i = 0; i < n_dpif_ports; i++) {
|
||||
svec_add(&cur_ifaces, dpif_ports[i].devname);
|
||||
@@ -456,17 +456,17 @@ bridge_reconfigure(void)
|
||||
const char *if_name = add_ifaces.names[i];
|
||||
for (;;) {
|
||||
int internal = cfg_get_bool(0, "iface.%s.internal", if_name);
|
||||
int error = dpif_port_add(&br->dpif, if_name, next_port_no++,
|
||||
int error = dpif_port_add(br->dpif, if_name, next_port_no++,
|
||||
internal ? ODP_PORT_INTERNAL : 0);
|
||||
if (error != EEXIST) {
|
||||
if (next_port_no >= 256) {
|
||||
VLOG_ERR("ran out of valid port numbers on %s",
|
||||
dpif_name(&br->dpif));
|
||||
dpif_name(br->dpif));
|
||||
goto out;
|
||||
}
|
||||
if (error) {
|
||||
VLOG_ERR("failed to add %s interface to %s: %s",
|
||||
if_name, dpif_name(&br->dpif),
|
||||
if_name, dpif_name(br->dpif),
|
||||
strerror(error));
|
||||
}
|
||||
break;
|
||||
@@ -495,14 +495,14 @@ bridge_reconfigure(void)
|
||||
struct iface *iface = port->ifaces[j];
|
||||
if (iface->dp_ifidx < 0) {
|
||||
VLOG_ERR("%s interface not in %s, dropping",
|
||||
iface->name, dpif_name(&br->dpif));
|
||||
iface->name, dpif_name(br->dpif));
|
||||
iface_destroy(iface);
|
||||
} else {
|
||||
if (iface->dp_ifidx == ODPP_LOCAL) {
|
||||
local_iface = iface;
|
||||
}
|
||||
VLOG_DBG("%s has interface %s on port %d",
|
||||
dpif_name(&br->dpif),
|
||||
dpif_name(br->dpif),
|
||||
iface->name, iface->dp_ifidx);
|
||||
j++;
|
||||
}
|
||||
@@ -531,7 +531,7 @@ bridge_reconfigure(void)
|
||||
ofproto_set_datapath_id(br->ofproto, dpid);
|
||||
|
||||
/* Set NetFlow configuration on this bridge. */
|
||||
dpif_get_netflow_ids(&br->dpif, &engine_type, &engine_id);
|
||||
dpif_get_netflow_ids(br->dpif, &engine_type, &engine_id);
|
||||
if (cfg_has("netflow.%s.engine-type", br->name)) {
|
||||
engine_type = cfg_get_int(0, "netflow.%s.engine-type",
|
||||
br->name);
|
||||
@@ -812,7 +812,7 @@ bridge_create(const char *name)
|
||||
free(br);
|
||||
return NULL;
|
||||
}
|
||||
dpif_flow_flush(&br->dpif);
|
||||
dpif_flow_flush(br->dpif);
|
||||
} else if (error) {
|
||||
VLOG_ERR("failed to create datapath %s: %s", name, strerror(error));
|
||||
free(br);
|
||||
@@ -822,8 +822,8 @@ bridge_create(const char *name)
|
||||
error = ofproto_create(name, &bridge_ofhooks, br, &br->ofproto);
|
||||
if (error) {
|
||||
VLOG_ERR("failed to create switch %s: %s", name, strerror(error));
|
||||
dpif_delete(&br->dpif);
|
||||
dpif_close(&br->dpif);
|
||||
dpif_delete(br->dpif);
|
||||
dpif_close(br->dpif);
|
||||
free(br);
|
||||
return NULL;
|
||||
}
|
||||
@@ -840,7 +840,7 @@ bridge_create(const char *name)
|
||||
|
||||
list_push_back(&all_bridges, &br->node);
|
||||
|
||||
VLOG_INFO("created bridge %s on %s", br->name, dpif_name(&br->dpif));
|
||||
VLOG_INFO("created bridge %s on %s", br->name, dpif_name(br->dpif));
|
||||
|
||||
return br;
|
||||
}
|
||||
@@ -855,12 +855,12 @@ bridge_destroy(struct bridge *br)
|
||||
port_destroy(br->ports[br->n_ports - 1]);
|
||||
}
|
||||
list_remove(&br->node);
|
||||
error = dpif_delete(&br->dpif);
|
||||
error = dpif_delete(br->dpif);
|
||||
if (error && error != ENOENT) {
|
||||
VLOG_ERR("failed to delete %s: %s",
|
||||
dpif_name(&br->dpif), strerror(error));
|
||||
dpif_name(br->dpif), strerror(error));
|
||||
}
|
||||
dpif_close(&br->dpif);
|
||||
dpif_close(br->dpif);
|
||||
ofproto_destroy(br->ofproto);
|
||||
free(br->controller);
|
||||
mac_learning_destroy(br->ml);
|
||||
@@ -1248,17 +1248,17 @@ bridge_fetch_dp_ifaces(struct bridge *br)
|
||||
}
|
||||
port_array_clear(&br->ifaces);
|
||||
|
||||
dpif_port_list(&br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
|
||||
for (i = 0; i < n_dpif_ports; i++) {
|
||||
struct odp_port *p = &dpif_ports[i];
|
||||
struct iface *iface = iface_lookup(br, p->devname);
|
||||
if (iface) {
|
||||
if (iface->dp_ifidx >= 0) {
|
||||
VLOG_WARN("%s reported interface %s twice",
|
||||
dpif_name(&br->dpif), p->devname);
|
||||
dpif_name(br->dpif), p->devname);
|
||||
} else if (iface_from_dp_ifidx(br, p->port)) {
|
||||
VLOG_WARN("%s reported interface %"PRIu16" twice",
|
||||
dpif_name(&br->dpif), p->port);
|
||||
dpif_name(br->dpif), p->port);
|
||||
} else {
|
||||
port_array_set(&br->ifaces, p->port, iface);
|
||||
iface->dp_ifidx = p->port;
|
||||
|
Reference in New Issue
Block a user