]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Reduce size of NTP sources hash table
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 13 Oct 2009 15:16:41 +0000 (17:16 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 13 Oct 2009 15:16:41 +0000 (17:16 +0200)
IPv6 addressing significantly increased size of the table,
keep only pointers to get it back.

ntp_core.c
ntp_core.h
ntp_sources.c

index daee104d204f7a5d5f49b96ee8a44806df5a4d68..8a6ea203e9dfbaf4473484f31ff3d3b793c4e20a 100644 (file)
@@ -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;
+}
+
+/* ================================================== */
index 86926c499f45614522c7b79231deb3d6e947189b..9691cf8f0a0fb7b2d74a87a3cbcfc0c78f4db509 100644 (file)
@@ -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 */
index 7d4c5ba86b46a324a89d2974720f488b0d5eba82..9040eb4cd0f7817bc5ebde9a23eb33cddea953cb 100644 (file)
@@ -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<N_RECORDS; i++) {
-    records[i].in_use = 0;
+    records[i].remote_addr = NULL;
   }
   n_sources = 0;
   initialised = 1;
@@ -147,15 +147,15 @@ find_slot(NTP_Remote_Address *remote_addr, int *slot, int *found)
   hash = ip ^ (ip >> 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; i<N_RECORDS; i++) {
-    if (records[i].in_use) {
+    if (records[i].remote_addr) {
 #if 0
       LOG(LOGS_INFO, LOGF_Sources, "IP=%s dfreq=%f doff=%f",
-          UTI_IPToString(&records[i].remote_addr.ip_addr), dfreq, doffset);
+          UTI_IPToString(&records[i].remote_addr->ip_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; i<N_RECORDS; i++) {
-    if (records[i].in_use) {
+    if (records[i].remote_addr) {
       if (address->family == 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; i<N_RECORDS; i++) {
-    if (records[i].in_use) {
+    if (records[i].remote_addr) {
       if (address->family == 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; i<N_RECORDS; i++) {
-    if (records[i].in_use) {
+    if (records[i].remote_addr) {
       if (address->family == 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; i<N_RECORDS; i++) {
-    if (records[i].in_use) {
+    if (records[i].remote_addr) {
       NCR_IncrementActivityCounters(records[i].data, &report->online, &report->offline,
                                     &report->burst_online, &report->burst_offline);
     }