diff options
author | Pravin B Shelar <pshelar@nicira.com> | 2015-03-02 17:29:44 -0800 |
---|---|---|
committer | Pravin B Shelar <pshelar@nicira.com> | 2015-03-03 13:37:39 -0800 |
commit | 6fd6ed71cb9f2dba8307da371d5e86c34695783c (patch) | |
tree | f531082ec70f33a24c7d7e62c615d8234a0145f3 /lib | |
parent | cf62fa4c7074121184a1f1d07980990113657612 (diff) | |
download | openvswitch-6fd6ed71cb9f2dba8307da371d5e86c34695783c.tar.gz |
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 <pshelar@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundle.c | 2 | ||||
-rw-r--r-- | lib/dpctl.c | 41 | ||||
-rw-r--r-- | lib/dpif-netdev.c | 26 | ||||
-rw-r--r-- | lib/dpif-netlink.c | 14 | ||||
-rw-r--r-- | lib/dpif.c | 10 | ||||
-rw-r--r-- | lib/jsonrpc.c | 6 | ||||
-rw-r--r-- | lib/learn.c | 6 | ||||
-rw-r--r-- | lib/learning-switch.c | 16 | ||||
-rw-r--r-- | lib/netdev-dummy.c | 3 | ||||
-rw-r--r-- | lib/netlink-socket.c | 76 | ||||
-rw-r--r-- | lib/netlink.c | 26 | ||||
-rw-r--r-- | lib/nx-match.c | 50 | ||||
-rw-r--r-- | lib/odp-util.c | 16 | ||||
-rw-r--r-- | lib/ofp-actions.c | 131 | ||||
-rw-r--r-- | lib/ofp-errors.c | 4 | ||||
-rw-r--r-- | lib/ofp-msgs.c | 76 | ||||
-rw-r--r-- | lib/ofp-parse.c | 8 | ||||
-rw-r--r-- | lib/ofp-print.c | 4 | ||||
-rw-r--r-- | lib/ofp-util.c | 374 | ||||
-rw-r--r-- | lib/ofpbuf.c | 173 | ||||
-rw-r--r-- | lib/ofpbuf.h | 300 | ||||
-rw-r--r-- | lib/rconn.c | 18 | ||||
-rw-r--r-- | lib/route-table.c | 2 | ||||
-rw-r--r-- | lib/rtnetlink-link.c | 2 | ||||
-rw-r--r-- | lib/tnl-ports.c | 8 | ||||
-rw-r--r-- | lib/vconn-stream.c | 22 | ||||
-rw-r--r-- | lib/vconn.c | 28 |
27 files changed, 549 insertions, 893 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, "<any>")) { - /* Ensure that 'ofpbuf_data(b)' isn't actually null. */ + /* Ensure that 'b->data' isn't actually null. */ ofpbuf_prealloc_tailroom(b, 1); return 0; } @@ -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 " |