chiark / gitweb /
sd-dhcp-client/networkd: add domainname support
authorTom Gundersen <teg@jklm.no>
Sat, 18 Jan 2014 14:47:57 +0000 (15:47 +0100)
committerTom Gundersen <teg@jklm.no>
Sat, 18 Jan 2014 16:52:10 +0000 (17:52 +0100)
src/libsystemd/sd-dhcp-client.c
src/network/networkd-gperf.gperf
src/network/networkd-manager.c
src/network/networkd-network.c
src/network/networkd.h
src/systemd/sd-dhcp-client.h

index 26ed35e5fec5502afff4527cdc05d132e7f057a1..908f844671df015dbf8837ba6751102b5307fcd8 100644 (file)
@@ -44,6 +44,7 @@ struct DHCPLease {
         struct in_addr *dns;
         size_t dns_size;
         uint16_t mtu;
         struct in_addr *dns;
         size_t dns_size;
         uint16_t mtu;
+        char *domainname;
         char *hostname;
 };
 
         char *hostname;
 };
 
@@ -237,6 +238,32 @@ int sd_dhcp_client_get_dns(sd_dhcp_client *client, struct in_addr **addr, size_t
         return 0;
 }
 
         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);
 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);
                 return;
 
         free(lease->hostname);
+        free(lease->domainname);
         free(lease->dns);
         free(lease);
 }
         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;
 
 
                 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);
         case DHCP_OPTION_HOST_NAME:
                 if (len >= 1) {
                         free(lease->hostname);
index 7686cdf3342e402ee38d299dcf4cc3471a357a77..abf6a30975366012804d5e510a1aeaa27ab40126 100644 (file)
@@ -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.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)
 Bridge.Description,      config_parse_string,           0,       offsetof(Bridge, description)
 Bridge.Name,             config_parse_ifname,           0,       offsetof(Bridge, name)
index c630ed7ed91aa6bae261a7ae5f3694a01aa5b4b6..5ab9ba0bafd09d240e104e44970383f382808bbf 100644 (file)
@@ -325,6 +325,7 @@ int manager_update_resolv_conf(Manager *m) {
         Link *link;
         Iterator i;
         unsigned count = 0;
         Link *link;
         Iterator i;
         unsigned count = 0;
+        const char *domainname = NULL;
         int r;
 
         assert(m);
         int r;
 
         assert(m);
@@ -350,12 +351,20 @@ int manager_update_resolv_conf(Manager *m) {
                         struct in_addr *nameservers;
                         size_t nameservers_size;
 
                         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);
                         }
                 }
         }
                         }
                 }
         }
index ff54423221788e31665a84b0e1f6180ca9e56fdd..b6b0c796d2387649a035460776562e46bd18852d 100644 (file)
@@ -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_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);
 
         r = config_parse(NULL, filename, file, "Match\0Network\0Address\0Route\0DHCPv4\0", config_item_perf_lookup,
                         (void*) network_gperf_lookup, false, false, network);
index 89f4cf24e796f7ec86361a993a43d13d419b1436..c684eb8a8f8e06b0cf1709524d82cd3f93398333 100644 (file)
@@ -89,6 +89,7 @@ struct Network {
         bool dhcp_dns;
         bool dhcp_mtu;
         bool dhcp_hostname;
         bool dhcp_dns;
         bool dhcp_mtu;
         bool dhcp_hostname;
+        bool dhcp_domainname;
 
         LIST_HEAD(Address, static_addresses);
         LIST_HEAD(Route, static_routes);
 
         LIST_HEAD(Address, static_addresses);
         LIST_HEAD(Route, static_routes);
index beb8642a898ae19110a9756898860fe0e0385d82..937ed86e8d216f8d912fa348b93cf81d052a82a8 100644 (file)
@@ -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_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);
 int sd_dhcp_client_get_hostname(sd_dhcp_client *client, const char **hostname);
 
 int sd_dhcp_client_stop(sd_dhcp_client *client);