tipc-discussion
---------------
Taking up this old patch again. I have rebased it and I'm now using the new
version of tipc_node_delete().

The user space part of this was merged into iproute2 and backed out when the
kernel part was held up due to a race condition discussion mainly between Jason
and Jon. If I recall correctly Jon was at the time working on some improvements
to node delete/stop that would mitigate this theoretical race.

The old discussion can be viewed here:
http://marc.info/?l=linux-netdev&m=145513342102669&w=2

Jon, can you re-review this. Is the race still there?
---------------

Add TIPC_NL_PEER_REMOVE netlink command. This command can remove
an offline peer node from the internal data structures.

This will be supported by the tipc user space tool in iproute2.

Signed-off-by: Richard Alpe <richard.a...@ericsson.com>
Reviewed-by: Jon Maloy <jon.ma...@ericsson.com>
Acked-by: Ying Xue <ying....@windriver.com>
---
 include/uapi/linux/tipc_netlink.h |  1 +
 net/tipc/net.h                    |  2 ++
 net/tipc/netlink.c                |  5 +++++
 net/tipc/node.c                   | 44 +++++++++++++++++++++++++++++++++++++++
 net/tipc/node.h                   |  1 +
 5 files changed, 53 insertions(+)

diff --git a/include/uapi/linux/tipc_netlink.h 
b/include/uapi/linux/tipc_netlink.h
index 5f3f6d0..bcb65ef 100644
--- a/include/uapi/linux/tipc_netlink.h
+++ b/include/uapi/linux/tipc_netlink.h
@@ -59,6 +59,7 @@ enum {
        TIPC_NL_MON_SET,
        TIPC_NL_MON_GET,
        TIPC_NL_MON_PEER_GET,
+       TIPC_NL_PEER_REMOVE,
 
        __TIPC_NL_CMD_MAX,
        TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
diff --git a/net/tipc/net.h b/net/tipc/net.h
index 77a7a11..c7c2549 100644
--- a/net/tipc/net.h
+++ b/net/tipc/net.h
@@ -39,6 +39,8 @@
 
 #include <net/genetlink.h>
 
+extern const struct nla_policy tipc_nl_net_policy[];
+
 int tipc_net_start(struct net *net, u32 addr);
 
 void tipc_net_stop(struct net *net);
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index a84daec..2718de6 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -238,6 +238,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
                .dumpit = tipc_nl_node_dump_monitor_peer,
                .policy = tipc_nl_policy,
        },
+       {
+               .cmd    = TIPC_NL_PEER_REMOVE,
+               .doit   = tipc_nl_peer_rm,
+               .policy = tipc_nl_policy,
+       }
 };
 
 int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr)
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 2197419..c1d0f84 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -1553,6 +1553,50 @@ discard:
        kfree_skb(skb);
 }
 
+int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
+{
+       int err;
+       u32 addr;
+       struct net *net = sock_net(skb->sk);
+       struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
+       struct tipc_net *tn = net_generic(net, tipc_net_id);
+       struct tipc_node *peer;
+
+       /* We identify the peer by its net */
+       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_ADDR])
+               return -EINVAL;
+
+       addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
+
+       spin_lock_bh(&tn->node_list_lock);
+       list_for_each_entry_rcu(peer, &tn->node_list, list) {
+               if (peer->addr != addr)
+                       continue;
+
+               if (peer->state == SELF_DOWN_PEER_DOWN ||
+                   peer->state == SELF_DOWN_PEER_LEAVING) {
+                       tipc_node_delete(peer);
+
+                       spin_unlock_bh(&tn->node_list_lock);
+                       return 0;
+               }
+               spin_unlock_bh(&tn->node_list_lock);
+               return -EBUSY;
+       }
+       spin_unlock_bh(&tn->node_list_lock);
+
+       return -ENXIO;
+}
+
 int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
 {
        int err;
diff --git a/net/tipc/node.h b/net/tipc/node.h
index d69fdfc..4578b34 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -77,6 +77,7 @@ int tipc_nl_node_dump_link(struct sk_buff *skb, struct 
netlink_callback *cb);
 int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info);
 int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info);
 int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info);
+int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info);
 
 int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info);
 int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info);
-- 
2.1.4


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to