summaryrefslogtreecommitdiff
path: root/device.c
diff options
context:
space:
mode:
authorArne Kappen <akappen@inet.tu-berlin.de>2016-08-18 11:35:29 +0200
committerFelix Fietkau <nbd@nbd.name>2016-08-26 10:38:50 +0200
commit8bf5df1d052a853579c0474dabc87af2d113fb53 (patch)
treecece5a620676a437299aff688a2a6294deda5dd8 /device.c
parentf56a7fbaa6f155c654e7d01b5c4c0594f21239d6 (diff)
downloadnetifd-8bf5df1d052a853579c0474dabc87af2d113fb53.tar.gz
device: add device handler list
Device handlers now also declare if they have bridge capabilities and include a string to prefix device names for their types. Signed-off-by: Arne Kappen <akappen@inet.tu-berlin.de> Signed-off-by: Felix Fietkau <nbd@nbd.name> [cleanup/fixes]
Diffstat (limited to 'device.c')
-rw-r--r--device.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/device.c b/device.c
index 07ec82f..8174ca0 100644
--- a/device.c
+++ b/device.c
@@ -24,10 +24,13 @@
#include <netinet/ether.h>
#endif
+#include <libubox/list.h>
+
#include "netifd.h"
#include "system.h"
#include "config.h"
+static struct list_head devtypes = LIST_HEAD_INIT(devtypes);
static struct avl_tree devices;
static bool default_ps = true;
@@ -63,6 +66,46 @@ const struct uci_blob_param_list device_attr_list = {
static int __devlock = 0;
+int device_type_add(struct device_type *devtype)
+{
+ if (device_type_get(devtype->name)) {
+ netifd_log_message(L_WARNING, "Device handler '%s' already exists\n",
+ devtype->name);
+ return 1;
+ }
+
+ netifd_log_message(L_NOTICE, "Added device handler type: %s\n",
+ devtype->name);
+
+ list_add(&devtype->list, &devtypes);
+ return 0;
+}
+
+/* initialize device type list and add known types */
+static void __init devtypes_init(void)
+{
+ device_type_add(&simple_device_type);
+ device_type_add(&bridge_device_type);
+ device_type_add(&tunnel_device_type);
+ device_type_add(&macvlan_device_type);
+ device_type_add(&vlandev_device_type);
+}
+
+/* Retrieve the device type for the given name. If 'bridge' is true, the type
+ * must have bridge capabilities
+ */
+struct device_type *
+device_type_get(const char *tname)
+{
+ struct device_type *cur;
+
+ list_for_each_entry(cur, &devtypes, list)
+ if (!strcmp(cur->name, tname))
+ return cur;
+
+ return NULL;
+}
+
void device_lock(void)
{
__devlock++;