/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <net/if.h>
#include <linux/types.h>
#include <linux/pkt_sched.h>
-#include <linux/rtnetlink.h>
-#include <linux/sockios.h>
#include <poll.h>
#include <stdlib.h>
#include <strings.h>
/* Attributes. */
const char *name; /* OVS_DP_ATTR_NAME. */
const uint32_t *upcall_pid; /* OVS_DP_ATTR_UPCALL_PID. */
+ uint32_t user_features; /* OVS_DP_ATTR_USER_FEATURES */
struct ovs_dp_stats stats; /* OVS_DP_ATTR_STATS. */
struct ovs_dp_megaflow_stats megaflow_stats;
/* OVS_DP_ATTR_MEGAFLOW_STATS.*/
static int dpif_linux_init(void);
static int open_dpif(const struct dpif_linux_dp *, struct dpif **);
static uint32_t dpif_linux_port_get_pid(const struct dpif *,
- odp_port_t port_no);
+ odp_port_t port_no, uint32_t hash);
static int dpif_linux_refresh_channels(struct dpif *);
static void dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *,
dpif_linux_enumerate(struct sset *all_dps)
{
struct nl_dump dump;
- struct ofpbuf msg;
+ uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
+ struct ofpbuf msg, buf;
int error;
error = dpif_linux_init();
return error;
}
+ ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
dpif_linux_dp_dump_start(&dump);
- while (nl_dump_next(&dump, &msg)) {
+ while (nl_dump_next(&dump, &msg, &buf)) {
struct dpif_linux_dp dp;
if (!dpif_linux_dp_from_ofpbuf(&dp, &msg)) {
sset_add(all_dps, dp.name);
}
}
+ ofpbuf_uninit(&buf);
return nl_dump_done(&dump);
}
upcall_pid = 0;
dp_request.upcall_pid = &upcall_pid;
} else {
- dp_request.cmd = OVS_DP_CMD_GET;
+ /* Use OVS_DP_CMD_SET to report user features */
+ dp_request.cmd = OVS_DP_CMD_SET;
}
dp_request.name = name;
+ dp_request.user_features |= OVS_DP_F_UNALIGNED;
error = dpif_linux_dp_transact(&dp_request, &dp, &buf);
if (error) {
return error;
dpif->n_events = dpif->event_offset = 0;
/* Don't close dpif->epoll_fd since that would cause other threads that
- * call dpif_recv_wait(dpif) to wait on an arbitrary fd or a closed fd. */
+ * call dpif_recv_wait() to wait on an arbitrary fd or a closed fd. */
}
static int
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
switch (vport->type) {
- case OVS_VPORT_TYPE_NETDEV:
- return "system";
+ case OVS_VPORT_TYPE_NETDEV: {
+ const char *type = netdev_get_type_from_name(vport->name);
+
+ return type ? type : "system";
+ }
case OVS_VPORT_TYPE_INTERNAL:
return "internal";
ofpbuf_use_stack(&options, options_stub, sizeof options_stub);
nl_msg_put_u16(&options, OVS_TUNNEL_ATTR_DST_PORT,
ntohs(tnl_cfg->dst_port));
- request.options = options.data;
- request.options_len = options.size;
+ request.options = ofpbuf_data(&options);
+ request.options_len = ofpbuf_size(&options);
}
request.port_no = *port_nop;
}
static uint32_t
-dpif_linux_get_max_ports(const struct dpif *dpif OVS_UNUSED)
-{
- return MAX_PORTS;
-}
-
-static uint32_t
-dpif_linux_port_get_pid(const struct dpif *dpif_, odp_port_t port_no)
+dpif_linux_port_get_pid(const struct dpif *dpif_, odp_port_t port_no,
+ uint32_t hash OVS_UNUSED)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
uint32_t port_idx = odp_to_u32(port_no);
/* The ODPP_NONE "reserved" port number uses the "ovs-system"'s
* channel, since it is not heavily loaded. */
uint32_t idx = port_idx >= dpif->uc_array_size ? 0 : port_idx;
- pid = nl_sock_pid(dpif->channels[idx].sock);
+ const struct nl_sock *sock = dpif->channels[idx].sock;
+ pid = sock ? nl_sock_pid(sock) : 0;
}
ovs_mutex_unlock(&dpif->upcall_lock);
struct dpif_linux_port_state {
struct nl_dump dump;
+ struct ofpbuf buf;
};
static void
*statep = state = xmalloc(sizeof *state);
dpif_linux_port_dump_start__(dpif, &state->dump);
+ ofpbuf_init(&state->buf, NL_DUMP_BUFSIZE);
return 0;
}
-static bool
+static int
dpif_linux_port_dump_next__(const struct dpif *dpif_, struct nl_dump *dump,
- struct dpif_linux_vport *vport)
+ struct dpif_linux_vport *vport,
+ struct ofpbuf *buffer)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct ofpbuf buf;
int error;
- if (!nl_dump_next(dump, &buf)) {
+ if (!nl_dump_next(dump, &buf, buffer)) {
return EOF;
}
struct dpif_linux_vport vport;
int error;
- error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport);
+ error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport,
+ &state->buf);
if (error) {
return error;
}
struct dpif_linux_port_state *state = state_;
int error = nl_dump_done(&state->dump);
+ ofpbuf_uninit(&state->buf);
free(state);
return error;
}
dpif_linux_flow_get_stats(&reply, stats);
}
if (actionsp) {
- buf->data = CONST_CAST(struct nlattr *, reply.actions);
- buf->size = reply.actions_len;
+ ofpbuf_set_data(buf, CONST_CAST(struct nlattr *, reply.actions));
+ ofpbuf_set_size(buf, reply.actions_len);
*actionsp = buf;
} else {
ofpbuf_delete(buf);
}
struct dpif_linux_flow_state {
- struct nl_dump dump;
struct dpif_linux_flow flow;
struct dpif_flow_stats stats;
- struct ofpbuf *buf;
+ struct ofpbuf buffer; /* Always used to store flows. */
+ struct ofpbuf *tmp; /* Used if kernel does not supply actions. */
+};
+
+struct dpif_linux_flow_iter {
+ struct nl_dump dump;
+ atomic_int status;
};
+static void
+dpif_linux_flow_dump_state_init(void **statep)
+{
+ struct dpif_linux_flow_state *state;
+
+ *statep = state = xmalloc(sizeof *state);
+ ofpbuf_init(&state->buffer, NL_DUMP_BUFSIZE);
+ state->tmp = NULL;
+}
+
+static void
+dpif_linux_flow_dump_state_uninit(void *state_)
+{
+ struct dpif_linux_flow_state *state = state_;
+
+ ofpbuf_uninit(&state->buffer);
+ ofpbuf_delete(state->tmp);
+ free(state);
+}
+
static int
-dpif_linux_flow_dump_start(const struct dpif *dpif_, void **statep)
+dpif_linux_flow_dump_start(const struct dpif *dpif_, void **iterp)
{
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- struct dpif_linux_flow_state *state;
+ struct dpif_linux_flow_iter *iter;
struct dpif_linux_flow request;
struct ofpbuf *buf;
- *statep = state = xmalloc(sizeof *state);
+ *iterp = iter = xmalloc(sizeof *iter);
dpif_linux_flow_init(&request);
request.cmd = OVS_FLOW_CMD_GET;
buf = ofpbuf_new(1024);
dpif_linux_flow_to_ofpbuf(&request, buf);
- nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
+ nl_dump_start(&iter->dump, NETLINK_GENERIC, buf);
ofpbuf_delete(buf);
-
- state->buf = NULL;
+ atomic_init(&iter->status, 0);
return 0;
}
static int
-dpif_linux_flow_dump_next(const struct dpif *dpif_ OVS_UNUSED, void *state_,
+dpif_linux_flow_dump_next(const struct dpif *dpif_, void *iter_, void *state_,
const struct nlattr **key, size_t *key_len,
const struct nlattr **mask, size_t *mask_len,
const struct nlattr **actions, size_t *actions_len,
const struct dpif_flow_stats **stats)
{
+ struct dpif_linux_flow_iter *iter = iter_;
struct dpif_linux_flow_state *state = state_;
struct ofpbuf buf;
int error;
do {
- ofpbuf_delete(state->buf);
- state->buf = NULL;
+ ofpbuf_delete(state->tmp);
+ state->tmp = NULL;
- if (!nl_dump_next(&state->dump, &buf)) {
+ if (!nl_dump_next(&iter->dump, &buf, &state->buffer)) {
return EOF;
}
error = dpif_linux_flow_from_ofpbuf(&state->flow, &buf);
if (error) {
+ atomic_store(&iter->status, error);
return error;
}
if (actions && !state->flow.actions) {
error = dpif_linux_flow_get__(dpif_, state->flow.key,
state->flow.key_len,
- &state->flow, &state->buf);
+ &state->flow, &state->tmp);
if (error == ENOENT) {
VLOG_DBG("dumped flow disappeared on get");
} else if (error) {
return error;
}
-static int
-dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
+static bool
+dpif_linux_flow_dump_next_may_destroy_keys(void *state_)
{
struct dpif_linux_flow_state *state = state_;
- int error = nl_dump_done(&state->dump);
- ofpbuf_delete(state->buf);
- free(state);
- return error;
+
+ return ofpbuf_size(&state->buffer) ? false : true;
+}
+
+static int
+dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *iter_)
+{
+ struct dpif_linux_flow_iter *iter = iter_;
+ int dump_status;
+ unsigned int nl_status = nl_dump_done(&iter->dump);
+
+ atomic_read(&iter->status, &dump_status);
+ free(iter);
+ return dump_status ? dump_status : nl_status;
}
static void
struct ofpbuf *buf)
{
struct ovs_header *k_exec;
+ size_t key_ofs;
ofpbuf_prealloc_tailroom(buf, (64
- + d_exec->packet->size
- + d_exec->key_len
+ + ofpbuf_size(d_exec->packet)
+ + ODP_KEY_METADATA_SIZE
+ d_exec->actions_len));
nl_msg_put_genlmsghdr(buf, 0, ovs_packet_family, NLM_F_REQUEST,
k_exec->dp_ifindex = dp_ifindex;
nl_msg_put_unspec(buf, OVS_PACKET_ATTR_PACKET,
- d_exec->packet->data, d_exec->packet->size);
- nl_msg_put_unspec(buf, OVS_PACKET_ATTR_KEY, d_exec->key, d_exec->key_len);
+ ofpbuf_data(d_exec->packet),
+ ofpbuf_size(d_exec->packet));
+
+ key_ofs = nl_msg_start_nested(buf, OVS_PACKET_ATTR_KEY);
+ odp_key_from_pkt_metadata(buf, &d_exec->md);
+ nl_msg_end_nested(buf, key_ofs);
+
nl_msg_put_unspec(buf, OVS_PACKET_ATTR_ACTIONS,
d_exec->actions, d_exec->actions_len);
}
}
static int
-dpif_linux_execute(struct dpif *dpif_, const struct dpif_execute *execute)
+dpif_linux_execute(struct dpif *dpif_, struct dpif_execute *execute)
{
const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
break;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
break;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
ofpbuf_uninit(&aux->request);
struct dpif_linux_vport vport;
size_t keep_channels_nbits;
struct nl_dump dump;
+ uint64_t reply_stub[NL_DUMP_BUFSIZE / 8];
+ struct ofpbuf buf;
int retval = 0;
size_t i;
dpif->n_events = dpif->event_offset = 0;
+ ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub);
dpif_linux_port_dump_start__(dpif_, &dump);
- while (dpif_linux_port_dump_next__(dpif_, &dump, &vport)) {
+ while (!dpif_linux_port_dump_next__(dpif_, &dump, &vport, &buf)) {
uint32_t port_no = odp_to_u32(vport.port_no);
struct nl_sock *sock = (port_no < dpif->uc_array_size
? dpif->channels[port_no].sock
nl_sock_destroy(sock);
}
nl_dump_done(&dump);
+ ofpbuf_uninit(&buf);
/* Discard any saved channels that we didn't reuse. */
for (i = 0; i < keep_channels_nbits; i++) {
return error;
}
+static int
+dpif_linux_handlers_set(struct dpif *dpif_ OVS_UNUSED,
+ uint32_t n_handlers OVS_UNUSED)
+{
+ return 0;
+}
+
static int
dpif_linux_queue_to_priority(const struct dpif *dpif OVS_UNUSED,
uint32_t queue_id, uint32_t *priority)
struct ofpbuf b;
int type;
- ofpbuf_use_const(&b, buf->data, buf->size);
+ ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
return EINVAL;
}
- memset(upcall, 0, sizeof *upcall);
+ /* (Re)set ALL fields of '*upcall' on successful return. */
upcall->type = type;
- upcall->packet = buf;
- upcall->packet->data = CONST_CAST(struct nlattr *,
- nl_attr_get(a[OVS_PACKET_ATTR_PACKET]));
- upcall->packet->size = nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]);
upcall->key = CONST_CAST(struct nlattr *,
nl_attr_get(a[OVS_PACKET_ATTR_KEY]));
upcall->key_len = nl_attr_get_size(a[OVS_PACKET_ATTR_KEY]);
upcall->userdata = a[OVS_PACKET_ATTR_USERDATA];
+
+ /* Allow overwriting the netlink attribute header without reallocating. */
+ ofpbuf_use_stub(&upcall->packet,
+ CONST_CAST(struct nlattr *,
+ nl_attr_get(a[OVS_PACKET_ATTR_PACKET])) - 1,
+ nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]) +
+ sizeof(struct nlattr));
+ ofpbuf_set_data(&upcall->packet,
+ (char *)ofpbuf_data(&upcall->packet) + sizeof(struct nlattr));
+ ofpbuf_set_size(&upcall->packet, nl_attr_get_size(a[OVS_PACKET_ATTR_PACKET]));
+
*dp_ifindex = ovs_header->dp_ifindex;
return 0;
}
static int
-dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
- struct ofpbuf *buf)
+dpif_linux_recv(struct dpif *dpif_, uint32_t handler_id OVS_UNUSED,
+ struct dpif_upcall *upcall, struct ofpbuf *buf)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
int error;
}
static void
-dpif_linux_recv_wait(struct dpif *dpif_)
+dpif_linux_recv_wait(struct dpif *dpif_, uint32_t handler_id OVS_UNUSED)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
dpif_linux_port_del,
dpif_linux_port_query_by_number,
dpif_linux_port_query_by_name,
- dpif_linux_get_max_ports,
dpif_linux_port_get_pid,
dpif_linux_port_dump_start,
dpif_linux_port_dump_next,
dpif_linux_flow_put,
dpif_linux_flow_del,
dpif_linux_flow_flush,
+ dpif_linux_flow_dump_state_init,
dpif_linux_flow_dump_start,
dpif_linux_flow_dump_next,
+ dpif_linux_flow_dump_next_may_destroy_keys,
dpif_linux_flow_dump_done,
+ dpif_linux_flow_dump_state_uninit,
dpif_linux_execute,
dpif_linux_operate,
dpif_linux_recv_set,
+ dpif_linux_handlers_set,
dpif_linux_queue_to_priority,
dpif_linux_recv,
dpif_linux_recv_wait,
dpif_linux_vport_init(vport);
- ofpbuf_use_const(&b, buf->data, buf->size);
+ ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
dpif_linux_dp_init(dp);
- ofpbuf_use_const(&b, buf->data, buf->size);
+ ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
nl_msg_put_u32(buf, OVS_DP_ATTR_UPCALL_PID, *dp->upcall_pid);
}
+ if (dp->user_features) {
+ nl_msg_put_u32(buf, OVS_DP_ATTR_USER_FEATURES, dp->user_features);
+ }
+
/* Skip OVS_DP_ATTR_STATS since we never have a reason to serialize it. */
}
dpif_linux_flow_init(flow);
- ofpbuf_use_const(&b, buf->data, buf->size);
+ ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);