ofp-util: Don't use ofpbuf in ofputil_packet_in struct.
authorEthan Jackson <ethan@nicira.com>
Thu, 22 Dec 2011 03:01:18 +0000 (19:01 -0800)
committerEthan Jackson <ethan@nicira.com>
Tue, 10 Jan 2012 22:30:15 +0000 (14:30 -0800)
This will make the memory ownership clearer in future patches which
make more extensive use of ofputil_packet_in.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
lib/ofp-util.c
lib/ofp-util.h
ofproto/connmgr.c
ofproto/ofproto-dpif.c

index bf7a82b..c3ee54e 100644 (file)
@@ -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);
index adff0d9..b9c2d54 100644 (file)
@@ -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_*. */
 
index 64d6005..33e6592 100644 (file)
@@ -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. */
index b9730cc..ac74bd1 100644 (file)
@@ -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 */