Commit 270bcda4 authored by Mike Hibler's avatar Mike Hibler
Browse files

Make broadcast mode work with master server.

I had never completed this. Two things to note:

1. Distribution via broadcast is still disabled by default in the master
   server. To enable it, see the comment added in 3.mfrisbeed.sh.in.
   To use broadcast by default in the client, see the comment in rc.frisbee.

2. If you specify broadcast (-b) in either the client or server, then you
   should use "-m 255.255.255.255". However, this will broadcast to ALL
   interfaces on the client/server. To limit to a specific interface, also
   include "-i <interface-IP>". This will tell the client/server to look up
   that interface and use the subnet broadcast address in place of
   255.255.255.255. Since the master server always starts up frisbeed
   instances with -i, broadcast will always be directed on the server.
   Since our rc.frisbee script also fires up the client with -i, it will
   likewise be directed.
parent 105d51fc
......@@ -469,6 +469,7 @@ main(int argc, char **argv)
serverip.s_addr = htonl(reply.servaddr);
mcastaddr.s_addr = htonl(reply.addr);
portnum = reply.port;
broadcast = (reply.method == MS_METHOD_BROADCAST);
/*
* Unless the user explicitly specified the interface
......@@ -479,15 +480,17 @@ main(int argc, char **argv)
mcastif = pif;
if (serverip.s_addr == mcastaddr.s_addr)
log("%s: address: %s:%d",
imageid, inet_ntoa(mcastaddr), portnum);
log("%s: address: %s:%d%s",
imageid, inet_ntoa(mcastaddr), portnum,
broadcast ? " (broadcast)" : "");
else {
char serverstr[sizeof("XXX.XXX.XXX.XXX")+1];
strncpy(serverstr, inet_ntoa(serverip),
sizeof serverstr);
log("%s: address: %s:%d, server: %s",
log("%s: address: %s:%d%s, server: %s",
imageid, inet_ntoa(mcastaddr), portnum,
broadcast ? " (broadcast)" : "",
serverstr);
}
break;
......
......@@ -251,6 +251,14 @@ set_get_values(struct config_host_authinfo *ai, int ix)
/* get_methods */
ii->get_methods = CONFIG_IMAGE_MCAST;
#if 1
/*
* XXX broadcast is a bad idea on a large shared LAN environment.
* But it can be enabled/disabled in the server, so this flag
* doesn't hurt.
*/
ii->get_methods |= CONFIG_IMAGE_BCAST;
#endif
#if 1
/*
* XXX the current frisbee server allows only a single client
......@@ -402,10 +410,12 @@ emulab_get_server_address(struct config_imageinfo *ii, int methods, int first,
int idx;
int a, b, c, d;
#if 0
if ((methods & (CONFIG_IMAGE_MCAST|CONFIG_IMAGE_UCAST)) == 0) {
error("get_server_address: only support UCAST/MCAST");
return 1;
}
#endif
if (!mydb_update("UPDATE emulab_indicies "
" SET idx=LAST_INSERT_ID(idx+1) "
......@@ -470,6 +480,15 @@ emulab_get_server_address(struct config_imageinfo *ii, int methods, int first,
if (first)
*addrp = 0;
}
/*
* Broadcast is the method of last resort since it could melt down
* a good-sized network.
*/
else if (methods & CONFIG_IMAGE_BCAST) {
*methp = CONFIG_IMAGE_BCAST;
if (first)
*addrp = INADDR_BROADCAST;
}
/*
* In the interest of uniform distribution, if we have a maximum
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2010-2011 University of Utah and the Flux Group.
* Copyright (c) 2010-2012 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -86,6 +86,14 @@ set_get_values(struct config_host_authinfo *ai, int ix)
/* get_methods */
ai->imageinfo[ix].get_methods = CONFIG_IMAGE_MCAST;
#if 1
/*
* XXX broadcast is a bad idea on a large shared LAN environment.
* But it can be enabled/disabled in the server, so this flag
* doesn't hurt.
*/
ai->imageinfo[ix].get_methods |= CONFIG_IMAGE_BCAST;
#endif
#if 1
/*
* XXX the current frisbee server allows only a single client
......@@ -201,10 +209,12 @@ null_get_server_address(struct config_imageinfo *ii, int methods, int first,
int incr = 1;
FILE *fd;
#if 0
if ((methods & (CONFIG_IMAGE_MCAST|CONFIG_IMAGE_UCAST)) == 0) {
error("get_server_address: only support UCAST/MCAST");
return 1;
}
#endif
again:
if ((fd = fopen(indexfile, "r+")) == NULL) {
......@@ -281,6 +291,15 @@ null_get_server_address(struct config_imageinfo *ii, int methods, int first,
if (first)
*addrp = 0;
}
/*
* Broadcast is the method of last resort since it could melt down
* a good-sized network.
*/
else if (methods & CONFIG_IMAGE_BCAST) {
*methp = CONFIG_IMAGE_BCAST;
if (first)
*addrp = INADDR_BROADCAST;
}
/*
* In the interest of uniform distribution, if we have a maximum
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2010-2011 University of Utah and the Flux Group.
* Copyright (c) 2010-2012 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -1314,7 +1314,7 @@ get_options(int argc, char **argv)
{
int ch;
while ((ch = getopt(argc, argv, "AC:DI:MRX:S:P:p:i:dh")) != -1)
while ((ch = getopt(argc, argv, "AC:DI:MRX:x:S:P:p:i:dh")) != -1)
switch(ch) {
case 'A':
usechildauth = 1;
......@@ -1584,8 +1584,9 @@ startchild(struct childinfo *ci)
opts = ci->imageinfo->get_options ?
ci->imageinfo->get_options : "";
snprintf(argbuf, sizeof argbuf,
"%s -i %s -T %d %s -m %s -p %d %s",
"%s -i %s -T %d %s %s -m %s -p %d %s",
pname, ifacestr, ci->timeout, opts,
ci->method == CONFIG_IMAGE_BCAST ? "-b" : "",
inet_ntoa(in), ci->port, ci->imageinfo->path);
break;
case PTYPE_CLIENT:
......@@ -1594,7 +1595,8 @@ startchild(struct childinfo *ci)
"%s -N -S %s -i %s %s %s -m %s -p %d %s",
pname, servstr, ifacestr,
debug > 1 ? "" : "-q",
ci->method == CONFIG_IMAGE_UCAST ? "-O" : "",
ci->method == CONFIG_IMAGE_UCAST ? "-O" :
(ci->method == CONFIG_IMAGE_BCAST ? "-b" : ""),
inet_ntoa(in), ci->port, ci->imageinfo->path);
break;
case PTYPE_UPLOADER:
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2011 University of Utah and the Flux Group.
* Copyright (c) 2000-2012 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -12,6 +12,8 @@
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -100,6 +102,42 @@ GetSockbufSize(void)
return sbsize;
}
/*
* Find the subnet broadcast address associated with the given interface
* address. We use this to limit broadcasts to a single interface.
* Returns zero if we successfully produced an address (in *bcaddr),
* non-zero otherwise.
*/
static int
GetBcastAddr(struct in_addr *ifaddr, struct in_addr *bcaddr)
{
struct ifaddrs *ifa, *nifa;
struct sockaddr_in *sin;
if (getifaddrs(&ifa) != 0) {
pwarning("Could not get interface list");
return 1;
}
for (nifa = ifa; nifa != NULL; nifa = nifa->ifa_next) {
if (nifa->ifa_addr->sa_family != AF_INET)
continue;
if ((nifa->ifa_flags & (IFF_UP|IFF_BROADCAST)) !=
(IFF_UP|IFF_BROADCAST))
continue;
sin = (struct sockaddr_in *)nifa->ifa_addr;
if (ifaddr->s_addr == sin->sin_addr.s_addr) {
*bcaddr = ((struct sockaddr_in *)nifa->ifa_broadaddr)->sin_addr;
freeifaddrs(ifa);
return 0;
}
}
freeifaddrs(ifa);
warning("Could not find interface %s", inet_ntoa(*ifaddr));
return 1;
}
static void
CommonInit(int dobind)
{
......@@ -186,13 +224,28 @@ CommonInit(int dobind)
}
}
else if (broadcast) {
log("Setting broadcast mode");
/*
* Otherwise, we use a broadcast addr.
* If they are using the local broadcast address and they
* have specified an interface, attempt to limit broadcasts
* to that interface by using the subnet broadcast address.
* Otherwise we issue a dire warning about the consequences
* of broadcasting to all interfaces.
*/
i = 1;
if (ntohl(mcastaddr.s_addr) == INADDR_BROADCAST) {
struct in_addr bcaddr;
if (mcastif.s_addr &&
GetBcastAddr(&mcastif, &bcaddr) == 0) {
log("Limiting broadcasts using %s",
inet_ntoa(bcaddr));
mcastaddr = bcaddr;
} else
warning("WARNING: will broadcast "
"to ALL configured interfaces!");
}
log("Setting broadcast mode\n");
i = 1;
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
&i, sizeof(i)) < 0)
pfatal("setsockopt(SOL_SOCKET, SO_BROADCAST)");
......@@ -736,4 +789,3 @@ ClientNetFindServer(in_addr_t sip, in_port_t sport,
return 1;
}
#endif
......@@ -309,6 +309,10 @@ loadone() {
ispath=0
fi
else
#
# Note: if you want to use broadcast rather that multicast as
# the distribution method, add "-X bcast" to the IMAGEID= below.
#
IMAGEID="-B 30 -F $IMAGEID"
isurl=0
ispath=0
......
......@@ -205,6 +205,11 @@ write_image()
echo "*** WARNING: could not parse imageid spec: $address"
return 1
fi
#
# Note: if you want to use broadcast rather that
# multicast as the distribution method, add "-X bcast"
# to the imageid= line below.
#
imageid="-B 30 -F $pid/$imagename"
;;
http|https)
......
......@@ -68,6 +68,8 @@ fi
echo -n " mfrisbeed"
rm -f /var/run/frisbeed-*.pid
args="-C emulab -i @BOSSNODE_IP@"
# to allow broadcast, uncomment the following line
#args="$args -x ucast,mcast,bcast"
# if an inner elab, use outer boss as our parent
if [ -n "@OUTERBOSS_NODENAME@" ]; then
args="$args -S @OUTERBOSS_NODENAME@"
......
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