mirror of
https://github.com/openvswitch/ovs
synced 2025-09-01 14:55:18 +00:00
dpif-linux: Factor out port dumping helper functions.
These helpers simplify new code to be added in an upcoming commit. Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -699,46 +699,66 @@ struct dpif_linux_port_state {
|
|||||||
struct nl_dump dump;
|
struct nl_dump dump;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static void
|
||||||
dpif_linux_port_dump_start(const struct dpif *dpif_, void **statep)
|
dpif_linux_port_dump_start__(const struct dpif *dpif_, struct nl_dump *dump)
|
||||||
{
|
{
|
||||||
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
||||||
struct dpif_linux_port_state *state;
|
|
||||||
struct dpif_linux_vport request;
|
struct dpif_linux_vport request;
|
||||||
struct ofpbuf *buf;
|
struct ofpbuf *buf;
|
||||||
|
|
||||||
*statep = state = xmalloc(sizeof *state);
|
|
||||||
|
|
||||||
dpif_linux_vport_init(&request);
|
dpif_linux_vport_init(&request);
|
||||||
request.cmd = OVS_VPORT_CMD_GET;
|
request.cmd = OVS_VPORT_CMD_GET;
|
||||||
request.dp_ifindex = dpif->dp_ifindex;
|
request.dp_ifindex = dpif->dp_ifindex;
|
||||||
|
|
||||||
buf = ofpbuf_new(1024);
|
buf = ofpbuf_new(1024);
|
||||||
dpif_linux_vport_to_ofpbuf(&request, buf);
|
dpif_linux_vport_to_ofpbuf(&request, buf);
|
||||||
nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
|
nl_dump_start(dump, NETLINK_GENERIC, buf);
|
||||||
ofpbuf_delete(buf);
|
ofpbuf_delete(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
dpif_linux_port_dump_start(const struct dpif *dpif, void **statep)
|
||||||
|
{
|
||||||
|
struct dpif_linux_port_state *state;
|
||||||
|
|
||||||
|
*statep = state = xmalloc(sizeof *state);
|
||||||
|
dpif_linux_port_dump_start__(dpif, &state->dump);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
dpif_linux_port_dump_next__(const struct dpif *dpif_, struct nl_dump *dump,
|
||||||
|
struct dpif_linux_vport *vport)
|
||||||
|
{
|
||||||
|
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
||||||
|
struct ofpbuf buf;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
if (!nl_dump_next(dump, &buf)) {
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = dpif_linux_vport_from_ofpbuf(vport, &buf);
|
||||||
|
if (error) {
|
||||||
|
VLOG_WARN_RL(&error_rl, "%s: failed to parse vport record (%s)",
|
||||||
|
dpif_name(&dpif->dpif), ovs_strerror(error));
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_,
|
dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_,
|
||||||
struct dpif_port *dpif_port)
|
struct dpif_port *dpif_port)
|
||||||
{
|
{
|
||||||
struct dpif_linux_port_state *state = state_;
|
struct dpif_linux_port_state *state = state_;
|
||||||
struct dpif_linux_vport vport;
|
struct dpif_linux_vport vport;
|
||||||
struct ofpbuf buf;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (!nl_dump_next(&state->dump, &buf)) {
|
error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport);
|
||||||
return EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
dpif_port->name = CONST_CAST(char *, vport.name);
|
dpif_port->name = CONST_CAST(char *, vport.name);
|
||||||
dpif_port->type = CONST_CAST(char *, get_vport_type(&vport));
|
dpif_port->type = CONST_CAST(char *, get_vport_type(&vport));
|
||||||
dpif_port->port_no = vport.port_no;
|
dpif_port->port_no = vport.port_no;
|
||||||
|
Reference in New Issue
Block a user