aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorRichard Alpe <richard.alpe@ericsson.com>2014-11-20 04:29:19 -0500
committerDavid S. Miller <davem@davemloft.net>2014-11-21 15:01:31 -0500
commit27c21416727af73df45051acb05331c0f10e50f6 (patch)
tree4de203dae4e71dc1ff9479b5be55656a4640b272 /net/tipc
parentfd3cf2ad519f73c2f7a46460ebedf32ad246520c (diff)
tipc: add net set to new netlink api
Add TIPC_NL_NET_SET command to the new tipc netlink API. This command can set the network id and network (tipc) address. Netlink logical layout of network set message: -> net [ -> id ] [ -> address ] 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>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/net.c47
-rw-r--r--net/tipc/net.h1
-rw-r--r--net/tipc/netlink.c5
3 files changed, 53 insertions, 0 deletions
diff --git a/net/tipc/net.c b/net/tipc/net.c
index d9e666a1be9d..cf13df3cde8f 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -197,3 +197,50 @@ out:
197 197
198 return skb->len; 198 return skb->len;
199} 199}
200
201int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
202{
203 int err;
204 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
205
206 if (!info->attrs[TIPC_NLA_NET])
207 return -EINVAL;
208
209 err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
210 info->attrs[TIPC_NLA_NET],
211 tipc_nl_net_policy);
212 if (err)
213 return err;
214
215 if (attrs[TIPC_NLA_NET_ID]) {
216 u32 val;
217
218 /* Can't change net id once TIPC has joined a network */
219 if (tipc_own_addr)
220 return -EPERM;
221
222 val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
223 if (val < 1 || val > 9999)
224 return -EINVAL;
225
226 tipc_net_id = val;
227 }
228
229 if (attrs[TIPC_NLA_NET_ADDR]) {
230 u32 addr;
231
232 /* Can't change net addr once TIPC has joined a network */
233 if (tipc_own_addr)
234 return -EPERM;
235
236 addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
237 if (!tipc_addr_node_valid(addr))
238 return -EINVAL;
239
240 rtnl_lock();
241 tipc_net_start(addr);
242 rtnl_unlock();
243 }
244
245 return 0;
246}
diff --git a/net/tipc/net.h b/net/tipc/net.h
index 60dc22fe9267..a81c1b9eb150 100644
--- a/net/tipc/net.h
+++ b/net/tipc/net.h
@@ -44,5 +44,6 @@ int tipc_net_start(u32 addr);
44void tipc_net_stop(void); 44void tipc_net_stop(void);
45 45
46int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); 46int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
47int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
47 48
48#endif 49#endif
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index c143f9c20f61..cb37d30378a8 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -180,6 +180,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
180 .cmd = TIPC_NL_NET_GET, 180 .cmd = TIPC_NL_NET_GET,
181 .dumpit = tipc_nl_net_dump, 181 .dumpit = tipc_nl_net_dump,
182 .policy = tipc_nl_policy, 182 .policy = tipc_nl_policy,
183 },
184 {
185 .cmd = TIPC_NL_NET_SET,
186 .doit = tipc_nl_net_set,
187 .policy = tipc_nl_policy,
183 } 188 }
184}; 189};
185 190