]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
tipc: add net set to new netlink api
authorRichard Alpe <richard.alpe@ericsson.com>
Thu, 20 Nov 2014 09:29:19 +0000 (10:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Nov 2014 20:01:31 +0000 (15:01 -0500)
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>
include/uapi/linux/tipc_netlink.h
net/tipc/net.c
net/tipc/net.h
net/tipc/netlink.c

index dcfd42002da785308376a70049f283e8d4ba0602..fb980e27f4254560e2da522f24cf7c991e32f1a7 100644 (file)
@@ -54,6 +54,7 @@ enum {
        TIPC_NL_MEDIA_SET,
        TIPC_NL_NODE_GET,
        TIPC_NL_NET_GET,
+       TIPC_NL_NET_SET,
 
        __TIPC_NL_CMD_MAX,
        TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
@@ -139,6 +140,7 @@ enum {
 enum {
        TIPC_NLA_NET_UNSPEC,
        TIPC_NLA_NET_ID,                /* u32 */
+       TIPC_NLA_NET_ADDR,              /* u32 */
 
        __TIPC_NLA_NET_MAX,
        TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1
index d9e666a1be9d64ca3fd099944122badceaaa019b..cf13df3cde8f9ec48ddb8ee2f326e2caad9a25de 100644 (file)
@@ -197,3 +197,50 @@ out:
 
        return skb->len;
 }
+
+int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
+{
+       int err;
+       struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
+
+       if (!info->attrs[TIPC_NLA_NET])
+               return -EINVAL;
+
+       err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
+                              info->attrs[TIPC_NLA_NET],
+                              tipc_nl_net_policy);
+       if (err)
+               return err;
+
+       if (attrs[TIPC_NLA_NET_ID]) {
+               u32 val;
+
+               /* Can't change net id once TIPC has joined a network */
+               if (tipc_own_addr)
+                       return -EPERM;
+
+               val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
+               if (val < 1 || val > 9999)
+                       return -EINVAL;
+
+               tipc_net_id = val;
+       }
+
+       if (attrs[TIPC_NLA_NET_ADDR]) {
+               u32 addr;
+
+               /* Can't change net addr once TIPC has joined a network */
+               if (tipc_own_addr)
+                       return -EPERM;
+
+               addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
+               if (!tipc_addr_node_valid(addr))
+                       return -EINVAL;
+
+               rtnl_lock();
+               tipc_net_start(addr);
+               rtnl_unlock();
+       }
+
+       return 0;
+}
index 60dc22fe9267f5582902ea7a231f1f6cfb7b0f71..a81c1b9eb150630706a807679d841afaa837cec3 100644 (file)
@@ -44,5 +44,6 @@ int tipc_net_start(u32 addr);
 void tipc_net_stop(void);
 
 int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb);
+int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info);
 
 #endif
index c143f9c20f6168c76524c64870a20d25c67afdc6..cb37d30378a8fe30d71601842ceb38f8645ad942 100644 (file)
@@ -180,6 +180,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
                .cmd    = TIPC_NL_NET_GET,
                .dumpit = tipc_nl_net_dump,
                .policy = tipc_nl_policy,
+       },
+       {
+               .cmd    = TIPC_NL_NET_SET,
+               .doit   = tipc_nl_net_set,
+               .policy = tipc_nl_policy,
        }
 };