]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
cleanup
authorHarlan Stenn <stenn@ntp.org>
Tue, 11 Jan 2011 01:32:44 +0000 (01:32 +0000)
committerHarlan Stenn <stenn@ntp.org>
Tue, 11 Jan 2011 01:32:44 +0000 (01:32 +0000)
bk: 4d2bb33cvg1U7fvacKPejET1AIoj5w

sntp/main.c
sntp/sntp-opts.c
sntp/sntp-opts.def
sntp/sntp-opts.h
sntp/sntp-opts.texi
sntp/sntp.1
sntp/sntp.html

index 058621fc714fccd8c4e4d8593d813016fd0f5072..a3d59e002751f899b0297135c6fde23de88cbfd4 100644 (file)
 #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;
@@ -25,6 +18,7 @@ SOCKET sock4 = -1;            /* Socket for IPv4 */
 SOCKET sock6 = -1;             /* Socket for IPv6 */
 char *progname;
 struct event_base *base = NULL;
+struct evdns_base *dnsbase = NULL;
 
 struct dns_ctx {
        const char *    name;
@@ -56,6 +50,7 @@ static union {
 
 #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);
@@ -87,9 +82,6 @@ sntp_main (
 {
        int i;
        int optct;
-       /* boolean, u_int quiets gcc4 signed overflow warning */
-       // struct addrinfo *ai;
-       struct evdns_base *dnsbase;
        long l;
 
        progname = argv[0];
@@ -122,9 +114,7 @@ sntp_main (
        /* 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))
@@ -133,36 +123,19 @@ sntp_main (
                        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
@@ -182,43 +155,14 @@ sntp_main (
                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)) {
@@ -226,52 +170,15 @@ sntp_main (
                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);
@@ -281,6 +188,59 @@ sntp_main (
 }
 
 
+/*
+** 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:
index aaad1e7b504424dd0c0b1cb438fe6e2ea7c11bee..aa455ec3909661adc3e0bdc1129291c0a58dabd9 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  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
  *
@@ -116,6 +116,7 @@ static char const zKodText[] =
         "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))
 
@@ -206,7 +207,7 @@ static char const zBroadcastText[] =
         "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))
 
 /*
@@ -370,7 +371,7 @@ static tOptDesc optDesc[ OPTION_CT ] = {
      /* 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,
@@ -452,12 +453,12 @@ static tOptDesc optDesc[ OPTION_CT ] = {
   {  /* 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 },
 
index 0c724ee8f3d973fc0b2e5fed231d0c7196b9e570..c58792234854b21f4ae91d09ff878d062e1c9811 100644 (file)
@@ -55,6 +55,7 @@ flag = {
     value     = K;
     arg-type  = file;
     arg-name  = "file-name";
+    arg-default = "/var/db/ntp-kod";
     descrip   = "KoD history filename";
     doc = <<-  _EndOfDoc_
        Specifies the filename to be used for the  persistent history of KoD
@@ -143,6 +144,8 @@ flag = {
        descrip = "Use broadcasts to the address specified for synchronisation";
        arg-type = string;
        arg-name = "broadcast-address";
+       max      = NOLIMIT;
+       stack-arg;
        doc     = <<-  _EndOfDoc_
        If specified SNTP will listen to the specified broadcast address
        for NTP broadcasts.  The default maximum wait time,
index 7d943173222e0d32804dbd31f70dfebd460ce6ed..06f9a04a0181883be1c5133e2c2af7b1335cd76d 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  EDIT THIS FILE WITH CAUTION  (sntp-opts.h)
  *  
- *  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:02 AM by AutoGen 5.11.6pre7
  *  From the definitions    sntp-opts.def
  *  and the template file   options
  *
index aa0439201bdf10ed6561e5ca0afe6732814bbdee..2a4946cd479960abe0f42ad848f4855e2ae12ce4 100644 (file)
@@ -6,7 +6,7 @@
 # 
 # EDIT THIS FILE WITH CAUTION  (sntp-opts.texi)
 # 
-# It has been AutoGen-ed  January 10, 2011 at 11:23:56 PM by AutoGen 5.11.6pre7
+# It has been AutoGen-ed  January 11, 2011 at 01:30:08 AM by AutoGen 5.11.6pre7
 # From the definitions    sntp-opts.def
 # and the template file   aginfo.tpl
 @end ignore
@@ -108,6 +108,7 @@ USAGE:  sntp [ -<flag> [<val>] | --<name>[@{=| @}<val>] ]... \
    -c Str concurrent     Send concurrent queries to all IPs returned for host-name
                                 - may appear multiple times
    -b Str broadcast      Use broadcasts to the address specified for synchronisation
+                                - may appear multiple times
    -t Num timeout        Specify the number of seconds to wait for broadcasts
    -a Num authentication Enable authentication with the key auth-keynumber
    -k Fil keyfile        Specify a keyfile. SNTP will look in this file for the key specified with -a
@@ -171,6 +172,13 @@ key's identifier. See the keyfile option (-k) for more details.
 @cindex sntp-broadcast
 
 This is the ``use broadcasts to the address specified for synchronisation'' option.
+
+This option has some usage constraints.  It:
+@itemize @bullet
+@item
+may appear an unlimited number of times.
+@end itemize
+
 If specified SNTP will listen to the specified broadcast address
 for NTP broadcasts.  The default maximum wait time,
 68 seconds, can be modified with -t.
index bda755c027a2bc4c4fa8c92a2f5755daba232555..82858a3f36a7f2f8ed327ac1722806ca79124956 100644 (file)
@@ -1,7 +1,7 @@
-.TH SNTP 1 2011-01-10 "( 4.2.7p114)" "Programmer's Manual"
+.TH SNTP 1 2011-01-11 "( 4.2.7p114)" "Programmer's Manual"
 .\"  EDIT THIS FILE WITH CAUTION  (sntp.1)
 .\"  
-.\"  It has been AutoGen-ed  January 10, 2011 at 11:23:55 PM by AutoGen 5.11.6pre7
+.\"  It has been AutoGen-ed  January 11, 2011 at 01:30:07 AM by AutoGen 5.11.6pre7
 .\"  From the definitions    sntp-opts.def
 .\"  and the template file   agman1.tpl
 .\"
@@ -78,6 +78,9 @@ to the IPv6 namespace.
 .TP
 .BR \-K " \fIfile-name\fP, " \--kod "=" \fIfile-name\fP
 KoD history filename.
+The default \fIfile-name\fP for this option is:
+.ti +4
+ /var/db/ntp-kod
 .sp
 Specifies the filename to be used for the  persistent history of KoD
 responses received from servers.  The default is
@@ -136,6 +139,7 @@ so we can send concurrent queries.
 .TP
 .BR \-b " \fIbroadcast-address\fP, " \--broadcast "=" \fIbroadcast-address\fP
 Use broadcasts to the address specified for synchronisation.
+This option may appear an unlimited number of times.
 .sp
 If specified SNTP will listen to the specified broadcast address
 for NTP broadcasts.  The default maximum wait time,
index 83a59243e1722f823d9553f4e5e5672af4d797b0..b7435aca34ec5b14f159859a3449c7631b74b7bf 100644 (file)
@@ -183,6 +183,7 @@ USAGE:  sntp [ -&lt;flag&gt; [&lt;val&gt;] | --&lt;name&gt;[{=| }&lt;val&gt;] ].
    -c Str concurrent     Send concurrent queries to all IPs returned for host-name
                                 - may appear multiple times
    -b Str broadcast      Use broadcasts to the address specified for synchronisation
+                                - may appear multiple times
    -t Num timeout        Specify the number of seconds to wait for broadcasts
    -a Num authentication Enable authentication with the key auth-keynumber
    -k Fil keyfile        Specify a keyfile. SNTP will look in this file for the key specified with -a
@@ -264,8 +265,14 @@ Up:&nbsp;<a rel="up" accesskey="u" href="#sntp-Invocation">sntp Invocation</a>
 <h4 class="subsection">broadcast option (-b)</h4>
 
 <p><a name="index-sntp_002dbroadcast-6"></a>
-This is the &ldquo;use broadcasts to the address specified for synchronisation&rdquo; option. 
-If specified SNTP will listen to the specified broadcast address
+This is the &ldquo;use broadcasts to the address specified for synchronisation&rdquo; option.
+
+  <p>This option has some usage constraints.  It:
+     <ul>
+<li>may appear an unlimited number of times. 
+</ul>
+
+  <p>If specified SNTP will listen to the specified broadcast address
 for NTP broadcasts.  The default maximum wait time,
 68 seconds, can be modified with -t.