From 48b6c2aa6b9a80c09aacfb8289bb11e51be48b33 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 13 Oct 2009 17:16:41 +0200 Subject: [PATCH] Reduce size of NTP sources hash table IPv6 addressing significantly increased size of the table, keep only pointers to get it back. --- ntp_core.c | 8 ++++++++ ntp_core.h | 2 ++ ntp_sources.c | 40 +++++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index daee104..8a6ea20 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1912,3 +1912,11 @@ NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *offline, } /* ================================================== */ + +NTP_Remote_Address * +NCR_GetRemoteAddress(NCR_Instance inst) +{ + return &inst->remote_addr; +} + +/* ================================================== */ diff --git a/ntp_core.h b/ntp_core.h index 86926c4..9691cf8 100644 --- a/ntp_core.h +++ b/ntp_core.h @@ -102,4 +102,6 @@ extern void NCR_CycleLogFile(void); extern void NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *offline, int *burst_online, int *burst_offline); +extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance); + #endif /* GOT_NTP_CORE_H */ diff --git a/ntp_sources.c b/ntp_sources.c index 7d4c5ba..9040eb4 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -43,8 +43,8 @@ /* Record type private to this file, used to store information about particular sources */ typedef struct { - NTP_Remote_Address remote_addr; /* The address of this source */ - int in_use; /* Whether this slot in the table is in use */ + NTP_Remote_Address *remote_addr; /* The address of this source, non-NULL + means this slot in table is in use */ NCR_Instance data; /* Data for the protocol engine for this source */ } SourceRecord; @@ -83,7 +83,7 @@ NSR_Initialise(void) { int i; for (i=0; i> 16); hash = (hash ^ (hash >> 8)) & 0xff; - while ((records[hash].in_use) && - UTI_CompareIPs(&records[hash].remote_addr.ip_addr, + while (records[hash].remote_addr && + UTI_CompareIPs(&records[hash].remote_addr->ip_addr, &remote_addr->ip_addr, NULL)) { hash++; if (hash == 256) hash = 0; } - if (records[hash].in_use) { - if (records[hash].remote_addr.port == port) { + if (records[hash].remote_addr) { + if (records[hash].remote_addr->port == port) { *found = 2; } else { *found = 1; @@ -196,9 +196,8 @@ NSR_AddServer(NTP_Remote_Address *remote_addr, SourceParameters *params) return NSR_InvalidAF; } else { n_sources++; - records[slot].remote_addr = *remote_addr; - records[slot].in_use = 1; records[slot].data = NCR_GetServerInstance(remote_addr, params); /* Will need params passing through */ + records[slot].remote_addr = NCR_GetRemoteAddress(records[slot].data); return NSR_Success; } } @@ -230,9 +229,8 @@ NSR_AddPeer(NTP_Remote_Address *remote_addr, SourceParameters *params) return NSR_InvalidAF; } else { n_sources++; - records[slot].remote_addr = *remote_addr; - records[slot].in_use = 1; records[slot].data = NCR_GetPeerInstance(remote_addr, params); /* Will need params passing through */ + records[slot].remote_addr = NCR_GetRemoteAddress(records[slot].data); return NSR_Success; } } @@ -256,7 +254,7 @@ NSR_RemoveSource(NTP_Remote_Address *remote_addr) return NSR_NoSuchSource; } else { n_sources--; - records[slot].in_use = 0; + records[slot].remote_addr = NULL; NCR_DestroyInstance(records[slot].data); return NSR_Success; } @@ -318,10 +316,10 @@ slew_sources(struct timeval *raw, int i; for (i=0; iip_addr), dfreq, doffset); #endif NCR_SlewTimes(records[i].data, cooked, dfreq, doffset); @@ -340,9 +338,9 @@ NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address) any = 0; for (i=0; ifamily == IPADDR_UNSPEC || - !UTI_CompareIPs(&records[i].remote_addr.ip_addr, address, mask)) { + !UTI_CompareIPs(&records[i].remote_addr->ip_addr, address, mask)) { any = 1; NCR_TakeSourceOnline(records[i].data); } @@ -362,9 +360,9 @@ NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address) any = 0; for (i=0; ifamily == IPADDR_UNSPEC || - !UTI_CompareIPs(&records[i].remote_addr.ip_addr, address, mask)) { + !UTI_CompareIPs(&records[i].remote_addr->ip_addr, address, mask)) { any = 1; NCR_TakeSourceOffline(records[i].data); } @@ -461,9 +459,9 @@ NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples, any = 0; for (i=0; ifamily == IPADDR_UNSPEC || - !UTI_CompareIPs(&records[i].remote_addr.ip_addr, address, mask)) { + !UTI_CompareIPs(&records[i].remote_addr->ip_addr, address, mask)) { any = 1; NCR_InitiateSampleBurst(records[i].data, n_good_samples, n_total_samples); } @@ -508,7 +506,7 @@ NSR_GetActivityReport(RPT_ActivityReport *report) report->burst_offline = 0; for (i=0; ionline, &report->offline, &report->burst_online, &report->burst_offline); }