Index: ospfd/ospf_dump.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_dump.c,v retrieving revision 1.13 diff -u -r1.13 ospf_dump.c --- ospfd/ospf_dump.c 11 Oct 2004 10:11:25 -0000 1.13 +++ ospfd/ospf_dump.c 26 Nov 2004 14:10:07 -0000 @@ -455,7 +455,7 @@ lsa = (struct lsa_header *) STREAM_PNT (s); ospf_lsa_header_dump (lsa); - stream_forward (s, OSPF_LSA_HEADER_SIZE); + stream_forward_getp (s, OSPF_LSA_HEADER_SIZE); length -= OSPF_LSA_HEADER_SIZE; } } @@ -481,7 +481,7 @@ length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE; - stream_forward (s, OSPF_DB_DESC_MIN_SIZE); + stream_forward_getp (s, OSPF_DB_DESC_MIN_SIZE); ospf_lsa_header_list_dump (s, length); @@ -577,7 +577,7 @@ break; } - stream_forward (s, lsa_len); + stream_forward_getp (s, lsa_len); length -= lsa_len; count--; } @@ -673,7 +673,7 @@ /* Show OSPF header detail. */ ospf_header_dump (ospfh); - stream_forward (s, OSPF_HEADER_SIZE); + stream_forward_getp (s, OSPF_HEADER_SIZE); switch (ospfh->type) { Index: ospfd/ospf_lsa.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_lsa.c,v retrieving revision 1.30 diff -u -r1.30 ospf_lsa.c --- ospfd/ospf_lsa.c 19 Oct 2004 19:44:44 -0000 1.30 +++ ospfd/ospf_lsa.c 26 Nov 2004 14:10:09 -0000 @@ -407,7 +407,7 @@ lsah->adv_router = router_id; lsah->ls_seqnum = htonl (OSPF_INITIAL_SEQUENCE_NUMBER); - ospf_output_forward (s, OSPF_LSA_HEADER_SIZE); + stream_forward_putp (s, OSPF_LSA_HEADER_SIZE); } @@ -710,7 +710,7 @@ stream_putc (s, 0); /* Keep pointer to # links. */ - putp = s->putp; + putp = stream_get_putp(s); /* Forward word */ stream_putw(s, 0); Index: ospfd/ospf_packet.c =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_packet.c,v retrieving revision 1.53 diff -u -r1.53 ospf_packet.c --- ospfd/ospf_packet.c 20 Nov 2004 02:07:00 -0000 1.53 +++ ospfd/ospf_packet.c 26 Nov 2004 14:10:11 -0000 @@ -84,13 +84,6 @@ } -/* forward output pointer. */ -void -ospf_output_forward (struct stream *s, int size) -{ - s->putp += size; -} - struct ospf_packet * ospf_packet_new (size_t size) { @@ -210,18 +203,6 @@ ospf_packet_free (op); } -struct stream * -ospf_stream_copy (struct stream *new, struct stream *s) -{ - new->endp = s->endp; - new->putp = s->putp; - new->getp = s->getp; - - memcpy (new->data, s->data, stream_get_endp (s)); - - return new; -} - struct ospf_packet * ospf_packet_dup (struct ospf_packet *op) { @@ -233,7 +214,7 @@ /* Reserve space for MD5 authentication that may be added later. */ new = ospf_packet_new (stream_get_endp(op->s) + OSPF_AUTH_MD5_SIZE); - ospf_stream_copy (new->s, op->s); + stream_copy (new->s, op->s); new->dst = op->dst; new->length = op->length; @@ -370,7 +351,8 @@ op->length = ntohs (ospfh->length) + OSPF_AUTH_MD5_SIZE; if (stream_get_endp(op->s) != op->length) - zlog_warn("ospf_make_md5_digest: length mismatch stream %ld ospf_packet %d", stream_get_endp(op->s), op->length); + zlog_warn("ospf_make_md5_digest: length mismatch stream %ld ospf_packet %d", + stream_get_endp(op->s), op->length); return OSPF_AUTH_MD5_SIZE; } @@ -555,7 +537,7 @@ } iph->ip_off += offset; - stream_forward (op->s, iovp->iov_len); + stream_forward_getp (op->s, iovp->iov_len); iovp->iov_base = STREAM_PNT (op->s); } @@ -968,12 +950,12 @@ struct ospf_lsa *new, *find; struct lsa_header *lsah; - stream_forward (s, OSPF_DB_DESC_MIN_SIZE); + stream_forward_getp(s, OSPF_DB_DESC_MIN_SIZE); for (size -= OSPF_DB_DESC_MIN_SIZE; size >= OSPF_LSA_HEADER_SIZE; size -= OSPF_LSA_HEADER_SIZE) { lsah = (struct lsa_header *) STREAM_PNT (s); - stream_forward (s, OSPF_LSA_HEADER_SIZE); + stream_forward_getp(s, OSPF_LSA_HEADER_SIZE); /* Unknown LS type. */ if (lsah->type < OSPF_MIN_LSA || lsah->type >= OSPF_MAX_LSA) @@ -1446,7 +1428,7 @@ size -= OSPF_LS_UPD_MIN_SIZE; /* # LSAs */ for (; size >= OSPF_LSA_HEADER_SIZE && count > 0; - size -= length, stream_forward (s, length), count--) + size -= length, stream_forward_getp(s, length), count--) { lsah = (struct lsa_header *) STREAM_PNT (s); length = ntohs (lsah->length); @@ -1963,7 +1945,7 @@ /* lsah = (struct lsa_header *) STREAM_PNT (s); */ size -= OSPF_LSA_HEADER_SIZE; - stream_forward (s, OSPF_LSA_HEADER_SIZE); + stream_forward_getp(s, OSPF_LSA_HEADER_SIZE); if (lsa->data->type < OSPF_MIN_LSA || lsa->data->type >= OSPF_MAX_LSA) { @@ -2047,10 +2029,10 @@ ip_len = ip_len + (iph.ip_hl << 2); #endif - ibuf = stream_new (ip_len); - iov.iov_base = STREAM_DATA (ibuf); - iov.iov_len = ip_len; - ret = recvmsg (fd, &msgh, 0); + if ( (ibuf = stream_new (ip_len)) == NULL) + return NULL; + + ret = stream_recvmsg (ibuf, fd, &msgh, 0, ip_len); ifindex = getsockopt_ifindex (AF_INET, &msgh); @@ -2348,7 +2330,7 @@ } /* Adjust size to message length. */ - stream_forward (ibuf, iph->ip_hl * 4); + stream_forward_getp(ibuf, iph->ip_hl * 4); /* Get ospf packet header. */ ospfh = (struct ospf_header *) STREAM_PNT (ibuf); @@ -2435,7 +2417,7 @@ return ret; } - stream_forward (ibuf, OSPF_HEADER_SIZE); + stream_forward_getp(ibuf, OSPF_HEADER_SIZE); /* Adjust size to message length. */ length = ntohs (ospfh->length) - OSPF_HEADER_SIZE; @@ -2488,7 +2470,7 @@ memset (ospfh->u.auth_data, 0, OSPF_AUTH_SIMPLE_SIZE); - ospf_output_forward (s, OSPF_HEADER_SIZE); + stream_forward_putp (s, OSPF_HEADER_SIZE); } /* Make Authentication Data. */ @@ -2590,7 +2572,7 @@ /* Set Designated Router. */ stream_put_ipv4 (s, DR (oi).s_addr); - p = s->putp; + p = stream_get_putp(s); /* Set Backup Designated Router. */ stream_put_ipv4 (s, BDR (oi).s_addr); @@ -2810,7 +2792,7 @@ zlog_info ("ospf_make_ls_upd: Start"); pp = stream_get_putp (s); - ospf_output_forward (s, OSPF_LS_UPD_MIN_SIZE); + stream_forward_putp (s, OSPF_LS_UPD_MIN_SIZE); while ((node = listhead (update)) != NULL) { @@ -2851,7 +2833,7 @@ stream_set_putp (s, pp); stream_putl (s, count); - stream_set_putp (s, s->endp); + stream_set_putp (s, stream_get_endp(s)); if (IS_DEBUG_OSPF_EVENT) zlog_info ("ospf_make_ls_upd: Stop"); Index: ospfd/ospf_packet.h =================================================================== RCS file: /var/cvsroot/quagga/ospfd/ospf_packet.h,v retrieving revision 1.4 diff -u -r1.4 ospf_packet.h --- ospfd/ospf_packet.h 11 Oct 2004 11:00:30 -0000 1.4 +++ ospfd/ospf_packet.h 26 Nov 2004 14:10:11 -0000 @@ -133,7 +133,6 @@ #define IS_SET_DD_ALL(X) ((X) & OSPF_DD_FLAG_ALL) /* Prototypes. */ -void ospf_output_forward (struct stream *, int); struct ospf_packet *ospf_packet_new (size_t); void ospf_packet_free (struct ospf_packet *); struct ospf_fifo *ospf_fifo_new (); Index: zebra/irdp_packet.c =================================================================== RCS file: /var/cvsroot/quagga/zebra/irdp_packet.c,v retrieving revision 1.7 diff -u -r1.7 irdp_packet.c --- zebra/irdp_packet.c 20 Nov 2004 02:07:07 -0000 1.7 +++ zebra/irdp_packet.c 26 Nov 2004 14:10:11 -0000 @@ -35,7 +35,7 @@ #include - +#include #ifdef HAVE_IRDP @@ -306,11 +306,11 @@ icmp = (struct icmphdr *) (buf + sizeof (struct ip)); /* Merge IP header with icmp packet */ - - stream_get(icmp, s, s->putp); + assert (stream_get_endp(s) < (sizeof (buf) - sizeof (struct ip))); + stream_get(icmp, s, stream_get_endp(s)); /* icmp->checksum is already calculated */ - ip->ip_len = sizeof(struct ip) + s->putp; + ip->ip_len = sizeof(struct ip) + stream_get_endp(s); stream_free(s); on = 1; @@ -366,6 +366,3 @@ #endif /* HAVE_IRDP */ - - - Index: zebra/zserv.c =================================================================== RCS file: /var/cvsroot/quagga/zebra/zserv.c,v retrieving revision 1.21 diff -u -r1.21 zserv.c --- zebra/zserv.c 20 Nov 2004 02:07:07 -0000 1.21 +++ zebra/zserv.c 26 Nov 2004 14:10:12 -0000 @@ -562,7 +562,7 @@ { stream_putl (s, rib->metric); num = 0; - nump = s->putp; + nump = stream_get_putp(s); stream_putc (s, 0); for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) @@ -629,7 +629,7 @@ { stream_putl (s, rib->metric); num = 0; - nump = s->putp; + nump = stream_get_putp (s); stream_putc (s, 0); for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) @@ -690,7 +690,7 @@ { stream_putl (s, rib->metric); num = 0; - nump = s->putp; + nump = stream_get_putp (s); stream_putc (s, 0); for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) @@ -853,14 +853,14 @@ break; case ZEBRA_NEXTHOP_IFNAME: ifname_len = stream_getc (s); - stream_forward (s, ifname_len); + stream_forward_getp (s, ifname_len); break; case ZEBRA_NEXTHOP_IPV4: nexthop.s_addr = stream_get_ipv4 (s); nexthop_ipv4_add (rib, &nexthop); break; case ZEBRA_NEXTHOP_IPV6: - stream_forward (s, IPV6_MAX_BYTELEN); + stream_forward_getp (s, IPV6_MAX_BYTELEN); break; case ZEBRA_NEXTHOP_BLACKHOLE: nexthop_blackhole_add (rib); @@ -925,13 +925,13 @@ break; case ZEBRA_NEXTHOP_IFNAME: ifname_len = stream_getc (s); - stream_forward (s, ifname_len); + stream_forward_getp (s, ifname_len); break; case ZEBRA_NEXTHOP_IPV4: nexthop.s_addr = stream_get_ipv4 (s); break; case ZEBRA_NEXTHOP_IPV6: - stream_forward (s, IPV6_MAX_BYTELEN); + stream_forward_getp (s, IPV6_MAX_BYTELEN); break; } } Index: bgpd/bgp_attr.c =================================================================== RCS file: /var/cvsroot/quagga/bgpd/bgp_attr.c,v retrieving revision 1.6 diff -u -r1.6 bgp_attr.c --- bgpd/bgp_attr.c 31 Oct 2004 18:58:09 -0000 1.6 +++ bgpd/bgp_attr.c 26 Nov 2004 14:10:13 -0000 @@ -701,7 +701,7 @@ } /* Forward pointer. */ - stream_forward (peer->ibuf, length); + stream_forward_getp (peer->ibuf, length); /* Set aspath attribute flag. */ attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATH); @@ -789,7 +789,7 @@ receiving speaker. */ if (peer_sort (peer) == BGP_PEER_EBGP) { - stream_forward (peer->ibuf, length); + stream_forward_getp (peer->ibuf, length); return 0; } @@ -859,7 +859,7 @@ { attr->community = community_parse ((u_int32_t *)stream_pnt (peer->ibuf), length); - stream_forward (peer->ibuf, length); + stream_forward_getp (peer->ibuf, length); } attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); @@ -908,7 +908,7 @@ attr->cluster = cluster_parse ((struct in_addr *)stream_pnt (peer->ibuf), length); - stream_forward (peer->ibuf, length);; + stream_forward_getp (peer->ibuf, length);; attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST); @@ -991,7 +991,7 @@ while (snpa_num--) { snpa_len = stream_getc (s); - stream_forward (s, (snpa_len + 1) >> 1); + stream_forward_getp (s, (snpa_len + 1) >> 1); } /* If peer is based on old draft-00. I read NLRI length from the @@ -1016,7 +1016,7 @@ mp_update->nlri = stream_pnt (s); mp_update->length = nlri_len; - stream_forward (s, nlri_len); + stream_forward_getp (s, nlri_len); return 0; } @@ -1053,7 +1053,7 @@ mp_withdraw->nlri = stream_pnt (s); mp_withdraw->length = withdraw_len; - stream_forward (s, withdraw_len); + stream_forward_getp (s, withdraw_len); return 0; } @@ -1069,7 +1069,7 @@ { attr->ecommunity = ecommunity_parse ((u_int8_t *)stream_pnt (peer->ibuf), length); - stream_forward (peer->ibuf, length); + stream_forward_getp (peer->ibuf, length); } attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES); @@ -1089,7 +1089,7 @@ "Unknown attribute type %d length %d is received", type, length); /* Forward read pointer of input stream. */ - stream_forward (peer->ibuf, length); + stream_forward_getp (peer->ibuf, length); /* Adjest total length to include type and length. */ total = length + (CHECK_FLAG (flag, BGP_ATTR_FLAG_EXTLEN) ? 4 : 3); Index: bgpd/bgp_btoa.c =================================================================== RCS file: /var/cvsroot/quagga/bgpd/bgp_btoa.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 bgp_btoa.c --- bgpd/bgp_btoa.c 13 Dec 2002 20:15:29 -0000 1.1.1.1 +++ bgpd/bgp_btoa.c 26 Nov 2004 14:10:13 -0000 @@ -55,11 +55,12 @@ u_int16_t length; u_int16_t lim; - lim = s->getp + len; + lim = stream_get_getp (s) + len; - printf ("attr_parse s->getp %d, len %d, lim %d\n", s->getp, len, lim); + printf ("attr_parse stream_get_getp (s) %d, len %d, lim %d\n", + stream_get_getp (s), len, lim); - while (s->getp < lim) + while (stream_get_getp (s) < lim) { flag = stream_getc (s); type = stream_getc (s); @@ -86,13 +87,13 @@ { struct aspath aspath; - aspath.data = (s->data + s->getp); + aspath.data = (s->data + stream_get_getp (s)); aspath.length = length; aspath.str = aspath_make_str_count (&aspath); printf ("ASPATH: %s\n", aspath.str); free (aspath.str); - stream_forward (s, length); + stream_forward_getp (s, length); } break; case BGP_ATTR_NEXT_HOP: @@ -100,11 +101,11 @@ struct in_addr nexthop; nexthop.s_addr = stream_get_ipv4 (s); printf ("NEXTHOP: %s\n", inet_ntoa (nexthop)); - /* stream_forward (s, length); */ + /* stream_forward_getp (s, length); */ } break; default: - stream_forward (s, length); + stream_forward_getp (s, length); break; } } @@ -242,7 +243,7 @@ printf ("SEQUENCE: %d\n", seq_num); /* start */ - while (s->getp < len - 16) + while (stream_get_getp (s) < len - 16) { p.prefix.s_addr = stream_get_ipv4 (s); p.prefixlen = stream_getc (s); Index: bgpd/bgp_packet.c =================================================================== RCS file: /var/cvsroot/quagga/bgpd/bgp_packet.c,v retrieving revision 1.11 diff -u -r1.11 bgp_packet.c --- bgpd/bgp_packet.c 20 Nov 2004 02:07:00 -0000 1.11 +++ bgpd/bgp_packet.c 26 Nov 2004 14:10:14 -0000 @@ -102,23 +102,6 @@ stream_free (stream_fifo_pop (peer->obuf)); } -/* Duplicate packet. */ -struct stream * -bgp_packet_dup (struct stream *s) -{ - struct stream *new; - - new = stream_new (stream_get_endp (s)); - - new->endp = s->endp; - new->putp = s->putp; - new->getp = s->getp; - - memcpy (new->data, s->data, stream_get_endp (s)); - - return new; -} - /* Check file descriptor whether connect is established. */ static void bgp_connect_check (struct peer *peer) @@ -236,7 +219,7 @@ if (! stream_empty (s)) { bgp_packet_set_size (s); - packet = bgp_packet_dup (s); + packet = stream_dup (s); bgp_packet_add (peer, packet); BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd); stream_reset (s); @@ -320,7 +303,7 @@ stream_putw (s, 0); } bgp_packet_set_size (s); - packet = bgp_packet_dup (s); + packet = stream_dup (s); bgp_packet_add (peer, packet); stream_reset (s); return packet; @@ -384,7 +367,7 @@ /* Set size. */ bgp_packet_set_size (s); - packet = bgp_packet_dup (s); + packet = stream_dup (s); stream_free (s); /* Dump packet if debug option is set. */ @@ -463,7 +446,7 @@ bgp_packet_set_size (s); - packet = bgp_packet_dup (s); + packet = stream_dup (s); stream_free (s); /* Add packet to the peer. */ @@ -590,7 +573,7 @@ } if (num != writenum) { - stream_forward (s, num); + stream_forward_getp (s, num); if (write_errno == EAGAIN) break; @@ -986,7 +969,7 @@ } /* Make real packet. */ - packet = bgp_packet_dup (s); + packet = stream_dup (s); stream_free (s); /* Add packet to the peer. */ @@ -1049,7 +1032,7 @@ length = bgp_packet_set_size (s); /* Make real packet. */ - packet = bgp_packet_dup (s); + packet = stream_dup (s); stream_free (s); /* Add packet to the peer. */ @@ -1330,7 +1313,7 @@ if (ret < 0) return ret; - stream_forward (peer->ibuf, optlen); + stream_forward_getp (peer->ibuf, optlen); } else { @@ -1438,7 +1421,7 @@ withdraw.safi = SAFI_UNICAST; withdraw.nlri = stream_pnt (s); withdraw.length = withdraw_len; - stream_forward (s, withdraw_len); + stream_forward_getp (s, withdraw_len); } /* Attribute total length check. */ @@ -1500,7 +1483,7 @@ update.safi = SAFI_UNICAST; update.nlri = stream_pnt (s); update.length = update_len; - stream_forward (s, update_len); + stream_forward_getp (s, update_len); } /* NLRI is processed only when the peer is configured specific @@ -1893,7 +1876,7 @@ peer->orf_plist[afi][safi] = prefix_list_lookup (AFI_ORF_PREFIX, name); } - stream_forward (s, orf_len); + stream_forward_getp (s, orf_len); } if (BGP_DEBUG (normal, NORMAL)) zlog_info ("%s rcvd Refresh %s ORF request", peer->host, @@ -2099,7 +2082,7 @@ int nbytes; int readsize; - readsize = peer->packet_size - peer->ibuf->putp; + readsize = peer->packet_size - stream_get_putp (peer->ibuf); /* If size is zero then return. */ if (! readsize) @@ -2135,7 +2118,7 @@ } /* We read partial packet. */ - if (peer->ibuf->putp != peer->packet_size) + if (stream_get_putp (peer->ibuf) != peer->packet_size) return -1; return 0; @@ -2188,7 +2171,7 @@ if (peer->packet_size == 0) peer->packet_size = BGP_HEADER_SIZE; - if (peer->ibuf->putp < BGP_HEADER_SIZE) + if (stream_get_putp (peer->ibuf) < BGP_HEADER_SIZE) { ret = bgp_read_packet (peer); @@ -2197,7 +2180,7 @@ goto done; /* Get size and type. */ - stream_forward (peer->ibuf, BGP_MARKER_SIZE); + stream_forward_getp (peer->ibuf, BGP_MARKER_SIZE); memcpy (notify_data_length, stream_pnt (peer->ibuf), 2); size = stream_getw (peer->ibuf); type = stream_getc (peer->ibuf); Index: ripd/ripd.c =================================================================== RCS file: /var/cvsroot/quagga/ripd/ripd.c,v retrieving revision 1.34 diff -u -r1.34 ripd.c --- ripd/ripd.c 20 Nov 2004 02:07:00 -0000 1.34 +++ ripd/ripd.c 26 Nov 2004 14:10:16 -0000 @@ -970,7 +970,7 @@ return; /* Get packet length. */ - len = s->putp; + len = stream_get_putp (s); /* Check packet length. */ if (len < (RIP_HEADER_SIZE + RIP_RTE_SIZE)) @@ -1029,7 +1029,7 @@ memset (secret, 0, RIP_AUTH_MD5_SIZE); strncpy ((char *)secret, auth_str, RIP_AUTH_MD5_SIZE); md5_init_ctx (&ctx); - md5_process_bytes (s->data, s->endp, &ctx); + md5_process_bytes (s->data, stream_get_endp(s), &ctx); md5_process_bytes (secret, RIP_AUTH_MD5_SIZE, &ctx); md5_finish_ctx (&ctx, digest); @@ -2038,9 +2038,9 @@ stream_putw (s, RIP_FAMILY_AUTH); stream_putw (s, RIP_AUTH_SIMPLE_PASSWORD); - memset ((s->data + s->putp), 0, 16); - strncpy ((char *)(s->data + s->putp), ri->auth_str, 16); - stream_set_putp (s, s->putp + 16); + memset ((s->data + stream_get_putp (s)), 0, 16); + strncpy ((char *)(s->data + stream_get_putp (s)), ri->auth_str, 16); + stream_set_putp (s, stream_get_putp (s) + 16); num++; } @@ -2060,10 +2060,10 @@ stream_putw (s, RIP_FAMILY_AUTH); stream_putw (s, RIP_AUTH_SIMPLE_PASSWORD); - memset ((s->data + s->putp), 0, 16); - strncpy ((char *)(s->data + s->putp), + memset ((s->data + stream_get_putp (s)), 0, 16); + strncpy ((char *)(s->data + stream_get_putp (s)), key->string, 16); - stream_set_putp (s, s->putp + 16); + stream_set_putp (s, stream_get_putp (s) + 16); num++; }