Commit 424eb38c authored by Mike Hibler's avatar Mike Hibler

Replace lots of individual checks for "is node allocated?" with one central

check.  There is now a per-command flag indicating whether the calling
node must be allocated to an experiment to use the command.
parent 7b82a611
......@@ -243,6 +243,7 @@ COMMAND_PROTOTYPE(dotmcctest);
#define F_REMUDP 0x1 /* remote nodes can request using UDP */
#define F_MINLOG 0x2 /* record minimal logging info normally */
#define F_MAXLOG 0x4 /* record maximal logging info normally */
#define F_ALLOCATED 0x8 /* node must be allocated to make call */
struct command {
char *cmdname;
......@@ -253,46 +254,46 @@ struct command {
{ "reboot", FULLCONFIG_NONE, 0, doreboot },
{ "nodeid", FULLCONFIG_ALL, 0, donodeid },
{ "status", FULLCONFIG_NONE, 0, dostatus },
{ "ifconfig", FULLCONFIG_ALL, 0, doifconfig },
{ "ifconfig", FULLCONFIG_ALL, F_ALLOCATED, doifconfig },
{ "accounts", FULLCONFIG_ALL, 0, doaccounts },
{ "delay", FULLCONFIG_ALL, 0, dodelay },
{ "linkdelay", FULLCONFIG_ALL, 0, dolinkdelay },
{ "hostnames", FULLCONFIG_NONE, 0, dohosts },
{ "rpms", FULLCONFIG_ALL, 0, dorpms },
{ "deltas", FULLCONFIG_NONE, 0, dodeltas },
{ "tarballs", FULLCONFIG_ALL, 0, dotarballs },
{ "startupcmd", FULLCONFIG_ALL, 0, dostartcmd },
{ "startstatus", FULLCONFIG_NONE, 0, dostartstat }, /* Before startstat*/
{ "delay", FULLCONFIG_ALL, F_ALLOCATED, dodelay },
{ "linkdelay", FULLCONFIG_ALL, F_ALLOCATED, dolinkdelay },
{ "hostnames", FULLCONFIG_NONE, F_ALLOCATED, dohosts },
{ "rpms", FULLCONFIG_ALL, F_ALLOCATED, dorpms },
{ "deltas", FULLCONFIG_NONE, F_ALLOCATED, dodeltas },
{ "tarballs", FULLCONFIG_ALL, F_ALLOCATED, dotarballs },
{ "startupcmd", FULLCONFIG_ALL, F_ALLOCATED, dostartcmd },
{ "startstatus", FULLCONFIG_NONE, F_ALLOCATED, dostartstat }, /* Before startstat*/
{ "startstat", FULLCONFIG_NONE, 0, dostartstat },
{ "readycount", FULLCONFIG_NONE, 0, doreadycount },
{ "ready", FULLCONFIG_NONE, 0, doready },
{ "mounts", FULLCONFIG_ALL, 0, domounts },
{ "sfshostid", FULLCONFIG_NONE, 0, dosfshostid },
{ "readycount", FULLCONFIG_NONE, F_ALLOCATED, doreadycount },
{ "ready", FULLCONFIG_NONE, F_ALLOCATED, doready },
{ "mounts", FULLCONFIG_ALL, F_ALLOCATED, domounts },
{ "sfshostid", FULLCONFIG_NONE, F_ALLOCATED, dosfshostid },
{ "loadinfo", FULLCONFIG_NONE, 0, doloadinfo},
{ "reset", FULLCONFIG_NONE, 0, doreset},
{ "routing", FULLCONFIG_ALL, 0, dorouting},
{ "trafgens", FULLCONFIG_ALL, 0, dotrafgens},
{ "nseconfigs", FULLCONFIG_ALL, 0, donseconfigs},
{ "creator", FULLCONFIG_ALL, 0, docreator},
{ "routing", FULLCONFIG_ALL, F_ALLOCATED, dorouting},
{ "trafgens", FULLCONFIG_ALL, F_ALLOCATED, dotrafgens},
{ "nseconfigs", FULLCONFIG_ALL, F_ALLOCATED, donseconfigs},
{ "creator", FULLCONFIG_ALL, F_ALLOCATED, docreator},
{ "state", FULLCONFIG_NONE, 0, dostate},
{ "tunnels", FULLCONFIG_ALL, 0, dotunnels},
{ "tunnels", FULLCONFIG_ALL, F_ALLOCATED, dotunnels},
{ "vnodelist", FULLCONFIG_PHYS, 0, dovnodelist},
{ "subnodelist", FULLCONFIG_PHYS, 0, dosubnodelist},
{ "subnodelist", FULLCONFIG_PHYS, F_ALLOCATED, dosubnodelist},
{ "isalive", FULLCONFIG_NONE, F_REMUDP|F_MINLOG, doisalive},
{ "ipodinfo", FULLCONFIG_NONE, 0, doipodinfo},
{ "ntpinfo", FULLCONFIG_PHYS, 0, dontpinfo},
{ "ntpdrift", FULLCONFIG_NONE, 0, dontpdrift},
{ "jailconfig", FULLCONFIG_VIRT, 0, dojailconfig},
{ "plabconfig", FULLCONFIG_VIRT, 0, doplabconfig},
{ "subconfig", FULLCONFIG_NONE, 0, dosubconfig},
{ "jailconfig", FULLCONFIG_VIRT, F_ALLOCATED, dojailconfig},
{ "plabconfig", FULLCONFIG_VIRT, F_ALLOCATED, doplabconfig},
{ "subconfig", FULLCONFIG_NONE, F_ALLOCATED, dosubconfig},
{ "sdparams", FULLCONFIG_PHYS, 0, doslothdparams},
{ "programs", FULLCONFIG_ALL, 0, doprogagents},
{ "syncserver", FULLCONFIG_ALL, 0, dosyncserver},
{ "keyhash", FULLCONFIG_ALL, 0, dokeyhash},
{ "eventkey", FULLCONFIG_ALL, 0, doeventkey},
{ "fullconfig", FULLCONFIG_NONE, 0, dofullconfig},
{ "routelist", FULLCONFIG_PHYS, 0, doroutelist},
{ "role", FULLCONFIG_PHYS, 0, dorole},
{ "programs", FULLCONFIG_ALL, F_ALLOCATED, doprogagents},
{ "syncserver", FULLCONFIG_ALL, F_ALLOCATED, dosyncserver},
{ "keyhash", FULLCONFIG_ALL, F_ALLOCATED, dokeyhash},
{ "eventkey", FULLCONFIG_ALL, F_ALLOCATED, doeventkey},
{ "fullconfig", FULLCONFIG_NONE, F_ALLOCATED, dofullconfig},
{ "routelist", FULLCONFIG_PHYS, F_ALLOCATED, doroutelist},
{ "role", FULLCONFIG_PHYS, F_ALLOCATED, dorole},
{ "rusage", FULLCONFIG_NONE, F_REMUDP|F_MINLOG, dorusage},
{ "watchdoginfo", FULLCONFIG_NONE, F_REMUDP|F_MINLOG, dodoginfo},
{ "hostkeys", FULLCONFIG_NONE, 0, dohostkeys},
......@@ -1023,11 +1024,18 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int istcp)
*/
if (!istcp && !reqp->islocal &&
(command_array[i].flags & F_REMUDP) == 0) {
error("%s: Invalid request (%s) from remote node using UDP!\n",
error("%s: %s: Invalid UDP request from remote node\n",
reqp->nodeid, command_array[i].cmdname);
goto skipit;
}
if (!reqp->allocated && (command_array[i].flags & F_ALLOCATED) != 0) {
if (verbose || (command_array[i].flags & F_MINLOG) == 0)
error("%s: %s: Invalid request from free node\n",
reqp->nodeid, command_array[i].cmdname);
goto skipit;
}
/*
* Execute it.
*/
......@@ -1096,7 +1104,7 @@ COMMAND_PROTOTYPE(dostatus)
* Now check reserved table
*/
if (! reqp->allocated) {
info("STATUS: %s: Node is free\n", reqp->nodeid);
info("STATUS: %s: FREE\n", reqp->nodeid);
strcpy(buf, "FREE\n");
client_writeback(sock, buf, strlen(buf), tcp);
return 0;
......@@ -1123,15 +1131,6 @@ COMMAND_PROTOTYPE(doifconfig)
int nrows;
int num_interfaces=0;
/*
* Now check reserved table
*/
if (! reqp->allocated) {
if (verbose)
info("IFCONFIG: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* For Virtual Nodes, we return interfaces that belong to it.
*/
......@@ -1500,7 +1499,8 @@ COMMAND_PROTOTYPE(doaccounts)
* Now check reserved table
*/
if ((reqp->islocal || reqp->isvnode) && !reqp->allocated) {
error("ACCOUNTS: %s: Node is free\n", reqp->nodeid);
error("%s: accounts: Invalid request from free node\n",
reqp->nodeid);
return 1;
}
......@@ -2006,12 +2006,6 @@ COMMAND_PROTOTYPE(dodelay)
char buf[2*MYBUFSIZE], *ebufp = &buf[sizeof(buf)];
int nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Get delay parameters for the machine. The point of this silly
* join is to get the type out so that we can pass it back. Of
......@@ -2119,12 +2113,6 @@ COMMAND_PROTOTYPE(dolinkdelay)
char buf[2*MYBUFSIZE];
int nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Get link delay parameters for the machine. We store veth
* interfaces in another dynamic table, so must join with both
......@@ -2232,12 +2220,6 @@ COMMAND_PROTOTYPE(dohosts)
struct hostentry *next;
} *hosts = 0, *host;
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Now use the virt_nodes table to get a list of all of the
* nodes and all of the IPs on those nodes. This is the basis
......@@ -2453,12 +2435,6 @@ COMMAND_PROTOTYPE(dorpms)
MYSQL_ROW row;
char buf[MYBUFSIZE], *bp, *sp;
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Get RPM list for the node.
*/
......@@ -2509,12 +2485,6 @@ COMMAND_PROTOTYPE(dotarballs)
MYSQL_ROW row;
char buf[MYBUFSIZE], *bp, *sp, *tp;
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Get Tarball list for the node.
*/
......@@ -2578,12 +2548,6 @@ COMMAND_PROTOTYPE(dostartcmd)
MYSQL_ROW row;
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
/*
* Get run command for the node.
*/
......@@ -2625,12 +2589,6 @@ COMMAND_PROTOTYPE(dostartstat)
{
int exitstatus;
/*
* Make sure currently allocated to an experiment!
*/
if (!reqp->allocated)
return 0;
/*
* Dig out the exit status
*/
......@@ -2664,12 +2622,6 @@ COMMAND_PROTOTYPE(dostartstat)
*/
COMMAND_PROTOTYPE(doready)
{
/*
* Make sure currently allocated to an experiment!
*/
if (!reqp->allocated)
return 0;
/*
* Vnodes not allowed!
*/
......@@ -2705,12 +2657,6 @@ COMMAND_PROTOTYPE(doreadycount)
char buf[MYBUFSIZE];
int total, ready, i;
/*
* Make sure currently allocated to an experiment!
*/
if (!reqp->allocated)
return 0;
/*
* Vnodes not allowed!
*/
......@@ -2765,14 +2711,6 @@ COMMAND_PROTOTYPE(domounts)
int nrows;
int usesfs;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("MOUNTS: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* Should SFS mounts be served?
*/
......@@ -3072,14 +3010,6 @@ COMMAND_PROTOTYPE(dosfshostid)
return 0;
}
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("dosfshostid: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* Dig out the hostid. Need to be careful about not overflowing
* the buffer.
......@@ -3140,14 +3070,6 @@ COMMAND_PROTOTYPE(dorouting)
char buf[MYBUFSIZE];
int n, nrows, isstatic = 0;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("ROUTES: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* Get the routing type from the nodes table.
*/
......@@ -3385,14 +3307,6 @@ COMMAND_PROTOTYPE(dotrafgens)
char buf[MYBUFSIZE];
int nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("TRAFGENS: %s: Node is free\n", reqp->nodeid);
return 1;
}
res = mydb_query("select vi.vname,role,proto,"
" vnode,port,ip,target_vnode,target_port,target_ip, "
" generator "
......@@ -3460,14 +3374,6 @@ COMMAND_PROTOTYPE(donseconfigs)
return 1;
}
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("NSECONFIGS: %s: Node is free\n", reqp->nodeid);
return 1;
}
res = mydb_query("select nseconfig from nseconfigs as nse "
"where nse.pid='%s' and nse.eid='%s' "
"and nse.vname='%s'",
......@@ -3555,12 +3461,6 @@ COMMAND_PROTOTYPE(docreator)
{
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated)
return 0;
OUTPUT(buf, sizeof(buf), "CREATOR=%s\n", reqp->creator);
client_writeback(sock, buf, strlen(buf), tcp);
if (verbose)
......@@ -3578,14 +3478,6 @@ COMMAND_PROTOTYPE(dotunnels)
char buf[MYBUFSIZE];
int nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("TRAFGENS: %s: Node is free\n", reqp->nodeid);
return 1;
}
res = mydb_query("select vname,isserver,peer_ip,port,password, "
" encrypt,compress,assigned_ip,proto,mask "
"from tunnels where node_id='%s'",
......@@ -3679,11 +3571,6 @@ COMMAND_PROTOTYPE(dosubnodelist)
char buf[MYBUFSIZE];
int nrows;
if (!reqp->allocated) {
error("SUBNODE: %s: Node is free\n", reqp->nodeid);
return 1;
}
res = mydb_query("select r.node_id,nt.class from reserved as r "
"left join nodes as n on r.node_id=n.node_id "
"left join node_types as nt on nt.type=n.type "
......@@ -4318,10 +4205,6 @@ COMMAND_PROTOTYPE(dontpinfo)
return 1;
}
/*
* Node is allowed to be free?
*/
/*
* First get the servers and peers.
*/
......@@ -4435,10 +4318,6 @@ COMMAND_PROTOTYPE(dojailconfig)
/* Silent error is fine */
return 0;
}
if (!reqp->allocated) {
error("JAILCONFIG: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (!reqp->jailflag)
return 0;
......@@ -4556,10 +4435,6 @@ COMMAND_PROTOTYPE(doplabconfig)
/* Silent error is fine */
return 0;
}
if (!reqp->allocated) {
error("PLABCONFIG: %s: Node is free\n", reqp->nodeid);
return 1;
}
/* XXX Check for Plab-ness */
/*
......@@ -4599,10 +4474,6 @@ COMMAND_PROTOTYPE(dosubconfig)
error("SUBCONFIG: %s: Not a subnode\n", reqp->nodeid);
return 1;
}
if (!reqp->allocated) {
error("SUBCONFIG: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (! strcmp(reqp->type, "ixp-bv"))
return(doixpconfig(sock, reqp, rdata, tcp, vers));
......@@ -4701,14 +4572,6 @@ COMMAND_PROTOTYPE(doprogagents)
char buf[MYBUFSIZE];
int nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("PROGAGENTS: %s: Node is free\n", reqp->nodeid);
return 1;
}
res = mydb_query("select vname,command from virt_programs "
"where vnode='%s' and pid='%s' and eid='%s'",
2, reqp->nickname, reqp->pid, reqp->eid);
......@@ -4757,13 +4620,6 @@ COMMAND_PROTOTYPE(dosyncserver)
{
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("SYNCSERVER: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (!strlen(reqp->syncserver))
return 0;
......@@ -4787,13 +4643,6 @@ COMMAND_PROTOTYPE(dokeyhash)
{
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("KEYHASH: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (!strlen(reqp->keyhash))
return 0;
......@@ -4813,13 +4662,6 @@ COMMAND_PROTOTYPE(doeventkey)
{
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("EVENTKEY: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (!strlen(reqp->eventkey))
return 0;
......@@ -4842,14 +4684,6 @@ COMMAND_PROTOTYPE(doroutelist)
char buf[MYBUFSIZE];
int n, nrows;
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("ROUTES: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* Get the routing type from the nodes table.
*/
......@@ -4954,14 +4788,6 @@ COMMAND_PROTOTYPE(dorole)
MYSQL_ROW row;
char buf[MYBUFSIZE];
/*
* Now check reserved table
*/
if (!reqp->allocated) {
error("ROLE: %s: Node is free\n", reqp->nodeid);
return 1;
}
/*
* Get the erole from the reserved table
*/
......@@ -5003,15 +4829,6 @@ COMMAND_PROTOTYPE(dofullconfig)
int i;
int mask;
/*
* Now check reserved table. If free, give it a minimal status
* section so that stuff works as normal.
*/
if (!reqp->allocated) {
error("FULLCONFIG: %s: Node is free\n", reqp->nodeid);
return 1;
}
if (reqp->isvnode)
mask = FULLCONFIG_VIRT;
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment