add a iface pointer to services and records
authorJohn Crispin <blogic@openwrt.org>
Thu, 4 Sep 2014 20:35:48 +0000 (22:35 +0200)
committerJohn Crispin <blogic@openwrt.org>
Thu, 4 Sep 2014 20:35:48 +0000 (22:35 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
cache.c
cache.h
main.c

diff --git a/cache.c b/cache.c
index 190290a9afa3ab7a9343355051d82dea82866646..e4479226609b0b2ac69b92ec0f3755af03270ef1 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -100,16 +100,18 @@ cache_init(void)
        return 0;
 }
 
-void cache_cleanup(void)
+void cache_cleanup(struct interface *iface)
 {
        struct cache_record *r, *p;
        struct cache_service *s, *t;
 
-       avl_for_each_element_safe(&records, r, avl, p)
-               cache_record_free(r);
-
        avl_for_each_element_safe(&services, s, avl, t)
-               cache_service_free(s);
+               if (!iface || iface == s->iface)
+                       cache_service_free(s);
+
+       avl_for_each_element_safe(&records, r, avl, p)
+               if (!iface || iface == r->iface)
+                       cache_record_free(r);
 }
 
 void
@@ -142,6 +144,7 @@ cache_service(struct interface *iface, char *entry, int hlen, int ttl)
        s->avl.key = s->entry = strcpy(entry_buf, entry);
        s->time = time(NULL);
        s->ttl = ttl;
+       s->iface = iface;
 
        if (hlen)
                s->host = strncpy(host_buf, s->entry, hlen);
@@ -320,6 +323,7 @@ cache_answer(struct interface *iface, uint8_t *base, int blen, char *name, struc
        r->port = port;
        r->rdlength = dlen;
        r->time = time(NULL);
+       r->iface = iface;
 
        if (tlen)
                r->txt = memcpy(txt_ptr, rdata_buffer, tlen);
diff --git a/cache.h b/cache.h
index 72bd08c7a043fc9dc04a6e5284ddc46f41c94116..211f464b401dd6f7857a374e7efe175312515dcf 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -19,6 +19,7 @@
 #include <libubox/blob.h>
 
 #include "dns.h"
+#include "interface.h"
 
 struct cache_service {
        struct avl_node avl;
@@ -27,6 +28,7 @@ struct cache_service {
        const char *host;
        uint32_t ttl;
        time_t time;
+       struct interface *iface;
 };
 
 struct cache_record {
@@ -40,13 +42,14 @@ struct cache_record {
        const uint8_t *rdata;
        uint16_t rdlength;
        time_t time;
+       struct interface *iface;
 };
 
 extern struct avl_tree services;
 
 int cache_init(void);
 void cache_scan(void);
-void cache_cleanup(void);
+void cache_cleanup(struct interface *iface);
 void cache_answer(struct interface *iface, uint8_t *base, int blen,
                  char *name, struct dns_answer *a, uint8_t *rdata, int flush);
 int cache_host_is_known(char *record);
diff --git a/main.c b/main.c
index 1806dfc589a195ccf20a4490a5e9a81f99ed4bc0..02d13f54ff3423e76d4ea02af077127bced3d194 100644 (file)
--- a/main.c
+++ b/main.c
@@ -98,7 +98,7 @@ main(int argc, char **argv)
        uloop_done();
 
        interface_shutdown();
-       cache_cleanup();
+       cache_cleanup(NULL);
        service_cleanup();
        vlist_flush(&interfaces);