}
ofpbuf_put(ofpacts, &slave_port, sizeof slave_port);
- bundle = ofpacts->frame;
+ bundle = ofpacts->header;
bundle->n_slaves++;
}
ofpact_update_len(ofpacts, &bundle->ofpact);
FOR_EACH_CORE_ON_NUMA (iter, dump) {
if (ovs_numa_core_is_pinned(iter->core_id)) {
error = dpif_flow_put(dpif, flags,
- ofpbuf_data(&key), ofpbuf_size(&key),
- ofpbuf_size(&mask) == 0 ? NULL : ofpbuf_data(&mask),
- ofpbuf_size(&mask), ofpbuf_data(&actions),
- ofpbuf_size(&actions), ufid_present ? &ufid : NULL,
+ key.data, key.size,
+ mask.size == 0 ? NULL : mask.data,
+ mask.size, actions.data,
+ actions.size, ufid_present ? &ufid : NULL,
iter->core_id, dpctl_p->print_statistics ? &stats : NULL);
}
}
}
} else {
error = dpif_flow_put(dpif, flags,
- ofpbuf_data(&key), ofpbuf_size(&key),
- ofpbuf_size(&mask) == 0 ? NULL : ofpbuf_data(&mask),
- ofpbuf_size(&mask), ofpbuf_data(&actions),
- ofpbuf_size(&actions), ufid_present ? &ufid : NULL,
+ key.data, key.size,
+ mask.size == 0 ? NULL : mask.data,
+ mask.size, actions.data,
+ actions.size, ufid_present ? &ufid : NULL,
PMD_ID_NULL, dpctl_p->print_statistics ? &stats : NULL);
}
if (error) {
FOR_EACH_CORE_ON_NUMA (iter, dump) {
if (ovs_numa_core_is_pinned(iter->core_id)) {
- error = dpif_flow_del(dpif, ofpbuf_data(&key),
- ofpbuf_size(&key), ufid_present ? &ufid : NULL,
+ error = dpif_flow_del(dpif, key.data,
+ key.size, ufid_present ? &ufid : NULL,
iter->core_id, dpctl_p->print_statistics ? &stats : NULL);
}
}
error = EINVAL;
}
} else {
- error = dpif_flow_del(dpif, ofpbuf_data(&key), ofpbuf_size(&key),
+ error = dpif_flow_del(dpif, key.data, key.size,
ufid_present ? &ufid : NULL, PMD_ID_NULL,
dpctl_p->print_statistics ? &stats : NULL);
}
}
ds_init(&s);
- format_odp_actions(&s, ofpbuf_data(&actions), ofpbuf_size(&actions));
+ format_odp_actions(&s, actions.data, actions.size);
dpctl_print(dpctl_p, "%s\n", ds_cstr(&s));
ds_destroy(&s);
}
ds_clear(&s);
- odp_flow_format(ofpbuf_data(&keybuf), ofpbuf_size(&keybuf), NULL, 0, NULL,
+ odp_flow_format(keybuf.data, keybuf.size, NULL, 0, NULL,
&s, dpctl_p->verbosity);
dpctl_print(dpctl_p, "input flow: %s\n", ds_cstr(&s));
- error = odp_flow_key_to_flow(ofpbuf_data(&keybuf), ofpbuf_size(&keybuf),
- &flow);
+ error = odp_flow_key_to_flow(keybuf.data, keybuf.size, &flow);
if (error) {
dpctl_error(dpctl_p, error, "odp_flow_key_to_flow");
goto out_freekeybuf;
if (dpctl_p->verbosity) {
ds_clear(&s);
- format_odp_actions(&s, ofpbuf_data(&odp_actions),
- ofpbuf_size(&odp_actions));
+ format_odp_actions(&s, odp_actions.data, odp_actions.size);
dpctl_print(dpctl_p, "input actions: %s\n", ds_cstr(&s));
}
hmap_init(&actions_per_flow);
- NL_ATTR_FOR_EACH (a, left, ofpbuf_data(&odp_actions),
- ofpbuf_size(&odp_actions)) {
+ NL_ATTR_FOR_EACH (a, left, odp_actions.data, odp_actions.size) {
const struct ovs_action_push_vlan *push;
switch(nl_attr_type(a)) {
case OVS_ACTION_ATTR_POP_VLAN:
for (i = 0; i < n_afs; i++) {
struct actions_for_flow *af = afs[i];
- sort_output_actions(ofpbuf_data(&af->actions),
- ofpbuf_size(&af->actions));
+ sort_output_actions(af->actions.data, af->actions.size);
if (af->flow.vlan_tci != htons(0)) {
dpctl_print(dpctl_p, "vlan(vid=%"PRIu16",pcp=%d): ",
}
ds_clear(&s);
- format_odp_actions(&s, ofpbuf_data(&af->actions),
- ofpbuf_size(&af->actions));
+ format_odp_actions(&s, af->actions.data, af->actions.size);
dpctl_print(dpctl_p, ds_cstr(&s));
ofpbuf_uninit(&af->actions);
miniflow_expand(&netdev_flow->cr.mask->mf, &wc.masks);
/* Key */
- offset = ofpbuf_size(key_buf);
+ offset = key_buf->size;
flow->key = ofpbuf_tail(key_buf);
odp_flow_key_from_flow(key_buf, &netdev_flow->flow, &wc.masks,
netdev_flow->flow.in_port.odp_port, true);
- flow->key_len = ofpbuf_size(key_buf) - offset;
+ flow->key_len = key_buf->size - offset;
/* Mask */
- offset = ofpbuf_size(mask_buf);
+ offset = mask_buf->size;
flow->mask = ofpbuf_tail(mask_buf);
odp_flow_key_from_mask(mask_buf, &wc.masks, &netdev_flow->flow,
odp_to_u32(wc.masks.in_port.odp_port),
SIZE_MAX, true);
- flow->mask_len = ofpbuf_size(mask_buf) - offset;
+ flow->mask_len = mask_buf->size - offset;
/* Actions */
actions = dp_netdev_flow_get_actions(netdev_flow);
packet_str = ofp_packet_to_string(dp_packet_data(packet_),
dp_packet_size(packet_));
- odp_flow_key_format(ofpbuf_data(&key), ofpbuf_size(&key), &ds);
+ odp_flow_key_format(key.data, key.size, &ds);
VLOG_DBG("%s: %s upcall:\n%s\n%s", dp->name,
dpif_upcall_type_to_string(type), ds_cstr(&ds), packet_str);
ofpbuf_uninit(&key);
free(packet_str);
+
ds_destroy(&ds);
}
* the actions. Otherwise, if there are any slow path actions,
* we'll send the packet up twice. */
dp_netdev_execute_actions(pmd, &packets[i], 1, true,
- ofpbuf_data(&actions),
- ofpbuf_size(&actions));
-
- add_actions = ofpbuf_size(&put_actions)
- ? &put_actions
- : &actions;
+ actions.data, actions.size);
+ add_actions = put_actions.size ? &put_actions : &actions;
if (OVS_LIKELY(error != ENOSPC)) {
/* XXX: There's a race window where a flow covering this packet
* could have already been installed since we last did the flow
netdev_flow = dp_netdev_pmd_lookup_flow(pmd, &keys[i]);
if (OVS_LIKELY(!netdev_flow)) {
netdev_flow = dp_netdev_flow_add(pmd, &match, &ufid,
- ofpbuf_data(add_actions),
- ofpbuf_size(add_actions));
+ add_actions->data,
+ add_actions->size);
}
ovs_mutex_unlock(&pmd->flow_mutex);
NULL);
if (!error || error == ENOSPC) {
dp_netdev_execute_actions(pmd, &packets[i], 1, may_steal,
- ofpbuf_data(&actions),
- ofpbuf_size(&actions));
+ actions.data, actions.size);
} else if (may_steal) {
dp_packet_delete(packets[i]);
}
}
nl_msg_end_nested(&options, ext_ofs);
}
- request.options = ofpbuf_data(&options);
- request.options_len = ofpbuf_size(&options);
+ request.options = options.data;
+ request.options_len = options.size;
}
request.port_no = *port_nop;
n_flows = 0;
while (!n_flows
- || (n_flows < max_flows && ofpbuf_size(&thread->nl_flows))) {
+ || (n_flows < max_flows && thread->nl_flows.size)) {
struct dpif_netlink_flow datapath_flow;
struct ofpbuf nl_flow;
int error;
struct ofpbuf b;
int type;
- ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
+ ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
dpif_netlink_vport_init(vport);
- ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
+ ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
dpif_netlink_dp_init(dp);
- ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
+ ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
dpif_netlink_flow_init(flow);
- ofpbuf_use_const(&b, ofpbuf_data(buf), ofpbuf_size(buf));
+ ofpbuf_use_const(&b, buf->data, buf->size);
nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);
genl = ofpbuf_try_pull(&b, sizeof *genl);
ovs_header = ofpbuf_try_pull(&b, sizeof *ovs_header);
* restarted) at just the right time such that feature probes from the
* previous run are still present in the datapath. */
error = dpif_flow_put(dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY | DPIF_FP_PROBE,
- ofpbuf_data(key), ofpbuf_size(key), NULL, 0, NULL, 0,
+ key->data, key->size, NULL, 0, NULL, 0,
ufid, PMD_ID_NULL, NULL);
if (error) {
if (error != EINVAL) {
}
ofpbuf_use_stack(&reply, &stub, sizeof stub);
- error = dpif_flow_get(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
+ error = dpif_flow_get(dpif, key->data, key->size, ufid,
PMD_ID_NULL, &reply, &flow);
if (!error
&& (!ufid || (flow.ufid_present && ovs_u128_equal(ufid, &flow.ufid)))) {
enable_feature = true;
}
- error = dpif_flow_del(dpif, ofpbuf_data(key), ofpbuf_size(key), ufid,
+ error = dpif_flow_del(dpif, key->data, key->size, ufid,
PMD_ID_NULL, NULL);
if (error) {
VLOG_WARN("%s: failed to delete %s feature probe flow",
odp_put_tunnel_action(&md->tunnel, &execute_actions);
ofpbuf_put(&execute_actions, action, NLA_ALIGN(action->nla_len));
- execute.actions = ofpbuf_data(&execute_actions);
- execute.actions_len = ofpbuf_size(&execute_actions);
+ execute.actions = execute_actions.data;
+ execute.actions_len = execute_actions.size;
} else {
execute.actions = action;
execute.actions_len = NLA_ALIGN(action->nla_len);
struct ofpbuf *buf = ofpbuf_from_list(rpc->output.next);
int retval;
- retval = stream_send(rpc->stream, ofpbuf_data(buf), ofpbuf_size(buf));
+ retval = stream_send(rpc->stream, buf->data, buf->size);
if (retval >= 0) {
rpc->backlog -= retval;
ofpbuf_pull(buf, retval);
- if (!ofpbuf_size(buf)) {
+ if (!buf->size) {
list_remove(&buf->list_node);
rpc->output_count--;
ofpbuf_delete(buf);
buf = xmalloc(sizeof *buf);
ofpbuf_use(buf, s, length);
- ofpbuf_set_size(buf, length);
+ buf->size = length;
list_push_back(&rpc->output, &buf->list_node);
rpc->output_count++;
rpc->backlog += length;
}
ofpact_pad(ofpacts);
- fm->ofpacts = ofpbuf_data(ofpacts);
- fm->ofpacts_len = ofpbuf_size(ofpacts);
+ fm->ofpacts = ofpacts->data;
+ fm->ofpacts_len = ofpacts->size;
}
/* Perform a bitwise-OR on 'wc''s fields that are relevant as sources in
char *error;
spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
- learn = ofpacts->frame;
+ learn = ofpacts->header;
learn->n_specs++;
error = learn_parse_spec(orig, name, value, spec);
switch (type) {
case OFPTYPE_ECHO_REQUEST:
- process_echo_request(sw, ofpbuf_data(msg));
+ process_echo_request(sw, msg->data);
break;
case OFPTYPE_FEATURES_REPLY:
if (sw->state == S_FEATURES_REPLY) {
- if (!process_switch_features(sw, ofpbuf_data(msg))) {
+ if (!process_switch_features(sw, msg->data)) {
sw->state = S_SWITCHING;
} else {
rconn_disconnect(sw->rconn);
break;
case OFPTYPE_PACKET_IN:
- process_packet_in(sw, ofpbuf_data(msg));
+ process_packet_in(sw, msg->data);
break;
case OFPTYPE_FLOW_REMOVED:
case OFPTYPE_BUNDLE_ADD_MESSAGE:
default:
if (VLOG_IS_DBG_ENABLED()) {
- char *s = ofp_to_string(ofpbuf_data(msg), ofpbuf_size(msg), 2);
+ char *s = ofp_to_string(msg->data, msg->size, 2);
VLOG_DBG_RL(&rl, "%016llx: OpenFlow packet ignored: %s",
sw->datapath_id, s);
free(s);
po.packet_len = 0;
}
po.in_port = pi.fmd.in_port;
- po.ofpacts = ofpbuf_data(&ofpacts);
- po.ofpacts_len = ofpbuf_size(&ofpacts);
+ po.ofpacts = ofpacts.data;
+ po.ofpacts_len = ofpacts.size;
/* Send the packet, and possibly the whole flow, to the output port. */
if (sw->max_idle >= 0 && (!sw->ml || out_port != OFPP_FLOOD)) {
fm.idle_timeout = sw->max_idle;
fm.buffer_id = pi.buffer_id;
fm.out_port = OFPP_NONE;
- fm.ofpacts = ofpbuf_data(&ofpacts);
- fm.ofpacts_len = ofpbuf_size(&ofpacts);
+ fm.ofpacts = ofpacts.data;
+ fm.ofpacts_len = ofpacts.size;
buffer = ofputil_encode_flow_mod(&fm, sw->protocol);
queue_tx(sw, buffer);
}
/* Convert odp_key to flow. */
- fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key),
- ofpbuf_size(&odp_key), &flow);
+ fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
if (fitness == ODP_FIT_ERROR) {
ofpbuf_uninit(&odp_key);
return NULL;
ovs_header = ofpbuf_put_uninit(&reply, ovs_msg_size);
if (!DeviceIoControl(sock->handle, OVS_IOCTL_TRANSACT,
- ofpbuf_data(txn.request), ofpbuf_size(txn.request),
- ofpbuf_data(txn.reply), ofpbuf_size(txn.reply),
+ txn.request->data, txn.request->size,
+ txn.reply->data, txn.reply->size,
&bytes, NULL)) {
retval = EINVAL;
goto done;
struct nlmsghdr *nlmsg = nl_msg_nlmsghdr(msg);
int error;
- nlmsg->nlmsg_len = ofpbuf_size(msg);
+ nlmsg->nlmsg_len = msg->size;
nlmsg->nlmsg_seq = nlmsg_seq;
nlmsg->nlmsg_pid = sock->pid;
do {
DWORD bytes;
if (!DeviceIoControl(sock->handle, OVS_IOCTL_WRITE,
- ofpbuf_data(msg), ofpbuf_size(msg), NULL, 0,
+ msg->data, msg->size, NULL, 0,
&bytes, NULL)) {
retval = -1;
/* XXX: Map to a more appropriate error based on GetLastError(). */
errno = EINVAL;
} else {
- retval = ofpbuf_size(msg);
+ retval = msg->size;
}
#else
- retval = send(sock->fd, ofpbuf_data(msg), ofpbuf_size(msg),
+ retval = send(sock->fd, msg->data, msg->size,
wait ? 0 : MSG_DONTWAIT);
#endif
error = retval < 0 ? errno : 0;
} while (error == EINTR);
- log_nlmsg(__func__, error, ofpbuf_data(msg), ofpbuf_size(msg), sock->protocol);
+ log_nlmsg(__func__, error, msg->data, msg->size, sock->protocol);
if (!error) {
COVERAGE_INC(netlink_sent);
}
}
/* Tries to send 'msg', which must contain a Netlink message, to the kernel on
- * 'sock'. nlmsg_len in 'msg' will be finalized to match ofpbuf_size(msg), nlmsg_pid
+ * 'sock'. nlmsg_len in 'msg' will be finalized to match msg->size, nlmsg_pid
* will be set to 'sock''s pid, and nlmsg_seq will be initialized to a fresh
* sequence number, before the message is sent.
*
}
/* Tries to send 'msg', which must contain a Netlink message, to the kernel on
- * 'sock'. nlmsg_len in 'msg' will be finalized to match ofpbuf_size(msg), nlmsg_pid
+ * 'sock'. nlmsg_len in 'msg' will be finalized to match msg->size, nlmsg_pid
* will be set to 'sock''s pid, and nlmsg_seq will be initialized to
* 'nlmsg_seq', before the message is sent.
*
ovs_assert(buf->allocated >= sizeof *nlmsghdr);
ofpbuf_clear(buf);
- iov[0].iov_base = ofpbuf_base(buf);
+ iov[0].iov_base = buf->base;
iov[0].iov_len = buf->allocated;
iov[1].iov_base = tail;
iov[1].iov_len = sizeof tail;
* anything in the receive buffer in that case, so we can initialize the
* Netlink header with an impossible message length and then, upon success,
* check whether it changed. */
- nlmsghdr = ofpbuf_base(buf);
+ nlmsghdr = buf->base;
do {
nlmsghdr->nlmsg_len = UINT32_MAX;
#ifdef _WIN32
} else {
if (retval >= buf->allocated) {
ofpbuf_reinit(buf, retval);
- nlmsghdr = ofpbuf_base(buf);
+ nlmsghdr = buf->base;
nlmsghdr->nlmsg_len = UINT32_MAX;
}
- memcpy(ofpbuf_data(buf), tail, retval);
- ofpbuf_set_size(buf, retval);
+ memcpy(buf->data, tail, retval);
+ buf->size = retval;
}
}
#else
return EPROTO;
}
#ifndef _WIN32
- ofpbuf_set_size(buf, MIN(retval, buf->allocated));
+ buf->size = MIN(retval, buf->allocated);
if (retval > buf->allocated) {
COVERAGE_INC(netlink_recv_jumbo);
ofpbuf_put(buf, tail, retval - buf->allocated);
}
#endif
- log_nlmsg(__func__, 0, ofpbuf_data(buf), ofpbuf_size(buf), sock->protocol);
+ log_nlmsg(__func__, 0, buf->data, buf->size, sock->protocol);
COVERAGE_INC(netlink_received);
return 0;
struct nl_transaction *txn = transactions[i];
struct nlmsghdr *nlmsg = nl_msg_nlmsghdr(txn->request);
- nlmsg->nlmsg_len = ofpbuf_size(txn->request);
+ nlmsg->nlmsg_len = txn->request->size;
nlmsg->nlmsg_seq = base_seq + i;
nlmsg->nlmsg_pid = sock->pid;
- iovs[i].iov_base = ofpbuf_data(txn->request);
- iovs[i].iov_len = ofpbuf_size(txn->request);
+ iovs[i].iov_base = txn->request->data;
+ iovs[i].iov_len = txn->request->size;
}
#ifndef _WIN32
for (i = 0; i < n; i++) {
struct nl_transaction *txn = transactions[i];
- log_nlmsg(__func__, error, ofpbuf_data(txn->request),
- ofpbuf_size(txn->request), sock->protocol);
+ log_nlmsg(__func__, error, txn->request->data,
+ txn->request->size, sock->protocol);
}
if (!error) {
COVERAGE_ADD(netlink_sent, n);
struct nlmsghdr *request_nlmsg, *reply_nlmsg;
if (!DeviceIoControl(sock->handle, OVS_IOCTL_TRANSACT,
- ofpbuf_data(txn->request),
- ofpbuf_size(txn->request),
+ txn->request->data,
+ txn->request->size,
reply_buf, sizeof reply_buf,
&reply_len, NULL)) {
/* XXX: Map to a more appropriate error. */
/* Handle errors embedded within the netlink message. */
ofpbuf_use_stub(&tmp_reply, reply_buf, sizeof reply_buf);
- ofpbuf_set_size(&tmp_reply, sizeof reply_buf);
+ tmp_reply.size = sizeof reply_buf;
if (nl_msg_nlmsgerr(&tmp_reply, &txn->error)) {
if (txn->reply) {
ofpbuf_clear(txn->reply);
if (reply_len > txn->reply->allocated) {
ofpbuf_reinit(txn->reply, reply_len);
}
- memcpy(ofpbuf_data(txn->reply), reply_buf, reply_len);
- ofpbuf_set_size(txn->reply, reply_len);
+ memcpy(txn->reply->data, reply_buf, reply_len);
+ txn->reply->size = reply_len;
}
}
ofpbuf_uninit(&tmp_reply);
#else
enum { MAX_BATCH_BYTES = 4096 - 512 };
#endif
- bytes = ofpbuf_size(transactions[0]->request);
+ bytes = transactions[0]->request->size;
for (count = 1; count < n && count < max_batch_count; count++) {
- if (bytes + ofpbuf_size(transactions[count]->request) > MAX_BATCH_BYTES) {
+ if (bytes + transactions[count]->request->size > MAX_BATCH_BYTES) {
break;
}
- bytes += ofpbuf_size(transactions[count]->request);
+ bytes += transactions[count]->request->size;
}
error = nl_sock_transact_multiple__(sock, transactions, count, &done);
struct nlmsghdr *nlmsghdr;
int error;
- while (!ofpbuf_size(buffer)) {
+ while (!buffer->size) {
error = nl_sock_recv__(dump->sock, buffer, false);
if (error) {
/* The kernel never blocks providing the results of a dump, so
* initialized. 'buffer' should be at least NL_DUMP_BUFSIZE bytes long.
*
* If successful, returns true and points 'reply->data' and
- * 'ofpbuf_size(reply)' to the message that was retrieved. The caller must not
+ * 'reply->size' to the message that was retrieved. The caller must not
* modify 'reply' (because it points within 'buffer', which will be used by
* future calls to this function).
*
* On failure, returns false and sets 'reply->data' to NULL and
- * 'ofpbuf_size(reply)' to 0. Failure might indicate an actual error or merely
+ * 'reply->size' to 0. Failure might indicate an actual error or merely
* the end of replies. An error status for the entire dump operation is
* provided when it is completed by calling nl_dump_done().
*
* If the buffer is not empty, we don't check the dump's status.
* Otherwise, we could end up skipping some of the dump results if thread A
* hits EOF while thread B is in the midst of processing a batch. */
- if (!ofpbuf_size(buffer)) {
+ if (!buffer->size) {
ovs_mutex_lock(&dump->mutex);
if (!dump->status) {
/* Take the mutex here to avoid an in-kernel race. If two threads
}
if (retval) {
- ofpbuf_set_data(reply, NULL);
- ofpbuf_set_size(reply, 0);
+ reply->data = NULL;
+ reply->size = 0;
}
return !retval;
}
ovs_header->dp_ifindex = 0;
if (!DeviceIoControl(sock->handle, OVS_IOCTL_WRITE,
- ofpbuf_data(&request), ofpbuf_size(&request),
+ request.data, request.size,
NULL, 0, &bytes, overlapped)) {
error = GetLastError();
/* Check if the I/O got pended */
/* Set the total length of the netlink message. */
nlmsg = nl_msg_nlmsghdr(reply);
- nlmsg->nlmsg_len = ofpbuf_size(reply);
+ nlmsg->nlmsg_len = reply->size;
if (!nl_policy_parse(reply, NLMSG_HDRLEN + GENL_HDRLEN,
family_policy, attrs, ARRAY_SIZE(family_policy))
* reply, if any, is discarded.
*
* Before the message is sent, nlmsg_len in 'request' will be finalized to
- * match ofpbuf_size(msg), nlmsg_pid will be set to the pid of the socket used
+ * match msg->size, nlmsg_pid will be set to the pid of the socket used
* for sending the request, and nlmsg_seq will be initialized.
*
* The caller is responsible for destroying 'request'.
int code = EPROTO;
if (!err) {
VLOG_ERR_RL(&rl, "received invalid nlmsgerr (%"PRIu32" bytes < %"PRIuSIZE")",
- ofpbuf_size(msg), NLMSG_HDRLEN + sizeof *err);
+ msg->size, NLMSG_HDRLEN + sizeof *err);
} else if (err->error <= 0 && err->error > INT_MIN) {
code = -err->error;
}
{
struct nlmsghdr *nlmsghdr;
- ovs_assert(ofpbuf_size(msg) == 0);
+ ovs_assert(msg->size == 0);
nl_msg_reserve(msg, NLMSG_HDRLEN + expected_payload);
nlmsghdr = nl_msg_put_uninit(msg, NLMSG_HDRLEN);
struct genlmsghdr *genlmsghdr;
nl_msg_put_nlmsghdr(msg, GENL_HDRLEN + expected_payload, family, flags);
- ovs_assert(ofpbuf_size(msg) == NLMSG_HDRLEN);
+ ovs_assert(msg->size == NLMSG_HDRLEN);
genlmsghdr = nl_msg_put_uninit(msg, GENL_HDRLEN);
genlmsghdr->cmd = cmd;
genlmsghdr->version = version;
size_t
nl_msg_start_nested(struct ofpbuf *msg, uint16_t type)
{
- size_t offset = ofpbuf_size(msg);
+ size_t offset = msg->size;
nl_msg_put_unspec(msg, type, NULL, 0);
return offset;
}
nl_msg_end_nested(struct ofpbuf *msg, size_t offset)
{
struct nlattr *attr = ofpbuf_at_assert(msg, offset, sizeof *attr);
- attr->nla_len = ofpbuf_size(msg) - offset;
+ attr->nla_len = msg->size - offset;
}
/* Appends a nested Netlink attribute of the given 'type', with the 'size'
/* If 'buffer' begins with a valid "struct nlmsghdr", pulls the header and its
* payload off 'buffer', stores header and payload in 'msg->data' and
- * 'ofpbuf_size(msg)', and returns a pointer to the header.
+ * 'msg->size', and returns a pointer to the header.
*
* If 'buffer' does not begin with a "struct nlmsghdr" or begins with one that
* is invalid, returns NULL and clears 'buffer' and 'msg'. */
struct nlmsghdr *
nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg)
{
- if (ofpbuf_size(buffer) >= sizeof(struct nlmsghdr)) {
+ if (buffer->size >= sizeof(struct nlmsghdr)) {
struct nlmsghdr *nlmsghdr = nl_msg_nlmsghdr(buffer);
size_t len = nlmsghdr->nlmsg_len;
- if (len >= sizeof *nlmsghdr && len <= ofpbuf_size(buffer)) {
+ if (len >= sizeof *nlmsghdr && len <= buffer->size) {
ofpbuf_use_const(msg, nlmsghdr, len);
ofpbuf_pull(buffer, len);
return nlmsghdr;
}
ofpbuf_clear(buffer);
- ofpbuf_set_data(msg, NULL);
- ofpbuf_set_size(msg, 0);
+ msg->data = NULL;
+ msg->size = 0;
return NULL;
}
memset(attrs, 0, n_attrs * sizeof *attrs);
- if (ofpbuf_size(msg) < nla_offset) {
+ if (msg->size < nla_offset) {
VLOG_DBG_RL(&rl, "missing headers in nl_policy_parse");
return false;
}
NL_ATTR_FOR_EACH (nla, left, ofpbuf_at(msg, nla_offset, 0),
- ofpbuf_size(msg) - nla_offset)
+ msg->size - nla_offset)
{
uint16_t type = nl_attr_type(nla);
if (type < n_attrs && policy[type].type != NL_A_NO_ATTR) {
const struct nlattr *
nl_attr_find(const struct ofpbuf *buf, size_t hdr_len, uint16_t type)
{
- return nl_attr_find__(ofpbuf_at(buf, hdr_len, 0), ofpbuf_size(buf) - hdr_len,
+ return nl_attr_find__(ofpbuf_at(buf, hdr_len, 0), buf->size - hdr_len,
type);
}
nx_pull_header__(struct ofpbuf *b, bool allow_cookie, uint64_t *header,
const struct mf_field **field)
{
- if (ofpbuf_size(b) < 4) {
+ if (b->size < 4) {
goto bad_len;
}
- *header = ((uint64_t) ntohl(get_unaligned_be32(ofpbuf_data(b)))) << 32;
+ *header = ((uint64_t) ntohl(get_unaligned_be32(b->data))) << 32;
if (is_experimenter_oxm(*header)) {
- if (ofpbuf_size(b) < 8) {
+ if (b->size < 8) {
goto bad_len;
}
- *header = ntohll(get_unaligned_be64(ofpbuf_data(b)));
+ *header = ntohll(get_unaligned_be64(b->data));
}
if (nxm_length(*header) <= nxm_experimenter_len(*header)) {
VLOG_WARN_RL(&rl, "OXM header "NXM_HEADER_FMT" has invalid length %d "
bad_len:
VLOG_DBG_RL(&rl, "encountered partial (%"PRIu32"-byte) OXM entry",
- ofpbuf_size(b));
+ b->size);
error:
*header = 0;
*field = NULL;
if (!payload) {
VLOG_DBG_RL(&rl, "OXM header "NXM_HEADER_FMT" calls for %u-byte "
"payload but only %"PRIu32" bytes follow OXM header",
- NXM_HEADER_ARGS(*header), payload_len, ofpbuf_size(b));
+ NXM_HEADER_ARGS(*header), payload_len, b->size);
return OFPERR_OFPBMC_BAD_LEN;
}
}
ofpbuf_use_const(&b, p, match_len);
- while (ofpbuf_size(&b)) {
- const uint8_t *pos = ofpbuf_data(&b);
+ while (b.size) {
+ const uint8_t *pos = b.data;
const struct mf_field *field;
union mf_value value;
union mf_value mask;
if (!p) {
VLOG_DBG_RL(&rl, "nx_match length %u, rounded up to a "
"multiple of 8, is longer than space in message (max "
- "length %"PRIu32")", match_len, ofpbuf_size(b));
+ "length %"PRIu32")", match_len, b->size);
return OFPERR_OFPBMC_BAD_LEN;
}
}
static enum ofperr
oxm_pull_match__(struct ofpbuf *b, bool strict, struct match *match)
{
- struct ofp11_match_header *omh = ofpbuf_data(b);
+ struct ofp11_match_header *omh = b->data;
uint8_t *p;
uint16_t match_len;
- if (ofpbuf_size(b) < sizeof *omh) {
+ if (b->size < sizeof *omh) {
return OFPERR_OFPBMC_BAD_LEN;
}
if (!p) {
VLOG_DBG_RL(&rl, "oxm length %u, rounded up to a "
"multiple of 8, is longer than space in message (max "
- "length %"PRIu32")", match_len, ofpbuf_size(b));
+ "length %"PRIu32")", match_len, b->size);
return OFPERR_OFPBMC_BAD_LEN;
}
ovs_be64 cookie, ovs_be64 cookie_mask)
{
const struct flow *flow = &match->flow;
- const size_t start_len = ofpbuf_size(b);
+ const size_t start_len = b->size;
int match_len;
int i;
}
}
- match_len = ofpbuf_size(b) - start_len;
+ match_len = b->size - start_len;
return match_len;
}
{
int match_len;
struct ofp11_match_header *omh;
- size_t start_len = ofpbuf_size(b);
+ size_t start_len = b->size;
ovs_be64 cookie = htonll(0), cookie_mask = htonll(0);
ofpbuf_put_uninit(b, sizeof *omh);
ofpbuf_use_const(&b, p, match_len);
ds_init(&s);
- while (ofpbuf_size(&b)) {
+ while (b.size) {
union mf_value value;
union mf_value mask;
enum ofperr error;
ds_put_char(&s, ')');
}
- if (ofpbuf_size(&b)) {
+ if (b.size) {
if (s.length) {
ds_put_cstr(&s, ", ");
}
- ds_put_format(&s, "<%u invalid bytes>", ofpbuf_size(&b));
+ ds_put_format(&s, "<%u invalid bytes>", b.size);
}
return ds_steal_cstr(&s);
char *
oxm_match_to_string(const struct ofpbuf *p, unsigned int match_len)
{
- const struct ofp11_match_header *omh = ofpbuf_data(p);
+ const struct ofp11_match_header *omh = p->data;
uint16_t match_len_;
struct ds s;
nx_match_from_string_raw(const char *s, struct ofpbuf *b)
{
const char *full_s = s;
- const size_t start_len = ofpbuf_size(b);
+ const size_t start_len = b->size;
if (!strcmp(s, "<any>")) {
- /* Ensure that 'ofpbuf_data(b)' isn't actually null. */
+ /* Ensure that 'b->data' isn't actually null. */
ofpbuf_prealloc_tailroom(b, 1);
return 0;
}
s++;
}
- return ofpbuf_size(b) - start_len;
+ return b->size - start_len;
}
int
{
int match_len;
struct ofp11_match_header *omh;
- size_t start_len = ofpbuf_size(b);
+ size_t start_len = b->size;
ofpbuf_put_uninit(b, sizeof *omh);
match_len = nx_match_from_string_raw(s, b) + sizeof *omh;
{
union mf_subvalue *v = NULL;
- if (ofpbuf_size(stack)) {
+ if (stack->size) {
- ofpbuf_set_size(stack, ofpbuf_size(stack) - sizeof *v);
+ stack->size -= sizeof *v;
v = (union mf_subvalue *) ofpbuf_tail(stack);
}
if (end[0] != ')') {
return -EINVAL;
}
- user_data = ofpbuf_data(&buf);
- user_data_size = ofpbuf_size(&buf);
+ user_data = buf.data;
+ user_data_size = buf.size;
n = (end + 1) - s;
}
}
return 0;
}
- old_size = ofpbuf_size(actions);
+ old_size = actions->size;
for (;;) {
int retval;
retval = parse_odp_action(s, port_names, actions);
if (retval < 0 || !strchr(delimiters, s[retval])) {
- ofpbuf_set_size(actions, old_size);
+ actions->size = old_size;
return -retval;
}
s += retval;
nl_msg_end_nested(ofp, nested_mask);
}
- return ofpbuf_base(ofp);
+ return ofp->base;
}
int
odp_flow_from_string(const char *s, const struct simap *port_names,
struct ofpbuf *key, struct ofpbuf *mask)
{
- const size_t old_size = ofpbuf_size(key);
+ const size_t old_size = key->size;
for (;;) {
int retval;
retval = parse_odp_key_mask_attr(s, port_names, key, mask);
if (retval < 0) {
- ofpbuf_set_size(key, old_size);
+ key->size = old_size;
return -retval;
}
s += retval;
offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_USERSPACE);
nl_msg_put_u32(odp_actions, OVS_USERSPACE_ATTR_PID, pid);
if (userdata) {
- userdata_ofs = ofpbuf_size(odp_actions) + NLA_HDRLEN;
+ userdata_ofs = odp_actions->size + NLA_HDRLEN;
/* The OVS kernel module before OVS 1.11 and the upstream Linux kernel
* module before Linux 3.10 required the userdata to be exactly 8 bytes
if (error) {
return error;
}
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_NXBRC_MUST_BE_ZERO;
}
if (output_reg->ofpact.raw == NXAST_RAW_OUTPUT_REG2
|| !mf_nxm_header(output_reg->src.field->id)) {
struct nx_action_output_reg2 *naor = put_NXAST_OUTPUT_REG2(out);
- size_t size = ofpbuf_size(out);
+ size_t size = out->size;
naor->ofs_nbits = nxm_encode_ofs_nbits(output_reg->src.ofs,
output_reg->src.n_bits);
naor->max_len = htons(output_reg->max_len);
- ofpbuf_set_size(out, size - sizeof naor->pad);
+ out->size = size - sizeof naor->pad;
nx_put_header(out, output_reg->src.field->id, 0, false);
- ofpbuf_set_size(out, size);
+ out->size = size;
} else {
struct nx_action_output_reg *naor = put_NXAST_OUTPUT_REG(out);
ofpbuf_put(ofpacts, &ofp_port, sizeof ofp_port);
}
- bundle = ofpacts->frame;
+ bundle = ofpacts->header;
ofpact_update_len(ofpacts, &bundle->ofpact);
if (!error) {
return error;
}
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_NXBRC_MUST_BE_ZERO;
}
if (error) {
return error;
}
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_NXBRC_MUST_BE_ZERO;
}
* probe for support. Until we have that ability, we currently prefer
* NXAST_RAW_REG_MOVE for backward compatibility with older Open vSwitch
* versions. */
- size_t start_ofs = ofpbuf_size(out);
+ size_t start_ofs = out->size;
if (ofp_version >= OFP15_VERSION) {
struct ofp15_action_copy_field *copy = put_OFPAT15_COPY_FIELD(out);
copy->n_bits = htons(move->dst.n_bits);
copy->src_offset = htons(move->src.ofs);
copy->dst_offset = htons(move->dst.ofs);
- ofpbuf_set_size(out, ofpbuf_size(out) - sizeof copy->pad2);
+ out->size = out->size - sizeof copy->pad2;
nx_put_header(out, move->src.field->id, ofp_version, false);
nx_put_header(out, move->dst.field->id, ofp_version, false);
} else if (ofp_version == OFP13_VERSION
copy->n_bits = htons(move->dst.n_bits);
copy->src_offset = htons(move->src.ofs);
copy->dst_offset = htons(move->dst.ofs);
- ofpbuf_set_size(out, ofpbuf_size(out) - sizeof copy->pad3);
+ out->size = out->size - sizeof copy->pad3;
nx_put_header(out, move->src.field->id, ofp_version, false);
nx_put_header(out, move->dst.field->id, ofp_version, false);
} else {
memset(&sf->mask, 0xff, sf->field->n_bytes);
}
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
}
if (error) {
return error;
}
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_OFPBAC_BAD_SET_ARGUMENT;
}
{
struct ofp12_action_set_field *oasf OVS_UNUSED;
int n_bytes = mf_from_id(field)->n_bytes;
- size_t start_ofs = ofpbuf_size(openflow);
+ size_t start_ofs = openflow->size;
union mf_value value;
value.be64 = htonll(value_ << (8 * (8 - n_bytes)));
oasf = put_OFPAT12_SET_FIELD(openflow);
- ofpbuf_set_size(openflow, ofpbuf_size(openflow) - sizeof oasf->pad);
+ openflow->size = openflow->size - sizeof oasf->pad;
nx_put_entry(openflow, field, ofp_version, &value, NULL);
pad_ofpat(openflow, start_ofs);
}
if (sf->ofpact.raw == NXAST_RAW_REG_LOAD2
|| !mf_nxm_header(sf->field->id)) {
struct nx_action_reg_load2 *narl OVS_UNUSED;
- size_t start_ofs = ofpbuf_size(openflow);
+ size_t start_ofs = openflow->size;
narl = put_NXAST_REG_LOAD2(openflow);
- ofpbuf_set_size(openflow, ofpbuf_size(openflow) - sizeof narl->pad);
+ openflow->size = openflow->size - sizeof narl->pad;
nx_put_entry(openflow, sf->field->id, 0, &sf->value, &sf->mask);
pad_ofpat(openflow, start_ofs);
} else {
enum ofp_version ofp_version, struct ofpbuf *out)
{
struct ofp12_action_set_field *oasf OVS_UNUSED;
- size_t start_ofs = ofpbuf_size(out);
+ size_t start_ofs = out->size;
oasf = put_OFPAT12_SET_FIELD(out);
- ofpbuf_set_size(out, ofpbuf_size(out) - sizeof oasf->pad);
+ out->size = out->size - sizeof oasf->pad;
nx_put_entry(out, sf->field->id, ofp_version, &sf->value, &sf->mask);
pad_ofpat(out, start_ofs);
}
if (error) {
return error;
}
- stack_action->subfield.n_bits = ntohs(*(const ovs_be16 *) ofpbuf_data(&b));
+ stack_action->subfield.n_bits = ntohs(*(const ovs_be16 *) b.data);
ofpbuf_pull(&b, 2);
- if (!is_all_zeros(ofpbuf_data(&b), ofpbuf_size(&b))) {
+ if (!is_all_zeros(b.data, b.size)) {
return OFPERR_NXBRC_MUST_BE_ZERO;
}
ids = ofpact_put_DEC_TTL(out);
ids->n_controllers = 1;
ofpbuf_put(out, &id, sizeof id);
- ids = out->frame;
+ ids = out->header;
ofpact_update_len(out, &ids->ofpact);
return error;
}
for (i = 0; i < ids->n_controllers; i++) {
uint16_t id = ntohs(((ovs_be16 *)(nac_ids + 1))[i]);
ofpbuf_put(out, &id, sizeof id);
- ids = out->frame;
+ ids = out->header;
}
ofpact_update_len(out, &ids->ofpact);
ofpact_put_DEC_TTL(ofpacts);
ofpbuf_put(ofpacts, &id, sizeof id);
- ids = ofpacts->frame;
+ ids = ofpacts->header;
ids->n_controllers++;
ofpact_update_len(ofpacts, &ids->ofpact);
}
uint16_t id = atoi(cntr);
ofpbuf_put(ofpacts, &id, sizeof id);
- ids = ofpacts->frame;
+ ids = ofpacts->header;
ids->n_controllers++;
}
if (!ids->n_controllers) {
}
spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
- learn = ofpacts->frame;
+ learn = ofpacts->header;
learn->n_specs++;
spec->src_type = header & NX_LEARN_SRC_MASK;
struct nx_action_learn *nal;
size_t start_ofs;
- start_ofs = ofpbuf_size(out);
+ start_ofs = out->size;
nal = put_NXAST_LEARN(out);
nal->idle_timeout = htons(learn->idle_timeout);
nal->hard_timeout = htons(learn->hard_timeout);
encode_NOTE(const struct ofpact_note *note,
enum ofp_version ofp_version OVS_UNUSED, struct ofpbuf *out)
{
- size_t start_ofs = ofpbuf_size(out);
+ size_t start_ofs = out->size;
struct nx_action_note *nan;
unsigned int remainder;
unsigned int len;
put_NXAST_NOTE(out);
- ofpbuf_set_size(out, ofpbuf_size(out) - sizeof nan->note);
+ out->size = out->size - sizeof nan->note;
ofpbuf_put(out, note->data, note->length);
- len = ofpbuf_size(out) - start_ofs;
+ len = out->size - start_ofs;
remainder = len % OFP_ACTION_ALIGN;
if (remainder) {
ofpbuf_put_zeros(out, OFP_ACTION_ALIGN - remainder);
}
nan = ofpbuf_at(out, start_ofs, sizeof *nan);
- nan->len = htons(ofpbuf_size(out) - start_ofs);
+ nan->len = htons(out->size - start_ofs);
}
static char * OVS_WARN_UNUSED_RESULT
}
ofpbuf_put(ofpacts, &byte, 1);
- note = ofpacts->frame;
+ note = ofpacts->header;
note->length++;
arg += 2;
enum ofp_version ofp_version, struct ofpbuf *out)
{
if (ofp_version > OFP10_VERSION) {
- const size_t ofs = ofpbuf_size(out);
+ const size_t ofs = out->size;
instruction_put_OFPIT11_WRITE_ACTIONS(out);
ofpacts_put_openflow_actions(actions->actions,
/* Pull off existing actions or instructions. */
ofpact_pad(ofpacts);
- ofs = ofpbuf_size(ofpacts);
+ ofs = ofpacts->size;
ofpbuf_pull(ofpacts, ofs);
/* Add a Write-Actions instruction and then pull it off. */
/* Put the Write-Actions back on and update its length. */
on = ofpbuf_push_uninit(ofpacts, sizeof *on);
- on->ofpact.len = ofpbuf_size(ofpacts);
+ on->ofpact.len = ofpacts->size;
/* Put any previous actions or instructions back on. */
ofpbuf_push_uninit(ofpacts, ofs);
struct ofpbuf openflow;
ofpbuf_use_const(&openflow, actions, actions_len);
- while (ofpbuf_size(&openflow)) {
- const struct ofp_action_header *action = ofpbuf_data(&openflow);
+ while (openflow.size) {
+ const struct ofp_action_header *action = openflow.data;
enum ofp_raw_action_type raw;
enum ofperr error;
uint64_t arg;
if (actions == NULL) {
VLOG_WARN_RL(&rl, "OpenFlow message actions length %u exceeds "
"remaining message length (%"PRIu32")",
- actions_len, ofpbuf_size(openflow));
+ actions_len, openflow->size);
return OFPERR_OFPBRC_BAD_LEN;
}
return error;
}
- error = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
+ error = ofpacts_verify(ofpacts->data, ofpacts->size,
allowed_ovsinsts);
if (error) {
ofpbuf_clear(ofpacts);
const struct ofpact *a;
target = NULL;
- OFPACT_FOR_EACH (a, ofpbuf_data(in), ofpbuf_size(in)) {
+ OFPACT_FOR_EACH (a, in->data, in->size) {
if (a->type == filter) {
target = a;
}
{
const struct ofpact *a;
- OFPACT_FOR_EACH (a, ofpbuf_data(in), ofpbuf_size(in)) {
+ OFPACT_FOR_EACH (a, in->data, in->size) {
if (filter(a)) {
ofpact_copy(out, a);
}
{
enum ofperr error;
struct ofpact *a;
- size_t start = ofpbuf_size(out);
+ size_t start = out->size;
error = ofpacts_decode(in, n_in, version, out);
return error;
}
- OFPACT_FOR_EACH (a, ofpact_end(ofpbuf_data(out), start), ofpbuf_size(out) - start) {
+ OFPACT_FOR_EACH (a, ofpact_end(out->data, start), out->size - start) {
if (!ofpact_is_allowed_in_actions_set(a)) {
VLOG_WARN_RL(&rl, "disallowed action in action set");
return OFPERR_OFPBAC_BAD_TYPE;
if (instructions == NULL) {
VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u exceeds "
"remaining message length (%"PRIu32")",
- instructions_len, ofpbuf_size(openflow));
+ instructions_len, openflow->size);
error = OFPERR_OFPBIC_BAD_LEN;
goto exit;
}
size_t start;
ofpact_pad(ofpacts);
- start = ofpbuf_size(ofpacts);
+ start = ofpacts->size;
on = ofpact_put(ofpacts, OFPACT_WRITE_ACTIONS,
offsetof(struct ofpact_nest, actions));
get_actions_from_instruction(insts[OVSINST_OFPIT11_WRITE_ACTIONS],
goto exit;
}
on = ofpbuf_at_assert(ofpacts, start, sizeof *on);
- on->ofpact.len = ofpbuf_size(ofpacts) - start;
+ on->ofpact.len = ofpacts->size - start;
}
if (insts[OVSINST_OFPIT11_WRITE_METADATA]) {
const struct ofp11_instruction_write_metadata *oiwm;
ogt->table_id = oigt->table_id;
}
- error = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
+ error = ofpacts_verify(ofpacts->data, ofpacts->size,
(1u << N_OVS_INSTRUCTIONS) - 1);
exit:
if (error) {
struct ofp11_instruction_actions *oia;
oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia);
- if (ofpbuf_size(openflow) > ofs + sizeof *oia) {
- oia->len = htons(ofpbuf_size(openflow) - ofs);
+ if (openflow->size > ofs + sizeof *oia) {
+ oia->len = htons(openflow->size - ofs);
} else {
- ofpbuf_set_size(openflow, ofs);
+ openflow->size = ofs;
}
}
\f
enum ofp_version ofp_version)
{
const struct ofpact *a;
- size_t start_size = ofpbuf_size(openflow);
+ size_t start_size = openflow->size;
OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
encode_ofpact(a, ofp_version, openflow);
}
- return ofpbuf_size(openflow) - start_size;
+ return openflow->size - start_size;
}
static enum ovs_instruction_type
a = ofpacts;
while (a < end) {
if (ofpact_is_apply_actions(a)) {
- size_t ofs = ofpbuf_size(openflow);
+ size_t ofs = openflow->size;
instruction_put_OFPIT11_APPLY_ACTIONS(openflow);
do {
struct ofpact *ofpact;
ofpact_pad(ofpacts);
- ofpact = ofpacts->frame = ofpbuf_put_uninit(ofpacts, len);
+ ofpacts->header = ofpbuf_put_uninit(ofpacts, len);
+ ofpact = ofpacts->header;
ofpact_init(ofpact, type, len);
return ofpact;
}
void
ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *ofpact)
{
- ovs_assert(ofpact == ofpacts->frame);
+ ovs_assert(ofpact == ofpacts->header);
ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
}
void
ofpact_pad(struct ofpbuf *ofpacts)
{
- unsigned int pad = PAD_SIZE(ofpbuf_size(ofpacts), OFPACT_ALIGNTO);
+ unsigned int pad = PAD_SIZE(ofpacts->size, OFPACT_ALIGNTO);
if (pad) {
ofpbuf_put_zeros(ofpacts, pad);
}
}
ofpact_pad(ofpacts);
- if (drop && ofpbuf_size(ofpacts)) {
+ if (drop && ofpacts->size) {
return xstrdup("\"drop\" must not be accompanied by any other action "
"or instruction");
}
- retval = ofpacts_verify(ofpbuf_data(ofpacts), ofpbuf_size(ofpacts),
+ retval = ofpacts_verify(ofpacts->data, ofpacts->size,
(allow_instructions
? (1u << N_OVS_INSTRUCTIONS) - 1
: 1u << OVSINST_OFPIT11_APPLY_ACTIONS));
ofpacts_parse(char *str, struct ofpbuf *ofpacts,
enum ofputil_protocol *usable_protocols, bool allow_instructions)
{
- uint32_t orig_size = ofpbuf_size(ofpacts);
+ uint32_t orig_size = ofpacts->size;
char *error = ofpacts_parse__(str, ofpacts, usable_protocols,
allow_instructions);
if (error) {
- ofpbuf_set_size(ofpacts, orig_size);
+ ofpacts->size = orig_size;
}
return error;
}
ofpact_pull_raw(struct ofpbuf *buf, enum ofp_version ofp_version,
enum ofp_raw_action_type *raw, uint64_t *arg)
{
- const struct ofp_action_header *oah = ofpbuf_data(buf);
+ const struct ofp_action_header *oah = buf->data;
const struct ofpact_raw_instance *action;
unsigned int length;
enum ofperr error;
*raw = *arg = 0;
- error = ofpact_decode_raw(ofp_version, oah, ofpbuf_size(buf), &action);
+ error = ofpact_decode_raw(ofp_version, oah, buf->size, &action);
if (error) {
return error;
}
}
length = ntohs(oah->len);
- if (length > ofpbuf_size(buf)) {
+ if (length > buf->size) {
VLOG_WARN_RL(&rl, "OpenFlow action %s length %u exceeds action buffer "
- "length %"PRIu32, action->name, length, ofpbuf_size(buf));
+ "length %"PRIu32, action->name, length, buf->size);
return OFPERR_OFPBAC_BAD_LEN;
}
if (length < action->min_length || length > action->max_length) {
{
struct ofp_action_header *oah;
- ofpbuf_put_zeros(openflow, PAD_SIZE(ofpbuf_size(openflow) - start_ofs, 8));
+ ofpbuf_put_zeros(openflow, PAD_SIZE(openflow->size - start_ofs, 8));
oah = ofpbuf_at_assert(openflow, start_ofs, sizeof *oah);
- oah->len = htons(ofpbuf_size(openflow) - start_ofs);
+ oah->len = htons(openflow->size - start_ofs);
}
/* Translate the error type and code into an ofperr. */
error = ofperr_decode(oh->version, vendor, type, code);
if (error && payload) {
- ofpbuf_init(payload, ofpbuf_size(&b));
- ofpbuf_push(payload, ofpbuf_data(&b), ofpbuf_size(&b));
+ ofpbuf_init(payload, b.size);
+ ofpbuf_push(payload, b.data, b.size);
}
return error;
}
}
/* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts
- * at 'ofpbuf_data(msg)' and has length 'ofpbuf_size(msg)' bytes. On success,
+ * at 'msg->data' and has length 'msg->size' bytes. On success,
* returns 0 and stores the type into '*rawp'. On failure, returns an OFPERR_*
* error code and zeros '*rawp'.
*
* In addition to setting '*rawp', this function pulls off the OpenFlow header
* (including the stats headers, vendor header, and any subtype header) with
* ofpbuf_pull(). It also sets 'msg->frame' to the start of the OpenFlow
- * header and 'msg->l3' just beyond the headers (that is, to the final value of
- * ofpbuf_data(msg)). */
+ * header and 'msg->msg' just beyond the headers (that is, to the final value of
+ * msg->data). */
enum ofperr
ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg)
{
enum ofpraw raw;
/* Set default outputs. */
- msg->frame = ofpbuf_data(msg);
- ofpbuf_set_l3(msg, msg->frame);
+ msg->header = msg->data;
+ msg->msg = msg->header;
*rawp = 0;
- len = ofpbuf_size(msg);
- error = ofphdrs_decode(&hdrs, ofpbuf_data(msg), len);
+ len = msg->size;
+ error = ofphdrs_decode(&hdrs, msg->data, len);
if (error) {
return error;
}
info = raw_info_get(raw);
instance = raw_instance_get(info, hdrs.version);
- msg->frame = ofpbuf_pull(msg, instance->hdrs_len);
- ofpbuf_set_l3(msg, ofpbuf_data(msg));
+ msg->header = ofpbuf_pull(msg, instance->hdrs_len);
+ msg->msg = msg->data;
min_len = instance->hdrs_len + info->min_body;
switch (info->extra_multiple) {
* must specify a valid (raw, version) pair.
*
* Upon return, 'buf->frame' points to the beginning of the OpenFlow header and
- * 'buf->l3' points just after it, to where the message's body will start. The
+ * 'buf->msg' points just after it, to where the message's body will start. The
* caller must actually allocating the body into the space reserved for it,
* e.g. with ofpbuf_put_uninit(). */
void
ofpbuf_prealloc_tailroom(buf, (instance->hdrs_len + info->min_body
+ extra_tailroom));
- buf->frame = ofpbuf_put_uninit(buf, instance->hdrs_len);
- ofpbuf_set_l3(buf, ofpbuf_tail(buf));
+ buf->header = ofpbuf_put_uninit(buf, instance->hdrs_len);
+ buf->msg = ofpbuf_tail(buf);
- oh = buf->frame;
+ oh = buf->header;
oh->version = version;
oh->type = hdrs->type;
- oh->length = htons(ofpbuf_size(buf));
+ oh->length = htons(buf->size);
oh->xid = xid;
if (hdrs->type == OFPT_VENDOR) {
- struct nicira_header *nh = buf->frame;
+ struct nicira_header *nh = buf->header;
ovs_assert(hdrs->vendor == NX_VENDOR_ID);
nh->vendor = htonl(hdrs->vendor);
} else if (version == OFP10_VERSION
&& (hdrs->type == OFPT10_STATS_REQUEST ||
hdrs->type == OFPT10_STATS_REPLY)) {
- struct ofp10_stats_msg *osm = buf->frame;
+ struct ofp10_stats_msg *osm = buf->header;
osm->type = htons(hdrs->stat);
osm->flags = htons(0);
if (hdrs->stat == OFPST_VENDOR) {
- struct ofp10_vendor_stats_msg *ovsm = buf->frame;
+ struct ofp10_vendor_stats_msg *ovsm = buf->header;
ovsm->vendor = htonl(hdrs->vendor);
if (hdrs->vendor == NX_VENDOR_ID) {
- struct nicira10_stats_msg *nsm = buf->frame;
+ struct nicira10_stats_msg *nsm = buf->header;
nsm->subtype = htonl(hdrs->subtype);
memset(nsm->pad, 0, sizeof nsm->pad);
} else if (version != OFP10_VERSION
&& (hdrs->type == OFPT11_STATS_REQUEST ||
hdrs->type == OFPT11_STATS_REPLY)) {
- struct ofp11_stats_msg *osm = buf->frame;
+ struct ofp11_stats_msg *osm = buf->header;
osm->type = htons(hdrs->stat);
osm->flags = htons(0);
memset(osm->pad, 0, sizeof osm->pad);
if (hdrs->stat == OFPST_VENDOR) {
- struct ofp11_vendor_stats_msg *ovsm = buf->frame;
+ struct ofp11_vendor_stats_msg *ovsm = buf->header;
ovsm->vendor = htonl(hdrs->vendor);
if (hdrs->vendor == NX_VENDOR_ID) {
- struct nicira11_stats_msg *nsm = buf->frame;
+ struct nicira11_stats_msg *nsm = buf->header;
nsm->subtype = htonl(hdrs->subtype);
} else {
}
/* Determines the OFPTYPE_* type of the OpenFlow message in 'msg', which starts
- * at 'ofpbuf_data(msg)' and has length 'ofpbuf_size(msg)' bytes. On success,
+ * at 'msg->data' and has length 'msg->size' bytes. On success,
* returns 0 and stores the type into '*typep'. On failure, returns an
* OFPERR_* error code and zeros '*typep'.
*
* In addition to setting '*typep', this function pulls off the OpenFlow header
* (including the stats headers, vendor header, and any subtype header) with
* ofpbuf_pull(). It also sets 'msg->frame' to the start of the OpenFlow
- * header and 'msg->l3' just beyond the headers (that is, to the final value of
- * ofpbuf_data(msg)). */
+ * header and 'msg->msg' just beyond the headers (that is, to the final value of
+ * msg->data). */
enum ofperr
ofptype_pull(enum ofptype *typep, struct ofpbuf *buf)
{
}
\f
/* Updates the 'length' field of the OpenFlow message in 'buf' to
- * 'ofpbuf_size(buf)'. */
+ * 'buf->size'. */
void
ofpmsg_update_length(struct ofpbuf *buf)
{
struct ofp_header *oh = ofpbuf_at_assert(buf, 0, sizeof *oh);
- oh->length = htons(ofpbuf_size(buf));
+ oh->length = htons(buf->size);
}
/* Returns just past the OpenFlow header (including the stats headers, vendor
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
- if (ofpbuf_size(msg) + len <= UINT16_MAX) {
+ if (msg->size + len <= UINT16_MAX) {
ofpbuf_prealloc_tailroom(msg, len);
return msg;
} else {
struct ofpbuf *next;
struct ofphdrs hdrs;
- ofphdrs_decode_assert(&hdrs, ofpbuf_data(msg), ofpbuf_size(msg));
+ ofphdrs_decode_assert(&hdrs, msg->data, msg->size);
hdrs_len = ofphdrs_len(&hdrs);
next = ofpbuf_new(MAX(1024, hdrs_len + len));
- ofpbuf_put(next, ofpbuf_data(msg), hdrs_len);
- next->frame = ofpbuf_data(next);
- ofpbuf_set_l3(next, ofpbuf_tail(next));
+ ofpbuf_put(next, msg->data, hdrs_len);
+ next->header = next->data;
+ next->msg = ofpbuf_tail(next);
list_push_back(replies, &next->list_node);
- *ofpmp_flags__(ofpbuf_data(msg)) |= htons(OFPSF_REPLY_MORE);
+ *ofpmp_flags__(msg->data) |= htons(OFPSF_REPLY_MORE);
return next;
}
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
ovs_assert(start_ofs <= UINT16_MAX);
- if (ofpbuf_size(msg) > UINT16_MAX) {
- size_t len = ofpbuf_size(msg) - start_ofs;
+ if (msg->size > UINT16_MAX) {
+ size_t len = msg->size - start_ofs;
memcpy(ofpmp_append(replies, len),
- (const uint8_t *) ofpbuf_data(msg) + start_ofs, len);
- ofpbuf_set_size(msg, start_ofs);
+ (const uint8_t *) msg->data + start_ofs, len);
+ msg->size = start_ofs;
}
}
ofpmp_version(struct ovs_list *replies)
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
- const struct ofp_header *oh = ofpbuf_data(msg);
+ const struct ofp_header *oh = msg->data;
return oh->version;
}
enum ofperr error;
enum ofpraw raw;
- error = ofpraw_decode_partial(&raw, ofpbuf_data(msg), ofpbuf_size(msg));
+ error = ofpraw_decode_partial(&raw, msg->data, msg->size);
ovs_assert(!error);
return raw;
}
if (!error) {
enum ofperr err;
- err = ofpacts_check(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &fm->match.flow,
+ err = ofpacts_check(ofpacts.data, ofpacts.size, &fm->match.flow,
OFPP_MAX, fm->table_id, 255, usable_protocols);
if (!err && !usable_protocols) {
err = OFPERR_OFPBAC_MATCH_INCONSISTENT;
return error;
}
- fm->ofpacts_len = ofpbuf_size(&ofpacts);
+ fm->ofpacts_len = ofpacts.size;
fm->ofpacts = ofpbuf_steal_data(&ofpacts);
} else {
fm->ofpacts_len = 0;
ofpbuf_uninit(&ofpacts);
return error;
}
- bucket->ofpacts = ofpbuf_data(&ofpacts);
- bucket->ofpacts_len = ofpbuf_size(&ofpacts);
+ bucket->ofpacts = ofpacts.data;
+ bucket->ofpacts_len = ofpacts.size;
return NULL;
}
ds_put_format(string, " %s\n", ofperr_get_name(error));
if (error == OFPERR_OFPHFC_INCOMPATIBLE || error == OFPERR_OFPHFC_EPERM) {
- ds_put_printable(string, ofpbuf_data(&payload), ofpbuf_size(&payload));
+ ds_put_printable(string, payload.data, payload.size);
} else {
- s = ofp_to_string(ofpbuf_data(&payload), ofpbuf_size(&payload), 1);
+ s = ofp_to_string(payload.data, payload.size, 1);
ds_put_cstr(string, s);
free(s);
}
unsigned int padded_len;
unsigned int len;
- if (ofpbuf_size(msg) < sizeof *oph) {
+ if (msg->size < sizeof *oph) {
return OFPERR_OFPBPC_BAD_LEN;
}
- oph = ofpbuf_data(msg);
+ oph = msg->data;
len = ntohs(oph->len);
padded_len = ROUND_UP(len, alignment);
- if (len < sizeof *oph || padded_len > ofpbuf_size(msg)) {
+ if (len < sizeof *oph || padded_len > msg->size) {
return OFPERR_OFPBPC_BAD_LEN;
}
*typep = ntohs(oph->type);
if (property) {
- ofpbuf_use_const(property, ofpbuf_data(msg), len);
+ ofpbuf_use_const(property, msg->data, len);
}
ofpbuf_pull(msg, padded_len);
return 0;
static size_t
start_property(struct ofpbuf *msg, uint16_t type)
{
- size_t start_ofs = ofpbuf_size(msg);
+ size_t start_ofs = msg->size;
struct ofp_prop_header *oph;
oph = ofpbuf_put_uninit(msg, sizeof *oph);
struct ofp_prop_header *oph;
oph = ofpbuf_at_assert(msg, start_ofs, sizeof *oph);
- oph->len = htons(ofpbuf_size(msg) - start_ofs);
- ofpbuf_padto(msg, ROUND_UP(ofpbuf_size(msg), 8));
+ oph->len = htons(msg->size - start_ofs);
+ ofpbuf_padto(msg, ROUND_UP(msg->size, 8));
}
static void
ofputil_pull_ofp11_match(struct ofpbuf *buf, struct match *match,
uint16_t *padded_match_len)
{
- struct ofp11_match_header *omh = ofpbuf_data(buf);
+ struct ofp11_match_header *omh = buf->data;
uint16_t match_len;
- if (ofpbuf_size(buf) < sizeof *omh) {
+ if (buf->size < sizeof *omh) {
return OFPERR_OFPBMC_BAD_LEN;
}
case OFPMT_STANDARD: {
struct ofp11_match *om;
- if (match_len != sizeof *om || ofpbuf_size(buf) < sizeof *om) {
+ if (match_len != sizeof *om || buf->size < sizeof *om) {
return OFPERR_OFPBMC_BAD_LEN;
}
om = ofpbuf_pull(buf, sizeof *om);
ofpbuf_pull(&msg, sizeof *oh);
*allowed_versions = version_bitmap_from_version(oh->version);
- while (ofpbuf_size(&msg)) {
+ while (msg.size) {
const struct ofp_hello_elem_header *oheh;
unsigned int len;
- if (ofpbuf_size(&msg) < sizeof *oheh) {
+ if (msg.size < sizeof *oheh) {
return false;
}
- oheh = ofpbuf_data(&msg);
+ oheh = msg.data;
len = ntohs(oheh->length);
if (len < sizeof *oheh || !ofpbuf_try_pull(&msg, ROUND_UP(len, 8))) {
return false;
}
}
- error = ofpacts_pull_openflow_instructions(&b, ofpbuf_size(&b),
+ error = ofpacts_pull_openflow_instructions(&b, b.size,
oh->version, ofpacts);
if (error) {
return error;
}
- fm->ofpacts = ofpbuf_data(ofpacts);
- fm->ofpacts_len = ofpbuf_size(ofpacts);
+ fm->ofpacts = ofpacts->data;
+ fm->ofpacts_len = ofpacts->size;
error = ofputil_decode_flow_mod_flags(raw_flags, fm->command,
oh->version, &fm->flags);
mm->meter.flags & OFPMF13_PKTPS) {
return OFPERR_OFPMMFC_BAD_FLAGS;
}
- mm->meter.bands = ofpbuf_data(bands);
+ mm->meter.bands = bands->data;
- error = ofputil_pull_bands(&b, ofpbuf_size(&b), &mm->meter.n_bands, bands);
+ error = ofputil_pull_bands(&b, b.size, &mm->meter.n_bands, bands);
if (error) {
return error;
}
const struct ofputil_meter_config *mc)
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
- size_t start_ofs = ofpbuf_size(msg);
+ size_t start_ofs = msg->size;
struct ofp13_meter_config *reply = ofpbuf_put_uninit(msg, sizeof *reply);
reply->flags = htons(mc->flags);
reply->meter_id = htonl(mc->meter_id);
ofputil_put_bands(mc->n_bands, mc->bands, msg);
- reply->length = htons(ofpbuf_size(msg) - start_ofs);
+ reply->length = htons(msg->size - start_ofs);
ofpmp_postappend(replies, start_ofs);
}
enum ofperr err;
/* Pull OpenFlow headers for the first call. */
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
if (!omc) {
VLOG_WARN_RL(&bad_ofmsg_rl,
"OFPMP_METER_CONFIG reply has %"PRIu32" leftover bytes at end",
- ofpbuf_size(msg));
+ msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
}
mc->meter_id = ntohl(omc->meter_id);
mc->flags = ntohs(omc->flags);
- mc->bands = ofpbuf_data(bands);
+ mc->bands = bands->data;
return 0;
}
enum ofperr err;
/* Pull OpenFlow headers for the first call. */
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
if (!oms) {
VLOG_WARN_RL(&bad_ofmsg_rl,
"OFPMP_METER reply has %"PRIu32" leftover bytes at end",
- ofpbuf_size(msg));
+ msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
ms->byte_in_count = ntohll(oms->byte_in_count);
ms->duration_sec = ntohl(oms->duration_sec);
ms->duration_nsec = ntohl(oms->duration_nsec);
- ms->bands = ofpbuf_data(bands);
+ ms->bands = bands->data;
return 0;
}
nfm->command = ofputil_tid_command(fm, protocol);
nfm->cookie = fm->new_cookie;
match_len = nx_put_match(msg, &fm->match, fm->cookie, fm->cookie_mask);
- nfm = ofpbuf_l3(msg);
+ nfm = msg->msg;
nfm->idle_timeout = htons(fm->idle_timeout);
nfm->hard_timeout = htons(fm->hard_timeout);
nfm->priority = htons(fm->priority);
if (error) {
return error;
}
- if (ofpbuf_size(b)) {
+ if (b->size) {
return OFPERR_OFPBRC_BAD_LEN;
}
switch ((int) raw) {
case OFPRAW_OFPT10_QUEUE_GET_CONFIG_REQUEST:
- qgcr10 = ofpbuf_data(&b);
+ qgcr10 = b.data;
*port = u16_to_ofp(ntohs(qgcr10->port));
return 0;
case OFPRAW_OFPT11_QUEUE_GET_CONFIG_REQUEST:
- qgcr11 = ofpbuf_data(&b);
+ qgcr11 = b.data;
return ofputil_port_from_ofp11(qgcr11->port, port);
}
ofputil_append_queue_get_config_reply(struct ofpbuf *reply,
const struct ofputil_queue_config *oqc)
{
- const struct ofp_header *oh = ofpbuf_data(reply);
+ const struct ofp_header *oh = reply->data;
size_t start_ofs, len_ofs;
ovs_be16 *len;
- start_ofs = ofpbuf_size(reply);
+ start_ofs = reply->size;
if (oh->version < OFP12_VERSION) {
struct ofp10_packet_queue *opq10;
opq10 = ofpbuf_put_zeros(reply, sizeof *opq10);
opq10->queue_id = htonl(oqc->queue_id);
- len_ofs = (char *) &opq10->len - (char *) ofpbuf_data(reply);
+ len_ofs = (char *) &opq10->len - (char *) reply->data;
} else {
struct ofp11_queue_get_config_reply *qgcr11;
struct ofp12_packet_queue *opq12;
ovs_be32 port;
- qgcr11 = ofpbuf_l3(reply);
+ qgcr11 = reply->msg;
port = qgcr11->port;
opq12 = ofpbuf_put_zeros(reply, sizeof *opq12);
opq12->port = port;
opq12->queue_id = htonl(oqc->queue_id);
- len_ofs = (char *) &opq12->len - (char *) ofpbuf_data(reply);
+ len_ofs = (char *) &opq12->len - (char *) reply->data;
}
put_queue_rate(reply, OFPQT_MIN_RATE, oqc->min_rate);
put_queue_rate(reply, OFPQT_MAX_RATE, oqc->max_rate);
len = ofpbuf_at(reply, len_ofs, sizeof *len);
- *len = htons(ofpbuf_size(reply) - start_ofs);
+ *len = htons(reply->size - start_ofs);
}
/* Decodes the initial part of an OFPT_QUEUE_GET_CONFIG_REPLY from 'reply' and
unsigned int opq_len;
unsigned int len;
- if (!ofpbuf_size(reply)) {
+ if (!reply->size) {
return EOF;
}
queue->min_rate = UINT16_MAX;
queue->max_rate = UINT16_MAX;
- oh = reply->frame;
+ oh = reply->header;
if (oh->version < OFP12_VERSION) {
const struct ofp10_packet_queue *opq10;
opq_len = sizeof *opq12;
}
- if (len < opq_len || len > ofpbuf_size(reply) + opq_len || len % 8) {
+ if (len < opq_len || len > reply->size + opq_len || len % 8) {
return OFPERR_OFPBRC_BAD_LEN;
}
len -= opq_len;
hdr = ofpbuf_at_assert(reply, 0, sizeof *hdr);
prop_len = ntohs(hdr->len);
- if (prop_len < sizeof *hdr || prop_len > ofpbuf_size(reply) || prop_len % 8) {
+ if (prop_len < sizeof *hdr || prop_len > reply->size || prop_len % 8) {
return OFPERR_OFPBRC_BAD_LEN;
}
raw = ofpraw_pull_assert(&b);
switch ((int) raw) {
case OFPRAW_OFPST10_FLOW_REQUEST:
- return ofputil_decode_ofpst10_flow_request(fsr, ofpbuf_data(&b), false);
+ return ofputil_decode_ofpst10_flow_request(fsr, b.data, false);
case OFPRAW_OFPST10_AGGREGATE_REQUEST:
- return ofputil_decode_ofpst10_flow_request(fsr, ofpbuf_data(&b), true);
+ return ofputil_decode_ofpst10_flow_request(fsr, b.data, true);
case OFPRAW_OFPST11_FLOW_REQUEST:
return ofputil_decode_ofpst11_flow_request(fsr, &b, false);
match_len = nx_put_match(msg, &fsr->match,
fsr->cookie, fsr->cookie_mask);
- nfsr = ofpbuf_l3(msg);
+ nfsr = msg->msg;
nfsr->out_port = htons(ofp_to_u16(fsr->out_port));
nfsr->match_len = htons(match_len);
nfsr->table_id = fsr->table_id;
enum ofperr error;
enum ofpraw raw;
- error = (msg->frame
- ? ofpraw_decode(&raw, msg->frame)
+ error = (msg->header ? ofpraw_decode(&raw, msg->header)
: ofpraw_pull(&raw, msg));
if (error) {
return error;
}
- oh = msg->frame;
+ oh = msg->header;
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
} else if (raw == OFPRAW_OFPST11_FLOW_REPLY
|| raw == OFPRAW_OFPST13_FLOW_REPLY) {
ofs = ofpbuf_try_pull(msg, sizeof *ofs);
if (!ofs) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %"PRIu32" leftover "
- "bytes at end", ofpbuf_size(msg));
+ "bytes at end", msg->size);
return EINVAL;
}
ofs = ofpbuf_try_pull(msg, sizeof *ofs);
if (!ofs) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply has %"PRIu32" leftover "
- "bytes at end", ofpbuf_size(msg));
+ "bytes at end", msg->size);
return EINVAL;
}
nfs = ofpbuf_try_pull(msg, sizeof *nfs);
if (!nfs) {
VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW reply has %"PRIu32" leftover "
- "bytes at end", ofpbuf_size(msg));
+ "bytes at end", msg->size);
return EINVAL;
}
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply bad instructions");
return EINVAL;
}
- fs->ofpacts = ofpbuf_data(ofpacts);
- fs->ofpacts_len = ofpbuf_size(ofpacts);
+ fs->ofpacts = ofpacts->data;
+ fs->ofpacts_len = ofpacts->size;
return 0;
}
struct ovs_list *replies)
{
struct ofpbuf *reply = ofpbuf_from_list(list_back(replies));
- size_t start_ofs = ofpbuf_size(reply);
+ size_t start_ofs = reply->size;
enum ofp_version version = ofpmp_version(replies);
enum ofpraw raw = ofpmp_decode_raw(replies);
version);
ofs = ofpbuf_at_assert(reply, start_ofs, sizeof *ofs);
- ofs->length = htons(ofpbuf_size(reply) - start_ofs);
+ ofs->length = htons(reply->size - start_ofs);
ofs->table_id = fs->table_id;
ofs->pad = 0;
ofs->duration_sec = htonl(fs->duration_sec);
ofpacts_put_openflow_actions(fs->ofpacts, fs->ofpacts_len, reply,
version);
ofs = ofpbuf_at_assert(reply, start_ofs, sizeof *ofs);
- ofs->length = htons(ofpbuf_size(reply) - start_ofs);
+ ofs->length = htons(reply->size - start_ofs);
ofs->table_id = fs->table_id;
ofs->pad = 0;
ofputil_match_to_ofp10_match(&fs->match, &ofs->match);
ofpacts_put_openflow_actions(fs->ofpacts, fs->ofpacts_len, reply,
version);
nfs = ofpbuf_at_assert(reply, start_ofs, sizeof *nfs);
- nfs->length = htons(ofpbuf_size(reply) - start_ofs);
+ nfs->length = htons(reply->size - start_ofs);
nfs->table_id = fs->table_id;
nfs->pad = 0;
nfs->duration_sec = htonl(fs->duration_sec);
ofpbuf_use_const(&msg, reply, ntohs(reply->length));
ofpraw_pull_assert(&msg);
- asr = ofpbuf_l3(&msg);
+ asr = msg.msg;
stats->packet_count = ntohll(get_32aligned_be64(&asr->packet_count));
stats->byte_count = ntohll(get_32aligned_be64(&asr->byte_count));
stats->flow_count = ntohl(asr->flow_count);
if (error) {
return error;
}
- if (ofpbuf_size(&b)) {
+ if (b.size) {
return OFPERR_OFPBRC_BAD_LEN;
}
ofpbuf_put_zeros(msg, sizeof *nfr);
match_len = nx_put_match(msg, &fr->match, 0, 0);
- nfr = ofpbuf_l3(msg);
+ nfr = msg->msg;
nfr->cookie = fr->cookie;
nfr->priority = htons(fr->priority);
nfr->reason = reason;
ofputil_decode_packet_in_finish(struct ofputil_packet_in *pin,
struct match *match, struct ofpbuf *b)
{
- pin->packet = ofpbuf_data(b);
- pin->packet_len = ofpbuf_size(b);
+ pin->packet = b->data;
+ pin->packet_len = b->size;
pin->fmd.in_port = match->flow.in_port.ofp_port;
pin->fmd.tun_id = match->flow.tunnel.tun_id;
opi = ofpbuf_pull(&b, offsetof(struct ofp10_packet_in, data));
pin->packet = opi->data;
- pin->packet_len = ofpbuf_size(&b);
+ pin->packet_len = b.size;
pin->fmd.in_port = u16_to_ofp(ntohs(opi->in_port));
pin->reason = opi->reason;
opi = ofpbuf_pull(&b, sizeof *opi);
- pin->packet = ofpbuf_data(&b);
- pin->packet_len = ofpbuf_size(&b);
+ pin->packet = b.data;
+ pin->packet_len = b.size;
pin->buffer_id = ntohl(opi->buffer_id);
error = ofputil_port_from_ofp11(opi->in_port, &pin->fmd.in_port);
ofpbuf_put_zeros(packet, 2);
ofpbuf_put(packet, pin->packet, pin->packet_len);
- npi = ofpbuf_l3(packet);
+ npi = packet->msg;
npi->buffer_id = htonl(pin->buffer_id);
npi->total_len = htons(pin->total_len);
npi->reason = pin->reason;
ofpbuf_put_zeros(packet, 2);
ofpbuf_put(packet, pin->packet, pin->packet_len);
- opi = ofpbuf_l3(packet);
+ opi = packet->msg;
opi->pi.buffer_id = htonl(pin->buffer_id);
opi->pi.total_len = htons(pin->total_len);
opi->pi.reason = pin->reason;
return OFPERR_OFPBRC_BAD_PORT;
}
- po->ofpacts = ofpbuf_data(ofpacts);
- po->ofpacts_len = ofpbuf_size(ofpacts);
+ po->ofpacts = ofpacts->data;
+ po->ofpacts_len = ofpacts->size;
if (po->buffer_id == UINT32_MAX) {
- po->packet = ofpbuf_data(&b);
- po->packet_len = ofpbuf_size(&b);
+ po->packet = b.data;
+ po->packet_len = b.size;
} else {
po->packet = NULL;
po->packet_len = 0;
parse_ofp14_port_ethernet_property(const struct ofpbuf *payload,
struct ofputil_phy_port *pp)
{
- struct ofp14_port_desc_prop_ethernet *eth = ofpbuf_data(payload);
+ struct ofp14_port_desc_prop_ethernet *eth = payload->data;
- if (ofpbuf_size(payload) != sizeof *eth) {
+ if (payload->size != sizeof *eth) {
return OFPERR_OFPBPC_BAD_LEN;
}
}
len = ntohs(op->length);
- if (len < sizeof *op || len - sizeof *op > ofpbuf_size(msg)) {
+ if (len < sizeof *op || len - sizeof *op > msg->size) {
return OFPERR_OFPBRC_BAD_LEN;
}
len -= sizeof *op;
pp->config = ntohl(op->config) & OFPPC11_ALL;
pp->state = ntohl(op->state) & OFPPS11_ALL;
- while (ofpbuf_size(&properties) > 0) {
+ while (properties.size > 0) {
struct ofpbuf payload;
enum ofperr error;
uint16_t type;
struct ovs_list *replies)
{
struct ofpbuf *reply = ofpbuf_from_list(list_back(replies));
- size_t start_ofs = ofpbuf_size(reply);
+ size_t start_ofs = reply->size;
ofputil_put_phy_port(ofpmp_version(replies), pp, reply);
ofpmp_postappend(replies, start_ofs);
bool
ofputil_switch_features_has_ports(struct ofpbuf *b)
{
- struct ofp_header *oh = ofpbuf_data(b);
+ struct ofp_header *oh = b->data;
size_t phy_port_size;
if (oh->version >= OFP13_VERSION) {
/* The feature reply has no room for more ports. Probably the list is
* truncated. Drop the ports and tell the caller to retrieve them with
* OFPST_PORT_DESC. */
- ofpbuf_set_size(b, sizeof *oh + sizeof(struct ofp_switch_features));
+ b->size = sizeof *oh + sizeof(struct ofp_switch_features);
ofpmsg_update_length(b);
return false;
}
ofputil_put_switch_features_port(const struct ofputil_phy_port *pp,
struct ofpbuf *b)
{
- const struct ofp_header *oh = ofpbuf_data(b);
+ const struct ofp_header *oh = b->data;
if (oh->version < OFP13_VERSION) {
/* Try adding a port description to the message, but drop it again if
* the buffer overflows. (This possibility for overflow is why
* OpenFlow 1.3+ moved port descriptions into a multipart message.) */
- size_t start_ofs = ofpbuf_size(b);
+ size_t start_ofs = b->size;
ofputil_put_phy_port(oh->version, pp, b);
- if (ofpbuf_size(b) > UINT16_MAX) {
- ofpbuf_set_size(b, start_ofs);
+ if (b->size > UINT16_MAX) {
+ b->size = start_ofs;
}
}
}
parse_port_mod_ethernet_property(struct ofpbuf *property,
struct ofputil_port_mod *pm)
{
- struct ofp14_port_mod_prop_ethernet *eth = ofpbuf_data(property);
+ struct ofp14_port_mod_prop_ethernet *eth = property->data;
- if (ofpbuf_size(property) != sizeof *eth) {
+ if (property->size != sizeof *eth) {
return OFPERR_OFPBRC_BAD_LEN;
}
raw = ofpraw_pull_assert(&b);
if (raw == OFPRAW_OFPT10_PORT_MOD) {
- const struct ofp10_port_mod *opm = ofpbuf_data(&b);
+ const struct ofp10_port_mod *opm = b.data;
pm->port_no = u16_to_ofp(ntohs(opm->port_no));
memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
pm->mask = ntohl(opm->mask) & OFPPC10_ALL;
pm->advertise = netdev_port_features_from_ofp10(opm->advertise);
} else if (raw == OFPRAW_OFPT11_PORT_MOD) {
- const struct ofp11_port_mod *opm = ofpbuf_data(&b);
+ const struct ofp11_port_mod *opm = b.data;
enum ofperr error;
error = ofputil_port_from_ofp11(opm->port_no, &pm->port_no);
pm->config = ntohl(opm->config) & OFPPC11_ALL;
pm->mask = ntohl(opm->mask) & OFPPC11_ALL;
- while (ofpbuf_size(&b) > 0) {
+ while (b.size > 0) {
struct ofpbuf property;
enum ofperr error;
uint16_t type;
{
uint32_t types = 0;
- while (ofpbuf_size(payload) > 0) {
+ while (payload->size > 0) {
uint16_t type;
enum ofperr error;
parse_instruction_ids(struct ofpbuf *payload, bool loose, uint32_t *insts)
{
*insts = 0;
- while (ofpbuf_size(payload) > 0) {
+ while (payload->size > 0) {
enum ovs_instruction_type inst;
enum ofperr error;
uint16_t ofpit;
size_t i;
memset(next_tables, 0, bitmap_n_bytes(255));
- for (i = 0; i < ofpbuf_size(payload); i++) {
- uint8_t id = ((const uint8_t *) ofpbuf_data(payload))[i];
+ for (i = 0; i < payload->size; i++) {
+ uint8_t id = ((const uint8_t *) payload->data)[i];
if (id >= 255) {
return OFPERR_OFPBPC_BAD_VALUE;
}
struct mf_bitmap exact = MF_BITMAP_INITIALIZER;
struct mf_bitmap masked = MF_BITMAP_INITIALIZER;
- while (ofpbuf_size(payload) > 0) {
+ while (payload->size > 0) {
const struct mf_field *field;
enum ofperr error;
bool hasmask;
memset(tf, 0, sizeof *tf);
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- oh = ofpbuf_l2(msg);
+ oh = msg->header;
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
- if (ofpbuf_size(msg) < sizeof *otf) {
+ if (msg->size < sizeof *otf) {
return OFPERR_OFPBPC_BAD_LEN;
}
- otf = ofpbuf_data(msg);
+ otf = msg->data;
len = ntohs(otf->length);
- if (len < sizeof *otf || len % 8 || len > ofpbuf_size(msg)) {
+ if (len < sizeof *otf || len % 8 || len > msg->size) {
return OFPERR_OFPBPC_BAD_LEN;
}
ofpbuf_use_const(&properties, ofpbuf_pull(msg, len), len);
tf->miss_config = ofputil_table_miss_from_config(otf->config, oh->version);
tf->max_entries = ntohl(otf->max_entries);
- while (ofpbuf_size(&properties) > 0) {
+ while (properties.size > 0) {
struct ofpbuf payload;
enum ofperr error;
uint16_t type;
{
struct ofpbuf *reply = ofpbuf_from_list(list_back(replies));
enum ofp_version version = ofpmp_version(replies);
- size_t start_ofs = ofpbuf_size(reply);
+ size_t start_ofs = reply->size;
struct ofp13_table_features *otf;
otf = ofpbuf_put_zeros(reply, sizeof *otf);
OFPTFPT13_WILDCARDS, version);
otf = ofpbuf_at_assert(reply, start_ofs, sizeof *otf);
- otf->length = htons(ofpbuf_size(reply) - start_ofs);
+ otf->length = htons(reply->size - start_ofs);
ofpmp_postappend(replies, start_ofs);
}
raw = ofpraw_pull_assert(&b);
if (raw == OFPRAW_OFPT11_TABLE_MOD) {
- const struct ofp11_table_mod *otm = ofpbuf_data(&b);
+ const struct ofp11_table_mod *otm = b.data;
pm->table_id = otm->table_id;
pm->miss_config = ofputil_table_miss_from_config(otm->config,
if (raw == OFPRAW_OFPT12_ROLE_REQUEST ||
raw == OFPRAW_OFPT12_ROLE_REPLY) {
- const struct ofp12_role_request *orr = ofpbuf_l3(&b);
+ const struct ofp12_role_request *orr = b.msg;
if (orr->role != htonl(OFPCR12_ROLE_NOCHANGE) &&
orr->role != htonl(OFPCR12_ROLE_EQUAL) &&
}
} else if (raw == OFPRAW_NXT_ROLE_REQUEST ||
raw == OFPRAW_NXT_ROLE_REPLY) {
- const struct nx_role_request *nrr = ofpbuf_l3(&b);
+ const struct nx_role_request *nrr = b.msg;
BUILD_ASSERT(NX_ROLE_OTHER + 1 == OFPCR12_ROLE_EQUAL);
BUILD_ASSERT(NX_ROLE_MASTER + 1 == OFPCR12_ROLE_MASTER);
raw = ofpraw_pull_assert(&b);
ovs_assert(raw == OFPRAW_OFPT14_ROLE_STATUS);
- r = ofpbuf_l3(&b);
+ r = b.msg;
if (r->role != htonl(OFPCR12_ROLE_NOCHANGE) &&
r->role != htonl(OFPCR12_ROLE_EQUAL) &&
r->role != htonl(OFPCR12_ROLE_MASTER) &&
const struct ofputil_table_stats *stats,
const struct ofputil_table_features *features)
{
- struct ofp_header *oh = ofpbuf_l2(reply);
+ struct ofp_header *oh = reply->header;
ovs_assert(stats->table_id == features->table_id);
{
const struct ofp_header *oh;
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- oh = msg->frame;
+ oh = msg->header;
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
struct nx_flow_monitor_request *nfmr;
uint16_t flags;
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
nfmr = ofpbuf_try_pull(msg, sizeof *nfmr);
if (!nfmr) {
VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR request has %"PRIu32" "
- "leftover bytes at end", ofpbuf_size(msg));
+ "leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
size_t start_ofs;
int match_len;
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
ofpraw_put(OFPRAW_NXST_FLOW_MONITOR_REQUEST, OFP10_VERSION, msg);
}
- start_ofs = ofpbuf_size(msg);
+ start_ofs = msg->size;
ofpbuf_put_zeros(msg, sizeof *nfmr);
match_len = nx_put_match(msg, &rq->match, htonll(0), htonll(0));
unsigned int length;
struct ofp_header *oh;
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
- if (ofpbuf_size(msg) < sizeof(struct nx_flow_update_header)) {
+ if (msg->size < sizeof(struct nx_flow_update_header)) {
goto bad_len;
}
- oh = msg->frame;
+ oh = msg->header;
- nfuh = ofpbuf_data(msg);
+ nfuh = msg->data;
update->event = ntohs(nfuh->event);
length = ntohs(nfuh->length);
- if (length > ofpbuf_size(msg) || length % 8) {
+ if (length > msg->size || length % 8) {
goto bad_len;
}
return error;
}
- update->ofpacts = ofpbuf_data(ofpacts);
- update->ofpacts_len = ofpbuf_size(ofpacts);
+ update->ofpacts = ofpacts->data;
+ update->ofpacts_len = ofpacts->size;
return 0;
} else {
VLOG_WARN_RL(&bad_ofmsg_rl,
bad_len:
VLOG_WARN_RL(&bad_ofmsg_rl, "NXST_FLOW_MONITOR reply has %"PRIu32" "
- "leftover bytes at end", ofpbuf_size(msg));
+ "leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
size_t start_ofs;
msg = ofpbuf_from_list(list_back(replies));
- start_ofs = ofpbuf_size(msg);
+ start_ofs = msg->size;
if (update->event == NXFME_ABBREV) {
struct nx_flow_update_abbrev *nfua;
}
nfuh = ofpbuf_at_assert(msg, start_ofs, sizeof *nfuh);
- nfuh->length = htons(ofpbuf_size(msg) - start_ofs);
+ nfuh->length = htons(msg->size - start_ofs);
nfuh->event = htons(update->event);
ofpmp_postappend(replies, start_ofs);
msg = ofpraw_alloc(OFPRAW_OFPT10_PACKET_OUT, OFP10_VERSION, size);
ofpbuf_put_zeros(msg, sizeof *opo);
- actions_ofs = ofpbuf_size(msg);
+ actions_ofs = msg->size;
ofpacts_put_openflow_actions(po->ofpacts, po->ofpacts_len, msg,
ofp_version);
- opo = ofpbuf_l3(msg);
+ opo = msg->msg;
opo->buffer_id = htonl(po->buffer_id);
opo->in_port = htons(ofp_to_u16(po->in_port));
- opo->actions_len = htons(ofpbuf_size(msg) - actions_ofs);
+ opo->actions_len = htons(msg->size - actions_ofs);
break;
}
ofpbuf_put_zeros(msg, sizeof *opo);
len = ofpacts_put_openflow_actions(po->ofpacts, po->ofpacts_len, msg,
ofp_version);
- opo = ofpbuf_l3(msg);
+ opo = msg->msg;
opo->buffer_id = htonl(po->buffer_id);
opo->in_port = ofputil_port_to_ofp11(po->in_port);
opo->actions_len = htons(len);
ofpbuf_use_const(&rq_buf, rq, ntohs(rq->length));
ofpraw_pull_assert(&rq_buf);
- reply = ofpraw_alloc_reply(OFPRAW_OFPT_ECHO_REPLY, rq, ofpbuf_size(&rq_buf));
- ofpbuf_put(reply, ofpbuf_data(&rq_buf), ofpbuf_size(&rq_buf));
+ reply = ofpraw_alloc_reply(OFPRAW_OFPT_ECHO_REPLY, rq, rq_buf.size);
+ ofpbuf_put(reply, rq_buf.data, rq_buf.size);
return reply;
}
}
case OFP14_VERSION:
case OFP15_VERSION:
- return ofpbuf_size(b) ? ofputil_pull_ofp14_port(pp, b) : EOF;
+ return b->size ? ofputil_pull_ofp14_port(pp, b) : EOF;
default:
OVS_NOT_REACHED();
}
parse_ofp14_port_stats_ethernet_property(const struct ofpbuf *payload,
struct ofputil_port_stats *ops)
{
- const struct ofp14_port_stats_prop_ethernet *eth = ofpbuf_data(payload);
+ const struct ofp14_port_stats_prop_ethernet *eth = payload->data;
- if (ofpbuf_size(payload) != sizeof *eth) {
+ if (payload->size != sizeof *eth) {
return OFPERR_OFPBPC_BAD_LEN;
}
}
len = ntohs(ps14->length);
- if (len < sizeof *ps14 || len - sizeof *ps14 > ofpbuf_size(msg)) {
+ if (len < sizeof *ps14 || len - sizeof *ps14 > msg->size) {
return OFPERR_OFPBRC_BAD_LEN;
}
len -= sizeof *ps14;
ops->stats.rx_crc_errors = UINT64_MAX;
ops->stats.collisions = UINT64_MAX;
- while (ofpbuf_size(&properties) > 0) {
+ while (properties.size > 0) {
struct ofpbuf payload;
enum ofperr error;
uint16_t type;
enum ofperr error;
enum ofpraw raw;
- error = (msg->frame
- ? ofpraw_decode(&raw, msg->frame)
+ error = (msg->header ? ofpraw_decode(&raw, msg->header)
: ofpraw_pull(&raw, msg));
if (error) {
return error;
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
} else if (raw == OFPRAW_OFPST14_PORT_REPLY) {
return ofputil_pull_ofp14_port_stats(ps, msg);
bad_len:
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_PORT reply has %"PRIu32" leftover "
- "bytes at end", ofpbuf_size(msg));
+ "bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
size_t i;
gs->bucket_stats = NULL;
- error = (msg->frame
- ? ofpraw_decode(&raw, msg->frame)
+ error = (msg->header ? ofpraw_decode(&raw, msg->header)
: ofpraw_pull(&raw, msg));
if (error) {
return error;
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
if (!ogs11) {
VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %"PRIu32" leftover bytes at end",
- ofpraw_get_name(raw), ofpbuf_size(msg));
+ ofpraw_get_name(raw), msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
length = ntohs(ogs11->length);
obc = ofpbuf_try_pull(msg, gs->n_buckets * sizeof *obc);
if (!obc) {
VLOG_WARN_RL(&bad_ofmsg_rl, "%s reply has %"PRIu32" leftover bytes at end",
- ofpraw_get_name(raw), ofpbuf_size(msg));
+ ofpraw_get_name(raw), msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
struct ofp11_bucket *ob;
size_t start;
- start = ofpbuf_size(openflow);
+ start = openflow->size;
ofpbuf_put_zeros(openflow, sizeof *ob);
ofpacts_put_openflow_actions(bucket->ofpacts, bucket->ofpacts_len,
openflow, ofp_version);
ob = ofpbuf_at_assert(openflow, start, sizeof *ob);
- ob->len = htons(ofpbuf_size(openflow) - start);
+ ob->len = htons(openflow->size - start);
ob->weight = htons(bucket->weight);
ob->watch_port = ofputil_port_to_ofp11(bucket->watch_port);
ob->watch_group = htonl(bucket->watch_group);
struct ofp15_bucket *ob;
size_t start, actions_start, actions_len;
- start = ofpbuf_size(openflow);
+ start = openflow->size;
ofpbuf_put_zeros(openflow, sizeof *ob);
- actions_start = ofpbuf_size(openflow);
+ actions_start = openflow->size;
ofpacts_put_openflow_actions(bucket->ofpacts, bucket->ofpacts_len,
openflow, ofp_version);
- actions_len = ofpbuf_size(openflow) - actions_start;
+ actions_len = openflow->size - actions_start;
if (group_type == OFPGT11_SELECT) {
ofputil_put_ofp15_group_bucket_prop_weight(htons(bucket->weight),
}
ob = ofpbuf_at_assert(openflow, start, sizeof *ob);
- ob->len = htons(ofpbuf_size(openflow) - start);
+ ob->len = htons(openflow->size - start);
ob->action_array_len = htons(actions_len);
ob->bucket_id = htonl(bucket_id);
}
struct ofputil_bucket *bucket;
size_t start_ogds;
- start_ogds = ofpbuf_size(reply);
+ start_ogds = reply->size;
ofpbuf_put_zeros(reply, sizeof *ogds);
LIST_FOR_EACH (bucket, list_node, buckets) {
ofputil_put_ofp11_bucket(bucket, reply, version);
}
ogds = ofpbuf_at_assert(reply, start_ogds, sizeof *ogds);
- ogds->length = htons(ofpbuf_size(reply) - start_ogds);
+ ogds->length = htons(reply->size - start_ogds);
ogds->type = gds->type;
ogds->group_id = htonl(gds->group_id);
struct ofputil_bucket *bucket;
size_t start_ogds, start_buckets;
- start_ogds = ofpbuf_size(reply);
+ start_ogds = reply->size;
ofpbuf_put_zeros(reply, sizeof *ogds);
- start_buckets = ofpbuf_size(reply);
+ start_buckets = reply->size;
LIST_FOR_EACH (bucket, list_node, buckets) {
ofputil_put_ofp15_bucket(bucket, bucket->bucket_id,
gds->type, reply, version);
}
ogds = ofpbuf_at_assert(reply, start_ogds, sizeof *ogds);
- ogds->length = htons(ofpbuf_size(reply) - start_ogds);
+ ogds->length = htons(reply->size - start_ogds);
ogds->type = gds->type;
ogds->group_id = htonl(gds->group_id);
- ogds->bucket_list_len = htons(ofpbuf_size(reply) - start_buckets);
+ ogds->bucket_list_len = htons(reply->size - start_buckets);
ofpmp_postappend(replies, start_ogds);
}
bucket->bucket_id = bucket_id++;
bucket->ofpacts = ofpbuf_steal_data(&ofpacts);
- bucket->ofpacts_len = ofpbuf_size(&ofpacts);
+ bucket->ofpacts_len = ofpacts.size;
list_push_back(buckets, &bucket->list_node);
}
parse_ofp15_group_bucket_prop_weight(const struct ofpbuf *payload,
ovs_be16 *weight)
{
- struct ofp15_group_bucket_prop_weight *prop = ofpbuf_data(payload);
+ struct ofp15_group_bucket_prop_weight *prop = payload->data;
- if (ofpbuf_size(payload) != sizeof *prop) {
+ if (payload->size != sizeof *prop) {
log_property(false, "OpenFlow bucket weight property length "
- "%u is not valid", ofpbuf_size(payload));
+ "%u is not valid", payload->size);
return OFPERR_OFPBPC_BAD_LEN;
}
parse_ofp15_group_bucket_prop_watch(const struct ofpbuf *payload,
ovs_be32 *watch)
{
- struct ofp15_group_bucket_prop_watch *prop = ofpbuf_data(payload);
+ struct ofp15_group_bucket_prop_watch *prop = payload->data;
- if (ofpbuf_size(payload) != sizeof *prop) {
+ if (payload->size != sizeof *prop) {
log_property(false, "OpenFlow bucket watch port or group "
- "property length %u is not valid", ofpbuf_size(payload));
+ "property length %u is not valid", payload->size);
return OFPERR_OFPBPC_BAD_LEN;
}
ofpbuf_use_const(&properties, ofpbuf_pull(msg, properties_len),
properties_len);
- while (ofpbuf_size(&properties) > 0) {
+ while (properties.size > 0) {
struct ofpbuf payload;
uint16_t type;
}
bucket->ofpacts = ofpbuf_steal_data(&ofpacts);
- bucket->ofpacts_len = ofpbuf_size(&ofpacts);
+ bucket->ofpacts_len = ofpacts.size;
list_push_back(buckets, &bucket->list_node);
continue;
struct ofp11_group_desc_stats *ogds;
size_t length;
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
ogds = ofpbuf_try_pull(msg, sizeof *ogds);
if (!ogds) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply has %"PRIu32" "
- "leftover bytes at end", ofpbuf_size(msg));
+ "leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
gd->type = ogds->type;
gd->group_id = ntohl(ogds->group_id);
length = ntohs(ogds->length);
- if (length < sizeof *ogds || length - sizeof *ogds > ofpbuf_size(msg)) {
+ if (length < sizeof *ogds || length - sizeof *ogds > msg->size) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply claims invalid "
"length %"PRIuSIZE, length);
return OFPERR_OFPBRC_BAD_LEN;
struct ofp15_group_desc_stats *ogds;
uint16_t length, bucket_list_len;
- if (!msg->frame) {
+ if (!msg->header) {
ofpraw_pull_assert(msg);
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
}
ogds = ofpbuf_try_pull(msg, sizeof *ogds);
if (!ogds) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply has %"PRIu32" "
- "leftover bytes at end", ofpbuf_size(msg));
+ "leftover bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
gd->type = ogds->type;
gd->group_id = ntohl(ogds->group_id);
length = ntohs(ogds->length);
- if (length < sizeof *ogds || length - sizeof *ogds > ofpbuf_size(msg)) {
+ if (length < sizeof *ogds || length - sizeof *ogds > msg->size) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST11_GROUP_DESC reply claims invalid "
"length %u", length);
return OFPERR_OFPBRC_BAD_LEN;
struct ofputil_bucket *bucket;
b = ofpraw_alloc(OFPRAW_OFPT11_GROUP_MOD, ofp_version, 0);
- start_ogm = ofpbuf_size(b);
+ start_ogm = b->size;
ofpbuf_put_zeros(b, sizeof *ogm);
LIST_FOR_EACH (bucket, list_node, &gm->buckets) {
struct id_pool *bucket_ids = NULL;
b = ofpraw_alloc(OFPRAW_OFPT15_GROUP_MOD, ofp_version, 0);
- start_ogm = ofpbuf_size(b);
+ start_ogm = b->size;
ofpbuf_put_zeros(b, sizeof *ogm);
LIST_FOR_EACH (bucket, list_node, &gm->buckets) {
ogm->type = gm->type;
ogm->group_id = htonl(gm->group_id);
ogm->command_bucket_id = htonl(gm->command_bucket_id);
- ogm->bucket_array_len = htons(ofpbuf_size(b) - start_ogm - sizeof *ogm);
+ ogm->bucket_array_len = htons(b->size - start_ogm - sizeof *ogm);
id_pool_destroy(bucket_ids);
return b;
gm->group_id = ntohl(ogm->group_id);
gm->command_bucket_id = OFPG15_BUCKET_ALL;
- error = ofputil_pull_ofp11_buckets(msg, ofpbuf_size(msg), ofp_version,
+ error = ofputil_pull_ofp11_buckets(msg, msg->size, ofp_version,
&gm->buckets);
/* OF1.3.5+ prescribes an error when an OFPGC_DELETE includes buckets. */
}
bucket_list_len = ntohs(ogm->bucket_array_len);
- if (bucket_list_len < ofpbuf_size(msg)) {
+ if (bucket_list_len < msg->size) {
VLOG_WARN_RL(&bad_ofmsg_rl, "group has %u trailing bytes",
- ofpbuf_size(msg) - bucket_list_len);
+ msg->size - bucket_list_len);
return OFPERR_OFPGMFC_BAD_BUCKET;
}
}
len = ntohs(qs14->length);
- if (len < sizeof *qs14 || len - sizeof *qs14 > ofpbuf_size(msg)) {
+ if (len < sizeof *qs14 || len - sizeof *qs14 > msg->size) {
return OFPERR_OFPBRC_BAD_LEN;
}
ofpbuf_pull(msg, len - sizeof *qs14);
enum ofperr error;
enum ofpraw raw;
- error = (msg->frame
- ? ofpraw_decode(&raw, msg->frame)
+ error = (msg->header ? ofpraw_decode(&raw, msg->header)
: ofpraw_pull(&raw, msg));
if (error) {
return error;
}
- if (!ofpbuf_size(msg)) {
+ if (!msg->size) {
return EOF;
} else if (raw == OFPRAW_OFPST14_QUEUE_REPLY) {
return ofputil_pull_ofp14_queue_stats(qs, msg);
bad_len:
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_QUEUE reply has %"PRIu32" leftover "
- "bytes at end", ofpbuf_size(msg));
+ "bytes at end", msg->size);
return OFPERR_OFPBRC_BAD_LEN;
}
raw = ofpraw_pull_assert(&b);
ovs_assert(raw == OFPRAW_OFPT14_BUNDLE_CONTROL);
- m = ofpbuf_l3(&b);
+ m = b.msg;
msg->bundle_id = ntohl(m->bundle_id);
msg->type = ntohs(m->type);
msg->flags = ntohs(m->flags);
msg->bundle_id = ntohl(m->bundle_id);
msg->flags = ntohs(m->flags);
- msg->msg = ofpbuf_data(&b);
+ msg->msg = b.data;
inner_len = ntohs(msg->msg->length);
- if (inner_len < sizeof(struct ofp_header) || inner_len > ofpbuf_size(&b)) {
+ if (inner_len < sizeof(struct ofp_header) || inner_len > b.size) {
return OFPERR_OFPBFC_MSG_BAD_LEN;
}
if (msg->msg->xid != oh->xid) {
{
b->allocated = allocated;
b->source = source;
- b->frame = NULL;
- b->l2_pad_size = 0;
- b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
+ b->header = NULL;
+ b->msg = NULL;
list_poison(&b->list_node);
}
ofpbuf_use__(struct ofpbuf *b, void *base, size_t allocated,
enum ofpbuf_source source)
{
- ofpbuf_set_base(b, base);
- ofpbuf_set_data(b, base);
- ofpbuf_set_size(b, 0);
+ b->base = base;
+ b->data = base;
+ b->size = 0;
ofpbuf_init__(b, allocated, source);
}
ofpbuf_use_const(struct ofpbuf *b, const void *data, size_t size)
{
ofpbuf_use__(b, CONST_CAST(void *, data), size, OFPBUF_STACK);
- ofpbuf_set_size(b, size);
-}
-
-/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
- * memory starting at 'base'. DPDK allocated ofpbuf and *data is allocated
- * from one continous memory region, so in memory data start right after
- * ofpbuf. Therefore there is special method to free this type of
- * buffer. ofpbuf base, data and size are initialized by dpdk rcv() so no
- * need to initialize those fields. */
-void
-ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated)
-{
- ofpbuf_init__(b, allocated, OFPBUF_DPDK);
+ b->size = size;
}
/* Initializes 'b' as an empty ofpbuf with an initial capacity of 'size'
{
if (b) {
if (b->source == OFPBUF_MALLOC) {
- free(ofpbuf_base(b));
- } else if (b->source == OFPBUF_DPDK) {
-#ifdef DPDK_NETDEV
- /* If this ofpbuf was allocated by DPDK it must have been
- * created as a dp_packet */
- free_dpdk_buf((struct dp_packet*) b);
-#else
- ovs_assert(b->source != OFPBUF_DPDK);
-#endif
+ free(b->base);
}
}
}
}
/* Creates and returns a new ofpbuf that initially contains a copy of the
- * 'ofpbuf_size(buffer)' bytes of data starting at 'buffer->data' with no headroom or
+ * 'buffer->size' bytes of data starting at 'buffer->data' with no headroom or
* tailroom. */
struct ofpbuf *
ofpbuf_clone(const struct ofpbuf *buffer)
{
struct ofpbuf *new_buffer;
- new_buffer = ofpbuf_clone_data_with_headroom(ofpbuf_data(buffer),
- ofpbuf_size(buffer),
+ new_buffer = ofpbuf_clone_data_with_headroom(buffer->data,
+ buffer->size,
headroom);
- if (buffer->frame) {
+ if (buffer->header) {
uintptr_t data_delta
- = (char *)ofpbuf_data(new_buffer) - (char *)ofpbuf_data(buffer);
+ = (char *)new_buffer->data - (char *)buffer->data;
- new_buffer->frame = (char *) buffer->frame + data_delta;
+ new_buffer->header = (char *) buffer->header + data_delta;
}
- new_buffer->l2_pad_size = buffer->l2_pad_size;
- new_buffer->l2_5_ofs = buffer->l2_5_ofs;
- new_buffer->l3_ofs = buffer->l3_ofs;
- new_buffer->l4_ofs = buffer->l4_ofs;
+ new_buffer->msg = buffer->msg;
return new_buffer;
}
ofpbuf_copy__(struct ofpbuf *b, uint8_t *new_base,
size_t new_headroom, size_t new_tailroom)
{
- const uint8_t *old_base = ofpbuf_base(b);
+ const uint8_t *old_base = b->base;
size_t old_headroom = ofpbuf_headroom(b);
size_t old_tailroom = ofpbuf_tailroom(b);
size_t copy_headroom = MIN(old_headroom, new_headroom);
memcpy(&new_base[new_headroom - copy_headroom],
&old_base[old_headroom - copy_headroom],
- copy_headroom + ofpbuf_size(b) + copy_tailroom);
+ copy_headroom + b->size + copy_tailroom);
}
/* Reallocates 'b' so that it has exactly 'new_headroom' and 'new_tailroom'
void *new_base, *new_data;
size_t new_allocated;
- new_allocated = new_headroom + ofpbuf_size(b) + new_tailroom;
+ new_allocated = new_headroom + b->size + new_tailroom;
switch (b->source) {
- case OFPBUF_DPDK:
- OVS_NOT_REACHED();
-
case OFPBUF_MALLOC:
if (new_headroom == ofpbuf_headroom(b)) {
- new_base = xrealloc(ofpbuf_base(b), new_allocated);
+ new_base = xrealloc(b->base, new_allocated);
} else {
new_base = xmalloc(new_allocated);
ofpbuf_copy__(b, new_base, new_headroom, new_tailroom);
- free(ofpbuf_base(b));
+ free(b->base);
}
break;
}
b->allocated = new_allocated;
- ofpbuf_set_base(b, new_base);
+ b->base = new_base;
new_data = (char *) new_base + new_headroom;
- if (ofpbuf_data(b) != new_data) {
- if (b->frame) {
- uintptr_t data_delta = (char *) new_data - (char *) ofpbuf_data(b);
+ if (b->data != new_data) {
+ if (b->header) {
+ uintptr_t data_delta = (char *) new_data - (char *) b->data;
- b->frame = (char *) b->frame + data_delta;
+ b->header = (char *) b->header + data_delta;
}
- ofpbuf_set_data(b, new_data);
+ b->data = new_data;
}
}
void
ofpbuf_trim(struct ofpbuf *b)
{
- ovs_assert(b->source != OFPBUF_DPDK);
-
if (b->source == OFPBUF_MALLOC
&& (ofpbuf_headroom(b) || ofpbuf_tailroom(b))) {
ofpbuf_resize__(b, 0, 0);
void
ofpbuf_padto(struct ofpbuf *b, size_t length)
{
- if (ofpbuf_size(b) < length) {
- ofpbuf_put_zeros(b, length - ofpbuf_size(b));
+ if (b->size < length) {
+ ofpbuf_put_zeros(b, length - b->size);
}
}
: true);
if (delta != 0) {
- char *dst = (char *) ofpbuf_data(b) + delta;
- memmove(dst, ofpbuf_data(b), ofpbuf_size(b));
- ofpbuf_set_data(b, dst);
+ char *dst = (char *) b->data + delta;
+ memmove(dst, b->data, b->size);
+ b->data = dst;
}
}
void *p;
ofpbuf_prealloc_tailroom(b, size);
p = ofpbuf_tail(b);
- ofpbuf_set_size(b, ofpbuf_size(b) + size);
+ b->size += size;
return p;
}
char *
ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n)
{
- size_t initial_size = ofpbuf_size(b);
+ size_t initial_size = b->size;
for (;;) {
uint8_t byte;
bool ok;
byte = hexits_value(s, 2, &ok);
if (!ok) {
if (n) {
- *n = ofpbuf_size(b) - initial_size;
+ *n = b->size - initial_size;
}
return CONST_CAST(char *, s);
}
void
ofpbuf_reserve(struct ofpbuf *b, size_t size)
{
- ovs_assert(!ofpbuf_size(b));
+ ovs_assert(!b->size);
ofpbuf_prealloc_tailroom(b, size);
- ofpbuf_set_data(b, (char*)ofpbuf_data(b) + size);
-}
-
-/* Reserves 'headroom' bytes at the head and 'tailroom' at the end so that
- * they can be later allocated with ofpbuf_push_uninit() or
- * ofpbuf_put_uninit() without reallocating the ofpbuf. */
-void
-ofpbuf_reserve_with_tailroom(struct ofpbuf *b, size_t headroom,
- size_t tailroom)
-{
- ovs_assert(!ofpbuf_size(b));
- ofpbuf_prealloc_tailroom(b, headroom + tailroom);
- ofpbuf_set_data(b, (char*)ofpbuf_data(b) + headroom);
+ b->data = (char*)b->data + size;
}
/* Prefixes 'size' bytes to the head end of 'b', reallocating and copying its
ofpbuf_push_uninit(struct ofpbuf *b, size_t size)
{
ofpbuf_prealloc_headroom(b, size);
- ofpbuf_set_data(b, (char*)ofpbuf_data(b) - size);
- ofpbuf_set_size(b, ofpbuf_size(b) + size);
- return ofpbuf_data(b);
+ b->data = (char*)b->data - size;
+ b->size += size;
+ return b->data;
}
/* Prefixes 'size' zeroed bytes to the head end of 'b', reallocating and
ofpbuf_steal_data(struct ofpbuf *b)
{
void *p;
- ovs_assert(b->source != OFPBUF_DPDK);
- if (b->source == OFPBUF_MALLOC && ofpbuf_data(b) == ofpbuf_base(b)) {
- p = ofpbuf_data(b);
+ if (b->source == OFPBUF_MALLOC && b->data == b->base) {
+ p = b->data;
} else {
- p = xmemdup(ofpbuf_data(b), ofpbuf_size(b));
+ p = xmemdup(b->data, b->size);
if (b->source == OFPBUF_MALLOC) {
- free(ofpbuf_base(b));
+ free(b->base);
}
}
- ofpbuf_set_base(b, NULL);
- ofpbuf_set_data(b, NULL);
+ b->base = NULL;
+ b->data = NULL;
return p;
}
ds_init(&s);
ds_put_format(&s, "size=%"PRIu32", allocated=%"PRIu32", head=%"PRIuSIZE", tail=%"PRIuSIZE"\n",
- ofpbuf_size(b), b->allocated,
+ b->size, b->allocated,
ofpbuf_headroom(b), ofpbuf_tailroom(b));
- ds_put_hex_dump(&s, ofpbuf_data(b), MIN(ofpbuf_size(b), maxbytes), 0, false);
+ ds_put_hex_dump(&s, b->data, MIN(b->size, maxbytes), 0, false);
return ds_cstr(&s);
}
ofpbuf_delete(b);
}
}
-
-static inline void
-ofpbuf_adjust_layer_offset(uint16_t *offset, int increment)
-{
- if (*offset != UINT16_MAX) {
- *offset += increment;
- }
-}
-
-/* Adjust the size of the l2_5 portion of the ofpbuf, updating the l2
- * pointer and the layer offsets. The caller is responsible for
- * modifying the contents. */
-void *
-ofpbuf_resize_l2_5(struct ofpbuf *b, int increment)
-{
- if (increment >= 0) {
- ofpbuf_push_uninit(b, increment);
- } else {
- ofpbuf_pull(b, -increment);
- }
-
- b->frame = ofpbuf_data(b);
- /* Adjust layer offsets after l2_5. */
- ofpbuf_adjust_layer_offset(&b->l3_ofs, increment);
- ofpbuf_adjust_layer_offset(&b->l4_ofs, increment);
-
- return b->frame;
-}
-
-/* Adjust the size of the l2 portion of the ofpbuf, updating the l2
- * pointer and the layer offsets. The caller is responsible for
- * modifying the contents. */
-void *
-ofpbuf_resize_l2(struct ofpbuf *b, int increment)
-{
- ofpbuf_resize_l2_5(b, increment);
- ofpbuf_adjust_layer_offset(&b->l2_5_ofs, increment);
- return b->frame;
-}
#include "list.h"
#include "packets.h"
#include "util.h"
-#include "netdev-dpdk.h"
#ifdef __cplusplus
extern "C" {
OFPBUF_MALLOC, /* Obtained via malloc(). */
OFPBUF_STACK, /* Un-movable stack space or static buffer. */
OFPBUF_STUB, /* Starts on stack, may expand into heap. */
- OFPBUF_DPDK, /* buffer data is from DPDK allocated memory.
- ref to build_ofpbuf() in netdev-dpdk. */
};
/* Buffer for holding arbitrary data. An ofpbuf is automatically reallocated
* as necessary if it grows too large for the available memory.
*
- * 'frame' and offset conventions:
+ * 'header' and 'msg' conventions:
*
- * Network frames (aka "packets"): 'frame' MUST be set to the start of the
- * packet, layer offsets MAY be set as appropriate for the packet.
- * Additionally, we assume in many places that the 'frame' and 'data' are
- * the same for packets.
- *
- * OpenFlow messages: 'frame' points to the start of the OpenFlow
- * header, while 'l3_ofs' is the length of the OpenFlow header.
+ * OpenFlow messages: 'header' points to the start of the OpenFlow
+ * header, while 'msg' is the OpenFlow msg bofy.
* When parsing, the 'data' will move past these, as data is being
* pulled from the OpenFlow message.
*
- * Actions: When encoding OVS action lists, the 'frame' is used
+ * Actions: When encoding OVS action lists, the 'header' is used
* as a pointer to the beginning of the current action (see ofpact_put()).
*
- * rconn: Reuses 'frame' as a private pointer while queuing.
+ * rconn: Reuses 'header' as a private pointer while queuing.
*/
struct ofpbuf {
-#ifdef DPDK_NETDEV
- struct rte_mbuf mbuf; /* DPDK mbuf */
-#else
- void *base_; /* First byte of allocated space. */
- void *data_; /* First byte actually in use. */
- uint32_t size_; /* Number of bytes in use. */
-#endif
+ void *base; /* First byte of allocated space. */
+ void *data; /* First byte actually in use. */
+ uint32_t size; /* Number of bytes in use. */
uint32_t allocated; /* Number of bytes allocated. */
- void *frame; /* Packet frame start, or NULL. */
- enum ofpbuf_source source; /* Source of memory allocated as 'base'. */
- uint8_t l2_pad_size; /* Detected l2 padding size.
- * Padding is non-pullable. */
- uint16_t l2_5_ofs; /* MPLS label stack offset from 'frame', or
- * UINT16_MAX */
- uint16_t l3_ofs; /* Network-level header offset from 'frame',
- or UINT16_MAX. */
- uint16_t l4_ofs; /* Transport-level header offset from 'frame',
- or UINT16_MAX. */
+ void *header; /* OpenFlow header. */
+ void *msg; /* message's body */
struct ovs_list list_node; /* Private list element for use by owner. */
+ enum ofpbuf_source source; /* Source of memory allocated as 'base'. */
};
-static inline void * ofpbuf_data(const struct ofpbuf *);
-static inline void ofpbuf_set_data(struct ofpbuf *, void *);
-static inline void * ofpbuf_base(const struct ofpbuf *);
-static inline void ofpbuf_set_base(struct ofpbuf *, void *);
-
-static inline uint32_t ofpbuf_size(const struct ofpbuf *);
-static inline void ofpbuf_set_size(struct ofpbuf *, uint32_t);
-
-void * ofpbuf_resize_l2(struct ofpbuf *, int increment);
-void * ofpbuf_resize_l2_5(struct ofpbuf *, int increment);
-static inline void * ofpbuf_l2(const struct ofpbuf *);
-static inline void ofpbuf_set_frame(struct ofpbuf *, void *);
-static inline uint8_t ofpbuf_l2_pad_size(const struct ofpbuf *);
-static inline void ofpbuf_set_l2_pad_size(struct ofpbuf *, uint8_t);
-static inline void * ofpbuf_l2_5(const struct ofpbuf *);
-static inline void ofpbuf_set_l2_5(struct ofpbuf *, void *);
-static inline void * ofpbuf_l3(const struct ofpbuf *);
-static inline void ofpbuf_set_l3(struct ofpbuf *, void *);
-static inline void * ofpbuf_l4(const struct ofpbuf *);
-static inline void ofpbuf_set_l4(struct ofpbuf *, void *);
-static inline size_t ofpbuf_l4_size(const struct ofpbuf *);
-static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *);
-static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *);
-static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *);
-static inline const void *ofpbuf_get_icmp_payload(const struct ofpbuf *);
-static inline const void *ofpbuf_get_nd_payload(const struct ofpbuf *);
-
void ofpbuf_use(struct ofpbuf *, void *, size_t);
void ofpbuf_use_stack(struct ofpbuf *, void *, size_t);
void ofpbuf_use_stub(struct ofpbuf *, void *, size_t);
void ofpbuf_use_const(struct ofpbuf *, const void *, size_t);
-void ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated);
-
void ofpbuf_init(struct ofpbuf *, size_t);
void ofpbuf_uninit(struct ofpbuf *);
-static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *);
void ofpbuf_reinit(struct ofpbuf *, size_t);
struct ofpbuf *ofpbuf_new(size_t);
void *ofpbuf_put(struct ofpbuf *, const void *, size_t);
char *ofpbuf_put_hex(struct ofpbuf *, const char *s, size_t *n);
void ofpbuf_reserve(struct ofpbuf *, size_t);
-void ofpbuf_reserve_with_tailroom(struct ofpbuf *b, size_t headroom,
- size_t tailroom);
void *ofpbuf_push_uninit(struct ofpbuf *b, size_t);
void *ofpbuf_push_zeros(struct ofpbuf *, size_t);
void *ofpbuf_push(struct ofpbuf *b, const void *, size_t);
static inline bool ofpbuf_equal(const struct ofpbuf *, const struct ofpbuf *);
\f
-/* Returns a pointer that may be passed to free() to accomplish the same thing
- * as ofpbuf_uninit(b). The return value is a null pointer if ofpbuf_uninit()
- * would not free any memory. */
-static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *b)
-{
- /* XXX: If 'source' is OFPBUF_DPDK memory gets leaked! */
- return b && b->source == OFPBUF_MALLOC ? ofpbuf_base(b) : NULL;
-}
-
/* Frees memory that 'b' points to, as well as 'b' itself. */
static inline void ofpbuf_delete(struct ofpbuf *b)
{
if (b) {
- if (b->source == OFPBUF_DPDK) {
- /* If this ofpbuf was allocated by DPDK it must have been
- * created as a dp_packet */
- free_dpdk_buf((struct dp_packet*) b);
- return;
- }
-
ofpbuf_uninit(b);
free(b);
}
static inline void *ofpbuf_at(const struct ofpbuf *b, size_t offset,
size_t size)
{
- return offset + size <= ofpbuf_size(b) ? (char *) ofpbuf_data(b) + offset : NULL;
+ return offset + size <= b->size ? (char *) b->data + offset : NULL;
}
/* Returns a pointer to byte 'offset' in 'b', which must contain at least
static inline void *ofpbuf_at_assert(const struct ofpbuf *b, size_t offset,
size_t size)
{
- ovs_assert(offset + size <= ofpbuf_size(b));
- return ((char *) ofpbuf_data(b)) + offset;
+ ovs_assert(offset + size <= b->size);
+ return ((char *) b->data) + offset;
}
/* Returns a pointer to byte following the last byte of data in use in 'b'. */
static inline void *ofpbuf_tail(const struct ofpbuf *b)
{
- return (char *) ofpbuf_data(b) + ofpbuf_size(b);
+ return (char *) b->data + b->size;
}
/* Returns a pointer to byte following the last byte allocated for use (but
* not necessarily in use) in 'b'. */
static inline void *ofpbuf_end(const struct ofpbuf *b)
{
- return (char *) ofpbuf_base(b) + b->allocated;
+ return (char *) b->base + b->allocated;
}
/* Returns the number of bytes of headroom in 'b', that is, the number of bytes
* headroom is 0.) */
static inline size_t ofpbuf_headroom(const struct ofpbuf *b)
{
- return (char*)ofpbuf_data(b) - (char*)ofpbuf_base(b);
+ return (char*)b->data - (char*)b->base;
}
/* Returns the number of bytes that may be appended to the tail end of ofpbuf
/* Clears any data from 'b'. */
static inline void ofpbuf_clear(struct ofpbuf *b)
{
- ofpbuf_set_data(b, ofpbuf_base(b));
- ofpbuf_set_size(b, 0);
+ b->data = b->base;
+ b->size = 0;
}
/* Removes 'size' bytes from the head end of 'b', which must contain at least
* 'size' bytes of data. Returns the first byte of data removed. */
static inline void *ofpbuf_pull(struct ofpbuf *b, size_t size)
{
- void *data = ofpbuf_data(b);
- ovs_assert(ofpbuf_size(b) - ofpbuf_l2_pad_size(b) >= size);
- ofpbuf_set_data(b, (char*)ofpbuf_data(b) + size);
- ofpbuf_set_size(b, ofpbuf_size(b) - size);
+ void *data = b->data;
+ b->data = (char*)b->data + size;
+ b->size = b->size - size;
return data;
}
* null pointer without modifying 'b'. */
static inline void *ofpbuf_try_pull(struct ofpbuf *b, size_t size)
{
- return ofpbuf_size(b) - ofpbuf_l2_pad_size(b) >= size
- ? ofpbuf_pull(b, size) : NULL;
+ return b->size >= size ? ofpbuf_pull(b, size) : NULL;
}
static inline struct ofpbuf *ofpbuf_from_list(const struct ovs_list *list)
static inline bool ofpbuf_equal(const struct ofpbuf *a, const struct ofpbuf *b)
{
- return ofpbuf_size(a) == ofpbuf_size(b) &&
- memcmp(ofpbuf_data(a), ofpbuf_data(b), ofpbuf_size(a)) == 0;
-}
-
-/* Get the start if the Ethernet frame. 'l3_ofs' marks the end of the l2
- * headers, so return NULL if it is not set. */
-static inline void * ofpbuf_l2(const struct ofpbuf *b)
-{
- return (b->l3_ofs != UINT16_MAX) ? b->frame : NULL;
-}
-
-/* Sets the packet frame start pointer and resets all layer offsets.
- * l3 offset must be set before 'l2' can be retrieved. */
-static inline void ofpbuf_set_frame(struct ofpbuf *b, void *packet)
-{
- b->frame = packet;
- b->l2_pad_size = 0;
- b->l2_5_ofs = UINT16_MAX;
- b->l3_ofs = UINT16_MAX;
- b->l4_ofs = UINT16_MAX;
-}
-
-static inline uint8_t ofpbuf_l2_pad_size(const struct ofpbuf *b)
-{
- return b->l2_pad_size;
-}
-
-static inline void ofpbuf_set_l2_pad_size(struct ofpbuf *b, uint8_t pad_size)
-{
- ovs_assert(pad_size <= ofpbuf_size(b));
- b->l2_pad_size = pad_size;
-}
-
-static inline void * ofpbuf_l2_5(const struct ofpbuf *b)
-{
- return b->l2_5_ofs != UINT16_MAX ? (char *)b->frame + b->l2_5_ofs : NULL;
-}
-
-static inline void ofpbuf_set_l2_5(struct ofpbuf *b, void *l2_5)
-{
- b->l2_5_ofs = l2_5 ? (char *)l2_5 - (char *)b->frame : UINT16_MAX;
-}
-
-static inline void * ofpbuf_l3(const struct ofpbuf *b)
-{
- return b->l3_ofs != UINT16_MAX ? (char *)b->frame + b->l3_ofs : NULL;
-}
-
-static inline void ofpbuf_set_l3(struct ofpbuf *b, void *l3)
-{
- b->l3_ofs = l3 ? (char *)l3 - (char *)b->frame : UINT16_MAX;
-}
-
-static inline void * ofpbuf_l4(const struct ofpbuf *b)
-{
- return b->l4_ofs != UINT16_MAX ? (char *)b->frame + b->l4_ofs : NULL;
-}
-
-static inline void ofpbuf_set_l4(struct ofpbuf *b, void *l4)
-{
- b->l4_ofs = l4 ? (char *)l4 - (char *)b->frame : UINT16_MAX;
-}
-
-static inline size_t ofpbuf_l4_size(const struct ofpbuf *b)
-{
- return b->l4_ofs != UINT16_MAX
- ? (const char *)ofpbuf_tail(b) - (const char *)ofpbuf_l4(b)
- - ofpbuf_l2_pad_size(b)
- : 0;
-}
-
-static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *b)
-{
- size_t l4_size = ofpbuf_l4_size(b);
-
- if (OVS_LIKELY(l4_size >= TCP_HEADER_LEN)) {
- struct tcp_header *tcp = ofpbuf_l4(b);
- int tcp_len = TCP_OFFSET(tcp->tcp_ctl) * 4;
-
- if (OVS_LIKELY(tcp_len >= TCP_HEADER_LEN && tcp_len <= l4_size)) {
- return (const char *)tcp + tcp_len;
- }
- }
- return NULL;
-}
-
-static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *b)
-{
- return OVS_LIKELY(ofpbuf_l4_size(b) >= UDP_HEADER_LEN)
- ? (const char *)ofpbuf_l4(b) + UDP_HEADER_LEN : NULL;
-}
-
-static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *b)
-{
- return OVS_LIKELY(ofpbuf_l4_size(b) >= SCTP_HEADER_LEN)
- ? (const char *)ofpbuf_l4(b) + SCTP_HEADER_LEN : NULL;
-}
-
-static inline const void *ofpbuf_get_icmp_payload(const struct ofpbuf *b)
-{
- return OVS_LIKELY(ofpbuf_l4_size(b) >= ICMP_HEADER_LEN)
- ? (const char *)ofpbuf_l4(b) + ICMP_HEADER_LEN : NULL;
-}
-
-static inline const void *ofpbuf_get_nd_payload(const struct ofpbuf *b)
-{
- return OVS_LIKELY(ofpbuf_l4_size(b) >= ND_MSG_LEN)
- ? (const char *)ofpbuf_l4(b) + ND_MSG_LEN : NULL;
-}
-
-#ifdef DPDK_NETDEV
-BUILD_ASSERT_DECL(offsetof(struct ofpbuf, mbuf) == 0);
-
-static inline void * ofpbuf_data(const struct ofpbuf *b)
-{
- return b->mbuf.pkt.data;
-}
-
-static inline void ofpbuf_set_data(struct ofpbuf *b, void *d)
-{
- b->mbuf.pkt.data = d;
-}
-
-static inline void * ofpbuf_base(const struct ofpbuf *b)
-{
- return b->mbuf.buf_addr;
-}
-
-static inline void ofpbuf_set_base(struct ofpbuf *b, void *d)
-{
- b->mbuf.buf_addr = d;
-}
-
-static inline uint32_t ofpbuf_size(const struct ofpbuf *b)
-{
- return b->mbuf.pkt.pkt_len;
-}
-
-static inline void ofpbuf_set_size(struct ofpbuf *b, uint32_t v)
-{
- b->mbuf.pkt.data_len = v; /* Current seg length. */
- b->mbuf.pkt.pkt_len = v; /* Total length of all segments linked to
- * this segment. */
-}
-
-#else
-static inline void * ofpbuf_data(const struct ofpbuf *b)
-{
- return b->data_;
-}
-
-static inline void ofpbuf_set_data(struct ofpbuf *b, void *d)
-{
- b->data_ = d;
-}
-
-static inline void * ofpbuf_base(const struct ofpbuf *b)
-{
- return b->base_;
-}
-
-static inline void ofpbuf_set_base(struct ofpbuf *b, void *d)
-{
- b->base_ = d;
-}
-
-static inline uint32_t ofpbuf_size(const struct ofpbuf *b)
-{
- return b->size_;
-}
-
-static inline void ofpbuf_set_size(struct ofpbuf *b, uint32_t v)
-{
- b->size_ = v;
-}
-#endif
-
-static inline void ofpbuf_reset_packet(struct ofpbuf *b, int off)
-{
- ofpbuf_set_size(b, ofpbuf_size(b) - off);
- ofpbuf_set_data(b, (void *) ((unsigned char *) b->frame + off));
- b->frame = NULL;
- b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX;
+ return a->size == b->size &&
+ memcmp(a->data, b->data, a->size) == 0;
}
#ifdef __cplusplus
copy_to_monitor(rc, b);
if (counter) {
- rconn_packet_counter_inc(counter, ofpbuf_size(b));
+ rconn_packet_counter_inc(counter, b->size);
}
/* Reuse 'frame' as a private pointer while 'b' is in txq. */
- ofpbuf_set_frame(b, counter);
+ b->header = counter;
list_push_back(&rc->txq, &b->list_node);
OVS_REQUIRES(rc->mutex)
{
struct ofpbuf *msg = ofpbuf_from_list(rc->txq.next);
- unsigned int n_bytes = ofpbuf_size(msg);
- struct rconn_packet_counter *counter = msg->frame;
+ unsigned int n_bytes = msg->size;
+ struct rconn_packet_counter *counter = msg->header;
int retval;
/* Eagerly remove 'msg' from the txq. We can't remove it from the list
* after sending, if sending is successful, because it is then owned by the
* vconn, which might have freed it already. */
list_remove(&msg->list_node);
- ofpbuf_set_frame(msg, NULL);
+ msg->header = NULL;
retval = vconn_send(rc->vconn, msg);
if (retval) {
- ofpbuf_set_frame(msg, counter);
+ msg->header = counter;
list_push_front(&rc->txq, &msg->list_node);
if (retval != EAGAIN) {
report_error(rc, retval);
}
while (!list_is_empty(&rc->txq)) {
struct ofpbuf *b = ofpbuf_from_list(list_pop_front(&rc->txq));
- struct rconn_packet_counter *counter = b->frame;
+ struct rconn_packet_counter *counter = b->header;
if (counter) {
- rconn_packet_counter_dec(counter, ofpbuf_size(b));
+ rconn_packet_counter_dec(counter, b->size);
}
COVERAGE_INC(rconn_discarded);
ofpbuf_delete(b);
enum ofptype type;
enum ofperr error;
- error = ofptype_decode(&type, ofpbuf_data(b));
+ error = ofptype_decode(&type, b->data);
if (error) {
return false;
}
const struct nlmsghdr *nlmsg;
int rta_oif; /* Output interface index. */
- nlmsg = ofpbuf_data(buf);
+ nlmsg = buf->data;
rtm = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *rtm);
if (rtm->rtm_family != AF_INET) {
const struct nlmsghdr *nlmsg;
const struct ifinfomsg *ifinfo;
- nlmsg = ofpbuf_data(buf);
+ nlmsg = buf->data;
ifinfo = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifinfo);
change->nlmsg_type = nlmsg->nlmsg_type;
ofpbuf_use_stack(&buf, &keybuf, sizeof keybuf);
odp_flow_key_from_flow(&buf, &flow, &wc.masks,
flow.in_port.odp_port, true);
- key = ofpbuf_data(&buf);
- key_len = ofpbuf_size(&buf);
+ key = buf.data;
+ key_len = buf.size;
/* mask*/
ofpbuf_use_stack(&buf, &maskbuf, sizeof maskbuf);
odp_flow_key_from_mask(&buf, &wc.masks, &flow,
odp_to_u32(wc.masks.in_port.odp_port),
SIZE_MAX, false);
- mask = ofpbuf_data(&buf);
- mask_len = ofpbuf_size(&buf);
+ mask = buf.data;
+ mask_len = buf.size;
/* build string. */
odp_flow_format(key, key_len, mask, mask_len, NULL, &ds, false);
struct vconn_stream *s = vconn_stream_cast(vconn);
if ((vconn->error == EPROTO || s->n_packets < 1) && s->rxbuf) {
- stream_report_content(ofpbuf_data(s->rxbuf), ofpbuf_size(s->rxbuf), STREAM_OPENFLOW,
+ stream_report_content(s->rxbuf->data, s->rxbuf->size, STREAM_OPENFLOW,
THIS_MODULE, vconn_get_name(vconn));
}
struct ofpbuf *rx = s->rxbuf;
int want_bytes, retval;
- want_bytes = rx_len - ofpbuf_size(rx);
+ want_bytes = rx_len - rx->size;
ofpbuf_prealloc_tailroom(rx, want_bytes);
retval = stream_recv(s->stream, ofpbuf_tail(rx), want_bytes);
if (retval > 0) {
- ofpbuf_set_size(rx, ofpbuf_size(rx) + retval);
+ rx->size += retval;
return retval == want_bytes ? 0 : EAGAIN;
} else if (retval == 0) {
- if (ofpbuf_size(rx)) {
+ if (rx->size) {
VLOG_ERR_RL(&rl, "connection dropped mid-packet");
return EPROTO;
}
}
/* Read ofp_header. */
- if (ofpbuf_size(s->rxbuf) < sizeof(struct ofp_header)) {
+ if (s->rxbuf->size < sizeof(struct ofp_header)) {
int retval = vconn_stream_recv__(s, sizeof(struct ofp_header));
if (retval) {
return retval;
}
/* Read payload. */
- oh = ofpbuf_data(s->rxbuf);
+ oh = s->rxbuf->data;
rx_len = ntohs(oh->length);
if (rx_len < sizeof(struct ofp_header)) {
VLOG_ERR_RL(&rl, "received too-short ofp_header (%d bytes)", rx_len);
return EPROTO;
- } else if (ofpbuf_size(s->rxbuf) < rx_len) {
+ } else if (s->rxbuf->size < rx_len) {
int retval = vconn_stream_recv__(s, rx_len);
if (retval) {
return retval;
return EAGAIN;
}
- retval = stream_send(s->stream, ofpbuf_data(buffer), ofpbuf_size(buffer));
- if (retval == ofpbuf_size(buffer)) {
+ retval = stream_send(s->stream, buffer->data, buffer->size);
+ if (retval == buffer->size) {
ofpbuf_delete(buffer);
return 0;
} else if (retval >= 0 || retval == -EAGAIN) {
return;
}
- retval = stream_send(s->stream, ofpbuf_data(s->txbuf), ofpbuf_size(s->txbuf));
+ retval = stream_send(s->stream, s->txbuf->data, s->txbuf->size);
if (retval < 0) {
if (retval != -EAGAIN) {
VLOG_ERR_RL(&rl, "send: %s", ovs_strerror(-retval));
}
} else if (retval > 0) {
ofpbuf_pull(s->txbuf, retval);
- if (!ofpbuf_size(s->txbuf)) {
+ if (!s->txbuf->size) {
vconn_stream_clear_txbuf(s);
return;
}
enum ofptype type;
enum ofperr error;
- error = ofptype_decode(&type, ofpbuf_data(b));
+ error = ofptype_decode(&type, b->data);
if (!error && type == OFPTYPE_HELLO) {
char *peer_s, *local_s;
uint32_t common_versions;
- if (!ofputil_decode_hello(ofpbuf_data(b), &vconn->peer_versions)) {
+ if (!ofputil_decode_hello(b->data, &vconn->peer_versions)) {
struct ds msg = DS_EMPTY_INITIALIZER;
ds_put_format(&msg, "%s: unknown data in hello:\n",
vconn->name);
- ds_put_hex_dump(&msg, ofpbuf_data(b), ofpbuf_size(b), 0, true);
+ ds_put_hex_dump(&msg, b->data, b->size, 0, true);
VLOG_WARN_RL(&bad_ofmsg_rl, "%s", ds_cstr(&msg));
ds_destroy(&msg);
}
ofpbuf_delete(b);
return;
} else {
- char *s = ofp_to_string(ofpbuf_data(b), ofpbuf_size(b), 1);
+ char *s = ofp_to_string(b->data, b->size, 1);
VLOG_WARN_RL(&bad_ofmsg_rl,
"%s: received message while expecting hello: %s",
vconn->name, s);
retval = do_recv(vconn, &msg);
}
if (!retval && !vconn->recv_any_version) {
- const struct ofp_header *oh = ofpbuf_data(msg);
+ const struct ofp_header *oh = msg->data;
if (oh->version != vconn->version) {
enum ofptype type;
- if (ofptype_decode(&type, ofpbuf_data(msg))
+ if (ofptype_decode(&type, msg->data)
|| (type != OFPTYPE_HELLO &&
type != OFPTYPE_ERROR &&
type != OFPTYPE_ECHO_REQUEST &&
if (!retval) {
COVERAGE_INC(vconn_received);
if (VLOG_IS_DBG_ENABLED()) {
- char *s = ofp_to_string(ofpbuf_data(*msgp), ofpbuf_size(*msgp), 1);
+ char *s = ofp_to_string((*msgp)->data, (*msgp)->size, 1);
VLOG_DBG_RL(&ofmsg_rl, "%s: received: %s", vconn->name, s);
free(s);
}
{
int retval;
- ovs_assert(ofpbuf_size(msg) >= sizeof(struct ofp_header));
+ ovs_assert(msg->size >= sizeof(struct ofp_header));
ofpmsg_update_length(msg);
if (!VLOG_IS_DBG_ENABLED()) {
COVERAGE_INC(vconn_sent);
retval = (vconn->vclass->send)(vconn, msg);
} else {
- char *s = ofp_to_string(ofpbuf_data(msg), ofpbuf_size(msg), 1);
+ char *s = ofp_to_string(msg->data, msg->size, 1);
retval = (vconn->vclass->send)(vconn, msg);
if (retval != EAGAIN) {
VLOG_DBG_RL(&ofmsg_rl, "%s: sent (%s): %s",
*replyp = NULL;
return error;
}
- recv_xid = ((struct ofp_header *) ofpbuf_data(reply))->xid;
+ recv_xid = ((struct ofp_header *) reply->data)->xid;
if (xid == recv_xid) {
*replyp = reply;
return 0;
vconn_transact(struct vconn *vconn, struct ofpbuf *request,
struct ofpbuf **replyp)
{
- ovs_be32 send_xid = ((struct ofp_header *) ofpbuf_data(request))->xid;
+ ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
int error;
*replyp = NULL;
*replyp = NULL;
/* Send request. */
- request_xid = ((struct ofp_header *) ofpbuf_data(request))->xid;
+ request_xid = ((struct ofp_header *) request->data)->xid;
error = vconn_send_block(vconn, request);
if (error) {
ofpbuf_delete(request);
/* Send barrier. */
barrier = ofputil_encode_barrier_request(vconn_get_version(vconn));
- barrier_xid = ((struct ofp_header *) ofpbuf_data(barrier))->xid;
+ barrier_xid = ((struct ofp_header *) barrier->data)->xid;
error = vconn_send_block(vconn, barrier);
if (error) {
ofpbuf_delete(barrier);
return error;
}
- msg_xid = ((struct ofp_header *) ofpbuf_data(msg))->xid;
+ msg_xid = ((struct ofp_header *) msg->data)->xid;
if (msg_xid == request_xid) {
if (*replyp) {
VLOG_WARN_RL(&bad_ofmsg_rl, "%s: duplicate replies with "
ofpact_pad(&ofpacts);
match_init_catchall(&match);
- ofproto_add_flow(mgr->ofproto, &match, 0, ofpbuf_data(&ofpacts),
- ofpbuf_size(&ofpacts));
+ ofproto_add_flow(mgr->ofproto, &match, 0, ofpacts.data,
+ ofpacts.size);
ofpbuf_uninit(&ofpacts);
}
match_init_catchall(&match);
ofproto_add_flow(fo->ofproto, &match, FAIL_OPEN_PRIORITY,
- ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts));
+ ofpacts.data, ofpacts.size);
ofpbuf_uninit(&ofpacts);
}
switch (rule->op) {
case ADD:
ofproto_add_flow(ib->ofproto, &rule->match, rule->priority,
- ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts));
+ ofpacts.data, ofpacts.size);
break;
case DEL:
struct netflow_v5_header *nf_hdr;
struct netflow_v5_record *nf_rec;
- if (!ofpbuf_size(&nf->packet)) {
+ if (!nf->packet.size) {
struct timespec now;
time_wall_timespec(&now);
nf_hdr->sampling_interval = htons(0);
}
- nf_hdr = ofpbuf_data(&nf->packet);
+ nf_hdr = nf->packet.data;
nf_hdr->count = htons(ntohs(nf_hdr->count) + 1);
nf_hdr->flow_seq = htonl(nf->netflow_cnt++);
long long int now = time_msec();
struct netflow_flow *nf_flow, *next;
- if (ofpbuf_size(&nf->packet)) {
- collectors_send(nf->collectors, ofpbuf_data(&nf->packet), ofpbuf_size(&nf->packet));
- ofpbuf_set_size(&nf->packet, 0);
+ if (nf->packet.size) {
+ collectors_send(nf->collectors, nf->packet.data, nf->packet.size);
+ nf->packet.size = 0;
}
if (!nf->active_timeout || now < nf->next_timeout) {
if (nf->active_timeout) {
poll_timer_wait_until(nf->next_timeout);
}
- if (ofpbuf_size(&nf->packet)) {
+ if (nf->packet.size) {
poll_immediate_wake();
}
ovs_mutex_unlock(&mutex);
if (!upcall->xout.slow) {
ofpbuf_use_const(&upcall->put_actions,
- ofpbuf_data(upcall->xout.odp_actions),
- ofpbuf_size(upcall->xout.odp_actions));
+ upcall->xout.odp_actions->data,
+ upcall->xout.odp_actions->size);
} else {
ofpbuf_init(&upcall->put_actions, 0);
compose_slow_path(udpif, &upcall->xout, upcall->flow,
}
if (upcall.xout.slow && put_actions) {
- ofpbuf_put(put_actions, ofpbuf_data(&upcall.put_actions),
- ofpbuf_size(&upcall.put_actions));
+ ofpbuf_put(put_actions, upcall.put_actions.data,
+ upcall.put_actions.size);
}
if (OVS_LIKELY(wc)) {
* actions were composed assuming that the packet contained no
* VLAN. So, we must remove the VLAN header from the packet before
* trying to execute the actions. */
- if (ofpbuf_size(upcall->xout.odp_actions)) {
+ if (upcall->xout.odp_actions->size) {
eth_pop_vlan(CONST_CAST(struct dp_packet *, upcall->packet));
}
op->dop.u.flow_put.mask_len = ukey->mask_len;
op->dop.u.flow_put.ufid = upcall->ufid;
op->dop.u.flow_put.stats = NULL;
- op->dop.u.flow_put.actions = ofpbuf_data(ukey->actions);
- op->dop.u.flow_put.actions_len = ofpbuf_size(ukey->actions);
+ op->dop.u.flow_put.actions = ukey->actions->data;
+ op->dop.u.flow_put.actions_len = ukey->actions->size;
}
- if (ofpbuf_size(upcall->xout.odp_actions)) {
+ if (upcall->xout.odp_actions->size) {
op = &ops[n_ops++];
op->ukey = NULL;
op->dop.type = DPIF_OP_EXECUTE;
op->dop.u.execute.packet = CONST_CAST(struct dp_packet *, packet);
odp_key_to_pkt_metadata(upcall->key, upcall->key_len,
&op->dop.u.execute.packet->md);
- op->dop.u.execute.actions = ofpbuf_data(upcall->xout.odp_actions);
- op->dop.u.execute.actions_len = ofpbuf_size(upcall->xout.odp_actions);
+ op->dop.u.execute.actions = upcall->xout.odp_actions->data;
+ op->dop.u.execute.actions_len = upcall->xout.odp_actions->size;
op->dop.u.execute.needs_help = (upcall->xout.slow & SLOW_ACTION) != 0;
op->dop.u.execute.probe = false;
}
UINT32_MAX, max_mpls, recirc);
}
- return ukey_create__(ofpbuf_data(&keybuf), ofpbuf_size(&keybuf),
- ofpbuf_data(&maskbuf), ofpbuf_size(&maskbuf),
+ return ukey_create__(keybuf.data, keybuf.size, maskbuf.data, maskbuf.size,
true, upcall->ufid, upcall->pmd_id,
&upcall->put_actions, upcall->dump_seq,
upcall->reval_seq, 0);
}
if (!xout.slow) {
- ofpbuf_use_const(&xout_actions, ofpbuf_data(xout.odp_actions),
- ofpbuf_size(xout.odp_actions));
+ ofpbuf_use_const(&xout_actions, xout.odp_actions->data,
+ xout.odp_actions->size);
} else {
ofpbuf_use_stack(&xout_actions, slow_path_buf, sizeof slow_path_buf);
compose_slow_path(udpif, &xout, &flow, flow.in_port.odp_port,
/* Forwarding is disabled by STP and RSTP. Let OFPP_NORMAL and
* the learning action look at the packet, then drop it. */
struct flow old_base_flow = ctx->base_flow;
- size_t old_size = ofpbuf_size(ctx->xout->odp_actions);
+ size_t old_size = ctx->xout->odp_actions->size;
mirror_mask_t old_mirrors = ctx->xout->mirrors;
xlate_table_action(ctx, flow->in_port.ofp_port, table_id,
true, true);
ctx->xout->mirrors = old_mirrors;
ctx->base_flow = old_base_flow;
- ofpbuf_set_size(ctx->xout->odp_actions, old_size);
+ ctx->xout->odp_actions->size = old_size;
}
}
MAX_RESUBMIT_RECURSION);
} else if (ctx->resubmits >= MAX_RESUBMITS + MAX_INTERNAL_RESUBMITS) {
VLOG_ERR_RL(&rl, "over %d resubmit actions", MAX_RESUBMITS);
- } else if (ofpbuf_size(ctx->xout->odp_actions) > UINT16_MAX) {
+ } else if (ctx->xout->odp_actions->size > UINT16_MAX) {
VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of actions");
- } else if (ofpbuf_size(&ctx->stack) >= 65536) {
+ } else if (ctx->stack.size >= 65536) {
VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of stack");
} else {
return true;
ofpacts_execute_action_set(&action_list, &action_set);
ctx->recurse++;
- do_xlate_actions(ofpbuf_data(&action_list), ofpbuf_size(&action_list), ctx);
+ do_xlate_actions(action_list.data, action_list.size, ctx);
ctx->recurse--;
ofpbuf_uninit(&action_set);
ctx->xbridge->masked_set_action);
odp_execute_actions(NULL, &packet, 1, false,
- ofpbuf_data(ctx->xout->odp_actions),
- ofpbuf_size(ctx->xout->odp_actions), NULL);
+ ctx->xout->odp_actions->data,
+ ctx->xout->odp_actions->size, NULL);
pin = xmalloc(sizeof *pin);
pin->up.packet_len = dp_packet_size(packet);
ctx->in_action_set = true;
ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
ofpacts_execute_action_set(&action_list, &ctx->action_set);
- do_xlate_actions(ofpbuf_data(&action_list), ofpbuf_size(&action_list), ctx);
+ do_xlate_actions(action_list.data, action_list.size, ctx);
ctx->in_action_set = false;
ofpbuf_uninit(&action_list);
}
dst->odp_actions = &dst->odp_actions_buf;
ofpbuf_use_stub(dst->odp_actions, dst->odp_actions_stub,
sizeof dst->odp_actions_stub);
- ofpbuf_put(dst->odp_actions, ofpbuf_data(src->odp_actions),
- ofpbuf_size(src->odp_actions));
+ ofpbuf_put(dst->odp_actions, src->odp_actions->data, src->odp_actions->size);
}
\f
static struct skb_priority_to_dscp *
const struct nlattr *a;
unsigned int left;
- NL_ATTR_FOR_EACH_UNSAFE (a, left, ofpbuf_data(ctx->xout->odp_actions),
- ofpbuf_size(ctx->xout->odp_actions)) {
+ NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->xout->odp_actions->data,
+ ctx->xout->odp_actions->size) {
if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
&& nl_attr_get_odp_port(a) == local_odp_port) {
return true;
size_t left;
int n = 0;
- NL_ATTR_FOR_EACH_UNSAFE (a, left, ofpbuf_data(odp_actions),
- ofpbuf_size(odp_actions)) {
+ NL_ATTR_FOR_EACH_UNSAFE (a, left, odp_actions->data, odp_actions->size) {
if (a->nla_type == OVS_ACTION_ATTR_OUTPUT) {
n++;
}
too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
{
#ifdef __linux__
- return (ofpbuf_size(odp_actions) / NL_A_U32_SIZE > netdev_max_backlog()
+ return (odp_actions->size / NL_A_U32_SIZE > netdev_max_backlog()
&& count_output_actions(odp_actions) > netdev_max_backlog());
#else
/* OSes other than Linux might have similar limits, but we don't know how
add_sflow_action(&ctx);
add_ipfix_action(&ctx);
- sample_actions_len = ofpbuf_size(ctx.xout->odp_actions);
+ sample_actions_len = ctx.xout->odp_actions->size;
if (tnl_may_send && (!in_port || may_receive(in_port, &ctx))) {
do_xlate_actions(ofpacts, ofpacts_len, &ctx);
* packet, so drop it now if forwarding is disabled. */
if (in_port && (!xport_stp_forward_state(in_port) ||
!xport_rstp_forward_state(in_port))) {
- ofpbuf_set_size(ctx.xout->odp_actions, sample_actions_len);
+ ctx.xout->odp_actions->size = sample_actions_len;
}
}
- if (ofpbuf_size(&ctx.action_set)) {
+ if (ctx.action_set.size) {
xlate_action_set(&ctx);
}
}
}
- if (nl_attr_oversized(ofpbuf_size(ctx.xout->odp_actions))) {
+ if (nl_attr_oversized(ctx.xout->odp_actions->size)) {
/* These datapath actions are too big for a Netlink attribute, so we
* can't hand them to the kernel directly. dpif_execute() can execute
* them one by one with help, so just mark the result as SLOW_ACTION to
ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
odp_flow_key_from_flow(&key, &flow, NULL, 0, true);
- dpif_flow_hash(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key), &ufid);
+ dpif_flow_hash(backer->dpif, key.data, key.size, &ufid);
enable_ufid = dpif_probe_feature(backer->dpif, "UFID", &key, &ufid);
/* Execute the actions. On older datapaths this fails with ERANGE, on
* newer datapaths it succeeds. */
- execute.actions = ofpbuf_data(&actions);
- execute.actions_len = ofpbuf_size(&actions);
+ execute.actions = actions.data;
+ execute.actions_len = actions.size;
execute.packet = &packet;
execute.needs_help = false;
execute.probe = true;
/* Execute the actions. On older datapaths this fails with EINVAL, on
* newer datapaths it succeeds. */
- execute.actions = ofpbuf_data(&actions);
- execute.actions_len = ofpbuf_size(&actions);
+ execute.actions = actions.data;
+ execute.actions_len = actions.size;
execute.packet = &packet;
execute.needs_help = false;
execute.probe = true;
xin.resubmit_stats = &stats;
xlate_actions(&xin, &xout);
- execute.actions = ofpbuf_data(xout.odp_actions);
- execute.actions_len = ofpbuf_size(xout.odp_actions);
+ execute.actions = xout.odp_actions->data;
+ execute.actions_len = xout.odp_actions->size;
pkt_metadata_from_flow(&packet->md, flow);
execute.packet = packet;
ds_put_char_multiple(result, '\t', level);
ds_put_format(result, "%s: ", title);
- format_odp_actions(result, ofpbuf_data(odp_actions),
- ofpbuf_size(odp_actions));
+ format_odp_actions(result, odp_actions->data, odp_actions->size);
ds_put_char(result, '\n');
}
goto exit;
}
- if (odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key),
- flow) == ODP_FIT_ERROR) {
+ if (odp_flow_key_to_flow(odp_key.data, odp_key.size, flow) == ODP_FIT_ERROR) {
error = "Failed to parse flow key";
goto exit;
}
goto exit;
}
if (enforce_consistency) {
- retval = ofpacts_check_consistency(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts),
+ retval = ofpacts_check_consistency(ofpacts.data, ofpacts.size,
&flow, u16_to_ofp(ofproto->up.max_ports),
0, 0, usable_protocols);
} else {
- retval = ofpacts_check(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &flow,
+ retval = ofpacts_check(ofpacts.data, ofpacts.size, &flow,
u16_to_ofp(ofproto->up.max_ports), 0, 0,
&usable_protocols);
}
}
ofproto_trace(ofproto, &flow, packet,
- ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &result);
+ ofpacts.data, ofpacts.size, &result);
unixctl_command_reply(conn, ds_cstr(&result));
exit:
trace_format_megaflow(ds, 0, "Megaflow", &trace);
ds_put_cstr(ds, "Datapath actions: ");
- format_odp_actions(ds, ofpbuf_data(trace.xout.odp_actions),
- ofpbuf_size(trace.xout.odp_actions));
+ format_odp_actions(ds, trace.xout.odp_actions->data,
+ trace.xout.odp_actions->size);
if (trace.xout.slow) {
enum slow_path_reason slow;
fm.buffer_id = 0;
fm.out_port = 0;
fm.flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY;
- fm.ofpacts = ofpbuf_data(ofpacts);
- fm.ofpacts_len = ofpbuf_size(ofpacts);
+ fm.ofpacts = ofpacts->data;
+ fm.ofpacts_len = ofpacts->size;
error = ofproto_flow_mod(&ofproto->up, &fm);
if (error) {
ofpbuf_use_const(&msg, request, ntohs(request->length));
ofpraw_pull_assert(&msg);
- if (ofpbuf_size(&msg) || ofpmp_more(request)) {
+ if (msg.size || ofpmp_more(request)) {
return OFPERR_OFPTFFC_EPERM;
}
handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
OVS_EXCLUDED(ofproto_mutex)
{
- const struct ofp_header *oh = ofpbuf_data(msg);
+ const struct ofp_header *oh = msg->data;
enum ofptype type;
enum ofperr error;
{
int error = handle_openflow__(ofconn, ofp_msg);
if (error) {
- ofconn_send_error(ofconn, ofpbuf_data(ofp_msg), error);
+ ofconn_send_error(ofconn, ofp_msg->data, error);
}
COVERAGE_INC(ofproto_recv_openflow);
}
ovs_fatal(0, "%s", error);
}
- action = ofpbuf_data(&ofpacts);
+ action = ofpacts.data;
bundle = ofpact_get_BUNDLE(xmemdup(action, action->len));
ofpbuf_uninit(&ofpacts);
putchar('\n');
}
- if (ofpbuf_size(buf)) {
- printf("%"PRIu32" extra bytes after last record\n", ofpbuf_size(buf));
+ if (buf->size) {
+ printf("%"PRIu32" extra bytes after last record\n", buf->size);
}
}
ofpbuf_clear(&buf);
do {
- retval = recv(sock, ofpbuf_data(&buf), buf.allocated, 0);
+ retval = recv(sock, buf.data, buf.allocated, 0);
} while (retval < 0 && errno == EINTR);
if (retval > 0) {
ofpbuf_put_uninit(&buf, retval);
if (!wc_keys) {
/* Convert odp_key to flow. */
- fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &flow);
+ fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
switch (fitness) {
case ODP_FIT_PERFECT:
break;
odp_flow_key_from_flow(&odp_key, &flow, NULL,
flow.in_port.odp_port, true);
- if (ofpbuf_size(&odp_key) > ODPUTIL_FLOW_KEY_BYTES) {
+ if (odp_key.size > ODPUTIL_FLOW_KEY_BYTES) {
printf ("too long: %"PRIu32" > %d\n",
- ofpbuf_size(&odp_key), ODPUTIL_FLOW_KEY_BYTES);
+ odp_key.size, ODPUTIL_FLOW_KEY_BYTES);
exit_code = 1;
}
}
/* Convert odp_key to string. */
ds_init(&out);
if (wc_keys) {
- odp_flow_format(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key),
- ofpbuf_data(&odp_mask), ofpbuf_size(&odp_mask), NULL, &out, false);
+ odp_flow_format(odp_key.data, odp_key.size,
+ odp_mask.data, odp_mask.size, NULL, &out, false);
} else {
- odp_flow_key_format(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &out);
+ odp_flow_key_format(odp_key.data, odp_key.size, &out);
}
puts(ds_cstr(&out));
ds_destroy(&out);
/* Convert odp_actions back to string. */
ds_init(&out);
- format_odp_actions(&out, ofpbuf_data(&odp_actions), ofpbuf_size(&odp_actions));
+ format_odp_actions(&out, odp_actions.data, odp_actions.size);
puts(ds_cstr(&out));
ds_destroy(&out);
struct match match, match_filter;
struct minimatch minimatch;
- odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &flow);
- odp_flow_key_to_mask(ofpbuf_data(&odp_mask), ofpbuf_size(&odp_mask), &wc.masks,
+ odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
+ odp_flow_key_to_mask(odp_mask.data, odp_mask.size, &wc.masks,
&flow);
match_init(&match, &flow, &wc);
}
/* Convert odp_key to string. */
ds_init(&out);
- odp_flow_format(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key),
- ofpbuf_data(&odp_mask), ofpbuf_size(&odp_mask), NULL, &out, false);
+ odp_flow_format(odp_key.data, odp_key.size,
+ odp_mask.data, odp_mask.size, NULL, &out, false);
puts(ds_cstr(&out));
ds_destroy(&out);
print_sflow(struct ofpbuf *buf)
{
char *dgram_buf;
- int dgram_len = ofpbuf_size(buf);
+ int dgram_len = buf->size;
struct sflow_xdr xdrDatagram;
struct sflow_xdr *x = &xdrDatagram;
memset(x, 0, sizeof *x);
if (SFLOWXDR_try(x)) {
- SFLOWXDR_assert(x, (dgram_buf = ofpbuf_try_pull(buf, ofpbuf_size(buf))));
+ SFLOWXDR_assert(x, (dgram_buf = ofpbuf_try_pull(buf, buf->size)));
sflowxdr_init(x, dgram_buf, dgram_len);
SFLOWXDR_assert(x, dgram_len >= SFLOW_MIN_LEN);
process_datagram(x);
ofpbuf_clear(&buf);
do {
- retval = recv(sock, ofpbuf_data(&buf), buf.allocated, 0);
+ retval = recv(sock, buf.data, buf.allocated, 0);
} while (retval < 0 && errno == EINTR);
if (retval > 0) {
ofpbuf_put_uninit(&buf, retval);
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
htonl(0x12345678), 0);
- test_send_hello(type, ofpbuf_data(hello), ofpbuf_size(hello), 0);
+ test_send_hello(type, hello->data, hello->size, 0);
ofpbuf_delete(hello);
}
htonl(0x12345678), EXTRA_BYTES);
ofpbuf_put_zeros(hello, EXTRA_BYTES);
ofpmsg_update_length(hello);
- test_send_hello(type, ofpbuf_data(hello), ofpbuf_size(hello), 0);
+ test_send_hello(type, hello->data, hello->size, 0);
ofpbuf_delete(hello);
}
echo = ofpraw_alloc_xid(OFPRAW_OFPT_ECHO_REQUEST, OFP13_VERSION,
htonl(0x12345678), 0);
- test_send_hello(type, ofpbuf_data(echo), ofpbuf_size(echo), EPROTO);
+ test_send_hello(type, echo->data, echo->size, EPROTO);
ofpbuf_delete(echo);
}
hello = ofpraw_alloc_xid(OFPRAW_OFPT_HELLO, OFP13_VERSION,
htonl(0x12345678), 0);
- ((struct ofp_header *) ofpbuf_data(hello))->version = 0;
- test_send_hello(type, ofpbuf_data(hello), ofpbuf_size(hello), EPROTO);
+ ((struct ofp_header *) hello->data)->version = 0;
+ test_send_hello(type, hello->data, hello->size, EPROTO);
ofpbuf_delete(hello);
}
ofpmsg_update_length(request);
run(vconn_transact(vconn, request, &reply), "talking to %s",
vconn_get_name(vconn));
- ofp_print(stdout, ofpbuf_data(reply), ofpbuf_size(reply), verbosity + 1);
+ ofp_print(stdout, reply->data, reply->size, verbosity + 1);
ofpbuf_delete(reply);
}
static void
dump_stats_transaction(struct vconn *vconn, struct ofpbuf *request)
{
- const struct ofp_header *request_oh = ofpbuf_data(request);
+ const struct ofp_header *request_oh = request->data;
ovs_be32 send_xid = request_oh->xid;
enum ofpraw request_raw;
enum ofpraw reply_raw;
bool done = false;
- ofpraw_decode_partial(&request_raw, ofpbuf_data(request), ofpbuf_size(request));
+ ofpraw_decode_partial(&request_raw, request->data, request->size);
reply_raw = ofpraw_stats_request_to_reply(request_raw,
request_oh->version);
struct ofpbuf *reply;
run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
- recv_xid = ((struct ofp_header *) ofpbuf_data(reply))->xid;
+ recv_xid = ((struct ofp_header *) reply->data)->xid;
if (send_xid == recv_xid) {
enum ofpraw raw;
- ofp_print(stdout, ofpbuf_data(reply), ofpbuf_size(reply), verbosity + 1);
+ ofp_print(stdout, reply->data, reply->size, verbosity + 1);
- ofpraw_decode(&raw, ofpbuf_data(reply));
+ ofpraw_decode(&raw, reply->data);
if (ofptype_from_ofpraw(raw) == OFPTYPE_ERROR) {
done = true;
} else if (raw == reply_raw) {
- done = !ofpmp_more(ofpbuf_data(reply));
+ done = !ofpmp_more(reply->data);
} else {
ovs_fatal(0, "received bad reply: %s",
- ofp_to_string(ofpbuf_data(reply), ofpbuf_size(reply),
+ ofp_to_string(reply->data, reply->size,
verbosity + 1));
}
} else {
run(vconn_transact_multiple_noreply(vconn, requests, &reply),
"talking to %s", vconn_get_name(vconn));
if (reply) {
- ofp_print(stderr, ofpbuf_data(reply), ofpbuf_size(reply), verbosity + 2);
+ ofp_print(stderr, reply->data, reply->size, verbosity + 2);
exit(1);
}
ofpbuf_delete(reply);
run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
has_ports = ofputil_switch_features_has_ports(reply);
- ofp_print(stdout, ofpbuf_data(reply), ofpbuf_size(reply), verbosity + 1);
+ ofp_print(stdout, reply->data, reply->size, verbosity + 1);
ofpbuf_delete(reply);
if (!has_ports) {
run(vconn_transact(vconn, request, &reply),
"talking to %s", vconn_get_name(vconn));
- oh = ofpbuf_data(reply);
- if (ofptype_decode(&type, ofpbuf_data(reply))
+ oh = reply->data;
+ if (ofptype_decode(&type, reply->data)
|| type != OFPTYPE_FEATURES_REPLY) {
ovs_fatal(0, "%s: received bad features reply", vconn_get_name(vconn));
}
request = ofputil_encode_port_desc_stats_request(vconn_get_version(vconn),
port_no);
- send_xid = ((struct ofp_header *) ofpbuf_data(request))->xid;
+ send_xid = ((struct ofp_header *) request->data)->xid;
send_openflow_buffer(vconn, request);
while (!done) {
struct ofpbuf *reply;
run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
- recv_xid = ((struct ofp_header *) ofpbuf_data(reply))->xid;
+ recv_xid = ((struct ofp_header *) reply->data)->xid;
if (send_xid == recv_xid) {
- struct ofp_header *oh = ofpbuf_data(reply);
+ struct ofp_header *oh = reply->data;
enum ofptype type;
struct ofpbuf b;
uint16_t flags;
if (ofptype_pull(&type, &b)
|| type != OFPTYPE_PORT_DESC_STATS_REPLY) {
ovs_fatal(0, "received bad reply: %s",
- ofp_to_string(ofpbuf_data(reply), ofpbuf_size(reply),
+ ofp_to_string(reply->data, reply->size,
verbosity + 1));
}
run(vconn_transact_noreply(vconn, request, &reply),
"talking to %s", vconn_get_name(vconn));
if (reply) {
- char *s = ofp_to_string(ofpbuf_data(reply), ofpbuf_size(reply), 2);
+ char *s = ofp_to_string(reply->data, reply->size, 2);
VLOG_DBG("%s: failed to set protocol, switch replied: %s",
vconn_get_name(vconn), s);
free(s);
size_t i;
vconn = prepare_dump_flows(argc, argv, false, &request);
- send_xid = ((struct ofp_header *) ofpbuf_data(request))->xid;
+ send_xid = ((struct ofp_header *) request->data)->xid;
send_openflow_buffer(vconn, request);
fses = NULL;
return "Trailing garbage in hex data";
}
- if (ofpbuf_size(msg) < sizeof(struct ofp_header)) {
+ if (msg->size < sizeof(struct ofp_header)) {
ofpbuf_delete(msg);
return "Message too short for OpenFlow";
}
- oh = ofpbuf_data(msg);
- if (ofpbuf_size(msg) != ntohs(oh->length)) {
+ oh = msg->data;
+ if (msg->size != ntohs(oh->length)) {
ofpbuf_delete(msg);
return "Message size does not match length in OpenFlow header";
}
}
fprintf(stderr, "send: ");
- ofp_print(stderr, ofpbuf_data(msg), ofpbuf_size(msg), verbosity);
+ ofp_print(stderr, msg->data, msg->size, verbosity);
error = vconn_send_block(vconn, msg);
if (error) {
free(s);
}
- ofptype_decode(&type, ofpbuf_data(b));
- ofp_print(stderr, ofpbuf_data(b), ofpbuf_size(b), verbosity + 2);
+ ofptype_decode(&type, b->data);
+ ofp_print(stderr, b->data, b->size, verbosity + 2);
fflush(stderr);
switch ((int) type) {
if (reply_to_echo_requests) {
struct ofpbuf *reply;
- reply = make_echo_reply(ofpbuf_data(b));
+ reply = make_echo_reply(b->data);
retval = vconn_send_block(vconn, reply);
if (retval) {
ovs_fatal(retval, "failed to send echo reply");
run(vconn_transact_noreply(vconn, spif, &reply),
"talking to %s", vconn_get_name(vconn));
if (reply) {
- char *s = ofp_to_string(ofpbuf_data(reply), ofpbuf_size(reply), 2);
+ char *s = ofp_to_string(reply->data, reply->size, 2);
VLOG_DBG("%s: failed to set packet in format to nxm, controller"
" replied: %s. Falling back to the switch default.",
vconn_get_name(vconn), s);
open_vconn(argv[1], &vconn);
request = make_echo_request(vconn_get_version(vconn));
run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
- if (ofpbuf_size(reply) != sizeof(struct ofp_header)) {
+ if (reply->size != sizeof(struct ofp_header)) {
ovs_fatal(0, "reply does not match request");
}
ofpbuf_delete(reply);
po.buffer_id = UINT32_MAX;
po.in_port = str_to_port_no(argv[1], argv[2]);
- po.ofpacts = ofpbuf_data(&ofpacts);
- po.ofpacts_len = ofpbuf_size(&ofpacts);
+ po.ofpacts = ofpacts.data;
+ po.ofpacts_len = ofpacts.size;
protocol = open_vconn(argv[1], &vconn);
for (i = 4; i < argc; i++) {
ovs_fatal(0, "%s: unexpected end of file mid-message", filename);
}
- ofp_print(stdout, ofpbuf_data(&b), ofpbuf_size(&b), verbosity + 2);
+ ofp_print(stdout, b.data, b.size, verbosity + 2);
}
ofpbuf_uninit(&b);
run(vconn_transact(vconn, ofpbuf_clone(request), &reply), "transact");
xgettimeofday(&end);
- rpy_hdr = ofpbuf_data(reply);
+ rpy_hdr = reply->data;
if (ofptype_pull(&type, reply)
|| type != OFPTYPE_ECHO_REPLY
- || ofpbuf_size(reply) != payload
- || memcmp(ofpbuf_l3(request), ofpbuf_l3(reply), payload)) {
+ || reply->size != payload
+ || memcmp(request->msg, reply->msg, payload)) {
printf("Reply does not match request. Request:\n");
- ofp_print(stdout, request, ofpbuf_size(request), verbosity + 2);
+ ofp_print(stdout, request, request->size, verbosity + 2);
printf("Reply:\n");
- ofp_print(stdout, reply, ofpbuf_size(reply), verbosity + 2);
+ ofp_print(stdout, reply, reply->size, verbosity + 2);
}
printf("%"PRIu32" bytes from %s: xid=%08"PRIx32" time=%.1f ms\n",
- ofpbuf_size(reply), argv[1], ntohl(rpy_hdr->xid),
+ reply->size, argv[1], ntohl(rpy_hdr->xid),
(1000*(double)(end.tv_sec - start.tv_sec))
+ (.001*(end.tv_usec - start.tv_usec)));
ofpbuf_delete(request);
do {
run(vconn_recv_block(vconn, &reply),
"OpenFlow packet receive failed");
- } while (((struct ofp_header *) ofpbuf_data(reply))->xid != send_xid);
+ } while (((struct ofp_header *) reply->data)->xid != send_xid);
- error = ofptype_decode(&type, ofpbuf_data(reply));
+ error = ofptype_decode(&type, reply->data);
if (error || type != OFPTYPE_FLOW_STATS_REPLY) {
ovs_fatal(0, "received bad reply: %s",
- ofp_to_string(ofpbuf_data(reply), ofpbuf_size(reply),
+ ofp_to_string(reply->data, reply->size,
verbosity + 1));
}
}
return true;
case EOF:
- more = ofpmp_more(reply->frame);
+ more = ofpmp_more(reply->header);
ofpbuf_delete(reply);
reply = NULL;
if (!more) {
fsr.table_id = 0xff;
fsr.cookie = fsr.cookie_mask = htonll(0);
request = ofputil_encode_flow_stats_request(&fsr, protocol);
- send_xid = ((struct ofp_header *) ofpbuf_data(request))->xid;
+ send_xid = ((struct ofp_header *) request->data)->xid;
send_openflow_buffer(vconn, request);
reply = NULL;
struct ofpbuf *msg;
msg = ofputil_encode_flow_mod(fm, protocol);
- ofp_print(stdout, ofpbuf_data(msg), ofpbuf_size(msg), verbosity);
+ ofp_print(stdout, msg->data, msg->size, verbosity);
ofpbuf_delete(msg);
free(CONST_CAST(struct ofpact *, fm->ofpacts));
} else {
match_len = nx_put_match(&nx_match, &match,
cookie, cookie_mask);
- out = nx_match_to_string(ofpbuf_data(&nx_match), match_len);
+ out = nx_match_to_string(nx_match.data, match_len);
}
puts(out);
free(out);
if (verbosity > 0) {
- ovs_hex_dump(stdout, ofpbuf_data(&nx_match),
- ofpbuf_size(&nx_match), 0, false);
+ ovs_hex_dump(stdout, nx_match.data, nx_match.size, 0, false);
}
} else {
printf("nx_pull_match() returned error %s\n",
/* Convert to ofpacts. */
ofpbuf_init(&ofpacts, 0);
- size = ofpbuf_size(&of_in);
+ size = of_in.size;
error = (instructions
? ofpacts_pull_openflow_instructions
: ofpacts_pull_openflow_actions)(
- &of_in, ofpbuf_size(&of_in), version, &ofpacts);
+ &of_in, of_in.size, version, &ofpacts);
if (!error && instructions) {
/* Verify actions, enforce consistency. */
enum ofputil_protocol protocol;
memset(&flow, 0, sizeof flow);
protocol = ofputil_protocols_from_ofp_version(version);
- error = ofpacts_check_consistency(ofpbuf_data(&ofpacts),
- ofpbuf_size(&ofpacts),
+ error = ofpacts_check_consistency(ofpacts.data, ofpacts.size,
&flow, OFPP_MAX,
table_id ? atoi(table_id) : 0,
255, protocol);
/* Print cls_rule. */
ds_init(&s);
ds_put_cstr(&s, "actions=");
- ofpacts_format(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &s);
+ ofpacts_format(ofpacts.data, ofpacts.size, &s);
puts(ds_cstr(&s));
ds_destroy(&s);
/* Convert back to ofp10 actions and print differences from input. */
ofpbuf_init(&of_out, 0);
if (instructions) {
- ofpacts_put_openflow_instructions( ofpbuf_data(&ofpacts),
- ofpbuf_size(&ofpacts),
- &of_out, version);
+ ofpacts_put_openflow_instructions(ofpacts.data, ofpacts.size,
+ &of_out, version);
} else {
- ofpacts_put_openflow_actions( ofpbuf_data(&ofpacts),
- ofpbuf_size(&ofpacts),
+ ofpacts_put_openflow_actions(ofpacts.data, ofpacts.size,
&of_out, version);
}
- print_differences("", ofpbuf_data(&of_in), ofpbuf_size(&of_in),
- ofpbuf_data(&of_out), ofpbuf_size(&of_out));
+ print_differences("", of_in.data, of_in.size,
+ of_out.data, of_out.size);
putchar('\n');
ofpbuf_uninit(&ofpacts);
if (ofpbuf_put_hex(&match_expout, ds_cstr(&expout), NULL)[0] != '\0') {
ovs_fatal(0, "Trailing garbage in hex data");
}
- if (ofpbuf_size(&match_expout) != sizeof(struct ofp10_match)) {
+ if (match_expout.size != sizeof(struct ofp10_match)) {
ovs_fatal(0, "Input is %"PRIu32" bytes, expected %"PRIuSIZE,
- ofpbuf_size(&match_expout), sizeof(struct ofp10_match));
+ match_expout.size, sizeof(struct ofp10_match));
}
/* Parse hex bytes for input. */
if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') {
ovs_fatal(0, "Trailing garbage in hex data");
}
- if (ofpbuf_size(&match_in) != sizeof(struct ofp10_match)) {
+ if (match_in.size != sizeof(struct ofp10_match)) {
ovs_fatal(0, "Input is %"PRIu32" bytes, expected %"PRIuSIZE,
- ofpbuf_size(&match_in), sizeof(struct ofp10_match));
+ match_in.size, sizeof(struct ofp10_match));
}
/* Convert to cls_rule and print. */
- ofputil_match_from_ofp10_match(ofpbuf_data(&match_in), &match);
+ ofputil_match_from_ofp10_match(match_in.data, &match);
match_print(&match);
/* Convert back to ofp10_match and print differences from input. */
ofputil_match_to_ofp10_match(&match, &match_out);
- print_differences("", ofpbuf_data(&match_expout), ofpbuf_size(&match_expout),
+ print_differences("", match_expout.data, match_expout.size,
&match_out, sizeof match_out);
/* Normalize, then convert and compare again. */
if (ofpbuf_put_hex(&match_in, ds_cstr(&in), NULL)[0] != '\0') {
ovs_fatal(0, "Trailing garbage in hex data");
}
- if (ofpbuf_size(&match_in) != sizeof(struct ofp11_match)) {
+ if (match_in.size != sizeof(struct ofp11_match)) {
ovs_fatal(0, "Input is %"PRIu32" bytes, expected %"PRIuSIZE,
- ofpbuf_size(&match_in), sizeof(struct ofp11_match));
+ match_in.size, sizeof(struct ofp11_match));
}
/* Convert to match. */
- error = ofputil_match_from_ofp11_match(ofpbuf_data(&match_in), &match);
+ error = ofputil_match_from_ofp11_match(match_in.data, &match);
if (error) {
printf("bad ofp11_match: %s\n\n", ofperr_get_name(error));
ofpbuf_uninit(&match_in);
/* Convert back to ofp11_match and print differences from input. */
ofputil_match_to_ofp11_match(&match, &match_out);
- print_differences("", ofpbuf_data(&match_in), ofpbuf_size(&match_in),
+ print_differences("", match_in.data, match_in.size,
&match_out, sizeof match_out);
putchar('\n');
/* Convert to and from NXM. */
ofpbuf_init(&nxm, 0);
nxm_match_len = nx_put_match(&nxm, &match, htonll(0), htonll(0));
- nxm_s = nx_match_to_string(ofpbuf_data(&nxm), nxm_match_len);
+ nxm_s = nx_match_to_string(nxm.data, nxm_match_len);
error = nx_pull_match(&nxm, nxm_match_len, &nxm_match, NULL, NULL);
printf("NXM: %s -> ", nxm_s);
if (error) {
if (ofpbuf_put_hex(&request, argv[2], NULL)[0] != '\0') {
ovs_fatal(0, "Trailing garbage in hex data");
}
- if (ofpbuf_size(&request) < sizeof(struct ofp_header)) {
+ if (request.size < sizeof(struct ofp_header)) {
ovs_fatal(0, "Request too short");
}
- oh = ofpbuf_data(&request);
- if (ofpbuf_size(&request) != ntohs(oh->length)) {
+ oh = request.data;
+ if (request.size != ntohs(oh->length)) {
ovs_fatal(0, "Request size inconsistent");
}
- reply = ofperr_encode_reply(error, ofpbuf_data(&request));
+ reply = ofperr_encode_reply(error, request.data);
ofpbuf_uninit(&request);
- ovs_hex_dump(stdout, ofpbuf_data(reply), ofpbuf_size(reply), 0, false);
+ ovs_hex_dump(stdout, reply->data, reply->size, 0, false);
ofpbuf_delete(reply);
}
if (ofpbuf_put_hex(&packet, buffer, NULL)[0] != '\0') {
ovs_fatal(0, "trailing garbage following hex bytes");
}
- ofp_print(stdout, ofpbuf_data(&packet), ofpbuf_size(&packet), verbosity);
+ ofp_print(stdout, packet.data, packet.size, verbosity);
ofpbuf_uninit(&packet);
ds_destroy(&line);
}
struct ofpbuf *hello;
hello = ofputil_encode_hello(bitmap);
- ovs_hex_dump(stdout, ofpbuf_data(hello), ofpbuf_size(hello), 0, false);
- ofp_print(stdout, ofpbuf_data(hello), ofpbuf_size(hello), verbosity);
+ ovs_hex_dump(stdout, hello->data, hello->size, 0, false);
+ ofp_print(stdout, hello->data, hello->size, verbosity);
ofpbuf_delete(hello);
}
}
if (iface->ofp_port != OFPP_NONE) {
- const struct ofproto_port_queue *port_queues = ofpbuf_data(&queues_buf);
- size_t n_queues = ofpbuf_size(&queues_buf) / sizeof *port_queues;
+ const struct ofproto_port_queue *port_queues = queues_buf.data;
+ size_t n_queues = queues_buf.size / sizeof *port_queues;
ofproto_port_set_queues(iface->port->bridge->ofproto, iface->ofp_port,
port_queues, n_queues);