+static void *setup_network_in_netns_thread(void *arg) {
+ meshlink_handle_t *mesh = arg;
+
+ if(setns(mesh->netns, CLONE_NEWNET) != 0) {
+ return NULL;
+ }
+
+ bool success = setup_network(mesh);
+ add_local_addresses(mesh);
+ return success ? arg : NULL;
+}
+
+meshlink_open_params_t *meshlink_open_params_init(const char *confbase, const char *name, const char *appname, dev_class_t devclass) {
+ if(!confbase || !*confbase) {
+ logger(NULL, MESHLINK_ERROR, "No confbase given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ if(!appname || !*appname) {
+ logger(NULL, MESHLINK_ERROR, "No appname given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ if(strchr(appname, ' ')) {
+ logger(NULL, MESHLINK_ERROR, "Invalid appname given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ if(!name || !*name) {
+ logger(NULL, MESHLINK_ERROR, "No name given!\n");
+ //return NULL;
+ } else { //check name only if there is a name != NULL
+ if(!check_id(name)) {
+ logger(NULL, MESHLINK_ERROR, "Invalid name given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+ }
+
+ if((int)devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
+ meshlink_errno = MESHLINK_EINVAL;
+ return NULL;
+ }
+
+ meshlink_open_params_t *params = xzalloc(sizeof * params);
+
+ params->confbase = xstrdup(confbase);
+ params->name = xstrdup(name);
+ params->appname = xstrdup(appname);
+ params->devclass = devclass;
+ params->netns = -1;
+
+ return params;
+}
+
+void meshlink_open_params_free(meshlink_open_params_t *params) {
+ if(!params) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ free(params->confbase);
+ free(params->name);
+ free(params->appname);
+
+ free(params);
+}
+