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 bf7a82b659932538463f0697c3e344da4beb0326..c3ee54e250c26be96ae3b48a8b2980a30f545457 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 adff0d9ba52879e3a9950a0553b75b4e606cfd4d..b9c2d54e4e002a2e8b23366820f0139df46046f0 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 64d6005574500e570cd601f610a420b1ed8e32ed..33e65921533ddc4de23947d009a767a8dfcadbb0 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 b9730cc49bcdf571d34fc74182ee43027e948a48..ac74bd16884ff9b0c1bca09996b59587337239ad 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 */