backends: handle priority, weight and ttl from backends
authorPavel Šimerda <psimerda@redhat.com>
Wed, 8 Oct 2014 16:17:56 +0000 (18:17 +0200)
committerPavel Šimerda <psimerda@redhat.com>
Wed, 8 Oct 2014 16:26:16 +0000 (18:26 +0200)
12 files changed:
backends/any.c
backends/aresdns.c
backends/exec.c
backends/getaddrinfo.c
backends/hosts.c
backends/loopback.c
backends/nss.c
backends/numerichost.c
backends/ubdns.c
backends/unix.c
lib/backend.c
lib/netresolve-backend.h

index acd84a30f4c60f3c1425d85a2e850c231cd06124..24c70dd57caf78662c4d1982f13dad49335c2c76 100644 (file)
@@ -38,7 +38,7 @@ start(netresolve_query_t query, char **settings)
                return;
        }
 
-       netresolve_backend_add_path(query, AF_INET, &inaddr_any, 0, 0, 0, 0, 0, 0);
-       netresolve_backend_add_path(query, AF_INET6, &in6addr_any, 0, 0, 0, 0, 0, 0);
+       netresolve_backend_add_path(query, AF_INET, &inaddr_any, 0, 0, 0, 0, 0, 0, 0);
+       netresolve_backend_add_path(query, AF_INET6, &in6addr_any, 0, 0, 0, 0, 0, 0, 0);
        netresolve_backend_finished(query);
 }
index decd968e34fe9aad1dff66790032849e79f3a037..0004bfa4ab4ccdd0bc2c3931ca885d013064169b 100644 (file)
@@ -91,6 +91,7 @@ host_callback(void *arg, int status, int timeouts, struct hostent *he)
        int port = -1;
        int priority = 0;
        int weight = 0;
+       int ttl = 0;
 
        if (srv) {
                socktype = netresolve_backend_get_socktype(query);
@@ -107,7 +108,7 @@ host_callback(void *arg, int status, int timeouts, struct hostent *he)
                priv->ptfd = netresolve_backend_add_timeout(query, partial_timeout, 0);
                if (priv->ptfd == -1)
                        error("timer: %s", strerror(errno));
-               netresolve_backend_apply_hostent(query, he, socktype, protocol, port, priority, weight);
+               netresolve_backend_apply_hostent(query, he, socktype, protocol, port, priority, weight, ttl);
                break;
        default:
                error("ares: %s\n", ares_strerror(status));
index dde7fb48652e2079a188a3ec9d728428d009d074..7c62e64f08263cab49bbee859d996db8cf52c886 100644 (file)
@@ -124,11 +124,11 @@ received_line(netresolve_query_t query, struct priv_exec *priv, const char *line
        if (!strncmp(addrprefix, line, addrprefixlen)) {
                if (netresolve_backend_parse_address(line + addrprefixlen,
                                        &address, &family, &ifindex))
-                       netresolve_backend_add_path(query, family, &address, ifindex, 0, 0, 0, 0, 0);
+                       netresolve_backend_add_path(query, family, &address, ifindex, 0, 0, 0, 0, 0, 0);
        } else if (!strncmp(pathprefix, line, pathprefixlen)) {
                if (netresolve_backend_parse_path(line + pathprefixlen,
                                        &address, &family, &ifindex, &socktype, &protocol, &port))
-                       netresolve_backend_add_path(query, family, &address, ifindex, socktype, protocol, port, 0, 0);
+                       netresolve_backend_add_path(query, family, &address, ifindex, socktype, protocol, port, 0, 0, 0);
        }
 
        return false;
index e4a29d2af5d9353fa414fd118ff34838f7663362..a86c0666a12ecbf876c56bd29616a5de5cb5e429 100644 (file)
@@ -58,7 +58,7 @@ add_addresses(netresolve_query_t query, const struct addrinfo *first)
                netresolve_backend_add_path(query,
                                ai->ai_family, &address, ifindex,
                                ai->ai_socktype, ai->ai_protocol, port,
-                               0, 0);
+                               0, 0, 0);
        }
 
 }
index f4f9c679129e56f4523e5ab1cfc190d4afabed5b..e77255f5d5f15fda5359012acd7664263d3a9f02 100644 (file)
@@ -158,7 +158,7 @@ start(netresolve_query_t query, char **settings)
        for (item = list.items; item->name; item++) {
                if (request_node && strcmp(request_node, item->name))
                        continue;
-               netresolve_backend_add_path(query, item->family, &item->address, item->ifindex, 0, 0, 0, 0, 0);
+               netresolve_backend_add_path(query, item->family, &item->address, item->ifindex, 0, 0, 0, 0, 0, 0);
                count++;
        }
 
index 0befa7f625dfffe88ffe180e9fbed509d23afa2c..3a74febbf664a876674bd766841e3c7895459055 100644 (file)
@@ -47,8 +47,8 @@ start(netresolve_query_t query, char **settings)
        }
 
        if (ipv4)
-               netresolve_backend_add_path(query, AF_INET, &inaddr_loopback, 0, 0, 0, 0, 0, 0);
+               netresolve_backend_add_path(query, AF_INET, &inaddr_loopback, 0, 0, 0, 0, 0, 0, 0);
        if (ipv6)
-               netresolve_backend_add_path(query, AF_INET6, &in6addr_loopback, 0, 0, 0, 0, 0, 0);
+               netresolve_backend_add_path(query, AF_INET6, &in6addr_loopback, 0, 0, 0, 0, 0, 0, 0);
        netresolve_backend_finished(query);
 }
index 9f93c3c94324a3a47a29bd4212639c5aa2668839..421ed95149af5446e81ced0bbc2fd7a907ac2c62 100644 (file)
@@ -168,9 +168,9 @@ start(netresolve_query_t query, char **settings)
                status = combine_statuses(status4, status6);
                if (status == NSS_STATUS_SUCCESS) {
                        if (status4 == NSS_STATUS_SUCCESS)
-                               netresolve_backend_apply_hostent(query, &he4, 0, 0, 0, 0, 0);
+                               netresolve_backend_apply_hostent(query, &he4, 0, 0, 0, 0, 0, 0);
                        if (status6 == NSS_STATUS_SUCCESS)
-                               netresolve_backend_apply_hostent(query, &he6, 0, 0, 0, 0, 0);
+                               netresolve_backend_apply_hostent(query, &he6, 0, 0, 0, 0, 0, 0);
                }
        } else if (node && priv->gethostbyname_r) {
                char buffer[SIZE];
@@ -181,7 +181,7 @@ start(netresolve_query_t query, char **settings)
                        &he, buffer, sizeof buffer, &errnop, &h_errnop));
 
                if (status == NSS_STATUS_SUCCESS) {
-                       netresolve_backend_apply_hostent(query, &he, 0, 0, 0, 0, 0);
+                       netresolve_backend_apply_hostent(query, &he, 0, 0, 0, 0, 0, 0);
                }
        }
 
index dc1a642c106d6c5d4c562402828a34cf0967d72c..45f6d7dceb9446dea36171314916b3b7f78d1e82 100644 (file)
@@ -36,6 +36,6 @@ start(netresolve_query_t query, char **settings)
                return;
        }
 
-       netresolve_backend_add_path(query, family, &address, ifindex, 0, 0, 0, 0, 0);
+       netresolve_backend_add_path(query, family, &address, ifindex, 0, 0, 0, 0, 0, 0);
        netresolve_backend_finished(query);
 }
index 6b9ef7bcf930a9d65309cb17bfc409b19ff64930..941b56d263df619529d4bb9568d208a7043e8d97 100644 (file)
@@ -49,6 +49,7 @@ host_callback(void *arg, int status, struct ub_result* result)
        int port = -1;
        int priority = 0;
        int weight = 0;
+       int ttl = 0;
 
        switch (status) {
        case 0:
@@ -56,7 +57,7 @@ host_callback(void *arg, int status, struct ub_result* result)
                        char **data;
 
                        for (data = result->data; *data; data++)
-                               netresolve_backend_add_path(query, family, *data, 0, socktype, protocol, port, priority, weight);
+                               netresolve_backend_add_path(query, family, *data, 0, socktype, protocol, port, priority, weight, ttl);
                }
                ub_resolve_free(result);
                break;
index 38264cd87cdf281bb91b701712aaa8eedddb9c46..ccd3d4417e08cb2d9a98d0a669202ad3bc4f415e 100644 (file)
@@ -38,6 +38,6 @@ start(netresolve_query_t query, char **settings)
                return;
        }
 
-       netresolve_backend_add_path(query, AF_UNIX, node, 0, socktype, 0, 0, 0, 0);
+       netresolve_backend_add_path(query, AF_UNIX, node, 0, socktype, 0, 0, 0, 0, 0);
        netresolve_backend_finished(query);
 }
index be0a0c237e2ca295a14a8b1ffa3791512cf5426c..a3bee113a0b05773dcd8c39318f9471f29395f4f 100644 (file)
@@ -92,6 +92,9 @@ typedef struct {
        int family;
        const void *address;
        int ifindex;
+       int priority;
+       int weight;
+       int32_t ttl;
 } PathData;
 
 static void
@@ -102,7 +105,7 @@ path_callback(int socktype, int protocol, int port, void *user_data)
        netresolve_backend_add_path(data->query,
                        data->family, data->address, data->ifindex,
                        socktype, protocol, port,
-                       0, 0);
+                       data->priority, data->weight, data->ttl);
 }
 
 static int
@@ -120,15 +123,14 @@ void
 netresolve_backend_add_path(netresolve_query_t query,
                int family, const void *address, int ifindex,
                int socktype, int protocol, int portnum,
-               int priority, int weight)
+               int priority, int weight, int32_t ttl)
 {
        struct netresolve_response *response = &query->response;
-       struct netresolve_path path;
        int i;
 
        if (family == AF_UNIX && !socktype) {
-               netresolve_backend_add_path(query, family, address, 0, SOCK_STREAM, 0, 0, 0, 0);
-               netresolve_backend_add_path(query, family, address, 0, SOCK_DGRAM, 0, 0, 0, 0);
+               netresolve_backend_add_path(query, family, address, 0, SOCK_STREAM, 0, 0, priority, weight, ttl);
+               netresolve_backend_add_path(query, family, address, 0, SOCK_DGRAM, 0, 0, priority, weight, ttl);
                return;
        }
 
@@ -138,6 +140,9 @@ netresolve_backend_add_path(netresolve_query_t query,
                        .family = family,
                        .address = address,
                        .ifindex = ifindex,
+                       .priority = priority,
+                       .weight = weight,
+                       .ttl = ttl
                };
 
                netresolve_get_service_info(path_callback, &data, query->request.servname,
@@ -150,18 +155,26 @@ netresolve_backend_add_path(netresolve_query_t query,
 
        size_t length = family_to_length(family);
 
-       memset(&path, 0, sizeof path);
-       path.node.family = family;
+       struct netresolve_path path = {
+               .node = {
+                       .family = family,
+                       .address = { 0 },
+                       .ifindex = ifindex
+               },
+               .service = {
+                       .socktype = socktype,
+                       .protocol = protocol,
+                       .port = portnum
+               },
+               .priority = priority,
+               .weight = weight,
+               .ttl = ttl
+       };
+
        if (length)
                memcpy(path.node.address, address, length);
        else
                strncpy(path.node.address, address, sizeof path.node.address);
-       path.node.ifindex = ifindex;
-       path.service.socktype = socktype;
-       path.service.protocol = protocol;
-       path.service.port = portnum;
-       path.priority = priority;
-       path.weight = weight;
 
        for (i = 0; i < response->pathcount; i++)
                if (path_cmp(&path, &response->paths[i]) < 0)
@@ -388,7 +401,7 @@ void
 netresolve_backend_apply_hostent(netresolve_query_t query,
                const struct hostent *he,
                int socktype, int protocol, int port,
-               int priority, int weight)
+               int priority, int weight, int32_t ttl)
 {
        char **addr;
 
@@ -396,7 +409,7 @@ netresolve_backend_apply_hostent(netresolve_query_t query,
                netresolve_backend_add_path(query,
                                he->h_addrtype, *addr, 0,
                                socktype, protocol, port,
-                               priority, weight);
+                               priority, weight, ttl);
 
        if (he->h_name)
                netresolve_backend_set_canonical_name(query, he->h_name);
index 4a53635c2b0830b5b182d3596f206cc1dcc263ea..80f8e496db1af89b397e19183b4ae67bd85c6cc8 100644 (file)
@@ -48,7 +48,7 @@ bool netresolve_backend_get_dns_srv_lookup(netresolve_query_t query);
 void netresolve_backend_add_path(netresolve_query_t query,
                int family, const void *address, int ifindex,
                int socktype, int protocol, int port,
-               int priority, int weight);
+               int priority, int weight, int32_t ttl);
 void netresolve_backend_set_canonical_name(netresolve_query_t query, const char *canonical_name);
 
 /* Tools */
@@ -75,7 +75,7 @@ bool netresolve_backend_parse_path(const char *str,
 void netresolve_backend_apply_hostent(netresolve_query_t query,
                const struct hostent *he,
                int socktype, int protocol, int port,
-               int priority, int weight);
+               int priority, int weight, int32_t ttl);
 
 /* Backend function prototypes */
 void start(netresolve_query_t query, char **settings);
This page took 0.083396 seconds and 5 git commands to generate.