]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move debug printing for "receive" to process function
authorAlan T. DeKok <aland@freeradius.org>
Fri, 9 Apr 2021 11:34:40 +0000 (07:34 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 9 Apr 2021 11:34:40 +0000 (07:34 -0400)
src/listen/radius/proto_radius.c
src/process/radius/base.c

index 37405d55f88e7c96d25e1de95f510d86a4b6ff9b..9249ce023a15bb7da4ab1ecf834a435ecdaa8c91 100644 (file)
@@ -281,20 +281,6 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d
                }
        }
 
-       if (RDEBUG_ENABLED) {
-               RDEBUG("Received %s ID %i from %pV:%i to %pV:%i length %zu via socket %s",
-                      fr_packet_codes[request->packet->code],
-                      request->packet->id,
-                      fr_box_ipaddr(request->packet->socket.inet.src_ipaddr),
-                      request->packet->socket.inet.src_port,
-                      fr_box_ipaddr(request->packet->socket.inet.dst_ipaddr),
-                      request->packet->socket.inet.dst_port,
-                      request->packet->data_len,
-                      request->async->listen->name);
-
-               log_request_pair_list(L_DBG_LVL_1, request, NULL, &request->request_pairs, NULL);
-       }
-
        if (!inst->io.app_io->decode) return 0;
 
        /*
index 523f2c7a1c18de1aae1f0a2f2e3594c0648820af..00f9a7fbb6dec6069a12ada84e30a57db21e3afe 100644 (file)
@@ -191,6 +191,48 @@ static const CONF_PARSER config[] = {
        CONF_PARSER_TERMINATOR
 };
 
+/*
+ *     Debug the packet if requested.
+ */
+static void radius_packet_debug(request_t *request, fr_radius_packet_t *packet, fr_pair_list_t *list, bool received)
+{
+#ifdef WITH_IFINDEX_NAME_RESOLUTION
+       char if_name[IFNAMSIZ];
+#endif
+
+       if (!packet) return;
+       if (!RDEBUG_ENABLED) return;
+
+       log_request(L_DBG, L_DBG_LVL_1, request, __FILE__, __LINE__, "%s %s ID %d from %s%pV%s:%i to %s%pV%s:%i "
+#ifdef WITH_IFINDEX_NAME_RESOLUTION
+                      "%s%s%s"
+#endif
+                      "",
+                      received ? "Received" : "Sending",
+                      fr_packet_codes[packet->code],
+                      packet->id,
+                      packet->socket.inet.src_ipaddr.af == AF_INET6 ? "[" : "",
+                      fr_box_ipaddr(packet->socket.inet.src_ipaddr),
+                      packet->socket.inet.src_ipaddr.af == AF_INET6 ? "]" : "",
+                      packet->socket.inet.src_port,
+                      packet->socket.inet.dst_ipaddr.af == AF_INET6 ? "[" : "",
+                      fr_box_ipaddr(packet->socket.inet.dst_ipaddr),
+                      packet->socket.inet.dst_ipaddr.af == AF_INET6 ? "]" : "",
+                      packet->socket.inet.dst_port
+#ifdef WITH_IFINDEX_NAME_RESOLUTION
+                      , packet->socket.inet.ifindex ? "via " : "",
+                      packet->socket.inet.ifindex ? fr_ifname_from_ifindex(if_name, packet->socket.inet.ifindex) : "",
+                      packet->socket.inet.ifindex ? " " : ""
+#endif
+                      );
+
+       if (received || request->parent) {
+               log_request_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
+       } else {
+               log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, list, NULL);
+       }
+}
+
 #define RAUTH(fmt, ...)                log_request(L_AUTH, L_DBG_LVL_OFF, request, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
 
 /*
@@ -745,10 +787,7 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mc
 
        UPDATE_STATE(packet);
 
-       if (request->parent && RDEBUG_ENABLED) {
-               RDEBUG("Received %s ID %i", fr_packet_codes[request->packet->code], request->packet->id);
-               log_request_pair_list(L_DBG_LVL_1, request, NULL, &request->request_pairs, NULL);
-       }
+       radius_packet_debug(request, request->packet, &request->request_pairs, true);
 
        return state->recv(p_result, mctx, request);
 }