]> git.ozlabs.org Git - petitboot/commitdiff
config: DNS configuration isn't interface-specific
authorJeremy Kerr <jk@ozlabs.org>
Thu, 8 Aug 2013 06:21:00 +0000 (14:21 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 8 Aug 2013 08:28:39 +0000 (16:28 +0800)
Rather than attaching DNS configuration to an interface, separate it out
into general network config.

The powerpc-nvram storage exepects dns as a "dns,server,..." string.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/pb-config/pb-config.h
lib/pb-config/storage-powerpc-nvram.c
lib/pb-config/storage-test.c

index 748b409ada3c04a5ff85602c55b33fc53291685a..6a64ef116670030783e685350b82313f24add494 100644 (file)
@@ -19,7 +19,6 @@ struct interface_config {
                struct {
                        char *address;
                        char *gateway;
                struct {
                        char *address;
                        char *gateway;
-                       char *dns;
                } static_config;
        };
 };
                } static_config;
        };
 };
@@ -27,6 +26,8 @@ struct interface_config {
 struct network_config {
        struct interface_config **interfaces;
        int                     n_interfaces;
 struct network_config {
        struct interface_config **interfaces;
        int                     n_interfaces;
+       const char              **dns_servers;
+       int                     n_dns_servers;
 };
 
 struct config {
 };
 
 struct config {
index e6bf7df5544408900d5b1c24fc0f9d608a076798..734741e2cb08340ab9660745b10423a2725d6359 100644 (file)
@@ -243,7 +243,7 @@ static int parse_one_interface_config(struct config *config,
        } else if (!strcmp(tok, "static")) {
                ifconf->method = CONFIG_METHOD_STATIC;
 
        } else if (!strcmp(tok, "static")) {
                ifconf->method = CONFIG_METHOD_STATIC;
 
-               /* ip/mask, [optional] gateway, [optional] dns */
+               /* ip/mask, [optional] gateway */
                tok = strtok_r(NULL, ",", &saveptr);
                if (!tok)
                        goto out_err;
                tok = strtok_r(NULL, ",", &saveptr);
                if (!tok)
                        goto out_err;
@@ -254,13 +254,8 @@ static int parse_one_interface_config(struct config *config,
                if (tok) {
                        ifconf->static_config.gateway =
                                talloc_strdup(ifconf, tok);
                if (tok) {
                        ifconf->static_config.gateway =
                                talloc_strdup(ifconf, tok);
-                       tok = strtok_r(NULL, ",", &saveptr);
                }
 
                }
 
-               if (tok) {
-                       ifconf->static_config.dns =
-                               talloc_strdup(config, tok);
-               }
        } else {
                pb_log("Unknown network configuration method %s\n", tok);
                goto out_err;
        } else {
                pb_log("Unknown network configuration method %s\n", tok);
                goto out_err;
@@ -279,6 +274,27 @@ out_err:
        return -1;
 }
 
        return -1;
 }
 
+static int parse_one_dns_config(struct config *config,
+               char *confstr)
+{
+       char *tok, *saveptr;
+
+       for (tok = strtok_r(confstr, ",", &saveptr); tok;
+                       tok = strtok_r(NULL, ",", &saveptr)) {
+
+               char *server = talloc_strdup(config, tok);
+
+               config->network.dns_servers = talloc_realloc(config,
+                               config->network.dns_servers, const char *,
+                               ++config->network.n_dns_servers);
+
+               config->network.dns_servers[config->network.n_dns_servers - 1]
+                               = server;
+       }
+
+       return 0;
+}
+
 static void populate_network_config(struct powerpc_nvram_storage *nv,
                struct config *config)
 {
 static void populate_network_config(struct powerpc_nvram_storage *nv,
                struct config *config)
 {
@@ -299,7 +315,10 @@ static void populate_network_config(struct powerpc_nvram_storage *nv,
                if (!tok)
                        break;
 
                if (!tok)
                        break;
 
-               parse_one_interface_config(config, tok);
+               if (strncmp(tok, "dns,", strlen("dns,")))
+                       parse_one_dns_config(config, tok + strlen("dns,"));
+               else
+                       parse_one_interface_config(config, tok);
 
        }
 
 
        }
 
index bdb1d0dec2153c46d7c5a49f25dcdef13a7a6ad0..3114712b4825cb60625ac3d76640004e531fd2fa 100644 (file)
@@ -22,6 +22,7 @@ struct interface_config net2 = {
 };
 
 struct interface_config *interface_configs[] = { &net1, &net2 };
 };
 
 struct interface_config *interface_configs[] = { &net1, &net2 };
+const char *dns_servers[] = { "192.168.1.1", "192.168.1.2" };
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
@@ -30,6 +31,8 @@ struct config test_config = {
        .network = {
                .interfaces = interface_configs,
                .n_interfaces = ARRAY_SIZE(interface_configs),
        .network = {
                .interfaces = interface_configs,
                .n_interfaces = ARRAY_SIZE(interface_configs),
+               .dns_servers = dns_servers,
+               .n_dns_servers = ARRAY_SIZE(dns_servers),
        }
 };
 
        }
 };