]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3473] RefID of refclocks should always be text format
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 15 Jun 2019 07:17:38 +0000 (09:17 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 15 Jun 2019 07:17:38 +0000 (09:17 +0200)
bk: 5d049b92qj6cdT04KM0PGr_RCEfJhw

ChangeLog
ntpd/ntp_control.c
ntpdc/ntpdc_ops.c
ntpq/ntpq.c

index 9ff845c81028eeecbd72fd587d28555bc5f781e5..a62501ffb2a740c2cc43cfac0658014b45694b0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3473] RefID of refclocks should always be text format <perlinger@ntp.org>
+  - applied patch by Gerry Garvey (with minor formatting changes)
+
 ---
 (4.2.8p13) 2019/03/07 Released by Harlan Stenn <stenn@ntp.org>
 
index 49a197ed7c61ccf906a2d76d4070063abed8b3a7..3503f63ef5f217d0b59c5686c71b2a84faa8adf8 100644 (file)
@@ -2965,14 +2965,9 @@ ctl_putclock(
                break;
 
        case CC_FUDGEVAL2:
-               if (mustput || (pcs->haveflags & CLK_HAVEVAL2)) {
-                       if (pcs->fudgeval1 > 1)
-                               ctl_putadr(clock_var[id].text,
-                                          pcs->fudgeval2, NULL);
-                       else
-                               ctl_putrefid(clock_var[id].text,
-                                            pcs->fudgeval2);
-               }
+               /* RefID of clocks are always text even if stratum is fudged */
+               if (mustput || (pcs->haveflags & CLK_HAVEVAL2))
+                       ctl_putrefid(clock_var[id].text, pcs->fudgeval2);
                break;
 
        case CC_FLAGS:
@@ -3483,7 +3478,7 @@ write_variables(
                                return;
                        }
                }
-               
+
                if (ext_var) {
                        octets = strlen(v->text) + strlen(valuep) + 2;
                        vareqv = emalloc(octets);
index 3b50916e7f8a873d8b7cedd65a96727b56c0965e..1240ad100c1130e7d9e768bfe7b1735eb8ccbcb4 100644 (file)
@@ -40,7 +40,7 @@ static        int     check1item      (size_t, FILE *);
  */
 static void    peerlist        (struct parse *, FILE *);
 static void    peers           (struct parse *, FILE *);
-static void    doconfig        (struct parse *pcmd, FILE *fp, int mode, int refc);
+static void    doconfig        (struct parse *pcmd, FILE *fp, int mode, int refc);
 static void    dmpeers         (struct parse *, FILE *);
 static void    dopeers         (struct parse *, FILE *, int);
 static void    printpeer       (struct info_peer *, FILE *);
@@ -260,7 +260,7 @@ do {                                                                \
 
 
 /*
- * SET_ADDRS - setup source and destination addresses for 
+ * SET_ADDRS - setup source and destination addresses for
  * v4/v6 as needed
  */
 #define SET_ADDRS(a1, a2, info, a1prefix, a2prefix)            \
@@ -359,9 +359,9 @@ peerlist(
 
 again:
        res = doquery(impl_ver, REQ_PEER_LIST, 0, 0, 0, (char *)NULL, &items,
-                     &itemsize, (void *)&plist, 0, 
+                     &itemsize, (void *)&plist, 0,
                      sizeof(struct info_peer_list));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -439,9 +439,9 @@ dopeers(
 
 again:
        res = doquery(impl_ver, REQ_PEER_LIST_SUM, 0, 0, 0, (char *)NULL,
-                     &items, &itemsize, (void *)&plist, 0, 
+                     &items, &itemsize, (void *)&plist, 0,
                      sizeof(struct info_peer_summary));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -588,22 +588,24 @@ printpeer(
        register int i;
        l_fp tempts;
        sockaddr_u srcadr, dstadr;
-       
+
        SET_ADDRS(dstadr, srcadr, pp, dstadr, srcadr);
-       
+
        (void) fprintf(fp, "remote %s, local %s\n",
                       stoa(&srcadr), stoa(&dstadr));
        (void) fprintf(fp, "hmode %s, pmode %s, stratum %d, precision %d\n",
                       modetoa(pp->hmode), modetoa(pp->pmode),
                       pp->stratum, pp->precision);
-       
+
        (void) fprintf(fp,
                       "leap %c%c, refid [%s], rootdistance %s, rootdispersion %s\n",
                       pp->leap & 0x2 ? '1' : '0',
                       pp->leap & 0x1 ? '1' : '0',
-                      refid_string(pp->refid, pp->stratum), fptoa(NTOHS_FP(pp->rootdelay), 5),
+                      refid_string(pp->refid,
+                                   (pp->flags & INFO_FLAG_REFCLOCK ? 0 : pp->stratum)),
+                      fptoa(NTOHS_FP(pp->rootdelay), 5),
                       ufptoa(NTOHS_FP(pp->rootdispersion), 5));
-       
+
        (void) fprintf(fp,
                       "ppoll %d, hpoll %d, keyid %lu, version %d, association %u\n",
                       pp->ppoll, pp->hpoll, (u_long)pp->keyid, pp->version, ntohs(pp->associd));
@@ -614,9 +616,9 @@ printpeer(
 
        (void) fprintf(fp, "boffset %s, ttl/mode %d\n",
                       fptoa(NTOHS_FP(pp->estbdelay), 5), pp->ttl);
-       
+
        (void) fprintf(fp, "timer %lds, flags", (long)ntohl(pp->timer));
-       print_pflag(fp, pp->flags); 
+       print_pflag(fp, pp->flags);
 
        NTOHL_FP(&pp->reftime, &tempts);
        (void) fprintf(fp, "reference time:      %s\n",
@@ -630,7 +632,7 @@ printpeer(
        NTOHL_FP(&pp->xmt, &tempts);
        (void) fprintf(fp, "transmit timestamp:  %s\n",
                       prettydate(&tempts));
-       
+
        (void) fprintf(fp, "filter delay: ");
        for (i = 0; i < NTP_SHIFT; i++) {
                (void) fprintf(fp, " %-8.8s",
@@ -656,7 +658,7 @@ printpeer(
                    (void) fprintf(fp, "\n              ");
        }
        (void) fprintf(fp, "\n");
-       
+
 
        NTOHL_FP(&pp->offset, &tempts);
        (void) fprintf(fp,
@@ -715,7 +717,7 @@ again:
        res = doquery(impl_ver, REQ_PEER_INFO, 0, qitems,
                      sendsize, (char *)plist, &items,
                      &itemsize, (void *)&pp, 0, sizeof(struct info_peer));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -790,9 +792,9 @@ again:
 
        res = doquery(impl_ver, REQ_PEER_STATS, 0, qitems,
                      sendsize, (char *)plist, &items,
-                     &itemsize, (void *)&pp, 0, 
+                     &itemsize, (void *)&pp, 0,
                      sizeof(struct info_peer_stats));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -890,9 +892,9 @@ loopinfo(
 
 again:
        res = doquery(impl_ver, REQ_LOOP_INFO, 0, 0, 0, (char *)NULL,
-                     &items, &itemsize, (void *)&il, 0, 
+                     &items, &itemsize, (void *)&il, 0,
                      sizeof(struct info_loop));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -955,7 +957,7 @@ again:
        res = doquery(impl_ver, REQ_SYS_INFO, 0, 0, 0, (char *)NULL,
                      &items, &itemsize, (void *)&is, 0,
                      sizeof(struct info_sys));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1041,9 +1043,9 @@ sysstats(
 
 again:
        res = doquery(impl_ver, REQ_SYS_STATS, 0, 0, 0, (char *)NULL,
-                     &items, &itemsize, (void *)&ss, 0, 
+                     &items, &itemsize, (void *)&ss, 0,
                      sizeof(struct info_sys_stats));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1083,7 +1085,7 @@ again:
                (u_long)ntohl(ss->badauth));
        if (itemsize != sizeof(struct info_sys_stats))
            return;
-       
+
        fprintf(fp, "rate exceeded:          %lu\n",
               (u_long)ntohl(ss->limitrejected));
 }
@@ -1108,7 +1110,7 @@ iostats(
 again:
        res = doquery(impl_ver, REQ_IO_STATS, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&io, 0, sizeof(*io));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1169,7 +1171,7 @@ memstats(
 again:
        res = doquery(impl_ver, REQ_MEM_STATS, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&mem, 0, sizeof(*mem));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1226,7 +1228,7 @@ timerstats(
 again:
        res = doquery(impl_ver, REQ_TIMER_STATS, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&tim, 0, sizeof(*tim));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1412,13 +1414,13 @@ again:
                        version);
                res = TRUE;
        }
-       if (minpoll < NTP_MINPOLL || minpoll > NTP_MAXPOLL || 
-           maxpoll < NTP_MINPOLL || maxpoll > NTP_MAXPOLL || 
+       if (minpoll < NTP_MINPOLL || minpoll > NTP_MAXPOLL ||
+           maxpoll < NTP_MINPOLL || maxpoll > NTP_MAXPOLL ||
            minpoll > maxpoll) {
                fprintf(fp, "***min/max-poll must be within %d..%d\n",
                        NTP_MINPOLL, NTP_MAXPOLL);
                res = TRUE;
-       }                                       
+       }
 
        if (res)
                return;
@@ -1449,7 +1451,7 @@ again:
        res = doquery(impl_ver, REQ_CONFIG, 1, 1,
                      sendsize, (char *)&cpeer, &items,
                      &itemsize, &dummy, 0, sizeof(struct conf_peer));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1516,7 +1518,7 @@ again:
        res = doquery(impl_ver, REQ_UNCONFIG, 1, qitems,
                      sendsize, (char *)plist, &items,
                      &itemsize, &dummy, 0, sizeof(struct conf_unpeer));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1603,7 +1605,7 @@ again:
        res = doquery(impl_ver, req, 1, 1,
                      sizeof(struct conf_sys_flags), (char *)&sys, &items,
                      &itemsize, &dummy, 0, sizeof(struct conf_sys_flags));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1690,9 +1692,9 @@ reslist(
 
 again:
        res = doquery(impl_ver, REQ_GET_RESTRICT, 0, 0, 0, (char *)NULL,
-                     &items, &itemsize, (void *)&rl, 0, 
+                     &items, &itemsize, (void *)&rl, 0,
                      sizeof(struct info_restrict));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1924,7 +1926,7 @@ again:
 
        res = doquery(impl_ver, req_code, 1, 1, sendsize, (char *)&cres,
                      &items, &itemsize, &dummy, 0, sizeof(cres));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -1965,7 +1967,7 @@ again:
                      (version == 1 || version == -1) ? REQ_MON_GETLIST_1 :
                      REQ_MON_GETLIST, 0, 0, 0, NULL,
                      &items, &itemsize, &struct_star,
-                     (version < 0) ? (1 << INFO_ERR_REQ) : 0, 
+                     (version < 0) ? (1 << INFO_ERR_REQ) : 0,
                      sizeof(struct info_monitor_1));
 
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
@@ -1973,11 +1975,11 @@ again:
                goto again;
        }
 
-       if (res == INFO_ERR_REQ && version < 0) 
+       if (res == INFO_ERR_REQ && version < 0)
                res = doquery(impl_ver, REQ_MON_GETLIST, 0, 0, 0, NULL,
                              &items, &itemsize, &struct_star, 0,
                              sizeof(struct info_monitor));
-       
+
        if (res != 0)
                return;
 
@@ -1997,9 +1999,9 @@ again:
                        if ((pcmd->nargs == 0) ||
                            ((pcmd->argval->ival == 6) && (m1->v6_flag != 0)) ||
                            ((pcmd->argval->ival == 4) && (m1->v6_flag == 0)))
-                               fprintf(fp, 
+                               fprintf(fp,
                                    "%-22.22s %5d %-15s %8lu %1u %1u %6lx %6lu %7lu\n",
-                                   nntohost(&addr), 
+                                   nntohost(&addr),
                                    ntohs(m1->port),
                                    stoa(&dstadr),
                                    (u_long)ntohl(m1->count),
@@ -2124,7 +2126,7 @@ again:
        res = doquery(impl_ver, REQ_RESET_STATS, 1, 1,
                      sizeof(struct reset_flags), (char *)&rflags, &items,
                      &itemsize, &dummy, 0, sizeof(struct reset_flags));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2184,7 +2186,7 @@ again:
        res = doquery(impl_ver, REQ_RESET_PEER, 1, qitems,
                      sendsize, (char *)plist, &items,
                      &itemsize, &dummy, 0, sizeof(struct conf_unpeer));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2213,7 +2215,7 @@ readkeys(
 again:
        res = doquery(impl_ver, REQ_REREAD_KEYS, 1, 0, 0, (char *)0,
                      &items, &itemsize, &dummy, 0, sizeof(dummy));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2276,9 +2278,9 @@ do_trustkey(
 
 again:
        res = doquery(impl_ver, req, 1, ritems, sizeof(u_long),
-                     (char *)keyids, &items, &itemsize, &dummy, 0, 
+                     (char *)keyids, &items, &itemsize, &dummy, 0,
                      sizeof(dummy));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2309,7 +2311,7 @@ authinfo(
 again:
        res = doquery(impl_ver, REQ_AUTHINFO, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&ia, 0, sizeof(*ia));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2366,7 +2368,7 @@ traps(
 again:
        res = doquery(impl_ver, REQ_TRAPS, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&it, 0, sizeof(*it));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2399,7 +2401,7 @@ again:
                        fprintf(fp, "low priority\n");
                else
                        fprintf(fp, "normal priority\n");
-               
+
                fprintf(fp, "set for %ld secs, last set %ld secs ago\n",
                        (long)ntohl(it->origtime),
                        (long)ntohl(it->settime));
@@ -2492,9 +2494,9 @@ again:
        }
 
        res = doquery(impl_ver, req, 1, 1, sendsize,
-                     (char *)&ctrap, &items, &itemsize, &dummy, 0, 
+                     (char *)&ctrap, &items, &itemsize, &dummy, 0,
                      sizeof(struct conf_trap));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2555,9 +2557,9 @@ do_changekey(
 
 again:
        res = doquery(impl_ver, req, 1, 1, sizeof(u_int32),
-                     (char *)&key, &items, &itemsize, &dummy, 0, 
+                     (char *)&key, &items, &itemsize, &dummy, 0,
                      sizeof(dummy));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2588,7 +2590,7 @@ ctlstats(
 again:
        res = doquery(impl_ver, REQ_GET_CTLSTATS, 0, 0, 0, NULL, &items,
                      &itemsize, (void *)&ic, 0, sizeof(*ic));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2664,7 +2666,7 @@ again:
        res = doquery(impl_ver, REQ_GET_CLOCKINFO, 0, qitems,
                      sizeof(u_int32), (char *)clist, &items,
                      &itemsize, (void *)&cl, 0, sizeof(struct info_clock));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2847,7 +2849,7 @@ again:
        res = doquery(impl_ver, REQ_GET_CLKBUGINFO, 0, qitems,
                      sizeof(u_int32), (char *)clist, &items,
                      &itemsize, (void *)&cl, 0, sizeof(struct info_clkbug));
-       
+
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
                goto again;
@@ -2933,7 +2935,7 @@ kerninfo(
 
 again:
        res = doquery(impl_ver, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL,
-                     &items, &itemsize, (void *)&ik, 0, 
+                     &items, &itemsize, (void *)&ik, 0,
                      sizeof(struct info_kernel));
 
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
@@ -3078,9 +3080,9 @@ iflist(
 
        fprintf(fp, IF_LIST_FMT_STR, IF_LIST_LABELS);
        fprintf(fp, IF_LIST_LINE);
-       
+
        while (items > 0) {
-               SET_ADDR(saddr, ntohl(ifs->v6_flag), 
+               SET_ADDR(saddr, ntohl(ifs->v6_flag),
                         ifs->unaddr.addr.s_addr, ifs->unaddr.addr6);
                fprintf(fp, IF_LIST_FMT,
                        ntohl(ifs->ifnum),
@@ -3098,12 +3100,12 @@ iflist(
                        (u_long)ntohl(ifs->peercnt),
                        (u_long)ntohl(ifs->uptime));
 
-               SET_ADDR(saddr, ntohl(ifs->v6_flag), 
+               SET_ADDR(saddr, ntohl(ifs->v6_flag),
                         ifs->unmask.addr.s_addr, ifs->unmask.addr6);
                fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'M');
 
                if (!ntohl(ifs->v6_flag) && ntohl(ifs->flags) & (INT_BCASTOPEN)) {
-                       SET_ADDR(saddr, ntohl(ifs->v6_flag), 
+                       SET_ADDR(saddr, ntohl(ifs->v6_flag),
                                 ifs->unbcast.addr.s_addr, ifs->unbcast.addr6);
                        fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'B');
 
@@ -3127,7 +3129,7 @@ get_if_stats(
        int res;
 
        res = doquery(impl_ver, REQ_IF_STATS, 1, 0, 0, (char *)NULL, &items,
-                     &itemsize, (void *)&ifs, 0, 
+                     &itemsize, (void *)&ifs, 0,
                      sizeof(struct info_if_stats));
        iflist(fp, ifs, items, itemsize, res);
 }
@@ -3145,7 +3147,7 @@ do_if_reload(
        int res;
 
        res = doquery(impl_ver, REQ_IF_RELOAD, 1, 0, 0, (char *)NULL, &items,
-                     &itemsize, (void *)&ifs, 0, 
+                     &itemsize, (void *)&ifs, 0,
                      sizeof(struct info_if_stats));
        iflist(fp, ifs, items, itemsize, res);
 }
index 6e7a5c375175aeb721aa089559cde64cbf0c45d0..c17962624d09e70006899bbd7da6256622dc3aa1 100644 (file)
@@ -3657,7 +3657,20 @@ cookedprint(
                        if (!value) {
                                output_raw = '?';
                        } else if (decodenetnum(value, &hval)) {
-                               if (ISREFCLOCKADR(&hval))
+                               if (datatype == TYPE_CLOCK && IS_IPV4(&hval)) {
+                                       /*
+                                        * Workaround to override numeric refid formats 
+                                        * for refclocks received from faulty nptd servers 
+                                        * and output them as text.
+                                        */
+                                       int i;
+                                       unsigned char *str = (unsigned char *)&(hval.sa4).sin_addr;
+                                       char refid_buf[5];
+                                       for (i=0; i<4 && str[i]; i++)
+                                               refid_buf[i] = (isprint(str[i]) ? str[i] : '?');
+                                       refid_buf[i] = 0; /* Null terminator */
+                                       output(fp, name, refid_buf);
+                               } else if (ISREFCLOCKADR(&hval))
                                        output(fp, name,
                                               refnumtoa(&hval));
                                else