#include "includes.h"
-extern int DEBUGLEVEL;
-
-extern pstring scope;
-
extern pstring global_myname;
extern fstring global_myworkgroup;
DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n",
workgroup_name, subrec->subnet_name ));
- bzero(outbuf,sizeof(outbuf));
+ memset(outbuf,'\0',sizeof(outbuf));
p = outbuf;
- CVAL(p,0) = ANN_Election; /* Election opcode. */
+ SCVAL(p,0,ANN_Election); /* Election opcode. */
p++;
- CVAL(p,0) = (criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION;
+ SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION));
SIVAL(p,1,criterion);
SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */
p += 13;
send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf),
global_myname, 0,
workgroup_name, 0x1e,
- subrec->bcast_ip, subrec->myip);
+ subrec->bcast_ip, subrec->myip, DGRAM_PORT);
}
/*******************************************************************
lastime = t;
+ START_PROFILE(run_elections);
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
{
struct work_record *work;
*/
struct nmb_name nmbname;
- make_nmb_name(&nmbname, work->work_group, 0x1e, scope);
+ make_nmb_name(&nmbname, work->work_group, 0x1e);
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 ));
+yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
continue;
}
}
}
}
+ END_PROFILE(run_elections);
}
/*******************************************************************
struct work_record *work;
char *workgroup_name = dgram->dest_name.name;
+ START_PROFILE(election);
server_name[15] = 0;
DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n",
{
DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n",
workgroup_name, subrec->subnet_name ));
- return;
+ goto done;
}
if (!strequal(work->work_group, global_myworkgroup))
{
DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \
is not my workgroup.\n", work->work_group, subrec->subnet_name ));
- return;
+ goto done;
}
if (win_election(work, version,criterion,timeup,server_name))
unbecome_local_master_browser(subrec, work, False);
}
}
+done:
+ END_PROFILE(election);
}
/****************************************************************************
*/
struct nmb_name nmbname;
- make_nmb_name(&nmbname, work->work_group, 0x1e, scope);
+ make_nmb_name(&nmbname, work->work_group, 0x1e);
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 ));
+yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name ));
continue;
}
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, "");
}
}
}
return run_any_election;
}
+
+
+
+/****************************************************************************
+process a internal Samba message forcing an election
+***************************************************************************/
+void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len)
+{
+ struct subnet_record *subrec;
+
+ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
+ struct work_record *work;
+ for (work = subrec->workgrouplist; work; work = work->next) {
+ if (strequal(work->work_group, global_myworkgroup)) {
+ work->needelection = True;
+ work->ElectionCount=0;
+ work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
+ }
+ }
+ }
+}