fr_bio_read_t discard, fr_bio_t *next)
{
fr_bio_network_t *my;
- fr_bio_t *fd;
fr_bio_fd_info_t const *info;
/*
* want to have an API which allows for two different "offset" values to be passed to two
* different bios.
*/
- fd = NULL;
-
- /*
- * @todo - add an internal "type" to the bio?
- */
- do {
- if (strcmp(talloc_get_name(next), "fr_bio_fd_t") == 0) {
- fd = next;
- break;
- }
- } while ((next = fr_bio_next(next)) != NULL);
-
- if (!fd) return NULL;
+ if (strcmp(talloc_get_name(next), "fr_bio_fd_t") != 0) {
+ fr_strerror_const("Invalid 'next' BIO - must be an FD one");
+ return NULL;
+ }
- info = fr_bio_fd_info(fd);
+ info = fr_bio_fd_info(next);
fr_assert(info != NULL);
/*
case FR_BIO_FD_INVALID:
case FR_BIO_FD_CONNECTED:
+ fr_strerror_const("Cannot use network BIO with connected FD BIO");
return NULL;
case FR_BIO_FD_LISTEN:
my = talloc_zero(ctx, fr_bio_network_t);
if (!my) return NULL;
- my->offset = ((fr_bio_fd_t *) fd)->offset;
+ my->offset = ((fr_bio_fd_t *) next)->offset;
my->discard = discard;
my->bio.write = fr_bio_next_write;
}
fr_bio_chain(&my->bio, next);
+ talloc_set_destructor((fr_bio_t *) my, fr_bio_destructor); /* always use a common destructor */
return (fr_bio_t *) my;
}
*/
if (fr_trie_insert_by_key(trie, &allow[i].addr, allow[i].prefix, FR_BIO_NETWORK_ALLOW) < 0) {
fr_strerror_printf("Failed adding 'allow = %pV' to filtering rules", fr_box_ipaddr(allow[i]));
- return NULL;
+ goto fail;
}
}
*/
if (fr_trie_insert_by_key(trie, &deny[i].addr, deny[i].prefix, FR_BIO_NETWORK_DENY) < 0) {
fr_strerror_printf("Failed adding 'deny = %pV' to filtering rules", fr_box_ipaddr(deny[i]));
- return NULL;
+ goto fail;
}
}