aboutsummaryrefslogtreecommitdiff
path: root/lib/dpif-netdev.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-02-15 16:48:32 -0800
committerBen Pfaff <blp@nicira.com>2013-02-15 16:48:32 -0800
commite995e3df57ea4e27678bc0bea5eb30872994155b (patch)
tree8ef5beb74a4a2dc4e5cb268cb719cb2ce9eb7a56 /lib/dpif-netdev.c
parent7e2d8aeaf5ef25408a6f345e2611b647851e0120 (diff)
Allow OVS_USERSPACE_ATTR_USERDATA to be variable length.
Until now, the optional OVS_USERSPACE_ATTR_USERDATA attribute had to be exactly 64 bits long, if it was present. However, 64 bits is not enough space to associate as much information with a flow as would be convenient for some userspace features now under development. This commit generalizes the attribute, allowing it to be any length. This generalization is backward-compatible: if userspace only uses 64-bit attributes, then it will not see any change in behavior. CC: Romain Lenglet <rlenglet@vmware.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jesse Gross <jesse@nicira.com>
Diffstat (limited to 'lib/dpif-netdev.c')
-rw-r--r--lib/dpif-netdev.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index d315b594..305e196b 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -151,7 +151,7 @@ static int dpif_netdev_open(const struct dpif_class *, const char *name,
bool create, struct dpif **);
static int dp_netdev_output_userspace(struct dp_netdev *, const struct ofpbuf *,
int queue_no, const struct flow *,
- uint64_t arg);
+ const struct nlattr *userdata);
static void dp_netdev_execute_actions(struct dp_netdev *,
struct ofpbuf *, struct flow *,
const struct nlattr *actions,
@@ -1043,7 +1043,7 @@ dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port,
dp->n_hit++;
} else {
dp->n_missed++;
- dp_netdev_output_userspace(dp, packet, DPIF_UC_MISS, &key, 0);
+ dp_netdev_output_userspace(dp, packet, DPIF_UC_MISS, &key, NULL);
}
}
@@ -1108,37 +1108,51 @@ dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
static int
dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet,
- int queue_no, const struct flow *flow, uint64_t arg)
+ int queue_no, const struct flow *flow,
+ const struct nlattr *userdata)
{
struct dp_netdev_queue *q = &dp->queues[queue_no];
- struct dp_netdev_upcall *u;
- struct dpif_upcall *upcall;
- struct ofpbuf *buf;
- size_t key_len;
-
- if (q->head - q->tail >= MAX_QUEUE_LEN) {
- dp->n_lost++;
- return ENOBUFS;
- }
+ if (q->head - q->tail < MAX_QUEUE_LEN) {
+ struct dp_netdev_upcall *u = &q->upcalls[q->head++ & QUEUE_MASK];
+ struct dpif_upcall *upcall = &u->upcall;
+ struct ofpbuf *buf = &u->buf;
+ size_t buf_size;
+
+ upcall->type = queue_no;
+
+ /* Allocate buffer big enough for everything. */
+ buf_size = ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size;
+ if (userdata) {
+ buf_size += NLA_ALIGN(userdata->nla_len);
+ }
+ ofpbuf_init(buf, buf_size);
- u = &q->upcalls[q->head++ & QUEUE_MASK];
+ /* Put ODP flow. */
+ odp_flow_key_from_flow(buf, flow, flow->in_port);
+ upcall->key = buf->data;
+ upcall->key_len = buf->size;
- buf = &u->buf;
- ofpbuf_init(buf, ODPUTIL_FLOW_KEY_BYTES + 2 + packet->size);
- odp_flow_key_from_flow(buf, flow, flow->in_port);
- key_len = buf->size;
- ofpbuf_pull(buf, key_len);
- ofpbuf_reserve(buf, 2);
- ofpbuf_put(buf, packet->data, packet->size);
+ /* Put userdata. */
+ if (userdata) {
+ upcall->userdata = ofpbuf_put(buf, userdata,
+ NLA_ALIGN(userdata->nla_len));
+ }
- upcall = &u->upcall;
- upcall->type = queue_no;
- upcall->packet = buf;
- upcall->key = buf->base;
- upcall->key_len = key_len;
- upcall->userdata = arg;
+ /* Put packet.
+ *
+ * We adjust 'data' and 'size' in 'buf' so that only the packet itself
+ * is visible in 'upcall->packet'. The ODP flow and (if present)
+ * userdata become part of the headroom. */
+ ofpbuf_put_zeros(buf, 2);
+ buf->data = ofpbuf_put(buf, packet->data, packet->size);
+ buf->size = packet->size;
+ upcall->packet = buf;
- return 0;
+ return 0;
+ } else {
+ dp->n_lost++;
+ return ENOBUFS;
+ }
}
static void
@@ -1180,11 +1194,9 @@ dp_netdev_action_userspace(struct dp_netdev *dp,
struct ofpbuf *packet, struct flow *key,
const struct nlattr *a)
{
- const struct nlattr *userdata_attr;
- uint64_t userdata;
+ const struct nlattr *userdata;
- userdata_attr = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
- userdata = userdata_attr ? nl_attr_get_u64(userdata_attr) : 0;
+ userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
dp_netdev_output_userspace(dp, packet, DPIF_UC_ACTION, key, userdata);
}