state back to potential browser, or none.
******************************************************************/
-static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name )
+static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name,
+ BOOL force_new_election )
{
struct work_record *work;
struct server_record *servrec;
remove_permanent_name_from_unicast( subrec, &nmbname);
+ if(force_new_election)
+ work->needelection = True;
}
/*******************************************************************
struct nmb_name *released_name,
struct in_addr released_ip)
{
+ BOOL force_new_election = False;
+
+ memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
+
DEBUG(3,("unbecome_local_master_success: released name %s.\n",
namestr(released_name)));
/* Now reset the workgroup and server state. */
- reset_workgroup_state( subrec, released_name->name );
+ reset_workgroup_state( subrec, released_name->name, force_new_election );
DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \
on subnet %s *****\n\n", timestring(), global_myname, released_name->name, subrec->subnet_name));
struct nmb_name *fail_name)
{
struct name_record *namerec;
+ struct userdata_struct *userdata = rrec->userdata;
+ BOOL force_new_election = False;
+
+ memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL));
DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \
Removing from namelist anyway.\n", namestr(fail_name)));
remove_name_from_namelist(subrec, namerec);
/* Now reset the workgroup and server state. */
- reset_workgroup_state( subrec, fail_name->name );
+ reset_workgroup_state( subrec, fail_name->name, force_new_election );
DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \
on subnet %s *****\n\n", timestring(), global_myname, fail_name->name, subrec->subnet_name));
-
}
/*******************************************************************
- Utility function to remove the WORKGROUP<1d> name called by both
- success and fail of releasing the MSBROWSE name.
+ Utility function to remove the WORKGROUP<1d> name.
******************************************************************/
-void release_1d_name( struct subnet_record *subrec, char *workgroup_name)
+static void release_1d_name( struct subnet_record *subrec, char *workgroup_name,
+ BOOL force_new_election)
{
struct nmb_name nmbname;
struct name_record *namerec;
make_nmb_name(&nmbname, workgroup_name, 0x1d, scope);
if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL)
{
+ struct userdata_struct *userdata;
+
+ if((userdata = (struct userdata_struct *)malloc(
+ sizeof(struct userdata_struct) + sizeof(BOOL))) == NULL)
+ {
+ DEBUG(0,("release_1d_name: malloc fail.\n"));
+ return;
+ }
+
+ userdata->copy_fn = NULL;
+ userdata->free_fn = NULL;
+ userdata->userdata_len = sizeof(BOOL);
+ memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL));
+
release_name(subrec, namerec,
unbecome_local_master_success,
unbecome_local_master_fail,
- NULL);
+ userdata);
+
+ free((char *)userdata);
}
}
/* Remove the permanent MSBROWSE name added into the unicast subnet. */
remove_permanent_name_from_unicast( subrec, released_name);
-
- release_1d_name( subrec, userdata->data );
}
/*******************************************************************
struct response_record *rrec,
struct nmb_name *fail_name)
{
- struct userdata_struct *userdata = rrec->userdata;
struct name_record *namerec;
DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.",
/* Remove the permanent MSBROWSE name added into the unicast subnet. */
remove_permanent_name_from_unicast( subrec, fail_name);
-
- release_1d_name( subrec, userdata->data );
}
/*******************************************************************
- Unbecome the local master browser.
+ Unbecome the local master browser. If force_new_election is true, restart
+ the election process after we've unbecome the local master.
******************************************************************/
-void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work)
+void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work,
+ BOOL force_new_election)
{
struct server_record *servrec;
struct name_record *namerec;
struct nmb_name nmbname;
- struct userdata_struct *userdata;
/* Sanity check. */
/* Set the state to unbecoming. */
work->mst_state = MST_UNBECOMING_MASTER;
- /* Setup the userdata for the MSBROWSE name release. */
- if((userdata = (struct userdata_struct *)malloc( sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL)
- {
- DEBUG(0,("unbecome_local_master_browser: malloc fail.\n"));
- return;
- }
+ /*
+ * Release the WORKGROUP<1d> name asap to allow another machine to
+ * claim it.
+ */
- userdata->copy_fn = NULL;
- userdata->free_fn = NULL;
- userdata->userdata_len = strlen(work->work_group)+1;
- pstrcpy(userdata->data, work->work_group);
+ release_1d_name( subrec, work->work_group, force_new_election);
/* Deregister any browser names we may have. */
make_nmb_name(&nmbname, MSBROWSE, 0x1, scope);
release_name(subrec, namerec,
release_msbrowse_name_success,
release_msbrowse_name_fail,
- userdata);
+ NULL);
}
- free((char *)userdata);
+ /*
+ * Ensure we have sent and processed these release packets
+ * before returning - we don't want to process any election
+ * packets before dealing with the 1d release.
+ */
+
+ retransmit_or_expire_response_records(time(NULL));
}
/****************************************************************************
}
/* Roll back all the way by calling unbecome_local_master_browser(). */
- unbecome_local_master_browser(subrec, work);
+ unbecome_local_master_browser(subrec, work, False);
}
/****************************************************************************
return;
}
- reset_workgroup_state( subrec, work->work_group );
+ reset_workgroup_state( subrec, work->work_group, False );
DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \
workgroup %s on subnet %s. Couldn't register name %s.\n",
extern int DEBUGLEVEL;
+extern pstring scope;
+
extern pstring global_myname;
extern fstring global_myworkgroup;
p = skip_string(p,1);
send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
- server_name, 0,
+ global_myname, 0,
workgroup_name, 0x1e,
subrec->bcast_ip, subrec->myip);
}
not to become the local master, but we still need one,
having detected that one doesn't exist.
*/
- send_election_dgram(subrec, work->work_group, 0, 0, global_myname);
+ send_election_dgram(subrec, work->work_group, 0, 0, "");
}
}
}
struct subnet_record *subrec;
- /* Send election packets once a second - note */
- if (lastime && (t - lastime <= 0))
+ /* Send election packets once every 2 seconds - note */
+ if (lastime && (t - lastime < 2))
return;
lastime = t;
{
if (work->RunningElection)
{
+ /*
+ * We can only run an election for a workgroup if we have
+ * registered the WORKGROUP<1e> name, as that's the name
+ * we must listen to.
+ */
+ struct nmb_name nmbname;
+
+ make_nmb_name(&nmbname, work->work_group, 0x1e, scope);
+ if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
+ DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \
+yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name ));
+ continue;
+ }
+
send_election_dgram(subrec, work->work_group, work->ElectionCriterion,
t - StartupTime, global_myname);
DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n",
work->work_group, subrec->subnet_name ));
if (AM_LOCAL_MASTER_BROWSER(work))
- unbecome_local_master_browser(subrec, work);
+ unbecome_local_master_browser(subrec, work, False);
}
}
}
/* Only start an election if we are in the potential browser state. */
if (work->needelection && !work->RunningElection && AM_POTENTIAL_MASTER_BROWSER(work))
{
+ /*
+ * We can only run an election for a workgroup if we have
+ * registered the WORKGROUP<1e> name, as that's the name
+ * we must listen to.
+ */
+ struct nmb_name nmbname;
+
+ make_nmb_name(&nmbname, work->work_group, 0x1e, scope);
+ if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) {
+ DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \
+yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name ));
+ continue;
+ }
+
DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n",
work->work_group, subrec->subnet_name ));
work->ElectionCount = 0;
work->RunningElection = True;
work->needelection = False;
+
+ /* Send a force election packet to begin. */
+ send_election_dgram(subrec, work->work_group, 0, 0, "");
}
}
}