]>
git.proxmox.com Git - mirror_iproute2.git/blob - tipc/peer.c
2 * peer.c TIPC peer functionality.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Richard Alpe <richard.alpe@ericsson.com>
17 #include <linux/tipc_netlink.h>
18 #include <linux/tipc.h>
19 #include <linux/genetlink.h>
20 #include <libmnl/libmnl.h>
27 static int cmd_peer_rm_addr(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
28 struct cmdl
*cmdl
, void *data
)
33 char buf
[MNL_SOCKET_BUFFER_SIZE
];
35 if ((cmdl
->argc
!= cmdl
->optind
+ 1) || help_flag
) {
36 fprintf(stderr
, "Usage: %s peer remove address ADDRESS\n",
41 str
= shift_cmdl(cmdl
);
43 /* First try legacy Z.C.N format, then integer format */
50 if (!(nlh
= msg_init(buf
, TIPC_NL_PEER_REMOVE
))) {
51 fprintf(stderr
, "error, message initialisation failed\n");
55 nest
= mnl_attr_nest_start(nlh
, TIPC_NLA_NET
);
56 mnl_attr_put_u32(nlh
, TIPC_NLA_NET_ADDR
, addr
);
57 mnl_attr_nest_end(nlh
, nest
);
59 return msg_doit(nlh
, NULL
, NULL
);
62 static int cmd_peer_rm_nodeid(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
63 struct cmdl
*cmdl
, void *data
)
65 char buf
[MNL_SOCKET_BUFFER_SIZE
];
67 __u64
*w0
= (__u64
*)&id
[0];
68 __u64
*w1
= (__u64
*)&id
[8];
72 if (cmdl
->argc
!= cmdl
->optind
+ 1) {
73 fprintf(stderr
, "Usage: %s peer remove identity NODEID\n",
78 str
= shift_cmdl(cmdl
);
79 if (str2nodeid(str
, id
)) {
80 fprintf(stderr
, "Invalid node identity\n");
84 nlh
= msg_init(buf
, TIPC_NL_PEER_REMOVE
);
86 fprintf(stderr
, "error, message initialisation failed\n");
90 nest
= mnl_attr_nest_start(nlh
, TIPC_NLA_NET
);
91 mnl_attr_put_u64(nlh
, TIPC_NLA_NET_NODEID
, *w0
);
92 mnl_attr_put_u64(nlh
, TIPC_NLA_NET_NODEID_W1
, *w1
);
93 mnl_attr_nest_end(nlh
, nest
);
95 return msg_doit(nlh
, NULL
, NULL
);
98 static void cmd_peer_rm_help(struct cmdl
*cmdl
)
100 fprintf(stderr
, "Usage: %s peer remove PROPERTY\n\n"
102 " identity NODEID - Remove peer node identity\n",
106 static void cmd_peer_rm_addr_help(struct cmdl
*cmdl
)
108 fprintf(stderr
, "Usage: %s peer remove address ADDRESS\n",
112 static void cmd_peer_rm_nodeid_help(struct cmdl
*cmdl
)
114 fprintf(stderr
, "Usage: %s peer remove identity NODEID\n",
118 static int cmd_peer_rm(struct nlmsghdr
*nlh
, const struct cmd
*cmd
,
119 struct cmdl
*cmdl
, void *data
)
121 const struct cmd cmds
[] = {
122 { "address", cmd_peer_rm_addr
, cmd_peer_rm_addr_help
},
123 { "identity", cmd_peer_rm_nodeid
, cmd_peer_rm_nodeid_help
},
127 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);
130 void cmd_peer_help(struct cmdl
*cmdl
)
133 "Usage: %s peer COMMAND [ARGS] ...\n\n"
135 " remove - Remove an offline peer node\n",
139 int cmd_peer(struct nlmsghdr
*nlh
, const struct cmd
*cmd
, struct cmdl
*cmdl
,
142 const struct cmd cmds
[] = {
143 { "remove", cmd_peer_rm
, cmd_peer_rm_help
},
147 return run_cmd(nlh
, cmd
, cmds
, cmdl
, NULL
);