]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - net/tipc/net.c
tipc: make bearer list support net namespace
[mirror_ubuntu-zesty-kernel.git] / net / tipc / net.c
index cf13df3cde8f9ec48ddb8ee2f326e2caad9a25de..38633e5f8a7d0be73b85d00493396ce5e2045913 100644 (file)
@@ -108,44 +108,48 @@ static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
  *     - A local spin_lock protecting the queue of subscriber events.
 */
 
-int tipc_net_start(u32 addr)
+int tipc_net_start(struct net *net, u32 addr)
 {
+       struct tipc_net *tn = net_generic(net, tipc_net_id);
        char addr_string[16];
        int res;
 
        tipc_own_addr = addr;
        tipc_named_reinit();
        tipc_sk_reinit();
-       res = tipc_bclink_init();
+       res = tipc_bclink_init(net);
        if (res)
                return res;
 
-       tipc_nametbl_publish(TIPC_CFG_SRV, tipc_own_addr, tipc_own_addr,
+       tipc_nametbl_publish(net, TIPC_CFG_SRV, tipc_own_addr, tipc_own_addr,
                             TIPC_ZONE_SCOPE, 0, tipc_own_addr);
 
        pr_info("Started in network mode\n");
        pr_info("Own node address %s, network identity %u\n",
-               tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id);
+               tipc_addr_string_fill(addr_string, tipc_own_addr),
+               tn->net_id);
        return 0;
 }
 
-void tipc_net_stop(void)
+void tipc_net_stop(struct net *net)
 {
        if (!tipc_own_addr)
                return;
 
-       tipc_nametbl_withdraw(TIPC_CFG_SRV, tipc_own_addr, 0, tipc_own_addr);
+       tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tipc_own_addr, 0,
+                             tipc_own_addr);
        rtnl_lock();
-       tipc_bearer_stop();
-       tipc_bclink_stop();
-       tipc_node_stop();
+       tipc_bearer_stop(net);
+       tipc_bclink_stop(net);
+       tipc_node_stop(net);
        rtnl_unlock();
 
        pr_info("Left network mode\n");
 }
 
-static int __tipc_nl_add_net(struct tipc_nl_msg *msg)
+static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
 {
+       struct tipc_net *tn = net_generic(net, tipc_net_id);
        void *hdr;
        struct nlattr *attrs;
 
@@ -158,7 +162,7 @@ static int __tipc_nl_add_net(struct tipc_nl_msg *msg)
        if (!attrs)
                goto msg_full;
 
-       if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id))
+       if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id))
                goto attr_msg_full;
 
        nla_nest_end(msg->skb, attrs);
@@ -176,6 +180,7 @@ msg_full:
 
 int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = sock_net(skb->sk);
        int err;
        int done = cb->args[0];
        struct tipc_nl_msg msg;
@@ -187,7 +192,7 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
        msg.portid = NETLINK_CB(cb->skb).portid;
        msg.seq = cb->nlh->nlmsg_seq;
 
-       err = __tipc_nl_add_net(&msg);
+       err = __tipc_nl_add_net(net, &msg);
        if (err)
                goto out;
 
@@ -200,8 +205,10 @@ out:
 
 int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
 {
-       int err;
+       struct net *net = genl_info_net(info);
+       struct tipc_net *tn = net_generic(net, tipc_net_id);
        struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
+       int err;
 
        if (!info->attrs[TIPC_NLA_NET])
                return -EINVAL;
@@ -223,7 +230,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
                if (val < 1 || val > 9999)
                        return -EINVAL;
 
-               tipc_net_id = val;
+               tn->net_id = val;
        }
 
        if (attrs[TIPC_NLA_NET_ADDR]) {
@@ -238,7 +245,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
                        return -EINVAL;
 
                rtnl_lock();
-               tipc_net_start(addr);
+               tipc_net_start(net, addr);
                rtnl_unlock();
        }