The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
app_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: c8fd04bb5e374d231bcdcfa4d6e8069225f6f952 $
19  * @file io/app_io.c
20  * @brief APP IO utility functions
21  *
22  * @copyright 2018 Alan DeKok (aland@freeradius.org)
23  */
24 #include <freeradius-devel/io/base.h>
25 #include <freeradius-devel/io/application.h>
26 #include <freeradius-devel/util/syserror.h>
27 #include <freeradius-devel/util/debug.h>
28 
29 /*
30  * @todo - include the name of the virtual server, too.
31  */
32 char const *fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io,
33  fr_ipaddr_t const *src_ipaddr, int src_port,
34  fr_ipaddr_t const *dst_ipaddr, int dst_port,
35  char const *interface)
36 {
37  char dst_buf[128], src_buf[128];
38 
39  /*
40  * Get our name.
41  */
42  if (fr_ipaddr_is_inaddr_any(dst_ipaddr)) {
43  if (dst_ipaddr->af == AF_INET) {
44  strlcpy(dst_buf, "*", sizeof(dst_buf));
45  } else {
46  fr_assert(dst_ipaddr->af == AF_INET6);
47  strlcpy(dst_buf, "::", sizeof(dst_buf));
48  }
49  } else {
50  fr_value_box_print(&FR_SBUFF_OUT(dst_buf, sizeof(dst_buf)), fr_box_ipaddr(*dst_ipaddr), NULL);
51  }
52 
53  if (src_ipaddr) fr_value_box_print(&FR_SBUFF_OUT(src_buf, sizeof(src_buf)), fr_box_ipaddr(*src_ipaddr), NULL);
54 
55  if (!interface) {
56  if (!src_ipaddr) {
57  return talloc_typed_asprintf(ctx, "%s server %s port %u",
58  app_io->common.name, dst_buf, dst_port);
59  }
60 
61 
62  return talloc_typed_asprintf(ctx, "%s from client %s port %u to server %s port %u",
63  app_io->common.name, src_buf, src_port, dst_buf, dst_port);
64  }
65 
66  if (!src_ipaddr) {
67  return talloc_typed_asprintf(ctx, "%s server %s port %u on interface %s",
68  app_io->common.name, dst_buf, dst_port, interface);
69  }
70 
71 
72  return talloc_typed_asprintf(ctx, "%s from client %s port %u to server %s port %u on interface %s",
73  app_io->common.name, src_buf, src_port, dst_buf, dst_port, interface);
74 }
char const * fr_app_io_socket_name(TALLOC_CTX *ctx, fr_app_io_t const *app_io, fr_ipaddr_t const *src_ipaddr, int src_port, fr_ipaddr_t const *dst_ipaddr, int dst_port, char const *interface)
Definition: app_io.c:32
module_t common
Common fields to all loadable modules.
Definition: app_io.h:34
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
int fr_ipaddr_is_inaddr_any(fr_ipaddr_t const *ipaddr)
Determine if an address is the INADDR_ANY address for its address family.
Definition: inet.c:62
int af
Address family.
Definition: inet.h:64
IPv4/6 prefix.
Definition: merged_model.c:272
static fr_app_io_t app_io
Definition: radius1_test.c:146
#define FR_SBUFF_OUT(_start, _len_or_end)
fr_assert(0)
size_t strlcpy(char *dst, char const *src, size_t siz)
Definition: strlcpy.c:34
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition: talloc.c:492
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules)
Print one boxed value to a string.
Definition: value.c:5352
#define fr_box_ipaddr(_val)
Definition: value.h:294