diff options
author | Kay Sievers <kay@vrfy.org> | 2013-05-21 00:28:50 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2013-05-21 00:28:50 +0200 |
commit | d4a2a92b88e41afc7cf10113aa3c22156e1f5152 (patch) | |
tree | b4cd456d3470c6afea9c39fb46257d51d8348b4c | |
parent | e79dbd6434ec9e02dddecfa331d660e61651ac3a (diff) | |
download | kdbus-bus-d4a2a92b88e41afc7cf10113aa3c22156e1f5152.tar.gz kdbus-bus-d4a2a92b88e41afc7cf10113aa3c22156e1f5152.tar.bz2 kdbus-bus-d4a2a92b88e41afc7cf10113aa3c22156e1f5152.zip |
track connection state in 'type' not in 'active'
-rw-r--r-- | connection.c | 71 | ||||
-rw-r--r-- | connection.h | 17 | ||||
-rw-r--r-- | kdbus.h | 2 | ||||
-rw-r--r-- | kdbus.txt | 3 | ||||
-rw-r--r-- | notify.c | 2 | ||||
-rw-r--r-- | test/kdbus-enum.c | 2 |
6 files changed, 52 insertions, 45 deletions
diff --git a/connection.c b/connection.c index c77744cfd19..fc57df0bad4 100644 --- a/connection.c +++ b/connection.c @@ -288,7 +288,7 @@ int kdbus_conn_queue_insert(struct kdbus_conn *conn, struct kdbus_kmsg *kmsg, size_t size; int ret = 0; - if (!conn->active) + if (!conn->type == KDBUS_CONN_EP_CONNECTED) return -ENOTCONN; if (kmsg->fds && !(conn->flags & KDBUS_HELLO_ACCEPT_FD)) @@ -514,23 +514,18 @@ int kdbus_conn_kmsg_send(struct kdbus_ep *ep, mutex_lock(&ep->bus->lock); list_for_each_entry(conn_dst, &ep->bus->conns_list, connection_entry) { - if (conn_dst->type != KDBUS_CONN_EP) + if (conn_dst->type != KDBUS_CONN_EP_CONNECTED) continue; if (conn_dst->id == msg->src_id) continue; - if (!conn_dst->active) - continue; - if (!kdbus_match_db_match_kmsg(conn_dst->match_db, conn_src, conn_dst, kmsg)) continue; - ret = kdbus_conn_queue_insert(conn_dst, kmsg, 0); - if (ret < 0) - break; + kdbus_conn_queue_insert(conn_dst, kmsg, 0); } mutex_unlock(&ep->bus->lock); @@ -895,7 +890,7 @@ static int kdbus_conn_open(struct inode *inode, struct file *file) list_add_tail(&conn->connection_entry, &conn->ep->bus->conns_list); mutex_unlock(&ep->bus->lock); - //FIXME: cleanup here! + //FIXME: cleanup here; send notfy only after HELLO! ret = kdbus_notify_id_change(conn->ep, KDBUS_MSG_ID_ADD, conn->id, conn->flags); if (ret < 0) return ret; @@ -917,15 +912,20 @@ static int kdbus_conn_release(struct inode *inode, struct file *file) struct kdbus_bus *bus; switch (conn->type) { - case KDBUS_CONN_NS_OWNER: + case KDBUS_CONN_CONTROL_NS_OWNER: + //FIXME: break; - case KDBUS_CONN_BUS_OWNER: + case KDBUS_CONN_CONTROL_BUS_OWNER: kdbus_bus_disconnect(conn->bus_owner); kdbus_bus_unref(conn->bus_owner); break; - case KDBUS_CONN_EP: { + case KDBUS_CONN_EP_OWNER: + //FIXME: + break; + + case KDBUS_CONN_EP_CONNECTED: { struct kdbus_conn_queue *queue, *tmp; struct list_head list; @@ -996,7 +996,6 @@ static bool check_flags(u64 kernel_flags) { /* The higher 32bit are considered 'incompatible * flags'. Refuse them all for now */ - return kernel_flags <= 0xFFFFFFFFULL; } @@ -1043,7 +1042,7 @@ static long kdbus_conn_ioctl_control(struct file *file, unsigned int cmd, break; /* turn the control fd into a new bus owner device */ - conn->type = KDBUS_CONN_BUS_OWNER; + conn->type = KDBUS_CONN_CONTROL_BUS_OWNER; conn->bus_owner = bus; break; } @@ -1071,7 +1070,7 @@ static long kdbus_conn_ioctl_control(struct file *file, unsigned int cmd, break; /* turn the control fd into a new ns owner device */ - conn->type = KDBUS_CONN_NS_OWNER; + conn->type = KDBUS_CONN_CONTROL_NS_OWNER; conn->ns_owner = ns; break; @@ -1098,19 +1097,16 @@ static long kdbus_conn_ioctl_control(struct file *file, unsigned int cmd, return ret; } -/* kdbus bus endpoint commands */ +/* kdbus endpoint make commands */ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd, void __user *buf) { struct kdbus_conn *conn = file->private_data; struct kdbus_cmd_ep_kmake *kmake = NULL; struct kdbus_cmd_hello *hello = NULL; - struct kdbus_bus *bus = NULL; + struct kdbus_bus *bus = conn->ep->bus; long ret = 0; - if (conn && conn->ep) - bus = conn->ep->bus; - switch (cmd) { case KDBUS_CMD_EP_MAKE: { umode_t mode = 0; @@ -1141,6 +1137,7 @@ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd, current_fsuid(), gid, kmake->make.flags & KDBUS_MAKE_POLICY_OPEN); + conn->type = KDBUS_CONN_EP_OWNER; break; } @@ -1155,11 +1152,6 @@ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd, break; } - if (conn->active) { - ret = -EISCONN; - break; - } - if (kdbus_size_get_user(&size, buf, struct kdbus_cmd_hello)) { ret = -EFAULT; break; @@ -1227,11 +1219,30 @@ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd, } conn->flags = hello->conn_flags; - conn->active = true; + conn->type = KDBUS_CONN_EP_CONNECTED; + break; + } + default: + ret = -ENOTTY; break; } + kfree(kmake); + kfree(hello); + + return ret; +} + +/* kdbus endpoint commands for connected peers */ +static long kdbus_conn_ioctl_ep_connected(struct file *file, unsigned int cmd, + void __user *buf) +{ + struct kdbus_conn *conn = file->private_data; + struct kdbus_bus *bus = conn->ep->bus; + long ret = 0; + + switch (cmd) { case KDBUS_CMD_EP_POLICY_SET: /* upload a policy for this endpoint */ if (!KDBUS_IS_ALIGNED8((uintptr_t)buf)) { @@ -1406,9 +1417,6 @@ static long kdbus_conn_ioctl_ep(struct file *file, unsigned int cmd, break; } - kfree(kmake); - kfree(hello); - return ret; } @@ -1425,6 +1433,9 @@ static long kdbus_conn_ioctl(struct file *file, unsigned int cmd, case KDBUS_CONN_EP: return kdbus_conn_ioctl_ep(file, cmd, argp); + case KDBUS_CONN_EP_CONNECTED: + return kdbus_conn_ioctl_ep_connected(file, cmd, argp); + default: return -EBADFD; } @@ -1437,7 +1448,7 @@ static unsigned int kdbus_conn_poll(struct file *file, unsigned int mask = 0; /* Only an endpoint can read/write data */ - if (conn->type != KDBUS_CONN_EP) + if (conn->type != KDBUS_CONN_EP_CONNECTED) return POLLERR | POLLHUP; poll_wait(file, &conn->ep->wait, wait); diff --git a/connection.h b/connection.h index 677e1ca7c6e..c301580f61b 100644 --- a/connection.h +++ b/connection.h @@ -21,11 +21,13 @@ * - connection to a control node or an endpoint */ enum kdbus_conn_type { - KDBUS_CONN_UNDEFINED, - KDBUS_CONN_CONTROL, - KDBUS_CONN_NS_OWNER, - KDBUS_CONN_BUS_OWNER, - KDBUS_CONN_EP, + _KDBUS_CONN_NULL, + KDBUS_CONN_CONTROL, /* new fd of a control node */ + KDBUS_CONN_CONTROL_NS_OWNER, /* fd to hold a namespace */ + KDBUS_CONN_CONTROL_BUS_OWNER, /* fd to hold a bus */ + KDBUS_CONN_EP, /* new fd of a bus node */ + KDBUS_CONN_EP_CONNECTED, /* connection after HELLO */ + KDBUS_CONN_EP_OWNER, /* fd to hold an endpoint */ }; struct kdbus_conn { @@ -37,17 +39,14 @@ struct kdbus_conn { struct kdbus_ep *ep; }; u64 id; /* id of the connection on the bus */ - u64 flags; - bool active; /* did the connection say hello yet? */ struct mutex lock; struct mutex names_lock; struct mutex accounting_lock; - struct list_head msg_list; + struct list_head msg_list; struct hlist_node hentry; - struct list_head connection_entry; /* bus' connections */ struct list_head monitor_entry; /* bus' monitor connections */ struct list_head names_list; /* names on this connection */ @@ -151,7 +151,7 @@ enum { }; enum { - _KDBUS_PAYLOAD_NULL, + KDBUS_PAYLOAD_KERNEL, KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */ KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */ }; diff --git a/kdbus.txt b/kdbus.txt index 72a84549b0b..016e371b8cd 100644 --- a/kdbus.txt +++ b/kdbus.txt @@ -465,9 +465,6 @@ EINVAL string which is not NUL terminated, or a string length that points behind the first NUL byte in the string. -EISCON - A control connection is already activated. - EMEDIUMTYPE A file descriptor which is not a kdbus memfd was refused to send as KDBUS_MSG_PAYLOAD_MEMFD. @@ -53,7 +53,7 @@ static int kdbus_notify_reply(struct kdbus_ep *ep, u64 src_id, kmsg->msg.dst_id = src_id; kmsg->msg.src_id = KDBUS_SRC_ID_KERNEL; - kmsg->msg.payload_type = _KDBUS_PAYLOAD_NULL; + kmsg->msg.payload_type = KDBUS_PAYLOAD_KERNEL; kmsg->msg.cookie_reply = cookie; item = kmsg->msg.items; diff --git a/test/kdbus-enum.c b/test/kdbus-enum.c index c3fc387aff2..4439787e469 100644 --- a/test/kdbus-enum.c +++ b/test/kdbus-enum.c @@ -94,7 +94,7 @@ TABLE(MATCH) = { LOOKUP(MATCH); TABLE(PAYLOAD) = { - ENUM(_KDBUS_PAYLOAD_NULL), + ENUM(KDBUS_PAYLOAD_KERNEL), ENUM(KDBUS_PAYLOAD_DBUS1), ENUM(KDBUS_PAYLOAD_GVARIANT), }; |