diff options
-rw-r--r-- | isisd/ChangeLog | 29 | ||||
-rw-r--r-- | isisd/isis_lsp.c | 30 | ||||
-rw-r--r-- | isisd/isis_network.c | 27 | ||||
-rw-r--r-- | isisd/isis_pdu.c | 7 | ||||
-rw-r--r-- | isisd/isis_tlv.c | 4 |
5 files changed, 54 insertions, 43 deletions
diff --git a/isisd/ChangeLog b/isisd/ChangeLog index 081ee654..d5c8ec52 100644 --- a/isisd/ChangeLog +++ b/isisd/ChangeLog @@ -1,3 +1,32 @@ +2005-05-03 Paul Jakma <paul@dishone.st> + + * (general) More cleaning up of stream abuse, isisd should be + back to previous functionality. Replace various XMALLOC+memset's + with XCALLOC + * isis_tlv.c: (tlv_add_padding) use stream_put to clear the stream + rather than forward endp, as isisd reuses streams. + * isis_pdu.c: (process_lsp) cleanup direct reference to stream endp + (send_lsp) manual copy of a stream cleaned up to use stream_copy. + * isis_network.c: (isis_recv_pdu_bcast) replace direct memcpy with + stream_write + (isis_recv_pdu_p2p) replace recvfrom directly into stream with + stream_recvfrom. Remove dangerous and now unneeded manual update + of endp. + (isis_recv_pdu_bcast / non-GNU_LINUX) Replace direct memcpy with + stream_write. + (isis_recv_pdu_p2p) replace read direct into stream with + stream_read_try, and hence remove the manual update of endp. + * isis_lsp.c: (lsp_update_data) manual stream dup replaced with + stream_dup. + (lsppdu_realloc) mempcy into stream data replaced with stream_put. + (lsp_build_nonpseudo) remove mysterious stream_forward_endp's - + which were originally stream_set_putp - shouldn't be needed + now that all the manual fiddling of private stream data has been + corrected. + (build_topology_lsp_data) remove unneeded twiddling of endp, + appears to be due to lsppdu_realloc(), but it appears to sort of + do the right thing wrt streams. + 2005-04-15 Paul Jakma <paul@dishone.st> * topology/Makefile.am: random.c is a source of libtopology, so list diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index f59e804b..0860b150 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -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 <stdlib.h> #include <stdio.h> #include <zebra.h> @@ -364,11 +365,8 @@ lsp_update_data (struct isis_lsp *lsp, struct stream *stream, 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, int memorytype, int size) #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 *lsp, struct isis_area *area) } } - 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 *lsp, struct isis_area *area) /* * 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, struct isis_circuit *circuit, 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, struct isis_circuit *circuit, (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, struct isis_circuit *circuit, 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 *lsp, struct isis_area *area, (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 */ diff --git a/isisd/isis_network.c b/isisd/isis_network.c index 2e901f1a..466a9177 100644 --- a/isisd/isis_network.c +++ b/isisd/isis_network.c @@ -420,9 +420,7 @@ isis_recv_pdu_bcast (struct isis_circuit *circuit, u_char * ssnpa) (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 *circuit, u_char * ssnpa) 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 *circuit, u_char * ssnpa) 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 *circuit, u_char * ssnpa) 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 *circuit, u_char * ssnpa) { 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 *circuit, u_char * ssnpa) return ISIS_WARNING; } - circuit->rcv_stream->endp = bytesread; - return ISIS_OK; } diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 9d3b18ad..b83c6339 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -949,7 +949,8 @@ process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa) 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); diff --git a/isisd/isis_tlv.c b/isisd/isis_tlv.c index 3dae5d89..1194f046 100644 --- a/isisd/isis_tlv.c +++ b/isisd/isis_tlv.c @@ -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; |