char nexthop[SIZ];
};
-
-NetMap *the_netmap;
-int netmap_changed;
-char *working_ignetcfg;
-
-void load_working_ignetcfg(void);
-void read_network_map(void);
-void write_network_map(void);
-int is_valid_node(char *nexthop, char *secret, char *node);
+char* load_working_ignetcfg(void);
+NetMap *read_network_map(void);
+void write_network_map(NetMap *the_netmap, int netmap_changed);
+int is_valid_node(char *nexthop, char *secret, char *node, char *working_ignetcfg, NetMap *the_netmap);
void network_spoolout_room(char *room_to_spool);
-void network_do_spoolin(void);
-void network_consolidate_spoolout(void);
+void network_do_spoolin(char *working_ignetcfg, NetMap *the_netmap, int *netmap_changed);
+void network_consolidate_spoolout(char *working_ignetcfg, NetMap *the_netmap);
void free_spoolcontrol_struct(SpoolControl **scc);
int writenfree_spoolcontrol_file(SpoolControl **scc, char *filename);
int read_spoolcontrol_file(SpoolControl **scc, char *filename);
#include "ctdl_module.h"
-/*
- * We build a map of network nodes during processing.
- */
-NetMap *the_netmap = NULL;
-int netmap_changed = 0;
-char *working_ignetcfg = NULL;
-
/*
* Load or refresh the Citadel network (IGnet) configuration for this node.
*/
-void load_working_ignetcfg(void) {
- char *cfg;
- char *oldcfg;
-
- cfg = CtdlGetSysConfig(IGNETCFG);
- if (cfg == NULL) {
- cfg = strdup("");
- }
-
- oldcfg = working_ignetcfg;
- working_ignetcfg = cfg;
- if (oldcfg != NULL) {
- free(oldcfg);
- }
+char* load_working_ignetcfg(void) {
+ return CtdlGetSysConfig(IGNETCFG);
}
+
/*
* Read the network map from its configuration file into memory.
*/
-void read_network_map(void) {
+NetMap *read_network_map(void) {
char *serialized_map = NULL;
int i;
char buf[SIZ];
- NetMap *nmptr;
+ NetMap *nmptr, *the_netmap;
+ the_netmap = NULL;
serialized_map = CtdlGetSysConfig(IGNETMAP);
- if (serialized_map == NULL) return; /* if null, no entries */
+ if (serialized_map == NULL) return NULL; /* if null, no entries */
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(serialized_map, '\n'); ++i) {
}
free(serialized_map);
- netmap_changed = 0;
+ return the_netmap;
}
/*
* Write the network map from memory back to the configuration file.
*/
-void write_network_map(void) {
+void write_network_map(NetMap *the_netmap, int netmap_changed) {
char *serialized_map = NULL;
NetMap *nmptr;
}
+
/*
* Check the network map and determine whether the supplied node name is
* valid. If it is not a neighbor node, supply the name of a neighbor node
* which is the next hop. If it *is* a neighbor node, we also fill in the
* shared secret.
*/
-int is_valid_node(char *nexthop, char *secret, char *node) {
+int is_valid_node(char *nexthop,
+ char *secret,
+ char *node,
+ char *working_ignetcfg,
+ NetMap *the_netmap)
+{
int i;
char linebuf[SIZ];
char buf[SIZ];
/*
* First try the neighbor nodes
*/
- if (working_ignetcfg == NULL) {
- syslog(LOG_ERR, "working_ignetcfg is NULL!\n");
+ if ((working_ignetcfg == NULL) || (*working_ignetcfg == '\0')) {
+ syslog(LOG_ERR, "working_ignetcfg is empty!\n");
if (nexthop != NULL) {
strcpy(nexthop, "");
}
*/
void cmd_netp(char *cmdbuf)
{
+ char *working_ignetcfg;
char node[256];
char pass[256];
int v;
extract_token(pass, cmdbuf, 1, '|', sizeof pass);
/* load the IGnet Configuration to check node validity */
- load_working_ignetcfg();
- v = is_valid_node(nexthop, secret, node);
+ working_ignetcfg = load_working_ignetcfg();
+ v = is_valid_node(nexthop, secret, node, working_ignetcfg, NULL); //// TODO do we need the netmap?
if (v != 0) {
snprintf(err_buf, sizeof err_buf,
syslog(LOG_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
+ free(working_ignetcfg);
return;
}
syslog(LOG_WARNING, "%s", err_buf);
cprintf("%d authentication failed\n", ERROR + PASSWORD_REQUIRED);
CtdlAideMessage(err_buf, "IGNet Networking.");
+ free(working_ignetcfg);
return;
}
if (network_talking_to(node, NTT_CHECK)) {
syslog(LOG_WARNING, "Duplicate session for network node <%s>", node);
cprintf("%d Already talking to %s right now\n", ERROR + RESOURCE_BUSY, node);
+ free(working_ignetcfg);
return;
}
CC->net_node, CC->cs_host, CC->cs_addr
);
cprintf("%d authenticated as network node '%s'\n", CIT_OK, CC->net_node);
+ free(working_ignetcfg);
}
int netconfig_check_roomaccess(
/*
* Spools out one message from the list.
*/
-void network_spool_msg(long msgnum, void *userdata) {
+void network_spool_msg(long msgnum,
+ void *userdata,
+ char *working_ignetcfg,
+ NetMap *the_netmap)
+{
SpoolControl *sc;
int i;
char *newpath = NULL;
if (!strcasecmp(msg->cm_fields['N'], config.c_nodename)) {
ok_to_participate = 1;
}
- if (is_valid_node(NULL, NULL, msg->cm_fields['N']) == 0) {
+ if (is_valid_node(NULL,
+ NULL,
+ msg->cm_fields['N'],
+ working_ignetcfg,
+ the_netmap) == 0)
+ {
ok_to_participate = 1;
}
}
send = 1;
/* Check for valid node name */
- if (is_valid_node(NULL, NULL, mptr->remote_nodename) != 0) {
+ if (is_valid_node(NULL,
+ NULL,
+ mptr->remote_nodename,
+ working_ignetcfg,
+ the_netmap) != 0)
+ {
syslog(LOG_ERR, "Invalid node <%s>\n", mptr->remote_nodename);
send = 0;
}
/*
* Learn topology from path fields
*/
-void network_learn_topology(char *node, char *path) {
+void network_learn_topology(char *node, char *path, NetMap *the_netmap, int *netmap_changed) {
char nexthop[256];
NetMap *nmptr;
if (!strcasecmp(nmptr->nodename, node)) {
extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
nmptr->lastcontact = time(NULL);
- ++netmap_changed;
+ (*netmap_changed) ++;
return;
}
}
extract_token(nmptr->nexthop, path, 0, '!', sizeof nmptr->nexthop);
nmptr->next = the_netmap;
the_netmap = nmptr;
- ++netmap_changed;
+ (*netmap_changed) ++;
}
* Process a buffer containing a single message from a single file
* from the inbound queue
*/
-void network_process_buffer(char *buffer, long size) {
+void network_process_buffer(char *buffer, long size, char *working_ignetcfg, NetMap *the_netmap, int *netmap_changed)
+{
struct CtdlMessage *msg = NULL;
long pos;
int field;
/* route the message */
strcpy(nexthop, "");
- if (is_valid_node(nexthop, NULL, msg->cm_fields['D']) == 0) {
+ if (is_valid_node(nexthop,
+ NULL,
+ msg->cm_fields['D'],
+ working_ignetcfg,
+ the_netmap) == 0)
+ {
/* prepend our node to the path */
if (msg->cm_fields['P'] != NULL) {
oldpath = msg->cm_fields['P'];
/* Learn network topology from the path */
if ((msg->cm_fields['N'] != NULL) && (msg->cm_fields['P'] != NULL)) {
- network_learn_topology(msg->cm_fields['N'], msg->cm_fields['P']);
+ network_learn_topology(msg->cm_fields['N'],
+ msg->cm_fields['P'],
+ the_netmap,
+ netmap_changed);
}
/* Is the sending node giving us a very persuasive suggestion about
/*
* Process a single message from a single file from the inbound queue
*/
-void network_process_message(FILE *fp, long msgstart, long msgend) {
+void network_process_message(FILE *fp,
+ long msgstart,
+ long msgend,
+ char *working_ignetcfg,
+ NetMap *the_netmap,
+ int *netmap_changed)
+{
long hold_pos;
long size;
char *buffer;
if (buffer != NULL) {
fseek(fp, msgstart, SEEK_SET);
if (fread(buffer, size, 1, fp) > 0) {
- network_process_buffer(buffer, size);
+ network_process_buffer(buffer,
+ size,
+ working_ignetcfg,
+ the_netmap,
+ netmap_changed);
}
free(buffer);
}
/*
* Process a single file from the inbound queue
*/
-void network_process_file(char *filename) {
+void network_process_file(char *filename,
+ char *working_ignetcfg,
+ NetMap *the_netmap,
+ int *netmap_changed)
+{
FILE *fp;
long msgstart = (-1L);
long msgend = (-1L);
if (ch == 255) {
if (msgstart >= 0L) {
msgend = msgcur - 1;
- network_process_message(fp, msgstart, msgend);
+ network_process_message(fp,
+ msgstart,
+ msgend,
+ working_ignetcfg,
+ the_netmap,
+ netmap_changed);
}
msgstart = msgcur;
}
msgend = msgcur - 1;
if (msgstart >= 0L) {
- network_process_message(fp, msgstart, msgend);
+ network_process_message(fp,
+ msgstart,
+ msgend,
+ working_ignetcfg,
+ the_netmap,
+ netmap_changed);
}
fclose(fp);
/*
* Process anything in the inbound queue
*/
-void network_do_spoolin(void) {
+void network_do_spoolin(char *working_ignetcfg, NetMap *the_netmap, int *netmap_changed)
+{
DIR *dp;
struct dirent *d;
struct stat statbuf;
ctdl_netin_dir,
d->d_name
);
- network_process_file(filename);
+ network_process_file(filename,
+ working_ignetcfg,
+ the_netmap,
+ netmap_changed);
}
}
* Step 1: consolidate files in the outbound queue into one file per neighbor node
* Step 2: delete any files in the outbound queue that were for neighbors who no longer exist.
*/
-void network_consolidate_spoolout(void) {
+void network_consolidate_spoolout(char *working_ignetcfg, NetMap *the_netmap)
+{
DIR *dp;
struct dirent *d;
char filename[PATH_MAX];
);
strcpy(nexthop, "");
- i = is_valid_node(nexthop, NULL, d->d_name);
+ i = is_valid_node(nexthop,
+ NULL,
+ d->d_name,
+ working_ignetcfg,
+ the_netmap);
if ( (i != 0) || !IsEmptyStr(nexthop) ) {
unlink(filename);
void destroy_network_queue_room(void)
{
struct RoomProcList *cur, *p;
- NetMap *nmcur, *nmp;
cur = rplist;
begin_critical_section(S_RPLIST);
}
rplist = NULL;
end_critical_section(S_RPLIST);
-
- nmcur = the_netmap;
- while (nmcur != NULL)
- {
- nmp = nmcur->next;
- free (nmcur);
- nmcur = nmp;
- }
- the_netmap = NULL;
- if (working_ignetcfg != NULL)
- free (working_ignetcfg);
- working_ignetcfg = NULL;
}
static time_t last_run = 0L;
struct RoomProcList *ptr;
int full_processing = 1;
+ char *working_ignetcfg;
+ NetMap *the_netmap = NULL;
+ int netmap_changed = 0;
/*
* Run the full set of processing tasks no more frequently
doing_queue = 1;
/* Load the IGnet Configuration into memory */
- load_working_ignetcfg();
+ working_ignetcfg = load_working_ignetcfg();
/*
* Load the network map and filter list into memory.
*/
- read_network_map();
+ the_netmap = read_network_map();
load_network_filter_list();
/*
/* If there is anything in the inbound queue, process it */
if (!server_shutting_down) {
- network_do_spoolin();
+ network_do_spoolin(working_ignetcfg,
+ the_netmap,
+ &netmap_changed);
}
/* Save the network map back to disk */
- write_network_map();
+ write_network_map(the_netmap, netmap_changed);
/* Free the filter list in memory */
free_netfilter_list();
- network_consolidate_spoolout();
+ network_consolidate_spoolout(working_ignetcfg, the_netmap);
+ free(working_ignetcfg);
syslog(LOG_DEBUG, "network: queue run completed\n");
#include "netconfig.h"
#include "ctdl_module.h"
+
/*
* receive network spool from the remote system
*/
* Set "full" to nonzero to force a poll of every node, or to zero to poll
* only nodes to which we have data to send.
*/
-void network_poll_other_citadel_nodes(int full_poll) {
+void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
+{
int i;
char linebuf[256];
char node[SIZ];
void network_do_clientqueue(void)
{
+ char *working_ignetcfg;
int full_processing = 1;
static time_t last_run = 0L;
);
}
-
+ working_ignetcfg = load_working_ignetcfg();
/*
* Poll other Citadel nodes. Maybe. If "full_processing" is set
* then we poll everyone. Otherwise we only poll nodes we have stuff
* to send to.
*/
- network_poll_other_citadel_nodes(full_processing);
+ network_poll_other_citadel_nodes(full_processing, working_ignetcfg);
+ if (working_ignetcfg)
+ free(working_ignetcfg);
}