The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
bio.c
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: aa6687ba81b103a2b6d382d2403a721b748fa9d9 $
19 *
20 * @file protocols/radius/bio.c
21 * @brief Functions to support RADIUS bio handlers
22 *
23 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSID("$Id: aa6687ba81b103a2b6d382d2403a721b748fa9d9 $")
26
27#include <freeradius-devel/radius/bio.h>
28
29/** Callback for RADIUS packet verification.
30 *
31 */
32fr_bio_verify_action_t fr_radius_bio_verify(UNUSED fr_bio_t *bio, void *verify_ctx, UNUSED void *packet_ctx, const void *data, size_t *size)
33{
35 size_t in_buffer = *size;
36 fr_radius_bio_verify_t *uctx = verify_ctx;
37 uint8_t const *hdr = data;
38 size_t want;
39
40 if (in_buffer < 4) {
43 }
44
45 want = fr_nbo_to_uint16(hdr + 2);
46 if (uctx->max_packet_size && (want > uctx->max_packet_size)) {
48 }
49
50 /*
51 * See if we need to discard the packet.
52 */
53 if (!fr_radius_ok(data, size, uctx->max_attributes, uctx->require_message_authenticator, &failure)) {
55
57 }
58
59 if (!uctx->allowed[hdr[0]]) return FR_BIO_VERIFY_DISCARD;
60
61 /*
62 * On input, *size is how much data we have. On output, *size is how much data we want.
63 */
64 return (in_buffer >= *size) ? FR_BIO_VERIFY_OK : FR_BIO_VERIFY_WANT_MORE;
65}
66
67/** And verify a datagram packet.
68 *
69 */
70fr_bio_verify_action_t fr_radius_bio_verify_datagram(UNUSED fr_bio_t *bio, void *verify_ctx, UNUSED void *packet_ctx, const void *data, size_t *size)
71{
73 size_t in_buffer = *size;
74 fr_radius_bio_verify_t *uctx = verify_ctx;
75 uint8_t const *hdr = data;
76 size_t want;
77
78 if (in_buffer < RADIUS_HEADER_LENGTH) return FR_BIO_VERIFY_DISCARD;
79
80 want = fr_nbo_to_uint16(hdr + 2);
81 if (uctx->max_packet_size && (want > uctx->max_packet_size)) {
83 }
84
85 /*
86 * See if we need to discard the packet.
87 *
88 * @todo - move the "allowed" list to this function
89 */
90 if (!fr_radius_ok(data, size, uctx->max_attributes, uctx->require_message_authenticator, &failure)) {
92 }
93
94 if (!uctx->allowed[hdr[0]]) return FR_BIO_VERIFY_DISCARD;
95
96 /*
97 * On input, *size is how much data we have. On output, *size is how much data we want.
98 */
99 return (in_buffer >= *size) ? FR_BIO_VERIFY_OK : FR_BIO_VERIFY_DISCARD;
100}
#define RCSID(id)
Definition build.h:483
#define UNUSED
Definition build.h:315
fr_bio_verify_action_t
Status returned by the verification callback.
Definition mem.h:32
@ FR_BIO_VERIFY_ERROR_CLOSE
fatal error, the bio should be closed.
Definition mem.h:36
@ FR_BIO_VERIFY_DISCARD
the packet should be discarded
Definition mem.h:34
@ FR_BIO_VERIFY_OK
packet is OK
Definition mem.h:33
@ FR_BIO_VERIFY_WANT_MORE
not enough data for one packet
Definition mem.h:35
bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p, uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
unsigned char uint8_t
static uint16_t fr_nbo_to_uint16(uint8_t const data[static sizeof(uint16_t)])
Read an unsigned 16bit integer from wire format (big endian)
Definition nbo.h:146
#define RADIUS_HEADER_LENGTH
Definition net.h:80
fr_bio_verify_action_t fr_radius_bio_verify_datagram(UNUSED fr_bio_t *bio, void *verify_ctx, UNUSED void *packet_ctx, const void *data, size_t *size)
And verify a datagram packet.
Definition bio.c:70
fr_bio_verify_action_t fr_radius_bio_verify(UNUSED fr_bio_t *bio, void *verify_ctx, UNUSED void *packet_ctx, const void *data, size_t *size)
Callback for RADIUS packet verification.
Definition bio.c:32
uint32_t max_attributes
Definition bio.h:37
bool require_message_authenticator
Definition bio.h:42
bool allowed[FR_RADIUS_CODE_MAX]
allowed outgoing packet types
Definition bio.h:40
uint32_t max_packet_size
Definition bio.h:38
fr_radius_decode_fail_t
Failure reasons.
Definition radius.h:162
@ DECODE_FAIL_UNKNOWN_PACKET_CODE
Definition radius.h:169
static fr_slen_t data
Definition value.h:1265