diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-08-08 14:21:00 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-08-08 16:28:39 +0800 |
commit | f53d1e4dc6735b90806ceed54f9d73572b5960f5 (patch) | |
tree | e90000c8c788ebe0599dea91ffc87632abce06f1 | |
parent | 2b41985dde73e71daad90c36fa5d06c199da3ae1 (diff) | |
download | petitboot-f53d1e4dc6735b90806ceed54f9d73572b5960f5.zip petitboot-f53d1e4dc6735b90806ceed54f9d73572b5960f5.tar.gz |
config: DNS configuration isn't interface-specific
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>
-rw-r--r-- | lib/pb-config/pb-config.h | 3 | ||||
-rw-r--r-- | lib/pb-config/storage-powerpc-nvram.c | 33 | ||||
-rw-r--r-- | lib/pb-config/storage-test.c | 3 |
3 files changed, 31 insertions, 8 deletions
diff --git a/lib/pb-config/pb-config.h b/lib/pb-config/pb-config.h index 748b409..6a64ef1 100644 --- a/lib/pb-config/pb-config.h +++ b/lib/pb-config/pb-config.h @@ -19,7 +19,6 @@ struct interface_config { struct { char *address; char *gateway; - char *dns; } static_config; }; }; @@ -27,6 +26,8 @@ struct interface_config { struct network_config { struct interface_config **interfaces; int n_interfaces; + const char **dns_servers; + int n_dns_servers; }; struct config { diff --git a/lib/pb-config/storage-powerpc-nvram.c b/lib/pb-config/storage-powerpc-nvram.c index e6bf7df..734741e 100644 --- a/lib/pb-config/storage-powerpc-nvram.c +++ b/lib/pb-config/storage-powerpc-nvram.c @@ -243,7 +243,7 @@ static int parse_one_interface_config(struct config *config, } 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; @@ -254,13 +254,8 @@ static int parse_one_interface_config(struct config *config, 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; @@ -279,6 +274,27 @@ out_err: 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) { @@ -299,7 +315,10 @@ static void populate_network_config(struct powerpc_nvram_storage *nv, 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); } diff --git a/lib/pb-config/storage-test.c b/lib/pb-config/storage-test.c index bdb1d0d..3114712 100644 --- a/lib/pb-config/storage-test.c +++ b/lib/pb-config/storage-test.c @@ -22,6 +22,7 @@ struct interface_config 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])) @@ -30,6 +31,8 @@ struct config test_config = { .network = { .interfaces = interface_configs, .n_interfaces = ARRAY_SIZE(interface_configs), + .dns_servers = dns_servers, + .n_dns_servers = ARRAY_SIZE(dns_servers), } }; |