# define INADDR_BROADCAST INADDR_NONE
#endif
+fr_dict_attr_t const *dhcp_option_82;
+
/* @todo: this is a hack */
# define DEBUG if (fr_debug_lvl && fr_log_fp) fr_printf_log
{
VALUE_PAIR const *my_a = a;
VALUE_PAIR const *my_b = b;
+ fr_dict_attr_t const *a_82, *b_82;
VERIFY_VP(my_a);
VERIFY_VP(my_b);
((my_b->da->parent->type != PW_TYPE_TLV) && (my_b->da->attr == PW_DHCP_MESSAGE_TYPE))) return +1;
/*
- * Relay-Agent is last
+ * Relay-Agent is last.
+ *
+ * Check if either of the options are descended from option 82.
*/
- if ((my_a->da->parent->attr == PW_DHCP_OPTION_82) &&
- (my_b->da->parent->attr != PW_DHCP_OPTION_82)) return +1;
- if ((my_a->da->parent->attr != PW_DHCP_OPTION_82) &&
- (my_b->da->parent->attr == PW_DHCP_OPTION_82)) return -1;
+ a_82 = fr_dict_parent_common(dhcp_option_82, my_a->da, true);
+ b_82 = fr_dict_parent_common(dhcp_option_82, my_b->da, true);
+ if (a_82 && !b_82) return +1;
+ if (!a_82 && !b_82) return -1;
return fr_pair_cmp_by_parent_num_tag(my_a, my_b);
}
return packet;
}
#endif
+
+/** Resolve/cache attributes in the DHCP dictionary
+ *
+ * @return
+ * - 0 on success.
+ * - -1 on failure.
+ */
+int dhcp_init(void)
+{
+ dhcp_option_82 = fr_dict_attr_by_num(NULL, DHCP_MAGIC_VENDOR, PW_DHCP_OPTION_82);
+ if (!dhcp_option_82) {
+ fr_strerror_printf("Missing dictionary attribute for DHCP-Option-82");
+ return -1;
+ }
+
+ return 0;
+}
static int dhcp_load(void)
{
- return fr_dict_read(main_config.dict, main_config.dictionary_dir, "dictionary.dhcp");
+ int ret;
+
+ ret = fr_dict_read(main_config.dict, main_config.dictionary_dir, "dictionary.dhcp");
+ if (dhcp_init() < 0) {
+ ERROR("%s", fr_strerror());
+ return -1;
+ }
+
+ return ret;
}
return 0;
}
+static int dhcp_load(void)
+{
+ int ret;
+
+ ret = fr_dict_read(main_config.dict, main_config.dictionary_dir, "dictionary.dhcp");
+ if (dhcp_init() < 0) {
+ ERROR("%s", fr_strerror());
+ return -1;
+ }
+
+ return ret;
+}
/*
* The module name should be the only globally exported symbol.
.magic = RLM_MODULE_INIT,
.name = "dhcp",
.inst_size = sizeof(rlm_dhcp_t),
+
+ .load = dhcp_load,
.bootstrap = mod_bootstrap,
};