]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Decode restrict flags on receive() debug output
authorHarlan Stenn <stenn@ntp.org>
Sat, 20 Jan 2018 11:41:34 +0000 (03:41 -0800)
committerHarlan Stenn <stenn@ntp.org>
Sat, 20 Jan 2018 11:41:34 +0000 (03:41 -0800)
bk: 5a632aeeKD7fCebULbu0NKJQRkUPtQ

ChangeLog
include/ntp.h
ntpd/ntp_config.c
ntpd/ntp_proto.c

index 4f55f0d3e1b603edc84ea689e54ece6e04912d1b..6798e8008e232737a06ca3172bca15546a9cd012 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -81,6 +81,7 @@
 * Add DPRINTF(2,...) lines to receive() for packet drops.  HStenn.
 * Rename the configuration flag fifo variables.  HStenn.
 * Improve saveconfig output.  HStenn.
+* Decode restrict flags on receive() debug output.  HStenn.
 
 ---
 (4.2.8p10) 2017/03/21 Released by Harlan Stenn <stenn@ntp.org>
index c29cad16611cd92ed75978ff0924fb663c9fee77..beebafed34487611836de1a169a4c7c9a42d8bb7 100644 (file)
@@ -840,6 +840,9 @@ struct restrict_u_tag {
 #define        V6_SIZEOF_RESTRICT_U    (offsetof(restrict_u, u)        \
                                 + sizeof(res_addr6))
 
+char *build_rflags(u_short flags);
+char *build_mflags(u_short flags);
+
 /*
  * Access flags
  */
index 716e54ec93ea40e5cb9d652ed8fd297a4e05bf33..0adfcfc70de6de8a69143dca8eea569c75dfb9f1 100644 (file)
@@ -149,9 +149,9 @@ typedef struct peer_resolved_ctx_tag {
 extern int yydebug;                    /* ntp_parser.c (.y) */
 config_tree cfgt;                      /* Parser output stored here */
 struct config_tree_tag *cfg_tree_history;      /* History of configs */
-char   *sys_phone[MAXPHONE] = {NULL};  /* ACTS phone numbers */
+char * sys_phone[MAXPHONE] = {NULL};   /* ACTS phone numbers */
 char   default_keysdir[] = NTP_KEYSDIR;
-char   *keysdir = default_keysdir;     /* crypto keys directory */
+char * keysdir = default_keysdir;      /* crypto keys directory */
 char * saveconfigdir;
 #if defined(HAVE_SCHED_SETSCHEDULER)
 int    config_priority_override = 0;
@@ -364,8 +364,7 @@ static u_int32 get_match(const char *, struct masks *);
 static u_int32 get_logmask(const char *);
 static int/*BOOL*/ is_refclk_addr(const address_node * addr);
 
-static char *  rflagstoa(u_short);
-static char *  rmflagstoa(u_short);
+static void    appendstr(char *, size_t, char *);
 
 
 #ifndef SIM
@@ -2596,6 +2595,7 @@ config_access(
        ippeerlimit = -1;
        my_node = HEAD_PFIFO(ptree->restrict_opts);
        /* Grab the ippeerlmit */
+
        for (; my_node != NULL; my_node = my_node->link) {
                /* Parse the flags */
                flags = 0;
@@ -5243,3 +5243,140 @@ ntp_rlimit(
        }
 }
 #endif /* HAVE_SETRLIMIT */
+
+
+char *
+build_mflags(u_short mflags)
+{
+       static char mfs[1024];
+
+       mfs[0] = '\0';
+
+       if (mflags & RESM_NTPONLY) {
+               mflags &= ~RESM_NTPONLY;
+               appendstr(mfs, sizeof mfs, "ntponly");
+       }
+
+       if (mflags & RESM_SOURCE) {
+               mflags &= ~RESM_SOURCE;
+               appendstr(mfs, sizeof mfs, "source");
+       }
+
+       if (mflags) {
+               char string[10];
+
+               snprintf(string, sizeof string, "%0x", mflags);
+               appendstr(mfs, sizeof mfs, string);
+       }
+
+       return mfs;
+}
+
+
+char *
+build_rflags(u_short flags)
+{
+       static char mfs[1024];
+
+       mfs[0] = '\0';
+
+       if (flags & RES_FLAKE) {
+               flags &= ~RES_FLAKE;
+               appendstr(mfs, sizeof mfs, "flake");
+       }
+
+       if (flags & RES_IGNORE) {
+               flags &= ~RES_IGNORE;
+               appendstr(mfs, sizeof mfs, "ignore");
+       }
+
+       if (flags & RES_KOD) {
+               flags &= ~RES_KOD;
+               appendstr(mfs, sizeof mfs, "kod");
+       }
+
+       if (flags & RES_MSSNTP) {
+               flags &= ~RES_MSSNTP;
+               appendstr(mfs, sizeof mfs, "mssntp");
+       }
+
+       if (flags & RES_LIMITED) {
+               flags &= ~RES_LIMITED;
+               appendstr(mfs, sizeof mfs, "limited");
+       }
+
+       if (flags & RES_LPTRAP) {
+               flags &= ~RES_LPTRAP;
+               appendstr(mfs, sizeof mfs, "lptrap");
+       }
+
+       if (flags & RES_NOMODIFY) {
+               flags &= ~RES_NOMODIFY;
+               appendstr(mfs, sizeof mfs, "nomodify");
+       }
+
+       if (flags & RES_NOMRULIST) {
+               flags &= ~RES_NOMRULIST;
+               appendstr(mfs, sizeof mfs, "nomrulist");
+       }
+
+       if (flags & RES_NOEPEER) {
+               flags &= ~RES_NOEPEER;
+               appendstr(mfs, sizeof mfs, "noepeer");
+       }
+
+       if (flags & RES_NOPEER) {
+               flags &= ~RES_NOPEER;
+               appendstr(mfs, sizeof mfs, "nopeer");
+       }
+
+       if (flags & RES_NOQUERY) {
+               flags &= ~RES_NOQUERY;
+               appendstr(mfs, sizeof mfs, "noquery");
+       }
+
+       if (flags & RES_DONTSERVE) {
+               flags &= ~RES_DONTSERVE;
+               appendstr(mfs, sizeof mfs, "dontserve");
+       }
+
+       if (flags & RES_NOTRAP) {
+               flags &= ~RES_NOTRAP;
+               appendstr(mfs, sizeof mfs, "notrap");
+       }
+
+       if (flags & RES_DONTTRUST) {
+               flags &= ~RES_DONTTRUST;
+               appendstr(mfs, sizeof mfs, "notrust");
+       }
+
+       if (flags & RES_VERSION) {
+               flags &= ~RES_VERSION;
+               appendstr(mfs, sizeof mfs, "version");
+       }
+
+       if (flags) {
+               char string[10];
+
+               snprintf(string, sizeof string, "%0x", flags);
+               appendstr(mfs, sizeof mfs, string);
+       }
+
+       return mfs;
+}
+
+
+static void
+appendstr(
+       char *string,
+       size_t s,
+       char *new
+       )
+{
+       if (*string != '\0') {
+               (void)strlcat(string, ",", s);
+       }
+       (void)strlcat(string, new, s);
+
+       return;
+}
index 8e844128a01cca3e234670c3a6c500472efbeb24..462a4673802e49b92afa62af9b675d22c33d2881 100644 (file)
@@ -635,10 +635,11 @@ receive(
        hisleap = PKT_LEAP(pkt->li_vn_mode);
        hismode = (int)PKT_MODE(pkt->li_vn_mode);
        hisstratum = PKT_TO_STRATUM(pkt->stratum);
-       DPRINTF(2, ("receive: at %ld %s<-%s mode %d flags %x restrict %03x org %#010x.%08x xmt %#010x.%08x\n",
+       DPRINTF(2, ("receive: at %ld %s<-%s mode %d flags %x restrict %s org %#010x.%08x xmt %#010x.%08x\n",
                    current_time, stoa(&rbufp->dstadr->sin),
                    stoa(&rbufp->recv_srcadr), hismode, rbufp->dstadr->flags,
-                   restrict_mask, ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf),
+                   build_rflags(restrict_mask),
+                   ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf),
                    ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf)));
 
        /* See basic mode and broadcast checks, below */