return false;
}
+bool set_config_int(config_t *cfg, int val)
+{
+ if(!cfg)
+ return false;
+
+ char val_str[1024];
+ snprintf(val_str, sizeof(val_str), "%d", val);
+
+ if(cfg->value)
+ free(cfg->value);
+
+ cfg->value = xstrdup(val_str);
+
+ return true;
+}
+
bool get_config_string(const config_t *cfg, char **result) {
if(!cfg)
return false;
return true;
}
+bool set_config_string(config_t *cfg, const char* val)
+{
+ if(!cfg)
+ return false;
+
+ if(cfg->value)
+ free(cfg->value);
+
+ cfg->value = xstrdup(val);
+
+ return true;
+}
+
bool get_config_address(const config_t *cfg, struct addrinfo **result) {
struct addrinfo *ai;
return result;
}
+bool write_config_file(const struct splay_tree_t *config_tree, const char *fname)
+{
+ FILE *fp;
+
+ fp = fopen(fname, "w+");
+
+ if(!fp) {
+ logger(NULL, MESHLINK_ERROR, "Cannot open config file %s: %s", fname, strerror(errno));
+ return false;
+ }
+
+ for splay_each(config_t, cnf, config_tree)
+ {
+ if(fwrite(cnf->variable, sizeof(char), strlen(cnf->variable), fp) < strlen(cnf->variable)) {
+ logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
+ return false;
+ }
+
+ if(fwrite(" = ", sizeof(char), 3, fp) < 3) {
+ logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
+ return false;
+ }
+
+ if(fwrite(cnf->value, sizeof(char), strlen(cnf->value), fp) < strlen(cnf->value)) {
+ logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
+ return false;
+ }
+
+ if(fwrite("\n", sizeof(char), 1, fp) < 1) {
+ logger(NULL, MESHLINK_ERROR, "Cannot write to config file %s: %s", fname, strerror(errno));
+ return false;
+ }
+ }
+
+ fclose(fp);
+
+ return true;
+}
+
bool read_server_config(meshlink_handle_t *mesh) {
char filename[PATH_MAX];
bool x;
return x;
}
+bool write_host_config(struct meshlink_handle *mesh, const struct splay_tree_t *config_tree, const char *name)
+{
+ char filename[PATH_MAX];
+
+ snprintf(filename,PATH_MAX, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name);
+ return write_config_file(config_tree, filename);
+}
+
bool append_config_file(meshlink_handle_t *mesh, const char *name, const char *key, const char *value) {
char filename[PATH_MAX];
snprintf(filename,PATH_MAX, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name);
extern config_t *lookup_config_next(struct splay_tree_t *, const config_t *);
extern bool get_config_bool(const config_t *, bool *);
extern bool get_config_int(const config_t *, int *);
+extern bool set_config_int(config_t *, int);
extern bool get_config_string(const config_t *, char **);
+extern bool set_config_string(config_t *, const char *);
extern bool get_config_address(const config_t *, struct addrinfo **);
extern config_t *parse_config_line(char *, const char *, int);
extern bool read_config_file(struct splay_tree_t *, const char *);
+extern bool write_config_file(const struct splay_tree_t *, const char *);
extern bool read_server_config(struct meshlink_handle *mesh);
extern bool read_host_config(struct meshlink_handle *mesh, struct splay_tree_t *, const char *);
+extern bool write_host_config(struct meshlink_handle *mesh, const struct splay_tree_t *, const char *);
extern bool append_config_file(struct meshlink_handle *mesh, const char *, const char *, const char *);
#endif /* __MESHLINK_CONF_H__ */
packet.len = len;
n->status.broadcast = i >= 4 && n->mtuprobes <= 10 && n->prevedge;
- logger(mesh, MESHLINK_INFO, "Sending MTU probe length %d to %s (%s)", len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending MTU probe length %d to %s (%s)", len, n->name, n->hostname);
send_udppacket(mesh, n, &packet);
}
}
static void mtu_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet, uint16_t len) {
- logger(mesh, MESHLINK_INFO, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname);
if(!packet->data[0]) {
/* It's a probe request, send back a reply */
return mesh->invitation_key;
}
+bool node_read_dclass(meshlink_handle_t *mesh, node_t *n) {
+ if(n->dclass != 0)
+ return true;
+
+ splay_tree_t *config_tree;
+ char *p;
+
+ init_configuration(&config_tree);
+ if(!read_host_config(mesh, config_tree, n->name))
+ goto exit;
+
+ if(get_config_string(lookup_config(config_tree, "DeviceClass"), &p)) {
+ n->dclass = atoi(p);
+ free(p);
+ }
+
+exit:
+ exit_configuration(&config_tree);
+ return n->dclass != 0;
+}
+
+bool node_write_dclass(meshlink_handle_t *mesh, node_t *n) {
+
+ if(n->dclass == 0)
+ return false;
+
+ bool result = false;
+
+ splay_tree_t *config_tree;
+ init_configuration(&config_tree);
+
+ // ignore read errors; in case the file does not exist we will create it
+ read_host_config(mesh, config_tree, n->name);
+
+ config_t* cnf = lookup_config(config_tree, "DeviceClass");
+
+ if(!cnf)
+ {
+ cnf = new_config();
+ cnf->variable = xstrdup("DeviceClass");
+ config_add(config_tree, cnf);
+ }
+
+ set_config_int(cnf, n->dclass);
+
+ if(!write_host_config(mesh, config_tree, n->name))
+ goto fail;
+
+ result = true;
+
+fail:
+ exit_configuration(&config_tree);
+ return result;
+}
+
void load_all_nodes(meshlink_handle_t *mesh) {
DIR *dir;
struct dirent *ent;
n = new_node();
n->name = xstrdup(ent->d_name);
+ node_read_dclass(mesh, n);
node_add(mesh, n);
}
}
n->dclass = dclass;
+ node_write_dclass(mesh, n);
+
n->connection = c;
c->node = n;
if(!(c->options & options & OPTION_PMTU_DISCOVERY)) {
}
from->dclass = from_dclass;
+ node_write_dclass(mesh, from);
if(!to) {
to = new_node();
}
to->dclass = to_dclass;
+ node_write_dclass(mesh, to);
/* Convert addresses */