From: <richard.alpe@ericsson.com>
To: <netdev@vger.kernel.org>
Cc: tipc-discussion@lists.sourceforge.net
Subject: [PATCH net-next 11/14] tipc: add net dump to new netlink api
Date: Thu, 11 Sep 2014 10:29:24 +0200 [thread overview]
Message-ID: <1410424167-17427-12-git-send-email-richard.alpe@ericsson.com> (raw)
In-Reply-To: <1410424167-17427-1-git-send-email-richard.alpe@ericsson.com>
From: Richard Alpe <richard.alpe@ericsson.com>
Add TIPC_NL_NET_GET command to the new tipc netlink API.
This command dumps the network id of the node.
Netlink logical layout of returned network data:
-> net
-> id
Signed-off-by: Richard Alpe <richard.alpe@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
---
include/uapi/linux/tipc_config.h | 11 +++++++
net/tipc/net.c | 59 ++++++++++++++++++++++++++++++++++++++
net/tipc/net.h | 7 ++++-
net/tipc/netlink.c | 9 +++++-
4 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/tipc_config.h b/include/uapi/linux/tipc_config.h
index e3dfad7..68a58b0 100644
--- a/include/uapi/linux/tipc_config.h
+++ b/include/uapi/linux/tipc_config.h
@@ -61,6 +61,7 @@ enum {
TIPC_NL_MEDIA_GET,
TIPC_NL_MEDIA_SET,
TIPC_NL_NODE_GET,
+ TIPC_NL_NET_GET,
__TIPC_NL_CMD_MAX,
TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
@@ -74,6 +75,7 @@ enum {
TIPC_NLA_LINK, /* nest */
TIPC_NLA_MEDIA, /* nest */
TIPC_NLA_NODE, /* nest */
+ TIPC_NLA_NET, /* nest */
__TIPC_NLA_MAX,
TIPC_NLA_MAX = __TIPC_NLA_MAX - 1
@@ -139,6 +141,15 @@ enum {
TIPC_NLA_NODE_MAX = __TIPC_NLA_NODE_MAX - 1
};
+/* Net info */
+enum {
+ TIPC_NLA_NET_UNSPEC,
+ TIPC_NLA_NET_ID, /* u32 */
+
+ __TIPC_NLA_NET_MAX,
+ TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1
+};
+
/* Nest, publication info */
enum {
TIPC_NLA_PUBL_UNSPEC,
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 93b9944..b5435a6 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -42,6 +42,11 @@
#include "node.h"
#include "config.h"
+static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
+ [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC },
+ [TIPC_NLA_NET_ID] = { .type = NLA_U32 }
+};
+
/*
* The TIPC locking policy is designed to ensure a very fine locking
* granularity, permitting complete parallel access to individual
@@ -138,3 +143,57 @@ void tipc_net_stop(void)
pr_info("Left network mode\n");
}
+
+static int __tipc_nl_add_net(struct tipc_nl_msg *msg)
+{
+ void *hdr;
+ struct nlattr *attrs;
+
+ hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
+ NLM_F_MULTI, TIPC_NL_NET_GET);
+ if (!hdr)
+ return -EMSGSIZE;
+
+ attrs = nla_nest_start(msg->skb, TIPC_NLA_NET);
+ if (!attrs)
+ goto msg_full;
+
+ if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id))
+ goto attr_msg_full;
+
+ nla_nest_end(msg->skb, attrs);
+ genlmsg_end(msg->skb, hdr);
+
+ return 0;
+
+attr_msg_full:
+ nla_nest_cancel(msg->skb, attrs);
+msg_full:
+ genlmsg_cancel(msg->skb, hdr);
+
+ return -EMSGSIZE;
+}
+
+int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
+{
+ int err;
+ int done = cb->args[0];
+ struct tipc_nl_msg msg;
+
+ if (done)
+ return 0;
+
+ msg.skb = skb;
+ msg.portid = NETLINK_CB(cb->skb).portid;
+ msg.seq = cb->nlh->nlmsg_seq;
+
+ err = __tipc_nl_add_net(&msg);
+ if (err)
+ goto out;
+
+ done = 1;
+out:
+ cb->args[0] = done;
+
+ return skb->len;
+}
diff --git a/net/tipc/net.h b/net/tipc/net.h
index 59ef338..60dc22f 100644
--- a/net/tipc/net.h
+++ b/net/tipc/net.h
@@ -1,7 +1,7 @@
/*
* net/tipc/net.h: Include file for TIPC network routing code
*
- * Copyright (c) 1995-2006, Ericsson AB
+ * Copyright (c) 1995-2006, 2014, Ericsson AB
* Copyright (c) 2005, 2010-2011, Wind River Systems
* All rights reserved.
*
@@ -37,7 +37,12 @@
#ifndef _TIPC_NET_H
#define _TIPC_NET_H
+#include <net/genetlink.h>
+
int tipc_net_start(u32 addr);
+
void tipc_net_stop(void);
+int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
+
#endif
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index d42027e..3730876 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -40,6 +40,7 @@
#include "bearer.h"
#include "link.h"
#include "node.h"
+#include "net.h"
#include <net/genetlink.h>
static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
@@ -78,7 +79,8 @@ static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = {
[TIPC_NLA_SOCK] = { .type = NLA_NESTED, },
[TIPC_NLA_LINK] = { .type = NLA_NESTED, },
[TIPC_NLA_MEDIA] = { .type = NLA_NESTED, },
- [TIPC_NLA_NODE] = { .type = NLA_NESTED, }
+ [TIPC_NLA_NODE] = { .type = NLA_NESTED, },
+ [TIPC_NLA_NET] = { .type = NLA_NESTED, }
};
struct genl_family tipc_genl_family = {
@@ -152,6 +154,11 @@ static const struct genl_ops tipc_genl_ops[] = {
.cmd = TIPC_NL_NODE_GET,
.dumpit = tipc_nl_node_dump,
.policy = tipc_nl_policy,
+ },
+ {
+ .cmd = TIPC_NL_NET_GET,
+ .dumpit = tipc_nl_net_dump,
+ .policy = tipc_nl_policy,
}
};
--
1.7.10.4
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
next prev parent reply other threads:[~2014-09-11 8:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-11 8:29 [PATCH net-next 00/14] tipc: new netlink API richard.alpe
2014-09-11 8:29 ` [PATCH net-next 01/14] tipc: add bearer disable/enable to new netlink api richard.alpe
2014-09-12 21:07 ` David Miller
2014-09-11 8:29 ` [PATCH net-next 02/14] tipc: add bearer get/dump " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 03/14] tipc: add bearer set " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 04/14] tipc: add sock dump " richard.alpe
2014-09-12 21:10 ` David Miller
2014-09-15 7:55 ` Richard Alpe
2014-09-15 8:51 ` Florian Westphal
2014-09-15 12:35 ` Richard Alpe
2014-09-15 15:38 ` David Miller
2014-09-15 16:35 ` Jon Maloy
2014-09-23 11:12 ` Richard Alpe
2014-09-23 15:37 ` David Miller
2014-09-11 8:29 ` [PATCH net-next 05/14] tipc: add link get/dump " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 06/14] tipc: add link set " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 07/14] tipc: add link stat reset " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 08/14] tipc: add media get/dump " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 09/14] tipc: add media set " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 10/14] tipc: add node get/dump " richard.alpe
2014-09-11 8:29 ` richard.alpe [this message]
2014-09-11 8:29 ` [PATCH net-next 12/14] tipc: add net set " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 13/14] tipc: add name table dump " richard.alpe
2014-09-11 8:29 ` [PATCH net-next 14/14] tipc: remove old ASCII netlink API richard.alpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410424167-17427-12-git-send-email-richard.alpe@ericsson.com \
--to=richard.alpe@ericsson.com \
--cc=netdev@vger.kernel.org \
--cc=tipc-discussion@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).