X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fpktbuf.c;h=7cc96a5cedc8f90e6395431fc27af2b3f5cc035f;hb=999fba59afd9c8eef30d30a6fd2f490b85c24665;hp=02c590cf61375861a5d49481db87fac515eb3d9d;hpb=007948177581f3b3dad188221593d0e4bdca6ba0;p=openvswitch diff --git a/ofproto/pktbuf.c b/ofproto/pktbuf.c index 02c590cf..7cc96a5c 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 OpenFlow 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,10 @@ 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, - sizeof(struct ofp_packet_in)); - ofpbuf_put(p->buffer, buffer->data, buffer->size); + p->buffer = ofpbuf_clone_data_with_headroom(buffer, buffer_size, + sizeof(struct ofp_packet_in)); + + p->timeout = time_msec() + OVERWRITE_MSECS; p->in_port = in_port; return make_id(p - pb->packets, p->cookie); @@ -161,6 +164,8 @@ pktbuf_get_null(void) * identifies a "null" packet buffer (created with pktbuf_get_null()), stores * NULL in '*bufferp' and UINT16_max in '*in_port'. * + * 'in_port' may be NULL if the input port is not of interest. + * * A returned packet will have at least sizeof(struct ofp_packet_in) bytes of * headroom. * @@ -189,7 +194,9 @@ pktbuf_retrieve(struct pktbuf *pb, uint32_t id, struct ofpbuf **bufferp, struct ofpbuf *buffer = p->buffer; if (buffer) { *bufferp = buffer; - *in_port = p->in_port; + if (in_port) { + *in_port = p->in_port; + } p->buffer = NULL; COVERAGE_INC(pktbuf_retrieved); return 0; @@ -211,7 +218,9 @@ pktbuf_retrieve(struct pktbuf *pb, uint32_t id, struct ofpbuf **bufferp, } error: *bufferp = NULL; - *in_port = UINT16_MAX; + if (in_port) { + *in_port = UINT16_MAX; + } return error; }