#include <ctype.h>
#include <stdlib.h>
#include <time.h>
+#include <fnmatch.h>
#include <libubox/uloop.h>
{
struct qosify_map_entry *e;
char *pattern;
+ char *c;
if (data->id < CL_MAP_DNS) {
e = calloc(1, sizeof(*e));
e = calloc_a(sizeof(*e), &pattern, strlen(data->addr.dns.pattern) + 1);
strcpy(pattern, data->addr.dns.pattern);
e->data.addr.dns.pattern = pattern;
- if (regcomp(&e->data.addr.dns.regex, pattern,
- REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
+
+ for (c = pattern; *c; c++)
+ *c = tolower(*c);
+
+ if (pattern[0] == '/' &&
+ regcomp(&e->data.addr.dns.regex, pattern + 1,
+ REG_EXTENDED | REG_NOSUB)) {
free(e);
return NULL;
}
}
-int qosify_map_add_dns_host(const char *host, const char *addr, const char *type, int ttl)
+int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl)
{
struct qosify_map_data data = {
.id = CL_MAP_DNS,
};
struct qosify_map_entry *e;
int prev_timeout = qosify_map_timeout;
+ char *c;
e = avl_find_ge_element(&map_data, &data, e, avl);
if (!e)
if (qosify_map_fill_ip(&data, addr))
return -1;
+ for (c = host; *c; c++)
+ *c = tolower(*c);
+
avl_for_element_to_last(&map_data, e, e, avl) {
regex_t *regex = &e->data.addr.dns.regex;
if (e->data.id != CL_MAP_DNS)
return 0;
- if (regexec(regex, host, 0, NULL, 0) != 0)
- continue;
+ if (e->data.addr.dns.pattern[0] == '/') {
+ if (regexec(regex, host, 0, NULL, 0) != 0)
+ continue;
+ } else {
+ if (fnmatch(e->data.addr.dns.pattern, host, 0))
+ continue;
+ }
if (ttl)
qosify_map_timeout = ttl;
void qosify_map_set_dscp_default(enum qosify_map_id id, uint8_t val);
void qosify_map_reset_config(void);
void qosify_map_update_config(void);
-int qosify_map_add_dns_host(const char *host, const char *addr, const char *type, int ttl);
+int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl);
int qosify_iface_init(void);
void qosify_iface_config_update(struct blob_attr *ifaces, struct blob_attr *devs);