]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
WIP: Support new server connect syntax
authorArtem Boldariev <artem@boldariev.com>
Thu, 25 Nov 2021 16:40:15 +0000 (18:40 +0200)
committerArtem Boldariev <artem@boldariev.com>
Fri, 26 Nov 2021 19:43:32 +0000 (21:43 +0200)
bin/named/server.c
lib/dns/include/dns/peer.h
lib/dns/include/dns/transport.h
lib/dns/peer.c
lib/dns/transport.c

index b2d47186228e0fdcfc07b57b367fd76918945182..026b6ebe3d2c511734e4c810f1f6a1cb49ca7df3 100644 (file)
@@ -1528,6 +1528,13 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) {
                CHECK(dns_peer_setforcetcp(peer, cfg_obj_asboolean(obj)));
        }
 
+       obj = NULL;
+       (void)cfg_map_get(cpeer, "connect", &obj);
+       if (obj != NULL) {
+               (void)dns_peer_setforcetcp(peer, false);
+               //(void)dns_peer_settransport(peer, DNS_TRANSPORT_TCP);
+       }
+
        obj = NULL;
        (void)cfg_map_get(cpeer, "tcp-keepalive", &obj);
        if (obj != NULL) {
index facbf2dc230088cef3c6b79326c549ff7ee987f0..b08c9dd2813cdffbd1de95a91fd30fdb711dbc7f 100644 (file)
@@ -32,6 +32,7 @@
 #include <isc/netaddr.h>
 #include <isc/refcount.h>
 
+#include <dns/transport.h>
 #include <dns/types.h>
 
 #define DNS_PEERLIST_MAGIC ISC_MAGIC('s', 'e', 'R', 'L')
@@ -221,4 +222,11 @@ dns_peer_setednsversion(dns_peer_t *peer, uint8_t ednsversion);
 
 isc_result_t
 dns_peer_getednsversion(dns_peer_t *peer, uint8_t *ednsversion);
+
+isc_result_t
+dns_peer_settransport(dns_peer_t *peer, dns_transport_type_t type);
+
+isc_result_t
+dns_peer_gettransport(dns_peer_t *peer, dns_transport_t **transportp);
+
 ISC_LANG_ENDDECLS
index 63526fc8e302efd8d84d02ba2eae30b10d70e109..f1a84c10c68fa1762645e93b50a765ee41ad83fe 100644 (file)
@@ -30,6 +30,9 @@ typedef enum {
 typedef struct dns_transport     dns_transport_t;
 typedef struct dns_transport_list dns_transport_list_t;
 
+dns_transport_t *
+dns_transport_create(dns_transport_type_t type, isc_mem_t *mctx);
+
 dns_transport_t *
 dns_transport_new(const dns_name_t *name, dns_transport_type_t type,
                  dns_transport_list_t *list);
index 641574f82720f16446f321bed20a89e17f507b37..ed7fe40d5ffbebc9be74ba406054e55e16a9569e 100644 (file)
@@ -71,6 +71,7 @@ struct dns_peer {
        uint8_t ednsversion; /* edns version */
 
        uint32_t bitflags;
+       dns_transport_t *transport;
 
        ISC_LINK(dns_peer_t) next;
 };
@@ -96,6 +97,7 @@ struct dns_peer {
 #define FORCE_TCP_BIT             15
 #define SERVER_PADDING_BIT        16
 #define REQUEST_TCP_KEEPALIVE_BIT  17
+#define TRANSPORT_BIT             18
 
 static void
 peerlist_delete(dns_peerlist_t **list);
@@ -344,6 +346,11 @@ peer_delete(dns_peer_t **peer) {
                            sizeof(*p->transfer_source));
        }
 
+       if (DNS_BIT_CHECK(TRANSPORT_BIT, &p->bitflags)) {
+               INSIST(p->transport != NULL);
+               dns_transport_detach(&p->transport);
+       }
+
        isc_mem_put(mem, p, sizeof(*p));
 }
 
@@ -965,3 +972,26 @@ dns_peer_getednsversion(dns_peer_t *peer, uint8_t *ednsversion) {
                return (ISC_R_NOTFOUND);
        }
 }
+
+isc_result_t
+dns_peer_settransport(dns_peer_t *peer, dns_transport_type_t type) {
+       REQUIRE(DNS_PEER_VALID(peer));
+
+       peer->transport = dns_transport_create(type, peer->mem);
+       DNS_BIT_SET(TRANSPORT_BIT, &peer->bitflags);
+       return (ISC_R_SUCCESS);
+}
+
+isc_result_t
+dns_peer_gettransport(dns_peer_t *peer, dns_transport_t **transportp) {
+       REQUIRE(DNS_PEER_VALID(peer));
+       REQUIRE(transportp != NULL && *transportp == NULL);
+
+       if (!DNS_BIT_CHECK(EDNS_VERSION_BIT, &peer->bitflags)) {
+               return (ISC_R_NOTFOUND);
+       }
+
+       *transportp = peer->transport;
+
+       return (ISC_R_SUCCESS);
+}
index 64fe5f6ce457d0de5ee80ac5b49b863cfe48072b..19f038ec19b71d23d9ca3b9d19e9fec1d40457af 100644 (file)
@@ -131,14 +131,23 @@ dns_transport_get_mode(dns_transport_t *transport) {
 }
 
 dns_transport_t *
-dns_transport_new(const dns_name_t *name, dns_transport_type_t type,
-                 dns_transport_list_t *list) {
-       dns_transport_t *transport = isc_mem_get(list->mctx,
-                                                sizeof(*transport));
+dns_transport_create(dns_transport_type_t type, isc_mem_t *mctx) {
+       dns_transport_t *transport;
+
+       REQUIRE(type > DNS_TRANSPORT_NONE && type < DNS_TRANSPORT_COUNT);
+
+       transport = isc_mem_get(mctx, sizeof(*transport));
        *transport = (dns_transport_t){ .type = type };
        isc_refcount_init(&transport->references, 1);
-       isc_mem_attach(list->mctx, &transport->mctx);
+       isc_mem_attach(mctx, &transport->mctx);
        transport->magic = TRANSPORT_MAGIC;
+       return (transport);
+}
+
+dns_transport_t *
+dns_transport_new(const dns_name_t *name, dns_transport_type_t type,
+                 dns_transport_list_t *list) {
+       dns_transport_t *transport = dns_transport_create(type, list->mctx);
 
        list_add(list, name, type, transport);