char* load_working_ignetcfg(void);
NetMap *read_network_map(void);
-void write_network_map(NetMap *the_netmap, int netmap_changed);
+void write_and_free_network_map(NetMap **the_netmap, int netmap_changed);
int is_valid_node(char *nexthop, char *secret, char *node, char *working_ignetcfg, NetMap *the_netmap);
/* Use the string tokenizer to grab one line at a time */
for (i=0; i<num_tokens(serialized_map, '\n'); ++i) {
extract_token(buf, serialized_map, i, '\n', sizeof buf);
+
nmptr = (NetMap *) malloc(sizeof(NetMap));
+
extract_token(nmptr->nodename, buf, 0, '|', sizeof nmptr->nodename);
nmptr->lastcontact = extract_long(buf, 1);
extract_token(nmptr->nexthop, buf, 2, '|', sizeof nmptr->nexthop);
+
nmptr->next = the_netmap;
the_netmap = nmptr;
}
/*
* Write the network map from memory back to the configuration file.
*/
-void write_network_map(NetMap *the_netmap, int netmap_changed) {
+void write_and_free_network_map(NetMap **the_netmap, int netmap_changed)
+{
char *serialized_map = NULL;
NetMap *nmptr;
-
if (netmap_changed) {
serialized_map = strdup("");
- if (the_netmap != NULL) {
- for (nmptr = the_netmap; nmptr != NULL; nmptr = nmptr->next) {
+ if (*the_netmap != NULL) {
+ for (nmptr = *the_netmap; nmptr != NULL; nmptr = nmptr->next) {
serialized_map = realloc(serialized_map,
(strlen(serialized_map)+SIZ) );
if (!IsEmptyStr(nmptr->nodename)) {
}
/* Now free the list */
- while (the_netmap != NULL) {
- nmptr = the_netmap->next;
- free(the_netmap);
- the_netmap = nmptr;
+ while (*the_netmap != NULL) {
+ nmptr = (*the_netmap)->next;
+ free(*the_netmap);
+ *the_netmap = nmptr;
}
}
char pass[256];
int v;
- char secret[256];
- char nexthop[256];
- char err_buf[SIZ];
+ char secret[256] = "";
+ char nexthop[256] = "";
+ char err_buf[SIZ] = "";
/* Authenticate */
nodelen = extract_token(node, cmdbuf, 0, '|', sizeof node);
&netmap_changed);
}
- /* Save the network map back to disk */
- write_network_map(the_netmap, netmap_changed);
-
/* Free the filter list in memory */
free_netfilter_list();
network_consolidate_spoolout(working_ignetcfg, the_netmap);
+
+ /* Save the network map back to disk */
+ write_and_free_network_map(&the_netmap, netmap_changed);
+
free(working_ignetcfg);
syslog(LOG_DEBUG, "network: queue run completed\n");