summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2013-04-07 14:39:28 +0200
committerDaniel Mack <zonque@gmail.com>2013-04-07 14:39:28 +0200
commit68e6c56a7d7a5a4e5347058ec27b0589eea484fd (patch)
treeec801574323d4be1f223803986927148432eb255
parentb57ad991d5daf29b50b7e3fe8f2c274ccce73fe9 (diff)
downloadkdbus-bus-68e6c56a7d7a5a4e5347058ec27b0589eea484fd.tar.gz
kdbus-bus-68e6c56a7d7a5a4e5347058ec27b0589eea484fd.tar.bz2
kdbus-bus-68e6c56a7d7a5a4e5347058ec27b0589eea484fd.zip
match db: add stub container, redirect ioctls
-rw-r--r--Makefile1
-rw-r--r--connection.c9
-rw-r--r--kdbus_internal.h15
-rw-r--r--match.c71
4 files changed, 93 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 25d6b4b3c9d..7fb4727e09c 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ kdbus-y := \
connection.o \
ep.o \
main.o \
+ match.o \
message.o \
names.o \
notify.o \
diff --git a/connection.c b/connection.c
index d4fe44f4e86..25fe11ee143 100644
--- a/connection.c
+++ b/connection.c
@@ -147,6 +147,8 @@ static int kdbus_conn_open(struct inode *inode, struct file *file)
conn->timer.data = (unsigned long) conn;
add_timer(&conn->timer);
+ conn->match_db = kdbus_match_db_new();
+
conn->creds.uid = current_uid();
conn->creds.gid = current_gid();
conn->creds.pid = current->pid;
@@ -213,6 +215,7 @@ static int kdbus_conn_release(struct inode *inode, struct file *file)
bus = conn->ep->bus;
kdbus_name_remove_by_conn(bus->name_registry, conn);
kdbus_policy_db_remove_conn(conn->ep->policy_db, conn);
+ kdbus_match_db_unref(conn->match_db);
kdbus_ep_unref(conn->ep);
break;
@@ -464,19 +467,19 @@ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd,
case KDBUS_CMD_NAME_QUERY:
/* return details about a specific well-known name */
bus = conn->ep->bus;
- ret =kdbus_name_query(bus->name_registry, conn, buf);
+ ret = kdbus_name_query(bus->name_registry, conn, buf);
break;
case KDBUS_CMD_MATCH_ADD:
/* subscribe to/filter for broadcast messages */
- ret = -ENOSYS;
+ ret = kdbus_match_db_add(conn->match_db, buf);
break;
case KDBUS_CMD_MATCH_REMOVE:
/* unsubscribe from broadcast messages */
- ret = -ENOSYS;
+ ret = kdbus_match_db_remove(conn->match_db, buf);
break;
diff --git a/kdbus_internal.h b/kdbus_internal.h
index 55e22987ace..46b80484034 100644
--- a/kdbus_internal.h
+++ b/kdbus_internal.h
@@ -114,6 +114,20 @@ struct kdbus_name_entry *kdbus_name_lookup(struct kdbus_name_registry *reg,
void kdbus_name_remove_by_conn(struct kdbus_name_registry *reg,
struct kdbus_conn *conn);
+/* match database */
+struct kdbus_match_db {
+ struct kref kref;
+ DECLARE_HASHTABLE(entries_hash, 6);
+ struct mutex entries_lock;
+};
+
+struct kdbus_match_db *kdbus_match_db_new(void);
+void kdbus_match_db_unref(struct kdbus_match_db *db);
+int kdbus_match_db_add(struct kdbus_match_db *db,
+ void __user *buf);
+int kdbus_match_db_remove(struct kdbus_match_db *db,
+ void __user *buf);
+
/*
* kdbus bus
* - provides a "bus" endpoint
@@ -209,6 +223,7 @@ struct kdbus_conn {
struct timer_list timer;
struct kdbus_creds creds;
+ struct kdbus_match_db *match_db;
};
struct kdbus_fds {
diff --git a/match.c b/match.c
new file mode 100644
index 00000000000..6d660fdb631
--- /dev/null
+++ b/match.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2013 Kay Sievers
+ * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+ * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
+ * Copyright (C) 2013 Linux Foundation
+ *
+ * kdbus is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/idr.h>
+#include <linux/fs.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/mutex.h>
+#include <linux/init.h>
+#include <linux/hash.h>
+#include <linux/uaccess.h>
+#include "kdbus.h"
+
+#include "kdbus_internal.h"
+
+static void __kdbus_match_db_free(struct kref *kref)
+{
+ struct kdbus_match_db *db =
+ container_of(kref, struct kdbus_match_db, kref);
+
+ mutex_lock(&db->entries_lock);
+ // ...
+ mutex_unlock(&db->entries_lock);
+
+ kfree(db);
+}
+
+void kdbus_match_db_unref(struct kdbus_match_db *db)
+{
+ kref_put(&db->kref, __kdbus_match_db_free);
+}
+
+struct kdbus_match_db *kdbus_match_db_new(void)
+{
+ struct kdbus_match_db *db;
+
+ db = kzalloc(sizeof(*db), GFP_KERNEL);
+ if (!db)
+ return NULL;
+
+ kref_init(&db->kref);
+ hash_init(db->entries_hash);
+ mutex_init(&db->entries_lock);
+
+ return db;
+}
+
+int kdbus_match_db_add(struct kdbus_match_db *db,
+ void __user *buf)
+{
+ return -ENOSYS;
+}
+
+int kdbus_match_db_remove(struct kdbus_match_db *db,
+ void __user *buf)
+{
+ return -ENOSYS;
+}