summaryrefslogtreecommitdiff
path: root/usr.sbin/ntpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-07-20 16:47:56 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-07-20 16:47:56 +0000
commitc0994a25cb3e771d8ee589fb60bf9f35815eda76 (patch)
treee56a89f7c7f952b98dbafe0c9c2573265e1e176c /usr.sbin/ntpd
parent95c633c4f926f9a795d048bc6e68b877e88ce1e9 (diff)
wrap the heads for the linked list of addresses into a new ntp_addr_wrap
which, besides the head pointer for the list of course, stores the original address as specified (i. e. as hostname instead of resolved IPs) and flags and such.
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r--usr.sbin/ntpd/client.c4
-rw-r--r--usr.sbin/ntpd/ntpd.h10
-rw-r--r--usr.sbin/ntpd/parse.y39
3 files changed, 40 insertions, 13 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index e99ff71ecaf..de993cee523 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.27 2004/07/18 13:26:53 henning Exp $ */
+/* $OpenBSD: client.c,v 1.28 2004/07/20 16:47:55 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -74,7 +74,7 @@ client_nextaddr(struct ntp_peer *p)
close(p->query->fd);
if ((p->addr = p->addr->next) == NULL)
- p->addr = p->addr_head;
+ p->addr = p->addr_head.a;
if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
fatal("client_query socket");
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 7b05aa07832..5d13c278e7e 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.27 2004/07/18 12:59:41 henning Exp $ */
+/* $OpenBSD: ntpd.h,v 1.28 2004/07/20 16:47:55 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -68,6 +68,12 @@ struct ntp_addr {
struct sockaddr_storage ss;
};
+struct ntp_addr_wrap {
+ char *name;
+ u_int8_t pool;
+ struct ntp_addr *a;
+};
+
struct ntp_status {
u_int8_t leap;
int8_t precision;
@@ -89,7 +95,7 @@ struct ntp_offset {
struct ntp_peer {
TAILQ_ENTRY(ntp_peer) entry;
- struct ntp_addr *addr_head;
+ struct ntp_addr_wrap addr_head;
struct ntp_addr *addr;
struct ntp_query *query;
enum client_state state;
diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y
index 5599202e012..43d36efeb04 100644
--- a/usr.sbin/ntpd/parse.y
+++ b/usr.sbin/ntpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.12 2004/07/12 09:22:38 dtucker Exp $ */
+/* $OpenBSD: parse.y,v 1.13 2004/07/20 16:47:55 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -68,7 +68,7 @@ typedef struct {
union {
u_int32_t number;
char *string;
- struct ntp_addr *addr;
+ struct ntp_addr_wrap *addr;
} v;
int lineno;
} YYSTYPE;
@@ -127,7 +127,7 @@ conf_main : LISTEN ON address {
struct listen_addr *la;
struct ntp_addr *h, *next;
- for (h = $3; h != NULL; h = next) {
+ for (h = $3->a; h != NULL; h = next) {
next = h->next;
if (h->ss.ss_family == AF_UNSPEC) {
conf->listen_all = 1;
@@ -144,17 +144,21 @@ conf_main : LISTEN ON address {
entry);
free(h);
}
+ free($3->name);
+ free($3);
}
| SERVERS address {
struct ntp_peer *p;
struct ntp_addr *h, *next;
- for (h = $2; h != NULL; h = next) {
+ for (h = $2->a; h != NULL; h = next) {
next = h->next;
if (h->ss.ss_family != AF_INET &&
h->ss.ss_family != AF_INET6) {
yyerror("IPv4 or IPv6 address "
"or hostname expected");
+ free($2->name);
+ free($2);
YYERROR;
}
p = calloc(1, sizeof(struct ntp_peer));
@@ -162,8 +166,14 @@ conf_main : LISTEN ON address {
fatal("conf_main server calloc");
h->next = NULL;
p->addr = h;
- p->addr_head = h;
+ p->addr_head.a = h;
+ p->addr_head.pool = 1;
+ p->addr_head.name = strdup($2->name);
+ if (p->addr_head.name == NULL)
+ fatal(NULL);
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
+ free($2->name);
+ free($2);
}
}
| SERVER address {
@@ -172,31 +182,42 @@ conf_main : LISTEN ON address {
if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
fatal("conf_main server calloc");
- for (h = $2; h != NULL; h = next) {
+ for (h = $2->a; h != NULL; h = next) {
next = h->next;
if (h->ss.ss_family != AF_INET &&
h->ss.ss_family != AF_INET6) {
yyerror("IPv4 or IPv6 address "
"or hostname expected");
+ free($2->name);
+ free($2);
YYERROR;
}
h->next = p->addr;
p->addr = h;
}
- p->addr_head = p->addr;
+ p->addr_head.a = p->addr;
+ p->addr_head.pool = 0;
+ p->addr_head.name = strdup($2->name);
+ if (p->addr_head.name == NULL)
+ fatal(NULL);
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
+ free($2->name);
+ free($2);
}
;
address : STRING {
- if (($$ = host($1)) == NULL) {
+ if (($$ = calloc(1, sizeof(struct ntp_addr_wrap))) ==
+ NULL)
+ fatal(NULL);
+ if (($$->a = host($1)) == NULL) {
yyerror("could not parse address spec \"%s\"",
$1);
free($1);
YYERROR;
}
- free($1);
+ $$->name = $1;
}
;