[ovs-dev] [packet_in v2 05/18] pktbuf: Directly use pointers in pktbuf_save().

Ethan Jackson ethan at nicira.com
Sat Jan 7 19:11:46 UTC 2012


In future patches, directly using a void * pointer in the
pktbuf_save() definition will simplify the code.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 ofproto/connmgr.c |    3 ++-
 ofproto/pktbuf.c  |   12 +++++++-----
 ofproto/pktbuf.h  |    4 +++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 6caad06..bd8ec91 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -1210,7 +1210,8 @@ 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->data,
+                                    pin.packet->size, flow->in_port);
     }
 
     /* Figure out how much of the packet to send. */
diff --git a/ofproto/pktbuf.c b/ofproto/pktbuf.c
index fc4c66c..e552db3 100644
--- a/ofproto/pktbuf.c
+++ b/ofproto/pktbuf.c
@@ -92,8 +92,9 @@ make_id(unsigned int buffer_idx, unsigned int cookie)
 }
 
 /* Attempts to allocate an OpenFlow packet buffer id within 'pb'.  The packet
- * buffer will store a copy of 'buffer' and the port number 'in_port', which
- * should be the datapath port number on which 'buffer' was received.
+ * buffer will store a copy of 'buffer_size' bytes in 'buffer' and the port
+ * number 'in_port', which should be the datapath port number on which 'buffer'
+ * was received.
  *
  * If successful, returns the packet buffer id (a number other than
  * UINT32_MAX).  pktbuf_retrieve() can later be used to retrieve the buffer and
@@ -102,7 +103,8 @@ make_id(unsigned int buffer_idx, unsigned int cookie)
  *
  * The caller retains ownership of 'buffer'. */
 uint32_t
-pktbuf_save(struct pktbuf *pb, struct ofpbuf *buffer, uint16_t in_port)
+pktbuf_save(struct pktbuf *pb, const void *buffer, size_t buffer_size,
+            uint16_t in_port)
 {
     struct packet *p = &pb->packets[pb->buffer_idx];
     pb->buffer_idx = (pb->buffer_idx + 1) & PKTBUF_MASK;
@@ -117,9 +119,9 @@ pktbuf_save(struct pktbuf *pb, struct ofpbuf *buffer, uint16_t in_port)
     if (++p->cookie >= COOKIE_MAX) {
         p->cookie = 0;
     }
-    p->buffer = ofpbuf_new_with_headroom(buffer->size,
+    p->buffer = ofpbuf_new_with_headroom(buffer_size,
                                          sizeof(struct ofp_packet_in));
-    ofpbuf_put(p->buffer, buffer->data, buffer->size);
+    ofpbuf_put(p->buffer, buffer, buffer_size);
     p->timeout = time_msec() + OVERWRITE_MSECS;
     p->in_port = in_port;
     return make_id(p - pb->packets, p->cookie);
diff --git a/ofproto/pktbuf.h b/ofproto/pktbuf.h
index 67f4973..82d7a85 100644
--- a/ofproto/pktbuf.h
+++ b/ofproto/pktbuf.h
@@ -17,6 +17,7 @@
 #ifndef PKTBUF_H
 #define PKTBUF_H 1
 
+#include <stddef.h>
 #include <stdint.h>
 
 struct pktbuf;
@@ -26,7 +27,8 @@ int pktbuf_capacity(void);
 
 struct pktbuf *pktbuf_create(void);
 void pktbuf_destroy(struct pktbuf *);
-uint32_t pktbuf_save(struct pktbuf *, struct ofpbuf *buffer, uint16_t in_port);
+uint32_t pktbuf_save(struct pktbuf *, const void *buffer, size_t buffer_size,
+                     uint16_t in_port);
 uint32_t pktbuf_get_null(void);
 int pktbuf_retrieve(struct pktbuf *, uint32_t id, struct ofpbuf **bufferp,
                     uint16_t *in_port);
-- 
1.7.7.1




More information about the dev mailing list