From: Alan T. DeKok Date: Fri, 9 Apr 2021 11:34:40 +0000 (-0400) Subject: move debug printing for "receive" to process function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fc4589dee1c5137efe18e38257de26f8d8694fd;p=thirdparty%2Ffreeradius-server.git move debug printing for "receive" to process function --- diff --git a/src/listen/radius/proto_radius.c b/src/listen/radius/proto_radius.c index 37405d55f8..9249ce023a 100644 --- a/src/listen/radius/proto_radius.c +++ b/src/listen/radius/proto_radius.c @@ -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; /* diff --git a/src/process/radius/base.c b/src/process/radius/base.c index 523f2c7a1c..00f9a7fbb6 100644 --- a/src/process/radius/base.c +++ b/src/process/radius/base.c @@ -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); }