]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1663] ntpdsim should not open net sockets.
authorDave Hart <hart@ntp.org>
Fri, 15 Oct 2010 00:23:01 +0000 (00:23 +0000)
committerDave Hart <hart@ntp.org>
Fri, 15 Oct 2010 00:23:01 +0000 (00:23 +0000)
bk: 4cb79ee5ycU-a2A2lt8TNCden42Ocw

ChangeLog
include/ntp_data_structures.h
ntpd/ntp_data_structures.c
ntpd/ntp_io.c
ntpd/ntp_timer.c
ntpd/ntpsim.c

index 1fb9266d1193ebf633b738d657237520982a2a27..d926abe0003d712ab78a7729e75fa9fb77fbe651 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 * [Bug 1584] from 4.2.6p3-RC3: ntpsnmpd OID must be mib-2.197.
 * [Bug 1659] from 4.2.6p3: Need CLOCK_TRUETIME not CLOCK_TRUE.
+* [Bug 1663] ntpdsim should not open net sockets.
 * [Bug 1665] from 4.2.6p3: is_anycast() u_int32_t should be u_int32.
 * from 4.2.6p3: ntpsnmpd, libntpq warning cleanup.
 * Documentation updates from Dave Mills.
index c4619236f2f9348ec940295b4808f94850b7e482..6dfd973f543a8529ce5122b3198f9f5b3005ff34 100644 (file)
@@ -27,10 +27,12 @@ typedef struct node {
 } node;
 #define node_next nodeu.next
 
+typedef int (*q_order_func)(const void *, const void *);
+
 typedef struct Queue {
-       int (*get_order)(void *, void *);
-       node *front;
-       int no_of_elements;
+       q_order_func    get_order;
+       node *          front;
+       int             no_of_elements;
 } queue;
 
 
@@ -49,7 +51,7 @@ queue *enqueue(queue *my_queue, void *my_node);
 void append_queue(queue *q1, queue *q2);
 void *dequeue(queue *my_queue);
 int get_no_of_elements(queue *my_queue);
-int get_fifo_order(void *el1, void *el2);
+int get_fifo_order(const void *el1, const void *el2);
 
 /*
  * Preserve original callsite __FILE__ and __LINE__ for these 
@@ -64,16 +66,18 @@ int get_fifo_order(void *el1, void *el2);
 #endif
 
 queue *debug_create_priority_queue(
-       int (*get_order)(void *, void *)
+       q_order_func    get_order
 #ifdef _CRTDBG_MAP_ALLOC
-       , const char *, int     /* __FILE__, __LINE__ */
-#endif
+       , const char *  sourcefile
+       , int           line_num
+#endif 
        );
 
 void *debug_get_node(
-       size_t
+       size_t          size
 #ifdef _CRTDBG_MAP_ALLOC
-       , const char *, int     /* __FILE__, __LINE__ */
+       , const char *  sourcefile
+       , int           line_num
 #endif
        );
 
index be55b429a6ab3e12d9a965b8bf59d6bafc0d15d7..e9782ff5f73c6d476bf1dad1636318b3af262fb5 100644 (file)
  * is determined by a function 'get_order' which is supplied to the
  * priority_queue
  */
-
-
 queue *debug_create_priority_queue(
-       int (*get_order)(void *, void *) 
+       q_order_func    get_order
 #ifdef _CRTDBG_MAP_ALLOC
-       , const char *sourcefile
-       , int line_num
+       , const char *  sourcefile
+       , int           line_num
 #endif 
        )
 {
@@ -234,7 +232,7 @@ void append_queue(
 /* C is not Lisp and does not allow anonymous lambda functions :-(. 
  * So define a get_fifo_order function here
  */
-int get_fifo_order(void *el1, void *el2)
+int get_fifo_order(const void *el1, const void *el2)
 {
        return 1;
 }
index 9a4d7014ddf4228162762fb571ee961c28e8b08d..0e2f5e1d2d9c10b0a50cf460dcfb442966b7b3fc 100644 (file)
@@ -587,15 +587,15 @@ collect_timing(struct recvbuf *rb, const char *tag, int count, l_fp *dts)
  */
 
 /*
- * init_io - initialize I/O data structures and call socket creation routine
+ * init_io - initialize I/O module.
  */
 void
 init_io(void)
 {
-       /*
-        * Init buffer free list and stat counters
-        */
+       /* Init buffer free list and stat counters */
        init_recvbuff(RECV_INIT);
+       /* update interface every 5 minutes as default */
+       interface_interval = 300;
 
 #ifdef SYS_WINNT
        init_io_completion_port();
index 51502ede056296d24d6a18e2ba15170af06f6b7b..5bbcd18d01d00df153dc29bb7bac036e46102d9d 100644 (file)
@@ -49,8 +49,8 @@
  * Finally, we call the hourly procedure to do cleanup and print a
  * message.
  */
-volatile int interface_interval = 300;     /* update interface every 5 minutes as default */
-         
+volatile int interface_interval;     /* init_io() sets def. 300s */
+
 /*
  * Alarm flag. The mainline code imports this.
  */
index 3a91a66b60f1bff3ccfb9a3e88067d427738a3cc..60a6a3137df4ed663878a4c20d3ccc7d3ff6f33c 100644 (file)
 #include "ntpsim.h"
 #include "ntp_data_structures.h"
 
+/* forward prototypes */
+int determine_event_ordering(const Event *e1, const Event *e2);
+int determine_recv_buf_ordering(const struct recvbuf *b1, 
+                               const struct recvbuf *b2);
+void create_server_associations(void);
 
 /* Global Variable Definitions */
-
 sim_info simulation;           /* Simulation Control Variables */
 local_clock_info simclock;     /* Local Clock Variables */
 queue *event_queue;            /* Event Queue */
@@ -29,33 +33,43 @@ void (*event_ptr[]) (Event *) = {
 };                     /* Function pointer to the events */
 
 
-/* Define a function to compare two events to determine which one occurs first
+/*
+ * Define a function to compare two events to determine which one occurs
+ * first.
  */
-
-int determine_event_ordering(Event *e1, Event *e2);
-
-int determine_event_ordering(Event *e1, Event *e2)
+int
+determine_event_ordering(
+       const Event *e1,
+       const Event *e2
+       )
 {
-    return (e1->time - e2->time);
+       return (e1->time - e2->time);
 }
 
-/* Define a function to compare two received packets to determine which one
- * is received first
- */
-int determine_recv_buf_ordering(struct recvbuf *b1, struct recvbuf *b2);
 
-int determine_recv_buf_ordering(struct recvbuf *b1, struct recvbuf *b2)
+/*
+ * Define a function to compare two received packets to determine which
+ * one is received first.
+ */
+int
+determine_recv_buf_ordering(
+       const struct recvbuf *b1,
+       const struct recvbuf *b2
+       )
 {
-    double recv_time1, recv_time2;
+       double recv_time1;
+       double recv_time2;
 
-    /* Simply convert the time received to double and subtract */
-    LFPTOD(&b1->recv_time, recv_time1);
-    LFPTOD(&b2->recv_time, recv_time2);
-    return ((int)(recv_time1 - recv_time2));
+       /* Simply convert the time received to double and subtract */
+       LFPTOD(&b1->recv_time, recv_time1);
+       LFPTOD(&b2->recv_time, recv_time2);
+
+       return (int)(recv_time1 - recv_time2);
 }
 
+
 /* Define a function to create the server associations */
-void create_server_associations()
+void create_server_associations(void)
 {
     int i;
     for (i = 0;i < simulation.num_of_servers;++i) {
@@ -80,80 +94,79 @@ void create_server_associations()
 
 /* Main Simulator Code */
 
-int ntpsim(int argc, char *argv[])
+int
+ntpsim(
+       int     argc,
+       char *  argv[]
+       )
 {
-    Event *curr_event;
-    struct timeval seed;
-
-    /* Initialize the local Clock 
-     */
-    simclock.local_time = 0;
-    simclock.adj = 0;
-    simclock.slew = 0;
-
-    /* Initialize the simulation 
-     */
-    simulation.num_of_servers = 0;
-    simulation.beep_delay = BEEP_DLY;
-    simulation.sim_time = 0;
-    simulation.end_time = SIM_TIME;
+       Event *         curr_event;
+       struct timeval  seed;
 
-    /*
-     * Initialize ntp variables
-     */
-    initializing = 1;
-    init_auth();
-    init_util();
-    init_restrict();
-    init_mon();
-    init_timer();
-    init_lib();
-    init_request();
-    init_control();
-    init_peer();
-    init_proto();
-    init_io();
-    init_loopfilter();
-    mon_start(MON_OFF);    
-
-    /* Call getconfig to parse the configuration file */
-    getconfig(argc, argv);
-    initializing = 0;
-    loop_config(LOOP_DRIFTCOMP, old_drift / 1e6);
-
-    /*
-     * Watch out here, we want the real time, not the silly stuff.
-     */
-    gettimeofday(&seed, NULL);
-    ntp_srandom(seed.tv_usec);
+       /* Initialize the local Clock */
+       simclock.local_time = 0;
+       simclock.adj = 0;
+       simclock.slew = 0;
+
+       /* Initialize the simulation */
+       simulation.num_of_servers = 0;
+       simulation.beep_delay = BEEP_DLY;
+       simulation.sim_time = 0;
+       simulation.end_time = SIM_TIME;
+
+       /* Initialize ntp modules */
+       initializing = 1;
+       init_auth();
+       init_util();
+       init_restrict();
+       init_mon();
+       init_timer();
+       init_lib();
+       init_request();
+       init_control();
+       init_peer();
+       init_proto();
+       init_loopfilter();
+       mon_start(MON_OFF);
+
+       /* Call getconfig to parse the configuration file */
+       getconfig(argc, argv);
+       initializing = 0;
+       loop_config(LOOP_DRIFTCOMP, old_drift / 1e6);
+
+       /*
+        * Watch out here, we want the real time, not the silly stuff.
+        */
+       gettimeofday(&seed, NULL);
+       ntp_srandom(seed.tv_usec);
 
+       /* Initialize the event queue */
+       event_queue = create_priority_queue((q_order_func)
+           determine_event_ordering);
 
-    /* Initialize the event queue */
-    event_queue = create_priority_queue((int(*)(void *, void*)) 
-                                       determine_event_ordering);
+       /* Initialize the receive queue */
+       recv_queue = create_priority_queue((q_order_func)
+           determine_recv_buf_ordering);
 
-    /* Initialize the receive queue */
-    recv_queue = create_priority_queue((int(*)(void *, void*))
-                                      determine_recv_buf_ordering);
+       /* Push a beep and a timer on the event queue */
+       enqueue(event_queue, event(0, BEEP));
+       enqueue(event_queue, event(simulation.sim_time + 1.0, TIMER));
 
-    /* Push a beep and a timer on the event queue */
-    enqueue(event_queue, event(0, BEEP));
-    enqueue(event_queue, event(simulation.sim_time + 1.0, TIMER));
-    /* 
-     * Pop the queue until nothing is left or time is exceeded
-     */
-    /* maxtime = simulation.sim_time + simulation.end_time;*/
-    while (simulation.sim_time <= simulation.end_time &&
+       /* 
+        * Pop the queue until nothing is left or time is exceeded
+        */
+       /* maxtime = simulation.sim_time + simulation.end_time;*/
+       while (simulation.sim_time <= simulation.end_time &&
           (!empty(event_queue))) {
-       curr_event = dequeue(event_queue);
-       /* Update all the clocks to the time on the event */
-       sim_update_clocks(curr_event);
+               curr_event = dequeue(event_queue);
+               /* Update all the clocks to the time on the event */
+               sim_update_clocks(curr_event);
 
-       /* Execute the function associated with the event */
-       event_ptr[curr_event->function](curr_event);
-       free_node(curr_event);
-    }
-    return (0);
+               /* Execute the function associated with the event */
+               (*event_ptr[curr_event->function])(curr_event);
+               free_node(curr_event);
+       }
+       return (0);
 }