summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c26
-rw-r--r--src/net.c28
2 files changed, 32 insertions, 22 deletions
diff --git a/src/config.c b/src/config.c
index e8901f5..d7d0b06 100644
--- a/src/config.c
+++ b/src/config.c
@@ -76,7 +76,7 @@ static struct config core_config = {
/* Network */
{
"",
- { SA_INIT },
+ { {""} },
0
},
@@ -101,25 +101,27 @@ static int range_print(struct re_printf *pf, const struct range *rng)
static int dns_server_handler(const struct pl *pl, void *arg)
{
struct config_net *cfg = arg;
- struct sa sa;
+ const size_t max_count = ARRAY_SIZE(cfg->nsv);
int err;
- err = sa_decode(&sa, pl->p, pl->l);
- if (err) {
- warning("config: dns_server: could not decode `%r'\n", pl);
- return err;
- }
-
- if (cfg->nsc >= ARRAY_SIZE(cfg->nsv)) {
+ if (cfg->nsc >= max_count) {
warning("config: too many DNS nameservers (max %zu)\n",
- ARRAY_SIZE(cfg->nsv));
+ max_count);
return EOVERFLOW;
}
/* Append dns_server to the network config */
- cfg->nsv[cfg->nsc++] = sa;
+ err = pl_strcpy(pl, cfg->nsv[cfg->nsc].addr,
+ sizeof(cfg->nsv[0].addr));
+ if (err) {
+ warning("config: dns_server: could not copy string (%r)\n",
+ pl);
+ return err;
+ }
- return err;
+ ++cfg->nsc;
+
+ return 0;
}
diff --git a/src/net.c b/src/net.c
index 7c12580..2919dc3 100644
--- a/src/net.c
+++ b/src/net.c
@@ -8,9 +8,6 @@
#include "core.h"
-#define MAX_NS 8
-
-
struct network {
struct config_net cfg;
struct sa laddr;
@@ -21,7 +18,7 @@ struct network {
#endif
struct tmr tmr;
struct dnsc *dnsc;
- struct sa nsv[MAX_NS];/**< Configured name servers */
+ struct sa nsv[NET_MAX_NS];/**< Configured name servers */
uint32_t nsn; /**< Number of configured name servers */
uint32_t interval;
int af; /**< Preferred address family */
@@ -48,7 +45,7 @@ static int net_dnssrv_add(struct network *net, const struct sa *sa)
static int net_dns_srv_get(const struct network *net,
struct sa *srvv, uint32_t *n, bool *from_sys)
{
- struct sa nsv[MAX_NS];
+ struct sa nsv[NET_MAX_NS];
uint32_t i, nsn = ARRAY_SIZE(nsv);
int err;
@@ -94,7 +91,7 @@ static int net_dns_srv_get(const struct network *net,
*/
static void dns_refresh(struct network *net)
{
- struct sa nsv[MAX_NS];
+ struct sa nsv[NET_MAX_NS];
uint32_t nsn;
int err;
@@ -184,7 +181,7 @@ bool net_check(struct network *net)
static int dns_init(struct network *net)
{
- struct sa nsv[MAX_NS];
+ struct sa nsv[NET_MAX_NS];
uint32_t nsn = ARRAY_SIZE(nsv);
int err;
@@ -228,7 +225,7 @@ static void net_destructor(void *data)
int net_alloc(struct network **netp, const struct config_net *cfg, int af)
{
struct network *net;
- struct sa nsv[MAX_NS];
+ struct sa nsv[NET_MAX_NS];
uint32_t nsn = ARRAY_SIZE(nsv);
char buf4[128] = "", buf6[128] = "";
int err;
@@ -269,7 +266,18 @@ int net_alloc(struct network **netp, const struct config_net *cfg, int af)
for (i=0; i<cfg->nsc; i++) {
- err = net_dnssrv_add(net, &cfg->nsv[i]);
+ const char *ns = cfg->nsv[i].addr;
+ struct sa sa;
+
+ err = sa_decode(&sa, ns, str_len(ns));
+ if (err) {
+ warning("net: dns_server:"
+ " could not decode `%s' (%m)\n",
+ ns, err);
+ goto out;
+ }
+
+ err = net_dnssrv_add(net, &sa);
if (err) {
warning("net: failed to add nameserver: %m\n",
err);
@@ -429,7 +437,7 @@ void net_force_change(struct network *net)
static int dns_debug(struct re_printf *pf, const struct network *net)
{
- struct sa nsv[MAX_NS];
+ struct sa nsv[NET_MAX_NS];
uint32_t i, nsn = ARRAY_SIZE(nsv);
bool from_sys = false;
int err;