diff --git a/include/if.h b/include/if.h index 7901867bd..4cd991a8e 100644 --- a/include/if.h +++ b/include/if.h @@ -106,13 +106,4 @@ int if_get_irqs(struct interface *i); */ int if_set_affinity(struct interface *i, int affinity); -/** Search the global list of interfaces for a given index. - * - * @param index The interface index to search for - * @param interfaces A linked list of all interfaces - * @retval NULL if no interface with index was found. - * @retval >0 Success. A pointer to the interface. - */ -struct interface * if_lookup_index(int index); - #endif /* _IF_H_ */ diff --git a/include/node.h b/include/node.h index a8773f2b2..185b51e9b 100644 --- a/include/node.h +++ b/include/node.h @@ -32,7 +32,8 @@ __attribute__((constructor)) static void __register() { \ list_push(&node_types, vt); \ } -extern struct list node_types; +extern struct list nodes; /**< List of all nodes */ +extern struct list node_types; /**< Vtable for virtual node sub types */ /* Forward declarations */ struct config_setting_t *cfg; diff --git a/lib/if.c b/lib/if.c index c1d917195..a1437012c 100644 --- a/lib/if.c +++ b/lib/if.c @@ -23,9 +23,6 @@ #include "utils.h" #include "checks.h" -/** Linked list of interfaces. */ -struct list interfaces; - struct interface * if_create(struct rtnl_link *link) { struct interface *i = alloc(sizeof(struct interface)); @@ -41,7 +38,6 @@ struct interface * if_create(struct rtnl_link *link) warn("Did not found any interrupts for interface '%s'", rtnl_link_get_name(i->nl_link)); list_init(&i->sockets, NULL); - list_push(&interfaces, i); return i; } @@ -205,14 +201,3 @@ int if_set_affinity(struct interface *i, int affinity) return 0; } - -struct interface * if_lookup_index(int index) -{ - list_foreach(struct interface *i, &interfaces) { - if (rtnl_link_get_ifindex(i->nl_link) == index) - return i; - } - - return NULL; -} - diff --git a/lib/node.c b/lib/node.c index d5e22b2ec..ee26780bc 100644 --- a/lib/node.c +++ b/lib/node.c @@ -12,8 +12,8 @@ #include "cfg.h" #include "utils.h" -/** Vtable for virtual node sub types */ -struct list node_types = LIST_INIT(NULL); +struct list nodes = LIST_INIT((dtor_cb_t) node_destroy); /**< List of all nodes */ +struct list node_types = LIST_INIT(NULL); /**< Vtable for virtual node sub types */ int node_parse(struct node *n, config_setting_t *cfg) { @@ -129,6 +129,7 @@ struct node * node_create(struct node_type *vt) { struct node *n = alloc(sizeof(struct node)); + list_push(&nodes, n); list_push(&vt->instances, n); n->_vt = vt; @@ -146,6 +147,9 @@ void node_destroy(struct node *n) { if (n->_vt->destroy) n->_vt->destroy(n); + + list_remove(&nodes, n); + list_remove(&n->_vt->instances, n); free(n->_vd); free(n->_name); diff --git a/lib/socket.c b/lib/socket.c index 041a240b1..f3d899c84 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -32,12 +32,12 @@ #include "socket.h" #include "checks.h" -/** Linked list of interfaces */ -extern struct list interfaces; - /* Forward declartions */ static struct node_type vt; +/* Private static storage */ +struct list interfaces; + int socket_init(int argc, char * argv[], config_setting_t *cfg) { if (check_root()) @@ -58,12 +58,18 @@ int socket_init(int argc, char * argv[], config_setting_t *cfg) free(buf); } - int ifindex = rtnl_link_get_ifindex(link); - struct interface *i = if_lookup_index(ifindex); - if (!i) - i = if_create(link); + /* Search of existing interface with correct ifindex */ + struct interface *i; + list_foreach(i, &interfaces) { + if (rtnl_link_get_ifindex(i->nl_link) == rtnl_link_get_ifindex(link)) + goto found; + } + + /* If not found, create a new interface */ + i = if_create(link); + list_push(&interfaces, i); - list_push(&i->sockets, s); +found: list_push(&i->sockets, s); } /** @todo Improve mapping of NIC IRQs per path */ diff --git a/src/hooks.c b/src/hooks.c index 867650b4a..4e21b5368 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -21,8 +21,7 @@ #include "hooks.h" #include "path.h" #include "utils.h" - -extern struct list nodes; +#include "node.h" struct list hooks; diff --git a/src/server.c b/src/server.c index daa77cc84..4a7d94d95 100644 --- a/src/server.c +++ b/src/server.c @@ -25,7 +25,6 @@ #include "opal.h" #endif -struct list nodes; /**< Linked list of nodes */ struct list paths; /**< Linked list of paths */ struct settings settings; /**< The global configuration */ static config_t config; /**< libconfig handle */ @@ -143,7 +142,6 @@ int main(int argc, char *argv[]) error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN); /* Initialize lists */ - list_init(&nodes, (dtor_cb_t) node_destroy); list_init(&paths, (dtor_cb_t) path_destroy); info("Initialize real-time system"); diff --git a/src/test.c b/src/test.c index 73731d303..ebae5e062 100644 --- a/src/test.c +++ b/src/test.c @@ -21,8 +21,6 @@ #include "hist.h" #include "timing.h" -/** Linked list of nodes */ -struct list nodes; /** The global configuration */ struct settings settings;