From: Alan T. DeKok Date: Wed, 27 Jan 2021 19:42:58 +0000 (-0500) Subject: unify checks for buffer_len==1 and do_not_respond X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5839a07c9feb9102f362c2e09e5579f7e0ec6b61;p=thirdparty%2Ffreeradius-server.git unify checks for buffer_len==1 and do_not_respond --- diff --git a/src/modules/proto_arp/proto_arp.c b/src/modules/proto_arp/proto_arp.c index 3bbbfa03a3..cdf70a341c 100644 --- a/src/modules/proto_arp/proto_arp.c +++ b/src/modules/proto_arp/proto_arp.c @@ -110,17 +110,9 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf fr_arp_packet_t *arp; /* - * The packet timed out. Tell the network side that the packet is dead. + * Process layer NAK, never respond, or "Do not respond". */ - if (buffer_len == 1) { - *buffer = true; - return 1; - } - - /* - * "Do not respond" - */ - if (!inst->active || + if ((buffer_len == 1) || !inst->active || (request->reply->code == FR_ARP_CODE_DO_NOT_RESPOND) || (request->reply->code == 0) || (request->reply->code >= FR_ARP_MAX_PACKET_CODE)) { *buffer = false; diff --git a/src/modules/proto_dhcpv4/proto_dhcpv4.c b/src/modules/proto_dhcpv4/proto_dhcpv4.c index cedec26d25..b86f37b9b3 100644 --- a/src/modules/proto_dhcpv4/proto_dhcpv4.c +++ b/src/modules/proto_dhcpv4/proto_dhcpv4.c @@ -252,21 +252,14 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf RADCLIENT const *client; /* - * The packet timed out. Tell the network side that the packet is dead. + * process layer NAK, or "Do not respond". We also never + * send replies to a release. */ - if (buffer_len == 1) { - *buffer = true; - return 1; - } - - /* - * "Do not respond". We also never send replies to a release. - */ - if ((request->reply->code == FR_MESSAGE_TYPE_VALUE_DO_NOT_RESPOND) || + if ((buffer_len == 1) || + (request->reply->code == FR_MESSAGE_TYPE_VALUE_DO_NOT_RESPOND) || (request->reply->code == 0) || (request->reply->code >= FR_DHCP_MAX) || (request->packet->code == FR_DHCP_RELEASE)) { track->do_not_respond = true; - *buffer = false; return 1; } diff --git a/src/modules/proto_dhcpv6/proto_dhcpv6.c b/src/modules/proto_dhcpv6/proto_dhcpv6.c index 802d6a41cc..864d4efb92 100644 --- a/src/modules/proto_dhcpv6/proto_dhcpv6.c +++ b/src/modules/proto_dhcpv6/proto_dhcpv6.c @@ -251,20 +251,12 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf RADCLIENT const *client; /* - * The packet timed out. Tell the network side that the packet is dead. + * Process layer NAK, never respond, or "Do not respond". */ - if (buffer_len == 1) { - *buffer = true; - return 1; - } - - /* - * "Do not respond". We also never send replies to a release. - */ - if ((request->reply->code == FR_DHCPV6_DO_NOT_RESPOND) || + if ((buffer_len == 1) || + (request->reply->code == FR_DHCPV6_DO_NOT_RESPOND) || (request->reply->code == 0) || (request->reply->code >= FR_DHCPV6_MAX_CODE)) { track->do_not_respond = true; - *buffer = false; return 1; } diff --git a/src/modules/proto_radius/proto_radius.c b/src/modules/proto_radius/proto_radius.c index 1d3d2e69a3..781800684f 100644 --- a/src/modules/proto_radius/proto_radius.c +++ b/src/modules/proto_radius/proto_radius.c @@ -309,20 +309,12 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf RADCLIENT const *client; /* - * The packet timed out. Tell the network side that the packet is dead. + * Process layer NAK, or "Do not respond". */ - if (buffer_len == 1) { - *buffer = true; - return 1; - } - - /* - * "Do not respond" - */ - if ((request->reply->code == FR_CODE_DO_NOT_RESPOND) || + if ((buffer_len == 1) || + (request->reply->code == FR_CODE_DO_NOT_RESPOND) || (request->reply->code == 0) || (request->reply->code >= FR_RADIUS_MAX_PACKET_CODE)) { track->do_not_respond = true; - *buffer = false; return 1; } diff --git a/src/modules/proto_tacacs/proto_tacacs.c b/src/modules/proto_tacacs/proto_tacacs.c index 549d712a0c..8218261911 100644 --- a/src/modules/proto_tacacs/proto_tacacs.c +++ b/src/modules/proto_tacacs/proto_tacacs.c @@ -324,23 +324,15 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf RADCLIENT const *client; /* - * The packet timed out. Tell the network side that the packet is dead. + * Process layer NAK, or "Do not respond". */ - if (buffer_len == 1) { - *buffer = true; + if ((buffer_len == 1) || + (request->reply->code == FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND) || + (request->reply->code == 0) || (request->reply->code >= FR_PACKET_TYPE_MAX)) { + track->do_not_respond = true; return 1; } - /* - * "Do not respond" - */ - if (request->reply->code == FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND) { - *buffer = false; - return 1; - } - fr_assert(request->reply->code != 0); - fr_assert(request->reply->code < FR_PACKET_TYPE_MAX); - client = address->radclient; fr_assert(client); diff --git a/src/modules/proto_vmps/proto_vmps.c b/src/modules/proto_vmps/proto_vmps.c index fc7b280828..e1497af49c 100644 --- a/src/modules/proto_vmps/proto_vmps.c +++ b/src/modules/proto_vmps/proto_vmps.c @@ -236,20 +236,12 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf fr_dcursor_t cursor; /* - * The packet timed out. Tell the network side that the packet is dead. + * Process layer NAK, never respond, or "Do not respond". */ - if (buffer_len == 1) { - *buffer = true; - return 1; - } - - /* - * "Do not respond" - */ - if ((request->reply->code == FR_CODE_DO_NOT_RESPOND) || + if ((buffer_len == 1) || + (request->reply->code == FR_CODE_DO_NOT_RESPOND) || (request->reply->code >= FR_VQP_MAX_CODE)) { track->do_not_respond = true; - *buffer = false; return 1; }