diff options
author | Richard Alpe <richard.alpe@ericsson.com> | 2014-11-20 04:29:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-11-21 15:01:31 -0500 |
commit | fd3cf2ad519f73c2f7a46460ebedf32ad246520c (patch) | |
tree | 805def541890ad8d3343fff208f43d3d747c56a9 | |
parent | 3e4b6ab58d614934e7ca99bdf448089695d34ffa (diff) |
tipc: add net dump to new netlink api
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/uapi/linux/tipc_netlink.h | 11 | ||||
-rw-r--r-- | net/tipc/net.c | 59 | ||||
-rw-r--r-- | net/tipc/net.h | 7 | ||||
-rw-r--r-- | net/tipc/netlink.c | 9 |
4 files changed, 84 insertions, 2 deletions
diff --git a/include/uapi/linux/tipc_netlink.h b/include/uapi/linux/tipc_netlink.h index 08a793374e8c..dcfd42002da7 100644 --- a/include/uapi/linux/tipc_netlink.h +++ b/include/uapi/linux/tipc_netlink.h | |||
@@ -53,6 +53,7 @@ enum { | |||
53 | TIPC_NL_MEDIA_GET, | 53 | TIPC_NL_MEDIA_GET, |
54 | TIPC_NL_MEDIA_SET, | 54 | TIPC_NL_MEDIA_SET, |
55 | TIPC_NL_NODE_GET, | 55 | TIPC_NL_NODE_GET, |
56 | TIPC_NL_NET_GET, | ||
56 | 57 | ||
57 | __TIPC_NL_CMD_MAX, | 58 | __TIPC_NL_CMD_MAX, |
58 | TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1 | 59 | TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1 |
@@ -67,6 +68,7 @@ enum { | |||
67 | TIPC_NLA_LINK, /* nest */ | 68 | TIPC_NLA_LINK, /* nest */ |
68 | TIPC_NLA_MEDIA, /* nest */ | 69 | TIPC_NLA_MEDIA, /* nest */ |
69 | TIPC_NLA_NODE, /* nest */ | 70 | TIPC_NLA_NODE, /* nest */ |
71 | TIPC_NLA_NET, /* nest */ | ||
70 | 72 | ||
71 | __TIPC_NLA_MAX, | 73 | __TIPC_NLA_MAX, |
72 | TIPC_NLA_MAX = __TIPC_NLA_MAX - 1 | 74 | TIPC_NLA_MAX = __TIPC_NLA_MAX - 1 |
@@ -133,6 +135,15 @@ enum { | |||
133 | TIPC_NLA_NODE_MAX = __TIPC_NLA_NODE_MAX - 1 | 135 | TIPC_NLA_NODE_MAX = __TIPC_NLA_NODE_MAX - 1 |
134 | }; | 136 | }; |
135 | 137 | ||
138 | /* Net info */ | ||
139 | enum { | ||
140 | TIPC_NLA_NET_UNSPEC, | ||
141 | TIPC_NLA_NET_ID, /* u32 */ | ||
142 | |||
143 | __TIPC_NLA_NET_MAX, | ||
144 | TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1 | ||
145 | }; | ||
146 | |||
136 | /* Publication info */ | 147 | /* Publication info */ |
137 | enum { | 148 | enum { |
138 | TIPC_NLA_PUBL_UNSPEC, | 149 | TIPC_NLA_PUBL_UNSPEC, |
diff --git a/net/tipc/net.c b/net/tipc/net.c index 93b9944a6a8b..d9e666a1be9d 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
@@ -42,6 +42,11 @@ | |||
42 | #include "node.h" | 42 | #include "node.h" |
43 | #include "config.h" | 43 | #include "config.h" |
44 | 44 | ||
45 | static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { | ||
46 | [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC }, | ||
47 | [TIPC_NLA_NET_ID] = { .type = NLA_U32 } | ||
48 | }; | ||
49 | |||
45 | /* | 50 | /* |
46 | * The TIPC locking policy is designed to ensure a very fine locking | 51 | * The TIPC locking policy is designed to ensure a very fine locking |
47 | * granularity, permitting complete parallel access to individual | 52 | * granularity, permitting complete parallel access to individual |
@@ -138,3 +143,57 @@ void tipc_net_stop(void) | |||
138 | 143 | ||
139 | pr_info("Left network mode\n"); | 144 | pr_info("Left network mode\n"); |
140 | } | 145 | } |
146 | |||
147 | static int __tipc_nl_add_net(struct tipc_nl_msg *msg) | ||
148 | { | ||
149 | void *hdr; | ||
150 | struct nlattr *attrs; | ||
151 | |||
152 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | ||
153 | NLM_F_MULTI, TIPC_NL_NET_GET); | ||
154 | if (!hdr) | ||
155 | return -EMSGSIZE; | ||
156 | |||
157 | attrs = nla_nest_start(msg->skb, TIPC_NLA_NET); | ||
158 | if (!attrs) | ||
159 | goto msg_full; | ||
160 | |||
161 | if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id)) | ||
162 | goto attr_msg_full; | ||
163 | |||
164 | nla_nest_end(msg->skb, attrs); | ||
165 | genlmsg_end(msg->skb, hdr); | ||
166 | |||
167 | return 0; | ||
168 | |||
169 | attr_msg_full: | ||
170 | nla_nest_cancel(msg->skb, attrs); | ||
171 | msg_full: | ||
172 | genlmsg_cancel(msg->skb, hdr); | ||
173 | |||
174 | return -EMSGSIZE; | ||
175 | } | ||
176 | |||
177 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
178 | { | ||
179 | int err; | ||
180 | int done = cb->args[0]; | ||
181 | struct tipc_nl_msg msg; | ||
182 | |||
183 | if (done) | ||
184 | return 0; | ||
185 | |||
186 | msg.skb = skb; | ||
187 | msg.portid = NETLINK_CB(cb->skb).portid; | ||
188 | msg.seq = cb->nlh->nlmsg_seq; | ||
189 | |||
190 | err = __tipc_nl_add_net(&msg); | ||
191 | if (err) | ||
192 | goto out; | ||
193 | |||
194 | done = 1; | ||
195 | out: | ||
196 | cb->args[0] = done; | ||
197 | |||
198 | return skb->len; | ||
199 | } | ||
diff --git a/net/tipc/net.h b/net/tipc/net.h index 59ef3388be2c..60dc22fe9267 100644 --- a/net/tipc/net.h +++ b/net/tipc/net.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/net.h: Include file for TIPC network routing code | 2 | * net/tipc/net.h: Include file for TIPC network routing code |
3 | * | 3 | * |
4 | * Copyright (c) 1995-2006, Ericsson AB | 4 | * Copyright (c) 1995-2006, 2014, Ericsson AB |
5 | * Copyright (c) 2005, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -37,7 +37,12 @@ | |||
37 | #ifndef _TIPC_NET_H | 37 | #ifndef _TIPC_NET_H |
38 | #define _TIPC_NET_H | 38 | #define _TIPC_NET_H |
39 | 39 | ||
40 | #include <net/genetlink.h> | ||
41 | |||
40 | int tipc_net_start(u32 addr); | 42 | int tipc_net_start(u32 addr); |
43 | |||
41 | void tipc_net_stop(void); | 44 | void tipc_net_stop(void); |
42 | 45 | ||
46 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); | ||
47 | |||
43 | #endif | 48 | #endif |
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index 5b0e3c8457d2..c143f9c20f61 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include "bearer.h" | 40 | #include "bearer.h" |
41 | #include "link.h" | 41 | #include "link.h" |
42 | #include "node.h" | 42 | #include "node.h" |
43 | #include "net.h" | ||
43 | #include <net/genetlink.h> | 44 | #include <net/genetlink.h> |
44 | 45 | ||
45 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | 46 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) |
@@ -79,7 +80,8 @@ static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { | |||
79 | [TIPC_NLA_PUBL] = { .type = NLA_NESTED, }, | 80 | [TIPC_NLA_PUBL] = { .type = NLA_NESTED, }, |
80 | [TIPC_NLA_LINK] = { .type = NLA_NESTED, }, | 81 | [TIPC_NLA_LINK] = { .type = NLA_NESTED, }, |
81 | [TIPC_NLA_MEDIA] = { .type = NLA_NESTED, }, | 82 | [TIPC_NLA_MEDIA] = { .type = NLA_NESTED, }, |
82 | [TIPC_NLA_NODE] = { .type = NLA_NESTED, } | 83 | [TIPC_NLA_NODE] = { .type = NLA_NESTED, }, |
84 | [TIPC_NLA_NET] = { .type = NLA_NESTED, } | ||
83 | }; | 85 | }; |
84 | 86 | ||
85 | /* Legacy ASCII API */ | 87 | /* Legacy ASCII API */ |
@@ -173,6 +175,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = { | |||
173 | .cmd = TIPC_NL_NODE_GET, | 175 | .cmd = TIPC_NL_NODE_GET, |
174 | .dumpit = tipc_nl_node_dump, | 176 | .dumpit = tipc_nl_node_dump, |
175 | .policy = tipc_nl_policy, | 177 | .policy = tipc_nl_policy, |
178 | }, | ||
179 | { | ||
180 | .cmd = TIPC_NL_NET_GET, | ||
181 | .dumpit = tipc_nl_net_dump, | ||
182 | .policy = tipc_nl_policy, | ||
176 | } | 183 | } |
177 | }; | 184 | }; |
178 | 185 | ||