netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] tipc: add support for link state subscriptions
@ 2014-04-23 15:01 erik.hugne
  2014-04-23 15:01 ` [PATCH net-next 1/2] " erik.hugne
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: erik.hugne @ 2014-04-23 15:01 UTC (permalink / raw)
  To: netdev, tipc-discussion, jon.maloy, maloy
  Cc: ying.xue, paul.gortmaker, richard.alpe, Erik Hugne

From: Erik Hugne <erik.hugne@ericsson.com>

Low level topology information like TIPC link up/down is useful for
applications like teamd to make smarter failover decisions in a
HA cluster environment. Fetching logical link names through an ioctl
may hurt the eyes of some. Suggestions for a more elegant way of doing
this would be appreciated in that case. :)

Erik Hugne (2):
  tipc: add support for link state subscriptions
  tipc: add ioctl to fetch link names

 include/uapi/linux/tipc.h | 10 ++++++++++
 net/tipc/node.c           | 35 ++++++++++++++++++++++++++++++++++-
 net/tipc/node.h           |  1 +
 net/tipc/socket.c         | 29 ++++++++++++++++++++++++++---
 4 files changed, 71 insertions(+), 4 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] tipc: add support for link state subscriptions
  2014-04-23 15:01 [PATCH net-next 0/2] tipc: add support for link state subscriptions erik.hugne
@ 2014-04-23 15:01 ` erik.hugne
  2014-04-23 15:01 ` [PATCH net-next 2/2] tipc: add ioctl to fetch link names erik.hugne
  2014-04-24 10:52 ` [PATCH net-next 0/2] tipc: add support for link state subscriptions Erik Hugne
  2 siblings, 0 replies; 4+ messages in thread
From: erik.hugne @ 2014-04-23 15:01 UTC (permalink / raw)
  To: netdev, tipc-discussion, jon.maloy, maloy
  Cc: ying.xue, paul.gortmaker, richard.alpe, Erik Hugne

From: Erik Hugne <erik.hugne@ericsson.com>

When links are established over a bearer plane, we create a node
local publication containing information about the peer node and
bearer plane. This allows TIPC applications to use the standard
TIPC topology server subscription mechanism to get notifications
when a link goes up or down.

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
 include/uapi/linux/tipc.h | 1 +
 net/tipc/node.c           | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h
index 852373d..53cd790 100644
--- a/include/uapi/linux/tipc.h
+++ b/include/uapi/linux/tipc.h
@@ -87,6 +87,7 @@ static inline unsigned int tipc_node(__u32 addr)
 
 #define TIPC_CFG_SRV		0	/* configuration service name type */
 #define TIPC_TOP_SRV		1	/* topology service name type */
+#define TIPC_LINK_STATE		2	/* link state name type */
 #define TIPC_RESERVED_TYPES	64	/* lowest user-publishable name type */
 
 /*
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 1d3a499..527e751 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -144,9 +144,12 @@ void tipc_node_stop(void)
 void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 {
 	struct tipc_link **active = &n_ptr->active_links[0];
+	u32 addr = n_ptr->addr;
+	u32 identity = l_ptr->b_ptr->identity;
 
 	n_ptr->working_links++;
-
+	tipc_nametbl_publish(TIPC_LINK_STATE, addr, addr, TIPC_NODE_SCOPE,
+			     identity, addr);
 	pr_info("Established link <%s> on network plane %c\n",
 		l_ptr->name, l_ptr->b_ptr->net_plane);
 
@@ -203,8 +206,11 @@ static void node_select_active_links(struct tipc_node *n_ptr)
 void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 {
 	struct tipc_link **active;
+	u32 addr = n_ptr->addr;
+	u32 identity = l_ptr->b_ptr->identity;
 
 	n_ptr->working_links--;
+	tipc_nametbl_withdraw(TIPC_LINK_STATE, addr, identity, addr);
 
 	if (!tipc_link_is_active(l_ptr)) {
 		pr_info("Lost standby link <%s> on network plane %c\n",
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] tipc: add ioctl to fetch link names
  2014-04-23 15:01 [PATCH net-next 0/2] tipc: add support for link state subscriptions erik.hugne
  2014-04-23 15:01 ` [PATCH net-next 1/2] " erik.hugne
@ 2014-04-23 15:01 ` erik.hugne
  2014-04-24 10:52 ` [PATCH net-next 0/2] tipc: add support for link state subscriptions Erik Hugne
  2 siblings, 0 replies; 4+ messages in thread
From: erik.hugne @ 2014-04-23 15:01 UTC (permalink / raw)
  To: netdev, tipc-discussion, jon.maloy, maloy
  Cc: ying.xue, paul.gortmaker, richard.alpe, Erik Hugne

From: Erik Hugne <erik.hugne@ericsson.com>

We add a new ioctl for AF_TIPC that can be used to fetch the
logical name for a link to a remote node on a given bearer. This
should be used in combination with link state subscriptions.

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
---
 include/uapi/linux/tipc.h |  9 +++++++++
 net/tipc/node.c           | 27 +++++++++++++++++++++++++++
 net/tipc/node.h           |  1 +
 net/tipc/socket.c         | 29 ++++++++++++++++++++++++++---
 4 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h
index 53cd790..172042c 100644
--- a/include/uapi/linux/tipc.h
+++ b/include/uapi/linux/tipc.h
@@ -38,6 +38,7 @@
 #define _LINUX_TIPC_H_
 
 #include <linux/types.h>
+#include <linux/sockios.h>
 
 /*
  * TIPC addressing primitives
@@ -207,4 +208,12 @@ struct sockaddr_tipc {
 #define TIPC_NODE_RECVQ_DEPTH	131	/* Default: none (read only) */
 #define TIPC_SOCK_RECVQ_DEPTH	132	/* Default: none (read only) */
 
+
+#define SIOCGETLINKNAME		SIOCPROTOPRIVATE
+
+struct tipc_sioc_ln_req {
+	__u32 peer;
+	__u32 bearer_id;
+	char linkname[255];
+};
 #endif
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 527e751..5172221 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -442,3 +442,30 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
 	rcu_read_unlock();
 	return buf;
 }
+
+/**
+ * tipc_node_get_linkname - get the name of a link
+ *
+ * @bearer_id: id of the bearer
+ * @node: peer node address
+ * @linkname: link name output buffer
+ *
+ * Returns 0 on success
+ */
+int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname)
+{
+	struct tipc_link *link;
+	struct tipc_node *node = tipc_node_find(addr);
+
+	if ((bearer_id > MAX_BEARERS) || !node)
+		return -EINVAL;
+	tipc_node_lock(node);
+	link = node->links[bearer_id];
+	if (link) {
+		strncpy(linkname, link->name, TIPC_MAX_LINK_NAME);
+		tipc_node_unlock(node);
+		return 0;
+	}
+	tipc_node_unlock(node);
+	return -EINVAL;
+}
diff --git a/net/tipc/node.h b/net/tipc/node.h
index 7cbb8ce..baf3bf7 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -118,6 +118,7 @@ int tipc_node_active_links(struct tipc_node *n_ptr);
 int tipc_node_is_up(struct tipc_node *n_ptr);
 struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space);
 struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space);
+int tipc_node_get_linkname(u32 bearer_id, u32 node, char *linkname);
 
 static inline void tipc_node_lock(struct tipc_node *n_ptr)
 {
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 29b7f26..841f986 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -36,6 +36,7 @@
 
 #include "core.h"
 #include "port.h"
+#include "node.h"
 
 #include <linux/export.h>
 
@@ -1906,6 +1907,28 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
 	return put_user(sizeof(value), ol);
 }
 
+int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg)
+{
+	struct tipc_sioc_ln_req lnr;
+	void __user *argp = (void __user *)arg;
+
+	switch (cmd) {
+	case SIOCGETLINKNAME:
+		if (copy_from_user(&lnr, argp, sizeof(lnr)))
+			return -EFAULT;
+		if (!tipc_node_get_linkname(lnr.bearer_id, lnr.peer,
+					    lnr.linkname)) {
+			if (copy_to_user(argp, &lnr, sizeof(lnr)))
+				return -EFAULT;
+			return 0;
+		}
+		return -EADDRNOTAVAIL;
+		break;
+	default:
+		return -ENOIOCTLCMD;
+	}
+}
+
 /* Protocol switches for the various types of TIPC sockets */
 
 static const struct proto_ops msg_ops = {
@@ -1918,7 +1941,7 @@ static const struct proto_ops msg_ops = {
 	.accept		= sock_no_accept,
 	.getname	= tipc_getname,
 	.poll		= tipc_poll,
-	.ioctl		= sock_no_ioctl,
+	.ioctl		= tipc_ioctl,
 	.listen		= sock_no_listen,
 	.shutdown	= tipc_shutdown,
 	.setsockopt	= tipc_setsockopt,
@@ -1939,7 +1962,7 @@ static const struct proto_ops packet_ops = {
 	.accept		= tipc_accept,
 	.getname	= tipc_getname,
 	.poll		= tipc_poll,
-	.ioctl		= sock_no_ioctl,
+	.ioctl		= tipc_ioctl,
 	.listen		= tipc_listen,
 	.shutdown	= tipc_shutdown,
 	.setsockopt	= tipc_setsockopt,
@@ -1960,7 +1983,7 @@ static const struct proto_ops stream_ops = {
 	.accept		= tipc_accept,
 	.getname	= tipc_getname,
 	.poll		= tipc_poll,
-	.ioctl		= sock_no_ioctl,
+	.ioctl		= tipc_ioctl,
 	.listen		= tipc_listen,
 	.shutdown	= tipc_shutdown,
 	.setsockopt	= tipc_setsockopt,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] tipc: add support for link state subscriptions
  2014-04-23 15:01 [PATCH net-next 0/2] tipc: add support for link state subscriptions erik.hugne
  2014-04-23 15:01 ` [PATCH net-next 1/2] " erik.hugne
  2014-04-23 15:01 ` [PATCH net-next 2/2] tipc: add ioctl to fetch link names erik.hugne
@ 2014-04-24 10:52 ` Erik Hugne
  2 siblings, 0 replies; 4+ messages in thread
From: Erik Hugne @ 2014-04-24 10:52 UTC (permalink / raw)
  To: netdev, tipc-discussion, jon.maloy, maloy
  Cc: ying.xue, paul.gortmaker, richard.alpe

On Wed, Apr 23, 2014 at 05:01:13PM +0200, erik.hugne@ericsson.com wrote:
> From: Erik Hugne <erik.hugne@ericsson.com>
> 
> Low level topology information like TIPC link up/down is useful for
> applications like teamd to make smarter failover decisions in a
> HA cluster environment. Fetching logical link names through an ioctl
> may hurt the eyes of some. Suggestions for a more elegant way of doing
> this would be appreciated in that case. :)
>

Please ignore this set, i just noticed it doesn't apply cleanly 
(pebkac on my side). Will do a v2 resend, sorry.

//E

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-24 10:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-23 15:01 [PATCH net-next 0/2] tipc: add support for link state subscriptions erik.hugne
2014-04-23 15:01 ` [PATCH net-next 1/2] " erik.hugne
2014-04-23 15:01 ` [PATCH net-next 2/2] tipc: add ioctl to fetch link names erik.hugne
2014-04-24 10:52 ` [PATCH net-next 0/2] tipc: add support for link state subscriptions Erik Hugne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).