]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Avoid extra copy of received data to buffer
authorSoman K S <somanks@gmail.com>
Sat, 30 May 2020 08:23:45 +0000 (13:53 +0530)
committerSoman K S <somanks@gmail.com>
Sat, 30 May 2020 08:23:45 +0000 (13:53 +0530)
When received packet is processed in bgp_process_reads(), the data
is copied to static buffer and then copied to stream buffer.
The data can be copied directly to stream buffer which will avoid extra memcpy

Signed-off-by: kssoman <somanks@gmail.com>
bgpd/bgp_io.c

index ab50c545b52e28f4439231a6b907233147d90bb5..412c8e3e5ec0e13dafef76c3e95cd2ec11d378c7 100644 (file)
@@ -201,7 +201,6 @@ static int bgp_process_reads(struct thread *thread)
 
        while (more) {
                /* static buffer for transferring packets */
-               static unsigned char pktbuf[BGP_MAX_PACKET_SIZE];
                /* shorter alias to peer's input buffer */
                struct ringbuf *ibw = peer->ibuf_work;
                /* packet size as given by header */
@@ -231,8 +230,9 @@ static int bgp_process_reads(struct thread *thread)
                 */
                if (ringbuf_remain(ibw) >= pktsize) {
                        struct stream *pkt = stream_new(pktsize);
-                       assert(ringbuf_get(ibw, pktbuf, pktsize) == pktsize);
-                       stream_put(pkt, pktbuf, pktsize);
+                       assert(STREAM_WRITEABLE(pkt) == pktsize);
+                       assert(ringbuf_get(ibw, pkt->data, pktsize) == pktsize);
+                       stream_set_endp(pkt, pktsize);
 
                        frr_with_mutex(&peer->io_mtx) {
                                stream_fifo_push(peer->ibuf, pkt);