ntp_monitor.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ntp_monitor.c - monitor who is using the xntpd server
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <signal.h>
#include <errno.h>
# ifdef HAVE_SYS_IOCTL_H
# endif
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_if.h"
#include "ntp_stdlib.h"
/*
* I'm still not sure I like what I've done here. It certainly consumes
* memory like it is going out of style, and also may not be as low
* overhead as I'd imagined.
*
* Anyway, we record statistics based on source address, mode and version
* (for now, anyway. Check the code). The receive procedure calls us with
* the incoming rbufp before it does anything else.
*
* Each entry is doubly linked into two lists, a hash table and a
* most-recently-used list. When a packet arrives it is looked up
* in the hash table. If found, the statistics are updated and the
* entry relinked at the head of the MRU list. If not found, a new
* entry is allocated, initialized and linked into both the hash
* table and at the head of the MRU list.
*
* Memory is usually allocated by grabbing a big chunk of new memory
* and cutting it up into littler pieces. The exception to this when we
* hit the memory limit. Then we free memory by grabbing entries off
* the tail for the MRU list, unlinking from the hash table, and
* reinitializing.
*
* trimmed back memory consumption ... jdg 8/94
*/
/*
* Limits on the number of structures allocated. This limit is picked
* with the illicit knowlege that we can only return somewhat less
* than 8K bytes in a mode 7 response packet, and that each structure
* will require about 20 bytes of space in the response.
*
* ... I don't believe the above is true anymore ... jdg
*/
#ifndef MAXMONMEM
#endif
#ifndef MONMEMINC
#endif
/*
* Hashing stuff
*/
#define MON_HASH_SIZE 128
/*
* Pointers to the hash table, the MRU list and the count table. Memory
* for the hash and count tables is only allocated if monitoring is turned on.
*/
struct mon_data mon_mru_list;
struct mon_data mon_fifo_list;
/*
* List of free structures structures, and counters of free and total
* structures. The free structures are linked with the hash_next field.
*/
static int mon_total_mem; /* total number of structures allocated */
static int mon_mem_increments; /* number of times we've called malloc() */
/*
* Initialization state. We may be monitoring, we may not. If
* we aren't, we may not even have allocated any memory yet.
*/
int mon_enabled;
static int mon_have_memory;
/*
* Imported from the timer module
*/
extern u_long current_time;
static void mon_getmoremem P((void));
static void remove_from_hash P((struct mon_data *));
/*
* init_mon - initialize monitoring global data
*/
void
init_mon()
{
/*
* Don't do much of anything here. We don't allocate memory
* until someone explicitly starts us.
*/
mon_have_memory = 0;
mon_total_mem = 0;
mon_mem_increments = 0;
}
/*
* mon_start - start up the monitoring software
*/
void
int mode;
{
if (mon_enabled != MON_OFF) {
mon_enabled |= mode;
return;
}
return; /* Ooops.. */
if (!mon_have_memory) {
mon_total_mem = 0;
mon_mem_increments = 0;
mon_have_memory = 1;
}
mon_enabled = mode;
}
/*
* mon_stop - stop the monitoring software
*/
void
int mode;
{
register int i;
if (mon_enabled == MON_OFF)
return;
return;
mon_enabled &= ~mode;
if (mon_enabled != MON_OFF)
return;
/*
* Put everything back on the free list
*/
for (i = 0; i < MON_HASH_SIZE; i++) {
}
}
}
/*
* ntp_monitor - record stats about this packet
*/
void
{
register int hash;
register int mode;
if (mon_enabled == MON_OFF)
return;
/* ?? md->interface == rbufp->dstadr && ?? */
/*
* Shuffle him to the head of the
* mru list. What a crock.
*/
return;
}
}
/*
* If we got here, this is the first we've heard of this
* guy. Get him some memory, either from the free list
* or from the tail of the MRU list.
*/
/*
* Get it from MRU list
*/
/*
* Get it from FIFO list
*/
} else {
mon_getmoremem(); /* then get more */
}
/*
* Got one, initialize it
*/
/*
* Drop him into front of the hash table.
* Also put him on top of the MRU list
* and at bottom of FIFO list
*/
}
/*
* mon_getmoremem - get more memory and put it on the free list
*/
static void
{
register int i;
for (i = 0; i < (MONMEMINC-1); i++) {
md++;
}
/*
* md now points at the last. Link in the rest of the chain.
*/
}
static void
{ register int hash;
} else {
/* logic error */
return;
}
}
}
}