#include <event2/util.h>
#include <event2/event.h>
-#if 0
-// Might need:
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#endif
-
int n_pending_dns = 0;
int n_pending_ntp = 0;
int ai_fam_pref = AF_UNSPEC;
SOCKET sock6 = -1; /* Socket for IPv6 */
char *progname;
struct event_base *base = NULL;
+struct evdns_base *dnsbase = NULL;
struct dns_ctx {
const char * name;
#define r_pkt rbuf.pkt
+void handle_lookup( char *name, int flags );
void dns_cb (int errcode, struct evutil_addrinfo *addr, void *ptr);
void ntp_cb (evutil_socket_t, short, void *);
void set_li_vn_mode (struct pkt *spkt, char leap, char version, char mode);
{
int i;
int optct;
- /* boolean, u_int quiets gcc4 signed overflow warning */
- // struct addrinfo *ai;
- struct evdns_base *dnsbase;
long l;
progname = argv[0];
/* IPv6 available? */
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
ai_fam_pref = AF_INET;
-#ifdef DEBUG
- printf("No ipv6 support available, forcing ipv4\n");
-#endif
+ DPRINTF(1, ("No ipv6 support available, forcing ipv4\n"));
} else {
/* Check for options -4 and -6 */
if (HAVE_OPT(IPV4))
ai_fam_pref = AF_INET6;
}
- /* Parse config file if declared TODO */
+ /* TODO: Parse config file if declared */
/*
- ** If there's a specified KOD file init KOD system. If not use
- ** default file. For embedded systems with no writable filesystem,
+ ** Init the KOD system.
+ ** For embedded systems with no writable filesystem,
** -K /dev/null can be used to disable KoD storage.
*/
- if (HAVE_OPT(KOD))
- kod_init_kod_db(OPT_ARG(KOD));
- else
- kod_init_kod_db("/var/db/ntp-kod");
+ kod_init_kod_db(OPT_ARG(KOD));
+ // HMS: Should we use arg-defalt for this too?
if (HAVE_OPT(KEYFILE))
auth_init(OPT_ARG(KEYFILE), &keys);
-#ifdef EXERCISE_KOD_DB
- add_entry("192.168.169.170", "DENY");
- add_entry("192.168.169.171", "DENY");
- add_entry("192.168.169.172", "DENY");
- add_entry("192.168.169.173", "DENY");
- add_entry("192.168.169.174", "DENY");
- delete_entry("192.168.169.174", "DENY");
- delete_entry("192.168.169.172", "DENY");
- delete_entry("192.168.169.170", "DENY");
- if ((kodc = search_entry("192.168.169.173", &reason)) == 0)
- printf("entry for 192.168.169.173 not found but should have been!\n");
- else
- free(reason);
-#endif
-
/*
** Considering employing a variable that prevents functions of doing
** anything until everything is initialized properly
return -1;
}
- if (ENABLED_OPT(BROADCAST)) {
- struct evutil_addrinfo hints;
- struct dns_ctx *dns_ctx;
-
- ZERO(hints);
- hints.ai_family = ai_fam_pref;
- hints.ai_flags |= EVUTIL_AI_CANONNAME;
- hints.ai_flags |= EVUTIL_AI_NUMERICSERV;
- /*
- ** Unless we specify a socktype, we'll get at least two
- ** entries for each address: one for TCP and one for
- ** UDP. That's not what we want.
- */
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- dns_ctx = emalloc(sizeof(*dns_ctx));
- memset(dns_ctx, 0, sizeof(*dns_ctx));
-
- dns_ctx->name = OPT_ARG(BROADCAST);
- dns_ctx->flags = CTX_BCST;
- dns_ctx->timeout = timeout_tv;
-
- if (ENABLED_OPT(AUTHENTICATION) &&
- atoint(OPT_ARG(AUTHENTICATION), &l)) {
- dns_ctx->key_id = l;
- get_key(dns_ctx->key_id, &dns_ctx->key);
- } else {
- dns_ctx->key_id = -1;
- dns_ctx->key = NULL;
- }
+ if (HAVE_OPT(BROADCAST)) {
+ int cn = STACKCT_OPT( BROADCAST );
+ const char ** cp = STACKLST_OPT( BROADCAST );
- printf("broadcast-before: <%s> n_pending_dns = %d\n", OPT_ARG(BROADCAST), n_pending_dns);
- ++n_pending_dns;
- evdns_getaddrinfo(dnsbase, OPT_ARG(BROADCAST), "123", &hints,
- dns_cb, dns_ctx);
- printf("broadcast-after: <%s> n_pending_dns = %d\n", OPT_ARG(BROADCAST), n_pending_dns);
+ while (cn-- > 0) {
+ handle_lookup(*cp, CTX_BCST);
+ cp++;
+ }
}
if (HAVE_OPT(CONCURRENT)) {
const char ** cp = STACKLST_OPT( CONCURRENT );
while (cn-- > 0) {
- /* Do something with *cp++ */
- printf("Concurrent: <%s>\n", *cp++);
+ handle_lookup(*cp, CTX_UCST|CTX_CONC);
+ cp++;
}
}
for (i = 0; i < argc; ++i) {
- struct evutil_addrinfo hints; /* local copy is OK */
- struct dns_ctx *dns_ctx;
-
- ZERO(hints);
- hints.ai_family = ai_fam_pref;
- hints.ai_flags |= EVUTIL_AI_CANONNAME;
- hints.ai_flags |= EVUTIL_AI_NUMERICSERV;
- /*
- ** Unless we specify a socktype, we'll get at least two
- ** entries for each address: one for TCP and one for
- ** UDP. That's not what we want.
- */
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- dns_ctx = emalloc(sizeof(*dns_ctx));
- memset(dns_ctx, 0, sizeof(*dns_ctx));
-
- dns_ctx->name = argv[i];
- dns_ctx->flags = CTX_UCST;
- dns_ctx->timeout = ucst_timeout_tv;
-
- if (ENABLED_OPT(AUTHENTICATION) &&
- atoint(OPT_ARG(AUTHENTICATION), &l)) {
- dns_ctx->key_id = l;
- get_key(dns_ctx->key_id, &dns_ctx->key);
- } else {
- dns_ctx->key_id = -1;
- dns_ctx->key = NULL;
- }
-
- // printf("unicast-before: <%s> n_pending_dns = %d\n", argv[i], n_pending_dns);
- ++n_pending_dns;
- evdns_getaddrinfo(dnsbase, argv[i], "123", &hints,
- dns_cb, dns_ctx);
- // printf("unicast-after: <%s> n_pending_dns = %d\n", argv[i], n_pending_dns);
+ handle_lookup(argv[i], CTX_UCST);
}
- // printf("unicast: n_pending_dns = %d\n", n_pending_dns);
-
event_base_dispatch(base);
evdns_base_free(dnsbase, 0);
}
+/*
+** handle_lookup
+*/
+void
+handle_lookup(
+ char *name,
+ int flags
+ )
+{
+ struct evutil_addrinfo hints; /* Local copy is OK */
+ struct dns_ctx *dns_ctx;
+ long l;
+
+ DPRINTF(1, ("handle_lookup(%s,%#x)\n", name, flags));
+
+ ZERO(hints);
+ hints.ai_family = ai_fam_pref;
+ hints.ai_flags |= EVUTIL_AI_CANONNAME;
+ hints.ai_flags |= EVUTIL_AI_NUMERICSERV;
+ /*
+ ** Unless we specify a socktype, we'll get at least two
+ ** entries for each address: one for TCP and one for
+ ** UDP. That's not what we want.
+ */
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+
+ dns_ctx = emalloc(sizeof(*dns_ctx));
+ memset(dns_ctx, 0, sizeof(*dns_ctx));
+
+ dns_ctx->name = OPT_ARG(BROADCAST);
+ dns_ctx->flags = flags;
+ dns_ctx->timeout =
+ (flags & CTX_BCST)
+ ? timeout_tv
+ : ucst_timeout_tv
+ ;
+
+ // The following should arguably be passed in...
+ if (ENABLED_OPT(AUTHENTICATION) &&
+ atoint(OPT_ARG(AUTHENTICATION), &l)) {
+ dns_ctx->key_id = l;
+ get_key(dns_ctx->key_id, &dns_ctx->key);
+ } else {
+ dns_ctx->key_id = -1;
+ dns_ctx->key = NULL;
+ }
+
+ ++n_pending_dns;
+ evdns_getaddrinfo(dnsbase, name, "123", &hints, dns_cb, dns_ctx);
+}
+
+
/*
** DNS Callback:
** - For each IP:
/*
* EDIT THIS FILE WITH CAUTION (sntp-opts.c)
*
- * It has been AutoGen-ed January 10, 2011 at 11:23:51 PM by AutoGen 5.11.6pre7
+ * It has been AutoGen-ed January 11, 2011 at 01:30:03 AM by AutoGen 5.11.6pre7
* From the definitions sntp-opts.def
* and the template file options
*
"KoD history filename";
static char const zKod_NAME[] = "KOD";
static char const zKod_Name[] = "kod";
+static char const zKodDefaultArg[] = "/var/db/ntp-kod";
#define KOD_FLAGS (OPTST_DISABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_FILE))
"Use broadcasts to the address specified for synchronisation";
static char const zBroadcast_NAME[] = "BROADCAST";
static char const zBroadcast_Name[] = "broadcast";
-#define BROADCAST_FLAGS (OPTST_DISABLED \
+#define BROADCAST_FLAGS (OPTST_DISABLED | OPTST_STACKED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ KOD_FLAGS, 0,
- /* last opt argumnt */ { NULL },
+ /* last opt argumnt */ { zKodDefaultArg },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ doOptKod,
{ /* entry idx, value */ 11, VALUE_OPT_BROADCAST,
/* equiv idx, value */ 11, VALUE_OPT_BROADCAST,
/* equivalenced to */ NO_EQUIVALENT,
- /* min, max, act ct */ 0, 1, 0,
+ /* min, max, act ct */ 0, NOLIMIT, 0,
/* opt state flags */ BROADCAST_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
- /* option proc */ NULL,
+ /* option proc */ optionStackArg,
/* desc, NAME, name */ zBroadcastText, zBroadcast_NAME, zBroadcast_Name,
/* disablement strs */ NULL, NULL },