The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
protocol.c
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: 3fd4b0bb6f2073207110cdfaa30615258ca50443 $
20  *
21  * @file lib/server/protocol.c
22  * @brief Protocol module API.
23  *
24  * @copyright 2013 Alan DeKok
25  */
26 RCSIDH(protocol_h, "$Id: 3fd4b0bb6f2073207110cdfaa30615258ca50443 $")
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <freeradius-devel/io/base.h>
33 
34 #include <freeradius-devel/server/dl_module.h>
35 #include <freeradius-devel/server/listen.h>
36 
37 /*
38  * Debug the packet if requested.
39  */
40 void common_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *pairs, bool received)
41 {
42 #ifdef WITH_IFINDEX_NAME_RESOLUTION
43  char if_name[IFNAMSIZ];
44 #endif
45 
46  if (!packet) return;
47  if (!RDEBUG_ENABLED) return;
48 
49 
50  log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s code %u Id %i from %s%pV%s:%i to %s%pV%s:%i "
51 #ifdef WITH_IFINDEX_NAME_RESOLUTION
52  "%s%s%s"
53 #endif
54  "length %zu",
55  received ? "Received" : "Sent",
56  packet->code,
57  packet->id,
58  packet->src_ipaddr.af == AF_INET6 ? "[" : "",
59  fr_box_ipaddr(packet->src_ipaddr),
60  packet->src_ipaddr.af == AF_INET6 ? "]" : "",
61  packet->src_port,
62  packet->dst_ipaddr.af == AF_INET6 ? "[" : "",
63  fr_box_ipaddr(packet->dst_ipaddr),
64  packet->dst_ipaddr.af == AF_INET6 ? "]" : "",
65  packet->dst_port,
66 #ifdef WITH_IFINDEX_NAME_RESOLUTION
67  packet->ifindex ? "via " : "",
68  packet->ifindex ? fr_ifname_from_ifindex(if_name, packet->ifindex) : "",
69  packet->ifindex ? " " : "",
70 #endif
71  packet->data_len);
72 
73  if (received || request->parent) {
74  log_request_pair_list(L_DBG_LVL_1, request, NULL, pairs, NULL);
75  } else {
76  log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, pairs, NULL);
77  }
78 }
#define RCSIDH(h, id)
Definition: build.h:482
void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a list of protocol fr_pair_ts.
Definition: log.c:854
void log_request(fr_log_type_t type, fr_log_lvl_t lvl, request_t *request, char const *file, int line, char const *fmt,...)
Marshal variadic log arguments into a va_list and pass to normal logging functions.
Definition: log.c:612
void log_request_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a fr_pair_list_t.
Definition: log.c:830
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition: log.h:70
@ L_DBG
Only displayed when debugging is enabled.
Definition: log.h:59
void common_packet_debug(request_t *request, fr_packet_t *packet, fr_pair_list_t *pairs, bool received)
Definition: protocol.c:40
#define RDEBUG_ENABLED()
Definition: radclient.h:49
unsigned int code
Packet code (type).
Definition: packet.h:61
int id
Packet ID (used to link requests/responses).
Definition: packet.h:60
size_t data_len
Length of packet data.
Definition: packet.h:64
#define fr_box_ipaddr(_val)
Definition: value.h:294