The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
client_tcp.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: 207f686d8c1519f292f0af0ac43f5d0479699d35 $
19  *
20  * @file protocols/radius/client_tcp.c
21  * @brief Functions to support RADIUS bio handlers for client tcp sockets
22  *
23  * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
24  */
25 RCSID("$Id: 207f686d8c1519f292f0af0ac43f5d0479699d35 $")
26 
27 #include <freeradius-devel/bio/packet.h>
28 #include <freeradius-devel/radius/client_tcp.h>
29 #include <freeradius-devel/radius/client_priv.h>
30 
31 /** Allocate an ID, and write one packet.
32  *
33  */
35 {
36  fr_radius_client_fd_bio_t *my = talloc_get_type_abort(bio, fr_radius_client_fd_bio_t);
37 
38  /*
39  * We never retransmit TCP packets.
40  */
41  fr_assert(!packet->data);
42 
43  return fr_radius_client_fd_bio_write(my, request_ctx, packet, list);
44 }
45 
46 /** Allocate a RADIUS bio for writing client packets
47  *
48  * It also verifies that the packets we receive are valid for RADIUS.
49  */
51 {
53 
54  my = fr_radius_client_fd_bio_alloc(ctx, 2 * 4096, cfg, fd_cfg);
55  if (!my) return NULL;
56 
57  if (fr_bio_mem_set_verify(my->mem, fr_radius_bio_verify, true) < 0) {
58  talloc_free(my);
59  return NULL;
60  }
61 
64 
65  return (fr_bio_packet_t *) my;
66 }
fr_bio_packet_write_t write
write to the underlying bio
Definition: packet.h:73
fr_bio_packet_read_t read
read from the underlying bio
Definition: packet.h:72
#define RCSID(id)
Definition: build.h:444
fr_bio_packet_t common
Definition: client_priv.h:35
static int fr_radius_client_tcp_bio_write(fr_bio_packet_t *bio, void *request_ctx, fr_packet_t *packet, fr_pair_list_t *list)
Allocate an ID, and write one packet.
Definition: client_tcp.c:34
fr_bio_packet_t * fr_radius_client_tcp_bio_alloc(TALLOC_CTX *ctx, fr_radius_client_config_t *cfg, fr_bio_fd_config_t const *fd_cfg)
Allocate a RADIUS bio for writing client packets.
Definition: client_tcp.c:50
Configuration for sockets.
Definition: fd.h:76
int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram)
Set the verification function for memory bios.
Definition: mem.c:799
talloc_free(reap)
fr_bio_verify_action_t fr_radius_bio_verify(fr_bio_t *bio, UNUSED void *packet_ctx, const void *data, size_t *size)
Callback for RADIUS packet verification.
Definition: bio.c:32
static fr_bio_t * bio
Definition: radclient-ng.c:86
#define request_ctx
Talloc ctx for allocating request pairs under.
Definition: request.h:94
fr_radius_client_fd_bio_t * fr_radius_client_fd_bio_alloc(TALLOC_CTX *ctx, size_t read_size, fr_radius_client_config_t *cfg, fr_bio_fd_config_t const *fd_cfg)
Definition: client.c:61
int fr_radius_client_fd_bio_read(fr_bio_packet_t *bio, void **request_ctx_p, fr_packet_t **packet_p, UNUSED TALLOC_CTX *out_ctx, fr_pair_list_t *out)
Definition: client.c:329
int fr_radius_client_fd_bio_write(fr_radius_client_fd_bio_t *my, void *request_ctx, fr_packet_t *packet, fr_pair_list_t *list)
Definition: client.c:119
fr_assert(0)
uint8_t * data
Packet data (body).
Definition: packet.h:63