bgpd: Remove unnecessary stream_dup calls
BGP packet handling creates a stream to handle data for an outgoing packet.
In some cases the code would create a new stream, add data, then duplicate
the stream and then free the original stream. This change removes
the unnecessary duplication, which entails a malloc and memcpy.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 7d27972..e1ae494 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -275,7 +275,6 @@
bgp_update_packet_eor (struct peer *peer, afi_t afi, safi_t safi)
{
struct stream *s;
- struct stream *packet;
if (DISABLE_BGP_ANNOUNCE)
return NULL;
@@ -308,10 +307,8 @@
}
bgp_packet_set_size (s);
- packet = stream_dup (s);
- bgp_packet_add (peer, packet);
- stream_free (s);
- return packet;
+ bgp_packet_add (peer, s);
+ return s;
}
/* Make BGP withdraw packet. */
@@ -431,7 +428,6 @@
afi_t afi, safi_t safi, struct peer *from)
{
struct stream *s;
- struct stream *packet;
struct prefix p;
unsigned long pos;
bgp_size_t total_attr_len;
@@ -482,16 +478,13 @@
/* Set size. */
bgp_packet_set_size (s);
- packet = stream_dup (s);
- stream_free (s);
-
/* Dump packet if debug option is set. */
#ifdef DEBUG
/* bgp_packet_dump (packet); */
#endif /* DEBUG */
/* Add packet to the peer. */
- bgp_packet_add (peer, packet);
+ bgp_packet_add (peer, s);
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
@@ -500,7 +493,6 @@
bgp_default_withdraw_send (struct peer *peer, afi_t afi, safi_t safi)
{
struct stream *s;
- struct stream *packet;
struct prefix p;
unsigned long attrlen_pos = 0;
unsigned long cp;
@@ -570,11 +562,8 @@
bgp_packet_set_size (s);
- packet = stream_dup (s);
- stream_free (s);
-
/* Add packet to the peer. */
- bgp_packet_add (peer, packet);
+ bgp_packet_add (peer, s);
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
@@ -1029,7 +1018,6 @@
u_char orf_type, u_char when_to_refresh, int remove)
{
struct stream *s;
- struct stream *packet;
int length;
struct bgp_filter *filter;
int orf_refresh = 0;
@@ -1110,12 +1098,8 @@
BGP_MSG_ROUTE_REFRESH_NEW : BGP_MSG_ROUTE_REFRESH_OLD, length);
}
- /* Make real packet. */
- packet = stream_dup (s);
- stream_free (s);
-
/* Add packet to the peer. */
- bgp_packet_add (peer, packet);
+ bgp_packet_add (peer, s);
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
}
@@ -1126,7 +1110,6 @@
int capability_code, int action)
{
struct stream *s;
- struct stream *packet;
int length;
/* Adjust safi code. */
@@ -1157,12 +1140,9 @@
/* Set packet size. */
length = bgp_packet_set_size (s);
- /* Make real packet. */
- packet = stream_dup (s);
- stream_free (s);
/* Add packet to the peer. */
- bgp_packet_add (peer, packet);
+ bgp_packet_add (peer, s);
if (BGP_DEBUG (normal, NORMAL))
zlog_debug ("%s send message type %d, length (incl. header) %d",