/* site.c - manage communication with a remote network site */
+#include "secnet.h"
#include <stdio.h>
-#include <sys/mman.h>
+/* MBM asserts the next one is needed for compilation under BSD. */
+#include <sys/socket.h>
-#include "secnet.h"
+#include <sys/mman.h>
#include "util.h"
#include "unaligned.h"
#define SITE_SENTMSG5 7
#define SITE_WAIT 8
+#if 0
static string_t state_name(uint32_t state)
{
switch (state) {
default: return "*bad state*";
}
}
+#endif /* 0 */
#define LABEL_MSG0 0x00020200
#define LABEL_MSG1 0x01010101
cfgfatal(loc,"site","parameter must be a dictionary\n");
dict=item->data.dict;
+ st->localname=dict_read_string(dict, "local-name", True, "site", loc);
+ st->remotename=dict_read_string(dict, "name", True, "site", loc);
+ /* Sanity check (which also allows the 'sites' file to include
+ site() closures for all sites including our own): refuse to
+ talk to ourselves */
+ if (strcmp(st->localname,st->remotename)==0) {
+ Message(M_INFO,"site %s: talking to ourselves!\n",st->localname);
+ free(st);
+ return NULL;
+ }
st->netlink=find_cl_if(dict,"netlink",CL_NETLINK,True,"site",loc);
st->comm=find_cl_if(dict,"comm",CL_COMM,True,"site",loc);
st->resolver=find_cl_if(dict,"resolver",CL_RESOLVER,True,"site",loc);
st->log=find_cl_if(dict,"log",CL_LOG,True,"site",loc);
st->random=find_cl_if(dict,"random",CL_RANDOMSRC,True,"site",loc);
- st->localname=dict_read_string(dict, "local-name", True, "site", loc);
st->privkey=find_cl_if(dict,"local-key",CL_RSAPRIVKEY,True,"site",loc);
st->remoteport=dict_read_number(dict,"port",True,"site",loc,0);
- st->remotename=dict_read_string(dict, "name", True, "site", loc);
st->address=dict_read_string(dict, "address", False, "site", loc);
dict_read_subnet_list(dict, "networks", True, "site", loc,
&st->remotenets);
/* XXX fix this bit for unaligned access */
st->setupsiglen=strlen(st->remotename)+strlen(st->localname)+8;
st->setupsig=safe_malloc(st->setupsiglen,"site_apply");
- *(uint32_t *)&(st->setupsig[0])=LABEL_MSG1;
- *(uint16_t *)&(st->setupsig[4])=htons(strlen(st->remotename));
+ put_uint32(st->setupsig+0,LABEL_MSG1);
+ put_uint16(st->setupsig+4,strlen(st->remotename));
memcpy(&st->setupsig[6],st->remotename,strlen(st->remotename));
- *(uint16_t *)&(st->setupsig[6+strlen(st->remotename)])=
- htons(strlen(st->localname));
+ put_uint16(st->setupsig+(6+strlen(st->remotename)),strlen(st->localname));
memcpy(&st->setupsig[8+strlen(st->remotename)],st->localname,
strlen(st->localname));
st->setup_priority=(strcmp(st->localname,st->remotename)>0);