Browse Source

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.
OPENBSD_3_6
henning 20 years ago
parent
commit
6fe4af12fd
3 changed files with 40 additions and 13 deletions
  1. +2
    -2
      src/usr.sbin/ntpd/client.c
  2. +8
    -2
      src/usr.sbin/ntpd/ntpd.h
  3. +30
    -9
      src/usr.sbin/ntpd/parse.y

+ 2
- 2
src/usr.sbin/ntpd/client.c View File

@ -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> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -74,7 +74,7 @@ client_nextaddr(struct ntp_peer *p)
close(p->query->fd); close(p->query->fd);
if ((p->addr = p->addr->next) == NULL) 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) if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
fatal("client_query socket"); fatal("client_query socket");


+ 8
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -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> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -68,6 +68,12 @@ struct ntp_addr {
struct sockaddr_storage ss; struct sockaddr_storage ss;
}; };
struct ntp_addr_wrap {
char *name;
u_int8_t pool;
struct ntp_addr *a;
};
struct ntp_status { struct ntp_status {
u_int8_t leap; u_int8_t leap;
int8_t precision; int8_t precision;
@ -89,7 +95,7 @@ struct ntp_offset {
struct ntp_peer { struct ntp_peer {
TAILQ_ENTRY(ntp_peer) entry; TAILQ_ENTRY(ntp_peer) entry;
struct ntp_addr *addr_head;
struct ntp_addr_wrap addr_head;
struct ntp_addr *addr; struct ntp_addr *addr;
struct ntp_query *query; struct ntp_query *query;
enum client_state state; enum client_state state;


+ 30
- 9
src/usr.sbin/ntpd/parse.y View File

@ -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> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -68,7 +68,7 @@ typedef struct {
union { union {
u_int32_t number; u_int32_t number;
char *string; char *string;
struct ntp_addr *addr;
struct ntp_addr_wrap *addr;
} v; } v;
int lineno; int lineno;
} YYSTYPE; } YYSTYPE;
@ -127,7 +127,7 @@ conf_main : LISTEN ON address {
struct listen_addr *la; struct listen_addr *la;
struct ntp_addr *h, *next; struct ntp_addr *h, *next;
for (h = $3; h != NULL; h = next) {
for (h = $3->a; h != NULL; h = next) {
next = h->next; next = h->next;
if (h->ss.ss_family == AF_UNSPEC) { if (h->ss.ss_family == AF_UNSPEC) {
conf->listen_all = 1; conf->listen_all = 1;
@ -144,17 +144,21 @@ conf_main : LISTEN ON address {
entry); entry);
free(h); free(h);
} }
free($3->name);
free($3);
} }
| SERVERS address { | SERVERS address {
struct ntp_peer *p; struct ntp_peer *p;
struct ntp_addr *h, *next; struct ntp_addr *h, *next;
for (h = $2; h != NULL; h = next) {
for (h = $2->a; h != NULL; h = next) {
next = h->next; next = h->next;
if (h->ss.ss_family != AF_INET && if (h->ss.ss_family != AF_INET &&
h->ss.ss_family != AF_INET6) { h->ss.ss_family != AF_INET6) {
yyerror("IPv4 or IPv6 address " yyerror("IPv4 or IPv6 address "
"or hostname expected"); "or hostname expected");
free($2->name);
free($2);
YYERROR; YYERROR;
} }
p = calloc(1, sizeof(struct ntp_peer)); p = calloc(1, sizeof(struct ntp_peer));
@ -162,8 +166,14 @@ conf_main : LISTEN ON address {
fatal("conf_main server calloc"); fatal("conf_main server calloc");
h->next = NULL; h->next = NULL;
p->addr = h; 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); TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
free($2->name);
free($2);
} }
} }
| SERVER address { | SERVER address {
@ -172,31 +182,42 @@ conf_main : LISTEN ON address {
if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL) if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
fatal("conf_main server calloc"); fatal("conf_main server calloc");
for (h = $2; h != NULL; h = next) {
for (h = $2->a; h != NULL; h = next) {
next = h->next; next = h->next;
if (h->ss.ss_family != AF_INET && if (h->ss.ss_family != AF_INET &&
h->ss.ss_family != AF_INET6) { h->ss.ss_family != AF_INET6) {
yyerror("IPv4 or IPv6 address " yyerror("IPv4 or IPv6 address "
"or hostname expected"); "or hostname expected");
free($2->name);
free($2);
YYERROR; YYERROR;
} }
h->next = p->addr; h->next = p->addr;
p->addr = h; 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); TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
free($2->name);
free($2);
} }
; ;
address : STRING { 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\"", yyerror("could not parse address spec \"%s\"",
$1); $1);
free($1); free($1);
YYERROR; YYERROR;
} }
free($1);
$$->name = $1;
} }
; ;


Loading…
Cancel
Save