From: Dave Hart Date: Thu, 25 Mar 2010 16:12:20 +0000 (+0000) Subject: ntpq-subs.c: X-Git-Tag: NTP_4_2_7P22~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c4a1dce195160c672c37cd5a5569147f12ab6d0;p=thirdparty%2Fntp.git ntpq-subs.c: Add ntpq "mrulist limited" and "mrulist kod" support, equivalent to ntpq -c "mrulist resany=0x20" and ntpq -c "mrulist resany=0x400" respectively. Add "r" rate limiting column to mrulist output containing a period, or K for KoD sent in response to last packet, or L for no response to last packet due to rate limiting. These are redundant with bits 0x400 and 0x20 in the rstr column and treated differently than other restrict bits, reflecting not if the restriction bit is enabled for the remote address, but if RES_KOD or RES_LIMITED handling was triggered by the last packet from them. it. ntp.h, ntpdc_ops.c, ntp_proto.c, ntp_config.c: rename RES_TIMEOUT to RES_FLAKE to reflect v4 use (as a flakeway which drops 10% of incoming packets from matching addresses). ntp_intres.c: rename RES_TIMEOUT to RES_FLAKE to reflect v4 use (as a flakeway which drops 10% of incoming packets from matching addresses), eliminating conflict with RES_TIMEOUT provided by some systems DNS headers. bk: 4bab8b64gZ0D42JzVbbuJCDOxIdD-A --- diff --git a/include/ntp.h b/include/ntp.h index ecf20da98..8f9b39fa9 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -831,12 +831,12 @@ struct restrict_u_tag { #define RES_KOD 0x0400 /* send kiss of death packet */ #define RES_MSSNTP 0x0800 /* enable MS-SNTP authentication */ -#define RES_TIMEOUT 0x1000 /* timeout this entry */ +#define RES_FLAKE 0x1000 /* flakeway - drop 10% */ #define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY | \ RES_NOMODIFY | RES_NOTRAP | \ RES_LPTRAP | RES_KOD | \ - RES_MSSNTP | RES_TIMEOUT) + RES_MSSNTP | RES_FLAKE) /* * Match flags diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 4e30e4e4d..7a56ce1d1 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -2262,7 +2262,7 @@ config_access( break; case T_Flake: - flags |= RES_TIMEOUT; + flags |= RES_FLAKE; break; case T_Ignore: diff --git a/ntpd/ntp_intres.c b/ntpd/ntp_intres.c index 30990abbc..b1808cce9 100644 --- a/ntpd/ntp_intres.c +++ b/ntpd/ntp_intres.c @@ -81,9 +81,6 @@ # include # endif # include -# ifdef RES_TIMEOUT -# undef RES_TIMEOUT /* resolv.h has one, we want ours */ -# endif # ifdef HAVE_INT32_ONLY_WITH_DNS # define HAVE_INT32 # endif diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index c129b285d..78951bb69 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -416,7 +416,7 @@ receive( * This is for testing. If restricted drop ten percent of * surviving packets. */ - if (restrict_mask & RES_TIMEOUT) { + if (restrict_mask & RES_FLAKE) { if ((double)ntp_random() / 0x7fffffff < .1) { sys_restricted++; return; /* no flakeway */ diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index 242d455cf..280753aa6 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -1672,7 +1672,7 @@ static struct resflags resflagsV3[] = { { "limited", RES_LIMITED }, { "version", RES_VERSION }, { "kod", RES_KOD }, - { "timeout", RES_TIMEOUT }, + { "flake", RES_FLAKE }, { "", 0 } }; diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 072db0c43..2df0e4f94 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -2761,6 +2761,7 @@ mrulist( mru_sort_order order; const char * const *ppkeyword; char parms_buf[128]; + char buf[24]; char *parms; char *arg; size_t cb; @@ -2808,6 +2809,20 @@ mrulist( COUNTOF(mru_sort_keywords)) order = ppkeyword - mru_sort_keywords; + } else if (!strcmp("limited", arg) || + !strcmp("kod", arg)) { + /* transform to resany=... */ + snprintf(buf, sizeof(buf), + ", resany=0x%x", + ('k' == arg[0]) + ? RES_KOD + : RES_LIMITED); + cb = 1 + strlen(buf); + if (parms + cb < + parms_buf + sizeof(parms_buf)) { + memcpy(parms, buf, cb); + parms += cb - 1; + } } else fprintf(stderr, "ignoring unrecognized mrulist parameter: %s\n", @@ -2845,7 +2860,7 @@ mrulist( qsort(sorted, mru_count, sizeof(sorted[0]), mru_qcmp_table[order]); - printf( "lstint avgint rstr m v count rport remote address\n" + printf( "lstint avgint rstr r m v count rport remote address\n" "==============================================================================\n"); /* '=' x 78 */ for (ppentry = sorted; ppentry < sorted + mru_count; ppentry++) { @@ -2859,10 +2874,15 @@ mrulist( LFPTOD(&interval, favgint); favgint /= recent->count; avgint = (int)(favgint + 0.5); - fprintf(fp, "%6d %6d %4hx %d %d %6d %5hu %s\n", - lstint, avgint, recent->rs, (int)recent->mode, - (int)recent->ver, recent->count, - SRCPORT(&recent->addr), + fprintf(fp, "%6d %6d %4hx %c %d %d %6d %5hu %s\n", + lstint, avgint, recent->rs, + (RES_KOD & recent->rs) + ? 'K' + : (RES_LIMITED & recent->rs) + ? 'L' + : '.', + (int)recent->mode, (int)recent->ver, + recent->count, SRCPORT(&recent->addr), nntohost(&recent->addr)); if (showhostnames) fflush(fp);