25 #include <freeradius-devel/util/value.h>
26 #include <freeradius-devel/util/trie.h>
28 #include <freeradius-devel/bio/bio_priv.h>
29 #include <freeradius-devel/bio/fd_priv.h>
31 #include <freeradius-devel/bio/network.h>
60 if (rcode <= 0)
return rcode;
62 if (!packet_ctx)
return rcode;
70 &addr->
socket.inet.src_ipaddr.addr, addr->
socket.inet.src_ipaddr.prefix);
72 if (
my->discard)
return my->discard(bio, packet_ctx,
buffer, rcode);
110 if (strcmp(talloc_get_name(
next),
"fr_bio_fd_t") == 0) {
116 if (!fd)
return NULL;
126 if (!((info->
socket.
af == AF_INET) || (info->
socket.
af == AF_INET6)))
return NULL;
131 switch (info->
type) {
144 if (!
my)
return NULL;
147 my->discard = discard;
172 if (!trie)
return NULL;
174 num = talloc_array_length(allow);
177 for (i = 0; i < num; i++) {
183 if (allow[i].af != af) {
210 if (network && (network->prefix <= allow[i].
prefix)) {
212 fr_strerror_const(
"Entry is completely enclosed inside of a previously defined network.");
229 num = talloc_array_length(deny);
230 if (!num)
return trie;
235 for (i = 0; i < num; i++) {
241 if (deny[i].af != af) {
262 "contained within a previous 'allow'", i + 1,
fr_box_ipaddr(deny[i]));
static int const char char buffer[256]
ssize_t(* fr_bio_read_t)(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Do a raw read from a socket, or other data source.
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
size_t offset
where fr_bio_fd_packet_ctx_t is stored
fr_trie_t * fr_bio_network_trie_alloc(TALLOC_CTX *ctx, int af, fr_ipaddr_t const *allow, fr_ipaddr_t const *deny)
Create a patricia trie for doing network filtering.
fr_bio_read_t discard
callback to run when discarding a packet due to filtering
fr_bio_t * fr_bio_network_alloc(TALLOC_CTX *ctx, fr_ipaddr_t const *allow, fr_ipaddr_t const *deny, fr_bio_read_t discard, fr_bio_t *next)
Allocate a bio for filtering IP addresses.
static ssize_t fr_bio_network_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Read a UDP packet, and only return packets from allowed sources.
fr_trie_t const * trie
patricia trie for filtering
The network filtering bio.
#define FR_BIO_NETWORK_DENY
#define FR_BIO_NETWORK_ALLOW
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
fr_bio_fd_info_t const * fr_bio_fd_info(fr_bio_t *bio)
Returns a pointer to the bio-specific information.
fr_socket_t socket
as connected socket
@ FR_BIO_FD_ACCEPTED
temporarily until it's connected.
@ FR_BIO_FD_CONNECTED
connected client sockets (UDP or TCP)
@ FR_BIO_FD_UNCONNECTED
unconnected UDP / datagram only
@ FR_BIO_FD_LISTEN
returns new fd in buffer on fr_bio_read() or fr_bio_fd_accept()
fr_bio_fd_type_t type
type of the socket
fr_socket_t socket
socket information, including FD.
Run-time status of the socket.
#define fr_bio_fd_packet_ctx(_my, _packet_ctx)
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
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_trie_t * fr_trie_alloc(TALLOC_CTX *ctx, fr_trie_key_t get_key, fr_free_t free_data)
Allocate a trie.
void * fr_trie_match_by_key(fr_trie_t const *ft, void const *key, size_t keylen)
Match a key and length in a trie and return user ctx, if any.
int fr_trie_insert_by_key(fr_trie_t *ft, void const *key, size_t keylen, void const *data)
Insert a key and user ctx into a trie.
void * fr_trie_lookup_by_key(fr_trie_t const *ft, void const *key, size_t keylen)
Lookup a key in a trie and return user ctx, if any.
int af
AF_INET, AF_INET6, or AF_UNIX.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
#define fr_box_ipaddr(_val)