From 29ebe8803c3a1ef03cbc92fbc352a2cdce5a8f55 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Tue, 3 Jan 2012 14:22:44 -0800 Subject: ofproto: Always clone packets in PACKET_IN message. This patch removes an optimization which significantly complicates the code in ways which would get worse in future patches if not removed. Furthermore, future patches will have fewer cases which can take advantage of the optimization further mitigating its justification. Signed-off-by: Ethan Jackson --- lib/ofp-util.c | 29 ++++++----------------------- lib/ofp-util.h | 3 +-- 2 files changed, 7 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 42dab87f..bf7a82b6 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -1543,34 +1543,17 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr, } /* Converts abstract ofputil_packet_in 'pin' into an OFPT_PACKET_IN message - * and returns the message. - * - * If 'rw_packet' is NULL, the caller takes ownership of the newly allocated - * returned ofpbuf. - * - * If 'rw_packet' is nonnull, then it must contain the same data as - * pin->packet. 'rw_packet' is allowed to be the same ofpbuf as pin->packet. - * It is modified in-place into an OFPT_PACKET_IN message according to 'pin', - * and then ofputil_encode_packet_in() returns 'rw_packet'. If 'rw_packet' has - * enough headroom to insert a "struct ofp_packet_in", this is more efficient - * than ofputil_encode_packet_in() because it does not copy the packet - * payload. */ + * and returns the message. */ struct ofpbuf * -ofputil_encode_packet_in(const struct ofputil_packet_in *pin, - struct ofpbuf *rw_packet) +ofputil_encode_packet_in(const struct ofputil_packet_in *pin) { int total_len = pin->packet->size; struct ofp_packet_in opi; + struct ofpbuf *rw_packet; - if (rw_packet) { - if (pin->send_len < rw_packet->size) { - rw_packet->size = pin->send_len; - } - } else { - rw_packet = ofpbuf_clone_data_with_headroom( - pin->packet->data, MIN(pin->send_len, pin->packet->size), - offsetof(struct ofp_packet_in, data)); - } + rw_packet = ofpbuf_clone_data_with_headroom( + pin->packet->data, MIN(pin->send_len, pin->packet->size), + offsetof(struct ofp_packet_in, data)); /* Add OFPT_PACKET_IN. */ memset(&opi, 0, sizeof opi); diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 8fa729e9..adff0d9b 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -222,8 +222,7 @@ struct ofputil_packet_in { int send_len; }; -struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *, - struct ofpbuf *rw_packet); +struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *); /* OpenFlow protocol utility functions. */ void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **); -- cgit v1.2.3