25#include <freeradius-devel/bio/bio_priv.h>
26#include <freeradius-devel/bio/null.h>
27#include <freeradius-devel/bio/buf.h>
29#include <freeradius-devel/bio/mem.h>
76 my->priv_cb.eof = NULL;
153 if (rcode < 0)
return rcode;
182 if (rcode == 0)
return 0;
221 if (rcode != 0)
return rcode;
256 if (rcode <= 0)
return rcode;
282 if (rcode <= 0)
return rcode;
338 size_t room, leftover;
353 if (rcode < 0)
return rcode;
358 if ((
size_t) rcode == size)
return rcode;
365 if (!
buffer)
return rcode;
371 if (error < 0)
return error;
383 leftover = size - rcode;
391 if (room < leftover) leftover = room;
451 if (rcode < 0)
return rcode;
509 if (rcode < 0)
return rcode;
527 if (rcode < 0)
return rcode;
544 if (!
used)
return NULL;
582 while (packet < end) {
618 packet = my->read_buffer.
read += want;
646 if (size < 1024) size = 1024;
647 if (size > (1 << 20)) size = 1 << 20;
684 if (!my)
return NULL;
694 if (write_size > 0) {
696 fr_strerror_const(
"Invalid write size. If read size is zero, then write size must also be zero");
755 if (!write_size)
return NULL;
758 if (!my)
return NULL;
808 if (room < size) size = room;
827 if (!read_size)
return NULL;
830 if (!my)
return NULL;
873 fr_strerror_const(
"Invalid memory BIO - we need a read buffer for verifying packets from a stream socket");
952 if (!my->cb.write_resume)
return 1;
954 return my->cb.write_resume(bio);
static int const char char buffer[256]
fr_bio_write_t _CONST write
write to the underlying bio
fr_bio_read_t _CONST read
read from the underlying bio
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
static int packet_ctx
the tests pass only the address of packet_ctx
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
size_t fr_bio_buf_make_room(fr_bio_buf_t *bio_buf)
size_t fr_bio_buf_read(fr_bio_buf_t *bio_buf, void *buffer, size_t size)
int fr_bio_buf_alloc(TALLOC_CTX *ctx, fr_bio_buf_t *bio_buf, size_t size)
ssize_t fr_bio_buf_write(fr_bio_buf_t *bio_buf, const void *buffer, size_t size)
static bool fr_bio_buf_initialized(fr_bio_buf_t const *bio_buf)
static size_t fr_bio_buf_write_room(fr_bio_buf_t const *bio_buf)
uint8_t * start
start of the buffer
static size_t fr_bio_buf_used(fr_bio_buf_t const *bio_buf)
static void fr_bio_buf_reset(fr_bio_buf_t *bio_buf)
static uint8_t * fr_bio_buf_write_reserve(fr_bio_buf_t *bio_buf, size_t size)
uint8_t * read
where in the buffer reads are taken from
static int fr_bio_buf_write_alloc(fr_bio_buf_t *bio_buf, size_t size)
uint8_t * write
where in the buffer writes are sent to
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
int fr_bio_write_blocked(fr_bio_t *bio)
Internal BIO function to tell all BIOs that it's blocked.
int fr_bio_shutdown_discard(fr_bio_t *bio)
Shut down the chain now, discarding anything which is still buffered.
int fr_bio_destructor(fr_bio_t *bio)
Free this bio.
fr_bio_t * fr_bio_eof(fr_bio_t *bio)
Internal BIO function to run EOF callbacks.
ssize_t fr_bio_next_write(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Internal bio function which just writes to the "next" bio.
fr_bio_t * fr_bio_mem_alloc(TALLOC_CTX *ctx, size_t read_size, size_t write_size, fr_bio_t *next)
Allocate a memory buffer bio.
static ssize_t fr_bio_mem_write_read_buffer(fr_bio_t *bio, UNUSED void *packet_ctx, void const *buffer, size_t size)
Write to the read buffer.
static ssize_t fr_bio_mem_read_verify_stream(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Return data only if we have a complete packet.
void * verify_ctx
verify context
void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size)
Discard data from the read buffer.
fr_bio_t * fr_bio_mem_sink_alloc(TALLOC_CTX *ctx, size_t read_size)
Allocate a memory buffer which sinks data from a bio system into the callers application.
fr_bio_buf_t read_buffer
buffering for reads
static int fr_bio_mem_eof(fr_bio_t *bio)
struct fr_bio_mem_s fr_bio_mem_t
The memory buffer bio.
static ssize_t fr_bio_mem_write_next(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Pass writes to the next BIO.
static ssize_t fr_bio_mem_read_verify_datagram(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Return data only if we have a complete packet.
fr_bio_t * fr_bio_mem_source_alloc(TALLOC_CTX *ctx, size_t write_size, fr_bio_t *next)
Allocate a memory buffer which sources data from the callers application into the bio system.
static ssize_t fr_bio_mem_read_buffer(fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
Read from a buffer which a previous bio has filled.
int fr_bio_mem_write_resume(fr_bio_t *bio)
See if we can resume writes to the memory bio.
fr_bio_buf_t write_buffer
buffering for writes
fr_bio_verify_t verify
verify data to see if we have a packet.
static ssize_t fr_bio_mem_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Read from a memory BIO.
int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram)
Set the verification function for memory bios.
fr_bio_mem_type_t type
source, sink, etc.
static ssize_t fr_bio_mem_read_eof(fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
At EOF, read data from the buffer until it is empty.
static bool fr_bio_mem_buf_alloc(fr_bio_mem_t *my, fr_bio_buf_t *buf, size_t size)
Allocate a memory buffer bio for either reading or writing.
static ssize_t fr_bio_mem_write_flush(fr_bio_mem_t *my, size_t size)
Flush the memory buffer.
static int fr_bio_mem_call_verify(fr_bio_t *bio, void *packet_ctx, size_t *size))
Verify that a packet is OK.
int fr_bio_mem_write_pause(fr_bio_t *bio)
Pause writes.
uint8_t const * fr_bio_mem_read_peek(fr_bio_t *bio, size_t *size)
Peek at the data in the read buffer.
static ssize_t fr_bio_mem_read_packet(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
See is there's a full packet in the buffer.
static ssize_t fr_bio_mem_write_buffer(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
fr_bio_verify_action_t(* fr_bio_verify_t)(fr_bio_t *bio, void *verify_ctx, void *packet_ctx, const void *buffer, size_t *size)
Verifies the packet.
@ FR_BIO_VERIFY_ERROR_CLOSE
fatal error, the bio should be closed.
@ FR_BIO_VERIFY_DISCARD
the packet should be discarded
@ FR_BIO_VERIFY_OK
packet is OK
@ FR_BIO_VERIFY_WANT_MORE
not enough data for one packet
ssize_t fr_bio_fail_read(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void *buffer, UNUSED size_t size)
Always return error on read.
#define fr_strerror_const(_msg)