[systemd-commits] 5 commits - src/libsystemd src/network src/systemd TODO

Tom Gundersen tomegun at kemper.freedesktop.org
Sat Jan 18 08:53:24 PST 2014


 TODO                             |    2 -
 src/libsystemd/resolve-util.h    |    2 -
 src/libsystemd/sd-dhcp-client.c  |   36 ++++++++++++++++++++++++++
 src/libsystemd/sd-resolve.c      |   53 +++++++++++++++------------------------
 src/libsystemd/test-resolve.c    |    2 -
 src/network/networkd-gperf.gperf |    1 
 src/network/networkd-manager.c   |   19 ++++++++++---
 src/network/networkd-network.c   |    1 
 src/network/networkd.h           |    1 
 src/systemd/sd-dhcp-client.h     |    1 
 src/systemd/sd-resolve.h         |    9 ++----
 11 files changed, 79 insertions(+), 48 deletions(-)

New commits:
commit 35bbea48dcb74ed2ecc1cab1ca7306acf6d6bb65
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Sat Jan 18 16:07:31 2014 +0100

    sd-resolv: declare functions from .h public

diff --git a/src/libsystemd/sd-resolve.c b/src/libsystemd/sd-resolve.c
index b6bf8d4..464967b 100644
--- a/src/libsystemd/sd-resolve.c
+++ b/src/libsystemd/sd-resolve.c
@@ -414,7 +414,7 @@ static void* thread_worker(void *p) {
         return NULL;
 }
 
-sd_resolve* sd_resolve_new(unsigned n_proc) {
+_public_ sd_resolve* sd_resolve_new(unsigned n_proc) {
         sd_resolve *resolve = NULL;
         int i, r;
 
@@ -468,7 +468,7 @@ fail:
         return NULL;
 }
 
-void sd_resolve_free(sd_resolve *resolve) {
+_public_ void sd_resolve_free(sd_resolve *resolve) {
         int i;
         int saved_errno = errno;
         unsigned p;
@@ -511,7 +511,7 @@ void sd_resolve_free(sd_resolve *resolve) {
         errno = saved_errno;
 }
 
-int sd_resolve_fd(sd_resolve *resolve) {
+_public_ int sd_resolve_fd(sd_resolve *resolve) {
         assert(resolve);
 
         return resolve->fds[RESPONSE_RECV_FD];
@@ -709,7 +709,7 @@ static int handle_response(sd_resolve *resolve, const Packet *packet, size_t len
         return 0;
 }
 
-int sd_resolve_wait(sd_resolve *resolve, int block) {
+_public_ int sd_resolve_wait(sd_resolve *resolve, int block) {
         int handled = 0;
         assert(resolve);
 
@@ -787,7 +787,7 @@ static sd_resolve_query *alloc_query(sd_resolve *resolve) {
         return q;
 }
 
-sd_resolve_query* sd_resolve_getaddrinfo(sd_resolve *resolve, const char *node, const char *service, const struct addrinfo *hints) {
+_public_ sd_resolve_query* sd_resolve_getaddrinfo(sd_resolve *resolve, const char *node, const char *service, const struct addrinfo *hints) {
         AddrInfoRequest data[BUFSIZE/sizeof(AddrInfoRequest) + 1] = {};
         AddrInfoRequest *req = data;
         sd_resolve_query *q;
@@ -840,7 +840,7 @@ fail:
         return NULL;
 }
 
-int sd_resolve_getaddrinfo_done(sd_resolve *resolve, sd_resolve_query* q, struct addrinfo **ret_res) {
+_public_ int sd_resolve_getaddrinfo_done(sd_resolve *resolve, sd_resolve_query* q, struct addrinfo **ret_res) {
         int ret;
         assert(resolve);
         assert(q);
@@ -871,7 +871,7 @@ int sd_resolve_getaddrinfo_done(sd_resolve *resolve, sd_resolve_query* q, struct
         return ret;
 }
 
-sd_resolve_query* sd_resolve_getnameinfo(sd_resolve *resolve, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv) {
+_public_ sd_resolve_query* sd_resolve_getnameinfo(sd_resolve *resolve, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv) {
         NameInfoRequest data[BUFSIZE/sizeof(NameInfoRequest) + 1] = {};
         NameInfoRequest *req = data;
         sd_resolve_query *q;
@@ -917,7 +917,7 @@ fail:
         return NULL;
 }
 
-int sd_resolve_getnameinfo_done(sd_resolve *resolve, sd_resolve_query* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen) {
+_public_ int sd_resolve_getnameinfo_done(sd_resolve *resolve, sd_resolve_query* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen) {
         int ret;
         assert(resolve);
         assert(q);
@@ -1002,15 +1002,15 @@ fail:
         return NULL;
 }
 
-sd_resolve_query* sd_resolve_res_query(sd_resolve *resolve, const char *dname, int class, int type) {
+_public_ sd_resolve_query* sd_resolve_res_query(sd_resolve *resolve, const char *dname, int class, int type) {
         return resolve_res(resolve, REQUEST_RES_QUERY, dname, class, type);
 }
 
-sd_resolve_query* sd_resolve_res_search(sd_resolve *resolve, const char *dname, int class, int type) {
+_public_ sd_resolve_query* sd_resolve_res_search(sd_resolve *resolve, const char *dname, int class, int type) {
         return resolve_res(resolve, REQUEST_RES_SEARCH, dname, class, type);
 }
 
-int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char **answer) {
+_public_ int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char **answer) {
         int ret;
         assert(resolve);
         assert(q);
@@ -1043,17 +1043,17 @@ int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char
         return ret < 0 ? -errno : ret;
 }
 
-sd_resolve_query* sd_resolve_get_next(sd_resolve *resolve) {
+_public_ sd_resolve_query* sd_resolve_get_next(sd_resolve *resolve) {
         assert(resolve);
         return resolve->done_head;
 }
 
-int sd_resolve_get_n_queries(sd_resolve *resolve) {
+_public_ int sd_resolve_get_n_queries(sd_resolve *resolve) {
         assert(resolve);
         return resolve->n_queries;
 }
 
-void sd_resolve_cancel(sd_resolve *resolve, sd_resolve_query* q) {
+_public_ void sd_resolve_cancel(sd_resolve *resolve, sd_resolve_query* q) {
         int i;
         int saved_errno = errno;
 
@@ -1089,7 +1089,7 @@ void sd_resolve_cancel(sd_resolve *resolve, sd_resolve_query* q) {
         errno = saved_errno;
 }
 
-void sd_resolve_freeaddrinfo(struct addrinfo *ai) {
+_public_ void sd_resolve_freeaddrinfo(struct addrinfo *ai) {
         int saved_errno = errno;
 
         while (ai) {
@@ -1105,7 +1105,7 @@ void sd_resolve_freeaddrinfo(struct addrinfo *ai) {
         errno = saved_errno;
 }
 
-int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q) {
+_public_ int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q) {
         assert(resolve);
         assert(q);
         assert(q->resolve == resolve);
@@ -1113,7 +1113,7 @@ int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q) {
         return q->done;
 }
 
-void sd_resolve_setuserdata(sd_resolve *resolve, sd_resolve_query *q, void *userdata) {
+_public_ void sd_resolve_setuserdata(sd_resolve *resolve, sd_resolve_query *q, void *userdata) {
         assert(q);
         assert(resolve);
         assert(q->resolve = resolve);
@@ -1121,7 +1121,7 @@ void sd_resolve_setuserdata(sd_resolve *resolve, sd_resolve_query *q, void *user
         q->userdata = userdata;
 }
 
-void* sd_resolve_getuserdata(sd_resolve *resolve, sd_resolve_query *q) {
+_public_ void* sd_resolve_getuserdata(sd_resolve *resolve, sd_resolve_query *q) {
         assert(q);
         assert(resolve);
         assert(q->resolve = resolve);

commit 127b55d5a49e8e534e12107fc5d5a684c390d7aa
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Sat Jan 18 14:30:28 2014 +0100

    sd-resolve: rename get_next() and get_n_queries() + cleanup

diff --git a/TODO b/TODO
index 91a7bda..a842158 100644
--- a/TODO
+++ b/TODO
@@ -38,7 +38,6 @@ Features:
   - maybe simplify function calls that take a sd_resolve_query object, to not also require the matching sd_resolve?
   - maybe drop the "n_proc" parameter to sd_resolve_new()?
   - change all functions to return "int" and negative errno errors
-  - getnext and getnqueries should be renamed to get_next() and get_n_queries(), i.e. functions that are not modelled directly after the libc counterparts don't need to be a single word...
 
 * New service property: maximum CPU and wallclock runtime for a service
 
diff --git a/src/libsystemd/sd-resolve.c b/src/libsystemd/sd-resolve.c
index 7cc8dc4..b6bf8d4 100644
--- a/src/libsystemd/sd-resolve.c
+++ b/src/libsystemd/sd-resolve.c
@@ -1043,12 +1043,12 @@ int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char
         return ret < 0 ? -errno : ret;
 }
 
-sd_resolve_query* sd_resolve_getnext(sd_resolve *resolve) {
+sd_resolve_query* sd_resolve_get_next(sd_resolve *resolve) {
         assert(resolve);
         return resolve->done_head;
 }
 
-int sd_resolve_getnqueries(sd_resolve *resolve) {
+int sd_resolve_get_n_queries(sd_resolve *resolve) {
         assert(resolve);
         return resolve->n_queries;
 }
diff --git a/src/systemd/sd-resolve.h b/src/systemd/sd-resolve.h
index 8df6152..2779db0 100644
--- a/src/systemd/sd-resolve.h
+++ b/src/systemd/sd-resolve.h
@@ -63,7 +63,7 @@ void sd_resolve_free(sd_resolve *resolve);
 int sd_resolve_fd(sd_resolve *resolve);
 
 /** Process pending responses. After this function is called you can
- * get the next completed query object(s) using sd_resolve_getnext(). If
+ * get the next completed query object(s) using sd_resolve_get_next(). If
  * block is non-zero wait until at least one response has been
  * processed. If block is zero, process all pending responses and
  * return. */
@@ -124,11 +124,11 @@ int sd_resolve_res_done(sd_resolve *resolve, sd_resolve_query* q, unsigned char
 /** Return the next completed query object. If no query has been
  * completed yet, return NULL. Please note that you need to run
  * sd_resolve_wait() before this function will return sensible data.  */
-sd_resolve_query* sd_resolve_getnext(sd_resolve *resolve);
+sd_resolve_query* sd_resolve_get_next(sd_resolve *resolve);
 
 /** Return the number of query objects (completed or not) attached to
  * this session */
-int sd_resolve_getnqueries(sd_resolve *resolve);
+int sd_resolve_get_n_queries(sd_resolve *resolve);
 
 /** Cancel a currently running query. q is is destroyed by this call
  * and may not be used any futher. */
@@ -139,9 +139,6 @@ void sd_resolve_cancel(sd_resolve *resolve, sd_resolve_query* q);
  * of the libc's freeaddrinfo()! */
 void sd_resolve_freeaddrinfo(struct addrinfo *ai);
 
-/** Free the answer data as returned by sd_resolve_res_done().*/
-void sd_resolve_freeanswer(unsigned char *answer);
-
 /** Returns non-zero when the query operation specified by q has been completed */
 int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q);
 

commit 885d1c80d991b7f9f8074c8d06f64dab1e53b7ad
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Sat Jan 18 14:30:27 2014 +0100

    sd-resolve: Allocate objects with new()

diff --git a/src/libsystemd/sd-resolve.c b/src/libsystemd/sd-resolve.c
index 6958aa9..7cc8dc4 100644
--- a/src/libsystemd/sd-resolve.c
+++ b/src/libsystemd/sd-resolve.c
@@ -423,7 +423,7 @@ sd_resolve* sd_resolve_new(unsigned n_proc) {
         if (n_proc > MAX_WORKERS)
                 n_proc = MAX_WORKERS;
 
-        resolve = malloc(sizeof(sd_resolve));
+        resolve = new(sd_resolve, 1);
         if (!resolve) {
                 errno = ENOMEM;
                 goto fail;
@@ -562,7 +562,7 @@ static const void *unserialize_addrinfo(const void *p, struct addrinfo **ret_ai,
         if (*length < l)
                 return NULL;
 
-        ai = malloc(sizeof(struct addrinfo));
+        ai = new(struct addrinfo, 1);
         if (!ai)
                 goto fail;
 
@@ -765,7 +765,7 @@ static sd_resolve_query *alloc_query(sd_resolve *resolve) {
                         resolve->current_index -= MAX_QUERIES;
         }
 
-        q = resolve->queries[resolve->current_index] = malloc(sizeof(sd_resolve_query));
+        q = resolve->queries[resolve->current_index] = new(sd_resolve_query, 1);
         if (!q) {
                 errno = ENOMEM;
                 return NULL;

commit 65883c9108cb2670a5458f0c2f49a5879f2a4ed9
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Sat Jan 18 14:30:26 2014 +0100

    sd-resolve: get rid of sd_resolve_freeanswer()

diff --git a/TODO b/TODO
index a567669..91a7bda 100644
--- a/TODO
+++ b/TODO
@@ -35,7 +35,6 @@ Features:
 * sd-resolve:
   - make sure event loop integration works similar to event loop integration in other libs
   - maybe drop _free() call, introduce _unref() instead
-  - sd_resolve_freeanswer() is probably pointless, we don't define such a function for any other return values, but expect people to call free directly
   - maybe simplify function calls that take a sd_resolve_query object, to not also require the matching sd_resolve?
   - maybe drop the "n_proc" parameter to sd_resolve_new()?
   - change all functions to return "int" and negative errno errors
diff --git a/src/libsystemd/resolve-util.h b/src/libsystemd/resolve-util.h
index 4310f88..58df738 100644
--- a/src/libsystemd/resolve-util.h
+++ b/src/libsystemd/resolve-util.h
@@ -24,8 +24,6 @@
 #include "util.h"
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(sd_resolve*, sd_resolve_free);
-DEFINE_TRIVIAL_CLEANUP_FUNC(unsigned char *, sd_resolve_freeanswer);
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct addrinfo*, sd_resolve_freeaddrinfo);
 #define _cleanup_resolve_free_ _cleanup_(sd_resolve_freep)
-#define _cleanup_resolve_answer_free_ _cleanup_(sd_resolve_freeanswerp)
 #define _cleanup_resolve_addrinfo_free_ _cleanup_(sd_resolve_freeaddrinfop)
diff --git a/src/libsystemd/sd-resolve.c b/src/libsystemd/sd-resolve.c
index a368c1b..6958aa9 100644
--- a/src/libsystemd/sd-resolve.c
+++ b/src/libsystemd/sd-resolve.c
@@ -1105,17 +1105,6 @@ void sd_resolve_freeaddrinfo(struct addrinfo *ai) {
         errno = saved_errno;
 }
 
-void sd_resolve_freeanswer(unsigned char *answer) {
-        int saved_errno = errno;
-
-        if (!answer)
-                return;
-
-        free(answer);
-
-        errno = saved_errno;
-}
-
 int sd_resolve_isdone(sd_resolve *resolve, sd_resolve_query*q) {
         assert(resolve);
         assert(q);
diff --git a/src/libsystemd/test-resolve.c b/src/libsystemd/test-resolve.c
index 7c1e7aa..3903e64 100644
--- a/src/libsystemd/test-resolve.c
+++ b/src/libsystemd/test-resolve.c
@@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
         int r = 1, ret;
         _cleanup_resolve_free_ sd_resolve *resolve = NULL;
         _cleanup_resolve_addrinfo_free_ struct addrinfo *ai = NULL;
-        _cleanup_resolve_answer_free_ unsigned char *srv = NULL;
+        _cleanup_free_ unsigned char *srv = NULL;
         sd_resolve_query *q1, *q2, *q3;
         struct addrinfo hints = {};
         struct sockaddr_in sa = {};

commit 039ebe6aebaebcaa18375b33caf1db5fe2551621
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Jan 18 15:47:57 2014 +0100

    sd-dhcp-client/networkd: add domainname support

diff --git a/src/libsystemd/sd-dhcp-client.c b/src/libsystemd/sd-dhcp-client.c
index 26ed35e..908f844 100644
--- a/src/libsystemd/sd-dhcp-client.c
+++ b/src/libsystemd/sd-dhcp-client.c
@@ -44,6 +44,7 @@ struct DHCPLease {
         struct in_addr *dns;
         size_t dns_size;
         uint16_t mtu;
+        char *domainname;
         char *hostname;
 };
 
@@ -237,6 +238,32 @@ int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t
         return 0;
 }
 
+int sd_dhcp_client_get_domainname(sd_dhcp_client *client, const char **domainname) {
+        assert_return(client, -EINVAL);
+        assert_return(domainname, -EINVAL);
+
+        switch (client->state) {
+        case DHCP_STATE_INIT:
+        case DHCP_STATE_SELECTING:
+        case DHCP_STATE_INIT_REBOOT:
+        case DHCP_STATE_REBOOTING:
+        case DHCP_STATE_REQUESTING:
+                return -EADDRNOTAVAIL;
+
+        case DHCP_STATE_BOUND:
+        case DHCP_STATE_RENEWING:
+        case DHCP_STATE_REBINDING:
+                if (client->lease->domainname)
+                        *domainname = client->lease->domainname;
+                else
+                        return -ENOENT;
+
+                break;
+        }
+
+        return 0;
+}
+
 int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname) {
         assert_return(client, -EINVAL);
         assert_return(hostname, -EINVAL);
@@ -336,6 +363,7 @@ static void lease_free(DHCPLease *lease) {
                 return;
 
         free(lease->hostname);
+        free(lease->domainname);
         free(lease->dns);
         free(lease);
 }
@@ -832,6 +860,14 @@ static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
 
                 break;
 
+        case DHCP_OPTION_DOMAIN_NAME:
+                if (len >= 1) {
+                        free(lease->domainname);
+                        lease->domainname = strndup((const char *)option, len);
+                }
+
+                break;
+
         case DHCP_OPTION_HOST_NAME:
                 if (len >= 1) {
                         free(lease->hostname);
diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf
index 7686cdf..abf6a30 100644
--- a/src/network/networkd-gperf.gperf
+++ b/src/network/networkd-gperf.gperf
@@ -33,5 +33,6 @@ Route.Destination,       config_parse_destination,      0,       0
 DHCPv4.UseDNS,           config_parse_bool,             0,       offsetof(Network, dhcp_dns)
 DHCPv4.UseMTU,           config_parse_bool,             0,       offsetof(Network, dhcp_mtu)
 DHCPv4.UseHostname,      config_parse_bool,             0,       offsetof(Network, dhcp_hostname)
+DHCPv4.UseDomainName,    config_parse_bool,             0,       offsetof(Network, dhcp_domainname)
 Bridge.Description,      config_parse_string,           0,       offsetof(Bridge, description)
 Bridge.Name,             config_parse_ifname,           0,       offsetof(Bridge, name)
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index c630ed7..5ab9ba0 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -325,6 +325,7 @@ int manager_update_resolv_conf(Manager *m) {
         Link *link;
         Iterator i;
         unsigned count = 0;
+        const char *domainname = NULL;
         int r;
 
         assert(m);
@@ -350,12 +351,20 @@ int manager_update_resolv_conf(Manager *m) {
                         struct in_addr *nameservers;
                         size_t nameservers_size;
 
-                        r = sd_dhcp_client_get_dns(link->dhcp, &nameservers, &nameservers_size);
-                        if (r >= 0) {
-                                unsigned j;
+                        if (link->network->dhcp_dns) {
+                                r = sd_dhcp_client_get_dns(link->dhcp, &nameservers, &nameservers_size);
+                                if (r >= 0) {
+                                        unsigned j;
 
-                                for (j = 0; j < nameservers_size; j++)
-                                        append_dns(f, &nameservers[j], AF_INET, &count);
+                                        for (j = 0; j < nameservers_size; j++)
+                                                append_dns(f, &nameservers[j], AF_INET, &count);
+                                }
+                        }
+
+                        if (link->network->dhcp_domainname && !domainname) {
+                                r = sd_dhcp_client_get_domainname(link->dhcp, &domainname);
+                                if (r >= 0)
+                                       fprintf(f, "domain %s\n", domainname);
                         }
                 }
         }
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index ff54423..b6b0c79 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -68,6 +68,7 @@ static int network_load_one(Manager *manager, const char *filename) {
         network->dhcp_dns = true;
         network->dhcp_mtu = true;
         network->dhcp_hostname = true;
+        network->dhcp_domainname = true;
 
         r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0DHCPv4\0", config_item_perf_lookup,
                         (void*) network_gperf_lookup, false, false, network);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 89f4cf2..c684eb8 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -89,6 +89,7 @@ struct Network {
         bool dhcp_dns;
         bool dhcp_mtu;
         bool dhcp_hostname;
+        bool dhcp_domainname;
 
         LIST_HEAD(Address, static_addresses);
         LIST_HEAD(Route, static_routes);
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index beb8642..937ed86 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -56,6 +56,7 @@ int sd_dhcp_client_prefixlen(const struct in_addr *addr);
 int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr);
 int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t *addr_size);
 int sd_dhcp_client_get_mtu(sd_dhcp_client *client, uint16_t *mtu);
+int sd_dhcp_client_get_domainname(sd_dhcp_client *client, const char **domainname);
 int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname);
 
 int sd_dhcp_client_stop(sd_dhcp_client *client);



More information about the systemd-commits mailing list