[tipc-discussion] [iproute2-next] tipc: support 128bit node identity for peer removing

2020-08-26 Thread Hoang Huu Le
From: Hoang Le 

Problem:
In kernel upstream, we add the support to set node identity with
128bit. However, we are still using legacy format in command tipc
peer removing. Then, we got a problem when trying to remove
offline node i.e:

$ tipc node list
Node IdentityHash State
d6babc1c1c6d 1cbcd7ca down

$ tipc peer remove address d6babc1c1c6d
invalid network address, syntax: Z.C.N
error: No such device or address

Solution:
We add the support to remove a specific node down with 128bit
node identifier, as an alternative to legacy 32-bit node address.

Acked-by: Jon Maloy 
Signed-off-by: Hoang Huu Le 
---
 tipc/peer.c | 53 -
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/tipc/peer.c b/tipc/peer.c
index f6380777033d..f14ec35e6f71 100644
--- a/tipc/peer.c
+++ b/tipc/peer.c
@@ -59,17 +59,68 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const 
struct cmd *cmd,
return msg_doit(nlh, NULL, NULL);
 }
 
+static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
+ struct cmdl *cmdl, void *data)
+{
+   char buf[MNL_SOCKET_BUFFER_SIZE];
+   __u8 id[16] = {0,};
+   __u64 *w0 = (__u64 *)[0];
+   __u64 *w1 = (__u64 *)[8];
+   struct nlattr *nest;
+   char *str;
+
+   if (cmdl->argc != cmdl->optind + 1) {
+   fprintf(stderr, "Usage: %s peer remove identity NODEID\n",
+   cmdl->argv[0]);
+   return -EINVAL;
+   }
+
+   str = shift_cmdl(cmdl);
+   if (str2nodeid(str, id)) {
+   fprintf(stderr, "Invalid node identity\n");
+   return -EINVAL;
+   }
+
+   nlh = msg_init(buf, TIPC_NL_PEER_REMOVE);
+   if (!nlh) {
+   fprintf(stderr, "error, message initialisation failed\n");
+   return -1;
+   }
+
+   nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID, *w0);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID_W1, *w1);
+   mnl_attr_nest_end(nlh, nest);
+
+   return msg_doit(nlh, NULL, NULL);
+}
+
 static void cmd_peer_rm_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove PROPERTY\n\n"
+   "PROPERTIES\n"
+   " identity NODEID - Remove peer node identity\n",
+   cmdl->argv[0]);
+}
+
+static void cmd_peer_rm_addr_help(struct cmdl *cmdl)
 {
fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
cmdl->argv[0]);
 }
 
+static void cmd_peer_rm_nodeid_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove identity NODEID\n",
+   cmdl->argv[0]);
+}
+
 static int cmd_peer_rm(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
 {
const struct cmd cmds[] = {
-   { "address",cmd_peer_rm_addr,   cmd_peer_rm_help },
+   { "address",  cmd_peer_rm_addr,   cmd_peer_rm_addr_help },
+   { "identity", cmd_peer_rm_nodeid, cmd_peer_rm_nodeid_help },
{ NULL }
};
 
-- 
2.25.1



___
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion


[tipc-discussion] [iproute2-next] tipc: support 128bit node identity for peer removing

2020-08-24 Thread Hoang Huu Le
From: Hoang Le 

Problem:
In kernel upstream, we add the support to set node identity with
128bit. However, we are still using legacy format in command tipc
peer removing. Then, we got a problem when trying to remove
offline node i.e:

Node IdentityHash State
d6babc1c1c6d 1cbcd7ca down

invalid network address, syntax: Z.C.N
error: No such device or address

Solution:
We add the support to remove a specific node down with 128bit
node identifier, as an alternative to legacy 32-bit node address.

Signed-off-by: Hoang Le 
Signed-off-by: Hoang Huu Le 
---
 tipc/peer.c | 53 -
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/tipc/peer.c b/tipc/peer.c
index f6380777033d..f14ec35e6f71 100644
--- a/tipc/peer.c
+++ b/tipc/peer.c
@@ -59,17 +59,68 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const 
struct cmd *cmd,
return msg_doit(nlh, NULL, NULL);
 }
 
+static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
+ struct cmdl *cmdl, void *data)
+{
+   char buf[MNL_SOCKET_BUFFER_SIZE];
+   __u8 id[16] = {0,};
+   __u64 *w0 = (__u64 *)[0];
+   __u64 *w1 = (__u64 *)[8];
+   struct nlattr *nest;
+   char *str;
+
+   if (cmdl->argc != cmdl->optind + 1) {
+   fprintf(stderr, "Usage: %s peer remove identity NODEID\n",
+   cmdl->argv[0]);
+   return -EINVAL;
+   }
+
+   str = shift_cmdl(cmdl);
+   if (str2nodeid(str, id)) {
+   fprintf(stderr, "Invalid node identity\n");
+   return -EINVAL;
+   }
+
+   nlh = msg_init(buf, TIPC_NL_PEER_REMOVE);
+   if (!nlh) {
+   fprintf(stderr, "error, message initialisation failed\n");
+   return -1;
+   }
+
+   nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID, *w0);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID_W1, *w1);
+   mnl_attr_nest_end(nlh, nest);
+
+   return msg_doit(nlh, NULL, NULL);
+}
+
 static void cmd_peer_rm_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove PROPERTY\n\n"
+   "PROPERTIES\n"
+   " identity NODEID - Remove peer node identity\n",
+   cmdl->argv[0]);
+}
+
+static void cmd_peer_rm_addr_help(struct cmdl *cmdl)
 {
fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
cmdl->argv[0]);
 }
 
+static void cmd_peer_rm_nodeid_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove identity NODEID\n",
+   cmdl->argv[0]);
+}
+
 static int cmd_peer_rm(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
 {
const struct cmd cmds[] = {
-   { "address",cmd_peer_rm_addr,   cmd_peer_rm_help },
+   { "address",  cmd_peer_rm_addr,   cmd_peer_rm_addr_help },
+   { "identity", cmd_peer_rm_nodeid, cmd_peer_rm_nodeid_help },
{ NULL }
};
 
-- 
2.25.1



___
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion


[tipc-discussion] [iproute2-next] tipc: support 128bit node identity for peer removing

2019-10-13 Thread Hoang Le
We add the support to remove a specific node down with 128bit
node identifier, as an alternative to legacy 32-bit node address.

Signed-off-by: Hoang Le 
---
 tipc/peer.c | 54 -
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/tipc/peer.c b/tipc/peer.c
index f6380777033d..9f116b257fda 100644
--- a/tipc/peer.c
+++ b/tipc/peer.c
@@ -59,17 +59,69 @@ static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const 
struct cmd *cmd,
return msg_doit(nlh, NULL, NULL);
 }
 
+static int cmd_peer_rm_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
+ struct cmdl *cmdl, void *data)
+{
+   char buf[MNL_SOCKET_BUFFER_SIZE];
+   __u8 id[16] = {0,};
+   __u64 *w0 = (__u64 *)[0];
+   __u64 *w1 = (__u64 *)[8];
+   struct nlattr *nest;
+   char *str;
+
+   if (cmdl->argc != cmdl->optind + 1) {
+   fprintf(stderr, "Usage: %s peer remove nodeid NODEID\n",
+   cmdl->argv[0]);
+   return -EINVAL;
+   }
+
+   str = shift_cmdl(cmdl);
+   if (str2nodeid(str, id)) {
+   fprintf(stderr, "Invalid node identity\n");
+   return -EINVAL;
+   }
+
+   nlh = msg_init(buf, TIPC_NL_PEER_REMOVE);
+   if (!nlh) {
+   fprintf(stderr, "error, message initialisation failed\n");
+   return -1;
+   }
+
+   nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID, *w0);
+   mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID_W1, *w1);
+   mnl_attr_nest_end(nlh, nest);
+
+   return msg_doit(nlh, NULL, NULL);
+}
+
 static void cmd_peer_rm_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove PROPERTY\n\n",
+   "PROPERTIES\n"
+   " address  - Remove peer node address\n"
+   " nodeid   - Remove peer node identity\n",
+   cmdl->argv[0]);
+}
+
+static void cmd_peer_rm_addr_help(struct cmdl *cmdl)
 {
fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
cmdl->argv[0]);
 }
 
+static void cmd_peer_rm_nodeid_help(struct cmdl *cmdl)
+{
+   fprintf(stderr, "Usage: %s peer remove nodeid NODEID\n",
+   cmdl->argv[0]);
+}
+
 static int cmd_peer_rm(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, void *data)
 {
const struct cmd cmds[] = {
-   { "address",cmd_peer_rm_addr,   cmd_peer_rm_help },
+   { "address", cmd_peer_rm_addr,   cmd_peer_rm_addr_help },
+   { "nodeid",  cmd_peer_rm_nodeid, cmd_peer_rm_nodeid_help },
{ NULL }
};
 
-- 
2.20.1



___
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion