mirror of
https://github.com/openvswitch/ovs
synced 2025-10-29 15:28:56 +00:00
ofpbuf: Abstract 'l2' pointer and document usage conventions.
Rename 'l2' to 'frame' and add new ofpbuf_set_frame() and ofpbuf_l2().
ofpbuf_set_frame() alse resets all the layer offsets. ofpbuf_l2()
returns NULL if the packet has no Ethernet header, as indicated either
by unset l3 offset or NULL frame pointer. Callers of ofpbuf_l2() are
supposed to check the return value, unless they can otherwise be sure
that the packet has a valid Ethernet header.
The recent commit 437d0d22 made some assumptions that were not valid
regarding the use of the 'l2' pointer in rconn module and by
compose_rarp(). This is now fixed as follows: rconn now relies on the
fact that once OpenFlow messages are given to rconn for transport, the
frame pointer is no longer needed to refer to the OpenFlow header; and
compose_rarp() now sets the frame pointer and offsets as expected.
In addition to storing network frames, ofpbufs are also used for
handling OpenFlow messages and action lists. lib/ofpbuf.h now has a
comment documenting the current usage conventions and invariants.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
@@ -225,7 +225,7 @@ dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat)
|
||||
ids->ofpact.compat = compat;
|
||||
ids->n_controllers = 1;
|
||||
ofpbuf_put(out, &id, sizeof id);
|
||||
ids = out->l2;
|
||||
ids = out->frame;
|
||||
ofpact_update_len(out, &ids->ofpact);
|
||||
return error;
|
||||
}
|
||||
@@ -258,7 +258,7 @@ dec_ttl_cnt_ids_from_openflow(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->l2;
|
||||
ids = out->frame;
|
||||
}
|
||||
|
||||
ofpact_update_len(out, &ids->ofpact);
|
||||
@@ -1077,7 +1077,7 @@ static void
|
||||
set_field_to_openflow(const struct ofpact_set_field *sf,
|
||||
struct ofpbuf *openflow)
|
||||
{
|
||||
struct ofp_header *oh = (struct ofp_header *)openflow->l2;
|
||||
struct ofp_header *oh = (struct ofp_header *)openflow->frame;
|
||||
|
||||
if (oh->version >= OFP12_VERSION) {
|
||||
set_field_to_openflow12(sf, openflow);
|
||||
@@ -3608,7 +3608,7 @@ ofpact_put(struct ofpbuf *ofpacts, enum ofpact_type type, size_t len)
|
||||
struct ofpact *ofpact;
|
||||
|
||||
ofpact_pad(ofpacts);
|
||||
ofpact = ofpacts->l2 = ofpbuf_put_uninit(ofpacts, len);
|
||||
ofpact = ofpacts->frame = ofpbuf_put_uninit(ofpacts, len);
|
||||
ofpact_init(ofpact, type, len);
|
||||
return ofpact;
|
||||
}
|
||||
@@ -3631,7 +3631,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->l2);
|
||||
ovs_assert(ofpact == ofpacts->frame);
|
||||
ofpact->len = (char *) ofpbuf_tail(ofpacts) - (char *) ofpact;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user