[ovs-dev] [packet_in 09/13] ofp-util: Use constant ofpbuf in ofputil_packet_in struct.

Ethan Jackson ethan at nicira.com
Thu Dec 29 01:52:36 UTC 2011


This will make the memory ownership clearer when future patches
make more extensive use of ofputil_packet_in.
---
 lib/ofp-util.c         |    4 ++--
 lib/ofp-util.h         |    4 ++--
 ofproto/connmgr.c      |    5 +++--
 ofproto/ofproto-dpif.c |    4 ++--
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 11b0f15..3a14013 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1539,7 +1539,7 @@ struct ofpbuf *
 ofputil_encode_packet_in(const struct ofputil_packet_in *pin,
                         struct ofpbuf *rw_packet)
 {
-    int total_len = pin->packet->size;
+    int total_len = pin->packet.size;
     struct ofp_packet_in opi;
 
     if (rw_packet) {
@@ -1548,7 +1548,7 @@ ofputil_encode_packet_in(const struct ofputil_packet_in *pin,
         }
     } else {
         rw_packet = ofpbuf_clone_data_with_headroom(
-            pin->packet->data, MIN(pin->send_len, pin->packet->size),
+            pin->packet.data, MIN(pin->send_len, pin->packet.size),
             offsetof(struct ofp_packet_in, data));
     }
 
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 909467f..5a11a69 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -23,11 +23,11 @@
 #include <stdint.h>
 #include "classifier.h"
 #include "flow.h"
+#include "ofpbuf.h"
 #include "openflow/nicira-ext.h"
 #include "openvswitch/types.h"
 
 struct cls_rule;
-struct ofpbuf;
 
 /* Basic decoding and length validation of OpenFlow messages. */
 enum ofputil_msg_code {
@@ -211,7 +211,7 @@ struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
 
 /* Abstract packet-in message. */
 struct ofputil_packet_in {
-    struct ofpbuf *packet;
+    struct ofpbuf packet;       /* Const ofpbuf. */
     uint16_t in_port;
     uint8_t reason;             /* One of OFPR_*. */
 
diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 6caad06..d32f5fd 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -1210,12 +1210,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, flow->in_port);
+        pin.buffer_id = pktbuf_save(ofconn->pktbuf, &pin.packet,
+                                    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.size;
     } 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 391a1dd..2038302 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -2406,11 +2406,11 @@ send_packet_in_miss(struct ofproto_dpif *ofproto, struct ofpbuf *packet,
 {
     struct ofputil_packet_in pin;
 
-    pin.packet = packet;
     pin.in_port = flow->in_port;
     pin.reason = OFPR_NO_MATCH;
     pin.buffer_id = 0;          /* not yet known */
     pin.send_len = 0;           /* not used for flow table misses */
+    ofpbuf_use_const(&pin.packet, packet->data, packet->size);
     connmgr_send_packet_in(ofproto->up.connmgr, &pin, flow,
                            clone ? NULL : packet);
 }
@@ -2433,11 +2433,11 @@ send_packet_in_action(struct ofproto_dpif *ofproto, struct ofpbuf *packet,
 
     memcpy(&cookie, &userdata, sizeof(cookie));
 
-    pin.packet = packet;
     pin.in_port = flow->in_port;
     pin.reason = OFPR_ACTION;
     pin.buffer_id = 0;          /* not yet known */
     pin.send_len = cookie.data;
+    ofpbuf_use_const(&pin.packet, packet->data, packet->size);
     connmgr_send_packet_in(ofproto->up.connmgr, &pin, flow,
                            clone ? NULL : packet);
 }
-- 
1.7.7.1




More information about the dev mailing list