Skip to content

Commit

Permalink
tipc: add peer removal functionality
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jon Maloy <[email protected]>
Acked-by: Ying Xue <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Richard Alpe authored and davem330 committed Aug 19, 2016
1 parent 36a6503 commit b340402
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/uapi/linux/tipc_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions net/tipc/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions net/tipc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions net/tipc/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,69 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
kfree_skb(skb);
}

int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
{
struct net *net = sock_net(skb->sk);
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
struct tipc_node *peer;
u32 addr;
int err;
int i;

/* 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]);

if (in_own_node(net, addr))
return -ENOTSUPP;

spin_lock_bh(&tn->node_list_lock);
peer = tipc_node_find(net, addr);
if (!peer) {
spin_unlock_bh(&tn->node_list_lock);
return -ENXIO;
}

tipc_node_write_lock(peer);
if (peer->state != SELF_DOWN_PEER_DOWN &&
peer->state != SELF_DOWN_PEER_LEAVING) {
tipc_node_write_unlock(peer);
err = -EBUSY;
goto err_out;
}

for (i = 0; i < MAX_BEARERS; i++) {
struct tipc_link_entry *le = &peer->links[i];

if (le->link) {
kfree(le->link);
le->link = NULL;
peer->link_cnt--;
}
}
tipc_node_write_unlock(peer);
tipc_node_delete(peer);

err = 0;
err_out:
tipc_node_put(peer);
spin_unlock_bh(&tn->node_list_lock);

return err;
}

int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
int err;
Expand Down
1 change: 1 addition & 0 deletions net/tipc/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b340402

Please sign in to comment.