uloop_timeout_set(&qosify_map_timer, timeout * 1000);
}
-
-int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl)
+int qosify_map_lookup_dns_entry(char *host, uint8_t *dscp)
{
struct qosify_map_data data = {
.id = CL_MAP_DNS,
.addr.dns.pattern = "",
};
struct qosify_map_entry *e;
- int prev_timeout = qosify_map_timeout;
+ bool ret = -1;
char *c;
e = avl_find_ge_element(&map_data, &data, e, avl);
if (!e)
- return 0;
-
- memset(&data, 0, sizeof(data));
- data.user = true;
- if (!strcmp(type, "A"))
- data.id = CL_MAP_IPV4_ADDR;
- else if (!strcmp(type, "AAAA"))
- data.id = CL_MAP_IPV6_ADDR;
- else
- return 0;
-
- if (qosify_map_fill_ip(&data, addr))
return -1;
for (c = host; *c; c++)
regex_t *regex = &e->data.addr.dns.regex;
if (e->data.id != CL_MAP_DNS)
- return 0;
+ break;
if (e->data.addr.dns.pattern[0] == '/') {
if (regexec(regex, host, 0, NULL, 0) != 0)
continue;
}
- if (ttl)
- qosify_map_timeout = ttl;
- data.dscp = e->data.dscp;
- __qosify_map_set_entry(&data);
- qosify_map_timeout = prev_timeout;
+ *dscp = e->data.dscp;
+ ret = 0;
}
+ return ret;
+}
+
+
+int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl)
+{
+ struct qosify_map_data data = {};
+ int prev_timeout = qosify_map_timeout;
+
+ if (qosify_map_lookup_dns_entry(host, &data.dscp))
+ return 0;
+
+ data.user = true;
+ if (!strcmp(type, "A"))
+ data.id = CL_MAP_IPV4_ADDR;
+ else if (!strcmp(type, "AAAA"))
+ data.id = CL_MAP_IPV6_ADDR;
+ else
+ return 0;
+
+ if (qosify_map_fill_ip(&data, addr))
+ return -1;
+
+ if (ttl)
+ qosify_map_timeout = ttl;
+ __qosify_map_set_entry(&data);
+ qosify_map_timeout = prev_timeout;
+
return 0;
}
void qosify_map_reset_config(void);
void qosify_map_update_config(void);
void qosify_map_set_classes(struct blob_attr *val);
+int qosify_map_lookup_dns_entry(char *host, uint8_t *dscp);
int qosify_map_add_dns_host(char *host, const char *addr, const char *type, int ttl);
int map_parse_flow_config(struct qosify_flow_config *cfg, struct blob_attr *attr,
bool reset);