All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 6fd6ed71 authored by Pravin B Shelar's avatar Pravin B Shelar

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: default avatarPravin B Shelar <pshelar@nicira.com>
Acked-by: default avatarJarno Rajahalme <jrajahalme@nicira.com>
Acked-by: default avatarBen Pfaff <blp@nicira.com>
parent cf62fa4c
......@@ -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);
......
......@@ -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);
......
......@@ -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]);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
This diff is collapsed.
......@@ -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);
}
......
......@@ -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));