]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- ub_ctx_set_stub() function for libunbound to config stub zones.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 23 Feb 2016 10:43:10 +0000 (10:43 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 23 Feb 2016 10:43:10 +0000 (10:43 +0000)
git-svn-id: file:///svn/unbound/trunk@3632 be551aaa-1e26-0410-a405-d3ace91eadb9

configure
configure.ac
doc/Changelog
libunbound/libunbound.c
libunbound/unbound.h
util/config_file.c
util/config_file.h

index 6cab7e2ffb38c57d8ceb7a6fba71e6d12caefca6..6c6b9efeb1e31bbd95f5b94ac840a37d5749e6d8 100755 (executable)
--- a/configure
+++ b/configure
@@ -2711,9 +2711,9 @@ UNBOUND_VERSION_MINOR=5
 UNBOUND_VERSION_MICRO=8
 
 
-LIBUNBOUND_CURRENT=5
-LIBUNBOUND_REVISION=11
-LIBUNBOUND_AGE=3
+LIBUNBOUND_CURRENT=6
+LIBUNBOUND_REVISION=0
+LIBUNBOUND_AGE=4
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
 # 1.0.2 had 0:14:0
@@ -2759,7 +2759,7 @@ LIBUNBOUND_AGE=3
 # 1.5.5 had 5:8:3
 # 1.5.6 had 5:9:3
 # 1.5.7 had 5:10:3
-# 1.5.8 had 5:11:3
+# 1.5.8 had 6:0:4 # adds ub_ctx_set_stub
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
index 44d732e46b48714202a06080d9148ed4c7049066..0e53a5b7dd3ba85d70b9f49a75a69f6cd8e39c89 100644 (file)
@@ -16,9 +16,9 @@ AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
 
-LIBUNBOUND_CURRENT=5
-LIBUNBOUND_REVISION=11
-LIBUNBOUND_AGE=3
+LIBUNBOUND_CURRENT=6
+LIBUNBOUND_REVISION=0
+LIBUNBOUND_AGE=4
 # 1.0.0 had 0:12:0
 # 1.0.1 had 0:13:0
 # 1.0.2 had 0:14:0
@@ -64,7 +64,7 @@ LIBUNBOUND_AGE=3
 # 1.5.5 had 5:8:3
 # 1.5.6 had 5:9:3
 # 1.5.7 had 5:10:3
-# 1.5.8 had 5:11:3
+# 1.5.8 had 6:0:4 # adds ub_ctx_set_stub
 
 #   Current  -- the number of the binary API that we're implementing
 #   Revision -- which iteration of the implementation of the binary
index 29a214deccbdae5d8a9fbb2bf44c4984cf1faf1f..ac66444fe9b8836eaba3075c2ec3c84330a86937 100644 (file)
@@ -1,3 +1,6 @@
+23 February 2016: Wouter
+       - ub_ctx_set_stub() function for libunbound to config stub zones.
+
 19 February 2016: Wouter
        - Print understandable debug log when unusable DS record is seen.
        - load gost algorithm if digest is seen before key algorithm.
index 17f50e8e81db8abccf46873ffa7d97388787a678..d62e41ce66f792a8e0088784b0ab180d2e2b0a39 100644 (file)
@@ -924,6 +924,83 @@ ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr)
        return UB_NOERROR;
 }
 
+int ub_ctx_set_stub(struct ub_ctx* ctx, const char* zone, const char* addr,
+       int isprime)
+{
+       struct sockaddr_storage storage;
+       socklen_t stlen;
+       uint8_t* nm;
+       int nmlabs;
+       size_t nmlen;
+       char* a;
+       struct config_stub **prev, *elem;
+
+       /* check syntax for zone name */
+       if(!parse_dname(zone, &nm, &nmlen, &nmlabs)) {
+               errno=EINVAL;
+               return UB_SYNTAX; /* should have zone name, or "." for root */
+       }
+       free(nm);
+       nm = NULL;
+
+       /* check syntax for addr (if not NULL) */
+       if(addr!=NULL && !extstrtoaddr(addr, &storage, &stlen)) {
+               errno=EINVAL;
+               return UB_SYNTAX;
+       }
+
+       lock_basic_lock(&ctx->cfglock);
+       if(ctx->finalized) {
+               lock_basic_unlock(&ctx->cfglock);
+               errno=EINVAL;
+               return UB_AFTERFINAL;
+       }
+
+       /* arguments all right, now find or add the stub */
+       prev = &ctx->env->cfg->stubs;
+       elem = cfg_stub_find(&prev, zone);
+       if(!elem && !addr) {
+               /* not found and we want to delete, nothing to do */
+               lock_basic_unlock(&ctx->cfglock);
+               return UB_NOERROR;
+       } else if(elem && !addr) {
+               /* found, and we want to delete */
+               *prev = elem->next;
+               config_delstub(elem);
+               lock_basic_unlock(&ctx->cfglock);
+               return UB_NOERROR;
+       } else if(!elem) {
+               /* not found, create the stub entry */
+               elem=(struct config_stub*)calloc(1, sizeof(struct config_stub));
+               if(elem) elem->name = strdup(zone);
+               if(!elem || !elem->name) {
+                       free(elem);
+                       lock_basic_unlock(&ctx->cfglock);
+                       errno = ENOMEM;
+                       return UB_NOMEM;
+               }
+               elem->next = ctx->env->cfg->stubs;
+               ctx->env->cfg->stubs = elem;
+       }
+
+       /* add the address to the list and set settings */
+       elem->isprime = isprime;
+       a = strdup(addr);
+       if(!a) {
+               lock_basic_unlock(&ctx->cfglock);
+               errno = ENOMEM;
+               return UB_NOMEM;
+       }
+       if(!cfg_strlist_insert(&elem->addrs, a)) {
+               lock_basic_unlock(&ctx->cfglock);
+               free(a);
+               errno = ENOMEM;
+               return UB_NOMEM;
+       }
+       lock_basic_unlock(&ctx->cfglock);
+       return UB_NOERROR;
+}
+
 int 
 ub_ctx_resolvconf(struct ub_ctx* ctx, const char* fname)
 {
index fe903d0c51d4bdcef4edf9bf6ec1a5bb47fb58d5..9c828fc292bce0c570c9749d633fbc0a7c963acc 100644 (file)
@@ -303,6 +303,27 @@ int ub_ctx_config(struct ub_ctx* ctx, const char* fname);
  */
 int ub_ctx_set_fwd(struct ub_ctx* ctx, const char* addr);
 
+/**
+ * Add a stub zone, with given address to send to.  This is for custom
+ * root hints or pointing to a local authoritative dns server.
+ * For dns resolvers and the 'DHCP DNS' ip address, use ub_ctx_set_fwd.
+ * This is similar to a stub-zone entry in unbound.conf.
+ *
+ * @param ctx: context.
+ *     It is only possible to set configuration before the
+ *     first resolve is done.
+ * @param zone: name of the zone, string.
+ * @param addr: address, IP4 or IP6 in string format.
+ *     The addr is added to the list of stub-addresses if the entry exists.
+ *     If the addr is NULL the stub entry is removed.
+ * @param isprime: set to true to set stub-prime to yes for the stub.
+ *     For local authoritative servers, people usually set it to false,
+ *     For root hints it should be set to true.
+ * @return 0 if OK, else error.
+ */
+int ub_ctx_set_stub(struct ub_ctx* ctx, const char* zone, const char* addr,
+       int isprime);
+
 /**
  * Read list of nameservers to use from the filename given.
  * Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
index b450aaf385511403ab6d06862a9d62c5bffea638..f9b1531c23dcef04988f68ac73cfad92d7045f90 100644 (file)
@@ -873,6 +873,18 @@ config_read(struct config_file* cfg, const char* filename, const char* chroot)
        return 1;
 }
 
+struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm)
+{
+       struct config_stub* p = *(*pp);
+       while(p) {
+               if(strcmp(p->name, nm) == 0)
+                       return p;
+               (*pp) = &p->next;
+               p = p->next;
+       }
+       return NULL;
+}
+
 void
 config_delstrlist(struct config_strlist* p)
 {
@@ -898,16 +910,23 @@ config_deldblstrlist(struct config_str2list* p)
        }
 }
 
+void
+config_delstub(struct config_stub* p)
+{
+       if(!p) return;
+       free(p->name);
+       config_delstrlist(p->hosts);
+       config_delstrlist(p->addrs);
+       free(p);
+}
+
 void
 config_delstubs(struct config_stub* p)
 {
        struct config_stub* np;
        while(p) {
                np = p->next;
-               free(p->name);
-               config_delstrlist(p->hosts);
-               config_delstrlist(p->addrs);
-               free(p);
+               config_delstub(p);
                p = np;
        }
 }
index 42917c434bbab202bb26df81684b5d72f395200d..ef823fb88d3a082d683020537d651add5feff78e 100644 (file)
@@ -559,6 +559,17 @@ int cfg_strlist_insert(struct config_strlist** head, char* item);
  */
 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
 
+/**
+ * Find stub in config list, also returns prevptr (for deletion).
+ * @param pp: call routine with pointer to a pointer to the start of the list,
+ *     if the stub is found, on exit, the value contains a pointer to the
+ *     next pointer that points to the found element (or to the list start
+ *     pointer if it is the first element).
+ * @param nm: name of stub to find.
+ * @return: pointer to config_stub if found, or NULL if not found.
+ */
+struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
+
 /**
  * Delete items in config string list.
  * @param list: list.
@@ -571,6 +582,12 @@ void config_delstrlist(struct config_strlist* list);
  */
 void config_deldblstrlist(struct config_str2list* list);
 
+/**
+ * Delete a stub item
+ * @param p: stub item
+ */
+void config_delstub(struct config_stub* p);
+
 /**
  * Delete items in config stub list.
  * @param list: list.