/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
uint32_t port_idx = odp_to_u32(port_no);
uint32_t pid = 0;
- if (dpif->handlers) {
+ if (dpif->handlers && dpif->uc_array_size > 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;
struct dpif_handler *h = &dpif->handlers[hash % dpif->n_handlers];
- pid = nl_sock_pid(h->channels[idx].sock);
+ /* Needs to check in case the socket pointer is changed in between
+ * the holding of upcall_lock. A known case happens when the main
+ * thread deletes the vport while the handler thread is handling
+ * the upcall from that port. */
+ if (h->channels[idx].sock) {
+ pid = nl_sock_pid(h->channels[idx].sock);
+ }
}
return pid;
return dpif_linux_execute__(dpif->dp_ifindex, execute);
}
-#define MAX_OPS 50
-
-static void
+/* Executes, against 'dpif', up to the first 'n_ops' operations in 'ops'.
+ * Returns the number actually executed (at least 1, if 'n_ops' is
+ * positive). */
+static size_t
dpif_linux_operate__(struct dpif_linux *dpif, struct dpif_op **ops, size_t n_ops)
{
+ enum { MAX_OPS = 50 };
struct op_auxdata {
struct nl_transaction txn;
struct nl_transaction *txnsp[MAX_OPS];
size_t i;
- ovs_assert(n_ops <= MAX_OPS);
+ n_ops = MIN(n_ops, MAX_OPS);
for (i = 0; i < n_ops; i++) {
struct op_auxdata *aux = &auxes[i];
struct dpif_op *op = ops[i];
struct dpif_flow_put *put;
struct dpif_flow_del *del;
- struct dpif_execute *execute;
struct dpif_linux_flow flow;
ofpbuf_use_stub(&aux->request,
break;
case DPIF_OP_EXECUTE:
- execute = &op->u.execute;
- dpif_linux_encode_execute(dpif->dp_ifindex, execute,
- &aux->request);
+ /* Can't execute a packet that won't fit in a Netlink attribute. */
+ if (OVS_UNLIKELY(nl_attr_oversized(
+ ofpbuf_size(op->u.execute.packet)))) {
+ /* Report an error immediately if this is the first operation.
+ * Otherwise the easiest thing to do is to postpone to the next
+ * call (when this will be the first operation). */
+ if (i == 0) {
+ VLOG_ERR_RL(&error_rl,
+ "dropping oversized %"PRIu32"-byte packet",
+ ofpbuf_size(op->u.execute.packet));
+ op->error = ENOBUFS;
+ return 1;
+ }
+ n_ops = i;
+ } else {
+ dpif_linux_encode_execute(dpif->dp_ifindex, &op->u.execute,
+ &aux->request);
+ }
+
break;
default:
ofpbuf_uninit(&aux->request);
ofpbuf_uninit(&aux->reply);
}
+
+ return n_ops;
}
static void
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
while (n_ops > 0) {
- size_t chunk = MIN(n_ops, MAX_OPS);
- dpif_linux_operate__(dpif, ops, chunk);
+ size_t chunk = dpif_linux_operate__(dpif, ops, n_ops);
ops += chunk;
n_ops -= chunk;
}