isisd, ospfd, tests: Switch to using stream_resize_inplace

Switch code and tests to use new stream_resize_inplace functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2018-08-21 20:22:28 -04:00
parent 4388866917
commit db3c830afe
3 changed files with 27 additions and 25 deletions

View File

@ -536,7 +536,7 @@ void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
*stream = stream_new(stream_size); *stream = stream_new(stream_size);
} else { } else {
if (STREAM_SIZE(*stream) != stream_size) if (STREAM_SIZE(*stream) != stream_size)
stream_resize(*stream, stream_size); stream_resize_inplace(stream, stream_size);
stream_reset(*stream); stream_reset(*stream);
} }
} }

View File

@ -416,7 +416,7 @@ static uint16_t ospf_link_cost(struct ospf_interface *oi)
} }
/* Set a link information. */ /* Set a link information. */
static char link_info_set(struct stream *s, struct in_addr id, static char link_info_set(struct stream **s, struct in_addr id,
struct in_addr data, uint8_t type, uint8_t tos, struct in_addr data, uint8_t type, uint8_t tos,
uint16_t cost) uint16_t cost)
{ {
@ -425,11 +425,11 @@ static char link_info_set(struct stream *s, struct in_addr id,
* more. * more.
* we try accomodate those here. * we try accomodate those here.
*/ */
if (STREAM_WRITEABLE(s) < OSPF_ROUTER_LSA_LINK_SIZE) { if (STREAM_WRITEABLE(*s) < OSPF_ROUTER_LSA_LINK_SIZE) {
size_t ret = OSPF_MAX_LSA_SIZE; size_t ret = OSPF_MAX_LSA_SIZE;
/* Can we enlarge the stream still? */ /* Can we enlarge the stream still? */
if (STREAM_SIZE(s) == OSPF_MAX_LSA_SIZE) { if (STREAM_SIZE(*s) == OSPF_MAX_LSA_SIZE) {
/* we futz the size here for simplicity, really we need /* we futz the size here for simplicity, really we need
* to account * to account
* for just: * for just:
@ -441,30 +441,31 @@ static char link_info_set(struct stream *s, struct in_addr id,
* *
* Simpler just to subtract OSPF_MAX_LSA_SIZE though. * Simpler just to subtract OSPF_MAX_LSA_SIZE though.
*/ */
ret = stream_resize( ret = stream_resize_inplace(
s, OSPF_MAX_PACKET_SIZE - OSPF_MAX_LSA_SIZE); s, OSPF_MAX_PACKET_SIZE - OSPF_MAX_LSA_SIZE);
} }
if (ret == OSPF_MAX_LSA_SIZE) { if (ret == OSPF_MAX_LSA_SIZE) {
zlog_warn( zlog_warn(
"%s: Out of space in LSA stream, left %zd, size %zd", "%s: Out of space in LSA stream, left %zd, size %zd",
__func__, STREAM_WRITEABLE(s), STREAM_SIZE(s)); __func__, STREAM_WRITEABLE(*s),
STREAM_SIZE(*s));
return 0; return 0;
} }
} }
/* TOS based routing is not supported. */ /* TOS based routing is not supported. */
stream_put_ipv4(s, id.s_addr); /* Link ID. */ stream_put_ipv4(*s, id.s_addr); /* Link ID. */
stream_put_ipv4(s, data.s_addr); /* Link Data. */ stream_put_ipv4(*s, data.s_addr); /* Link Data. */
stream_putc(s, type); /* Link Type. */ stream_putc(*s, type); /* Link Type. */
stream_putc(s, tos); /* TOS = 0. */ stream_putc(*s, tos); /* TOS = 0. */
stream_putw(s, cost); /* Link Cost. */ stream_putw(*s, cost); /* Link Cost. */
return 1; return 1;
} }
/* Describe Point-to-Point link (Section 12.4.1.1). */ /* Describe Point-to-Point link (Section 12.4.1.1). */
static int lsa_link_ptop_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_ptop_set(struct stream **s, struct ospf_interface *oi)
{ {
int links = 0; int links = 0;
struct ospf_neighbor *nbr; struct ospf_neighbor *nbr;
@ -510,7 +511,7 @@ static int lsa_link_ptop_set(struct stream *s, struct ospf_interface *oi)
} }
/* Describe Broadcast Link. */ /* Describe Broadcast Link. */
static int lsa_link_broadcast_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_broadcast_set(struct stream **s, struct ospf_interface *oi)
{ {
struct ospf_neighbor *dr; struct ospf_neighbor *dr;
struct in_addr id, mask; struct in_addr id, mask;
@ -556,7 +557,7 @@ static int lsa_link_broadcast_set(struct stream *s, struct ospf_interface *oi)
} }
} }
static int lsa_link_loopback_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_loopback_set(struct stream **s, struct ospf_interface *oi)
{ {
struct in_addr id, mask; struct in_addr id, mask;
@ -570,7 +571,8 @@ static int lsa_link_loopback_set(struct stream *s, struct ospf_interface *oi)
} }
/* Describe Virtual Link. */ /* Describe Virtual Link. */
static int lsa_link_virtuallink_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_virtuallink_set(struct stream **s,
struct ospf_interface *oi)
{ {
struct ospf_neighbor *nbr; struct ospf_neighbor *nbr;
uint16_t cost = ospf_link_cost(oi); uint16_t cost = ospf_link_cost(oi);
@ -593,7 +595,7 @@ static int lsa_link_virtuallink_set(struct stream *s, struct ospf_interface *oi)
12.4.1.4.*/ 12.4.1.4.*/
/* from "edward rrr" <edward_rrr@hotmail.com> /* from "edward rrr" <edward_rrr@hotmail.com>
http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */ http://marc.theaimsgroup.com/?l=zebra&m=100739222210507&w=2 */
static int lsa_link_ptomp_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_ptomp_set(struct stream **s, struct ospf_interface *oi)
{ {
int links = 0; int links = 0;
struct route_node *rn; struct route_node *rn;
@ -634,7 +636,7 @@ static int lsa_link_ptomp_set(struct stream *s, struct ospf_interface *oi)
} }
/* Set router-LSA link information. */ /* Set router-LSA link information. */
static int router_lsa_link_set(struct stream *s, struct ospf_area *area) static int router_lsa_link_set(struct stream **s, struct ospf_area *area)
{ {
struct listnode *node; struct listnode *node;
struct ospf_interface *oi; struct ospf_interface *oi;
@ -677,28 +679,28 @@ static int router_lsa_link_set(struct stream *s, struct ospf_area *area)
} }
/* Set router-LSA body. */ /* Set router-LSA body. */
static void ospf_router_lsa_body_set(struct stream *s, struct ospf_area *area) static void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area)
{ {
unsigned long putp; unsigned long putp;
uint16_t cnt; uint16_t cnt;
/* Set flags. */ /* Set flags. */
stream_putc(s, router_lsa_flags(area)); stream_putc(*s, router_lsa_flags(area));
/* Set Zero fields. */ /* Set Zero fields. */
stream_putc(s, 0); stream_putc(*s, 0);
/* Keep pointer to # links. */ /* Keep pointer to # links. */
putp = stream_get_endp(s); putp = stream_get_endp(*s);
/* Forward word */ /* Forward word */
stream_putw(s, 0); stream_putw(*s, 0);
/* Set all link information. */ /* Set all link information. */
cnt = router_lsa_link_set(s, area); cnt = router_lsa_link_set(s, area);
/* Set # of links here. */ /* Set # of links here. */
stream_putw_at(s, putp, cnt); stream_putw_at(*s, putp, cnt);
} }
static int ospf_stub_router_timer(struct thread *t) static int ospf_stub_router_timer(struct thread *t)
@ -783,7 +785,7 @@ static struct ospf_lsa *ospf_router_lsa_new(struct ospf_area *area)
OSPF_ROUTER_LSA, ospf->router_id, ospf->router_id); OSPF_ROUTER_LSA, ospf->router_id, ospf->router_id);
/* Set router-LSA body fields. */ /* Set router-LSA body fields. */
ospf_router_lsa_body_set(s, area); ospf_router_lsa_body_set(&s, area);
/* Set length. */ /* Set length. */
length = stream_get_endp(s); length = stream_get_endp(s);

View File

@ -57,7 +57,7 @@ int main(void)
print_stream(s); print_stream(s);
stream_resize(s, stream_get_endp(s)); stream_resize_inplace(&s, stream_get_endp(s));
print_stream(s); print_stream(s);