Skip to content

Commit b340402

Browse files
Richard Alpedavem330
authored andcommitted
tipc: add peer removal functionality
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]>
1 parent 36a6503 commit b340402

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

include/uapi/linux/tipc_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum {
5959
TIPC_NL_MON_SET,
6060
TIPC_NL_MON_GET,
6161
TIPC_NL_MON_PEER_GET,
62+
TIPC_NL_PEER_REMOVE,
6263

6364
__TIPC_NL_CMD_MAX,
6465
TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1

net/tipc/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
#include <net/genetlink.h>
4141

42+
extern const struct nla_policy tipc_nl_net_policy[];
43+
4244
int tipc_net_start(struct net *net, u32 addr);
4345

4446
void tipc_net_stop(struct net *net);

net/tipc/netlink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
238238
.dumpit = tipc_nl_node_dump_monitor_peer,
239239
.policy = tipc_nl_policy,
240240
},
241+
{
242+
.cmd = TIPC_NL_PEER_REMOVE,
243+
.doit = tipc_nl_peer_rm,
244+
.policy = tipc_nl_policy,
245+
}
241246
};
242247

243248
int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr)

net/tipc/node.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,69 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
15531553
kfree_skb(skb);
15541554
}
15551555

1556+
int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info)
1557+
{
1558+
struct net *net = sock_net(skb->sk);
1559+
struct tipc_net *tn = net_generic(net, tipc_net_id);
1560+
struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
1561+
struct tipc_node *peer;
1562+
u32 addr;
1563+
int err;
1564+
int i;
1565+
1566+
/* We identify the peer by its net */
1567+
if (!info->attrs[TIPC_NLA_NET])
1568+
return -EINVAL;
1569+
1570+
err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
1571+
info->attrs[TIPC_NLA_NET],
1572+
tipc_nl_net_policy);
1573+
if (err)
1574+
return err;
1575+
1576+
if (!attrs[TIPC_NLA_NET_ADDR])
1577+
return -EINVAL;
1578+
1579+
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
1580+
1581+
if (in_own_node(net, addr))
1582+
return -ENOTSUPP;
1583+
1584+
spin_lock_bh(&tn->node_list_lock);
1585+
peer = tipc_node_find(net, addr);
1586+
if (!peer) {
1587+
spin_unlock_bh(&tn->node_list_lock);
1588+
return -ENXIO;
1589+
}
1590+
1591+
tipc_node_write_lock(peer);
1592+
if (peer->state != SELF_DOWN_PEER_DOWN &&
1593+
peer->state != SELF_DOWN_PEER_LEAVING) {
1594+
tipc_node_write_unlock(peer);
1595+
err = -EBUSY;
1596+
goto err_out;
1597+
}
1598+
1599+
for (i = 0; i < MAX_BEARERS; i++) {
1600+
struct tipc_link_entry *le = &peer->links[i];
1601+
1602+
if (le->link) {
1603+
kfree(le->link);
1604+
le->link = NULL;
1605+
peer->link_cnt--;
1606+
}
1607+
}
1608+
tipc_node_write_unlock(peer);
1609+
tipc_node_delete(peer);
1610+
1611+
err = 0;
1612+
err_out:
1613+
tipc_node_put(peer);
1614+
spin_unlock_bh(&tn->node_list_lock);
1615+
1616+
return err;
1617+
}
1618+
15561619
int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
15571620
{
15581621
int err;

net/tipc/node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb);
7777
int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info);
7878
int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info);
7979
int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info);
80+
int tipc_nl_peer_rm(struct sk_buff *skb, struct genl_info *info);
8081

8182
int tipc_nl_node_set_monitor(struct sk_buff *skb, struct genl_info *info);
8283
int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info);

0 commit comments

Comments
 (0)