diff options
Diffstat (limited to 'ntpd/ntp_monitor.c')
-rw-r--r-- | ntpd/ntp_monitor.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/ntpd/ntp_monitor.c b/ntpd/ntp_monitor.c index 6b288fc32fecf..753fa767ce80f 100644 --- a/ntpd/ntp_monitor.c +++ b/ntpd/ntp_monitor.c @@ -9,6 +9,7 @@ #include "ntp_io.h" #include "ntp_if.h" #include "ntp_stdlib.h" +#include <ntp_random.h> #include <stdio.h> #include <signal.h> @@ -177,11 +178,31 @@ mon_stop( mon_mru_list.mru_prev = &mon_mru_list; } +void +ntp_monclearinterface(struct interface *interface) +{ + struct mon_data *md; + + for (md = mon_mru_list.mru_next; md != &mon_mru_list; + md = md->mru_next) { + if (md->interface == interface) + { + /* dequeue from mru list and put to free list */ + md->mru_prev->mru_next = md->mru_next; + md->mru_next->mru_prev = md->mru_prev; + remove_from_hash(md); + md->hash_next = mon_free; + mon_free = md; + } + } +} /* * 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 ) @@ -193,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)); @@ -223,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; } @@ -239,9 +260,10 @@ ntp_monitor( * Preempt from the MRU list if old enough. */ md = mon_mru_list.mru_prev; - if (((u_long)RANDOM & 0xffffffff) / FRAC > + /* 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; @@ -266,7 +288,7 @@ ntp_monitor( md->mode = (u_char) mode; md->version = PKT_VERSION(pkt->li_vn_mode); md->interface = rbufp->dstadr; - md->cast_flags = (u_char)(((rbufp->dstadr->flags & INT_MULTICAST) && + md->cast_flags = (u_char)(((rbufp->dstadr->flags & INT_MCASTOPEN) && rbufp->fd == md->interface->fd) ? MDF_MCAST: rbufp->fd == md->interface->bfd ? MDF_BCAST : MDF_UCAST); @@ -280,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; } |