Hi Jon,

The patch is fine with me. But when I applied it to latest iproute2 git
repo, the following error met:

Applying: tipc: introduce command for handling a new 128-bit node identity
error: include/linux/tipc_netlink.h: does not exist in index
Patch failed at 0001 tipc: introduce command for handling a new 128-bit
node identity
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Below is the latest commit of iproute2 git repo:

Commit ID: 527f85141c9e6982f73f043f85949eaf7ff498bc ("ip-address: Fix
negative prints of large TX rate limits").

Can you please help to rebase the patch to latest version?

Thanks,
Ying


On 03/08/2018 02:29 AM, Jon Maloy wrote:
> We add the possibility to set and get a 128 bit node identifier, as
> an alternative to the legacy 32-bit node address we are using now.
> 
> Signed-off-by: Jon Maloy <[email protected]>
> ---
>  include/linux/tipc_netlink.h |  2 ++
>  tipc/misc.c                  | 82 +++++++++++++++++++++++++++++++++++++++++-
>  tipc/misc.h                  |  2 ++
>  tipc/node.c                  | 84 
> ++++++++++++++++++++++++++++++++++++++++++--
>  4 files changed, 167 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/tipc_netlink.h b/include/linux/tipc_netlink.h
> index f9edd20..5dd1db8 100644
> --- a/include/linux/tipc_netlink.h
> +++ b/include/linux/tipc_netlink.h
> @@ -161,6 +161,8 @@ enum {
>       TIPC_NLA_NET_UNSPEC,
>       TIPC_NLA_NET_ID,                /* u32 */
>       TIPC_NLA_NET_ADDR,              /* u32 */
> +     TIPC_NLA_NET_NODEID,            /* u64 */
> +     TIPC_NLA_NET_NODEID_W1,         /* u64 */
>  
>       __TIPC_NLA_NET_MAX,
>       TIPC_NLA_NET_MAX = __TIPC_NLA_NET_MAX - 1
> diff --git a/tipc/misc.c b/tipc/misc.c
> index 8091222..b8d23a0 100644
> --- a/tipc/misc.c
> +++ b/tipc/misc.c
> @@ -12,9 +12,10 @@
>  #include <stdio.h>
>  #include <stdint.h>
>  #include <linux/tipc.h>
> -
> +#include <string.h>
>  #include "misc.h"
>  
> +
>  #define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low))
>  
>  uint32_t str2addr(char *str)
> @@ -33,3 +34,82 @@ uint32_t str2addr(char *str)
>       fprintf(stderr, "invalid network address \"%s\"\n", str);
>       return 0;
>  }
> +
> +static int is_hex(char *arr, int last)
> +{
> +     int i;
> +
> +     while (!arr[last])
> +             last--;
> +
> +     for (i = 0; i <= last; i++) {
> +             if (!IN_RANGE(arr[i], '0', '9') &&
> +                 !IN_RANGE(arr[i], 'a', 'f') &&
> +                 !IN_RANGE(arr[i], 'A', 'F'))
> +                     return 0;
> +     }
> +     return 1;
> +}
> +
> +static int is_name(char *arr, int last)
> +{
> +     int i;
> +     char c;
> +
> +     while (!arr[last])
> +             last--;
> +
> +     if (last > 15)
> +             return 0;
> +
> +     for (i = 0; i <= last; i++) {
> +             c = arr[i];
> +             if (!IN_RANGE(c, '0', '9') && !IN_RANGE(c, 'a', 'z') &&
> +                 !IN_RANGE(c, 'A', 'Z') && c != '-' && c != '_' &&
> +                 c != '.' && c != ':' && c != '@')
> +                     return 0;
> +     }
> +     return 1;
> +}
> +
> +int str2nodeid(char *str, uint8_t *id)
> +{
> +     int len = strlen(str);
> +     int i;
> +
> +     if (len > 32)
> +             return -1;
> +
> +     if (is_name(str, len - 1)) {
> +             memcpy(id, str, len);
> +             return 0;
> +     }
> +     if (!is_hex(str, len - 1))
> +             return -1;
> +
> +     str[len] = '0';
> +     for (i = 0; i < 16; i++) {
> +             if (sscanf(&str[2 * i], "%02x", &id[i]) == 1)
> +                     continue;
> +             break;
> +     }
> +     return 0;
> +}
> +
> +void nodeid2str(uint8_t *id, char *str)
> +{
> +     int i;
> +
> +     if (is_name(id, 15)) {
> +             memcpy(str, id, 16);
> +             return;
> +     }
> +
> +     for (i = 0; i < 16; i++) {
> +             sprintf(&str[2 * i], "%02x", id[i]);
> +     }
> +
> +     for (i = 31; str[i] == '0'; i--) {
> +             str[i] = 0;
> +     }
> +}
> diff --git a/tipc/misc.h b/tipc/misc.h
> index 585df74..6e8afdd 100644
> --- a/tipc/misc.h
> +++ b/tipc/misc.h
> @@ -15,5 +15,7 @@
>  #include <stdint.h>
>  
>  uint32_t str2addr(char *str);
> +int str2nodeid(char *str, uint8_t *id);
> +void nodeid2str(uint8_t *id, char *str);
>  
>  #endif
> diff --git a/tipc/node.c b/tipc/node.c
> index 201fe1a..fc9e843 100644
> --- a/tipc/node.c
> +++ b/tipc/node.c
> @@ -130,6 +130,81 @@ static int cmd_node_get_addr(struct nlmsghdr *nlh, const 
> struct cmd *cmd,
>       return 0;
>  }
>  
> +static int cmd_node_set_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
> +                            struct cmdl *cmdl, void *data)
> +{
> +     char buf[MNL_SOCKET_BUFFER_SIZE];
> +     uint8_t id[16] = {0,};
> +     struct nlattr *nest;
> +     char *str;
> +
> +     if (cmdl->argc != cmdl->optind + 1) {
> +             fprintf(stderr, "Usage: %s node set nodeid NODE_ID\n",
> +                     cmdl->argv[0]);
> +             return -EINVAL;
> +     }
> +
> +     str = shift_cmdl(cmdl);
> +     if (str2nodeid(str, id)) {
> +             fprintf(stderr, "Invalid node identity\n");
> +             return -EINVAL;
> +     }
> +
> +     if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
> +             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, *(uint64_t *)&id[0]);
> +     mnl_attr_put_u64(nlh, TIPC_NLA_NET_NODEID_W1, *(uint64_t *)&id[8]);
> +     mnl_attr_nest_end(nlh, nest);
> +     return msg_doit(nlh, NULL, NULL);
> +}
> +
> +static int nodeid_get_cb(const struct nlmsghdr *nlh, void *data)
> +{
> +     struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
> +     struct nlattr *info[TIPC_NLA_MAX + 1] = {};
> +     struct nlattr *attrs[TIPC_NLA_NET_MAX + 1] = {};
> +     char str[33] = {0,};
> +     char id[16] = {0,};
> +
> +     mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
> +     if (!info[TIPC_NLA_NET])
> +             return MNL_CB_ERROR;
> +
> +     mnl_attr_parse_nested(info[TIPC_NLA_NET], parse_attrs, attrs);
> +     if (!attrs[TIPC_NLA_NET_ID])
> +             return MNL_CB_ERROR;
> +
> +     *(uint64_t*) &id[0]  = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID]);
> +     *(uint64_t*) &id[8]  = mnl_attr_get_u64(attrs[TIPC_NLA_NET_NODEID_W1]);
> +     printf("%llu, %llu\n",&id[0], &id[8]);
> +     nodeid2str(id, str);
> +     printf("%llu, %llu\n",&id[0], &id[8]);
> +     printf("%s\n", str);
> +     return MNL_CB_OK;
> +}
> +
> +static int cmd_node_get_nodeid(struct nlmsghdr *nlh, const struct cmd *cmd,
> +                            struct cmdl *cmdl, void *data)
> +{
> +     char buf[MNL_SOCKET_BUFFER_SIZE];
> +
> +     if (help_flag) {
> +             (cmd->help)(cmdl);
> +             return -EINVAL;
> +     }
> +
> +     if (!(nlh = msg_init(buf, TIPC_NL_NET_GET))) {
> +             fprintf(stderr, "error, message initialisation failed\n");
> +             return -1;
> +     }
> +
> +     return msg_dumpit(nlh, nodeid_get_cb, NULL);
> +}
> +
> +
>  static int netid_get_cb(const struct nlmsghdr *nlh, void *data)
>  {
>       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
> @@ -203,7 +278,8 @@ static void cmd_node_set_help(struct cmdl *cmdl)
>       fprintf(stderr,
>               "Usage: %s node set PROPERTY\n\n"
>               "PROPERTIES\n"
> -             " address ADDRESS       - Set local address\n"
> +//           " address ADDRESS       - Set local address\n"
> +             " identity NODEID       - Set node identity\n"
>               " netid NETID           - Set local netid\n",
>               cmdl->argv[0]);
>  }
> @@ -213,7 +289,9 @@ static int cmd_node_set(struct nlmsghdr *nlh, const 
> struct cmd *cmd,
>  {
>       const struct cmd cmds[] = {
>               { "address",    cmd_node_set_addr,      NULL },
> +             { "identity",   cmd_node_set_nodeid,    NULL },
>               { "netid",      cmd_node_set_netid,     NULL },
> +             { "clusterid",  cmd_node_set_netid,     NULL },
>               { NULL }
>       };
>  
> @@ -225,7 +303,8 @@ static void cmd_node_get_help(struct cmdl *cmdl)
>       fprintf(stderr,
>               "Usage: %s node get PROPERTY\n\n"
>               "PROPERTIES\n"
> -             " address               - Get local address\n"
> +//           " address               - Get local address\n"
> +             " identity              - Get node identity\n"
>               " netid                 - Get local netid\n",
>               cmdl->argv[0]);
>  }
> @@ -235,6 +314,7 @@ static int cmd_node_get(struct nlmsghdr *nlh, const 
> struct cmd *cmd,
>  {
>       const struct cmd cmds[] = {
>               { "address",    cmd_node_get_addr,      NULL },
> +             { "identity",   cmd_node_get_nodeid,    NULL },
>               { "netid",      cmd_node_get_netid,     NULL },
>               { NULL }
>       };
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to