This is a replacement for buffer.c which handles the
buffering of packets when the link is down and forwards
them when the link comes up.
It fixes two bugs:
1/ The buffer would be corrupted if the
'-buffer-fifo-dispose' option was used. This was due
to disposing of packets from the buffer without
checking whether it was empty.
2/ Resizing the buffer would cause corruption. ie.
changing the buffer_size option in /etc/diald.conf, and
then issuing a 'reset' command on the fifo or tcpport.
This was because buffer state vars were not reset. So
head/tail/used would be wrong.
It also makes these changes:
Added a struct for the buffer packet header.
Changed the 'stamp' field to an 'expires' field; ie.
now adds 'buffer-timeout' before buffering. This paves
the way for different timeouts for different packet
types. eg. ntp is not happy if packets get buffered
for 10 mins!
The algorithm for reads/writes of the ring buffer uses
either one or two calls to memcpy(3), instead of the
byte-by-byte loop with modulo arithmetic.
More paranoid when setting up the buffer, checking
parameters and return values.
Setting buffer_size to 0 (or malloc(3) failing) will
disable the forward_packets option.
Note: The diff was bigger than the file, hence the
replacement.
Replacement buffer.c for v1.0
Logged In: NO
bug! i try it...