? lib/aaa-notes.txt Index: isisd/isis_lsp.c =================================================================== RCS file: /var/cvsroot/quagga/isisd/isis_lsp.c,v retrieving revision 1.20 diff -u -p -r1.20 isis_lsp.c --- isisd/isis_lsp.c 10 Apr 2005 15:58:10 -0000 1.20 +++ isisd/isis_lsp.c 3 May 2005 07:35:09 -0000 @@ -20,6 +20,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #include #include #include @@ -364,11 +365,8 @@ lsp_update_data (struct isis_lsp *lsp, s int retval; /* copying only the relevant part of our stream */ - lsp->pdu = stream_new (stream->endp); - lsp->pdu->getp = stream->getp; - lsp->pdu->endp = stream->endp; - memcpy (lsp->pdu->data, stream->data, stream->endp); - + lsp->pdu = stream_dup (stream); + /* setting pointers to the correct place */ lsp->isis_header = (struct isis_fixed_hdr *) (STREAM_DATA (lsp->pdu)); lsp->lsp_header = (struct isis_link_state_hdr *) (STREAM_DATA (lsp->pdu) + @@ -926,8 +924,7 @@ lsppdu_realloc (struct isis_lsp * lsp, i #else /* otherwise we have to move all pointers */ u_char *newpdu; newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size); - memcpy (STREAM_DATA (newpdu), STREAM_DATA (lsp->pdu), - ntohs (lsp->lsp_header->pdu_len)); + stream_put (newpdu, STREAM_DATA(lsp->pdu), ntohs (lsp->lsp_header->pdu_len); XFREE (memorytype, lsp->pdu); lsp->pdu = newpdu; lsp->isis_header = (struct isis_fixed_hdr *) STREAM_DATA (lsp->pdu); @@ -1132,8 +1129,6 @@ lsp_build_nonpseudo (struct isis_lsp *ls } } - stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); - if (lsp->tlv_data.nlpids) tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu); if (lsp->tlv_data.hostname) @@ -1310,7 +1305,6 @@ lsp_build_nonpseudo (struct isis_lsp *ls /* * Building the zero lsp */ - stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); /* * Add the authentication info if its present */ @@ -1874,8 +1868,8 @@ lsp_build_pseudo (struct isis_lsp *lsp, lsp->tlv_data.is_neighs = list_new (); lsp->tlv_data.is_neighs->del = free_tlv; } - is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); - memset (is_neigh, 0, sizeof (struct is_neigh)); + is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); + memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN); listnode_add (lsp->tlv_data.is_neighs, is_neigh); @@ -1892,8 +1886,8 @@ lsp_build_pseudo (struct isis_lsp *lsp, (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) { /* an IS neighbour -> add it */ - is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); - memset (is_neigh, 0, sizeof (struct is_neigh)); + is_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh)); + memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN); listnode_add (lsp->tlv_data.is_neighs, is_neigh); } @@ -1906,15 +1900,14 @@ lsp_build_pseudo (struct isis_lsp *lsp, lsp->tlv_data.es_neighs = list_new (); lsp->tlv_data.es_neighs->del = free_tlv; } - es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh)); - memset (es_neigh, 0, sizeof (struct es_neigh)); + es_neigh = XCALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh)); + memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN); listnode_add (lsp->tlv_data.es_neighs, is_neigh); } } } - stream_forward_endp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); /* * Add the authentication info if it's present */ @@ -2452,8 +2445,5 @@ build_topology_lsp_data (struct isis_lsp (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen (buff)) - 1); memcpy (lsp->tlv_data.hostname->name, buff, strlen (buff)); } - - /* thanks to hannes, another bug bites the dust */ - lsp->pdu->endp = ntohs (lsp->lsp_header->pdu_len); } #endif /* TOPOLOGY_GENERATE */ Index: isisd/isis_network.c =================================================================== RCS file: /var/cvsroot/quagga/isisd/isis_network.c,v retrieving revision 1.9 diff -u -p -r1.9 isis_network.c --- isisd/isis_network.c 9 Feb 2005 15:51:57 -0000 1.9 +++ isisd/isis_network.c 3 May 2005 07:35:09 -0000 @@ -420,9 +420,7 @@ isis_recv_pdu_bcast (struct isis_circuit (struct sockaddr *) &s_addr, (socklen_t *) &addr_len); /* then we lose the LLC */ - memcpy (STREAM_DATA (circuit->rcv_stream), - sock_buff + LLC_LEN, bytesread - LLC_LEN); - circuit->rcv_stream->endp = bytesread - LLC_LEN; + stream_write (circuit->rcv_stream, sock_buff + LLC_LEN, bytesread - LLC_LEN); memcpy (ssnpa, &s_addr.sll_addr, s_addr.sll_halen); @@ -439,9 +437,10 @@ isis_recv_pdu_p2p (struct isis_circuit * addr_len = sizeof (s_addr); /* we can read directly to the stream */ - bytesread = recvfrom (circuit->fd, STREAM_DATA (circuit->rcv_stream), - circuit->interface->mtu, 0, - (struct sockaddr *) &s_addr, (socklen_t *) &addr_len); + bytesread = stream_recvfrom (circuit->rcv_stream, circuit->fd, + circuit->interface->mtu, 0, + (struct sockaddr *) &s_addr, + (socklen_t *) &addr_len); if (s_addr.sll_pkttype == PACKET_OUTGOING) { @@ -452,8 +451,6 @@ isis_recv_pdu_p2p (struct isis_circuit * return ISIS_WARNING; } - circuit->rcv_stream->endp = bytesread; - /* If we don't have protocol type 0x00FE which is * ISO over GRE we exit with pain :) */ @@ -572,11 +569,9 @@ isis_recv_pdu_bcast (struct isis_circuit offset = bpf_hdr->bh_hdrlen + LLC_LEN + ETHER_HDR_LEN; /* then we lose the BPF, LLC and ethernet headers */ - memcpy (STREAM_DATA (circuit->rcv_stream), - readbuff + offset, bpf_hdr->bh_caplen - LLC_LEN - ETHER_HDR_LEN); - - circuit->rcv_stream->endp = bpf_hdr->bh_caplen - LLC_LEN - ETHER_HDR_LEN; - circuit->rcv_stream->getp = 0; + stream_write (circuit->rcv_stream, readbuff + offset, + bpf_hdr->bh_caplen - LLC_LEN - ETHER_HDR_LEN); + stream_set_getp (circuit->rcv_stream, 0); memcpy (ssnpa, readbuff + bpf_hdr->bh_hdrlen + ETHER_ADDR_LEN, ETHER_ADDR_LEN); @@ -592,8 +587,8 @@ isis_recv_pdu_p2p (struct isis_circuit * { int bytesread; - bytesread = read (circuit->fd, STREAM_DATA (circuit->rcv_stream), - circuit->interface->mtu); + bytesread = stream_read (circuit->rcv_stream, circuit->fd, + circuit->interface->mtu); if (bytesread < 0) { @@ -601,8 +596,6 @@ isis_recv_pdu_p2p (struct isis_circuit * return ISIS_WARNING; } - circuit->rcv_stream->endp = bytesread; - return ISIS_OK; } Index: isisd/isis_pdu.c =================================================================== RCS file: /var/cvsroot/quagga/isisd/isis_pdu.c,v retrieving revision 1.16 diff -u -p -r1.16 isis_pdu.c --- isisd/isis_pdu.c 7 Apr 2005 07:30:20 -0000 1.16 +++ isisd/isis_pdu.c 3 May 2005 07:35:10 -0000 @@ -949,7 +949,8 @@ process_lsp (int level, struct isis_circ ntohl (hdr->seq_num), ntohs (hdr->checksum), ntohs (hdr->rem_lifetime), - circuit->rcv_stream->endp, circuit->interface->name); + stream_get_endp (circuit->rcv_stream), + circuit->interface->name); } assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN); @@ -2497,9 +2498,7 @@ send_lsp (struct thread *thread) circuit->interface->name); } /* copy our lsp to the send buffer */ - circuit->snd_stream->getp = lsp->pdu->getp; - circuit->snd_stream->endp = lsp->pdu->endp; - memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp); + stream_copy (circuit->snd_stream, lsp->pdu); retval = circuit->tx (circuit, lsp->level); Index: isisd/isis_tlv.c =================================================================== RCS file: /var/cvsroot/quagga/isisd/isis_tlv.c,v retrieving revision 1.13 diff -u -p -r1.13 isis_tlv.c --- isisd/isis_tlv.c 7 Apr 2005 07:30:20 -0000 1.13 +++ isisd/isis_tlv.c 3 May 2005 07:35:10 -0000 @@ -1069,7 +1069,7 @@ tlv_add_padding (struct stream *stream) goto err; if (!stream_putc (stream, (u_char) 255)) /* LENGHT */ goto err; - stream_forward_endp (stream, 255); /* VALUE */ + stream_put (stream, NULL, 255); /* zero padding */ } left = STREAM_SIZE (stream) - stream_get_endp (stream); @@ -1086,7 +1086,7 @@ tlv_add_padding (struct stream *stream) stream_putc (stream, PADDING); stream_putc (stream, left - 2); - stream_forward_endp (stream, left - 2); + stream_put (stream, NULL, left-2); return ISIS_OK; Index: lib/stream.c =================================================================== RCS file: /var/cvsroot/quagga/lib/stream.c,v retrieving revision 1.9 diff -u -p -r1.9 stream.c --- lib/stream.c 24 Feb 2005 16:02:53 -0000 1.9 +++ lib/stream.c 3 May 2005 07:35:10 -0000 @@ -208,6 +208,20 @@ stream_forward_endp (struct stream *s, s s->endp += size; } + +void +stream_set_endp (struct stream *s, size_t size) +{ + STREAM_VERIFY_SANE(s); + + if (!ENDP_VALID (s, size)) + { + STREAM_BOUND_WARN (s, "seek endp"); + return; + } + + s->endp = size; +} /* Copy from stream to destination. */ void @@ -368,6 +382,8 @@ stream_get_ipv4 (struct stream *s) * * XXX: This uses CHECK_SIZE and hence has funny semantics -> Size will wrap * around. This should be fixed once the stream updates are working. + * + * stream_write() is saner */ void stream_put (struct stream *s, void *src, size_t size) @@ -630,12 +646,44 @@ stream_read_try(struct stream *s, int fd return -1; } +/* Read up to size bytes into the stream from the fd, using recvmsgfrom + * whose arguments match the remaining arguments to this function + */ +ssize_t +stream_recvfrom (struct stream *s, int fd, size_t size, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + ssize_t nbytes; + + STREAM_VERIFY_SANE(s); + + if (STREAM_WRITEABLE(s) < size) + { + STREAM_BOUND_WARN (s, "put"); + /* Fatal (not transient) error, since retrying will not help + (stream is too small to contain the desired data). */ + return -1; + } + + if ((nbytes = recvfrom (fd, s->data + s->endp, size, + flags, from, fromlen)) >= 0) + { + s->endp += nbytes; + return nbytes; + } + /* Error: was it transient (return -2) or fatal (return -1)? */ + if (ERRNO_IO_RETRY(errno)) + return -2; + zlog_warn("%s: read failed on fd %d: %s", __func__, fd, safe_strerror(errno)); + return -1; +} + /* Read up to smaller of size or SIZE_REMAIN() bytes to the stream, starting * from endp. * First iovec will be used to receive the data. * Stream need not be empty. */ -int +ssize_t stream_recvmsg (struct stream *s, int fd, struct msghdr *msgh, int flags, size_t size) { @@ -666,7 +714,7 @@ stream_recvmsg (struct stream *s, int fd } /* Write data to buffer. */ -int +size_t stream_write (struct stream *s, u_char *ptr, size_t size) { Index: lib/stream.h =================================================================== RCS file: /var/cvsroot/quagga/lib/stream.h,v retrieving revision 1.7 diff -u -p -r1.7 stream.h --- lib/stream.h 24 Feb 2005 16:02:53 -0000 1.7 +++ lib/stream.h 3 May 2005 07:35:10 -0000 @@ -184,9 +184,11 @@ int stream_read_unblock (struct stream * */ extern ssize_t stream_read_try(struct stream *s, int fd, size_t size); -int stream_recvmsg (struct stream *s, int fd, struct msghdr *, +extern ssize_t stream_recvmsg (struct stream *s, int fd, struct msghdr *, int flags, size_t size); -int stream_write (struct stream *, u_char *, size_t); +extern ssize_t stream_recvfrom (struct stream *s, int fd, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); +size_t stream_write (struct stream *, u_char *, size_t); void stream_reset (struct stream *); /* reset the stream. See Note above */ int stream_flush (struct stream *, int); @@ -203,4 +205,8 @@ struct stream *stream_fifo_head (struct void stream_fifo_clean (struct stream_fifo *fifo); void stream_fifo_free (struct stream_fifo *fifo); +#if !defined(QUAGGA_NO_DEPRECATED_INTERFACES) +extern void stream_set_endp (struct stream *, size_t); +#endif /* !QUAGGA_NO_DEPRECATED_INTERFACES*/ + #endif /* _ZEBRA_STREAM_H */