From: Dave Hart Date: Fri, 15 Oct 2010 00:23:01 +0000 (+0000) Subject: [Bug 1663] ntpdsim should not open net sockets. X-Git-Tag: NTP_4_2_7P64~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58025e667fc09d2c29c6351cf8726fdfe6852141;p=thirdparty%2Fntp.git [Bug 1663] ntpdsim should not open net sockets. bk: 4cb79ee5ycU-a2A2lt8TNCden42Ocw --- diff --git a/ChangeLog b/ChangeLog index 1fb9266d1..d926abe00 100644 --- 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. diff --git a/include/ntp_data_structures.h b/include/ntp_data_structures.h index c4619236f..6dfd973f5 100644 --- a/include/ntp_data_structures.h +++ b/include/ntp_data_structures.h @@ -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 ); diff --git a/ntpd/ntp_data_structures.c b/ntpd/ntp_data_structures.c index be55b429a..e9782ff5f 100644 --- a/ntpd/ntp_data_structures.c +++ b/ntpd/ntp_data_structures.c @@ -21,13 +21,11 @@ * 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; } diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 9a4d7014d..0e2f5e1d2 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -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(); diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 51502ede0..5bbcd18d0 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -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. */ diff --git a/ntpd/ntpsim.c b/ntpd/ntpsim.c index 3a91a66b6..60a6a3137 100644 --- a/ntpd/ntpsim.c +++ b/ntpd/ntpsim.c @@ -15,9 +15,13 @@ #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); }