#include "netlink.h"
#include "odp-util.h"
#include "ofpbuf.h"
-#include "openvswitch/datapath-compat.h"
#include "packets.h"
#include "poll-loop.h"
#include "random.h"
/* Attributes. */
const char *name; /* OVS_DP_ATTR_NAME. */
- const uint32_t *upcall_pid; /* OVS_DP_UPCALL_PID. */
+ 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 void dpif_linux_dp_init(struct dpif_linux_dp *);
int dp_ifindex;
/* Upcall messages. */
+ struct ovs_mutex upcall_lock;
int uc_array_size; /* Size of 'channels' and 'epoll_events'. */
struct dpif_channel *channels;
struct epoll_event *epoll_events;
int event_offset; /* Offset into 'epoll_events'. */
/* Change notification. */
- struct sset changed_ports; /* Ports that have changed. */
- struct nln_notifier *port_notifier;
- bool change_error;
+ struct nl_sock *port_notifier; /* vport multicast group subscriber. */
+ bool refresh_channels;
};
static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(9999, 5);
-/* Generic Netlink family numbers for OVS. */
+/* Generic Netlink family numbers for OVS.
+ *
+ * Initialized by dpif_linux_init(). */
static int ovs_datapath_family;
static int ovs_vport_family;
static int ovs_flow_family;
static int ovs_packet_family;
-/* Generic Netlink socket. */
-static struct nln *nln = NULL;
+/* Generic Netlink multicast groups for OVS.
+ *
+ * Initialized by dpif_linux_init(). */
+static unsigned int ovs_vport_mcgroup;
static int dpif_linux_init(void);
-static void open_dpif(const struct dpif_linux_dp *, struct dpif **);
-static bool dpif_linux_nln_parse(struct ofpbuf *, void *);
-static void dpif_linux_port_changed(const void *vport, void *dpif);
+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);
+static int dpif_linux_refresh_channels(struct dpif *);
static void dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *,
struct ofpbuf *);
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;
}
- open_dpif(&dp, dpifp);
+ error = open_dpif(&dp, dpifp);
ofpbuf_delete(buf);
- return 0;
+ return error;
}
-static void
+static int
open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp)
{
struct dpif_linux *dpif;
dpif = xzalloc(sizeof *dpif);
- dpif->port_notifier = nln_notifier_create(nln, dpif_linux_port_changed,
- dpif);
+ dpif->port_notifier = NULL;
+ ovs_mutex_init(&dpif->upcall_lock);
dpif->epoll_fd = -1;
dpif_init(&dpif->dpif, &dpif_linux_class, dp->name,
dp->dp_ifindex, dp->dp_ifindex);
dpif->dp_ifindex = dp->dp_ifindex;
- sset_init(&dpif->changed_ports);
*dpifp = &dpif->dpif;
+
+ return 0;
}
static void
continue;
}
+ epoll_ctl(dpif->epoll_fd, EPOLL_CTL_DEL, nl_sock_fd(ch->sock), NULL);
+
/* Turn off upcalls. */
dpif_linux_vport_init(&vport_request);
vport_request.cmd = OVS_VPORT_CMD_SET;
dpif->epoll_events = NULL;
dpif->n_events = dpif->event_offset = 0;
- close(dpif->epoll_fd);
- dpif->epoll_fd = -1;
+ /* 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. */
}
static int
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- nln_notifier_destroy(dpif->port_notifier);
+ nl_sock_destroy(dpif->port_notifier);
destroy_channels(dpif);
- sset_destroy(&dpif->changed_ports);
+ if (dpif->epoll_fd >= 0) {
+ close(dpif->epoll_fd);
+ }
+ ovs_mutex_destroy(&dpif->upcall_lock);
free(dpif);
}
}
static void
-dpif_linux_run(struct dpif *dpif_ OVS_UNUSED)
-{
- if (nln) {
- nln_run(nln);
- }
-}
-
-static void
-dpif_linux_wait(struct dpif *dpif OVS_UNUSED)
+dpif_linux_run(struct dpif *dpif_)
{
- if (nln) {
- nln_wait(nln);
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ if (dpif->refresh_channels) {
+ dpif->refresh_channels = false;
+ dpif_linux_refresh_channels(dpif_);
}
}
stats->n_missed = dp.stats.n_missed;
stats->n_lost = dp.stats.n_lost;
stats->n_flows = dp.stats.n_flows;
+ stats->n_masks = dp.megaflow_stats.n_masks;
+ stats->n_mask_hit = dp.megaflow_stats.n_mask_hit;
ofpbuf_delete(buf);
}
return error;
}
static int
-dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
- odp_port_t *port_nop)
+dpif_linux_port_add__(struct dpif *dpif_, struct netdev *netdev,
+ odp_port_t *port_nop)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
const struct netdev_tunnel_config *tnl_cfg;
}
static int
-dpif_linux_port_del(struct dpif *dpif_, odp_port_t port_no)
+dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
+ odp_port_t *port_nop)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_port_add__(dpif_, netdev, port_nop);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
+static int
+dpif_linux_port_del__(struct dpif *dpif_, odp_port_t port_no)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_vport vport;
return error;
}
+static int
+dpif_linux_port_del(struct dpif *dpif_, odp_port_t port_no)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_port_del__(dpif_, port_no);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
static int
dpif_linux_port_query__(const struct dpif *dpif, odp_port_t port_no,
const char *port_name, struct dpif_port *dpif_port)
return dpif_linux_port_query__(dpif, 0, devname, dpif_port);
}
-static odp_port_t
-dpif_linux_get_max_ports(const struct dpif *dpif OVS_UNUSED)
-{
- return u32_to_odp(MAX_PORTS);
-}
-
static uint32_t
dpif_linux_port_get_pid(const struct dpif *dpif_, odp_port_t port_no)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
uint32_t port_idx = odp_to_u32(port_no);
+ uint32_t pid = 0;
- if (dpif->epoll_fd < 0) {
- return 0;
- } else {
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
/* 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;
- return 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);
+
+ return pid;
}
static int
dpif_linux_flow_flush(struct dpif *dpif_)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_flow flow;
dpif_linux_flow_init(&flow);
struct nl_dump dump;
};
-static int
-dpif_linux_port_dump_start(const struct dpif *dpif_, void **statep)
+static void
+dpif_linux_port_dump_start__(const struct dpif *dpif_, struct nl_dump *dump)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- struct dpif_linux_port_state *state;
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_vport request;
struct ofpbuf *buf;
- *statep = state = xmalloc(sizeof *state);
-
dpif_linux_vport_init(&request);
- request.cmd = OVS_DP_CMD_GET;
+ request.cmd = OVS_VPORT_CMD_GET;
request.dp_ifindex = dpif->dp_ifindex;
buf = ofpbuf_new(1024);
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);
+}
+
+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;
}
static int
-dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_,
- struct dpif_port *dpif_port)
+dpif_linux_port_dump_next__(const struct dpif *dpif_, struct nl_dump *dump,
+ struct dpif_linux_vport *vport)
{
- struct dpif_linux_port_state *state = state_;
- struct dpif_linux_vport vport;
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct ofpbuf buf;
int error;
- if (!nl_dump_next(&state->dump, &buf)) {
+ if (!nl_dump_next(dump, &buf)) {
return EOF;
}
- error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
+ error = dpif_linux_vport_from_ofpbuf(vport, &buf);
if (error) {
- return error;
+ VLOG_WARN_RL(&error_rl, "%s: failed to parse vport record (%s)",
+ dpif_name(&dpif->dpif), ovs_strerror(error));
}
+ return error;
+}
+
+static int
+dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_,
+ struct dpif_port *dpif_port)
+{
+ struct dpif_linux_port_state *state = state_;
+ struct dpif_linux_vport vport;
+ int error;
+ error = dpif_linux_port_dump_next__(dpif, &state->dump, &vport);
+ if (error) {
+ return error;
+ }
dpif_port->name = CONST_CAST(char *, vport.name);
dpif_port->type = CONST_CAST(char *, get_vport_type(&vport));
dpif_port->port_no = vport.port_no;
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (dpif->change_error) {
- dpif->change_error = false;
- sset_clear(&dpif->changed_ports);
+ /* Lazily create the Netlink socket to listen for notifications. */
+ if (!dpif->port_notifier) {
+ struct nl_sock *sock;
+ int error;
+
+ error = nl_sock_create(NETLINK_GENERIC, &sock);
+ if (error) {
+ return error;
+ }
+
+ error = nl_sock_join_mcgroup(sock, ovs_vport_mcgroup);
+ if (error) {
+ nl_sock_destroy(sock);
+ return error;
+ }
+ dpif->port_notifier = sock;
+
+ /* We have no idea of the current state so report that everything
+ * changed. */
return ENOBUFS;
- } else if (!sset_is_empty(&dpif->changed_ports)) {
- *devnamep = sset_pop(&dpif->changed_ports);
- return 0;
- } else {
- return EAGAIN;
+ }
+
+ for (;;) {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+ uint64_t buf_stub[4096 / 8];
+ struct ofpbuf buf;
+ int error;
+
+ ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub);
+ error = nl_sock_recv(dpif->port_notifier, &buf, false);
+ if (!error) {
+ struct dpif_linux_vport vport;
+
+ error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
+ if (!error) {
+ if (vport.dp_ifindex == dpif->dp_ifindex
+ && (vport.cmd == OVS_VPORT_CMD_NEW
+ || vport.cmd == OVS_VPORT_CMD_DEL
+ || vport.cmd == OVS_VPORT_CMD_SET)) {
+ VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
+ dpif->dpif.full_name, vport.name, vport.cmd);
+ if (vport.cmd == OVS_VPORT_CMD_DEL) {
+ dpif->refresh_channels = true;
+ }
+ *devnamep = xstrdup(vport.name);
+ ofpbuf_uninit(&buf);
+ return 0;
+ }
+ }
+ } else if (error != EAGAIN) {
+ VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
+ ovs_strerror(error));
+ nl_sock_drain(dpif->port_notifier);
+ error = ENOBUFS;
+ }
+
+ ofpbuf_uninit(&buf);
+ if (error) {
+ return error;
+ }
}
}
static void
dpif_linux_port_poll_wait(const struct dpif *dpif_)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (!sset_is_empty(&dpif->changed_ports) || dpif->change_error) {
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ if (dpif->port_notifier) {
+ nl_sock_wait(dpif->port_notifier, POLLIN);
+ } else {
poll_immediate_wake();
}
}
const struct nlattr *key, size_t key_len,
struct dpif_linux_flow *reply, struct ofpbuf **bufp)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_flow request;
dpif_linux_flow_init(&request);
{
static const struct nlattr dummy_action;
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
dpif_linux_flow_init(request);
request->cmd = (put->flags & DPIF_FP_CREATE
dpif_linux_init_flow_del(struct dpif *dpif_, const struct dpif_flow_del *del,
struct dpif_linux_flow *request)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
dpif_linux_flow_init(request);
request->cmd = OVS_FLOW_CMD_DEL;
static int
dpif_linux_flow_dump_start(const struct dpif *dpif_, void **statep)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_flow_state *state;
struct dpif_linux_flow request;
struct ofpbuf *buf;
*statep = state = xmalloc(sizeof *state);
dpif_linux_flow_init(&request);
- request.cmd = OVS_DP_CMD_GET;
+ request.cmd = OVS_FLOW_CMD_GET;
request.dp_ifindex = dpif->dp_ifindex;
buf = ofpbuf_new(1024);
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
+ + ODP_KEY_METADATA_SIZE
+ d_exec->actions_len));
nl_msg_put_genlmsghdr(buf, 0, ovs_packet_family, NLM_F_REQUEST,
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);
+
+ 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)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
return dpif_linux_execute__(dpif->dp_ifindex, execute);
}
static void
dpif_linux_operate__(struct dpif *dpif_, struct dpif_op **ops, size_t n_ops)
{
- struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct op_auxdata {
struct nl_transaction txn;
break;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
break;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
ofpbuf_uninit(&aux->request);
}
}
+/* Synchronizes 'dpif->channels' with the set of vports currently in 'dpif' in
+ * the kernel, by adding a new channel for any kernel vport that lacks one and
+ * deleting any channels that have no backing kernel vports. */
static int
-dpif_linux_recv_set(struct dpif *dpif_, bool enable)
+dpif_linux_refresh_channels(struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ unsigned long int *keep_channels;
+ struct dpif_linux_vport vport;
+ size_t keep_channels_nbits;
+ struct nl_dump dump;
+ int retval = 0;
+ size_t i;
- if ((dpif->epoll_fd >= 0) == enable) {
- return 0;
- }
-
- if (!enable) {
- destroy_channels(dpif);
- } else {
- struct dpif_port_dump port_dump;
- struct dpif_port port;
-
+ /* To start with, we need an epoll fd. */
+ if (dpif->epoll_fd < 0) {
dpif->epoll_fd = epoll_create(10);
if (dpif->epoll_fd < 0) {
return errno;
}
+ }
- DPIF_PORT_FOR_EACH (&port, &port_dump, &dpif->dpif) {
- struct dpif_linux_vport vport_request;
- struct nl_sock *sock;
- uint32_t upcall_pid;
- int error;
+ keep_channels_nbits = dpif->uc_array_size;
+ keep_channels = bitmap_allocate(keep_channels_nbits);
+
+ dpif->n_events = dpif->event_offset = 0;
+ dpif_linux_port_dump_start__(dpif_, &dump);
+ while (!dpif_linux_port_dump_next__(dpif_, &dump, &vport)) {
+ 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
+ : NULL);
+ bool new_sock = !sock;
+ int error;
+
+ if (new_sock) {
error = nl_sock_create(NETLINK_GENERIC, &sock);
if (error) {
- return error;
+ retval = error;
+ goto error;
}
+ }
- upcall_pid = nl_sock_pid(sock);
+ /* Configure the vport to deliver misses to 'sock'. */
+ if (!vport.upcall_pid || *vport.upcall_pid != nl_sock_pid(sock)) {
+ uint32_t upcall_pid = nl_sock_pid(sock);
+ struct dpif_linux_vport vport_request;
dpif_linux_vport_init(&vport_request);
vport_request.cmd = OVS_VPORT_CMD_SET;
vport_request.dp_ifindex = dpif->dp_ifindex;
- vport_request.port_no = port.port_no;
+ vport_request.port_no = vport.port_no;
vport_request.upcall_pid = &upcall_pid;
error = dpif_linux_vport_transact(&vport_request, NULL, NULL);
if (!error) {
VLOG_WARN_RL(&error_rl,
"%s: failed to set upcall pid on port: %s",
dpif_name(&dpif->dpif), ovs_strerror(error));
- nl_sock_destroy(sock);
- if (error == ENODEV || error == ENOENT) {
- /* This device isn't there, but keep trying the others. */
- continue;
+ if (error != ENODEV && error != ENOENT) {
+ retval = error;
} else {
- return error;
+ /* The vport isn't really there, even though the dump says
+ * it is. Probably we just hit a race after a port
+ * disappeared. */
}
+ goto error;
}
+ }
- error = add_channel(dpif, port.port_no, sock);
+ if (new_sock) {
+ error = add_channel(dpif, vport.port_no, sock);
if (error) {
VLOG_INFO("%s: could not add channel for port %s",
- dpif_name(dpif_), port.name);
- nl_sock_destroy(sock);
- return error;
+ dpif_name(dpif_), vport.name);
+ retval = error;
+ goto error;
}
}
+
+ if (port_no < keep_channels_nbits) {
+ bitmap_set1(keep_channels, port_no);
+ }
+ continue;
+
+ error:
+ nl_sock_destroy(sock);
+ }
+ nl_dump_done(&dump);
+
+ /* Discard any saved channels that we didn't reuse. */
+ for (i = 0; i < keep_channels_nbits; i++) {
+ if (!bitmap_is_set(keep_channels, i)) {
+ nl_sock_destroy(dpif->channels[i].sock);
+ dpif->channels[i].sock = NULL;
+ }
}
+ free(keep_channels);
- return 0;
+ return retval;
+}
+
+static int
+dpif_linux_recv_set__(struct dpif *dpif_, bool enable)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ if ((dpif->epoll_fd >= 0) == enable) {
+ return 0;
+ } else if (!enable) {
+ destroy_channels(dpif);
+ return 0;
+ } else {
+ return dpif_linux_refresh_channels(dpif_);
+ }
+}
+
+static int
+dpif_linux_recv_set(struct dpif *dpif_, bool enable)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_recv_set__(dpif_, enable);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
}
static int
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));
+ upcall->packet.data = (char *)upcall->packet.data + sizeof(struct nlattr);
+ upcall->packet.size = 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_, struct dpif_upcall *upcall,
+ struct ofpbuf *buf)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
int read_tries = 0;
return EAGAIN;
}
+static int
+dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
+ struct ofpbuf *buf)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_recv__(dpif_, upcall, buf);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
static void
dpif_linux_recv_wait(struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (dpif->epoll_fd < 0) {
- return;
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
+ poll_fd_wait(dpif->epoll_fd, POLLIN);
}
-
- poll_fd_wait(dpif->epoll_fd, POLLIN);
+ ovs_mutex_unlock(&dpif->upcall_lock);
}
static void
dpif_linux_recv_purge(struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- struct dpif_channel *ch;
- if (dpif->epoll_fd < 0) {
- return;
- }
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
+ struct dpif_channel *ch;
- for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size]; ch++) {
- if (ch->sock) {
- nl_sock_drain(ch->sock);
+ for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size];
+ ch++) {
+ if (ch->sock) {
+ nl_sock_drain(ch->sock);
+ }
}
}
+ ovs_mutex_unlock(&dpif->upcall_lock);
}
const struct dpif_class dpif_linux_class = {
dpif_linux_close,
dpif_linux_destroy,
dpif_linux_run,
- dpif_linux_wait,
+ NULL, /* wait */
dpif_linux_get_stats,
dpif_linux_port_add,
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,
static int
dpif_linux_init(void)
{
- static int error = -1;
-
- if (error < 0) {
- unsigned int ovs_vport_mcgroup;
+ static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+ static int error;
+ if (ovsthread_once_start(&once)) {
error = nl_lookup_genl_family(OVS_DATAPATH_FAMILY,
&ovs_datapath_family);
if (error) {
}
if (!error) {
error = nl_lookup_genl_mcgroup(OVS_VPORT_FAMILY, OVS_VPORT_MCGROUP,
- &ovs_vport_mcgroup,
- OVS_VPORT_MCGROUP_FALLBACK_ID);
- }
- if (!error) {
- static struct dpif_linux_vport vport;
- nln = nln_create(NETLINK_GENERIC, ovs_vport_mcgroup,
- dpif_linux_nln_parse, &vport);
+ &ovs_vport_mcgroup);
}
+
+ ovsthread_once_done(&once);
}
return error;
return reply.type == OVS_VPORT_TYPE_INTERNAL;
}
-
-static bool
-dpif_linux_nln_parse(struct ofpbuf *buf, void *vport_)
-{
- struct dpif_linux_vport *vport = vport_;
- return dpif_linux_vport_from_ofpbuf(vport, buf) == 0;
-}
-
-static void
-dpif_linux_port_changed(const void *vport_, void *dpif_)
-{
- const struct dpif_linux_vport *vport = vport_;
- struct dpif_linux *dpif = dpif_;
-
- if (vport) {
- if (vport->dp_ifindex == dpif->dp_ifindex
- && (vport->cmd == OVS_VPORT_CMD_NEW
- || vport->cmd == OVS_VPORT_CMD_DEL
- || vport->cmd == OVS_VPORT_CMD_SET)) {
- VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
- dpif->dpif.full_name, vport->name, vport->cmd);
- sset_add(&dpif->changed_ports, vport->name);
- }
- } else {
- dpif->change_error = true;
- }
-}
\f
/* Parses the contents of 'buf', which contains a "struct ovs_header" followed
* by Netlink attributes, into 'vport'. Returns 0 if successful, otherwise a
[OVS_DP_ATTR_NAME] = { .type = NL_A_STRING, .max_len = IFNAMSIZ },
[OVS_DP_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_dp_stats),
.optional = true },
+ [OVS_DP_ATTR_MEGAFLOW_STATS] = {
+ NL_POLICY_FOR(struct ovs_dp_megaflow_stats),
+ .optional = true },
};
struct nlattr *a[ARRAY_SIZE(ovs_datapath_policy)];
sizeof dp->stats);
}
+ if (a[OVS_DP_ATTR_MEGAFLOW_STATS]) {
+ /* Can't use structure assignment because Netlink doesn't ensure
+ * sufficient alignment for 64-bit members. */
+ memcpy(&dp->megaflow_stats, nl_attr_get(a[OVS_DP_ATTR_MEGAFLOW_STATS]),
+ sizeof dp->megaflow_stats);
+ }
+
return 0;
}
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_dp_init(struct dpif_linux_dp *dp)
{
memset(dp, 0, sizeof *dp);
+ dp->megaflow_stats.n_masks = UINT32_MAX;
+ dp->megaflow_stats.n_mask_hit = UINT64_MAX;
}
static void
ofpbuf_delete(request_buf);
if (reply) {
+ dpif_linux_dp_init(reply);
if (!error) {
error = dpif_linux_dp_from_ofpbuf(reply, *bufp);
}
if (error) {
- dpif_linux_dp_init(reply);
ofpbuf_delete(*bufp);
*bufp = NULL;
}
time_msec() - ch->last_poll);
}
- VLOG_WARN("%s: lost packet on channel %td%s",
+ VLOG_WARN("%s: lost packet on channel %"PRIdPTR"%s",
dpif_name(dpif_), ch - dpif->channels, ds_cstr(&s));
ds_destroy(&s);
}