bgpd: efficient NLRI packing for AFs != ipv4-unicast

ISSUE:

  Currently, for non-ipv4-unicast address families where prefixes are
  encoded in MP_REACH/MP_UNREACH attributes, BGP ends up sending one
  prefix per UPDATE message. This is quite inefficient. The patch
  addresses the issue.

PATCH:

  We introduce a scratch buffer in the peer structure that stores the
  MP_REACH/MP_UNREACH attributes for non-ipv4-unicast families. This
  enables us to encode multiple prefixes. In the end, the two buffers
  are merged to create the UPDATE packet.

Signed-off-by: Pradosh Mohapatra <pmohapat@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
[DL: removed no longer existing bgp_packet_withdraw prototype]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/stream.c b/lib/stream.c
index ccd4623..9a6fcbc 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -154,6 +154,25 @@
   return (stream_copy (new, s));
 }
 
+struct stream *
+stream_dupcat (struct stream *s1, struct stream *s2, size_t offset)
+{
+  struct stream *new;
+
+  STREAM_VERIFY_SANE (s1);
+  STREAM_VERIFY_SANE (s2);
+
+  if ( (new = stream_new (s1->endp + s2->endp)) == NULL)
+    return NULL;
+
+  memcpy (new->data, s1->data, offset);
+  memcpy (new->data + offset, s2->data, s2->endp);
+  memcpy (new->data + offset + s2->endp, s1->data + offset,
+	  (s1->endp - offset));
+  new->endp = s1->endp + s2->endp;
+  return new;
+}
+
 size_t
 stream_resize (struct stream *s, size_t newsize)
 {