]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
hoist common code to worker
authorAlan T. DeKok <aland@freeradius.org>
Sun, 12 Mar 2023 01:43:04 +0000 (20:43 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 14 Mar 2023 21:10:38 +0000 (17:10 -0400)
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

src/lib/io/worker.c
src/listen/dhcpv4/proto_dhcpv4.c
src/listen/dhcpv6/proto_dhcpv6.c
src/listen/dns/proto_dns.c
src/listen/radius/proto_radius.c
src/listen/tacacs/proto_tacacs.c
src/listen/vmps/proto_vmps.c

index 4cc547544746d0cc1259a3c8c584cefe77b62361..da168a39eb28fd6bec56f833f4767af3fe2194f5 100644 (file)
@@ -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");
index c76f75a2229aa1a4455a45cd41ea7a7da3400a2c..f112bcae0710535458fa551217bcaa5a8d2b78a6 100644 (file)
@@ -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) {
index 0f56ea8b0cd9f90e811a4a037fe167f9d954a837..21117a6262d300fd7a3b9522f854039a9122d3f8 100644 (file)
@@ -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);
index 8ea07c08273397160e65ab36852111eb84f400f4..2763c18edd041897006ca28ffb16227756e71157 100644 (file)
@@ -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;
index 5c46979fc69ecc55967d471036524b9b012644a3..e12283ece78c2d2d15aa14572c77ca41a283caf5 100644 (file)
@@ -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
index 5cb73aaea8534022d9f36c26c9b9f5f6eba5f94a..be02c105e1aa9fcb3720de991ca4acce8452dd34 100644 (file)
@@ -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;
 
index 208a9ee21b20bb9a3932ecf96c30da402b245f8f..7a931b0a50b3ca3099d100d01854036b3d50f07f 100644 (file)
@@ -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