diff --git a/include/villas/kernel/if.h b/include/villas/kernel/if.h index f1c964b1c..5df083efb 100644 --- a/include/villas/kernel/if.h +++ b/include/villas/kernel/if.h @@ -43,7 +43,7 @@ struct interface { * @retval >0 Success. A pointer to the new interface. * @retval 0 Error. The creation failed. */ -struct interface * if_create(struct rtnl_link *link); +int if_init(struct interface * , struct rtnl_link *link); /** Destroy interface by freeing dynamically allocated memory. diff --git a/lib/kernel/if.c b/lib/kernel/if.c index 6109822e5..765bf22aa 100644 --- a/lib/kernel/if.c +++ b/lib/kernel/if.c @@ -20,10 +20,8 @@ #include "utils.h" -struct interface * if_create(struct rtnl_link *link) +int if_init(struct interface *i, struct rtnl_link *link) { - struct interface *i = alloc(sizeof(struct interface)); - i->nl_link = link; debug(LOG_IF | 3, "Created interface '%s'", rtnl_link_get_name(i->nl_link)); @@ -36,7 +34,7 @@ struct interface * if_create(struct rtnl_link *link) list_init(&i->sockets); - return i; + return 0; } int if_destroy(struct interface *i) diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 57bbcb219..d7ffc679f 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -64,8 +64,12 @@ int socket_init(int argc, char * argv[], config_setting_t *cfg) } /* If not found, create a new interface */ - i = if_create(link); - list_push(&interfaces, i); + struct interface j; + + if_init(&j, link); + + list_push(&interfaces, memdup(&j, sizeof(j))); + i = &j; found: list_push(&i->sockets, s); }