extern bool rescan_listen_set;
extern bool global_in_nmbd;
+extern int num_response_packets;
+
extern bool override_logfile;
/* have we found LanMan clients yet? */
send_packet(p);
}
-/**************************************************************************** **
- The main select loop.
- **************************************************************************** */
-
-static void process(struct messaging_context *msg)
+static bool nmbd_periodic_processing(time_t t)
{
bool run_election;
- while( True ) {
- time_t t = time(NULL);
- TALLOC_CTX *frame = talloc_stackframe();
+ /*
+ * Check all broadcast subnets to see if
+ * we need to run an election on any of them.
+ * (nmbd_elections.c)
+ */
- /*
- * Check all broadcast subnets to see if
- * we need to run an election on any of them.
- * (nmbd_elections.c)
- */
+ run_election = check_elections();
- run_election = check_elections();
+ /*
+ * Read incoming UDP packets.
+ * (nmbd_packets.c)
+ */
- /*
- * Read incoming UDP packets.
- * (nmbd_packets.c)
- */
+ if (listen_for_packets(msg, run_election)) {
+ return run_election;
+ }
- if (listen_for_packets(msg, run_election)) {
- TALLOC_FREE(frame);
- return;
- }
+ /*
+ * Process all incoming packets
+ * read above. This calls the success and
+ * failure functions registered when response
+ * packets arrrive, and also deals with request
+ * packets from other sources.
+ * (nmbd_packets.c)
+ */
- /*
- * Process all incoming packets
- * read above. This calls the success and
- * failure functions registered when response
- * packets arrrive, and also deals with request
- * packets from other sources.
- * (nmbd_packets.c)
- */
+ run_packet_queue();
- run_packet_queue();
+ /*
+ * Run any elections - initiate becoming
+ * a local master browser if we have won.
+ * (nmbd_elections.c)
+ */
- /*
- * Run any elections - initiate becoming
- * a local master browser if we have won.
- * (nmbd_elections.c)
- */
+ run_elections(t);
- run_elections(t);
+ /*
+ * Send out any broadcast announcements
+ * of our server names. This also announces
+ * the workgroup name if we are a local
+ * master browser.
+ * (nmbd_sendannounce.c)
+ */
- /*
- * Send out any broadcast announcements
- * of our server names. This also announces
- * the workgroup name if we are a local
- * master browser.
- * (nmbd_sendannounce.c)
- */
+ announce_my_server_names(t);
- announce_my_server_names(t);
+ /*
+ * Send out any LanMan broadcast announcements
+ * of our server names.
+ * (nmbd_sendannounce.c)
+ */
- /*
- * Send out any LanMan broadcast announcements
- * of our server names.
- * (nmbd_sendannounce.c)
- */
+ announce_my_lm_server_names(t);
- announce_my_lm_server_names(t);
+ /*
+ * If we are a local master browser, periodically
+ * announce ourselves to the domain master browser.
+ * This also deals with syncronising the domain master
+ * browser server lists with ourselves as a local
+ * master browser.
+ * (nmbd_sendannounce.c)
+ */
- /*
- * If we are a local master browser, periodically
- * announce ourselves to the domain master browser.
- * This also deals with syncronising the domain master
- * browser server lists with ourselves as a local
- * master browser.
- * (nmbd_sendannounce.c)
- */
+ announce_myself_to_domain_master_browser(t);
- announce_myself_to_domain_master_browser(t);
+ /*
+ * Fullfill any remote announce requests.
+ * (nmbd_sendannounce.c)
+ */
- /*
- * Fullfill any remote announce requests.
- * (nmbd_sendannounce.c)
- */
+ announce_remote(t);
- announce_remote(t);
+ /*
+ * Fullfill any remote browse sync announce requests.
+ * (nmbd_sendannounce.c)
+ */
- /*
- * Fullfill any remote browse sync announce requests.
- * (nmbd_sendannounce.c)
- */
+ browse_sync_remote(t);
- browse_sync_remote(t);
+ /*
+ * Scan the broadcast subnets, and WINS client
+ * namelists and refresh any that need refreshing.
+ * (nmbd_mynames.c)
+ */
- /*
- * Scan the broadcast subnets, and WINS client
- * namelists and refresh any that need refreshing.
- * (nmbd_mynames.c)
- */
+ refresh_my_names(t);
- refresh_my_names(t);
+ /*
+ * Scan the subnet namelists and server lists and
+ * expire thos that have timed out.
+ * (nmbd.c)
+ */
- /*
- * Scan the subnet namelists and server lists and
- * expire thos that have timed out.
- * (nmbd.c)
- */
+ expire_names_and_servers(t);
+
+ /*
+ * Write out a snapshot of our current browse list into
+ * the browse.dat file. This is used by smbd to service
+ * incoming NetServerEnum calls - used to synchronise
+ * browse lists over subnets.
+ * (nmbd_serverlistdb.c)
+ */
- expire_names_and_servers(t);
+ write_browse_list(t, False);
- /*
- * Write out a snapshot of our current browse list into
- * the browse.dat file. This is used by smbd to service
- * incoming NetServerEnum calls - used to synchronise
- * browse lists over subnets.
- * (nmbd_serverlistdb.c)
- */
+ /*
+ * If we are a domain master browser, we have a list of
+ * local master browsers we should synchronise browse
+ * lists with (these are added by an incoming local
+ * master browser announcement packet). Expire any of
+ * these that are no longer current, and pull the server
+ * lists from each of these known local master browsers.
+ * (nmbd_browsesync.c)
+ */
- write_browse_list(t, False);
+ dmb_expire_and_sync_browser_lists(t);
- /*
- * If we are a domain master browser, we have a list of
- * local master browsers we should synchronise browse
- * lists with (these are added by an incoming local
- * master browser announcement packet). Expire any of
- * these that are no longer current, and pull the server
- * lists from each of these known local master browsers.
- * (nmbd_browsesync.c)
- */
+ /*
+ * Check that there is a local master browser for our
+ * workgroup for all our broadcast subnets. If one
+ * is not found, start an election (which we ourselves
+ * may or may not participate in, depending on the
+ * setting of the 'local master' parameter.
+ * (nmbd_elections.c)
+ */
- dmb_expire_and_sync_browser_lists(t);
+ check_master_browser_exists(t);
- /*
- * Check that there is a local master browser for our
- * workgroup for all our broadcast subnets. If one
- * is not found, start an election (which we ourselves
- * may or may not participate in, depending on the
- * setting of the 'local master' parameter.
- * (nmbd_elections.c)
- */
+ /*
+ * If we are configured as a logon server, attempt to
+ * register the special NetBIOS names to become such
+ * (WORKGROUP<1c> name) on all broadcast subnets and
+ * with the WINS server (if used). If we are configured
+ * to become a domain master browser, attempt to register
+ * the special NetBIOS name (WORKGROUP<1b> name) to
+ * become such.
+ * (nmbd_become_dmb.c)
+ */
- check_master_browser_exists(t);
+ add_domain_names(t);
- /*
- * If we are configured as a logon server, attempt to
- * register the special NetBIOS names to become such
- * (WORKGROUP<1c> name) on all broadcast subnets and
- * with the WINS server (if used). If we are configured
- * to become a domain master browser, attempt to register
- * the special NetBIOS name (WORKGROUP<1b> name) to
- * become such.
- * (nmbd_become_dmb.c)
- */
+ /*
+ * If we are a WINS server, do any timer dependent
+ * processing required.
+ * (nmbd_winsserver.c)
+ */
- add_domain_names(t);
+ initiate_wins_processing(t);
- /*
- * If we are a WINS server, do any timer dependent
- * processing required.
- * (nmbd_winsserver.c)
- */
+ /*
+ * If we are a domain master browser, attempt to contact the
+ * WINS server to get a list of all known WORKGROUPS/DOMAINS.
+ * This will only work to a Samba WINS server.
+ * (nmbd_browsesync.c)
+ */
- initiate_wins_processing(t);
+ if (lp_enhanced_browsing())
+ collect_all_workgroup_names_from_wins_server(t);
- /*
- * If we are a domain master browser, attempt to contact the
- * WINS server to get a list of all known WORKGROUPS/DOMAINS.
- * This will only work to a Samba WINS server.
- * (nmbd_browsesync.c)
- */
+ /*
+ * Go through the response record queue and time out or re-transmit
+ * and expired entries.
+ * (nmbd_packets.c)
+ */
- if (lp_enhanced_browsing())
- collect_all_workgroup_names_from_wins_server(t);
+ retransmit_or_expire_response_records(t);
- /*
- * Go through the response record queue and time out or re-transmit
- * and expired entries.
- * (nmbd_packets.c)
- */
+ /*
+ * check to see if any remote browse sync child processes have completed
+ */
- retransmit_or_expire_response_records(t);
+ sync_check_completion();
- /*
- * check to see if any remote browse sync child processes have completed
- */
+ /*
+ * regularly sync with any other DMBs we know about
+ */
- sync_check_completion();
+ if (lp_enhanced_browsing())
+ sync_all_dmbs(t);
- /*
- * regularly sync with any other DMBs we know about
- */
+ /* check for new network interfaces */
+
+ reload_interfaces(t);
+
+ return run_election;
+}
+
+
+static void nmbd_periodic_timer_event(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval current_time,
+ void *private_data)
+{
+ time_t t = current_time.tv_sec;
+ struct timeval next;
+ bool run_elections;
+
+ run_elections = nmbd_periodic_processing(t);
+
+ if (run_election || num_response_packets) {
+ next = timeval_current_ofs_msec(1000);
+ } else {
+ next = timeval_current_ofs_msec(NMBD_SELECT_LOOP * 1000);
+ }
- if (lp_enhanced_browsing())
- sync_all_dmbs(t);
+ te = tevent_add_timer(nmbd_event_context(),
+ msg,
+ next,
+ nmbd_periodic_timer_event,
+ NULL);
+ if (te == NULL) {
- /* check for new network interfaces */
+ }
+}
+/**************************************************************************** **
+ The main select loop.
+ **************************************************************************** */
+
+static void process(struct messaging_context *msg)
+{
+ struct tevent_timer *te = NULL;
+
+static void nmbd_periodic_timer_event(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval current_time,
+ void *private_data);
+ te = tevent_add_timer(nmbd_event_context(),
+ msg,
+ timeval_current(),
+ nmbd_periodic_timer_event,
+ NULL);
+ if (te == NULL) {
+
+ }
+
+ while( True ) {
+ time_t t = time(NULL);
+ TALLOC_CTX *frame = talloc_stackframe();
- reload_interfaces(t);
+ nmbd_periodic_processing(t);
/* free up temp memory */
TALLOC_FREE(frame);