The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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: 7aa0298846ee38b119276261f3afe49569a877c3 $
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: 7aa0298846ee38b119276261f3afe49569a877c3 $")
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 < 20) {
43 }
44 want = *size;
45
46 /*
47 * See if we need to discard the packet.
48 */
49 if (!fr_radius_ok(data, &want, uctx->max_attributes, uctx->require_message_authenticator, false, &failure)) {
50 if (want) {
51 *size = want;
52
53 if (uctx->max_packet_size && (want > uctx->max_packet_size)) {
55 }
56
59 }
60
62 }
63
65 }
66 *size = want;
67
68 if (!uctx->allowed[hdr[0]]) return FR_BIO_VERIFY_DISCARD;
69
70 /*
71 * The packet is too large, we can't process it. Close the socket.
72 */
73 if (uctx->max_packet_size && (want > uctx->max_packet_size)) {
75 }
76
77 /*
78 * On input, *size is how much data we have. On output, *size is how much data we want.
79 */
80 return (in_buffer >= *size) ? FR_BIO_VERIFY_OK : FR_BIO_VERIFY_WANT_MORE;
81}
82
83/** And verify a datagram packet.
84 *
85 */
86fr_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)
87{
89 size_t in_buffer = *size;
90 fr_radius_bio_verify_t *uctx = verify_ctx;
91 uint8_t const *hdr = data;
92 size_t want;
93
94 if (in_buffer < RADIUS_HEADER_LENGTH) return FR_BIO_VERIFY_DISCARD;
95
96 want = fr_nbo_to_uint16(hdr + 2);
97 if (uctx->max_packet_size && (want > uctx->max_packet_size)) {
99 }
100
101 /*
102 * See if we need to discard the packet.
103 *
104 * @todo - move the "allowed" list to this function
105 */
106 if (!fr_radius_ok(data, size, uctx->max_attributes, uctx->require_message_authenticator, false, &failure)) {
108 }
109
110 if (!uctx->allowed[hdr[0]]) return FR_BIO_VERIFY_DISCARD;
111
112 /*
113 * On input, *size is how much data we have. On output, *size is how much data we want.
114 */
115 return (in_buffer >= *size) ? FR_BIO_VERIFY_OK : FR_BIO_VERIFY_DISCARD;
116}
static int packet_ctx
the tests pass only the address of packet_ctx
#define RCSID(id)
Definition build.h:609
#define UNUSED
Definition build.h:415
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
unsigned char uint8_t
bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p, uint32_t max_attributes, bool require_message_authenticator, bool radius_1_1, decode_fail_t *reason)
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:86
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:89
@ FR_RADIUS_FAIL_MIN_LENGTH_MISMATCH
Definition radius.h:94
static fr_slen_t data
Definition value.h:1366