From 3e3252fa1d7e057463ddbd66dab84f0d02ef0f1d Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Wed, 21 Dec 2011 19:01:18 -0800 Subject: [PATCH] ofp-util: Don't use ofpbuf in ofputil_packet_in struct. This will make the memory ownership clearer in future patches which make more extensive use of ofputil_packet_in. Signed-off-by: Ethan Jackson --- lib/ofp-util.c | 5 ++--- lib/ofp-util.h | 4 +++- ofproto/connmgr.c | 6 +++--- ofproto/ofproto-dpif.c | 6 ++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index bf7a82b6..c3ee54e2 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -1547,19 +1547,18 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr, struct ofpbuf * 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; rw_packet = ofpbuf_clone_data_with_headroom( - pin->packet->data, MIN(pin->send_len, pin->packet->size), + pin->packet, MIN(pin->send_len, pin->packet_len), offsetof(struct ofp_packet_in, data)); /* Add OFPT_PACKET_IN. */ memset(&opi, 0, sizeof opi); opi.header.version = OFP_VERSION; opi.header.type = OFPT_PACKET_IN; - opi.total_len = htons(total_len); + opi.total_len = htons(pin->packet_len); opi.in_port = htons(pin->in_port); opi.reason = pin->reason; opi.buffer_id = htonl(pin->buffer_id); diff --git a/lib/ofp-util.h b/lib/ofp-util.h index adff0d9b..b9c2d54e 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -214,7 +214,9 @@ struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *, /* Abstract packet-in message. */ struct ofputil_packet_in { - struct ofpbuf *packet; + const void *packet; + size_t packet_len; + uint16_t in_port; uint8_t reason; /* One of OFPR_*. */ diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 64d60055..33e65921 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -1193,13 +1193,13 @@ schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin, } else if (!ofconn->pktbuf) { pin.buffer_id = UINT32_MAX; } else { - pin.buffer_id = pktbuf_save(ofconn->pktbuf, pin.packet->data, - pin.packet->size, flow->in_port); + pin.buffer_id = pktbuf_save(ofconn->pktbuf, pin.packet, pin.packet_len, + flow->in_port); } /* Figure out how much of the packet to send. */ if (pin.reason == OFPR_NO_MATCH) { - pin.send_len = pin.packet->size; + pin.send_len = pin.packet_len; } else { /* Caller should have initialized 'send_len' to 'max_len' specified in * struct ofp_action_output. */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index b9730cc4..ac74bd16 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2417,7 +2417,8 @@ send_packet_in_miss(struct ofproto_dpif *ofproto, struct ofpbuf *packet, { struct ofputil_packet_in pin; - pin.packet = packet; + pin.packet = packet->data; + pin.packet_len = packet->size; pin.in_port = flow->in_port; pin.reason = OFPR_NO_MATCH; pin.buffer_id = 0; /* not yet known */ @@ -2440,7 +2441,8 @@ send_packet_in_action(struct ofproto_dpif *ofproto, struct ofpbuf *packet, memcpy(&cookie, &userdata, sizeof(cookie)); - pin.packet = packet; + pin.packet = packet->data; + pin.packet_len = packet->size; pin.in_port = flow->in_port; pin.reason = OFPR_ACTION; pin.buffer_id = 0; /* not yet known */ -- 2.30.2