]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
rrset-order support.
authorMark Andrews <marka@isc.org>
Thu, 7 Mar 2002 06:29:37 +0000 (06:29 +0000)
committerMark Andrews <marka@isc.org>
Thu, 7 Mar 2002 06:29:37 +0000 (06:29 +0000)
lib/dns/Makefile.in
lib/dns/include/dns/order.h [new file with mode: 0644]
lib/dns/order.c [new file with mode: 0644]
util/copyrights

index e310c853f0588ec76917f65927286140be05e374..85a4dfb8e9e0f2058cf4ef980e610f26f497fe12 100644 (file)
@@ -13,7 +13,7 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: Makefile.in,v 1.128 2001/10/01 18:54:00 gson Exp $
+# $Id: Makefile.in,v 1.129 2002/03/07 06:29:36 marka Exp $
 
 srcdir =       @srcdir@
 VPATH =                @srcdir@
@@ -49,7 +49,7 @@ OBJS =                a6.@O@ acl.@O@ adb.@O@ byaddr.@O@ \
                dnssec.@O@ forward.@O@ journal.@O@ keytable.@O@ \
                lib.@O@ log.@O@ lookup.@O@ \
                master.@O@ masterdump.@O@ message.@O@ \
-               name.@O@ ncache.@O@ nxt.@O@ peer.@O@ \
+               name.@O@ ncache.@O@ nxt.@O@ order.@O@ peer.@O@ \
                rbt.@O@ rbtdb.@O@ rbtdb64.@O@ rdata.@O@ rdatalist.@O@ \
                rdataset.@O@ rdatasetiter.@O@ rdataslab.@O@ request.@O@ \
                resolver.@O@ result.@O@ rootns.@O@ sdb.@O@ soa.@O@ ssu.@O@ \
@@ -65,7 +65,7 @@ SRCS =                a6.c acl.c adb.c byaddr.c \
                dnssec.c forward.c journal.c keytable.c \
                lib.c log.c lookup.c \
                master.c masterdump.c message.c \
-               name.c ncache.c nxt.c peer.c \
+               name.c ncache.c nxt.c order.c peer.c \
                rbt.c rbtdb.c rbtdb64.c rdata.c rdatalist.c \
                rdataset.c rdatasetiter.c rdataslab.c request.c \
                resolver.c result.c rootns.c sdb.c soa.c ssu.c \
diff --git a/lib/dns/include/dns/order.h b/lib/dns/include/dns/order.h
new file mode 100644 (file)
index 0000000..fdd0c04
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2002  Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: order.h,v 1.1 2002/03/07 06:29:37 marka Exp $ */
+
+#include <isc/lang.h>
+#include <isc/types.h>
+
+#include <dns/types.h>
+
+ISC_LANG_BEGINDECLS
+
+isc_result_t
+dns_order_create(dns_order_t **orderp, isc_mem_t *mctx);
+/*
+ * Create a order object.
+ *
+ * Requires:
+ *     'orderp' to be non NULL and '*orderp == NULL'.
+ *     'mctx' to be valid.
+ *
+ * Returns:
+ *     ISC_R_SUCCESS
+ *     ISC_R_NOMEMORY
+ */
+
+isc_result_t
+dns_order_add(dns_order_t *order, dns_name_t *name,
+             dns_rdatatype_t rdtype, dns_rdataclass_t rdclass,
+             unsigned int mode);
+/*
+ * Add a entry to the end of the order list.
+ *
+ * Requires:
+ *     'order' to be valid.
+ *     'name' to be valid.
+ *     'mode' to be one of DNS_RDATASERATTR_RANDOMIZE,
+ *             DNS_RDATASERATTR_RANDOMIZE or zero (DNS_RDATASERATTR_CYCLIC).
+ *
+ * Returns:
+ *     ISC_R_SUCCESS
+ *     ISC_R_NOMEMORY
+ */
+
+unsigned int
+dns_order_find(dns_order_t *order, dns_name_t *name,
+              dns_rdatatype_t rdtype, dns_rdataclass_t rdclass);
+/*
+ * Find the first matching entry on the list.
+ *
+ * Requires:
+ *     'order' to be valid.
+ *     'name' to be valid.
+ *
+ * Returns the mode set by dns_order_add() or zero.
+ */
+
+void
+dns_order_attach(dns_order_t *source, dns_order_t **target);
+/*
+ * Attach to the 'source' object.
+ *
+ * Requires:
+ *     'source' to be valid.
+ *     'target' to be non NULL and '*target == NULL'.
+ */
+
+void
+dns_order_detach(dns_order_t **orderp);
+/*
+ * Detach from the object.  Clean up if last this was the last
+ * reference.
+ *
+ * Requires:
+ *     '*orderp' to be valid.
+ */
+
+ISC_LANG_ENDDECLS
diff --git a/lib/dns/order.c b/lib/dns/order.c
new file mode 100644 (file)
index 0000000..74d8589
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2002  Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: order.c,v 1.1 2002/03/07 06:29:37 marka Exp $ */
+
+#include <isc/magic.h>
+#include <isc/mem.h>
+#include <isc/types.h>
+#include <isc/util.h>
+#include <isc/refcount.h>
+
+#include <dns/fixedname.h>
+#include <dns/name.h>
+#include <dns/order.h>
+#include <dns/rdataset.h>
+#include <dns/types.h>
+
+typedef struct dns_order_ent dns_order_ent_t;
+struct dns_order_ent {
+       dns_fixedname_t                 name;
+       dns_rdataclass_t                rdclass;
+       dns_rdatatype_t                 rdtype;
+       unsigned int                    mode;
+       ISC_LINK(dns_order_ent_t)       link;
+};
+
+struct dns_order {
+       unsigned int                    magic;
+       isc_refcount_t                  references;
+       ISC_LIST(dns_order_ent_t)       ents;
+       isc_mem_t                       *mctx;
+};
+       
+#define DNS_ORDER_MAGIC ISC_MAGIC('O','r','d','r')
+#define DNS_ORDER_VALID(order) ISC_MAGIC_VALID(order, DNS_ORDER_MAGIC)
+
+isc_result_t
+dns_order_create(dns_order_t **orderp, isc_mem_t *mctx) {
+       dns_order_t *order;
+       REQUIRE(orderp != NULL && *orderp == NULL);
+
+       order = isc_mem_get(mctx, sizeof(*order));
+       if (order == NULL)
+               return (ISC_R_NOMEMORY);
+       
+       ISC_LIST_INIT(order->ents);
+       isc_refcount_init(&order->references, 1);     /* Implicit attach. */
+
+       order->mctx = 0;
+       isc_mem_attach(mctx, &order->mctx);
+       order->magic = DNS_ORDER_MAGIC;
+       return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+dns_order_add(dns_order_t *order, dns_name_t *name,
+             dns_rdatatype_t rdtype, dns_rdataclass_t rdclass,
+             unsigned int mode)
+{
+       dns_order_ent_t *ent;
+
+       REQUIRE(DNS_ORDER_VALID(order));
+       REQUIRE(mode == DNS_RDATASETATTR_RANDOMIZE ||
+               mode == DNS_RDATASETATTR_FIXEDORDER ||
+               mode == 0 /* DNS_RDATASETATTY_CYCLIC */ );
+
+       ent = isc_mem_get(order->mctx, sizeof(*ent));
+       if (ent == NULL)
+               return (ISC_R_NOMEMORY);
+
+       dns_fixedname_init(&ent->name);
+       RUNTIME_CHECK(dns_name_copy(name, dns_fixedname_name(&ent->name), NULL)
+                     == ISC_R_SUCCESS);
+       ent->rdtype = rdtype;
+       ent->rdclass = rdclass;
+       ent->mode = mode;
+       ISC_LINK_INIT(ent, link);
+       ISC_LIST_INITANDAPPEND(order->ents, ent, link);
+       return (ISC_R_SUCCESS);
+}
+
+static inline isc_boolean_t
+match(dns_name_t *name1, dns_name_t *name2) {
+       
+       if (dns_name_iswildcard(name2))
+               return(dns_name_matcheswildcard(name1, name2));
+       return (dns_name_equal(name1, name2));
+}
+
+unsigned int
+dns_order_find(dns_order_t *order, dns_name_t *name,
+              dns_rdatatype_t rdtype, dns_rdataclass_t rdclass)
+{
+       dns_order_ent_t *ent;
+       REQUIRE(DNS_ORDER_VALID(order));
+
+       for (ent = ISC_LIST_HEAD(order->ents);
+            ent != NULL;
+            ent = ISC_LIST_NEXT(ent, link)) {
+               if (ent->rdtype != rdtype && ent->rdtype != dns_rdatatype_any)
+                       continue;
+               if (ent->rdclass != rdclass &&
+                   ent->rdclass != dns_rdataclass_any)
+                       continue;
+               if (match(name, dns_fixedname_name(&ent->name)))
+                       return (ent->mode);
+       }
+       return (0);
+}
+
+void
+dns_order_attach(dns_order_t *source, dns_order_t **target) {
+       REQUIRE(DNS_ORDER_VALID(source));
+       REQUIRE(target != NULL && *target == NULL);
+       isc_refcount_increment(&source->references, NULL);
+       *target = source;
+}
+
+void
+dns_order_detach(dns_order_t **orderp) {
+       dns_order_t *order;
+       dns_order_ent_t *ent;
+       unsigned int references;
+
+       REQUIRE(orderp != NULL);
+       order = *orderp;
+       REQUIRE(DNS_ORDER_VALID(order));
+       isc_refcount_decrement(&order->references, &references);
+       *orderp = NULL;
+       if (references != 0)
+               return;
+
+       order->magic = 0;
+       while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
+               ISC_LIST_UNLINK(order->ents, ent, link);
+               isc_mem_put(order->mctx, ent, sizeof(*ent));
+       }
+       isc_refcount_destroy(&order->references);
+       isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
+}
index 61cdb3f4037aef63da15de53e1d4eff9c6c76ee2..05b6ef2d996f489bbba3187ce14e4446c8918cdc 100644 (file)
 ./lib/dns/include/dns/name.h                   C       1998,1999,2000,2001,2002
 ./lib/dns/include/dns/ncache.h                 C       1999,2000,2001,2002
 ./lib/dns/include/dns/nxt.h                    C       1999,2000,2001
+./lib/dns/include/dns/order.h                  C       2002
 ./lib/dns/include/dns/peer.h                   C       2000,2001
 ./lib/dns/include/dns/rbt.h                    C       1999,2000,2001
 ./lib/dns/include/dns/rcode.h                  C       1999,2000,2001
 ./lib/dns/name.c                               C       1998,1999,2000,2001
 ./lib/dns/ncache.c                             C       1999,2000,2001,2002
 ./lib/dns/nxt.c                                        C       1999,2000,2001
+./lib/dns/order.c                              C       2002
 ./lib/dns/peer.c                               C       2000,2001
 ./lib/dns/rbt.c                                        C       1999,2000,2001
 ./lib/dns/rbtdb.c                              C       1999,2000,2001