From 7c9d82cdd578a95cfe729354e3dffb5ac26ebcfe Mon Sep 17 00:00:00 2001 From: Soman K S Date: Sat, 30 May 2020 13:53:45 +0530 Subject: [PATCH] bgpd: Avoid extra copy of received data to buffer 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 --- bgpd/bgp_io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index ab50c545b5..412c8e3e5e 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -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); -- 2.39.5