From 6fd6ed71cb9f2dba8307da371d5e86c34695783c Mon Sep 17 00:00:00 2001 From: Pravin B Shelar Date: Mon, 2 Mar 2015 17:29:44 -0800 Subject: [PATCH] ofpbuf: Simplify ofpbuf API. ofpbuf was complicated due to its wide usage across all layers of OVS, Now we have introduced independent dp_packet which can be used for datapath packet, we can simplify ofpbuf. Following patch removes DPDK mbuf and access API of ofpbuf members. Signed-off-by: Pravin B Shelar Acked-by: Jarno Rajahalme Acked-by: Ben Pfaff --- lib/bundle.c | 2 +- lib/dpctl.c | 41 ++-- lib/dpif-netdev.c | 26 +-- lib/dpif-netlink.c | 14 +- lib/dpif.c | 10 +- lib/jsonrpc.c | 6 +- lib/learn.c | 6 +- lib/learning-switch.c | 16 +- lib/netdev-dummy.c | 3 +- lib/netlink-socket.c | 76 +++---- lib/netlink.c | 26 +-- lib/nx-match.c | 50 ++--- lib/odp-util.c | 16 +- lib/ofp-actions.c | 131 ++++++------ lib/ofp-errors.c | 4 +- lib/ofp-msgs.c | 76 +++---- lib/ofp-parse.c | 8 +- lib/ofp-print.c | 4 +- lib/ofp-util.c | 374 +++++++++++++++++----------------- lib/ofpbuf.c | 173 +++++----------- lib/ofpbuf.h | 300 +++------------------------ lib/rconn.c | 18 +- lib/route-table.c | 2 +- lib/rtnetlink-link.c | 2 +- lib/tnl-ports.c | 8 +- lib/vconn-stream.c | 22 +- lib/vconn.c | 28 +-- ofproto/connmgr.c | 4 +- ofproto/fail-open.c | 2 +- ofproto/in-band.c | 2 +- ofproto/netflow.c | 12 +- ofproto/ofproto-dpif-upcall.c | 27 ++- ofproto/ofproto-dpif-xlate.c | 36 ++-- ofproto/ofproto-dpif.c | 34 ++-- ofproto/ofproto.c | 6 +- tests/test-bundle.c | 2 +- tests/test-netflow.c | 6 +- tests/test-odp.c | 22 +- tests/test-sflow.c | 6 +- tests/test-vconn.c | 10 +- utilities/ovs-ofctl.c | 148 +++++++------- vswitchd/bridge.c | 4 +- 42 files changed, 705 insertions(+), 1058 deletions(-) diff --git a/lib/bundle.c b/lib/bundle.c index e66ceed06..ee8079c81 100644 --- a/lib/bundle.c +++ b/lib/bundle.c @@ -175,7 +175,7 @@ bundle_parse__(const char *s, char **save_ptr, } ofpbuf_put(ofpacts, &slave_port, sizeof slave_port); - bundle = ofpacts->frame; + bundle = ofpacts->header; bundle->n_slaves++; } ofpact_update_len(ofpacts, &bundle->ofpact); diff --git a/lib/dpctl.c b/lib/dpctl.c index 125023cc4..4c4d1c32c 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -933,10 +933,10 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags, 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); } } @@ -946,10 +946,10 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags, } } 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) { @@ -1123,8 +1123,8 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p) 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); } } @@ -1133,7 +1133,7 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p) 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); } @@ -1246,7 +1246,7 @@ dpctl_parse_actions(int argc, const char *argv[], struct dpctl_params* dpctl_p) } 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); @@ -1390,12 +1390,11 @@ dpctl_normalize_actions(int argc, const char *argv[], } 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; @@ -1411,14 +1410,12 @@ dpctl_normalize_actions(int argc, const char *argv[], 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: @@ -1451,8 +1448,7 @@ dpctl_normalize_actions(int argc, const char *argv[], 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): ", @@ -1472,8 +1468,7 @@ dpctl_normalize_actions(int argc, const char *argv[], } 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); diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 531e5a36d..f01fecb68 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1573,19 +1573,19 @@ dp_netdev_flow_to_dpif_flow(const struct dp_netdev_flow *netdev_flow, 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); @@ -2711,13 +2711,14 @@ dp_netdev_upcall(struct dp_netdev_pmd_thread *pmd, struct dp_packet *packet_, 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); } @@ -2947,13 +2948,9 @@ fast_path_processing(struct dp_netdev_pmd_thread *pmd, * 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 @@ -2965,8 +2962,8 @@ fast_path_processing(struct dp_netdev_pmd_thread *pmd, 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); @@ -3183,8 +3180,7 @@ dp_execute_cb(void *aux_, struct dp_packet **packets, int cnt, 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]); } diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 15f83b910..93fd8a451 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -867,8 +867,8 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, struct netdev *netdev, } 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; @@ -1469,7 +1469,7 @@ dpif_netlink_flow_dump_next(struct dpif_flow_dump_thread *thread_, 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; @@ -1973,7 +1973,7 @@ parse_odp_packet(const struct dpif_netlink *dpif, struct ofpbuf *buf, 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); @@ -2393,7 +2393,7 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, 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); @@ -2561,7 +2561,7 @@ dpif_netlink_dp_from_ofpbuf(struct dpif_netlink_dp *dp, const struct ofpbuf *buf 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); @@ -2719,7 +2719,7 @@ dpif_netlink_flow_from_ofpbuf(struct dpif_netlink_flow *flow, 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); diff --git a/lib/dpif.c b/lib/dpif.c index 499def94b..ee71774a7 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -877,7 +877,7 @@ dpif_probe_feature(struct dpif *dpif, const char *name, * 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) { @@ -888,14 +888,14 @@ dpif_probe_feature(struct dpif *dpif, const char *name, } 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", @@ -1103,8 +1103,8 @@ dpif_execute_helper_cb(void *aux_, struct dp_packet **packets, int cnt, 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); diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 5323e07e3..3e4a91262 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -119,11 +119,11 @@ jsonrpc_run(struct jsonrpc *rpc) 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); @@ -257,7 +257,7 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg) 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; diff --git a/lib/learn.c b/lib/learn.c index 71c9780b8..99d56e601 100644 --- a/lib/learn.c +++ b/lib/learn.c @@ -164,8 +164,8 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow, } 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 @@ -380,7 +380,7 @@ learn_parse__(char *orig, char *arg, struct ofpbuf *ofpacts) 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); diff --git a/lib/learning-switch.c b/lib/learning-switch.c index 9ea70836e..bad354883 100644 --- a/lib/learning-switch.c +++ b/lib/learning-switch.c @@ -364,12 +364,12 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg) 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); @@ -378,7 +378,7 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg) break; case OFPTYPE_PACKET_IN: - process_packet_in(sw, ofpbuf_data(msg)); + process_packet_in(sw, msg->data); break; case OFPTYPE_FLOW_REMOVED: @@ -451,7 +451,7 @@ lswitch_process_packet(struct lswitch *sw, const struct ofpbuf *msg) 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); @@ -656,8 +656,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh) 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)) { @@ -675,8 +675,8 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh) 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); diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index f1da891ca..7fb103e6c 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -1140,8 +1140,7 @@ eth_from_packet_or_flow(const char *s) } /* 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; diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index e4f153f4d..df889d3eb 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -307,8 +307,8 @@ get_sock_pid_from_kernel(struct nl_sock *sock) 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; @@ -497,7 +497,7 @@ nl_sock_send__(struct nl_sock *sock, const struct ofpbuf *msg, 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 { @@ -506,21 +506,21 @@ nl_sock_send__(struct nl_sock *sock, const struct ofpbuf *msg, 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); } @@ -528,7 +528,7 @@ nl_sock_send__(struct nl_sock *sock, const struct ofpbuf *msg, } /* 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. * @@ -542,7 +542,7 @@ nl_sock_send(struct nl_sock *sock, const struct ofpbuf *msg, bool wait) } /* 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. * @@ -577,7 +577,7 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) 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; @@ -593,7 +593,7 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) * 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 @@ -610,11 +610,11 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) } 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 @@ -648,14 +648,14 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) 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; @@ -721,12 +721,12 @@ nl_sock_transact_multiple__(struct nl_sock *sock, 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 @@ -740,8 +740,8 @@ nl_sock_transact_multiple__(struct nl_sock *sock, 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); @@ -829,8 +829,8 @@ nl_sock_transact_multiple__(struct nl_sock *sock, 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. */ @@ -859,7 +859,7 @@ nl_sock_transact_multiple__(struct nl_sock *sock, /* 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); @@ -875,8 +875,8 @@ nl_sock_transact_multiple__(struct nl_sock *sock, 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); @@ -928,12 +928,12 @@ nl_sock_transact_multiple(struct nl_sock *sock, #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); @@ -1025,7 +1025,7 @@ nl_dump_refill(struct nl_dump *dump, struct ofpbuf *buffer) 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 @@ -1075,12 +1075,12 @@ nl_dump_next__(struct ofpbuf *reply, struct ofpbuf *buffer) * 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(). * @@ -1100,7 +1100,7 @@ nl_dump_next(struct nl_dump *dump, struct ofpbuf *reply, struct ofpbuf *buffer) * 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 @@ -1130,8 +1130,8 @@ nl_dump_next(struct nl_dump *dump, struct ofpbuf *reply, struct ofpbuf *buffer) } if (retval) { - ofpbuf_set_data(reply, NULL); - ofpbuf_set_size(reply, 0); + reply->data = NULL; + reply->size = 0; } return !retval; } @@ -1208,7 +1208,7 @@ pend_io_request(struct nl_sock *sock) 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 */ @@ -1445,7 +1445,7 @@ do_lookup_genl_family(const char *name, struct nlattr **attrs, /* 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)) @@ -1597,7 +1597,7 @@ nl_pool_release(struct nl_sock *sock) * 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'. diff --git a/lib/netlink.c b/lib/netlink.c index 52fc7ddb9..09723b24d 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -67,7 +67,7 @@ nl_msg_nlmsgerr(const struct ofpbuf *msg, int *errorp) 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; } @@ -113,7 +113,7 @@ nl_msg_put_nlmsghdr(struct ofpbuf *msg, { 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); @@ -152,7 +152,7 @@ nl_msg_put_genlmsghdr(struct ofpbuf *msg, size_t expected_payload, 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; @@ -432,7 +432,7 @@ nl_msg_push_string(struct ofpbuf *msg, uint16_t type, const char *value) 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; } @@ -443,7 +443,7 @@ void 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' @@ -459,17 +459,17 @@ nl_msg_put_nested(struct ofpbuf *msg, /* 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; @@ -477,8 +477,8 @@ nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg) } ofpbuf_clear(buffer); - ofpbuf_set_data(msg, NULL); - ofpbuf_set_size(msg, 0); + msg->data = NULL; + msg->size = 0; return NULL; } @@ -729,13 +729,13 @@ nl_policy_parse(const struct ofpbuf *msg, size_t nla_offset, 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) { @@ -799,7 +799,7 @@ nl_attr_find__(const struct nlattr *attrs, size_t size, uint16_t type) 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); } diff --git a/lib/nx-match.c b/lib/nx-match.c index c92467ad3..fd0e0c8bd 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -283,16 +283,16 @@ static enum ofperr 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 " @@ -316,7 +316,7 @@ nx_pull_header__(struct ofpbuf *b, bool allow_cookie, uint64_t *header, bad_len: VLOG_DBG_RL(&rl, "encountered partial (%"PRIu32"-byte) OXM entry", - ofpbuf_size(b)); + b->size); error: *header = 0; *field = NULL; @@ -343,7 +343,7 @@ nx_pull_entry__(struct ofpbuf *b, bool allow_cookie, uint64_t *header, 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; } @@ -453,8 +453,8 @@ nx_pull_raw(const uint8_t *p, unsigned int match_len, bool strict, } 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; @@ -505,7 +505,7 @@ nx_pull_match__(struct ofpbuf *b, unsigned int match_len, bool strict, 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; } } @@ -541,11 +541,11 @@ nx_pull_match_loose(struct ofpbuf *b, unsigned int match_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; } @@ -562,7 +562,7 @@ oxm_pull_match__(struct ofpbuf *b, bool strict, struct match *match) 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; } @@ -813,7 +813,7 @@ nx_put_raw(struct ofpbuf *b, enum ofp_version oxm, const struct match *match, 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; @@ -965,7 +965,7 @@ nx_put_raw(struct ofpbuf *b, enum ofp_version oxm, const struct match *match, } } - match_len = ofpbuf_size(b) - start_len; + match_len = b->size - start_len; return match_len; } @@ -1006,7 +1006,7 @@ oxm_put_match(struct ofpbuf *b, const struct match *match, { 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); @@ -1068,7 +1068,7 @@ nx_match_to_string(const uint8_t *p, unsigned int match_len) 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; @@ -1100,12 +1100,12 @@ nx_match_to_string(const uint8_t *p, unsigned int match_len) 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); @@ -1114,7 +1114,7 @@ nx_match_to_string(const uint8_t *p, unsigned int match_len) 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; @@ -1230,10 +1230,10 @@ static int 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, "")) { - /* Ensure that 'ofpbuf_data(b)' isn't actually null. */ + /* Ensure that 'b->data' isn't actually null. */ ofpbuf_prealloc_tailroom(b, 1); return 0; } @@ -1282,7 +1282,7 @@ nx_match_from_string_raw(const char *s, struct ofpbuf *b) s++; } - return ofpbuf_size(b) - start_len; + return b->size - start_len; } int @@ -1298,7 +1298,7 @@ oxm_match_from_string(const char *s, struct ofpbuf *b) { 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; @@ -1475,9 +1475,9 @@ nx_stack_pop(struct ofpbuf *stack) { 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); } diff --git a/lib/odp-util.c b/lib/odp-util.c index 7c85ececa..5dedf4b67 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -812,8 +812,8 @@ parse_odp_userspace_action(const char *s, struct ofpbuf *actions) 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; } } @@ -1154,7 +1154,7 @@ odp_actions_from_string(const char *s, const struct simap *port_names, return 0; } - old_size = ofpbuf_size(actions); + old_size = actions->size; for (;;) { int retval; @@ -1165,7 +1165,7 @@ odp_actions_from_string(const char *s, const struct simap *port_names, 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; @@ -2028,7 +2028,7 @@ generate_all_wildcard_mask(struct ofpbuf *ofp, const struct nlattr *key) nl_msg_end_nested(ofp, nested_mask); } - return ofpbuf_base(ofp); + return ofp->base; } int @@ -2830,7 +2830,7 @@ 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; @@ -2841,7 +2841,7 @@ odp_flow_from_string(const char *s, const struct simap *port_names, 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; @@ -3826,7 +3826,7 @@ odp_put_userspace_action(uint32_t pid, 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 diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 765725e1c..260d85474 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -781,7 +781,7 @@ decode_NXAST_RAW_OUTPUT_REG2(const struct nx_action_output_reg2 *naor, 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; } @@ -799,15 +799,15 @@ encode_OUTPUT_REG(const struct ofpact_output_reg *output_reg, 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); @@ -969,7 +969,7 @@ decode_bundle(bool load, const struct nx_action_bundle *nab, ofpbuf_put(ofpacts, &ofp_port, sizeof ofp_port); } - bundle = ofpacts->frame; + bundle = ofpacts->header; ofpact_update_len(ofpacts, &bundle->ofpact); if (!error) { @@ -1879,7 +1879,7 @@ decode_copy_field__(ovs_be16 src_offset, ovs_be16 dst_offset, ovs_be16 n_bits, 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; } @@ -1929,7 +1929,7 @@ decode_NXAST_RAW_REG_MOVE(const struct nx_action_reg_move *narm, 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; } @@ -1946,13 +1946,13 @@ encode_REG_MOVE(const struct ofpact_reg_move *move, * 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 @@ -1961,7 +1961,7 @@ encode_REG_MOVE(const struct ofpact_reg_move *move, 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 { @@ -2104,7 +2104,7 @@ decode_ofpat_set_field(const struct ofp12_action_set_field *oasf, 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; } @@ -2205,7 +2205,7 @@ decode_NXAST_RAW_REG_LOAD2(const struct nx_action_reg_load2 *narl, 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; } @@ -2223,13 +2223,13 @@ ofpact_put_set_field(struct ofpbuf *openflow, enum ofp_version ofp_version, { 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); } @@ -2266,10 +2266,10 @@ set_field_to_nxast(const struct ofpact_set_field *sf, struct ofpbuf *openflow) 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 { @@ -2412,10 +2412,10 @@ set_field_to_set_field(const struct ofpact_set_field *sf, 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); } @@ -2609,9 +2609,9 @@ decode_stack_action(const struct nx_action_stack *nasp, 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; } @@ -2729,7 +2729,7 @@ decode_OFPAT_RAW_DEC_NW_TTL(struct ofpbuf *out) 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; } @@ -2763,7 +2763,7 @@ decode_NXAST_RAW_DEC_TTL_CNT_IDS(const struct nx_action_cnt_ids *nac_ids, 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); @@ -2803,7 +2803,7 @@ parse_noargs_dec_ttl(struct ofpbuf *ofpacts) 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); } @@ -2825,7 +2825,7 @@ parse_DEC_TTL(char *arg, struct ofpbuf *ofpacts, uint16_t id = atoi(cntr); ofpbuf_put(ofpacts, &id, sizeof id); - ids = ofpacts->frame; + ids = ofpacts->header; ids->n_controllers++; } if (!ids->n_controllers) { @@ -3772,7 +3772,7 @@ decode_NXAST_RAW_LEARN(const struct nx_action_learn *nal, } spec = ofpbuf_put_zeros(ofpacts, sizeof *spec); - learn = ofpacts->frame; + learn = ofpacts->header; learn->n_specs++; spec->src_type = header & NX_LEARN_SRC_MASK; @@ -3853,7 +3853,7 @@ encode_LEARN(const struct ofpact_learn *learn, 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); @@ -4141,23 +4141,23 @@ static void 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 @@ -4184,7 +4184,7 @@ parse_NOTE(const char *arg, struct ofpbuf *ofpacts, } ofpbuf_put(ofpacts, &byte, 1); - note = ofpacts->frame; + note = ofpacts->header; note->length++; arg += 2; @@ -4400,7 +4400,7 @@ encode_WRITE_ACTIONS(const struct ofpact_nest *actions, 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, @@ -4420,7 +4420,7 @@ parse_WRITE_ACTIONS(char *arg, struct ofpbuf *ofpacts, /* 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. */ @@ -4438,7 +4438,7 @@ parse_WRITE_ACTIONS(char *arg, struct ofpbuf *ofpacts, /* 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); @@ -4600,8 +4600,8 @@ ofpacts_decode(const void *actions, size_t actions_len, 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; @@ -4643,7 +4643,7 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow, 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; } @@ -4653,7 +4653,7 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow, 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); @@ -4836,7 +4836,7 @@ ofpacts_copy_last(struct ofpbuf *out, const struct ofpbuf *in, 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; } @@ -4855,7 +4855,7 @@ ofpacts_copy_all(struct ofpbuf *out, const struct ofpbuf *in, { 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); } @@ -4914,7 +4914,7 @@ ofpacts_decode_for_action_set(const struct ofp_action_header *in, { 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); @@ -4922,7 +4922,7 @@ ofpacts_decode_for_action_set(const struct ofp_action_header *in, 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; @@ -5234,7 +5234,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, 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; } @@ -5279,7 +5279,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, 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], @@ -5290,7 +5290,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, 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; @@ -5313,7 +5313,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow, 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) { @@ -5331,10 +5331,10 @@ ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs) 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; } } @@ -5754,12 +5754,12 @@ ofpacts_put_openflow_actions(const struct ofpact ofpacts[], size_t ofpacts_len, 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 @@ -5787,7 +5787,7 @@ ofpacts_put_openflow_instructions(const struct ofpact ofpacts[], 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 { @@ -6124,7 +6124,8 @@ ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len) 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; } @@ -6147,7 +6148,7 @@ ofpact_init(struct ofpact *ofpact, enum ofpact_type type, size_t len) 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; } @@ -6164,7 +6165,7 @@ ofpact_update_len(struct ofpbuf *ofpacts, struct ofpact *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); } @@ -6275,12 +6276,12 @@ ofpacts_parse__(char *str, struct ofpbuf *ofpacts, } 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)); @@ -6295,11 +6296,11 @@ static char * OVS_WARN_UNUSED_RESULT 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; } @@ -6547,13 +6548,13 @@ static enum ofperr 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; } @@ -6565,9 +6566,9 @@ ofpact_pull_raw(struct ofpbuf *buf, enum ofp_version ofp_version, } 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) { @@ -6664,9 +6665,9 @@ pad_ofpat(struct ofpbuf *openflow, size_t start_ofs) { 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); } diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c index ce85f6758..615910520 100644 --- a/lib/ofp-errors.c +++ b/lib/ofp-errors.c @@ -327,8 +327,8 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload) /* 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; } diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index 364ce7616..4d14ff963 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -372,7 +372,7 @@ ofpraw_decode_assert(const struct ofp_header *oh) } /* 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'. * @@ -382,8 +382,8 @@ ofpraw_decode_assert(const struct ofp_header *oh) * 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) { @@ -400,12 +400,12 @@ 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; } @@ -417,8 +417,8 @@ ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg) 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) { @@ -593,7 +593,7 @@ ofpraw_alloc_stats_reply(const struct ofp_header *request, * 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 @@ -665,17 +665,17 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, 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); @@ -683,17 +683,17 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, } 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); @@ -704,18 +704,18 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, } 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 { @@ -792,7 +792,7 @@ ofptype_decode(enum ofptype *typep, const struct ofp_header *oh) } /* 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'. * @@ -802,8 +802,8 @@ ofptype_decode(enum ofptype *typep, const struct ofp_header *oh) * 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) { @@ -826,12 +826,12 @@ ofptype_from_ofpraw(enum ofpraw raw) } /* 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 @@ -882,7 +882,7 @@ ofpmp_reserve(struct ovs_list *replies, size_t len) { 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 { @@ -890,16 +890,16 @@ ofpmp_reserve(struct ovs_list *replies, size_t len) 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; } @@ -929,11 +929,11 @@ ofpmp_postappend(struct ovs_list *replies, size_t start_ofs) 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; } } @@ -943,7 +943,7 @@ enum ofp_version 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; } @@ -957,7 +957,7 @@ ofpmp_decode_raw(struct ovs_list *replies) 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; } diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 6fc5af03f..8d05681d6 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -452,7 +452,7 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string, 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; @@ -468,7 +468,7 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string, return error; } - fm->ofpacts_len = ofpbuf_size(&ofpacts); + fm->ofpacts_len = ofpacts.size; fm->ofpacts = ofpbuf_steal_data(&ofpacts); } else { fm->ofpacts_len = 0; @@ -1151,8 +1151,8 @@ parse_bucket_str(struct ofputil_bucket *bucket, char *str_, 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; } diff --git a/lib/ofp-print.c b/lib/ofp-print.c index f3a8c1475..b7c9a2641 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1355,9 +1355,9 @@ ofp_print_error_msg(struct ds *string, const struct ofp_header *oh) 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); } diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 54373390c..d5927a9f3 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -75,20 +75,20 @@ ofputil_pull_property__(struct ofpbuf *msg, struct ofpbuf *property, 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; @@ -124,7 +124,7 @@ log_property(bool loose, const char *message, ...) 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); @@ -139,8 +139,8 @@ end_property(struct ofpbuf *msg, size_t start_ofs) 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 @@ -366,10 +366,10 @@ enum ofperr 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; } @@ -379,7 +379,7 @@ ofputil_pull_ofp11_match(struct ofpbuf *buf, struct match *match, 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); @@ -1353,15 +1353,15 @@ ofputil_decode_hello(const struct ofp_header *oh, uint32_t *allowed_versions) 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; @@ -1791,13 +1791,13 @@ ofputil_decode_flow_mod(struct ofputil_flow_mod *fm, } } - 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); @@ -1895,9 +1895,9 @@ ofputil_decode_meter_mod(const struct ofp_header *oh, 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; } @@ -1973,14 +1973,14 @@ ofputil_append_meter_config(struct ovs_list *replies, 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); } @@ -2035,11 +2035,11 @@ ofputil_decode_meter_config(struct ofpbuf *msg, 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; } @@ -2047,7 +2047,7 @@ ofputil_decode_meter_config(struct ofpbuf *msg, 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; } @@ -2059,7 +2059,7 @@ ofputil_decode_meter_config(struct ofpbuf *msg, } mc->meter_id = ntohl(omc->meter_id); mc->flags = ntohs(omc->flags); - mc->bands = ofpbuf_data(bands); + mc->bands = bands->data; return 0; } @@ -2111,11 +2111,11 @@ ofputil_decode_meter_stats(struct ofpbuf *msg, 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; } @@ -2123,7 +2123,7 @@ ofputil_decode_meter_stats(struct ofpbuf *msg, 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; } @@ -2139,7 +2139,7 @@ ofputil_decode_meter_stats(struct ofpbuf *msg, 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; } @@ -2299,7 +2299,7 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm, 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); @@ -2373,7 +2373,7 @@ ofputil_decode_nxst_flow_request(struct ofputil_flow_stats_request *fsr, if (error) { return error; } - if (ofpbuf_size(b)) { + if (b->size) { return OFPERR_OFPBRC_BAD_LEN; } @@ -2429,12 +2429,12 @@ ofputil_decode_queue_get_config_request(const struct ofp_header *oh, 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); } @@ -2503,36 +2503,36 @@ void 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 @@ -2591,14 +2591,14 @@ ofputil_pull_queue_get_config_reply(struct ofpbuf *reply, 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; @@ -2621,7 +2621,7 @@ ofputil_pull_queue_get_config_reply(struct ofpbuf *reply, 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; @@ -2634,7 +2634,7 @@ ofputil_pull_queue_get_config_reply(struct ofpbuf *reply, 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; } @@ -2676,10 +2676,10 @@ ofputil_decode_flow_stats_request(struct ofputil_flow_stats_request *fsr, 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); @@ -2760,7 +2760,7 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr, 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; @@ -2805,15 +2805,14 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs, 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) { @@ -2824,7 +2823,7 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs, 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; } @@ -2873,7 +2872,7 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs, 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; } @@ -2906,7 +2905,7 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs, 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; } @@ -2952,8 +2951,8 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs, 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; } @@ -2976,7 +2975,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs, 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); @@ -2989,7 +2988,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs, 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); @@ -3018,7 +3017,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs, 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); @@ -3042,7 +3041,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs, 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); @@ -3108,7 +3107,7 @@ ofputil_decode_aggregate_stats_reply(struct ofputil_aggregate_stats *stats, 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); @@ -3175,7 +3174,7 @@ ofputil_decode_flow_removed(struct ofputil_flow_removed *fr, if (error) { return error; } - if (ofpbuf_size(&b)) { + if (b.size) { return OFPERR_OFPBRC_BAD_LEN; } @@ -3266,7 +3265,7 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr, 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; @@ -3291,8 +3290,8 @@ static void 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; @@ -3355,7 +3354,7 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin, 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; @@ -3367,8 +3366,8 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin, 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); @@ -3486,7 +3485,7 @@ ofputil_encode_nx_packet_in(const struct ofputil_packet_in *pin) 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; @@ -3550,7 +3549,7 @@ ofputil_encode_ofp12_packet_in(const struct ofputil_packet_in *pin, 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; @@ -3706,12 +3705,12 @@ ofputil_decode_packet_out(struct ofputil_packet_out *po, 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; @@ -3833,9 +3832,9 @@ static enum ofperr 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; } @@ -3864,7 +3863,7 @@ ofputil_pull_ofp14_port(struct ofputil_phy_port *pp, struct ofpbuf *msg) } 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; @@ -3880,7 +3879,7 @@ ofputil_pull_ofp14_port(struct ofputil_phy_port *pp, struct ofpbuf *msg) 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; @@ -4065,7 +4064,7 @@ ofputil_append_port_desc_stats_reply(const struct ofputil_phy_port *pp, 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); @@ -4163,7 +4162,7 @@ ofputil_decode_switch_features(const struct ofp_header *oh, 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) { @@ -4183,7 +4182,7 @@ ofputil_switch_features_has_ports(struct ofpbuf *b) /* 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; } @@ -4260,16 +4259,16 @@ void 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; } } } @@ -4349,9 +4348,9 @@ static enum ofperr 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; } @@ -4372,7 +4371,7 @@ ofputil_decode_port_mod(const struct ofp_header *oh, 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); @@ -4380,7 +4379,7 @@ ofputil_decode_port_mod(const struct ofp_header *oh, 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); @@ -4407,7 +4406,7 @@ ofputil_decode_port_mod(const struct ofp_header *oh, 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; @@ -4532,7 +4531,7 @@ parse_action_bitmap(struct ofpbuf *payload, enum ofp_version ofp_version, { uint32_t types = 0; - while (ofpbuf_size(payload) > 0) { + while (payload->size > 0) { uint16_t type; enum ofperr error; @@ -4553,7 +4552,7 @@ static enum ofperr 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; @@ -4589,8 +4588,8 @@ parse_table_features_next_table(struct ofpbuf *payload, 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; } @@ -4606,7 +4605,7 @@ parse_oxms(struct ofpbuf *payload, bool loose, 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; @@ -4658,22 +4657,22 @@ ofputil_decode_table_features(struct ofpbuf *msg, 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); @@ -4690,7 +4689,7 @@ ofputil_decode_table_features(struct ofpbuf *msg, 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; @@ -4887,7 +4886,7 @@ ofputil_append_table_features_reply(const struct ofputil_table_features *tf, { 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); @@ -4907,7 +4906,7 @@ ofputil_append_table_features_reply(const struct ofputil_table_features *tf, 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); } @@ -4980,7 +4979,7 @@ ofputil_decode_table_mod(const struct ofp_header *oh, 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, @@ -5063,7 +5062,7 @@ ofputil_decode_role_message(const struct ofp_header *oh, 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) && @@ -5084,7 +5083,7 @@ ofputil_decode_role_message(const struct ofp_header *oh, } } 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); @@ -5182,7 +5181,7 @@ ofputil_decode_role_status(const struct ofp_header *oh, 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) && @@ -5414,7 +5413,7 @@ ofputil_append_table_stats_reply(struct ofpbuf *reply, 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); @@ -5577,12 +5576,12 @@ ofputil_decode_table_stats_reply(struct ofpbuf *msg, { 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; } @@ -5628,18 +5627,18 @@ ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *rq, 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; } @@ -5672,11 +5671,11 @@ ofputil_append_flow_monitor_request( 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)); @@ -5712,24 +5711,24 @@ ofputil_decode_flow_update(struct ofputil_flow_update *update, 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; } @@ -5780,8 +5779,8 @@ ofputil_decode_flow_update(struct ofputil_flow_update *update, 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, @@ -5792,7 +5791,7 @@ ofputil_decode_flow_update(struct ofputil_flow_update *update, 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; } @@ -5838,7 +5837,7 @@ ofputil_append_flow_update(const struct ofputil_flow_update *update, 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; @@ -5864,7 +5863,7 @@ ofputil_append_flow_update(const struct ofputil_flow_update *update, } 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); @@ -5890,14 +5889,14 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po, 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; } @@ -5913,7 +5912,7 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po, 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); @@ -5952,8 +5951,8 @@ make_echo_reply(const struct ofp_header *rq) 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; } @@ -6254,7 +6253,7 @@ ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *b, } 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(); } @@ -6685,9 +6684,9 @@ static enum ofperr 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; } @@ -6714,7 +6713,7 @@ ofputil_pull_ofp14_port_stats(struct ofputil_port_stats *ops, } 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; @@ -6740,7 +6739,7 @@ ofputil_pull_ofp14_port_stats(struct ofputil_port_stats *ops, 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; @@ -6802,14 +6801,13 @@ ofputil_decode_port_stats(struct ofputil_port_stats *ps, struct ofpbuf *msg) 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); @@ -6843,7 +6841,7 @@ ofputil_decode_port_stats(struct ofputil_port_stats *ps, struct ofpbuf *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; } @@ -7264,14 +7262,13 @@ ofputil_decode_group_stats_reply(struct ofpbuf *msg, 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; } @@ -7297,7 +7294,7 @@ ofputil_decode_group_stats_reply(struct ofpbuf *msg, 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); @@ -7316,7 +7313,7 @@ ofputil_decode_group_stats_reply(struct ofpbuf *msg, 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; } @@ -7336,12 +7333,12 @@ ofputil_put_ofp11_bucket(const struct ofputil_bucket *bucket, 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); @@ -7383,13 +7380,13 @@ ofputil_put_ofp15_bucket(const struct ofputil_bucket *bucket, 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), @@ -7409,7 +7406,7 @@ ofputil_put_ofp15_bucket(const struct ofputil_bucket *bucket, } 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); } @@ -7425,13 +7422,13 @@ ofputil_append_ofp11_group_desc_reply(const struct ofputil_group_desc *gds, 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); @@ -7449,18 +7446,18 @@ ofputil_append_ofp15_group_desc_reply(const struct ofputil_group_desc *gds, 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); } @@ -7551,7 +7548,7 @@ ofputil_pull_ofp11_buckets(struct ofpbuf *msg, size_t buckets_length, 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); } @@ -7562,11 +7559,11 @@ static enum ofperr 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; } @@ -7579,11 +7576,11 @@ static enum ofperr 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; } @@ -7649,7 +7646,7 @@ ofputil_pull_ofp15_buckets(struct ofpbuf *msg, size_t buckets_length, 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; @@ -7703,7 +7700,7 @@ ofputil_pull_ofp15_buckets(struct ofpbuf *msg, size_t buckets_length, } 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; @@ -7732,25 +7729,25 @@ ofputil_decode_ofp11_group_desc_reply(struct ofputil_group_desc *gd, 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; @@ -7768,25 +7765,25 @@ ofputil_decode_ofp15_group_desc_reply(struct ofputil_group_desc *gd, 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; @@ -7844,7 +7841,7 @@ ofputil_encode_ofp11_group_mod(enum ofp_version ofp_version, 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) { @@ -7869,7 +7866,7 @@ ofputil_encode_ofp15_group_mod(enum ofp_version ofp_version, 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) { @@ -7908,7 +7905,7 @@ ofputil_encode_ofp15_group_mod(enum ofp_version ofp_version, 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; @@ -8008,7 +8005,7 @@ ofputil_pull_ofp11_group_mod(struct ofpbuf *msg, enum ofp_version ofp_version, 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. */ @@ -8067,9 +8064,9 @@ ofputil_pull_ofp15_group_mod(struct ofpbuf *msg, enum ofp_version ofp_version, } 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; } @@ -8314,7 +8311,7 @@ ofputil_pull_ofp14_queue_stats(struct ofputil_queue_stats *oqs, } 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); @@ -8340,14 +8337,13 @@ ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg) 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); @@ -8381,7 +8377,7 @@ ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *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; } @@ -8481,7 +8477,7 @@ ofputil_decode_bundle_ctrl(const struct ofp_header *oh, 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); @@ -8611,9 +8607,9 @@ ofputil_decode_bundle_add(const struct ofp_header *oh, 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) { diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 38862617a..7510edb9b 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -27,9 +27,8 @@ ofpbuf_init__(struct ofpbuf *b, size_t allocated, enum ofpbuf_source source) { 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); } @@ -37,9 +36,9 @@ static void 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); } @@ -105,19 +104,7 @@ void 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' @@ -134,15 +121,7 @@ ofpbuf_uninit(struct ofpbuf *b) { 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); } } } @@ -176,7 +155,7 @@ ofpbuf_new_with_headroom(size_t size, size_t headroom) } /* 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) @@ -191,19 +170,16 @@ ofpbuf_clone_with_headroom(const struct ofpbuf *buffer, size_t headroom) { 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; } @@ -231,7 +207,7 @@ static void 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); @@ -239,7 +215,7 @@ ofpbuf_copy__(struct ofpbuf *b, uint8_t *new_base, 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' @@ -250,19 +226,16 @@ ofpbuf_resize__(struct ofpbuf *b, size_t new_headroom, size_t 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; @@ -280,16 +253,16 @@ ofpbuf_resize__(struct ofpbuf *b, size_t new_headroom, size_t new_tailroom) } 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; } } @@ -323,8 +296,6 @@ ofpbuf_prealloc_headroom(struct ofpbuf *b, size_t size) 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); @@ -336,8 +307,8 @@ ofpbuf_trim(struct ofpbuf *b) 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); } } @@ -353,9 +324,9 @@ ofpbuf_shift(struct ofpbuf *b, int delta) : 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; } } @@ -368,7 +339,7 @@ ofpbuf_put_uninit(struct ofpbuf *b, size_t size) void *p; ofpbuf_prealloc_tailroom(b, size); p = ofpbuf_tail(b); - ofpbuf_set_size(b, ofpbuf_size(b) + size); + b->size += size; return p; } @@ -402,7 +373,7 @@ ofpbuf_put(struct ofpbuf *b, const void *p, size_t size) 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; @@ -411,7 +382,7 @@ ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n) 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); } @@ -426,21 +397,9 @@ ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n) 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 @@ -450,9 +409,9 @@ void * 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 @@ -484,18 +443,17 @@ void * 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; } @@ -508,9 +466,9 @@ ofpbuf_to_string(const struct ofpbuf *b, size_t maxbytes) 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); } @@ -526,42 +484,3 @@ ofpbuf_list_delete(struct ovs_list *list) 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; -} diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h index 8067779d8..80b0dc4aa 100644 --- a/lib/ofpbuf.h +++ b/lib/ofpbuf.h @@ -22,7 +22,6 @@ #include "list.h" #include "packets.h" #include "util.h" -#include "netdev-dpdk.h" #ifdef __cplusplus extern "C" { @@ -32,90 +31,42 @@ enum OVS_PACKED_ENUM ofpbuf_source { 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); @@ -140,8 +91,6 @@ void *ofpbuf_put_zeros(struct ofpbuf *, 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); @@ -166,26 +115,10 @@ void ofpbuf_list_delete(struct ovs_list *); static inline bool ofpbuf_equal(const struct ofpbuf *, const struct ofpbuf *); -/* 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); } @@ -196,7 +129,7 @@ static inline void ofpbuf_delete(struct ofpbuf *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 @@ -204,21 +137,21 @@ static inline void *ofpbuf_at(const struct ofpbuf *b, size_t offset, 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 @@ -227,7 +160,7 @@ static inline void *ofpbuf_end(const struct ofpbuf *b) * 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 @@ -240,18 +173,17 @@ static inline size_t ofpbuf_tailroom(const struct ofpbuf *b) /* 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; } @@ -260,8 +192,7 @@ static inline void *ofpbuf_pull(struct ofpbuf *b, size_t size) * 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) @@ -271,189 +202,8 @@ 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 diff --git a/lib/rconn.c b/lib/rconn.c index 625cb6822..6692b4603 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -745,11 +745,11 @@ rconn_send__(struct rconn *rc, struct ofpbuf *b, 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); @@ -1113,19 +1113,19 @@ try_send(struct rconn *rc) 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); @@ -1226,9 +1226,9 @@ flush_queue(struct rconn *rc) } 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); @@ -1338,7 +1338,7 @@ is_admitted_msg(const struct ofpbuf *b) enum ofptype type; enum ofperr error; - error = ofptype_decode(&type, ofpbuf_data(b)); + error = ofptype_decode(&type, b->data); if (error) { return false; } diff --git a/lib/route-table.c b/lib/route-table.c index 1459b7d54..a5a42ca83 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -193,7 +193,7 @@ route_table_parse(struct ofpbuf *buf, struct route_table_msg *change) 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) { diff --git a/lib/rtnetlink-link.c b/lib/rtnetlink-link.c index 1c12562c5..308338fca 100644 --- a/lib/rtnetlink-link.c +++ b/lib/rtnetlink-link.c @@ -58,7 +58,7 @@ rtnetlink_link_parse(struct ofpbuf *buf, 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; diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c index 478945d0d..759d6ba33 100644 --- a/lib/tnl-ports.c +++ b/lib/tnl-ports.c @@ -169,15 +169,15 @@ tnl_port_show(struct unixctl_conn *conn, int argc OVS_UNUSED, 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); diff --git a/lib/vconn-stream.c b/lib/vconn-stream.c index eaf459f56..0ccc99fd4 100644 --- a/lib/vconn-stream.c +++ b/lib/vconn-stream.c @@ -103,7 +103,7 @@ vconn_stream_close(struct vconn *vconn) 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)); } @@ -126,14 +126,14 @@ vconn_stream_recv__(struct vconn_stream *s, int rx_len) 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; } @@ -156,7 +156,7 @@ vconn_stream_recv(struct vconn *vconn, struct ofpbuf **bufferp) } /* 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; @@ -164,12 +164,12 @@ vconn_stream_recv(struct vconn *vconn, struct ofpbuf **bufferp) } /* 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; @@ -199,8 +199,8 @@ vconn_stream_send(struct vconn *vconn, struct ofpbuf *buffer) 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) { @@ -225,7 +225,7 @@ vconn_stream_run(struct vconn *vconn) 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)); @@ -234,7 +234,7 @@ vconn_stream_run(struct vconn *vconn) } } else if (retval > 0) { ofpbuf_pull(s->txbuf, retval); - if (!ofpbuf_size(s->txbuf)) { + if (!s->txbuf->size) { vconn_stream_clear_txbuf(s); return; } diff --git a/lib/vconn.c b/lib/vconn.c index 10e2deca0..5a2860304 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -456,16 +456,16 @@ vcs_recv_hello(struct vconn *vconn) 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); } @@ -495,7 +495,7 @@ vcs_recv_hello(struct vconn *vconn) 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); @@ -598,11 +598,11 @@ vconn_recv(struct vconn *vconn, struct ofpbuf **msgp) 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 && @@ -641,7 +641,7 @@ do_recv(struct vconn *vconn, struct ofpbuf **msgp) 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); } @@ -674,14 +674,14 @@ do_send(struct vconn *vconn, struct ofpbuf *msg) { 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", @@ -763,7 +763,7 @@ vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp) *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; @@ -790,7 +790,7 @@ int 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; @@ -824,7 +824,7 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request, *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); @@ -833,7 +833,7 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *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); @@ -852,7 +852,7 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request, 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 " diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 09771a6bd..de3665a79 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -1979,8 +1979,8 @@ connmgr_flushed(struct connmgr *mgr) 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); } diff --git a/ofproto/fail-open.c b/ofproto/fail-open.c index c60f6b9e9..c8d553e46 100644 --- a/ofproto/fail-open.c +++ b/ofproto/fail-open.c @@ -232,7 +232,7 @@ fail_open_flushed(struct fail_open *fo) 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); } diff --git a/ofproto/in-band.c b/ofproto/in-band.c index 01950facc..902a86ca1 100644 --- a/ofproto/in-band.c +++ b/ofproto/in-band.c @@ -390,7 +390,7 @@ in_band_run(struct in_band *ib) 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: diff --git a/ofproto/netflow.c b/ofproto/netflow.c index 99bd6b8e4..0470443bb 100644 --- a/ofproto/netflow.c +++ b/ofproto/netflow.c @@ -110,7 +110,7 @@ gen_netflow_rec(struct netflow *nf, struct netflow_flow *nf_flow, 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); @@ -126,7 +126,7 @@ gen_netflow_rec(struct netflow *nf, struct netflow_flow *nf_flow, 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++); @@ -298,9 +298,9 @@ netflow_run__(struct netflow *nf) OVS_REQUIRES(mutex) 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) { @@ -339,7 +339,7 @@ netflow_wait(struct netflow *nf) OVS_EXCLUDED(mutex) 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); diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 2220c9bf4..262f1d5a0 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -980,8 +980,8 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall, 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, @@ -1033,8 +1033,8 @@ upcall_cb(const struct dp_packet *packet, const struct flow *flow, ovs_u128 *ufi } 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)) { @@ -1170,7 +1170,7 @@ handle_upcalls(struct udpif *udpif, struct upcall *upcalls, * 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)); } @@ -1200,19 +1200,19 @@ handle_upcalls(struct udpif *udpif, struct upcall *upcalls, 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; } @@ -1329,8 +1329,7 @@ ukey_create_from_upcall(const struct upcall *upcall) 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); @@ -1646,8 +1645,8 @@ revalidate_ukey(struct udpif *udpif, struct udpif_key *ukey, } 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, diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 419e86125..647fa1148 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2736,13 +2736,13 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_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; } } @@ -2926,9 +2926,9 @@ xlate_resubmit_resource_check(struct xlate_ctx *ctx) 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; @@ -3008,7 +3008,7 @@ xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket) 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); @@ -3211,8 +3211,8 @@ execute_controller_action(struct xlate_ctx *ctx, int len, 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); @@ -3754,7 +3754,7 @@ xlate_action_set(struct xlate_ctx *ctx) 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); } @@ -4215,8 +4215,7 @@ xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src) 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); } static struct skb_priority_to_dscp * @@ -4267,8 +4266,8 @@ actions_output_to_local_port(const struct xlate_ctx *ctx) 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; @@ -4322,8 +4321,7 @@ count_output_actions(const struct ofpbuf *odp_actions) 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++; } @@ -4341,7 +4339,7 @@ static bool 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 @@ -4524,7 +4522,7 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout) 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); @@ -4533,11 +4531,11 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout) * 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); } @@ -4554,7 +4552,7 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout) } } - 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 diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 867f450a1..57a6f3e62 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1096,7 +1096,7 @@ check_ufid(struct dpif_backer *backer) 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); @@ -1149,8 +1149,8 @@ check_variable_length_userdata(struct dpif_backer *backer) /* 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; @@ -1244,8 +1244,8 @@ check_masked_set_action(struct dpif_backer *backer) /* 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; @@ -3615,8 +3615,8 @@ ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto, 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; @@ -4496,8 +4496,7 @@ trace_format_odp(struct ds *result, int level, const char *title, 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'); } @@ -4639,8 +4638,7 @@ parse_flow_and_packet(int argc, const char *argv[], 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; } @@ -4789,11 +4787,11 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, 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); } @@ -4806,7 +4804,7 @@ ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc, } 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: @@ -4856,8 +4854,8 @@ ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow, 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; @@ -5503,8 +5501,8 @@ ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto, 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) { diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index b74653701..61fccb44d 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -3331,7 +3331,7 @@ handle_table_features_request(struct ofconn *ofconn, 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; } @@ -6293,7 +6293,7 @@ static enum ofperr 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; @@ -6474,7 +6474,7 @@ handle_openflow(struct ofconn *ofconn, const struct ofpbuf *ofp_msg) { 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); } diff --git a/tests/test-bundle.c b/tests/test-bundle.c index 83893ffa6..4f6eb0c1f 100644 --- a/tests/test-bundle.c +++ b/tests/test-bundle.c @@ -76,7 +76,7 @@ parse_bundle_actions(char *actions) ovs_fatal(0, "%s", error); } - action = ofpbuf_data(&ofpacts); + action = ofpacts.data; bundle = ofpact_get_BUNDLE(xmemdup(action, action->len)); ofpbuf_uninit(&ofpacts); diff --git a/tests/test-netflow.c b/tests/test-netflow.c index b918d1550..d9f29d1c2 100644 --- a/tests/test-netflow.c +++ b/tests/test-netflow.c @@ -161,8 +161,8 @@ print_netflow(struct ofpbuf *buf) 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); } } @@ -214,7 +214,7 @@ test_netflow_main(int argc, char *argv[]) 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); diff --git a/tests/test-odp.c b/tests/test-odp.c index 48ad56aca..4daf47287 100644 --- a/tests/test-odp.c +++ b/tests/test-odp.c @@ -55,7 +55,7 @@ parse_keys(bool wc_keys) 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; @@ -78,9 +78,9 @@ parse_keys(bool wc_keys) 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; } } @@ -88,10 +88,10 @@ parse_keys(bool wc_keys) /* 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); @@ -126,7 +126,7 @@ parse_actions(void) /* 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); @@ -184,8 +184,8 @@ parse_filter(char *filter_parse) 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); @@ -201,8 +201,8 @@ parse_filter(char *filter_parse) } /* 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); diff --git a/tests/test-sflow.c b/tests/test-sflow.c index 4f7940db9..3e3c45014 100644 --- a/tests/test-sflow.c +++ b/tests/test-sflow.c @@ -607,13 +607,13 @@ static void 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); @@ -669,7 +669,7 @@ test_sflow_main(int argc, char *argv[]) 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); diff --git a/tests/test-vconn.c b/tests/test-vconn.c index 187f6f52e..c3e8a3474 100644 --- a/tests/test-vconn.c +++ b/tests/test-vconn.c @@ -368,7 +368,7 @@ test_send_plain_hello(int argc OVS_UNUSED, char *argv[]) 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); } @@ -386,7 +386,7 @@ test_send_long_hello(int argc OVS_UNUSED, char *argv[]) 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); } @@ -400,7 +400,7 @@ test_send_echo_hello(int argc OVS_UNUSED, char *argv[]) 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); } @@ -426,8 +426,8 @@ test_send_invalid_version_hello(int argc OVS_UNUSED, char *argv[]) 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); } diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 9b78a42be..44c52751c 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -505,7 +505,7 @@ dump_transaction(struct vconn *vconn, struct ofpbuf *request) 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); } @@ -524,13 +524,13 @@ dump_trivial_transaction(const char *vconn_name, enum ofpraw raw) 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); @@ -540,20 +540,20 @@ dump_stats_transaction(struct vconn *vconn, struct ofpbuf *request) 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 { @@ -593,7 +593,7 @@ transact_multiple_noreply(struct vconn *vconn, struct ovs_list *requests) 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); @@ -664,7 +664,7 @@ ofctl_show(int argc OVS_UNUSED, char *argv[]) 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) { @@ -731,8 +731,8 @@ fetch_port_by_features(struct vconn *vconn, 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)); } @@ -783,7 +783,7 @@ fetch_port_by_stats(struct vconn *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) { @@ -791,9 +791,9 @@ fetch_port_by_stats(struct vconn *vconn, 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; @@ -802,7 +802,7 @@ fetch_port_by_stats(struct vconn *vconn, 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)); } @@ -906,7 +906,7 @@ try_set_protocol(struct vconn *vconn, enum ofputil_protocol want, 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); @@ -1040,7 +1040,7 @@ ofctl_dump_flows(int argc, char *argv[]) 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; @@ -1310,13 +1310,13 @@ openflow_from_hex(const char *hex, struct ofpbuf **msgp) 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"; } @@ -1349,7 +1349,7 @@ ofctl_send(struct unixctl_conn *conn, int argc, } 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) { @@ -1498,8 +1498,8 @@ monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests) 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) { @@ -1514,7 +1514,7 @@ monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests) 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"); @@ -1594,7 +1594,7 @@ ofctl_monitor(int argc, char *argv[]) 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); @@ -1665,7 +1665,7 @@ ofctl_probe(int argc OVS_UNUSED, char *argv[]) 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); @@ -1691,8 +1691,8 @@ ofctl_packet_out(int argc, char *argv[]) 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++) { @@ -1897,7 +1897,7 @@ ofctl_ofp_parse(int argc OVS_UNUSED, char *argv[]) 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); @@ -2022,18 +2022,18 @@ ofctl_ping(int argc, char *argv[]) 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); @@ -2475,12 +2475,12 @@ recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, 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)); } } @@ -2493,7 +2493,7 @@ recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, return true; case EOF: - more = ofpmp_more(reply->frame); + more = ofpmp_more(reply->header); ofpbuf_delete(reply); reply = NULL; if (!more) { @@ -2530,7 +2530,7 @@ read_flows_from_switch(struct vconn *vconn, 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; @@ -2829,7 +2829,7 @@ ofctl_parse_flows__(struct ofputil_flow_mod *fms, size_t n_fms, 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)); @@ -2922,15 +2922,14 @@ ofctl_parse_nxm__(bool oxm, enum ofp_version version) } 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", @@ -3027,11 +3026,11 @@ ofctl_parse_actions__(const char *version_s, bool instructions) /* 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; @@ -3039,8 +3038,7 @@ ofctl_parse_actions__(const char *version_s, bool instructions) 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); @@ -3058,24 +3056,22 @@ ofctl_parse_actions__(const char *version_s, bool instructions) /* 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); @@ -3141,9 +3137,9 @@ ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) 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. */ @@ -3156,18 +3152,18 @@ ofctl_parse_ofp10_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) 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. */ @@ -3205,13 +3201,13 @@ ofctl_parse_ofp11_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) 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); @@ -3224,7 +3220,7 @@ ofctl_parse_ofp11_match(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) /* 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'); @@ -3310,7 +3306,7 @@ ofctl_check_vlan(int argc OVS_UNUSED, char *argv[]) /* 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) { @@ -3416,19 +3412,19 @@ ofctl_encode_error_reply(int argc OVS_UNUSED, char *argv[]) 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); } @@ -3466,7 +3462,7 @@ ofctl_ofp_print(int argc, char *argv[]) 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); } @@ -3480,8 +3476,8 @@ ofctl_encode_hello(int argc OVS_UNUSED, char *argv[]) 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); } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 55811933a..0a681c5f8 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -4166,8 +4166,8 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos) } 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); -- 2.20.1