From: Alan T. DeKok Date: Sun, 12 Mar 2023 01:43:04 +0000 (-0500) Subject: hoist common code to worker X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1218d02a974d427972ea0aae0f4bd56be86d9f98;p=thirdparty%2Ffreeradius-server.git hoist common code to worker none of the app_io libraries currently have their own encode functions. So remove the duplicate code in each proto_foo which checks for that. Instead, hoist it to the worker, which prioritizes the app_io over the app encode routine --- diff --git a/src/lib/io/worker.c b/src/lib/io/worker.c index 4cc54754474..da168a39eb2 100644 --- a/src/lib/io/worker.c +++ b/src/lib/io/worker.c @@ -648,12 +648,12 @@ static void worker_send_reply(fr_worker_t *worker, request_t *request, bool send fr_pair_unflatten(request->pair_list.reply); } /* else noop */ - if (listen->app->encode) { - slen = listen->app->encode(listen->app_instance, request, - reply->m.data, reply->m.rb_size); - } else if (listen->app_io->encode) { + if (listen->app_io->encode) { slen = listen->app_io->encode(listen->app_io_instance, request, reply->m.data, reply->m.rb_size); + } else if (listen->app->encode) { + slen = listen->app->encode(listen->app_instance, request, + reply->m.data, reply->m.rb_size); } if (slen < 0) { RPERROR("Failed encoding request"); diff --git a/src/listen/dhcpv4/proto_dhcpv4.c b/src/listen/dhcpv4/proto_dhcpv4.c index c76f75a2229..f112bcae071 100644 --- a/src/listen/dhcpv4/proto_dhcpv4.c +++ b/src/listen/dhcpv4/proto_dhcpv4.c @@ -248,9 +248,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_dhcpv4_t const *inst = talloc_get_type_abort_const(instance, proto_dhcpv4_t); fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; dhcp_packet_t *reply = (dhcp_packet_t *) buffer; @@ -320,15 +319,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf COPY(xid); MEMCPY(chaddr); - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - data_len = fr_dhcpv4_encode(buffer, buffer_len, original, request->reply->code, ntohl(original->xid), &request->reply_pairs); if (data_len < 0) { diff --git a/src/listen/dhcpv6/proto_dhcpv6.c b/src/listen/dhcpv6/proto_dhcpv6.c index 0f56ea8b0cd..21117a6262d 100644 --- a/src/listen/dhcpv6/proto_dhcpv6.c +++ b/src/listen/dhcpv6/proto_dhcpv6.c @@ -247,9 +247,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_dhcpv6_t const *inst = talloc_get_type_abort_const(instance, proto_dhcpv6_t); fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; fr_dhcpv6_packet_t *reply = (fr_dhcpv6_packet_t *) buffer; @@ -307,15 +306,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf memset(buffer, 0, buffer_len); memcpy(&reply->transaction_id, &original->transaction_id, sizeof(reply->transaction_id)); - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - data_len = fr_dhcpv6_encode(&FR_DBUFF_TMP(buffer, buffer_len), request->packet->data, request->packet->data_len, request->reply->code, &request->reply_pairs); diff --git a/src/listen/dns/proto_dns.c b/src/listen/dns/proto_dns.c index 8ea07c08273..2763c18edd0 100644 --- a/src/listen/dns/proto_dns.c +++ b/src/listen/dns/proto_dns.c @@ -238,9 +238,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_dns_t const *inst = talloc_get_type_abort_const(instance, proto_dns_t); // fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_dns_packet_t *reply = (fr_dns_packet_t *) buffer; fr_dns_packet_t *original = (fr_dns_packet_t *) request->packet->data; @@ -262,15 +261,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf return -1; } - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - packet_ctx.tmp_ctx = talloc(request, uint8_t); packet_ctx.packet = buffer; packet_ctx.packet_len = buffer_len; diff --git a/src/listen/radius/proto_radius.c b/src/listen/radius/proto_radius.c index 5c46979fc69..e12283ece78 100644 --- a/src/listen/radius/proto_radius.c +++ b/src/listen/radius/proto_radius.c @@ -314,9 +314,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_radius_t const *inst = talloc_get_type_abort_const(instance, proto_radius_t); fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; ssize_t data_len; @@ -373,15 +372,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf return sizeof(new_client); } - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - /* * Overwrite the src ip address on the outbound packet * with the one specified by the client. This is useful diff --git a/src/listen/tacacs/proto_tacacs.c b/src/listen/tacacs/proto_tacacs.c index 5cb73aaea85..be02c105e1a 100644 --- a/src/listen/tacacs/proto_tacacs.c +++ b/src/listen/tacacs/proto_tacacs.c @@ -351,9 +351,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_tacacs_t const *inst = talloc_get_type_abort_const(instance, proto_tacacs_t); fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; ssize_t data_len; @@ -421,15 +420,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf return sizeof(new_client); } - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - secret = client->secret; if (secret) secretlen = talloc_array_length(client->secret) - 1; diff --git a/src/listen/vmps/proto_vmps.c b/src/listen/vmps/proto_vmps.c index 208a9ee21b2..7a931b0a50b 100644 --- a/src/listen/vmps/proto_vmps.c +++ b/src/listen/vmps/proto_vmps.c @@ -239,9 +239,8 @@ static int mod_decode(void const *instance, request_t *request, uint8_t *const d return inst->io.app_io->decode(inst->io.app_io_instance, request, data, data_len); } -static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) +static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len) { - proto_vmps_t const *inst = talloc_get_type_abort_const(instance, proto_vmps_t); fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t); fr_io_address_t const *address = track->address; ssize_t data_len; @@ -290,15 +289,6 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf return sizeof(new_client); } - /* - * If the app_io encodes the packet, then we don't need - * to do that. - */ - if (inst->io.app_io->encode) { - data_len = inst->io.app_io->encode(inst->io.app_io_instance, request, buffer, buffer_len); - if (data_len > 0) return data_len; - } - /* * Overwrite the src ip address on the outbound packet * with the one specified by the client. This is useful