summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-08-08 15:41:39 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-08-08 16:30:00 +0800
commit9b7a01a40fd9476583fb5f7dfbd4006e45d8e291 (patch)
treeae9182a4f668ad5344a7d35a10dccad2803969f3
parent6557f07325409d769f414035cca05a563418e729 (diff)
downloadpetitboot-9b7a01a40fd9476583fb5f7dfbd4006e45d8e291.zip
petitboot-9b7a01a40fd9476583fb5f7dfbd4006e45d8e291.tar.gz
network: handle DNS config
If we have a dns config option, update resolv.conf Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--discover/network.c57
-rw-r--r--lib/pb-config/pb-config.c4
-rw-r--r--lib/pb-config/storage-powerpc-nvram.c2
3 files changed, 61 insertions, 2 deletions
diff --git a/discover/network.c b/discover/network.c
index 910649e..3b01f9f 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <linux/netlink.h>
@@ -15,6 +16,7 @@
#include <pb-config/pb-config.h>
#include <system/system.h>
+#include "file.h"
#include "network.h"
#define HWADDR_SIZE 6
@@ -399,6 +401,59 @@ static int network_netlink_process(void *arg)
return 0;
}
+static void network_init_dns(struct network *network)
+{
+ const struct config *config;
+ int i, rc, len;
+ bool modified;
+ char *buf;
+
+ if (network->dry_run)
+ return;
+
+ config = config_get();
+ if (!config || !config->network.n_dns_servers)
+ return;
+
+ rc = read_file(network, "/etc/resolv.conf", &buf, &len);
+
+ if (rc) {
+ buf = talloc_strdup(network, "");
+ len = 0;
+ }
+
+ modified = false;
+
+ for (i = 0; i < config->network.n_dns_servers; i++) {
+ int dns_conf_len;
+ char *dns_conf;
+
+ dns_conf = talloc_asprintf(network, "server %s\n",
+ config->network.dns_servers[i]);
+
+ if (strstr(buf, dns_conf)) {
+ talloc_free(dns_conf);
+ continue;
+ }
+
+ dns_conf_len = strlen(dns_conf);
+ buf = talloc_realloc(network, buf, char, len + dns_conf_len);
+ memcpy(buf + len, dns_conf, dns_conf_len);
+ len += dns_conf_len;
+ modified = true;
+ }
+
+ if (!modified)
+ return;
+
+ rc = replace_file("/etc/resolv.conf", buf, len);
+ if (rc) {
+ pb_log("error replacing resolv.conf: %s\n", strerror(errno));
+ return;
+ }
+
+}
+
struct network *network_init(void *ctx, struct waitset *waitset, bool dry_run)
{
struct network *network;
@@ -409,6 +464,8 @@ struct network *network_init(void *ctx, struct waitset *waitset, bool dry_run)
network->manual_config = false;
network->dry_run = dry_run;
+ network_init_dns(network);
+
rc = network_init_netlink(network);
if (rc)
goto err;
diff --git a/lib/pb-config/pb-config.c b/lib/pb-config/pb-config.c
index 5cd303b..315d990 100644
--- a/lib/pb-config/pb-config.c
+++ b/lib/pb-config/pb-config.c
@@ -26,7 +26,7 @@ static void dump_config(struct config *config)
pb_log(" autoboot: %s\n",
config->autoboot_enabled ? "enabled" : "disabled");
- if (config->n_network_configs > 0)
+ if (config->network.n_interfaces || config->network.n_dns_servers)
pb_log(" network configuration:\n");
for (i = 0; i < config->network.n_interfaces; i++) {
@@ -53,6 +53,8 @@ static void dump_config(struct config *config)
}
}
+ for (i = 0; i < config->network.n_dns_servers; i++)
+ pb_log(" dns server %s\n", config->network.dns_servers[i]);
}
int config_init(void *ctx)
diff --git a/lib/pb-config/storage-powerpc-nvram.c b/lib/pb-config/storage-powerpc-nvram.c
index 734741e..3ed3c46 100644
--- a/lib/pb-config/storage-powerpc-nvram.c
+++ b/lib/pb-config/storage-powerpc-nvram.c
@@ -315,7 +315,7 @@ static void populate_network_config(struct powerpc_nvram_storage *nv,
if (!tok)
break;
- if (strncmp(tok, "dns,", strlen("dns,")))
+ if (!strncasecmp(tok, "dns,", strlen("dns,")))
parse_one_dns_config(config, tok + strlen("dns,"));
else
parse_one_interface_config(config, tok);
OpenPOWER on IntegriCloud