]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 691] ntp_monitor()/restrictions() interaction fixes
authorHarlan Stenn <stenn@ntp.org>
Fri, 8 Sep 2006 23:23:32 +0000 (19:23 -0400)
committerHarlan Stenn <stenn@ntp.org>
Fri, 8 Sep 2006 23:23:32 +0000 (19:23 -0400)
bk: 4501fb74ok2LEZlHdNofbtKeI5k8Bw

include/ntpd.h
ntpd/ntp_monitor.c
ntpd/ntp_proto.c
ntpd/ntp_restrict.c

index 7651331aced12d2767f1a558426166d62b77131c..d51ddf74f1625ff14c8b744c7861df465fa3d4fe 100644 (file)
@@ -126,7 +126,7 @@ extern      u_long  sys_tai;
 extern void    init_mon        P((void));
 extern void    mon_start       P((int));
 extern void    mon_stop        P((int));
-extern void    ntp_monitor     P((struct recvbuf *));
+extern int     ntp_monitor     P((struct recvbuf *));
 extern  void    ntp_monclearinterface P((struct interface *interface));
 
 /* ntp_peer.c */
@@ -211,7 +211,7 @@ extern      void    process_private P((struct recvbuf *, int));
 
 /* ntp_restrict.c */
 extern void    init_restrict   P((void));
-extern int     restrictions    P((struct sockaddr_storage *));
+extern int     restrictions    P((struct sockaddr_storage *, int));
 extern void    hack_restrict   P((int, struct sockaddr_storage *, struct sockaddr_storage *, int, int));
 
 /* ntp_timer.c */
index d4f495f461e9369f8b3827974063a29911f6d646..753fa767ce80f3759941ae39a9156ac7051eeec7 100644 (file)
@@ -199,8 +199,10 @@ ntp_monclearinterface(struct interface *interface)
 
 /*
  * ntp_monitor - record stats about this packet
+ *
+ * Returns 1 if the packet is at the head of the list, 0 otherwise.
  */
-void
+int
 ntp_monitor(
        struct recvbuf *rbufp
        )
@@ -212,7 +214,7 @@ ntp_monitor(
        register int mode;
 
        if (mon_enabled == MON_OFF)
-               return;
+               return 0;
 
        pkt = &rbufp->recv_pkt;
        memset(&addr, 0, sizeof(addr));
@@ -242,7 +244,7 @@ ntp_monitor(
                        md->mru_prev = &mon_mru_list;
                        mon_mru_list.mru_next->mru_prev = md;
                        mon_mru_list.mru_next = md;
-                       return;
+                       return 1;
                }
                md = md->hash_next;
        }
@@ -261,7 +263,7 @@ ntp_monitor(
                /* We get 31 bits from ntp_random() */
                if (((u_long)ntp_random()) / FRAC >
                    (double)(current_time - md->lasttime) / mon_age)
-                       return;
+                       return 0;
 
                md->mru_prev->mru_next = &mon_mru_list;
                mon_mru_list.mru_prev = md->mru_prev;
@@ -300,6 +302,7 @@ ntp_monitor(
        md->mru_prev = &mon_mru_list;
        mon_mru_list.mru_next->mru_prev = md;
        mon_mru_list.mru_next = md;
+       return 1;
 }
 
 
index 0ce6a8b1144a6bb6ef95ff51ee07a2568314f229..1dae30e3532523983ee3c985f80165cb4598054e 100644 (file)
@@ -349,6 +349,7 @@ receive(
        int     rval;                   /* cookie snatcher */
 #endif /* OPENSSL */
        int retcode = AM_NOMATCH;
+       int     at_listhead;
 
        /*
         * Monitor the packet and get restrictions. Note that the packet
@@ -369,8 +370,8 @@ receive(
                sys_badlength++;
                return;                         /* bogus port */
        }
-       ntp_monitor(rbufp);
-       restrict_mask = restrictions(&rbufp->recv_srcadr);
+       at_listhead = ntp_monitor(rbufp);
+       restrict_mask = restrictions(&rbufp->recv_srcadr, at_listhead);
 #ifdef DEBUG
        if (debug > 1)
                printf("receive: at %ld %s<-%s flags %x restrict %03x\n",
index 23f50392dd9eb9ae314f9d513497a57be3bc5304..334b538c0be34095aef078e6d385b13116c497ae 100644 (file)
@@ -158,7 +158,8 @@ init_restrict(void)
  */
 int
 restrictions(
-       struct sockaddr_storage *srcadr
+       struct sockaddr_storage *srcadr,
+       int at_listhead
        )
 {
        struct restrictlist *rl;
@@ -260,7 +261,7 @@ restrictions(
         * packet is greater than res_min_interval and the average is
         * greater thatn res_avg_interval.
         */
-       if (mon_enabled == MON_OFF) {
+       if (!at_listhead || mon_enabled == MON_OFF) {
                flags &= ~RES_LIMITED;
        } else {
                struct mon_data *md;