The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
io.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program 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
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; 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: 829350bbf33c9da5628de4ddff5890cb54cbefe5 $
19 *
20 * @file unlang/io.c
21 * @brief Shim I/O worker functions for running fake requests.
22 *
23 * @copyright 2006-2019 The FreeRADIUS server project
24 */
25RCSID("$Id: 829350bbf33c9da5628de4ddff5890cb54cbefe5 $")
26
27#include <freeradius-devel/io/listen.h>
28#include "unlang_priv.h"
29
30/** Allocate a child request based on the parent.
31 *
32 * @param[in] parent spawning the child request.
33 * @param[in] namespace the child request operates in. If NULL the parent's namespace is used.
34 * @param[in] detachable Allow/disallow the child to be detached.
35 * @return
36 * - The new child request.
37 * - NULL on error.
38 */
39request_t *unlang_io_subrequest_alloc(request_t *parent, fr_dict_t const *namespace, bool detachable)
40{
41 request_t *child;
42 char const *server;
43
44 if (!namespace) namespace = parent->proto_dict;
45
46 /*
47 * A child cannot refer to local variables in the parent context.
48 */
49 fr_assert(fr_dict_proto_dict(namespace) == namespace);
50
51 child = request_local_alloc_internal(detachable ? NULL : parent,
53 .parent = parent,
54 .namespace = namespace,
55 .detachable = detachable
56 }));
57 if (!child) return NULL;
58
59 /*
60 * Child gets its parent's interpreter
61 */
62 ((unlang_stack_t *)child->stack)->intp = ((unlang_stack_t *)parent->stack)->intp;
63
64 /*
65 * Push the child, and set its top frame to be true.
66 */
67 child->log.indent.unlang = parent->log.indent.unlang;
68
69 /*
70 * Initialize some basic information for the child.
71 */
72 child->number = parent->number;
73
74 /*
75 * Initialize all of the async fields.
76 */
77 child->async = talloc_zero(child, fr_async_t);
78 child->async->request = child;
79
80#define COPY_FIELD(_x) child->async->_x = parent->async->_x
81 COPY_FIELD(recv_time);
83
85 if (server) {
86 child->packet->socket = (fr_socket_t) {
88 .virtual.server = server,
89 };
90 child->reply->socket = child->packet->socket;
91 }
92
93 REQUEST_VERIFY(child);
94
95 return child;
96}
#define RCSID(id)
Definition build.h:560
fr_dict_t const * fr_dict_proto_dict(fr_dict_t const *dict)
Definition dict_util.c:5274
#define AF_FR_VIRTUAL_SERVER
Definition inet.h:110
char const * unlang_interpret_virtual_server(request_t *request)
Return the current virtual server for this request.
Definition interpret.c:2437
request_t * unlang_io_subrequest_alloc(request_t *parent, fr_dict_t const *namespace, bool detachable)
Allocate a child request based on the parent.
Definition io.c:39
#define COPY_FIELD(_x)
Minimal data structure to use the new code.
Definition listen.h:63
#define fr_assert(_expr)
Definition rad_assert.h:37
#define REQUEST_VERIFY(_x)
Definition request.h:310
#define request_is_internal(_x)
Definition request.h:186
#define request_local_alloc_internal(_ctx, _args)
Allocate a new internal request outside of the request pool.
Definition request.h:344
Optional arguments for initialising requests.
Definition request.h:288
Private interpreter structures and functions.
An unlang stack associated with a request.
static fr_slen_t parent
Definition pair.h:858
Holds information necessary for binding or connecting to a socket.
Definition socket.h:60