]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Autoload proto_dhcpv4_base attributes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 19 May 2018 14:48:18 +0000 (20:48 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 19 May 2018 14:48:18 +0000 (20:48 +0600)
src/modules/proto_dhcpv4/proto_dhcpv4_base.c

index 970674cbd0e64b2491c79ee9fb882d4793a3aef0..64d3b3d887b46b6659426830e0ffad50b6f226c1 100644 (file)
 #include <freeradius-devel/dhcpv4/dhcpv4.h>
 #include <freeradius-devel/dhcpv4.h>
 
+static fr_dict_t const *dict_dhcpv4;
+
+extern fr_dict_autoload_t proto_dhcpv4_dict[];
+fr_dict_autoload_t proto_dhcpv4_dict[] = {
+       { .out = &dict_dhcpv4, .proto = "dhcpv4" },
+       { NULL }
+};
+
+static fr_dict_attr_t const *attr_dhcpv4_message_type;
+
+extern fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[];
+fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[] = {
+       { .out = &attr_dhcpv4_message_type, .name = "DHCP-Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
+       { NULL }
+};
+
 static int reply_ok[FR_DHCP_INFORM + 1] = {
        [0]                     = FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND,
        [FR_DHCP_DISCOVER]      = FR_DHCP_OFFER,
@@ -69,15 +85,12 @@ static fr_io_final_t mod_process(REQUEST *request, UNUSED fr_io_action_t action)
 
        switch (request->request_state) {
        case REQUEST_INIT:
-               log_request(L_DBG, L_DBG_LVL_1, request, "Received %s ID %08x",
-                              dhcp_message_types[request->packet->code], request->packet->id);
+               RDEBUG("Received %s ID %08x", dhcp_message_types[request->packet->code], request->packet->id);
                log_request_proto_pair_list(L_DBG_LVL_1, request, request->packet->vps, "");
 
                request->component = "dhcpv4";
 
-               da = fr_dict_attr_by_num(NULL, DHCP_MAGIC_VENDOR, FR_DHCP_MESSAGE_TYPE);
-               rad_assert(da != NULL);
-               dv = fr_dict_enum_by_value(da, fr_box_uint32(request->packet->code));
+               dv = fr_dict_enum_by_value(attr_dhcpv4_message_type, fr_box_uint32(request->packet->code));
                if (!dv) {
                        REDEBUG("Failed to find value for &request:DHCP-Message-Type");
                        return FR_IO_FAIL;
@@ -105,19 +118,14 @@ static fr_io_final_t mod_process(REQUEST *request, UNUSED fr_io_action_t action)
 
                rad_assert(request->log.unlang_indent == 0);
 
-               if (!da) da = fr_dict_attr_by_num(NULL, DHCP_MAGIC_VENDOR, FR_DHCP_MESSAGE_TYPE);
-               rad_assert(da != NULL);
-
                /*
                 *      Allow the admin to explicitly set the reply
                 *      type.
                 */
-               vp = fr_pair_find_by_num(request->reply->vps, DHCP_MAGIC_VENDOR, FR_DHCP_MESSAGE_TYPE, TAG_ANY);
+               vp = fr_pair_find_by_da(request->reply->vps, attr_dhcpv4_message_type, TAG_ANY);
                if (vp) {
                        request->reply->code = vp->vp_uint8;
-               } else
-
-               switch (rcode) {
+               } else switch (rcode) {
                case RLM_MODULE_NOOP:
                case RLM_MODULE_OK:
                case RLM_MODULE_UPDATED:
@@ -171,11 +179,8 @@ static fr_io_final_t mod_process(REQUEST *request, UNUSED fr_io_action_t action)
                         *      the NAK section.
                         */
                        if (request->reply->code != FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND) {
-                               if (!da) da = fr_dict_attr_by_num(NULL, DHCP_MAGIC_VENDOR, FR_DHCP_MESSAGE_TYPE);
-                               rad_assert(da != NULL);
-
-                               dv = fr_dict_enum_by_value(da, fr_box_uint32(request->reply->code));
-                               RWDEBUG("Failed running 'send %s', trying 'send Do-Not-Respond'.", dv->alias);
+                               dv = fr_dict_enum_by_value(attr_dhcpv4_message_type, fr_box_uint32(request->reply->code));
+                               RWDEBUG("Failed running 'send %s', trying 'send Do-Not-Respond'", dv->alias);
 
                                request->reply->code = FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND;
 
@@ -196,7 +201,7 @@ static fr_io_final_t mod_process(REQUEST *request, UNUSED fr_io_action_t action)
                 *      Check for "do not respond".
                 */
                if (request->reply->code == FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND) {
-                       RDEBUG("Not sending reply to client.");
+                       RDEBUG("Not sending reply to client");
                        return FR_IO_DONE;
                }